From 768ed4bbe040c53ee5010038c34aec7c69dba0a5 Mon Sep 17 00:00:00 2001 From: Allison Ryan Lortie Date: Mon, 30 Nov 2015 14:46:12 -0500 Subject: engine, client: add list_locks() operation Add an API to dconf-engine (and exposed via DConfClient) for getting a list of locks that are present in a given dconf profile. https://bugzilla.gnome.org/show_bug.cgi?id=758864 --- engine/dconf-engine.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ engine/dconf-engine.h | 5 ++++ 2 files changed, 70 insertions(+) (limited to 'engine') diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c index 57bce96..e51ec57 100644 --- a/engine/dconf-engine.c +++ b/engine/dconf-engine.c @@ -363,6 +363,71 @@ dconf_engine_is_writable (DConfEngine *engine, return writable; } +gchar ** +dconf_engine_list_locks (DConfEngine *engine, + const gchar *path, + gint *length) +{ + gchar **strv; + + if (dconf_is_dir (path, NULL)) + { + GHashTable *set; + + set = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + + dconf_engine_acquire_sources (engine); + + if (engine->n_sources > 0 && engine->sources[0]->writable) + { + gint i, j; + + for (i = 1; i < engine->n_sources; i++) + { + if (engine->sources[i]->locks) + { + strv = gvdb_table_get_names (engine->sources[i]->locks, NULL); + + for (j = 0; strv[j]; j++) + { + /* It is not currently possible to lock dirs, so we + * don't (yet) have to check the other direction. + */ + if (g_str_has_prefix (strv[j], path)) + g_hash_table_add (set, strv[j]); + else + g_free (strv[j]); + } + + g_free (strv); + } + } + } + else + g_hash_table_add (set, g_strdup (path)); + + dconf_engine_release_sources (engine); + + strv = (gchar **) g_hash_table_get_keys_as_array (set, (guint *) length); + g_hash_table_steal_all (set); + g_hash_table_unref (set); + } + else + { + if (dconf_engine_is_writable (engine, path)) + { + strv = g_new0 (gchar *, 0 + 1); + } + else + { + strv = g_new0 (gchar *, 1 + 1); + strv[0] = g_strdup (path); + } + } + + return strv; +} + static gboolean dconf_engine_find_key_in_queue (GQueue *queue, const gchar *key, diff --git a/engine/dconf-engine.h b/engine/dconf-engine.h index 9ea118c..5c34bbd 100644 --- a/engine/dconf-engine.h +++ b/engine/dconf-engine.h @@ -111,6 +111,11 @@ G_GNUC_INTERNAL gboolean dconf_engine_is_writable (DConfEngine *engine, const gchar *key); +G_GNUC_INTERNAL +gchar ** dconf_engine_list_locks (DConfEngine *engine, + const gchar *path, + gint *length); + G_GNUC_INTERNAL GVariant * dconf_engine_read (DConfEngine *engine, GQueue *read_through, -- cgit v1.2.1