static void contacts_type_entry_changed (GtkWidget *widget, EContactTypeChangeData *data) { GList *v = contacts_entries_get_values (widget, NULL); if (v) { guint i; const TypeTuple *types = contacts_get_field_types (data->attr_name); const gchar *type = (const gchar *)v->data; gboolean custom_type = TRUE; for (i = 0; types[i].index; i++) { if (g_ascii_strcasecmp (type, types[i].index) == 0) custom_type = FALSE; } e_vcard_attribute_param_remove_values (data->param); /* Prefix a 'X-' to non-standard types, as per vCard spec */ if (custom_type) { gchar *new_type = g_strdup_printf ("X-%s", type); e_vcard_attribute_param_add_value ( data->param, (const char *)new_type); g_free (new_type); } else e_vcard_attribute_param_add_value ( data->param, (const char *)v->data); g_list_foreach (v, (GFunc)g_free, NULL); g_list_free (v); *data->changed = TRUE; } }
/** * e_vcard_attribute_param_free: * @param: an #EVCardAttributeParam * * Frees @param and its values. **/ void e_vcard_attribute_param_free (EVCardAttributeParam *param) { g_return_if_fail (param != NULL); g_free (param->name); e_vcard_attribute_param_remove_values (param); g_slice_free (EVCardAttributeParam, param); }
/* * Convenience function to set the type parmeter of a vcard attribute * * attr: the attribute to modify * type: semicolan seperated list of values * */ void hito_vcard_attribute_set_type (EVCardAttribute *attr, const gchar *type) { GList *params; EVCardAttributeParam *p = NULL; gchar **values; gint i; /* look for the TYPE parameter */ for (params = e_vcard_attribute_get_params (attr); params; params = g_list_next (params)) { if (!strcmp (e_vcard_attribute_param_get_name (params->data), "TYPE")) { p = params->data; break; } } /* we didn't find the TYPE parameter, so create it now */ if (!p) { /* if there isn't an existing TYPE and we are not setting a value, we can * return straight away */ if (!type) return; p = e_vcard_attribute_param_new ("TYPE"); e_vcard_attribute_add_param (attr, p); } /* remove the current values */ e_vcard_attribute_param_remove_values (p); /* if type is null, we don't want to add any type parameters */ if (!type) return; values = g_strsplit (type, ";", -1); for (i = 0; (values[i]); i++) { e_vcard_attribute_param_add_value (p, values[i]); } g_strfreev (values); }