From d4fd9c55c7f5d5b7ad3f0bf1c4a2481023f7bceb Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 18 Oct 2001 21:18:25 +0000 Subject: Bumped the required version of gal to 0.15.99.1 for use in 2001-10-18 Christopher James Lahey * 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 --- ChangeLog | 24 ++++++++++ configure.in | 2 +- tools/.cvsignore | 6 ++- tools/Makefile.am | 41 +++++++++++++++- tools/evolution-addressbook-clean.in | 24 ++++++++++ tools/evolution-addressbook-export.c | 67 ++++++++++++++++++++++++++ tools/evolution-addressbook-import.c | 93 ++++++++++++++++++++++++++++++++++++ 7 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 tools/evolution-addressbook-clean.in create mode 100644 tools/evolution-addressbook-export.c create mode 100644 tools/evolution-addressbook-import.c diff --git a/ChangeLog b/ChangeLog index bbbf1a0d3c..63c27085ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2001-10-18 Christopher James Lahey + + * 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. + 2001-10-18 Wang Jian * configure.in(ALL_LINGUAS): Added zh_CN for Simplified Chinese. diff --git a/configure.in b/configure.in index d0cb7a484c..d5f28df685 100644 --- a/configure.in +++ b/configure.in @@ -571,7 +571,7 @@ EVO_CHECK_LIB(Bonobo, bonobox, 1.0.3) EVO_CHECK_LIB(OAF, oaf, 0.6.2) EVO_CHECK_LIB(libglade, libglade, 0.14) EVO_CHECK_LIB(gdk-pixbuf with GNOME canvas support, gnomecanvaspixbuf, 0.9.0) -EVO_CHECK_LIB(GAL, gal, 0.14) +EVO_CHECK_LIB(GAL, gal, 0.15.99.1) EVO_CHECK_LIB(GtkHTML, gtkhtml, 0.15) EVO_CHECK_LIB(GNOME-VFS, vfs, 1.0) EVO_CHECK_LIB(libxml, xml, 1.8.10, 2.0) diff --git a/tools/.cvsignore b/tools/.cvsignore index 36a2ee1e24..22a085436b 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -1,3 +1,7 @@ Makefile Makefile.in -.deps \ No newline at end of file +evolution-addressbook-clean +evolution-addressbook-import +evolution-addressbook-export +.deps +.libs \ No newline at end of file diff --git a/tools/Makefile.am b/tools/Makefile.am index cd69457f3e..4b5516d28f 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,3 +1,42 @@ -bin_SCRIPTS = killev evolution-move-tasks +bin_SCRIPTS = killev evolution-move-tasks evolution-addressbook-clean +bin_PROGRAMS = evolution-addressbook-import evolution-addressbook-export + +EXTRA_DIST = \ + evolution-addressbook-clean.in + +INCLUDES = \ + -DG_LOG_DOMAIN=\"evolution-tools\" \ + $(EXTRA_GNOME_CFLAGS) \ + $(GNOME_INCLUDEDIR) \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + $(BONOBO_HTML_GNOME_CFLAGS) \ + -DEVOLUTION_BINDIR=\""$(bindir)"\" \ + -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ + -I$(top_srcdir)/addressbook EXTRA_DIST = $(bin_SCRIPTS) verify-evolution-install.sh + +evolution_addressbook_import_LDADD = \ + $(EXTRA_GNOME_LIBS) \ + $(BONOBO_HTML_GNOME_LIBS) \ + $(BONOBO_CONF_LIBS) \ + $(top_builddir)/addressbook/backend/ebook/libebook.la \ + $(top_builddir)/camel/libcamel.la \ + $(top_builddir)/libibex/libibex.la \ + $(top_builddir)/e-util/ename/libename.la \ + $(top_builddir)/libversit/libversit.la \ + $(top_builddir)/e-util/libeutil.la \ + $(top_builddir)/widgets/menus/libmenus.la + +evolution_addressbook_export_LDADD = \ + $(evolution_addressbook_import_LDADD) + +CLEANFILES = evolution-addressbook-clean + + +evolution-addressbook-clean: evolution-addressbook-clean.in Makefile +## Use sed and then mv to avoid problems if the user interrupts. + sed -e 's?\@EVOLUTION_BINDIR\@?$(bindir)?g' \ + < $(srcdir)/evolution-addressbook-clean.in > evolution-addressbook-clean.tmp \ + && mv evolution-addressbook-clean.tmp evolution-addressbook-clean diff --git a/tools/evolution-addressbook-clean.in b/tools/evolution-addressbook-clean.in new file mode 100644 index 0000000000..ec407296da --- /dev/null +++ b/tools/evolution-addressbook-clean.in @@ -0,0 +1,24 @@ +#! /usr/bin/perl -w + +sub do_system +{ + my ($command) = @_; + system ($command); + if ($? != 0) { + die "Command failed: $command"; + } +} + +$filename = `@EVOLUTION_BINDIR@/evolution-addressbook-export`; +if ($? != 0) { + $! = $?; + die $!; +} + +$HOME = $ENV{"HOME"}; + +system ("@EVOLUTION_BINDIR@/killev"); +do_system ("/bin/mv ${HOME}/evolution/local/Contacts/addressbook.db ${HOME}/evolution/local/Contacts/addressbook-backup.db"); +do_system ("@EVOLUTION_BINDIR@/evolution-addressbook-import --input-file $filename"); +do_system ("/bin/rm $filename"); + diff --git a/tools/evolution-addressbook-export.c b/tools/evolution-addressbook-export.c new file mode 100644 index 0000000000..cfc0237a02 --- /dev/null +++ b/tools/evolution-addressbook-export.c @@ -0,0 +1,67 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +#include + +#include +#include +#include +#include +#include +#include + +static void +save_cards (EBook *book, EBookSimpleQueryStatus status, const GList *cards, gpointer closure) +{ + char *filename = closure; + char *vcard; + int result; + /* This has to be an array so that it's not const. */ + char tmpname[] = "/tmp/evo-addressbook-tmp.XXXXXX"; + + vcard = e_card_list_get_vcard (cards); + + if (filename) + result = e_write_file (filename, vcard, O_CREAT | O_EXCL); + else + result = e_write_file_mkstemp (tmpname, vcard); + printf (tmpname); + sync(); + gtk_exit (result); +} + +static void +use_addressbook (EBook *book, gpointer closure) +{ + if (book == NULL) + g_error (_("Error loading default addressbook.")); + e_book_simple_query (book, "(contains \"x-evolution-any-field\" \"\")", save_cards, closure); +} + +int +main (int argc, char *argv[]) +{ + char *filename = NULL; + + struct poptOption options[] = { + { "output-file", '\0', POPT_ARG_STRING, &filename, 0, N_("Output 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); + 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; +} 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 + +#include +#include +#include +#include + +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; +} -- cgit v1.2.3