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