[glib: 5/5] GSettings: store (default, options) in gvdb
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 5/5] GSettings: store (default, options) in gvdb
- Date: Thu, 10 Jun 2010 17:55:16 +0000 (UTC)
commit 3a062d2e33aa1d54dd460a1a2cb297009d94d4d6
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Jun 10 13:49:57 2010 -0400
GSettings: store (default, options) in gvdb
gvdb just dropped the ability to have a separate "options" field. We
now store the options into a GVariant along with the default value.
For now, we use a small shim in GSettingsSchema in order not to touch
too much code. A more complete rewrite will follow.
This represents a change to the schema file format with another likely
to follow. glib-compile-schemas needs to be re-run after installing
this change.
gio/gschema-compile.c | 7 +++----
gio/gsettings.c | 12 +++++-------
gio/gsettingsschema.c | 25 ++++++++++++++++---------
gio/gsettingsschema.h | 3 +++
4 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/gio/gschema-compile.c b/gio/gschema-compile.c
index 95f7582..f462a7b 100644
--- a/gio/gschema-compile.c
+++ b/gio/gschema-compile.c
@@ -551,10 +551,9 @@ end_element (GMarkupParseContext *context,
state->choices = NULL;
}
- gvdb_item_set_value (state->key, state->value);
- gvdb_item_set_options (state->key,
- g_variant_builder_end (&state->key_options));
-
+ gvdb_item_set_value (state->key,
+ g_variant_new ("(*a{sv})", state->value,
+ &state->key_options));
state->value = NULL;
}
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 6ad842a..01db482 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -991,7 +991,7 @@ GSettings *
g_settings_get_child (GSettings *settings,
const gchar *name)
{
- GVariant *child_schema;
+ const gchar *child_schema;
gchar *child_path;
gchar *child_name;
GSettings *child;
@@ -999,19 +999,17 @@ g_settings_get_child (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
child_name = g_strconcat (name, "/", NULL);
- child_schema = g_settings_schema_get_value (settings->priv->schema,
- child_name, NULL);
- if (child_schema == NULL ||
- !g_variant_is_of_type (child_schema, G_VARIANT_TYPE_STRING))
+ child_schema = g_settings_schema_get_string (settings->priv->schema,
+ child_name);
+ if (child_schema == NULL)
g_error ("Schema '%s' has no child '%s'",
settings->priv->schema_name, name);
child_path = g_strconcat (settings->priv->path, child_name, NULL);
child = g_object_new (G_TYPE_SETTINGS,
- "schema", g_variant_get_string (child_schema, NULL),
+ "schema", child_schema,
"path", child_path,
NULL);
- g_variant_unref (child_schema);
g_free (child_path);
g_free (child_name);
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index af2c7d8..c0fbf17 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -112,14 +112,14 @@ g_settings_schema_class_init (GSettingsSchemaClass *class)
g_type_class_add_private (class, sizeof (GSettingsSchemaPrivate));
}
-static const gchar *
+const gchar *
g_settings_schema_get_string (GSettingsSchema *schema,
const gchar *key)
{
const gchar *result = NULL;
GVariant *value;
- if ((value = gvdb_table_get_value (schema->priv->table, key, NULL)))
+ if ((value = gvdb_table_get_value (schema->priv->table, key)))
{
result = g_variant_get_string (value, NULL);
g_variant_unref (value);
@@ -167,10 +167,11 @@ g_settings_schema_get_value (GSettingsSchema *schema,
const gchar *key,
GVariant **options)
{
+ GVariant *variant, *value;
#if G_BYTE_ORDER == G_BIG_ENDIAN
- GVariant *variant, *tmp;
+ GVariant *tmp;
- tmp = gvdb_table_get_value (schema->priv->table, key, options);
+ tmp = gvdb_table_get_value (schema->priv->table, key);
if (tmp)
{
@@ -179,13 +180,19 @@ g_settings_schema_get_value (GSettingsSchema *schema,
}
else
variant = NULL;
-
- /* NOTE: no options have byteswapped data in them at the moment */
-
- return variant;
#else
- return gvdb_table_get_value (schema->priv->table, key, options);
+ variant = gvdb_table_get_value (schema->priv->table, key);
#endif
+
+ if (variant == NULL)
+ return NULL;
+
+ value = g_variant_get_child_value (variant, 0);
+ if (options != NULL)
+ *options = g_variant_get_child_value (variant, 1);
+ g_variant_unref (variant);
+
+ return value;
}
const gchar *
diff --git a/gio/gsettingsschema.h b/gio/gsettingsschema.h
index f57b015..9ac86a9 100644
--- a/gio/gsettingsschema.h
+++ b/gio/gsettingsschema.h
@@ -70,6 +70,9 @@ gboolean g_settings_schema_has_key (GSettin
G_GNUC_INTERNAL
const GQuark * g_settings_schema_list (GSettingsSchema *schema,
gint *n_items);
+G_GNUC_INTERNAL
+const gchar * g_settings_schema_get_string (GSettingsSchema *schema,
+ const gchar *key);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]