require explicit <child> in schemas

This commit is contained in:
Ryan Lortie
2010-04-14 21:20:45 -04:00
parent 9d22ef333b
commit 7b41a660dd
2 changed files with 41 additions and 4 deletions

View File

@@ -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)
{

View File

@@ -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;
}