Skip to main content

gio/auto/
vfs.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::{File, ffi};
6use glib::{prelude::*, translate::*};
7use std::boxed::Box as Box_;
8
9glib::wrapper! {
10    #[doc(alias = "GVfs")]
11    pub struct Vfs(Object<ffi::GVfs, ffi::GVfsClass>);
12
13    match fn {
14        type_ => || ffi::g_vfs_get_type(),
15    }
16}
17
18impl Vfs {
19    pub const NONE: Option<&'static Vfs> = None;
20
21    #[doc(alias = "g_vfs_get_default")]
22    #[doc(alias = "get_default")]
23    #[allow(clippy::should_implement_trait)]
24    pub fn default() -> Vfs {
25        unsafe { from_glib_none(ffi::g_vfs_get_default()) }
26    }
27
28    #[doc(alias = "g_vfs_get_local")]
29    #[doc(alias = "get_local")]
30    pub fn local() -> Vfs {
31        unsafe { from_glib_none(ffi::g_vfs_get_local()) }
32    }
33}
34
35unsafe impl Send for Vfs {}
36unsafe impl Sync for Vfs {}
37
38pub trait VfsExt: IsA<Vfs> + 'static {
39    #[doc(alias = "g_vfs_get_file_for_path")]
40    #[doc(alias = "get_file_for_path")]
41    fn file_for_path(&self, path: impl AsRef<std::path::Path>) -> File {
42        unsafe {
43            from_glib_full(ffi::g_vfs_get_file_for_path(
44                self.as_ref().to_glib_none().0,
45                path.as_ref().to_glib_none().0,
46            ))
47        }
48    }
49
50    #[doc(alias = "g_vfs_get_file_for_uri")]
51    #[doc(alias = "get_file_for_uri")]
52    fn file_for_uri(&self, uri: &str) -> File {
53        unsafe {
54            from_glib_full(ffi::g_vfs_get_file_for_uri(
55                self.as_ref().to_glib_none().0,
56                uri.to_glib_none().0,
57            ))
58        }
59    }
60
61    #[doc(alias = "g_vfs_get_supported_uri_schemes")]
62    #[doc(alias = "get_supported_uri_schemes")]
63    fn supported_uri_schemes(&self) -> Vec<glib::GString> {
64        unsafe {
65            FromGlibPtrContainer::from_glib_none(ffi::g_vfs_get_supported_uri_schemes(
66                self.as_ref().to_glib_none().0,
67            ))
68        }
69    }
70
71    #[doc(alias = "g_vfs_is_active")]
72    fn is_active(&self) -> bool {
73        unsafe { from_glib(ffi::g_vfs_is_active(self.as_ref().to_glib_none().0)) }
74    }
75
76    #[doc(alias = "g_vfs_parse_name")]
77    fn parse_name(&self, parse_name: &str) -> File {
78        unsafe {
79            from_glib_full(ffi::g_vfs_parse_name(
80                self.as_ref().to_glib_none().0,
81                parse_name.to_glib_none().0,
82            ))
83        }
84    }
85
86    #[doc(alias = "g_vfs_register_uri_scheme")]
87    fn register_uri_scheme(
88        &self,
89        scheme: &str,
90        uri_func: Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
91        parse_name_func: Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
92    ) -> bool {
93        let uri_func_data: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
94            Box_::new(uri_func);
95        unsafe extern "C" fn uri_func_func(
96            vfs: *mut ffi::GVfs,
97            identifier: *const std::ffi::c_char,
98            user_data: glib::ffi::gpointer,
99        ) -> *mut ffi::GFile {
100            unsafe {
101                let vfs = from_glib_borrow(vfs);
102                let identifier: Borrowed<glib::GString> = from_glib_borrow(identifier);
103                let callback = &*(user_data
104                    as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>);
105                if let Some(ref callback) = *callback {
106                    callback(&vfs, identifier.as_str())
107                } else {
108                    panic!("cannot get closure...")
109                }
110                .to_glib_full()
111            }
112        }
113        let uri_func = if uri_func_data.is_some() {
114            Some(uri_func_func as _)
115        } else {
116            None
117        };
118        let parse_name_func_data: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
119            Box_::new(parse_name_func);
120        unsafe extern "C" fn parse_name_func_func(
121            vfs: *mut ffi::GVfs,
122            identifier: *const std::ffi::c_char,
123            user_data: glib::ffi::gpointer,
124        ) -> *mut ffi::GFile {
125            unsafe {
126                let vfs = from_glib_borrow(vfs);
127                let identifier: Borrowed<glib::GString> = from_glib_borrow(identifier);
128                let callback = &*(user_data
129                    as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>);
130                if let Some(ref callback) = *callback {
131                    callback(&vfs, identifier.as_str())
132                } else {
133                    panic!("cannot get closure...")
134                }
135                .to_glib_full()
136            }
137        }
138        let parse_name_func = if parse_name_func_data.is_some() {
139            Some(parse_name_func_func as _)
140        } else {
141            None
142        };
143        unsafe extern "C" fn uri_destroy_func(data: glib::ffi::gpointer) {
144            unsafe {
145                let _callback = Box_::from_raw(
146                    data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
147                );
148            }
149        }
150        let destroy_call4 = Some(uri_destroy_func as _);
151        unsafe extern "C" fn parse_name_destroy_func(data: glib::ffi::gpointer) {
152            unsafe {
153                let _callback = Box_::from_raw(
154                    data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
155                );
156            }
157        }
158        let destroy_call7 = Some(parse_name_destroy_func as _);
159        let super_callback0: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
160            uri_func_data;
161        let super_callback1: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
162            parse_name_func_data;
163        unsafe {
164            from_glib(ffi::g_vfs_register_uri_scheme(
165                self.as_ref().to_glib_none().0,
166                scheme.to_glib_none().0,
167                uri_func,
168                Box_::into_raw(super_callback0) as *mut _,
169                destroy_call4,
170                parse_name_func,
171                Box_::into_raw(super_callback1) as *mut _,
172                destroy_call7,
173            ))
174        }
175    }
176
177    #[doc(alias = "g_vfs_unregister_uri_scheme")]
178    fn unregister_uri_scheme(&self, scheme: &str) -> bool {
179        unsafe {
180            from_glib(ffi::g_vfs_unregister_uri_scheme(
181                self.as_ref().to_glib_none().0,
182                scheme.to_glib_none().0,
183            ))
184        }
185    }
186}
187
188impl<O: IsA<Vfs>> VfsExt for O {}