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 /// Monitors a file or directory for changes.
16 ///
17 /// To obtain a `GFileMonitor` for a file or directory, use
18 /// [`FileExt::monitor()`][crate::prelude::FileExt::monitor()], [`FileExt::monitor_file()`][crate::prelude::FileExt::monitor_file()], or
19 /// [`FileExt::monitor_directory()`][crate::prelude::FileExt::monitor_directory()].
20 ///
21 /// To get informed about changes to the file or directory you are
22 /// monitoring, connect to the [`changed`][struct@crate::FileMonitor#changed] signal. The
23 /// signal will be emitted in the thread-default main context (see
24 /// [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()]) of the thread that the monitor
25 /// was created in (though if the global default main context is blocked, this
26 /// may cause notifications to be blocked even if the thread-default
27 /// context is still running).
28 ///
29 /// This is an Abstract Base Class, you cannot instantiate it.
30 ///
31 /// ## Properties
32 ///
33 ///
34 /// #### `cancelled`
35 /// Whether the monitor has been cancelled.
36 ///
37 /// Readable
38 ///
39 ///
40 /// #### `rate-limit`
41 /// The limit of the monitor to watch for changes, in milliseconds.
42 ///
43 /// Readable | Writeable
44 ///
45 /// ## Signals
46 ///
47 ///
48 /// #### `changed`
49 /// Emitted when @file has been changed.
50 ///
51 /// If using [`FileMonitorFlags::WATCH_MOVES`][crate::FileMonitorFlags::WATCH_MOVES] on a directory monitor, and
52 /// the information is available (and if supported by the backend),
53 /// @event_type may be [`FileMonitorEvent::Renamed`][crate::FileMonitorEvent::Renamed],
54 /// [`FileMonitorEvent::MovedIn`][crate::FileMonitorEvent::MovedIn] or [`FileMonitorEvent::MovedOut`][crate::FileMonitorEvent::MovedOut].
55 ///
56 /// In all cases @file will be a child of the monitored directory. For
57 /// renames, @file will be the old name and @other_file is the new
58 /// name. For "moved in" events, @file is the name of the file that
59 /// appeared and @other_file is the old name that it was moved from (in
60 /// another directory). For "moved out" events, @file is the name of
61 /// the file that used to be in this directory and @other_file is the
62 /// name of the file at its new location.
63 ///
64 /// It makes sense to treat [`FileMonitorEvent::MovedIn`][crate::FileMonitorEvent::MovedIn] as
65 /// equivalent to [`FileMonitorEvent::Created`][crate::FileMonitorEvent::Created] and
66 /// [`FileMonitorEvent::MovedOut`][crate::FileMonitorEvent::MovedOut] as equivalent to
67 /// [`FileMonitorEvent::Deleted`][crate::FileMonitorEvent::Deleted], with extra information.
68 /// [`FileMonitorEvent::Renamed`][crate::FileMonitorEvent::Renamed] is equivalent to a delete/create
69 /// pair. This is exactly how the events will be reported in the case
70 /// that the [`FileMonitorFlags::WATCH_MOVES`][crate::FileMonitorFlags::WATCH_MOVES] flag is not in use.
71 ///
72 /// If using the deprecated flag [`FileMonitorFlags::SEND_MOVED`][crate::FileMonitorFlags::SEND_MOVED] flag and @event_type is
73 /// [`FileMonitorEvent::Moved`][crate::FileMonitorEvent::Moved], @file will be set to a #GFile containing the
74 /// old path, and @other_file will be set to a #GFile containing the new path.
75 ///
76 /// In all the other cases, @other_file will be set to #NULL.
77 ///
78 ///
79 ///
80 /// # Implements
81 ///
82 /// [`FileMonitorExt`][trait@crate::prelude::FileMonitorExt], [`trait@glib::ObjectExt`]
83 #[doc(alias = "GFileMonitor")]
84 pub struct FileMonitor(Object<ffi::GFileMonitor, ffi::GFileMonitorClass>);
85
86 match fn {
87 type_ => || ffi::g_file_monitor_get_type(),
88 }
89}
90
91impl FileMonitor {
92 pub const NONE: Option<&'static FileMonitor> = None;
93}
94
95/// Trait containing all [`struct@FileMonitor`] methods.
96///
97/// # Implementors
98///
99/// [`FileMonitor`][struct@crate::FileMonitor]
100pub trait FileMonitorExt: IsA<FileMonitor> + 'static {
101 /// Cancels a file monitor.
102 ///
103 /// # Returns
104 ///
105 /// always [`true`]
106 #[doc(alias = "g_file_monitor_cancel")]
107 fn cancel(&self) -> bool {
108 unsafe { from_glib(ffi::g_file_monitor_cancel(self.as_ref().to_glib_none().0)) }
109 }
110
111 /// Emits the #GFileMonitor::changed signal if a change
112 /// has taken place. Should be called from file monitor
113 /// implementations only.
114 ///
115 /// Implementations are responsible to call this method from the
116 /// thread-default main context (see [`glib::MainContext::push_thread_default()`][crate::glib::MainContext::push_thread_default()])
117 /// of the thread that the monitor was created in.
118 /// ## `child`
119 /// a #GFile.
120 /// ## `other_file`
121 /// a #GFile.
122 /// ## `event_type`
123 /// a set of #GFileMonitorEvent flags.
124 #[doc(alias = "g_file_monitor_emit_event")]
125 fn emit_event(
126 &self,
127 child: &impl IsA<File>,
128 other_file: &impl IsA<File>,
129 event_type: FileMonitorEvent,
130 ) {
131 unsafe {
132 ffi::g_file_monitor_emit_event(
133 self.as_ref().to_glib_none().0,
134 child.as_ref().to_glib_none().0,
135 other_file.as_ref().to_glib_none().0,
136 event_type.into_glib(),
137 );
138 }
139 }
140
141 /// Returns whether the monitor is canceled.
142 ///
143 /// # Returns
144 ///
145 /// [`true`] if monitor is canceled. [`false`] otherwise.
146 #[doc(alias = "g_file_monitor_is_cancelled")]
147 #[doc(alias = "cancelled")]
148 fn is_cancelled(&self) -> bool {
149 unsafe {
150 from_glib(ffi::g_file_monitor_is_cancelled(
151 self.as_ref().to_glib_none().0,
152 ))
153 }
154 }
155
156 /// Sets the rate limit to which the @self will report
157 /// consecutive change events to the same file.
158 /// ## `limit_msecs`
159 /// a non-negative integer with the limit in milliseconds
160 /// to poll for changes
161 #[doc(alias = "g_file_monitor_set_rate_limit")]
162 #[doc(alias = "rate-limit")]
163 fn set_rate_limit(&self, limit_msecs: i32) {
164 unsafe {
165 ffi::g_file_monitor_set_rate_limit(self.as_ref().to_glib_none().0, limit_msecs);
166 }
167 }
168
169 /// The limit of the monitor to watch for changes, in milliseconds.
170 #[doc(alias = "rate-limit")]
171 fn rate_limit(&self) -> i32 {
172 ObjectExt::property(self.as_ref(), "rate-limit")
173 }
174
175 /// Emitted when @file has been changed.
176 ///
177 /// If using [`FileMonitorFlags::WATCH_MOVES`][crate::FileMonitorFlags::WATCH_MOVES] on a directory monitor, and
178 /// the information is available (and if supported by the backend),
179 /// @event_type may be [`FileMonitorEvent::Renamed`][crate::FileMonitorEvent::Renamed],
180 /// [`FileMonitorEvent::MovedIn`][crate::FileMonitorEvent::MovedIn] or [`FileMonitorEvent::MovedOut`][crate::FileMonitorEvent::MovedOut].
181 ///
182 /// In all cases @file will be a child of the monitored directory. For
183 /// renames, @file will be the old name and @other_file is the new
184 /// name. For "moved in" events, @file is the name of the file that
185 /// appeared and @other_file is the old name that it was moved from (in
186 /// another directory). For "moved out" events, @file is the name of
187 /// the file that used to be in this directory and @other_file is the
188 /// name of the file at its new location.
189 ///
190 /// It makes sense to treat [`FileMonitorEvent::MovedIn`][crate::FileMonitorEvent::MovedIn] as
191 /// equivalent to [`FileMonitorEvent::Created`][crate::FileMonitorEvent::Created] and
192 /// [`FileMonitorEvent::MovedOut`][crate::FileMonitorEvent::MovedOut] as equivalent to
193 /// [`FileMonitorEvent::Deleted`][crate::FileMonitorEvent::Deleted], with extra information.
194 /// [`FileMonitorEvent::Renamed`][crate::FileMonitorEvent::Renamed] is equivalent to a delete/create
195 /// pair. This is exactly how the events will be reported in the case
196 /// that the [`FileMonitorFlags::WATCH_MOVES`][crate::FileMonitorFlags::WATCH_MOVES] flag is not in use.
197 ///
198 /// If using the deprecated flag [`FileMonitorFlags::SEND_MOVED`][crate::FileMonitorFlags::SEND_MOVED] flag and @event_type is
199 /// [`FileMonitorEvent::Moved`][crate::FileMonitorEvent::Moved], @file will be set to a #GFile containing the
200 /// old path, and @other_file will be set to a #GFile containing the new path.
201 ///
202 /// In all the other cases, @other_file will be set to #NULL.
203 /// ## `file`
204 /// a #GFile.
205 /// ## `other_file`
206 /// a #GFile or #NULL.
207 /// ## `event_type`
208 /// a #GFileMonitorEvent.
209 #[doc(alias = "changed")]
210 fn connect_changed<F: Fn(&Self, &File, Option<&File>, FileMonitorEvent) + 'static>(
211 &self,
212 f: F,
213 ) -> SignalHandlerId {
214 unsafe extern "C" fn changed_trampoline<
215 P: IsA<FileMonitor>,
216 F: Fn(&P, &File, Option<&File>, FileMonitorEvent) + 'static,
217 >(
218 this: *mut ffi::GFileMonitor,
219 file: *mut ffi::GFile,
220 other_file: *mut ffi::GFile,
221 event_type: ffi::GFileMonitorEvent,
222 f: glib::ffi::gpointer,
223 ) {
224 let f: &F = &*(f as *const F);
225 f(
226 FileMonitor::from_glib_borrow(this).unsafe_cast_ref(),
227 &from_glib_borrow(file),
228 Option::<File>::from_glib_borrow(other_file)
229 .as_ref()
230 .as_ref(),
231 from_glib(event_type),
232 )
233 }
234 unsafe {
235 let f: Box_<F> = Box_::new(f);
236 connect_raw(
237 self.as_ptr() as *mut _,
238 c"changed".as_ptr() as *const _,
239 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
240 changed_trampoline::<Self, F> as *const (),
241 )),
242 Box_::into_raw(f),
243 )
244 }
245 }
246
247 #[doc(alias = "cancelled")]
248 fn connect_cancelled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249 unsafe extern "C" fn notify_cancelled_trampoline<
250 P: IsA<FileMonitor>,
251 F: Fn(&P) + 'static,
252 >(
253 this: *mut ffi::GFileMonitor,
254 _param_spec: glib::ffi::gpointer,
255 f: glib::ffi::gpointer,
256 ) {
257 let f: &F = &*(f as *const F);
258 f(FileMonitor::from_glib_borrow(this).unsafe_cast_ref())
259 }
260 unsafe {
261 let f: Box_<F> = Box_::new(f);
262 connect_raw(
263 self.as_ptr() as *mut _,
264 c"notify::cancelled".as_ptr() as *const _,
265 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
266 notify_cancelled_trampoline::<Self, F> as *const (),
267 )),
268 Box_::into_raw(f),
269 )
270 }
271 }
272
273 #[doc(alias = "rate-limit")]
274 fn connect_rate_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
275 unsafe extern "C" fn notify_rate_limit_trampoline<
276 P: IsA<FileMonitor>,
277 F: Fn(&P) + 'static,
278 >(
279 this: *mut ffi::GFileMonitor,
280 _param_spec: glib::ffi::gpointer,
281 f: glib::ffi::gpointer,
282 ) {
283 let f: &F = &*(f as *const F);
284 f(FileMonitor::from_glib_borrow(this).unsafe_cast_ref())
285 }
286 unsafe {
287 let f: Box_<F> = Box_::new(f);
288 connect_raw(
289 self.as_ptr() as *mut _,
290 c"notify::rate-limit".as_ptr() as *const _,
291 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292 notify_rate_limit_trampoline::<Self, F> as *const (),
293 )),
294 Box_::into_raw(f),
295 )
296 }
297 }
298}
299
300impl<O: IsA<FileMonitor>> FileMonitorExt for O {}