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::{ffi, File};
6use glib::{prelude::*, translate::*};
7use std::boxed::Box as Box_;
8
9glib::wrapper! {
10 /// Entry point for using GIO functionality.
11 ///
12 /// # Implements
13 ///
14 /// [`VfsExt`][trait@crate::prelude::VfsExt], [`trait@glib::ObjectExt`]
15 #[doc(alias = "GVfs")]
16 pub struct Vfs(Object<ffi::GVfs, ffi::GVfsClass>);
17
18 match fn {
19 type_ => || ffi::g_vfs_get_type(),
20 }
21}
22
23impl Vfs {
24 pub const NONE: Option<&'static Vfs> = None;
25
26 /// Gets the default #GVfs for the system.
27 ///
28 /// # Returns
29 ///
30 /// a #GVfs, which will be the local
31 /// file system #GVfs if no other implementation is available.
32 #[doc(alias = "g_vfs_get_default")]
33 #[doc(alias = "get_default")]
34 #[allow(clippy::should_implement_trait)]
35 pub fn default() -> Vfs {
36 unsafe { from_glib_none(ffi::g_vfs_get_default()) }
37 }
38
39 /// Gets the local #GVfs for the system.
40 ///
41 /// # Returns
42 ///
43 /// a #GVfs.
44 #[doc(alias = "g_vfs_get_local")]
45 #[doc(alias = "get_local")]
46 pub fn local() -> Vfs {
47 unsafe { from_glib_none(ffi::g_vfs_get_local()) }
48 }
49}
50
51unsafe impl Send for Vfs {}
52unsafe impl Sync for Vfs {}
53
54/// Trait containing all [`struct@Vfs`] methods.
55///
56/// # Implementors
57///
58/// [`Vfs`][struct@crate::Vfs]
59pub trait VfsExt: IsA<Vfs> + 'static {
60 /// Gets a #GFile for @path.
61 /// ## `path`
62 /// a string containing a VFS path.
63 ///
64 /// # Returns
65 ///
66 /// a #GFile.
67 /// Free the returned object with g_object_unref().
68 #[doc(alias = "g_vfs_get_file_for_path")]
69 #[doc(alias = "get_file_for_path")]
70 fn file_for_path(&self, path: &str) -> File {
71 unsafe {
72 from_glib_full(ffi::g_vfs_get_file_for_path(
73 self.as_ref().to_glib_none().0,
74 path.to_glib_none().0,
75 ))
76 }
77 }
78
79 /// Gets a #GFile for @uri.
80 ///
81 /// This operation never fails, but the returned object
82 /// might not support any I/O operation if the URI
83 /// is malformed or if the URI scheme is not supported.
84 /// ## `uri`
85 /// a string containing a URI
86 ///
87 /// # Returns
88 ///
89 /// a #GFile.
90 /// Free the returned object with g_object_unref().
91 #[doc(alias = "g_vfs_get_file_for_uri")]
92 #[doc(alias = "get_file_for_uri")]
93 fn file_for_uri(&self, uri: &str) -> File {
94 unsafe {
95 from_glib_full(ffi::g_vfs_get_file_for_uri(
96 self.as_ref().to_glib_none().0,
97 uri.to_glib_none().0,
98 ))
99 }
100 }
101
102 /// Gets a list of URI schemes supported by @self.
103 ///
104 /// # Returns
105 ///
106 /// a [`None`]-terminated array of strings.
107 /// The returned array belongs to GIO and must
108 /// not be freed or modified.
109 #[doc(alias = "g_vfs_get_supported_uri_schemes")]
110 #[doc(alias = "get_supported_uri_schemes")]
111 fn supported_uri_schemes(&self) -> Vec<glib::GString> {
112 unsafe {
113 FromGlibPtrContainer::from_glib_none(ffi::g_vfs_get_supported_uri_schemes(
114 self.as_ref().to_glib_none().0,
115 ))
116 }
117 }
118
119 /// Checks if the VFS is active.
120 ///
121 /// # Returns
122 ///
123 /// [`true`] if construction of the @self was successful
124 /// and it is now active.
125 #[doc(alias = "g_vfs_is_active")]
126 fn is_active(&self) -> bool {
127 unsafe { from_glib(ffi::g_vfs_is_active(self.as_ref().to_glib_none().0)) }
128 }
129
130 /// This operation never fails, but the returned object might
131 /// not support any I/O operations if the @parse_name cannot
132 /// be parsed by the #GVfs module.
133 /// ## `parse_name`
134 /// a string to be parsed by the VFS module.
135 ///
136 /// # Returns
137 ///
138 /// a #GFile for the given @parse_name.
139 /// Free the returned object with g_object_unref().
140 #[doc(alias = "g_vfs_parse_name")]
141 fn parse_name(&self, parse_name: &str) -> File {
142 unsafe {
143 from_glib_full(ffi::g_vfs_parse_name(
144 self.as_ref().to_glib_none().0,
145 parse_name.to_glib_none().0,
146 ))
147 }
148 }
149
150 /// Registers @uri_func and @parse_name_func as the #GFile URI and parse name
151 /// lookup functions for URIs with a scheme matching @scheme.
152 /// Note that @scheme is registered only within the running application, as
153 /// opposed to desktop-wide as it happens with GVfs backends.
154 ///
155 /// When a #GFile is requested with an URI containing @scheme (e.g. through
156 /// g_file_new_for_uri()), @uri_func will be called to allow a custom
157 /// constructor. The implementation of @uri_func should not be blocking, and
158 /// must not call g_vfs_register_uri_scheme() or g_vfs_unregister_uri_scheme().
159 ///
160 /// When g_file_parse_name() is called with a parse name obtained from such file,
161 /// @parse_name_func will be called to allow the #GFile to be created again. In
162 /// that case, it's responsibility of @parse_name_func to make sure the parse
163 /// name matches what the custom #GFile implementation returned when
164 /// g_file_get_parse_name() was previously called. The implementation of
165 /// @parse_name_func should not be blocking, and must not call
166 /// g_vfs_register_uri_scheme() or g_vfs_unregister_uri_scheme().
167 ///
168 /// It's an error to call this function twice with the same scheme. To unregister
169 /// a custom URI scheme, use g_vfs_unregister_uri_scheme().
170 /// ## `scheme`
171 /// an URI scheme, e.g. "http"
172 /// ## `uri_func`
173 /// a #GVfsFileLookupFunc
174 /// ## `uri_data`
175 /// custom data passed to be passed to @uri_func, or [`None`]
176 /// ## `uri_destroy`
177 /// function to be called when unregistering the
178 /// URI scheme, or when @self is disposed, to free the resources used
179 /// by the URI lookup function
180 /// ## `parse_name_func`
181 /// a #GVfsFileLookupFunc
182 /// ## `parse_name_data`
183 /// custom data passed to be passed to
184 /// @parse_name_func, or [`None`]
185 /// ## `parse_name_destroy`
186 /// function to be called when unregistering the
187 /// URI scheme, or when @self is disposed, to free the resources used
188 /// by the parse name lookup function
189 ///
190 /// # Returns
191 ///
192 /// [`true`] if @scheme was successfully registered, or [`false`] if a handler
193 /// for @scheme already exists.
194 #[doc(alias = "g_vfs_register_uri_scheme")]
195 fn register_uri_scheme(
196 &self,
197 scheme: &str,
198 uri_func: Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
199 parse_name_func: Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
200 ) -> bool {
201 let uri_func_data: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
202 Box_::new(uri_func);
203 unsafe extern "C" fn uri_func_func(
204 vfs: *mut ffi::GVfs,
205 identifier: *const std::ffi::c_char,
206 user_data: glib::ffi::gpointer,
207 ) -> *mut ffi::GFile {
208 let vfs = from_glib_borrow(vfs);
209 let identifier: Borrowed<glib::GString> = from_glib_borrow(identifier);
210 let callback =
211 &*(user_data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>);
212 if let Some(ref callback) = *callback {
213 callback(&vfs, identifier.as_str())
214 } else {
215 panic!("cannot get closure...")
216 }
217 .to_glib_full()
218 }
219 let uri_func = if uri_func_data.is_some() {
220 Some(uri_func_func as _)
221 } else {
222 None
223 };
224 let parse_name_func_data: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
225 Box_::new(parse_name_func);
226 unsafe extern "C" fn parse_name_func_func(
227 vfs: *mut ffi::GVfs,
228 identifier: *const std::ffi::c_char,
229 user_data: glib::ffi::gpointer,
230 ) -> *mut ffi::GFile {
231 let vfs = from_glib_borrow(vfs);
232 let identifier: Borrowed<glib::GString> = from_glib_borrow(identifier);
233 let callback =
234 &*(user_data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>);
235 if let Some(ref callback) = *callback {
236 callback(&vfs, identifier.as_str())
237 } else {
238 panic!("cannot get closure...")
239 }
240 .to_glib_full()
241 }
242 let parse_name_func = if parse_name_func_data.is_some() {
243 Some(parse_name_func_func as _)
244 } else {
245 None
246 };
247 unsafe extern "C" fn uri_destroy_func(data: glib::ffi::gpointer) {
248 let _callback = Box_::from_raw(
249 data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
250 );
251 }
252 let destroy_call4 = Some(uri_destroy_func as _);
253 unsafe extern "C" fn parse_name_destroy_func(data: glib::ffi::gpointer) {
254 let _callback = Box_::from_raw(
255 data as *mut Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>,
256 );
257 }
258 let destroy_call7 = Some(parse_name_destroy_func as _);
259 let super_callback0: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
260 uri_func_data;
261 let super_callback1: Box_<Option<Box_<dyn Fn(&Vfs, &str) -> Option<File> + 'static>>> =
262 parse_name_func_data;
263 unsafe {
264 from_glib(ffi::g_vfs_register_uri_scheme(
265 self.as_ref().to_glib_none().0,
266 scheme.to_glib_none().0,
267 uri_func,
268 Box_::into_raw(super_callback0) as *mut _,
269 destroy_call4,
270 parse_name_func,
271 Box_::into_raw(super_callback1) as *mut _,
272 destroy_call7,
273 ))
274 }
275 }
276
277 /// Unregisters the URI handler for @scheme previously registered with
278 /// g_vfs_register_uri_scheme().
279 /// ## `scheme`
280 /// an URI scheme, e.g. "http"
281 ///
282 /// # Returns
283 ///
284 /// [`true`] if @scheme was successfully unregistered, or [`false`] if a
285 /// handler for @scheme does not exist.
286 #[doc(alias = "g_vfs_unregister_uri_scheme")]
287 fn unregister_uri_scheme(&self, scheme: &str) -> bool {
288 unsafe {
289 from_glib(ffi::g_vfs_unregister_uri_scheme(
290 self.as_ref().to_glib_none().0,
291 scheme.to_glib_none().0,
292 ))
293 }
294 }
295}
296
297impl<O: IsA<Vfs>> VfsExt for O {}