From 931a82aa48e7d8cc5c3aa9cf3041c632e29435f5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 16 Apr 2012 16:33:46 +0100 Subject: [PATCH 02/14] tp_account_channel_request_new_text, tp_account_channel_request_set_target_contact, tp_account_channel_request_set_target_id: add Signed-off-by: Simon McVittie --- docs/reference/telepathy-glib-sections.txt | 3 + telepathy-glib/account-channel-request.c | 113 ++++++++++++++++++++++++++++ telepathy-glib/account-channel-request.h | 15 ++++ telepathy-glib/capabilities.c | 8 +- 4 files changed, 137 insertions(+), 2 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 1862663..f393351 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -6024,6 +6024,9 @@ tp_account_channel_request_new tp_account_channel_request_get_request tp_account_channel_request_get_user_action_time tp_account_channel_request_get_account +tp_account_channel_request_set_target_contact +tp_account_channel_request_set_target_id +tp_account_channel_request_new_text tp_account_channel_request_create_and_handle_channel_async tp_account_channel_request_create_and_handle_channel_finish tp_account_channel_request_ensure_and_handle_channel_async diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c index 4742b74..3c52472 100644 --- a/telepathy-glib/account-channel-request.c +++ b/telepathy-glib/account-channel-request.c @@ -79,6 +79,7 @@ #include #include #include +#include #include #include #include @@ -1718,3 +1719,115 @@ _tp_account_channel_request_get_client (TpAccountChannelRequest *self) return self->priv->handler; } + +/** + * tp_account_channel_request_set_target_contact: + * @self: a #TpAccountChannelRequest + * @contact: the contact to be contacted + * + * Configure this request to create a peer-to-peer channel with @contact as + * the other peer. + * + * This function can't be called once @self has been used to request a + * channel. + * + * Since: 0.19.UNRELEASED + */ +void +tp_account_channel_request_set_target_contact ( + TpAccountChannelRequest *self, + TpContact *contact) +{ + g_return_if_fail (TP_IS_ACCOUNT_CHANNEL_REQUEST (self)); + g_return_if_fail (TP_IS_CONTACT (contact)); + g_return_if_fail (!self->priv->requested); + + /* Do not use tp_asv_set_uint32 or similar - the key is dup'd */ + g_hash_table_insert (self->priv->request, + g_strdup (TP_PROP_CHANNEL_TARGET_HANDLE_TYPE), + tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT)); + /* We use the ID because it persists across a disconnect/reconnect */ + g_hash_table_insert (self->priv->request, + g_strdup (TP_PROP_CHANNEL_TARGET_ID), + tp_g_value_slice_new_string (tp_contact_get_identifier (contact))); +} + +/** + * tp_account_channel_request_set_target_id: + * @self: a #TpAccountChannelRequest + * @handle_type: the type of @identifier, typically %TP_HANDLE_TYPE_CONTACT + * or %TP_HANDLE_TYPE_ROOM + * @identifier: the unique identifier of the contact, room etc. to be + * contacted + * + * Configure this request to create a channel with @identifier, + * an identifier of type @handle_type. + * + * This function can't be called once @self has been used to request a + * channel. + * + * Since: 0.19.UNRELEASED + */ +void +tp_account_channel_request_set_target_id ( + TpAccountChannelRequest *self, + TpHandleType handle_type, + const gchar *identifier) +{ + g_return_if_fail (TP_IS_ACCOUNT_CHANNEL_REQUEST (self)); + g_return_if_fail (identifier != NULL); + g_return_if_fail (handle_type != TP_HANDLE_TYPE_NONE); + g_return_if_fail (!self->priv->requested); + + /* Do not use tp_asv_set_uint32 or similar - the key is dup'd */ + g_hash_table_insert (self->priv->request, + g_strdup (TP_PROP_CHANNEL_TARGET_HANDLE_TYPE), + tp_g_value_slice_new_uint (handle_type)); + g_hash_table_insert (self->priv->request, + g_strdup (TP_PROP_CHANNEL_TARGET_ID), + tp_g_value_slice_new_string (identifier)); +} + +/** + * tp_account_channel_request_new_text: + * @account: a #TpAccount + * @user_action_time: the time of the user action that caused this request, + * or one of the special values %TP_USER_ACTION_TIME_NOT_USER_ACTION or + * %TP_USER_ACTION_TIME_CURRENT_TIME (see + * #TpAccountChannelRequest:user-action-time) + * + * Convenience function to create a new #TpAccountChannelRequest object + * which will yield a Text channel. + * + * After creating the request, you will also need to set the "target" + * of the channel by calling one of the following functions: + * + * * tp_account_channel_request_set_target_contact() + * * tp_account_channel_request_set_target_id() + * + * Returns: a new #TpAccountChannelRequest object + * + * Since: 0.19.UNRELEASED + */ +TpAccountChannelRequest * +tp_account_channel_request_new_text ( + TpAccount *account, + gint64 user_action_time) +{ + TpAccountChannelRequest *self; + GHashTable *request; + + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + + request = tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, + NULL); + + self = g_object_new (TP_TYPE_ACCOUNT_CHANNEL_REQUEST, + "account", account, + "request", request, + "user-action-time", user_action_time, + NULL); + g_hash_table_unref (request); + return self; +} diff --git a/telepathy-glib/account-channel-request.h b/telepathy-glib/account-channel-request.h index b09679f..022c282 100644 --- a/telepathy-glib/account-channel-request.h +++ b/telepathy-glib/account-channel-request.h @@ -87,6 +87,21 @@ void tp_account_channel_request_set_delegate_to_preferred_handler ( TpAccountChannelRequest *self, gboolean delegate); +/* Text */ + +TpAccountChannelRequest *tp_account_channel_request_new_text ( + TpAccount *account, + gint64 user_action_time) G_GNUC_WARN_UNUSED_RESULT; + +/* Channel target (shared between all channel types) */ + +void tp_account_channel_request_set_target_contact ( + TpAccountChannelRequest *self, + TpContact *contact); +void tp_account_channel_request_set_target_id (TpAccountChannelRequest *self, + TpHandleType handle_type, + const gchar *identifier); + /* Request and handle API */ void tp_account_channel_request_create_and_handle_channel_async ( diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c index 66140b2..1536212 100644 --- a/telepathy-glib/capabilities.c +++ b/telepathy-glib/capabilities.c @@ -312,7 +312,9 @@ supports_simple_channel (TpCapabilities *self, * @self: a #TpCapabilities object * * Return whether private text channels can be established by providing - * a contact identifier. + * a contact identifier, for instance by calling + * tp_account_channel_request_new_text() followed by + * tp_account_channel_request_set_target_contact(). * * If the protocol is such that text chats can be established, but only via a * more elaborate D-Bus API than normal (because more information is needed), @@ -337,7 +339,9 @@ tp_capabilities_supports_text_chats (TpCapabilities *self) * * If the #TpCapabilities:contact-specific property is %FALSE, this function * checks if named text chatrooms can be joined by providing a chatroom - * identifier. + * identifier, for instance by calling + * tp_account_channel_request_new_text() followed by + * tp_account_channel_request_set_target_id() with %TP_HANDLE_TYPE_ROOM. * * If the #TpCapabilities:contact-specific property is %TRUE, this function * checks if the contact associated with this #TpCapabilities can be invited -- 1.7.10