Clean up GSettingsSchema logic

The way we created the global schema list predates
g_settings_schema_source_new_from_directory() and therefore doesn't use
it.

Update it to use that function, removing some code.

https://bugzilla.gnome.org/show_bug.cgi?id=668232
This commit is contained in:
Ryan Lortie 2013-10-26 18:49:58 -04:00
parent ba3103763d
commit e462eda3d5

View File

@ -176,6 +176,7 @@ G_DEFINE_BOXED_TYPE (GSettingsSchema, g_settings_schema, g_settings_schema_ref,
struct _GSettingsSchemaSource struct _GSettingsSchemaSource
{ {
GSettingsSchemaSource *parent; GSettingsSchemaSource *parent;
gchar *directory;
GvdbTable *table; GvdbTable *table;
gint ref_count; gint ref_count;
@ -183,20 +184,6 @@ struct _GSettingsSchemaSource
static GSettingsSchemaSource *schema_sources; static GSettingsSchemaSource *schema_sources;
static void
prepend_schema_table (GvdbTable *table)
{
GSettingsSchemaSource *source;
/* we steal the reference from 'schema_sources' for our ->parent */
source = g_slice_new (GSettingsSchemaSource);
source->parent = schema_sources;
source->table = table;
source->ref_count = 1;
schema_sources = source;
}
/** /**
* g_settings_schema_source_ref: * g_settings_schema_source_ref:
* @source: a #GSettingsSchemaSource * @source: a #GSettingsSchemaSource
@ -234,6 +221,7 @@ g_settings_schema_source_unref (GSettingsSchemaSource *source)
if (source->parent) if (source->parent)
g_settings_schema_source_unref (source->parent); g_settings_schema_source_unref (source->parent);
gvdb_table_unref (source->table); gvdb_table_unref (source->table);
g_free (source->directory);
g_slice_free (GSettingsSchemaSource, source); g_slice_free (GSettingsSchemaSource, source);
} }
@ -297,6 +285,7 @@ g_settings_schema_source_new_from_directory (const gchar *directory,
return NULL; return NULL;
source = g_slice_new (GSettingsSchemaSource); source = g_slice_new (GSettingsSchemaSource);
source->directory = g_strdup (directory);
source->parent = parent ? g_settings_schema_source_ref (parent) : NULL; source->parent = parent ? g_settings_schema_source_ref (parent) : NULL;
source->table = table; source->table = table;
source->ref_count = 1; source->ref_count = 1;
@ -304,6 +293,18 @@ g_settings_schema_source_new_from_directory (const gchar *directory,
return source; return source;
} }
static void
try_prepend_dir (const gchar *directory)
{
GSettingsSchemaSource *source;
source = g_settings_schema_source_new_from_directory (directory, schema_sources, TRUE, NULL);
/* If we successfully created it then prepend it to the global list */
if (source != NULL)
schema_sources = source;
}
static void static void
initialise_schema_sources (void) initialise_schema_sources (void)
{ {
@ -324,31 +325,15 @@ initialise_schema_sources (void)
while (i--) while (i--)
{ {
gchar *filename; gchar *dirname;
GvdbTable *table;
filename = g_build_filename (dirs[i], "glib-2.0", "schemas", "gschemas.compiled", NULL); dirname = g_build_filename (dirs[i], "glib-2.0", "schemas", NULL);
table = gvdb_table_new (filename, TRUE, NULL); try_prepend_dir (dirname);
g_free (dirname);
if (table != NULL)
prepend_schema_table (table);
g_free (filename);
} }
if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL) if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
{ try_prepend_dir (path);
gchar *filename;
GvdbTable *table;
filename = g_build_filename (path, "gschemas.compiled", NULL);
table = gvdb_table_new (filename, TRUE, NULL);
if (table != NULL)
prepend_schema_table (table);
g_free (filename);
}
g_once_init_leave (&initialised, TRUE); g_once_init_leave (&initialised, TRUE);
} }