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