diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index a04315c..6f26dd6 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -3093,10 +3093,14 @@ TP_CHANNEL_FEATURE_GROUP tp_channel_group_get_flags tp_channel_group_get_handle_owner tp_channel_group_get_self_handle -tp_channel_group_get_local_pending tp_channel_group_get_members +tp_channel_group_get_local_pending tp_channel_group_get_remote_pending tp_channel_group_get_local_pending_info +tp_channel_group_add_members_async +tp_channel_group_add_members_finish +tp_channel_group_remove_members_async +tp_channel_group_remove_members_finish TP_ERRORS_REMOVED_FROM_GROUP TP_CHANNEL_FEATURE_PASSWORD @@ -3539,6 +3543,28 @@ 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_connection_set_group_members_async +tp_connection_set_group_members_finish +tp_connection_add_to_group_async +tp_connection_add_to_group_finish +tp_connection_remove_from_group_async +tp_connection_remove_from_group_finish +tp_connection_remove_group_async +tp_connection_remove_group_finish +tp_connection_rename_group_async +tp_connection_rename_group_finish tp_cli_connection_callback_for_connect tp_cli_connection_call_connect @@ -4184,6 +4210,21 @@ tp_contact_get_contact_groups tp_contact_set_contact_groups_async tp_contact_set_contact_groups_finish tp_contact_has_feature + +tp_contact_request_subscription_async +tp_contact_request_subscription_finish +tp_contact_authorize_publication_async +tp_contact_authorize_publication_finish +tp_contact_remove_async +tp_contact_remove_finish +tp_contact_unsubscribe_async +tp_contact_unsubscribe_finish +tp_contact_unpublish_async +tp_contact_unpublish_finish +tp_contact_add_to_group_async +tp_contact_add_to_group_finish +tp_contact_remove_from_group_async +tp_contact_remove_from_group_finish tp_contact_feature_get_type tp_contact_get_type diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 54a42b8..4571516 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -47,11 +47,13 @@ our_headers = \ client-message.h \ cm-message.h \ connection.h \ + connection-contact-list.h \ connection-manager.h \ contact-search.h \ contact-search-result.h \ capabilities.h \ contact.h \ + contact-operations.h \ base-contact-list.h \ contacts-mixin.h \ dbus.h \ @@ -158,6 +160,7 @@ libtelepathy_glib_internal_la_SOURCES = \ capabilities.c \ capabilities-internal.h \ channel.c \ + channel-contacts.c \ channel-group.c \ channel-internal.h \ channel-dispatcher.c \ @@ -172,12 +175,14 @@ 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 \ contact.c \ contact-list-channel-internal.h \ contact-list-channel.c \ + contact-operations.c \ contact-search.c \ contact-search-internal.h \ contact-search-result.c \ diff --git a/telepathy-glib/channel-contacts.c b/telepathy-glib/channel-contacts.c new file mode 100644 index 0000000..0c99363 --- /dev/null +++ b/telepathy-glib/channel-contacts.c @@ -0,0 +1,145 @@ +/* + * channel.c - proxy for a Telepathy channel (contacts feature) + * + * Copyright (C) 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/channel-internal.h" + +#define DEBUG_FLAG TP_DEBUG_GROUPS +#include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/util-internal.h" + +static void +generic_callback (TpChannel *self, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + g_simple_async_result_set_from_error (result, error); + g_simple_async_result_complete (result); +} + +/** + * tp_channel_group_add_members_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 + * invite to the channel. + * @message: A string message, which can be blank if desired. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Invite all the given @contacts into the channel, or accept requests for + * channel membership for @contacts on the pending local list. + * + * Since: 0.UNRELEASED + */ +void +tp_channel_group_add_members_async (TpChannel *self, + guint n_contacts, + TpContact * const *contacts, + const gchar *message, + GAsyncReadyCallback callback, + gpointer user_data) +{ + _tp_implement_async_contacts_begin (self->priv->connection, + tp_channel_group_add_members_async); + + tp_cli_channel_interface_group_call_add_members (self, -1, handles, message, + generic_callback, result, g_object_unref, NULL); + + g_array_unref (handles); +} + +/** + * tp_channel_group_add_members_finish: + * @self: a #TpChannel + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_channel_group_remove_members_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_channel_group_add_members_finish (TpChannel *self, + GAsyncResult *result, + GError **error) +{ + _tp_implement_finish_void (self, tp_channel_group_add_members_async); +} + +/** + * tp_channel_group_remove_members_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 from the channel. + * @message: A string message, which can be blank if desired. + * @reason: A reason for the change. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Requests the removal of @contacts from a channel, reject their request for + * channel membership on the pending local list, or rescind their invitation on + * the pending remote list. + * + * Since: 0.UNRELEASED + */ +void +tp_channel_group_remove_members_async (TpChannel *self, + guint n_contacts, + TpContact * const *contacts, + const gchar *message, + TpChannelGroupChangeReason reason, + GAsyncReadyCallback callback, + gpointer user_data) +{ + _tp_implement_async_contacts_begin (self->priv->connection, + tp_channel_group_add_members_async); + + tp_cli_channel_interface_group_call_add_members (self, -1, handles, message, + generic_callback, result, g_object_unref, NULL); + + g_array_unref (handles); +} + +/** + * tp_channel_group_remove_members_finish: + * @self: a #TpChannel + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_channel_group_remove_members_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_channel_group_remove_members_finish (TpChannel *self, + GAsyncResult *result, + GError **error) +{ + _tp_implement_finish_void (self, tp_channel_group_remove_members_async); +} diff --git a/telepathy-glib/channel.h b/telepathy-glib/channel.h index bde5cd1..1f3588b 100644 --- a/telepathy-glib/channel.h +++ b/telepathy-glib/channel.h @@ -23,6 +23,7 @@ #define __TP_CHANNEL_H__ #include +#include #include #include #include @@ -128,6 +129,19 @@ GQuark tp_channel_get_feature_quark_core (void) G_GNUC_CONST; tp_channel_get_feature_quark_group () GQuark tp_channel_get_feature_quark_group (void) G_GNUC_CONST; +void tp_channel_group_add_members_async (TpChannel *self, + guint n_contacts, TpContact * const *contacts, const gchar *message, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_channel_group_add_members_finish (TpChannel *self, + GAsyncResult *result, GError **error); + +void tp_channel_group_remove_members_async (TpChannel *self, + guint n_contacts, TpContact * const *contacts, const gchar *message, + TpChannelGroupChangeReason reason, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_channel_group_remove_members_finish (TpChannel *self, + GAsyncResult *result, GError **error); + #define TP_CHANNEL_FEATURE_CHAT_STATES \ tp_channel_get_feature_quark_chat_states () GQuark tp_channel_get_feature_quark_chat_states (void) G_GNUC_CONST; diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c new file mode 100644 index 0000000..5f7f410 --- /dev/null +++ b/telepathy-glib/connection-contact-list.c @@ -0,0 +1,495 @@ +/* + * 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" + +#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) + g_simple_async_result_set_from_error (result, error); + g_simple_async_result_complete (result); +} + +#define contact_list_generic_async(method, ...) \ + _tp_implement_async_contacts_begin (self, 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); + +#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. + * + * 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. + * + * 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. + * + * 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. + * + * 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. + * + * 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); +} + +#define contact_groups_generic_async(method) \ + _tp_implement_async_contacts_begin (self, tp_connection_##method##_async) \ + tp_cli_connection_interface_contact_groups_call_##method (self, -1, \ + group, handles, generic_callback, result, g_object_unref, NULL); \ + g_array_unref (handles); + +/** + * tp_connection_set_group_members_async: + * @self: a #TpConnection + * @group: the group to alter. + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects members + * for the group. If this set is empty, this method MAY remove the group. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Add the given @contacts to the given @group (creating it if necessary), and + * remove all other members. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_set_group_members_async (TpConnection *self, + const gchar *group, guint n_contacts, TpContact * const *contacts, + GAsyncReadyCallback callback, gpointer user_data) +{ + contact_groups_generic_async (set_group_members) +} + +/** + * tp_connection_set_group_members_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_set_group_members_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_set_group_members_finish (TpConnection *self, + GAsyncResult *result, GError **error) +{ + generic_finish (set_group_members); +} + +/** + * tp_connection_add_to_group_async: + * @self: a #TpConnection + * @group: the group to alter. + * @n_contacts: The number of contacts in @contacts (must be at least 1) + * @contacts: (array length=n_contacts): An array of #TpContact objects to + * include in the group. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Add the given @contacts to the given @group, creating it if necessary. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_add_to_group_async (TpConnection *self, + const gchar *group, guint n_contacts, TpContact * const *contacts, + GAsyncReadyCallback callback, gpointer user_data) +{ + contact_groups_generic_async (add_to_group) +} + +/** + * tp_connection_add_to_group_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_add_to_group_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_add_to_group_finish (TpConnection *self, + GAsyncResult *result, GError **error) +{ + generic_finish (add_to_group); +} + +/** + * tp_connection_remove_from_group_async: + * @self: a #TpConnection + * @group: the group to alter. + * @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 from the group. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Remove the given @contacts from the given @group. If there are no members + * left in the group afterwards, the group MAY itself be removed. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_remove_from_group_async (TpConnection *self, + const gchar *group, guint n_contacts, TpContact * const *contacts, + GAsyncReadyCallback callback, gpointer user_data) +{ + contact_groups_generic_async (remove_from_group) +} + +/** + * tp_connection_remove_from_group_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_remove_from_group_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_remove_from_group_finish (TpConnection *self, + GAsyncResult *result, GError **error) +{ + generic_finish (remove_from_group); +} + +/** + * tp_connection_remove_group_async: + * @self: a #TpConnection + * @group: the group to remove. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Remove all members from the given group, then remove the group itself. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_remove_group_async (TpConnection *self, + const gchar *group, GAsyncReadyCallback callback, gpointer user_data) +{ + GSimpleAsyncResult *result; + + g_return_if_fail (TP_IS_CONNECTION (self)); + + result = g_simple_async_result_new ((GObject *) self, callback, user_data, + tp_connection_remove_group_async); + + tp_cli_connection_interface_contact_groups_call_remove_group (self, -1, \ + group, generic_callback, result, g_object_unref, NULL); +} + +/** + * tp_connection_remove_group_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_remove_group_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_remove_group_finish (TpConnection *self, + GAsyncResult *result, GError **error) +{ + generic_finish (remove_group); +} + +/** + * tp_connection_rename_group_async: + * @self: a #TpConnection + * @old_name: the group to rename + * @new_name: the new name for the group + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Rename the given @old_name. + * + * On protocols where groups behave like tags, this is an API short-cut for + * adding all of the group's members to a group with the new name, then removing + * the old group. + * + * Since: 0.UNRELEASED + */ +void +tp_connection_rename_group_async (TpConnection *self, + const gchar *old_name, const gchar *new_name, + GAsyncReadyCallback callback, gpointer user_data) +{ + GSimpleAsyncResult *result; + + g_return_if_fail (TP_IS_CONNECTION (self)); + + result = g_simple_async_result_new ((GObject *) self, callback, user_data, + tp_connection_rename_group_async); + + tp_cli_connection_interface_contact_groups_call_rename_group (self, -1, \ + old_name, new_name, generic_callback, result, g_object_unref, NULL); +} + +/** + * tp_connection_rename_group_finish: + * @self: a #TpConnection + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_connection_rename_group_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_connection_rename_group_finish (TpConnection *self, + GAsyncResult *result, GError **error) +{ + generic_finish (rename_group); +} diff --git a/telepathy-glib/connection-contact-list.h b/telepathy-glib/connection-contact-list.h new file mode 100644 index 0000000..61592b3 --- /dev/null +++ b/telepathy-glib/connection-contact-list.h @@ -0,0 +1,90 @@ +/* + * 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); + +void tp_connection_set_group_members_async (TpConnection *self, + const gchar *group, guint n_contacts, TpContact * const *contacts, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_connection_set_group_members_finish (TpConnection *self, + GAsyncResult *result, GError **error); + +void tp_connection_add_to_group_async (TpConnection *self, + const gchar *group, guint n_contacts, TpContact * const *contacts, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_connection_add_to_group_finish (TpConnection *self, + GAsyncResult *result, GError **error); + +void tp_connection_remove_from_group_async (TpConnection *self, + const gchar *group, guint n_contacts, TpContact * const *contacts, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_connection_remove_from_group_finish (TpConnection *self, + GAsyncResult *result, GError **error); + +void tp_connection_remove_group_async (TpConnection *self, + const gchar *group, GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_connection_remove_group_finish (TpConnection *self, + GAsyncResult *result, GError **error); + +void tp_connection_rename_group_async (TpConnection *self, + const gchar *old_name, const gchar *new_name, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_connection_rename_group_finish (TpConnection *self, + GAsyncResult *result, GError **error); + +G_END_DECLS + +#endif diff --git a/telepathy-glib/contact-operations.c b/telepathy-glib/contact-operations.c new file mode 100644 index 0000000..8b85f69 --- /dev/null +++ b/telepathy-glib/contact-operations.c @@ -0,0 +1,318 @@ +/* Async operations for TpContact + * + * Copyright (C) 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 + +#include + +#define DEBUG_FLAG TP_DEBUG_CONTACTS +#include "telepathy-glib/debug-internal.h" + +/** + * tp_contact_request_subscription_async: + * @self: a #TpContact + * @message: an optional message + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_request_subscription_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_request_subscription_async (TpContact *self, + const gchar *message, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_request_subscription_async (tp_contact_get_connection (self), + 1, &self, message, callback, user_data); +} + +/** + * tp_contact_request_subscription_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_request_subscription_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_request_subscription_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_request_subscription_finish ( + tp_contact_get_connection (self), result, error); +} + +/** + * tp_contact_authorize_publication_async: + * @self: a #TpContact + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_authorize_publication_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_authorize_publication_async (TpContact *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_authorize_publication_async (tp_contact_get_connection (self), + 1, &self, callback, user_data); +} + +/** + * tp_contact_authorize_publication_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_authorize_publication_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_authorize_publication_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_authorize_publication_finish ( + tp_contact_get_connection (self), result, error); +} + +/** + * tp_contact_remove_async: + * @self: a #TpContact + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_remove_contacts_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_remove_async (TpContact *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_remove_contacts_async (tp_contact_get_connection (self), + 1, &self, callback, user_data); +} + +/** + * tp_contact_remove_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_remove_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_remove_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_remove_contacts_finish ( + tp_contact_get_connection (self), result, error); +} + +/** + * tp_contact_unsubscribe_async: + * @self: a #TpContact + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_unsubscribe_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_unsubscribe_async (TpContact *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_unsubscribe_async (tp_contact_get_connection (self), + 1, &self, callback, user_data); +} + +/** + * tp_contact_unsubscribe_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_unsubscribe_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_unsubscribe_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_unsubscribe_finish ( + tp_contact_get_connection (self), result, error); +} + +/** + * tp_contact_unpublish_async: + * @self: a #TpContact + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_unpublish_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_unpublish_async (TpContact *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_unpublish_async (tp_contact_get_connection (self), + 1, &self, callback, user_data); +} + +/** + * tp_contact_unpublish_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_unpublish_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_unpublish_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_unpublish_finish ( + tp_contact_get_connection (self), result, error); +} + +/** + * tp_contact_add_to_group_async: + * @self: a #TpContact + * @group: the group to alter. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_add_to_group_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_add_to_group_async (TpContact *self, + const gchar *group, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_add_to_group_async (tp_contact_get_connection (self), + group, 1, &self, callback, user_data); +} + +/** + * tp_contact_add_to_group_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_add_to_group_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_add_to_group_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_add_to_group_finish ( + tp_contact_get_connection (self), result, error); +} + +/** + * tp_contact_remove_from_group_async: + * @self: a #TpContact + * @group: the group to alter. + * @callback: a callback to call when the operation finishes + * @user_data: data to pass to @callback + * + * Convenient wrapper for tp_connection_remove_from_group_async() on single + * contact. + * + * Since: 0.UNRELEASED + */ +void +tp_contact_remove_from_group_async (TpContact *self, + const gchar *group, + GAsyncReadyCallback callback, + gpointer user_data) +{ + tp_connection_remove_from_group_async (tp_contact_get_connection (self), + group, 1, &self, callback, user_data); +} + +/** + * tp_contact_remove_from_group_finish: + * @self: a #TpContact + * @result: a #GAsyncResult + * @error: a #GError to fill + * + * Finishes tp_contact_remove_from_group_async() + * + * Returns: %FALSE if the operation failed, %TRUE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_contact_remove_from_group_finish (TpContact *self, + GAsyncResult *result, + GError **error) +{ + return tp_connection_remove_from_group_finish ( + tp_contact_get_connection (self), result, error); +} diff --git a/telepathy-glib/contact-operations.h b/telepathy-glib/contact-operations.h new file mode 100644 index 0000000..09fb1bd --- /dev/null +++ b/telepathy-glib/contact-operations.h @@ -0,0 +1,64 @@ +/* Async operations for TpContact + * + * Copyright (C) 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_CONTACT_OPERATIONS_H__ +#define __TP_CONTACT_OPERATIONS_H__ + +#include + +G_BEGIN_DECLS + +void tp_contact_request_subscription_async (TpContact *self, + const gchar *message, GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_request_subscription_finish (TpContact *self, + GAsyncResult *result, GError **error); + +void tp_contact_authorize_publication_async (TpContact *self, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_authorize_publication_finish (TpContact *self, + GAsyncResult *result, GError **error); + +void tp_contact_remove_async (TpContact *self, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_remove_finish (TpContact *self, + GAsyncResult *result, GError **error); + +void tp_contact_unsubscribe_async (TpContact *self, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_unsubscribe_finish (TpContact *self, + GAsyncResult *result, GError **error); + +void tp_contact_unpublish_async (TpContact *self, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_unpublish_finish (TpContact *self, + GAsyncResult *result, GError **error); + +void tp_contact_add_to_group_async (TpContact *self, + const gchar *group, GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_add_to_group_finish (TpContact *self, + GAsyncResult *result, GError **error); + +void tp_contact_remove_from_group_async (TpContact *self, + const gchar *group, GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_contact_remove_from_group_finish (TpContact *self, + GAsyncResult *result, GError **error); + +G_END_DECLS + +#endif diff --git a/telepathy-glib/introspection.am b/telepathy-glib/introspection.am index f75e158..a1e70c6 100644 --- a/telepathy-glib/introspection.am +++ b/telepathy-glib/introspection.am @@ -16,11 +16,13 @@ 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 \ $(srcdir)/connection-manager.c $(srcdir)/connection-manager.h \ $(srcdir)/channel.c $(srcdir)/channel.h \ + $(srcdir)/channel-contacts.c \ $(srcdir)/channel-group.c \ $(srcdir)/handle.c $(srcdir)/handle.h \ $(srcdir)/handle-channels-context.c $(srcdir)/handle-channels-context.h \ @@ -30,6 +32,7 @@ INTROSPECTION_FILES = \ $(srcdir)/dbus.c $(srcdir)/dbus.h \ $(srcdir)/capabilities.c $(srcdir)/capabilities.h \ $(srcdir)/contact.c $(srcdir)/contact.h \ + $(srcdir)/contact-operations.c $(srcdir)/contact-operations.h \ $(srcdir)/contact-search.c $(srcdir)/contact-search.h \ $(srcdir)/contact-search-result.c $(srcdir)/contact-search-result.h \ $(srcdir)/defs.h \ diff --git a/telepathy-glib/util-internal.h b/telepathy-glib/util-internal.h index f3bd5a1..b7b2a7b 100644 --- a/telepathy-glib/util-internal.h +++ b/telepathy-glib/util-internal.h @@ -39,6 +39,28 @@ GSocketAddress * _tp_create_temp_unix_socket (GSocketService *service, GList * _tp_create_channel_request_list (TpDBusDaemon *dbus, GHashTable *request_props); +#define _tp_implement_async_contacts_begin(connection, tag) \ + GSimpleAsyncResult *result; \ + GArray *handles; \ + guint i; \ +\ + handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), n_contacts); \ +\ + for (i = 0; i < n_contacts; i++) \ + { \ + TpHandle handle; \ +\ + g_return_if_fail (TP_IS_CONTACT (contacts[i])); \ + g_return_if_fail (tp_contact_get_connection (contacts[i]) == \ + connection); \ +\ + handle = tp_contact_get_handle (contacts[i]); \ + g_array_append_val (handles, handle); \ + } \ +\ + result = g_simple_async_result_new ((GObject *) self, callback, user_data, \ + tag); + /* Copied from wocky/wocky-utils.h */ #define _tp_implement_finish_void(source, tag) \ diff --git a/tests/dbus/channel-request.c b/tests/dbus/channel-request.c index cc121e3..a56ecca 100644 --- a/tests/dbus/channel-request.c +++ b/tests/dbus/channel-request.c @@ -348,7 +348,7 @@ test_properties (Test *test, props = tp_asv_new ( TP_PROP_CHANNEL_REQUEST_ACCOUNT, DBUS_TYPE_G_OBJECT_PATH, ACCOUNT_PATH, - TP_PROP_CHANNEL_REQUEST_USER_ACTION_TIME, G_TYPE_INT64, 12345, + TP_PROP_CHANNEL_REQUEST_USER_ACTION_TIME, G_TYPE_INT64, (gint64) 12345, TP_PROP_CHANNEL_REQUEST_PREFERRED_HANDLER, G_TYPE_STRING, "Badger", TP_PROP_CHANNEL_REQUEST_HINTS, TP_HASH_TYPE_STRING_VARIANT_MAP, hints, NULL);