[next] telepathy-glib: add TpAccount::avatar-changed signal
Guillaume Desmottes
gdesmott at kemper.freedesktop.org
Tue Oct 29 14:31:37 CET 2013
Module: telepathy-glib
Branch: next
Commit: 79acc094fb8d0136641022ae7e19e401e7aec8e5
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=79acc094fb8d0136641022ae7e19e401e7aec8e5
Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date: Wed Oct 23 14:55:10 2013 +0200
add TpAccount::avatar-changed signal
Fix https://bugs.freedesktop.org/show_bug.cgi?id=52938
---
telepathy-glib/account.c | 30 ++++++++++++++++++++++++++++++
tests/dbus/account.c | 28 ++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c
index 26d9793..3be8a54 100644
--- a/telepathy-glib/account.c
+++ b/telepathy-glib/account.c
@@ -149,6 +149,7 @@ G_DEFINE_TYPE (TpAccount, tp_account, TP_TYPE_PROXY)
enum {
STATUS_CHANGED,
PRESENCE_CHANGED,
+ AVATAR_CHANGED,
LAST_SIGNAL
};
@@ -1007,6 +1008,14 @@ _tp_account_properties_changed (TpAccount *proxy,
}
static void
+avatar_changed_cb (TpAccount *self,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ g_signal_emit (self, signals[AVATAR_CHANGED], 0);
+}
+
+static void
_tp_account_got_all_cb (TpProxy *proxy,
GHashTable *properties,
const GError *error,
@@ -1027,6 +1036,11 @@ _tp_account_got_all_cb (TpProxy *proxy,
}
_tp_account_update (self, properties);
+
+ /* We can't try connecting this signal earlier as tp_proxy_add_interfaces()
+ * has to be called first if we support the Avatar interface. */
+ tp_cli_account_interface_avatar_connect_to_avatar_changed (self,
+ avatar_changed_cb, NULL, NULL, G_OBJECT (self), NULL);
}
static void
@@ -2150,6 +2164,22 @@ tp_account_class_init (TpAccountClass *klass)
0, NULL, NULL, NULL,
G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+ /**
+ * TpAccount::avatar-changed:
+ * @self: a #TpAccount
+ *
+ * Emitted when the avatar changes. Call tp_account_get_avatar_async()
+ * to get the new avatar data.
+ *
+ * Since: UNRELEASED
+ */
+ signals[AVATAR_CHANGED] = g_signal_new ("avatar-changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 0);
+
proxy_class->interface = TP_IFACE_QUARK_ACCOUNT;
proxy_class->list_features = _tp_account_list_features;
tp_account_init_known_interfaces ();
diff --git a/tests/dbus/account.c b/tests/dbus/account.c
index eb21dc1..81ac8f1 100644
--- a/tests/dbus/account.c
+++ b/tests/dbus/account.c
@@ -690,6 +690,13 @@ test_addressing (Test *test,
}
static void
+avatar_changed_cb (TpAccount *account,
+ Test *test)
+{
+ g_main_loop_quit (test->mainloop);
+}
+
+static void
test_avatar (Test *test,
gconstpointer mode)
{
@@ -714,6 +721,27 @@ test_avatar (Test *test,
g_assert_cmpstr (((char *) blob->data), ==, ":-)");
tp_clear_object (&test->result);
+
+ /* change the avatar */
+ g_signal_connect (test->account, "avatar-changed",
+ G_CALLBACK (avatar_changed_cb), test);
+
+ tp_tests_simple_account_set_avatar (test->account_service, ":-(");
+ g_main_loop_run (test->mainloop);
+
+ tp_account_get_avatar_async (test->account,
+ tp_tests_result_ready_cb, &test->result);
+ tp_tests_run_until_result (&test->result);
+
+ blob = tp_account_get_avatar_finish (
+ test->account, test->result, &error);
+ g_assert_no_error (error);
+
+ g_assert (blob != NULL);
+ g_assert_cmpuint (blob->len, ==, 4);
+ g_assert_cmpstr (((char *) blob->data), ==, ":-(");
+
+ tp_clear_object (&test->result);
}
static void
More information about the telepathy-commits
mailing list