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::{SignalHandlerId, connect_raw},
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            unsafe {
72                let f: &F = &*(f as *const F);
73                f(&from_glib_borrow(this))
74            }
75        }
76        unsafe {
77            let f: Box_<F> = Box_::new(f);
78            connect_raw(
79                self.as_ptr() as *mut _,
80                c"mountpoints-changed".as_ptr() as *const _,
81                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
82                    mountpoints_changed_trampoline::<F> as *const (),
83                )),
84                Box_::into_raw(f),
85            )
86        }
87    }
88
89    /// Emitted when the Unix mount entries have changed.
90    #[doc(alias = "mounts-changed")]
91    pub fn connect_mounts_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
92        unsafe extern "C" fn mounts_changed_trampoline<F: Fn(&MountMonitor) + 'static>(
93            this: *mut ffi::GUnixMountMonitor,
94            f: glib::ffi::gpointer,
95        ) {
96            unsafe {
97                let f: &F = &*(f as *const F);
98                f(&from_glib_borrow(this))
99            }
100        }
101        unsafe {
102            let f: Box_<F> = Box_::new(f);
103            connect_raw(
104                self.as_ptr() as *mut _,
105                c"mounts-changed".as_ptr() as *const _,
106                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
107                    mounts_changed_trampoline::<F> as *const (),
108                )),
109                Box_::into_raw(f),
110            )
111        }
112    }
113}