[glib/new-gsettings] require explicit <child> in schemas
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/new-gsettings] require explicit <child> in schemas
- Date: Thu, 15 Apr 2010 01:37:49 +0000 (UTC)
commit 7b41a660dd3d622f39c7886aae43034cb6687f16
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Apr 14 21:20:45 2010 -0400
require explicit <child> in schemas
gio/gschema-compile.c | 22 ++++++++++++++++++++++
gio/gsettings.c | 23 +++++++++++++++++++----
2 files changed, 41 insertions(+), 4 deletions(-)
---
diff --git a/gio/gschema-compile.c b/gio/gschema-compile.c
index 0576ce8..f5d4796 100644
--- a/gio/gschema-compile.c
+++ b/gio/gschema-compile.c
@@ -111,6 +111,28 @@ start_element (GMarkupParseContext *context,
return;
}
+ else if (strcmp (element_name, "child") == 0)
+ {
+ const gchar *name, *schema;
+
+ if (COLLECT (STRING, "name", &name, STRING, "schema", &schema))
+ {
+ gchar *childname;
+
+ childname = g_strconcat (name, "/", NULL);
+
+ if (!g_hash_table_lookup (state->schema, childname))
+ gvdb_hash_table_insert_string (state->schema, childname, schema);
+
+ else
+ g_set_error (error, G_MARKUP_ERROR,
+ G_MARKUP_ERROR_INVALID_CONTENT,
+ "<child name='%s'> already specified", name);
+
+ g_free (childname);
+ return;
+ }
+ }
}
else if (strcmp (container, "key") == 0)
{
diff --git a/gio/gsettings.c b/gio/gsettings.c
index f08ee12..b6d577e 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -745,12 +745,27 @@ GSettings *
g_settings_get_child (GSettings *settings,
const gchar *name)
{
- gchar *child_schema;
+ GVariant *child_schema;
+ gchar *child_path;
+ gchar *child_name;
GSettings *child;
- child_schema = g_strconcat (settings->priv->schema_name, ".", name, NULL);
- child = g_object_new (G_TYPE_SETTINGS, "schema", child_schema, NULL);
- g_free (child_schema);
+ 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))
+ g_error ("Schema '%s' has no child '%s'\n",
+ settings->priv->schema_name, name);
+
+ child_path = g_strconcat (settings->priv->path, child_name, NULL);
+ child = g_object_new (G_TYPE_SETTINGS,
+ "schema", child_schema,
+ "path", child_path,
+ NULL);
+ g_variant_unref (child_schema);
+ g_free (child_path);
+ g_free (child_name);
return child;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]