]> git.0d.be Git - empathy.git/commitdiff
Incorporate updates from empathy-contact-widget into contactinfo-utils
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Thu, 8 Sep 2011 03:31:00 +0000 (13:31 +1000)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>
Thu, 20 Oct 2011 22:42:23 +0000 (09:42 +1100)
Update empathy-individual-widget for these changes. This comes from the rebase
of this branch.

libempathy-gtk/empathy-contactinfo-utils.c
libempathy-gtk/empathy-contactinfo-utils.h
libempathy-gtk/empathy-individual-widget.c

index c4bbeb1abf568f010ea1ad158e1000f5c8029207..e4e18f19db1b5ec2c4497aa69aa07c3a642b4e85 100644 (file)
 #include <config.h>
 
 #include <string.h>
 #include <config.h>
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <glib/gi18n-lib.h>
 
 #include <telepathy-glib/util.h>
 
 
 #include <glib/gi18n-lib.h>
 
 #include <telepathy-glib/util.h>
 
+#include <libempathy/empathy-time.h>
+
 #include "empathy-contactinfo-utils.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;
 
 typedef struct
 {
   const gchar *field_name;
   const gchar *title;
-  gboolean linkify;
+  FieldFormatFunc format;
 } InfoFieldData;
 
 static InfoFieldData info_field_data[] =
 {
 } 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 }
 };
 
   { 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
 empathy_contact_info_lookup_field (const gchar *field_name,
     const gchar **title,
-    gboolean *linkify)
+    EmpathyContactInfoFormatFunc *format)
 {
   guint i;
 
 {
   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 (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;
         }
 
           return TRUE;
         }
index 059085c84e612dbd71aa4bdc77394e98cab84acf..ac9528e5f152b57f92e3231a9dc3c0c7f81195f7 100644 (file)
 
 G_BEGIN_DECLS
 
 
 G_BEGIN_DECLS
 
+typedef gchar * (* EmpathyContactInfoFormatFunc) (GStrv);
+
 gboolean empathy_contact_info_lookup_field (const gchar *field_name,
 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);
 
 char *empathy_contact_info_field_label (const char *field_name,
     GStrv parameters);
 
index 7354ee83e462440b2c824a5ee56a82acb597540d..bec9225e6bb9cd32395d0b80b3a8715913606078 100644 (file)
@@ -46,7 +46,6 @@
 #include "empathy-groups-widget.h"
 #include "empathy-gtk-enum-types.h"
 #include "empathy-individual-widget.h"
 #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
 #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;
       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)
       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,
       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;
         {
           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);
 
       /* Add Value */
       w = gtk_label_new (value);
 
-      if (linkify == TRUE)
+      if (format != NULL)
         {
           gchar *markup;
 
         {
           gchar *markup;
 
-          markup = empathy_add_link_markup (value);
+          markup = format (field->field_value);
           gtk_label_set_markup (GTK_LABEL (w), markup);
           g_free (markup);
         }
           gtk_label_set_markup (GTK_LABEL (w), markup);
           g_free (markup);
         }