aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend/ebook
diff options
context:
space:
mode:
authorIain Holmes <iain@src.gnome.org>2001-01-12 03:09:03 +0800
committerIain Holmes <iain@src.gnome.org>2001-01-12 03:09:03 +0800
commit76db8f7ba9e9d947a715c2ec5501fd481671dbd3 (patch)
treeff5631f1aadefe6948e27225c1d9553a1b739476 /addressbook/backend/ebook
parent0fd4de8110c0dc2aebd29dc40434a9629e6a5d27 (diff)
downloadgsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.tar
gsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.tar.gz
gsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.tar.bz2
gsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.tar.lz
gsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.tar.xz
gsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.tar.zst
gsoc2013-evolution-76db8f7ba9e9d947a715c2ec5501fd481671dbd3.zip
GnomeCard importer
svn path=/trunk/; revision=7399
Diffstat (limited to 'addressbook/backend/ebook')
-rw-r--r--addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oaf.in30
-rw-r--r--addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oafinfo30
-rw-r--r--addressbook/backend/ebook/Makefile.am17
-rw-r--r--addressbook/backend/ebook/evolution-gnomecard-importer.c217
4 files changed, 293 insertions, 1 deletions
diff --git a/addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oaf.in b/addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oaf.in
new file mode 100644
index 0000000000..e6a4a3ed40
--- /dev/null
+++ b/addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oaf.in
@@ -0,0 +1,30 @@
+<oaf_info>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_GnomeCard_ImporterFactory"
+ type="exe"
+ location="evolution-gnomecard-importer">
+
+ <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 GnomeCard files into Evolution."/>
+</oaf_server>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_GnomeCard_Importer"
+ type="factory"
+ location="OAFIID:GNOME_Evolution_Addressbook_GnomeCard_ImporterFactory">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/Evolution/ImporterFactory:1.0"/>
+ <item value="IDL:GNOME/Evolution/Importer:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="evolution:menu-name" type="string"
+ value="GnomeCard (.vcf, .gcrd)"/>
+ <oaf_attribute name="description" type="string"
+ value="Imports GnomeCard files into Evolution."/>
+</oaf_server>
+
+</oaf_info>
diff --git a/addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oafinfo b/addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oafinfo
new file mode 100644
index 0000000000..e6a4a3ed40
--- /dev/null
+++ b/addressbook/backend/ebook/GNOME_Evolution_Addressbook_GnomeCard_Importer.oafinfo
@@ -0,0 +1,30 @@
+<oaf_info>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_GnomeCard_ImporterFactory"
+ type="exe"
+ location="evolution-gnomecard-importer">
+
+ <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 GnomeCard files into Evolution."/>
+</oaf_server>
+
+<oaf_server iid="OAFIID:GNOME_Evolution_Addressbook_GnomeCard_Importer"
+ type="factory"
+ location="OAFIID:GNOME_Evolution_Addressbook_GnomeCard_ImporterFactory">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/Evolution/ImporterFactory:1.0"/>
+ <item value="IDL:GNOME/Evolution/Importer:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="evolution:menu-name" type="string"
+ value="GnomeCard (.vcf, .gcrd)"/>
+ <oaf_attribute name="description" type="string"
+ value="Imports GnomeCard files into Evolution."/>
+</oaf_server>
+
+</oaf_info>
diff --git a/addressbook/backend/ebook/Makefile.am b/addressbook/backend/ebook/Makefile.am
index 4262cb8394..771f3e9d76 100644
--- a/addressbook/backend/ebook/Makefile.am
+++ b/addressbook/backend/ebook/Makefile.am
@@ -1,6 +1,7 @@
noinst_PROGRAMS = test-card test-client test-client-list
-bin_PROGRAMS = load-pine-addressbook load-gnomecard-addressbook
+bin_PROGRAMS = evolution-gnomecard-importer \
+ load-pine-addressbook load-gnomecard-addressbook
CORBA_SOURCE = \
addressbook.h \
@@ -29,6 +30,7 @@ INCLUDES = \
-I$(top_srcdir)/addressbook/ename \
-I$(top_builddir)/addressbook/backend \
-I$(top_builddir)/addressbook/ename \
+ -I$(top_builddir)/shell/importer \
$(BONOBO_GNOME_CFLAGS) \
$(EXTRA_GNOME_CFLAGS)
@@ -100,6 +102,16 @@ test_card_LDADD = \
$(top_builddir)/libversit/libversit.la \
$(top_builddir)/e-util/libeutil.la
+evolution_gnomecard_importer_SOURCES = \
+ evolution-gnomecard-importer.c
+evolution_gnomecard_importer_LDADD = \
+ libebook.la \
+ $(BONOBO_GNOME_LIBS) \
+ $(EXTRA_GNOME_LIBS) \
+ $(top_builddir)/e-util/ename/libename.la \
+ $(top_builddir)/libversit/libversit.la \
+ $(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/shell/importer/libevolution-importer.la
load_pine_addressbook_SOURCES = \
load-pine-addressbook.c
@@ -127,3 +139,6 @@ load_gnomecard_addressbook_LDADD = \
BUILT_SOURCES = $(CORBA_SOURCE)
CLEANFILES += $(BUILT_SOURCES)
+
+oafdir = $(datadir)/oaf
+oaf_DATA = GNOME_Evolution_Addressbook_GnomeCard_Importer.oafinfo
diff --git a/addressbook/backend/ebook/evolution-gnomecard-importer.c b/addressbook/backend/ebook/evolution-gnomecard-importer.c
new file mode 100644
index 0000000000..1961e2abc7
--- /dev/null
+++ b/addressbook/backend/ebook/evolution-gnomecard-importer.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#include <config.h>
+#include <bonobo.h>
+#include <gnome.h>
+#include <liboaf/liboaf.h>
+#include <stdio.h>
+
+#include <e-book.h>
+
+#include <evolution-importer.h>
+#include <evolution-importer-factory.h>
+#include <GNOME_Evolution_Importer.h>
+
+#define COMPONENT_FACTORY_IID "OAFIID:GNOME_Evolution_Addressbook_GnomeCard_ImporterFactory"
+
+static BonoboGenericFactory *factory = NULL;
+
+typedef struct {
+ char *filename;
+ GList *cardlist;
+ GList *iterator;
+ EBook *book;
+ gboolean ready;
+} GnomeCardImporter;
+
+static void
+add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
+{
+ ECard *card = E_CARD(closure);
+ char *vcard = e_card_get_vcard(card);
+ g_print ("Saved card: %s\n", vcard);
+ g_free(vcard);
+ gtk_object_unref(GTK_OBJECT(card));
+}
+
+static void
+book_open_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+ GnomeCardImporter *gci = (GnomeCardImporter *) closure;
+
+ gci->cardlist = e_card_load_cards_from_file(gci->filename);
+ gci->ready = TRUE;
+}
+
+static void
+ebook_create (GnomeCardImporter *gci)
+{
+ gchar *path, *uri;
+
+ gci->book = e_book_new ();
+
+ if (!gci->book) {
+ printf ("%s: %s(): Couldn't create EBook, bailing.\n",
+ __FILE__,
+ __FUNCTION__);
+ return;
+ }
+
+ path = g_concat_dir_and_file (g_get_home_dir (),
+ "evolution/local/Contacts/addressbook.db");
+ uri = g_strdup_printf ("file://%s", path);
+ g_free (path);
+
+ if (! e_book_load_uri (gci->book, uri, book_open_cb, gci)) {
+ printf ("error calling load_uri!\n");
+ }
+ g_free(uri);
+}
+
+/* EvolutionImporter methods */
+static void
+process_item_fn (EvolutionImporter *importer,
+ GNOME_Evolution_ImporterListener listener,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ GnomeCardImporter *gci = (GnomeCardImporter *) closure;
+ ECard *card;
+
+ if (gci->iterator == NULL)
+ gci->iterator = gci->cardlist;
+
+ if (gci->ready == FALSE) {
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_NOT_READY,
+ gci->iterator ? TRUE : FALSE,
+ ev);
+ return;
+ }
+
+ if (gci->iterator == NULL) {
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_UNSUPPORTED_OPERATION,
+ FALSE, ev);
+ return;
+ }
+
+ card = gci->iterator->data;
+ e_book_add_card (gci->book, card, add_card_cb, card);
+
+ gci->iterator = gci->iterator->next;
+
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_OK,
+ gci->iterator ? TRUE : FALSE,
+ ev);
+ if (ev->_major != CORBA_NO_EXCEPTION) {
+ g_warning ("Error notifying listeners.");
+ }
+
+ return;
+}
+
+static char *
+get_error_fn (EvolutionImporter *importer,
+ void *closure)
+{
+ return NULL;
+}
+
+/* EvolutionImporterFactory methods */
+
+static char *supported_extensions[3] = {
+ ".vcf", ".gcrd", NULL
+};
+
+static gboolean
+support_format_fn (EvolutionImporterFactory *_factory,
+ const char *filename,
+ void *closure)
+{
+ char *ext;
+ int i;
+
+ ext = strrchr (filename, '.');
+ for (i = 0; supported_extensions[i] != NULL; i++) {
+ if (strcmp (supported_extensions[i], ext) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+importer_destroy_cb (GtkObject *object,
+ GnomeCardImporter *gci)
+{
+ gtk_main_quit ();
+}
+
+static EvolutionImporter *
+load_file_fn (EvolutionImporterFactory *_factory,
+ const char *filename,
+ void *closure)
+{
+ EvolutionImporter *importer;
+ GnomeCardImporter *gci;
+
+ gci = g_new (GnomeCardImporter, 1);
+ gci->filename = g_strdup (filename);
+ gci->cardlist = NULL;
+ gci->iterator = NULL;
+ gci->ready = FALSE;
+ ebook_create (gci);
+
+ importer = evolution_importer_new (process_item_fn, get_error_fn, gci);
+ gtk_signal_connect (GTK_OBJECT (importer), "destroy",
+ GTK_SIGNAL_FUNC (importer_destroy_cb), gci);
+
+ return importer;
+}
+
+static BonoboObject *
+factory_fn (BonoboGenericFactory *_factory,
+ void *closure)
+{
+ EvolutionImporterFactory *importer_factory;
+ importer_factory = evolution_importer_factory_new (support_format_fn,
+ load_file_fn, NULL);
+ return BONOBO_OBJECT (importer_factory);
+}
+
+static void
+importer_init (void)
+{
+ if (factory != NULL)
+ return;
+
+ factory = bonobo_generic_factory_new (COMPONENT_FACTORY_IID,
+ factory_fn, NULL);
+
+ if (factory == NULL) {
+ g_error ("Unable to create factory");
+ }
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ CORBA_ORB orb;
+
+ gnome_init_with_popt_table ("Evolution-GnomeCard-Importer",
+ "0.0", argc, argv, oaf_popt_options, 0,
+ NULL);
+ orb = oaf_init (argc, argv);
+ if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) {
+ g_error ("Could not initialize Bonobo.");
+ }
+
+ importer_init ();
+ bonobo_main ();
+
+ return 0;
+}
+
+