From 94bc9ecd27c2fd9cf0c00adbca8b454ed767cf18 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Sat, 29 Jul 2000 15:04:56 +0000 Subject: Added load-gnomecard-addressbook compilation. 2000-07-29 Christopher James Lahey * backend/ebook/Makefile.am: Added load-gnomecard-addressbook compilation. * backend/ebook/e-card.c, backend/ebook/e-card.h: Added e_card_load_cards_from_file helper function to load multiple cards from a single file. * backend/ebook/load-gnomecard-addressbook.c: New file to load vcard files. I think this is the format that gnomecard uses so if you copy your gnomecard file to gnomecard.vcf and then run this program in the same directory, it'll copy all your gnome contacts into evolution. It needs to be changed to take a filename as a parameter. Some fields (phone and address information, for example) aren't displayed properly, but are saved. This is new code, so some other than phone and address may be lost. svn path=/trunk/; revision=4414 --- .../backend/ebook/load-gnomecard-addressbook.c | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 addressbook/backend/ebook/load-gnomecard-addressbook.c (limited to 'addressbook/backend/ebook/load-gnomecard-addressbook.c') diff --git a/addressbook/backend/ebook/load-gnomecard-addressbook.c b/addressbook/backend/ebook/load-gnomecard-addressbook.c new file mode 100644 index 0000000000..f1f20bf50b --- /dev/null +++ b/addressbook/backend/ebook/load-gnomecard-addressbook.c @@ -0,0 +1,110 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#include +#include +#include +#include + +#include + +static CORBA_Environment ev; + +#ifdef USING_OAF + +#include + +static void +init_corba (int *argc, char **argv) +{ + gnome_init_with_popt_table("blah", "0.0", *argc, argv, NULL, 0, NULL); + + oaf_init (*argc, argv); +} + +#else + +#include + +static void +init_corba (int *argc, char **argv) +{ + gnome_CORBA_init_with_popt_table ( + "blah", "0.0", + argc, argv, NULL, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev); +} + +#endif + +static void +init_bonobo (int argc, char **argv) +{ + if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) + g_error (_("Could not initialize Bonobo")); +} + +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) +{ + GList *list = e_card_load_cards_from_file("gnomecard.vcf"); + GList *iterator; + for (iterator = list; iterator; iterator = g_list_next(iterator)) { + ECard *card = iterator->data; + e_book_add_card(book, card, add_card_cb, card); + } + g_list_free(list); +} + +static guint +ebook_create (void) +{ + EBook *book; + gchar *path, *uri; + + book = e_book_new (); + + if (!book) { + printf ("%s: %s(): Couldn't create EBook, bailing.\n", + __FILE__, + __FUNCTION__); + return FALSE; + } + + + 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 (book, uri, book_open_cb, NULL)) { + printf ("error calling load_uri!\n"); + } + g_free(uri); + + + return FALSE; +} + +int +main (int argc, char **argv) +{ + + CORBA_exception_init (&ev); + + init_corba (&argc, argv); + init_bonobo (argc, argv); + + gtk_idle_add ((GtkFunction) ebook_create, NULL); + + bonobo_main (); + + return 0; +} -- cgit v1.2.3