]> git.0d.be Git - empathy.git/commitdiff
ContactWidget: generalize linkifying values
authorWill Thompson <will.thompson@collabora.co.uk>
Tue, 10 May 2011 16:27:04 +0000 (17:27 +0100)
committerWill Thompson <will.thompson@collabora.co.uk>
Mon, 16 May 2011 12:31:04 +0000 (13:31 +0100)
Many of the new fields exposed by Idle need more processing than just
bunging the first string into a label. Let's start by generalizing
linkifying the first string. I speculatively allow the format functions
to fail.

libempathy-gtk/empathy-contact-widget.c

index 4f37ccb01ee48a5cf46491c8faee99e31bbd543a..f8f7b268b043b12c42ba3db8a13aa2c07513cbaa 100644 (file)
@@ -283,20 +283,28 @@ contact_widget_bday_changed_cb (GtkCalendar *calendar,
 
 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
 
+typedef gchar * (* FieldFormatFunc) (GStrv);
+
 typedef struct
 {
   const gchar *field_name;
   const gchar *title;
-  gboolean linkify;
+  FieldFormatFunc format;
 } InfoFieldData;
 
+static gchar *
+linkify_first_value (GStrv values)
+{
+  return empathy_add_link_markup (values[0]);
+}
+
 static InfoFieldData info_field_datas[] =
 {
-  { "fn",    N_("Full name:"),      FALSE },
-  { "tel",   N_("Phone number:"),   FALSE },
-  { "email", N_("E-mail address:"), TRUE },
-  { "url",   N_("Website:"),        TRUE },
-  { "bday",  N_("Birthday:"),       FALSE },
+  { "fn",    N_("Full name:"),      NULL },
+  { "tel",   N_("Phone number:"),   NULL },
+  { "email", N_("E-mail address:"), linkify_first_value },
+  { "url",   N_("Website:"),        linkify_first_value },
+  { "bday",  N_("Birthday:"),       NULL },
   { NULL, NULL }
 };
 
@@ -602,6 +610,7 @@ contact_widget_details_update_show (EmpathyContactWidget *information)
       TpContactInfoField *field = l->data;
       InfoFieldData *field_data;
       const gchar *value;
+      gchar *markup = NULL;
       GtkWidget *w;
 
       if (field->field_value == NULL || field->field_value[0] == NULL)
@@ -611,7 +620,7 @@ contact_widget_details_update_show (EmpathyContactWidget *information)
 
       if (!tp_strdiff (field->field_name, "x-irc-channel"))
         {
-          g_ptr_array_add (channels, (gpointer) value);
+          g_ptr_array_add (channels, (gpointer) field->field_value[0]);
           continue;
         }
 
@@ -622,6 +631,18 @@ contact_widget_details_update_show (EmpathyContactWidget *information)
           continue;
         }
 
+      if (field_data->format != NULL)
+        {
+          markup = field_data->format (field->field_value);
+
+          if (markup == NULL)
+            {
+              DEBUG ("Invalid value for field '%s' (first element was '%s')",
+                  field->field_name, field->field_value[0]);
+              continue;
+            }
+        }
+
       /* Add Title */
       w = gtk_label_new (_(field_data->title));
       gtk_table_attach (GTK_TABLE (information->table_details),
@@ -631,11 +652,8 @@ contact_widget_details_update_show (EmpathyContactWidget *information)
 
       /* Add Value */
       w = gtk_label_new (value);
-      if (field_data->linkify)
+      if (markup != NULL)
         {
-          gchar *markup;
-
-          markup = empathy_add_link_markup (value);
           gtk_label_set_markup (GTK_LABEL (w), markup);
           g_free (markup);
         }