[Telepathy-commits] [telepathy-gabble/master] Implement avatars in the Contacts interface

Sjoerd Simons sjoerd.simons at collabora.co.uk
Tue Aug 19 10:54:23 PDT 2008


20080729113717-b58c9-48d70e94ffa57623cdbd9f9f2cf6ffc2bda1493b.gz
---
 src/conn-avatars.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/conn-avatars.c b/src/conn-avatars.c
index a519738..cfe1e60 100644
--- a/src/conn-avatars.c
+++ b/src/conn-avatars.c
@@ -27,6 +27,8 @@
 #include <loudmouth/loudmouth.h>
 
 #include <telepathy-glib/svc-connection.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/contacts-mixin.h>
 
 #include "base64.h"
 #include "presence.h"
@@ -820,6 +822,39 @@ gabble_connection_clear_avatar (TpSvcConnectionInterfaceAvatars *iface,
   gabble_connection_set_avatar (iface, NULL, NULL, context);
 }
 
+static void
+conn_avatars_get_contact_attributes (GObject *obj,
+    const GArray *contacts, GHashTable *attributes_hash)
+{
+  guint i;
+  GabbleConnection *self = GABBLE_CONNECTION(obj);
+  TpBaseConnection *base = (TpBaseConnection *) self;
+
+  for (i = 0; i < contacts->len; i++)
+    {
+      TpHandle handle = g_array_index (contacts, guint, i);
+      GabblePresence *presence = NULL;
+
+      if (base->self_handle == handle)
+        presence = self->self_presence;
+      else
+        presence = gabble_presence_cache_get (self->presence_cache, handle);
+
+      if (NULL != presence)
+        {
+          GValue *val = tp_g_value_slice_new (G_TYPE_STRING);
+
+          if (NULL != presence->avatar_sha1)
+            g_value_set_string (val, presence->avatar_sha1);
+          else
+            g_value_set_string (val, "");
+
+          tp_contacts_mixin_set_contact_attribute (attributes_hash, handle,
+            TP_IFACE_CONNECTION_INTERFACE_AVATARS"/token", val);
+        }
+    }
+}
+
 
 void
 conn_avatars_init (GabbleConnection *conn)
@@ -828,6 +863,10 @@ conn_avatars_init (GabbleConnection *conn)
       (connection_got_self_initial_avatar_cb), conn);
   g_signal_connect (conn->presence_cache, "avatar-update", G_CALLBACK
       (connection_avatar_update_cb), conn);
+
+  tp_contacts_mixin_add_inspectable_iface (G_OBJECT (conn),
+      TP_IFACE_CONNECTION_INTERFACE_AVATARS,
+          conn_avatars_get_contact_attributes);
 }
 
 
-- 
1.5.6.3




More information about the Telepathy-commits mailing list