[Telepathy-commits] [telepathy-glib/master] Add a attributes helper function to the presence mixin for use with the contacts mixin

Sjoerd Simons sjoerd at luon.net
Tue Aug 19 04:25:19 PDT 2008


20080728150827-93b9a-9a2999f5a69fb260e116463ed8bece013a347ef6.gz
---
 telepathy-glib/presence-mixin.c |   82 +++++++++++++++++++++++++++++++++------
 telepathy-glib/presence-mixin.h |    3 +
 2 files changed, 73 insertions(+), 12 deletions(-)

diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c
index 3544efa..ebb9e3f 100644
--- a/telepathy-glib/presence-mixin.c
+++ b/telepathy-glib/presence-mixin.c
@@ -72,6 +72,7 @@
 #include <telepathy-glib/errors.h>
 #include <telepathy-glib/gtypes.h>
 #include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/contacts-mixin.h>
 
 #define DEBUG_FLAG TP_DEBUG_PRESENCE
 
@@ -1164,22 +1165,17 @@ out:
     g_hash_table_destroy (optional_arguments);
 }
 
-static void
-construct_simple_presence_hash_foreach (gpointer key,
-                                        gpointer value,
-                                        gpointer user_data)
+static GValueArray *
+construct_simple_presence_value_array (TpPresenceStatus *status,
+    const TpPresenceStatusSpec *supported_statuses)
 {
-  TpHandle handle = GPOINTER_TO_UINT (key);
-  TpPresenceStatus *status = (TpPresenceStatus *) value;
-  struct _i_absolutely_love_g_hash_table_foreach *data =
-    (struct _i_absolutely_love_g_hash_table_foreach *) user_data;
-  GValueArray *presence;
-  const gchar *status_name;
   TpConnectionPresenceType status_type;
+  const gchar *status_name;
   const gchar *message = NULL;
+  GValueArray *presence;
 
-  status_name = data->supported_statuses[status->index].name;
-  status_type = data->supported_statuses[status->index].presence_type;
+  status_name = supported_statuses[status->index].name;
+  status_type = supported_statuses[status->index].presence_type;
 
   if (status->optional_arguments != NULL)
     {
@@ -1206,6 +1202,23 @@ construct_simple_presence_hash_foreach (gpointer key,
   g_value_init (g_value_array_get_nth (presence, 2), G_TYPE_STRING);
   g_value_set_string (g_value_array_get_nth (presence, 2), message);
 
+  return presence;
+}
+
+static void
+construct_simple_presence_hash_foreach (gpointer key,
+                                        gpointer value,
+                                        gpointer user_data)
+{
+  TpHandle handle = GPOINTER_TO_UINT (key);
+  TpPresenceStatus *status = (TpPresenceStatus *) value;
+  struct _i_absolutely_love_g_hash_table_foreach *data =
+    (struct _i_absolutely_love_g_hash_table_foreach *) user_data;
+  GValueArray *presence;
+
+  presence = construct_simple_presence_value_array (status,
+    data->supported_statuses);
+
   g_hash_table_insert (data->presence_hash, GUINT_TO_POINTER (handle),
       presence);
 }
@@ -1315,3 +1328,48 @@ tp_presence_mixin_simple_presence_iface_init (gpointer g_iface,
   IMPLEMENT(get_presences);
 #undef IMPLEMENT
 }
+
+static void
+simple_presence_get_attributes_foreach (gpointer key,
+                                        gpointer value,
+                                        gpointer user_data)
+{
+  TpHandle handle = GPOINTER_TO_UINT (key);
+  TpPresenceStatus *status = (TpPresenceStatus *) value;
+  struct _i_absolutely_love_g_hash_table_foreach *data =
+    (struct _i_absolutely_love_g_hash_table_foreach *) user_data;
+  GValue *val;
+  GValueArray *presence;
+
+  presence = construct_simple_presence_value_array (status,
+    data->supported_statuses);
+
+  val = tp_g_value_slice_new (G_TYPE_VALUE_ARRAY);
+  g_value_set_boxed (val, presence);
+
+  tp_contacts_mixin_set_contact_attribute (data->presence_hash,
+    handle,
+    "org.freedesktop.Telepathy.Connection.Interface.SimplePresence/presence",
+    val);
+}
+
+void
+tp_presence_mixin_simple_presence_get_attributes (GObject *obj,
+  const GArray *contacts, GHashTable *attributes_hash)
+{
+  TpPresenceMixinClass *mixin_cls =
+    TP_PRESENCE_MIXIN_CLASS (G_OBJECT_GET_CLASS (obj));
+  struct _i_absolutely_love_g_hash_table_foreach data = {
+        mixin_cls->statuses, NULL, attributes_hash };
+  GHashTable *contact_statuses;
+
+  contact_statuses = mixin_cls->get_contact_statuses (obj, contacts, NULL);
+
+  g_assert (contact_statuses != NULL);
+
+  data.contact_statuses = contact_statuses;
+  g_hash_table_foreach (contact_statuses,
+      simple_presence_get_attributes_foreach, &data);
+
+  g_hash_table_destroy (contact_statuses);
+}
diff --git a/telepathy-glib/presence-mixin.h b/telepathy-glib/presence-mixin.h
index 00f7b66..3a24304 100644
--- a/telepathy-glib/presence-mixin.h
+++ b/telepathy-glib/presence-mixin.h
@@ -259,6 +259,9 @@ void tp_presence_mixin_iface_init (gpointer g_iface, gpointer iface_data);
 void tp_presence_mixin_simple_presence_iface_init (gpointer g_iface, gpointer iface_data);
 void tp_presence_mixin_simple_presence_init_dbus_properties (GObjectClass *cls);
 
+void tp_presence_mixin_simple_presence_get_attributes (GObject *obj,
+  const GArray *contacts, GHashTable *attributes_hash);
+
 G_END_DECLS
 
 #endif /* #ifndef __TP_PRESENCE_MIXIN_H__ */
-- 
1.5.6.3




More information about the Telepathy-commits mailing list