aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-03-20 18:17:25 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-03-20 18:17:25 +0800
commit1dc4c5de39970316494ab17e2b50ae1a7ca6170e (patch)
treef474ee61d5e15306ca95f386223d91f1cb060761
parent4ac5734af0ee578f5e769bf4bd5a420d379d2155 (diff)
downloadgsoc2013-evolution-1dc4c5de39970316494ab17e2b50ae1a7ca6170e.tar.gz
gsoc2013-evolution-1dc4c5de39970316494ab17e2b50ae1a7ca6170e.tar.zst
gsoc2013-evolution-1dc4c5de39970316494ab17e2b50ae1a7ca6170e.zip
** for mail part of bug #38461.
2003-03-21 Not Zed <NotZed@Ximian.com> ** 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
-rw-r--r--mail/ChangeLog46
-rw-r--r--mail/importers/elm-importer.c105
-rw-r--r--mail/importers/evolution-mbox-importer.c105
-rw-r--r--mail/importers/evolution-outlook-importer.c6
-rw-r--r--mail/importers/netscape-importer.c101
-rw-r--r--mail/importers/pine-importer.c114
-rw-r--r--mail/mail-importer.c111
-rw-r--r--mail/mail-importer.h4
8 files changed, 276 insertions, 316 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 876f404239..b263eafd14 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,49 @@
+2003-03-21 Not Zed <NotZed@Ximian.com>
+
+ ** 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.
+
2003-03-19 Jeffrey Stedfast <fejj@ximian.com>
* mail-config-druid.c (mail_config_druid_new): Revert ettore's
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 <importer/evolution-importer-client.h>
#include <importer/GNOME_Evolution_Importer.h>
+#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);
}
diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c
index 31d3d4c6a2..9cbcdeb9de 100644
--- a/mail/importers/evolution-mbox-importer.c
+++ b/mail/importers/evolution-mbox-importer.c
@@ -120,19 +120,9 @@ process_item_fn (EvolutionImporter *eimporter,
const char *mozilla_status;
if (importer->folder == NULL) {
- /* if it failed, need to say it failed ... */
- /* the create_folder callback needs to store the create result */
- /* here we need to pass FALSE for more items */
- printf("not ready\n");
- if (mbi->create_result == GNOME_Evolution_Storage_OK)
- GNOME_Evolution_ImporterListener_notifyResult (listener,
- GNOME_Evolution_ImporterListener_NOT_READY,
- TRUE, ev);
- else
- GNOME_Evolution_ImporterListener_notifyResult (listener,
- GNOME_Evolution_ImporterListener_BAD_FILE,
- FALSE, ev);
- return;
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_BAD_FILE,
+ FALSE, ev);
}
if (mbi->is_folder == TRUE) {
@@ -247,59 +237,14 @@ importer_destroy_cb (void *data, GObject *object)
g_free (mbi);
}
-static void
-folder_created_cb (BonoboListener *listener,
- const char *event_name,
- const BonoboArg *event_data,
- CORBA_Environment *ev,
- MailImporter *importer)
-{
- char *fullpath;
- GNOME_Evolution_Storage_FolderResult *result;
- CamelException *ex;
-
- if (strcmp (event_name, "evolution-shell:folder_created") != 0) {
- return; /* Unknown event */
- }
-
- result = event_data->_value;
-
- printf("folder created cb, result = %d\n", result->result);
- ((MboxImporter *)importer)->create_result = result->result;
-
- if (result->result != GNOME_Evolution_Storage_OK)
- return;
-
- fullpath = g_strconcat ("file://", result->path, NULL);
-
- ex = camel_exception_new ();
- importer->folder = mail_tool_uri_to_folder (fullpath, CAMEL_STORE_FOLDER_CREATE, ex);
- if (camel_exception_is_set (ex)) {
- g_warning ("Error opening %s", fullpath);
- camel_exception_free (ex);
-
- g_free (fullpath);
- ((MboxImporter *)importer)->create_result = GNOME_Evolution_Storage_GENERIC_ERROR;
-
- return;
- }
-
- camel_folder_freeze (importer->folder);
- importer->frozen = TRUE;
-
- g_free (fullpath);
- bonobo_object_unref (BONOBO_OBJECT (listener));
-}
-
static gboolean
load_file_fn (EvolutionImporter *eimporter,
const char *filename,
- const char *folderpath,
+ const char *uri,
void *closure)
{
MboxImporter *mbi;
MailImporter *importer;
- gboolean delayed = FALSE;
struct stat buf;
int fd;
@@ -328,46 +273,12 @@ load_file_fn (EvolutionImporter *eimporter,
}
importer->mstream = NULL;
- if (folderpath == NULL || *folderpath == '\0') {
+ if (uri == NULL || *uri == '\0')
importer->folder = mail_tool_get_local_inbox (NULL);
- } else {
- char *parent, *fullpath, *homedir;
- const char *name;
- BonoboListener *listener;
- CamelException *ex;
-
- homedir = g_strdup_printf("file://%s/evolution/local", g_get_home_dir());
+ else
+ importer->folder = mail_tool_uri_to_folder(uri, 0, NULL);
- fullpath = e_path_to_physical (homedir, folderpath);
- ex = camel_exception_new ();
- importer->folder = mail_tool_uri_to_folder (fullpath, 0, ex);
- g_free (homedir);
-
- if (camel_exception_is_set (ex) || importer->folder == NULL) {
- /* Make a new directory */
- name = strrchr (folderpath, '/');
- if (name == NULL) {
- parent = g_strdup ("/");
- name = folderpath;
- } else {
- name += 1;
- parent = g_path_get_dirname (folderpath);
- }
-
- listener = bonobo_listener_new (NULL, NULL);
- g_signal_connect((listener), "event-notify",
- G_CALLBACK (folder_created_cb),
- importer);
- mbi->create_result = GNOME_Evolution_Storage_OK;
- mail_importer_create_folder (parent, name, NULL, listener);
- delayed = importer->folder == NULL;
- g_free (parent);
- }
- camel_exception_free (ex);
- g_free (fullpath);
- }
-
- if (importer->folder == NULL && delayed == FALSE){
+ if (importer->folder == NULL) {
g_warning ("Bad folder\n");
goto fail;
}
diff --git a/mail/importers/evolution-outlook-importer.c b/mail/importers/evolution-outlook-importer.c
index 2737aa592a..f0c697c6b6 100644
--- a/mail/importers/evolution-outlook-importer.c
+++ b/mail/importers/evolution-outlook-importer.c
@@ -224,7 +224,7 @@ importer_destroy_cb (void *data, GObject *object)
static gboolean
load_file_fn (EvolutionImporter *eimporter,
const char *filename,
- const char *folderpath,
+ const char *uri,
void *closure)
{
OutlookImporter *oli;
@@ -263,10 +263,10 @@ load_file_fn (EvolutionImporter *eimporter,
importer->mstream = NULL;
- if (folderpath == NULL || *folderpath == '\0')
+ if (uri == NULL || *uri == 0)
importer->folder = mail_tool_get_local_inbox (NULL);
else
- importer->folder = mail_tool_uri_to_folder (folderpath, CAMEL_STORE_FOLDER_CREATE, NULL);
+ importer->folder = mail_tool_uri_to_folder (uri, 0, NULL);
if (importer->folder == NULL){
g_warning ("Bad folder");
diff --git a/mail/importers/netscape-importer.c b/mail/importers/netscape-importer.c
index b08c1f7e00..cb0f430299 100644
--- a/mail/importers/netscape-importer.c
+++ b/mail/importers/netscape-importer.c
@@ -64,6 +64,7 @@
#include <shell/evolution-shell-client.h>
#include "Mailer.h"
+#include "mail/mail-importer.h"
static char *nsmail_dir = NULL;
static GHashTable *user_prefs = NULL;
@@ -94,8 +95,8 @@ typedef struct {
GList *dir_list;
int progress_count;
- int num;
- guint import_id;
+ int more;
+ EvolutionImporterResult result;
GNOME_Evolution_Importer importer;
EvolutionImporterListener *listener;
@@ -1728,26 +1729,6 @@ netscape_can_import (EvolutionIntelligentImporter *ii,
}
}
-static gboolean
-importer_timeout_fn (gpointer data)
-{
- NsImporter *importer = (NsImporter *) data;
- CORBA_Object objref;
- CORBA_Environment ev;
-
- importer->import_id = 0;
-
- CORBA_exception_init (&ev);
- objref = bonobo_object_corba_objref (BONOBO_OBJECT (importer->listener));
- GNOME_Evolution_Importer_processItem (importer->importer, objref, &ev);
- CORBA_exception_free (&ev);
-
- if (ev._major != CORBA_NO_EXCEPTION)
- g_warning ("Exception: %s", CORBA_exception_id (&ev));
-
- return FALSE;
-}
-
static void
importer_cb (EvolutionImporterListener *listener,
EvolutionImporterResult result,
@@ -1755,25 +1736,9 @@ importer_cb (EvolutionImporterListener *listener,
void *data)
{
NsImporter *importer = (NsImporter *) data;
-
- if (result == EVOLUTION_IMPORTER_NOT_READY ||
- result == EVOLUTION_IMPORTER_BUSY) {
- g_timeout_add (1000, importer_timeout_fn, data);
- return;
- }
-
- if (more_items) {
- importer->progress_count++;
- if ((importer->progress_count & 0xf) == 0)
- gtk_progress_bar_pulse(GTK_PROGRESS_BAR(importer->progressbar));
- importer->import_id = g_idle_add(importer_timeout_fn, importer);
- return;
- }
- if (importer->dir_list)
- import_next (importer);
- else
- bonobo_object_unref((BonoboObject *)importer->ii);
+ importer->result = result;
+ importer->more = more_items;
}
static gboolean
@@ -1784,9 +1749,9 @@ netscape_import_file (NsImporter *importer,
CORBA_boolean result;
CORBA_Environment ev;
CORBA_Object objref;
- char *str;
+ char *str, *uri;
- /* Do import */
+ /* Do import of mail folder */
d(g_warning ("Importing %s as %s", path, folderpath));
CORBA_exception_init (&ev);
@@ -1794,33 +1759,43 @@ netscape_import_file (NsImporter *importer,
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;
- result = GNOME_Evolution_Importer_loadFile (importer->importer, path,
- folderpath, &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));
- d(g_print ("%s:Processing...\n", G_GNUC_FUNCTION));
- CORBA_exception_init (&ev);
- 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;
}
typedef struct {
@@ -1835,9 +1810,11 @@ import_next (NsImporter *importer)
{
NetscapeCreateDirectoryData *data;
+trynext:
if (importer->dir_list) {
char *folder;
GList *l;
+ int ok;
l = importer->dir_list;
data = l->data;
@@ -1847,12 +1824,16 @@ import_next (NsImporter *importer)
importer->dir_list = l->next;
g_list_free_1(l);
- netscape_import_file (importer, data->path, folder);
+ ok = netscape_import_file (importer, data->path, folder);
g_free (folder);
g_free (data->parent);
g_free (data->path);
g_free (data->foldername);
g_free (data);
+ if (!ok)
+ goto trynext;
+ } else {
+ bonobo_object_unref((BonoboObject *)importer->ii);
}
}
diff --git a/mail/importers/pine-importer.c b/mail/importers/pine-importer.c
index af4f8f783b..2368c0c12f 100644
--- a/mail/importers/pine-importer.c
+++ b/mail/importers/pine-importer.c
@@ -54,6 +54,8 @@
#include <importer/evolution-importer-client.h>
#include <importer/GNOME_Evolution_Importer.h>
+#include "mail/mail-importer.h"
+
#include <ebook/e-book.h>
#include <ebook/e-card-simple.h>
@@ -74,6 +76,8 @@ typedef struct {
GList *dir_list;
int progress_count;
+ int more;
+ EvolutionImporterResult result;
GNOME_Evolution_Importer importer;
EvolutionImporterListener *listener;
@@ -85,9 +89,6 @@ typedef struct {
EBook *book;
- int timeout_id;
- int more;
-
/* GUI */
GtkWidget *dialog;
GtkWidget *label;
@@ -258,33 +259,6 @@ import_addressbook (PineImporter *importer)
g_free (uri);
}
-static gboolean
-importer_timeout_fn (gpointer data)
-{
- PineImporter *importer = (PineImporter *) data;
- CORBA_Environment ev;
-
- importer->timeout_id = 0;
-
- if (importer->more) {
- importer->progress_count++;
- if ((importer->progress_count & 0xf) == 0)
- gtk_progress_bar_pulse(GTK_PROGRESS_BAR(importer->progressbar));
-
- 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);
- } else if (importer->dir_list) {
- import_next (importer);
- } else {
- bonobo_object_unref (BONOBO_OBJECT (importer->ii));
- }
-
- return FALSE;
-}
-
static void
importer_cb (EvolutionImporterListener *listener,
EvolutionImporterResult result,
@@ -292,26 +266,9 @@ importer_cb (EvolutionImporterListener *listener,
void *data)
{
PineImporter *importer = (PineImporter *) data;
-
- if (result == EVOLUTION_IMPORTER_NOT_READY ||
- result == EVOLUTION_IMPORTER_BUSY) {
- importer->more = more_items;
- importer->timeout_id = gtk_timeout_add (1000, importer_timeout_fn, data);
- return;
- }
-
- if (importer->timeout_id) {
- /* we ignore multiple calls, we can get them if for
- example we're waiting for a folder to open, yet we
- tried to open the next. Uh, this shouldn't happen
- anyway, but ... */
- return;
- }
+ importer->result = result;
importer->more = more_items;
-
- importer->timeout_id = g_idle_add(importer_timeout_fn, importer);
- return;
}
static gboolean
@@ -323,36 +280,59 @@ pine_import_file (PineImporter *importer,
CORBA_boolean result;
CORBA_Environment ev;
CORBA_Object objref;
- char *str;
+ char *str, *uri;
+ struct stat st;
CORBA_exception_init (&ev);
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;
+
+ /* only create dirs, dont try to import them */
+ 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);
+ 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\n%s, %s", CORBA_exception_id (&ev), path, folderpath);
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);
- }
+ 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 gboolean
@@ -385,10 +365,12 @@ static void
import_next (PineImporter *importer)
{
PineFolder *data;
-
+
+trynext:
if (importer->dir_list) {
char *folder;
GList *l;
+ int ok;
l = importer->dir_list;
data = l->data;
@@ -396,14 +378,18 @@ import_next (PineImporter *importer)
importer->dir_list = l->next;
g_list_free_1(l);
- pine_import_file (importer, data->path, folder, data->folder);
+ ok = pine_import_file (importer, data->path, folder, data->folder);
+
g_free (folder);
g_free (data->parent);
g_free (data->path);
g_free (data->foldername);
g_free (data);
+ if (!ok)
+ goto trynext;
+ } else {
+ bonobo_object_unref((BonoboObject *)importer->ii);
}
-
}
/* Pine uses sent-mail and saved-mail whereas Evolution uses Sent and Drafts */
diff --git a/mail/mail-importer.c b/mail/mail-importer.c
index f6b67351d3..f6d73a5d30 100644
--- a/mail/mail-importer.c
+++ b/mail/mail-importer.c
@@ -39,62 +39,91 @@
#include "mail-local.h"
#include "mail.h"
-
static GList *importer_modules = NULL;
-
extern char *evolution_dir;
-
static GNOME_Evolution_Storage local_storage = NULL;
-/* Prototype */
-
void mail_importer_uninit (void);
+struct _create_data {
+ GNOME_Evolution_Storage_Result create_result;
+ int create_done:1;
+};
+
+static void
+folder_created_cb(BonoboListener *listener, const char *event_name, const BonoboArg *event_data,
+ CORBA_Environment *ev, struct _create_data *data)
+{
+ GNOME_Evolution_Storage_FolderResult *result;
+
+ data->create_done = TRUE;
+
+ if (strcmp (event_name, "evolution-shell:folder_created") != 0) {
+ return; /* Unknown event */
+ }
+
+ result = event_data->_value;
+ data->create_result = result->result;
+}
+
/**
- * mail_importer_create_folder:
- * parent_path: The path of the parent folder.
- * name: The name of the folder to be created.
- * description: A description of the folder.
- * listener: A BonoboListener for notification.
- *
- * Attempts to create the folder @parent_path/@name. When the folder has been
- * created, or there is an error, the "evolution-shell:folder-created" event is
- * emitted on @listener. The BonoboArg that is sent to @listener is a
- * GNOME_Evolution_Storage_FolderResult which has two elements: result and path.
- * Result contains the error code, or success, and path contains the complete
- * physical path to the newly created folder.
- */
-void
-mail_importer_create_folder (const char *parent_path,
- const char *name,
- const char *description,
- const BonoboListener *listener)
+ * mail_importer_make_local_folder:
+ * @folderpath:
+ *
+ * Check a local folder exists at path @folderpath, and if not, create it.
+ *
+ * Return value: The physical uri of the folder, or NULL if the folder did
+ * not exist and could not be created.
+ **/
+char *
+mail_importer_make_local_folder(const char *folderpath)
{
- Bonobo_Listener corba_listener;
CORBA_Environment ev;
- char *path, *physical;
- char *real_description;
+ char *uri = NULL, *tmp;
+ GNOME_Evolution_Folder *fi;
+ BonoboListener *listener;
- g_return_if_fail (local_storage != NULL);
- g_return_if_fail (listener != NULL);
- g_return_if_fail (BONOBO_IS_LISTENER (listener));
+ CORBA_exception_init (&ev);
- path = g_build_filename(parent_path, name, NULL);
- physical = g_strdup_printf ("file://%s/local/%s", evolution_dir, parent_path);
+ /* first, check, does this folder exist, if so, use the right path */
+ fi = GNOME_Evolution_Storage_getFolderAtPath(local_storage, folderpath, &ev);
+ if (fi) {
+ printf("folder %s exists @ %s\n", folderpath, fi->physicalUri);
+ uri = g_strdup(fi->physicalUri);
+ CORBA_free(fi);
+ } else {
+ struct _create_data data = { GNOME_Evolution_Storage_GENERIC_ERROR, FALSE };
- corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener));
+ tmp = g_strdup_printf("file://%s/local", evolution_dir);
+ uri = e_path_to_physical(tmp, folderpath);
+ g_free(tmp);
+ tmp = strrchr(uri, '/');
+ tmp[0] = 0;
- /* Darn CORBA wanting non-NULL values for strings */
- real_description = CORBA_string_dup (description ? description : "");
+ printf("Creating folder %s, parent %s\n", folderpath, uri);
+
+ listener = bonobo_listener_new (NULL, NULL);
+ g_signal_connect(listener, "event-notify", G_CALLBACK (folder_created_cb), &data);
+
+ GNOME_Evolution_Storage_asyncCreateFolder(local_storage, folderpath, "mail", "", uri,
+ bonobo_object_corba_objref((BonoboObject *)listener), &ev);
+
+ while (!data.create_done)
+ g_main_context_iteration(NULL, TRUE);
+
+ bonobo_object_unref((BonoboObject *)listener);
+
+ if (data.create_result != GNOME_Evolution_Storage_OK) {
+ g_free(uri);
+ uri = NULL;
+ } else {
+ *tmp = '/';
+ }
+ }
- CORBA_exception_init (&ev);
- GNOME_Evolution_Storage_asyncCreateFolder (local_storage,
- path, "mail",
- real_description, physical,
- corba_listener, &ev);
CORBA_exception_free (&ev);
- g_free (path);
- g_free (physical);
+
+ return uri;
}
/**
diff --git a/mail/mail-importer.h b/mail/mail-importer.h
index 41e7e0471c..66b4441e1d 100644
--- a/mail/mail-importer.h
+++ b/mail/mail-importer.h
@@ -46,4 +46,8 @@ void mail_importer_create_folder (const char *parent_path,
const char *name,
const char *description,
const BonoboListener *listener);
+
+/* creates a folder at folderpath on the local storage */
+char *mail_importer_make_local_folder(const char *folderpath);
+
#endif