Пример #1
0
static void
contacts_change_groups_cb (GtkWidget *widget, ContactsGroupChangeData *data)
{
	GList *g, *bools = NULL;
	GList *results = NULL;
	GList *values = e_vcard_attribute_get_values (data->attr);

	for (g = data->contacts_data->contacts_groups; g; g = g->next) {
		if (g_list_find_custom (values, g->data, (GCompareFunc)strcmp))
			bools = g_list_append (bools, GINT_TO_POINTER (TRUE));
		else
			bools = g_list_append (bools, GINT_TO_POINTER (FALSE));
	}
	
	if (contacts_chooser (data->contacts_data, _("Change groups"), _("<b>Choose groups"
		"</b>"), data->contacts_data->contacts_groups, bools, TRUE, TRUE, &results)) {

		gchar *new_groups = results ?
			contacts_string_list_as_string (results, ", ", FALSE) :
			g_strdup ("None");
		g_free (new_groups);

		e_vcard_attribute_remove_values (data->attr);
		for (g = results; g; g = g->next) {
			e_vcard_attribute_add_value (data->attr, g->data);
			if (!g_list_find_custom (data->contacts_data->contacts_groups, g->data, (GCompareFunc) strcmp))
					data->contacts_data->contacts_groups = g_list_prepend (data->contacts_data->contacts_groups, g_strdup (g->data));
		}
		data->contacts_data->changed = TRUE;
	}
}
/**
 * e_vcard_attribute_free:
 * @attr: attribute to free
 *
 * Frees an attribute, its values and its parameters.
 **/
void
e_vcard_attribute_free (EVCardAttribute *attr)
{
	g_return_if_fail (attr != NULL);

	g_free (attr->group);
	g_free (attr->name);

	e_vcard_attribute_remove_values (attr);

	e_vcard_attribute_remove_params (attr);

	g_slice_free (EVCardAttribute, attr);
}
Пример #3
0
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;
}