mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
Merge branch 'wip/issue-1884' into 'master'
gsettings: Resolve child schemas from the parent's schema source Closes #1884 See merge request GNOME/glib!2132
This commit is contained in:
commit
205045e5c7
@ -2434,28 +2434,24 @@ GSettings *
|
|||||||
g_settings_get_child (GSettings *settings,
|
g_settings_get_child (GSettings *settings,
|
||||||
const gchar *name)
|
const gchar *name)
|
||||||
{
|
{
|
||||||
const gchar *child_schema;
|
GSettingsSchema *child_schema;
|
||||||
gchar *child_path;
|
gchar *child_path;
|
||||||
gchar *child_name;
|
|
||||||
GSettings *child;
|
GSettings *child;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
|
g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
|
||||||
|
|
||||||
child_name = g_strconcat (name, "/", NULL);
|
child_schema = g_settings_schema_get_child_schema (settings->priv->schema,
|
||||||
child_schema = g_settings_schema_get_string (settings->priv->schema,
|
name);
|
||||||
child_name);
|
|
||||||
if (child_schema == NULL)
|
if (child_schema == NULL)
|
||||||
g_error ("Schema '%s' has no child '%s'",
|
g_error ("Schema '%s' has no child '%s' or child schema not found",
|
||||||
g_settings_schema_get_id (settings->priv->schema), name);
|
g_settings_schema_get_id (settings->priv->schema), name);
|
||||||
|
|
||||||
child_path = g_strconcat (settings->priv->path, child_name, NULL);
|
child_path = g_strconcat (settings->priv->path, name, "/", NULL);
|
||||||
child = g_object_new (G_TYPE_SETTINGS,
|
child = g_settings_new_full (child_schema,
|
||||||
"backend", settings->priv->backend,
|
settings->priv->backend,
|
||||||
"schema-id", child_schema,
|
child_path);
|
||||||
"path", child_path,
|
g_settings_schema_unref (child_schema);
|
||||||
NULL);
|
|
||||||
g_free (child_path);
|
g_free (child_path);
|
||||||
g_free (child_name);
|
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,9 @@ const GQuark * g_settings_schema_list (GSettin
|
|||||||
const gchar * g_settings_schema_get_string (GSettingsSchema *schema,
|
const gchar * g_settings_schema_get_string (GSettingsSchema *schema,
|
||||||
const gchar *key);
|
const gchar *key);
|
||||||
|
|
||||||
|
GSettingsSchema * g_settings_schema_get_child_schema (GSettingsSchema *schema,
|
||||||
|
const gchar *name);
|
||||||
|
|
||||||
void g_settings_schema_key_init (GSettingsSchemaKey *key,
|
void g_settings_schema_key_init (GSettingsSchemaKey *key,
|
||||||
GSettingsSchema *schema,
|
GSettingsSchema *schema,
|
||||||
const gchar *name);
|
const gchar *name);
|
||||||
|
@ -968,6 +968,24 @@ g_settings_schema_get_string (GSettingsSchema *schema,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GSettingsSchema *
|
||||||
|
g_settings_schema_get_child_schema (GSettingsSchema *schema,
|
||||||
|
const gchar *name)
|
||||||
|
{
|
||||||
|
const gchar *child_id;
|
||||||
|
gchar *child_name;
|
||||||
|
|
||||||
|
child_name = g_strconcat (name, "/", NULL);
|
||||||
|
child_id = g_settings_schema_get_string (schema, child_name);
|
||||||
|
|
||||||
|
g_free (child_name);
|
||||||
|
|
||||||
|
if (child_id == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return g_settings_schema_source_lookup (schema->source, child_id, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
GVariantIter *
|
GVariantIter *
|
||||||
g_settings_schema_get_value (GSettingsSchema *schema,
|
g_settings_schema_get_value (GSettingsSchema *schema,
|
||||||
const gchar *key)
|
const gchar *key)
|
||||||
|
@ -2572,7 +2572,7 @@ test_schema_source (void)
|
|||||||
GSettingsBackend *backend;
|
GSettingsBackend *backend;
|
||||||
GSettingsSchema *schema;
|
GSettingsSchema *schema;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GSettings *settings;
|
GSettings *settings, *child;
|
||||||
gboolean enabled;
|
gboolean enabled;
|
||||||
|
|
||||||
backend = g_settings_backend_get_default ();
|
backend = g_settings_backend_get_default ();
|
||||||
@ -2628,13 +2628,18 @@ test_schema_source (void)
|
|||||||
g_assert_nonnull (schema);
|
g_assert_nonnull (schema);
|
||||||
|
|
||||||
/* try to use it for something */
|
/* try to use it for something */
|
||||||
settings = g_settings_new_full (schema, backend, g_settings_schema_get_path (schema));
|
settings = g_settings_new_full (schema, backend, "/test/");
|
||||||
g_settings_schema_unref (schema);
|
g_settings_schema_unref (schema);
|
||||||
enabled = FALSE;
|
enabled = FALSE;
|
||||||
g_settings_get (settings, "enabled", "b", &enabled);
|
g_settings_get (settings, "enabled", "b", &enabled);
|
||||||
g_assert_true (enabled);
|
g_assert_true (enabled);
|
||||||
g_object_unref (settings);
|
|
||||||
|
|
||||||
|
/* Check that child schemas are resolved from the correct schema source, see glib#1884 */
|
||||||
|
child = g_settings_get_child (settings, "child");
|
||||||
|
g_settings_get (settings, "enabled", "b", &enabled);
|
||||||
|
|
||||||
|
g_object_unref (child);
|
||||||
|
g_object_unref (settings);
|
||||||
g_settings_schema_source_unref (source);
|
g_settings_schema_source_unref (source);
|
||||||
|
|
||||||
/* try again, but with no parent */
|
/* try again, but with no parent */
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<schemalist>
|
<schemalist>
|
||||||
<schema id="org.gtk.schemasourcecheck" path="/tests/">
|
<schema id="org.gtk.schemasourcecheck">
|
||||||
<key name="enabled" type="b">
|
<key name="enabled" type="b">
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
</key>
|
</key>
|
||||||
|
<child name="child" schema="org.gtk.schemasourcecheck" />
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
|
Loading…
Reference in New Issue
Block a user