[empathy/more-contact-info: 3/7] ContactWidget: generalize linkifying values
- From: Will Thompson <wjt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy/more-contact-info: 3/7] ContactWidget: generalize linkifying values
- Date: Thu, 12 May 2011 12:48:48 +0000 (UTC)
commit d870c39dc08ee916e2fd8421573f42504f0cb6d4
Author: Will Thompson <will thompson collabora co uk>
Date: Tue May 10 17:27:04 2011 +0100
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.
libempathy-gtk/empathy-contact-widget.c | 40 ++++++++++++++++++++++--------
1 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 4f37ccb..f8f7b26 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]