diff options
author | Ryan Lortie <desrt@desrt.ca> | 2012-07-06 16:38:31 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2012-07-06 16:38:31 -0400 |
commit | 0f5906d6491444dbe90de806b0e73a4f83078785 (patch) | |
tree | 0776b95c1011bc37ac7ecac4fde873651891238b /common | |
parent | a20d8fa3133eadf11a3db9d9ad1761e02bb20d41 (diff) | |
download | dconf-0f5906d6491444dbe90de806b0e73a4f83078785.tar.gz |
dconf_changeset_set: support resetting paths
When someone resets a path with dconf_changeset_set(), delete all keys
that are currently under that path in the changeset.
Diffstat (limited to 'common')
-rw-r--r-- | common/dconf-changeset.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/common/dconf-changeset.c b/common/dconf-changeset.c index 261d4ff..1dcee39 100644 --- a/common/dconf-changeset.c +++ b/common/dconf-changeset.c @@ -93,24 +93,48 @@ dconf_changeset_ref (DConfChangeset *change) /** * dconf_changeset_set: * @change: a #DConfChangeset - * @key: a key to modify + * @path: a path to modify * @value: the value for the key, or %NULL to reset * - * Adds an operation to modify @key to a #DConfChangeset. + * Adds an operation to modify @path to a #DConfChangeset. * - * @value, if non-%NULL specifies the new requested value of @key. If - * @value is %NULL, the key is reset. + * @path may either be a key or a dir. If it is a key then @value may + * be a #GVariant, or %NULL (to set or reset the key). + * + * If @path is a dir then this must be a reset operation: @value must be + * %NULL. It is not permitted to assign a #GVariant value to a dir. **/ void dconf_changeset_set (DConfChangeset *change, - const gchar *key, + const gchar *path, GVariant *value) { g_return_if_fail (change->root == NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (key[0] == '/'); + g_return_if_fail (dconf_is_path (path, NULL)); + + /* Check if we are performing a path reset */ + if (g_str_has_suffix (path, "/")) + { + GHashTableIter iter; + gpointer key; + + g_return_if_fail (value == NULL); + + /* When we reset a path we must also reset all keys within that + * path. + */ + g_hash_table_iter_init (&iter, change->table); + while (g_hash_table_iter_next (&iter, &key, NULL)) + if (g_str_has_prefix (key, path)) + g_hash_table_iter_remove (&iter); + + /* Record the reset itself. */ + g_hash_table_insert (change->table, g_strdup (path), NULL); + } - g_hash_table_insert (change->table, g_strdup (key), value ? g_variant_ref_sink (value) : NULL); + /* else, just a normal value write or reset */ + else + g_hash_table_insert (change->table, g_strdup (path), value ? g_variant_ref_sink (value) : NULL); } /** |