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