summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/dconf-client.c54
-rw-r--r--client/dconf-client.h3
-rw-r--r--tests/client.c3
3 files changed, 60 insertions, 0 deletions
diff --git a/client/dconf-client.c b/client/dconf-client.c
index 105ca88..ea2e07c 100644
--- a/client/dconf-client.c
+++ b/client/dconf-client.c
@@ -242,6 +242,60 @@ dconf_client_read (DConfClient *client,
return dconf_engine_read (client->engine, NULL, key);
}
+/* This provides a "read through" queue that resets all of the keys.
+ * This is a good way to get the default value for a key.
+ *
+ * We cache the value of this queue in a static instead of generating
+ * and freeing it each time.
+ */
+static GQueue *
+dconf_client_get_reset_queue (void)
+{
+ static GQueue *reset_queue;
+
+ if (g_once_init_enter (&reset_queue))
+ {
+ DConfChangeset *reset_all;
+ GQueue *tmp;
+
+ reset_all = dconf_changeset_new ();
+ dconf_changeset_set (reset_all, "/", NULL);
+ dconf_changeset_seal (reset_all);
+
+ tmp = g_queue_new ();
+ g_queue_push_tail (tmp, reset_all);
+ g_once_init_leave (&reset_queue, tmp);
+ }
+
+ return reset_queue;
+}
+
+/**
+ * dconf_client_read_default:
+ * @client: a #DConfClient
+ * @key: the key to read the default value of
+ *
+ * Reads the current default value of @key.
+ *
+ * The default value of the key is the value that the key would have if
+ * were to be reset. This is usually %NULL, but it may be something
+ * else in the case that the system administrator has defined a default
+ * value for a key.
+ *
+ * If there are outstanding "fast" changes in progress they may affect
+ * the result of this call.
+ *
+ * Returns: a #GVariant, or %NULL
+ */
+GVariant *
+dconf_client_read_default (DConfClient *client,
+ const gchar *key)
+{
+ g_return_val_if_fail (DCONF_IS_CLIENT (client), NULL);
+
+ return dconf_engine_read (client->engine, dconf_client_get_reset_queue (), key);
+}
+
/**
* dconf_client_list:
* @client: a #DConfClient
diff --git a/client/dconf-client.h b/client/dconf-client.h
index 1e07f80..e50792b 100644
--- a/client/dconf-client.h
+++ b/client/dconf-client.h
@@ -39,6 +39,9 @@ DConfClient * dconf_client_new (void);
GVariant * dconf_client_read (DConfClient *client,
const gchar *key);
+GVariant * dconf_client_read_default (DConfClient *client,
+ const gchar *key);
+
gchar ** dconf_client_list (DConfClient *client,
const gchar *dir,
gint *length);
diff --git a/tests/client.c b/tests/client.c
index 7d0f95d..4a3505c 100644
--- a/tests/client.c
+++ b/tests/client.c
@@ -68,6 +68,7 @@ queue_up_100_writes (DConfClient *client)
/* We should always see the most recently written value. */
check_and_free (dconf_client_read (client, "/test/value"), g_variant_new_int32 (i));
+ check_and_free (dconf_client_read_default (client, "/test/value"), NULL);
}
g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), ==, 2);
@@ -140,6 +141,7 @@ test_fast (void)
g_assert (changed_was_called);
check_and_free (dconf_client_read (client, "/test/value"), g_variant_new_int32 (99));
+ check_and_free (dconf_client_read_default (client, "/test/value"), NULL);
}
/* Because of the pending-merging logic, we should only have had to
@@ -154,6 +156,7 @@ test_fast (void)
/* Should read back now as NULL */
check_and_free (dconf_client_read (client, "/test/value"), NULL);
+ check_and_free (dconf_client_read_default (client, "/test/value"), NULL);
/* Cleanup */
g_signal_handlers_disconnect_by_func (client, changed, NULL);