gio/auto/
volume_monitor.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::{Drive, Mount, Volume, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// `GVolumeMonitor` is for listing the user interesting devices and volumes
16    /// on the computer. In other words, what a file selector or file manager
17    /// would show in a sidebar.
18    ///
19    /// `GVolumeMonitor` is not
20    /// thread-default-context aware (see
21    /// [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()]), and so should not be used
22    /// other than from the main thread, with no thread-default-context active.
23    ///
24    /// In order to receive updates about volumes and mounts monitored through GVFS,
25    /// a main loop must be running.
26    ///
27    /// ## Signals
28    ///
29    ///
30    /// #### `drive-changed`
31    ///  Emitted when a drive changes.
32    ///
33    ///
34    ///
35    ///
36    /// #### `drive-connected`
37    ///  Emitted when a drive is connected to the system.
38    ///
39    ///
40    ///
41    ///
42    /// #### `drive-disconnected`
43    ///  Emitted when a drive is disconnected from the system.
44    ///
45    ///
46    ///
47    ///
48    /// #### `drive-eject-button`
49    ///  Emitted when the eject button is pressed on @drive.
50    ///
51    ///
52    ///
53    ///
54    /// #### `drive-stop-button`
55    ///  Emitted when the stop button is pressed on @drive.
56    ///
57    ///
58    ///
59    ///
60    /// #### `mount-added`
61    ///  Emitted when a mount is added.
62    ///
63    ///
64    ///
65    ///
66    /// #### `mount-changed`
67    ///  Emitted when a mount changes.
68    ///
69    ///
70    ///
71    ///
72    /// #### `mount-pre-unmount`
73    ///  May be emitted when a mount is about to be removed.
74    ///
75    /// This signal depends on the backend and is only emitted if
76    /// GIO was used to unmount.
77    ///
78    ///
79    ///
80    ///
81    /// #### `mount-removed`
82    ///  Emitted when a mount is removed.
83    ///
84    ///
85    ///
86    ///
87    /// #### `volume-added`
88    ///  Emitted when a mountable volume is added to the system.
89    ///
90    ///
91    ///
92    ///
93    /// #### `volume-changed`
94    ///  Emitted when mountable volume is changed.
95    ///
96    ///
97    ///
98    ///
99    /// #### `volume-removed`
100    ///  Emitted when a mountable volume is removed from the system.
101    ///
102    ///
103    ///
104    /// # Implements
105    ///
106    /// [`VolumeMonitorExt`][trait@crate::prelude::VolumeMonitorExt], [`trait@glib::ObjectExt`]
107    #[doc(alias = "GVolumeMonitor")]
108    pub struct VolumeMonitor(Object<ffi::GVolumeMonitor, ffi::GVolumeMonitorClass>);
109
110    match fn {
111        type_ => || ffi::g_volume_monitor_get_type(),
112    }
113}
114
115impl VolumeMonitor {
116    pub const NONE: Option<&'static VolumeMonitor> = None;
117
118    /// Gets the volume monitor used by gio.
119    ///
120    /// # Returns
121    ///
122    /// a reference to the #GVolumeMonitor used by gio. Call
123    ///    g_object_unref() when done with it, after disconnecting any signal handlers.
124    #[doc(alias = "g_volume_monitor_get")]
125    pub fn get() -> VolumeMonitor {
126        unsafe { from_glib_full(ffi::g_volume_monitor_get()) }
127    }
128}
129
130/// Trait containing all [`struct@VolumeMonitor`] methods.
131///
132/// # Implementors
133///
134/// [`NativeVolumeMonitor`][struct@crate::NativeVolumeMonitor], [`VolumeMonitor`][struct@crate::VolumeMonitor]
135pub trait VolumeMonitorExt: IsA<VolumeMonitor> + 'static {
136    /// Gets a list of drives connected to the system.
137    ///
138    /// The returned list should be freed with g_list_free(), after
139    /// its elements have been unreffed with g_object_unref().
140    ///
141    /// # Returns
142    ///
143    /// a #GList of connected #GDrive objects.
144    #[doc(alias = "g_volume_monitor_get_connected_drives")]
145    #[doc(alias = "get_connected_drives")]
146    fn connected_drives(&self) -> Vec<Drive> {
147        unsafe {
148            FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_connected_drives(
149                self.as_ref().to_glib_none().0,
150            ))
151        }
152    }
153
154    /// Finds a #GMount object by its UUID (see g_mount_get_uuid())
155    /// ## `uuid`
156    /// the UUID to look for
157    ///
158    /// # Returns
159    ///
160    /// a #GMount or [`None`] if no such mount is available.
161    ///     Free the returned object with g_object_unref().
162    #[doc(alias = "g_volume_monitor_get_mount_for_uuid")]
163    #[doc(alias = "get_mount_for_uuid")]
164    fn mount_for_uuid(&self, uuid: &str) -> Option<Mount> {
165        unsafe {
166            from_glib_full(ffi::g_volume_monitor_get_mount_for_uuid(
167                self.as_ref().to_glib_none().0,
168                uuid.to_glib_none().0,
169            ))
170        }
171    }
172
173    /// Gets a list of the mounts on the system.
174    ///
175    /// The returned list should be freed with g_list_free(), after
176    /// its elements have been unreffed with g_object_unref().
177    ///
178    /// # Returns
179    ///
180    /// a #GList of #GMount objects.
181    #[doc(alias = "g_volume_monitor_get_mounts")]
182    #[doc(alias = "get_mounts")]
183    fn mounts(&self) -> Vec<Mount> {
184        unsafe {
185            FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_mounts(
186                self.as_ref().to_glib_none().0,
187            ))
188        }
189    }
190
191    /// Finds a #GVolume object by its UUID (see g_volume_get_uuid())
192    /// ## `uuid`
193    /// the UUID to look for
194    ///
195    /// # Returns
196    ///
197    /// a #GVolume or [`None`] if no such volume is available.
198    ///     Free the returned object with g_object_unref().
199    #[doc(alias = "g_volume_monitor_get_volume_for_uuid")]
200    #[doc(alias = "get_volume_for_uuid")]
201    fn volume_for_uuid(&self, uuid: &str) -> Option<Volume> {
202        unsafe {
203            from_glib_full(ffi::g_volume_monitor_get_volume_for_uuid(
204                self.as_ref().to_glib_none().0,
205                uuid.to_glib_none().0,
206            ))
207        }
208    }
209
210    /// Gets a list of the volumes on the system.
211    ///
212    /// The returned list should be freed with g_list_free(), after
213    /// its elements have been unreffed with g_object_unref().
214    ///
215    /// # Returns
216    ///
217    /// a #GList of #GVolume objects.
218    #[doc(alias = "g_volume_monitor_get_volumes")]
219    #[doc(alias = "get_volumes")]
220    fn volumes(&self) -> Vec<Volume> {
221        unsafe {
222            FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_volumes(
223                self.as_ref().to_glib_none().0,
224            ))
225        }
226    }
227
228    /// Emitted when a drive changes.
229    /// ## `drive`
230    /// the drive that changed
231    #[doc(alias = "drive-changed")]
232    fn connect_drive_changed<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
233        unsafe extern "C" fn drive_changed_trampoline<
234            P: IsA<VolumeMonitor>,
235            F: Fn(&P, &Drive) + 'static,
236        >(
237            this: *mut ffi::GVolumeMonitor,
238            drive: *mut ffi::GDrive,
239            f: glib::ffi::gpointer,
240        ) {
241            unsafe {
242                let f: &F = &*(f as *const F);
243                f(
244                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
245                    &from_glib_borrow(drive),
246                )
247            }
248        }
249        unsafe {
250            let f: Box_<F> = Box_::new(f);
251            connect_raw(
252                self.as_ptr() as *mut _,
253                c"drive-changed".as_ptr() as *const _,
254                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
255                    drive_changed_trampoline::<Self, F> as *const (),
256                )),
257                Box_::into_raw(f),
258            )
259        }
260    }
261
262    /// Emitted when a drive is connected to the system.
263    /// ## `drive`
264    /// a #GDrive that was connected.
265    #[doc(alias = "drive-connected")]
266    fn connect_drive_connected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
267        unsafe extern "C" fn drive_connected_trampoline<
268            P: IsA<VolumeMonitor>,
269            F: Fn(&P, &Drive) + 'static,
270        >(
271            this: *mut ffi::GVolumeMonitor,
272            drive: *mut ffi::GDrive,
273            f: glib::ffi::gpointer,
274        ) {
275            unsafe {
276                let f: &F = &*(f as *const F);
277                f(
278                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
279                    &from_glib_borrow(drive),
280                )
281            }
282        }
283        unsafe {
284            let f: Box_<F> = Box_::new(f);
285            connect_raw(
286                self.as_ptr() as *mut _,
287                c"drive-connected".as_ptr() as *const _,
288                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289                    drive_connected_trampoline::<Self, F> as *const (),
290                )),
291                Box_::into_raw(f),
292            )
293        }
294    }
295
296    /// Emitted when a drive is disconnected from the system.
297    /// ## `drive`
298    /// a #GDrive that was disconnected.
299    #[doc(alias = "drive-disconnected")]
300    fn connect_drive_disconnected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
301        unsafe extern "C" fn drive_disconnected_trampoline<
302            P: IsA<VolumeMonitor>,
303            F: Fn(&P, &Drive) + 'static,
304        >(
305            this: *mut ffi::GVolumeMonitor,
306            drive: *mut ffi::GDrive,
307            f: glib::ffi::gpointer,
308        ) {
309            unsafe {
310                let f: &F = &*(f as *const F);
311                f(
312                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
313                    &from_glib_borrow(drive),
314                )
315            }
316        }
317        unsafe {
318            let f: Box_<F> = Box_::new(f);
319            connect_raw(
320                self.as_ptr() as *mut _,
321                c"drive-disconnected".as_ptr() as *const _,
322                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
323                    drive_disconnected_trampoline::<Self, F> as *const (),
324                )),
325                Box_::into_raw(f),
326            )
327        }
328    }
329
330    /// Emitted when the eject button is pressed on @drive.
331    /// ## `drive`
332    /// the drive where the eject button was pressed
333    #[doc(alias = "drive-eject-button")]
334    fn connect_drive_eject_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
335        unsafe extern "C" fn drive_eject_button_trampoline<
336            P: IsA<VolumeMonitor>,
337            F: Fn(&P, &Drive) + 'static,
338        >(
339            this: *mut ffi::GVolumeMonitor,
340            drive: *mut ffi::GDrive,
341            f: glib::ffi::gpointer,
342        ) {
343            unsafe {
344                let f: &F = &*(f as *const F);
345                f(
346                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
347                    &from_glib_borrow(drive),
348                )
349            }
350        }
351        unsafe {
352            let f: Box_<F> = Box_::new(f);
353            connect_raw(
354                self.as_ptr() as *mut _,
355                c"drive-eject-button".as_ptr() as *const _,
356                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
357                    drive_eject_button_trampoline::<Self, F> as *const (),
358                )),
359                Box_::into_raw(f),
360            )
361        }
362    }
363
364    /// Emitted when the stop button is pressed on @drive.
365    /// ## `drive`
366    /// the drive where the stop button was pressed
367    #[doc(alias = "drive-stop-button")]
368    fn connect_drive_stop_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
369        unsafe extern "C" fn drive_stop_button_trampoline<
370            P: IsA<VolumeMonitor>,
371            F: Fn(&P, &Drive) + 'static,
372        >(
373            this: *mut ffi::GVolumeMonitor,
374            drive: *mut ffi::GDrive,
375            f: glib::ffi::gpointer,
376        ) {
377            unsafe {
378                let f: &F = &*(f as *const F);
379                f(
380                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
381                    &from_glib_borrow(drive),
382                )
383            }
384        }
385        unsafe {
386            let f: Box_<F> = Box_::new(f);
387            connect_raw(
388                self.as_ptr() as *mut _,
389                c"drive-stop-button".as_ptr() as *const _,
390                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
391                    drive_stop_button_trampoline::<Self, F> as *const (),
392                )),
393                Box_::into_raw(f),
394            )
395        }
396    }
397
398    /// Emitted when a mount is added.
399    /// ## `mount`
400    /// a #GMount that was added.
401    #[doc(alias = "mount-added")]
402    fn connect_mount_added<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
403        unsafe extern "C" fn mount_added_trampoline<
404            P: IsA<VolumeMonitor>,
405            F: Fn(&P, &Mount) + 'static,
406        >(
407            this: *mut ffi::GVolumeMonitor,
408            mount: *mut ffi::GMount,
409            f: glib::ffi::gpointer,
410        ) {
411            unsafe {
412                let f: &F = &*(f as *const F);
413                f(
414                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
415                    &from_glib_borrow(mount),
416                )
417            }
418        }
419        unsafe {
420            let f: Box_<F> = Box_::new(f);
421            connect_raw(
422                self.as_ptr() as *mut _,
423                c"mount-added".as_ptr() as *const _,
424                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
425                    mount_added_trampoline::<Self, F> as *const (),
426                )),
427                Box_::into_raw(f),
428            )
429        }
430    }
431
432    /// Emitted when a mount changes.
433    /// ## `mount`
434    /// a #GMount that changed.
435    #[doc(alias = "mount-changed")]
436    fn connect_mount_changed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
437        unsafe extern "C" fn mount_changed_trampoline<
438            P: IsA<VolumeMonitor>,
439            F: Fn(&P, &Mount) + 'static,
440        >(
441            this: *mut ffi::GVolumeMonitor,
442            mount: *mut ffi::GMount,
443            f: glib::ffi::gpointer,
444        ) {
445            unsafe {
446                let f: &F = &*(f as *const F);
447                f(
448                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
449                    &from_glib_borrow(mount),
450                )
451            }
452        }
453        unsafe {
454            let f: Box_<F> = Box_::new(f);
455            connect_raw(
456                self.as_ptr() as *mut _,
457                c"mount-changed".as_ptr() as *const _,
458                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
459                    mount_changed_trampoline::<Self, F> as *const (),
460                )),
461                Box_::into_raw(f),
462            )
463        }
464    }
465
466    /// May be emitted when a mount is about to be removed.
467    ///
468    /// This signal depends on the backend and is only emitted if
469    /// GIO was used to unmount.
470    /// ## `mount`
471    /// a #GMount that is being unmounted.
472    #[doc(alias = "mount-pre-unmount")]
473    fn connect_mount_pre_unmount<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
474        unsafe extern "C" fn mount_pre_unmount_trampoline<
475            P: IsA<VolumeMonitor>,
476            F: Fn(&P, &Mount) + 'static,
477        >(
478            this: *mut ffi::GVolumeMonitor,
479            mount: *mut ffi::GMount,
480            f: glib::ffi::gpointer,
481        ) {
482            unsafe {
483                let f: &F = &*(f as *const F);
484                f(
485                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
486                    &from_glib_borrow(mount),
487                )
488            }
489        }
490        unsafe {
491            let f: Box_<F> = Box_::new(f);
492            connect_raw(
493                self.as_ptr() as *mut _,
494                c"mount-pre-unmount".as_ptr() as *const _,
495                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
496                    mount_pre_unmount_trampoline::<Self, F> as *const (),
497                )),
498                Box_::into_raw(f),
499            )
500        }
501    }
502
503    /// Emitted when a mount is removed.
504    /// ## `mount`
505    /// a #GMount that was removed.
506    #[doc(alias = "mount-removed")]
507    fn connect_mount_removed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
508        unsafe extern "C" fn mount_removed_trampoline<
509            P: IsA<VolumeMonitor>,
510            F: Fn(&P, &Mount) + 'static,
511        >(
512            this: *mut ffi::GVolumeMonitor,
513            mount: *mut ffi::GMount,
514            f: glib::ffi::gpointer,
515        ) {
516            unsafe {
517                let f: &F = &*(f as *const F);
518                f(
519                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
520                    &from_glib_borrow(mount),
521                )
522            }
523        }
524        unsafe {
525            let f: Box_<F> = Box_::new(f);
526            connect_raw(
527                self.as_ptr() as *mut _,
528                c"mount-removed".as_ptr() as *const _,
529                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
530                    mount_removed_trampoline::<Self, F> as *const (),
531                )),
532                Box_::into_raw(f),
533            )
534        }
535    }
536
537    /// Emitted when a mountable volume is added to the system.
538    /// ## `volume`
539    /// a #GVolume that was added.
540    #[doc(alias = "volume-added")]
541    fn connect_volume_added<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
542        unsafe extern "C" fn volume_added_trampoline<
543            P: IsA<VolumeMonitor>,
544            F: Fn(&P, &Volume) + 'static,
545        >(
546            this: *mut ffi::GVolumeMonitor,
547            volume: *mut ffi::GVolume,
548            f: glib::ffi::gpointer,
549        ) {
550            unsafe {
551                let f: &F = &*(f as *const F);
552                f(
553                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
554                    &from_glib_borrow(volume),
555                )
556            }
557        }
558        unsafe {
559            let f: Box_<F> = Box_::new(f);
560            connect_raw(
561                self.as_ptr() as *mut _,
562                c"volume-added".as_ptr() as *const _,
563                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
564                    volume_added_trampoline::<Self, F> as *const (),
565                )),
566                Box_::into_raw(f),
567            )
568        }
569    }
570
571    /// Emitted when mountable volume is changed.
572    /// ## `volume`
573    /// a #GVolume that changed.
574    #[doc(alias = "volume-changed")]
575    fn connect_volume_changed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
576        unsafe extern "C" fn volume_changed_trampoline<
577            P: IsA<VolumeMonitor>,
578            F: Fn(&P, &Volume) + 'static,
579        >(
580            this: *mut ffi::GVolumeMonitor,
581            volume: *mut ffi::GVolume,
582            f: glib::ffi::gpointer,
583        ) {
584            unsafe {
585                let f: &F = &*(f as *const F);
586                f(
587                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
588                    &from_glib_borrow(volume),
589                )
590            }
591        }
592        unsafe {
593            let f: Box_<F> = Box_::new(f);
594            connect_raw(
595                self.as_ptr() as *mut _,
596                c"volume-changed".as_ptr() as *const _,
597                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598                    volume_changed_trampoline::<Self, F> as *const (),
599                )),
600                Box_::into_raw(f),
601            )
602        }
603    }
604
605    /// Emitted when a mountable volume is removed from the system.
606    /// ## `volume`
607    /// a #GVolume that was removed.
608    #[doc(alias = "volume-removed")]
609    fn connect_volume_removed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
610        unsafe extern "C" fn volume_removed_trampoline<
611            P: IsA<VolumeMonitor>,
612            F: Fn(&P, &Volume) + 'static,
613        >(
614            this: *mut ffi::GVolumeMonitor,
615            volume: *mut ffi::GVolume,
616            f: glib::ffi::gpointer,
617        ) {
618            unsafe {
619                let f: &F = &*(f as *const F);
620                f(
621                    VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
622                    &from_glib_borrow(volume),
623                )
624            }
625        }
626        unsafe {
627            let f: Box_<F> = Box_::new(f);
628            connect_raw(
629                self.as_ptr() as *mut _,
630                c"volume-removed".as_ptr() as *const _,
631                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
632                    volume_removed_trampoline::<Self, F> as *const (),
633                )),
634                Box_::into_raw(f),
635            )
636        }
637    }
638}
639
640impl<O: IsA<VolumeMonitor>> VolumeMonitorExt for O {}