gio/auto/
drive.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, DriveStartFlags, DriveStartStopType, Icon, 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    /// `GDrive` represents a piece of hardware connected to the machine.
19    /// It’s generally only created for removable hardware or hardware with
20    /// removable media. For example, an optical disc drive, or a USB flash drive.
21    ///
22    /// `GDrive` is a container class for [`Volume`][crate::Volume] objects that stem from
23    /// the same piece of media. As such, `GDrive` abstracts a drive with
24    /// (or without) removable media and provides operations for querying
25    /// whether media is available, determining whether media change is
26    /// automatically detected and ejecting the media.
27    ///
28    /// If the `GDrive` reports that media isn’t automatically detected, one
29    /// can poll for media; typically one should not do this periodically
30    /// as a poll for media operation is potentially expensive and may
31    /// spin up the drive creating noise.
32    ///
33    /// `GDrive` supports starting and stopping drives with authentication
34    /// support for the former. This can be used to support a diverse set
35    /// of use cases including connecting/disconnecting iSCSI devices,
36    /// powering down external disk enclosures and starting/stopping
37    /// multi-disk devices such as RAID devices. Note that the actual
38    /// semantics and side-effects of starting/stopping a `GDrive` may vary
39    /// according to implementation. To choose the correct verbs in e.g. a
40    /// file manager, use [`DriveExt::start_stop_type()`][crate::prelude::DriveExt::start_stop_type()].
41    ///
42    /// For [porting from GnomeVFS](migrating-gnome-vfs.html) note that there is no
43    /// equivalent of `GDrive` in that API.
44    ///
45    /// ## Signals
46    ///
47    ///
48    /// #### `changed`
49    ///  Emitted when the drive's state has changed.
50    ///
51    ///
52    ///
53    ///
54    /// #### `disconnected`
55    ///  This signal is emitted when the #GDrive have been
56    /// disconnected. If the recipient is holding references to the
57    /// object they should release them so the object can be
58    /// finalized.
59    ///
60    ///
61    ///
62    ///
63    /// #### `eject-button`
64    ///  Emitted when the physical eject button (if any) of a drive has
65    /// been pressed.
66    ///
67    ///
68    ///
69    ///
70    /// #### `stop-button`
71    ///  Emitted when the physical stop button (if any) of a drive has
72    /// been pressed.
73    ///
74    ///
75    ///
76    /// # Implements
77    ///
78    /// [`DriveExt`][trait@crate::prelude::DriveExt]
79    #[doc(alias = "GDrive")]
80    pub struct Drive(Interface<ffi::GDrive, ffi::GDriveIface>);
81
82    match fn {
83        type_ => || ffi::g_drive_get_type(),
84    }
85}
86
87impl Drive {
88    pub const NONE: Option<&'static Drive> = None;
89}
90
91mod sealed {
92    pub trait Sealed {}
93    impl<T: super::IsA<super::Drive>> Sealed for T {}
94}
95
96/// Trait containing all [`struct@Drive`] methods.
97///
98/// # Implementors
99///
100/// [`Drive`][struct@crate::Drive]
101pub trait DriveExt: IsA<Drive> + sealed::Sealed + 'static {
102    /// Checks if a drive can be ejected.
103    ///
104    /// # Returns
105    ///
106    /// [`true`] if the @self can be ejected, [`false`] otherwise.
107    #[doc(alias = "g_drive_can_eject")]
108    fn can_eject(&self) -> bool {
109        unsafe { from_glib(ffi::g_drive_can_eject(self.as_ref().to_glib_none().0)) }
110    }
111
112    /// Checks if a drive can be polled for media changes.
113    ///
114    /// # Returns
115    ///
116    /// [`true`] if the @self can be polled for media changes,
117    ///     [`false`] otherwise.
118    #[doc(alias = "g_drive_can_poll_for_media")]
119    fn can_poll_for_media(&self) -> bool {
120        unsafe {
121            from_glib(ffi::g_drive_can_poll_for_media(
122                self.as_ref().to_glib_none().0,
123            ))
124        }
125    }
126
127    /// Checks if a drive can be started.
128    ///
129    /// # Returns
130    ///
131    /// [`true`] if the @self can be started, [`false`] otherwise.
132    #[doc(alias = "g_drive_can_start")]
133    fn can_start(&self) -> bool {
134        unsafe { from_glib(ffi::g_drive_can_start(self.as_ref().to_glib_none().0)) }
135    }
136
137    /// Checks if a drive can be started degraded.
138    ///
139    /// # Returns
140    ///
141    /// [`true`] if the @self can be started degraded, [`false`] otherwise.
142    #[doc(alias = "g_drive_can_start_degraded")]
143    fn can_start_degraded(&self) -> bool {
144        unsafe {
145            from_glib(ffi::g_drive_can_start_degraded(
146                self.as_ref().to_glib_none().0,
147            ))
148        }
149    }
150
151    /// Checks if a drive can be stopped.
152    ///
153    /// # Returns
154    ///
155    /// [`true`] if the @self can be stopped, [`false`] otherwise.
156    #[doc(alias = "g_drive_can_stop")]
157    fn can_stop(&self) -> bool {
158        unsafe { from_glib(ffi::g_drive_can_stop(self.as_ref().to_glib_none().0)) }
159    }
160
161    /// Ejects a drive. This is an asynchronous operation, and is
162    /// finished by calling g_drive_eject_with_operation_finish() with the @self
163    /// and #GAsyncResult data returned in the @callback.
164    /// ## `flags`
165    /// flags affecting the unmount if required for eject
166    /// ## `mount_operation`
167    /// a #GMountOperation or [`None`] to avoid
168    ///     user interaction.
169    /// ## `cancellable`
170    /// optional #GCancellable object, [`None`] to ignore.
171    /// ## `callback`
172    /// a #GAsyncReadyCallback, or [`None`].
173    #[doc(alias = "g_drive_eject_with_operation")]
174    fn eject_with_operation<P: FnOnce(Result<(), glib::Error>) + 'static>(
175        &self,
176        flags: MountUnmountFlags,
177        mount_operation: Option<&impl IsA<MountOperation>>,
178        cancellable: Option<&impl IsA<Cancellable>>,
179        callback: P,
180    ) {
181        let main_context = glib::MainContext::ref_thread_default();
182        let is_main_context_owner = main_context.is_owner();
183        let has_acquired_main_context = (!is_main_context_owner)
184            .then(|| main_context.acquire().ok())
185            .flatten();
186        assert!(
187            is_main_context_owner || has_acquired_main_context.is_some(),
188            "Async operations only allowed if the thread is owning the MainContext"
189        );
190
191        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
192            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
193        unsafe extern "C" fn eject_with_operation_trampoline<
194            P: FnOnce(Result<(), glib::Error>) + 'static,
195        >(
196            _source_object: *mut glib::gobject_ffi::GObject,
197            res: *mut crate::ffi::GAsyncResult,
198            user_data: glib::ffi::gpointer,
199        ) {
200            let mut error = std::ptr::null_mut();
201            ffi::g_drive_eject_with_operation_finish(_source_object as *mut _, res, &mut error);
202            let result = if error.is_null() {
203                Ok(())
204            } else {
205                Err(from_glib_full(error))
206            };
207            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
208                Box_::from_raw(user_data as *mut _);
209            let callback: P = callback.into_inner();
210            callback(result);
211        }
212        let callback = eject_with_operation_trampoline::<P>;
213        unsafe {
214            ffi::g_drive_eject_with_operation(
215                self.as_ref().to_glib_none().0,
216                flags.into_glib(),
217                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
218                cancellable.map(|p| p.as_ref()).to_glib_none().0,
219                Some(callback),
220                Box_::into_raw(user_data) as *mut _,
221            );
222        }
223    }
224
225    fn eject_with_operation_future(
226        &self,
227        flags: MountUnmountFlags,
228        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
229    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
230        let mount_operation = mount_operation.map(ToOwned::to_owned);
231        Box_::pin(crate::GioFuture::new(
232            self,
233            move |obj, cancellable, send| {
234                obj.eject_with_operation(
235                    flags,
236                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
237                    Some(cancellable),
238                    move |res| {
239                        send.resolve(res);
240                    },
241                );
242            },
243        ))
244    }
245
246    /// Gets the kinds of identifiers that @self has.
247    /// Use g_drive_get_identifier() to obtain the identifiers
248    /// themselves.
249    ///
250    /// # Returns
251    ///
252    /// a [`None`]-terminated
253    ///     array of strings containing kinds of identifiers. Use g_strfreev()
254    ///     to free.
255    #[doc(alias = "g_drive_enumerate_identifiers")]
256    fn enumerate_identifiers(&self) -> Vec<glib::GString> {
257        unsafe {
258            FromGlibPtrContainer::from_glib_full(ffi::g_drive_enumerate_identifiers(
259                self.as_ref().to_glib_none().0,
260            ))
261        }
262    }
263
264    /// Gets the icon for @self.
265    ///
266    /// # Returns
267    ///
268    /// #GIcon for the @self.
269    ///    Free the returned object with g_object_unref().
270    #[doc(alias = "g_drive_get_icon")]
271    #[doc(alias = "get_icon")]
272    fn icon(&self) -> Icon {
273        unsafe { from_glib_full(ffi::g_drive_get_icon(self.as_ref().to_glib_none().0)) }
274    }
275
276    /// Gets the identifier of the given kind for @self. The only
277    /// identifier currently available is
278    /// [`DRIVE_IDENTIFIER_KIND_UNIX_DEVICE`][crate::DRIVE_IDENTIFIER_KIND_UNIX_DEVICE].
279    /// ## `kind`
280    /// the kind of identifier to return
281    ///
282    /// # Returns
283    ///
284    /// a newly allocated string containing the
285    ///     requested identifier, or [`None`] if the #GDrive
286    ///     doesn't have this kind of identifier.
287    #[doc(alias = "g_drive_get_identifier")]
288    #[doc(alias = "get_identifier")]
289    fn identifier(&self, kind: &str) -> Option<glib::GString> {
290        unsafe {
291            from_glib_full(ffi::g_drive_get_identifier(
292                self.as_ref().to_glib_none().0,
293                kind.to_glib_none().0,
294            ))
295        }
296    }
297
298    /// Gets the name of @self.
299    ///
300    /// # Returns
301    ///
302    /// a string containing @self's name. The returned
303    ///     string should be freed when no longer needed.
304    #[doc(alias = "g_drive_get_name")]
305    #[doc(alias = "get_name")]
306    fn name(&self) -> glib::GString {
307        unsafe { from_glib_full(ffi::g_drive_get_name(self.as_ref().to_glib_none().0)) }
308    }
309
310    /// Gets the sort key for @self, if any.
311    ///
312    /// # Returns
313    ///
314    /// Sorting key for @self or [`None`] if no such key is available.
315    #[doc(alias = "g_drive_get_sort_key")]
316    #[doc(alias = "get_sort_key")]
317    fn sort_key(&self) -> Option<glib::GString> {
318        unsafe { from_glib_none(ffi::g_drive_get_sort_key(self.as_ref().to_glib_none().0)) }
319    }
320
321    /// Gets a hint about how a drive can be started/stopped.
322    ///
323    /// # Returns
324    ///
325    /// A value from the #GDriveStartStopType enumeration.
326    #[doc(alias = "g_drive_get_start_stop_type")]
327    #[doc(alias = "get_start_stop_type")]
328    fn start_stop_type(&self) -> DriveStartStopType {
329        unsafe {
330            from_glib(ffi::g_drive_get_start_stop_type(
331                self.as_ref().to_glib_none().0,
332            ))
333        }
334    }
335
336    /// Gets the icon for @self.
337    ///
338    /// # Returns
339    ///
340    /// symbolic #GIcon for the @self.
341    ///    Free the returned object with g_object_unref().
342    #[doc(alias = "g_drive_get_symbolic_icon")]
343    #[doc(alias = "get_symbolic_icon")]
344    fn symbolic_icon(&self) -> Icon {
345        unsafe {
346            from_glib_full(ffi::g_drive_get_symbolic_icon(
347                self.as_ref().to_glib_none().0,
348            ))
349        }
350    }
351
352    /// Get a list of mountable volumes for @self.
353    ///
354    /// The returned list should be freed with g_list_free(), after
355    /// its elements have been unreffed with g_object_unref().
356    ///
357    /// # Returns
358    ///
359    /// #GList containing any #GVolume objects on the given @self.
360    #[doc(alias = "g_drive_get_volumes")]
361    #[doc(alias = "get_volumes")]
362    fn volumes(&self) -> Vec<Volume> {
363        unsafe {
364            FromGlibPtrContainer::from_glib_full(ffi::g_drive_get_volumes(
365                self.as_ref().to_glib_none().0,
366            ))
367        }
368    }
369
370    /// Checks if the @self has media. Note that the OS may not be polling
371    /// the drive for media changes; see g_drive_is_media_check_automatic()
372    /// for more details.
373    ///
374    /// # Returns
375    ///
376    /// [`true`] if @self has media, [`false`] otherwise.
377    #[doc(alias = "g_drive_has_media")]
378    fn has_media(&self) -> bool {
379        unsafe { from_glib(ffi::g_drive_has_media(self.as_ref().to_glib_none().0)) }
380    }
381
382    /// Check if @self has any mountable volumes.
383    ///
384    /// # Returns
385    ///
386    /// [`true`] if the @self contains volumes, [`false`] otherwise.
387    #[doc(alias = "g_drive_has_volumes")]
388    fn has_volumes(&self) -> bool {
389        unsafe { from_glib(ffi::g_drive_has_volumes(self.as_ref().to_glib_none().0)) }
390    }
391
392    /// Checks if @self is capable of automatically detecting media changes.
393    ///
394    /// # Returns
395    ///
396    /// [`true`] if the @self is capable of automatically detecting
397    ///     media changes, [`false`] otherwise.
398    #[doc(alias = "g_drive_is_media_check_automatic")]
399    fn is_media_check_automatic(&self) -> bool {
400        unsafe {
401            from_glib(ffi::g_drive_is_media_check_automatic(
402                self.as_ref().to_glib_none().0,
403            ))
404        }
405    }
406
407    /// Checks if the @self supports removable media.
408    ///
409    /// # Returns
410    ///
411    /// [`true`] if @self supports removable media, [`false`] otherwise.
412    #[doc(alias = "g_drive_is_media_removable")]
413    fn is_media_removable(&self) -> bool {
414        unsafe {
415            from_glib(ffi::g_drive_is_media_removable(
416                self.as_ref().to_glib_none().0,
417            ))
418        }
419    }
420
421    /// Checks if the #GDrive and/or its media is considered removable by the user.
422    /// See g_drive_is_media_removable().
423    ///
424    /// # Returns
425    ///
426    /// [`true`] if @self and/or its media is considered removable, [`false`] otherwise.
427    #[doc(alias = "g_drive_is_removable")]
428    fn is_removable(&self) -> bool {
429        unsafe { from_glib(ffi::g_drive_is_removable(self.as_ref().to_glib_none().0)) }
430    }
431
432    /// Asynchronously polls @self to see if media has been inserted or removed.
433    ///
434    /// When the operation is finished, @callback will be called.
435    /// You can then call g_drive_poll_for_media_finish() to obtain the
436    /// result of the operation.
437    /// ## `cancellable`
438    /// optional #GCancellable object, [`None`] to ignore.
439    /// ## `callback`
440    /// a #GAsyncReadyCallback, or [`None`].
441    #[doc(alias = "g_drive_poll_for_media")]
442    fn poll_for_media<P: FnOnce(Result<(), glib::Error>) + 'static>(
443        &self,
444        cancellable: Option<&impl IsA<Cancellable>>,
445        callback: P,
446    ) {
447        let main_context = glib::MainContext::ref_thread_default();
448        let is_main_context_owner = main_context.is_owner();
449        let has_acquired_main_context = (!is_main_context_owner)
450            .then(|| main_context.acquire().ok())
451            .flatten();
452        assert!(
453            is_main_context_owner || has_acquired_main_context.is_some(),
454            "Async operations only allowed if the thread is owning the MainContext"
455        );
456
457        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
458            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
459        unsafe extern "C" fn poll_for_media_trampoline<
460            P: FnOnce(Result<(), glib::Error>) + 'static,
461        >(
462            _source_object: *mut glib::gobject_ffi::GObject,
463            res: *mut crate::ffi::GAsyncResult,
464            user_data: glib::ffi::gpointer,
465        ) {
466            let mut error = std::ptr::null_mut();
467            ffi::g_drive_poll_for_media_finish(_source_object as *mut _, res, &mut error);
468            let result = if error.is_null() {
469                Ok(())
470            } else {
471                Err(from_glib_full(error))
472            };
473            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
474                Box_::from_raw(user_data as *mut _);
475            let callback: P = callback.into_inner();
476            callback(result);
477        }
478        let callback = poll_for_media_trampoline::<P>;
479        unsafe {
480            ffi::g_drive_poll_for_media(
481                self.as_ref().to_glib_none().0,
482                cancellable.map(|p| p.as_ref()).to_glib_none().0,
483                Some(callback),
484                Box_::into_raw(user_data) as *mut _,
485            );
486        }
487    }
488
489    fn poll_for_media_future(
490        &self,
491    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
492        Box_::pin(crate::GioFuture::new(
493            self,
494            move |obj, cancellable, send| {
495                obj.poll_for_media(Some(cancellable), move |res| {
496                    send.resolve(res);
497                });
498            },
499        ))
500    }
501
502    /// Asynchronously starts a drive.
503    ///
504    /// When the operation is finished, @callback will be called.
505    /// You can then call g_drive_start_finish() to obtain the
506    /// result of the operation.
507    /// ## `flags`
508    /// flags affecting the start operation.
509    /// ## `mount_operation`
510    /// a #GMountOperation or [`None`] to avoid
511    ///     user interaction.
512    /// ## `cancellable`
513    /// optional #GCancellable object, [`None`] to ignore.
514    /// ## `callback`
515    /// a #GAsyncReadyCallback, or [`None`].
516    #[doc(alias = "g_drive_start")]
517    fn start<P: FnOnce(Result<(), glib::Error>) + 'static>(
518        &self,
519        flags: DriveStartFlags,
520        mount_operation: Option<&impl IsA<MountOperation>>,
521        cancellable: Option<&impl IsA<Cancellable>>,
522        callback: P,
523    ) {
524        let main_context = glib::MainContext::ref_thread_default();
525        let is_main_context_owner = main_context.is_owner();
526        let has_acquired_main_context = (!is_main_context_owner)
527            .then(|| main_context.acquire().ok())
528            .flatten();
529        assert!(
530            is_main_context_owner || has_acquired_main_context.is_some(),
531            "Async operations only allowed if the thread is owning the MainContext"
532        );
533
534        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
535            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
536        unsafe extern "C" fn start_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
537            _source_object: *mut glib::gobject_ffi::GObject,
538            res: *mut crate::ffi::GAsyncResult,
539            user_data: glib::ffi::gpointer,
540        ) {
541            let mut error = std::ptr::null_mut();
542            ffi::g_drive_start_finish(_source_object as *mut _, res, &mut error);
543            let result = if error.is_null() {
544                Ok(())
545            } else {
546                Err(from_glib_full(error))
547            };
548            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
549                Box_::from_raw(user_data as *mut _);
550            let callback: P = callback.into_inner();
551            callback(result);
552        }
553        let callback = start_trampoline::<P>;
554        unsafe {
555            ffi::g_drive_start(
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 start_future(
567        &self,
568        flags: DriveStartFlags,
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.start(
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    /// Asynchronously stops a drive.
588    ///
589    /// When the operation is finished, @callback will be called.
590    /// You can then call g_drive_stop_finish() to obtain the
591    /// result of the operation.
592    /// ## `flags`
593    /// flags affecting the unmount if required for stopping.
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_drive_stop")]
602    fn stop<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 stop_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
622            _source_object: *mut glib::gobject_ffi::GObject,
623            res: *mut crate::ffi::GAsyncResult,
624            user_data: glib::ffi::gpointer,
625        ) {
626            let mut error = std::ptr::null_mut();
627            ffi::g_drive_stop_finish(_source_object as *mut _, res, &mut error);
628            let result = if error.is_null() {
629                Ok(())
630            } else {
631                Err(from_glib_full(error))
632            };
633            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
634                Box_::from_raw(user_data as *mut _);
635            let callback: P = callback.into_inner();
636            callback(result);
637        }
638        let callback = stop_trampoline::<P>;
639        unsafe {
640            ffi::g_drive_stop(
641                self.as_ref().to_glib_none().0,
642                flags.into_glib(),
643                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
644                cancellable.map(|p| p.as_ref()).to_glib_none().0,
645                Some(callback),
646                Box_::into_raw(user_data) as *mut _,
647            );
648        }
649    }
650
651    fn stop_future(
652        &self,
653        flags: MountUnmountFlags,
654        mount_operation: Option<&(impl IsA<MountOperation> + Clone + 'static)>,
655    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
656        let mount_operation = mount_operation.map(ToOwned::to_owned);
657        Box_::pin(crate::GioFuture::new(
658            self,
659            move |obj, cancellable, send| {
660                obj.stop(
661                    flags,
662                    mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
663                    Some(cancellable),
664                    move |res| {
665                        send.resolve(res);
666                    },
667                );
668            },
669        ))
670    }
671
672    /// Emitted when the drive's state has changed.
673    #[doc(alias = "changed")]
674    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
675        unsafe extern "C" fn changed_trampoline<P: IsA<Drive>, F: Fn(&P) + 'static>(
676            this: *mut ffi::GDrive,
677            f: glib::ffi::gpointer,
678        ) {
679            let f: &F = &*(f as *const F);
680            f(Drive::from_glib_borrow(this).unsafe_cast_ref())
681        }
682        unsafe {
683            let f: Box_<F> = Box_::new(f);
684            connect_raw(
685                self.as_ptr() as *mut _,
686                b"changed\0".as_ptr() as *const _,
687                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
688                    changed_trampoline::<Self, F> as *const (),
689                )),
690                Box_::into_raw(f),
691            )
692        }
693    }
694
695    /// This signal is emitted when the #GDrive have been
696    /// disconnected. If the recipient is holding references to the
697    /// object they should release them so the object can be
698    /// finalized.
699    #[doc(alias = "disconnected")]
700    fn connect_disconnected<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
701        unsafe extern "C" fn disconnected_trampoline<P: IsA<Drive>, F: Fn(&P) + 'static>(
702            this: *mut ffi::GDrive,
703            f: glib::ffi::gpointer,
704        ) {
705            let f: &F = &*(f as *const F);
706            f(Drive::from_glib_borrow(this).unsafe_cast_ref())
707        }
708        unsafe {
709            let f: Box_<F> = Box_::new(f);
710            connect_raw(
711                self.as_ptr() as *mut _,
712                b"disconnected\0".as_ptr() as *const _,
713                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
714                    disconnected_trampoline::<Self, F> as *const (),
715                )),
716                Box_::into_raw(f),
717            )
718        }
719    }
720
721    /// Emitted when the physical eject button (if any) of a drive has
722    /// been pressed.
723    #[doc(alias = "eject-button")]
724    fn connect_eject_button<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
725        unsafe extern "C" fn eject_button_trampoline<P: IsA<Drive>, F: Fn(&P) + 'static>(
726            this: *mut ffi::GDrive,
727            f: glib::ffi::gpointer,
728        ) {
729            let f: &F = &*(f as *const F);
730            f(Drive::from_glib_borrow(this).unsafe_cast_ref())
731        }
732        unsafe {
733            let f: Box_<F> = Box_::new(f);
734            connect_raw(
735                self.as_ptr() as *mut _,
736                b"eject-button\0".as_ptr() as *const _,
737                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
738                    eject_button_trampoline::<Self, F> as *const (),
739                )),
740                Box_::into_raw(f),
741            )
742        }
743    }
744
745    /// Emitted when the physical stop button (if any) of a drive has
746    /// been pressed.
747    #[doc(alias = "stop-button")]
748    fn connect_stop_button<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
749        unsafe extern "C" fn stop_button_trampoline<P: IsA<Drive>, F: Fn(&P) + 'static>(
750            this: *mut ffi::GDrive,
751            f: glib::ffi::gpointer,
752        ) {
753            let f: &F = &*(f as *const F);
754            f(Drive::from_glib_borrow(this).unsafe_cast_ref())
755        }
756        unsafe {
757            let f: Box_<F> = Box_::new(f);
758            connect_raw(
759                self.as_ptr() as *mut _,
760                b"stop-button\0".as_ptr() as *const _,
761                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
762                    stop_button_trampoline::<Self, F> as *const (),
763                )),
764                Box_::into_raw(f),
765            )
766        }
767    }
768}
769
770impl<O: IsA<Drive>> DriveExt for O {}