[telepathy-glib/master] account: add tp_account_get_avatar_async and _finish method.

Jonny Lamb jonny.lamb at collabora.co.uk
Mon Sep 28 07:38:37 PDT 2009


Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 docs/reference/telepathy-glib-sections.txt |    2 +
 telepathy-glib/account.c                   |   77 ++++++++++++++++++++++++++++
 telepathy-glib/account.h                   |    6 ++
 3 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 63b03b2..1174069 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -3030,6 +3030,8 @@ tp_account_set_nickname_async
 tp_account_set_nickname_finish
 tp_account_refresh_properties
 tp_account_get_unique_name
+tp_account_get_avatar_async
+tp_account_get_avatar_finish
 <SUBSECTION>
 tp_cli_account_callback_for_reconnect
 tp_cli_account_call_reconnect
diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c
index 8220dbf..1107c91 100644
--- a/telepathy-glib/account.c
+++ b/telepathy-glib/account.c
@@ -2146,3 +2146,80 @@ tp_account_get_unique_name (TpAccount *account)
 {
   return tp_proxy_get_object_path (account);
 }
+
+static void
+_tp_account_got_avatar_cb (TpProxy *proxy,
+    const GValue *out_Value,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
+  GValueArray *avatar;
+  GArray *res;
+
+  if (error != NULL)
+    {
+      DEBUG ("Failed to get avatar: %s", error->message);
+      g_simple_async_result_set_from_error (result, (GError *) error);
+    }
+  else
+    {
+      avatar = g_value_get_boxed (out_Value);
+      res = g_value_get_boxed (g_value_array_get_nth (avatar, 0));
+      g_simple_async_result_set_op_res_gpointer (result, res, NULL);
+    }
+
+  g_simple_async_result_complete (result);
+  g_object_unref (result);
+}
+
+/**
+ * tp_account_get_avatar_async:
+ * @account: a #TpAccount
+ * @callback: a callback to call when the request is satisfied
+ * @user_data: data to pass to @callback
+ *
+ * Requests an asynchronous get of @account's avatar. When
+ * the operation is finished, @callback will be called. You can then call
+ * tp_account_get_avatar_finish() to get the result of the operation.
+ */
+void
+tp_account_get_avatar_async (TpAccount *account,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (account),
+      callback, user_data, tp_account_get_avatar_finish);
+
+  tp_cli_dbus_properties_call_get (account, -1,
+      TP_IFACE_ACCOUNT_INTERFACE_AVATAR, "Avatar", _tp_account_got_avatar_cb,
+      result, NULL, G_OBJECT (account));
+}
+
+/**
+ * tp_account_get_avatar_finish:
+ * @account: a #TpAccount
+ * @result: a #GAsyncResult
+ * @error: a #GError to fill
+ *
+ * Finishes an async get operation of @account's avatar.
+ *
+ * Returns: a #GArray of the account's avatar, or %NULL on failure
+ */
+const GArray *
+tp_account_get_avatar_finish (TpAccount *account,
+    GAsyncResult *result,
+    GError **error)
+{
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+          error) ||
+      !g_simple_async_result_is_valid (result, G_OBJECT (account),
+          tp_account_get_avatar_finish))
+    return NULL;
+
+  return g_simple_async_result_get_op_res_gpointer (
+      G_SIMPLE_ASYNC_RESULT (result));
+}
diff --git a/telepathy-glib/account.h b/telepathy-glib/account.h
index 53b4fbe..615c402 100644
--- a/telepathy-glib/account.h
+++ b/telepathy-glib/account.h
@@ -181,6 +181,12 @@ void tp_account_refresh_properties (TpAccount *account);
 
 const gchar *tp_account_get_unique_name (TpAccount *account);
 
+void tp_account_get_avatar_async (TpAccount *account,
+    GAsyncReadyCallback callback, gpointer user_data);
+
+const GArray *tp_account_get_avatar_finish (TpAccount *account,
+    GAsyncResult *result, GError **error);
+
 G_END_DECLS
 
 #include <telepathy-glib/_gen/tp-cli-account.h>
-- 
1.5.6.5




More information about the telepathy-commits mailing list