diff options
-rw-r--r-- | addressbook/ChangeLog | 8 | ||||
-rw-r--r-- | addressbook/tools/Makefile.am | 16 | ||||
-rw-r--r-- | addressbook/tools/evolution-addressbook-export-list-cards.c | 698 | ||||
-rw-r--r-- | addressbook/tools/evolution-addressbook-export-list-folders.c | 104 | ||||
-rw-r--r-- | addressbook/tools/evolution-addressbook-export.c | 6 |
5 files changed, 422 insertions, 410 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index e70f83847f..53b021843f 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,5 +1,13 @@ 2004-05-24 Chris Toshok <toshok@ximian.com> + * tools/Makefile.am: fix this for current build foo. + + * tools/evolution-addressbook-export-list-folders.c, + * tools/evolution-addressbook-export-list-cards.c, + * tools/evolution-addressbook-export.c: revive this. + +2004-05-24 Chris Toshok <toshok@ximian.com> + [ fixes bug #32194 ] * importers/evolution-vcard-importer.c (process_item_fn): make diff --git a/addressbook/tools/Makefile.am b/addressbook/tools/Makefile.am index fe76abcc08..adeb3176d6 100644 --- a/addressbook/tools/Makefile.am +++ b/addressbook/tools/Makefile.am @@ -5,8 +5,6 @@ privlibexec_SCRIPTS = \ bin_PROGRAMS = \ evolution-addressbook-export -noinst_PROGRAMS= evolution-addressbook-abuse - INCLUDES = \ -DG_LOG_DOMAIN=\"evolution-addressbook-tools\" \ -I$(top_srcdir) \ @@ -17,9 +15,8 @@ INCLUDES = \ -DDATADIR=\""$(datadir)"\" \ -DLIBDIR=\""$(libdir)"\" \ -I$(top_srcdir)/addressbook \ - -I$(top_srcdir)/addressbook/backend \ - -I$(top_builddir)/addressbook/backend \ - $(GNOME_FULL_CFLAGS) + -I$(top_builddir)/addressbook \ + $(EVOLUTION_ADDRESSBOOK_CFLAGS) evolution_addressbook_export_SOURCES = \ evolution-addressbook-export.c \ @@ -28,14 +25,7 @@ evolution_addressbook_export_SOURCES = \ 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 + $(EVOLUTION_ADDRESSBOOK_LIBS) EXTRA_DIST = $(privlibexec_SCRIPTS) \ evolution-addressbook-clean.in diff --git a/addressbook/tools/evolution-addressbook-export-list-cards.c b/addressbook/tools/evolution-addressbook-export-list-cards.c index c51393d047..88923fd244 100644 --- a/addressbook/tools/evolution-addressbook-export-list-cards.c +++ b/addressbook/tools/evolution-addressbook-export-list-cards.c @@ -23,6 +23,7 @@ #include <config.h> +#include <string.h> #include <sys/types.h> #include <unistd.h> @@ -31,9 +32,8 @@ #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 <libebook/e-book.h> +#include <libebook/e-contact.h> #include "evolution-addressbook-export.h" @@ -41,8 +41,8 @@ typedef enum _CARD_FORMAT CARD_FORMAT; typedef enum _DeliveryAddressField DeliveryAddressField; -typedef enum _ECardSimpleFieldCSV ECardSimpleFieldCSV; -typedef struct _ECardCSVFieldData ECardCSVFieldData; +typedef enum _EContactFieldCSV EContactFieldCSV; +typedef struct _EContactCSVFieldData EContactCSVFieldData; enum _CARD_FORMAT { @@ -54,346 +54,340 @@ enum _DeliveryAddressField { DELIVERY_ADDRESS_STREET, DELIVERY_ADDRESS_EXT, - DELIVERY_ADDRESS_CITY, + DELIVERY_ADDRESS_LOCALITY, DELIVERY_ADDRESS_REGION, DELIVERY_ADDRESS_CODE, DELIVERY_ADDRESS_COUNTRY }; -enum _ECardSimpleFieldCSV +enum _EContactFieldCSV { - 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 + E_CONTACT_CSV_FILE_AS, + E_CONTACT_CSV_FULL_NAME, + E_CONTACT_CSV_EMAIL, + E_CONTACT_CSV_PHONE_PRIMARY, + E_CONTACT_CSV_PHONE_ASSISTANT, + E_CONTACT_CSV_PHONE_BUSINESS, + E_CONTACT_CSV_PHONE_CALLBACK, + E_CONTACT_CSV_PHONE_COMPANY, + E_CONTACT_CSV_PHONE_HOME, + E_CONTACT_CSV_ORG, + /*E_CONTACT_CSV_ADDRESS_BUSINESS, */ + E_CONTACT_CSV_ADDRESS_BUSINESS_STREET, + E_CONTACT_CSV_ADDRESS_BUSINESS_EXT, + E_CONTACT_CSV_ADDRESS_BUSINESS_CITY, + E_CONTACT_CSV_ADDRESS_BUSINESS_REGION, + E_CONTACT_CSV_ADDRESS_BUSINESS_POSTCODE, + E_CONTACT_CSV_ADDRESS_BUSINESS_COUNTRY, + /*E_CONTACT_CSV_ADDRESS_HOME, */ + E_CONTACT_CSV_ADDRESS_HOME_STREET, + E_CONTACT_CSV_ADDRESS_HOME_EXT, + E_CONTACT_CSV_ADDRESS_HOME_CITY, + E_CONTACT_CSV_ADDRESS_HOME_REGION, + E_CONTACT_CSV_ADDRESS_HOME_POSTCODE, + E_CONTACT_CSV_ADDRESS_HOME_COUNTRY, + E_CONTACT_CSV_PHONE_MOBILE, + E_CONTACT_CSV_PHONE_CAR, + E_CONTACT_CSV_PHONE_BUSINESS_FAX, + E_CONTACT_CSV_PHONE_HOME_FAX, + E_CONTACT_CSV_PHONE_BUSINESS_2, + E_CONTACT_CSV_PHONE_HOME_2, + E_CONTACT_CSV_PHONE_ISDN, + E_CONTACT_CSV_PHONE_OTHER, + E_CONTACT_CSV_PHONE_OTHER_FAX, + E_CONTACT_CSV_PHONE_PAGER, + E_CONTACT_CSV_PHONE_RADIO, + E_CONTACT_CSV_PHONE_TELEX, + E_CONTACT_CSV_PHONE_TTYTDD, + /*E_CONTACT_CSV_ADDRESS_OTHER, */ + E_CONTACT_CSV_ADDRESS_OTHER_STREET, + E_CONTACT_CSV_ADDRESS_OTHER_EXT, + E_CONTACT_CSV_ADDRESS_OTHER_CITY, + E_CONTACT_CSV_ADDRESS_OTHER_REGION, + E_CONTACT_CSV_ADDRESS_OTHER_POSTCODE, + E_CONTACT_CSV_ADDRESS_OTHER_COUNTRY, + E_CONTACT_CSV_EMAIL_2, + E_CONTACT_CSV_EMAIL_3, + E_CONTACT_CSV_HOMEPAGE_URL, + E_CONTACT_CSV_ORG_UNIT, + E_CONTACT_CSV_OFFICE, + E_CONTACT_CSV_TITLE, + E_CONTACT_CSV_ROLE, + E_CONTACT_CSV_MANAGER, + E_CONTACT_CSV_ASSISTANT, + E_CONTACT_CSV_NICKNAME, + E_CONTACT_CSV_SPOUSE, + E_CONTACT_CSV_NOTE, + E_CONTACT_CSV_CALENDAR_URI, + E_CONTACT_CSV_FREEBUSY_URL, + /*E_CONTACT_CSV_ANNIVERSARY, */ + E_CONTACT_CSV_ANNIVERSARY_YEAR, + E_CONTACT_CSV_ANNIVERSARY_MONTH, + E_CONTACT_CSV_ANNIVERSARY_DAY, + /*E_CONTACT_CSV_BIRTH_DATE, */ + E_CONTACT_CSV_BIRTH_DATE_YEAR, + E_CONTACT_CSV_BIRTH_DATE_MONTH, + E_CONTACT_CSV_BIRTH_DATE_DAY, + E_CONTACT_CSV_MAILER, + E_CONTACT_CSV_NAME_OR_ORG, + E_CONTACT_CSV_CATEGORIES, + E_CONTACT_CSV_FAMILY_NAME, + E_CONTACT_CSV_GIVEN_NAME, + E_CONTACT_CSV_WANTS_HTML, + E_CONTACT_CSV_IS_LIST, + E_CONTACT_CSV_LAST }; -struct _ECardCSVFieldData +struct _EContactCSVFieldData { gint csv_field; - gint simple_field; + gint contact_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, +static EContactCSVFieldData csv_field_data[] = { + {E_CONTACT_CSV_FILE_AS, E_CONTACT_FILE_AS, ""}, + {E_CONTACT_CSV_FULL_NAME, E_CONTACT_CSV_FULL_NAME, ""}, + {E_CONTACT_CSV_EMAIL, E_CONTACT_EMAIL, ""}, + {E_CONTACT_CSV_PHONE_PRIMARY, E_CONTACT_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_CONTACT_CSV_PHONE_ASSISTANT, + E_CONTACT_PHONE_ASSISTANT, ""}, + {E_CONTACT_CSV_PHONE_BUSINESS, + E_CONTACT_PHONE_BUSINESS, ""}, + {E_CONTACT_CSV_PHONE_CALLBACK, + E_CONTACT_PHONE_CALLBACK, ""}, + {E_CONTACT_CSV_PHONE_COMPANY, E_CONTACT_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, + {E_CONTACT_CSV_PHONE_HOME, E_CONTACT_PHONE_HOME, ""}, + {E_CONTACT_CSV_ORG, E_CONTACT_ORG, ""}, + /*E_CONTACT_CSV_ADDRESS_BUSINESS, */ + {E_CONTACT_CSV_ADDRESS_BUSINESS_STREET, NOMAP, "Business Address"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_EXT, NOMAP, + {E_CONTACT_CSV_ADDRESS_BUSINESS_EXT, NOMAP, "Business Address2"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_CITY, NOMAP, + {E_CONTACT_CSV_ADDRESS_BUSINESS_CITY, NOMAP, "Business Address City"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_REGION, NOMAP, + {E_CONTACT_CSV_ADDRESS_BUSINESS_REGION, NOMAP, "Business Address State"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_POSTCODE, NOMAP, + {E_CONTACT_CSV_ADDRESS_BUSINESS_POSTCODE, NOMAP, "Business Address PostCode"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_COUNTRY, NOMAP, + {E_CONTACT_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, + /*E_CONTACT_CSV_ADDRESS_HOME, */ + {E_CONTACT_CSV_ADDRESS_HOME_STREET, NOMAP, "Home Address"}, + {E_CONTACT_CSV_ADDRESS_HOME_EXT, NOMAP, "Home Address2"}, + {E_CONTACT_CSV_ADDRESS_HOME_CITY, NOMAP, "Home Address City"}, + {E_CONTACT_CSV_ADDRESS_HOME_REGION, NOMAP, "Home Address State"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_POSTCODE, NOMAP, + {E_CONTACT_CSV_ADDRESS_HOME_POSTCODE, NOMAP, "Home Address PostCode"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_COUNTRY, NOMAP, + {E_CONTACT_CSV_ADDRESS_HOME_COUNTRY, NOMAP, "Home Address Country"}, - {E_CARD_SIMPLE_FIELD_CSV_PHONE_MOBILE, E_CARD_SIMPLE_FIELD_PHONE_MOBILE, + {E_CONTACT_CSV_PHONE_MOBILE, E_CONTACT_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_CONTACT_CSV_PHONE_CAR, E_CONTACT_PHONE_CAR, ""}, + {E_CONTACT_CSV_PHONE_BUSINESS_FAX, + E_CONTACT_PHONE_BUSINESS_FAX, ""}, + {E_CONTACT_CSV_PHONE_HOME_FAX, + E_CONTACT_PHONE_HOME_FAX, ""}, + {E_CONTACT_CSV_PHONE_BUSINESS_2, + E_CONTACT_PHONE_BUSINESS_2, ""}, + {E_CONTACT_CSV_PHONE_HOME_2, E_CONTACT_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_CONTACT_CSV_PHONE_ISDN, E_CONTACT_PHONE_ISDN, ""}, + {E_CONTACT_CSV_PHONE_OTHER, E_CONTACT_PHONE_OTHER, ""}, + {E_CONTACT_CSV_PHONE_OTHER_FAX, + E_CONTACT_PHONE_OTHER_FAX, ""}, + {E_CONTACT_CSV_PHONE_PAGER, E_CONTACT_PHONE_PAGER, ""}, + {E_CONTACT_CSV_PHONE_RADIO, E_CONTACT_PHONE_RADIO, ""}, + {E_CONTACT_CSV_PHONE_TELEX, E_CONTACT_PHONE_TELEX, ""}, + {E_CONTACT_CSV_PHONE_TTYTDD, E_CONTACT_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, + /*E_CONTACT_CSV_ADDRESS_OTHER, */ + {E_CONTACT_CSV_ADDRESS_OTHER_STREET, NOMAP, "Other Address"}, + {E_CONTACT_CSV_ADDRESS_OTHER_EXT, NOMAP, "Other Address2"}, + {E_CONTACT_CSV_ADDRESS_OTHER_CITY, NOMAP, "Other Address City"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_REGION, NOMAP, + {E_CONTACT_CSV_ADDRESS_OTHER_REGION, NOMAP, "Other Address State"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_POSTCODE, NOMAP, + {E_CONTACT_CSV_ADDRESS_OTHER_POSTCODE, NOMAP, "Other Address PostCode"}, - {E_CARD_SIMPLE_FIELD_CSV_ADDRESS_OTHER_COUNTRY, NOMAP, + {E_CONTACT_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, ""} + {E_CONTACT_CSV_EMAIL_2, E_CONTACT_EMAIL_2, ""}, + {E_CONTACT_CSV_EMAIL_3, E_CONTACT_EMAIL_3, ""}, + {E_CONTACT_CSV_HOMEPAGE_URL, E_CONTACT_HOMEPAGE_URL, ""}, + {E_CONTACT_CSV_ORG_UNIT, E_CONTACT_ORG_UNIT, ""}, + {E_CONTACT_CSV_OFFICE, E_CONTACT_OFFICE, ""}, + {E_CONTACT_CSV_TITLE, E_CONTACT_TITLE, ""}, + {E_CONTACT_CSV_ROLE, E_CONTACT_ROLE, ""}, + {E_CONTACT_CSV_MANAGER, E_CONTACT_MANAGER, ""}, + {E_CONTACT_CSV_ASSISTANT, E_CONTACT_ASSISTANT, ""}, + {E_CONTACT_CSV_NICKNAME, E_CONTACT_NICKNAME, ""}, + {E_CONTACT_CSV_SPOUSE, E_CONTACT_SPOUSE, ""}, + {E_CONTACT_CSV_NOTE, E_CONTACT_NOTE, ""}, + {E_CONTACT_CSV_CALENDAR_URI, E_CONTACT_CALENDAR_URI, ""}, + {E_CONTACT_CSV_FREEBUSY_URL, E_CONTACT_FREEBUSY_URL, ""}, + /*E_CONTACT_ANNIVERSARY, */ + {E_CONTACT_CSV_ANNIVERSARY_YEAR, NOMAP, "Anniversary Year"}, + {E_CONTACT_CSV_ANNIVERSARY_MONTH, NOMAP, "Anniversary Month"}, + {E_CONTACT_CSV_ANNIVERSARY_DAY, NOMAP, "Anniversary Day"}, + /*E_CONTACT_BIRTH_DATE, */ + {E_CONTACT_CSV_BIRTH_DATE_YEAR, NOMAP, "Birth Year"}, + {E_CONTACT_CSV_BIRTH_DATE_MONTH, NOMAP, "Birth Month"}, + {E_CONTACT_CSV_BIRTH_DATE_DAY, NOMAP, "Birth Day"}, + {E_CONTACT_CSV_MAILER, E_CONTACT_MAILER, ""}, + {E_CONTACT_CSV_NAME_OR_ORG, E_CONTACT_NAME_OR_ORG, ""}, + {E_CONTACT_CSV_CATEGORIES, E_CONTACT_CATEGORIES, ""}, + {E_CONTACT_CSV_FAMILY_NAME, E_CONTACT_FAMILY_NAME, ""}, + {E_CONTACT_CSV_GIVEN_NAME, E_CONTACT_GIVEN_NAME, ""}, + {E_CONTACT_CSV_WANTS_HTML, E_CONTACT_WANTS_HTML, ""}, + {E_CONTACT_CSV_IS_LIST, E_CONTACT_IS_LIST, ""}, + {E_CONTACT_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); +gint e_contact_csv_get_contact_field (EContactFieldCSV csv_field); +gchar *e_contact_csv_get_name (EContactFieldCSV csv_field); +gchar *e_contact_csv_get (EContact * contact, EContactFieldCSV csv_field); +gchar *e_contact_csv_get_header_line (GSList * csv_all_fields); +gchar *e_contact_to_csv (EContact * contact, GSList * csv_all_fields); +gchar *e_contact_get_csv (EContact * contact, GSList * csv_all_fields); +gchar *delivery_address_get_sub_field (const EContactAddress * 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); +gchar *escape_string (gchar * orig); +int output_n_cards_file (FILE * outputfile, GList *contacts, 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) +e_contact_csv_get_contact_field (EContactFieldCSV csv_field) { - return csv_field_data[csv_field].simple_field; + return csv_field_data[csv_field].contact_field; } gchar * -e_card_simple_csv_get_name (ECardSimpleFieldCSV csv_field) +e_contact_csv_get_name (EContactFieldCSV csv_field) { - gint simple_field; + gint contact_field; gchar *name; - gchar *esc_name; gchar *quoted_name; - ECardSimple *a_simple_card; + contact_field = e_contact_csv_get_contact_field (csv_field); - 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)); + if (contact_field != NOMAP) { + name = g_strdup (e_contact_field_name (contact_field)); } else { name = g_strdup (csv_field_data[csv_field].csv_name); } - esc_name = g_strescape (name, NULL); + quoted_name = escape_string (name); 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) +e_contact_csv_get (EContact * contact, EContactFieldCSV csv_field) { - gint simple_field; + gint contact_field; gchar *field_value; - gchar *esc_field_value; gchar *quoted_field_value; - const ECardDeliveryAddress *delivery_address = NULL; + EContactAddress *delivery_address = NULL; + EContactDate *date; - simple_field = e_card_simple_csv_get_simple_field (csv_field); + contact_field = e_contact_csv_get_contact_field (csv_field); - if (simple_field != NOMAP) { - field_value = e_card_simple_get (simple, simple_field); + if (contact_field != NOMAP) { + field_value = e_contact_get (contact, contact_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); + case E_CONTACT_CSV_ADDRESS_HOME_STREET: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_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); + case E_CONTACT_CSV_ADDRESS_HOME_EXT: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_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); + case E_CONTACT_CSV_ADDRESS_HOME_CITY: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_HOME); + field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_LOCALITY); 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); + case E_CONTACT_CSV_ADDRESS_HOME_REGION: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_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); + case E_CONTACT_CSV_ADDRESS_HOME_POSTCODE: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_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); + case E_CONTACT_CSV_ADDRESS_HOME_COUNTRY: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_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); + case E_CONTACT_CSV_ADDRESS_BUSINESS_STREET: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_WORK); 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); + case E_CONTACT_CSV_ADDRESS_BUSINESS_EXT: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_WORK); 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); + case E_CONTACT_CSV_ADDRESS_BUSINESS_CITY: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_WORK); + field_value = delivery_address_get_sub_field (delivery_address, DELIVERY_ADDRESS_LOCALITY); 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); + case E_CONTACT_CSV_ADDRESS_BUSINESS_REGION: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_WORK); 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); + case E_CONTACT_CSV_ADDRESS_BUSINESS_POSTCODE: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_WORK); 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); + case E_CONTACT_CSV_ADDRESS_BUSINESS_COUNTRY: + delivery_address = e_contact_get (contact, E_CONTACT_ADDRESS_WORK); 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 { + case E_CONTACT_CSV_BIRTH_DATE_YEAR: + date = e_contact_get (contact, E_CONTACT_BIRTH_DATE); + if (date) { + field_value = g_strdup_printf ("%04d", date->year); + e_contact_date_free (date); + } + 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 { + case E_CONTACT_CSV_BIRTH_DATE_MONTH: + date = e_contact_get (contact, E_CONTACT_BIRTH_DATE); + if (date) { + field_value = g_strdup_printf ("%04d", date->month); + e_contact_date_free (date); + } + 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 { + case E_CONTACT_CSV_BIRTH_DATE_DAY: + date = e_contact_get (contact, E_CONTACT_BIRTH_DATE); + if (date) { + field_value = g_strdup_printf ("%04d", date->day); + e_contact_date_free (date); + } + else { field_value = g_strdup (""); } break; @@ -407,18 +401,18 @@ e_card_simple_csv_get (ECardSimple * simple, ECardSimpleFieldCSV csv_field) if (field_value == NULL) field_value = g_strdup (""); - esc_field_value = g_strescape (field_value, NULL); + quoted_field_value = escape_string (field_value); g_free (field_value); - quoted_field_value = quote_string (esc_field_value); - g_free (esc_field_value); + if (delivery_address) + e_contact_address_free (delivery_address); return quoted_field_value; } gchar * -e_card_simple_csv_get_header_line (GSList * csv_all_fields) +e_contact_csv_get_header_line (GSList * csv_all_fields) { guint field_number; @@ -433,7 +427,7 @@ e_card_simple_csv_get_header_line (GSList * csv_all_fields) 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); + *(field_name_array + loop_counter) = e_contact_csv_get_name (csv_field); } header_line = g_strjoinv (COMMA_SEPARATOR, field_name_array); @@ -449,7 +443,7 @@ e_card_simple_csv_get_header_line (GSList * csv_all_fields) gchar * -e_card_simple_to_csv (ECardSimple * simple, GSList * csv_all_fields) +e_contact_to_csv (EContact * contact, GSList * csv_all_fields) { guint field_number; gint csv_field; @@ -463,7 +457,7 @@ e_card_simple_to_csv (ECardSimple * simple, GSList * csv_all_fields) 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); + *(field_value_array + loop_counter) = e_contact_csv_get (contact, csv_field); } aline = g_strjoinv (COMMA_SEPARATOR, field_value_array); @@ -479,14 +473,11 @@ e_card_simple_to_csv (ECardSimple * simple, GSList * csv_all_fields) gchar * -e_card_get_csv (ECard * card, GSList * csv_all_fields) +e_contact_get_csv (EContact * contact, 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)); + aline = e_contact_to_csv (contact, csv_all_fields); return aline; } @@ -502,7 +493,8 @@ check_null_pointer (gchar * orig) return result; } -gchar *delivery_address_get_sub_field (const ECardDeliveryAddress * address, DeliveryAddressField sub_field) +gchar * +delivery_address_get_sub_field (const EContactAddress * address, DeliveryAddressField sub_field) { gchar *sub_field_value; gchar *str_temp, *str_temp_a; @@ -518,8 +510,8 @@ gchar *delivery_address_get_sub_field (const ECardDeliveryAddress * address, Del 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); + case DELIVERY_ADDRESS_LOCALITY: + sub_field_value = check_null_pointer (address->locality); break; case DELIVERY_ADDRESS_REGION: sub_field_value = check_null_pointer (address->region); @@ -540,37 +532,73 @@ gchar *delivery_address_get_sub_field (const ECardDeliveryAddress * address, Del } gchar * -quote_string (gchar *orig) +escape_string (gchar *orig) { + const guchar *p; + gchar *dest; + gchar *q; + if (orig == NULL) return g_strdup ("\"\""); - return g_strdup_printf("\"%s\"", orig); + + p = (guchar *) orig; + /* Each source byte needs maximally two destination chars (\n), and the extra 2 is for the leading and trailing '"' */ + q = dest = g_malloc (strlen (orig) * 2 + 1 + 2); + + *q++ = '\"'; + while (*p) + { + switch (*p) + { + case '\n': + *q++ = '\\'; + *q++ = 'n'; + break; + case '\r': + *q++ = '\\'; + *q++ = 'r'; + break; + case '\\': + *q++ = '\\'; + *q++ = '\\'; + break; + case '"': + *q++ = '"'; + *q++ = '"'; + break; + default: + *q++ = *p; + } + p++; + } + + *q++ = '\"'; + *q = 0; + + return dest; } int -output_n_cards_file (FILE * outputfile, ECardCursor * cursor, int size, int begin_no, CARD_FORMAT format) +output_n_cards_file (FILE * outputfile, GList *contacts, 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); + EContact *contact = g_list_nth_data (contacts, i); + gchar *vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30); 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); + gchar *csv_fields_name = e_contact_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); + EContact *contact = g_list_nth_data (contacts, i); + gchar *csv = e_contact_get_csv (contact, pre_defined_fields); fprintf (outputfile, "%s\n", csv); g_free (csv); - g_object_unref (G_OBJECT (card)); - } } @@ -601,7 +629,7 @@ fork_to_background (void) static void -action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * cursor, ActionContext * p_actctx) +action_list_cards (GList *contacts, ActionContext * p_actctx) { FILE *outputfile; long length; @@ -611,7 +639,7 @@ action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * CARD_FORMAT format; int size; - length = e_card_cursor_get_length (cursor); + length = g_list_length (contacts); if (length <= 0) { g_warning ("Couldn't load addressbook correctly!!!! %s####", p_actctx->action_list_cards.addressbook_folder_uri); @@ -636,9 +664,7 @@ action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * else format = CARD_FORMAT_CSV; - output_n_cards_file (outputfile, cursor, length, 0, format); - - + output_n_cards_file (outputfile, contacts, length, 0, format); if (p_actctx->action_list_cards.output_file != NULL) { fclose (outputfile); @@ -673,7 +699,7 @@ action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * format = CARD_FORMAT_VCARD; else format = CARD_FORMAT_CSV; - output_n_cards_file (outputfile, cursor, size, series_no * size, format); + output_n_cards_file (outputfile, contacts, size, series_no * size, format); fclose (outputfile); @@ -689,92 +715,82 @@ action_list_cards_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * 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_CONTACT_CSV_GIVEN_NAME)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_FAMILY_NAME)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_FULL_NAME)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_NICKNAME)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_EMAIL)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_EMAIL_2)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_WANTS_HTML)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_PHONE_BUSINESS)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_PHONE_HOME)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_PHONE_BUSINESS_FAX)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_PHONE_PAGER)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_PHONE_MOBILE)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_HOME_STREET)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_HOME_EXT)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_HOME_CITY)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_HOME_REGION)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_POSTCODE)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_HOME_POSTCODE)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_HOME_COUNTRY)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_HOME_COUNTRY)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_STREET)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_BUSINESS_STREET)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_EXT)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_BUSINESS_EXT)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_CITY)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_BUSINESS_CITY)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_REGION)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_BUSINESS_REGION)); *pre_defined_fields = - g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CARD_SIMPLE_FIELD_CSV_ADDRESS_BUSINESS_POSTCODE)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_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)); + g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ADDRESS_BUSINESS_COUNTRY)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_TITLE)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_OFFICE)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_ORG)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_HOMEPAGE_URL)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_CALENDAR_URI)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_BIRTH_DATE_YEAR)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_BIRTH_DATE_MONTH)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_CSV_BIRTH_DATE_DAY)); + *pre_defined_fields = g_slist_append (*pre_defined_fields, GINT_TO_POINTER (E_CONTACT_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); + EBook *book; + EBookQuery *query; + GList *contacts; + + if (p_actctx->action_list_cards.addressbook_folder_uri != NULL) { + book = e_book_new_from_uri (p_actctx->action_list_cards.addressbook_folder_uri, NULL); + } else { + book = e_book_new_default_addressbook (NULL); + } + + if (!book + || !e_book_open (book, TRUE, NULL)) { + g_warning ("Couldn't load addressbook %s", p_actctx->action_list_cards.addressbook_folder_uri); + exit (-1); + } + + query = e_book_query_any_field_contains (""); + e_book_get_contacts (book, query, &contacts, NULL); + e_book_query_unref (query); + + action_list_cards (contacts, p_actctx); + + g_list_foreach (contacts, (GFunc)g_object_unref, NULL); + g_list_free (contacts); return SUCCESS; } diff --git a/addressbook/tools/evolution-addressbook-export-list-folders.c b/addressbook/tools/evolution-addressbook-export-list-folders.c index 8922422a8f..78fdca7f9f 100644 --- a/addressbook/tools/evolution-addressbook-export-list-folders.c +++ b/addressbook/tools/evolution-addressbook-export-list-folders.c @@ -28,72 +28,72 @@ #include <libbonobo.h> #include <libgnome/libgnome.h> -#include <ebook/e-book.h> -#include <ebook/e-book-util.h> +#include <libebook/e-book.h> #include "evolution-addressbook-export.h" -static void -action_list_folders_get_cursor_cb (EBook * book, EBookStatus status, ECardCursor * cursor, ActionContext * p_actctx) +guint +action_list_folders_init (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 */ + ESourceList *addressbooks = NULL; + GSList *groups, *group; + FILE *outputfile = NULL; + + if (!e_book_get_addressbooks (&addressbooks, NULL)) { + g_warning (_("Couldn't get list of addressbooks")); + exit (-1); + } + + if (p_actctx->action_list_folders.output_file != NULL) { 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 (); -} + groups = e_source_list_peek_groups (addressbooks); + for (group = groups; group; group = group->next) { + ESourceGroup *g = group->data; + GSList *sources, *source; -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); - } -} + sources = e_source_group_peek_sources (g); + for (source = sources; source; source = source->next) { + ESource *s = source->data; + EBook *book; + EBookQuery *query; + GList *contacts; + char *uri; + const char *name; -static guint -action_list_folders_run (ActionContext * p_actctx) -{ - EBook *book; - book = e_book_new (); + book = e_book_new (s, NULL); + if (!book + || !e_book_open (book, TRUE, NULL)) { + g_warning (_("failed to open book")); + continue; + } - e_book_load_default_book (book, (EBookCallback)action_list_folders_open_cb, p_actctx); - return SUCCESS; -} + query = e_book_query_any_field_contains (""); + e_book_get_contacts (book, query, &contacts, NULL); + e_book_query_unref (query); -guint -action_list_folders_init (ActionContext * p_actctx) -{ - g_idle_add ((GSourceFunc) action_list_folders_run, p_actctx); + uri = e_source_get_uri (s); + name = e_source_peek_name (s); + + if (outputfile) + fprintf (outputfile, "\"%s\",\"%s\",%d\n", uri, name, g_list_length (contacts)); + else + printf ("\"%s\",\"%s\",%d\n", uri, name, g_list_length (contacts)); + + g_free (uri); + g_list_foreach (contacts, (GFunc)g_object_unref, NULL); + g_list_free (contacts); + + g_object_unref (book); + } + } + + if (outputfile) + fclose (outputfile); return SUCCESS; } diff --git a/addressbook/tools/evolution-addressbook-export.c b/addressbook/tools/evolution-addressbook-export.c index a61880ed14..b175024685 100644 --- a/addressbook/tools/evolution-addressbook-export.c +++ b/addressbook/tools/evolution-addressbook-export.c @@ -28,7 +28,7 @@ #include <bonobo/bonobo-main.h> #include <gnome.h> -#include <ebook/e-book.h> +#include <libebook/e-book.h> #include "evolution-addressbook-export.h" @@ -154,9 +154,7 @@ main (int argc, char **argv) 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; + exit (0); } |