[dconf/wip/reorg: 500/523] dconf_changeset_set: support resetting paths
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf/wip/reorg: 500/523] dconf_changeset_set: support resetting paths
- Date: Mon, 9 Jul 2012 02:49:25 +0000 (UTC)
commit 0f5906d6491444dbe90de806b0e73a4f83078785
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Jul 6 16:38:31 2012 -0400
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.
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);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]