gio/auto/
file_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, File, FileMonitorEvent};
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    #[doc(alias = "GFileMonitor")]
16    pub struct FileMonitor(Object<ffi::GFileMonitor, ffi::GFileMonitorClass>);
17
18    match fn {
19        type_ => || ffi::g_file_monitor_get_type(),
20    }
21}
22
23impl FileMonitor {
24    pub const NONE: Option<&'static FileMonitor> = None;
25}
26
27pub trait FileMonitorExt: IsA<FileMonitor> + 'static {
28    #[doc(alias = "g_file_monitor_cancel")]
29    fn cancel(&self) -> bool {
30        unsafe { from_glib(ffi::g_file_monitor_cancel(self.as_ref().to_glib_none().0)) }
31    }
32
33    #[doc(alias = "g_file_monitor_emit_event")]
34    fn emit_event(
35        &self,
36        child: &impl IsA<File>,
37        other_file: Option<&impl IsA<File>>,
38        event_type: FileMonitorEvent,
39    ) {
40        unsafe {
41            ffi::g_file_monitor_emit_event(
42                self.as_ref().to_glib_none().0,
43                child.as_ref().to_glib_none().0,
44                other_file.map(|p| p.as_ref()).to_glib_none().0,
45                event_type.into_glib(),
46            );
47        }
48    }
49
50    #[doc(alias = "g_file_monitor_is_cancelled")]
51    #[doc(alias = "cancelled")]
52    fn is_cancelled(&self) -> bool {
53        unsafe {
54            from_glib(ffi::g_file_monitor_is_cancelled(
55                self.as_ref().to_glib_none().0,
56            ))
57        }
58    }
59
60    #[doc(alias = "g_file_monitor_set_rate_limit")]
61    #[doc(alias = "rate-limit")]
62    fn set_rate_limit(&self, limit_msecs: i32) {
63        unsafe {
64            ffi::g_file_monitor_set_rate_limit(self.as_ref().to_glib_none().0, limit_msecs);
65        }
66    }
67
68    #[doc(alias = "rate-limit")]
69    fn rate_limit(&self) -> i32 {
70        ObjectExt::property(self.as_ref(), "rate-limit")
71    }
72
73    #[doc(alias = "changed")]
74    fn connect_changed<F: Fn(&Self, &File, Option<&File>, FileMonitorEvent) + 'static>(
75        &self,
76        f: F,
77    ) -> SignalHandlerId {
78        unsafe extern "C" fn changed_trampoline<
79            P: IsA<FileMonitor>,
80            F: Fn(&P, &File, Option<&File>, FileMonitorEvent) + 'static,
81        >(
82            this: *mut ffi::GFileMonitor,
83            file: *mut ffi::GFile,
84            other_file: *mut ffi::GFile,
85            event_type: ffi::GFileMonitorEvent,
86            f: glib::ffi::gpointer,
87        ) {
88            let f: &F = &*(f as *const F);
89            f(
90                FileMonitor::from_glib_borrow(this).unsafe_cast_ref(),
91                &from_glib_borrow(file),
92                Option::<File>::from_glib_borrow(other_file)
93                    .as_ref()
94                    .as_ref(),
95                from_glib(event_type),
96            )
97        }
98        unsafe {
99            let f: Box_<F> = Box_::new(f);
100            connect_raw(
101                self.as_ptr() as *mut _,
102                c"changed".as_ptr() as *const _,
103                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
104                    changed_trampoline::<Self, F> as *const (),
105                )),
106                Box_::into_raw(f),
107            )
108        }
109    }
110
111    #[doc(alias = "cancelled")]
112    fn connect_cancelled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
113        unsafe extern "C" fn notify_cancelled_trampoline<
114            P: IsA<FileMonitor>,
115            F: Fn(&P) + 'static,
116        >(
117            this: *mut ffi::GFileMonitor,
118            _param_spec: glib::ffi::gpointer,
119            f: glib::ffi::gpointer,
120        ) {
121            let f: &F = &*(f as *const F);
122            f(FileMonitor::from_glib_borrow(this).unsafe_cast_ref())
123        }
124        unsafe {
125            let f: Box_<F> = Box_::new(f);
126            connect_raw(
127                self.as_ptr() as *mut _,
128                c"notify::cancelled".as_ptr() as *const _,
129                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
130                    notify_cancelled_trampoline::<Self, F> as *const (),
131                )),
132                Box_::into_raw(f),
133            )
134        }
135    }
136
137    #[doc(alias = "rate-limit")]
138    fn connect_rate_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
139        unsafe extern "C" fn notify_rate_limit_trampoline<
140            P: IsA<FileMonitor>,
141            F: Fn(&P) + 'static,
142        >(
143            this: *mut ffi::GFileMonitor,
144            _param_spec: glib::ffi::gpointer,
145            f: glib::ffi::gpointer,
146        ) {
147            let f: &F = &*(f as *const F);
148            f(FileMonitor::from_glib_borrow(this).unsafe_cast_ref())
149        }
150        unsafe {
151            let f: Box_<F> = Box_::new(f);
152            connect_raw(
153                self.as_ptr() as *mut _,
154                c"notify::rate-limit".as_ptr() as *const _,
155                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
156                    notify_rate_limit_trampoline::<Self, F> as *const (),
157                )),
158                Box_::into_raw(f),
159            )
160        }
161    }
162}
163
164impl<O: IsA<FileMonitor>> FileMonitorExt for O {}