From 1dc4c5de39970316494ab17e2b50ae1a7ca6170e Mon Sep 17 00:00:00 2001 From: Not Zed Date: Thu, 20 Mar 2003 10:17:25 +0000 Subject: ** for mail part of bug #38461. 2003-03-21 Not Zed ** for mail part of bug #38461. * importers/evolution-outlook-importer.c (load_file_fn): dont pass in create flag to uri_to_folder, the folder must already exist. * importers/evolution-mbox-importer.c (folder_created_cb): Removed, we now force the caller to create the destination folder first. (load_file_fn): Dont try and create a folder if it doesn't exist. Also, use the uri directly as the destination uri, so we can import into any folder. (process_item_fn): If we dont have a folder, thats just an error, return BAD_FILE. * importers/netscape-importer.c (netscape_import_file): As below for elm_import_file. (import_next): similarly as for pine import_next. (importer_cb): just record result. (importer_timeout_fn): removed. * importers/pine-importer.c (import_next): Similar to below for the elm import_next. (pine_import_file): As below for elm_import_file. (importer_timeout_fn): removed. (importer_cb): just record the result, and exit. (import_next): change around to behave more like the elm importer, cleaning up when we're done. * importers/elm-importer.c (elm_import_file): Create the destination folder ourselves, dont pass it onto the mbox importer. Simplify logic, just do the import within a while loop, polling the g main loop as necessary, remove need for idle callbacks and other crap. (import_next): If elm_import_file fails, then just go straight to the next folder, stops it falling in a heap. (import_item_idle): removed. (importer_cb): just record result/exit. * mail-importer.c (mail_importer_create_folder): removed. (mail_importer_make_local_folder): new function to create a local-only folder from a path. It runs synchronously by using a recursive main loop. (folder_created_cb): callback for make_local_folder. svn path=/trunk/; revision=20379 --- mail/importers/elm-importer.c | 105 ++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 51 deletions(-) (limited to 'mail/importers/elm-importer.c') diff --git a/mail/importers/elm-importer.c b/mail/importers/elm-importer.c index 0314952b94..730167243f 100644 --- a/mail/importers/elm-importer.c +++ b/mail/importers/elm-importer.c @@ -52,6 +52,8 @@ #include #include +#include "mail/mail-importer.h" + #define ELM_INTELLIGENT_IMPORTER_IID "OAFIID:GNOME_Evolution_Mail_Elm_Intelligent_Importer_Factory" #define MBOX_IMPORTER_IID "OAFIID:GNOME_Evolution_Mail_Mbox_Importer" #define KEY "elm-mail-imported" @@ -68,13 +70,13 @@ typedef struct { GList *dir_list; - int num; int progress_count; - int import_id; + int more; + EvolutionImporterResult result; GNOME_Evolution_Importer importer; EvolutionImporterListener *listener; - + GtkWidget *mail; gboolean do_mail; @@ -129,26 +131,6 @@ elm_restore_settings (ElmImporter *importer) importer->do_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/elm/mail", NULL); } -static gboolean -import_item_idle(void *data) -{ - ElmImporter *importer = data; - CORBA_Environment ev; - - importer->import_id = 0; - - CORBA_exception_init (&ev); - GNOME_Evolution_Importer_processItem (importer->importer, - bonobo_object_corba_objref (BONOBO_OBJECT (importer->listener)), - &ev); - if (ev._major != CORBA_NO_EXCEPTION) - g_warning ("Exception: %s", CORBA_exception_id (&ev)); - - CORBA_exception_free (&ev); - - return FALSE; -} - static void importer_cb (EvolutionImporterListener *listener, EvolutionImporterResult result, @@ -156,16 +138,9 @@ importer_cb (EvolutionImporterListener *listener, void *data) { ElmImporter *importer = (ElmImporter *) data; - - if (more_items) { - g_assert(importer->import_id == 0); - importer->progress_count++; - if ((importer->progress_count & 0xf) == 0) - gtk_progress_bar_pulse(GTK_PROGRESS_BAR(importer->progressbar)); - importer->import_id = g_idle_add(import_item_idle, importer); - } else { - import_next (importer); - } + + importer->result = result; + importer->more = more_items; } static gboolean @@ -176,37 +151,60 @@ elm_import_file (ElmImporter *importer, CORBA_boolean result; CORBA_Environment ev; CORBA_Object objref; - char *str; - - CORBA_exception_init (&ev); + char *str, *uri; + struct stat st; str = g_strdup_printf (_("Importing %s as %s"), path, folderpath); gtk_label_set_text (GTK_LABEL (importer->label), str); g_free (str); - while (gtk_events_pending ()) { - gtk_main_iteration (); + while (g_main_context_iteration(NULL, FALSE)) + ; + + uri = mail_importer_make_local_folder(folderpath); + if (!uri) + return FALSE; + + /* if its a dir, we just create it, but dont add anything */ + if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) { + g_free(uri); + /* this is ok, we return false to say we haven't launched an async task */ + return FALSE; } - result = GNOME_Evolution_Importer_loadFile (importer->importer, path, - folderpath, &ev); + CORBA_exception_init(&ev); + + result = GNOME_Evolution_Importer_loadFile (importer->importer, path, uri, &ev); + g_free(uri); if (ev._major != CORBA_NO_EXCEPTION || result == FALSE) { g_warning ("Exception here: %s", CORBA_exception_id (&ev)); CORBA_exception_free (&ev); return FALSE; } - importer->listener = evolution_importer_listener_new (importer_cb, - importer); + /* process all items in a direct loop */ + importer->listener = evolution_importer_listener_new (importer_cb, importer); objref = bonobo_object_corba_objref (BONOBO_OBJECT (importer->listener)); - GNOME_Evolution_Importer_processItem (importer->importer, objref, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("Exception: %s", CORBA_exception_id (&ev)); - CORBA_exception_free (&ev); - return FALSE; - } + do { + importer->progress_count++; + if ((importer->progress_count & 0xf) == 0) + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(importer->progressbar)); + + importer->result = -1; + GNOME_Evolution_Importer_processItem (importer->importer, objref, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("Exception: %s", CORBA_exception_id (&ev)); + break; + } + + while (importer->result == -1 || g_main_context_pending(NULL)) + g_main_context_iteration(NULL, TRUE); + } while (importer->more); + + bonobo_object_unref((BonoboObject *)importer->listener); + CORBA_exception_free (&ev); - return TRUE; + return FALSE; } static void @@ -346,9 +344,11 @@ import_next (ElmImporter *importer) { ElmFolder *data; +trynext: if (importer->dir_list) { char *folder; GList *l; + int ok; l = importer->dir_list; data = l->data; @@ -357,13 +357,16 @@ import_next (ElmImporter *importer) importer->dir_list = l->next; g_list_free_1(l); - - elm_import_file (importer, data->path, folder); + + ok = elm_import_file (importer, data->path, folder); g_free (folder); g_free (data->parent); g_free (data->path); g_free (data->foldername); g_free (data); + /* its ugly, but so is everything else in this file */ + if (!ok) + goto trynext; } else { bonobo_object_unref((BonoboObject *)importer->ii); } -- cgit v1.2.3