]> git.0d.be Git - empathy.git/commitdiff
contact: enable showing a phone next to contacts who are on phones
authorJonny Lamb <jonny.lamb@collabora.co.uk>
Thu, 30 Sep 2010 15:01:20 +0000 (16:01 +0100)
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
Mon, 15 Nov 2010 16:59:11 +0000 (17:59 +0100)
The future!

Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
libempathy-gtk/empathy-individual-store.c
libempathy-gtk/empathy-individual-store.h
libempathy-gtk/empathy-individual-view.c
libempathy/empathy-contact.c
libempathy/empathy-contact.h
libempathy/empathy-tp-contact-factory.c

index 807afb2a220c174567817b1613ca14565ae71e15..abd1d02e855361263609645ba8d7c2e8556198f0 100644 (file)
@@ -154,6 +154,33 @@ individual_can_audio_video_call (FolksIndividual *individual,
   *can_video_call = can_video;
 }
 
+static const gchar * const *
+individual_get_client_types (FolksIndividual *individual)
+{
+  GList *personas, *l;
+  const gchar * const *types = NULL;
+  FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
+
+  personas = folks_individual_get_personas (individual);
+  for (l = personas; l != NULL; l = l->next)
+    {
+      FolksPresence *presence = FOLKS_PRESENCE (l->data);
+
+      if (folks_presence_typecmp (folks_presence_get_presence_type (presence),
+              presence_type) > 0)
+        {
+          TpContact *tp_contact;
+
+          presence_type = folks_presence_get_presence_type (presence);
+
+          tp_contact = tpf_persona_get_contact (TPF_PERSONA (l->data));
+          types = tp_contact_get_client_types (tp_contact);
+        }
+    }
+
+  return types;
+}
+
 static void
 add_individual_to_store (GtkTreeStore *self,
     GtkTreeIter *iter,
@@ -161,10 +188,13 @@ add_individual_to_store (GtkTreeStore *self,
     FolksIndividual *individual)
 {
   gboolean can_audio_call, can_video_call;
+  const gchar * const *types;
 
   individual_can_audio_video_call (individual, &can_audio_call,
       &can_video_call);
 
+  types = individual_get_client_types (individual);
+
   gtk_tree_store_insert_with_values (self, iter, parent, 0,
       EMPATHY_INDIVIDUAL_STORE_COL_NAME,
       folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)),
@@ -173,6 +203,7 @@ add_individual_to_store (GtkTreeStore *self,
       EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
       EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
       EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
+      EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
       -1);
 }
 
@@ -738,10 +769,13 @@ individual_store_contact_update (EmpathyIndividualStore *self,
   for (l = iters; l && set_model; l = l->next)
     {
       gboolean can_audio_call, can_video_call;
+      const gchar * const *types;
 
       individual_can_audio_video_call (individual, &can_audio_call,
           &can_video_call);
 
+      types = individual_get_client_types (individual);
+
       gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
           EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
           EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
@@ -757,6 +791,7 @@ individual_store_contact_update (EmpathyIndividualStore *self,
           EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, FALSE,
           EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, can_audio_call,
           EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, can_video_call,
+          EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, types,
           -1);
     }
 
@@ -859,6 +894,8 @@ individual_personas_changed_cb (FolksIndividual *individual,
       g_object_set_data (G_OBJECT (contact), "individual", individual);
       g_signal_connect (contact, "notify::capabilities",
           (GCallback) individual_store_contact_updated_cb, self);
+      g_signal_connect (contact, "notify::client-types",
+          (GCallback) individual_store_contact_updated_cb, self);
 
       g_object_unref (contact);
     }
@@ -1494,6 +1531,7 @@ individual_store_setup (EmpathyIndividualStore *self)
     G_TYPE_BOOLEAN,             /* Can make audio calls */
     G_TYPE_BOOLEAN,             /* Can make video calls */
     G_TYPE_BOOLEAN,             /* Is a fake group */
+    G_TYPE_STRV,                /* Client types */
   };
 
   priv = GET_PRIV (self);
index debb218ad488d1a0cd911ff4ac13c449b4281377..246c73b913e58215fee82ece973a5775261002f2 100644 (file)
@@ -64,6 +64,7 @@ typedef enum
   EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL,
   EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL,
   EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP,
+  EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES,
   EMPATHY_INDIVIDUAL_STORE_COL_COUNT,
 } EmpathyIndividualStoreCol;
 
index 6eb301d341c58b10498b384e1cbbf6daba8ee01c..94e60a41cd0f5e50a14f5b188934107aef2ad64c 100644 (file)
@@ -1191,6 +1191,36 @@ individual_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
   individual_view_cell_set_background (view, cell, is_group, is_active);
 }
 
+static void
+individual_view_phone_cell_data_func (GtkTreeViewColumn *tree_column,
+    GtkCellRenderer *cell,
+    GtkTreeModel *model,
+    GtkTreeIter *iter,
+    EmpathyIndividualView *view)
+{
+  gboolean is_group;
+  gboolean is_active;
+  gchar **types;
+
+  gtk_tree_model_get (model, iter,
+      EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
+      EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, &is_active,
+      EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES, &types,
+      -1);
+
+  g_object_set (cell,
+      "visible",
+        !is_group
+        && types != NULL
+        && g_strv_length (types) > 0
+        && !tp_strdiff (types[0], "phone"),
+      NULL);
+
+  g_strfreev (types);
+
+  individual_view_cell_set_background (view, cell, is_group, is_active);
+}
+
 static void
 individual_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
     GtkCellRenderer *cell,
@@ -1833,6 +1863,15 @@ individual_view_constructed (GObject *object)
   gtk_tree_view_column_add_attribute (col, cell,
       "compact", EMPATHY_INDIVIDUAL_STORE_COL_COMPACT);
 
+  /* Phone Icon */
+  cell = gtk_cell_renderer_pixbuf_new ();
+  gtk_tree_view_column_pack_start (col, cell, FALSE);
+  gtk_tree_view_column_set_cell_data_func (col, cell,
+      (GtkTreeCellDataFunc) individual_view_phone_cell_data_func,
+      view, NULL);
+
+  g_object_set (cell, "visible", FALSE, "icon-name", "phone", NULL);
+
   /* Audio Call Icon */
   cell = empathy_cell_renderer_activatable_new ();
   gtk_tree_view_column_pack_start (col, cell, FALSE);
index 4db37f693294b7bc88f91bebba997883b588bee3..5383187c1b07bce2ef8327b86b8a9cf7c49f6d0d 100644 (file)
@@ -70,6 +70,7 @@ typedef struct {
    */
   GHashTable *location;
   GHashTable *groups;
+  gchar **client_types;
 } EmpathyContactPriv;
 
 static void contact_finalize (GObject *object);
@@ -85,6 +86,9 @@ static void update_geocode (EmpathyContact *contact);
 static void empathy_contact_set_location (EmpathyContact *contact,
     GHashTable *location);
 
+static void contact_set_client_types (EmpathyContact *contact,
+    const gchar * const *types);
+
 static void set_capabilities_from_tp_caps (EmpathyContact *self,
     TpCapabilities *caps);
 
@@ -110,7 +114,8 @@ enum
   PROP_HANDLE,
   PROP_CAPABILITIES,
   PROP_IS_USER,
-  PROP_LOCATION
+  PROP_LOCATION,
+  PROP_CLIENT_TYPES
 };
 
 enum {
@@ -163,6 +168,11 @@ tp_contact_notify_cb (TpContact *tp_contact,
     {
       contact_set_avatar_from_tp_contact (EMPATHY_CONTACT (contact));
     }
+  else if (!tp_strdiff (param->name, "client-types"))
+    {
+      contact_set_client_types (EMPATHY_CONTACT (contact),
+          tp_contact_get_client_types (tp_contact));
+    }
 }
 
 static void
@@ -223,6 +233,7 @@ contact_constructed (GObject *object)
   GHashTable *location;
   TpHandle self_handle;
   TpHandle handle;
+  const gchar * const *client_types;
 
   if (priv->tp_contact == NULL)
     return;
@@ -233,6 +244,10 @@ contact_constructed (GObject *object)
   if (location != NULL)
     empathy_contact_set_location (contact, location);
 
+  client_types = tp_contact_get_client_types (priv->tp_contact);
+  if (client_types != NULL)
+    contact_set_client_types (contact, client_types);
+
   set_capabilities_from_tp_caps (contact,
       tp_contact_get_capabilities (priv->tp_contact));
 
@@ -365,6 +380,14 @@ empathy_contact_class_init (EmpathyContactClass *class)
         G_TYPE_HASH_TABLE,
         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class,
+      PROP_CLIENT_TYPES,
+      g_param_spec_boxed ("client-types",
+        "Contact client types",
+        "Client types of the contact",
+        G_TYPE_STRV,
+        G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   signals[PRESENCE_CHANGED] =
     g_signal_new ("presence-changed",
                   G_TYPE_FROM_CLASS (class),
@@ -388,6 +411,7 @@ empathy_contact_init (EmpathyContact *contact)
   contact->priv = priv;
 
   priv->location = NULL;
+  priv->client_types = NULL;
   priv->groups = NULL;
 }
 
@@ -404,6 +428,7 @@ contact_finalize (GObject *object)
     g_hash_table_destroy (priv->groups);
   g_free (priv->alias);
   g_free (priv->id);
+  g_strfreev (priv->client_types);
 
   G_OBJECT_CLASS (empathy_contact_parent_class)->finalize (object);
 }
@@ -1396,6 +1421,31 @@ empathy_contact_set_location (EmpathyContact *contact,
   g_object_notify (G_OBJECT (contact), "location");
 }
 
+const gchar * const *
+empathy_contact_get_client_types (EmpathyContact *contact)
+{
+  EmpathyContactPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+  priv = GET_PRIV (contact);
+
+  return (const gchar * const *) priv->client_types;
+}
+
+static void
+contact_set_client_types (EmpathyContact *contact,
+    const gchar * const *client_types)
+{
+  EmpathyContactPriv *priv = GET_PRIV (contact);
+
+  if (priv->client_types != NULL)
+    g_strfreev (priv->client_types);
+
+  priv->client_types = g_strdupv ((gchar **) client_types);
+  g_object_notify (G_OBJECT (contact), "client-types");
+}
+
 /**
  * empathy_contact_equal:
  * @contact1: an #EmpathyContact
index 005cf1e7ae60d61892ecfad76a6a5f9a2a8b168d..f9217c108c4780379dcfafc26a82ce3f71a35bb5 100644 (file)
@@ -125,6 +125,7 @@ gboolean empathy_avatar_save_to_file (EmpathyAvatar *avatar,
     const gchar *filename, GError **error);
 
 GHashTable * empathy_contact_get_location (EmpathyContact *contact);
+const gchar * const * empathy_contact_get_client_types (EmpathyContact *contact);
 gboolean empathy_contact_equal (gconstpointer contact1,
     gconstpointer contact2);
 
index ff572cc431ef870afa2422029c4fe800d5b62d69..87c65385e21b40125ae37f970660b6b38b7b79e1 100644 (file)
@@ -31,6 +31,7 @@ static TpContactFeature contact_features[] = {
        TP_CONTACT_FEATURE_PRESENCE,
        TP_CONTACT_FEATURE_LOCATION,
        TP_CONTACT_FEATURE_CAPABILITIES,
+       TP_CONTACT_FEATURE_CLIENT_TYPES,
 };
 
 typedef union {