Skip to main content

gio/auto/
mount.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::{
6    AsyncResult, Cancellable, Drive, File, Icon, MountMountFlags, MountOperation,
7    MountUnmountFlags, Volume, ffi,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::{boxed::Box as Box_, pin::Pin};
16
17glib::wrapper! {
18    #[doc(alias = "GMount")]
19    pub struct Mount(Interface<ffi::GMount, ffi::GMountIface>);
20
21    match fn {
22        type_ => || ffi::g_mount_get_type(),
23    }
24}
25
26impl Mount {
27    pub const NONE: Option<&'static Mount> = None;
28}
29
30pub trait MountExt: IsA<Mount> + 'static {
31    #[doc(alias = "g_mount_can_eject")]
32    fn can_eject(&self) -> bool {
33        unsafe { from_glib(ffi::g_mount_can_eject(self.as_ref().to_glib_none().0)) }
34    }
35
36    #[doc(alias = "g_mount_can_unmount")]
37    fn can_unmount(&self) -> bool {
38        unsafe { from_glib(ffi::g_mount_can_unmount(self.as_ref().to_glib_none().0)) }
39    }
40
41    #[doc(alias = "g_mount_eject_with_operation")]
42    fn eject_with_operation<P: FnOnce(Result<(), glib::Error>) + 'static>(
43        &self,
44        flags: MountUnmountFlags,
45        mount_operation: Option<&impl IsA<MountOperation>>,
46        cancellable: Option<&impl IsA<Cancellable>>,
47        callback: P,
48    ) {
49        let main_context = glib::MainContext::ref_thread_default();
50        let is_main_context_owner = main_context.is_owner();
51        let has_acquired_main_context = (!is_main_context_owner)
52            .then(|| main_context.acquire().ok())
53            .flatten();
54        assert!(
55            is_main_context_owner || has_acquired_main_context.is_some(),
56            "Async operations only allowed if the thread is owning the MainContext"
57        );
58
59        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
60            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
61        unsafe extern "C" fn eject_with_operation_trampoline<
62            P: FnOnce(Result<(), glib::Error>) + 'static,
63        >(
64            _source_object: *mut glib::gobject_ffi::GObject,
65            res: *mut crate::ffi::GAsyncResult,
66            user_data: glib::ffi::gpointer,
67        ) {
68            unsafe {
69                let mut error = std::ptr::null_mut();
70                ffi::g_mount_eject_with_operation_finish(_source_object as *mut _, res, &mut error);
71                let result = if error.is_null() {
72                    Ok(())
73                } else {
74                    Err(from_glib_full(error))
75                };
76                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
77                    Box_::from_raw(user_data as *mut _);
78                let callback: P = callback.into_inner();
79                callback(result);
80            }
81        }
82        let callback = eject_with_operation_trampoline::<P>;
83        unsafe {
84            ffi::g_mount_eject_with_operation(
85                self.as_ref().to_glib_none().0,
86                flags.into_glib(),
87                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
88                cancellable.map(|p| p.as_ref()).to_glib_none().0,
89                Some(callback),
90                Box_::into_raw(user_data) as *mut _,
91            );
92        }
93    }
94
95    fn eject_with_operation_future(
96        &self,
97        flags: MountUnmountFlags,
98        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
99    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
100        let mount_operation = mount_operation.map(ToOwned::to_owned);
101        Box_::pin(crate::GioFuture::new(
102            self,
103            move |obj, cancellable, send| {
104                obj.eject_with_operation(
105                    flags,
106                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
107                    Some(cancellable),
108                    move |res| {
109                        send.resolve(res);
110                    },
111                );
112            },
113        ))
114    }
115
116    #[doc(alias = "g_mount_get_default_location")]
117    #[doc(alias = "get_default_location")]
118    fn default_location(&self) -> File {
119        unsafe {
120            from_glib_full(ffi::g_mount_get_default_location(
121                self.as_ref().to_glib_none().0,
122            ))
123        }
124    }
125
126    #[doc(alias = "g_mount_get_drive")]
127    #[doc(alias = "get_drive")]
128    fn drive(&self) -> Option<Drive> {
129        unsafe { from_glib_full(ffi::g_mount_get_drive(self.as_ref().to_glib_none().0)) }
130    }
131
132    #[doc(alias = "g_mount_get_icon")]
133    #[doc(alias = "get_icon")]
134    fn icon(&self) -> Icon {
135        unsafe { from_glib_full(ffi::g_mount_get_icon(self.as_ref().to_glib_none().0)) }
136    }
137
138    #[doc(alias = "g_mount_get_name")]
139    #[doc(alias = "get_name")]
140    fn name(&self) -> glib::GString {
141        unsafe { from_glib_full(ffi::g_mount_get_name(self.as_ref().to_glib_none().0)) }
142    }
143
144    #[doc(alias = "g_mount_get_root")]
145    #[doc(alias = "get_root")]
146    fn root(&self) -> File {
147        unsafe { from_glib_full(ffi::g_mount_get_root(self.as_ref().to_glib_none().0)) }
148    }
149
150    #[doc(alias = "g_mount_get_sort_key")]
151    #[doc(alias = "get_sort_key")]
152    fn sort_key(&self) -> Option<glib::GString> {
153        unsafe { from_glib_none(ffi::g_mount_get_sort_key(self.as_ref().to_glib_none().0)) }
154    }
155
156    #[doc(alias = "g_mount_get_symbolic_icon")]
157    #[doc(alias = "get_symbolic_icon")]
158    fn symbolic_icon(&self) -> Icon {
159        unsafe {
160            from_glib_full(ffi::g_mount_get_symbolic_icon(
161                self.as_ref().to_glib_none().0,
162            ))
163        }
164    }
165
166    #[doc(alias = "g_mount_get_uuid")]
167    #[doc(alias = "get_uuid")]
168    fn uuid(&self) -> Option<glib::GString> {
169        unsafe { from_glib_full(ffi::g_mount_get_uuid(self.as_ref().to_glib_none().0)) }
170    }
171
172    #[doc(alias = "g_mount_get_volume")]
173    #[doc(alias = "get_volume")]
174    fn volume(&self) -> Option<Volume> {
175        unsafe { from_glib_full(ffi::g_mount_get_volume(self.as_ref().to_glib_none().0)) }
176    }
177
178    #[doc(alias = "g_mount_guess_content_type")]
179    fn guess_content_type<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>(
180        &self,
181        force_rescan: bool,
182        cancellable: Option<&impl IsA<Cancellable>>,
183        callback: P,
184    ) {
185        let main_context = glib::MainContext::ref_thread_default();
186        let is_main_context_owner = main_context.is_owner();
187        let has_acquired_main_context = (!is_main_context_owner)
188            .then(|| main_context.acquire().ok())
189            .flatten();
190        assert!(
191            is_main_context_owner || has_acquired_main_context.is_some(),
192            "Async operations only allowed if the thread is owning the MainContext"
193        );
194
195        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
196            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
197        unsafe extern "C" fn guess_content_type_trampoline<
198            P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static,
199        >(
200            _source_object: *mut glib::gobject_ffi::GObject,
201            res: *mut crate::ffi::GAsyncResult,
202            user_data: glib::ffi::gpointer,
203        ) {
204            unsafe {
205                let mut error = std::ptr::null_mut();
206                let ret = ffi::g_mount_guess_content_type_finish(
207                    _source_object as *mut _,
208                    res,
209                    &mut error,
210                );
211                let result = if error.is_null() {
212                    Ok(FromGlibPtrContainer::from_glib_full(ret))
213                } else {
214                    Err(from_glib_full(error))
215                };
216                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
217                    Box_::from_raw(user_data as *mut _);
218                let callback: P = callback.into_inner();
219                callback(result);
220            }
221        }
222        let callback = guess_content_type_trampoline::<P>;
223        unsafe {
224            ffi::g_mount_guess_content_type(
225                self.as_ref().to_glib_none().0,
226                force_rescan.into_glib(),
227                cancellable.map(|p| p.as_ref()).to_glib_none().0,
228                Some(callback),
229                Box_::into_raw(user_data) as *mut _,
230            );
231        }
232    }
233
234    fn guess_content_type_future(
235        &self,
236        force_rescan: bool,
237    ) -> Pin<
238        Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>,
239    > {
240        Box_::pin(crate::GioFuture::new(
241            self,
242            move |obj, cancellable, send| {
243                obj.guess_content_type(force_rescan, Some(cancellable), move |res| {
244                    send.resolve(res);
245                });
246            },
247        ))
248    }
249
250    #[doc(alias = "g_mount_guess_content_type_sync")]
251    fn guess_content_type_sync(
252        &self,
253        force_rescan: bool,
254        cancellable: Option<&impl IsA<Cancellable>>,
255    ) -> Result<Vec<glib::GString>, glib::Error> {
256        unsafe {
257            let mut error = std::ptr::null_mut();
258            let ret = ffi::g_mount_guess_content_type_sync(
259                self.as_ref().to_glib_none().0,
260                force_rescan.into_glib(),
261                cancellable.map(|p| p.as_ref()).to_glib_none().0,
262                &mut error,
263            );
264            if error.is_null() {
265                Ok(FromGlibPtrContainer::from_glib_full(ret))
266            } else {
267                Err(from_glib_full(error))
268            }
269        }
270    }
271
272    #[doc(alias = "g_mount_is_shadowed")]
273    fn is_shadowed(&self) -> bool {
274        unsafe { from_glib(ffi::g_mount_is_shadowed(self.as_ref().to_glib_none().0)) }
275    }
276
277    #[doc(alias = "g_mount_remount")]
278    fn remount<P: FnOnce(Result<(), glib::Error>) + 'static>(
279        &self,
280        flags: MountMountFlags,
281        mount_operation: Option<&impl IsA<MountOperation>>,
282        cancellable: Option<&impl IsA<Cancellable>>,
283        callback: P,
284    ) {
285        let main_context = glib::MainContext::ref_thread_default();
286        let is_main_context_owner = main_context.is_owner();
287        let has_acquired_main_context = (!is_main_context_owner)
288            .then(|| main_context.acquire().ok())
289            .flatten();
290        assert!(
291            is_main_context_owner || has_acquired_main_context.is_some(),
292            "Async operations only allowed if the thread is owning the MainContext"
293        );
294
295        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
296            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
297        unsafe extern "C" fn remount_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
298            _source_object: *mut glib::gobject_ffi::GObject,
299            res: *mut crate::ffi::GAsyncResult,
300            user_data: glib::ffi::gpointer,
301        ) {
302            unsafe {
303                let mut error = std::ptr::null_mut();
304                ffi::g_mount_remount_finish(_source_object as *mut _, res, &mut error);
305                let result = if error.is_null() {
306                    Ok(())
307                } else {
308                    Err(from_glib_full(error))
309                };
310                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
311                    Box_::from_raw(user_data as *mut _);
312                let callback: P = callback.into_inner();
313                callback(result);
314            }
315        }
316        let callback = remount_trampoline::<P>;
317        unsafe {
318            ffi::g_mount_remount(
319                self.as_ref().to_glib_none().0,
320                flags.into_glib(),
321                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
322                cancellable.map(|p| p.as_ref()).to_glib_none().0,
323                Some(callback),
324                Box_::into_raw(user_data) as *mut _,
325            );
326        }
327    }
328
329    fn remount_future(
330        &self,
331        flags: MountMountFlags,
332        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
333    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
334        let mount_operation = mount_operation.map(ToOwned::to_owned);
335        Box_::pin(crate::GioFuture::new(
336            self,
337            move |obj, cancellable, send| {
338                obj.remount(
339                    flags,
340                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
341                    Some(cancellable),
342                    move |res| {
343                        send.resolve(res);
344                    },
345                );
346            },
347        ))
348    }
349
350    #[doc(alias = "g_mount_shadow")]
351    fn shadow(&self) {
352        unsafe {
353            ffi::g_mount_shadow(self.as_ref().to_glib_none().0);
354        }
355    }
356
357    #[doc(alias = "g_mount_unmount_with_operation")]
358    fn unmount_with_operation<P: FnOnce(Result<(), glib::Error>) + 'static>(
359        &self,
360        flags: MountUnmountFlags,
361        mount_operation: Option<&impl IsA<MountOperation>>,
362        cancellable: Option<&impl IsA<Cancellable>>,
363        callback: P,
364    ) {
365        let main_context = glib::MainContext::ref_thread_default();
366        let is_main_context_owner = main_context.is_owner();
367        let has_acquired_main_context = (!is_main_context_owner)
368            .then(|| main_context.acquire().ok())
369            .flatten();
370        assert!(
371            is_main_context_owner || has_acquired_main_context.is_some(),
372            "Async operations only allowed if the thread is owning the MainContext"
373        );
374
375        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
376            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
377        unsafe extern "C" fn unmount_with_operation_trampoline<
378            P: FnOnce(Result<(), glib::Error>) + 'static,
379        >(
380            _source_object: *mut glib::gobject_ffi::GObject,
381            res: *mut crate::ffi::GAsyncResult,
382            user_data: glib::ffi::gpointer,
383        ) {
384            unsafe {
385                let mut error = std::ptr::null_mut();
386                ffi::g_mount_unmount_with_operation_finish(
387                    _source_object as *mut _,
388                    res,
389                    &mut error,
390                );
391                let result = if error.is_null() {
392                    Ok(())
393                } else {
394                    Err(from_glib_full(error))
395                };
396                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
397                    Box_::from_raw(user_data as *mut _);
398                let callback: P = callback.into_inner();
399                callback(result);
400            }
401        }
402        let callback = unmount_with_operation_trampoline::<P>;
403        unsafe {
404            ffi::g_mount_unmount_with_operation(
405                self.as_ref().to_glib_none().0,
406                flags.into_glib(),
407                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
408                cancellable.map(|p| p.as_ref()).to_glib_none().0,
409                Some(callback),
410                Box_::into_raw(user_data) as *mut _,
411            );
412        }
413    }
414
415    fn unmount_with_operation_future(
416        &self,
417        flags: MountUnmountFlags,
418        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
419    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
420        let mount_operation = mount_operation.map(ToOwned::to_owned);
421        Box_::pin(crate::GioFuture::new(
422            self,
423            move |obj, cancellable, send| {
424                obj.unmount_with_operation(
425                    flags,
426                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
427                    Some(cancellable),
428                    move |res| {
429                        send.resolve(res);
430                    },
431                );
432            },
433        ))
434    }
435
436    #[doc(alias = "g_mount_unshadow")]
437    fn unshadow(&self) {
438        unsafe {
439            ffi::g_mount_unshadow(self.as_ref().to_glib_none().0);
440        }
441    }
442
443    #[doc(alias = "changed")]
444    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
445        unsafe extern "C" fn changed_trampoline<P: IsA<Mount>, F: Fn(&P) + 'static>(
446            this: *mut ffi::GMount,
447            f: glib::ffi::gpointer,
448        ) {
449            unsafe {
450                let f: &F = &*(f as *const F);
451                f(Mount::from_glib_borrow(this).unsafe_cast_ref())
452            }
453        }
454        unsafe {
455            let f: Box_<F> = Box_::new(f);
456            connect_raw(
457                self.as_ptr() as *mut _,
458                c"changed".as_ptr(),
459                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
460                    changed_trampoline::<Self, F> as *const (),
461                )),
462                Box_::into_raw(f),
463            )
464        }
465    }
466
467    #[doc(alias = "pre-unmount")]
468    fn connect_pre_unmount<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
469        unsafe extern "C" fn pre_unmount_trampoline<P: IsA<Mount>, F: Fn(&P) + 'static>(
470            this: *mut ffi::GMount,
471            f: glib::ffi::gpointer,
472        ) {
473            unsafe {
474                let f: &F = &*(f as *const F);
475                f(Mount::from_glib_borrow(this).unsafe_cast_ref())
476            }
477        }
478        unsafe {
479            let f: Box_<F> = Box_::new(f);
480            connect_raw(
481                self.as_ptr() as *mut _,
482                c"pre-unmount".as_ptr(),
483                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
484                    pre_unmount_trampoline::<Self, F> as *const (),
485                )),
486                Box_::into_raw(f),
487            )
488        }
489    }
490
491    #[doc(alias = "unmounted")]
492    fn connect_unmounted<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
493        unsafe extern "C" fn unmounted_trampoline<P: IsA<Mount>, F: Fn(&P) + 'static>(
494            this: *mut ffi::GMount,
495            f: glib::ffi::gpointer,
496        ) {
497            unsafe {
498                let f: &F = &*(f as *const F);
499                f(Mount::from_glib_borrow(this).unsafe_cast_ref())
500            }
501        }
502        unsafe {
503            let f: Box_<F> = Box_::new(f);
504            connect_raw(
505                self.as_ptr() as *mut _,
506                c"unmounted".as_ptr(),
507                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
508                    unmounted_trampoline::<Self, F> as *const (),
509                )),
510                Box_::into_raw(f),
511            )
512        }
513    }
514}
515
516impl<O: IsA<Mount>> MountExt for O {}