From e3696d2d2947f01e1780e217f738c4a1da40bd4c Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Thu, 4 Dec 2003 20:35:12 +0000 Subject: [PATCH] print out the NAME_OR_ORG of the contact too. 2003-12-04 Chris Toshok * tests/ebook/test-ebook.c (print_email): print out the NAME_OR_ORG of the contact too. * libebook/e-contact.h (EContactField): add NAME_OR_ORG. * libebook/e-contact.c (field_info): add NAME_OR_ORG. (e_contact_get_property): handle NAME_OR_ORG. --- addressbook/ChangeLog | 10 ++++++++++ addressbook/libebook/e-contact.c | 26 ++++++++++++++++++++++++-- addressbook/libebook/e-contact.h | 5 +++++ addressbook/tests/ebook/test-ebook.c | 6 +++--- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index fa1280f..9783e2c 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,13 @@ +2003-12-04 Chris Toshok + + * tests/ebook/test-ebook.c (print_email): print out the + NAME_OR_ORG of the contact too. + + * libebook/e-contact.h (EContactField): add NAME_OR_ORG. + + * libebook/e-contact.c (field_info): add NAME_OR_ORG. + (e_contact_get_property): handle NAME_OR_ORG. + 2003-12-01 Hans Petter Jansson * libebook/e-book.c (e_book_unload_uri): When clearing the cached diff --git a/addressbook/libebook/e-contact.c b/addressbook/libebook/e-contact.c index b574038..9018467 100644 --- a/addressbook/libebook/e-contact.c +++ b/addressbook/libebook/e-contact.c @@ -83,6 +83,7 @@ static void date_setter (EContact *contact, EVCardAttribute *attr, void *data); #define MULTI_LIST_FIELD(id,vc,n,pn,ro) { E_CONTACT_FIELD_TYPE_MULTI, (id), (vc), (n), (pn), (ro) } #define GETSET_FIELD(id,vc,n,pn,ro,get,set) { E_CONTACT_FIELD_TYPE_GETSET, (id), (vc), (n), (pn), (ro), -1, NULL, NULL, (get), (set) } #define STRUCT_FIELD(id,vc,n,pn,ro,get,set,ty) { E_CONTACT_FIELD_TYPE_STRUCT | E_CONTACT_FIELD_TYPE_GETSET, (id), (vc), (n), (pn), (ro), -1, NULL, NULL, (get), (set), (ty) } +#define SYNTH_STR_FIELD(id,n,pn,ro) { E_CONTACT_FIELD_TYPE_STRING | E_CONTACT_FIELD_TYPE_SYNTHETIC, (id), NULL, (n), (pn), (ro) } #define LIST_ELEM_STR_FIELD(id,vc,n,pn,ro,nm) { E_CONTACT_FIELD_TYPE_LIST_ELEM | E_CONTACT_FIELD_TYPE_SYNTHETIC | E_CONTACT_FIELD_TYPE_STRING, (id), (vc), (n), (pn), (ro), (nm) } #define MULTI_ELEM_STR_FIELD(id,vc,n,pn,ro,nm) { E_CONTACT_FIELD_TYPE_MULTI_ELEM | E_CONTACT_FIELD_TYPE_SYNTHETIC | E_CONTACT_FIELD_TYPE_STRING, (id), (vc), (n), (pn), (ro), (nm) } #define ATTR_TYPE_STR_FIELD(id,vc,n,pn,ro,at1,nth) { E_CONTACT_FIELD_TYPE_ATTR_TYPE | E_CONTACT_FIELD_TYPE_SYNTHETIC | E_CONTACT_FIELD_TYPE_STRING, (id), (vc), (n), (pn), (ro), (nth), (at1), NULL } @@ -102,6 +103,7 @@ static EContactFieldInfo field_info[] = { LIST_ELEM_STR_FIELD (E_CONTACT_GIVEN_NAME, EVC_N, "given_name", N_("Given Name"), FALSE, 1), LIST_ELEM_STR_FIELD (E_CONTACT_FAMILY_NAME, EVC_N, "family_name", N_("Family Name"), FALSE, 0), STRING_FIELD (E_CONTACT_NICKNAME, EVC_NICKNAME, "nickname", N_("Nickname"), FALSE), + SYNTH_STR_FIELD (E_CONTACT_NAME_OR_ORG, "name_or_org", N_("Name or Org"), TRUE), /* Address fields */ MULTI_LIST_FIELD (E_CONTACT_ADDRESS, EVC_ADR, "address", N_("Address List"), FALSE), @@ -183,8 +185,8 @@ static EContactFieldInfo field_info[] = { STRING_FIELD (E_CONTACT_SPOUSE, EVC_X_SPOUSE, "spouse", N_("Spouse's Name"), FALSE), STRING_FIELD (E_CONTACT_NOTE, EVC_NOTE, "note", N_("Note"), FALSE), - STRUCT_FIELD (E_CONTACT_BIRTH_DATE, EVC_BDAY, "birth_date", N_("Birth Date"), FALSE, date_getter, date_setter, e_contact_date_get_type), - STRUCT_FIELD (E_CONTACT_ANNIVERSARY, EVC_BDAY, "anniversary", N_("Anniversary"), FALSE, date_getter, date_setter, e_contact_date_get_type), + STRUCT_FIELD (E_CONTACT_BIRTH_DATE, EVC_BDAY, "birth_date", N_("Birth Date"), FALSE, date_getter, date_setter, e_contact_date_get_type), + STRUCT_FIELD (E_CONTACT_ANNIVERSARY, EVC_X_ANNIVERSARY, "anniversary", N_("Anniversary"), FALSE, date_getter, date_setter, e_contact_date_get_type), BOOLEAN_FIELD (E_CONTACT_IS_LIST, EVC_X_LIST, "list", N_("List"), FALSE), BOOLEAN_FIELD (E_CONTACT_LIST_SHOW_ADDRESSES, EVC_X_LIST_SHOW_ADDRESSES, "list_show_addresses", N_("List Show Addresses"), FALSE) @@ -1005,6 +1007,26 @@ e_contact_get_property (GObject *object, else if (info->t & E_CONTACT_FIELD_TYPE_SYNTHETIC) { switch (info->field_id) { + case E_CONTACT_NAME_OR_ORG: { + char *str; + + str = e_contact_get_const (contact, E_CONTACT_FILE_AS); + if (!str) + str = e_contact_get_const (contact, E_CONTACT_FULL_NAME); + if (!str) + str = e_contact_get_const (contact, E_CONTACT_ORG); + if (!str) { + gboolean is_list = GPOINTER_TO_INT (e_contact_get (contact, E_CONTACT_IS_LIST)); + + if (is_list) + str = _("Unnamed List"); + else + str = e_contact_get_const (contact, E_CONTACT_EMAIL_1); + } + + g_value_set_string (value, str); + break; + } default: g_warning ("unhandled synthetic field 0x%02x", info->field_id); } diff --git a/addressbook/libebook/e-contact.h b/addressbook/libebook/e-contact.h index 21d43d3..9579230 100644 --- a/addressbook/libebook/e-contact.h +++ b/addressbook/libebook/e-contact.h @@ -131,6 +131,11 @@ typedef enum { E_CONTACT_X509_CERT, /* string field */ E_CONTACT_X509_CERT_SHA1_FINGERPRINT, /* string field */ + /* Convenience field for getting a name from the contact. + Returns the first one of [File-As, Full Name, Org, Email1] + to be set */ + E_CONTACT_NAME_OR_ORG, + E_CONTACT_FIELD_LAST, /* useful constants */ diff --git a/addressbook/tests/ebook/test-ebook.c b/addressbook/tests/ebook/test-ebook.c index ccb6429..020fd79 100644 --- a/addressbook/tests/ebook/test-ebook.c +++ b/addressbook/tests/ebook/test-ebook.c @@ -8,10 +8,12 @@ static void print_email (EContact *contact) { - char *file_as = e_contact_get (contact, E_CONTACT_FILE_AS); + char *file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS); + char *name_or_org = e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG); GList *emails, *e; printf ("Contact: %s\n", file_as); + printf ("Name or org: %s\n", name_or_org); printf ("Email addresses:\n"); emails = e_contact_get (contact, E_CONTACT_EMAIL); for (e = emails; e; e = e->next) { @@ -20,8 +22,6 @@ print_email (EContact *contact) g_list_foreach (emails, (GFunc)g_free, NULL); g_list_free (emails); - g_free (file_as); - printf ("\n"); } -- 2.7.4