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