Struct gio::SettingsSchema
source · pub struct SettingsSchema { /* private fields */ }
Expand description
The SettingsSchemaSource
and SettingsSchema
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.
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:
⚠️ The following code is in C ⚠️
typedef struct
{
...
GSettingsSchemaSource *schema_source;
...
} Plugin;
Plugin *
initialise_plugin (const gchar *dir)
{
Plugin *plugin;
...
plugin->schema_source =
g_settings_schema_source_new_from_directory (dir,
g_settings_schema_source_get_default (), FALSE, NULL);
...
return plugin;
}
...
GSettings *
plugin_get_settings (Plugin *plugin,
const gchar *schema_id)
{
GSettingsSchema *schema;
if (schema_id == NULL)
schema_id = plugin->identifier;
schema = g_settings_schema_source_lookup (plugin->schema_source,
schema_id, FALSE);
if (schema == NULL)
{
... disable the plugin or abort, etc ...
}
return g_settings_new_full (schema, NULL, NULL);
}
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:
⚠️ The following code is in C ⚠️
{
GSettings *settings;
gint some_value;
settings = plugin_get_settings (self, NULL);
some_value = g_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 a gschemas.compiled file. In that case, the plugin loading system must compile the schemas for itself before attempting to create the settings source.
Implementations§
source§impl SettingsSchema
impl SettingsSchema
sourcepub fn as_ptr(&self) -> *mut GSettingsSchema
pub fn as_ptr(&self) -> *mut GSettingsSchema
Return the inner pointer to the underlying C value.
sourcepub unsafe fn from_glib_ptr_borrow<'a>(
ptr: *const *const GSettingsSchema
) -> &'a Self
pub unsafe fn from_glib_ptr_borrow<'a>( ptr: *const *const GSettingsSchema ) -> &'a Self
Borrows the underlying C value.
source§impl SettingsSchema
impl SettingsSchema
sourcepub fn key(&self, name: &str) -> SettingsSchemaKey
pub fn key(&self, name: &str) -> SettingsSchemaKey
Gets the key named name
from self
.
It is a programmer error to request a key that does not exist. See
list_keys()
.
name
the name of a key
Returns
the SettingsSchemaKey
for name
sourcepub fn path(&self) -> Option<GString>
pub fn path(&self) -> Option<GString>
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
.
Returns
the path of the schema, or None
sourcepub fn list_children(&self) -> Vec<GString>
pub fn list_children(&self) -> Vec<GString>
Gets the list of children in self
.
You should free the return value with g_strfreev()
when you are done
with it.
Returns
a list of
the children on settings
, in no defined order
sourcepub fn list_keys(&self) -> Vec<GString>
pub fn list_keys(&self) -> Vec<GString>
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.
Returns
a list
of the keys on self
, in no defined order
Trait Implementations§
source§impl Clone for SettingsSchema
impl Clone for SettingsSchema
source§impl Debug for SettingsSchema
impl Debug for SettingsSchema
source§impl From<SettingsSchema> for Value
impl From<SettingsSchema> for Value
source§fn from(s: SettingsSchema) -> Self
fn from(s: SettingsSchema) -> Self
source§impl HasParamSpec for SettingsSchema
impl HasParamSpec for SettingsSchema
type ParamSpec = ParamSpecBoxed
§type SetValue = SettingsSchema
type SetValue = SettingsSchema
type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, SettingsSchema>
fn param_spec_builder() -> Self::BuilderFn
source§impl Hash for SettingsSchema
impl Hash for SettingsSchema
source§impl Ord for SettingsSchema
impl Ord for SettingsSchema
source§fn cmp(&self, other: &SettingsSchema) -> Ordering
fn cmp(&self, other: &SettingsSchema) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for SettingsSchema
impl PartialEq for SettingsSchema
source§fn eq(&self, other: &SettingsSchema) -> bool
fn eq(&self, other: &SettingsSchema) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for SettingsSchema
impl PartialOrd for SettingsSchema
source§fn partial_cmp(&self, other: &SettingsSchema) -> Option<Ordering>
fn partial_cmp(&self, other: &SettingsSchema) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl StaticType for SettingsSchema
impl StaticType for SettingsSchema
source§fn static_type() -> Type
fn static_type() -> Type
Self
.