gio/auto/
settings_schema_source.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::{ffi, SettingsSchema};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// This is an opaque structure type.  You may not access it directly.
10    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
11    pub struct SettingsSchemaSource(Shared<ffi::GSettingsSchemaSource>);
12
13    match fn {
14        ref => |ptr| ffi::g_settings_schema_source_ref(ptr),
15        unref => |ptr| ffi::g_settings_schema_source_unref(ptr),
16        type_ => || ffi::g_settings_schema_source_get_type(),
17    }
18}
19
20impl SettingsSchemaSource {
21    /// Attempts to create a new schema source corresponding to the contents
22    /// of the given directory.
23    ///
24    /// This function is not required for normal uses of #GSettings but it
25    /// may be useful to authors of plugin management systems.
26    ///
27    /// The directory should contain a file called `gschemas.compiled` as
28    /// produced by the [glib-compile-schemas][glib-compile-schemas] tool.
29    ///
30    /// If @trusted is [`true`] then `gschemas.compiled` is trusted not to be
31    /// corrupted. This assumption has a performance advantage, but can result
32    /// in crashes or inconsistent behaviour in the case of a corrupted file.
33    /// Generally, you should set @trusted to [`true`] for files installed by the
34    /// system and to [`false`] for files in the home directory.
35    ///
36    /// In either case, an empty file or some types of corruption in the file will
37    /// result in `G_FILE_ERROR_INVAL` being returned.
38    ///
39    /// If @parent is non-[`None`] then there are two effects.
40    ///
41    /// First, if g_settings_schema_source_lookup() is called with the
42    /// @recursive flag set to [`true`] and the schema can not be found in the
43    /// source, the lookup will recurse to the parent.
44    ///
45    /// Second, any references to other schemas specified within this
46    /// source (ie: `child` or `extends`) references may be resolved
47    /// from the @parent.
48    ///
49    /// For this second reason, except in very unusual situations, the
50    /// @parent should probably be given as the default schema source, as
51    /// returned by g_settings_schema_source_get_default().
52    /// ## `directory`
53    /// the filename of a directory
54    /// ## `parent`
55    /// a #GSettingsSchemaSource, or [`None`]
56    /// ## `trusted`
57    /// [`true`], if the directory is trusted
58    #[doc(alias = "g_settings_schema_source_new_from_directory")]
59    #[doc(alias = "new_from_directory")]
60    pub fn from_directory(
61        directory: impl AsRef<std::path::Path>,
62        parent: Option<&SettingsSchemaSource>,
63        trusted: bool,
64    ) -> Result<SettingsSchemaSource, glib::Error> {
65        unsafe {
66            let mut error = std::ptr::null_mut();
67            let ret = ffi::g_settings_schema_source_new_from_directory(
68                directory.as_ref().to_glib_none().0,
69                parent.to_glib_none().0,
70                trusted.into_glib(),
71                &mut error,
72            );
73            if error.is_null() {
74                Ok(from_glib_full(ret))
75            } else {
76                Err(from_glib_full(error))
77            }
78        }
79    }
80
81    /// Lists the schemas in a given source.
82    ///
83    /// If @recursive is [`true`] then include parent sources.  If [`false`] then
84    /// only include the schemas from one source (ie: one directory).  You
85    /// probably want [`true`].
86    ///
87    /// Non-relocatable schemas are those for which you can call
88    /// g_settings_new().  Relocatable schemas are those for which you must
89    /// use g_settings_new_with_path().
90    ///
91    /// Do not call this function from normal programs.  This is designed for
92    /// use by database editors, commandline tools, etc.
93    /// ## `recursive`
94    /// if we should recurse
95    ///
96    /// # Returns
97    ///
98    ///
99    /// ## `non_relocatable`
100    /// the
101    ///   list of non-relocatable schemas, in no defined order
102    ///
103    /// ## `relocatable`
104    /// the list
105    ///   of relocatable schemas, in no defined order
106    #[doc(alias = "g_settings_schema_source_list_schemas")]
107    pub fn list_schemas(&self, recursive: bool) -> (Vec<glib::GString>, Vec<glib::GString>) {
108        unsafe {
109            let mut non_relocatable = std::ptr::null_mut();
110            let mut relocatable = std::ptr::null_mut();
111            ffi::g_settings_schema_source_list_schemas(
112                self.to_glib_none().0,
113                recursive.into_glib(),
114                &mut non_relocatable,
115                &mut relocatable,
116            );
117            (
118                FromGlibPtrContainer::from_glib_full(non_relocatable),
119                FromGlibPtrContainer::from_glib_full(relocatable),
120            )
121        }
122    }
123
124    /// Looks up a schema with the identifier @schema_id in @self.
125    ///
126    /// This function is not required for normal uses of #GSettings but it
127    /// may be useful to authors of plugin management systems or to those who
128    /// want to introspect the content of schemas.
129    ///
130    /// If the schema isn't found directly in @self and @recursive is [`true`]
131    /// then the parent sources will also be checked.
132    ///
133    /// If the schema isn't found, [`None`] is returned.
134    /// ## `schema_id`
135    /// a schema ID
136    /// ## `recursive`
137    /// [`true`] if the lookup should be recursive
138    ///
139    /// # Returns
140    ///
141    /// a new #GSettingsSchema
142    #[doc(alias = "g_settings_schema_source_lookup")]
143    pub fn lookup(&self, schema_id: &str, recursive: bool) -> Option<SettingsSchema> {
144        unsafe {
145            from_glib_full(ffi::g_settings_schema_source_lookup(
146                self.to_glib_none().0,
147                schema_id.to_glib_none().0,
148                recursive.into_glib(),
149            ))
150        }
151    }
152
153    /// Gets the default system schema source.
154    ///
155    /// This function is not required for normal uses of #GSettings but it
156    /// may be useful to authors of plugin management systems or to those who
157    /// want to introspect the content of schemas.
158    ///
159    /// If no schemas are installed, [`None`] will be returned.
160    ///
161    /// The returned source may actually consist of multiple schema sources
162    /// from different directories, depending on which directories were given
163    /// in `XDG_DATA_DIRS` and `GSETTINGS_SCHEMA_DIR`. For this reason, all
164    /// lookups performed against the default source should probably be done
165    /// recursively.
166    ///
167    /// # Returns
168    ///
169    /// the default schema source
170    #[doc(alias = "g_settings_schema_source_get_default")]
171    #[doc(alias = "get_default")]
172    #[allow(clippy::should_implement_trait)]
173    pub fn default() -> Option<SettingsSchemaSource> {
174        unsafe { from_glib_none(ffi::g_settings_schema_source_get_default()) }
175    }
176}