diff options
author | Sjoerd Simons <sjoerd@luon.net> | 2008-07-28 15:08:27 +0000 |
---|---|---|
committer | Sjoerd Simons <sjoerd@luon.net> | 2008-07-28 15:08:27 +0000 |
commit | 42a59f050a72f02126a220f79dad022aaa81fba6 (patch) | |
tree | 23738200ecdd57ee5c066a741b88bb6681007a40 /telepathy-glib/presence-mixin.c | |
parent | 9c34170dedb6a4edc34ce000e8416f48e9c7dac8 (diff) | |
download | telepathy-glib-42a59f050a72f02126a220f79dad022aaa81fba6.tar.gz |
Add a attributes helper function to the presence mixin for use with the contacts mixin
20080728150827-93b9a-9a2999f5a69fb260e116463ed8bece013a347ef6.gz
Diffstat (limited to 'telepathy-glib/presence-mixin.c')
-rw-r--r-- | telepathy-glib/presence-mixin.c | 82 |
1 files changed, 70 insertions, 12 deletions
diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c index 3544efab1..ebb9e3f48 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); +} |