[Telepathy-commits] [telepathy-mission-control/master] McdAccountManager: correctly emit ValidAccounts and InvalidAccounts as 'ao'

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Dec 10 08:22:20 PST 2008


Previously they were emitted on D-Bus as type 'as', causing telepathy-qt4
to fail.

In the process, simplify accounts_to_gvalue() considerably.
---
 src/mcd-account-manager.c |   41 ++++++++++++++++-------------------------
 1 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c
index 9c73233..e42eb48 100644
--- a/src/mcd-account-manager.c
+++ b/src/mcd-account-manager.c
@@ -83,12 +83,6 @@ struct _McdAccountManagerPrivate
     GHashTable *invalid_accounts;
 };
 
-typedef struct
-{
-    gchar **accounts;
-    gint i;
-} McdAccountArray;
-
 enum
 {
     PROP_0,
@@ -330,30 +324,27 @@ account_manager_iface_init (McSvcAccountManagerClass *iface,
 }
 
 static void
-append_account (gpointer key, gpointer val, gpointer userdata)
+accounts_to_gvalue (GHashTable *accounts, GValue *value)
 {
-    McdAccountArray *aa = userdata;
-    const gchar *object_path;
+    static GType ao_type = G_TYPE_INVALID;
+    GPtrArray *account_array;
+    GHashTableIter iter;
+    gpointer k, v;
 
-    object_path = mcd_account_get_object_path (val);
-    aa->accounts[aa->i++] = g_strdup (object_path);
-    aa->accounts[aa->i] = NULL;
-}
+    if (G_UNLIKELY (ao_type == G_TYPE_INVALID))
+        ao_type = dbus_g_type_get_collection ("GPtrArray",
+                                              DBUS_TYPE_G_OBJECT_PATH);
 
-static void
-accounts_to_gvalue (GHashTable *accounts, GValue *value)
-{
-    McdAccountArray account_array;
-    gint n_accounts;
+    account_array = g_ptr_array_sized_new (g_hash_table_size (accounts));
+
+    g_hash_table_iter_init (&iter, accounts);
 
-    n_accounts = g_hash_table_size (accounts);
-    account_array.accounts = g_new (gchar *, n_accounts + 1);
-    account_array.accounts[0] = NULL;
-    account_array.i = 0;
+    while (g_hash_table_iter_next (&iter, &k, &v))
+        g_ptr_array_add (account_array,
+                         g_strdup (mcd_account_get_object_path (v)));
 
-    g_hash_table_foreach (accounts, append_account, &account_array);
-    g_value_init (value, G_TYPE_STRV);
-    g_value_take_boxed (value, account_array.accounts);
+    g_value_init (value, ao_type);
+    g_value_take_boxed (value, account_array);
 }
 
 static void
-- 
1.5.6.5




More information about the Telepathy-commits mailing list