Resets a key to its default value.
g_settings_revert
g_settings_get_has_unapplied
g_settings_get_child
+g_settings_reset
<SUBSECTION Introspection>
g_settings_list_schemas
gboolean default_value)
{
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
- GVariant *result;
+ gpointer result = NULL;
- if (!default_value &&
- (result = g_tree_lookup (delayed->priv->delayed, key)))
- return g_variant_ref (result);
+ if (!default_value)
+ {
+ g_static_mutex_lock (&delayed->priv->lock);
+ if (g_tree_lookup_extended (delayed->priv->delayed, key, NULL, &result))
+ {
+ /* NULL in the tree means we should consult the default value */
+ if (result != NULL)
+ g_variant_ref (result);
+ else
+ default_value = TRUE;
+ }
+ g_static_mutex_unlock (&delayed->priv->lock);
+ }
+
+ if (result == NULL)
+ result = g_settings_backend_read (delayed->priv->backend, key,
+ expected_type, default_value);
- return g_settings_backend_read (delayed->priv->backend,
- key, expected_type, default_value);
+ return result;
}
+
static gboolean
g_delayed_settings_backend_write (GSettingsBackend *backend,
const gchar *key,
const gchar *key,
gpointer origin_tag)
{
- /* deal with this... */
+ GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
+ gboolean was_empty;
+
+ g_static_mutex_lock (&delayed->priv->lock);
+ was_empty = g_tree_nnodes (delayed->priv->delayed) == 0;
+ g_tree_insert (delayed->priv->delayed, g_strdup (key), NULL);
+ g_static_mutex_unlock (&delayed->priv->lock);
+
+ if (was_empty)
+ g_delayed_settings_backend_notify_unapplied (delayed);
}
static void
g_settings_new_with_backend_and_path
g_settings_new_with_path
g_settings_revert
+g_settings_reset
g_settings_set
g_settings_set_value
g_settings_unbind
{
GMemorySettingsBackend *memory = data;
- g_hash_table_insert (memory->table, g_strdup (key), g_variant_ref (value));
+ if (value != NULL)
+ g_hash_table_insert (memory->table, g_strdup (key), g_variant_ref (value));
+ else
+ g_hash_table_remove (memory->table, key);
return FALSE;
}
return TRUE;
}
+static void
+g_memory_settings_backend_reset (GSettingsBackend *backend,
+ const gchar *key,
+ gpointer origin_tag)
+{
+ GMemorySettingsBackend *memory = G_MEMORY_SETTINGS_BACKEND (backend);
+
+ if (g_hash_table_lookup (memory->table, key))
+ {
+ g_hash_table_remove (memory->table, key);
+ g_settings_backend_changed (backend, key, origin_tag);
+ }
+}
+
static gboolean
g_memory_settings_backend_get_writable (GSettingsBackend *backend,
const gchar *name)
backend_class->read = g_memory_settings_backend_read;
backend_class->write = g_memory_settings_backend_write;
backend_class->write_keys = g_memory_settings_backend_write_keys;
+ backend_class->reset = g_memory_settings_backend_reset;
backend_class->get_writable = g_memory_settings_backend_get_writable;
backend_class->get_permission = g_memory_settings_backend_get_permission;
object_class->finalize = g_memory_settings_backend_finalize;
G_DELAYED_SETTINGS_BACKEND (settings->priv->backend));
}
-/* Extra API (sync, get_child, is_writable, list_items) {{{1 */
+/* Extra API (reset, sync, get_child, is_writable, list_items) {{{1 */
+/**
+ * g_settings_reset:
+ * @settings: a #GSettings object
+ * @key: the name of a key
+ *
+ * Resets @key to its default value.
+ *
+ * This call resets the key, as much as possible, to its default value.
+ * That might the value specified in the schema or the one set by the
+ * administrator.
+ **/
+void
+g_settings_reset (GSettings *settings,
+ const gchar *key)
+{
+ gchar *path;
+
+ path = g_strconcat (settings->priv->path, key, NULL);
+ g_settings_backend_reset (settings->priv->backend, path, NULL);
+ g_free (path);
+}
+
/**
* g_settings_sync:
*
const gchar *key,
const gchar *format,
...);
+void g_settings_reset (GSettings *settings,
+ const gchar *key);
gint g_settings_get_int (GSettings *settings,
const gchar *key);