summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Petter Jansson <hpj@ximian.com>2003-12-16 04:30:32 +0000
committerHans Petter <hansp@src.gnome.org>2003-12-16 04:30:32 +0000
commitbc819a1cfd88336756afd4db3d03e76560b1c7d2 (patch)
treea33aa79545812dbd3413a3ccdba800ca693b4500
parent31427c527860507aef84bb3231536ac931227fd7 (diff)
downloadevolution-data-server-bc819a1cfd88336756afd4db3d03e76560b1c7d2.tar.gz
Initialize the address_format field. Absence of this was causing crashes.
2003-12-15 Hans Petter Jansson <hpj@ximian.com> * libebook/e-contact.c (adr_getter): Initialize the address_format field. Absence of this was causing crashes. (e_contact_set_property): For synthetic attr_type fields, add a case for struct/get_set alongside strings. This makes addresses work. (e_contact_get_property): For multi_elem strings, count the matching attributes instead of trying to get a list from the first attribute encountered (which is what list_elem does). This makes e-mail addresses work.
-rw-r--r--addressbook/ChangeLog11
-rw-r--r--addressbook/libebook/e-contact.c73
2 files changed, 51 insertions, 33 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 3019d3bca..316f2195e 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,14 @@
+2003-12-15 Hans Petter Jansson <hpj@ximian.com>
+
+ * libebook/e-contact.c (adr_getter): Initialize the address_format
+ field. Absence of this was causing crashes.
+ (e_contact_set_property): For synthetic attr_type fields, add a
+ case for struct/get_set alongside strings. This makes addresses work.
+ (e_contact_get_property): For multi_elem strings, count the matching
+ attributes instead of trying to get a list from the first attribute
+ encountered (which is what list_elem does). This makes e-mail
+ addresses work.
+
2003-12-10 Hans Petter Jansson <hpj@ximian.com>
* backends/ldap/e-book-backend-ldap.c
diff --git a/addressbook/libebook/e-contact.c b/addressbook/libebook/e-contact.c
index 21979233e..021483d83 100644
--- a/addressbook/libebook/e-contact.c
+++ b/addressbook/libebook/e-contact.c
@@ -467,6 +467,7 @@ adr_getter (EContact *contact, EVCardAttribute *attr)
GList *p = e_vcard_attribute_get_values (attr);
EContactAddress *addr = g_new (EContactAddress, 1);
+ addr->address_format = g_strdup ("");
addr->po = g_strdup (p && p->data ? p->data : ""); if (p) p = p->next;
addr->ext = g_strdup (p && p->data ? p->data : ""); if (p) p = p->next;
addr->street = g_strdup (p && p->data ? p->data : ""); if (p) p = p->next;
@@ -619,7 +620,6 @@ e_contact_set_property (GObject *object,
int num_left = info->list_elem;
GList *attrs = e_vcard_get_attributes (E_VCARD (contact));
GList *l;
- const char *sval = g_value_get_string (value);
for (l = attrs; l && !found; l = l->next) {
const char *name, *group;
@@ -683,10 +683,19 @@ e_contact_set_property (GObject *object,
info->attr_type2);
}
- if (sval && *sval)
- e_vcard_attribute_add_value (attr, sval);
- else
- e_vcard_remove_attribute (E_VCARD (contact), attr);
+ if (info->t & E_CONTACT_FIELD_TYPE_STRUCT || info->t & E_CONTACT_FIELD_TYPE_GETSET) {
+ void *data = info->t & E_CONTACT_FIELD_TYPE_STRUCT ? g_value_get_boxed (value) : g_value_get_pointer (value);
+
+ info->struct_setter (contact, attr, data);
+ }
+ else {
+ const char *sval = g_value_get_string (value);
+
+ if (sval && *sval)
+ e_vcard_attribute_add_value (attr, sval);
+ else
+ e_vcard_remove_attribute (E_VCARD (contact), attr);
+ }
}
else if (info->t & E_CONTACT_FIELD_TYPE_LIST_ELEM) {
EVCardAttribute *attr = e_contact_get_first_attr (contact, info->vcard_field_name);
@@ -723,6 +732,26 @@ e_contact_set_property (GObject *object,
}
}
+ else if (info->t & E_CONTACT_FIELD_TYPE_STRUCT || info->t & E_CONTACT_FIELD_TYPE_GETSET) {
+ EVCardAttribute *attr = e_contact_get_first_attr (contact, info->vcard_field_name);
+ void *data = info->t & E_CONTACT_FIELD_TYPE_STRUCT ? g_value_get_boxed (value) : g_value_get_pointer (value);
+
+ if (attr) {
+ printf ("overwriting existing %s\n", info->vcard_field_name);
+ /* remove all existing values and parameters.
+ the setter will add the correct ones */
+ e_vcard_attribute_remove_values (attr);
+ e_vcard_attribute_remove_params (attr);
+ }
+ else {
+ printf ("adding new %s\n", info->vcard_field_name);
+ attr = e_vcard_attribute_new (NULL, info->vcard_field_name);
+
+ e_vcard_add_attribute (E_VCARD (contact), attr);
+ }
+
+ info->struct_setter (contact, attr, data);
+ }
else if (info->t & E_CONTACT_FIELD_TYPE_BOOLEAN) {
EVCardAttribute *attr;
@@ -759,26 +788,6 @@ e_contact_set_property (GObject *object,
g_value_get_string (value));
}
}
- else if (info->t & E_CONTACT_FIELD_TYPE_STRUCT || info->t & E_CONTACT_FIELD_TYPE_GETSET) {
- EVCardAttribute *attr = e_contact_get_first_attr (contact, info->vcard_field_name);
- void *data = info->t & E_CONTACT_FIELD_TYPE_STRUCT ? g_value_get_boxed (value) : g_value_get_pointer (value);
-
- if (attr) {
- printf ("overwriting existing %s\n", info->vcard_field_name);
- /* remove all existing values and parameters.
- the setter will add the correct ones */
- e_vcard_attribute_remove_values (attr);
- e_vcard_attribute_remove_params (attr);
- }
- else {
- printf ("adding new %s\n", info->vcard_field_name);
- attr = e_vcard_attribute_new (NULL, info->vcard_field_name);
-
- e_vcard_add_attribute (E_VCARD (contact), attr);
- }
-
- info->struct_setter (contact, attr, data);
- }
else {
g_warning ("unhandled attribute `%s'", info->vcard_field_name);
}
@@ -940,6 +949,7 @@ e_contact_get_property (GObject *object,
else if (info->t & E_CONTACT_FIELD_TYPE_MULTI_ELEM) {
if (info->t & E_CONTACT_FIELD_TYPE_STRING) {
GList *attrs, *l;
+ int num_left = info->list_elem;
attrs = e_vcard_get_attributes (E_VCARD (contact));
@@ -952,15 +962,12 @@ e_contact_get_property (GObject *object,
/* all the attributes we care about should be in group "" */
if ((!group || !*group) && !strcasecmp (name, info->vcard_field_name)) {
- GList *v;
- int count;
-
- v = e_vcard_attribute_get_values (attr);
- count = info->list_elem;
-
- v = g_list_nth (v, info->list_elem);
+ if (num_left-- == 0) {
+ GList *v = e_vcard_attribute_get_values (attr);
- g_value_set_string (value, v ? v->data : NULL);
+ g_value_set_string (value, v ? v->data : NULL);
+ break;
+ }
}
}
}