Drop the 'schema_name' field of GSettings

This is strictly redundant now that we can get the ID from the schema
itself.  Its only other purpose was to get the schema name from the
set_property() call to the constructed() call and we can avoid that by
doing the schema lookup at the time of the property being set.
This commit is contained in:
Ryan Lortie 2011-11-15 11:56:18 +00:00
parent 48b99017de
commit c25a36c920

View File

@ -230,7 +230,6 @@ struct _GSettingsPrivate
GSettingsBackend *backend; GSettingsBackend *backend;
GSettingsSchema *schema; GSettingsSchema *schema;
gchar *schema_name;
gchar *path; gchar *path;
GDelayedSettingsBackend *delayed; GDelayedSettingsBackend *delayed;
@ -428,15 +427,31 @@ g_settings_set_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_SCHEMA_ID: case PROP_SCHEMA_ID:
/* we receive a set_property() call for both "schema" and {
* "schema-id", even if they are not set. Hopefully only one of const gchar *schema_id;
* them is non-NULL.
*/ schema_id = g_value_get_string (value);
if (g_value_get_string (value) != NULL)
{ /* we receive a set_property() call for both "schema" and
g_assert (settings->priv->schema_name == NULL); * "schema-id", even if they are not set. Hopefully only one of
settings->priv->schema_name = g_value_dup_string (value); * them is non-NULL.
} */
if (schema_id != NULL)
{
GSettingsSchemaSource *default_source;
g_assert (settings->priv->schema == NULL);
default_source = g_settings_schema_source_get_default ();
if (default_source == NULL)
g_error ("No GSettings schemas are installed on the system");
settings->priv->schema = g_settings_schema_source_lookup (default_source, schema_id, TRUE);
if (settings->priv->schema == NULL)
g_error ("Settings schema '%s' is not installed\n", schema_id);
}
}
break; break;
case PROP_PATH: case PROP_PATH:
@ -463,7 +478,7 @@ g_settings_get_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_SCHEMA_ID: case PROP_SCHEMA_ID:
g_value_set_string (value, settings->priv->schema_name); g_value_set_string (value, g_settings_schema_get_id (settings->priv->schema));
break; break;
case PROP_BACKEND: case PROP_BACKEND:
@ -499,31 +514,19 @@ static void
g_settings_constructed (GObject *object) g_settings_constructed (GObject *object)
{ {
GSettings *settings = G_SETTINGS (object); GSettings *settings = G_SETTINGS (object);
GSettingsSchemaSource *default_source;
const gchar *schema_path; const gchar *schema_path;
default_source = g_settings_schema_source_get_default ();
if (default_source == NULL)
g_error ("No GSettings schemas are installed on the system");
settings->priv->schema = g_settings_schema_source_lookup (default_source, settings->priv->schema_name, TRUE);
if (settings->priv->schema == NULL)
g_error ("Settings schema '%s' is not installed\n", settings->priv->schema_name);
schema_path = g_settings_schema_get_path (settings->priv->schema); schema_path = g_settings_schema_get_path (settings->priv->schema);
if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0) if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
g_error ("settings object created with schema '%s' and path '%s', but " g_error ("settings object created with schema '%s' and path '%s', but path '%s' is specified by schema",
"path '%s' is specified by schema", g_settings_schema_get_id (settings->priv->schema), settings->priv->path, schema_path);
settings->priv->schema_name, settings->priv->path, schema_path);
if (settings->priv->path == NULL) if (settings->priv->path == NULL)
{ {
if (schema_path == NULL) if (schema_path == NULL)
g_error ("attempting to create schema '%s' without a path", g_error ("attempting to create schema '%s' without a path",
settings->priv->schema_name); g_settings_schema_get_id (settings->priv->schema));
settings->priv->path = g_strdup (schema_path); settings->priv->path = g_strdup (schema_path);
} }
@ -548,7 +551,6 @@ g_settings_finalize (GObject *object)
g_main_context_unref (settings->priv->main_context); g_main_context_unref (settings->priv->main_context);
g_object_unref (settings->priv->backend); g_object_unref (settings->priv->backend);
g_settings_schema_unref (settings->priv->schema); g_settings_schema_unref (settings->priv->schema);
g_free (settings->priv->schema_name);
g_free (settings->priv->path); g_free (settings->priv->path);
G_OBJECT_CLASS (g_settings_parent_class)->finalize (object); G_OBJECT_CLASS (g_settings_parent_class)->finalize (object);
@ -1218,7 +1220,7 @@ g_settings_set_value (GSettings *settings,
{ {
g_critical ("g_settings_set_value: key '%s' in '%s' expects type '%s', but a GVariant of type '%s' was given", g_critical ("g_settings_set_value: key '%s' in '%s' expects type '%s', but a GVariant of type '%s' was given",
key, key,
settings->priv->schema_name, g_settings_schema_get_id (settings->priv->schema),
g_variant_type_peek_string (skey.type), g_variant_type_peek_string (skey.type),
g_variant_get_type_string (value)); g_variant_get_type_string (value));
@ -1230,7 +1232,7 @@ g_settings_set_value (GSettings *settings,
g_warning ("g_settings_set_value: value for key '%s' in schema '%s' " g_warning ("g_settings_set_value: value for key '%s' in schema '%s' "
"is outside of valid range", "is outside of valid range",
key, key,
settings->priv->schema_name); g_settings_schema_get_id (settings->priv->schema));
return FALSE; return FALSE;
} }
@ -1386,7 +1388,7 @@ g_settings_get_mapped (GSettings *settings,
if (!mapping (NULL, &result, user_data)) if (!mapping (NULL, &result, user_data))
g_error ("The mapping function given to g_settings_get_mapped() for key " g_error ("The mapping function given to g_settings_get_mapped() for key "
"`%s' in schema `%s' returned FALSE when given a NULL value.", "`%s' in schema `%s' returned FALSE when given a NULL value.",
key, settings->priv->schema_name); key, g_settings_schema_get_id (settings->priv->schema));
okay: okay:
g_settings_schema_key_clear (&skey); g_settings_schema_key_clear (&skey);
@ -1928,7 +1930,7 @@ g_settings_get_child (GSettings *settings,
child_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'",
settings->priv->schema_name, 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, child_name, NULL);
child = g_object_new (G_TYPE_SETTINGS, child = g_object_new (G_TYPE_SETTINGS,
@ -2500,7 +2502,7 @@ g_settings_bind_with_mapping (GSettings *settings,
{ {
g_critical ("g_settings_bind: G_SETTINGS_BIND_INVERT_BOOLEAN " g_critical ("g_settings_bind: G_SETTINGS_BIND_INVERT_BOOLEAN "
"was specified, but key `%s' on schema `%s' has " "was specified, but key `%s' on schema `%s' has "
"type `%s'", key, settings->priv->schema_name, "type `%s'", key, g_settings_schema_get_id (settings->priv->schema),
g_variant_type_dup_string (binding->key.type)); g_variant_type_dup_string (binding->key.type));
return; return;
} }
@ -2517,7 +2519,7 @@ g_settings_bind_with_mapping (GSettings *settings,
"on schema '%s'", property, G_OBJECT_TYPE_NAME (object), "on schema '%s'", property, G_OBJECT_TYPE_NAME (object),
g_type_name (binding->property->value_type), g_type_name (binding->property->value_type),
g_variant_type_dup_string (binding->key.type), key, g_variant_type_dup_string (binding->key.type), key,
settings->priv->schema_name); g_settings_schema_get_id (settings->priv->schema));
return; return;
} }