From 9629f5ffe3193770b4c60769ca7e46db1cfecb5f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 30 Oct 2013 12:49:44 +0000 Subject: [PATCH 14/15] TpProtocol: add API for presence statuses --- docs/reference/telepathy-glib-sections.txt | 2 + telepathy-glib/protocol.c | 63 ++++++++++++++++++++++++++++++ telepathy-glib/protocol.h | 4 ++ 3 files changed, 69 insertions(+) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 7844951..2e9d5eb 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -6189,6 +6189,8 @@ tp_protocol_normalize_contact_finish tp_protocol_get_avatar_requirements +tp_protocol_dup_presence_statuses + tp_protocol_get_addressable_uri_schemes tp_protocol_get_addressable_vcard_fields tp_protocol_normalize_contact_uri_async diff --git a/telepathy-glib/protocol.c b/telepathy-glib/protocol.c index 0eded4c..8ab0bc8 100644 --- a/telepathy-glib/protocol.c +++ b/telepathy-glib/protocol.c @@ -148,6 +148,8 @@ struct _TpProtocolPrivate gchar *cm_name; GStrv addressable_vcard_fields; GStrv addressable_uri_schemes; + /* (transfer container) (element-type utf8 Simple_Status_Spec) */ + GHashTable *presence_statuses; }; enum @@ -411,6 +413,9 @@ tp_protocol_finalize (GObject *object) g_strfreev (self->priv->addressable_vcard_fields); g_strfreev (self->priv->addressable_uri_schemes); + if (self->priv->presence_statuses != NULL) + g_hash_table_unref (self->priv->presence_statuses); + if (self->priv->protocol_properties != NULL) g_hash_table_unref (self->priv->protocol_properties); @@ -610,6 +615,18 @@ tp_protocol_constructed (GObject *object) TP_PROP_PROTOCOL_INTERFACE_ADDRESSING_ADDRESSABLE_URI_SCHEMES); } + if (tp_proxy_has_interface_by_id (self, + TP_IFACE_QUARK_PROTOCOL_INTERFACE_PRESENCE)) + { + self->priv->presence_statuses = tp_asv_get_boxed ( + self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_PRESENCE_STATUSES, + TP_HASH_TYPE_SIMPLE_STATUS_SPEC_MAP); + + if (self->priv->presence_statuses != NULL) + g_hash_table_ref (self->priv->presence_statuses); + } + /* become ready immediately */ _tp_proxy_set_feature_prepared (proxy, TP_PROTOCOL_FEATURE_PARAMETERS, had_immutables); @@ -2242,3 +2259,49 @@ tp_protocol_get_addressable_uri_schemes (TpProtocol *self) g_return_val_if_fail (TP_IS_PROTOCOL (self), NULL); return (const gchar * const *) self->priv->addressable_uri_schemes; } + +/** + * tp_protocol_dup_presence_statuses: + * @self: a protocol object + * + * Return the presence statuses that might be supported by connections + * to this protocol. + * + * It is possible that some of these statuses will not actually be supported + * by a connection: for instance, an XMPP connection manager would + * include "hidden" in this list, even though not all XMPP servers allow + * users to be online-but-hidden. + * + * Returns: (transfer full) (element-type TelepathyGLib.PresenceStatusSpec): a + * list of statuses, or %NULL if unknown + */ +GList * +tp_protocol_dup_presence_statuses (TpProtocol *self) +{ + GHashTableIter iter; + gpointer k, v; + GList *l = NULL; + + g_return_val_if_fail (TP_IS_PROTOCOL (self), NULL); + + if (self->priv->presence_statuses == NULL) + return NULL; + + g_hash_table_iter_init (&iter, self->priv->presence_statuses); + + while (g_hash_table_iter_next (&iter, &k, &v)) + { + guint type; + gboolean on_self, message; + + tp_value_array_unpack (v, 3, + &type, + &on_self, + &message); + + l = g_list_prepend (l, tp_presence_status_spec_new (k, type, + on_self, message)); + } + + return g_list_reverse (l); +} diff --git a/telepathy-glib/protocol.h b/telepathy-glib/protocol.h index 8555144..e380441 100644 --- a/telepathy-glib/protocol.h +++ b/telepathy-glib/protocol.h @@ -123,6 +123,10 @@ const gchar * const * /* ... */ tp_protocol_get_addressable_uri_schemes (TpProtocol *self); +_TP_AVAILABLE_IN_UNRELEASED +GList *tp_protocol_dup_presence_statuses (TpProtocol *self) + G_GNUC_WARN_UNUSED_RESULT; + #define TP_PROTOCOL_FEATURE_CORE \ (tp_protocol_get_feature_quark_core ()) GQuark tp_protocol_get_feature_quark_core (void) G_GNUC_CONST; -- 1.8.4.rc3