/* * Strip empty attributes from a vcard * Returns: the number of attributes left on the card */ gint hito_vcard_strip_empty_attributes (EVCard *card) { GList *attrs, *values; gboolean remove; EVCardAttribute *attribute; gint count = 0; attrs = e_vcard_get_attributes (card); while (attrs) { count++; attribute = attrs->data; remove = TRUE; values = e_vcard_attribute_get_values (attrs->data); while (values) { if (g_utf8_strlen (values->data, -1) > 0) { remove = FALSE; break; } values = g_list_next (values); } attrs = g_list_next (attrs); if (remove) { e_vcard_remove_attribute (card, attribute); count--; } } return count; }
static void contacts_entry_changed (GtkWidget *widget, EContactChangeData *data) { GList *v, *values = contacts_entries_get_values (data->widget, NULL); e_vcard_attribute_remove_values (data->attr); /* Note: First element of a structured field is type, so remove it */ if (g_list_length (values) > 1) { GList *type = g_list_last (values); values = g_list_remove_link (values, type); g_free (type->data); g_list_free (type); } for (v = g_list_last (values); v; v = v->prev) { e_vcard_attribute_add_value (data->attr, (const gchar *)v->data); } if (!g_ascii_strcasecmp (e_vcard_attribute_get_name (data->attr), EVC_FN)) { /* add N and X-EVOLUTION-FILE-AS attributes */ ENameWestern *name; gchar *file_as; EVCardAttribute *attr; EVCard *evc = E_VCARD (data->contact); name = e_name_western_parse ((char*)values->data); /* Add "N" attribute */ attr = e_vcard_get_attribute (evc, EVC_N); if (attr) e_vcard_attribute_remove_values (attr); else { attr = e_vcard_attribute_new ("", EVC_N); e_vcard_add_attribute (evc, attr); } #define SAFESTR(x) (x) ? x : "" e_vcard_attribute_add_value (attr, SAFESTR (name->last)); e_vcard_attribute_add_value (attr, SAFESTR (name->first)); e_vcard_attribute_add_value (attr, SAFESTR (name->middle)); e_vcard_attribute_add_value (attr, SAFESTR (name->prefix)); e_vcard_attribute_add_value (attr, SAFESTR (name->suffix)); /* Add file-as attribute for evolution */ file_as = g_strdup_printf ("%s, %s", name->last, name->first); attr = e_vcard_get_attribute (evc, EVC_X_FILE_AS); if (attr) e_vcard_remove_attribute (evc, attr); attr = e_vcard_attribute_new ("", EVC_X_FILE_AS); e_vcard_add_attribute_with_value (evc, attr, file_as); g_free (file_as); g_free (name); } g_list_foreach (values, (GFunc)g_free, NULL); g_list_free (values); *data->changed = TRUE; }