1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::SettingsSchema;
use glib::translate::*;
use std::ptr;

glib::wrapper! {
    /// This is an opaque structure type. You may not access it directly.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct SettingsSchemaSource(Shared<ffi::GSettingsSchemaSource>);

    match fn {
        ref => |ptr| ffi::g_settings_schema_source_ref(ptr),
        unref => |ptr| ffi::g_settings_schema_source_unref(ptr),
        type_ => || ffi::g_settings_schema_source_get_type(),
    }
}

impl SettingsSchemaSource {
    /// Attempts to create a new schema source corresponding to the contents
    /// of the given directory.
    ///
    /// This function is not required for normal uses of [`Settings`][crate::Settings] but it
    /// may be useful to authors of plugin management systems.
    ///
    /// The directory should contain a file called `gschemas.compiled` as
    /// produced by the [glib-compile-schemas][glib-compile-schemas] tool.
    ///
    /// If `trusted` is [`true`] then `gschemas.compiled` is trusted not to be
    /// corrupted. This assumption has a performance advantage, but can result
    /// in crashes or inconsistent behaviour in the case of a corrupted file.
    /// Generally, you should set `trusted` to [`true`] for files installed by the
    /// system and to [`false`] for files in the home directory.
    ///
    /// In either case, an empty file or some types of corruption in the file will
    /// result in `G_FILE_ERROR_INVAL` being returned.
    ///
    /// If `parent` is non-[`None`] then there are two effects.
    ///
    /// First, if [`lookup()`][Self::lookup()] is called with the
    /// `recursive` flag set to [`true`] and the schema can not be found in the
    /// source, the lookup will recurse to the parent.
    ///
    /// Second, any references to other schemas specified within this
    /// source (ie: `child` or `extends`) references may be resolved
    /// from the `parent`.
    ///
    /// For this second reason, except in very unusual situations, the
    /// `parent` should probably be given as the default schema source, as
    /// returned by [`default()`][Self::default()].
    /// ## `directory`
    /// the filename of a directory
    /// ## `parent`
    /// a [`SettingsSchemaSource`][crate::SettingsSchemaSource], or [`None`]
    /// ## `trusted`
    /// [`true`], if the directory is trusted
    #[doc(alias = "g_settings_schema_source_new_from_directory")]
    #[doc(alias = "new_from_directory")]
    pub fn from_directory(
        directory: impl AsRef<std::path::Path>,
        parent: Option<&SettingsSchemaSource>,
        trusted: bool,
    ) -> Result<SettingsSchemaSource, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::g_settings_schema_source_new_from_directory(
                directory.as_ref().to_glib_none().0,
                parent.to_glib_none().0,
                trusted.into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Lists the schemas in a given source.
    ///
    /// If `recursive` is [`true`] then include parent sources. If [`false`] then
    /// only include the schemas from one source (ie: one directory). You
    /// probably want [`true`].
    ///
    /// Non-relocatable schemas are those for which you can call
    /// [`Settings::new()`][crate::Settings::new()]. Relocatable schemas are those for which you must
    /// use [`Settings::with_path()`][crate::Settings::with_path()].
    ///
    /// Do not call this function from normal programs. This is designed for
    /// use by database editors, commandline tools, etc.
    /// ## `recursive`
    /// if we should recurse
    ///
    /// # Returns
    ///
    ///
    /// ## `non_relocatable`
    /// the
    ///  list of non-relocatable schemas, in no defined order
    ///
    /// ## `relocatable`
    /// the list
    ///  of relocatable schemas, in no defined order
    #[doc(alias = "g_settings_schema_source_list_schemas")]
    pub fn list_schemas(&self, recursive: bool) -> (Vec<glib::GString>, Vec<glib::GString>) {
        unsafe {
            let mut non_relocatable = ptr::null_mut();
            let mut relocatable = ptr::null_mut();
            ffi::g_settings_schema_source_list_schemas(
                self.to_glib_none().0,
                recursive.into_glib(),
                &mut non_relocatable,
                &mut relocatable,
            );
            (
                FromGlibPtrContainer::from_glib_full(non_relocatable),
                FromGlibPtrContainer::from_glib_full(relocatable),
            )
        }
    }

    /// Looks up a schema with the identifier `schema_id` in `self`.
    ///
    /// This function is not required for normal uses of [`Settings`][crate::Settings] but it
    /// may be useful to authors of plugin management systems or to those who
    /// want to introspect the content of schemas.
    ///
    /// If the schema isn't found directly in `self` and `recursive` is [`true`]
    /// then the parent sources will also be checked.
    ///
    /// If the schema isn't found, [`None`] is returned.
    /// ## `schema_id`
    /// a schema ID
    /// ## `recursive`
    /// [`true`] if the lookup should be recursive
    ///
    /// # Returns
    ///
    /// a new [`SettingsSchema`][crate::SettingsSchema]
    #[doc(alias = "g_settings_schema_source_lookup")]
    pub fn lookup(&self, schema_id: &str, recursive: bool) -> Option<SettingsSchema> {
        unsafe {
            from_glib_full(ffi::g_settings_schema_source_lookup(
                self.to_glib_none().0,
                schema_id.to_glib_none().0,
                recursive.into_glib(),
            ))
        }
    }

    /// Gets the default system schema source.
    ///
    /// This function is not required for normal uses of [`Settings`][crate::Settings] but it
    /// may be useful to authors of plugin management systems or to those who
    /// want to introspect the content of schemas.
    ///
    /// If no schemas are installed, [`None`] will be returned.
    ///
    /// The returned source may actually consist of multiple schema sources
    /// from different directories, depending on which directories were given
    /// in `XDG_DATA_DIRS` and `GSETTINGS_SCHEMA_DIR`. For this reason, all
    /// lookups performed against the default source should probably be done
    /// recursively.
    ///
    /// # Returns
    ///
    /// the default schema source
    #[doc(alias = "g_settings_schema_source_get_default")]
    #[doc(alias = "get_default")]
    pub fn default() -> Option<SettingsSchemaSource> {
        unsafe { from_glib_none(ffi::g_settings_schema_source_get_default()) }
    }
}