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 gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::Value;
13use glib_sys;
14use gobject_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use File;
19use FileMonitorEvent;
20
21glib_wrapper! {
22    pub struct FileMonitor(Object<gio_sys::GFileMonitor, gio_sys::GFileMonitorClass, FileMonitorClass>);
23
24    match fn {
25        get_type => || gio_sys::g_file_monitor_get_type(),
26    }
27}
28
29pub const NONE_FILE_MONITOR: Option<&FileMonitor> = None;
30
31pub trait FileMonitorExt: 'static {
32    fn cancel(&self) -> bool;
33
34    fn emit_event<P: IsA<File>, Q: IsA<File>>(
35        &self,
36        child: &P,
37        other_file: &Q,
38        event_type: FileMonitorEvent,
39    );
40
41    fn is_cancelled(&self) -> bool;
42
43    fn set_rate_limit(&self, limit_msecs: i32);
44
45    fn get_property_cancelled(&self) -> bool;
46
47    fn get_property_rate_limit(&self) -> i32;
48
49    fn connect_changed<F: Fn(&Self, &File, Option<&File>, FileMonitorEvent) + 'static>(
50        &self,
51        f: F,
52    ) -> SignalHandlerId;
53
54    fn connect_property_cancelled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
55
56    fn connect_property_rate_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
57}
58
59impl<O: IsA<FileMonitor>> FileMonitorExt for O {
60    fn cancel(&self) -> bool {
61        unsafe {
62            from_glib(gio_sys::g_file_monitor_cancel(
63                self.as_ref().to_glib_none().0,
64            ))
65        }
66    }
67
68    fn emit_event<P: IsA<File>, Q: IsA<File>>(
69        &self,
70        child: &P,
71        other_file: &Q,
72        event_type: FileMonitorEvent,
73    ) {
74        unsafe {
75            gio_sys::g_file_monitor_emit_event(
76                self.as_ref().to_glib_none().0,
77                child.as_ref().to_glib_none().0,
78                other_file.as_ref().to_glib_none().0,
79                event_type.to_glib(),
80            );
81        }
82    }
83
84    fn is_cancelled(&self) -> bool {
85        unsafe {
86            from_glib(gio_sys::g_file_monitor_is_cancelled(
87                self.as_ref().to_glib_none().0,
88            ))
89        }
90    }
91
92    fn set_rate_limit(&self, limit_msecs: i32) {
93        unsafe {
94            gio_sys::g_file_monitor_set_rate_limit(self.as_ref().to_glib_none().0, limit_msecs);
95        }
96    }
97
98    fn get_property_cancelled(&self) -> bool {
99        unsafe {
100            let mut value = Value::from_type(<bool as StaticType>::static_type());
101            gobject_sys::g_object_get_property(
102                self.to_glib_none().0 as *mut gobject_sys::GObject,
103                b"cancelled\0".as_ptr() as *const _,
104                value.to_glib_none_mut().0,
105            );
106            value.get().unwrap()
107        }
108    }
109
110    fn get_property_rate_limit(&self) -> i32 {
111        unsafe {
112            let mut value = Value::from_type(<i32 as StaticType>::static_type());
113            gobject_sys::g_object_get_property(
114                self.to_glib_none().0 as *mut gobject_sys::GObject,
115                b"rate-limit\0".as_ptr() as *const _,
116                value.to_glib_none_mut().0,
117            );
118            value.get().unwrap()
119        }
120    }
121
122    fn connect_changed<F: Fn(&Self, &File, Option<&File>, FileMonitorEvent) + 'static>(
123        &self,
124        f: F,
125    ) -> SignalHandlerId {
126        unsafe extern "C" fn changed_trampoline<
127            P,
128            F: Fn(&P, &File, Option<&File>, FileMonitorEvent) + 'static,
129        >(
130            this: *mut gio_sys::GFileMonitor,
131            file: *mut gio_sys::GFile,
132            other_file: *mut gio_sys::GFile,
133            event_type: gio_sys::GFileMonitorEvent,
134            f: glib_sys::gpointer,
135        ) where
136            P: IsA<FileMonitor>,
137        {
138            let f: &F = &*(f as *const F);
139            f(
140                &FileMonitor::from_glib_borrow(this).unsafe_cast(),
141                &from_glib_borrow(file),
142                Option::<File>::from_glib_borrow(other_file).as_ref(),
143                from_glib(event_type),
144            )
145        }
146        unsafe {
147            let f: Box_<F> = Box_::new(f);
148            connect_raw(
149                self.as_ptr() as *mut _,
150                b"changed\0".as_ptr() as *const _,
151                Some(transmute(changed_trampoline::<Self, F> as usize)),
152                Box_::into_raw(f),
153            )
154        }
155    }
156
157    fn connect_property_cancelled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
158        unsafe extern "C" fn notify_cancelled_trampoline<P, F: Fn(&P) + 'static>(
159            this: *mut gio_sys::GFileMonitor,
160            _param_spec: glib_sys::gpointer,
161            f: glib_sys::gpointer,
162        ) where
163            P: IsA<FileMonitor>,
164        {
165            let f: &F = &*(f as *const F);
166            f(&FileMonitor::from_glib_borrow(this).unsafe_cast())
167        }
168        unsafe {
169            let f: Box_<F> = Box_::new(f);
170            connect_raw(
171                self.as_ptr() as *mut _,
172                b"notify::cancelled\0".as_ptr() as *const _,
173                Some(transmute(notify_cancelled_trampoline::<Self, F> as usize)),
174                Box_::into_raw(f),
175            )
176        }
177    }
178
179    fn connect_property_rate_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
180        unsafe extern "C" fn notify_rate_limit_trampoline<P, F: Fn(&P) + 'static>(
181            this: *mut gio_sys::GFileMonitor,
182            _param_spec: glib_sys::gpointer,
183            f: glib_sys::gpointer,
184        ) where
185            P: IsA<FileMonitor>,
186        {
187            let f: &F = &*(f as *const F);
188            f(&FileMonitor::from_glib_borrow(this).unsafe_cast())
189        }
190        unsafe {
191            let f: Box_<F> = Box_::new(f);
192            connect_raw(
193                self.as_ptr() as *mut _,
194                b"notify::rate-limit\0".as_ptr() as *const _,
195                Some(transmute(notify_rate_limit_trampoline::<Self, F> as usize)),
196                Box_::into_raw(f),
197            )
198        }
199    }
200}
201
202impl fmt::Display for FileMonitor {
203    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
204        write!(f, "FileMonitor")
205    }
206}