From a42af9641622c0ad804478c8ce7ef63bcbf2bb46 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 28 Oct 2013 14:53:04 +0000 Subject: [PATCH 10/15] TpPresenceStatusSpec: add some accessors --- docs/reference/telepathy-glib-sections.txt | 4 ++ telepathy-glib/presence-mixin.c | 101 +++++++++++++++++++++++++---- telepathy-glib/presence-mixin.h | 16 +++++ 3 files changed, 108 insertions(+), 13 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 36845e6..c8cef3d 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -2301,6 +2301,10 @@ TP_CONTACTS_MIXIN presence-mixin TpPresenceStatusOptionalArgumentSpec TpPresenceStatusSpec +tp_presence_status_spec_can_set_on_self +tp_presence_status_spec_get_name +tp_presence_status_spec_get_presence_type +tp_presence_status_spec_has_message TpPresenceMixinStatusAvailableFunc TpPresenceMixinGetContactStatusesFunc TpPresenceMixinSetOwnStatusFunc diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c index de0158e..f8d44b8 100644 --- a/telepathy-glib/presence-mixin.c +++ b/telepathy-glib/presence-mixin.c @@ -1257,25 +1257,15 @@ tp_presence_mixin_get_simple_presence_dbus_property (GObject *object, for (i=0; mixin_cls->statuses[i].name != NULL; i++) { - const TpPresenceStatusOptionalArgumentSpec *specs; - int j; - gboolean message = FALSE; + gboolean message; /* we include statuses here even if they're not available * to set on yourself */ if (!check_status_available (object, mixin_cls, i, NULL, FALSE)) continue; - specs = mixin_cls->statuses[i].optional_arguments; - - for (j = 0; specs != NULL && specs[j].name != NULL; j++) - { - if (!tp_strdiff (specs[j].name, "message")) - { - message = TRUE; - break; - } - } + message = tp_presence_status_spec_has_message ( + &mixin_cls->statuses[i]); status = tp_value_array_build (3, G_TYPE_UINT, (guint) mixin_cls->statuses[i].presence_type, @@ -1591,3 +1581,88 @@ tp_presence_mixin_simple_presence_register_with_contacts_mixin (GObject *obj) tp_presence_mixin_simple_presence_fill_contact_attributes); } +/** + * tp_presence_status_spec_get_presence_type: + * @self: a presence status specification + * + * Return the category into which this presence type falls. For instance, + * for XMPP's "" (do not disturb) status, this would return + * %TP_CONNECTION_PRESENCE_TYPE_BUSY. + * + * Returns: a #TpConnectionPresenceType + * Since: 0.UNRELEASED + */ +TpConnectionPresenceType +tp_presence_status_spec_get_presence_type (const TpPresenceStatusSpec *self) +{ + g_return_val_if_fail (self != NULL, TP_CONNECTION_PRESENCE_TYPE_UNSET); + + return self->presence_type; +} + +/** + * tp_presence_status_spec_get_name: + * @self: a presence status specification + * + * + * + * Returns: (transfer none): the name of this presence status, + * such as "available" or "out-to-lunch". + * Since: 0.UNRELEASED + */ +const gchar * +tp_presence_status_spec_get_name (const TpPresenceStatusSpec *self) +{ + g_return_val_if_fail (self != NULL, NULL); + + return self->name; +} + +/** + * tp_presence_status_spec_can_set_on_self: + * @self: a presence status specification + * + * + * + * Returns: %TRUE if the user can set this presence status on themselves (most + * statuses), or %FALSE if they cannot directly set it on + * themselves (typically used for %TP_CONNECTION_PRESENCE_TYPE_OFFLINE + * and %TP_CONNECTION_PRESENCE_TYPE_ERROR) + * Since: 0.UNRELEASED + */ +gboolean +tp_presence_status_spec_can_set_on_self (const TpPresenceStatusSpec *self) +{ + g_return_val_if_fail (self != NULL, FALSE); + + return self->self; +} + +/** + * tp_presence_status_spec_has_message: + * @self: a presence status specification + * + * + * + * Returns: %TRUE if this presence status is accompanied by an optional + * human-readable message + * Since: 0.UNRELEASED + */ +gboolean +tp_presence_status_spec_has_message (const TpPresenceStatusSpec *self) +{ + const TpPresenceStatusOptionalArgumentSpec *arg; + + g_return_val_if_fail (self != NULL, FALSE); + + if (self->optional_arguments == NULL) + return FALSE; + + for (arg = self->optional_arguments; arg->name != NULL; arg++) + { + if (!tp_strdiff (arg->name, "message") && !tp_strdiff (arg->dtype, "s")) + return TRUE; + } + + return FALSE; +} diff --git a/telepathy-glib/presence-mixin.h b/telepathy-glib/presence-mixin.h index 63d2c7e..6654c5b 100644 --- a/telepathy-glib/presence-mixin.h +++ b/telepathy-glib/presence-mixin.h @@ -56,6 +56,22 @@ struct _TpPresenceStatusSpec { gpointer _future2; }; +_TP_AVAILABLE_IN_UNRELEASED +TpConnectionPresenceType tp_presence_status_spec_get_presence_type ( + const TpPresenceStatusSpec *self); + +_TP_AVAILABLE_IN_UNRELEASED +const gchar *tp_presence_status_spec_get_name ( + const TpPresenceStatusSpec *self); + +_TP_AVAILABLE_IN_UNRELEASED +gboolean tp_presence_status_spec_can_set_on_self ( + const TpPresenceStatusSpec *self); + +_TP_AVAILABLE_IN_UNRELEASED +gboolean tp_presence_status_spec_has_message ( + const TpPresenceStatusSpec *self); + typedef struct _TpPresenceStatus TpPresenceStatus; struct _TpPresenceStatus { -- 1.8.4.rc3