aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/tools
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/tools')
-rw-r--r--addressbook/tools/.cvsignore5
-rw-r--r--addressbook/tools/Makefile.am49
-rwxr-xr-xaddressbook/tools/csv2vcard236
-rw-r--r--addressbook/tools/evolution-addressbook-abuse.c91
-rw-r--r--addressbook/tools/evolution-addressbook-clean.in24
-rw-r--r--addressbook/tools/evolution-addressbook-export-list-cards.c780
-rw-r--r--addressbook/tools/evolution-addressbook-export-list-folders.c99
-rw-r--r--addressbook/tools/evolution-addressbook-export.c162
-rw-r--r--addressbook/tools/evolution-addressbook-export.h81
-rw-r--r--addressbook/tools/evolution-addressbook-import.c90
10 files changed, 0 insertions, 1617 deletions
diff --git a/addressbook/tools/.cvsignore b/addressbook/tools/.cvsignore
deleted file mode 100644
index 25963ae030..0000000000
--- a/addressbook/tools/.cvsignore
+++ /dev/null
@@ -1,5 +0,0 @@
-Makefile
-Makefile.in
-evolution-addressbook-export
-evolution-addressbook-abuse
-evolution-addressbook-clean
diff --git a/addressbook/tools/Makefile.am b/addressbook/tools/Makefile.am
deleted file mode 100644
index fe76abcc08..0000000000
--- a/addressbook/tools/Makefile.am
+++ /dev/null
@@ -1,49 +0,0 @@
-privlibexec_SCRIPTS = \
- csv2vcard \
- evolution-addressbook-clean
-
-bin_PROGRAMS = \
- evolution-addressbook-export
-
-noinst_PROGRAMS= evolution-addressbook-abuse
-
-INCLUDES = \
- -DG_LOG_DOMAIN=\"evolution-addressbook-tools\" \
- -I$(top_srcdir) \
- -I$(top_builddir) \
- -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
- -DPREFIX=\""$(prefix)"\" \
- -DSYSCONFDIR=\""$(sysconfdir)"\" \
- -DDATADIR=\""$(datadir)"\" \
- -DLIBDIR=\""$(libdir)"\" \
- -I$(top_srcdir)/addressbook \
- -I$(top_srcdir)/addressbook/backend \
- -I$(top_builddir)/addressbook/backend \
- $(GNOME_FULL_CFLAGS)
-
-evolution_addressbook_export_SOURCES = \
- evolution-addressbook-export.c \
- evolution-addressbook-export-list-cards.c \
- evolution-addressbook-export-list-folders.c \
- evolution-addressbook-export.h
-
-evolution_addressbook_export_LDADD = \
- $(top_builddir)/addressbook/backend/ebook/libebook.la \
- $(top_builddir)/e-util/ename/libename.la \
- $(top_builddir)/e-util/libeutil.la
-
-evolution_addressbook_abuse_LDADD = \
- $(top_builddir)/addressbook/backend/ebook/libebook.la \
- $(top_builddir)/e-util/ename/libename.la \
- $(top_builddir)/e-util/libeutil.la
-
-EXTRA_DIST = $(privlibexec_SCRIPTS) \
- evolution-addressbook-clean.in
-
-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_TOOLSDIR\@?$(privlibexecdir)?g' \
- < $(srcdir)/evolution-addressbook-clean.in > evolution-addressbook-clean.tmp \
- && mv evolution-addressbook-clean.tmp evolution-addressbook-clean
diff --git a/addressbook/tools/csv2vcard b/addressbook/tools/csv2vcard
deleted file mode 100755
index b968fbd9c3..0000000000
--- a/addressbook/tools/csv2vcard
+++ /dev/null
@@ -1,236 +0,0 @@
-#!/usr/bin/perl -w
-#
-# cvs2vcard - Script to convert Outlook CSV files into VCard files
-# suitable to be imported into Evolution.
-#
-# Copyright (C) 2001 Ximian, Inc.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of version 2 of the GNU General Public
-# License as published by the Free Software Foundation.
-#
-# 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: Michael MacDonald <mjmac@ximian.com>
-#
-
-use strict;
-use diagnostics;
-use Text::ParseWords;
-
-sub usage
-{
- print STDERR << "--EndOfUsage";
-
-Takes a CSV-formatted list of contacts from Outlook and attempts to
-convert it into a list of VCards suitable for import into Evolution.
-
-Usage: $0 [infile outfile]
-
---EndOfUsage
-
- exit;
-}
-
-sub is_recognized_format
-{
- my $line = shift;
-
- # Making some assumptions here... Prolly OK.
- return $line =~ /(First Name|Middle Name|Last Name)/;
-}
-
-sub map_columns
-{
- my $line = shift;
-
- my @names = parse_line(',', 0, $line);
-
- my $ctr = 0;
- my %fieldmap = map { $_ => $ctr++ } @names;
-
- return %fieldmap;
-}
-
-sub build_vcard_attr_from_def
-{
- my ($def, $fields, $map) = @_;
-
- # Valid chars for lookup (from Outlook CSV) are
- # A-Za-z0-9_-'/
- # Valid chars for formatting of attr are
- # \s,|
- my @lookup = map { s/=0A$//; s/[^\w\s\-'\/]//; $_; } split /[\s,]*\|[\s,]*/, $def;
-
- foreach my $el (@lookup) {
- unless (defined($map->{ $el })) {
- print STDERR "$el is undefined\n";
- next;
- }
- if (defined($fields->[$map->{ $el }])) {
- unless ($fields->[$map->{ $el }] =~ /(^$|0\/0\/00)/) {
- $def =~ s/$el/$fields->[$map->{ $el }]/;
- } else {
- $def =~ s/((?<=\|)\s*)?$el(\s*?(?=\|))?(=0A)?,?//;
- }
- } else {
- $def =~ s/((?<=\|)\s*)?$el(\s*?(?=\|))?(=0A)?,?//;
- }
- }
- # Get rid of field delimiters
- $def =~ s/\|//g;
- # Snip off any trailing semicolons or whitespace
- $def =~ s/[\s;]*$//;
-
- return $def;
-}
-
-sub build_vcard_from_line {
- my ($line, %map) = @_;
- my %vcard;
-
- my @fields = parse_line(',', 0, $line);
-
- my %vcard_def = ( FN => 'Title |First Name |Middle Name |Last Name |Suffix',
- N => 'Last Name| Suffix|;First Name|;Middle Name|;Title',
- 'ADR;WORK' => 'PO Box|;Business Street 2|;Business Street|;Business City|;Business State|;Business Postal Code|;Business Country',
- 'LABEL;QUOTED-PRINTABLE;WORK' => 'PO Box |Business Street=0A|Business Street 2=0A|Business City,| Business State| Business Postal Code=0A|Business Country',
- 'TEL;WORK;VOICE' => 'Business Phone',
- 'TEL;WORK;VOICE2' => 'Business Phone 2',
- 'TEL;WORK;FAX' => 'Business Fax',
- 'TEL;WORK;COMPANY' => 'Company Main Phone',
- 'ADR;HOME' => ';Home Street 2|;Home Street|;Home City|;Home State|;Home Postal Code|;Home Country',
- 'LABEL;QUOTED-PRINTABLE;HOME' => 'Home Street=0A|Home Street 2=0A|Home City,| Home State| Home Postal Code=0A|Home Country',
- 'TEL;HOME;VOICE' => 'Home Phone',
- 'TEL;HOME;VOICE2' => 'Home Phone 2',
- 'TEL;HOME;FAX' => 'Home Fax',
- 'ADR;POSTAL' => ';Other Street 2|;Other Street|;Other City|;Other State|;Other Postal Code|;Other Country',
- 'LABEL;QUOTED-PRINTABLE;POSTAL' => 'Other Street=0A|Other Street 2=0A|Other City,| Other State| Other Postal Code=0A|Other Country',
- 'TEL;VOICE' => 'Other Phone',
- 'TEL;FAX' => 'Other Fax',
- 'TEL;CELL' => 'Mobile Phone',
- 'TEL;CAR' => 'Car Phone',
- 'TEL;PAGER' => 'Pager',
- 'TEL;PREF' => 'Primary Phone',
- 'TEL;ISDN' => 'ISDN',
- 'TEL;X-EVOLUTION-CALLBACK' => 'Callback',
- 'TEL;X-EVOLUTION-TTYTDD' => 'TTY/TDD Phone',
- 'TEL;X-EVOLUTION-TELEX' => 'Telex',
- 'TEL;X-EVOLUTION-RADIO' => 'Radio Phone',
- 'EMAIL;INTERNET' => 'E-mail Address',
- 'EMAIL;INTERNET2' => 'E-mail 2 Address',
- 'EMAIL;INTERNET3' => 'E-mail 3 Address',
- ORG => 'Company|;Department',
- TITLE => 'Job Title',
- ROLE => 'Profession',
- 'X-EVOLUTION-ASSISTANT' => "Assistant's Name",
- 'TEL;X-EVOLUTION-ASSISTANT' => "Assistant's Phone",
- 'X-EVOLUTION-SPOUSE' => 'Spouse',
- 'X-EVOLUTION-ANNIVERSARY' => 'Anniversary',
- 'X-EVOLUTION-MANAGER' => "Manager's Name",
- 'X-EVOLUTION-OFFICE' => 'Office Location',
- BDAY => 'Birthday',
- NOTE => 'Notes',
- FBURL => 'Internet Free Busy',
- URL => 'Web Page',
- );
-
- foreach my $key (keys(%vcard_def)) {
- my $attr = build_vcard_attr_from_def($vcard_def{ $key }, \@fields, \%map);
- if (defined($attr)) {
- $vcard{ $key } = $attr unless ($attr =~ /^$/);
- }
- }
-
- return %vcard;
-}
-
-sub print_vcard_to_fh
-{
- my ($fh, %vcard) = @_;
-
- print $fh "BEGIN:VCARD\n";
- foreach my $key (keys(%vcard)) {
- # Dirty hack because Evolution's vcard stores multiple email addrs
- # with same sttribute, hence key collision. Bleah.
- # Ugh! Same deal for multiple phones... (eg. bus. phone)
- #
- # And finally, while we're special-casing... Outlook exports dates
- # differently, so munge 'em if we find 'em.
- if ($key =~ /EMAIL;INTERNET/o) {
- (my $temp = $key) =~ s/\d$//;
- print $fh "$temp:$vcard{ $key }\n";
- } elsif ($key =~ /TEL;(HOME|WORK)/o) {
- (my $temp = $key) =~ s/\d$//;
- print $fh "$temp:$vcard{ $key }\n";
- } elsif ($key =~ /(BDAY|X\-EVOLUTION\-ANNIVERSARY)/o) {
- my $temp = $vcard{ $key };
- if ($temp =~ /(\d\d)\/(\d\d)\/(\d\d)/) {
- # Y2k !! MS Didn't learn anything.
- # Hope no one was born before 1915
- if ((1900 + $3) < 1915) {
- print $fh "$key:20$3-$1-$2\n";
- } else {
- print $fh "$key:19$3-$1-$2\n";
- }
- } else {
- # Something's funky... Just delete the attribute
- print STDERR "Couldn't figure out what to do with $key:$vcard{ $key }\n";
- delete($vcard{ $key });
- }
- } else {
- print $fh "$key:$vcard{ $key }\n";
- }
- }
- print $fh "END:VCARD\n\n";
-}
-
-my $in = $ARGV[0];
-my $out = $ARGV[1];
-
-usage() unless(defined($in) && defined($out));
-
-open (IN, $in)
- or die "Can't open($in): $!\n";
-
-open (OUT, ">$out")
- or die "Can't open($out): $!\n";
-
-my $linectr = 0;
-my %map;
-
-while (my $line = <IN>) {
- $line =~ s/\r//g;
- $line =~ s/\n$//;
- if ($linectr == 0) {
- $linectr++;
- usage() unless is_recognized_format($line);
- %map = map_columns($line);
- #if ($line =~ /\r\n$/) {
- # print STDERR "Apparenlty found DOS-style EOL indicators...\n";
- $/ = "\r\n";
- #}
- } else {
- $linectr++;
- while ($line =~ /^(("([^"]|\n|"")*")?,)*"([^"]|\n|"")*$/) {
- my $temp = $line;
- $line = <IN>;
- $line =~ s/\r//g;
- $line =~ s/\n$//;
- $line = "$temp $line";
- }
- my %vcard = build_vcard_from_line($line, %map);
- print_vcard_to_fh(\*OUT, %vcard);
- }
-}
-
-close(IN);
-close(OUT);
diff --git a/addressbook/tools/evolution-addressbook-abuse.c b/addressbook/tools/evolution-addressbook-abuse.c
deleted file mode 100644
index 3446e15938..0000000000
--- a/addressbook/tools/evolution-addressbook-abuse.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <config.h>
-
-#include <bonobo/bonobo-main.h>
-
-#include <backend/ebook/e-book.h>
-#include <gnome.h>
-
-#define CONTACTS_TO_ADD 2000
-
-static gchar *
-make_random_string (void)
-{
- const gchar *elements = " abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- gint len = strlen (elements);
- gint i, N = 5 + (random () % 10);
- gchar *str = g_malloc (N+1);
-
- for (i = 0; i < N; ++i) {
- str[i] = elements[random () % len];
- }
- str[i] = '\0';
-
- return str;
-}
-
-static gchar *
-make_random_vcard (void)
-{
- gchar *fa = make_random_string ();
- gchar *name = make_random_string ();
- gchar *email = make_random_string ();
- gchar *org = make_random_string ();
-
- gchar *vcard;
-
- vcard = g_strdup_printf ("BEGIN:VCARD\n"
- "X-EVOLUTION-FILE-AS:%s\n"
- "N:%s\n"
- "EMAIL;INTERNET:%s\n"
- "ORG:%s\n"
- "END:VCARD",
- fa, name, email, org);
- g_free (fa);
- g_free (name);
- g_free (email);
- g_free (org);
-
- return vcard;
-}
-
-int
-main (int argc, char *argv[])
-{
- EBook *book;
- int i;
-
- if (getenv ("ABUSE_THE_WOMBAT") == NULL) {
- g_print ("You probably don't want to use this program.\n"
- "It isn't very nice.\n");
- exit(0);
- }
-
- bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
- textdomain (GETTEXT_PACKAGE);
-
- gnome_program_init ("evolution-addressbook-abuse", VERSION,
- LIBGNOMEUI_MODULE, argc, argv,
- GNOME_PROGRAM_STANDARD_PROPERTIES,
- NULL);
-
- if (!e_book_get_default_addressbook (&book, NULL)) {
- g_warning ("couldn't open addressbook");
- exit (1);
- }
-
- for (i = 0; i < CONTACTS_TO_ADD; ++i) {
- gchar *vcard = make_random_vcard ();
- EContact *contact = e_contact_new_from_vcard (vcard);
- g_message ("adding %d", i);
- if (!e_book_add_contact (book, contact, NULL)) {
- g_warning ("something went wrong...");
- exit (1);
- }
- g_free (vcard);
- g_object_unref (contact);
- }
-
- return 0;
-}
diff --git a/addressbook/tools/evolution-addressbook-clean.in b/addressbook/tools/evolution-addressbook-clean.in
deleted file mode 100644
index b7ee7ba167..0000000000
--- a/addressbook/tools/evolution-addressbook-clean.in
+++ /dev/null
@@ -1,24 +0,0 @@
-#! /usr/bin/perl -w
-
-sub do_system
-{
- my ($command) = @_;
- system ($command);
- if ($? != 0) {
- die "Command failed: $command";
- }
-}
-
-$filename = `@EVOLUTION_TOOLSDIR@/evolution-addressbook-export`;
-if ($? != 0) {
- $! = $?;
- die $!;
-}
-
-$HOME = $ENV{"HOME"};
-
-system ("@EVOLUTION_TOOLSDIR@/killev");
-do_system ("/bin/mv ${HOME}/evolution/local/Contacts/addressbook.db ${HOME}/evolution/local/Contacts/addressbook-backup.db");
-do_system ("@EVOLUTION_TOOLSDIR@/evolution-addressbook-import --input-file $filename");
-do_system ("/bin/rm $filename");
-
diff --git a/addressbook/tools/evolution-addressbook-export-list-cards.c b/addressbook/tools/evolution-addressbook-export-list-cards.c
deleted file mode 100644
index c51393d047..0000000000
--- a/addressbook/tools/evolution-addressbook-export-list-cards.c
+++ /dev/null
@@ -1,780 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* evolution-addressbook-export-list-cards.c
- *
- * Copyright (C) 2003 Ximian, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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: Gilbert Fang <gilbert.fang@sun.com>
- *
- */
-
-#include <config.h>
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <glib.h>
-#include <bonobo-activation/bonobo-activation.h>
-#include <libbonobo.h>
-#include <libgnome/libgnome.h>
-
-#include <ebook/e-book.h>
-#include <ebook/e-card-simple.h>
-#include <ebook/e-book-util.h>
-
-#include "evolution-addressbook-export.h"
-
-#define COMMA_SEPARATOR ","
-
-typedef enum _CARD_FORMAT CARD_FORMAT;
-typedef enum _DeliveryAddressField DeliveryAddressField;
-typedef enum _ECardSimpleFieldCSV ECardSimpleFieldCSV;
-typedef struct _ECardCSVFieldData ECardCSVFieldData;
-
-enum _CARD_FORMAT
-{
- CARD_FORMAT_CSV,
- CARD_FORMAT_VCARD
-};
-
-enum _DeliveryAddressField
-{
- DELIVERY_ADDRESS_STREET,
- DELIVERY_ADDRESS_EXT,
- DELIVERY_ADDRESS_CITY,
- DELIVERY_ADDRESS_REGION,
- DELIVERY_ADDRESS_CODE,
- DELIVERY_ADDRESS_COUNTRY
-};
-
-enum _ECardSimpleFieldCSV
-{
- E_CARD_SIMPLE_FIELD_CSV_FILE_AS,
- E_CARD_SIMPLE_FIELD_CSV_FULL_NAME,
- E_CARD_SIMPLE_FIELD_CSV_EMAIL,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_PRIMARY,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_ASSISTANT,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_CALLBACK,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_COMPANY,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME,
- E_CARD_SIMPLE_FIELD_CSV_ORG,
- /*E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS, */
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_STREET,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_EXT,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_CITY,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_REGION,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_POSTCODE,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_COUNTRY,
- /*E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME, */
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_STREET,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_EXT,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_CITY,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_REGION,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_POSTCODE,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_COUNTRY,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_MOBILE,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_CAR,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS_FAX,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME_FAX,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS_2,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME_2,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_ISDN,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_OTHER,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_OTHER_FAX,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_PAGER,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_RADIO,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_TELEX,
- E_CARD_SIMPLE_FIELD_CSV_PHONE_TTYTDD,
- /*E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER, */
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_STREET,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_EXT,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_CITY,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_REGION,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_POSTCODE,
- E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_COUNTRY,
- E_CARD_SIMPLE_FIELD_CSV_EMAIL_2,
- E_CARD_SIMPLE_FIELD_CSV_EMAIL_3,
- E_CARD_SIMPLE_FIELD_CSV_URL,
- E_CARD_SIMPLE_FIELD_CSV_ORG_UNIT,
- E_CARD_SIMPLE_FIELD_CSV_OFFICE,
- E_CARD_SIMPLE_FIELD_CSV_TITLE,
- E_CARD_SIMPLE_FIELD_CSV_ROLE,
- E_CARD_SIMPLE_FIELD_CSV_MANAGER,
- E_CARD_SIMPLE_FIELD_CSV_ASSISTANT,
- E_CARD_SIMPLE_FIELD_CSV_NICKNAME,
- E_CARD_SIMPLE_FIELD_CSV_SPOUSE,
- E_CARD_SIMPLE_FIELD_CSV_NOTE,
- E_CARD_SIMPLE_FIELD_CSV_CALURI,
- E_CARD_SIMPLE_FIELD_CSV_FBURL,
- /*E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY, */
- E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY_YEAR,
- E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY_MONTH,
- E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY_DAY,
- /*E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE, */
- E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_YEAR,
- E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_MONTH,
- E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_DAY,
- E_CARD_SIMPLE_FIELD_CSV_MAILER,
- E_CARD_SIMPLE_FIELD_CSV_NAME_OR_ORG,
- E_CARD_SIMPLE_FIELD_CSV_CATEGORIES,
- E_CARD_SIMPLE_FIELD_CSV_FAMILY_NAME,
- E_CARD_SIMPLE_FIELD_CSV_GIVEN_NAME,
- E_CARD_SIMPLE_FIELD_CSV_ADDITIONAL_NAME,
- E_CARD_SIMPLE_FIELD_CSV_NAME_SUFFIX,
- E_CARD_SIMPLE_FIELD_CSV_WANTS_HTML,
- E_CARD_SIMPLE_FIELD_CSV_IS_LIST,
- E_CARD_SIMPLE_FIELD_CSV_LAST
-};
-
-struct _ECardCSVFieldData
-{
- gint csv_field;
- gint simple_field;
- gchar *csv_name;
-};
-
-#define NOMAP -1
-static ECardCSVFieldData csv_field_data[] = {
- {E_CARD_SIMPLE_FIELD_CSV_FILE_AS, E_CARD_SIMPLE_FIELD_FILE_AS, ""},
- {E_CARD_SIMPLE_FIELD_CSV_FULL_NAME, E_CARD_SIMPLE_FIELD_CSV_FULL_NAME, ""},
- {E_CARD_SIMPLE_FIELD_CSV_EMAIL, E_CARD_SIMPLE_FIELD_EMAIL, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_PRIMARY, E_CARD_SIMPLE_FIELD_PHONE_PRIMARY,
- ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_ASSISTANT,
- E_CARD_SIMPLE_FIELD_PHONE_ASSISTANT, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS,
- E_CARD_SIMPLE_FIELD_PHONE_BUSINESS, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_CALLBACK,
- E_CARD_SIMPLE_FIELD_PHONE_CALLBACK, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_COMPANY, E_CARD_SIMPLE_FIELD_PHONE_COMPANY,
- ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME, E_CARD_SIMPLE_FIELD_PHONE_HOME, ""},
- {E_CARD_SIMPLE_FIELD_CSV_ORG, E_CARD_SIMPLE_FIELD_ORG, ""},
- /*E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS, */
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_STREET, NOMAP,
- "Business Address"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_EXT, NOMAP,
- "Business Address2"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_CITY, NOMAP,
- "Business Address City"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_REGION, NOMAP,
- "Business Address State"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_POSTCODE, NOMAP,
- "Business Address PostCode"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_COUNTRY, NOMAP,
- "Business Address Country"},
- /*E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME, */
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_STREET, NOMAP, "Home Address"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_EXT, NOMAP, "Home Address2"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_CITY, NOMAP, "Home Address City"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_REGION, NOMAP,
- "Home Address State"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_POSTCODE, NOMAP,
- "Home Address PostCode"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_COUNTRY, NOMAP,
- "Home Address Country"},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_MOBILE, E_CARD_SIMPLE_FIELD_PHONE_MOBILE,
- ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_CAR, E_CARD_SIMPLE_FIELD_PHONE_CAR, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS_FAX,
- E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_FAX, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME_FAX,
- E_CARD_SIMPLE_FIELD_PHONE_HOME_FAX, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS_2,
- E_CARD_SIMPLE_FIELD_PHONE_BUSINESS_2, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME_2, E_CARD_SIMPLE_FIELD_PHONE_HOME_2,
- ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_ISDN, E_CARD_SIMPLE_FIELD_PHONE_ISDN, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_OTHER, E_CARD_SIMPLE_FIELD_PHONE_OTHER, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_OTHER_FAX,
- E_CARD_SIMPLE_FIELD_PHONE_OTHER_FAX, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_PAGER, E_CARD_SIMPLE_FIELD_PHONE_PAGER, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_RADIO, E_CARD_SIMPLE_FIELD_PHONE_RADIO, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_TELEX, E_CARD_SIMPLE_FIELD_PHONE_TELEX, ""},
- {E_CARD_SIMPLE_FIELD_CSV_PHONE_TTYTDD, E_CARD_SIMPLE_FIELD_PHONE_TTYTDD,
- ""},
- /*E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER, */
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_STREET, NOMAP, "Other Address"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_EXT, NOMAP, "Other Address2"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_CITY, NOMAP,
- "Other Address City"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_REGION, NOMAP,
- "Other Address State"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_POSTCODE, NOMAP,
- "Other Address PostCode"},
- {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_COUNTRY, NOMAP,
- "Other Address Country"},
- {E_CARD_SIMPLE_FIELD_CSV_EMAIL_2, E_CARD_SIMPLE_FIELD_EMAIL_2, ""},
- {E_CARD_SIMPLE_FIELD_CSV_EMAIL_3, E_CARD_SIMPLE_FIELD_EMAIL_3, ""},
- {E_CARD_SIMPLE_FIELD_CSV_URL, E_CARD_SIMPLE_FIELD_URL, ""},
- {E_CARD_SIMPLE_FIELD_CSV_ORG_UNIT, E_CARD_SIMPLE_FIELD_ORG_UNIT, ""},
- {E_CARD_SIMPLE_FIELD_CSV_OFFICE, E_CARD_SIMPLE_FIELD_OFFICE, ""},
- {E_CARD_SIMPLE_FIELD_CSV_TITLE, E_CARD_SIMPLE_FIELD_TITLE, ""},
- {E_CARD_SIMPLE_FIELD_CSV_ROLE, E_CARD_SIMPLE_FIELD_ROLE, ""},
- {E_CARD_SIMPLE_FIELD_CSV_MANAGER, E_CARD_SIMPLE_FIELD_MANAGER, ""},
- {E_CARD_SIMPLE_FIELD_CSV_ASSISTANT, E_CARD_SIMPLE_FIELD_ASSISTANT, ""},
- {E_CARD_SIMPLE_FIELD_CSV_NICKNAME, E_CARD_SIMPLE_FIELD_NICKNAME, ""},
- {E_CARD_SIMPLE_FIELD_CSV_SPOUSE, E_CARD_SIMPLE_FIELD_SPOUSE, ""},
- {E_CARD_SIMPLE_FIELD_CSV_NOTE, E_CARD_SIMPLE_FIELD_NOTE, ""},
- {E_CARD_SIMPLE_FIELD_CSV_CALURI, E_CARD_SIMPLE_FIELD_CALURI, ""},
- {E_CARD_SIMPLE_FIELD_CSV_FBURL, E_CARD_SIMPLE_FIELD_FBURL, ""},
- /*E_CARD_SIMPLE_FIELD_ANNIVERSARY, */
- {E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY_YEAR, NOMAP, "Anniversary Year"},
- {E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY_MONTH, NOMAP, "Anniversary Month"},
- {E_CARD_SIMPLE_FIELD_CSV_ANNIVERSARY_DAY, NOMAP, "Anniversary Day"},
- /*E_CARD_SIMPLE_FIELD_BIRTH_DATE, */
- {E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_YEAR, NOMAP, "Birth Year"},
- {E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_MONTH, NOMAP, "Birth Month"},
- {E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_DAY, NOMAP, "Birth Day"},
- {E_CARD_SIMPLE_FIELD_CSV_MAILER, E_CARD_SIMPLE_FIELD_MAILER, ""},
- {E_CARD_SIMPLE_FIELD_CSV_NAME_OR_ORG, E_CARD_SIMPLE_FIELD_NAME_OR_ORG, ""},
- {E_CARD_SIMPLE_FIELD_CSV_CATEGORIES, E_CARD_SIMPLE_FIELD_CATEGORIES, ""},
- {E_CARD_SIMPLE_FIELD_CSV_FAMILY_NAME, E_CARD_SIMPLE_FIELD_FAMILY_NAME, ""},
- {E_CARD_SIMPLE_FIELD_CSV_GIVEN_NAME, E_CARD_SIMPLE_FIELD_GIVEN_NAME, ""},
- {E_CARD_SIMPLE_FIELD_CSV_ADDITIONAL_NAME,
- E_CARD_SIMPLE_FIELD_ADDITIONAL_NAME, ""},
- {E_CARD_SIMPLE_FIELD_CSV_NAME_SUFFIX, E_CARD_SIMPLE_FIELD_NAME_SUFFIX, ""},
- {E_CARD_SIMPLE_FIELD_CSV_WANTS_HTML, E_CARD_SIMPLE_FIELD_WANTS_HTML, ""},
- {E_CARD_SIMPLE_FIELD_CSV_IS_LIST, E_CARD_SIMPLE_FIELD_IS_LIST, ""},
- {E_CARD_SIMPLE_FIELD_CSV_LAST, NOMAP, ""}
-
-};
-
-static GSList *pre_defined_fields;
-
-/*function prototypes*/
-gint e_card_simple_csv_get_simple_field (ECardSimpleFieldCSV csv_field);
-gchar *e_card_simple_csv_get_name (ECardSimpleFieldCSV csv_field);
-gchar *e_card_simple_csv_get (ECardSimple * simple, ECardSimpleFieldCSV csv_field);
-gchar *e_card_simple_csv_get_header_line (GSList * csv_all_fields);
-gchar *e_card_simple_to_csv (ECardSimple * simple, GSList * csv_all_fields);
-gchar *e_card_get_csv (ECard * card, GSList * csv_all_fields);
-gchar *delivery_address_get_sub_field (const ECardDeliveryAddress * delivery_address, DeliveryAddressField sub_field);
-gchar *check_null_pointer (gchar * orig);
-gchar *quote_string (gchar * orig);
-int output_n_cards_file (FILE * outputfile, ECardCursor * cursor, int size, int begin_no, CARD_FORMAT format);
-static void fork_to_background (void);
-static void action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * cursor, ActionContext * p_actctx);
-static void action_list_cards_open_cb (EBook * book, EBookStatus status, ActionContext * p_actctx);
-static guint action_list_cards_run (ActionContext * p_actctx);
-void set_pre_defined_field (GSList ** pre_defined_fields);
-guint action_list_cards_init (ActionContext * p_actctx);
-
-
-/* function declarations*/
-gint
-e_card_simple_csv_get_simple_field (ECardSimpleFieldCSV csv_field)
-{
- return csv_field_data[csv_field].simple_field;
-}
-
-gchar *
-e_card_simple_csv_get_name (ECardSimpleFieldCSV csv_field)
-{
- gint simple_field;
- gchar *name;
- gchar *esc_name;
- gchar *quoted_name;
-
- ECardSimple *a_simple_card;
-
- simple_field = e_card_simple_csv_get_simple_field (csv_field);
-
- if (simple_field != NOMAP) {
- a_simple_card = E_CARD_SIMPLE (g_object_new (E_TYPE_CARD_SIMPLE, NULL));
- name = g_strdup (e_card_simple_get_ecard_field (a_simple_card, simple_field));
- g_object_unref (G_OBJECT (a_simple_card));
- } else {
- name = g_strdup (csv_field_data[csv_field].csv_name);
- }
- esc_name = g_strescape (name, NULL);
- g_free (name);
- quoted_name = quote_string (esc_name);
- g_free (esc_name);
- return quoted_name;
-}
-
-
-gchar *
-e_card_simple_csv_get (ECardSimple * simple, ECardSimpleFieldCSV csv_field)
-{
- gint simple_field;
- gchar *field_value;
- gchar *esc_field_value;
- gchar *quoted_field_value;
-
- const ECardDeliveryAddress *delivery_address = NULL;
-
- simple_field = e_card_simple_csv_get_simple_field (csv_field);
-
- if (simple_field != NOMAP) {
- field_value = e_card_simple_get (simple, simple_field);
- } else {
-
- switch (csv_field) {
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_STREET:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_STREET);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_EXT:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_EXT);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_CITY:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_CITY);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_REGION:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_REGION);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_POSTCODE:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_CODE);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_COUNTRY:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_HOME);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_COUNTRY);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_STREET:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_STREET);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_EXT:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_EXT);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_CITY:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_CITY);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_REGION:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_REGION);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_POSTCODE:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_CODE);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_COUNTRY:
- delivery_address = e_card_simple_get_delivery_address (simple, E_CARD_SIMPLE_ADDRESS_ID_BUSINESS);
- field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_COUNTRY);
- break;
- case E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_YEAR:
- if (simple->card->bday != NULL) {
- field_value = g_strdup_printf ("%04d", simple->card->bday->year);
- } else {
- field_value = g_strdup ("");
- }
- break;
-
- case E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_MONTH:
- if (simple->card->bday != NULL) {
- field_value = g_strdup_printf ("%02d", simple->card->bday->month);
- } else {
- field_value = g_strdup ("");
- }
- break;
-
- case E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_DAY:
- if (simple->card->bday != NULL) {
- field_value = g_strdup_printf ("%02d", simple->card->bday->day);
- } else {
- field_value = g_strdup ("");
- }
- break;
-
- default:
- field_value = g_strdup ("");
- }
- }
-
- /*checking to avoid the NULL pointer */
- if (field_value == NULL)
- field_value = g_strdup ("");
-
- esc_field_value = g_strescape (field_value, NULL);
- g_free (field_value);
-
- quoted_field_value = quote_string (esc_field_value);
- g_free (esc_field_value);
-
- return quoted_field_value;
-}
-
-
-gchar *
-e_card_simple_csv_get_header_line (GSList * csv_all_fields)
-{
-
- guint field_number;
- gint csv_field;
- gchar **field_name_array;
- gchar *header_line;
-
- gint loop_counter;
-
- field_number = g_slist_length (csv_all_fields);
- field_name_array = g_new0 (gchar *, field_number + 1);
-
- for (loop_counter = 0; loop_counter < field_number; loop_counter++) {
- csv_field = GPOINTER_TO_INT (g_slist_nth_data (csv_all_fields, loop_counter));
- *(field_name_array + loop_counter) = e_card_simple_csv_get_name (csv_field);
- }
-
- header_line = g_strjoinv (COMMA_SEPARATOR, field_name_array);
-
- for (loop_counter = 0; loop_counter < field_number; loop_counter++) {
- g_free (*(field_name_array + loop_counter));
- }
- g_free (field_name_array);
-
- return header_line;
-
-}
-
-
-gchar *
-e_card_simple_to_csv (ECardSimple * simple, GSList * csv_all_fields)
-{
- guint field_number;
- gint csv_field;
- gchar **field_value_array;
- gchar *aline;
-
- gint loop_counter;
-
- field_number = g_slist_length (csv_all_fields);
- field_value_array = g_new0 (gchar *, field_number + 1);
-
- for (loop_counter = 0; loop_counter < field_number; loop_counter++) {
- csv_field = GPOINTER_TO_INT (g_slist_nth_data (csv_all_fields, loop_counter));
- *(field_value_array + loop_counter) = e_card_simple_csv_get (simple, csv_field);
- }
-
- aline = g_strjoinv (COMMA_SEPARATOR, field_value_array);
-
- for (loop_counter = 0; loop_counter < field_number; loop_counter++) {
- g_free (*(field_value_array + loop_counter));
- }
- g_free (field_value_array);
-
- return aline;
-
-}
-
-
-gchar *
-e_card_get_csv (ECard * card, GSList * csv_all_fields)
-{
- ECardSimple *simple_card;
- gchar *aline;
-
- simple_card = e_card_simple_new (card);
- aline = e_card_simple_to_csv (simple_card, csv_all_fields);
- g_object_unref (G_OBJECT (simple_card));
- return aline;
-}
-
-
-gchar *
-check_null_pointer (gchar * orig)
-{
- gchar *result;
- if (orig == NULL)
- result = g_strdup ("");
- else
- result = g_strdup (orig);
- return result;
-}
-
-gchar *delivery_address_get_sub_field (const ECardDeliveryAddress * address, DeliveryAddressField sub_field)
-{
- gchar *sub_field_value;
- gchar *str_temp, *str_temp_a;
- if (address != NULL) {
- switch (sub_field) {
- case DELIVERY_ADDRESS_STREET:
- str_temp_a = check_null_pointer (address->po);
- str_temp = check_null_pointer (address->street);
- sub_field_value = g_strdup_printf ("%s %s", str_temp_a, str_temp);
- g_free (str_temp);
- g_free (str_temp_a);
- break;
- case DELIVERY_ADDRESS_EXT:
- sub_field_value = check_null_pointer (address->ext);
- break;
- case DELIVERY_ADDRESS_CITY:
- sub_field_value = check_null_pointer (address->city);
- break;
- case DELIVERY_ADDRESS_REGION:
- sub_field_value = check_null_pointer (address->region);
- break;
- case DELIVERY_ADDRESS_CODE:
- sub_field_value = check_null_pointer (address->code);
- break;
- case DELIVERY_ADDRESS_COUNTRY:
- sub_field_value = check_null_pointer (address->country);
- break;
- default:
- sub_field_value = g_strdup ("");
- }
- } else {
- sub_field_value = g_strdup ("");
- }
- return sub_field_value;
-}
-
-gchar *
-quote_string (gchar *orig)
-{
- if (orig == NULL)
- return g_strdup ("\"\"");
- return g_strdup_printf("\"%s\"", orig);
-}
-
-int
-output_n_cards_file (FILE * outputfile, ECardCursor * cursor, int size, int begin_no, CARD_FORMAT format)
-{
- int i;
- if (format == CARD_FORMAT_VCARD) {
- for (i = begin_no; i < size + begin_no; i++) {
- ECard *card = e_card_cursor_get_nth (cursor, i);
- gchar *vcard = e_card_get_vcard_assume_utf8 (card);
- fprintf (outputfile, "%s\n", vcard);
- g_free (vcard);
- g_object_unref (G_OBJECT (card));
- }
- } else if (format == CARD_FORMAT_CSV) {
- gchar *csv_fields_name = e_card_simple_csv_get_header_line (pre_defined_fields);
- fprintf (outputfile, "%s\n", csv_fields_name);
- g_free (csv_fields_name);
-
- for (i = begin_no; i < size + begin_no; i++) {
- ECard *card = e_card_cursor_get_nth (cursor, i);
- gchar *csv = e_card_get_csv (card, pre_defined_fields);
- fprintf (outputfile, "%s\n", csv);
- g_free (csv);
- g_object_unref (G_OBJECT (card));
-
- }
- }
-
- return SUCCESS;
-
-}
-
-static void
-fork_to_background (void)
-{
- pid_t pid;
- pid = fork ();
- if (pid == -1) {
- /* ouch, fork() failed */
- perror ("fork");
- exit (-1);
- } else if (pid == 0) {
- /* child */
- /*contunue */
-
- } else {
- /* parent exit, note the use of _exit() instead of exit() */
- _exit (-1);
- }
-}
-
-
-
-
-static void
-action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * cursor, ActionContext * p_actctx)
-{
- FILE *outputfile;
- long length;
- int IsFirstOne;
- int series_no;
- gchar *file_series_name;
- CARD_FORMAT format;
- int size;
-
- length = e_card_cursor_get_length (cursor);
-
- if (length <= 0) {
- g_warning ("Couldn't load addressbook correctly!!!! %s####", p_actctx->action_list_cards.addressbook_folder_uri);
- exit (-1);
- }
-
-
- if (p_actctx->action_list_cards.async_mode == FALSE) { /* normal mode */
-
- if (p_actctx->action_list_cards.output_file == NULL) {
- outputfile = stdout;
- } else {
- /* fopen output file */
- if (!(outputfile = fopen (p_actctx->action_list_cards.output_file, "w"))) {
- g_warning (_("Can not open file"));
- exit (-1);
- }
- }
-
- if (p_actctx->action_list_cards.IsVCard == TRUE)
- format = CARD_FORMAT_VCARD;
- else
- format = CARD_FORMAT_CSV;
-
- output_n_cards_file (outputfile, cursor, length, 0, format);
-
-
-
- if (p_actctx->action_list_cards.output_file != NULL) {
- fclose (outputfile);
- }
- }
-
-
- /*async mode */
- else {
-
- size = p_actctx->action_list_cards.file_size;
- IsFirstOne = TRUE;
- series_no = 0;
-
- do {
- /* whether it is the last file */
- if ((series_no + 1) * size >= length) { /*last one */
- file_series_name = g_strdup_printf ("%s.end", p_actctx->action_list_cards.output_file);
-
- } else { /*next one */
- file_series_name =
- g_strdup_printf ("%s.%04d", p_actctx->action_list_cards.output_file, series_no);
- }
-
- if (!(outputfile = fopen (file_series_name, "w"))) {
- g_warning (_("Can not open file"));
- exit (-1);
- }
-
-
- if (p_actctx->action_list_cards.IsVCard == TRUE)
- format = CARD_FORMAT_VCARD;
- else
- format = CARD_FORMAT_CSV;
- output_n_cards_file (outputfile, cursor, size, series_no * size, format);
-
- fclose (outputfile);
-
- series_no++;
-
- if (IsFirstOne == TRUE) {
- fork_to_background ();
- IsFirstOne = FALSE;
- }
-
-
- }
- while (series_no * size < length);
- g_free (file_series_name);
- }
-
- bonobo_main_quit ();
-}
-
-
-
-
-static void
-action_list_cards_open_cb (EBook * book, EBookStatus status, ActionContext * p_actctx)
-{
- if (status != E_BOOK_STATUS_SUCCESS) {
- g_warning ("Couldn't load addressbook %s", p_actctx->action_list_cards.addressbook_folder_uri);
- exit (-1);
- }
- e_book_get_cursor (book, "(contains \"full_name\" \"\")", (EBookCursorCallback)action_list_cards_get_cursor_cb, p_actctx);
-}
-
-
-static guint
-action_list_cards_run (ActionContext * p_actctx)
-{
- EBook *book;
- book = e_book_new ();
-
- if (p_actctx->action_list_cards.addressbook_folder_uri != NULL) {
- e_book_load_uri (book, p_actctx->action_list_cards.addressbook_folder_uri,
- (EBookCallback)action_list_cards_open_cb, p_actctx);
- } else {
- e_book_load_default_book (book, (EBookCallback)action_list_cards_open_cb, p_actctx);
- }
- return SUCCESS;
-}
-
-
-void
-set_pre_defined_field (GSList ** pre_defined_fields)
-{
- *pre_defined_fields = NULL;
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_GIVEN_NAME));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_FAMILY_NAME));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_FULL_NAME));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_NICKNAME));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_EMAIL));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_EMAIL_2));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_WANTS_HTML));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_PHONE_HOME));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_PHONE_BUSINESS_FAX));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_PHONE_PAGER));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_PHONE_MOBILE));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_STREET));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_EXT));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_CITY));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_REGION));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_POSTCODE));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_COUNTRY));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_STREET));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_EXT));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_CITY));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_REGION));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_POSTCODE));
- *pre_defined_fields =
- g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_COUNTRY));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_TITLE));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_OFFICE));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ORG));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_URL));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_CALURI));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_YEAR));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_MONTH));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_BIRTH_DATE_DAY));
- *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_NOTE));
-}
-
-guint
-action_list_cards_init (ActionContext * p_actctx)
-{
- g_idle_add ((GSourceFunc) action_list_cards_run, p_actctx);
- set_pre_defined_field (&pre_defined_fields);
-
- return SUCCESS;
-}
diff --git a/addressbook/tools/evolution-addressbook-export-list-folders.c b/addressbook/tools/evolution-addressbook-export-list-folders.c
deleted file mode 100644
index 8922422a8f..0000000000
--- a/addressbook/tools/evolution-addressbook-export-list-folders.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* evolution-addressbook-export-list-folders.c
- *
- * Copyright (C) 2003 Ximian, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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: Gilbert Fang <gilbert.fang@sun.com>
- *
- */
-
-#include <config.h>
-
-#include <glib.h>
-#include <bonobo-activation/bonobo-activation.h>
-#include <libbonobo.h>
-#include <libgnome/libgnome.h>
-
-#include <ebook/e-book.h>
-#include <ebook/e-book-util.h>
-
-#include "evolution-addressbook-export.h"
-
-static void
-action_list_folders_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * cursor, ActionContext * p_actctx)
-{
- FILE *outputfile;
- long length;
- const char *uri;
- char *name;
-
- uri = e_book_get_default_book_uri ();
- length = e_card_cursor_get_length (cursor);
-
- /*Fix me *
- can not get name, should be a bug of e-book.Anyway, should set a default name.
- */
- /*name = e_book_get_name (book); */
- name = g_strdup (_("Contacts"));
-
- if (p_actctx->action_list_folders.output_file == NULL) {
- printf ("\"%s\",\"%s\",%d\n", uri, name, (int) length);
- } else {
- /*output to a file */
- if (!(outputfile = fopen (p_actctx->action_list_folders.output_file, "w"))) {
- g_warning (_("Can not open file"));
- exit (-1);
- }
- fprintf (outputfile, "\"%s\",\"%s\",%d\n", uri, name, (int) length);
- fclose (outputfile);
- }
-
- g_free (name);
- g_object_unref (G_OBJECT (book));
- bonobo_main_quit ();
-}
-
-static void
-action_list_folders_open_cb (EBook * book, EBookStatus status, ActionContext * p_actctx)
-{
- if (E_BOOK_STATUS_SUCCESS == status) {
- e_book_get_cursor (book, "(contains \"full_name\" \"\")",
- (EBookCursorCallback)action_list_folders_get_cursor_cb, p_actctx);
- } else {
- g_object_unref (G_OBJECT (book));
- g_warning (_("Can not load URI"));
- exit (-1);
- }
-}
-
-static guint
-action_list_folders_run (ActionContext * p_actctx)
-{
- EBook *book;
- book = e_book_new ();
-
- e_book_load_default_book (book, (EBookCallback)action_list_folders_open_cb, p_actctx);
- return SUCCESS;
-}
-
-guint
-action_list_folders_init (ActionContext * p_actctx)
-{
- g_idle_add ((GSourceFunc) action_list_folders_run, p_actctx);
-
- return SUCCESS;
-}
diff --git a/addressbook/tools/evolution-addressbook-export.c b/addressbook/tools/evolution-addressbook-export.c
deleted file mode 100644
index a61880ed14..0000000000
--- a/addressbook/tools/evolution-addressbook-export.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* evolution-addressbook-export.c
- *
- * Copyright (C) 2003 Ximian, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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: Gilbert Fang <gilbert.fang@sun.com>
- *
- */
-
-#include <config.h>
-
-#include <glib.h>
-#include <bonobo-activation/bonobo-activation.h>
-#include <bonobo/bonobo-main.h>
-#include <gnome.h>
-
-#include <ebook/e-book.h>
-
-#include "evolution-addressbook-export.h"
-
-int
-main (int argc, char **argv)
-{
- ActionContext actctx;
- GnomeProgram *program;
- poptContext context;
- const gchar **argvn;
-
- int current_action = ACTION_NOTHING;
- int IsCSV = FALSE;
- int IsVCard = FALSE;
-
- /*** popttable */
- char *output_file = NULL;
- int list_folders_mode = FALSE;
- char *output_format = NULL;
- char *addressbook_folder_uri = NULL;
- int async_mode = FALSE;
- int file_size = 0;
-
- struct poptOption options[] = {
- {"output", '\0', POPT_ARG_STRING, &output_file, 0, N_("Specify the output file instead of standard output"),
- N_("OUTPUTFILE")},
- {"list-addressbook-folders", 'l', POPT_ARG_NONE, &list_folders_mode, 0, N_("List local addressbook folders"),
- NULL},
- {"format", '\0', POPT_ARG_STRING, &output_format, 0, N_("Show cards as vcard or csv file"), N_("[vcard|csv]")},
- {"async", 'a', POPT_ARG_NONE, &async_mode, 0, N_("Export in asynchronous mode "), NULL},
- {"size", '\0', POPT_ARG_INT, &file_size, 0,
- N_("The number of cards in one output file in asychronous mode,default size 100."), N_("NUMBER")},
- {NULL, '\0', 0, NULL, 0, NULL, NULL}
- };
- /* popttable end ** */
-
- /*i18n-lize */
- bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
-
- program =
- gnome_program_init (PACKAGE, VERSION, GNOME_BONOBO_MODULE, argc, argv, GNOME_PARAM_POPT_TABLE, options,
- GNOME_PARAM_NONE);
-
- /* Parsing Parameter */
- g_object_get (program, "popt-context", &context, NULL);
- argvn = poptGetArgs (context);
- if (!argvn) {
- addressbook_folder_uri = NULL;
- } else { /* there at lease is a one argument, and that should be addressbook folder uri */
- addressbook_folder_uri = g_strdup (*argvn);
- }
- poptFreeContext (context);
-
- if (list_folders_mode != FALSE) {
- current_action = ACTION_LIST_FOLDERS;
- /* check there should not be addressbook-folder-uri , and async and size , output_format */
- if (addressbook_folder_uri != NULL || async_mode != FALSE || output_format != NULL || file_size != 0) {
- g_warning (_("Command line arguments error, please use --help option to see the usage."));
- exit (-1);
- }
- } else {
-
- current_action = ACTION_LIST_CARDS;
-
- /* check the output format */
- if (output_format == NULL) {
- IsVCard = TRUE;
- } else {
- IsCSV = !strcmp (output_format, "csv");
- IsVCard = !strcmp (output_format, "vcard");
- if (IsCSV == FALSE && IsVCard == FALSE) {
- g_warning (_("Only support csv or vcard format."));
- exit (-1);
- }
- }
-
- /*check async and output file */
- if (async_mode == TRUE) {
- /* check have to output file , set default file_size */
- if (output_file == NULL) {
- g_warning (_("In async mode, output must be file."));
- exit (-1);
- }
- if (file_size == 0)
- file_size = DEFAULT_SIZE_NUMBER;
- } else {
- /*check no file_size */
- if (file_size != 0) {
- g_warning (_("In normal mode, there should not need size option."));
- exit (-1);
- }
- }
- }
-
- /* do actions */
- if (current_action == ACTION_LIST_FOLDERS) {
- actctx.action_type = current_action;
- if (output_file == NULL) {
- actctx.action_list_folders.output_file = NULL;
- } else {
- actctx.action_list_folders.output_file = g_strdup (output_file);
- }
- action_list_folders_init (&actctx);
- } else if (current_action == ACTION_LIST_CARDS) {
- actctx.action_type = current_action;
- if (output_file == NULL) {
- actctx.action_list_cards.output_file = NULL;
- } else {
- actctx.action_list_cards.output_file = g_strdup (output_file);
- }
- actctx.action_list_cards.IsCSV = IsCSV;
- actctx.action_list_cards.IsVCard = IsVCard;
- actctx.action_list_cards.addressbook_folder_uri = g_strdup (addressbook_folder_uri);
- actctx.action_list_cards.async_mode = async_mode;
- actctx.action_list_cards.file_size = file_size;
-
- action_list_cards_init (&actctx);
-
- } else {
- g_warning (_("Impossible internal error."));
- exit (-1);
- }
-
- bonobo_main ();
-
- /*FIXME:should free actctx's some char* field, such as output_file! but since the program will end, so that will not cause mem leak. */
-
- return 0;
-}
diff --git a/addressbook/tools/evolution-addressbook-export.h b/addressbook/tools/evolution-addressbook-export.h
deleted file mode 100644
index 13749aed61..0000000000
--- a/addressbook/tools/evolution-addressbook-export.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* evolution-addressbook-export.h
- *
- * Copyright (C) 2003 Ximian, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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: Gilbert Fang <gilbert.fang@sun.com>
- *
- */
-
-#ifndef _EVOLUTION_ADDRESSBOOK_EXPORT_H_
-#define _EVOLUTION_ADDRESSBOOK_EXPORT_H__
-
-#include <glib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus */
-
-#define SUCCESS 0
-#define FAILED -1
-
-#define ACTION_NOTHING 0
-#define ACTION_LIST_FOLDERS 1
-#define ACTION_LIST_CARDS 2
-
-#define DEFAULT_SIZE_NUMBER 100
-
-union _ActionContext
-{
-
- guint action_type;
-
- struct
- {
- gint action_type;
- gchar *output_file;
- }
- action_list_folders;
-
- struct
- {
- gint action_type;
- gchar *output_file;
- gint IsCSV;
- gint IsVCard;
- gchar *addressbook_folder_uri;
- gint async_mode;
- gint file_size;
- }
- action_list_cards;
-};
-
-typedef union _ActionContext ActionContext;
-
-
-/* action_list_folders */
-guint action_list_folders_init (ActionContext * p_actctx);
-
-/*action list cards*/
-guint action_list_cards_init (ActionContext * p_actctx);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* _EVOLUTION_ADDRESSBOOK_EXPORT_H_ */
diff --git a/addressbook/tools/evolution-addressbook-import.c b/addressbook/tools/evolution-addressbook-import.c
deleted file mode 100644
index 28871efd96..0000000000
--- a/addressbook/tools/evolution-addressbook-import.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-#include <config.h>
-
-#include <bonobo-activation/bonobo-activation.h>
-#include <bonobo/bonobo-main.h>
-#include <backend/ebook/e-book-async.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)
- g_main_loop_quit (0);
-}
-
-static void
-add_cb (EBook *book, EBookStatus status, const char *id, gpointer closure)
-{
- switch (status) {
- case E_BOOK_ERROR_OK:
- unref_executable ();
- break;
- default:
- g_main_loop_quit (NULL);
- 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 },
- POPT_AUTOHELP
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
- textdomain (GETTEXT_PACKAGE);
-
- gnome_program_init ("evolution-addressbook-import", VERSION,
- LIBGNOMEUI_MODULE, argc, argv,
- GNOME_PROGRAM_STANDARD_PROPERTIES,
- GNOME_PARAM_POPT_TABLE, options,
- NULL);
-
- if (filename == NULL) {
- g_error (_("No filename provided."));
- }
-
- e_book_async_get_default_addressbook (use_addressbook, filename);
-
- bonobo_main ();
-
- return 0;
-}