From 65b574550542f6cc27d488908e308d60a0051c6b Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 27 Apr 2012 14:32:10 +0200 Subject: [PATCH] Move ChatState to TpTextChannel API on TpChannel is now deprecated but still used to implement the corresponding API on TpTextChannel. https://bugs.freedesktop.org/show_bug.cgi?id=49215 --- telepathy-glib/automatic-client-factory.c | 10 +++--- telepathy-glib/channel.c | 2 ++ telepathy-glib/channel.h | 2 +- telepathy-glib/text-channel.c | 54 +++++++++++++++++++++++++++++ telepathy-glib/text-channel.h | 6 ++++ 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/telepathy-glib/automatic-client-factory.c b/telepathy-glib/automatic-client-factory.c index b2cc10a..d8eab57 100644 --- a/telepathy-glib/automatic-client-factory.c +++ b/telepathy-glib/automatic-client-factory.c @@ -70,8 +70,9 @@ * type of channels. * * - * %TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES and - * %TP_TEXT_CHANNEL_FEATURE_SMS for #TpTextChannel + * %TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, + * %TP_TEXT_CHANNEL_FEATURE_SMS and %TP_TEXT_CHANNEL_FEATURE_CHAT_STATES + * for #TpTextChannel * * * %TP_FILE_TRANSFER_CHANNEL_FEATURE_CORE @@ -140,8 +141,8 @@ typedef struct { GType gtype; CheckPropertiesFunc check_properties; NewFunc new_func; - /* 0-terminated. All of a sudden, 3 is not such a scary number. */ - GQuark features[3]; + /* 0-terminated. All of a sudden, 4 is not such a scary number. */ + GQuark features[4]; } ChannelTypeMapping; static ChannelTypeMapping *channel_type_mapping = NULL; @@ -188,6 +189,7 @@ build_channel_type_mapping (void) (NewFunc) _tp_text_channel_new_with_factory, { TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, TP_TEXT_CHANNEL_FEATURE_SMS, + TP_TEXT_CHANNEL_FEATURE_CHAT_STATES, 0 }, }, { TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c index 41f016a..362da90 100644 --- a/telepathy-glib/channel.c +++ b/telepathy-glib/channel.c @@ -227,6 +227,7 @@ tp_channel_get_feature_quark_contacts (void) * tp_proxy_prepare_async() function, and waiting for it to callback. * * Since: 0.11.3 + * Deprecated: Use TP_TEXT_CHANNEL_FEATURE_CHAT_STATES instead. */ GQuark @@ -516,6 +517,7 @@ tp_channel_get_property (GObject *object, * Returns: the chat state for @contact, or %TP_CHANNEL_CHAT_STATE_INACTIVE * if their chat state is not known * Since: 0.11.3 + * Deprecated: Use tp_text_channel_get_chat_state() instead. */ TpChannelChatState tp_channel_get_chat_state (TpChannel *self, diff --git a/telepathy-glib/channel.h b/telepathy-glib/channel.h index cf31db6..f66528b 100644 --- a/telepathy-glib/channel.h +++ b/telepathy-glib/channel.h @@ -159,7 +159,7 @@ TpContact *tp_channel_group_get_contact_owner (TpChannel *self, tp_channel_get_feature_quark_chat_states () GQuark tp_channel_get_feature_quark_chat_states (void) G_GNUC_CONST; TpChannelChatState tp_channel_get_chat_state (TpChannel *self, - TpHandle contact); + TpHandle contact) _TP_GNUC_DEPRECATED_FOR (tp_text_channel_get_chat_state); void tp_channel_join_async (TpChannel *self, const gchar *message, diff --git a/telepathy-glib/text-channel.c b/telepathy-glib/text-channel.c index e56664b..d11514a 100644 --- a/telepathy-glib/text-channel.c +++ b/telepathy-glib/text-channel.c @@ -802,6 +802,7 @@ tp_text_channel_prepare_sms_async (TpProxy *proxy, enum { FEAT_PENDING_MESSAGES, FEAT_SMS, + FEAT_CHAT_STATES, N_FEAT }; @@ -810,6 +811,7 @@ tp_text_channel_list_features (TpProxyClass *cls G_GNUC_UNUSED) { static TpProxyFeature features[N_FEAT + 1] = { { 0 } }; static GQuark need_sms[2] = {0, 0}; + static GQuark depends_chat_state[2] = {0, 0}; if (G_LIKELY (features[0].name != 0)) return features; @@ -826,6 +828,11 @@ tp_text_channel_list_features (TpProxyClass *cls G_GNUC_UNUSED) need_sms[0] = TP_IFACE_QUARK_CHANNEL_INTERFACE_SMS; features[FEAT_SMS].interfaces_needed = need_sms; + features[FEAT_CHAT_STATES].name = + TP_TEXT_CHANNEL_FEATURE_CHAT_STATES; + depends_chat_state[0] = TP_CHANNEL_FEATURE_CHAT_STATES; + features[FEAT_CHAT_STATES].depends_on = depends_chat_state; + /* assert that the terminator at the end is there */ g_assert (features[N_FEAT].name == 0); @@ -1494,6 +1501,53 @@ tp_text_channel_ack_message_finish (TpTextChannel *self, _tp_implement_finish_void (self, tp_text_channel_ack_message_async) } +/** + * TP_TEXT_CHANNEL_FEATURE_CHAT_STATES: + * + * Expands to a call to a function that returns a quark representing the + * chat states feature on a #TpTextChannel. + * + * When this feature is prepared, tp_text_channel_get_chat_state() and the + * #TpChannel::chat-state-changed signal become useful. + * + * One can ask for a feature to be prepared using the + * tp_proxy_prepare_async() function, and waiting for it to callback. + * + * Since: 0.UNRELEASED + */ + +GQuark +tp_text_channel_get_feature_quark_chat_states (void) +{ + return g_quark_from_static_string ("tp-text-channel-feature-chat-states"); +} + +/** + * tp_text_channel_get_chat_state: + * @self: a channel + * @contact: a #TpContact + * + * Return the chat state for the given contact. If tp_proxy_is_prepared() + * would return %FALSE for the feature %TP_TEXT_CHANNEL_FEATURE_CHAT_STATES, + * the result will always be %TP_CHANNEL_CHAT_STATE_INACTIVE. + * + * Returns: the chat state for @contact, or %TP_CHANNEL_CHAT_STATE_INACTIVE + * if their chat state is not known + * Since: 0.UNRELEASED + */ +TpChannelChatState +tp_text_channel_get_chat_state (TpTextChannel *self, + TpContact *contact) +{ + g_return_val_if_fail (TP_IS_TEXT_CHANNEL (self), 0); + + /* Use the deprecated function internally to avoid duplicated introspection */ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + return tp_channel_get_chat_state ((TpChannel *) self, + tp_contact_get_handle (contact)); + G_GNUC_END_IGNORE_DEPRECATIONS +} + static void set_chat_state_cb (TpChannel *proxy, const GError *error, diff --git a/telepathy-glib/text-channel.h b/telepathy-glib/text-channel.h index 4d9fec5..62f6588 100644 --- a/telepathy-glib/text-channel.h +++ b/telepathy-glib/text-channel.h @@ -118,6 +118,12 @@ gboolean tp_text_channel_ack_all_pending_messages_finish (TpTextChannel *self, GAsyncResult *result, GError **error); +#define TP_TEXT_CHANNEL_FEATURE_CHAT_STATES \ + tp_text_channel_get_feature_quark_chat_states () +GQuark tp_text_channel_get_feature_quark_chat_states (void) G_GNUC_CONST; +TpChannelChatState tp_text_channel_get_chat_state (TpTextChannel *self, + TpContact *contact); + void tp_text_channel_set_chat_state_async (TpTextChannel *self, TpChannelChatState state, GAsyncReadyCallback callback, -- 1.7.9.5