From eff5efa6862416fa93187ac69af3dfc43b17fa6a Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Fri, 7 May 2010 13:35:30 +0200 Subject: [PATCH] Add stubs to TpConnection for setting the self presence and getting the allowed statuses https://bugs.freedesktop.org/show_bug.cgi?id=24107 --- docs/reference/telepathy-glib-sections.txt | 3 + telepathy-glib/connection-internal.h | 2 + telepathy-glib/connection.c | 197 ++++++++++++++++++++++++++++ telepathy-glib/connection.h | 35 +++++ 4 files changed, 237 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 4d79193..09591a1 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -2777,6 +2777,9 @@ tp_connection_presence_type_cmp_availability tp_connection_parse_object_path tp_connection_get_capabilities tp_connection_get_avatar_requirements +tp_connection_get_allowed_presence_statuses +TpConnectionSetSelfPresenceCb +tp_connection_set_self_presence TP_UNKNOWN_CONNECTION_STATUS TP_ERRORS_DISCONNECTED tp_connection_get_detailed_error diff --git a/telepathy-glib/connection-internal.h b/telepathy-glib/connection-internal.h index f96cfb9..8756881 100644 --- a/telepathy-glib/connection-internal.h +++ b/telepathy-glib/connection-internal.h @@ -51,6 +51,8 @@ struct _TpConnectionPrivate { TpAvatarRequirements *avatar_requirements; + GHashTable *allowed_presence_statuses; + TpProxyPendingCall *introspection_call; unsigned fetching_rcc:1; unsigned fetching_avatar_requirements:1; diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c index cd4b1a1..bc52359 100644 --- a/telepathy-glib/connection.c +++ b/telepathy-glib/connection.c @@ -60,6 +60,7 @@ * * connection status tracking * calling GetInterfaces() automatically + * Getting the valid presence statuses automatically * * * Since: 0.7.1 @@ -193,6 +194,28 @@ tp_connection_get_feature_quark_avatar_requirements (void) } /** + * TP_CONNECTION_FEATURE_SELF_PRESENCE: + * + * Expands to a call to a function that returns a #GQuark representing the + * "self-presence" feature. + * + * When this feature is prepared, the allowed presence statuses for this + * Connection have been retrieved. Use + * tp_connection_get_allowed_presence_statuses() to get them once prepared. + * + * One can ask for a feature to be prepared using the + * tp_proxy_prepare_async() function, and waiting for it to callback. + * + * Since: 0.11.5 + */ + +GQuark +tp_connection_get_feature_quark_self_presence (void) +{ + return g_quark_from_static_string ("tp-connection-feature-self-presence"); +} + +/** * TP_ERRORS_DISCONNECTED: * * #GError domain representing a Telepathy connection becoming disconnected. @@ -1090,6 +1113,7 @@ enum { FEAT_CONNECTED, FEAT_CAPABILITIES, FEAT_AVATAR_REQUIREMENTS, + FEAT_SELF_PRESENCE, N_FEAT }; @@ -2273,3 +2297,176 @@ tp_connection_get_detailed_error (TpConnection *self, } } } + +/** + * TpStatusSpec: + * @type: The type of a presence. This SHOULD NOT be used as a way to set + * statuses that the client does not recognise (as explained in SetPresence), + * but MAY be used to check that the client's assumptions about a particular + * status name match the connection manager's. + * @status: The string identifier of this status. + * @may_set_on_self: If true, the user can set this status on themselves using + * tp_connection_set_self_presence. + * @can_have_message: If true, a non-empty message can be set for this status. + * Otherwise, the empty string is the only acceptable message. On IRC you can + * be Away with a status message, but if you are available you cannot set a + * status message. + * + * The possible presence statuses for this connection in its current status. + * + * Since: 0.11.5 + */ + +/** + * TP_TYPE_STATUS_SPEC: + * + * The boxed type of a #TpStatusSpec. + * + * Since: 0.11.5 + */ +GType +tp_status_spec_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) + { + type = g_boxed_type_register_static ( + g_intern_static_string ("TpStatusSpec"), + (GBoxedCopyFunc) tp_status_spec_copy, + (GBoxedFreeFunc) tp_status_spec_destroy); + } + + return type; +} + +/** + * tp_status_spec_new: + * @type: The type of a presence. + * @status: The string identifier of this status. + * @may_set_on_self: If true, the user can set this status on themselves using + * tp_connection_set_self_presence. + * @can_have_message: If true, a non-empty message can be set for this status. + * + * + * + * Returns: a newly allocated #TpStatusSpec, free it with + * tp_status_spec_destroy() + * Since: 0.11.5 + */ +TpStatusSpec * +tp_status_spec_new (guint type, + gchar *status, + gboolean may_set_on_self, + gboolean can_have_message) +{ + TpStatusSpec *self; + + self = g_slice_new (TpStatusSpec); + self->type = type; + self->status = g_strdup (status); + self->may_set_on_self = may_set_on_self; + self->can_have_message = can_have_message; + + return self; +} + +/** + * tp_status_spec_copy: + * @self: a #TpStatusSpec + * + * + * + * Returns: a newly allocated #TpStatusSpec, free it with + * tp_status_spec_destroy() + * Since: 0.11.5 + */ +TpStatusSpec * +tp_status_spec_copy (TpStatusSpec *self) +{ + g_return_val_if_fail (self != NULL, NULL); + + return tp_status_spec_new (self->type, + self->status, + self->may_set_on_self, + self->can_have_message); +} + +/** + * tp_status_spec_destroy: + * @self: a #TpStatusSpec + * + * Free all memory used by the #TpStatusSpec. + * + * Since: 0.11.5 + */ +void +tp_status_spec_destroy (TpStatusSpec *self) +{ + g_return_if_fail (self != NULL); + + g_free (self->status); + g_slice_free (TpStatusSpec, self); +} + +/** + * tp_connection_get_allowed_presence_statuses: + * @self: a connection + * + * Return a dictionary of presence statuses valid for use in this connection. + * + * The value may have changed arbitrarily during the time the Connection + * spends in status TP_CONNECTION_STATUS_CONNECTING, again staying fixed for + * the entire time in TP_CONNECTION_STATUS_CONNECTED. + * + * This method requires TP_CONNECTION_FEATURE_SELF_PRESENCE to be enabled. + * To wait for the allowed presence statuses, call tp_proxy_prepare_async() + * with the feature %TP_CONNECTION_FEATURE_SELF_PRESENCE. + * + * Returns: (element-type utf8 StatusSpec): Dictionary from string identifiers to structs for each valid status. + * + * Since: 0.11.5 + */ +GHashTable * +tp_connection_get_allowed_presence_statuses (TpConnection *self) +{ + g_return_val_if_fail (TP_IS_CONNECTION (self), NULL); + + /* Temp mock */ + { + GHashTable *dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, + (GDestroyNotify) tp_status_spec_destroy); + TpStatusSpec *status = tp_status_spec_new (1, "brb", TRUE, TRUE); + g_hash_table_insert (dict, g_strdup("brb"), status); + + g_hash_table_ref (dict); + self->priv->allowed_presence_statuses = dict; + } + + return self->priv->allowed_presence_statuses; +} + +/** + * tp_connection_set_self_presence: + * @self: a connection + * @status: the desired status, one of the statuses returned by + * tp_connection_get_allowed_presence_statuses() + * @status_message: desired status message + * @callback: if not %NULL, called exactly once, when the operation has been + * finished or has failed + * @user_data: user-supplied data + * + * Set the self presence status. + * + * Note that clients SHOULD set the status message for the local user to the + * empty string, unless the user has actually provided a specific message (i.e. + * one that conveys more information than the Status). + * + * Since: 0.11.5 + */ +void +tp_connection_set_self_presence (TpConnection *self, gchar *status, + gchar *status_message, GAsyncReadyCallback callback, gpointer user_data) +{ + +} diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h index 13737ab..d4c266d 100644 --- a/telepathy-glib/connection.h +++ b/telepathy-glib/connection.h @@ -87,6 +87,32 @@ TpAvatarRequirements * tp_avatar_requirements_copy ( void tp_avatar_requirements_destroy (TpAvatarRequirements *self); +typedef struct _TpStatusSpec TpStatusSpec; +struct _TpStatusSpec +{ + guint type; + gchar *status; + gboolean may_set_on_self; + gboolean can_have_message; + + /**/ + gpointer _1; +}; + +#define TP_TYPE_STATUS_SPEC (tp_status_spec_get_type ()) +GType tp_status_spec_get_type (void); + +TpStatusSpec * tp_status_spec_new ( + guint type, + gchar *status, + gboolean may_set_on_self, + gboolean can_have_message); + +TpStatusSpec * tp_status_spec_copy (TpStatusSpec *self); + +void tp_status_spec_destroy (TpStatusSpec *self); + + GType tp_connection_get_type (void); #define TP_ERRORS_DISCONNECTED (tp_errors_disconnected_quark ()) @@ -159,6 +185,11 @@ gboolean tp_connection_parse_object_path (TpConnection *self, gchar **protocol, const gchar *tp_connection_get_detailed_error (TpConnection *self, const GHashTable **details); +GHashTable *tp_connection_get_allowed_presence_statuses (TpConnection *self); + +void tp_connection_set_self_presence (TpConnection *self, gchar *status, + gchar *status_message, GAsyncReadyCallback callback, gpointer user_data); + #define TP_CONNECTION_FEATURE_CORE \ (tp_connection_get_feature_quark_core ()) GQuark tp_connection_get_feature_quark_core (void) G_GNUC_CONST; @@ -175,6 +206,10 @@ GQuark tp_connection_get_feature_quark_capabilities (void) G_GNUC_CONST; (tp_connection_get_feature_quark_avatar_requirements ()) GQuark tp_connection_get_feature_quark_avatar_requirements (void) G_GNUC_CONST; +#define TP_CONNECTION_FEATURE_SELF_PRESENCE \ + (tp_connection_get_feature_quark_self_presence ()) +GQuark tp_connection_get_feature_quark_self_presence (void) G_GNUC_CONST; + /* connection-handles.c */ typedef void (*TpConnectionHoldHandlesCb) (TpConnection *connection, -- 1.6.6.1