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 
5 use crate::AsyncResult;
6 use crate::Cancellable;
7 use crate::Drive;
8 use crate::File;
9 use crate::Icon;
10 use crate::Mount;
11 use crate::MountMountFlags;
12 use crate::MountOperation;
13 use crate::MountUnmountFlags;
14 use glib::object::Cast;
15 use glib::object::IsA;
16 use glib::signal::connect_raw;
17 use glib::signal::SignalHandlerId;
18 use glib::translate::*;
19 use std::boxed::Box as Box_;
20 use std::fmt;
21 use std::mem::transmute;
22 use std::pin::Pin;
23 use std::ptr;
24 
25 glib::wrapper! {
26     #[doc(alias = "GVolume")]
27     pub struct Volume(Interface<ffi::GVolume, ffi::GVolumeIface>);
28 
29     match fn {
30         type_ => || ffi::g_volume_get_type(),
31     }
32 }
33 
34 pub const NONE_VOLUME: Option<&Volume> = None;
35 
36 pub trait VolumeExt: 'static {
37     #[doc(alias = "g_volume_can_eject")]
can_eject(&self) -> bool38     fn can_eject(&self) -> bool;
39 
40     #[doc(alias = "g_volume_can_mount")]
can_mount(&self) -> bool41     fn can_mount(&self) -> bool;
42 
43     #[doc(alias = "g_volume_eject_with_operation")]
eject_with_operation< P: IsA<MountOperation>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, flags: MountUnmountFlags, mount_operation: Option<&P>, cancellable: Option<&Q>, callback: R, )44     fn eject_with_operation<
45         P: IsA<MountOperation>,
46         Q: IsA<Cancellable>,
47         R: FnOnce(Result<(), glib::Error>) + Send + 'static,
48     >(
49         &self,
50         flags: MountUnmountFlags,
51         mount_operation: Option<&P>,
52         cancellable: Option<&Q>,
53         callback: R,
54     );
55 
eject_with_operation_future<P: IsA<MountOperation> + Clone + 'static>( &self, flags: MountUnmountFlags, mount_operation: Option<&P>, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>56     fn eject_with_operation_future<P: IsA<MountOperation> + Clone + 'static>(
57         &self,
58         flags: MountUnmountFlags,
59         mount_operation: Option<&P>,
60     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>;
61 
62     #[doc(alias = "g_volume_enumerate_identifiers")]
enumerate_identifiers(&self) -> Vec<glib::GString>63     fn enumerate_identifiers(&self) -> Vec<glib::GString>;
64 
65     #[doc(alias = "g_volume_get_activation_root")]
66     #[doc(alias = "get_activation_root")]
activation_root(&self) -> Option<File>67     fn activation_root(&self) -> Option<File>;
68 
69     #[doc(alias = "g_volume_get_drive")]
70     #[doc(alias = "get_drive")]
drive(&self) -> Option<Drive>71     fn drive(&self) -> Option<Drive>;
72 
73     #[doc(alias = "g_volume_get_icon")]
74     #[doc(alias = "get_icon")]
icon(&self) -> Icon75     fn icon(&self) -> Icon;
76 
77     #[doc(alias = "g_volume_get_identifier")]
78     #[doc(alias = "get_identifier")]
identifier(&self, kind: &str) -> Option<glib::GString>79     fn identifier(&self, kind: &str) -> Option<glib::GString>;
80 
81     #[doc(alias = "g_volume_get_mount")]
get_mount(&self) -> Option<Mount>82     fn get_mount(&self) -> Option<Mount>;
83 
84     #[doc(alias = "g_volume_get_name")]
85     #[doc(alias = "get_name")]
name(&self) -> glib::GString86     fn name(&self) -> glib::GString;
87 
88     #[doc(alias = "g_volume_get_sort_key")]
89     #[doc(alias = "get_sort_key")]
sort_key(&self) -> Option<glib::GString>90     fn sort_key(&self) -> Option<glib::GString>;
91 
92     #[doc(alias = "g_volume_get_symbolic_icon")]
93     #[doc(alias = "get_symbolic_icon")]
symbolic_icon(&self) -> Icon94     fn symbolic_icon(&self) -> Icon;
95 
96     #[doc(alias = "g_volume_get_uuid")]
97     #[doc(alias = "get_uuid")]
uuid(&self) -> Option<glib::GString>98     fn uuid(&self) -> Option<glib::GString>;
99 
100     #[doc(alias = "g_volume_mount")]
mount< P: IsA<MountOperation>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, flags: MountMountFlags, mount_operation: Option<&P>, cancellable: Option<&Q>, callback: R, )101     fn mount<
102         P: IsA<MountOperation>,
103         Q: IsA<Cancellable>,
104         R: FnOnce(Result<(), glib::Error>) + Send + 'static,
105     >(
106         &self,
107         flags: MountMountFlags,
108         mount_operation: Option<&P>,
109         cancellable: Option<&Q>,
110         callback: R,
111     );
112 
mount_future<P: IsA<MountOperation> + Clone + 'static>( &self, flags: MountMountFlags, mount_operation: Option<&P>, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>113     fn mount_future<P: IsA<MountOperation> + Clone + 'static>(
114         &self,
115         flags: MountMountFlags,
116         mount_operation: Option<&P>,
117     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>;
118 
119     #[doc(alias = "g_volume_should_automount")]
should_automount(&self) -> bool120     fn should_automount(&self) -> bool;
121 
122     #[doc(alias = "changed")]
connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId123     fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
124 
125     #[doc(alias = "removed")]
connect_removed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId126     fn connect_removed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
127 }
128 
129 impl<O: IsA<Volume>> VolumeExt for O {
can_eject(&self) -> bool130     fn can_eject(&self) -> bool {
131         unsafe { from_glib(ffi::g_volume_can_eject(self.as_ref().to_glib_none().0)) }
132     }
133 
can_mount(&self) -> bool134     fn can_mount(&self) -> bool {
135         unsafe { from_glib(ffi::g_volume_can_mount(self.as_ref().to_glib_none().0)) }
136     }
137 
eject_with_operation< P: IsA<MountOperation>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, flags: MountUnmountFlags, mount_operation: Option<&P>, cancellable: Option<&Q>, callback: R, )138     fn eject_with_operation<
139         P: IsA<MountOperation>,
140         Q: IsA<Cancellable>,
141         R: FnOnce(Result<(), glib::Error>) + Send + 'static,
142     >(
143         &self,
144         flags: MountUnmountFlags,
145         mount_operation: Option<&P>,
146         cancellable: Option<&Q>,
147         callback: R,
148     ) {
149         let user_data: Box_<R> = Box_::new(callback);
150         unsafe extern "C" fn eject_with_operation_trampoline<
151             R: FnOnce(Result<(), glib::Error>) + Send + 'static,
152         >(
153             _source_object: *mut glib::gobject_ffi::GObject,
154             res: *mut crate::ffi::GAsyncResult,
155             user_data: glib::ffi::gpointer,
156         ) {
157             let mut error = ptr::null_mut();
158             let _ = ffi::g_volume_eject_with_operation_finish(
159                 _source_object as *mut _,
160                 res,
161                 &mut error,
162             );
163             let result = if error.is_null() {
164                 Ok(())
165             } else {
166                 Err(from_glib_full(error))
167             };
168             let callback: Box_<R> = Box_::from_raw(user_data as *mut _);
169             callback(result);
170         }
171         let callback = eject_with_operation_trampoline::<R>;
172         unsafe {
173             ffi::g_volume_eject_with_operation(
174                 self.as_ref().to_glib_none().0,
175                 flags.into_glib(),
176                 mount_operation.map(|p| p.as_ref()).to_glib_none().0,
177                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
178                 Some(callback),
179                 Box_::into_raw(user_data) as *mut _,
180             );
181         }
182     }
183 
eject_with_operation_future<P: IsA<MountOperation> + Clone + 'static>( &self, flags: MountUnmountFlags, mount_operation: Option<&P>, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>184     fn eject_with_operation_future<P: IsA<MountOperation> + Clone + 'static>(
185         &self,
186         flags: MountUnmountFlags,
187         mount_operation: Option<&P>,
188     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
189         let mount_operation = mount_operation.map(ToOwned::to_owned);
190         Box_::pin(crate::GioFuture::new(
191             self,
192             move |obj, cancellable, send| {
193                 obj.eject_with_operation(
194                     flags,
195                     mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
196                     Some(cancellable),
197                     move |res| {
198                         send.resolve(res);
199                     },
200                 );
201             },
202         ))
203     }
204 
enumerate_identifiers(&self) -> Vec<glib::GString>205     fn enumerate_identifiers(&self) -> Vec<glib::GString> {
206         unsafe {
207             FromGlibPtrContainer::from_glib_full(ffi::g_volume_enumerate_identifiers(
208                 self.as_ref().to_glib_none().0,
209             ))
210         }
211     }
212 
activation_root(&self) -> Option<File>213     fn activation_root(&self) -> Option<File> {
214         unsafe {
215             from_glib_full(ffi::g_volume_get_activation_root(
216                 self.as_ref().to_glib_none().0,
217             ))
218         }
219     }
220 
drive(&self) -> Option<Drive>221     fn drive(&self) -> Option<Drive> {
222         unsafe { from_glib_full(ffi::g_volume_get_drive(self.as_ref().to_glib_none().0)) }
223     }
224 
icon(&self) -> Icon225     fn icon(&self) -> Icon {
226         unsafe { from_glib_full(ffi::g_volume_get_icon(self.as_ref().to_glib_none().0)) }
227     }
228 
identifier(&self, kind: &str) -> Option<glib::GString>229     fn identifier(&self, kind: &str) -> Option<glib::GString> {
230         unsafe {
231             from_glib_full(ffi::g_volume_get_identifier(
232                 self.as_ref().to_glib_none().0,
233                 kind.to_glib_none().0,
234             ))
235         }
236     }
237 
get_mount(&self) -> Option<Mount>238     fn get_mount(&self) -> Option<Mount> {
239         unsafe { from_glib_full(ffi::g_volume_get_mount(self.as_ref().to_glib_none().0)) }
240     }
241 
name(&self) -> glib::GString242     fn name(&self) -> glib::GString {
243         unsafe { from_glib_full(ffi::g_volume_get_name(self.as_ref().to_glib_none().0)) }
244     }
245 
sort_key(&self) -> Option<glib::GString>246     fn sort_key(&self) -> Option<glib::GString> {
247         unsafe { from_glib_none(ffi::g_volume_get_sort_key(self.as_ref().to_glib_none().0)) }
248     }
249 
symbolic_icon(&self) -> Icon250     fn symbolic_icon(&self) -> Icon {
251         unsafe {
252             from_glib_full(ffi::g_volume_get_symbolic_icon(
253                 self.as_ref().to_glib_none().0,
254             ))
255         }
256     }
257 
uuid(&self) -> Option<glib::GString>258     fn uuid(&self) -> Option<glib::GString> {
259         unsafe { from_glib_full(ffi::g_volume_get_uuid(self.as_ref().to_glib_none().0)) }
260     }
261 
mount< P: IsA<MountOperation>, Q: IsA<Cancellable>, R: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, flags: MountMountFlags, mount_operation: Option<&P>, cancellable: Option<&Q>, callback: R, )262     fn mount<
263         P: IsA<MountOperation>,
264         Q: IsA<Cancellable>,
265         R: FnOnce(Result<(), glib::Error>) + Send + 'static,
266     >(
267         &self,
268         flags: MountMountFlags,
269         mount_operation: Option<&P>,
270         cancellable: Option<&Q>,
271         callback: R,
272     ) {
273         let user_data: Box_<R> = Box_::new(callback);
274         unsafe extern "C" fn mount_trampoline<
275             R: FnOnce(Result<(), glib::Error>) + Send + 'static,
276         >(
277             _source_object: *mut glib::gobject_ffi::GObject,
278             res: *mut crate::ffi::GAsyncResult,
279             user_data: glib::ffi::gpointer,
280         ) {
281             let mut error = ptr::null_mut();
282             let _ = ffi::g_volume_mount_finish(_source_object as *mut _, res, &mut error);
283             let result = if error.is_null() {
284                 Ok(())
285             } else {
286                 Err(from_glib_full(error))
287             };
288             let callback: Box_<R> = Box_::from_raw(user_data as *mut _);
289             callback(result);
290         }
291         let callback = mount_trampoline::<R>;
292         unsafe {
293             ffi::g_volume_mount(
294                 self.as_ref().to_glib_none().0,
295                 flags.into_glib(),
296                 mount_operation.map(|p| p.as_ref()).to_glib_none().0,
297                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
298                 Some(callback),
299                 Box_::into_raw(user_data) as *mut _,
300             );
301         }
302     }
303 
mount_future<P: IsA<MountOperation> + Clone + 'static>( &self, flags: MountMountFlags, mount_operation: Option<&P>, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>304     fn mount_future<P: IsA<MountOperation> + Clone + 'static>(
305         &self,
306         flags: MountMountFlags,
307         mount_operation: Option<&P>,
308     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
309         let mount_operation = mount_operation.map(ToOwned::to_owned);
310         Box_::pin(crate::GioFuture::new(
311             self,
312             move |obj, cancellable, send| {
313                 obj.mount(
314                     flags,
315                     mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
316                     Some(cancellable),
317                     move |res| {
318                         send.resolve(res);
319                     },
320                 );
321             },
322         ))
323     }
324 
should_automount(&self) -> bool325     fn should_automount(&self) -> bool {
326         unsafe {
327             from_glib(ffi::g_volume_should_automount(
328                 self.as_ref().to_glib_none().0,
329             ))
330         }
331     }
332 
connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId333     fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
334         unsafe extern "C" fn changed_trampoline<P: IsA<Volume>, F: Fn(&P) + 'static>(
335             this: *mut ffi::GVolume,
336             f: glib::ffi::gpointer,
337         ) {
338             let f: &F = &*(f as *const F);
339             f(Volume::from_glib_borrow(this).unsafe_cast_ref())
340         }
341         unsafe {
342             let f: Box_<F> = Box_::new(f);
343             connect_raw(
344                 self.as_ptr() as *mut _,
345                 b"changed\0".as_ptr() as *const _,
346                 Some(transmute::<_, unsafe extern "C" fn()>(
347                     changed_trampoline::<Self, F> as *const (),
348                 )),
349                 Box_::into_raw(f),
350             )
351         }
352     }
353 
connect_removed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId354     fn connect_removed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
355         unsafe extern "C" fn removed_trampoline<P: IsA<Volume>, F: Fn(&P) + 'static>(
356             this: *mut ffi::GVolume,
357             f: glib::ffi::gpointer,
358         ) {
359             let f: &F = &*(f as *const F);
360             f(Volume::from_glib_borrow(this).unsafe_cast_ref())
361         }
362         unsafe {
363             let f: Box_<F> = Box_::new(f);
364             connect_raw(
365                 self.as_ptr() as *mut _,
366                 b"removed\0".as_ptr() as *const _,
367                 Some(transmute::<_, unsafe extern "C" fn()>(
368                     removed_trampoline::<Self, F> as *const (),
369                 )),
370                 Box_::into_raw(f),
371             )
372         }
373     }
374 }
375 
376 impl fmt::Display for Volume {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result377     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
378         f.write_str("Volume")
379     }
380 }
381