summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-30 12:49:44 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-11-11 16:49:32 +0000
commitd01acacceaef93160af478f8534e00d264baba03 (patch)
treec5fb4d6184431b0af68e281750a52ba2eb1a5ba2
parent043d6101a4c8ad46e496fd463318979b2674ac68 (diff)
TpProtocol: add API for presence statuses
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71048 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--docs/reference/telepathy-glib-sections.txt2
-rw-r--r--telepathy-glib/protocol.c63
-rw-r--r--telepathy-glib/protocol.h4
3 files changed, 69 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 78449512f..2e9d5eb3d 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -6189,6 +6189,8 @@ tp_protocol_normalize_contact_finish
<SUBSECTION>
tp_protocol_get_avatar_requirements
<SUBSECTION>
+tp_protocol_dup_presence_statuses
+<SUBSECTION>
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 0eded4c80..8ab0bc81a 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 8555144fd..e380441ef 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;