Skip to main content

gio/auto/
settings_schema.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{SettingsSchemaKey, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// schema_source,
10    ///                                             schema_id, FALSE);
11    ///
12    ///   if (schema == NULL)
13    ///     {
14    ///       … disable the plugin or abort, etc …
15    ///     }
16    ///
17    ///   return g_settings_new_full (schema, NULL, NULL);
18    /// }
19    /// ```text
20    ///
21    /// The code above shows how hooks should be added to the code that
22    /// initialises (or enables) the plugin to create the schema source and
23    /// how an API can be added to the plugin system to provide a convenient
24    /// way for the plugin to access its settings, using the schemas that it
25    /// ships.
26    ///
27    /// From the standpoint of the plugin, it would need to ensure that it
28    /// ships a gschemas.compiled file as part of itself, and then simply do
29    /// the following:
30    ///
31    /// ```c
32    /// {
33    ///   GSettings *settings;
34    ///   gint some_value;
35    ///
36    ///   settings = plugin_get_settings (self, NULL);
37    ///   some_value = g_settings_get_int (settings, "some-value");
38    ///   …
39    /// }
40    /// ```text
41    ///
42    /// It's also possible that the plugin system expects the schema source
43    /// files (ie: `.gschema.xml` files) instead of a `gschemas.compiled` file.
44    /// In that case, the plugin loading system must compile the schemas for
45    /// itself before attempting to create the settings source.
46    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
47    pub struct SettingsSchema(Shared<ffi::GSettingsSchema>);
48
49    match fn {
50        ref => |ptr| ffi::g_settings_schema_ref(ptr),
51        unref => |ptr| ffi::g_settings_schema_unref(ptr),
52        type_ => || ffi::g_settings_schema_get_type(),
53    }
54}
55
56impl SettingsSchema {
57    /// Get the ID of @self.
58    ///
59    /// # Returns
60    ///
61    /// the ID
62    #[doc(alias = "g_settings_schema_get_id")]
63    #[doc(alias = "get_id")]
64    pub fn id(&self) -> glib::GString {
65        unsafe { from_glib_none(ffi::g_settings_schema_get_id(self.to_glib_none().0)) }
66    }
67
68    /// Gets the key named @name from @self.
69    ///
70    /// It is a programmer error to request a key that does not exist.  See
71    /// g_settings_schema_list_keys().
72    /// ## `name`
73    /// the name of a key
74    ///
75    /// # Returns
76    ///
77    /// the #GSettingsSchemaKey for @name
78    #[doc(alias = "g_settings_schema_get_key")]
79    #[doc(alias = "get_key")]
80    pub fn key(&self, name: &str) -> SettingsSchemaKey {
81        unsafe {
82            from_glib_full(ffi::g_settings_schema_get_key(
83                self.to_glib_none().0,
84                name.to_glib_none().0,
85            ))
86        }
87    }
88
89    /// Gets the path associated with @self, or [`None`].
90    ///
91    /// Schemas may be single-instance or relocatable.  Single-instance
92    /// schemas correspond to exactly one set of keys in the backend
93    /// database: those located at the path returned by this function.
94    ///
95    /// Relocatable schemas can be referenced by other schemas and can
96    /// therefore describe multiple sets of keys at different locations.  For
97    /// relocatable schemas, this function will return [`None`].
98    ///
99    /// # Returns
100    ///
101    /// the path of the schema, or [`None`]
102    #[doc(alias = "g_settings_schema_get_path")]
103    #[doc(alias = "get_path")]
104    pub fn path(&self) -> Option<glib::GString> {
105        unsafe { from_glib_none(ffi::g_settings_schema_get_path(self.to_glib_none().0)) }
106    }
107
108    /// Checks if @self has a key named @name.
109    /// ## `name`
110    /// the name of a key
111    ///
112    /// # Returns
113    ///
114    /// [`true`] if such a key exists
115    #[doc(alias = "g_settings_schema_has_key")]
116    pub fn has_key(&self, name: &str) -> bool {
117        unsafe {
118            from_glib(ffi::g_settings_schema_has_key(
119                self.to_glib_none().0,
120                name.to_glib_none().0,
121            ))
122        }
123    }
124
125    /// Gets the list of children in @self.
126    ///
127    /// You should free the return value with g_strfreev() when you are done
128    /// with it.
129    ///
130    /// # Returns
131    ///
132    /// a list of
133    ///    the children on @settings, in no defined order
134    #[doc(alias = "g_settings_schema_list_children")]
135    pub fn list_children(&self) -> Vec<glib::GString> {
136        unsafe {
137            FromGlibPtrContainer::from_glib_full(ffi::g_settings_schema_list_children(
138                self.to_glib_none().0,
139            ))
140        }
141    }
142
143    /// Introspects the list of keys on @self.
144    ///
145    /// You should probably not be calling this function from "normal" code
146    /// (since you should already know what keys are in your schema).  This
147    /// function is intended for introspection reasons.
148    ///
149    /// # Returns
150    ///
151    /// a list
152    ///   of the keys on @self, in no defined order
153    #[doc(alias = "g_settings_schema_list_keys")]
154    pub fn list_keys(&self) -> Vec<glib::GString> {
155        unsafe {
156            FromGlibPtrContainer::from_glib_full(ffi::g_settings_schema_list_keys(
157                self.to_glib_none().0,
158            ))
159        }
160    }
161}