aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-contact-widget.c
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-05-11 00:27:04 +0800
committerWill Thompson <will.thompson@collabora.co.uk>2011-05-16 20:31:04 +0800
commit3e99c2d9e8b4f5a36507722c8bd681086c3220c4 (patch)
tree5989a291e2d8f580f2184645d8a974f161abcc36 /libempathy-gtk/empathy-contact-widget.c
parente92e9e9c411ec02dacc1bb11f15aa4682fd64cdf (diff)
downloadgsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.tar
gsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.tar.gz
gsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.tar.bz2
gsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.tar.lz
gsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.tar.xz
gsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.tar.zst
gsoc2013-empathy-3e99c2d9e8b4f5a36507722c8bd681086c3220c4.zip
ContactWidget: generalize linkifying values
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.
Diffstat (limited to 'libempathy-gtk/empathy-contact-widget.c')
-rw-r--r--libempathy-gtk/empathy-contact-widget.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 4f37ccb01..f8f7b268b 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -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);
}