GSettings: store (default, options) in gvdb
authorRyan Lortie <desrt@desrt.ca>
Thu, 10 Jun 2010 17:49:57 +0000 (13:49 -0400)
committerRyan Lortie <desrt@desrt.ca>
Thu, 10 Jun 2010 17:49:57 +0000 (13:49 -0400)
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
gio/gsettings.c
gio/gsettingsschema.c
gio/gsettingsschema.h

index 95f75822b95cf1efef0f17c61de6eb9d52c0fbbd..f462a7bf2c9e3f66119e505ec0bd56c363ce3a46 100644 (file)
@@ -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;
     }
 
index 6ad842a03f1b6898c8e9f21a0ef123b02ae0394c..01db482431f27d1c289929fd422dbbe1efd93e56 100644 (file)
@@ -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);
 
index af2c7d8fe78cd28020770ee7eada9af45c4547b1..c0fbf17943fbf34f9ced01957f2a130de208103e 100644 (file)
@@ -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 *
index f57b01582fc5ea8841e5d46e5cb9f0d1219ea1b4..9ac86a996722dbddd929f0dfec33710613c1ffd7 100644 (file)
@@ -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