]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-individual-widget.c
individual-widget: port to GtkGrid
[empathy.git] / libempathy-gtk / empathy-individual-widget.c
index 743be193c538c8b10a49ba73efaa84767299701e..215d3218e19ea524af29dfea458fab7f9439782a 100644 (file)
 #include <libempathy/empathy-time.h>
 
 #include "empathy-avatar-image.h"
 #include <libempathy/empathy-time.h>
 
 #include "empathy-avatar-image.h"
+#include "empathy-contactinfo-utils.h"
 #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
@@ -95,7 +95,7 @@ typedef struct {
   /* Location */
   GtkWidget *vbox_location;
   GtkWidget *subvbox_location;
   /* Location */
   GtkWidget *vbox_location;
   GtkWidget *subvbox_location;
-  GtkWidget *table_location;
+  GtkWidget *grid_location;
   GtkWidget *label_location;
 #ifdef HAVE_LIBCHAMPLAIN
   GtkWidget *viewport_map;
   GtkWidget *label_location;
 #ifdef HAVE_LIBCHAMPLAIN
   GtkWidget *viewport_map;
@@ -111,7 +111,7 @@ typedef struct {
 
   /* Details */
   GtkWidget *vbox_details;
 
   /* Details */
   GtkWidget *vbox_details;
-  GtkWidget *table_details;
+  GtkWidget *grid_details;
   GtkWidget *hbox_details_requested;
   GtkWidget *details_spinner;
   GCancellable *details_cancellable; /* owned */
   GtkWidget *hbox_details_requested;
   GtkWidget *details_spinner;
   GCancellable *details_cancellable; /* owned */
@@ -141,64 +141,6 @@ details_set_up (EmpathyIndividualWidget *self)
   gtk_widget_show (priv->details_spinner);
 }
 
   gtk_widget_show (priv->details_spinner);
 }
 
-typedef struct
-{
-  const gchar *field_name;
-  const gchar *title;
-  gboolean linkify;
-} 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 },
-  { NULL, NULL }
-};
-
-static InfoFieldData *
-find_info_field_data (const gchar *field_name)
-{
-  guint i;
-
-  for (i = 0; info_field_data[i].field_name != NULL; i++)
-    {
-      if (tp_strdiff (info_field_data[i].field_name, field_name) == FALSE)
-        return info_field_data + i;
-    }
-  return NULL;
-}
-
-static gint
-contact_info_field_name_cmp (const gchar *name1,
-    const gchar *name2)
-{
-  guint i;
-
-  if (tp_strdiff (name1, name2) == FALSE)
-    return 0;
-
-  /* We use the order of info_field_data */
-  for (i = 0; info_field_data[i].field_name != NULL; i++)
-    {
-      if (tp_strdiff (info_field_data[i].field_name, name1) == FALSE)
-        return -1;
-      if (tp_strdiff (info_field_data[i].field_name, name2) == FALSE)
-        return +1;
-    }
-
-  return g_strcmp0 (name1, name2);
-}
-
-static gint
-contact_info_field_cmp (TpContactInfoField *field1,
-    TpContactInfoField *field2)
-{
-  return contact_info_field_name_cmp (field1->field_name, field2->field_name);
-}
-
 static void
 client_types_notify_cb (TpContact *contact,
     GParamSpec *pspec,
 static void
 client_types_notify_cb (TpContact *contact,
     GParamSpec *pspec,
@@ -207,6 +149,11 @@ client_types_notify_cb (TpContact *contact,
   client_types_update (self);
 }
 
   client_types_update (self);
 }
 
+typedef struct {
+  EmpathyIndividualWidget *widget; /* weak */
+  TpContact *contact; /* owned */
+} DetailsData;
+
 static void
 update_weak_contact (EmpathyIndividualWidget *self)
 {
 static void
 update_weak_contact (EmpathyIndividualWidget *self)
 {
@@ -275,12 +222,13 @@ details_update_show (EmpathyIndividualWidget *self,
   guint n_rows = 0;
 
   info = tp_contact_get_contact_info (contact);
   guint n_rows = 0;
 
   info = tp_contact_get_contact_info (contact);
-  info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
+  info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
   for (l = info; l != NULL; l = l->next)
     {
       TpContactInfoField *field = l->data;
   for (l = info; l != NULL; l = l->next)
     {
       TpContactInfoField *field = l->data;
-      InfoFieldData *field_data;
+      gchar *title;
       const gchar *value;
       const gchar *value;
+      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)
@@ -288,27 +236,31 @@ details_update_show (EmpathyIndividualWidget *self,
 
       value = field->field_value[0];
 
 
       value = field->field_value[0];
 
-      field_data = find_info_field_data (field->field_name);
-      if (field_data == NULL)
+      if (!empathy_contact_info_lookup_field (field->field_name,
+          NULL, &format))
         {
           DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
           continue;
         }
 
       /* Add Title */
         {
           DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
           continue;
         }
 
       /* Add Title */
-      w = gtk_label_new (_(field_data->title));
-      gtk_table_attach (GTK_TABLE (priv->table_details),
-          w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
+      title = empathy_contact_info_field_label (field->field_name,
+          field->parameters);
+      w = gtk_label_new (title);
+      g_free (title);
+      gtk_grid_attach (GTK_GRID (priv->grid_details),
+          w, 0, n_rows, 1, 1);
       gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
       gtk_widget_show (w);
 
       /* Add Value */
       w = gtk_label_new (value);
       gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
       gtk_widget_show (w);
 
       /* Add Value */
       w = gtk_label_new (value);
-      if (field_data->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);
         }
@@ -316,8 +268,8 @@ details_update_show (EmpathyIndividualWidget *self,
       gtk_label_set_selectable (GTK_LABEL (w),
           (priv->flags & EMPATHY_INDIVIDUAL_WIDGET_FOR_TOOLTIP) ? FALSE : TRUE);
 
       gtk_label_set_selectable (GTK_LABEL (w),
           (priv->flags & EMPATHY_INDIVIDUAL_WIDGET_FOR_TOOLTIP) ? FALSE : TRUE);
 
-      gtk_table_attach_defaults (GTK_TABLE (priv->table_details),
-          w, 1, 2, n_rows, n_rows + 1);
+      gtk_grid_attach (GTK_GRID (priv->grid_details),
+          w, 1, n_rows, 1, 1);
       gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
       gtk_widget_show (w);
 
       gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
       gtk_widget_show (w);
 
@@ -336,7 +288,7 @@ details_notify_cb (TpContact *contact,
   EmpathyIndividualWidgetPriv *priv = GET_PRIV (self);
   guint n_rows;
 
   EmpathyIndividualWidgetPriv *priv = GET_PRIV (self);
   guint n_rows;
 
-  gtk_container_foreach (GTK_CONTAINER (priv->table_details),
+  gtk_container_foreach (GTK_CONTAINER (priv->grid_details),
       (GtkCallback) gtk_widget_destroy, NULL);
 
   n_rows = details_update_show (self, contact);
       (GtkCallback) gtk_widget_destroy, NULL);
 
   n_rows = details_update_show (self, contact);
@@ -344,7 +296,7 @@ details_notify_cb (TpContact *contact,
   if (n_rows > 0)
     {
       gtk_widget_show (priv->vbox_details);
   if (n_rows > 0)
     {
       gtk_widget_show (priv->vbox_details);
-      gtk_widget_show (priv->table_details);
+      gtk_widget_show (priv->grid_details);
     }
   else
     {
     }
   else
     {
@@ -411,7 +363,7 @@ fetch_contact_information (EmpathyIndividualWidget *self)
   /* Request the Individual's info */
   gtk_widget_show (priv->vbox_details);
   gtk_widget_show (priv->hbox_details_requested);
   /* Request the Individual's info */
   gtk_widget_show (priv->vbox_details);
   gtk_widget_show (priv->hbox_details_requested);
-  gtk_widget_hide (priv->table_details);
+  gtk_widget_hide (priv->grid_details);
   gtk_spinner_start (GTK_SPINNER (priv->details_spinner));
 
   if (priv->details_cancellable == NULL)
   gtk_spinner_start (GTK_SPINNER (priv->details_spinner));
 
   if (priv->details_cancellable == NULL)
@@ -629,12 +581,12 @@ location_update (EmpathyIndividualWidget *self)
     }
 
   /* Prepare the location information table */
     }
 
   /* Prepare the location information table */
-  if (priv->table_location != NULL)
-    gtk_widget_destroy (priv->table_location);
+  if (priv->grid_location != NULL)
+    gtk_widget_destroy (priv->grid_location);
 
 
-  priv->table_location = gtk_table_new (1, 2, FALSE);
+  priv->grid_location = gtk_grid_new ();
   gtk_box_pack_start (GTK_BOX (priv->subvbox_location),
   gtk_box_pack_start (GTK_BOX (priv->subvbox_location),
-      priv->table_location, FALSE, FALSE, 5);
+      priv->grid_location, FALSE, FALSE, 5);
 
 
   for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
 
 
   for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
@@ -651,8 +603,8 @@ location_update (EmpathyIndividualWidget *self)
 
       label = gtk_label_new (user_label);
       gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
 
       label = gtk_label_new (user_label);
       gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
-      gtk_table_attach (GTK_TABLE (priv->table_location),
-          label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
+      gtk_grid_attach (GTK_GRID (priv->grid_location),
+          label, 0, row, 1, 1);
       gtk_widget_show (label);
 
       if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
       gtk_widget_show (label);
 
       if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
@@ -676,8 +628,8 @@ location_update (EmpathyIndividualWidget *self)
       if (svalue != NULL)
         {
           label = gtk_label_new (svalue);
       if (svalue != NULL)
         {
           label = gtk_label_new (svalue);
-          gtk_table_attach_defaults (GTK_TABLE (priv->table_location),
-              label, 1, 2, row, row + 1);
+          gtk_grid_attach (GTK_GRID (priv->grid_location),
+              label, 1, row, 1, 1);
           gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
           gtk_widget_show (label);
 
           gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
           gtk_widget_show (label);
 
@@ -706,7 +658,7 @@ location_update (EmpathyIndividualWidget *self)
   if (row > 0)
     {
       /* We can display some fields */
   if (row > 0)
     {
       /* We can display some fields */
-      gtk_widget_show (priv->table_location);
+      gtk_widget_show (priv->grid_location);
     }
   else if (display_map == FALSE)
     {
     }
   else if (display_map == FALSE)
     {
@@ -1985,13 +1937,13 @@ empathy_individual_widget_init (EmpathyIndividualWidget *self)
 #endif
       "groups_widget", &priv->groups_widget,
       "vbox_details", &priv->vbox_details,
 #endif
       "groups_widget", &priv->groups_widget,
       "vbox_details", &priv->vbox_details,
-      "table_details", &priv->table_details,
+      "grid_details", &priv->grid_details,
       "hbox_details_requested", &priv->hbox_details_requested,
       "hbox_client_types", &priv->hbox_client_types,
       NULL);
   g_free (filename);
 
       "hbox_details_requested", &priv->hbox_details_requested,
       "hbox_client_types", &priv->hbox_client_types,
       NULL);
   g_free (filename);
 
-  priv->table_location = NULL;
+  priv->grid_location = NULL;
 
   gtk_box_pack_start (GTK_BOX (self), priv->vbox_individual_widget, TRUE, TRUE,
       0);
 
   gtk_box_pack_start (GTK_BOX (self), priv->vbox_individual_widget, TRUE, TRUE,
       0);