aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-11-04 16:16:41 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-11-04 16:16:41 +0800
commita0d57aa60447a6c2810013bad801b5ecc71d8b8c (patch)
treebb7caba6457044157b361932bb883e4ee5f825e5
parent182b9fa21320d52c886284d652b1a232d3ec2793 (diff)
parent60ceff650179f376d3f35831a4170b3bc0a2577a (diff)
downloadgsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.tar
gsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.tar.gz
gsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.tar.bz2
gsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.tar.lz
gsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.tar.xz
gsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.tar.zst
gsoc2013-empathy-a0d57aa60447a6c2810013bad801b5ecc71d8b8c.zip
Merge branch 'contact-info-630421'
-rw-r--r--libempathy-gtk/empathy-contact-widget.c152
1 files changed, 107 insertions, 45 deletions
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 4701abede..26713ebe4 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -149,10 +149,37 @@ enum
static gboolean
field_value_is_empty (TpContactInfoField *field)
{
+ guint i;
+
if (field->field_value == NULL)
return TRUE;
- return field->field_value[0] == NULL;
+ /* Field is empty if all its values are empty */
+ for (i = 0; field->field_value[i] != NULL; i++)
+ {
+ if (!tp_str_empty (field->field_value[i]))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+set_contact_info_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error = NULL;
+
+ if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
+ &error))
+ {
+ DEBUG ("SetContactInfo() failed: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ DEBUG ("SetContactInfo() succeeded");
}
static void
@@ -181,7 +208,7 @@ contact_widget_save (EmpathyContactWidget *information)
if (information->details_to_set != NULL)
{
tp_connection_set_contact_info_async (connection,
- information->details_to_set, NULL, NULL);
+ information->details_to_set, set_contact_info_cb, NULL);
tp_contact_info_list_free (information->details_to_set);
information->details_to_set = NULL;
}
@@ -271,11 +298,38 @@ contact_info_field_cmp (TpContactInfoField *field1,
return contact_info_field_name_cmp (field1->field_name, field2->field_name);
}
-static gint
-contact_info_field_spec_cmp (TpContactInfoFieldSpec *spec1,
- TpContactInfoFieldSpec *spec2)
+static gboolean
+field_name_in_field_list (GList *list,
+ const gchar *name)
{
- return contact_info_field_name_cmp (spec1->name, spec2->name);
+ GList *l;
+
+ for (l = list; l != NULL; l = g_list_next (l))
+ {
+ TpContactInfoField *field = l->data;
+
+ if (!tp_strdiff (field->field_name, name))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static TpContactInfoFieldSpec *
+get_spec_from_list (GList *list,
+ const gchar *name)
+{
+ GList *l;
+
+ for (l = list; l != NULL; l = g_list_next (l))
+ {
+ TpContactInfoFieldSpec *spec = l->data;
+
+ if (!tp_strdiff (spec->name, name))
+ return spec;
+ }
+
+ return NULL;
}
static guint
@@ -286,65 +340,72 @@ contact_widget_details_update_edit (EmpathyContactWidget *information)
GList *specs, *l;
guint n_rows = 0;
GList *info;
+ guint i;
g_assert (information->details_to_set == NULL);
contact = empathy_contact_get_tp_contact (information->contact);
connection = tp_contact_get_connection (contact);
+
info = tp_contact_get_contact_info (contact);
specs = tp_connection_get_contact_info_supported_fields (connection);
- specs = g_list_sort (specs, (GCompareFunc) contact_info_field_spec_cmp);
- for (l = specs; l != NULL; l = l->next)
+
+ /* Look at the fields set in our vCard */
+ for (l = info; l != NULL; l = l->next)
{
- TpContactInfoFieldSpec *spec = l->data;
- TpContactInfoField *field = NULL;
- InfoFieldData *field_data;
- GList *ll;
- GtkWidget *w;
+ TpContactInfoField *field = l->data;
- field_data = find_info_field_data (spec->name);
- if (field_data == NULL)
- {
- DEBUG ("Unhandled ContactInfo field spec: %s", spec->name);
- }
+ /* make a copy for the details_to_set list */
+ field = tp_contact_info_field_copy (field);
+ DEBUG ("Field %s is in our vCard", field->field_name);
- /* Search initial value */
- for (ll = info; ll != NULL && field == NULL; ll = ll->next)
- {
- TpContactInfoField *tmp = ll->data;
+ information->details_to_set = g_list_prepend (information->details_to_set,
+ field);
+ }
- if (!tp_strdiff (tmp->field_name, spec->name))
- field = tmp;
- }
+ /* Add fields which are supported but not in the vCard */
+ for (i = 0; info_field_datas[i].field_name != NULL; i++)
+ {
+ TpContactInfoFieldSpec *spec;
+ TpContactInfoField *field;
- if (field != NULL)
- {
- /* We found the field, make a copy for the details_to_set list */
- field = tp_contact_info_field_copy (field);
- DEBUG ("Field %s is in our vCard", spec->name);
- }
- else
- {
- /* Empathy doesn't support editing this field and it's not in the
- * contact's fields so we can't do much with it. */
- DEBUG ("Field %s is not in our vCard", spec->name);
+ /* Check if the field was in the vCard */
+ if (field_name_in_field_list (information->details_to_set,
+ info_field_datas[i].field_name))
+ continue;
- if (field_data == NULL)
- continue;
+ /* Check if the CM supports the field */
+ spec = get_spec_from_list (specs, info_field_datas[i].field_name);
+ if (spec == NULL)
+ continue;
- field = tp_contact_info_field_new (spec->name, spec->parameters,
- NULL);
- }
+ /* add an empty field so user can set a value */
+ field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
information->details_to_set = g_list_prepend (information->details_to_set,
field);
+ }
+
+ /* Add widgets for supported fields */
+ information->details_to_set = g_list_sort (information->details_to_set,
+ (GCompareFunc) contact_info_field_cmp);
+
+ for (l = information->details_to_set; l != NULL; l= g_list_next (l))
+ {
+ TpContactInfoField *field = l->data;
+ InfoFieldData *field_data;
+ GtkWidget *w;
- /* Empathy doesn't display this field so we can't change it. But we put
- * it in the details_to_set list so it won't be erased when calling
- * SetContactInfo (bgo #630427) */
+ field_data = find_info_field_data (field->field_name);
if (field_data == NULL)
- continue;
+ {
+ /* Empathy doesn't display this field so we can't change it.
+ * But we put it in the details_to_set list so it won't be erased
+ * when calling SetContactInfo (bgo #630427) */
+ DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
+ continue;
+ }
/* Add Title */
w = gtk_label_new (_(field_data->title));
@@ -366,6 +427,7 @@ contact_widget_details_update_edit (EmpathyContactWidget *information)
n_rows++;
}
+
g_list_free (specs);
g_list_free (info);