1use gdk;
6use gio;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::StaticType;
13use glib::ToValue;
14use glib::Value;
15use glib_sys;
16use gobject_sys;
17use gtk_sys;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21use Window;
22
23glib_wrapper! {
24 pub struct MountOperation(Object<gtk_sys::GtkMountOperation, gtk_sys::GtkMountOperationClass, MountOperationClass>) @extends gio::MountOperation;
25
26 match fn {
27 get_type => || gtk_sys::gtk_mount_operation_get_type(),
28 }
29}
30
31impl MountOperation {
32 pub fn new<P: IsA<Window>>(parent: Option<&P>) -> MountOperation {
33 assert_initialized_main_thread!();
34 unsafe {
35 gio::MountOperation::from_glib_full(gtk_sys::gtk_mount_operation_new(
36 parent.map(|p| p.as_ref()).to_glib_none().0,
37 ))
38 .unsafe_cast()
39 }
40 }
41}
42
43pub struct MountOperationBuilder {
44 parent: Option<Window>,
45 screen: Option<gdk::Screen>,
46 anonymous: Option<bool>,
47 choice: Option<i32>,
48 domain: Option<String>,
49 is_tcrypt_hidden_volume: Option<bool>,
50 is_tcrypt_system_volume: Option<bool>,
51 password: Option<String>,
52 pim: Option<u32>,
54 username: Option<String>,
55}
56
57impl MountOperationBuilder {
58 pub fn new() -> Self {
59 Self {
60 parent: None,
61 screen: None,
62 anonymous: None,
63 choice: None,
64 domain: None,
65 is_tcrypt_hidden_volume: None,
66 is_tcrypt_system_volume: None,
67 password: None,
68 pim: None,
69 username: None,
70 }
71 }
72
73 pub fn build(self) -> MountOperation {
74 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
75 if let Some(ref parent) = self.parent {
76 properties.push(("parent", parent));
77 }
78 if let Some(ref screen) = self.screen {
79 properties.push(("screen", screen));
80 }
81 if let Some(ref anonymous) = self.anonymous {
82 properties.push(("anonymous", anonymous));
83 }
84 if let Some(ref choice) = self.choice {
85 properties.push(("choice", choice));
86 }
87 if let Some(ref domain) = self.domain {
88 properties.push(("domain", domain));
89 }
90 if let Some(ref is_tcrypt_hidden_volume) = self.is_tcrypt_hidden_volume {
91 properties.push(("is-tcrypt-hidden-volume", is_tcrypt_hidden_volume));
92 }
93 if let Some(ref is_tcrypt_system_volume) = self.is_tcrypt_system_volume {
94 properties.push(("is-tcrypt-system-volume", is_tcrypt_system_volume));
95 }
96 if let Some(ref password) = self.password {
97 properties.push(("password", password));
98 }
99 if let Some(ref pim) = self.pim {
100 properties.push(("pim", pim));
101 }
102 if let Some(ref username) = self.username {
103 properties.push(("username", username));
104 }
105 glib::Object::new(MountOperation::static_type(), &properties)
106 .expect("object new")
107 .downcast()
108 .expect("downcast")
109 }
110
111 pub fn parent(mut self, parent: &Window) -> Self {
112 self.parent = Some(parent.clone());
113 self
114 }
115
116 pub fn screen(mut self, screen: &gdk::Screen) -> Self {
117 self.screen = Some(screen.clone());
118 self
119 }
120
121 pub fn anonymous(mut self, anonymous: bool) -> Self {
122 self.anonymous = Some(anonymous);
123 self
124 }
125
126 pub fn choice(mut self, choice: i32) -> Self {
127 self.choice = Some(choice);
128 self
129 }
130
131 pub fn domain(mut self, domain: &str) -> Self {
132 self.domain = Some(domain.to_string());
133 self
134 }
135
136 pub fn is_tcrypt_hidden_volume(mut self, is_tcrypt_hidden_volume: bool) -> Self {
137 self.is_tcrypt_hidden_volume = Some(is_tcrypt_hidden_volume);
138 self
139 }
140
141 pub fn is_tcrypt_system_volume(mut self, is_tcrypt_system_volume: bool) -> Self {
142 self.is_tcrypt_system_volume = Some(is_tcrypt_system_volume);
143 self
144 }
145
146 pub fn password(mut self, password: &str) -> Self {
147 self.password = Some(password.to_string());
148 self
149 }
150
151 pub fn pim(mut self, pim: u32) -> Self {
152 self.pim = Some(pim);
153 self
154 }
155
156 pub fn username(mut self, username: &str) -> Self {
157 self.username = Some(username.to_string());
158 self
159 }
160}
161
162pub const NONE_MOUNT_OPERATION: Option<&MountOperation> = None;
163
164pub trait MountOperationExt: 'static {
165 fn get_parent(&self) -> Option<Window>;
166
167 fn get_screen(&self) -> Option<gdk::Screen>;
168
169 fn is_showing(&self) -> bool;
170
171 fn set_parent<P: IsA<Window>>(&self, parent: Option<&P>);
172
173 fn set_screen(&self, screen: &gdk::Screen);
174
175 fn get_property_is_showing(&self) -> bool;
176
177 fn connect_property_is_showing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
178
179 fn connect_property_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
180
181 fn connect_property_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
182}
183
184impl<O: IsA<MountOperation>> MountOperationExt for O {
185 fn get_parent(&self) -> Option<Window> {
186 unsafe {
187 from_glib_none(gtk_sys::gtk_mount_operation_get_parent(
188 self.as_ref().to_glib_none().0,
189 ))
190 }
191 }
192
193 fn get_screen(&self) -> Option<gdk::Screen> {
194 unsafe {
195 from_glib_none(gtk_sys::gtk_mount_operation_get_screen(
196 self.as_ref().to_glib_none().0,
197 ))
198 }
199 }
200
201 fn is_showing(&self) -> bool {
202 unsafe {
203 from_glib(gtk_sys::gtk_mount_operation_is_showing(
204 self.as_ref().to_glib_none().0,
205 ))
206 }
207 }
208
209 fn set_parent<P: IsA<Window>>(&self, parent: Option<&P>) {
210 unsafe {
211 gtk_sys::gtk_mount_operation_set_parent(
212 self.as_ref().to_glib_none().0,
213 parent.map(|p| p.as_ref()).to_glib_none().0,
214 );
215 }
216 }
217
218 fn set_screen(&self, screen: &gdk::Screen) {
219 unsafe {
220 gtk_sys::gtk_mount_operation_set_screen(
221 self.as_ref().to_glib_none().0,
222 screen.to_glib_none().0,
223 );
224 }
225 }
226
227 fn get_property_is_showing(&self) -> bool {
228 unsafe {
229 let mut value = Value::from_type(<bool as StaticType>::static_type());
230 gobject_sys::g_object_get_property(
231 self.to_glib_none().0 as *mut gobject_sys::GObject,
232 b"is-showing\0".as_ptr() as *const _,
233 value.to_glib_none_mut().0,
234 );
235 value.get().unwrap()
236 }
237 }
238
239 fn connect_property_is_showing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
240 unsafe extern "C" fn notify_is_showing_trampoline<P, F: Fn(&P) + 'static>(
241 this: *mut gtk_sys::GtkMountOperation,
242 _param_spec: glib_sys::gpointer,
243 f: glib_sys::gpointer,
244 ) where
245 P: IsA<MountOperation>,
246 {
247 let f: &F = &*(f as *const F);
248 f(&MountOperation::from_glib_borrow(this).unsafe_cast())
249 }
250 unsafe {
251 let f: Box_<F> = Box_::new(f);
252 connect_raw(
253 self.as_ptr() as *mut _,
254 b"notify::is-showing\0".as_ptr() as *const _,
255 Some(transmute(notify_is_showing_trampoline::<Self, F> as usize)),
256 Box_::into_raw(f),
257 )
258 }
259 }
260
261 fn connect_property_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
262 unsafe extern "C" fn notify_parent_trampoline<P, F: Fn(&P) + 'static>(
263 this: *mut gtk_sys::GtkMountOperation,
264 _param_spec: glib_sys::gpointer,
265 f: glib_sys::gpointer,
266 ) where
267 P: IsA<MountOperation>,
268 {
269 let f: &F = &*(f as *const F);
270 f(&MountOperation::from_glib_borrow(this).unsafe_cast())
271 }
272 unsafe {
273 let f: Box_<F> = Box_::new(f);
274 connect_raw(
275 self.as_ptr() as *mut _,
276 b"notify::parent\0".as_ptr() as *const _,
277 Some(transmute(notify_parent_trampoline::<Self, F> as usize)),
278 Box_::into_raw(f),
279 )
280 }
281 }
282
283 fn connect_property_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
284 unsafe extern "C" fn notify_screen_trampoline<P, F: Fn(&P) + 'static>(
285 this: *mut gtk_sys::GtkMountOperation,
286 _param_spec: glib_sys::gpointer,
287 f: glib_sys::gpointer,
288 ) where
289 P: IsA<MountOperation>,
290 {
291 let f: &F = &*(f as *const F);
292 f(&MountOperation::from_glib_borrow(this).unsafe_cast())
293 }
294 unsafe {
295 let f: Box_<F> = Box_::new(f);
296 connect_raw(
297 self.as_ptr() as *mut _,
298 b"notify::screen\0".as_ptr() as *const _,
299 Some(transmute(notify_screen_trampoline::<Self, F> as usize)),
300 Box_::into_raw(f),
301 )
302 }
303 }
304}
305
306impl fmt::Display for MountOperation {
307 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
308 write!(f, "MountOperation")
309 }
310}