diff options
author | Christopher James Lahey <clahey@ximian.com> | 2001-09-02 14:27:53 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-09-02 14:27:53 +0800 |
commit | 0fbeb97f39c4c27665b53ae45707ba065d71ebb2 (patch) | |
tree | cfbaaca6c2389b42737c09e6d779f42ef890b111 /addressbook/backend | |
parent | 03a5d4a3d316d8ec923d7bde331b1e96d08c6720 (diff) | |
download | gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.tar gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.tar.gz gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.tar.bz2 gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.tar.lz gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.tar.xz gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.tar.zst gsoc2013-evolution-0fbeb97f39c4c27665b53ae45707ba065d71ebb2.zip |
Use e_card_get_vcard_assume_utf8 instead of e_card_get_vcard here since
2001-09-02 Christopher James Lahey <clahey@ximian.com>
* backend/ebook/e-book.c (e_book_add_card, e_book_commit_card),
backend/pas/pas-backend-file.c (do_create),
backend/pas/pas-backend-ldap.c
(create_card_handler, remove_card_handler, modify_card_handler,
pas_backend_ldap_process_get_vcard, poll_ldap): Use
e_card_get_vcard_assume_utf8 instead of e_card_get_vcard here
since all internal communications and database storage are assumed
to be utf8.
* backend/ebook/e-card-simple.c, backend/ebook/e-card-simple.h
(e_card_simple_duplicate): Simplified this function considerably.
(e_card_simple_get_vcard_assume_utf8): Added this function.
* backend/ebook/e-card.c, backend/ebook/e-card.h (e_card_new,
e_card_load_cards_from_file, e_card_load_cards_from_string): Made
these functions pay attention to charset attributes.
(e_card_new_with_default_charset,
e_card_load_cards_from_file_with_default_charset,
e_card_load_cards_from_string_with_default_charset): New functions
that let you change the default charset from UTF-8.
(e_card_get_vcard): Made this write out charset attributes when
necessary.
(e_card_get_vcard_assume_utf8): New function that writes out a
card without writing out charset attributes.
* backend/ebook/evolution-vcard-importer.c (book_open_cb),
backend/ebook/load-gnomecard-addressbook.c (book_open_cb),
backend/ebook/test-card.c (main),
gui/component/addressbook-component.c
(destination_folder_handle_drop), gui/contact-editor/test-editor.c
(main), gui/contact-list-editor/e-contact-list-editor.c
(table_drag_data_received_cb), gui/widgets/e-addressbook-view.c
(selection_received), gui/widgets/e-minicard-control.c
(pstream_load): Changed the default charset to be used here to
ISO-8859-1.
* backend/ebook/load-gnomecard-addressbook.c (add_card_cb),
backend/ebook/load-pine-addressbook.c (add_card_cb),
backend/ebook/test-client-list.c (get_cursor_cb),
backend/ebook/test-client.c (get_cursor_cb, get_card_cb): Use
e_card_get_vcard_assume_utf8 to print out testing strings.
* gui/component/select-names/e-select-names-model.c,
gui/component/select-names/e-select-names-model.h
(e_select_names_model_contains): Changed this to be const
EDestination *dest to fix a warning.
* gui/contact-editor/e-contact-editor.c (e_contact_editor_init):
Translate window title here.
svn path=/trunk/; revision=12558
Diffstat (limited to 'addressbook/backend')
-rw-r--r-- | addressbook/backend/ebook/e-book.c | 4 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-simple.c | 19 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card-simple.h | 113 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.c | 454 | ||||
-rw-r--r-- | addressbook/backend/ebook/e-card.h | 97 | ||||
-rw-r--r-- | addressbook/backend/ebook/evolution-vcard-importer.c | 5 | ||||
-rw-r--r-- | addressbook/backend/ebook/load-gnomecard-addressbook.c | 4 | ||||
-rw-r--r-- | addressbook/backend/ebook/load-pine-addressbook.c | 2 | ||||
-rw-r--r-- | addressbook/backend/ebook/test-card.c | 4 | ||||
-rw-r--r-- | addressbook/backend/ebook/test-client-list.c | 2 | ||||
-rw-r--r-- | addressbook/backend/ebook/test-client.c | 4 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 2 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.c | 12 |
13 files changed, 423 insertions, 299 deletions
diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c index a9b186b375..856b1d92b5 100644 --- a/addressbook/backend/ebook/e-book.c +++ b/addressbook/backend/ebook/e-book.c @@ -917,7 +917,7 @@ e_book_add_card (EBook *book, return FALSE; } - vcard = e_card_get_vcard (card); + vcard = e_card_get_vcard_assume_utf8 (card); if (vcard == NULL) { g_warning ("e_book_add_card: Cannot convert card to VCard string!\n"); @@ -999,7 +999,7 @@ e_book_commit_card (EBook *book, return FALSE; } - vcard = e_card_get_vcard (card); + vcard = e_card_get_vcard_assume_utf8 (card); if (vcard == NULL) { g_warning ("e_book_commit_card: Error " diff --git a/addressbook/backend/ebook/e-card-simple.c b/addressbook/backend/ebook/e-card-simple.c index 713b587cb2..f41c4f0cb5 100644 --- a/addressbook/backend/ebook/e-card-simple.c +++ b/addressbook/backend/ebook/e-card-simple.c @@ -240,10 +240,8 @@ e_card_simple_new (ECard *card) ECardSimple * e_card_simple_duplicate(ECardSimple *simple) { - char *vcard = e_card_simple_get_vcard(simple); - ECard *card = e_card_new(vcard); + ECard *card = simple->card ? e_card_duplicate (simple->card) : e_card_new (""); ECardSimple *new_simple = e_card_simple_new(card); - g_free (vcard); return new_simple; } @@ -293,6 +291,21 @@ e_card_simple_get_vcard (ECardSimple *simple) return g_strdup(""); } +/** + * e_card_simple_get_vcard_assume_utf8: + * @simple: an #ECardSimple + * + * Returns: a string in vcard format, which is wrapped by the @simple. + */ +char * +e_card_simple_get_vcard_assume_utf8 (ECardSimple *simple) +{ + if (simple->card) + return e_card_get_vcard_assume_utf8(simple->card); + else + return g_strdup(""); +} + static void e_card_simple_class_init (ECardSimpleClass *klass) { diff --git a/addressbook/backend/ebook/e-card-simple.h b/addressbook/backend/ebook/e-card-simple.h index 9e758516d3..675695a7ea 100644 --- a/addressbook/backend/ebook/e-card-simple.h +++ b/addressbook/backend/ebook/e-card-simple.h @@ -147,73 +147,74 @@ struct _ECardSimpleClass { }; typedef void (*ECardSimpleArbitraryCallback) (const ECardArbitrary *arbitrary, gpointer closure); -ECardSimple *e_card_simple_new (ECard *card); -const char *e_card_simple_get_id (ECardSimple *simple); -void e_card_simple_set_id (ECardSimple *simple, - const gchar *character); -char *e_card_simple_get_vcard (ECardSimple *simple); -ECardSimple *e_card_simple_duplicate (ECardSimple *simple); -char *e_card_simple_get (ECardSimple *simple, - ECardSimpleField field); -const char *e_card_simple_get_const (ECardSimple *simple, - ECardSimpleField field); -void e_card_simple_set (ECardSimple *simple, - ECardSimpleField field, - const char *data); -ECardSimpleType e_card_simple_type (ECardSimple *simple, - ECardSimpleField field); - -const char *e_card_simple_get_ecard_field (ECardSimple *simple, - ECardSimpleField field); -const char *e_card_simple_get_name (ECardSimple *simple, - ECardSimpleField field); -const char *e_card_simple_get_short_name (ECardSimple *simple, - ECardSimpleField field); +ECardSimple *e_card_simple_new (ECard *card); +const char *e_card_simple_get_id (ECardSimple *simple); +void e_card_simple_set_id (ECardSimple *simple, + const gchar *character); +char *e_card_simple_get_vcard (ECardSimple *simple); +char *e_card_simple_get_vcard_assume_utf8 (ECardSimple *simple); +ECardSimple *e_card_simple_duplicate (ECardSimple *simple); +char *e_card_simple_get (ECardSimple *simple, + ECardSimpleField field); +const char *e_card_simple_get_const (ECardSimple *simple, + ECardSimpleField field); +void e_card_simple_set (ECardSimple *simple, + ECardSimpleField field, + const char *data); +ECardSimpleType e_card_simple_type (ECardSimple *simple, + ECardSimpleField field); + +const char *e_card_simple_get_ecard_field (ECardSimple *simple, + ECardSimpleField field); +const char *e_card_simple_get_name (ECardSimple *simple, + ECardSimpleField field); +const char *e_card_simple_get_short_name (ECardSimple *simple, + ECardSimpleField field); /* Use these only if building lists of specific types. It should be * easier to use the above if you consider a phone field to be the * same as any other field. */ -const ECardPhone *e_card_simple_get_phone (ECardSimple *simple, - ECardSimplePhoneId id); -const char *e_card_simple_get_email (ECardSimple *simple, - ECardSimpleEmailId id); -const ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, - ECardSimpleAddressId id); -const ECardDeliveryAddress *e_card_simple_get_delivery_address (ECardSimple *simple, - ECardSimpleAddressId id); -void e_card_simple_set_phone (ECardSimple *simple, - ECardSimplePhoneId id, - const ECardPhone *phone); -void e_card_simple_set_email (ECardSimple *simple, - ECardSimpleEmailId id, - const char *email); -void e_card_simple_set_address (ECardSimple *simple, - ECardSimpleAddressId id, - const ECardAddrLabel *address); -void e_card_simple_set_delivery_address (ECardSimple *simple, - ECardSimpleAddressId id, - const ECardDeliveryAddress *delivery); -void e_card_simple_arbitrary_foreach (ECardSimple *simple, - ECardSimpleArbitraryCallback *callback, - gpointer closure); -const ECardArbitrary *e_card_simple_get_arbitrary (ECardSimple *simple, - const char *key); +const ECardPhone *e_card_simple_get_phone (ECardSimple *simple, + ECardSimplePhoneId id); +const char *e_card_simple_get_email (ECardSimple *simple, + ECardSimpleEmailId id); +const ECardAddrLabel *e_card_simple_get_address (ECardSimple *simple, + ECardSimpleAddressId id); +const ECardDeliveryAddress *e_card_simple_get_delivery_address (ECardSimple *simple, + ECardSimpleAddressId id); +void e_card_simple_set_phone (ECardSimple *simple, + ECardSimplePhoneId id, + const ECardPhone *phone); +void e_card_simple_set_email (ECardSimple *simple, + ECardSimpleEmailId id, + const char *email); +void e_card_simple_set_address (ECardSimple *simple, + ECardSimpleAddressId id, + const ECardAddrLabel *address); +void e_card_simple_set_delivery_address (ECardSimple *simple, + ECardSimpleAddressId id, + const ECardDeliveryAddress *delivery); +void e_card_simple_arbitrary_foreach (ECardSimple *simple, + ECardSimpleArbitraryCallback *callback, + gpointer closure); +const ECardArbitrary *e_card_simple_get_arbitrary (ECardSimple *simple, + const char *key); /* Any of these except key can be NULL */ -void e_card_simple_set_arbitrary (ECardSimple *simple, - const char *key, - const char *type, - const char *value); -void e_card_simple_sync_card (ECardSimple *simple); +void e_card_simple_set_arbitrary (ECardSimple *simple, + const char *key, + const char *type, + const char *value); +void e_card_simple_sync_card (ECardSimple *simple); /* These map between the individual list types and ECardSimpleField */ -ECardSimpleField e_card_simple_map_phone_to_field (ECardSimplePhoneId phone_id); -ECardSimpleField e_card_simple_map_email_to_field (ECardSimpleEmailId email_id); -ECardSimpleField e_card_simple_map_address_to_field (ECardSimpleAddressId address_id); +ECardSimpleField e_card_simple_map_phone_to_field (ECardSimplePhoneId phone_id); +ECardSimpleField e_card_simple_map_email_to_field (ECardSimpleEmailId email_id); +ECardSimpleField e_card_simple_map_address_to_field (ECardSimpleAddressId address_id); /* Standard Gtk function */ -GtkType e_card_simple_get_type (void); +GtkType e_card_simple_get_type (void); #endif /* ! __E_CARD_SIMPLE_H__ */ diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c index 57619b0080..4ac7dd0efa 100644 --- a/addressbook/backend/ebook/e-card.c +++ b/addressbook/backend/ebook/e-card.c @@ -13,6 +13,7 @@ #include "e-card.h" #include <gal/util/e-i18n.h> +#include <gal/widgets/e-unicode.h> #include <ctype.h> #include <stdio.h> @@ -82,7 +83,7 @@ enum { #if 0 static VObject *card_convert_to_vobject (ECard *crd); #endif -static void parse(ECard *card, VObject *vobj); +static void parse(ECard *card, VObject *vobj, char *default_charset); static void e_card_init (ECard *card); static void e_card_class_init (ECardClass *klass); @@ -90,48 +91,48 @@ static void e_card_destroy (GtkObject *object); static void e_card_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); static void e_card_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void assign_string(VObject *vobj, char **string); +static void assign_string(VObject *vobj, char *default_charset, char **string); -char *e_v_object_get_child_value(VObject *vobj, char *name); +char *e_v_object_get_child_value(VObject *vobj, char *name, char *default_charset); static ECardDate e_card_date_from_string (char *str); -static void parse_bday(ECard *card, VObject *object); -static void parse_full_name(ECard *card, VObject *object); -static void parse_file_as(ECard *card, VObject *object); -static void parse_name(ECard *card, VObject *object); -static void parse_email(ECard *card, VObject *object); -static void parse_phone(ECard *card, VObject *object); -static void parse_address(ECard *card, VObject *object); -static void parse_address_label(ECard *card, VObject *object); -static void parse_url(ECard *card, VObject *object); -static void parse_org(ECard *card, VObject *object); -static void parse_office(ECard *card, VObject *object); -static void parse_title(ECard *card, VObject *object); -static void parse_role(ECard *card, VObject *object); -static void parse_manager(ECard *card, VObject *object); -static void parse_assistant(ECard *card, VObject *object); -static void parse_nickname(ECard *card, VObject *object); -static void parse_spouse(ECard *card, VObject *object); -static void parse_anniversary(ECard *card, VObject *object); -static void parse_mailer(ECard *card, VObject *object); -static void parse_fburl(ECard *card, VObject *object); -static void parse_note(ECard *card, VObject *object); -static void parse_related_contacts(ECard *card, VObject *object); -static void parse_categories(ECard *card, VObject *object); -static void parse_wants_html(ECard *card, VObject *object); -static void parse_list(ECard *card, VObject *object); -static void parse_list_show_addresses(ECard *card, VObject *object); -static void parse_arbitrary(ECard *card, VObject *object); -static void parse_id(ECard *card, VObject *object); -static void parse_last_use(ECard *card, VObject *object); -static void parse_use_score(ECard *card, VObject *object); +static void parse_bday(ECard *card, VObject *object, char *default_charset); +static void parse_full_name(ECard *card, VObject *object, char *default_charset); +static void parse_file_as(ECard *card, VObject *object, char *default_charset); +static void parse_name(ECard *card, VObject *object, char *default_charset); +static void parse_email(ECard *card, VObject *object, char *default_charset); +static void parse_phone(ECard *card, VObject *object, char *default_charset); +static void parse_address(ECard *card, VObject *object, char *default_charset); +static void parse_address_label(ECard *card, VObject *object, char *default_charset); +static void parse_url(ECard *card, VObject *object, char *default_charset); +static void parse_org(ECard *card, VObject *object, char *default_charset); +static void parse_office(ECard *card, VObject *object, char *default_charset); +static void parse_title(ECard *card, VObject *object, char *default_charset); +static void parse_role(ECard *card, VObject *object, char *default_charset); +static void parse_manager(ECard *card, VObject *object, char *default_charset); +static void parse_assistant(ECard *card, VObject *object, char *default_charset); +static void parse_nickname(ECard *card, VObject *object, char *default_charset); +static void parse_spouse(ECard *card, VObject *object, char *default_charset); +static void parse_anniversary(ECard *card, VObject *object, char *default_charset); +static void parse_mailer(ECard *card, VObject *object, char *default_charset); +static void parse_fburl(ECard *card, VObject *object, char *default_charset); +static void parse_note(ECard *card, VObject *object, char *default_charset); +static void parse_related_contacts(ECard *card, VObject *object, char *default_charset); +static void parse_categories(ECard *card, VObject *object, char *default_charset); +static void parse_wants_html(ECard *card, VObject *object, char *default_charset); +static void parse_list(ECard *card, VObject *object, char *default_charset); +static void parse_list_show_addresses(ECard *card, VObject *object, char *default_charset); +static void parse_arbitrary(ECard *card, VObject *object, char *default_charset); +static void parse_id(ECard *card, VObject *object, char *default_charset); +static void parse_last_use(ECard *card, VObject *object, char *default_charset); +static void parse_use_score(ECard *card, VObject *object, char *default_charset); static ECardPhoneFlags get_phone_flags (VObject *vobj); static void set_phone_flags (VObject *vobj, ECardPhoneFlags flags); static ECardAddressFlags get_address_flags (VObject *vobj); static void set_address_flags (VObject *vobj, ECardAddressFlags flags); -typedef void (* ParsePropertyFunc) (ECard *card, VObject *object); +typedef void (* ParsePropertyFunc) (ECard *card, VObject *object, char *default_charset); struct { char *key; @@ -203,20 +204,14 @@ e_card_get_type (void) return card_type; } -/** - * e_card_new: - * @vcard: a string in vCard format - * - * Returns: a new #ECard that wraps the @vcard. - */ ECard * -e_card_new (char *vcard) +e_card_new_with_default_charset (char *vcard, char *default_charset) { ECard *card = E_CARD(gtk_type_new(e_card_get_type())); VObject *vobj = Parse_MIME(vcard, strlen(vcard)); while(vobj) { VObject *next; - parse(card, vobj); + parse(card, vobj, default_charset); next = nextVObjectInList(vobj); cleanVObject(vobj); vobj = next; @@ -230,10 +225,22 @@ e_card_new (char *vcard) return card; } +/** + * e_card_new: + * @vcard: a string in vCard format + * + * Returns: a new #ECard that wraps the @vcard. + */ +ECard * +e_card_new (char *vcard) +{ + return e_card_new_with_default_charset (vcard, "UTF-8"); +} + ECard * e_card_duplicate(ECard *card) { - char *vcard = e_card_get_vcard(card); + char *vcard = e_card_get_vcard_assume_utf8(card); ECard *new_card = e_card_new(vcard); g_free (vcard); @@ -370,35 +377,50 @@ e_card_date_to_string (ECardDate *dt) } static VObject * -e_card_get_vobject (ECard *card) +addPropValueUTF8(VObject *o, const char *p, const char *v) +{ + VObject *prop = addPropValue (o, p, v); + if (!e_utf8_is_ascii (v)) + addPropValue (prop, "CHARSET", "UTF-8"); + return prop; +} + +#define ADD_PROP_VALUE(o, p, v) (assumeUTF8 ? (addPropValue ((o), (p), (v))) : addPropValueUTF8 ((o), (p), (v))) +#define ADD_PROP_VALUE_SET_IS_ASCII(o, p, v) (addPropValue ((o), (p), (v)), is_ascii = is_ascii && e_utf8_is_ascii ((v))) + +static VObject * +e_card_get_vobject (ECard *card, gboolean assumeUTF8) { VObject *vobj; vobj = newVObject (VCCardProp); if ( card->file_as && *card->file_as ) - addPropValue(vobj, "X-EVOLUTION-FILE-AS", card->file_as); + ADD_PROP_VALUE(vobj, "X-EVOLUTION-FILE-AS", card->file_as); else if (card->file_as) addProp(vobj, "X-EVOLUTION-FILE_AS"); if ( card->fname ) - addPropValue(vobj, VCFullNameProp, card->fname); + ADD_PROP_VALUE(vobj, VCFullNameProp, card->fname); else if (card->fname) addProp(vobj, VCFullNameProp); if ( card->name && (card->name->prefix || card->name->given || card->name->additional || card->name->family || card->name->suffix) ) { VObject *nameprop; + gboolean is_ascii = TRUE; nameprop = addProp(vobj, VCNameProp); if ( card->name->prefix ) - addPropValue(nameprop, VCNamePrefixesProp, card->name->prefix); - if ( card->name->given ) - addPropValue(nameprop, VCGivenNameProp, card->name->given); + ADD_PROP_VALUE_SET_IS_ASCII(nameprop, VCNamePrefixesProp, card->name->prefix); + if ( card->name->given ) + ADD_PROP_VALUE_SET_IS_ASCII(nameprop, VCGivenNameProp, card->name->given); if ( card->name->additional ) - addPropValue(nameprop, VCAdditionalNamesProp, card->name->additional); + ADD_PROP_VALUE_SET_IS_ASCII(nameprop, VCAdditionalNamesProp, card->name->additional); if ( card->name->family ) - addPropValue(nameprop, VCFamilyNameProp, card->name->family); + ADD_PROP_VALUE_SET_IS_ASCII(nameprop, VCFamilyNameProp, card->name->family); if ( card->name->suffix ) - addPropValue(nameprop, VCNameSuffixesProp, card->name->suffix); + ADD_PROP_VALUE_SET_IS_ASCII(nameprop, VCNameSuffixesProp, card->name->suffix); + if (!(is_ascii || assumeUTF8)) + addPropValue (nameprop, "CHARSET", "UTF-8"); } else if (card->name) addProp(vobj, VCNameProp); @@ -409,24 +431,28 @@ e_card_get_vobject (ECard *card) for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { VObject *addressprop; ECardDeliveryAddress *address = (ECardDeliveryAddress *) e_iterator_get(iterator); + gboolean is_ascii = TRUE; + addressprop = addProp(vobj, VCAdrProp); set_address_flags (addressprop, address->flags); if ( address->po ) - addPropValue(addressprop, VCPostalBoxProp, address->po); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCPostalBoxProp, address->po); if ( address->ext ) - addPropValue(addressprop, VCExtAddressProp, address->ext); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCExtAddressProp, address->ext); if ( address->street ) - addPropValue(addressprop, VCStreetAddressProp, address->street); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCStreetAddressProp, address->street); if ( address->city ) - addPropValue(addressprop, VCCityProp, address->city); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCCityProp, address->city); if ( address->region ) - addPropValue(addressprop, VCRegionProp, address->region); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCRegionProp, address->region); if ( address->code ) - addPropValue(addressprop, VCPostalCodeProp, address->code); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCPostalCodeProp, address->code); if ( address->country ) - addPropValue(addressprop, VCCountryNameProp, address->country); + ADD_PROP_VALUE_SET_IS_ASCII(addressprop, VCCountryNameProp, address->country); addProp(addressprop, VCQuotedPrintableProp); + if (!(is_ascii || assumeUTF8)) + addPropValue (addressprop, "CHARSET", "UTF-8"); } gtk_object_unref(GTK_OBJECT(iterator)); } @@ -437,7 +463,7 @@ e_card_get_vobject (ECard *card) VObject *labelprop; ECardAddrLabel *address_label = (ECardAddrLabel *) e_iterator_get(iterator); if (address_label->data) - labelprop = addPropValue(vobj, VCDeliveryLabelProp, address_label->data); + labelprop = ADD_PROP_VALUE(vobj, VCDeliveryLabelProp, address_label->data); else labelprop = addProp(vobj, VCDeliveryLabelProp); @@ -452,7 +478,7 @@ e_card_get_vobject (ECard *card) for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { VObject *phoneprop; ECardPhone *phone = (ECardPhone *) e_iterator_get(iterator); - phoneprop = addPropValue(vobj, VCTelephoneProp, phone->number); + phoneprop = ADD_PROP_VALUE(vobj, VCTelephoneProp, phone->number); set_phone_flags (phoneprop, phone->flags); } @@ -463,7 +489,7 @@ e_card_get_vobject (ECard *card) EIterator *iterator = e_list_get_iterator(card->email); for ( ; e_iterator_is_valid(iterator) ;e_iterator_next(iterator) ) { VObject *emailprop; - emailprop = addPropValue(vobj, VCEmailAddressProp, (char *) e_iterator_get(iterator)); + emailprop = ADD_PROP_VALUE(vobj, VCEmailAddressProp, (char *) e_iterator_get(iterator)); addProp (emailprop, VCInternetProp); } gtk_object_unref(GTK_OBJECT(iterator)); @@ -472,81 +498,84 @@ e_card_get_vobject (ECard *card) if ( card->bday ) { char *value; value = e_card_date_to_string (card->bday); - addPropValue(vobj, VCBirthDateProp, value); + ADD_PROP_VALUE(vobj, VCBirthDateProp, value); g_free(value); } if (card->url) - addPropValue(vobj, VCURLProp, card->url); + ADD_PROP_VALUE(vobj, VCURLProp, card->url); if (card->org || card->org_unit) { VObject *orgprop; + gboolean is_ascii = TRUE; orgprop = addProp(vobj, VCOrgProp); if (card->org) - addPropValue(orgprop, VCOrgNameProp, card->org); + ADD_PROP_VALUE_SET_IS_ASCII(orgprop, VCOrgNameProp, card->org); if (card->org_unit) - addPropValue(orgprop, VCOrgUnitProp, card->org_unit); + ADD_PROP_VALUE_SET_IS_ASCII(orgprop, VCOrgUnitProp, card->org_unit); + if (!(is_ascii || assumeUTF8)) + addPropValue (orgprop, "CHARSET", "UTF-8"); } if (card->office) - addPropValue(vobj, "X-EVOLUTION-OFFICE", card->office); + ADD_PROP_VALUE(vobj, "X-EVOLUTION-OFFICE", card->office); if (card->title) - addPropValue(vobj, VCTitleProp, card->title); + ADD_PROP_VALUE(vobj, VCTitleProp, card->title); if (card->role) - addPropValue(vobj, VCBusinessRoleProp, card->role); + ADD_PROP_VALUE(vobj, VCBusinessRoleProp, card->role); if (card->manager) - addPropValue(vobj, "X-EVOLUTION-MANAGER", card->manager); + ADD_PROP_VALUE(vobj, "X-EVOLUTION-MANAGER", card->manager); if (card->assistant) - addPropValue(vobj, "X-EVOLUTION-ASSISTANT", card->assistant); + ADD_PROP_VALUE(vobj, "X-EVOLUTION-ASSISTANT", card->assistant); if (card->nickname) - addPropValue(vobj, "NICKNAME", card->nickname); + ADD_PROP_VALUE(vobj, "NICKNAME", card->nickname); if (card->spouse) - addPropValue(vobj, "X-EVOLUTION-SPOUSE", card->spouse); + ADD_PROP_VALUE(vobj, "X-EVOLUTION-SPOUSE", card->spouse); if ( card->anniversary ) { char *value; value = e_card_date_to_string (card->anniversary); - addPropValue(vobj, "X-EVOLUTION-ANNIVERSARY", value); + ADD_PROP_VALUE(vobj, "X-EVOLUTION-ANNIVERSARY", value); g_free(value); } if (card->mailer) { - addPropValue(vobj, VCMailerProp, card->mailer); + ADD_PROP_VALUE(vobj, VCMailerProp, card->mailer); } if (card->fburl) - addPropValue(vobj, "FBURL", card->fburl); + ADD_PROP_VALUE(vobj, "FBURL", card->fburl); if (card->note) { VObject *noteprop; - noteprop = addPropValue(vobj, VCNoteProp, card->note); + noteprop = ADD_PROP_VALUE(vobj, VCNoteProp, card->note); addProp(noteprop, VCQuotedPrintableProp); } if (card->last_use) { char *value; value = e_card_date_to_string (card->last_use); - addPropValue (vobj, "X-EVOLUTION-LAST-USE", value); + ADD_PROP_VALUE (vobj, "X-EVOLUTION-LAST-USE", value); g_free (value); } if (card->raw_use_score > 0) { char *value; value = g_strdup_printf ("%f", card->raw_use_score); - addPropValue (vobj, "X-EVOLUTION-USE-SCORE", value); + ADD_PROP_VALUE (vobj, "X-EVOLUTION-USE-SCORE", value); g_free (value); } if (card->related_contacts && *card->related_contacts) { - addPropValue(vobj, XEV_RELATED_CONTACTS, card->related_contacts); + ADD_PROP_VALUE(vobj, XEV_RELATED_CONTACTS, card->related_contacts); } if (card->categories) { @@ -571,17 +600,17 @@ e_card_get_vobject (ECard *card) stringptr --; *stringptr = 0; } - addPropValue (vobj, "CATEGORIES", string); + ADD_PROP_VALUE (vobj, "CATEGORIES", string); g_free(string); } if (card->wants_html_set) { - addPropValue (vobj, XEV_WANTS_HTML, card->wants_html ? "TRUE" : "FALSE"); + ADD_PROP_VALUE (vobj, XEV_WANTS_HTML, card->wants_html ? "TRUE" : "FALSE"); } if (card->list) { - addPropValue (vobj, XEV_LIST, "TRUE"); - addPropValue (vobj, XEV_LIST_SHOW_ADDRESSES, card->list_show_addresses ? "TRUE" : "FALSE"); + ADD_PROP_VALUE (vobj, XEV_LIST, "TRUE"); + ADD_PROP_VALUE (vobj, XEV_LIST_SHOW_ADDRESSES, card->list_show_addresses ? "TRUE" : "FALSE"); } if (card->arbitrary) { @@ -590,12 +619,12 @@ e_card_get_vobject (ECard *card) const ECardArbitrary *arbitrary = e_iterator_get(iterator); VObject *arb_object; if (arbitrary->value) { - arb_object = addPropValue (vobj, XEV_ARBITRARY, arbitrary->value); + arb_object = ADD_PROP_VALUE (vobj, XEV_ARBITRARY, arbitrary->value); } else { arb_object = addProp (vobj, XEV_ARBITRARY); } if (arbitrary->type) { - addPropValue (arb_object, "TYPE", arbitrary->type); + ADD_PROP_VALUE (arb_object, "TYPE", arbitrary->type); } if (arbitrary->key) { addProp (arb_object, arbitrary->key); @@ -603,7 +632,7 @@ e_card_get_vobject (ECard *card) } } - addPropValue (vobj, VCUniqueStringProp, card->id); + ADD_PROP_VALUE (vobj, VCUniqueStringProp, card->id); #if 0 if (crd->photo.prop.used) { @@ -618,7 +647,7 @@ e_card_get_vobject (ECard *card) for (node = crd->xtension.l; node; node = node->next) { CardXProperty *xp = (CardXProperty *) node->data; - addPropValue (vobj, xp->name, xp->data); + ADD_PROP_VALUE (vobj, xp->name, xp->data); add_CardProperty (vobj, &xp->prop); } } @@ -627,7 +656,7 @@ e_card_get_vobject (ECard *card) char *str; str = card_timezn_str (crd->timezn); - vprop = addPropValue (vobj, VCTimeZoneProp, str); + vprop = ADD_PROP_VALUE (vobj, VCTimeZoneProp, str); free (str); add_CardProperty (vprop, &crd->timezn.prop); } @@ -636,7 +665,7 @@ e_card_get_vobject (ECard *card) char *str; str = card_geopos_str (crd->geopos); - vprop = addPropValue (vobj, VCGeoLocationProp, str); + vprop = ADD_PROP_VALUE (vobj, VCGeoLocationProp, str); free (str); add_CardProperty (vprop, &crd->geopos.prop); } @@ -656,7 +685,7 @@ e_card_get_vobject (ECard *card) vprop = addPropSizedValue (vobj, VCPronunciationProp, crd->sound.data, crd->sound.size); else - vprop = addPropValue (vobj, VCPronunciationProp, + vprop = ADD_PROP_VALUE (vobj, VCPronunciationProp, crd->sound.data); add_SoundType (vprop, crd->sound.type); @@ -664,7 +693,7 @@ e_card_get_vobject (ECard *card) } if (crd->key.prop.used) { - vprop = addPropValue (vobj, VCPublicKeyProp, crd->key.data); + vprop = ADD_PROP_VALUE (vobj, VCPublicKeyProp, crd->key.data); add_KeyType (vprop, crd->key.type); add_CardProperty (vprop, &crd->key.prop); } @@ -684,7 +713,21 @@ e_card_get_vcard (ECard *card) VObject *vobj; char *temp, *ret_val; - vobj = e_card_get_vobject (card); + vobj = e_card_get_vobject (card, FALSE); + temp = writeMemVObject(NULL, NULL, vobj); + ret_val = g_strdup(temp); + free(temp); + cleanVObject(vobj); + return ret_val; +} + +char * +e_card_get_vcard_assume_utf8 (ECard *card) +{ + VObject *vobj; + char *temp, *ret_val; + + vobj = e_card_get_vobject (card, TRUE); temp = writeMemVObject(NULL, NULL, vobj); ret_val = g_strdup(temp); free(temp); @@ -711,7 +754,7 @@ e_card_list_get_vcard (GList *list) VObject *tempvobj; ECard *card = list->data; - tempvobj = e_card_get_vobject (card); + tempvobj = e_card_get_vobject (card, FALSE); addList (&vobj, tempvobj); } temp = writeMemVObjects(NULL, NULL, vobj); @@ -722,43 +765,43 @@ e_card_list_get_vcard (GList *list) } static void -parse_file_as(ECard *card, VObject *vobj) +parse_file_as(ECard *card, VObject *vobj, char *default_charset) { if ( card->file_as ) g_free(card->file_as); - assign_string(vobj, &(card->file_as)); + assign_string(vobj, default_charset, &(card->file_as)); } static void -parse_name(ECard *card, VObject *vobj) +parse_name(ECard *card, VObject *vobj, char *default_charset) { if ( card->name ) { e_card_name_free(card->name); } card->name = g_new(ECardName, 1); - card->name->family = e_v_object_get_child_value (vobj, VCFamilyNameProp); - card->name->given = e_v_object_get_child_value (vobj, VCGivenNameProp); - card->name->additional = e_v_object_get_child_value (vobj, VCAdditionalNamesProp); - card->name->prefix = e_v_object_get_child_value (vobj, VCNamePrefixesProp); - card->name->suffix = e_v_object_get_child_value (vobj, VCNameSuffixesProp); + card->name->family = e_v_object_get_child_value (vobj, VCFamilyNameProp, default_charset); + card->name->given = e_v_object_get_child_value (vobj, VCGivenNameProp, default_charset); + card->name->additional = e_v_object_get_child_value (vobj, VCAdditionalNamesProp, default_charset); + card->name->prefix = e_v_object_get_child_value (vobj, VCNamePrefixesProp, default_charset); + card->name->suffix = e_v_object_get_child_value (vobj, VCNameSuffixesProp, default_charset); } static void -parse_full_name(ECard *card, VObject *vobj) +parse_full_name(ECard *card, VObject *vobj, char *default_charset) { if ( card->fname ) g_free(card->fname); - assign_string(vobj, &(card->fname)); + assign_string(vobj, default_charset, &(card->fname)); } static void -parse_email(ECard *card, VObject *vobj) +parse_email(ECard *card, VObject *vobj, char *default_charset) { char *next_email; EList *list; - assign_string(vobj, &next_email); + assign_string(vobj, default_charset, &next_email); gtk_object_get(GTK_OBJECT(card), "email", &list, NULL); @@ -766,8 +809,9 @@ parse_email(ECard *card, VObject *vobj) g_free (next_email); } +/* Deal with charset */ static void -parse_bday(ECard *card, VObject *vobj) +parse_bday(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -780,12 +824,12 @@ parse_bday(ECard *card, VObject *vobj) } static void -parse_phone(ECard *card, VObject *vobj) +parse_phone(ECard *card, VObject *vobj, char *default_charset) { ECardPhone *next_phone = g_new(ECardPhone, 1); EList *list; - assign_string(vobj, &(next_phone->number)); + assign_string(vobj, default_charset, &(next_phone->number)); next_phone->flags = get_phone_flags(vobj); gtk_object_get(GTK_OBJECT(card), @@ -796,19 +840,19 @@ parse_phone(ECard *card, VObject *vobj) } static void -parse_address(ECard *card, VObject *vobj) +parse_address(ECard *card, VObject *vobj, char *default_charset) { ECardDeliveryAddress *next_addr = g_new(ECardDeliveryAddress, 1); EList *list; next_addr->flags = get_address_flags (vobj); - next_addr->po = e_v_object_get_child_value (vobj, VCPostalBoxProp); - next_addr->ext = e_v_object_get_child_value (vobj, VCExtAddressProp); - next_addr->street = e_v_object_get_child_value (vobj, VCStreetAddressProp); - next_addr->city = e_v_object_get_child_value (vobj, VCCityProp); - next_addr->region = e_v_object_get_child_value (vobj, VCRegionProp); - next_addr->code = e_v_object_get_child_value (vobj, VCPostalCodeProp); - next_addr->country = e_v_object_get_child_value (vobj, VCCountryNameProp); + next_addr->po = e_v_object_get_child_value (vobj, VCPostalBoxProp, default_charset); + next_addr->ext = e_v_object_get_child_value (vobj, VCExtAddressProp, default_charset); + next_addr->street = e_v_object_get_child_value (vobj, VCStreetAddressProp, default_charset); + next_addr->city = e_v_object_get_child_value (vobj, VCCityProp, default_charset); + next_addr->region = e_v_object_get_child_value (vobj, VCRegionProp, default_charset); + next_addr->code = e_v_object_get_child_value (vobj, VCPostalCodeProp, default_charset); + next_addr->country = e_v_object_get_child_value (vobj, VCCountryNameProp, default_charset); gtk_object_get(GTK_OBJECT(card), "address", &list, @@ -818,13 +862,13 @@ parse_address(ECard *card, VObject *vobj) } static void -parse_address_label(ECard *card, VObject *vobj) +parse_address_label(ECard *card, VObject *vobj, char *default_charset) { ECardAddrLabel *next_addr = g_new(ECardAddrLabel, 1); EList *list; next_addr->flags = get_address_flags (vobj); - assign_string(vobj, &next_addr->data); + assign_string(vobj, default_charset, &next_addr->data); gtk_object_get(GTK_OBJECT(card), "address_label", &list, @@ -834,85 +878,86 @@ parse_address_label(ECard *card, VObject *vobj) } static void -parse_url(ECard *card, VObject *vobj) +parse_url(ECard *card, VObject *vobj, char *default_charset) { if (card->url) g_free(card->url); - assign_string(vobj, &(card->url)); + assign_string(vobj, default_charset, &(card->url)); } static void -parse_org(ECard *card, VObject *vobj) +parse_org(ECard *card, VObject *vobj, char *default_charset) { char *temp; - temp = e_v_object_get_child_value(vobj, VCOrgNameProp); + temp = e_v_object_get_child_value(vobj, VCOrgNameProp, default_charset); g_free(card->org); card->org = temp; - temp = e_v_object_get_child_value(vobj, VCOrgUnitProp); + temp = e_v_object_get_child_value(vobj, VCOrgUnitProp, default_charset); g_free(card->org_unit); card->org_unit = temp; } static void -parse_office(ECard *card, VObject *vobj) +parse_office(ECard *card, VObject *vobj, char *default_charset) { if ( card->office ) g_free(card->office); - assign_string(vobj, &(card->office)); + assign_string(vobj, default_charset, &(card->office)); } static void -parse_title(ECard *card, VObject *vobj) +parse_title(ECard *card, VObject *vobj, char *default_charset) { if ( card->title ) g_free(card->title); - assign_string(vobj, &(card->title)); + assign_string(vobj, default_charset, &(card->title)); } static void -parse_role(ECard *card, VObject *vobj) +parse_role(ECard *card, VObject *vobj, char *default_charset) { if (card->role) g_free(card->role); - assign_string(vobj, &(card->role)); + assign_string(vobj, default_charset, &(card->role)); } static void -parse_manager(ECard *card, VObject *vobj) +parse_manager(ECard *card, VObject *vobj, char *default_charset) { if ( card->manager ) g_free(card->manager); - assign_string(vobj, &(card->manager)); + assign_string(vobj, default_charset, &(card->manager)); } static void -parse_assistant(ECard *card, VObject *vobj) +parse_assistant(ECard *card, VObject *vobj, char *default_charset) { if ( card->assistant ) g_free(card->assistant); - assign_string(vobj, &(card->assistant)); + assign_string(vobj, default_charset, &(card->assistant)); } static void -parse_nickname(ECard *card, VObject *vobj) +parse_nickname(ECard *card, VObject *vobj, char *default_charset) { if (card->nickname) g_free(card->nickname); - assign_string(vobj, &(card->nickname)); + assign_string(vobj, default_charset, &(card->nickname)); } static void -parse_spouse(ECard *card, VObject *vobj) +parse_spouse(ECard *card, VObject *vobj, char *default_charset) { if ( card->spouse ) g_free(card->spouse); - assign_string(vobj, &(card->spouse)); + assign_string(vobj, default_charset, &(card->spouse)); } +/* Deal with charset */ static void -parse_anniversary(ECard *card, VObject *vobj) +parse_anniversary(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -925,32 +970,32 @@ parse_anniversary(ECard *card, VObject *vobj) } static void -parse_mailer(ECard *card, VObject *vobj) +parse_mailer(ECard *card, VObject *vobj, char *default_charset) { if ( card->mailer ) g_free(card->mailer); - assign_string(vobj, &(card->mailer)); + assign_string(vobj, default_charset, &(card->mailer)); } static void -parse_fburl(ECard *card, VObject *vobj) +parse_fburl(ECard *card, VObject *vobj, char *default_charset) { g_free(card->fburl); - assign_string(vobj, &(card->fburl)); + assign_string(vobj, default_charset, &(card->fburl)); } static void -parse_note(ECard *card, VObject *vobj) +parse_note(ECard *card, VObject *vobj, char *default_charset) { g_free(card->note); - assign_string(vobj, &(card->note)); + assign_string(vobj, default_charset, &(card->note)); } static void -parse_related_contacts(ECard *card, VObject *vobj) +parse_related_contacts(ECard *card, VObject *vobj, char *default_charset) { g_free(card->related_contacts); - assign_string(vobj, &(card->related_contacts)); + assign_string(vobj, default_charset, &(card->related_contacts)); } static void @@ -1009,8 +1054,9 @@ do_parse_categories(ECard *card, char *str) g_free(copy); } +/* Deal with charset */ static void -parse_categories(ECard *card, VObject *vobj) +parse_categories(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -1019,8 +1065,9 @@ parse_categories(ECard *card, VObject *vobj) } } +/* Deal with charset */ static void -parse_wants_html(ECard *card, VObject *vobj) +parse_wants_html(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -1036,8 +1083,9 @@ parse_wants_html(ECard *card, VObject *vobj) } } +/* Deal with charset */ static void -parse_list(ECard *card, VObject *vobj) +parse_list(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -1051,8 +1099,9 @@ parse_list(ECard *card, VObject *vobj) } } +/* Deal with charset */ static void -parse_list_show_addresses(ECard *card, VObject *vobj) +parse_list_show_addresses(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -1084,7 +1133,7 @@ struct VObject { }; static void -parse_arbitrary(ECard *card, VObject *vobj) +parse_arbitrary(ECard *card, VObject *vobj, char *default_charset) { ECardArbitrary *arbitrary = e_card_arbitrary_new(); VObjectIterator iterator; @@ -1094,14 +1143,14 @@ parse_arbitrary(ECard *card, VObject *vobj) const char *name = vObjectName(temp); if (name && !strcmp(name, "TYPE")) { g_free(arbitrary->type); - assign_string(temp, &(arbitrary->type)); + assign_string(temp, default_charset, &(arbitrary->type)); } else { g_free(arbitrary->key); arbitrary->key = g_strdup(name); } } - assign_string(vobj, &(arbitrary->value)); + assign_string(vobj, default_charset, &(arbitrary->value)); gtk_object_get(GTK_OBJECT(card), "arbitrary", &list, @@ -1111,14 +1160,15 @@ parse_arbitrary(ECard *card, VObject *vobj) } static void -parse_id(ECard *card, VObject *vobj) +parse_id(ECard *card, VObject *vobj, char *default_charset) { g_free(card->id); - assign_string(vobj, &(card->id)); + assign_string(vobj, default_charset, &(card->id)); } +/* Deal with charset */ static void -parse_last_use(ECard *card, VObject *vobj) +parse_last_use(ECard *card, VObject *vobj, char *default_charset) { if ( vObjectValueType (vobj) ) { char *str = fakeCString (vObjectUStringZValue (vobj)); @@ -1130,8 +1180,9 @@ parse_last_use(ECard *card, VObject *vobj) } } +/* Deal with charset */ static void -parse_use_score(ECard *card, VObject *vobj) +parse_use_score(ECard *card, VObject *vobj, char *default_charset) { card->raw_use_score = 0; @@ -1143,20 +1194,20 @@ parse_use_score(ECard *card, VObject *vobj) } static void -parse_attribute(ECard *card, VObject *vobj) +parse_attribute(ECard *card, VObject *vobj, char *default_charset) { ParsePropertyFunc function = g_hash_table_lookup(E_CARD_CLASS(GTK_OBJECT(card)->klass)->attribute_jump_table, vObjectName(vobj)); if ( function ) - function(card, vobj); + function(card, vobj, default_charset); } static void -parse(ECard *card, VObject *vobj) +parse(ECard *card, VObject *vobj, char *default_charset) { VObjectIterator iterator; initPropIterator(&iterator, vobj); while(moreIteration (&iterator)) { - parse_attribute(card, nextVObject(&iterator)); + parse_attribute(card, nextVObject(&iterator), default_charset); } if (!card->fname) { card->fname = g_strdup(""); @@ -2278,14 +2329,14 @@ e_card_init (ECard *card) } GList * -e_card_load_cards_from_file(const char *filename) +e_card_load_cards_from_file_with_default_charset(const char *filename, char *default_charset) { VObject *vobj = Parse_MIME_FromFileName((char *) filename); GList *list = NULL; while(vobj) { VObject *next; ECard *card = E_CARD(gtk_type_new(e_card_get_type())); - parse(card, vobj); + parse(card, vobj, default_charset); next = nextVObjectInList(vobj); cleanVObject(vobj); vobj = next; @@ -2296,14 +2347,20 @@ e_card_load_cards_from_file(const char *filename) } GList * -e_card_load_cards_from_string(const char *str) +e_card_load_cards_from_file(const char *filename) +{ + return e_card_load_cards_from_file_with_default_charset (filename, "UTF-8"); +} + +GList * +e_card_load_cards_from_string_with_default_charset(const char *str, char *default_charset) { VObject *vobj = Parse_MIME(str, strlen (str)); GList *list = NULL; while(vobj) { VObject *next; ECard *card = E_CARD(gtk_type_new(e_card_get_type())); - parse(card, vobj); + parse(card, vobj, default_charset); next = nextVObjectInList(vobj); cleanVObject(vobj); vobj = next; @@ -2313,6 +2370,12 @@ e_card_load_cards_from_string(const char *str) return list; } +GList * +e_card_load_cards_from_string(const char *str) +{ + return e_card_load_cards_from_string_with_default_charset (str, "UTF-8"); +} + void e_card_free_empty_lists (ECard *card) { @@ -2348,24 +2411,49 @@ e_card_free_empty_lists (ECard *card) } static void -assign_string(VObject *vobj, char **string) +assign_string(VObject *vobj, char *default_charset, char **string) { int type = vObjectValueType(vobj); char *str; + char *charset = default_charset; + gboolean free_charset = FALSE; + VObject *charset_obj; + + if ((charset_obj = isAPropertyOf (vobj, "CHARSET"))) { + switch (vObjectValueType (charset_obj)) { + case VCVT_STRINGZ: + charset = (char *) vObjectStringZValue(charset_obj); + break; + case VCVT_USTRINGZ: + charset = fakeCString (vObjectUStringZValue (charset_obj)); + free_charset = TRUE; + break; + } + } switch(type) { case VCVT_STRINGZ: - *string = g_strdup (vObjectStringZValue(vobj)); + if (strcmp (charset, "UTF-8")) + *string = e_utf8_from_charset_string (charset, vObjectStringZValue(vobj)); + else + *string = g_strdup(vObjectStringZValue(vobj)); break; case VCVT_USTRINGZ: - str = (vObjectValueType (vobj) ? fakeCString (vObjectUStringZValue (vobj)) : calloc(1, 1)); - *string = g_strdup(str); + str = fakeCString (vObjectUStringZValue (vobj)); + if (strcmp (charset, "UTF-8")) + *string = e_utf8_from_charset_string (charset, str); + else + *string = g_strdup(str); free(str); break; default: *string = g_strdup(""); break; } + + if (free_charset) { + free (charset); + } } #if 0 @@ -3800,19 +3888,37 @@ e_card_date_from_string (char *str) } char * -e_v_object_get_child_value(VObject *vobj, char *name) +e_v_object_get_child_value(VObject *vobj, char *name, char *default_charset) { char *ret_val; VObjectIterator iterator; + gboolean free_charset = FALSE; + VObject *charset_obj; + + if ((charset_obj = isAPropertyOf (vobj, "CHARSET"))) { + switch (vObjectValueType (charset_obj)) { + case VCVT_STRINGZ: + default_charset = (char *) vObjectStringZValue(charset_obj); + break; + case VCVT_USTRINGZ: + default_charset = fakeCString (vObjectUStringZValue (charset_obj)); + free_charset = TRUE; + break; + } + } + initPropIterator(&iterator, vobj); while(moreIteration (&iterator)) { VObject *attribute = nextVObject(&iterator); const char *id = vObjectName(attribute); if ( ! strcmp(id, name) ) { - assign_string(attribute, &ret_val); + assign_string(attribute, default_charset, &ret_val); return ret_val; } } + if (free_charset) + free (default_charset); + return NULL; } @@ -4006,7 +4112,7 @@ e_card_list_send (GList *cards, ECardDisposition disposition) while (cards != NULL) { ECard *card = cards->data; EIterator *iterator; - const gchar *name, *addr; + gchar *name, *addr; char *file_as; gboolean is_list, is_hidden, free_name_addr; EList *email; @@ -4047,7 +4153,7 @@ e_card_list_send (GList *cards, ECardDisposition disposition) } else { /* is just a plain old card */ name = file_as; - addr = e_iterator_get (iterator); + addr = (char *) e_iterator_get (iterator); } } diff --git a/addressbook/backend/ebook/e-card.h b/addressbook/backend/ebook/e-card.h index c870ae2978..c9ac994a0d 100644 --- a/addressbook/backend/ebook/e-card.h +++ b/addressbook/backend/ebook/e-card.h @@ -116,68 +116,75 @@ struct _ECardClass { /* Simple functions */ -ECard *e_card_new (char *vcard); -const char *e_card_get_id (ECard *card); -void e_card_set_id (ECard *card, - const char *character); - -struct _EBook *e_card_get_book (ECard *card); -void e_card_set_book (ECard *card, - struct _EBook *book); -char *e_card_get_vcard (ECard *card); -char *e_card_list_get_vcard (GList *list); -ECard *e_card_duplicate (ECard *card); -float e_card_get_use_score (ECard *card); -void e_card_touch (ECard *card); +ECard *e_card_new (char *vcard); /* Assumes utf8 */ +ECard *e_card_new_with_default_charset (char *vcard, + char *default_charset); +const char *e_card_get_id (ECard *card); +void e_card_set_id (ECard *card, + const char *character); + +struct _EBook *e_card_get_book (ECard *card); +void e_card_set_book (ECard *card, + struct _EBook *book); +char *e_card_get_vcard (ECard *card); +char *e_card_get_vcard_assume_utf8 (ECard *card); +char *e_card_list_get_vcard (GList *list); +ECard *e_card_duplicate (ECard *card); +float e_card_get_use_score (ECard *card); +void e_card_touch (ECard *card); /* Evolution List convenience functions */ /* used for encoding uids in email addresses */ -gboolean e_card_evolution_list (ECard *card); -gboolean e_card_evolution_list_show_addresses (ECard *card); +gboolean e_card_evolution_list (ECard *card); +gboolean e_card_evolution_list_show_addresses (ECard *card); /* ECardPhone manipulation */ -ECardPhone *e_card_phone_new (void); -ECardPhone *e_card_phone_copy (const ECardPhone *phone); -void e_card_phone_free (ECardPhone *phone); +ECardPhone *e_card_phone_new (void); +ECardPhone *e_card_phone_copy (const ECardPhone *phone); +void e_card_phone_free (ECardPhone *phone); /* ECardDeliveryAddress manipulation */ -ECardDeliveryAddress *e_card_delivery_address_new (void); -ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr); -void e_card_delivery_address_free (ECardDeliveryAddress *addr); -gboolean e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr); -char *e_card_delivery_address_to_string (const ECardDeliveryAddress *addr); -ECardDeliveryAddress *e_card_delivery_address_from_label (const ECardAddrLabel *label); -ECardAddrLabel *e_card_delivery_address_to_label (const ECardDeliveryAddress *addr); +ECardDeliveryAddress *e_card_delivery_address_new (void); +ECardDeliveryAddress *e_card_delivery_address_copy (const ECardDeliveryAddress *addr); +void e_card_delivery_address_free (ECardDeliveryAddress *addr); +gboolean e_card_delivery_address_is_empty (const ECardDeliveryAddress *addr); +char *e_card_delivery_address_to_string (const ECardDeliveryAddress *addr); +ECardDeliveryAddress *e_card_delivery_address_from_label (const ECardAddrLabel *label); +ECardAddrLabel *e_card_delivery_address_to_label (const ECardDeliveryAddress *addr); /* ECardAddrLabel manipulation */ -ECardAddrLabel *e_card_address_label_new (void); -ECardAddrLabel *e_card_address_label_copy (const ECardAddrLabel *addr); -void e_card_address_label_free (ECardAddrLabel *addr); +ECardAddrLabel *e_card_address_label_new (void); +ECardAddrLabel *e_card_address_label_copy (const ECardAddrLabel *addr); +void e_card_address_label_free (ECardAddrLabel *addr); /* ECardName manipulation */ -ECardName *e_card_name_new (void); -ECardName *e_card_name_copy (const ECardName *name); -void e_card_name_free (ECardName *name); -char *e_card_name_to_string (const ECardName *name); -ECardName *e_card_name_from_string (const char *full_name); -gboolean e_card_name_match_string (const ECardName *name, - const gchar *str); +ECardName *e_card_name_new (void); +ECardName *e_card_name_copy (const ECardName *name); +void e_card_name_free (ECardName *name); +char *e_card_name_to_string (const ECardName *name); +ECardName *e_card_name_from_string (const char *full_name); +gboolean e_card_name_match_string (const ECardName *name, + const gchar *str); /* ECardArbitrary manipulation */ -ECardArbitrary *e_card_arbitrary_new (void); -ECardArbitrary *e_card_arbitrary_copy (const ECardArbitrary *arbitrary); -void e_card_arbitrary_free (ECardArbitrary *arbitrary); +ECardArbitrary *e_card_arbitrary_new (void); +ECardArbitrary *e_card_arbitrary_copy (const ECardArbitrary *arbitrary); +void e_card_arbitrary_free (ECardArbitrary *arbitrary); /* ECard email manipulation */ -gboolean e_card_email_match_string (const ECard *card, - const gchar *str); -gint e_card_email_find_number (const ECard *card, - const gchar *email); +gboolean e_card_email_match_string (const ECard *card, + const gchar *str); +gint e_card_email_find_number (const ECard *card, + const gchar *email); /* Specialized functionality */ -GList *e_card_load_cards_from_file (const char *filename); -GList *e_card_load_cards_from_string (const char *str); -void e_card_free_empty_lists (ECard *card); +GList *e_card_load_cards_from_file (const char *filename); +GList *e_card_load_cards_from_file_with_default_charset (const char *filename, + char *default_charset); +GList *e_card_load_cards_from_string (const char *str); +GList *e_card_load_cards_from_string_with_default_charset (const char *str, + char *default_charset); +void e_card_free_empty_lists (ECard *card); enum _ECardDisposition { E_CARD_DISPOSITION_AS_ATTACHMENT, diff --git a/addressbook/backend/ebook/evolution-vcard-importer.c b/addressbook/backend/ebook/evolution-vcard-importer.c index c838fbc1d7..ea474f780b 100644 --- a/addressbook/backend/ebook/evolution-vcard-importer.c +++ b/addressbook/backend/ebook/evolution-vcard-importer.c @@ -31,9 +31,6 @@ static void add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) { ECard *card = E_CARD(closure); - char *vcard = e_card_get_vcard(card); - - g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); } @@ -42,7 +39,7 @@ book_open_cb (EBook *book, EBookStatus status, gpointer closure) { VCardImporter *gci = (VCardImporter *) closure; - gci->cardlist = e_card_load_cards_from_file(gci->filename); + gci->cardlist = e_card_load_cards_from_file_with_default_charset(gci->filename, "ISO-8859-1"); gci->ready = TRUE; } diff --git a/addressbook/backend/ebook/load-gnomecard-addressbook.c b/addressbook/backend/ebook/load-gnomecard-addressbook.c index 5d16a26a7c..6f592a4664 100644 --- a/addressbook/backend/ebook/load-gnomecard-addressbook.c +++ b/addressbook/backend/ebook/load-gnomecard-addressbook.c @@ -25,7 +25,7 @@ static void add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) { ECard *card = E_CARD(closure); - char *vcard = e_card_get_vcard(card); + char *vcard = e_card_get_vcard_assume_utf8(card); g_print ("Saved card: %s\n", vcard); g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); @@ -34,7 +34,7 @@ add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) static void book_open_cb (EBook *book, EBookStatus status, gpointer closure) { - GList *list = e_card_load_cards_from_file("gnomecard.vcf"); + GList *list = e_card_load_cards_from_file_with_default_charset("gnomecard.vcf", "ISO-8859-1"); GList *iterator; for (iterator = list; iterator; iterator = g_list_next(iterator)) { ECard *card = iterator->data; diff --git a/addressbook/backend/ebook/load-pine-addressbook.c b/addressbook/backend/ebook/load-pine-addressbook.c index 2c18efb7c8..6963a7ed46 100644 --- a/addressbook/backend/ebook/load-pine-addressbook.c +++ b/addressbook/backend/ebook/load-pine-addressbook.c @@ -26,7 +26,7 @@ static void add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure) { ECard *card = E_CARD(closure); - char *vcard = e_card_get_vcard(card); + char *vcard = e_card_get_vcard_assume_utf8(card); g_print ("Saved card: %s\n", vcard); g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); diff --git a/addressbook/backend/ebook/test-card.c b/addressbook/backend/ebook/test-card.c index 239ce4069f..dd591d6c51 100644 --- a/addressbook/backend/ebook/test-card.c +++ b/addressbook/backend/ebook/test-card.c @@ -99,7 +99,7 @@ main (int argc, char **argv) } } #endif - card = e_card_new (cardstr); + card = e_card_new_with_default_charset (cardstr, "ISO-8859-1"); gtk_object_get(GTK_OBJECT(card), "full_name", &fname, "name", &name, @@ -189,7 +189,7 @@ main (int argc, char **argv) } gtk_object_unref(GTK_OBJECT(iterator)); } - printf("%s", e_card_get_vcard(card)); + printf("%s", e_card_get_vcard_assume_utf8(card)); gtk_object_unref (GTK_OBJECT (card)); return 0; diff --git a/addressbook/backend/ebook/test-client-list.c b/addressbook/backend/ebook/test-client-list.c index 0de62d701c..8a38ccf4e1 100644 --- a/addressbook/backend/ebook/test-client-list.c +++ b/addressbook/backend/ebook/test-client-list.c @@ -32,7 +32,7 @@ get_cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer cl printf ("Length: %d\n", (int) length); for ( i = 0; i < length; i++ ) { ECard *card = e_card_cursor_get_nth(cursor, i); - char *vcard = e_card_get_vcard(card); + char *vcard = e_card_get_vcard_assume_utf8(card); printf("[%s]\n", vcard); g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); diff --git a/addressbook/backend/ebook/test-client.c b/addressbook/backend/ebook/test-client.c index cc7572c24c..44b20ebdde 100644 --- a/addressbook/backend/ebook/test-client.c +++ b/addressbook/backend/ebook/test-client.c @@ -58,7 +58,7 @@ get_cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer cl for ( i = 0; i < length; i++ ) { ECard *card = e_card_cursor_get_nth(cursor, i); - char *vcard = e_card_get_vcard(card); + char *vcard = e_card_get_vcard_assume_utf8(card); printf("Get all cards callback: [%s]\n", vcard); g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); @@ -70,7 +70,7 @@ get_card_cb (EBook *book, EBookStatus status, ECard *card, gpointer closure) { char *vcard; - vcard = e_card_get_vcard(card); + vcard = e_card_get_vcard_assume_utf8(card); printf ("Card added: [%s]\n", vcard); g_free(vcard); gtk_object_unref(GTK_OBJECT(card)); diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 77455f59fc..c8d63104d4 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -472,7 +472,7 @@ do_create(PASBackend *backend, card = e_card_new(vcard_req); e_card_set_id(card, id); - vcard = e_card_get_vcard(card); + vcard = e_card_get_vcard_assume_utf8(card); string_to_dbt (vcard, &vcard_dbt); diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c index 54a7095d46..da49f8ea9a 100644 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ b/addressbook/backend/pas/pas-backend-ldap.c @@ -878,9 +878,9 @@ create_card_handler (PASBackend *backend, LDAPOp *op) bonobo_object_dup_ref(bonobo_object_corba_objref(BONOBO_OBJECT(view->book_view)), &ev); match = pas_backend_card_sexp_match_vcard (view->card_sexp, - e_card_simple_get_vcard (new_card)); + e_card_simple_get_vcard_assume_utf8 (new_card)); if (match) - pas_book_view_notify_add_1 (view->book_view, e_card_simple_get_vcard (new_card)); + pas_book_view_notify_add_1 (view->book_view, e_card_simple_get_vcard_assume_utf8 (new_card)); pas_book_view_notify_complete (view->book_view); bonobo_object_release_unref(bonobo_object_corba_objref(BONOBO_OBJECT(view->book_view)), &ev); @@ -971,7 +971,7 @@ remove_card_handler (PASBackend *backend, LDAPOp *op) bonobo_object_dup_ref(bonobo_object_corba_objref(BONOBO_OBJECT(view->book_view)), &ev); match = pas_backend_card_sexp_match_vcard (view->card_sexp, - e_card_simple_get_vcard (simple)); + e_card_simple_get_vcard_assume_utf8 (simple)); if (match) pas_book_view_notify_remove (view->book_view, remove_op->id); pas_book_view_notify_complete (view->book_view); @@ -1079,7 +1079,7 @@ modify_card_handler (PASBackend *backend, LDAPOp *op) bonobo_object_dup_ref(bonobo_object_corba_objref(BONOBO_OBJECT(view->book_view)), &ev); old_match = pas_backend_card_sexp_match_vcard (view->card_sexp, - e_card_simple_get_vcard (current_card)); + e_card_simple_get_vcard_assume_utf8 (current_card)); new_match = pas_backend_card_sexp_match_vcard (view->card_sexp, modify_op->vcard); if (old_match && new_match) @@ -1166,7 +1166,7 @@ pas_backend_ldap_process_get_vcard (PASBackend *backend, if (simple) { pas_book_respond_get_vcard (book, GNOME_Evolution_Addressbook_BookListener_Success, - e_card_simple_get_vcard (simple)); + e_card_simple_get_vcard_assume_utf8 (simple)); gtk_object_unref (GTK_OBJECT (simple)); } else { @@ -2005,7 +2005,7 @@ poll_ldap (LDAPSearchOp *op) while (NULL != e) { ECardSimple *card = build_card_from_entry (ldap, e); - cards = g_list_append (cards, e_card_simple_get_vcard (card)); + cards = g_list_append (cards, e_card_simple_get_vcard_assume_utf8 (card)); gtk_object_unref (GTK_OBJECT(card)); |