aboutsummaryrefslogtreecommitdiffstats
path: root/tools/evolution-addressbook-import.c
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-10-19 05:18:25 +0800
committerChris Lahey <clahey@src.gnome.org>2001-10-19 05:18:25 +0800
commitd4fd9c55c7f5d5b7ad3f0bf1c4a2481023f7bceb (patch)
tree0345248e002c380e1eff080933d05ca7353118d4 /tools/evolution-addressbook-import.c
parent8589cb087050e616facdba00e79479868b08c07f (diff)
downloadgsoc2013-evolution-d4fd9c55c7f5d5b7ad3f0bf1c4a2481023f7bceb.tar.gz
gsoc2013-evolution-d4fd9c55c7f5d5b7ad3f0bf1c4a2481023f7bceb.tar.zst
gsoc2013-evolution-d4fd9c55c7f5d5b7ad3f0bf1c4a2481023f7bceb.zip
Bumped the required version of gal to 0.15.99.1 for use in
2001-10-18 Christopher James Lahey <clahey@ximian.com> * configure.in: Bumped the required version of gal to 0.15.99.1 for use in evolution-addressbook-export. * tools/.cvsignore: Added evolution-addressbook-clean, evolution-addressbook-export, evolution-addressbook-import, and .libs. * tools/Makefile.am: Added evolution-addressbook-clean, evolution-addressbook-export, and evolution-addressbook-import. * tools/evolution-addressbook-clean.in: Main script to clean up the local contact database. * tools/evolution-addressbook-export.c: Exports the local addressbook to the specified file (--output-file). If no --output-file is given, writes out to a unique file in the /tmp directory. In either case, prints the filename to stdout. * tools/evolution-addressbook-import.c: Imports the specified file (--input-file) to the local addressbook. svn path=/trunk/; revision=13774
Diffstat (limited to 'tools/evolution-addressbook-import.c')
-rw-r--r--tools/evolution-addressbook-import.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/evolution-addressbook-import.c b/tools/evolution-addressbook-import.c
new file mode 100644
index 0000000000..9d79ccae0d
--- /dev/null
+++ b/tools/evolution-addressbook-import.c
@@ -0,0 +1,93 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <config.h>
+
+#include <liboaf/liboaf.h>
+#include <bonobo/bonobo-main.h>
+#include <backend/ebook/e-book-util.h>
+#include <gnome.h>
+
+static int exec_ref_count = 0;
+
+static void
+ref_executable (void)
+{
+ exec_ref_count ++;
+}
+
+static void
+unref_executable (void)
+{
+ exec_ref_count --;
+ if (exec_ref_count == 0)
+ gtk_exit (0);
+}
+
+static void
+add_cb (EBook *book, EBookStatus status, const char *id, gpointer closure)
+{
+ switch (status) {
+ case E_BOOK_STATUS_SUCCESS:
+ unref_executable ();
+ break;
+ default:
+ gtk_exit (status);
+ break;
+ }
+}
+
+static void
+use_addressbook (EBook *book, gpointer closure)
+{
+ GList *cards, *list;
+ char *filename = closure;
+
+ if (book == NULL)
+ g_error (_("Error loading default addressbook."));
+
+ cards = e_card_load_cards_from_file (filename);
+
+ ref_executable ();
+
+ for (list = cards; list; list = list->next) {
+ ref_executable ();
+ e_book_add_card (book, list->data, add_cb, closure);
+ }
+ sync();
+
+ unref_executable ();
+}
+
+int
+main (int argc, char *argv[])
+{
+ char *filename = NULL;
+
+ struct poptOption options[] = {
+ { "input-file", '\0', POPT_ARG_STRING, &filename, 0, N_("Input File"), NULL },
+ { NULL, '\0', POPT_ARG_INCLUDE_TABLE, &oaf_popt_options, 0, NULL, NULL },
+ POPT_AUTOHELP
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ };
+
+ bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR);
+ textdomain (PACKAGE);
+
+ gnome_init_with_popt_table ("evolution-addressbook-clean", "0.0",
+ argc, argv, options, 0, NULL);
+
+ if (filename == NULL) {
+ g_error (_("No filename provided."));
+ }
+
+ oaf_init (argc, argv);
+
+ if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE)
+ g_error (_("Could not initialize Bonobo"));
+
+ e_book_use_local_address_book (use_addressbook, filename);
+
+ bonobo_main ();
+
+ return 0;
+}