SettingsSchema

The GSettingsSchemaSource and GSettingsSchema APIs provide a mechanism for advanced control over the loading of schemas and a mechanism for introspecting their content.

Plugin loading systems that wish to provide plugins a way to access settings face the problem of how to make the schemas for these settings visible to GSettings. Typically, a plugin will want to ship the schema along with itself and it won't be installed into the standard system directories for schemas.

GSettingsSchemaSource provides a mechanism for dealing with this by allowing the creation of a new 'schema source' from which schemas can be acquired. This schema source can then become part of the metadata associated with the plugin and queried whenever the plugin requires access to some settings.

Consider the following example:

1 
2 typedef struct
3 {
4 ...
5 GSettingsSchemaSource *schema_source;
6 ...
7 } Plugin;
8 
9 Plugin *
10 initialise_plugin (const gchar *dir)
11 {
12 Plugin *plugin;
13 
14 ...
15 
16 plugin->schema_source =
17 g_settings_schema_source_new_from_directory (dir,
18 g_settings_schema_source_get_default (), FALSE, NULL);
19 
20 ...
21 
22 return plugin;
23 }
24 
25 ...
26 
27 GSettings *
28 plugin_get_settings (Plugin      *plugin,
29 const gchar *schema_id)
30 {
31 GSettingsSchema *schema;
32 
33 if (schema_id == NULL)
34 schema_id = plugin->identifier;
35 
36 schema = g_settings_schema_source_lookup (plugin->schema_source,
37 schema_id, FALSE);
38 
39 if (schema == NULL)
40 {
41 ... disable the plugin or abort, etc ...
42 }
43 
44 return g_settings_new_full (schema, NULL, NULL);
45 }

The code above shows how hooks should be added to the code that initialises (or enables) the plugin to create the schema source and how an API can be added to the plugin system to provide a convenient way for the plugin to access its settings, using the schemas that it ships.

From the standpoint of the plugin, it would need to ensure that it ships a gschemas.compiled file as part of itself, and then simply do the following:

1 
2 {
3 GSettings *settings;
4 gint some_value;
5 
6 settings = plugin_get_settings (self, NULL);
7 some_value = g_settings_get_int (settings, "some-value");
8 ...
9 }

It's also possible that the plugin system expects the schema source files (ie: .gschema.xml files) instead of a gschemas.compiled file. In that case, the plugin loading system must compile the schemas for itself before attempting to create the settings source.

Constructors

this
this(GSettingsSchema* gSettingsSchema, bool ownedRef = false)

Sets our main struct and passes it to the parent class.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

getId
string getId()

Get the ID of schema.

getKey
SettingsSchemaKey getKey(string name)

Gets the key named name from schema.

getPath
string getPath()

Gets the path associated with schema, or NULL.

getSettingsSchemaStruct
GSettingsSchema* getSettingsSchemaStruct(bool transferOwnership = false)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

hasKey
bool hasKey(string name)

Checks if schema has a key named name.

listChildren
string[] listChildren()

Gets the list of children in schema.

listKeys
string[] listKeys()

Introspects the list of keys on schema.

ref_
SettingsSchema ref_()

Increase the reference count of schema, returning a new reference.

unref
void unref()

Decrease the reference count of schema, possibly freeing it.

Static functions

getType
GType getType()

Variables

gSettingsSchema
GSettingsSchema* gSettingsSchema;

the main Gtk struct

Meta

Since

2.32