summaryrefslogtreecommitdiff
path: root/xfconf
diff options
context:
space:
mode:
authorAli Abdallah <aliovx@gmail.com>2016-02-15 18:30:19 +0100
committerAli Abdallah <aliovx@gmail.com>2016-02-15 18:30:19 +0100
commit00aaa90c08edccfe987378193f325d08ef822f19 (patch)
tree8866ff872752d78ac958dc8843d018bc387ad794 /xfconf
parent3c47818cefd97dccba8b1fb663e492d5b13c25d0 (diff)
downloadxfconf-00aaa90c08edccfe987378193f325d08ef822f19.tar.gz
Port xfconf_channel_get_arrayv to gdbus. Now the function works
as follows: xfconf_channel_get_internal is called to get a GValue which should contain a GVariant that is an array of variants value. Each of these GVariant value is transformed to a GValue and added to the GPtrArray.
Diffstat (limited to 'xfconf')
-rw-r--r--xfconf/xfconf-cache.c42
-rw-r--r--xfconf/xfconf-channel.c27
2 files changed, 42 insertions, 27 deletions
diff --git a/xfconf/xfconf-cache.c b/xfconf/xfconf-cache.c
index 0fd5f4b..477a79b 100644
--- a/xfconf/xfconf-cache.c
+++ b/xfconf/xfconf-cache.c
@@ -641,42 +641,41 @@ xfconf_cache_new(const gchar *channel_name)
NULL);
}
-static gboolean
-xfconf_cache_prefetch_ht(gpointer key,
- gpointer value,
- gpointer user_data)
-{
- XfconfCache *cache = XFCONF_CACHE(user_data);
- XfconfCacheItem *item;
-
- item = xfconf_cache_item_new(value, TRUE);
- g_tree_insert(cache->properties, key, item);
-
- return TRUE;
-}
-
gboolean
xfconf_cache_prefetch(XfconfCache *cache,
const gchar *property_base,
GError **error)
{
+ GVariant *props_variant, *value;
+ GVariantIter *iter;
+ gchar *key;
gboolean ret = FALSE;
- GHashTable *props = NULL;
- DBusGProxy *proxy = _xfconf_get_dbus_g_proxy();
+ GDBusProxy *proxy = _xfconf_get_gdbus_proxy ();
GError *tmp_error = NULL;
g_return_val_if_fail(g_tree_nnodes(cache->properties) == 0, FALSE);
xfconf_cache_mutex_lock(cache);
- if(xfconf_client_get_all_properties(proxy, cache->channel_name,
- property_base ? property_base : "/",
- &props, &tmp_error))
+ if(xfconf_client_call_get_all_properties_sync((XfconfClient *)proxy, cache->channel_name,
+ property_base ? property_base : "/",
+ &props_variant, NULL, &tmp_error))
{
- g_hash_table_foreach_steal(props, xfconf_cache_prefetch_ht, cache);
- g_hash_table_destroy(props);
+ g_variant_get (props_variant, "a{sv}", &iter);
+ while (g_variant_iter_next (iter, "{sv}", &key, &value))
+ {
+ XfconfCacheItem *item;
+ GValue gvalue = G_VALUE_INIT;
+ g_dbus_gvariant_to_gvalue(value, &gvalue);
+
+ item = xfconf_cache_item_new(&gvalue, FALSE);
+ g_tree_insert(cache->properties, key, item);
+ g_value_unset (&gvalue);
+ }
/* TODO: honor max entries */
ret = TRUE;
+ g_variant_iter_free (iter);
+ g_variant_unref(props_variant);
} else
g_propagate_error(error, tmp_error);
@@ -699,7 +698,6 @@ xfconf_cache_lookup_locked(XfconfCache *cache,
GDBusProxy *proxy = _xfconf_get_gdbus_proxy();
GValue tmpval = { 0, };
GError *tmp_error = NULL;
-
/* blocking, ugh */
if(xfconf_client_call_get_property_sync ((XfconfClient *)proxy, cache->channel_name,
property, &variant, NULL, &tmp_error))
diff --git a/xfconf/xfconf-channel.c b/xfconf/xfconf-channel.c
index 3950ada..6cda4f6 100644
--- a/xfconf/xfconf-channel.c
+++ b/xfconf/xfconf-channel.c
@@ -1537,8 +1537,12 @@ GPtrArray *
xfconf_channel_get_arrayv(XfconfChannel *channel,
const gchar *property)
{
- GValue val = { 0, };
GPtrArray *arr = NULL;
+ GValue val = { 0, };
+ GVariant *variant;
+ GVariant *value_prop;
+ GVariantIter iter;
+ gsize count;
gboolean ret;
g_return_val_if_fail(XFCONF_IS_CHANNEL(channel) && property, NULL);
@@ -1547,19 +1551,32 @@ xfconf_channel_get_arrayv(XfconfChannel *channel,
if(!ret)
return NULL;
- if(XFCONF_TYPE_G_VALUE_ARRAY != G_VALUE_TYPE(&val)) {
+ if(G_TYPE_VARIANT != G_VALUE_TYPE(&val)) {
g_value_unset(&val);
return NULL;
}
- arr = g_value_get_boxed(&val);
+ variant = g_value_get_variant (&val);
+ g_value_unset(&val);
+
+ count = g_variant_iter_init (&iter, variant);
+ arr = g_ptr_array_sized_new (count + 1);
+
+ while (g_variant_iter_next (&iter, "v", &value_prop)) {
+ GValue *arr_val;
+ arr_val = g_new0(GValue, 1);
+ g_dbus_gvariant_to_gvalue (value_prop, arr_val);
+
+ g_ptr_array_add(arr, arr_val);
+ g_variant_unref (value_prop);
+ }
+ g_variant_unref (variant);
+
if(!arr->len) {
g_ptr_array_free(arr, TRUE);
return NULL;
}
- /* FIXME: does anything with |val| leak here? */
-
return arr;
}