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, 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            let f: &F = &*(f as *const F);
242            f(
243                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
244                &from_glib_borrow(drive),
245            )
246        }
247        unsafe {
248            let f: Box_<F> = Box_::new(f);
249            connect_raw(
250                self.as_ptr() as *mut _,
251                c"drive-changed".as_ptr() as *const _,
252                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253                    drive_changed_trampoline::<Self, F> as *const (),
254                )),
255                Box_::into_raw(f),
256            )
257        }
258    }
259
260    /// Emitted when a drive is connected to the system.
261    /// ## `drive`
262    /// a #GDrive that was connected.
263    #[doc(alias = "drive-connected")]
264    fn connect_drive_connected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
265        unsafe extern "C" fn drive_connected_trampoline<
266            P: IsA<VolumeMonitor>,
267            F: Fn(&P, &Drive) + 'static,
268        >(
269            this: *mut ffi::GVolumeMonitor,
270            drive: *mut ffi::GDrive,
271            f: glib::ffi::gpointer,
272        ) {
273            let f: &F = &*(f as *const F);
274            f(
275                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
276                &from_glib_borrow(drive),
277            )
278        }
279        unsafe {
280            let f: Box_<F> = Box_::new(f);
281            connect_raw(
282                self.as_ptr() as *mut _,
283                c"drive-connected".as_ptr() as *const _,
284                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
285                    drive_connected_trampoline::<Self, F> as *const (),
286                )),
287                Box_::into_raw(f),
288            )
289        }
290    }
291
292    /// Emitted when a drive is disconnected from the system.
293    /// ## `drive`
294    /// a #GDrive that was disconnected.
295    #[doc(alias = "drive-disconnected")]
296    fn connect_drive_disconnected<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
297        unsafe extern "C" fn drive_disconnected_trampoline<
298            P: IsA<VolumeMonitor>,
299            F: Fn(&P, &Drive) + 'static,
300        >(
301            this: *mut ffi::GVolumeMonitor,
302            drive: *mut ffi::GDrive,
303            f: glib::ffi::gpointer,
304        ) {
305            let f: &F = &*(f as *const F);
306            f(
307                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
308                &from_glib_borrow(drive),
309            )
310        }
311        unsafe {
312            let f: Box_<F> = Box_::new(f);
313            connect_raw(
314                self.as_ptr() as *mut _,
315                c"drive-disconnected".as_ptr() as *const _,
316                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317                    drive_disconnected_trampoline::<Self, F> as *const (),
318                )),
319                Box_::into_raw(f),
320            )
321        }
322    }
323
324    /// Emitted when the eject button is pressed on @drive.
325    /// ## `drive`
326    /// the drive where the eject button was pressed
327    #[doc(alias = "drive-eject-button")]
328    fn connect_drive_eject_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
329        unsafe extern "C" fn drive_eject_button_trampoline<
330            P: IsA<VolumeMonitor>,
331            F: Fn(&P, &Drive) + 'static,
332        >(
333            this: *mut ffi::GVolumeMonitor,
334            drive: *mut ffi::GDrive,
335            f: glib::ffi::gpointer,
336        ) {
337            let f: &F = &*(f as *const F);
338            f(
339                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
340                &from_glib_borrow(drive),
341            )
342        }
343        unsafe {
344            let f: Box_<F> = Box_::new(f);
345            connect_raw(
346                self.as_ptr() as *mut _,
347                c"drive-eject-button".as_ptr() as *const _,
348                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
349                    drive_eject_button_trampoline::<Self, F> as *const (),
350                )),
351                Box_::into_raw(f),
352            )
353        }
354    }
355
356    /// Emitted when the stop button is pressed on @drive.
357    /// ## `drive`
358    /// the drive where the stop button was pressed
359    #[doc(alias = "drive-stop-button")]
360    fn connect_drive_stop_button<F: Fn(&Self, &Drive) + 'static>(&self, f: F) -> SignalHandlerId {
361        unsafe extern "C" fn drive_stop_button_trampoline<
362            P: IsA<VolumeMonitor>,
363            F: Fn(&P, &Drive) + 'static,
364        >(
365            this: *mut ffi::GVolumeMonitor,
366            drive: *mut ffi::GDrive,
367            f: glib::ffi::gpointer,
368        ) {
369            let f: &F = &*(f as *const F);
370            f(
371                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
372                &from_glib_borrow(drive),
373            )
374        }
375        unsafe {
376            let f: Box_<F> = Box_::new(f);
377            connect_raw(
378                self.as_ptr() as *mut _,
379                c"drive-stop-button".as_ptr() as *const _,
380                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381                    drive_stop_button_trampoline::<Self, F> as *const (),
382                )),
383                Box_::into_raw(f),
384            )
385        }
386    }
387
388    /// Emitted when a mount is added.
389    /// ## `mount`
390    /// a #GMount that was added.
391    #[doc(alias = "mount-added")]
392    fn connect_mount_added<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
393        unsafe extern "C" fn mount_added_trampoline<
394            P: IsA<VolumeMonitor>,
395            F: Fn(&P, &Mount) + 'static,
396        >(
397            this: *mut ffi::GVolumeMonitor,
398            mount: *mut ffi::GMount,
399            f: glib::ffi::gpointer,
400        ) {
401            let f: &F = &*(f as *const F);
402            f(
403                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
404                &from_glib_borrow(mount),
405            )
406        }
407        unsafe {
408            let f: Box_<F> = Box_::new(f);
409            connect_raw(
410                self.as_ptr() as *mut _,
411                c"mount-added".as_ptr() as *const _,
412                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
413                    mount_added_trampoline::<Self, F> as *const (),
414                )),
415                Box_::into_raw(f),
416            )
417        }
418    }
419
420    /// Emitted when a mount changes.
421    /// ## `mount`
422    /// a #GMount that changed.
423    #[doc(alias = "mount-changed")]
424    fn connect_mount_changed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
425        unsafe extern "C" fn mount_changed_trampoline<
426            P: IsA<VolumeMonitor>,
427            F: Fn(&P, &Mount) + 'static,
428        >(
429            this: *mut ffi::GVolumeMonitor,
430            mount: *mut ffi::GMount,
431            f: glib::ffi::gpointer,
432        ) {
433            let f: &F = &*(f as *const F);
434            f(
435                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
436                &from_glib_borrow(mount),
437            )
438        }
439        unsafe {
440            let f: Box_<F> = Box_::new(f);
441            connect_raw(
442                self.as_ptr() as *mut _,
443                c"mount-changed".as_ptr() as *const _,
444                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
445                    mount_changed_trampoline::<Self, F> as *const (),
446                )),
447                Box_::into_raw(f),
448            )
449        }
450    }
451
452    /// May be emitted when a mount is about to be removed.
453    ///
454    /// This signal depends on the backend and is only emitted if
455    /// GIO was used to unmount.
456    /// ## `mount`
457    /// a #GMount that is being unmounted.
458    #[doc(alias = "mount-pre-unmount")]
459    fn connect_mount_pre_unmount<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
460        unsafe extern "C" fn mount_pre_unmount_trampoline<
461            P: IsA<VolumeMonitor>,
462            F: Fn(&P, &Mount) + 'static,
463        >(
464            this: *mut ffi::GVolumeMonitor,
465            mount: *mut ffi::GMount,
466            f: glib::ffi::gpointer,
467        ) {
468            let f: &F = &*(f as *const F);
469            f(
470                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
471                &from_glib_borrow(mount),
472            )
473        }
474        unsafe {
475            let f: Box_<F> = Box_::new(f);
476            connect_raw(
477                self.as_ptr() as *mut _,
478                c"mount-pre-unmount".as_ptr() as *const _,
479                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
480                    mount_pre_unmount_trampoline::<Self, F> as *const (),
481                )),
482                Box_::into_raw(f),
483            )
484        }
485    }
486
487    /// Emitted when a mount is removed.
488    /// ## `mount`
489    /// a #GMount that was removed.
490    #[doc(alias = "mount-removed")]
491    fn connect_mount_removed<F: Fn(&Self, &Mount) + 'static>(&self, f: F) -> SignalHandlerId {
492        unsafe extern "C" fn mount_removed_trampoline<
493            P: IsA<VolumeMonitor>,
494            F: Fn(&P, &Mount) + 'static,
495        >(
496            this: *mut ffi::GVolumeMonitor,
497            mount: *mut ffi::GMount,
498            f: glib::ffi::gpointer,
499        ) {
500            let f: &F = &*(f as *const F);
501            f(
502                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
503                &from_glib_borrow(mount),
504            )
505        }
506        unsafe {
507            let f: Box_<F> = Box_::new(f);
508            connect_raw(
509                self.as_ptr() as *mut _,
510                c"mount-removed".as_ptr() as *const _,
511                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
512                    mount_removed_trampoline::<Self, F> as *const (),
513                )),
514                Box_::into_raw(f),
515            )
516        }
517    }
518
519    /// Emitted when a mountable volume is added to the system.
520    /// ## `volume`
521    /// a #GVolume that was added.
522    #[doc(alias = "volume-added")]
523    fn connect_volume_added<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
524        unsafe extern "C" fn volume_added_trampoline<
525            P: IsA<VolumeMonitor>,
526            F: Fn(&P, &Volume) + 'static,
527        >(
528            this: *mut ffi::GVolumeMonitor,
529            volume: *mut ffi::GVolume,
530            f: glib::ffi::gpointer,
531        ) {
532            let f: &F = &*(f as *const F);
533            f(
534                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
535                &from_glib_borrow(volume),
536            )
537        }
538        unsafe {
539            let f: Box_<F> = Box_::new(f);
540            connect_raw(
541                self.as_ptr() as *mut _,
542                c"volume-added".as_ptr() as *const _,
543                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
544                    volume_added_trampoline::<Self, F> as *const (),
545                )),
546                Box_::into_raw(f),
547            )
548        }
549    }
550
551    /// Emitted when mountable volume is changed.
552    /// ## `volume`
553    /// a #GVolume that changed.
554    #[doc(alias = "volume-changed")]
555    fn connect_volume_changed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
556        unsafe extern "C" fn volume_changed_trampoline<
557            P: IsA<VolumeMonitor>,
558            F: Fn(&P, &Volume) + 'static,
559        >(
560            this: *mut ffi::GVolumeMonitor,
561            volume: *mut ffi::GVolume,
562            f: glib::ffi::gpointer,
563        ) {
564            let f: &F = &*(f as *const F);
565            f(
566                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
567                &from_glib_borrow(volume),
568            )
569        }
570        unsafe {
571            let f: Box_<F> = Box_::new(f);
572            connect_raw(
573                self.as_ptr() as *mut _,
574                c"volume-changed".as_ptr() as *const _,
575                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576                    volume_changed_trampoline::<Self, F> as *const (),
577                )),
578                Box_::into_raw(f),
579            )
580        }
581    }
582
583    /// Emitted when a mountable volume is removed from the system.
584    /// ## `volume`
585    /// a #GVolume that was removed.
586    #[doc(alias = "volume-removed")]
587    fn connect_volume_removed<F: Fn(&Self, &Volume) + 'static>(&self, f: F) -> SignalHandlerId {
588        unsafe extern "C" fn volume_removed_trampoline<
589            P: IsA<VolumeMonitor>,
590            F: Fn(&P, &Volume) + 'static,
591        >(
592            this: *mut ffi::GVolumeMonitor,
593            volume: *mut ffi::GVolume,
594            f: glib::ffi::gpointer,
595        ) {
596            let f: &F = &*(f as *const F);
597            f(
598                VolumeMonitor::from_glib_borrow(this).unsafe_cast_ref(),
599                &from_glib_borrow(volume),
600            )
601        }
602        unsafe {
603            let f: Box_<F> = Box_::new(f);
604            connect_raw(
605                self.as_ptr() as *mut _,
606                c"volume-removed".as_ptr() as *const _,
607                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
608                    volume_removed_trampoline::<Self, F> as *const (),
609                )),
610                Box_::into_raw(f),
611            )
612        }
613    }
614}
615
616impl<O: IsA<VolumeMonitor>> VolumeMonitorExt for O {}