diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-09-08 11:31:00 +0800 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-10-21 06:42:23 +0800 |
commit | 558a3d0590e8dbd4f56e8a96dd9b023eb3241541 (patch) | |
tree | adb097aaca5b5335ebdfa2660158378a503fefe8 /libempathy-gtk | |
parent | cf23dd409cc36a8f692bf0db4f28e505da8633f8 (diff) | |
download | gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.tar gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.tar.gz gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.tar.bz2 gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.tar.lz gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.tar.xz gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.tar.zst gsoc2013-empathy-558a3d0590e8dbd4f56e8a96dd9b023eb3241541.zip |
Incorporate updates from empathy-contact-widget into contactinfo-utils
Update empathy-individual-widget for these changes. This comes from the rebase
of this branch.
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-contactinfo-utils.c | 74 | ||||
-rw-r--r-- | libempathy-gtk/empathy-contactinfo-utils.h | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-widget.c | 9 |
3 files changed, 72 insertions, 15 deletions
diff --git a/libempathy-gtk/empathy-contactinfo-utils.c b/libempathy-gtk/empathy-contactinfo-utils.c index c4bbeb1ab..e4e18f19d 100644 --- a/libempathy-gtk/empathy-contactinfo-utils.c +++ b/libempathy-gtk/empathy-contactinfo-utils.c @@ -23,27 +23,83 @@ #include <config.h> #include <string.h> +#include <stdlib.h> #include <glib/gi18n-lib.h> #include <telepathy-glib/util.h> +#include <libempathy/empathy-time.h> + #include "empathy-contactinfo-utils.h" +#include "empathy-string-parser.h" + +static gchar * +linkify_first_value (GStrv values) +{ + return empathy_add_link_markup (values[0]); +} + +static gchar * +format_idle_time (GStrv values) +{ + const gchar *value = values[0]; + int duration = strtol (value, NULL, 10); + + if (duration <= 0) + return NULL; + + return empathy_duration_to_string (duration); +} + +static gchar * +format_server (GStrv values) +{ + g_assert (values[0] != NULL); + + if (values[1] == NULL) + return g_markup_escape_text (values[0], -1); + else + return g_markup_printf_escaped ("%s (%s)", values[0], values[1]); +} + +static gchar * +presence_hack (GStrv values) +{ + if (tp_str_empty (values[0])) + return NULL; + + return g_markup_escape_text (values[0], -1); +} + +typedef gchar * (* FieldFormatFunc) (GStrv); typedef struct { const gchar *field_name; const gchar *title; - gboolean linkify; + FieldFormatFunc format; } InfoFieldData; static InfoFieldData info_field_data[] = { - { "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 }, + + /* Note to translators: this is the caption for a string of the form "5 + * minutes ago", and refers to the time since the contact last interacted + * with their IM client. */ + { "x-idle-time", N_("Last seen:"), format_idle_time }, + { "x-irc-server", N_("Server:"), format_server }, + { "x-host", N_("Connected from:"), format_server }, + + /* FIXME: once Idle implements SimplePresence using this information, we can + * and should bin this. */ + { "x-presence-status-message", N_("Away message:"), presence_hack }, + { NULL, NULL } }; @@ -68,7 +124,7 @@ static InfoParameterData info_parameter_data[] = gboolean empathy_contact_info_lookup_field (const gchar *field_name, const gchar **title, - gboolean *linkify) + EmpathyContactInfoFormatFunc *format) { guint i; @@ -79,8 +135,8 @@ empathy_contact_info_lookup_field (const gchar *field_name, if (title != NULL) *title = gettext (info_field_data[i].title); - if (linkify != NULL) - *linkify = info_field_data[i].linkify; + if (format != NULL) + *format = info_field_data[i].format; return TRUE; } diff --git a/libempathy-gtk/empathy-contactinfo-utils.h b/libempathy-gtk/empathy-contactinfo-utils.h index 059085c84..ac9528e5f 100644 --- a/libempathy-gtk/empathy-contactinfo-utils.h +++ b/libempathy-gtk/empathy-contactinfo-utils.h @@ -26,8 +26,10 @@ G_BEGIN_DECLS +typedef gchar * (* EmpathyContactInfoFormatFunc) (GStrv); + gboolean empathy_contact_info_lookup_field (const gchar *field_name, - const gchar **title, gboolean *linkify); + const gchar **title, EmpathyContactInfoFormatFunc *linkify); char *empathy_contact_info_field_label (const char *field_name, GStrv parameters); diff --git a/libempathy-gtk/empathy-individual-widget.c b/libempathy-gtk/empathy-individual-widget.c index 7354ee83e..bec9225e6 100644 --- a/libempathy-gtk/empathy-individual-widget.c +++ b/libempathy-gtk/empathy-individual-widget.c @@ -46,7 +46,6 @@ #include "empathy-groups-widget.h" #include "empathy-gtk-enum-types.h" #include "empathy-individual-widget.h" -#include "empathy-string-parser.h" #include "empathy-ui-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT @@ -229,7 +228,7 @@ details_update_show (EmpathyIndividualWidget *self, TpContactInfoField *field = l->data; gchar *title; const gchar *value; - gboolean linkify; + EmpathyContactInfoFormatFunc format; GtkWidget *w; if (field->field_value == NULL || field->field_value[0] == NULL) @@ -238,7 +237,7 @@ details_update_show (EmpathyIndividualWidget *self, value = field->field_value[0]; if (!empathy_contact_info_lookup_field (field->field_name, - NULL, &linkify)) + NULL, &format)) { DEBUG ("Unhandled ContactInfo field: %s", field->field_name); continue; @@ -257,11 +256,11 @@ details_update_show (EmpathyIndividualWidget *self, /* Add Value */ w = gtk_label_new (value); - if (linkify == TRUE) + if (format != NULL) { gchar *markup; - markup = empathy_add_link_markup (value); + markup = format (field->field_value); gtk_label_set_markup (GTK_LABEL (w), markup); g_free (markup); } |