diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 21 | ||||
-rw-r--r-- | mail/Makefile.am | 3 | ||||
-rw-r--r-- | mail/importers/GNOME_Evolution_Mail_Importers.server.in.in | 66 | ||||
-rw-r--r-- | mail/importers/Makefile.am | 24 | ||||
-rw-r--r-- | mail/importers/elm-importer.c | 409 | ||||
-rw-r--r-- | mail/importers/evolution-mbox-importer.c | 191 | ||||
-rw-r--r-- | mail/importers/mail-importer.c | 14 | ||||
-rw-r--r-- | mail/importers/mail-importer.h | 8 | ||||
-rw-r--r-- | mail/importers/pine-importer.c | 377 | ||||
-rw-r--r-- | mail/mail-component-factory.c | 8 |
10 files changed, 450 insertions, 671 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 810b854133..0cdd62fcf9 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -52,6 +52,27 @@ * mail-component.c: (handleuri_got_folder): Added "forward" command-line option. +2005-07-06 Not Zed <NotZed@Ximian.com> + + * importers/evolution-mbox-importer.c (mbox_getwidget): wrap the + widgets in another vbox so they display properly. + + * importers/pine-importer.c (pine_getwidget): pack the 'mail' + widget. + + * importers/pine-importer.c (pine_import): + importers/elm-importer.c (elm_import): + importers/evolution-mbox-importer.c (mbox_import): Dont create + widgets anymore, report progress through the EImport and handle + cancel. + +2005-07-01 Not Zed <NotZed@Ximian.com> + + * importers/Makefile.am: remove shell/importer link & take out + netscape & outlook temporarily. + + * Makefile.am: Removed importer link. + 2005-06-24 Matt Brown <matt@mattb.net.nz> * em-inline-filter.c: implement extraction of inline signed/encrypted pgp diff --git a/mail/Makefile.am b/mail/Makefile.am index 9e4cafdc2d..779ccb34d8 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -11,8 +11,6 @@ INCLUDES = \ -I$(top_builddir)/composer \ -I$(top_builddir)/shell \ -I$(top_srcdir)/shell \ - -I$(top_srcdir)/shell/importer \ - -I$(top_builddir)/shell/importer \ -I$(top_srcdir)/smime/lib \ -I$(top_srcdir)/smime/gui \ $(EVOLUTION_MAIL_CFLAGS) \ @@ -211,7 +209,6 @@ SMIME_LIB=$(top_builddir)/smime/gui/libevolution-smime.la endif libevolution_mail_la_LIBADD = \ - $(top_builddir)/shell/importer/libevolution-importer.la \ $(top_builddir)/mail/importers/libevolution-mail-importers.la\ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/shell/libeshell.la \ diff --git a/mail/importers/GNOME_Evolution_Mail_Importers.server.in.in b/mail/importers/GNOME_Evolution_Mail_Importers.server.in.in deleted file mode 100644 index e3c5f91e6b..0000000000 --- a/mail/importers/GNOME_Evolution_Mail_Importers.server.in.in +++ /dev/null @@ -1,66 +0,0 @@ -<oaf_info> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Elm_Intelligent_Importer:@VERSION@" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Factory:@VERSION@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/IntelligentImporter:@VERSION@"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Elm importer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_Importer:@VERSION@" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Factory:@VERSION@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/Importer:@VERSION@"/> - </oaf_attribute> - - <oaf_attribute name="evolution:menu_name" type="string" - _value="MBox (mbox)"/> - <oaf_attribute name="name" type="string" - _value="Evolution mbox importer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer:@VERSION@" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Factory:@VERSION@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/IntelligentImporter:@VERSION@"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Netscape Mail importer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_Importer:@VERSION@" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Factory:@VERSION@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/Importer:@VERSION@"/> - </oaf_attribute> - - <oaf_attribute name="evolution:menu_name" type="string" - _value="Outlook Express 4 (.mbx)"/> - <oaf_attribute name="name" type="string" - _value="Evolution Outlook Express 4 importer"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Pine_Intelligent_Importer:@VERSION@" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Factory:@VERSION@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/IntelligentImporter:@VERSION@"/> - </oaf_attribute> - - <oaf_attribute name="name" type="string" - _value="Evolution Pine importer"/> -</oaf_server> -</oaf_info> diff --git a/mail/importers/Makefile.am b/mail/importers/Makefile.am index f567e6e0db..b33c7e4265 100644 --- a/mail/importers/Makefile.am +++ b/mail/importers/Makefile.am @@ -4,8 +4,6 @@ privlib_LTLIBRARIES = libevolution-mail-importers.la INCLUDES = -I.. \ -I$(srcdir)/.. \ -I$(top_srcdir) \ - -I$(top_srcdir)/shell \ - -I$(top_builddir)/shell \ -DG_LOG_DOMAIN=\"evolution-mail-importer\" \ -I$(top_srcdir)/addressbook/backend \ -I$(top_builddir)/addressbook/backend \ @@ -17,27 +15,13 @@ libevolution_mail_importers_la_SOURCES = \ mail-importer.h \ elm-importer.c \ pine-importer.c \ - netscape-importer.c \ - evolution-outlook-importer.c \ evolution-mbox-importer.c +# these haven't been converted to plugins yet +# netscape-importer.c +# evolution-outlook-importer.c + libevolution_mail_importers_la_LIBADD = \ - $(top_builddir)/shell/importer/libevolution-importer.la \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/filter/libfilter.la \ - $(top_builddir)/shell/libeshell.la \ $(IMPORTERS_LIBS) - -server_in_files = \ - GNOME_Evolution_Mail_Importers.server.in.in -server_DATA = $(server_in_files:.server.in.in=_$(BASE_VERSION).server) -@EVO_SERVER_RULE@ -@INTLTOOL_SERVER_RULE@ - -BUILT_SOURCES = $(server_DATA) -CLEANFILES = $(BUILT_SOURCES) - -EXTRA_DIST = $(server_in_files) - -dist-hook: - cd $(distdir); rm -f $(BUILT_SOURCES) diff --git a/mail/importers/elm-importer.c b/mail/importers/elm-importer.c index 2793f58f50..7d8abdfa04 100644 --- a/mail/importers/elm-importer.c +++ b/mail/importers/elm-importer.c @@ -31,107 +31,51 @@ #include <sys/stat.h> #include <unistd.h> #include <dirent.h> +#include <string.h> #include <glib.h> -#include <gnome.h> +#include <glib/gi18n.h> +#include <gtk/gtkvbox.h> +#include <gtk/gtkcheckbutton.h> -#include <gconf/gconf.h> #include <gconf/gconf-client.h> #include <camel/camel-operation.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-control.h> - -#include <importer/evolution-intelligent-importer.h> -#include <importer/evolution-importer-client.h> -#include <importer/GNOME_Evolution_Importer.h> - #include "mail-importer.h" #include "mail/mail-mt.h" +#include "e-util/e-import.h" +#include "e-util/e-error.h" -#define KEY "elm-mail-imported" - -/*#define SUPER_IMPORTER_DEBUG*/ -#ifdef SUPER_IMPORTER_DEBUG #define d(x) x -#else -#define d(x) -#endif -typedef struct { - EvolutionIntelligentImporter *ii; +struct _elm_import_msg { + struct _mail_msg msg; - GHashTable *prefs; + EImport *import; + EImportTargetHome *target; GMutex *status_lock; char *status_what; int status_pc; int status_timeout_id; - CamelOperation *cancel; /* cancel/status port */ - - GtkWidget *mail; - gboolean do_mail; - gboolean done_mail; - - GtkWidget *dialog; - GtkWidget *label; - GtkWidget *progressbar; -} ElmImporter; - -static GtkWidget * -create_importer_gui (ElmImporter *importer) -{ - GtkWidget *dialog; - - dialog = gnome_message_box_new (_("Evolution is importing your old Elm mail"), GNOME_MESSAGE_BOX_INFO, NULL); - gtk_window_set_title (GTK_WINDOW (dialog), _("Importing...")); - - importer->label = gtk_label_new (_("Please wait")); - importer->progressbar = gtk_progress_bar_new (); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), importer->label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), importer->progressbar, FALSE, FALSE, 0); - - return dialog; -} - -static void -elm_store_settings (ElmImporter *importer) -{ - GConfClient *gconf; - - gconf = gconf_client_get_default (); - gconf_client_set_bool (gconf, "/apps/evolution/importer/elm/mail", importer->done_mail, NULL); - g_object_unref(gconf); -} - -static void -elm_restore_settings (ElmImporter *importer) -{ - GConfClient *gconf = gconf_client_get_default (); - - importer->done_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/elm/mail", NULL); - g_object_unref(gconf); -} + CamelOperation *status; +}; -static void -parse_elm_rc(ElmImporter *importer, const char *elmrc) +static GHashTable * +parse_elm_rc(const char *elmrc) { char line[4096]; FILE *handle; + GHashTable *prefs = g_hash_table_new(g_str_hash, g_str_equal); - if (importer->prefs) - return; - - importer->prefs = g_hash_table_new(g_str_hash, g_str_equal); - - if (!g_file_exists(elmrc)) - return; + if (!g_file_test(elmrc, G_FILE_TEST_IS_REGULAR)) + return prefs; handle = fopen (elmrc, "r"); if (handle == NULL) - return; + return prefs; while (fgets (line, 4096, handle) != NULL) { char *linestart, *end; @@ -167,77 +111,82 @@ parse_elm_rc(ElmImporter *importer, const char *elmrc) *end = 0; value = g_strdup (linestart); - g_hash_table_insert (importer->prefs, key, value); + g_hash_table_insert(prefs, key, value); } fclose (handle); + + return prefs; +} + +static void +elm_free_rc_item(void *k, void *v, void *d) +{ + g_free(k); + g_free(v); +} + +static void +elm_free_rc(void *prefs) +{ + g_hash_table_foreach(prefs, elm_free_rc_item, NULL); } static char * -elm_get_rc_value(ElmImporter *importer, const char *value) +elm_get_rc(EImport *ei, const char *name) { - return g_hash_table_lookup(importer->prefs, value); + GHashTable *prefs; + char *elmrc; + + prefs = g_object_get_data((GObject *)ei, "elm-rc"); + if (prefs == NULL) { + elmrc = g_build_filename(g_get_home_dir(), ".elm/elmrc", NULL); + prefs = parse_elm_rc(elmrc); + g_free(elmrc); + g_object_set_data_full((GObject *)ei, "elm-rc", prefs, elm_free_rc); + } + + if (prefs == NULL) + return NULL; + else + return g_hash_table_lookup(prefs, name); } static gboolean -elm_can_import(EvolutionIntelligentImporter *ii, void *closure) +elm_supported(EImport *ei, EImportTarget *target, EImportImporter *im) { - ElmImporter *importer = closure; + EImportTargetHome *s; const char *maildir; - char *elmdir, *elmrc; + char *elmdir; gboolean mailexists, exists; -#if 0 - char *aliasfile; - gboolean aliasexists; -#endif struct stat st; - elm_restore_settings(importer); + if (target->type != E_IMPORT_TARGET_HOME) + return FALSE; - importer->do_mail = !importer->done_mail; - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (importer->mail), importer->do_mail); - - elmdir = g_build_filename(g_get_home_dir(), ".elm", NULL); + s = (EImportTargetHome *)target; + + elmdir = g_build_filename(s->homedir, ".elm", NULL); exists = lstat(elmdir, &st) == 0 && S_ISDIR(st.st_mode); - g_free (elmdir); + g_free(elmdir); if (!exists) return FALSE; - elmrc = g_build_filename(g_get_home_dir(), ".elm/elmrc", NULL); - parse_elm_rc (importer, elmrc); - g_free(elmrc); - - maildir = elm_get_rc_value(importer, "maildir"); + maildir = elm_get_rc(ei, "maildir"); if (maildir == NULL) maildir = "Mail"; - if (!g_path_is_absolute (maildir)) - elmdir = g_build_filename(g_get_home_dir(), maildir, NULL); + if (!g_path_is_absolute(maildir)) + elmdir = g_build_filename(s->homedir, maildir, NULL); else elmdir = g_strdup (maildir); mailexists = lstat(elmdir, &st) == 0 && S_ISDIR(st.st_mode); g_free (elmdir); -#if 0 - aliasfile = gnome_util_prepend_user_home (".elm/aliases"); - aliasexists = lstat(aliasfile, &st) == 0 && S_ISREG(st.st_mode); - g_free (aliasfile); - - exists = (aliasexists || mailexists); -#endif - return mailexists; } -/* Almost all that follows is a direct copy of pine-importer.c with - * search and replace run on it */ -struct _elm_import_msg { - struct _mail_msg msg; - - ElmImporter *importer; -}; - static char * elm_import_describe (struct _mail_msg *mm, int complete) { @@ -253,62 +202,60 @@ static void elm_import_import(struct _mail_msg *mm) { struct _elm_import_msg *m = (struct _elm_import_msg *) mm; + const char *maildir; + char *elmdir; - if (m->importer->do_mail) { - const char *maildir; - char *elmdir; + maildir = elm_get_rc(m->import, "maildir"); + if (maildir == NULL) + maildir = "Mail"; - maildir = elm_get_rc_value(m->importer, "maildir"); - if (maildir == NULL) - maildir = "Mail"; - - if (!g_path_is_absolute(maildir)) - elmdir = g_build_filename(g_get_home_dir(), maildir, NULL); - else - elmdir = g_strdup(maildir); + if (!g_path_is_absolute(maildir)) + elmdir = g_build_filename(m->target->homedir, maildir, NULL); + else + elmdir = g_strdup(maildir); - mail_importer_import_folders_sync(elmdir, elm_special_folders, 0, m->importer->cancel); - } + mail_importer_import_folders_sync(elmdir, elm_special_folders, 0, m->status); + g_free(elmdir); } static void elm_import_imported(struct _mail_msg *mm) { + struct _elm_import_msg *m = (struct _elm_import_msg *)mm; + + printf("importing complete\n"); + + if (!camel_exception_is_set(&mm->ex)) { + GConfClient *gconf; + + gconf = gconf_client_get_default(); + gconf_client_set_bool(gconf, "/apps/evolution/importer/elm/mail", TRUE, NULL); + g_object_unref(gconf); + } + + e_import_complete(m->import, (EImportTarget *)m->target); } static void elm_import_free(struct _mail_msg *mm) { - /*struct _elm_import_msg *m = (struct _elm_import_msg *)mm;*/ -} + struct _elm_import_msg *m = (struct _elm_import_msg *)mm; -static struct _mail_msg_op elm_import_op = { - elm_import_describe, - elm_import_import, - elm_import_imported, - elm_import_free, -}; - -static int -mail_importer_elm_import(ElmImporter *importer) -{ - struct _elm_import_msg *m; - int id; + camel_operation_unref(m->status); - m = mail_msg_new(&elm_import_op, NULL, sizeof (*m)); - m->importer = importer; + g_free(m->status_what); + g_mutex_free(m->status_lock); - id = m->msg.seq; - - e_thread_put(mail_thread_queued, (EMsg *) m); + g_source_remove(m->status_timeout_id); + m->status_timeout_id = 0; - return id; + g_object_unref(m->import); } static void elm_status(CamelOperation *op, const char *what, int pc, void *data) { - ElmImporter *importer = data; + struct _elm_import_msg *importer = data; if (pc == CAMEL_OPERATION_START) pc = 0; @@ -325,129 +272,115 @@ elm_status(CamelOperation *op, const char *what, int pc, void *data) static gboolean elm_status_timeout(void *data) { - ElmImporter *importer = data; + struct _elm_import_msg *importer = data; int pc; char *what; - if (!importer->status_what) - return TRUE; + if (importer->status_what) { + g_mutex_lock(importer->status_lock); + what = importer->status_what; + importer->status_what = NULL; + pc = importer->status_pc; + g_mutex_unlock(importer->status_lock); - g_mutex_lock(importer->status_lock); - what = importer->status_what; - importer->status_what = NULL; - pc = importer->status_pc; - g_mutex_unlock(importer->status_lock); + e_import_status(importer->import, (EImportTarget *)importer->target, what, pc); + } - gtk_progress_bar_set_fraction((GtkProgressBar *)importer->progressbar, (gfloat)(pc/100.0)); - gtk_progress_bar_set_text((GtkProgressBar *)importer->progressbar, what); - return TRUE; } -static void -elm_create_structure (EvolutionIntelligentImporter *ii, - void *closure) -{ - ElmImporter *importer = closure; - - if (importer->do_mail) { - importer->dialog = create_importer_gui(importer); - gtk_widget_show_all(importer->dialog); - importer->status_timeout_id = g_timeout_add(100, elm_status_timeout, importer); - importer->cancel = camel_operation_new(elm_status, importer); - - mail_msg_wait(mail_importer_elm_import(importer)); +static struct _mail_msg_op elm_import_op = { + elm_import_describe, + elm_import_import, + elm_import_imported, + elm_import_free, +}; - camel_operation_unref(importer->cancel); - g_source_remove(importer->status_timeout_id); - importer->status_timeout_id = 0; +static int +mail_importer_elm_import(EImport *ei, EImportTarget *target) +{ + struct _elm_import_msg *m; + int id; - importer->done_mail = TRUE; - } + m = mail_msg_new(&elm_import_op, NULL, sizeof (*m)); + g_datalist_set_data(&target->data, "elm-msg", m); + m->import = ei; + g_object_ref(m->import); + m->target = (EImportTargetHome *)target; + m->status_timeout_id = g_timeout_add(100, elm_status_timeout, m); + m->status_lock = g_mutex_new(); + m->status = camel_operation_new(elm_status, m); - elm_store_settings (importer); + id = m->msg.seq; + + e_thread_put(mail_thread_queued, (EMsg *)m); - bonobo_object_unref (BONOBO_OBJECT (ii)); + return id; } static void -free_pref(void *key, void *value, void *data) +checkbox_toggle_cb (GtkToggleButton *tb, EImportTarget *target) { - g_free(key); - g_free(value); + g_datalist_set_data(&target->data, "elm-do-mail", GINT_TO_POINTER(gtk_toggle_button_get_active(tb))); } -static void -elm_destroy_cb (ElmImporter *importer, GtkObject *object) +static GtkWidget * +elm_getwidget(EImport *ei, EImportTarget *target, EImportImporter *im) { - elm_store_settings(importer); + GtkWidget *box, *w; + GConfClient *gconf; + gboolean done_mail; - if (importer->status_timeout_id) - g_source_remove(importer->status_timeout_id); - g_free(importer->status_what); - g_mutex_free(importer->status_lock); + gconf = gconf_client_get_default (); + done_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/elm/mail", NULL); + g_object_unref(gconf); - if (importer->dialog) - gtk_widget_destroy(importer->dialog); + g_datalist_set_data(&target->data, "elm-do-mail", GINT_TO_POINTER(!done_mail)); - if (importer->prefs) { - g_hash_table_foreach(importer->prefs, free_pref, NULL); - g_hash_table_destroy(importer->prefs); - } + box = gtk_vbox_new(FALSE, 2); + + w = gtk_check_button_new_with_label(_("Mail")); + gtk_toggle_button_set_active((GtkToggleButton *)w, !done_mail); + g_signal_connect(w, "toggled", G_CALLBACK(checkbox_toggle_cb), target); + + gtk_box_pack_start((GtkBox *)box, w, FALSE, FALSE, 0); + gtk_widget_show_all(box); - g_free(importer); + return box; } -/* Fun initialisation stuff */ -/* Fun control stuff */ static void -checkbox_toggle_cb (GtkToggleButton *tb, - gboolean *do_item) +elm_import(EImport *ei, EImportTarget *target, EImportImporter *im) { - *do_item = gtk_toggle_button_get_active (tb); + if (GPOINTER_TO_INT(g_datalist_get_data(&target->data, "elm-do-mail"))) + mail_importer_elm_import(ei, target); + else + e_import_complete(ei, target); } -static BonoboControl * -create_checkboxes_control (ElmImporter *importer) +static void +elm_cancel(EImport *ei, EImportTarget *target, EImportImporter *im) { - GtkWidget *hbox; - BonoboControl *control; - - hbox = gtk_vbox_new (FALSE, 2); - - importer->mail = gtk_check_button_new_with_label (_("Mail")); - gtk_signal_connect (GTK_OBJECT (importer->mail), "toggled", - GTK_SIGNAL_FUNC (checkbox_toggle_cb), - &importer->do_mail); + struct _elm_import_msg *m = g_datalist_get_data(&target->data, "elm-msg"); - gtk_box_pack_start (GTK_BOX (hbox), importer->mail, FALSE, FALSE, 0); - - gtk_widget_show_all (hbox); - control = bonobo_control_new (hbox); - return control; + if (m) + camel_operation_cancel(m->status); } -BonoboObject * -elm_intelligent_importer_new(void) +static EImportImporter elm_importer = { + E_IMPORT_TARGET_HOME, + 0, + elm_supported, + elm_getwidget, + elm_import, + elm_cancel, +}; + +EImportImporter * +elm_importer_peek(void) { - EvolutionIntelligentImporter *importer; - BonoboControl *control; - ElmImporter *elm; - char *message = N_("Evolution has found Elm mail files\n" - "Would you like to import them into Evolution?"); - - elm = g_new0 (ElmImporter, 1); - elm->status_lock = g_mutex_new(); - elm_restore_settings (elm); - importer = evolution_intelligent_importer_new (elm_can_import, - elm_create_structure, - _("Elm"), - _(message), elm); - g_object_weak_ref(G_OBJECT (importer), (GWeakNotify)elm_destroy_cb, elm); - elm->ii = importer; - - control = create_checkboxes_control(elm); - bonobo_object_add_interface(BONOBO_OBJECT(importer), BONOBO_OBJECT(control)); - - return BONOBO_OBJECT(importer); + elm_importer.name = _("Evolution Elm importer"); + elm_importer.description = _("Import mail from Elm."); + + return &elm_importer; } diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c index 3630277cdd..804a137543 100644 --- a/mail/importers/evolution-mbox-importer.c +++ b/mail/importers/evolution-mbox-importer.c @@ -36,18 +36,13 @@ #include <string.h> #include <gtk/gtkhbox.h> +#include <gtk/gtkvbox.h> #include <gtk/gtklabel.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkprogressbar.h> -#include <bonobo/bonobo-control.h> -#include <libgnome/gnome-i18n.h> +#include <glib/gi18n.h> #include <camel/camel-exception.h> -#include <importer/evolution-importer.h> -#include <importer/GNOME_Evolution_Importer.h> - #include "mail/em-folder-selection-button.h" #include "mail/mail-component.h" @@ -55,17 +50,11 @@ #include "mail-importer.h" -/* #define IMPORTER_DEBUG */ -#ifdef IMPORTER_DEBUG -#define IN g_print ("=====> %s (%d)\n", G_GNUC_FUNCTION, __LINE__) -#define OUT g_print ("<==== %s (%d)\n", G_GNUC_FUNCTION, __LINE__) -#else -#define IN -#define OUT -#endif +#include "e-util/e-import.h" typedef struct { - EvolutionImporter *ii; + EImport *import; + EImportTarget *target; GMutex *status_lock; char *status_what; @@ -73,42 +62,18 @@ typedef struct { int status_timeout_id; CamelOperation *cancel; /* cancel/status port */ - GtkWidget *selector; - GtkWidget *label; - GtkWidget *progressbar; - GtkWidget *dialog; - char *uri; } MboxImporter; static void -process_item_fn(EvolutionImporter *eimporter, CORBA_Object listener, void *data, CORBA_Environment *ev) -{ - /*MboxImporter *importer = data;*/ - GNOME_Evolution_ImporterListener_ImporterResult result; - - /* This is essentially a NOOP, it merely returns ok/fail and is only called once */ - -#if 0 - if (camel_exception_is_set(importer->ex)) - result = GNOME_Evolution_ImporterListener_BAD_FILE; - else -#endif - result = GNOME_Evolution_ImporterListener_OK; - - GNOME_Evolution_ImporterListener_notifyResult(listener, result, FALSE, ev); - bonobo_object_unref(BONOBO_OBJECT(eimporter)); -} - -static void -folder_selected(EMFolderSelectionButton *button, MboxImporter *importer) +folder_selected(EMFolderSelectionButton *button, EImportTargetURI *target) { - g_free(importer->uri); - importer->uri = g_strdup(em_folder_selection_button_get_selection(button)); + g_free(target->uri_dest); + target->uri_dest = g_strdup(em_folder_selection_button_get_selection(button)); } -static void -create_control_fn(EvolutionImporter *importer, Bonobo_Control *control, void *data) +static GtkWidget * +mbox_getwidget(EImport *ei, EImportTarget *target, EImportImporter *im) { GtkWidget *hbox, *w; @@ -120,23 +85,35 @@ create_control_fn(EvolutionImporter *importer, Bonobo_Control *control, void *da w = em_folder_selection_button_new(_("Select folder"), _("Select folder to import into")); em_folder_selection_button_set_selection((EMFolderSelectionButton *)w, mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_INBOX)); - g_signal_connect(w, "selected", G_CALLBACK(folder_selected), data); + g_signal_connect(w, "selected", G_CALLBACK(folder_selected), target); gtk_box_pack_start((GtkBox *)hbox, w, FALSE, TRUE, 6); - gtk_widget_show_all(hbox); + w = gtk_vbox_new(FALSE, 0); + gtk_box_pack_start((GtkBox *)w, hbox, FALSE, FALSE, 0); + gtk_widget_show_all(w); - /* Another weird-arsed shell api */ - *control = BONOBO_OBJREF(bonobo_control_new(hbox)); + return w; } static gboolean -support_format_fn(EvolutionImporter *importer, const char *filename, void *closure) +mbox_supported(EImport *ei, EImportTarget *target, EImportImporter *im) { char signature[6]; gboolean ret = FALSE; int fd, n; + EImportTargetURI *s; + + if (target->type != E_IMPORT_TARGET_URI) + return FALSE; - fd = open(filename, O_RDONLY); + s = (EImportTargetURI *)target; + if (s->uri_src == NULL) + return TRUE; + + if (strncmp(s->uri_src, "file:///", strlen("file:///")) != 0) + return FALSE; + + fd = open(s->uri_src + strlen("file://"), O_RDONLY); if (fd != -1) { n = read(fd, signature, 5); ret = n == 5 && memcmp(signature, "From ", 5) == 0; @@ -147,22 +124,6 @@ support_format_fn(EvolutionImporter *importer, const char *filename, void *closu } static void -importer_destroy_cb(void *data, GObject *object) -{ - MboxImporter *importer = data; - - if (importer->status_timeout_id) - g_source_remove(importer->status_timeout_id); - g_free(importer->status_what); - g_mutex_free(importer->status_lock); - - if (importer->dialog) - gtk_widget_destroy(importer->dialog); - - g_free(importer); -} - -static void mbox_status(CamelOperation *op, const char *what, int pc, void *data) { MboxImporter *importer = data; @@ -186,72 +147,74 @@ mbox_status_timeout(void *data) int pc; char *what; - if (!importer->status_what) - return TRUE; + if (importer->status_what) { + g_mutex_lock(importer->status_lock); + what = importer->status_what; + importer->status_what = NULL; + pc = importer->status_pc; + g_mutex_unlock(importer->status_lock); - g_mutex_lock(importer->status_lock); - what = importer->status_what; - importer->status_what = NULL; - pc = importer->status_pc; - g_mutex_unlock(importer->status_lock); + e_import_status(importer->import, (EImportTarget *)importer->target, what, pc); + } - gtk_progress_bar_set_fraction((GtkProgressBar *)importer->progressbar, (gfloat)(pc/100.0)); - gtk_progress_bar_set_text((GtkProgressBar *)importer->progressbar, what); - return TRUE; } static void -mbox_importer_response(GtkWidget *w, guint button, void *data) +mbox_import_done(void *data, CamelException *ex) { MboxImporter *importer = data; - if (button == GTK_RESPONSE_CANCEL - && importer->cancel) - camel_operation_cancel(importer->cancel); + g_source_remove(importer->status_timeout_id); + g_free(importer->status_what); + g_mutex_free(importer->status_lock); + camel_operation_unref(importer->cancel); + + e_import_complete(importer->import, importer->target); + g_free(importer); } -static gboolean -load_file_fn(EvolutionImporter *eimporter, const char *filename, void *data) +static void +mbox_import(EImport *ei, EImportTarget *target, EImportImporter *im) { - MboxImporter *importer = data; - char *utf8_filename; - - utf8_filename = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL); - importer->dialog = gtk_message_dialog_new(NULL, 0/*GTK_DIALOG_NO_SEPARATOR*/, - GTK_MESSAGE_INFO, GTK_BUTTONS_CANCEL, - _("Importing `%s'"), utf8_filename); - g_free (utf8_filename); - gtk_window_set_title (GTK_WINDOW (importer->dialog), _("Importing...")); - - importer->label = gtk_label_new (_("Please wait")); - importer->progressbar = gtk_progress_bar_new (); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (importer->dialog)->vbox), importer->label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (importer->dialog)->vbox), importer->progressbar, FALSE, FALSE, 0); - g_signal_connect(importer->dialog, "response", G_CALLBACK(mbox_importer_response), importer); - gtk_widget_show_all(importer->dialog); + MboxImporter *importer; + /* TODO: do we validate target? */ + + importer = g_malloc0(sizeof(*importer)); + g_datalist_set_data(&target->data, "mbox-data", importer); + importer->import = ei; + importer->target = target; + importer->status_lock = g_mutex_new(); importer->status_timeout_id = g_timeout_add(100, mbox_status_timeout, importer); importer->cancel = camel_operation_new(mbox_status, importer); - mail_msg_wait(mail_importer_import_mbox(filename, importer->uri, importer->cancel)); + mail_importer_import_mbox(((EImportTargetURI *)target)->uri_src+strlen("file://"), ((EImportTargetURI *)target)->uri_dest, importer->cancel, mbox_import_done, importer); +} - camel_operation_unref(importer->cancel); - g_source_remove(importer->status_timeout_id); - importer->status_timeout_id = 0; +static void +mbox_cancel(EImport *ei, EImportTarget *target, EImportImporter *im) +{ + MboxImporter *importer = g_datalist_get_data(&target->data, "mbox-data"); - return TRUE; + if (importer) + camel_operation_cancel(importer->cancel); } -BonoboObject * -mbox_importer_new(void) +static EImportImporter mbox_importer = { + E_IMPORT_TARGET_URI, + 0, + mbox_supported, + mbox_getwidget, + mbox_import, + mbox_cancel, +}; + +EImportImporter * +mbox_importer_peek(void) { - MboxImporter *mbox; - - mbox = g_new0 (MboxImporter, 1); - mbox->status_lock = g_mutex_new(); - mbox->ii = evolution_importer_new(create_control_fn, support_format_fn, load_file_fn, process_item_fn, NULL, mbox); - g_object_weak_ref(G_OBJECT(mbox->ii), importer_destroy_cb, mbox); - - return BONOBO_OBJECT (mbox->ii); + mbox_importer.name = _("Berkeley Mailbox (mbox)"); + mbox_importer.description = _("Importer Berkeley Mailbox format folders"); + + return &mbox_importer; } diff --git a/mail/importers/mail-importer.c b/mail/importers/mail-importer.c index 7bd2fffcc3..e1a7110be7 100644 --- a/mail/importers/mail-importer.c +++ b/mail/importers/mail-importer.c @@ -112,6 +112,7 @@ mail_importer_add_line (MailImporter *importer, struct _BonoboObject *mail_importer_factory_cb(struct _BonoboGenericFactory *factory, const char *iid, void *data) { +#if 0 if (strcmp(iid, ELM_INTELLIGENT_IMPORTER_IID) == 0) return elm_intelligent_importer_new(); else if (strcmp(iid, PINE_INTELLIGENT_IMPORTER_IID) == 0) @@ -122,7 +123,7 @@ struct _BonoboObject *mail_importer_factory_cb(struct _BonoboGenericFactory *fac return mbox_importer_new(); else if (strcmp(iid, OUTLOOK_IMPORTER_IID) == 0) return outlook_importer_new(); - +#endif return NULL; } @@ -132,6 +133,9 @@ struct _import_mbox_msg { char *path; char *uri; CamelOperation *cancel; + + void (*done)(void *data, CamelException *ex); + void *done_data; }; static char * @@ -281,6 +285,10 @@ fail1: static void import_mbox_done(struct _mail_msg *mm) { + struct _import_mbox_msg *m = (struct _import_mbox_msg *)mm; + + if (m->done) + m->done(m->done_data, &mm->ex); } static void @@ -302,7 +310,7 @@ static struct _mail_msg_op import_mbox_op = { }; int -mail_importer_import_mbox(const char *path, const char *folderuri, CamelOperation *cancel) +mail_importer_import_mbox(const char *path, const char *folderuri, CamelOperation *cancel, void (*done)(void *data, CamelException *), void *data) { struct _import_mbox_msg *m; int id; @@ -310,6 +318,8 @@ mail_importer_import_mbox(const char *path, const char *folderuri, CamelOperatio m = mail_msg_new(&import_mbox_op, NULL, sizeof (*m)); m->path = g_strdup(path); m->uri = g_strdup(folderuri); + m->done = done; + m->done_data = data; if (cancel) { m->cancel = cancel; camel_operation_ref(cancel); diff --git a/mail/importers/mail-importer.h b/mail/importers/mail-importer.h index 17eeea1fb9..5b8e5b666a 100644 --- a/mail/importers/mail-importer.h +++ b/mail/importers/mail-importer.h @@ -49,6 +49,12 @@ char *mail_importer_make_local_folder(const char *folderpath); struct _BonoboObject; struct _BonoboGenericFactory; struct _CamelOperation; +struct _CamelException; + +struct _EImportImporter *mbox_importer_peek(void); + +struct _EImportImporter *elm_importer_peek(void); +struct _EImportImporter *pine_importer_peek(void); #define ELM_INTELLIGENT_IMPORTER_IID "OAFIID:GNOME_Evolution_Mail_Elm_Intelligent_Importer:" BASE_VERSION #define PINE_INTELLIGENT_IMPORTER_IID "OAFIID:GNOME_Evolution_Mail_Pine_Intelligent_Importer:" BASE_VERSION @@ -74,7 +80,7 @@ struct _BonoboObject *mail_importer_factory_cb(struct _BonoboGenericFactory *fac #define MSG_FLAG_MARKED 0x0004 #define MSG_FLAG_EXPUNGED 0x0008 -int mail_importer_import_mbox(const char *path, const char *folderuri, struct _CamelOperation *cancel); +int mail_importer_import_mbox(const char *path, const char *folderuri, struct _CamelOperation *cancel, void (*done)(void *data, struct _CamelException *), void *data); void mail_importer_import_mbox_sync(const char *path, const char *folderuri, struct _CamelOperation *cancel); struct _MailImporterSpecial { diff --git a/mail/importers/pine-importer.c b/mail/importers/pine-importer.c index 6c9d0449f7..ea6c9b669b 100644 --- a/mail/importers/pine-importer.c +++ b/mail/importers/pine-importer.c @@ -33,140 +33,62 @@ #include <sys/stat.h> #include <unistd.h> #include <dirent.h> -#include <ctype.h> #include <string.h> #include <glib.h> +#include <glib/gi18n.h> +#include <gtk/gtkvbox.h> +#include <gtk/gtkcheckbutton.h> -#include <libgnomeui/gnome-messagebox.h> -#include <gtk/gtk.h> - -#include <gconf/gconf.h> #include <gconf/gconf-client.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-context.h> -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-moniker-util.h> +#include <libebook/e-book.h> +#include <libebook/e-destination.h> -#include <importer/evolution-intelligent-importer.h> -#include <importer/evolution-importer-client.h> -#include <importer/GNOME_Evolution_Importer.h> +#include <camel/camel-operation.h> #include "mail-importer.h" #include "mail/mail-mt.h" -#include "mail/mail-component.h" - -#include <libebook/e-book.h> -#include <libebook/e-destination.h> +#include "e-util/e-import.h" +#include "e-util/e-error.h" -#define KEY "pine-mail-imported" - -/*#define SUPER_IMPORTER_DEBUG*/ -#ifdef SUPER_IMPORTER_DEBUG #define d(x) x -#else -#define d(x) -#endif -typedef struct { - EvolutionIntelligentImporter *ii; +struct _pine_import_msg { + struct _mail_msg msg; + + EImport *import; + EImportTarget *target; GMutex *status_lock; char *status_what; int status_pc; int status_timeout_id; - CamelOperation *cancel; /* cancel/status port */ - - GtkWidget *mail; - GtkWidget *address; - - gboolean do_mail; - gboolean done_mail; - gboolean do_address; - gboolean done_address; - - /* GUI */ - GtkWidget *dialog; - GtkWidget *label; - GtkWidget *progressbar; -} PineImporter; - -static void -pine_importer_response(GtkWidget *w, guint button, void *data) -{ - PineImporter *importer = data; - - if (button == GTK_RESPONSE_CANCEL - && importer->cancel) - camel_operation_cancel(importer->cancel); -} - -static GtkWidget * -create_importer_gui (PineImporter *importer) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new(NULL, 0/*GTK_DIALOG_NO_SEPARATOR*/, - GTK_MESSAGE_INFO, GTK_BUTTONS_CANCEL, - _("Evolution is importing your old Pine data")); - gtk_window_set_title (GTK_WINDOW (dialog), _("Importing...")); - - importer->label = gtk_label_new (_("Please wait")); - importer->progressbar = gtk_progress_bar_new (); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), importer->label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), importer->progressbar, FALSE, FALSE, 0); - g_signal_connect(dialog, "response", G_CALLBACK(pine_importer_response), importer); - - return dialog; -} - -static void -pine_store_settings (PineImporter *importer) -{ - GConfClient *gconf = gconf_client_get_default (); - - gconf_client_set_bool (gconf, "/apps/evolution/importer/pine/mail", importer->done_mail, NULL); - gconf_client_set_bool (gconf, "/apps/evolution/importer/pine/address", importer->done_address, NULL); - g_object_unref(gconf); -} - -static void -pine_restore_settings (PineImporter *importer) -{ - GConfClient *gconf = gconf_client_get_default (); - - importer->done_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/pine/mail", NULL); - importer->done_address = gconf_client_get_bool (gconf, "/apps/evolution/importer/pine/address", NULL); - g_object_unref(gconf); -} + CamelOperation *status; +}; static gboolean -pine_can_import (EvolutionIntelligentImporter *ii, void *closure) +pine_supported(EImport *ei, EImportTarget *target, EImportImporter *im) { - PineImporter *importer = closure; + EImportTargetHome *s; char *maildir, *addrfile; - gboolean md_exists = FALSE, addr_exists = FALSE; + gboolean md_exists, addr_exists; struct stat st; - - maildir = g_build_filename(g_get_home_dir(), "mail", NULL); - md_exists = lstat(maildir, &st) == 0 && S_ISDIR(st.st_mode); - g_free (maildir); - importer->do_mail = md_exists && !importer->done_mail; - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (importer->mail), importer->do_mail); - gtk_widget_set_sensitive (importer->mail, md_exists); + if (target->type != E_IMPORT_TARGET_HOME) + return FALSE; + + s = (EImportTargetHome *)target; + + maildir = g_build_filename(s->homedir, "mail", NULL); + md_exists = lstat(maildir, &st) == 0 && S_ISDIR(st.st_mode); + g_free(maildir); - addrfile = g_build_filename(g_get_home_dir(), ".addressbook", NULL); + addrfile = g_build_filename(s->homedir, ".addressbook", NULL); addr_exists = lstat(addrfile, &st) == 0 && S_ISREG(st.st_mode); g_free (addrfile); - gtk_widget_set_sensitive (importer->address, addr_exists); - return md_exists || addr_exists; } @@ -243,7 +165,7 @@ import_contact(EBook *book, char *line) } static void -import_contacts(PineImporter *importer) +import_contacts(void) { ESource *primary; ESourceList *source_list; @@ -302,12 +224,6 @@ import_contacts(PineImporter *importer) g_object_unref(book); } -struct _pine_import_msg { - struct _mail_msg msg; - - PineImporter *importer; -}; - static char * pine_import_describe (struct _mail_msg *mm, int complete) { @@ -325,14 +241,14 @@ pine_import_import(struct _mail_msg *mm) { struct _pine_import_msg *m = (struct _pine_import_msg *) mm; - if (m->importer->do_address) - import_contacts(m->importer); + if (GPOINTER_TO_INT(g_datalist_get_data(&m->target->data, "pine-do-addr"))) + import_contacts(); - if (m->importer->do_mail) { + if (GPOINTER_TO_INT(g_datalist_get_data(&m->target->data, "pine-do-mail"))) { char *path; path = g_build_filename(g_get_home_dir(), "mail", NULL); - mail_importer_import_folders_sync(path, pine_special_folders, 0, m->importer->cancel); + mail_importer_import_folders_sync(path, pine_special_folders, 0, m->status); g_free(path); } } @@ -340,41 +256,44 @@ pine_import_import(struct _mail_msg *mm) static void pine_import_imported(struct _mail_msg *mm) { + struct _pine_import_msg *m = (struct _pine_import_msg *)mm; + + printf("importing complete\n"); + + if (!camel_exception_is_set(&mm->ex)) { + GConfClient *gconf; + + gconf = gconf_client_get_default(); + if (GPOINTER_TO_INT(g_datalist_get_data(&m->target->data, "pine-do-addr"))) + gconf_client_set_bool(gconf, "/apps/evolution/importer/pine/addr", TRUE, NULL); + if (GPOINTER_TO_INT(g_datalist_get_data(&m->target->data, "pine-do-mail"))) + gconf_client_set_bool(gconf, "/apps/evolution/importer/pine/mail", TRUE, NULL); + g_object_unref(gconf); + } + + e_import_complete(m->import, (EImportTarget *)m->target); } static void pine_import_free(struct _mail_msg *mm) { - /*struct _pine_import_msg *m = (struct _pine_import_msg *)mm;*/ -} + struct _pine_import_msg *m = (struct _pine_import_msg *)mm; -static struct _mail_msg_op pine_import_op = { - pine_import_describe, - pine_import_import, - pine_import_imported, - pine_import_free, -}; + camel_operation_unref(m->status); -static int -mail_importer_pine_import(PineImporter *importer) -{ - struct _pine_import_msg *m; - int id; + g_free(m->status_what); + g_mutex_free(m->status_lock); - m = mail_msg_new(&pine_import_op, NULL, sizeof (*m)); - m->importer = importer; - - id = m->msg.seq; - - e_thread_put(mail_thread_queued, (EMsg *) m); + g_source_remove(m->status_timeout_id); + m->status_timeout_id = 0; - return id; + g_object_unref(m->import); } static void pine_status(CamelOperation *op, const char *what, int pc, void *data) { - PineImporter *importer = data; + struct _pine_import_msg *importer = data; if (pc == CAMEL_OPERATION_START) pc = 0; @@ -391,125 +310,129 @@ pine_status(CamelOperation *op, const char *what, int pc, void *data) static gboolean pine_status_timeout(void *data) { - PineImporter *importer = data; + struct _pine_import_msg *importer = data; int pc; char *what; - if (!importer->status_what) - return TRUE; + if (importer->status_what) { + g_mutex_lock(importer->status_lock); + what = importer->status_what; + importer->status_what = NULL; + pc = importer->status_pc; + g_mutex_unlock(importer->status_lock); - g_mutex_lock(importer->status_lock); - what = importer->status_what; - importer->status_what = NULL; - pc = importer->status_pc; - g_mutex_unlock(importer->status_lock); + e_import_status(importer->import, (EImportTarget *)importer->target, what, pc); + } - gtk_progress_bar_set_fraction((GtkProgressBar *)importer->progressbar, (gfloat)(pc/100.0)); - gtk_progress_bar_set_text((GtkProgressBar *)importer->progressbar, what); - return TRUE; } -static void -pine_create_structure (EvolutionIntelligentImporter *ii, void *closure) -{ - PineImporter *importer = closure; - - if (importer->do_address || importer->do_mail) { - importer->dialog = create_importer_gui (importer); - gtk_widget_show_all (importer->dialog); - importer->status_timeout_id = g_timeout_add(100, pine_status_timeout, importer); - importer->cancel = camel_operation_new(pine_status, importer); - - mail_msg_wait(mail_importer_pine_import(importer)); +static struct _mail_msg_op pine_import_op = { + pine_import_describe, + pine_import_import, + pine_import_imported, + pine_import_free, +}; - camel_operation_unref(importer->cancel); - g_source_remove(importer->status_timeout_id); - importer->status_timeout_id = 0; +static int +mail_importer_pine_import(EImport *ei, EImportTarget *target) +{ + struct _pine_import_msg *m; + int id; - if (importer->do_address) - importer->done_address = TRUE; - if (importer->do_mail) - importer->done_mail = TRUE; - } + m = mail_msg_new(&pine_import_op, NULL, sizeof (*m)); + g_datalist_set_data(&target->data, "pine-msg", m); + m->import = ei; + g_object_ref(m->import); + m->target = target; + m->status_timeout_id = g_timeout_add(100, pine_status_timeout, m); + m->status_lock = g_mutex_new(); + m->status = camel_operation_new(pine_status, m); - pine_store_settings (importer); + id = m->msg.seq; + + e_thread_put(mail_thread_queued, (EMsg *)m); - bonobo_object_unref (BONOBO_OBJECT (ii)); + return id; } static void -pine_destroy_cb (PineImporter *importer, GtkObject *object) +checkbox_mail_toggle_cb(GtkToggleButton *tb, EImportTarget *target) { - pine_store_settings (importer); - - if (importer->status_timeout_id) - g_source_remove(importer->status_timeout_id); - g_free(importer->status_what); - g_mutex_free(importer->status_lock); - - if (importer->dialog) - gtk_widget_destroy(importer->dialog); - - g_free(importer); + g_datalist_set_data(&target->data, "pine-do-mail", GINT_TO_POINTER(gtk_toggle_button_get_active(tb))); } -/* Fun inity stuff */ - -/* Fun control stuff */ static void -checkbox_toggle_cb(GtkToggleButton *tb, gboolean *do_item) +checkbox_addr_toggle_cb(GtkToggleButton *tb, EImportTarget *target) { - *do_item = gtk_toggle_button_get_active(tb); + g_datalist_set_data(&target->data, "pine-do-addr", GINT_TO_POINTER(gtk_toggle_button_get_active(tb))); } -static BonoboControl * -create_checkboxes_control (PineImporter *importer) +static GtkWidget * +pine_getwidget(EImport *ei, EImportTarget *target, EImportImporter *im) { - GtkWidget *hbox; - BonoboControl *control; + GtkWidget *box, *w; + GConfClient *gconf; + gboolean done_mail, done_addr; + + gconf = gconf_client_get_default (); + done_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/pine/mail", NULL); + done_addr = gconf_client_get_bool (gconf, "/apps/evolution/importer/pine/address", NULL); + g_object_unref(gconf); + + g_datalist_set_data(&target->data, "pine-do-mail", GINT_TO_POINTER(!done_mail)); + g_datalist_set_data(&target->data, "pine-do-addr", GINT_TO_POINTER(!done_addr)); + + box = gtk_vbox_new(FALSE, 2); + + w = gtk_check_button_new_with_label(_("Mail")); + gtk_toggle_button_set_active((GtkToggleButton *)w, !done_mail); + g_signal_connect(w, "toggled", G_CALLBACK(checkbox_mail_toggle_cb), target); + gtk_box_pack_start((GtkBox *)box, w, FALSE, FALSE, 0); - hbox = gtk_hbox_new (FALSE, 2); + w = gtk_check_button_new_with_label(_("Addressbook")); + gtk_toggle_button_set_active((GtkToggleButton *)w, !done_addr); + g_signal_connect(w, "toggled", G_CALLBACK(checkbox_addr_toggle_cb), target); + gtk_box_pack_start((GtkBox *)box, w, FALSE, FALSE, 0); - importer->mail = gtk_check_button_new_with_label (_("Mail")); - gtk_signal_connect (GTK_OBJECT (importer->mail), "toggled", - GTK_SIGNAL_FUNC (checkbox_toggle_cb), - &importer->do_mail); + gtk_widget_show_all(box); - importer->address = gtk_check_button_new_with_label (_("Addressbook")); - gtk_signal_connect (GTK_OBJECT (importer->address), "toggled", - GTK_SIGNAL_FUNC (checkbox_toggle_cb), - &importer->do_address); + return box; +} + +static void +pine_import(EImport *ei, EImportTarget *target, EImportImporter *im) +{ + if (GPOINTER_TO_INT(g_datalist_get_data(&target->data, "pine-do-mail")) + || GPOINTER_TO_INT(g_datalist_get_data(&target->data, "pine-do-addr"))) + mail_importer_pine_import(ei, target); + else + e_import_complete(ei, target); +} - gtk_box_pack_start (GTK_BOX (hbox), importer->mail, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), importer->address, FALSE, FALSE, 0); +static void +pine_cancel(EImport *ei, EImportTarget *target, EImportImporter *im) +{ + struct _pine_import_msg *m = g_datalist_get_data(&target->data, "pine-msg"); - gtk_widget_show_all (hbox); - control = bonobo_control_new (hbox); - return control; + if (m) + camel_operation_cancel(m->status); } -BonoboObject * -pine_intelligent_importer_new(void) +static EImportImporter pine_importer = { + E_IMPORT_TARGET_HOME, + 0, + pine_supported, + pine_getwidget, + pine_import, + pine_cancel, +}; + +EImportImporter * +pine_importer_peek(void) { - EvolutionIntelligentImporter *importer; - BonoboControl *control; - PineImporter *pine; - char *message = N_("Evolution has found Pine mail files.\n" - "Would you like to import them into Evolution?"); - - pine = g_new0 (PineImporter, 1); - pine->status_lock = g_mutex_new(); - pine_restore_settings(pine); - importer = evolution_intelligent_importer_new (pine_can_import, - pine_create_structure, - _("Pine"), - _(message), pine); - g_object_weak_ref((GObject *)importer, (GWeakNotify)pine_destroy_cb, pine); - pine->ii = importer; - - control = create_checkboxes_control(pine); - bonobo_object_add_interface(BONOBO_OBJECT(importer), BONOBO_OBJECT(control)); - - return BONOBO_OBJECT(importer); + pine_importer.name = _("Evolution Pine importer"); + pine_importer.description = _("Import mail from Pine."); + + return &pine_importer; } diff --git a/mail/mail-component-factory.c b/mail/mail-component-factory.c index cb0b10a6d0..c430525563 100644 --- a/mail/mail-component-factory.c +++ b/mail/mail-component-factory.c @@ -44,6 +44,7 @@ #include "em-format-html-display.h" #include "importers/mail-importer.h" +#include "e-util/e-import.h" #include <bonobo-activation/bonobo-activation.h> #include <bonobo/bonobo-shlib-factory.h> @@ -89,6 +90,8 @@ make_factory (PortableServer_POA poa, const char *iid, gpointer impl_ptr, CORBA_ static int init = 0; if (!init) { + EImportClass *klass; + init = 1; mail_config_init(); @@ -106,6 +109,11 @@ make_factory (PortableServer_POA poa, const char *iid, gpointer impl_ptr, CORBA_ e_plugin_hook_register_type(em_format_hook_get_type()); e_plugin_hook_register_type(em_event_hook_get_type()); e_plugin_hook_register_type(em_junk_hook_get_type()); + + klass = g_type_class_ref(e_import_get_type()); + e_import_class_add_importer(klass, mbox_importer_peek(), NULL, NULL); + e_import_class_add_importer(klass, elm_importer_peek(), NULL, NULL); + e_import_class_add_importer(klass, pine_importer_peek(), NULL, NULL); } return bonobo_shlib_factory_std (FACTORY_ID, poa, impl_ptr, factory, NULL, ev); |