telepathy-glib: TpAccount: implement change notification on uri-schemes property

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Wed Jan 9 05:05:20 PST 2013


Module: telepathy-glib
Branch: master
Commit: 18dd2cc616621f796bf1d1987e55b51eedca00b8
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=18dd2cc616621f796bf1d1987e55b51eedca00b8

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Mon Jan  7 17:29:45 2013 +0100

TpAccount: implement change notification on uri-schemes property

---

 telepathy-glib/account.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 tests/dbus/account.c       |    9 +++++++++
 tests/lib/simple-account.c |   15 +++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c
index c49699c..3b4d44f 100644
--- a/telepathy-glib/account.c
+++ b/telepathy-glib/account.c
@@ -1020,6 +1020,42 @@ _tp_account_got_all_cb (TpProxy *proxy,
 }
 
 static void
+addressing_props_changed (TpAccount *self,
+    GHashTable *changed_properties)
+{
+  const gchar * const * v;
+
+  if (self->priv->uri_schemes == NULL)
+    /* We did not fetch the initial value yet, ignoring */
+    return;
+
+  v = tp_asv_get_strv (changed_properties, "URISchemes");
+  if (v == NULL)
+    return;
+
+  g_strfreev (self->priv->uri_schemes);
+  self->priv->uri_schemes = g_strdupv ((GStrv) v);
+
+  g_object_notify (G_OBJECT (self), "uri-schemes");
+}
+
+static void
+dbus_properties_changed_cb (TpProxy *proxy,
+    const gchar *interface_name,
+    GHashTable *changed_properties,
+    const gchar **invalidated_properties,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  TpAccount *self = TP_ACCOUNT (weak_object);
+
+  if (!tp_strdiff (interface_name, TP_IFACE_ACCOUNT_INTERFACE_ADDRESSING))
+    {
+      addressing_props_changed (self, changed_properties);
+    }
+}
+
+static void
 _tp_account_constructed (GObject *object)
 {
   TpAccount *self = TP_ACCOUNT (object);
@@ -1059,6 +1095,9 @@ _tp_account_constructed (GObject *object)
   tp_cli_account_connect_to_account_property_changed (self,
       _tp_account_properties_changed, NULL, NULL, object, NULL);
 
+  tp_cli_dbus_properties_connect_to_properties_changed (self,
+      dbus_properties_changed_cb, NULL, NULL, object, NULL);
+
   tp_cli_dbus_properties_call_get_all (self, -1, TP_IFACE_ACCOUNT,
       _tp_account_got_all_cb, NULL, NULL, G_OBJECT (self));
 }
@@ -2047,6 +2086,9 @@ tp_account_class_init (TpAccountClass *klass)
    * protocol (for instance, "xmpp" for XMPP, or "sip" or "sips" for SIP),
    * since it should be assumed to be useful for those schemes in any case.
    *
+   * The notify::uri-schemes signal cannot be relied on if the Account Manager
+   * is Mission Control version 5.14.0 or older.
+   *
    * Since: UNRELEASED
    */
   g_object_class_install_property (object_class, PROP_URI_SCHEMES,
diff --git a/tests/dbus/account.c b/tests/dbus/account.c
index dc27ac1..b921f40 100644
--- a/tests/dbus/account.c
+++ b/tests/dbus/account.c
@@ -678,6 +678,15 @@ test_addressing (Test *test,
         "telnet"));
   g_assert (!tp_account_associated_with_uri_scheme (test->account,
         "xmpp"));
+
+  g_signal_connect (test->account, "notify::uri-schemes",
+      G_CALLBACK (notify_cb), test);
+
+  tp_tests_simple_account_add_uri_scheme (test->account_service, "xmpp");
+  g_main_loop_run (test->mainloop);
+
+  g_assert (tp_account_associated_with_uri_scheme (test->account,
+        "xmpp"));
 }
 
 static void
diff --git a/tests/lib/simple-account.c b/tests/lib/simple-account.c
index 892e0e5..dc09120 100644
--- a/tests/lib/simple-account.c
+++ b/tests/lib/simple-account.c
@@ -603,5 +603,20 @@ void
 tp_tests_simple_account_add_uri_scheme (TpTestsSimpleAccount *self,
     const gchar *uri_scheme)
 {
+  GHashTable *changed;
+  GStrv schemes;
+
   g_ptr_array_add (self->priv->uri_schemes, g_strdup (uri_scheme));
+
+  g_object_get (self, "uri-schemes", &schemes, NULL);
+
+  changed = tp_asv_new (
+      "URISchemes", G_TYPE_STRV, schemes,
+      NULL);
+
+  tp_svc_dbus_properties_emit_properties_changed (self,
+      TP_IFACE_ACCOUNT_INTERFACE_ADDRESSING, changed, NULL);
+
+  g_strfreev (schemes);
+  g_hash_table_unref (changed);
 }



More information about the telepathy-commits mailing list