From 198793efbb6ce097c98ee58022eea54ff1d605df Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sun, 5 Jun 2011 19:53:22 +0200 Subject: [PATCH] Add async wrapper for SetGroupMembers, AddToGroup, RemoveFromGroup, RemoveGroup and RenameGroup --- docs/reference/telepathy-glib-sections.txt | 11 + telepathy-glib/connection-contact-list.c | 277 ++++++++++++++++++++++++++++ telepathy-glib/connection-contact-list.h | 47 +++++ 3 files changed, 335 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 031248d..62fe619 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -3553,6 +3553,17 @@ 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 diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c index 38472b9..c7a886d 100644 --- a/telepathy-glib/connection-contact-list.c +++ b/telepathy-glib/connection-contact-list.c @@ -304,3 +304,280 @@ tp_connection_unpublish_finish (TpConnection *self, { generic_finish (unpublish); } + +#define contact_groups_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_GROUPS)); \ + 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_groups_call_##method (self, -1, \ + group, handles, generic_callback, result, g_object_unref, NULL); \ + g_array_unref (handles); \ + } G_STMT_END + +/** + * 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. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUP. + * + * 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. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUP. + * + * 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. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUP. + * + * 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. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_GROUP. + * + * 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)); + g_return_if_fail (tp_proxy_has_interface_by_id (self, + TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_GROUPS)); + + 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. + * + * For this to work properly @self must have interface + * %TP_IFACE_CONNECTION_INTERFACE_CONTACT_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)); + g_return_if_fail (tp_proxy_has_interface_by_id (self, + TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_GROUPS)); + + 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 index 1345cf0..74706da 100644 --- a/telepathy-glib/connection-contact-list.h +++ b/telepathy-glib/connection-contact-list.h @@ -72,6 +72,53 @@ 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 -- 1.7.4.1