aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--addressbook/ChangeLog6
-rw-r--r--addressbook/backend/ebook/Makefile.am4
-rw-r--r--addressbook/backend/ebook/evolution-gnomecard-importer.c4
-rw-r--r--configure.in1
-rw-r--r--mail/ChangeLog16
-rw-r--r--mail/GNOME_Evolution_Mail.oaf.in52
-rw-r--r--mail/Makefile.am10
-rw-r--r--mail/component-factory.c3
-rw-r--r--mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in29
-rw-r--r--mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in21
-rw-r--r--mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in29
-rw-r--r--mail/importers/Makefile.am29
-rw-r--r--mail/importers/evolution-mbox-importer.c233
-rw-r--r--mail/importers/evolution-outlook-importer.c307
-rw-r--r--mail/importers/netscape-importer.c465
-rw-r--r--mail/mail-importer.c144
-rw-r--r--mail/mail-importer.h6
-rw-r--r--mail/netscape-importer.c277
-rw-r--r--shell/ChangeLog38
-rw-r--r--shell/Evolution-Storage.idl5
-rw-r--r--shell/e-local-storage.c98
-rw-r--r--shell/e-shell.c4
-rw-r--r--shell/evolution-storage.c38
-rw-r--r--shell/importer/GNOME_Evolution_Importer.idl10
-rw-r--r--shell/importer/Makefile.am3
-rw-r--r--shell/importer/evolution-importer-listener.c52
-rw-r--r--shell/importer/evolution-importer-listener.h14
-rw-r--r--shell/importer/evolution-importer.c112
-rw-r--r--shell/importer/evolution-importer.h13
-rw-r--r--shell/importer/evolution-intelligent-importer.c198
-rw-r--r--shell/importer/evolution-intelligent-importer.h74
-rw-r--r--shell/importer/intelligent.c174
-rw-r--r--shell/importer/intelligent.h0
34 files changed, 1944 insertions, 529 deletions
diff --git a/ChangeLog b/ChangeLog
index af54db670a..eb7279ac06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2001-03-13 Iain Holmes <iain@ximian.com>
+
+ * configure.in: Added the mail/importers dir.
+
2001-03-12 Jeffrey Stedfast <fejj@ximian.com>
* README: Rearranged some of the dependencies to try to get them
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 6aafed1610..45873b7cb4 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,9 @@
+2001-03-13 Iain Holmes <iain@ximian.com>
+
+ * backend/ebook/Makefile.am: Change the importer includes around a bit.
+
+ * backend/ebook/evolution-gnomecard-importer.c: Correctly add the includes.
+
2001-03-09 JP Rosevear <jpr@ximian.com>
* conduit/Makefile.am: PISOCK_INCLUDEDIR has become
diff --git a/addressbook/backend/ebook/Makefile.am b/addressbook/backend/ebook/Makefile.am
index fbba0c98d0..7abee848e9 100644
--- a/addressbook/backend/ebook/Makefile.am
+++ b/addressbook/backend/ebook/Makefile.am
@@ -30,8 +30,8 @@ INCLUDES = \
-I$(top_srcdir)/addressbook/ename \
-I$(top_builddir)/addressbook/backend \
-I$(top_builddir)/addressbook/ename \
- -I$(top_builddir)/shell/importer \
- -I$(top_srcdir)/shell/importer \
+ -I$(top_builddir)/shell \
+ -I$(top_srcdir)/shell \
$(BONOBO_GNOME_CFLAGS) \
$(EXTRA_GNOME_CFLAGS)
diff --git a/addressbook/backend/ebook/evolution-gnomecard-importer.c b/addressbook/backend/ebook/evolution-gnomecard-importer.c
index aac268e09d..508f1fe16a 100644
--- a/addressbook/backend/ebook/evolution-gnomecard-importer.c
+++ b/addressbook/backend/ebook/evolution-gnomecard-importer.c
@@ -7,8 +7,8 @@
#include <e-book.h>
-#include <evolution-importer.h>
-#include <GNOME_Evolution_Importer.h>
+#include <importer/evolution-importer.h>
+#include <importer/GNOME_Evolution_Importer.h>
#define COMPONENT_FACTORY_IID "OAFIID:GNOME_Evolution_Addressbook_GnomeCard_ImporterFactory"
diff --git a/configure.in b/configure.in
index 5e2d719671..774d3cdd9d 100644
--- a/configure.in
+++ b/configure.in
@@ -799,6 +799,7 @@ addressbook/gui/component/select-names/Makefile
shell/Makefile
shell/glade/Makefile
shell/importer/Makefile
+mail/importers/Makefile
mail/Makefile
data/Makefile
libversit/Makefile
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 130b5df97e..d2b35cfbf7 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,19 @@
+2001-03-13 Iain Holmes <iain@ximian.com>
+
+ * Makefile.am: Removed the importers and created a subdirectory for them to
+ live happily as plugins.
+
+ * mail-importer.c (mail_importer_create_folder): Modified the function to take
+ a BonoboListener for the callback.
+ (get_importer_list): Get a list of importer plugins.
+ (free_importer_list): Free the list of plugins.
+ (mail_importer_init): Initalise the list of plugins.
+ (main_importer_uninit): Unload the modules.
+
+ * GNOME_Evolution_Mail.oaf.in: Remove the oaf_server entries for the importers.
+
+ * importers/*: Copy the importers in here.
+
2001-03-12 Jeffrey Stedfast <fejj@ximian.com>
* mail-config.c (mail_config_write): Make the transport save
diff --git a/mail/GNOME_Evolution_Mail.oaf.in b/mail/GNOME_Evolution_Mail.oaf.in
index 5febb74724..a30155258e 100644
--- a/mail/GNOME_Evolution_Mail.oaf.in
+++ b/mail/GNOME_Evolution_Mail.oaf.in
@@ -102,56 +102,4 @@
_value="Evolution mail composer."/>
</oaf_server>
-<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"
- type="exe"
- location="evolution-mail">
-
- <oaf_attribute name="repo_ids" type="stringv">
- <item value="IDL:GNOME/ObjectFactory:1.0"/>
- </oaf_attribute>
-
- <oaf_attribute name="description" type="string"
- _value="Factory to import Outlook Express 4 mails into Evolution"/>
-</oaf_server>
-
-<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_Importer"
- type="factory"
- location="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory">
-
- <oaf_attribute name="repo_ids" type="stringv">
- <item value="IDL:GNOME/Evolution/Importer:1.0"/>
- </oaf_attribute>
-
- <oaf_attribute name="evolution:menu-name" type="string"
- value="Outlook Express 4 (.mbx)"/>
- <oaf_attribute name="description" type="string"
- _value="Imports Outlook Express 4 files into Evolution"/>
-</oaf_server>
-
-<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory"
- type="exe"
- location="evolution-mail">
-
- <oaf_attribute name="repo_ids" type="stringv">
- <item value="IDL:GNOME/ObjectFactory:1.0"/>
- </oaf_attribute>
-
- <oaf_attribute name="description" type="string"
- _value="Factory to import mbox into Evolution"/>
-</oaf_server>
-
-<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_Importer"
- type="factory"
- location="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory">
-
- <oaf_attribute name="repo_ids" type="stringv">
- <item value="IDL:GNOME/Evolution/Importer:1.0"/>
- </oaf_attribute>
-
- <oaf_attribute name="evolution:menu-name" type="string"
- value="MBox (mbox)"/>
- <oaf_attribute name="description" type="string"
- _value="Imports mbox files into Evolution"/>
-</oaf_server>
-
</oaf_info>
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 66eb1b858d..84591e5b88 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -1,8 +1,11 @@
+SUBDIRS = importers
+
bin_PROGRAMS = evolution-mail
noinst_PROGRAMS = test-mail #test-thread
providerdir = $(libdir)/evolution/camel-providers/$(VERSION)
+importerdir = $(libdir)/evolution/evolution-mail-importers/$(VERSION)
INCLUDES = \
-I$(top_srcdir)/widgets \
@@ -31,6 +34,7 @@ INCLUDES = \
-DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
-DEVOLUTION_DATADIR=\""$(datadir)"\" \
-DCAMEL_PROVIDERDIR=\""$(providerdir)"\" \
+ -DMAIL_IMPORTERSDIR=\""$(importerdir)"\" \
-DG_LOG_DOMAIN=\"evolution-mail\"
EVOLUTION_MAIL_CORBA_GENERATED = \
@@ -96,11 +100,7 @@ evolution_mail_SOURCES = \
mail-session.h \
subscribe-dialog.c \
subscribe-dialog.h \
- mail.h \
- evolution-outlook-importer.c \
- evolution-outlook-importer.h \
- evolution-mbox-importer.c \
- evolution-mbox-importer.h
+ mail.h
evolution_mail_LDADD = \
$(top_builddir)/shell/libeshell.a \
diff --git a/mail/component-factory.c b/mail/component-factory.c
index 93e8ada015..c1ed7119f4 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -145,6 +145,9 @@ create_folder (EvolutionShellComponent *shell_component,
if (!strcmp (type, "mail")) {
uri = g_strdup_printf ("mbox://%s", physical_uri);
mail_create_folder (uri, do_create_folder, CORBA_Object_duplicate (listener, &ev));
+ GNOME_Evolution_ShellComponentListener_notifyResult (listener,
+ GNOME_Evolution_ShellComponentListener_OK, &ev);
+
} else {
GNOME_Evolution_ShellComponentListener_notifyResult (
listener, GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, &ev);
diff --git a/mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in b/mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in
new file mode 100644
index 0000000000..b9da9ce3c8
--- /dev/null
+++ b/mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in
@@ -0,0 +1,29 @@
+<oaf_info>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory"
+ type="exe"
+ location="evolution-mail">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/ObjectFactory:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="description" type="string"
+ _value="Factory to import mbox into Evolution"/>
+</oaf_server>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_Importer"
+ type="factory"
+ location="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/Evolution/Importer:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="evolution:menu-name" type="string"
+ value="MBox (mbox)"/>
+ <oaf_attribute name="description" type="string"
+ _value="Imports mbox files into Evolution"/>
+</oaf_server>
+
+</oaf_info>
diff --git a/mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in b/mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in
new file mode 100644
index 0000000000..db3f820d7b
--- /dev/null
+++ b/mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in
@@ -0,0 +1,21 @@
+<oaf_info>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer_Factory"
+ type="exe"
+ location="evolution-mail">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/ObjectFactory:1.0"/>
+ </oaf_attribute>
+</oaf_server>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer"
+ type="factory"
+ location="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer_Factory">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/Evolution/IntelligentImporter:1.0"/>
+ </oaf_attribute>
+
+</oaf_server>
+</oaf_info>
diff --git a/mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in b/mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in
new file mode 100644
index 0000000000..66317e3d7a
--- /dev/null
+++ b/mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in
@@ -0,0 +1,29 @@
+<oaf_info>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"
+ type="exe"
+ location="evolution-mail">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/ObjectFactory:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="description" type="string"
+ _value="Factory to import Outlook Express 4 mails into Evolution"/>
+</oaf_server>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_Importer"
+ type="factory"
+ location="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/Evolution/Importer:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="evolution:menu-name" type="string"
+ value="Outlook Express 4 (.mbx)"/>
+ <oaf_attribute name="description" type="string"
+ _value="Imports Outlook Express 4 files into Evolution"/>
+</oaf_server>
+
+</oaf_info>
diff --git a/mail/importers/Makefile.am b/mail/importers/Makefile.am
new file mode 100644
index 0000000000..aaefed7672
--- /dev/null
+++ b/mail/importers/Makefile.am
@@ -0,0 +1,29 @@
+importersdir = $(pkglibdir)/evolution-mail-importers/$(VERSION)
+
+importers_LTLIBRARIES = liboutlook.la libmbox.la libiinetscape.la
+
+INCLUDES = -I.. \
+ -I$(srcdir)/.. \
+ -I$(top_srcdir)/shell \
+ -I$(includedir) \
+ $(GNOME_INCLUDEDIR) \
+ -DG_LOG_DOMAIN=\"evolution-mail-importer\"
+
+liboutlook_la_SOURCES = \
+ evolution-outlook-importer.c
+liboutlook_la_LDFLAGS = -version-info 0:0:0
+
+libmbox_la_SOURCES = evolution-mbox-importer.c
+libmbox_la_LDFLAGS = -version-info 0:0:0
+
+libiinetscape_la_SOURCES = netscape-importer.c
+libiinetscape_la_LDFLAGS = -version-info 0:0:0
+
+oafdir = $(datadir)/oaf
+oaf_in_files = GNOME_Evolution_Mail_Mbox_Importer.oaf.in \
+ GNOME_Evolution_Mail_Outlook_Importer.oaf.in \
+ GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in
+
+oaf_DATA = $(oaf_in_files:.oaf.in=.oaf)
+
+@XML_I18N_MERGE_OAF_RULE@
diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c
new file mode 100644
index 0000000000..241055cb10
--- /dev/null
+++ b/mail/importers/evolution-mbox-importer.c
@@ -0,0 +1,233 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* evolution-mbox-importer.c
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-generic-factory.h>
+
+#include <stdio.h>
+
+#include <importer/evolution-importer.h>
+#include <importer/GNOME_Evolution_Importer.h>
+
+#include "mail-importer.h"
+
+#include <camel/camel-exception.h>
+#include <camel/camel-mime-parser.h>
+#include <camel/camel-mime-part.h>
+
+#define MBOX_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory"
+
+typedef struct {
+ MailImporter importer; /* Parent */
+
+ char *filename;
+ int num;
+ CamelMimeParser *mp;
+} MboxImporter;
+
+
+/* EvolutionImporter methods */
+
+static void
+process_item_fn (EvolutionImporter *eimporter,
+ CORBA_Object listener,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ MboxImporter *mbi = (MboxImporter *) closure;
+ MailImporter *importer = (MailImporter *) mbi;
+ gboolean done = FALSE;
+ CamelException *ex;
+
+ ex = camel_exception_new ();
+ if (camel_mime_parser_step (mbi->mp, 0, 0) == HSCAN_FROM) {
+ /* Import the next message */
+ CamelMimeMessage *msg;
+ CamelMessageInfo *info;
+
+ msg = camel_mime_message_new ();
+ if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg),
+ mbi->mp) == -1) {
+ g_warning ("Failed message %d", mbi->num);
+ camel_object_unref (CAMEL_OBJECT (msg));
+ done = TRUE;
+ }
+
+ /* write the mesg */
+ info = g_new0 (CamelMessageInfo, 1);
+ camel_folder_append_message (importer->folder, msg, info, ex);
+ g_free (info);
+ camel_object_unref (CAMEL_OBJECT (msg));
+ if (camel_exception_is_set (ex)) {
+ g_warning ("Failed message %d", mbi->num);
+ done = TRUE;
+ }
+ } else {
+ /* all messages have now been imported */
+ camel_folder_sync (importer->folder, FALSE, ex);
+ camel_folder_thaw (importer->folder);
+ importer->frozen = FALSE;
+ done = TRUE;
+ }
+
+ camel_exception_free (ex);
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_OK,
+ !done, ev);
+ return;
+}
+
+static gboolean
+support_format_fn (EvolutionImporter *importer,
+ const char *filename,
+ void *closure)
+{
+ char signature[6];
+ gboolean ret = FALSE;
+ int fd, n;
+
+ fd = open (filename, O_RDONLY);
+ if (fd == -1)
+ return FALSE;
+
+ n = read (fd, signature, 5);
+ if (n > 0) {
+ signature[n] = '\0';
+ if (!g_strncasecmp (signature, "From ", 5))
+ ret = TRUE;
+ }
+
+ close (fd);
+
+ return ret;
+}
+
+static void
+importer_destroy_cb (GtkObject *object,
+ MboxImporter *mbi)
+{
+ MailImporter *importer;
+
+ importer = (MailImporter *) mbi;
+ if (importer->frozen) {
+ camel_folder_sync (importer->folder, FALSE, NULL);
+ camel_folder_thaw (importer->folder);
+ }
+
+ if (importer->folder)
+ camel_object_unref (CAMEL_OBJECT (importer->folder));
+
+ g_free (mbi->filename);
+ if (mbi->mp)
+ camel_object_unref (CAMEL_OBJECT (mbi->mp));
+
+ g_free (mbi);
+}
+
+static gboolean
+load_file_fn (EvolutionImporter *eimporter,
+ const char *filename,
+ void *closure)
+{
+ MboxImporter *mbi;
+ MailImporter *importer;
+ int fd;
+
+ mbi = (MboxImporter *) closure;
+ importer = (MailImporter *) mbi;
+
+ mbi->filename = g_strdup (filename);
+
+ fd = open (filename, O_RDONLY);
+ if (fd == -1) {
+ g_warning ("Cannot open file");
+ return FALSE;
+ }
+
+ mbi->mp = camel_mime_parser_new ();
+ camel_mime_parser_scan_from (mbi->mp, TRUE);
+ if (camel_mime_parser_init_with_fd (mbi->mp, fd) == -1) {
+ g_warning ("Unable to process spool folder");
+ goto fail;
+ }
+
+ importer->mstream = NULL;
+ importer->folder = mail_tool_get_local_inbox (NULL);
+
+ if (importer->folder == NULL){
+ g_print ("Bad folder\n");
+ goto fail;
+ }
+
+ camel_folder_freeze (importer->folder);
+ importer->frozen = TRUE;
+
+ g_warning ("Okay, so everything is now ready to import that mbox file!");
+ return TRUE;
+
+ fail:
+ camel_object_unref (CAMEL_OBJECT (mbi->mp));
+ mbi->mp = NULL;
+
+ return FALSE;
+}
+
+static BonoboObject *
+mbox_factory_fn (BonoboGenericFactory *_factory,
+ void *closure)
+{
+ EvolutionImporter *importer;
+ MboxImporter *mbox;
+
+ mbox = g_new0 (MboxImporter, 1);
+ importer = evolution_importer_new (support_format_fn, load_file_fn,
+ process_item_fn, NULL, mbox);
+ gtk_signal_connect (GTK_OBJECT (importer), "destroy",
+ GTK_SIGNAL_FUNC (importer_destroy_cb), mbox);
+
+ return BONOBO_OBJECT (importer);
+}
+
+/* Entry point */
+void
+mail_importer_module_init (void)
+{
+ static gboolean initialised = FALSE;
+ BonoboGenericFactory *factory;
+
+ if (initialised == TRUE)
+ return;
+
+ factory = bonobo_generic_factory_new (MBOX_FACTORY_IID,
+ mbox_factory_fn, NULL);
+
+ if (factory == NULL)
+ g_warning ("Could not initialise Outlook importer factory.");
+
+ initialised = TRUE;
+}
+
diff --git a/mail/importers/evolution-outlook-importer.c b/mail/importers/evolution-outlook-importer.c
new file mode 100644
index 0000000000..a92f5086ab
--- /dev/null
+++ b/mail/importers/evolution-outlook-importer.c
@@ -0,0 +1,307 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* evolution-outlook-importer.c
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-generic-factory.h>
+
+#include <stdio.h>
+
+#include <importer/evolution-importer.h>
+#include <importer/GNOME_Evolution_Importer.h>
+
+#include "mail-importer.h"
+
+#include <camel/camel-exception.h>
+
+#define OUTLOOK_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"
+
+extern char *evolution_dir;
+typedef struct {
+ MailImporter importer;
+
+ char *filename;
+ gboolean oe4; /* Is file OE4 or not? */
+ FILE *handle;
+ long pos;
+ off_t size;
+
+ gboolean busy;
+} OutlookImporter;
+
+struct oe_msg_segmentheader {
+ int self;
+ int increase;
+ int include;
+ int next;
+ int usenet;
+};
+
+typedef struct oe_msg_segmentheader oe_msg_segmentheader;
+
+
+/* EvolutionImporter methods */
+
+/* Based on code from liboe 0.92 (STABLE)
+ Copyright (C) 2000 Stephan B. Nedregård (stephan@micropop.com)
+ Modified 2001 Iain Holmes <iain@ximian.com>
+ Copyright (C) 2001 Ximian, Inc. */
+
+static void
+process_item_fn (EvolutionImporter *eimporter,
+ CORBA_Object listener,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ OutlookImporter *oli = (OutlookImporter *) closure;
+ MailImporter *importer = (MailImporter *) oli;
+ oe_msg_segmentheader *header;
+ gboolean more = TRUE;
+ char *cb, *sfull, *s;
+ long end_pos = 0;
+ int i;
+
+ if (oli->busy == TRUE) {
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_BUSY,
+ more, ev);
+ return;
+ }
+
+ oli->busy = TRUE;
+ header = g_new (oe_msg_segmentheader, 1);
+ fread (header, 16, 1, oli->handle);
+
+ /* Write a From line */
+ mail_importer_add_line (importer,
+ "From evolution-outlook-importer", FALSE);
+ end_pos = oli->pos + header->include;
+ if (end_pos >= oli->size) {
+ end_pos = oli->size;
+ more = FALSE;
+ }
+
+ oli->pos += 4;
+
+ cb = g_new (char, 4);
+ sfull = g_new (char, 65536);
+ s = sfull;
+
+ while (oli->pos < end_pos) {
+ fread (cb, 1, 4, oli->handle);
+ for (i = 0; i < 4; i++, oli->pos++) {
+ if (*(cb + i ) != 0x0d) {
+ *s++ = *(cb + i);
+
+ if (*(cb + i) == 0x0a) {
+ *s = '\0';
+ mail_importer_add_line (importer,
+ sfull, FALSE);
+ s = sfull;
+ }
+ }
+ }
+ }
+
+ if (s != sfull) {
+ *s = '\0';
+ mail_importer_add_line (importer, sfull, FALSE);
+ s = sfull;
+ }
+
+ mail_importer_add_line (importer, "\n", TRUE);
+
+ oli->pos = end_pos;
+ fseek (oli->handle, oli->pos, SEEK_SET);
+
+ g_free (header);
+ g_free (sfull);
+ g_free (cb);
+
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_OK,
+ more, ev);
+ if (more == FALSE) {
+ CamelException *ex;
+
+ ex = camel_exception_new ();
+ camel_folder_thaw (importer->folder);
+ camel_folder_sync (importer->folder, FALSE, ex);
+ camel_exception_free (ex);
+ fclose (oli->handle);
+ oli->handle = NULL;
+ }
+
+ oli->busy = FALSE;
+ return;
+}
+
+
+/* EvolutionImporterFactory methods */
+
+static gboolean
+support_format_fn (EvolutionImporter *importer,
+ const char *filename,
+ void *closure)
+{
+ FILE *handle;
+ int signature[4];
+
+ /* Outlook Express sniffer.
+ Taken from liboe 0.92 (STABLE)
+ Copyright (C) 2000 Stephan B. Nedregård (stephan@micropop.com) */
+
+ handle = fopen (filename, "rb");
+ if (handle == NULL)
+ return FALSE; /* Can't open file: Can't support it :) */
+
+ /* SIGNATURE */
+ fread (&signature, 16, 1, handle);
+ if ((signature[0]!=0xFE12ADCF) || /* OE 5 & OE 5 BETA SIGNATURE */
+ (signature[1]!=0x6F74FDC5) ||
+ (signature[2]!=0x11D1E366) ||
+ (signature[3]!=0xC0004E9A)) {
+ if ((signature[0]==0x36464D4A) &&
+ (signature[1]==0x00010003)) /* OE4 SIGNATURE */ {
+ fclose (handle);
+ return TRUE; /* OE 4 */
+ }
+ fclose (handle);
+ return FALSE; /* Not Outlook 4 or 5 */
+ }
+
+ fclose (handle);
+ return FALSE; /* Can't handle OE 5 yet */
+}
+
+static void
+importer_destroy_cb (GtkObject *object,
+ OutlookImporter *oli)
+{
+ MailImporter *importer;
+
+ importer = (MailImporter *) oli;
+ if (importer->folder)
+ camel_object_unref (CAMEL_OBJECT (importer->folder));
+
+ g_free (oli->filename);
+ if (oli->handle)
+ fclose (oli->handle);
+
+ g_free (oli);
+}
+
+static gboolean
+load_file_fn (EvolutionImporter *eimporter,
+ const char *filename,
+ void *closure)
+{
+ OutlookImporter *oli;
+ MailImporter *importer;
+ struct stat buf;
+ long pos = 0x54;
+
+ oli = (OutlookImporter *) closure;
+ importer = (MailImporter *) oli;
+
+ oli->filename = g_strdup (filename);
+ /* Will return TRUE if oe4 format */
+ oli->oe4 = support_format_fn (NULL, filename, NULL);
+ if (oli->oe4 == FALSE) {
+ g_warning ("Not OE4 format");
+ return FALSE;
+ }
+
+ oli->handle = fopen (filename, "rb");
+ if (oli->handle == NULL) {
+ g_warning ("Cannot open the file");
+ return FALSE;
+ }
+
+ /* Get size of file */
+ if (stat (filename, &buf) == -1) {
+ g_warning ("Cannot stat file");
+ return FALSE;
+ }
+
+ oli->size = buf.st_size;
+
+ /* Set the fposition to the begining */
+ fseek (oli->handle, pos, SEEK_SET);
+ oli->pos = pos;
+
+ importer->mstream = NULL;
+
+ importer->folder = mail_tool_get_local_inbox (NULL);
+
+ if (importer->folder == NULL){
+ g_warning ("Bad folder");
+ return FALSE;
+ }
+
+ camel_folder_freeze (importer->folder);
+ oli->busy = FALSE;
+ return TRUE;
+}
+
+static BonoboObject *
+outlook_factory_fn (BonoboGenericFactory *_factory,
+ void *closure)
+{
+ EvolutionImporter *importer;
+ OutlookImporter *oli;
+
+ oli = g_new0 (OutlookImporter, 1);
+
+ importer = evolution_importer_new (support_format_fn, load_file_fn,
+ process_item_fn, NULL, oli);
+ gtk_signal_connect (GTK_OBJECT (importer), "destroy",
+ GTK_SIGNAL_FUNC (importer_destroy_cb), oli);
+
+ return BONOBO_OBJECT (importer);
+}
+
+/* Entry point */
+void
+mail_importer_module_init (void)
+{
+ static gboolean initialised = FALSE;
+ BonoboGenericFactory *factory;
+
+ if (initialised == TRUE)
+ return;
+
+ factory = bonobo_generic_factory_new (OUTLOOK_FACTORY_IID,
+ outlook_factory_fn, NULL);
+
+ if (factory == NULL)
+ g_warning ("Could not initialise Outlook importer factory.");
+
+ initialised = TRUE;
+}
+
+
diff --git a/mail/importers/netscape-importer.c b/mail/importers/netscape-importer.c
new file mode 100644
index 0000000000..281d033536
--- /dev/null
+++ b/mail/importers/netscape-importer.c
@@ -0,0 +1,465 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* netscape-importer.c
+ *
+ * Authors:
+ * Iain Holmes <iain@ximian.com>
+ *
+ * Copyright 2001 Ximian, Inc. (http://www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#include <glib.h>
+#include <gnome.h>
+
+#include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-generic-factory.h>
+#include <camel/camel-mime-message.h>
+#include <camel/camel-mime-part.h>
+#include <camel/camel-exception.h>
+
+#include <importer/evolution-intelligent-importer.h>
+#include <importer/GNOME_Evolution_Importer.h>
+#include "mail-importer.h"
+#include "mail-tools.h"
+
+static char *nsmail_dir = NULL;
+
+extern char *evolution_dir;
+
+#define NETSCAPE_INTELLIGENT_IMPORTER_IID "OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer_Factory"
+#define KEY "netscape-mail-imported"
+
+/*#define SUPER_IMPORTER_DEBUG*/
+#ifdef SUPER_IMPORTER_DEBUG
+#define d(x) x
+#else
+#define d(x)
+#endif
+
+typedef struct {
+ MailImporter importer;
+ GList *dir_list;
+
+ int num;
+ CamelMimeParser *mp;
+ BonoboListener *listener;
+} NetscapeImporter;
+
+static gboolean
+netscape_import_mbox (CamelFolder *folder,
+ const char *filename)
+{
+ gboolean done = FALSE;
+ CamelException *ex;
+ CamelMimeParser *mp;
+ int fd, n = 0;
+
+ fd = open (filename, O_RDONLY);
+ if (fd == -1) {
+ g_warning ("Cannot open %s", filename);
+ return FALSE;
+ }
+
+ camel_object_ref (CAMEL_OBJECT (folder));
+ camel_folder_freeze (folder);
+
+ ex = camel_exception_new ();
+ mp = camel_mime_parser_new ();
+ camel_mime_parser_scan_from (mp, TRUE);
+ if (camel_mime_parser_init_with_fd (mp, fd) == -1) {
+ g_warning ("Unable to process file %s", filename);
+ camel_object_unref (CAMEL_OBJECT (mp));
+ camel_folder_thaw (folder);
+ camel_object_unref (CAMEL_OBJECT (folder));
+ return FALSE;
+ }
+
+ while (camel_mime_parser_step (mp, 0, 0) == HSCAN_FROM) {
+ /* Import the next message */
+ CamelMimeMessage *msg;
+ CamelMessageInfo *info;
+
+ msg = camel_mime_message_new ();
+ if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg),
+ mp) == -1) {
+ g_warning ("Failed message %d", n);
+ camel_object_unref (CAMEL_OBJECT (msg));
+ done = TRUE;
+ }
+
+ info = g_new0 (CamelMessageInfo, 1);
+ camel_folder_append_message (folder, msg, info, ex);
+ g_free (info);
+ camel_object_unref (CAMEL_OBJECT (msg));
+ if (camel_exception_is_set (ex)) {
+ g_warning ("Failed message %d", n);
+ done = TRUE;
+ }
+
+ if (!done) {
+ n++;
+ camel_mime_parser_step (mp, 0, 0);
+ }
+ }
+
+ camel_folder_sync (folder, FALSE, ex);
+ camel_folder_thaw (folder);
+ camel_object_unref (CAMEL_OBJECT (folder));
+ done = TRUE;
+
+ camel_exception_free (ex);
+ return done;
+}
+
+static void
+netscape_clean_up (void)
+{
+ g_free (nsmail_dir);
+ nsmail_dir = NULL;
+}
+
+static gboolean
+netscape_can_import (EvolutionIntelligentImporter *ii,
+ void *closure)
+{
+ NetscapeImporter *importer = closure;
+ char *nsprefs;
+ FILE *prefs_handle;
+ char *key;
+
+ /* Already imported */
+ key = g_strdup_printf ("=%s/config/Mail=/importers/", evolution_dir);
+ gnome_config_push_prefix (key);
+ g_free (key);
+
+ if (gnome_config_get_bool (KEY) == TRUE) {
+ gnome_config_pop_prefix ();
+ return FALSE;
+ }
+ gnome_config_pop_prefix ();
+
+ nsprefs = gnome_util_prepend_user_home (".netscape/preferences.js");
+ prefs_handle = fopen (nsprefs, "r");
+ g_free (nsprefs);
+
+ if (prefs_handle == NULL) {
+ d(g_warning ("No .netscape/preferences.js"));
+ return FALSE;
+ }
+
+ /* Find the user mail dir */
+ while (1) {
+ char line[4096];
+
+ fgets (line, 4096, prefs_handle);
+ if (line == NULL) {
+ g_warning ("No mail.directory entry");
+ fclose (prefs_handle);
+ return FALSE;
+ }
+
+ if (strstr (line, "mail.directory") != NULL) {
+ char *sep, *start, *end;
+ /* Found the line */
+
+ sep = strchr (line, ',');
+ if (sep == NULL) {
+ g_warning ("Bad line %s", line);
+ fclose (prefs_handle);
+ return FALSE;
+ }
+
+ start = strchr (sep, '\"') + 1;
+ if (start == NULL) {
+ g_warning ("Bad line %s", line);
+ fclose (prefs_handle);
+ return FALSE;
+ }
+
+ end = strrchr (sep, '\"');
+ if (end == NULL) {
+ g_warning ("Bad line %s", line);
+ fclose (prefs_handle);
+ return FALSE;
+ }
+
+ nsmail_dir = g_strndup (start, end - start);
+ d(g_warning ("Got nsmail_dir: %s", nsmail_dir));
+ fclose (prefs_handle);
+ return TRUE;
+ }
+ }
+}
+
+static void
+netscape_import_file (NetscapeImporter *importer,
+ const char *parent,
+ const char *dirname,
+ const char *filename,
+ const char *fullpath)
+{
+ char *summary, *summarypath, *foldername, *path;
+ char *protocol;
+ CamelException *ex;
+ CamelFolder *folder;
+
+ /* Check that the file is a netscape mbox.
+ It should have an associated .summary file */
+ summary = g_strdup_printf (".%s.summary", filename);
+ summarypath = g_concat_dir_and_file (dirname, summary);
+ if (!g_file_exists (summarypath)) {
+ d(g_warning ("%s does not exist.\nIgnoring %s", summary,
+ filename));
+ g_free (summary);
+ g_free (summarypath);
+ return;
+ }
+
+ g_free (summary);
+ g_free (summarypath);
+
+ /* Do import */
+ foldername = g_concat_dir_and_file (parent, filename);
+
+ d(g_warning ("Importing %s as %s\n", filename, fullpath));
+
+ ex = camel_exception_new ();
+ protocol = g_strconcat ("file://", fullpath, NULL);
+ folder = mail_tool_uri_to_folder (protocol, ex);
+ if (camel_exception_is_set (ex)) {
+ g_free (protocol);
+ camel_exception_free (ex);
+ return;
+ }
+
+ if (folder == NULL) {
+ g_warning ("Folder for %s is NULL", fullpath);
+ camel_exception_free (ex);
+ return;
+ }
+
+ camel_exception_free (ex);
+
+ path = g_concat_dir_and_file (dirname, filename);
+ netscape_import_mbox (folder, path);
+ g_free (path);
+}
+
+typedef struct {
+ NetscapeImporter *importer;
+ char *parent;
+ char *dirname;
+ char *filename;
+} NetscapeCreateDirectoryData;
+
+static void
+netscape_dir_created (BonoboListener *listener,
+ const char *event_name,
+ const BonoboArg *event_data,
+ CORBA_Environment *ev,
+ NetscapeImporter *importer)
+{
+ NetscapeCreateDirectoryData *data;
+ GList *l;
+ GNOME_Evolution_Storage_FolderResult *result;
+ char *fullpath;
+
+ if (strcmp (event_name, "evolution-shell:folder_created") != 0) {
+ return; /* Unknown event notification */
+ }
+
+ result = event_data->_value;
+ fullpath = result->path;
+
+ l = importer->dir_list;
+ importer->dir_list = g_list_remove_link (importer->dir_list, l);
+ data = l->data;
+ g_list_free_1 (l);
+
+ /* Import the file */
+ /* We got the folder, so try to import the file into it. */
+ netscape_import_file (data->importer, data->parent,
+ data->dirname, data->filename, fullpath);
+
+ g_free (data->parent);
+ g_free (data->dirname);
+ g_free (data->filename);
+ g_free (data);
+
+ if (importer->dir_list) {
+ /* Do the next in the list */
+ data = importer->dir_list->data;
+ mail_importer_create_folder (data->parent, data->filename, NULL,
+ importer->listener);
+ }
+}
+
+/* This function basically flattens the tree structure.
+ It makes a list of all the directories that are to be imported. */
+static void
+scan_dir (NetscapeImporter *importer,
+ const char *orig_parent,
+ const char *dirname)
+{
+ DIR *nsmail;
+ struct stat buf;
+ struct dirent *current;
+
+ nsmail = opendir (dirname);
+ if (nsmail == NULL) {
+ d(g_warning ("Could not open %s\nopendir returned: %s",
+ dirname, g_strerror (errno)));
+ return;
+ }
+
+ current = readdir (nsmail);
+ while (current) {
+ char *fullname;
+
+ /* Ignore things which start with .
+ which should be ., .., and the summaries. */
+ if (current->d_name[0] =='.') {
+ current = readdir (nsmail);
+ continue;
+ }
+
+ fullname = g_concat_dir_and_file (dirname, current->d_name);
+ if (stat (fullname, &buf) == -1) {
+ d(g_warning ("Could not stat %s\nstat returned:%s",
+ fullname, g_strerror (errno)));
+ current = readdir (nsmail);
+ g_free (fullname);
+ continue;
+ }
+
+ if (S_ISREG (buf.st_mode)) {
+ char *sbd, *dir, *parent;
+ NetscapeCreateDirectoryData *data;
+
+ d(g_print ("File: %s\n", fullname));
+
+ data = g_new0 (NetscapeCreateDirectoryData, 1);
+ data->importer = importer;
+ data->parent = g_strdup (orig_parent);
+ data->dirname = g_strdup (dirname);
+ data->filename = g_strdup (current->d_name);
+
+ importer->dir_list = g_list_append (importer->dir_list,
+ data);
+
+
+ parent = g_concat_dir_and_file (orig_parent,
+ data->filename);
+
+ /* Check if a .sbd folder exists */
+ dir = g_concat_dir_and_file (data->dirname, data->filename);
+ sbd = g_strconcat (dir, ".sbd", NULL);
+ g_free (dir);
+ if (g_file_exists (sbd)) {
+ scan_dir (importer, parent, sbd);
+ }
+
+ g_free (parent);
+ g_free (sbd);
+ }
+
+ g_free (fullname);
+ current = readdir (nsmail);
+ }
+}
+
+static void
+netscape_create_structure (EvolutionIntelligentImporter *ii,
+ void *closure)
+{
+ NetscapeImporter *importer = closure;
+ NetscapeCreateDirectoryData *data;
+ char *key;
+
+ g_return_if_fail (nsmail_dir != NULL);
+
+ scan_dir (importer, "/", nsmail_dir);
+
+ importer->listener = bonobo_listener_new (NULL, NULL);
+ gtk_signal_connect (GTK_OBJECT (importer->listener), "event_notify",
+ GTK_SIGNAL_FUNC (netscape_dir_created), importer);
+ data = importer->dir_list->data;
+ mail_importer_create_folder (data->parent, data->filename, NULL,
+ importer->listener);
+
+ key = g_strdup_printf ("=%s/config/Mail=/importers/", evolution_dir);
+ gnome_config_push_prefix (key);
+ g_free (key);
+
+ gnome_config_set_bool (KEY, TRUE);
+ gnome_config_pop_prefix ();
+
+ gnome_config_sync ();
+ gnome_config_drop_all ();
+}
+
+static BonoboObject *
+netscape_factory_fn (BonoboGenericFactory *_factory,
+ void *closure)
+{
+ EvolutionIntelligentImporter *importer;
+ NetscapeImporter *netscape;
+ char *message = N_("Evolution has found Netscape mail files.\n"
+ "Would you like them to be imported into Evolution?");
+
+ netscape = g_new0 (NetscapeImporter, 1);
+ importer = evolution_intelligent_importer_new (netscape_can_import,
+ netscape_create_structure,
+ "Netscape mail",
+ message, netscape);
+ return BONOBO_OBJECT (importer);
+}
+
+/* Entry Point */
+void
+mail_importer_module_init (void)
+{
+ static gboolean initialised = FALSE;
+ BonoboGenericFactory *factory;
+
+ if (initialised == TRUE)
+ return;
+
+ factory = bonobo_generic_factory_new (NETSCAPE_INTELLIGENT_IMPORTER_IID,
+ netscape_factory_fn, NULL);
+ if (factory == NULL)
+ g_warning ("Could not initialise Netscape Intelligent Mail Importer.");
+ initialised = TRUE;
+}
+
+/* GModule g_module_unload routine */
+void
+g_module_unload (void)
+{
+ netscape_clean_up ();
+}
diff --git a/mail/mail-importer.c b/mail/mail-importer.c
index 03f2bd374b..85dfe5a57a 100644
--- a/mail/mail-importer.c
+++ b/mail/mail-importer.c
@@ -36,37 +36,56 @@
#include <camel/camel-stream-mem.h>
#include <camel/camel-exception.h>
-#include "evolution-outlook-importer.h"
-#include "evolution-mbox-importer.h"
+#include <dirent.h>
+#include <gmodule.h>
-static gboolean factory_initialised = FALSE;
+static GList *importer_modules = NULL;
extern char *evolution_dir;
static GNOME_Evolution_LocalStorage local_storage = NULL;
+/**
+ * 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 *type,
- const char *description)
+ const char *description,
+ const BonoboListener *listener)
{
- BonoboListener *listener;
Bonobo_Listener corba_listener;
CORBA_Environment ev;
char *path, *physical;
+ char *real_description;
+
+ g_return_if_fail (local_storage != NULL);
+ g_return_if_fail (listener != NULL);
+ g_return_if_fail (BONOBO_IS_LISTENER (listener));
path = g_concat_dir_and_file (parent_path, name);
physical = g_strdup_printf ("file://%s/local/%s", evolution_dir,
parent_path);
- listener = bonobo_listener_new (NULL, NULL);
corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener));
+ /* Darn CORBA wanting non-NULL values for strings */
+ real_description = CORBA_string_dup (description ? description : "");
CORBA_exception_init (&ev);
GNOME_Evolution_Storage_asyncCreateFolder (local_storage,
- path, "mail", name,
- physical,
+ path, "mail",
+ real_description, physical,
corba_listener, &ev);
CORBA_exception_free (&ev);
g_free (path);
@@ -120,6 +139,45 @@ mail_importer_add_line (MailImporter *importer,
g_free (info);
}
+/* module management */
+static GList *
+get_importer_list (void)
+{
+ DIR *dir;
+ struct dirent *d;
+ GList *importers_ret = NULL;
+
+ dir = opendir (MAIL_IMPORTERSDIR);
+ if (!dir) {
+ g_warning ("No importers dir: %s", MAIL_IMPORTERSDIR);
+ return NULL;
+ }
+
+ while ((d = readdir (dir))) {
+ char *path, *ext;
+
+ ext = strchr (d->d_name, '.');
+ if (!ext || strcmp (ext, ".so") != 0)
+ continue;
+
+ path = g_concat_dir_and_file (MAIL_IMPORTERSDIR, d->d_name);
+ importers_ret = g_list_prepend (importers_ret, path);
+ }
+
+ closedir (dir);
+ return importers_ret;
+}
+
+static void
+free_importer_list (GList *list)
+{
+ for (; list; list = list->next) {
+ g_free (list->data);
+ }
+
+ g_list_free (list);
+}
+
/**
* mail_importer_init:
*
@@ -128,26 +186,64 @@ mail_importer_add_line (MailImporter *importer,
void
mail_importer_init (EvolutionShellClient *client)
{
- BonoboGenericFactory *factory;
+ GList *importers, *l;
- if (factory_initialised == TRUE)
+ if (importer_modules != NULL) {
return;
+ }
- /* FIXME: Need plugins */
- factory = bonobo_generic_factory_new (OUTLOOK_FACTORY_IID,
- outlook_factory_fn,
- NULL);
- if (factory == NULL) {
- g_error ("Unable to create outlook factory.");
+ local_storage = evolution_shell_client_get_local_storage (client);
+
+ if (!g_module_supported ()) {
+ g_warning ("Could not initialise the importers as module loading"
+ " is not supported on this system");
+ return;
}
- factory = bonobo_generic_factory_new (MBOX_FACTORY_IID,
- mbox_factory_fn, NULL);
- if (factory == NULL) {
- g_error ("Unable to create mbox factory.");
+ importers = get_importer_list ();
+ if (importers == NULL)
+ return;
+
+ for (l = importers; l; l = l->next) {
+ GModule *module;
+
+ module = g_module_open (l->data, 0);
+ if (!module) {
+ g_warning ("Could not load: %s: %s", (char *) l->data,
+ g_module_error ());
+ } else {
+ void *(*mail_importer_module_init) ();
+
+ if (!g_module_symbol (module, "mail_importer_module_init",
+ (gpointer *)&mail_importer_module_init)) {
+ g_warning ("Could not load %s: No initialisation",
+ (char *) l->data);
+ g_module_close (module);
+ }
+
+ mail_importer_module_init ();
+ importer_modules = g_list_prepend (importer_modules, module);
+ }
}
-
- factory_initialised = TRUE;
- local_storage = evolution_shell_client_get_local_storage (client);
+
+ free_importer_list (importers);
+}
+
+/**
+ * mail_importer_uninit:
+ *
+ * Unloads all the modules.
+ */
+void
+mail_importer_uninit (void)
+{
+ GList *l;
+
+ for (l = importer_modules; l; l = l->next) {
+ g_module_close (l->data);
+ }
+
+ g_list_free (importer_modules);
+ importer_modules = NULL;
}
diff --git a/mail/mail-importer.h b/mail/mail-importer.h
index e50288c6c0..bab2ff5574 100644
--- a/mail/mail-importer.h
+++ b/mail/mail-importer.h
@@ -26,8 +26,8 @@
#include <camel/camel-folder.h>
#include <camel/camel-stream-mem.h>
-#include <camel/camel-exception.h>
#include <evolution-shell-client.h>
+#include <bonobo/bonobo-listener.h>
typedef struct _MailImporter MailImporter;
struct _MailImporter {
@@ -43,6 +43,6 @@ void mail_importer_add_line (MailImporter *importer,
gboolean finished);
void mail_importer_create_folder (const char *parent_path,
const char *name,
- const char *type,
- const char *description);
+ const char *description,
+ const BonoboListener *listener);
#endif
diff --git a/mail/netscape-importer.c b/mail/netscape-importer.c
deleted file mode 100644
index a505c9300f..0000000000
--- a/mail/netscape-importer.c
+++ /dev/null
@@ -1,277 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* netscape-importer.c
- *
- *
- * Authors:
- * Iain Holmes <iain@ximian.com>
- *
- * Copyright 2001 Ximian, Inc. (http://www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include <glib.h>
-#include <gnome.h>
-
-#include "mail-importer.h"
-static char *nsmail_dir = NULL;
-
-/*#define SUPER_IMPORTER_DEBUG*/
-#ifdef SUPER_IMPORTER_DEBUG
-#define d(x) x
-#else
-#define d(x)
-#endif
-
-#if 0
-typedef struct {
- MailImporter importer;
-
- int num;
- CamelMimeParser *mp;
-} NetscapeImporter;
-
-static void
-netscape_clean_up (void)
-{
- g_free (nsmail_dir);
- nsmail_dir = NULL;
-}
-
-static gboolean
-netscape_can_import (void)
-{
- char *nsprefs;
- FILE *prefs_handle;
-
- nsprefs = gnome_util_prepend_user_home (".netscape/preferences.js");
- prefs_handle = fopen (nsprefs, "r");
- g_free (nsprefs);
-
- if (prefs_handle == NULL) {
- d(g_warning ("No .netscape/preferences.js"));
- return FALSE;
- }
-
- /* Find the user mail dir */
- while (1) {
- char line[4096];
-
- fgets (line, 4096, prefs_handle);
- if (line == NULL) {
- d(g_warning ("No mail.directory entry"));
- fclose (prefs_handle);
- return FALSE;
- }
-
- if (strstr (line, "mail.directory") != NULL) {
- char *sep, *start, *end;
- /* Found the line */
-
- sep = strchr (line, ',');
- if (sep == NULL) {
- d(g_warning ("Bad line %s", line));
- fclose (prefs_handle);
- return FALSE;
- }
-
- start = strchr (sep, '\"') + 1;
- if (start == NULL) {
- d(g_warning ("Bad line %s", line));
- fclose (prefs_handle);
- return FALSE;
- }
-
- end = strrchr (sep, '\"');
- if (end == NULL) {
- d(g_warning ("Bad line %s", line));
- fclose (prefs_handle);
- return FALSE;
- }
-
- nsmail_dir = g_strndup (start, end - start);
- d(g_warning ("Got nsmail_dir: %s", nsmail_dir));
- fclose (prefs_handle);
- return TRUE;
- }
- }
-}
-
-static void
-netscape_import_file (const char *parent,
- const char *dirname,
- const char *filename)
-{
- char *summary, *summarypath;
-
- /* Check that the file is a netscape mbox.
- It should have an associated .summary file */
- summary = g_strdup_printf (".%s.summary", filename);
- summarypath = g_concat_dir_and_file (dirname, summary);
- if (!g_file_exists (summarypath)) {
- d(g_warning ("%s does not exist.\nIgnoring %s", summary,
- filename));
- g_free (summary);
- g_free (summarypath);
- return;
- }
-
- g_free (summary);
- g_free (summarypath);
-
- /* Do import */
- mail_importer_create_folder (parent, filename, "mail", NULL);
- g_print ("Importing %s as %s\n", parent, filename);
-}
-
-static void
-scan_dir (NetscapeImporter *importer,
- char *parent,
- const char *dirname)
-{
- DIR *nsmail;
- struct stat buf;
- struct dirent *current;
-
- nsmail = opendir (dirname);
- if (nsmail == NULL) {
- d(g_warning ("Could not open %s\nopendir returned: %s",
- dirname, g_strerror (errno)));
- return;
- }
-
- current = readdir (nsmail);
- while (current) {
- char *fullname;
-
- /* Ignore things which start with .
- which should be ., .., and the summaries. */
- if (current->d_name[0] =='.') {
- current = readdir (nsmail);
- continue;
- }
-
- fullname = g_concat_dir_and_file (dirname, current->d_name);
- if (stat (fullname, &buf) == -1) {
- d(g_warning ("Could not stat %s\nstat returned:%s",
- fullname, g_strerror (errno)));
- current = readdir (nsmail);
- g_free (fullname);
- continue;
- }
-
- if (S_ISREG (buf.st_mode)) {
- d(g_print ("File: %s\n", fullname));
- netscape_import_file (importer, parent, dirname,
- current->d_name);
- } else if (S_ISDIR (buf.st_mode)) {
- char *ext;
- d(g_print ("Directory: %s\n", fullname));
-
- ext = strrchr (current->d_name, '.');
- if (ext && strcmp (ext + 1, "sbd") == 0) {
- /* Strip the .sbd */
- if (parent == NULL) {
- parent = g_strndup (current->d_name,
- ext - current->d_name);
- } else {
- char *part;
- char *tmp;
-
- part = g_strndup (current->d_name,
- ext - current->d_name);
- tmp = parent;
- parent = g_concat_dir_and_file (parent,
- part);
- g_free (tmp);
- g_free (part);
- }
-
- scan_dir (importer, parent, fullname);
- }
- }
-
- g_free (fullname);
- current = readdir (nsmail);
- }
-}
-
-static void
-netscape_create_structure (void)
-{
- DIR *nsmail;
- struct dirent *current;
- NetscapeImporter *importer;
-
- g_return_if_fail (nsmail_dir != NULL);
-
- importer = g_new0 (NetscapeImporter, 1);
-
- g_print ("Creating structure\n"
- "------------------\n");
- scan_dir (importer, g_strdup ("/"), nsmail_dir);
- g_print ("------------------\n");
-}
-
-
-#ifdef STANDALONE
-int
-main (int argc,
- char **argv)
-#else
-int
-netscape_importer(void)
-#endif
-{
- gboolean found;
-
- g_print ("ISI - Iain's Super Importer\n");
- g_print ("Checking for Netscape mail:\t");
- found = netscape_can_import ();
- g_print ("%s", found ? "Found" : "Not found");
-
- if (found)
- g_print (" (%s)\n", nsmail_dir);
- else
- g_print ("\n");
-
- netscape_create_structure ();
-}
-
-BonoboObject *
-mbox_factory_fn (BonoboGenericFactory *_factory,
- void *closure)
-{
- EvolutionImporter *importer;
- NetscapeImporter *netscape;
-
- netscape = g_new0 (NetscapeImporter, 1);
- importer = evolution_importer_new (support_format_fn,
- load_file_fn,
- process_item_fn, NULL, netscape);
-}
-#endif
diff --git a/shell/ChangeLog b/shell/ChangeLog
index 78eaf1c244..cf6ab7683e 100644
--- a/shell/ChangeLog
+++ b/shell/ChangeLog
@@ -1,3 +1,41 @@
+2001-03-12 Iain Holmes <iain@ximian.com>
+
+ * Evolution-Storage.idl: Add a FolderResult structure.
+
+ * e-local-storage.c (struct _AsyncCreateFolderCallbackData): Add a
+ Bonobo_Listener.
+ (notify_listener): Function to...notify the listener.
+ (component_async_create_folder_callback): Use the notify_listener
+ function.
+ (real_do_folder_create): New prototype. Replace all returns with
+ a call to notify_listener. Make the directory with a call to
+ e_mkdir_hier instead of multiple calls to mkdir. Only emit a fail
+ on a bad error, not on EEXIST.
+ (bonobo_interface_create_folder_cb): Namespace create_folder_cb to match
+ the others.
+
+ e-shell.c: Run the intelligent importer.
+
+ evolution-storage.c (impl_Storage_async_create_folder): Just emit the signal,
+ not the callback.
+ (e_marshal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER): Lovely signal
+ marshaller.
+ (class_init): Change the signal definition for the create_folder signal.
+
+ importer/GNOME_Evolution_Importer.idl: Add an IntelligentImporter inteface.
+
+ importer/Makefile.am: Add the evolution-intelligent-importer.c, intelligent.c
+ and evolution-intelligent-importer.h to the files.
+
+ importer/evolution-importer-listener.[ch]: Convert to BonoboXObject.
+
+ importer/evolution-importer.[ch]: BonoboXObjectification.
+
+ importer/evolution-intelligent-importer.[ch]: BonoboXObject for the
+ GNOME:Evolution:IntelligentImporter interface.
+
+ importer/intelligent.c: Code for running the intelligent importers.
+
2001-03-08 Ettore Perazzoli <ettore@ximian.com>
* e-storage-set-view.c (get_folder_at_row): New helper function.
diff --git a/shell/Evolution-Storage.idl b/shell/Evolution-Storage.idl
index 879df8afb0..a0cf16a303 100644
--- a/shell/Evolution-Storage.idl
+++ b/shell/Evolution-Storage.idl
@@ -42,6 +42,11 @@ module Evolution {
GENERIC_ERROR
};
+ struct FolderResult {
+ Result result;
+ string path;
+ };
+
void asyncCreateFolder (in string path,
in string type,
in string description,
diff --git a/shell/e-local-storage.c b/shell/e-local-storage.c
index b669701be9..15247295e0 100644
--- a/shell/e-local-storage.c
+++ b/shell/e-local-storage.c
@@ -322,6 +322,7 @@ shell_component_result_to_storage_result (EvolutionShellComponentResult result)
struct _AsyncCreateFolderCallbackData {
EStorage *storage;
+ Bonobo_Listener listener;
char *path;
char *display_name;
@@ -336,14 +337,38 @@ struct _AsyncCreateFolderCallbackData {
typedef struct _AsyncCreateFolderCallbackData AsyncCreateFolderCallbackData;
static void
+notify_listener (const Bonobo_Listener listener,
+ EStorageResult result,
+ const char *physical_path)
+{
+ CORBA_any any;
+ GNOME_Evolution_Storage_FolderResult folder_result;
+ CORBA_Environment ev;
+
+ folder_result.result = result;
+ folder_result.path = CORBA_string_dup (physical_path ?
+ physical_path : "");
+ any._type = TC_GNOME_Evolution_Storage_FolderResult;
+ any._value = &folder_result;
+
+ CORBA_exception_init (&ev);
+ Bonobo_Listener_event (listener, "evolution-shell:folder_created",
+ &any, &ev);
+ CORBA_exception_free (&ev);
+}
+
+static void
component_async_create_folder_callback (EvolutionShellComponentClient *shell_component_client,
EvolutionShellComponentResult result,
void *data)
{
AsyncCreateFolderCallbackData *callback_data;
+ EStorageResult storage_result;
callback_data = (AsyncCreateFolderCallbackData *) data;
+ storage_result = shell_component_result_to_storage_result (result);
+
if (result != EVOLUTION_SHELL_COMPONENT_OK) {
/* XXX: This assumes the component won't leave any files in the directory. */
rmdir (callback_data->physical_path);
@@ -361,15 +386,19 @@ component_async_create_folder_callback (EvolutionShellComponentClient *shell_com
} else {
rmdir (callback_data->physical_path);
gtk_object_unref (GTK_OBJECT (folder));
- result = E_STORAGE_IOERROR;
+ storage_result = E_STORAGE_IOERROR;
}
}
bonobo_object_unref (BONOBO_OBJECT (shell_component_client));
+ if (callback_data->listener != CORBA_OBJECT_NIL)
+ notify_listener (callback_data->listener, storage_result,
+ callback_data->physical_path);
+
if (callback_data->callback != NULL)
(* callback_data->callback) (callback_data->storage,
- shell_component_result_to_storage_result (result),
+ storage_result,
callback_data->callback_data);
g_free (callback_data->path);
@@ -420,8 +449,9 @@ impl_get_name (EStorage *storage)
return E_LOCAL_STORAGE_NAME;
}
-static int
+static void
real_do_folder_create (ELocalStorage *local_storage,
+ Bonobo_Listener listener,
const char *path,
const char *type,
const char *description,
@@ -445,7 +475,7 @@ real_do_folder_create (ELocalStorage *local_storage,
if (callback != NULL)
(* callback) (storage, E_STORAGE_INVALIDTYPE, data);
- return E_STORAGE_INVALIDTYPE;
+ notify_listener (listener, E_STORAGE_INVALIDTYPE, NULL);
}
g_assert (g_path_is_absolute (path));
@@ -467,6 +497,7 @@ real_do_folder_create (ELocalStorage *local_storage,
subfolders_directory_physical_path = g_concat_dir_and_file (parent_physical_path,
SUBFOLDER_DIR_NAME);
+#if 0
if (! g_file_exists (subfolders_directory_physical_path)
&& mkdir (subfolders_directory_physical_path, 0700) == -1) {
g_free (parent_path);
@@ -477,7 +508,8 @@ real_do_folder_create (ELocalStorage *local_storage,
errno_to_storage_result (), data);
return errno_to_storage_result ();
}
-
+#endif
+
physical_path = g_concat_dir_and_file (subfolders_directory_physical_path,
folder_name);
g_free (subfolders_directory_physical_path);
@@ -486,13 +518,17 @@ real_do_folder_create (ELocalStorage *local_storage,
/* Create the directory that holds the folder. */
- if (mkdir (physical_path, 0700) == -1) {
- g_free (physical_path);
- if (callback != NULL)
- (* callback) (storage,
- errno_to_storage_result (), data);
+ if (e_mkdir_hier (physical_path, 0700) == -1) {
- return errno_to_storage_result ();
+ /* Bad error which we can't recover from */
+ if (errno != EEXIST) {
+ notify_listener (listener, errno_to_storage_result (),
+ physical_path);
+ g_free (physical_path);
+ if (callback != NULL)
+ (* callback) (storage,
+ errno_to_storage_result (), data);
+ }
}
/* Finally tell the component to do the job of creating the physical files in
@@ -510,6 +546,7 @@ real_do_folder_create (ELocalStorage *local_storage,
callback_data->description = g_strdup (description);
callback_data->physical_uri = physical_uri;
callback_data->physical_path = physical_path;
+ callback_data->listener = listener;
callback_data->callback = callback;
callback_data->callback_data = data;
@@ -520,25 +557,6 @@ real_do_folder_create (ELocalStorage *local_storage,
type,
component_async_create_folder_callback,
callback_data);
- return EVOLUTION_STORAGE_OK;
-}
-
-static int
-create_folder_cb (EvolutionStorage *estorage,
- const char *path,
- const char *type,
- const char *description,
- const char *parent_p_path,
- void *data)
-{
- ELocalStorage *local_storage;
- int ret;
-
- local_storage = E_LOCAL_STORAGE (data);
- ret = real_do_folder_create (local_storage, path, type,
- description, NULL, data);
-
- return ret;
}
static void
@@ -552,7 +570,7 @@ impl_async_create_folder (EStorage *storage,
ELocalStorage *local_storage;
local_storage = E_LOCAL_STORAGE (storage);
- real_do_folder_create (local_storage, path, type,
+ real_do_folder_create (local_storage, NULL, path, type,
description, callback, data);
}
@@ -569,6 +587,21 @@ impl_async_remove_folder (EStorage *storage,
/* Callbacks for the `Evolution::LocalStorage' interface we are exposing to the outside world. */
+static void
+bonobo_interface_create_folder_cb (EvolutionStorage *estorage,
+ const Bonobo_Listener listener,
+ const char *path,
+ const char *type,
+ const char *description,
+ const char *parent_p_path,
+ void *data)
+{
+ ELocalStorage *local_storage;
+
+ local_storage = E_LOCAL_STORAGE (data);
+ real_do_folder_create (local_storage, listener, path, type,
+ description, NULL, data);
+}
static void
bonobo_interface_update_folder_cb (EvolutionLocalStorage *bonobo_local_storage,
@@ -654,7 +687,8 @@ construct (ELocalStorage *local_storage,
priv->bonobo_interface = evolution_local_storage_new (E_LOCAL_STORAGE_NAME);
gtk_signal_connect (GTK_OBJECT (priv->bonobo_interface), "create_folder",
- GTK_SIGNAL_FUNC (create_folder_cb), local_storage);
+ GTK_SIGNAL_FUNC (bonobo_interface_create_folder_cb),
+ local_storage);
gtk_signal_connect (GTK_OBJECT (priv->bonobo_interface), "update_folder",
GTK_SIGNAL_FUNC (bonobo_interface_update_folder_cb),
local_storage);
diff --git a/shell/e-shell.c b/shell/e-shell.c
index 6656e2f79b..ba27c9a89f 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -752,6 +752,10 @@ e_shell_construct (EShell *shell,
/* Now that we have a local storage, we can tell the components we are here. */
set_owner_on_components (shell);
+ /* Run the intelligent importers to find see if any data needs
+ importing. */
+ intelligent_importer_init ();
+
shortcut_path = g_concat_dir_and_file (local_directory, "shortcuts.xml");
priv->shortcuts = e_shortcuts_new (priv->storage_set,
priv->folder_type_registry,
diff --git a/shell/evolution-storage.c b/shell/evolution-storage.c
index bf02c19110..c3ffad319c 100644
--- a/shell/evolution-storage.c
+++ b/shell/evolution-storage.c
@@ -287,23 +287,12 @@ impl_Storage_async_create_folder (PortableServer_Servant servant,
{
BonoboObject *bonobo_object;
EvolutionStorage *storage;
- int int_result;
- CORBA_any any;
- GNOME_Evolution_Storage_Result corba_result;
bonobo_object = bonobo_object_from_servant (servant);
storage = EVOLUTION_STORAGE (bonobo_object);
- int_result = GNOME_Evolution_Storage_UNSUPPORTED_OPERATION;
gtk_signal_emit (GTK_OBJECT (storage), signals[CREATE_FOLDER],
- path, type, description, parent_physical_uri,
- &int_result);
-
- corba_result = storage_gtk_to_corba_result (int_result);
- any._type = TC_GNOME_Evolution_Storage_Result;
- any._value = &corba_result;
-
- Bonobo_Listener_event (listener, "result", &any, ev);
+ listener, path, type, description, parent_physical_uri);
}
static void
@@ -435,6 +424,29 @@ corba_class_init (void)
vepv->GNOME_Evolution_Storage_epv = evolution_storage_get_epv ();
}
+/* The worst signal marshaller in Scotland */
+typedef void (*GtkSignal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER) (GtkObject *,
+ gpointer, gpointer, gpointer, gpointer, gpointer,
+ gpointer user_data);
+
+static void
+e_marshal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args)
+{
+ GtkSignal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER rfunc;
+
+ rfunc = (GtkSignal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER) func;
+ (*rfunc) (object,
+ GTK_VALUE_POINTER (args[0]),
+ GTK_VALUE_POINTER (args[1]),
+ GTK_VALUE_POINTER (args[2]),
+ GTK_VALUE_POINTER (args[3]),
+ GTK_VALUE_POINTER (args[4]),
+ func_data);
+}
+
static void
class_init (EvolutionStorageClass *klass)
{
@@ -450,7 +462,7 @@ class_init (EvolutionStorageClass *klass)
object_class->type,
GTK_SIGNAL_OFFSET (EvolutionStorageClass,
create_folder),
- e_marshal_INT__POINTER_POINTER_POINTER_POINTER,
+ e_marshal_NONE__POINTER_POINTER_POINTER_POINTER_POINTER,
GTK_TYPE_INT, 4,
GTK_TYPE_STRING,
GTK_TYPE_STRING,
diff --git a/shell/importer/GNOME_Evolution_Importer.idl b/shell/importer/GNOME_Evolution_Importer.idl
index fe49ab82c5..7dec5e7e0c 100644
--- a/shell/importer/GNOME_Evolution_Importer.idl
+++ b/shell/importer/GNOME_Evolution_Importer.idl
@@ -79,5 +79,15 @@ module Evolution {
*/
boolean loadFile (in string filename);
};
+
+ interface IntelligentImporter : Bonobo::Unknown {
+
+ readonly attribute string importername;
+ readonly attribute string message;
+
+ boolean canImport ();
+
+ void importData ();
+ };
};
};
diff --git a/shell/importer/Makefile.am b/shell/importer/Makefile.am
index 96bbbafd5c..975d5a372a 100644
--- a/shell/importer/Makefile.am
+++ b/shell/importer/Makefile.am
@@ -27,14 +27,17 @@ idl_DATA = $(IDLS)
libevolution_importerincludedir = $(includedir)/evolution/importer
libevolution_importer_la_SOURCES = \
$(IDL_GENERATED) \
+ evolution-intelligent-importer.c \
evolution-importer-client.c \
evolution-importer-listener.c \
evolution-importer.c \
+ intelligent.c \
importer.c \
importer.h
libevolution_importerinclude_HEADERS = \
GNOME_Evolution_Importer.h \
+ evolution-intelligent-importer.h \
evolution-importer-client.h \
evolution-importer-listener.h \
evolution-importer.h
diff --git a/shell/importer/evolution-importer-listener.c b/shell/importer/evolution-importer-listener.c
index 35e73634d5..62dc35b19c 100644
--- a/shell/importer/evolution-importer-listener.c
+++ b/shell/importer/evolution-importer-listener.c
@@ -31,9 +31,9 @@
#include "GNOME_Evolution_Importer.h"
#include "evolution-importer-listener.h"
-#define PARENT_TYPE (bonobo_object_get_type ())
+#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
-static BonoboObjectClass *parent_class;
+static BonoboObjectClass *parent_class = NULL;
struct _EvolutionImporterListenerPrivate {
EvolutionImporterListenerCallback callback;
@@ -41,6 +41,7 @@ struct _EvolutionImporterListenerPrivate {
void *closure;
};
+#if 0
static POA_GNOME_Evolution_ImporterListener__vepv Listener_vepv;
static POA_GNOME_Evolution_ImporterListener *
@@ -64,6 +65,7 @@ create_servant (void)
return servant;
}
+#endif
static EvolutionImporterResult
corba_result_to_evolution (GNOME_Evolution_ImporterListener_ImporterResult corba_result)
@@ -88,20 +90,24 @@ corba_result_to_evolution (GNOME_Evolution_ImporterListener_ImporterResult corba
}
}
+static inline EvolutionImporterListener *
+evolution_importer_listener_from_servant (PortableServer_Servant servant)
+{
+ return EVOLUTION_IMPORTER_LISTENER (bonobo_object_from_servant (servant));
+}
+
static void
impl_GNOME_Evolution_ImporterListener_notifyResult (PortableServer_Servant servant,
GNOME_Evolution_ImporterListener_ImporterResult result,
CORBA_boolean more_items,
CORBA_Environment *ev)
{
- BonoboObject *bonobo_object;
EvolutionImporterListener *listener;
EvolutionImporterListenerPrivate *priv;
EvolutionImporterResult out_result;
- bonobo_object = bonobo_object_from_servant (servant);
- listener = EVOLUTION_IMPORTER_LISTENER (bonobo_object);
- priv = listener->private;
+ listener = evolution_importer_listener_from_servant (servant);
+ priv = listener->priv;
out_result = corba_result_to_evolution (result);
if (priv->callback) {
@@ -121,17 +127,18 @@ destroy (GtkObject *object)
EvolutionImporterListenerPrivate *priv;
listener = EVOLUTION_IMPORTER_LISTENER (object);
- priv = listener->private;
+ priv = listener->priv;
if (priv == NULL)
return;
g_free (priv);
- listener->private = NULL;
+ listener->priv = NULL;
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
+#if 0
static void
corba_class_init (void)
{
@@ -152,32 +159,30 @@ corba_class_init (void)
vepv->Bonobo_Unknown_epv = bonobo_object_get_epv ();
vepv->GNOME_Evolution_ImporterListener_epv = epv;
}
+#endif
static void
-class_init (EvolutionImporterListenerClass *klass)
+evolution_importer_listener_class_init (EvolutionImporterListenerClass *klass)
{
GtkObjectClass *object_class;
+ POA_GNOME_Evolution_ImporterListener__epv *epv = &klass->epv;
object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = destroy;
parent_class = gtk_type_class (PARENT_TYPE);
-
- corba_class_init ();
+ epv->notifyResult = impl_GNOME_Evolution_ImporterListener_notifyResult;
}
static void
-init (EvolutionImporterListener *listener)
+evolution_importer_listener_init (EvolutionImporterListener *listener)
{
EvolutionImporterListenerPrivate *priv;
priv = g_new0 (EvolutionImporterListenerPrivate, 1);
- listener->private = priv;
+ listener->priv = priv;
}
-E_MAKE_TYPE (evolution_importer_listener, "EvolutionImporterListener",
- EvolutionImporterListener, class_init, init, PARENT_TYPE);
-
static void
evolution_importer_listener_construct (EvolutionImporterListener *listener,
GNOME_Evolution_ImporterListener corba_object,
@@ -191,7 +196,7 @@ evolution_importer_listener_construct (EvolutionImporterListener *listener,
g_return_if_fail (corba_object != CORBA_OBJECT_NIL);
g_return_if_fail (callback != NULL);
- priv = listener->private;
+ priv = listener->priv;
priv->callback = callback;
priv->closure = closure;
@@ -212,18 +217,15 @@ evolution_importer_listener_new (EvolutionImporterListenerCallback callback,
void *closure)
{
EvolutionImporterListener *listener;
- POA_GNOME_Evolution_ImporterListener *servant;
GNOME_Evolution_ImporterListener corba_object;
- servant = create_servant ();
- if (servant == NULL)
- return NULL;
-
listener = gtk_type_new (evolution_importer_listener_get_type ());
- corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (listener),
- servant);
evolution_importer_listener_construct (listener, corba_object,
callback, closure);
return listener;
}
+
+BONOBO_X_TYPE_FUNC_FULL (EvolutionImporterListener,
+ GNOME_Evolution_ImporterListener,
+ PARENT_TYPE, evolution_importer_listener);
diff --git a/shell/importer/evolution-importer-listener.h b/shell/importer/evolution-importer-listener.h
index 33c4617332..e61fdb3465 100644
--- a/shell/importer/evolution-importer-listener.h
+++ b/shell/importer/evolution-importer-listener.h
@@ -24,8 +24,8 @@
#ifndef EVOLUTION_IMPORTER_LISTENER_H
#define EVOLUTION_IMPORTER_LISTENER_H
-#include <bonobo/bonobo-object.h>
-
+#include <bonobo/bonobo-xobject.h>
+#include <importer/GNOME_Evolution_Importer.h>
#include "evolution-importer.h"
#ifdef __cplusplus
@@ -48,13 +48,15 @@ typedef void (* EvolutionImporterListenerCallback) (EvolutionImporterListener *l
gboolean more_items,
void *closure);
struct _EvolutionImporterListener {
- BonoboObject parent;
-
- EvolutionImporterListenerPrivate *private;
+ BonoboXObject parent;
+
+ EvolutionImporterListenerPrivate *priv;
};
struct _EvolutionImporterListenerClass {
- BonoboObjectClass parent_class;
+ BonoboXObjectClass parent_class;
+
+ POA_GNOME_Evolution_ImporterListener__epv epv;
};
GtkType evolution_importer_listener_get_type (void);
diff --git a/shell/importer/evolution-importer.c b/shell/importer/evolution-importer.c
index 85d2446a19..c48390c9e5 100644
--- a/shell/importer/evolution-importer.c
+++ b/shell/importer/evolution-importer.c
@@ -32,7 +32,7 @@
#include "evolution-importer.h"
-#define PARENT_TYPE BONOBO_OBJECT_TYPE
+#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
static BonoboObjectClass *parent_class = NULL;
struct _EvolutionImporterPrivate {
@@ -45,28 +45,10 @@ struct _EvolutionImporterPrivate {
};
-static POA_GNOME_Evolution_Importer__vepv Importer_vepv;
-
-static POA_GNOME_Evolution_Importer *
-create_servant (void)
+static inline EvolutionImporter *
+evolution_importer_from_servant (PortableServer_Servant servant)
{
- POA_GNOME_Evolution_Importer *servant;
- CORBA_Environment ev;
-
- servant = (POA_GNOME_Evolution_Importer *) g_new0 (BonoboObjectServant, 1);
- servant->vepv = &Importer_vepv;
-
- CORBA_exception_init (&ev);
- POA_GNOME_Evolution_Importer__init ((PortableServer_Servant) servant, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_free (servant);
- CORBA_exception_free (&ev);
- return NULL;
- }
-
- CORBA_exception_free (&ev);
-
- return servant;
+ return EVOLUTION_IMPORTER (bonobo_object_from_servant (servant));
}
static CORBA_boolean
@@ -74,13 +56,11 @@ impl_GNOME_Evolution_Importer_supportFormat (PortableServer_Servant servant,
const CORBA_char *filename,
CORBA_Environment *ev)
{
- BonoboObject *bonobo_object;
EvolutionImporter *importer;
EvolutionImporterPrivate *priv;
- bonobo_object = bonobo_object_from_servant (servant);
- importer = EVOLUTION_IMPORTER (bonobo_object);
- priv = importer->private;
+ importer = evolution_importer_from_servant (servant);
+ priv = importer->priv;
if (priv->support_format_fn != NULL)
return (priv->support_format_fn) (importer, filename,
@@ -94,13 +74,11 @@ impl_GNOME_Evolution_Importer_loadFile (PortableServer_Servant servant,
const CORBA_char *filename,
CORBA_Environment *ev)
{
- BonoboObject *bonobo_object;
EvolutionImporter *importer;
EvolutionImporterPrivate *priv;
- bonobo_object = bonobo_object_from_servant (servant);
- importer = EVOLUTION_IMPORTER (bonobo_object);
- priv = importer->private;
+ importer = evolution_importer_from_servant (servant);
+ priv = importer->priv;
if (priv->load_file_fn != NULL)
return (priv->load_file_fn) (importer, filename, priv->closure);
@@ -113,13 +91,11 @@ impl_GNOME_Evolution_Importer_processItem (PortableServer_Servant servant,
GNOME_Evolution_ImporterListener listener,
CORBA_Environment *ev)
{
- BonoboObject *bonobo_object;
EvolutionImporter *importer;
EvolutionImporterPrivate *priv;
- bonobo_object = bonobo_object_from_servant (servant);
- importer = EVOLUTION_IMPORTER (bonobo_object);
- priv = importer->private;
+ importer = evolution_importer_from_servant (servant);
+ priv = importer->priv;
if (priv->process_item_fn != NULL)
(priv->process_item_fn) (importer, listener, priv->closure, ev);
@@ -132,14 +108,12 @@ static CORBA_char *
impl_GNOME_Evolution_Importer_getError (PortableServer_Servant servant,
CORBA_Environment *ev)
{
- BonoboObject *bonobo_object;
EvolutionImporter *importer;
EvolutionImporterPrivate *priv;
CORBA_char *out_str;
- bonobo_object = bonobo_object_from_servant (servant);
- importer = EVOLUTION_IMPORTER (bonobo_object);
- priv = importer->private;
+ importer = evolution_importer_from_servant (servant);
+ priv = importer->priv;
if (priv->get_error_fn != NULL) {
out_str = (priv->get_error_fn) (importer, priv->closure);
@@ -156,65 +130,47 @@ destroy (GtkObject *object)
EvolutionImporterPrivate *priv;
importer = EVOLUTION_IMPORTER (object);
- priv = importer->private;
+ priv = importer->priv;
if (priv == NULL)
return;
g_free (priv);
- importer->private = NULL;
+ importer->priv = NULL;
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
-corba_class_init (void)
-{
- POA_GNOME_Evolution_Importer__vepv *vepv;
- POA_GNOME_Evolution_Importer__epv *epv;
- PortableServer_ServantBase__epv *base_epv;
-
- base_epv = g_new0 (PortableServer_ServantBase__epv, 1);
-
- epv = g_new0 (POA_GNOME_Evolution_Importer__epv, 1);
- epv->supportFormat = impl_GNOME_Evolution_Importer_supportFormat;
- epv->loadFile = impl_GNOME_Evolution_Importer_loadFile;
- epv->processItem = impl_GNOME_Evolution_Importer_processItem;
- epv->getError = impl_GNOME_Evolution_Importer_getError;
-
- vepv = &Importer_vepv;
- vepv->_base_epv = base_epv;
- vepv->Bonobo_Unknown_epv = bonobo_object_get_epv ();
- vepv->GNOME_Evolution_Importer_epv = epv;
-}
-
-static void
-class_init (EvolutionImporterClass *klass)
+evolution_importer_class_init (EvolutionImporterClass *klass)
{
GtkObjectClass *object_class;
+ POA_GNOME_Evolution_Importer__epv *epv = &klass->epv;
object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = destroy;
parent_class = gtk_type_class (PARENT_TYPE);
- corba_class_init ();
+ epv->supportFormat = impl_GNOME_Evolution_Importer_supportFormat;
+ epv->loadFile = impl_GNOME_Evolution_Importer_loadFile;
+ epv->processItem = impl_GNOME_Evolution_Importer_processItem;
+ epv->getError = impl_GNOME_Evolution_Importer_getError;
}
static void
-init (EvolutionImporter *importer)
+evolution_importer_init (EvolutionImporter *importer)
{
EvolutionImporterPrivate *priv;
priv = g_new0 (EvolutionImporterPrivate, 1);
- importer->private = priv;
+ importer->priv = priv;
}
static void
evolution_importer_construct (EvolutionImporter *importer,
- GNOME_Evolution_Importer corba_object,
EvolutionImporterSupportFormatFn support_format_fn,
EvolutionImporterLoadFileFn load_file_fn,
EvolutionImporterProcessItemFn process_item_fn,
@@ -225,14 +181,11 @@ evolution_importer_construct (EvolutionImporter *importer,
g_return_if_fail (importer != NULL);
g_return_if_fail (EVOLUTION_IS_IMPORTER (importer));
- g_return_if_fail (corba_object != CORBA_OBJECT_NIL);
g_return_if_fail (support_format_fn != NULL);
g_return_if_fail (load_file_fn != NULL);
g_return_if_fail (process_item_fn != NULL);
- bonobo_object_construct (BONOBO_OBJECT (importer), corba_object);
-
- priv = importer->private;
+ priv = importer->priv;
priv->support_format_fn = support_format_fn;
priv->load_file_fn = load_file_fn;
priv->process_item_fn = process_item_fn;
@@ -262,21 +215,14 @@ evolution_importer_new (EvolutionImporterSupportFormatFn support_format_fn,
void *closure)
{
EvolutionImporter *importer;
- POA_GNOME_Evolution_Importer *servant;
- GNOME_Evolution_Importer corba_object;
-
- servant = create_servant ();
- if (servant == NULL)
- return NULL;
importer = gtk_type_new (evolution_importer_get_type ());
- corba_object = bonobo_object_activate_servant (BONOBO_OBJECT (importer),
- servant);
- evolution_importer_construct (importer, corba_object,
- support_format_fn, load_file_fn,
+ evolution_importer_construct (importer, support_format_fn, load_file_fn,
process_item_fn, get_error_fn, closure);
return importer;
}
-E_MAKE_TYPE (evolution_importer, "EvolutionImporter", EvolutionImporter,
- class_init, init, PARENT_TYPE);
+BONOBO_X_TYPE_FUNC_FULL (EvolutionImporter,
+ GNOME_Evolution_Importer,
+ PARENT_TYPE,
+ evolution_importer);
diff --git a/shell/importer/evolution-importer.h b/shell/importer/evolution-importer.h
index fa5c944c2c..a5f6e07e87 100644
--- a/shell/importer/evolution-importer.h
+++ b/shell/importer/evolution-importer.h
@@ -24,7 +24,8 @@
#ifndef EVOLUTION_IMPORTER_H
#define EVOLUTION_IMPORTER_H
-#include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-xobject.h>
+#include <importer/GNOME_Evolution_Importer.h>
#ifdef __cplusplus
extern "C" {
@@ -67,13 +68,15 @@ typedef enum {
} EvolutionImporterResult;
struct _EvolutionImporter {
- BonoboObject parent;
-
- EvolutionImporterPrivate *private;
+ BonoboXObject parent;
+
+ EvolutionImporterPrivate *priv;
};
struct _EvolutionImporterClass {
- BonoboObjectClass parent_class;
+ BonoboXObjectClass parent_class;
+
+ POA_GNOME_Evolution_Importer__epv epv;
};
GtkType evolution_importer_get_type (void);
diff --git a/shell/importer/evolution-intelligent-importer.c b/shell/importer/evolution-intelligent-importer.c
new file mode 100644
index 0000000000..0149d48f97
--- /dev/null
+++ b/shell/importer/evolution-intelligent-importer.c
@@ -0,0 +1,198 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* evolution-intelligent-importer.c
+ *
+ * Copyright (C) 2000, 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Iain Holmes <iain@ximian.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-object.h>
+
+#include "GNOME_Evolution_Importer.h"
+#include "evolution-intelligent-importer.h"
+
+
+#define PARENT_TYPE BONOBO_X_OBJECT_TYPE
+static BonoboObjectClass *parent_class = NULL;
+
+struct _EvolutionIntelligentImporterPrivate {
+ EvolutionIntelligentImporterCanImportFn can_import_fn;
+ EvolutionIntelligentImporterImportDataFn import_data_fn;
+
+ char *importername;
+ char *message;
+ void *closure;
+};
+
+
+static inline EvolutionIntelligentImporter *
+evolution_intelligent_importer_from_servant (PortableServer_Servant servant)
+{
+ return EVOLUTION_INTELLIGENT_IMPORTER (bonobo_object_from_servant (servant));
+}
+
+static CORBA_char *
+impl_GNOME_Evolution_IntelligentImporter__get_importername (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ EvolutionIntelligentImporter *ii;
+
+ ii = evolution_intelligent_importer_from_servant (servant);
+
+ return CORBA_string_dup (ii->priv->importername ?
+ ii->priv->importername : "");
+}
+
+static CORBA_char *
+impl_GNOME_Evolution_IntelligentImporter__get_message (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ EvolutionIntelligentImporter *ii;
+
+ ii = evolution_intelligent_importer_from_servant (servant);
+
+ return CORBA_string_dup (ii->priv->message ?
+ ii->priv->message : "");
+}
+
+static CORBA_boolean
+impl_GNOME_Evolution_IntelligentImporter_canImport (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ EvolutionIntelligentImporter *ii;
+ EvolutionIntelligentImporterPrivate *priv;
+
+ ii = evolution_intelligent_importer_from_servant (servant);
+ priv = ii->priv;
+
+ if (priv->can_import_fn != NULL)
+ return (priv->can_import_fn) (ii, priv->closure);
+ else
+ return FALSE;
+}
+
+static void
+impl_GNOME_Evolution_IntelligentImporter_importData (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ EvolutionIntelligentImporter *ii;
+ EvolutionIntelligentImporterPrivate *priv;
+
+ ii = evolution_intelligent_importer_from_servant (servant);
+ priv = ii->priv;
+
+ if (priv->import_data_fn)
+ (priv->import_data_fn) (ii, priv->closure);
+}
+
+
+static void
+destroy (GtkObject *object)
+{
+ EvolutionIntelligentImporter *ii;
+
+ ii = EVOLUTION_INTELLIGENT_IMPORTER (object);
+
+ if (ii->priv == NULL)
+ return;
+
+ g_free (ii->priv->importername);
+ g_free (ii->priv);
+ ii->priv = NULL;
+
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
+
+static void
+evolution_intelligent_importer_class_init (EvolutionIntelligentImporterClass *klass)
+{
+ GtkObjectClass *object_class;
+ POA_GNOME_Evolution_IntelligentImporter__epv *epv = &klass->epv;
+
+ object_class = GTK_OBJECT_CLASS (klass);
+ object_class->destroy = destroy;
+
+ parent_class = gtk_type_class (PARENT_TYPE);
+ epv->_get_importername = impl_GNOME_Evolution_IntelligentImporter__get_importername;
+ epv->_get_message = impl_GNOME_Evolution_IntelligentImporter__get_message;
+ epv->canImport = impl_GNOME_Evolution_IntelligentImporter_canImport;
+ epv->importData = impl_GNOME_Evolution_IntelligentImporter_importData;
+}
+
+static void
+evolution_intelligent_importer_init (EvolutionIntelligentImporter *ii)
+{
+ ii->priv = g_new0 (EvolutionIntelligentImporterPrivate, 1);
+}
+
+
+static void
+evolution_intelligent_importer_construct (EvolutionIntelligentImporter *ii,
+ EvolutionIntelligentImporterCanImportFn can_import_fn,
+ EvolutionIntelligentImporterImportDataFn import_data_fn,
+ const char *importername,
+ const char *message,
+ void *closure)
+{
+ g_return_if_fail (ii != NULL);
+ ii->priv->importername = g_strdup (importername);
+ ii->priv->message = g_strdup (message);
+
+ ii->priv->can_import_fn = can_import_fn;
+ ii->priv->import_data_fn = import_data_fn;
+ ii->priv->closure = closure;
+}
+
+/**
+ * evolution_intelligent_importer_new:
+ * can_import_fn: The function that will be called to see if this importer can do
+ * anything.
+ * import_data_fn: The function that will be called when the importer should
+ * import the data.
+ * importername: The name of this importer.
+ * message: The message that will be displayed when the importer can import.
+ * closure: The data to be passed to @can_import_fn and @import_data_fn.
+ *
+ * Creates a new IntelligentImporter.
+ *
+ * Returns: A newly allocated EvolutionIntelligentImporter.
+ */
+EvolutionIntelligentImporter *
+evolution_intelligent_importer_new (EvolutionIntelligentImporterCanImportFn can_import_fn,
+ EvolutionIntelligentImporterImportDataFn import_data_fn,
+ const char *importername,
+ const char *message,
+ void *closure)
+{
+ EvolutionIntelligentImporter *ii;
+
+ ii = gtk_type_new (evolution_intelligent_importer_get_type ());
+ evolution_intelligent_importer_construct (ii, can_import_fn,
+ import_data_fn, importername,
+ message, closure);
+ return ii;
+}
+
+BONOBO_X_TYPE_FUNC_FULL (EvolutionIntelligentImporter,
+ GNOME_Evolution_IntelligentImporter,
+ PARENT_TYPE,
+ evolution_intelligent_importer);
diff --git a/shell/importer/evolution-intelligent-importer.h b/shell/importer/evolution-intelligent-importer.h
new file mode 100644
index 0000000000..1714a2a046
--- /dev/null
+++ b/shell/importer/evolution-intelligent-importer.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* evolution-intelligent-importer.h
+ *
+ * Copyright (C) 2000 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Iain Holmes <iain@ximian.com>
+ */
+
+#ifndef EVOLUTION_INTELLIGENT_IMPORTER_H
+#define EVOLUTION_INTELLIGENT_IMPORTER_H
+
+#include <bonobo/bonobo-xobject.h>
+#include <importer/GNOME_Evolution_Importer.h>
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+#define EVOLUTION_TYPE_INTELLIGENT_IMPORTER (evolution_intelligent_importer_get_type ())
+#define EVOLUTION_INTELLIGENT_IMPORTER(obj) (GTK_CHECK_CAST ((obj), EVOLUTION_TYPE_INTELLIGENT_IMPORTER, EvolutionIntelligentImporter))
+#define EVOLUTION_INTELLIGENT_IMPORTER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), EVOLUTION_TYPE_INTELLIGENT_IMPORTER, EvolutionIntelligentImporterClass))
+#define EVOLUTION_IS_INTELLIGENT_IMPORTER(obj) (GTK_CHECK_TYPE ((obj), EVOLUTION_TYPE_INTELLIGENT_IMPORTER))
+#define EVOLUTION_IS_INTELLIGENT_IMPORTER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), EVOLUTION_TYPE_INTELLIGENT_IMPORTER))
+
+typedef struct _EvolutionIntelligentImporter EvolutionIntelligentImporter;
+typedef struct _EvolutionIntelligentImporterPrivate EvolutionIntelligentImporterPrivate;
+typedef struct _EvolutionIntelligentImporterClass EvolutionIntelligentImporterClass;
+
+typedef gboolean (* EvolutionIntelligentImporterCanImportFn) (EvolutionIntelligentImporter *ii,
+ void *closure);
+typedef void (* EvolutionIntelligentImporterImportDataFn) (EvolutionIntelligentImporter *ii,
+ void *closure);
+
+struct _EvolutionIntelligentImporter {
+ BonoboXObject parent;
+
+ EvolutionIntelligentImporterPrivate *priv;
+};
+
+struct _EvolutionIntelligentImporterClass {
+ BonoboXObjectClass parent_class;
+
+ POA_GNOME_Evolution_IntelligentImporter__epv epv;
+};
+
+GtkType evolution_intelligent_importer_get_type (void);
+
+EvolutionIntelligentImporter *evolution_intelligent_importer_new (EvolutionIntelligentImporterCanImportFn can_import_fn,
+ EvolutionIntelligentImporterImportDataFn import_data_fn,
+ const char *importername,
+ const char *message,
+ void *closure);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/shell/importer/intelligent.c b/shell/importer/intelligent.c
new file mode 100644
index 0000000000..e3f0f4b03b
--- /dev/null
+++ b/shell/importer/intelligent.c
@@ -0,0 +1,174 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* intelligent.c
+ *
+ * Authors:
+ * Iain Holmes <iain@ximian.com>
+ *
+ * Copyright 2001 Ximian, Inc. (http://www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gnome.h>
+
+#include <liboaf/liboaf.h>
+
+#include "intelligent.h"
+#include "GNOME_Evolution_Importer.h"
+
+static void
+start_importer (const char *iid)
+{
+ CORBA_Object importer;
+ CORBA_Environment ev;
+ CORBA_char *name;
+ CORBA_char *message;
+ CORBA_boolean can_run;
+
+ GtkWidget *dialog, *label;
+ char *str;
+
+ if (iid == NULL || *iid == '\0')
+ return;
+
+ CORBA_exception_init (&ev);
+ importer = oaf_activate_from_id ((char *) iid, 0, NULL, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free (&ev);
+ g_warning ("Could not start %s", iid);
+ return;
+ }
+
+ CORBA_exception_free (&ev);
+ if (importer == CORBA_OBJECT_NIL) {
+ g_warning ("Could not activate_component %s", iid);
+ return;
+ }
+
+ CORBA_exception_init (&ev);
+ can_run = GNOME_Evolution_IntelligentImporter_canImport (importer, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ g_warning ("Could not get canImport(%s): %s", iid, CORBA_exception_id (&ev));
+ CORBA_Object_release (importer, &ev);
+ CORBA_exception_free (&ev);
+ return;
+ }
+ CORBA_exception_free (&ev);
+
+ if (can_run == FALSE) {
+ return;
+ }
+
+ name = GNOME_Evolution_IntelligentImporter__get_importername (importer,
+ &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ g_warning ("Could not get name(%s): %s", iid, CORBA_exception_id (&ev));
+ CORBA_Object_release (importer, &ev);
+ CORBA_exception_free (&ev);
+ return;
+ }
+ message = GNOME_Evolution_IntelligentImporter__get_message (importer, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ g_warning ("Could not get message(%s): %s", iid, CORBA_exception_id (&ev));
+ CORBA_Object_release (importer, &ev);
+ CORBA_exception_free (&ev);
+ return;
+ }
+
+ CORBA_exception_free (&ev);
+
+ dialog = gnome_dialog_new ("Import files",
+ GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO,
+ NULL);
+ gtk_window_set_title (GTK_WINDOW (dialog), name);
+ CORBA_free (name);
+
+ label = gtk_label_new (message);
+ CORBA_free (message);
+
+ gtk_box_pack_start (GNOME_DIALOG (dialog)->vbox, label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+ switch (gnome_dialog_run_and_close (GNOME_DIALOG (dialog))) {
+ case 0:
+ /* Yes */
+#if 0
+ /* This sucks */
+ dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ label = gtk_label_new ("Importing");
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ gtk_container_add (GTK_CONTAINER (dialog), label);
+ gtk_widget_show_all (dialog);
+#endif
+
+ GNOME_Evolution_IntelligentImporter_importData (importer, &ev);
+ break;
+ case 1:
+ case -1:
+ default:
+ /* No */
+ break;
+ }
+
+ CORBA_exception_init (&ev);
+ CORBA_Object_release (importer, &ev);
+ CORBA_exception_free (&ev);
+}
+
+
+static GList *
+get_intelligent_importers (void)
+{
+ OAF_ServerInfoList *info_list;
+ GList *iids_ret = NULL;
+ CORBA_Environment ev;
+ int i;
+
+ CORBA_exception_init (&ev);
+ info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/IntelligentImporter:1.0')", NULL, &ev);
+ CORBA_exception_free (&ev);
+
+ for (i = 0; i < info_list->_length; i++) {
+ const OAF_ServerInfo *info;
+
+ info = info_list->_buffer + i;
+ iids_ret = g_list_prepend (iids_ret, g_strdup (info->iid));
+ }
+
+ return iids_ret;
+}
+
+void
+intelligent_importer_init (void)
+{
+ GList *importers, *l;
+
+ importers = get_intelligent_importers ();
+ if (importers == NULL)
+ return; /* No intelligent importers. Easy :) */
+
+ /* Loop through each importer, running it. */
+ for (l = importers; l; l = l->next) {
+ start_importer (l->data);
+ g_free (l->data);
+ }
+
+ g_list_free (importers);
+}
+
diff --git a/shell/importer/intelligent.h b/shell/importer/intelligent.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/shell/importer/intelligent.h