[telepathy-gabble/master] add support for the 'location' attribute in the Contacts interface

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Aug 14 05:44:01 PDT 2009


---
 src/conn-location.c |   37 +++++++++++++++++++++++++++++++++++++
 src/conn-location.h |    2 ++
 src/connection.c    |    1 +
 3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/conn-location.c b/src/conn-location.c
index 14eaaf4..a5cb365 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -8,6 +8,8 @@
 
 #define DEBUG_FLAG GABBLE_DEBUG_LOCATION
 
+#include <telepathy-glib/gtypes.h>
+
 #include "debug.h"
 #include "extensions/extensions.h"
 #include "namespaces.h"
@@ -517,3 +519,38 @@ geolocation_event_handler (GabbleConnection *conn,
   return update_location_from_msg (conn, from, msg);
 }
 
+static void
+conn_location_fill_contact_attributes (GObject *obj,
+    const GArray *contacts,
+    GHashTable *attributes_hash)
+{
+  guint i;
+  GabbleConnection *self = GABBLE_CONNECTION(obj);
+
+  for (i = 0; i < contacts->len; i++)
+    {
+      TpHandle handle = g_array_index (contacts, TpHandle, i);
+      GHashTable *location;
+
+      location = get_cached_location_or_query (self, handle, NULL);
+      if (location != NULL)
+        {
+          GValue *val = tp_g_value_slice_new_boxed (
+              TP_HASH_TYPE_STRING_VARIANT_MAP, location);
+
+          tp_contacts_mixin_set_contact_attribute (attributes_hash,
+            handle, GABBLE_IFACE_CONNECTION_INTERFACE_LOCATION"/location",
+            val);
+
+          g_hash_table_unref (location);
+        }
+    }
+}
+
+void
+conn_location_init (GabbleConnection *conn)
+{
+  tp_contacts_mixin_add_contact_attributes_iface (G_OBJECT (conn),
+    GABBLE_IFACE_CONNECTION_INTERFACE_LOCATION,
+    conn_location_fill_contact_attributes);
+}
diff --git a/src/conn-location.h b/src/conn-location.h
index b773a78..eb3e358 100644
--- a/src/conn-location.h
+++ b/src/conn-location.h
@@ -17,6 +17,8 @@ gboolean conn_location_properties_setter (GObject *object, GQuark interface,
 gboolean geolocation_event_handler (GabbleConnection *conn,
     LmMessage *msg, TpHandle handle);
 
+void conn_location_init (GabbleConnection *conn);
+
 G_END_DECLS
 
 #endif /* __CONN_LOCATION_H__ */
diff --git a/src/connection.c b/src/connection.c
index db5f362..d71b1c6 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -293,6 +293,7 @@ gabble_connection_constructor (GType type,
   conn_avatars_init (self);
   conn_presence_init (self);
   conn_olpc_activity_properties_init (self);
+  conn_location_init (self);
 
   tp_contacts_mixin_add_contact_attributes_iface (G_OBJECT (self),
       TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES,
-- 
1.5.6.5




More information about the telepathy-commits mailing list