Gio.SettingsSchema¶
Fields¶
None
Methods¶
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class Gio.SettingsSchema¶
The [struct`Gio`.SettingsSchemaSource] 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
Gio.Settings
. 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.[struct`Gio`.SettingsSchemaSource] 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:
```c typedef struct { …
Gio.SettingsSchemaSource
*schema_source; … } Plugin;Plugin * initialise_plugin (const
str
*dir) { Plugin *plugin;…
plugin->schema_source =
Gio.SettingsSchemaSource.new_from_directory
(dir,Gio.SettingsSchemaSource.get_default
(),False
,None
);…
return plugin; }
…
Gio.Settings
* plugin_get_settings (Plugin *plugin, conststr
*schema_id) {Gio.SettingsSchema
*schema;if (schema_id ==
None
) schema_id = plugin->identifier;schema =
Gio.SettingsSchemaSource.lookup
(plugin->schema_source, schema_id,False
);if (schema ==
None
) { … disable the plugin or abort, etc … }return
Gio.Settings.new_full
(schema,None
,None
); } ```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:
```c {
Gio.Settings
*settings;int
some_value;settings = plugin_get_settings (self,
None
); some_value =Gio.Settings.get_int
(settings, “some-value”); … } ```It’s also possible that the plugin system expects the schema source files (ie:
.gschema.xml
files) instead of agschemas.compiled
file. In that case, the plugin loading system must compile the schemas for itself before attempting to create the settings source.New in version 2.32.
- get_key(name)[source]¶
- Parameters:
name (
str
) – the name of a key- Returns:
the
Gio.SettingsSchemaKey
for name- Return type:
Gets the key named name from self.
It is a programmer error to request a key that does not exist. See
Gio.SettingsSchema.list_keys
().New in version 2.40.
- get_path()[source]¶
-
Gets the path associated with self, or
None
.Schemas may be single-instance or relocatable. Single-instance schemas correspond to exactly one set of keys in the backend database: those located at the path returned by this function.
Relocatable schemas can be referenced by other schemas and can therefore describe multiple sets of keys at different locations. For relocatable schemas, this function will return
None
.New in version 2.32.
- list_children()[source]¶
- Returns:
a list of the children on settings, in no defined order
- Return type:
[
str
]
Gets the list of children in self.
You should free the return value with
GLib.strfreev
() when you are done with it.New in version 2.44.
- list_keys()[source]¶
- Returns:
a list of the keys on self, in no defined order
- Return type:
[
str
]
Introspects the list of keys on self.
You should probably not be calling this function from “normal” code (since you should already know what keys are in your schema). This function is intended for introspection reasons.
New in version 2.46.