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::{ffi, Drive, Mount, Volume};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
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.
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
130mod sealed {
131    pub trait Sealed {}
132    impl<T: super::IsA<super::VolumeMonitor>> Sealed for T {}
133}
134
135/// Trait containing all [`struct@VolumeMonitor`] methods.
136///
137/// # Implementors
138///
139/// [`NativeVolumeMonitor`][struct@crate::NativeVolumeMonitor], [`VolumeMonitor`][struct@crate::VolumeMonitor]
140pub trait VolumeMonitorExt: IsA<VolumeMonitor> + sealed::Sealed + 'static {
141    /// Gets a list of drives connected to the system.
142    ///
143    /// The returned list should be freed with g_list_free(), after
144    /// its elements have been unreffed with g_object_unref().
145    ///
146    /// # Returns
147    ///
148    /// a #GList of connected #GDrive objects.
149    #[doc(alias = "g_volume_monitor_get_connected_drives")]
150    #[doc(alias = "get_connected_drives")]
151    fn connected_drives(&self) -> Vec<Drive> {
152        unsafe {
153            FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_connected_drives(
154                self.as_ref().to_glib_none().0,
155            ))
156        }
157    }
158
159    /// Finds a #GMount object by its UUID (see g_mount_get_uuid())
160    /// ## `uuid`
161    /// the UUID to look for
162    ///
163    /// # Returns
164    ///
165    /// a #GMount or [`None`] if no such mount is available.
166    ///     Free the returned object with g_object_unref().
167    #[doc(alias = "g_volume_monitor_get_mount_for_uuid")]
168    #[doc(alias = "get_mount_for_uuid")]
169    fn mount_for_uuid(&self, uuid: &str) -> Option<Mount> {
170        unsafe {
171            from_glib_full(ffi::g_volume_monitor_get_mount_for_uuid(
172                self.as_ref().to_glib_none().0,
173                uuid.to_glib_none().0,
174            ))
175        }
176    }
177
178    /// Gets a list of the mounts on the system.
179    ///
180    /// The returned list should be freed with g_list_free(), after
181    /// its elements have been unreffed with g_object_unref().
182    ///
183    /// # Returns
184    ///
185    /// a #GList of #GMount objects.
186    #[doc(alias = "g_volume_monitor_get_mounts")]
187    #[doc(alias = "get_mounts")]
188    fn mounts(&self) -> Vec<Mount> {
189        unsafe {
190            FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_mounts(
191                self.as_ref().to_glib_none().0,
192            ))
193        }
194    }
195
196    /// Finds a #GVolume object by its UUID (see g_volume_get_uuid())
197    /// ## `uuid`
198    /// the UUID to look for
199    ///
200    /// # Returns
201    ///
202    /// a #GVolume or [`None`] if no such volume is available.
203    ///     Free the returned object with g_object_unref().
204    #[doc(alias = "g_volume_monitor_get_volume_for_uuid")]
205    #[doc(alias = "get_volume_for_uuid")]
206    fn volume_for_uuid(&self, uuid: &str) -> Option<Volume> {
207        unsafe {
208            from_glib_full(ffi::g_volume_monitor_get_volume_for_uuid(
209                self.as_ref().to_glib_none().0,
210                uuid.to_glib_none().0,
211            ))
212        }
213    }
214
215    /// Gets a list of the volumes on the system.
216    ///
217    /// The returned list should be freed with g_list_free(), after
218    /// its elements have been unreffed with g_object_unref().
219    ///
220    /// # Returns
221    ///
222    /// a #GList of #GVolume objects.
223    #[doc(alias = "g_volume_monitor_get_volumes")]
224    #[doc(alias = "get_volumes")]
225    fn volumes(&self) -> Vec<Volume> {
226        unsafe {
227            FromGlibPtrContainer::from_glib_full(ffi::g_volume_monitor_get_volumes(
228                self.as_ref().to_glib_none().0,
229            ))
230        }
231    }
232
233    /// Emitted when a drive changes.
234    /// ## `drive`
235    /// the drive that changed
236    #[doc(alias = "drive-changed")]
237    fn connect_drive_changed<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
238        unsafe extern "C" fn drive_changed_trampoline<
239            P: IsA<VolumeMonitor>,
240            F: Fn(&P, &Drive) + 'static,
241        >(
242            this: *mut ffi::GVolumeMonitor,
243            drive: *mut ffi::GDrive,
244            f: glib::ffi::gpointer,
245        ) {
246            let f: &F = &*(f as *const F);
247            f(
248                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
249                &from_glib_borrow(drive),
250            )
251        }
252        unsafe {
253            let f: Box_<F> = Box_::new(f);
254            connect_raw(
255                self.as_ptr() as *mut _,
256                b"drive-changed\0".as_ptr() as *const _,
257                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258                    drive_changed_trampoline::<Self, F> as *const (),
259                )),
260                Box_::into_raw(f),
261            )
262        }
263    }
264
265    /// Emitted when a drive is connected to the system.
266    /// ## `drive`
267    /// a #GDrive that was connected.
268    #[doc(alias = "drive-connected")]
269    fn connect_drive_connected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
270        unsafe extern "C" fn drive_connected_trampoline<
271            P: IsA<VolumeMonitor>,
272            F: Fn(&P, &Drive) + 'static,
273        >(
274            this: *mut ffi::GVolumeMonitor,
275            drive: *mut ffi::GDrive,
276            f: glib::ffi::gpointer,
277        ) {
278            let f: &F = &*(f as *const F);
279            f(
280                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
281                &from_glib_borrow(drive),
282            )
283        }
284        unsafe {
285            let f: Box_<F> = Box_::new(f);
286            connect_raw(
287                self.as_ptr() as *mut _,
288                b"drive-connected\0".as_ptr() as *const _,
289                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290                    drive_connected_trampoline::<Self, F> as *const (),
291                )),
292                Box_::into_raw(f),
293            )
294        }
295    }
296
297    /// Emitted when a drive is disconnected from the system.
298    /// ## `drive`
299    /// a #GDrive that was disconnected.
300    #[doc(alias = "drive-disconnected")]
301    fn connect_drive_disconnected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
302        unsafe extern "C" fn drive_disconnected_trampoline<
303            P: IsA<VolumeMonitor>,
304            F: Fn(&P, &Drive) + 'static,
305        >(
306            this: *mut ffi::GVolumeMonitor,
307            drive: *mut ffi::GDrive,
308            f: glib::ffi::gpointer,
309        ) {
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        unsafe {
317            let f: Box_<F> = Box_::new(f);
318            connect_raw(
319                self.as_ptr() as *mut _,
320                b"drive-disconnected\0".as_ptr() as *const _,
321                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
322                    drive_disconnected_trampoline::<Self, F> as *const (),
323                )),
324                Box_::into_raw(f),
325            )
326        }
327    }
328
329    /// Emitted when the eject button is pressed on @drive.
330    /// ## `drive`
331    /// the drive where the eject button was pressed
332    #[doc(alias = "drive-eject-button")]
333    fn connect_drive_eject_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
334        unsafe extern "C" fn drive_eject_button_trampoline<
335            P: IsA<VolumeMonitor>,
336            F: Fn(&P, &Drive) + 'static,
337        >(
338            this: *mut ffi::GVolumeMonitor,
339            drive: *mut ffi::GDrive,
340            f: glib::ffi::gpointer,
341        ) {
342            let f: &F = &*(f as *const F);
343            f(
344                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
345                &from_glib_borrow(drive),
346            )
347        }
348        unsafe {
349            let f: Box_<F> = Box_::new(f);
350            connect_raw(
351                self.as_ptr() as *mut _,
352                b"drive-eject-button\0".as_ptr() as *const _,
353                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
354                    drive_eject_button_trampoline::<Self, F> as *const (),
355                )),
356                Box_::into_raw(f),
357            )
358        }
359    }
360
361    /// Emitted when the stop button is pressed on @drive.
362    /// ## `drive`
363    /// the drive where the stop button was pressed
364    #[doc(alias = "drive-stop-button")]
365    fn connect_drive_stop_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
366        unsafe extern "C" fn drive_stop_button_trampoline<
367            P: IsA<VolumeMonitor>,
368            F: Fn(&P, &Drive) + 'static,
369        >(
370            this: *mut ffi::GVolumeMonitor,
371            drive: *mut ffi::GDrive,
372            f: glib::ffi::gpointer,
373        ) {
374            let f: &F = &*(f as *const F);
375            f(
376                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
377                &from_glib_borrow(drive),
378            )
379        }
380        unsafe {
381            let f: Box_<F> = Box_::new(f);
382            connect_raw(
383                self.as_ptr() as *mut _,
384                b"drive-stop-button\0".as_ptr() as *const _,
385                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386                    drive_stop_button_trampoline::<Self, F> as *const (),
387                )),
388                Box_::into_raw(f),
389            )
390        }
391    }
392
393    /// Emitted when a mount is added.
394    /// ## `mount`
395    /// a #GMount that was added.
396    #[doc(alias = "mount-added")]
397    fn connect_mount_added<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
398        unsafe extern "C" fn mount_added_trampoline<
399            P: IsA<VolumeMonitor>,
400            F: Fn(&P, &Mount) + 'static,
401        >(
402            this: *mut ffi::GVolumeMonitor,
403            mount: *mut ffi::GMount,
404            f: glib::ffi::gpointer,
405        ) {
406            let f: &F = &*(f as *const F);
407            f(
408                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
409                &from_glib_borrow(mount),
410            )
411        }
412        unsafe {
413            let f: Box_<F> = Box_::new(f);
414            connect_raw(
415                self.as_ptr() as *mut _,
416                b"mount-added\0".as_ptr() as *const _,
417                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418                    mount_added_trampoline::<Self, F> as *const (),
419                )),
420                Box_::into_raw(f),
421            )
422        }
423    }
424
425    /// Emitted when a mount changes.
426    /// ## `mount`
427    /// a #GMount that changed.
428    #[doc(alias = "mount-changed")]
429    fn connect_mount_changed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
430        unsafe extern "C" fn mount_changed_trampoline<
431            P: IsA<VolumeMonitor>,
432            F: Fn(&P, &Mount) + 'static,
433        >(
434            this: *mut ffi::GVolumeMonitor,
435            mount: *mut ffi::GMount,
436            f: glib::ffi::gpointer,
437        ) {
438            let f: &F = &*(f as *const F);
439            f(
440                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
441                &from_glib_borrow(mount),
442            )
443        }
444        unsafe {
445            let f: Box_<F> = Box_::new(f);
446            connect_raw(
447                self.as_ptr() as *mut _,
448                b"mount-changed\0".as_ptr() as *const _,
449                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450                    mount_changed_trampoline::<Self, F> as *const (),
451                )),
452                Box_::into_raw(f),
453            )
454        }
455    }
456
457    /// May be emitted when a mount is about to be removed.
458    ///
459    /// This signal depends on the backend and is only emitted if
460    /// GIO was used to unmount.
461    /// ## `mount`
462    /// a #GMount that is being unmounted.
463    #[doc(alias = "mount-pre-unmount")]
464    fn connect_mount_pre_unmount<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
465        unsafe extern "C" fn mount_pre_unmount_trampoline<
466            P: IsA<VolumeMonitor>,
467            F: Fn(&P, &Mount) + 'static,
468        >(
469            this: *mut ffi::GVolumeMonitor,
470            mount: *mut ffi::GMount,
471            f: glib::ffi::gpointer,
472        ) {
473            let f: &F = &*(f as *const F);
474            f(
475                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
476                &from_glib_borrow(mount),
477            )
478        }
479        unsafe {
480            let f: Box_<F> = Box_::new(f);
481            connect_raw(
482                self.as_ptr() as *mut _,
483                b"mount-pre-unmount\0".as_ptr() as *const _,
484                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
485                    mount_pre_unmount_trampoline::<Self, F> as *const (),
486                )),
487                Box_::into_raw(f),
488            )
489        }
490    }
491
492    /// Emitted when a mount is removed.
493    /// ## `mount`
494    /// a #GMount that was removed.
495    #[doc(alias = "mount-removed")]
496    fn connect_mount_removed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
497        unsafe extern "C" fn mount_removed_trampoline<
498            P: IsA<VolumeMonitor>,
499            F: Fn(&P, &Mount) + 'static,
500        >(
501            this: *mut ffi::GVolumeMonitor,
502            mount: *mut ffi::GMount,
503            f: glib::ffi::gpointer,
504        ) {
505            let f: &F = &*(f as *const F);
506            f(
507                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
508                &from_glib_borrow(mount),
509            )
510        }
511        unsafe {
512            let f: Box_<F> = Box_::new(f);
513            connect_raw(
514                self.as_ptr() as *mut _,
515                b"mount-removed\0".as_ptr() as *const _,
516                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
517                    mount_removed_trampoline::<Self, F> as *const (),
518                )),
519                Box_::into_raw(f),
520            )
521        }
522    }
523
524    /// Emitted when a mountable volume is added to the system.
525    /// ## `volume`
526    /// a #GVolume that was added.
527    #[doc(alias = "volume-added")]
528    fn connect_volume_added<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
529        unsafe extern "C" fn volume_added_trampoline<
530            P: IsA<VolumeMonitor>,
531            F: Fn(&P, &Volume) + 'static,
532        >(
533            this: *mut ffi::GVolumeMonitor,
534            volume: *mut ffi::GVolume,
535            f: glib::ffi::gpointer,
536        ) {
537            let f: &F = &*(f as *const F);
538            f(
539                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
540                &from_glib_borrow(volume),
541            )
542        }
543        unsafe {
544            let f: Box_<F> = Box_::new(f);
545            connect_raw(
546                self.as_ptr() as *mut _,
547                b"volume-added\0".as_ptr() as *const _,
548                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
549                    volume_added_trampoline::<Self, F> as *const (),
550                )),
551                Box_::into_raw(f),
552            )
553        }
554    }
555
556    /// Emitted when mountable volume is changed.
557    /// ## `volume`
558    /// a #GVolume that changed.
559    #[doc(alias = "volume-changed")]
560    fn connect_volume_changed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
561        unsafe extern "C" fn volume_changed_trampoline<
562            P: IsA<VolumeMonitor>,
563            F: Fn(&P, &Volume) + 'static,
564        >(
565            this: *mut ffi::GVolumeMonitor,
566            volume: *mut ffi::GVolume,
567            f: glib::ffi::gpointer,
568        ) {
569            let f: &F = &*(f as *const F);
570            f(
571                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
572                &from_glib_borrow(volume),
573            )
574        }
575        unsafe {
576            let f: Box_<F> = Box_::new(f);
577            connect_raw(
578                self.as_ptr() as *mut _,
579                b"volume-changed\0".as_ptr() as *const _,
580                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
581                    volume_changed_trampoline::<Self, F> as *const (),
582                )),
583                Box_::into_raw(f),
584            )
585        }
586    }
587
588    /// Emitted when a mountable volume is removed from the system.
589    /// ## `volume`
590    /// a #GVolume that was removed.
591    #[doc(alias = "volume-removed")]
592    fn connect_volume_removed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
593        unsafe extern "C" fn volume_removed_trampoline<
594            P: IsA<VolumeMonitor>,
595            F: Fn(&P, &Volume) + 'static,
596        >(
597            this: *mut ffi::GVolumeMonitor,
598            volume: *mut ffi::GVolume,
599            f: glib::ffi::gpointer,
600        ) {
601            let f: &F = &*(f as *const F);
602            f(
603                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
604                &from_glib_borrow(volume),
605            )
606        }
607        unsafe {
608            let f: Box_<F> = Box_::new(f);
609            connect_raw(
610                self.as_ptr() as *mut _,
611                b"volume-removed\0".as_ptr() as *const _,
612                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
613                    volume_removed_trampoline::<Self, F> as *const (),
614                )),
615                Box_::into_raw(f),
616            )
617        }
618    }
619}
620
621impl<O: IsA<VolumeMonitor>> VolumeMonitorExt for O {}