]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-widget.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / empathy-contact-widget.c
index b73fd66423b493d2441294c46235e503516c93cc..26713ebe421c34dbadf5f8f2f2b9dd00bba97bd1 100644 (file)
@@ -298,6 +298,40 @@ contact_info_field_cmp (TpContactInfoField *field1,
   return contact_info_field_name_cmp (field1->field_name, field2->field_name);
 }
 
+static gboolean
+field_name_in_field_list (GList *list,
+    const gchar *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
 contact_widget_details_update_edit (EmpathyContactWidget *information)
 {
@@ -306,6 +340,7 @@ 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);
 
@@ -313,21 +348,13 @@ contact_widget_details_update_edit (EmpathyContactWidget *information)
   connection = tp_contact_get_connection (contact);
 
   info = tp_contact_get_contact_info (contact);
-  info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
 
   specs = tp_connection_get_contact_info_supported_fields (connection);
 
+  /* Look at the fields set in our vCard */
   for (l = info; l != NULL; l = l->next)
     {
       TpContactInfoField *field = l->data;
-      InfoFieldData *field_data;
-      GtkWidget *w;
-
-      field_data = find_info_field_data (field->field_name);
-      if (field_data == NULL)
-        {
-          DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
-        }
 
       /* make a copy for the details_to_set list */
       field = tp_contact_info_field_copy (field);
@@ -335,13 +362,51 @@ contact_widget_details_update_edit (EmpathyContactWidget *information)
 
       information->details_to_set = g_list_prepend (information->details_to_set,
           field);
+    }
 
-      /* 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) */
-      if (field_data == NULL)
+  /* 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;
+
+      /* 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;
 
+      /* Check if the CM supports the field */
+      spec = get_spec_from_list (specs, info_field_datas[i].field_name);
+      if (spec == NULL)
+        continue;
+
+      /* 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;
+
+      field_data = find_info_field_data (field->field_name);
+      if (field_data == NULL)
+        {
+          /* 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));
       gtk_table_attach (GTK_TABLE (information->table_details),