gio_unix/auto/mount_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;
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 /// Watches for changes to the set of mount entries and mount points in the
16 /// system.
17 ///
18 /// Connect to the [`mounts-changed`][struct@crate::MountMonitor#mounts-changed] signal to be
19 /// notified of changes to the [`MountEntry`][crate::MountEntry] list.
20 ///
21 /// Connect to the [`mountpoints-changed`][struct@crate::MountMonitor#mountpoints-changed] signal to
22 /// be notified of changes to the [`MountPoint`][crate::MountPoint] list.
23 ///
24 /// ## Signals
25 ///
26 ///
27 /// #### `mountpoints-changed`
28 /// Emitted when the Unix mount points have changed.
29 ///
30 ///
31 ///
32 ///
33 /// #### `mounts-changed`
34 /// Emitted when the Unix mount entries have changed.
35 ///
36 ///
37 #[doc(alias = "GUnixMountMonitor")]
38 pub struct MountMonitor(Object<ffi::GUnixMountMonitor, ffi::GUnixMountMonitorClass>);
39
40 match fn {
41 type_ => || ffi::g_unix_mount_monitor_get_type(),
42 }
43}
44
45impl MountMonitor {
46 /// Gets the [`MountMonitor`][crate::MountMonitor] for the current thread-default main
47 /// context.
48 ///
49 /// The mount monitor can be used to monitor for changes to the list of
50 /// mounted filesystems as well as the list of mount points (ie: fstab
51 /// entries).
52 ///
53 /// You must only call `GObject::Object::unref()` on the return value from
54 /// under the same main context as you called this function.
55 ///
56 /// # Returns
57 ///
58 /// the [`MountMonitor`][crate::MountMonitor]
59 #[doc(alias = "g_unix_mount_monitor_get")]
60 pub fn get() -> MountMonitor {
61 unsafe { from_glib_full(ffi::g_unix_mount_monitor_get()) }
62 }
63
64 /// Emitted when the Unix mount points have changed.
65 #[doc(alias = "mountpoints-changed")]
66 pub fn connect_mountpoints_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
67 unsafe extern "C" fn mountpoints_changed_trampoline<F: Fn(&MountMonitor) + 'static>(
68 this: *mut ffi::GUnixMountMonitor,
69 f: glib::ffi::gpointer,
70 ) {
71 let f: &F = &*(f as *const F);
72 f(&from_glib_borrow(this))
73 }
74 unsafe {
75 let f: Box_<F> = Box_::new(f);
76 connect_raw(
77 self.as_ptr() as *mut _,
78 c"mountpoints-changed".as_ptr() as *const _,
79 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
80 mountpoints_changed_trampoline::<F> as *const (),
81 )),
82 Box_::into_raw(f),
83 )
84 }
85 }
86
87 /// Emitted when the Unix mount entries have changed.
88 #[doc(alias = "mounts-changed")]
89 pub fn connect_mounts_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
90 unsafe extern "C" fn mounts_changed_trampoline<F: Fn(&MountMonitor) + 'static>(
91 this: *mut ffi::GUnixMountMonitor,
92 f: glib::ffi::gpointer,
93 ) {
94 let f: &F = &*(f as *const F);
95 f(&from_glib_borrow(this))
96 }
97 unsafe {
98 let f: Box_<F> = Box_::new(f);
99 connect_raw(
100 self.as_ptr() as *mut _,
101 c"mounts-changed".as_ptr() as *const _,
102 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
103 mounts_changed_trampoline::<F> as *const (),
104 )),
105 Box_::into_raw(f),
106 )
107 }
108 }
109}