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