From f57e9587bbd46a7d483f1675c9aa749ce029dfd2 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sat, 4 Jun 2011 17:49:54 +0200 Subject: [PATCH] Add async wrapper for RequestSubscription, AuthorizePublication, RemoveContacts, Unsubscribe and Unpublish --- docs/reference/telepathy-glib-sections.txt | 11 + telepathy-glib/Makefile.am | 2 + telepathy-glib/connection-contact-list.c | 306 ++++++++++++++++++++++++++++ telepathy-glib/connection-contact-list.h | 77 +++++++ telepathy-glib/introspection.am | 1 + telepathy-glib/telepathy-glib.h | 1 + 6 files changed, 398 insertions(+), 0 deletions(-) create mode 100644 telepathy-glib/connection-contact-list.c create mode 100644 telepathy-glib/connection-contact-list.h diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index d3e8757..031248d 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -3542,6 +3542,17 @@ tp_contact_info_field_free TP_TYPE_CONTACT_INFO_LIST tp_contact_info_list_copy tp_contact_info_list_free + +tp_connection_request_subscription_async +tp_connection_request_subscription_finish +tp_connection_authorize_publication_async +tp_connection_authorize_publication_finish +tp_connection_remove_contacts_async +tp_connection_remove_contacts_finish +tp_connection_unsubscribe_async +tp_connection_unsubscribe_finish +tp_connection_unpublish_async +tp_connection_unpublish_finish tp_cli_connection_callback_for_connect tp_cli_connection_call_connect diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 987371f..6034646 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -47,6 +47,7 @@ our_headers = \ client-message.h \ cm-message.h \ connection.h \ + connection-contact-list.h \ connection-manager.h \ contact-search.h \ contact-search-result.h \ @@ -174,6 +175,7 @@ libtelepathy_glib_internal_la_SOURCES = \ connection.c \ connection-avatars.c \ connection-contact-info.c \ + connection-contact-list.c \ connection-internal.h \ connection-handles.c \ connection-manager.c \ diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c new file mode 100644 index 0000000..38472b9 --- /dev/null +++ b/telepathy-glib/connection-contact-list.c @@ -0,0 +1,306 @@ +/* + * Proxy for a Telepathy connection - ContactList support + * + * Copyright © 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "telepathy-glib/connection-contact-list.h" +#include + +#define DEBUG_FLAG TP_DEBUG_CONNECTION +#include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/util-internal.h" + +static void +generic_callback (TpConnection *self, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + { + DEBUG ("Operation failed: %s", error->message); + g_simple_async_result_set_from_error (result, error); + } + g_simple_async_result_complete (result); +} + +#define contact_list_generic_async(method, ...) \ + G_STMT_START { \ + GSimpleAsyncResult *result; \ + GArray *handles; \ + \ + g_return_if_fail (TP_IS_CONNECTION (self)); \ + g_return_if_fail (tp_proxy_has_interface_by_id (self, \ + TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_LIST)); \ + g_return_if_fail (_tp_contacts_to_handles (self, n_contacts, contacts, \ + &handles)); \ + \ + result = g_simple_async_result_new ((GObject *) self, callback, user_data, \ + tp_connection_##method##_async); \ + \ + tp_cli_connection_interface_contact_list_call_##method (self, -1, \ + handles, ##__VA_ARGS__, generic_callback, result, g_object_unref, NULL); \ + g_array_unref (handles); \ + } G_STMT_END + +#define generic_finish(method) \ + _tp_implement_finish_void (self, tp_connection_##method##_async); + +/** + * tp_connection_request_subscription_async: + * @self: a #TpConnection + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects to whom + * requests are to be sent. + * @message: an optional plain-text message from the user, to send to those + * @contacts with the subscription request. The + * #TpConnection:request-uses-message property indicates whether this message + * will be used or ignored + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Request that the given @contacts allow the local user to subscribe to their + * presence, i.e. that their #TpContact:subscribe-state property becomes + * %TP_SUBSCRIPTION_STATE_YES. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_request_subscription_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + const gchar *message, + GAsyncReadyCallback callback, + gpointer user_data) +{ + contact_list_generic_async (request_subscription, message); +} + +/** + * tp_connection_request_subscription_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_request_subscription_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_request_subscription_finish (TpConnection *self, + GAsyncResult *result, + GError **error) +{ + generic_finish (request_subscription); +} + +/** + * tp_connection_authorize_publication_async: + * @self: a #TpConnection + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects to + * authorize + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * For each of the given @contacts, request that the local user's presence is + * sent to that contact, i.e. that their #TpContact:publish-state property + * becomes %TP_SUBSCRIPTION_STATE_YES. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_authorize_publication_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data) +{ + contact_list_generic_async (authorize_publication); +} + +/** + * tp_connection_authorize_publication_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_authorize_publication_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_authorize_publication_finish (TpConnection *self, + GAsyncResult *result, + GError **error) +{ + generic_finish (authorize_publication); +} + +/** + * tp_connection_remove_contacts_async: + * @self: a #TpConnection + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects to + * remove + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Remove the given @contacts from the contact list entirely. It is + * protocol-dependent whether this works, and under which circumstances. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_remove_contacts_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data) +{ + contact_list_generic_async (remove_contacts); +} + +/** + * tp_connection_remove_contacts_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_remove_contacts_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_remove_contacts_finish (TpConnection *self, + GAsyncResult *result, + GError **error) +{ + generic_finish (remove_contacts); +} + +/** + * tp_connection_unsubscribe_async: + * @self: a #TpConnection + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects to + * remove + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Attempt to set the given @contacts' #TpContact:subscribe-state property to + * %TP_SUBSCRIPTION_STATE_NO, i.e. stop receiving their presence. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_unsubscribe_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data) +{ + contact_list_generic_async (unsubscribe); +} + +/** + * tp_connection_unsubscribe_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_unsubscribe_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_unsubscribe_finish (TpConnection *self, + GAsyncResult *result, + GError **error) +{ + generic_finish (unsubscribe); +} + +/** + * tp_connection_unpublish_async: + * @self: a #TpConnection + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects to + * remove + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Attempt to set the given @contacts' #TpContact:publish-state property to + * %TP_SUBSCRIPTION_STATE_NO, i.e. stop sending presence to them. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_unpublish_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data) +{ + contact_list_generic_async (unpublish); +} + +/** + * tp_connection_unpublish_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_unpublish_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_unpublish_finish (TpConnection *self, + GAsyncResult *result, + GError **error) +{ + generic_finish (unpublish); +} diff --git a/telepathy-glib/connection-contact-list.h b/telepathy-glib/connection-contact-list.h new file mode 100644 index 0000000..1345cf0 --- /dev/null +++ b/telepathy-glib/connection-contact-list.h @@ -0,0 +1,77 @@ +/* + * connection.h - proxy for a Telepathy connection + * + * Copyright © 2011 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __TP_CONNECTION_CONTACT_LIST_H__ +#define __TP_CONNECTION_CONTACT_LIST_H__ + +#include +#include + +G_BEGIN_DECLS + +void tp_connection_request_subscription_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + const gchar *message, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean tp_connection_request_subscription_finish (TpConnection *self, + GAsyncResult *result, + GError **error); + +void tp_connection_authorize_publication_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean tp_connection_authorize_publication_finish (TpConnection *self, + GAsyncResult *result, + GError **error); + +void tp_connection_remove_contacts_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean tp_connection_remove_contacts_finish (TpConnection *self, + GAsyncResult *result, + GError **error); + +void tp_connection_unsubscribe_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean tp_connection_unsubscribe_finish (TpConnection *self, + GAsyncResult *result, + GError **error); + +void tp_connection_unpublish_async (TpConnection *self, + guint n_contacts, + TpContact * const *contacts, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean tp_connection_unpublish_finish (TpConnection *self, + GAsyncResult *result, + GError **error); + +G_END_DECLS + +#endif diff --git a/telepathy-glib/introspection.am b/telepathy-glib/introspection.am index 0f96114..c574481 100644 --- a/telepathy-glib/introspection.am +++ b/telepathy-glib/introspection.am @@ -16,6 +16,7 @@ INTROSPECTION_FILES = \ $(srcdir)/basic-proxy-factory.c $(srcdir)/basic-proxy-factory.h \ $(srcdir)/client-channel-factory.c $(srcdir)/client-channel-factory.h \ $(srcdir)/connection.c $(srcdir)/connection.h \ + $(srcdir)/connection-contact-list.c $(srcdir)/connection-contact-list.h \ $(srcdir)/connection-handles.c $(srcdir)/connection-contact-info.c \ $(srcdir)/connection-avatars.c \ $(srcdir)/protocol.c $(srcdir)/protocol.h \ diff --git a/telepathy-glib/telepathy-glib.h b/telepathy-glib/telepathy-glib.h index a1d50db..46518f5 100644 --- a/telepathy-glib/telepathy-glib.h +++ b/telepathy-glib/telepathy-glib.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include -- 1.7.4.1