gio/auto/
settings_schema_source.rs1use crate::{ffi, SettingsSchema};
6use glib::translate::*;
7
8glib::wrapper! {
9 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10 pub struct SettingsSchemaSource(Shared<ffi::GSettingsSchemaSource>);
11
12 match fn {
13 ref => |ptr| ffi::g_settings_schema_source_ref(ptr),
14 unref => |ptr| ffi::g_settings_schema_source_unref(ptr),
15 type_ => || ffi::g_settings_schema_source_get_type(),
16 }
17}
18
19impl SettingsSchemaSource {
20 #[doc(alias = "g_settings_schema_source_new_from_directory")]
21 #[doc(alias = "new_from_directory")]
22 pub fn from_directory(
23 directory: impl AsRef<std::path::Path>,
24 parent: Option<&SettingsSchemaSource>,
25 trusted: bool,
26 ) -> Result<SettingsSchemaSource, glib::Error> {
27 unsafe {
28 let mut error = std::ptr::null_mut();
29 let ret = ffi::g_settings_schema_source_new_from_directory(
30 directory.as_ref().to_glib_none().0,
31 parent.to_glib_none().0,
32 trusted.into_glib(),
33 &mut error,
34 );
35 if error.is_null() {
36 Ok(from_glib_full(ret))
37 } else {
38 Err(from_glib_full(error))
39 }
40 }
41 }
42
43 #[doc(alias = "g_settings_schema_source_list_schemas")]
44 pub fn list_schemas(&self, recursive: bool) -> (Vec<glib::GString>, Vec<glib::GString>) {
45 unsafe {
46 let mut non_relocatable = std::ptr::null_mut();
47 let mut relocatable = std::ptr::null_mut();
48 ffi::g_settings_schema_source_list_schemas(
49 self.to_glib_none().0,
50 recursive.into_glib(),
51 &mut non_relocatable,
52 &mut relocatable,
53 );
54 (
55 FromGlibPtrContainer::from_glib_full(non_relocatable),
56 FromGlibPtrContainer::from_glib_full(relocatable),
57 )
58 }
59 }
60
61 #[doc(alias = "g_settings_schema_source_lookup")]
62 pub fn lookup(&self, schema_id: &str, recursive: bool) -> Option<SettingsSchema> {
63 unsafe {
64 from_glib_full(ffi::g_settings_schema_source_lookup(
65 self.to_glib_none().0,
66 schema_id.to_glib_none().0,
67 recursive.into_glib(),
68 ))
69 }
70 }
71
72 #[doc(alias = "g_settings_schema_source_get_default")]
73 #[doc(alias = "get_default")]
74 #[allow(clippy::should_implement_trait)]
75 pub fn default() -> Option<SettingsSchemaSource> {
76 unsafe { from_glib_none(ffi::g_settings_schema_source_get_default()) }
77 }
78}