summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2012-05-15 16:12:14 +0200
committerXavier Claessens <xavier.claessens@collabora.co.uk>2012-05-16 12:03:15 +0200
commit5783bcb85fce37e06851fe370a54e3d91857a426 (patch)
treec18522f522dc855ae2f348e50a489090fd72ca51
parent3103f894f39be73f755d999e91ef43d7f3488a6f (diff)
downloadtelepathy-glib-5783bcb85fce37e06851fe370a54e3d91857a426.tar.gz
Add tp_simple_client_factory_upgrade_contacts_async/finish
Use it everywhere we can
-rw-r--r--docs/reference/telepathy-glib-sections.txt2
-rw-r--r--telepathy-glib/connection-contact-list.c37
-rw-r--r--telepathy-glib/simple-client-factory.c89
-rw-r--r--telepathy-glib/simple-client-factory.h14
4 files changed, 119 insertions, 23 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 9c5ef18b1..302c50821 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -6991,6 +6991,8 @@ tp_simple_client_factory_add_channel_features
tp_simple_client_factory_add_channel_features_varargs
<SUBSECTION>
tp_simple_client_factory_ensure_contact
+tp_simple_client_factory_upgrade_contacts_async
+tp_simple_client_factory_upgrade_contacts_finish
tp_simple_client_factory_ensure_contact_by_id_async
tp_simple_client_factory_ensure_contact_by_id_finish
tp_simple_client_factory_dup_contact_features
diff --git a/telepathy-glib/connection-contact-list.c b/telepathy-glib/connection-contact-list.c
index 2e6d597bd..d48a4814e 100644
--- a/telepathy-glib/connection-contact-list.c
+++ b/telepathy-glib/connection-contact-list.c
@@ -138,10 +138,12 @@ new_contacts_upgraded_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- TpConnection *self = (TpConnection *) object;
+ TpSimpleClientFactory *factory = (TpSimpleClientFactory *) object;
+ TpConnection *self = user_data;
GError *error = NULL;
- if (!tp_connection_upgrade_contacts_finish (self, result, NULL, &error))
+ if (!tp_simple_client_factory_upgrade_contacts_finish (factory, result, NULL,
+ &error))
{
DEBUG ("Error upgrading new roster contacts: %s", error->message);
g_clear_error (&error);
@@ -156,7 +158,6 @@ process_queued_contacts_changed (TpConnection *self)
ContactsChangedItem *item;
GHashTableIter iter;
gpointer key, value;
- GArray *features;
item = g_queue_peek_head (self->priv->contacts_changed_queue);
if (item == NULL)
@@ -187,15 +188,9 @@ process_queued_contacts_changed (TpConnection *self)
return;
}
- features = tp_simple_client_factory_dup_contact_features (
- tp_proxy_get_factory (self), self);
-
- tp_connection_upgrade_contacts_async (self,
- item->new_contacts->len, (TpContact **) item->new_contacts->pdata,
- features->len, (TpContactFeature *) features->data,
- new_contacts_upgraded_cb, NULL);
-
- g_array_unref (features);
+ tp_simple_client_factory_upgrade_contacts_async (tp_proxy_get_factory (self),
+ self, item->new_contacts->len, (TpContact **) item->new_contacts->pdata,
+ new_contacts_upgraded_cb, self);
}
static void
@@ -1674,7 +1669,8 @@ blocked_contacts_upgraded_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- TpConnection *self = (TpConnection *) object;
+ TpSimpleClientFactory *factory = (TpSimpleClientFactory *) object;
+ TpConnection *self = user_data;
BlockedChangedItem *item;
guint i;
GPtrArray *added, *removed;
@@ -1683,7 +1679,8 @@ blocked_contacts_upgraded_cb (GObject *object,
item = g_queue_peek_head (self->priv->blocked_changed_queue);
- if (!tp_connection_upgrade_contacts_finish (self, result, &contacts, &error))
+ if (!tp_simple_client_factory_upgrade_contacts_finish (factory, result,
+ &contacts, &error))
{
DEBUG ("Error upgrading blocked contacts: %s", error->message);
g_clear_error (&error);
@@ -1746,7 +1743,6 @@ process_queued_blocked_changed (TpConnection *self)
BlockedChangedItem *item;
GHashTableIter iter;
gpointer key, value;
- GArray *features;
GPtrArray *contacts;
item = g_queue_peek_head (self->priv->blocked_changed_queue);
@@ -1796,15 +1792,10 @@ process_queued_blocked_changed (TpConnection *self)
return;
}
- features = tp_simple_client_factory_dup_contact_features (
- tp_proxy_get_factory (self), self);
-
- tp_connection_upgrade_contacts_async (self,
- contacts->len, (TpContact **) contacts->pdata,
- features->len, (TpContactFeature *) features->data,
- blocked_contacts_upgraded_cb, NULL);
+ tp_simple_client_factory_upgrade_contacts_async (tp_proxy_get_factory (self),
+ self, contacts->len, (TpContact **) contacts->pdata,
+ blocked_contacts_upgraded_cb, self);
- g_array_unref (features);
g_ptr_array_unref (contacts);
}
diff --git a/telepathy-glib/simple-client-factory.c b/telepathy-glib/simple-client-factory.c
index 8865293f4..51b922114 100644
--- a/telepathy-glib/simple-client-factory.c
+++ b/telepathy-glib/simple-client-factory.c
@@ -862,6 +862,95 @@ tp_simple_client_factory_ensure_contact (TpSimpleClientFactory *self,
}
static void
+upgrade_contacts_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpConnection *connection = (TpConnection *) source;
+ GSimpleAsyncResult *my_result = user_data;
+ GPtrArray *contacts;
+ GError *error = NULL;
+
+ if (!tp_connection_upgrade_contacts_finish (connection, result,
+ &contacts, &error))
+ {
+ g_simple_async_result_take_error (my_result, error);
+ }
+ else
+ {
+ g_simple_async_result_set_op_res_gpointer (my_result, contacts,
+ (GDestroyNotify) g_ptr_array_unref);
+ }
+
+ g_simple_async_result_complete (my_result);
+ g_object_unref (my_result);
+}
+
+
+/**
+ * tp_simple_client_factory_upgrade_contacts_async:
+ * @self: a #TpSimpleClientFactory object
+ * @connection: 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
+ * associated with @self
+ * @callback: a callback to call when the operation finishes
+ * @user_data: data to pass to @callback
+ *
+ * Same as tp_connection_upgrade_contacts_async(), but prepare contacts with all
+ * features previously passed to
+ * tp_simple_client_factory_add_contact_features().
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_simple_client_factory_upgrade_contacts_async (
+ TpSimpleClientFactory *self,
+ TpConnection *connection,
+ guint n_contacts,
+ TpContact * const *contacts,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *features;
+
+ result = g_simple_async_result_new ((GObject *) self, callback, user_data,
+ tp_simple_client_factory_upgrade_contacts_async);
+
+ features = tp_simple_client_factory_dup_contact_features (self, connection);
+ tp_connection_upgrade_contacts_async (connection, n_contacts, contacts,
+ features->len, (TpContactFeature *) features->data,
+ upgrade_contacts_cb, result);
+ g_array_unref (features);
+}
+
+/**
+ * tp_simple_client_factory_upgrade_contacts_finish:
+ * @self: a #TpSimpleClientFactory
+ * @result: a #GAsyncResult
+ * @contacts: (element-type TelepathyGLib.Contact) (transfer container) (out) (allow-none):
+ * a location to set a #GPtrArray of upgraded #TpContact, or %NULL.
+ * @error: a #GError to fill
+ *
+ * Finishes tp_simple_client_factory_upgrade_contacts_async()
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ * Since: 0.UNRELEASED
+ */
+gboolean
+tp_simple_client_factory_upgrade_contacts_finish (
+ TpSimpleClientFactory *self,
+ GAsyncResult *result,
+ GPtrArray **contacts,
+ GError **error)
+{
+ _tp_implement_finish_copy_pointer (self,
+ tp_simple_client_factory_upgrade_contacts_async,
+ g_ptr_array_ref, contacts);
+}
+
+static void
dup_contact_by_id_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
diff --git a/telepathy-glib/simple-client-factory.h b/telepathy-glib/simple-client-factory.h
index fe5cfce83..ced250405 100644
--- a/telepathy-glib/simple-client-factory.h
+++ b/telepathy-glib/simple-client-factory.h
@@ -176,6 +176,20 @@ TpContact *tp_simple_client_factory_ensure_contact (TpSimpleClientFactory *self,
TpHandle handle,
const gchar *identifier);
_TP_AVAILABLE_IN_UNRELEASED
+void tp_simple_client_factory_upgrade_contacts_async (
+ TpSimpleClientFactory *self,
+ TpConnection *connection,
+ guint n_contacts,
+ TpContact * const *contacts,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+_TP_AVAILABLE_IN_UNRELEASED
+gboolean tp_simple_client_factory_upgrade_contacts_finish (
+ TpSimpleClientFactory *self,
+ GAsyncResult *result,
+ GPtrArray **contacts,
+ GError **error);
+_TP_AVAILABLE_IN_UNRELEASED
void tp_simple_client_factory_ensure_contact_by_id_async (
TpSimpleClientFactory *self,
TpConnection *connection,