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    ffi, AsyncResult, Cancellable, Drive, File, Icon, MountMountFlags, MountOperation,
7    MountUnmountFlags, Volume,
8};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::{boxed::Box as Box_, pin::Pin};
16
17glib::wrapper! {
18    /// The `GMount` interface represents a user-visible mount, such as a mounted
19    /// file system.
20    ///
21    /// `GMount` is a ‘mounted’ filesystem that you can access. Mounted is in
22    /// quotes because it’s not the same as a UNIX mount, it might be a GVFS
23    /// mount, but you can still access the files on it if you use GIO.
24    ///
25    /// A `GMount` might be associated with a [`Volume`][crate::Volume] (such as a USB flash
26    /// drive) which hosts it.
27    ///
28    /// Unmounting a `GMount` instance is an asynchronous operation. For
29    /// more information about asynchronous operations, see [`AsyncResult`][crate::AsyncResult]
30    /// and [`Task`][crate::Task]. To unmount a `GMount` instance, first call
31    /// [`MountExt::unmount_with_operation()`][crate::prelude::MountExt::unmount_with_operation()] with (at least) the `GMount`
32    /// instance and a [type@Gio.AsyncReadyCallback].  The callback will be fired
33    /// when the operation has resolved (either with success or failure), and a
34    /// [`AsyncResult`][crate::AsyncResult] structure will be passed to the callback.  That
35    /// callback should then call `Gio::Mount::unmount_with_operation_finish()`
36    /// with the `GMount` and the [`AsyncResult`][crate::AsyncResult] data to see if the
37    /// operation was completed successfully.  If an `error` is present when
38    /// `Gio::Mount::unmount_with_operation_finish()` is called, then it will be
39    /// filled with any error information.
40    ///
41    /// Note, when [porting from GnomeVFS](migrating-gnome-vfs.html), `GMount` is the
42    /// moral equivalent of `GnomeVFSVolume`.
43    ///
44    /// ## Signals
45    ///
46    ///
47    /// #### `changed`
48    ///  Emitted when the mount has been changed.
49    ///
50    ///
51    ///
52    ///
53    /// #### `pre-unmount`
54    ///  This signal may be emitted when the #GMount is about to be
55    /// unmounted.
56    ///
57    /// This signal depends on the backend and is only emitted if
58    /// GIO was used to unmount.
59    ///
60    ///
61    ///
62    ///
63    /// #### `unmounted`
64    ///  This signal is emitted when the #GMount have been
65    /// unmounted. If the recipient is holding references to the
66    /// object they should release them so the object can be
67    /// finalized.
68    ///
69    ///
70    ///
71    /// # Implements
72    ///
73    /// [`MountExt`][trait@crate::prelude::MountExt]
74    #[doc(alias = "GMount")]
75    pub struct Mount(Interface<ffi::GMount, ffi::GMountIface>);
76
77    match fn {
78        type_ => || ffi::g_mount_get_type(),
79    }
80}
81
82impl Mount {
83    pub const NONE: Option<&'static Mount> = None;
84}
85
86mod sealed {
87    pub trait Sealed {}
88    impl<T: super::IsA<super::Mount>> Sealed for T {}
89}
90
91/// Trait containing all [`struct@Mount`] methods.
92///
93/// # Implementors
94///
95/// [`Mount`][struct@crate::Mount]
96pub trait MountExt: IsA<Mount> + sealed::Sealed + 'static {
97    /// Checks if @self can be ejected.
98    ///
99    /// # Returns
100    ///
101    /// [`true`] if the @self can be ejected.
102    #[doc(alias = "g_mount_can_eject")]
103    fn can_eject(&self) -> bool {
104        unsafe { from_glib(ffi::g_mount_can_eject(self.as_ref().to_glib_none().0)) }
105    }
106
107    /// Checks if @self can be unmounted.
108    ///
109    /// # Returns
110    ///
111    /// [`true`] if the @self can be unmounted.
112    #[doc(alias = "g_mount_can_unmount")]
113    fn can_unmount(&self) -> bool {
114        unsafe { from_glib(ffi::g_mount_can_unmount(self.as_ref().to_glib_none().0)) }
115    }
116
117    /// Ejects a mount. This is an asynchronous operation, and is
118    /// finished by calling g_mount_eject_with_operation_finish() with the @self
119    /// and #GAsyncResult data returned in the @callback.
120    /// ## `flags`
121    /// flags affecting the unmount if required for eject
122    /// ## `mount_operation`
123    /// a #GMountOperation or [`None`] to avoid
124    ///     user interaction.
125    /// ## `cancellable`
126    /// optional #GCancellable object, [`None`] to ignore.
127    /// ## `callback`
128    /// a #GAsyncReadyCallback, or [`None`].
129    #[doc(alias = "g_mount_eject_with_operation")]
130    fn eject_with_operation<P: FnOnce(Result<(), glib::Error>) + 'static>(
131        &self,
132        flags: MountUnmountFlags,
133        mount_operation: Option<&impl IsA<MountOperation>>,
134        cancellable: Option<&impl IsA<Cancellable>>,
135        callback: P,
136    ) {
137        let main_context = glib::MainContext::ref_thread_default();
138        let is_main_context_owner = main_context.is_owner();
139        let has_acquired_main_context = (!is_main_context_owner)
140            .then(|| main_context.acquire().ok())
141            .flatten();
142        assert!(
143            is_main_context_owner || has_acquired_main_context.is_some(),
144            "Async operations only allowed if the thread is owning the MainContext"
145        );
146
147        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
148            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
149        unsafe extern "C" fn eject_with_operation_trampoline<
150            P: FnOnce(Result<(), glib::Error>) + 'static,
151        >(
152            _source_object: *mut glib::gobject_ffi::GObject,
153            res: *mut crate::ffi::GAsyncResult,
154            user_data: glib::ffi::gpointer,
155        ) {
156            let mut error = std::ptr::null_mut();
157            let _ =
158                ffi::g_mount_eject_with_operation_finish(_source_object as *mut _, res, &mut error);
159            let result = if error.is_null() {
160                Ok(())
161            } else {
162                Err(from_glib_full(error))
163            };
164            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
165                Box_::from_raw(user_data as *mut _);
166            let callback: P = callback.into_inner();
167            callback(result);
168        }
169        let callback = eject_with_operation_trampoline::<P>;
170        unsafe {
171            ffi::g_mount_eject_with_operation(
172                self.as_ref().to_glib_none().0,
173                flags.into_glib(),
174                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
175                cancellable.map(|p| p.as_ref()).to_glib_none().0,
176                Some(callback),
177                Box_::into_raw(user_data) as *mut _,
178            );
179        }
180    }
181
182    fn eject_with_operation_future(
183        &self,
184        flags: MountUnmountFlags,
185        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
186    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
187        let mount_operation = mount_operation.map(ToOwned::to_owned);
188        Box_::pin(crate::GioFuture::new(
189            self,
190            move |obj, cancellable, send| {
191                obj.eject_with_operation(
192                    flags,
193                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
194                    Some(cancellable),
195                    move |res| {
196                        send.resolve(res);
197                    },
198                );
199            },
200        ))
201    }
202
203    /// Gets the default location of @self. The default location of the given
204    /// @self is a path that reflects the main entry point for the user (e.g.
205    /// the home directory, or the root of the volume).
206    ///
207    /// # Returns
208    ///
209    /// a #GFile.
210    ///      The returned object should be unreffed with
211    ///      g_object_unref() when no longer needed.
212    #[doc(alias = "g_mount_get_default_location")]
213    #[doc(alias = "get_default_location")]
214    fn default_location(&self) -> File {
215        unsafe {
216            from_glib_full(ffi::g_mount_get_default_location(
217                self.as_ref().to_glib_none().0,
218            ))
219        }
220    }
221
222    /// Gets the drive for the @self.
223    ///
224    /// This is a convenience method for getting the #GVolume and then
225    /// using that object to get the #GDrive.
226    ///
227    /// # Returns
228    ///
229    /// a #GDrive or [`None`] if @self is not
230    ///      associated with a volume or a drive.
231    ///      The returned object should be unreffed with
232    ///      g_object_unref() when no longer needed.
233    #[doc(alias = "g_mount_get_drive")]
234    #[doc(alias = "get_drive")]
235    fn drive(&self) -> Option<Drive> {
236        unsafe { from_glib_full(ffi::g_mount_get_drive(self.as_ref().to_glib_none().0)) }
237    }
238
239    /// Gets the icon for @self.
240    ///
241    /// # Returns
242    ///
243    /// a #GIcon.
244    ///      The returned object should be unreffed with
245    ///      g_object_unref() when no longer needed.
246    #[doc(alias = "g_mount_get_icon")]
247    #[doc(alias = "get_icon")]
248    fn icon(&self) -> Icon {
249        unsafe { from_glib_full(ffi::g_mount_get_icon(self.as_ref().to_glib_none().0)) }
250    }
251
252    /// Gets the name of @self.
253    ///
254    /// # Returns
255    ///
256    /// the name for the given @self.
257    ///     The returned string should be freed with g_free()
258    ///     when no longer needed.
259    #[doc(alias = "g_mount_get_name")]
260    #[doc(alias = "get_name")]
261    fn name(&self) -> glib::GString {
262        unsafe { from_glib_full(ffi::g_mount_get_name(self.as_ref().to_glib_none().0)) }
263    }
264
265    /// Gets the root directory on @self.
266    ///
267    /// # Returns
268    ///
269    /// a #GFile.
270    ///      The returned object should be unreffed with
271    ///      g_object_unref() when no longer needed.
272    #[doc(alias = "g_mount_get_root")]
273    #[doc(alias = "get_root")]
274    fn root(&self) -> File {
275        unsafe { from_glib_full(ffi::g_mount_get_root(self.as_ref().to_glib_none().0)) }
276    }
277
278    /// Gets the sort key for @self, if any.
279    ///
280    /// # Returns
281    ///
282    /// Sorting key for @self or [`None`] if no such key is available.
283    #[doc(alias = "g_mount_get_sort_key")]
284    #[doc(alias = "get_sort_key")]
285    fn sort_key(&self) -> Option<glib::GString> {
286        unsafe { from_glib_none(ffi::g_mount_get_sort_key(self.as_ref().to_glib_none().0)) }
287    }
288
289    /// Gets the symbolic icon for @self.
290    ///
291    /// # Returns
292    ///
293    /// a #GIcon.
294    ///      The returned object should be unreffed with
295    ///      g_object_unref() when no longer needed.
296    #[doc(alias = "g_mount_get_symbolic_icon")]
297    #[doc(alias = "get_symbolic_icon")]
298    fn symbolic_icon(&self) -> Icon {
299        unsafe {
300            from_glib_full(ffi::g_mount_get_symbolic_icon(
301                self.as_ref().to_glib_none().0,
302            ))
303        }
304    }
305
306    /// Gets the UUID for the @self. The reference is typically based on
307    /// the file system UUID for the mount in question and should be
308    /// considered an opaque string. Returns [`None`] if there is no UUID
309    /// available.
310    ///
311    /// # Returns
312    ///
313    /// the UUID for @self or [`None`] if no UUID
314    ///     can be computed.
315    ///     The returned string should be freed with g_free()
316    ///     when no longer needed.
317    #[doc(alias = "g_mount_get_uuid")]
318    #[doc(alias = "get_uuid")]
319    fn uuid(&self) -> Option<glib::GString> {
320        unsafe { from_glib_full(ffi::g_mount_get_uuid(self.as_ref().to_glib_none().0)) }
321    }
322
323    /// Gets the volume for the @self.
324    ///
325    /// # Returns
326    ///
327    /// a #GVolume or [`None`] if @self is not
328    ///      associated with a volume.
329    ///      The returned object should be unreffed with
330    ///      g_object_unref() when no longer needed.
331    #[doc(alias = "g_mount_get_volume")]
332    #[doc(alias = "get_volume")]
333    fn volume(&self) -> Option<Volume> {
334        unsafe { from_glib_full(ffi::g_mount_get_volume(self.as_ref().to_glib_none().0)) }
335    }
336
337    /// Tries to guess the type of content stored on @self. Returns one or
338    /// more textual identifiers of well-known content types (typically
339    /// prefixed with "x-content/"), e.g. x-content/image-dcf for camera
340    /// memory cards. See the
341    /// [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
342    /// specification for more on x-content types.
343    ///
344    /// This is an asynchronous operation (see
345    /// g_mount_guess_content_type_sync() for the synchronous version), and
346    /// is finished by calling g_mount_guess_content_type_finish() with the
347    /// @self and #GAsyncResult data returned in the @callback.
348    /// ## `force_rescan`
349    /// Whether to force a rescan of the content.
350    ///     Otherwise a cached result will be used if available
351    /// ## `cancellable`
352    /// optional #GCancellable object, [`None`] to ignore
353    /// ## `callback`
354    /// a #GAsyncReadyCallback
355    #[doc(alias = "g_mount_guess_content_type")]
356    fn guess_content_type<P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static>(
357        &self,
358        force_rescan: bool,
359        cancellable: Option<&impl IsA<Cancellable>>,
360        callback: P,
361    ) {
362        let main_context = glib::MainContext::ref_thread_default();
363        let is_main_context_owner = main_context.is_owner();
364        let has_acquired_main_context = (!is_main_context_owner)
365            .then(|| main_context.acquire().ok())
366            .flatten();
367        assert!(
368            is_main_context_owner || has_acquired_main_context.is_some(),
369            "Async operations only allowed if the thread is owning the MainContext"
370        );
371
372        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
373            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
374        unsafe extern "C" fn guess_content_type_trampoline<
375            P: FnOnce(Result<Vec<glib::GString>, glib::Error>) + 'static,
376        >(
377            _source_object: *mut glib::gobject_ffi::GObject,
378            res: *mut crate::ffi::GAsyncResult,
379            user_data: glib::ffi::gpointer,
380        ) {
381            let mut error = std::ptr::null_mut();
382            let ret =
383                ffi::g_mount_guess_content_type_finish(_source_object as *mut _, res, &mut error);
384            let result = if error.is_null() {
385                Ok(FromGlibPtrContainer::from_glib_full(ret))
386            } else {
387                Err(from_glib_full(error))
388            };
389            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
390                Box_::from_raw(user_data as *mut _);
391            let callback: P = callback.into_inner();
392            callback(result);
393        }
394        let callback = guess_content_type_trampoline::<P>;
395        unsafe {
396            ffi::g_mount_guess_content_type(
397                self.as_ref().to_glib_none().0,
398                force_rescan.into_glib(),
399                cancellable.map(|p| p.as_ref()).to_glib_none().0,
400                Some(callback),
401                Box_::into_raw(user_data) as *mut _,
402            );
403        }
404    }
405
406    fn guess_content_type_future(
407        &self,
408        force_rescan: bool,
409    ) -> Pin<
410        Box_<dyn std::future::Future<Output = Result<Vec<glib::GString>, glib::Error>> + 'static>,
411    > {
412        Box_::pin(crate::GioFuture::new(
413            self,
414            move |obj, cancellable, send| {
415                obj.guess_content_type(force_rescan, Some(cancellable), move |res| {
416                    send.resolve(res);
417                });
418            },
419        ))
420    }
421
422    /// Tries to guess the type of content stored on @self. Returns one or
423    /// more textual identifiers of well-known content types (typically
424    /// prefixed with "x-content/"), e.g. x-content/image-dcf for camera
425    /// memory cards. See the
426    /// [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
427    /// specification for more on x-content types.
428    ///
429    /// This is a synchronous operation and as such may block doing IO;
430    /// see g_mount_guess_content_type() for the asynchronous version.
431    /// ## `force_rescan`
432    /// Whether to force a rescan of the content.
433    ///     Otherwise a cached result will be used if available
434    /// ## `cancellable`
435    /// optional #GCancellable object, [`None`] to ignore
436    ///
437    /// # Returns
438    ///
439    /// a [`None`]-terminated array of content types or [`None`] on error.
440    ///     Caller should free this array with g_strfreev() when done with it.
441    #[doc(alias = "g_mount_guess_content_type_sync")]
442    fn guess_content_type_sync(
443        &self,
444        force_rescan: bool,
445        cancellable: Option<&impl IsA<Cancellable>>,
446    ) -> Result<Vec<glib::GString>, glib::Error> {
447        unsafe {
448            let mut error = std::ptr::null_mut();
449            let ret = ffi::g_mount_guess_content_type_sync(
450                self.as_ref().to_glib_none().0,
451                force_rescan.into_glib(),
452                cancellable.map(|p| p.as_ref()).to_glib_none().0,
453                &mut error,
454            );
455            if error.is_null() {
456                Ok(FromGlibPtrContainer::from_glib_full(ret))
457            } else {
458                Err(from_glib_full(error))
459            }
460        }
461    }
462
463    /// Determines if @self is shadowed. Applications or libraries should
464    /// avoid displaying @self in the user interface if it is shadowed.
465    ///
466    /// A mount is said to be shadowed if there exists one or more user
467    /// visible objects (currently #GMount objects) with a root that is
468    /// inside the root of @self.
469    ///
470    /// One application of shadow mounts is when exposing a single file
471    /// system that is used to address several logical volumes. In this
472    /// situation, a #GVolumeMonitor implementation would create two
473    /// #GVolume objects (for example, one for the camera functionality of
474    /// the device and one for a SD card reader on the device) with
475    /// activation URIs `gphoto2://[usb:001,002]/store1/`
476    /// and `gphoto2://[usb:001,002]/store2/`. When the
477    /// underlying mount (with root
478    /// `gphoto2://[usb:001,002]/`) is mounted, said
479    /// #GVolumeMonitor implementation would create two #GMount objects
480    /// (each with their root matching the corresponding volume activation
481    /// root) that would shadow the original mount.
482    ///
483    /// The proxy monitor in GVfs 2.26 and later, automatically creates and
484    /// manage shadow mounts (and shadows the underlying mount) if the
485    /// activation root on a #GVolume is set.
486    ///
487    /// # Returns
488    ///
489    /// [`true`] if @self is shadowed.
490    #[doc(alias = "g_mount_is_shadowed")]
491    fn is_shadowed(&self) -> bool {
492        unsafe { from_glib(ffi::g_mount_is_shadowed(self.as_ref().to_glib_none().0)) }
493    }
494
495    /// Remounts a mount. This is an asynchronous operation, and is
496    /// finished by calling g_mount_remount_finish() with the @self
497    /// and #GAsyncResults data returned in the @callback.
498    ///
499    /// Remounting is useful when some setting affecting the operation
500    /// of the volume has been changed, as these may need a remount to
501    /// take affect. While this is semantically equivalent with unmounting
502    /// and then remounting not all backends might need to actually be
503    /// unmounted.
504    /// ## `flags`
505    /// flags affecting the operation
506    /// ## `mount_operation`
507    /// a #GMountOperation or [`None`] to avoid
508    ///     user interaction.
509    /// ## `cancellable`
510    /// optional #GCancellable object, [`None`] to ignore.
511    /// ## `callback`
512    /// a #GAsyncReadyCallback, or [`None`].
513    #[doc(alias = "g_mount_remount")]
514    fn remount<P: FnOnce(Result<(), glib::Error>) + 'static>(
515        &self,
516        flags: MountMountFlags,
517        mount_operation: Option<&impl IsA<MountOperation>>,
518        cancellable: Option<&impl IsA<Cancellable>>,
519        callback: P,
520    ) {
521        let main_context = glib::MainContext::ref_thread_default();
522        let is_main_context_owner = main_context.is_owner();
523        let has_acquired_main_context = (!is_main_context_owner)
524            .then(|| main_context.acquire().ok())
525            .flatten();
526        assert!(
527            is_main_context_owner || has_acquired_main_context.is_some(),
528            "Async operations only allowed if the thread is owning the MainContext"
529        );
530
531        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
532            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
533        unsafe extern "C" fn remount_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
534            _source_object: *mut glib::gobject_ffi::GObject,
535            res: *mut crate::ffi::GAsyncResult,
536            user_data: glib::ffi::gpointer,
537        ) {
538            let mut error = std::ptr::null_mut();
539            let _ = ffi::g_mount_remount_finish(_source_object as *mut _, res, &mut error);
540            let result = if error.is_null() {
541                Ok(())
542            } else {
543                Err(from_glib_full(error))
544            };
545            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
546                Box_::from_raw(user_data as *mut _);
547            let callback: P = callback.into_inner();
548            callback(result);
549        }
550        let callback = remount_trampoline::<P>;
551        unsafe {
552            ffi::g_mount_remount(
553                self.as_ref().to_glib_none().0,
554                flags.into_glib(),
555                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
556                cancellable.map(|p| p.as_ref()).to_glib_none().0,
557                Some(callback),
558                Box_::into_raw(user_data) as *mut _,
559            );
560        }
561    }
562
563    fn remount_future(
564        &self,
565        flags: MountMountFlags,
566        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
567    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
568        let mount_operation = mount_operation.map(ToOwned::to_owned);
569        Box_::pin(crate::GioFuture::new(
570            self,
571            move |obj, cancellable, send| {
572                obj.remount(
573                    flags,
574                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
575                    Some(cancellable),
576                    move |res| {
577                        send.resolve(res);
578                    },
579                );
580            },
581        ))
582    }
583
584    /// Increments the shadow count on @self. Usually used by
585    /// #GVolumeMonitor implementations when creating a shadow mount for
586    /// @self, see g_mount_is_shadowed() for more information. The caller
587    /// will need to emit the #GMount::changed signal on @self manually.
588    #[doc(alias = "g_mount_shadow")]
589    fn shadow(&self) {
590        unsafe {
591            ffi::g_mount_shadow(self.as_ref().to_glib_none().0);
592        }
593    }
594
595    /// Unmounts a mount. This is an asynchronous operation, and is
596    /// finished by calling g_mount_unmount_with_operation_finish() with the @self
597    /// and #GAsyncResult data returned in the @callback.
598    /// ## `flags`
599    /// flags affecting the operation
600    /// ## `mount_operation`
601    /// a #GMountOperation or [`None`] to avoid
602    ///     user interaction.
603    /// ## `cancellable`
604    /// optional #GCancellable object, [`None`] to ignore.
605    /// ## `callback`
606    /// a #GAsyncReadyCallback, or [`None`].
607    #[doc(alias = "g_mount_unmount_with_operation")]
608    fn unmount_with_operation<P: FnOnce(Result<(), glib::Error>) + 'static>(
609        &self,
610        flags: MountUnmountFlags,
611        mount_operation: Option<&impl IsA<MountOperation>>,
612        cancellable: Option<&impl IsA<Cancellable>>,
613        callback: P,
614    ) {
615        let main_context = glib::MainContext::ref_thread_default();
616        let is_main_context_owner = main_context.is_owner();
617        let has_acquired_main_context = (!is_main_context_owner)
618            .then(|| main_context.acquire().ok())
619            .flatten();
620        assert!(
621            is_main_context_owner || has_acquired_main_context.is_some(),
622            "Async operations only allowed if the thread is owning the MainContext"
623        );
624
625        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
626            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
627        unsafe extern "C" fn unmount_with_operation_trampoline<
628            P: FnOnce(Result<(), glib::Error>) + 'static,
629        >(
630            _source_object: *mut glib::gobject_ffi::GObject,
631            res: *mut crate::ffi::GAsyncResult,
632            user_data: glib::ffi::gpointer,
633        ) {
634            let mut error = std::ptr::null_mut();
635            let _ = ffi::g_mount_unmount_with_operation_finish(
636                _source_object as *mut _,
637                res,
638                &mut error,
639            );
640            let result = if error.is_null() {
641                Ok(())
642            } else {
643                Err(from_glib_full(error))
644            };
645            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
646                Box_::from_raw(user_data as *mut _);
647            let callback: P = callback.into_inner();
648            callback(result);
649        }
650        let callback = unmount_with_operation_trampoline::<P>;
651        unsafe {
652            ffi::g_mount_unmount_with_operation(
653                self.as_ref().to_glib_none().0,
654                flags.into_glib(),
655                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
656                cancellable.map(|p| p.as_ref()).to_glib_none().0,
657                Some(callback),
658                Box_::into_raw(user_data) as *mut _,
659            );
660        }
661    }
662
663    fn unmount_with_operation_future(
664        &self,
665        flags: MountUnmountFlags,
666        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
667    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
668        let mount_operation = mount_operation.map(ToOwned::to_owned);
669        Box_::pin(crate::GioFuture::new(
670            self,
671            move |obj, cancellable, send| {
672                obj.unmount_with_operation(
673                    flags,
674                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
675                    Some(cancellable),
676                    move |res| {
677                        send.resolve(res);
678                    },
679                );
680            },
681        ))
682    }
683
684    /// Decrements the shadow count on @self. Usually used by
685    /// #GVolumeMonitor implementations when destroying a shadow mount for
686    /// @self, see g_mount_is_shadowed() for more information. The caller
687    /// will need to emit the #GMount::changed signal on @self manually.
688    #[doc(alias = "g_mount_unshadow")]
689    fn unshadow(&self) {
690        unsafe {
691            ffi::g_mount_unshadow(self.as_ref().to_glib_none().0);
692        }
693    }
694
695    /// Emitted when the mount has been changed.
696    #[doc(alias = "changed")]
697    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
698        unsafe extern "C" fn changed_trampoline<P: IsA<Mount>, F: Fn(&P) + 'static>(
699            this: *mut ffi::GMount,
700            f: glib::ffi::gpointer,
701        ) {
702            let f: &F = &*(f as *const F);
703            f(Mount::from_glib_borrow(this).unsafe_cast_ref())
704        }
705        unsafe {
706            let f: Box_<F> = Box_::new(f);
707            connect_raw(
708                self.as_ptr() as *mut _,
709                b"changed\0".as_ptr() as *const _,
710                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
711                    changed_trampoline::<Self, F> as *const (),
712                )),
713                Box_::into_raw(f),
714            )
715        }
716    }
717
718    /// This signal may be emitted when the #GMount is about to be
719    /// unmounted.
720    ///
721    /// This signal depends on the backend and is only emitted if
722    /// GIO was used to unmount.
723    #[doc(alias = "pre-unmount")]
724    fn connect_pre_unmount<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
725        unsafe extern "C" fn pre_unmount_trampoline<P: IsA<Mount>, F: Fn(&P) + 'static>(
726            this: *mut ffi::GMount,
727            f: glib::ffi::gpointer,
728        ) {
729            let f: &F = &*(f as *const F);
730            f(Mount::from_glib_borrow(this).unsafe_cast_ref())
731        }
732        unsafe {
733            let f: Box_<F> = Box_::new(f);
734            connect_raw(
735                self.as_ptr() as *mut _,
736                b"pre-unmount\0".as_ptr() as *const _,
737                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
738                    pre_unmount_trampoline::<Self, F> as *const (),
739                )),
740                Box_::into_raw(f),
741            )
742        }
743    }
744
745    /// This signal is emitted when the #GMount have been
746    /// unmounted. If the recipient is holding references to the
747    /// object they should release them so the object can be
748    /// finalized.
749    #[doc(alias = "unmounted")]
750    fn connect_unmounted<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
751        unsafe extern "C" fn unmounted_trampoline<P: IsA<Mount>, F: Fn(&P) + 'static>(
752            this: *mut ffi::GMount,
753            f: glib::ffi::gpointer,
754        ) {
755            let f: &F = &*(f as *const F);
756            f(Mount::from_glib_borrow(this).unsafe_cast_ref())
757        }
758        unsafe {
759            let f: Box_<F> = Box_::new(f);
760            connect_raw(
761                self.as_ptr() as *mut _,
762                b"unmounted\0".as_ptr() as *const _,
763                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
764                    unmounted_trampoline::<Self, F> as *const (),
765                )),
766                Box_::into_raw(f),
767            )
768        }
769    }
770}
771
772impl<O: IsA<Mount>> MountExt for O {}