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