gio/auto/
mount.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
5#[cfg(feature = "futures")]
6use futures::future;
7use gio_sys;
8use glib::object::Cast;
9use glib::object::IsA;
10use glib::signal::connect_raw;
11use glib::signal::SignalHandlerId;
12use glib::translate::*;
13use glib::GString;
14use glib_sys;
15use gobject_sys;
16use std::boxed::Box as Box_;
17use std::fmt;
18use std::mem::transmute;
19use std::ptr;
20use Cancellable;
21use Drive;
22use Error;
23use File;
24use Icon;
25use MountMountFlags;
26use MountOperation;
27use MountUnmountFlags;
28use Volume;
29
30glib_wrapper! {
31    pub struct Mount(Interface<gio_sys::GMount>);
32
33    match fn {
34        get_type => || gio_sys::g_mount_get_type(),
35    }
36}
37
38pub const NONE_MOUNT: Option<&Mount> = None;
39
40pub trait MountExt: 'static {
41    fn can_eject(&self) -> bool;
42
43    fn can_unmount(&self) -> bool;
44
45    fn eject_with_operation<
46        P: IsA<MountOperation>,
47        Q: IsA<Cancellable>,
48        R: FnOnce(Result<(), Error>) + Send + 'static,
49    >(
50        &self,
51        flags: MountUnmountFlags,
52        mount_operation: Option<&P>,
53        cancellable: Option<&Q>,
54        callback: R,
55    );
56
57    #[cfg(feature = "futures")]
58    fn eject_with_operation_future<P: IsA<MountOperation> + Clone + 'static>(
59        &self,
60        flags: MountUnmountFlags,
61        mount_operation: Option<&P>,
62    ) -> Box_<dyn future::Future<Output = Result<(), Error>> + std::marker::Unpin>;
63
64    fn get_default_location(&self) -> Option<File>;
65
66    fn get_drive(&self) -> Option<Drive>;
67
68    fn get_icon(&self) -> Option<Icon>;
69
70    fn get_name(&self) -> Option<GString>;
71
72    fn get_root(&self) -> Option<File>;
73
74    fn get_sort_key(&self) -> Option<GString>;
75
76    fn get_symbolic_icon(&self) -> Option<Icon>;
77
78    fn get_uuid(&self) -> Option<GString>;
79
80    fn get_volume(&self) -> Option<Volume>;
81
82    fn guess_content_type<
83        P: IsA<Cancellable>,
84        Q: FnOnce(Result<Vec<GString>, Error>) + Send + 'static,
85    >(
86        &self,
87        force_rescan: bool,
88        cancellable: Option<&P>,
89        callback: Q,
90    );
91
92    #[cfg(feature = "futures")]
93    fn guess_content_type_future(
94        &self,
95        force_rescan: bool,
96    ) -> Box_<dyn future::Future<Output = Result<Vec<GString>, Error>> + std::marker::Unpin>;
97
98    fn guess_content_type_sync<P: IsA<Cancellable>>(
99        &self,
100        force_rescan: bool,
101        cancellable: Option<&P>,
102    ) -> Result<Vec<GString>, Error>;
103
104    fn is_shadowed(&self) -> bool;
105
106    fn remount<
107        P: IsA<MountOperation>,
108        Q: IsA<Cancellable>,
109        R: FnOnce(Result<(), Error>) + Send + 'static,
110    >(
111        &self,
112        flags: MountMountFlags,
113        mount_operation: Option<&P>,
114        cancellable: Option<&Q>,
115        callback: R,
116    );
117
118    #[cfg(feature = "futures")]
119    fn remount_future<P: IsA<MountOperation> + Clone + 'static>(
120        &self,
121        flags: MountMountFlags,
122        mount_operation: Option<&P>,
123    ) -> Box_<dyn future::Future<Output = Result<(), Error>> + std::marker::Unpin>;
124
125    fn shadow(&self);
126
127    fn unmount_with_operation<
128        P: IsA<MountOperation>,
129        Q: IsA<Cancellable>,
130        R: FnOnce(Result<(), Error>) + Send + 'static,
131    >(
132        &self,
133        flags: MountUnmountFlags,
134        mount_operation: Option<&P>,
135        cancellable: Option<&Q>,
136        callback: R,
137    );
138
139    #[cfg(feature = "futures")]
140    fn unmount_with_operation_future<P: IsA<MountOperation> + Clone + 'static>(
141        &self,
142        flags: MountUnmountFlags,
143        mount_operation: Option<&P>,
144    ) -> Box_<dyn future::Future<Output = Result<(), Error>> + std::marker::Unpin>;
145
146    fn unshadow(&self);
147
148    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
149
150    fn connect_pre_unmount<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
151
152    fn connect_unmounted<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
153}
154
155impl<O: IsA<Mount>> MountExt for O {
156    fn can_eject(&self) -> bool {
157        unsafe { from_glib(gio_sys::g_mount_can_eject(self.as_ref().to_glib_none().0)) }
158    }
159
160    fn can_unmount(&self) -> bool {
161        unsafe { from_glib(gio_sys::g_mount_can_unmount(self.as_ref().to_glib_none().0)) }
162    }
163
164    fn eject_with_operation<
165        P: IsA<MountOperation>,
166        Q: IsA<Cancellable>,
167        R: FnOnce(Result<(), Error>) + Send + 'static,
168    >(
169        &self,
170        flags: MountUnmountFlags,
171        mount_operation: Option<&P>,
172        cancellable: Option<&Q>,
173        callback: R,
174    ) {
175        let user_data: Box<R> = Box::new(callback);
176        unsafe extern "C" fn eject_with_operation_trampoline<
177            R: FnOnce(Result<(), Error>) + Send + 'static,
178        >(
179            _source_object: *mut gobject_sys::GObject,
180            res: *mut gio_sys::GAsyncResult,
181            user_data: glib_sys::gpointer,
182        ) {
183            let mut error = ptr::null_mut();
184            let _ = gio_sys::g_mount_eject_with_operation_finish(
185                _source_object as *mut _,
186                res,
187                &mut error,
188            );
189            let result = if error.is_null() {
190                Ok(())
191            } else {
192                Err(from_glib_full(error))
193            };
194            let callback: Box<R> = Box::from_raw(user_data as *mut _);
195            callback(result);
196        }
197        let callback = eject_with_operation_trampoline::<R>;
198        unsafe {
199            gio_sys::g_mount_eject_with_operation(
200                self.as_ref().to_glib_none().0,
201                flags.to_glib(),
202                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
203                cancellable.map(|p| p.as_ref()).to_glib_none().0,
204                Some(callback),
205                Box::into_raw(user_data) as *mut _,
206            );
207        }
208    }
209
210    #[cfg(feature = "futures")]
211    fn eject_with_operation_future<P: IsA<MountOperation> + Clone + 'static>(
212        &self,
213        flags: MountUnmountFlags,
214        mount_operation: Option<&P>,
215    ) -> Box_<dyn future::Future<Output = Result<(), Error>> + std::marker::Unpin> {
216        use fragile::Fragile;
217        use GioFuture;
218
219        let mount_operation = mount_operation.map(ToOwned::to_owned);
220        GioFuture::new(self, move |obj, send| {
221            let cancellable = Cancellable::new();
222            let send = Fragile::new(send);
223            obj.eject_with_operation(
224                flags,
225                mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
226                Some(&cancellable),
227                move |res| {
228                    let _ = send.into_inner().send(res);
229                },
230            );
231
232            cancellable
233        })
234    }
235
236    fn get_default_location(&self) -> Option<File> {
237        unsafe {
238            from_glib_full(gio_sys::g_mount_get_default_location(
239                self.as_ref().to_glib_none().0,
240            ))
241        }
242    }
243
244    fn get_drive(&self) -> Option<Drive> {
245        unsafe { from_glib_full(gio_sys::g_mount_get_drive(self.as_ref().to_glib_none().0)) }
246    }
247
248    fn get_icon(&self) -> Option<Icon> {
249        unsafe { from_glib_full(gio_sys::g_mount_get_icon(self.as_ref().to_glib_none().0)) }
250    }
251
252    fn get_name(&self) -> Option<GString> {
253        unsafe { from_glib_full(gio_sys::g_mount_get_name(self.as_ref().to_glib_none().0)) }
254    }
255
256    fn get_root(&self) -> Option<File> {
257        unsafe { from_glib_full(gio_sys::g_mount_get_root(self.as_ref().to_glib_none().0)) }
258    }
259
260    fn get_sort_key(&self) -> Option<GString> {
261        unsafe {
262            from_glib_none(gio_sys::g_mount_get_sort_key(
263                self.as_ref().to_glib_none().0,
264            ))
265        }
266    }
267
268    fn get_symbolic_icon(&self) -> Option<Icon> {
269        unsafe {
270            from_glib_full(gio_sys::g_mount_get_symbolic_icon(
271                self.as_ref().to_glib_none().0,
272            ))
273        }
274    }
275
276    fn get_uuid(&self) -> Option<GString> {
277        unsafe { from_glib_full(gio_sys::g_mount_get_uuid(self.as_ref().to_glib_none().0)) }
278    }
279
280    fn get_volume(&self) -> Option<Volume> {
281        unsafe { from_glib_full(gio_sys::g_mount_get_volume(self.as_ref().to_glib_none().0)) }
282    }
283
284    fn guess_content_type<
285        P: IsA<Cancellable>,
286        Q: FnOnce(Result<Vec<GString>, Error>) + Send + 'static,
287    >(
288        &self,
289        force_rescan: bool,
290        cancellable: Option<&P>,
291        callback: Q,
292    ) {
293        let user_data: Box<Q> = Box::new(callback);
294        unsafe extern "C" fn guess_content_type_trampoline<
295            Q: FnOnce(Result<Vec<GString>, Error>) + Send + 'static,
296        >(
297            _source_object: *mut gobject_sys::GObject,
298            res: *mut gio_sys::GAsyncResult,
299            user_data: glib_sys::gpointer,
300        ) {
301            let mut error = ptr::null_mut();
302            let ret = gio_sys::g_mount_guess_content_type_finish(
303                _source_object as *mut _,
304                res,
305                &mut error,
306            );
307            let result = if error.is_null() {
308                Ok(FromGlibPtrContainer::from_glib_full(ret))
309            } else {
310                Err(from_glib_full(error))
311            };
312            let callback: Box<Q> = Box::from_raw(user_data as *mut _);
313            callback(result);
314        }
315        let callback = guess_content_type_trampoline::<Q>;
316        unsafe {
317            gio_sys::g_mount_guess_content_type(
318                self.as_ref().to_glib_none().0,
319                force_rescan.to_glib(),
320                cancellable.map(|p| p.as_ref()).to_glib_none().0,
321                Some(callback),
322                Box::into_raw(user_data) as *mut _,
323            );
324        }
325    }
326
327    #[cfg(feature = "futures")]
328    fn guess_content_type_future(
329        &self,
330        force_rescan: bool,
331    ) -> Box_<dyn future::Future<Output = Result<Vec<GString>, Error>> + std::marker::Unpin> {
332        use fragile::Fragile;
333        use GioFuture;
334
335        GioFuture::new(self, move |obj, send| {
336            let cancellable = Cancellable::new();
337            let send = Fragile::new(send);
338            obj.guess_content_type(force_rescan, Some(&cancellable), move |res| {
339                let _ = send.into_inner().send(res);
340            });
341
342            cancellable
343        })
344    }
345
346    fn guess_content_type_sync<P: IsA<Cancellable>>(
347        &self,
348        force_rescan: bool,
349        cancellable: Option<&P>,
350    ) -> Result<Vec<GString>, Error> {
351        unsafe {
352            let mut error = ptr::null_mut();
353            let ret = gio_sys::g_mount_guess_content_type_sync(
354                self.as_ref().to_glib_none().0,
355                force_rescan.to_glib(),
356                cancellable.map(|p| p.as_ref()).to_glib_none().0,
357                &mut error,
358            );
359            if error.is_null() {
360                Ok(FromGlibPtrContainer::from_glib_full(ret))
361            } else {
362                Err(from_glib_full(error))
363            }
364        }
365    }
366
367    fn is_shadowed(&self) -> bool {
368        unsafe { from_glib(gio_sys::g_mount_is_shadowed(self.as_ref().to_glib_none().0)) }
369    }
370
371    fn remount<
372        P: IsA<MountOperation>,
373        Q: IsA<Cancellable>,
374        R: FnOnce(Result<(), Error>) + Send + 'static,
375    >(
376        &self,
377        flags: MountMountFlags,
378        mount_operation: Option<&P>,
379        cancellable: Option<&Q>,
380        callback: R,
381    ) {
382        let user_data: Box<R> = Box::new(callback);
383        unsafe extern "C" fn remount_trampoline<R: FnOnce(Result<(), Error>) + Send + 'static>(
384            _source_object: *mut gobject_sys::GObject,
385            res: *mut gio_sys::GAsyncResult,
386            user_data: glib_sys::gpointer,
387        ) {
388            let mut error = ptr::null_mut();
389            let _ = gio_sys::g_mount_remount_finish(_source_object as *mut _, res, &mut error);
390            let result = if error.is_null() {
391                Ok(())
392            } else {
393                Err(from_glib_full(error))
394            };
395            let callback: Box<R> = Box::from_raw(user_data as *mut _);
396            callback(result);
397        }
398        let callback = remount_trampoline::<R>;
399        unsafe {
400            gio_sys::g_mount_remount(
401                self.as_ref().to_glib_none().0,
402                flags.to_glib(),
403                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
404                cancellable.map(|p| p.as_ref()).to_glib_none().0,
405                Some(callback),
406                Box::into_raw(user_data) as *mut _,
407            );
408        }
409    }
410
411    #[cfg(feature = "futures")]
412    fn remount_future<P: IsA<MountOperation> + Clone + 'static>(
413        &self,
414        flags: MountMountFlags,
415        mount_operation: Option<&P>,
416    ) -> Box_<dyn future::Future<Output = Result<(), Error>> + std::marker::Unpin> {
417        use fragile::Fragile;
418        use GioFuture;
419
420        let mount_operation = mount_operation.map(ToOwned::to_owned);
421        GioFuture::new(self, move |obj, send| {
422            let cancellable = Cancellable::new();
423            let send = Fragile::new(send);
424            obj.remount(
425                flags,
426                mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
427                Some(&cancellable),
428                move |res| {
429                    let _ = send.into_inner().send(res);
430                },
431            );
432
433            cancellable
434        })
435    }
436
437    fn shadow(&self) {
438        unsafe {
439            gio_sys::g_mount_shadow(self.as_ref().to_glib_none().0);
440        }
441    }
442
443    fn unmount_with_operation<
444        P: IsA<MountOperation>,
445        Q: IsA<Cancellable>,
446        R: FnOnce(Result<(), Error>) + Send + 'static,
447    >(
448        &self,
449        flags: MountUnmountFlags,
450        mount_operation: Option<&P>,
451        cancellable: Option<&Q>,
452        callback: R,
453    ) {
454        let user_data: Box<R> = Box::new(callback);
455        unsafe extern "C" fn unmount_with_operation_trampoline<
456            R: FnOnce(Result<(), Error>) + Send + 'static,
457        >(
458            _source_object: *mut gobject_sys::GObject,
459            res: *mut gio_sys::GAsyncResult,
460            user_data: glib_sys::gpointer,
461        ) {
462            let mut error = ptr::null_mut();
463            let _ = gio_sys::g_mount_unmount_with_operation_finish(
464                _source_object as *mut _,
465                res,
466                &mut error,
467            );
468            let result = if error.is_null() {
469                Ok(())
470            } else {
471                Err(from_glib_full(error))
472            };
473            let callback: Box<R> = Box::from_raw(user_data as *mut _);
474            callback(result);
475        }
476        let callback = unmount_with_operation_trampoline::<R>;
477        unsafe {
478            gio_sys::g_mount_unmount_with_operation(
479                self.as_ref().to_glib_none().0,
480                flags.to_glib(),
481                mount_operation.map(|p| p.as_ref()).to_glib_none().0,
482                cancellable.map(|p| p.as_ref()).to_glib_none().0,
483                Some(callback),
484                Box::into_raw(user_data) as *mut _,
485            );
486        }
487    }
488
489    #[cfg(feature = "futures")]
490    fn unmount_with_operation_future<P: IsA<MountOperation> + Clone + 'static>(
491        &self,
492        flags: MountUnmountFlags,
493        mount_operation: Option<&P>,
494    ) -> Box_<dyn future::Future<Output = Result<(), Error>> + std::marker::Unpin> {
495        use fragile::Fragile;
496        use GioFuture;
497
498        let mount_operation = mount_operation.map(ToOwned::to_owned);
499        GioFuture::new(self, move |obj, send| {
500            let cancellable = Cancellable::new();
501            let send = Fragile::new(send);
502            obj.unmount_with_operation(
503                flags,
504                mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
505                Some(&cancellable),
506                move |res| {
507                    let _ = send.into_inner().send(res);
508                },
509            );
510
511            cancellable
512        })
513    }
514
515    fn unshadow(&self) {
516        unsafe {
517            gio_sys::g_mount_unshadow(self.as_ref().to_glib_none().0);
518        }
519    }
520
521    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
522        unsafe extern "C" fn changed_trampoline<P, F: Fn(&P) + 'static>(
523            this: *mut gio_sys::GMount,
524            f: glib_sys::gpointer,
525        ) where
526            P: IsA<Mount>,
527        {
528            let f: &F = &*(f as *const F);
529            f(&Mount::from_glib_borrow(this).unsafe_cast())
530        }
531        unsafe {
532            let f: Box_<F> = Box_::new(f);
533            connect_raw(
534                self.as_ptr() as *mut _,
535                b"changed\0".as_ptr() as *const _,
536                Some(transmute(changed_trampoline::<Self, F> as usize)),
537                Box_::into_raw(f),
538            )
539        }
540    }
541
542    fn connect_pre_unmount<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
543        unsafe extern "C" fn pre_unmount_trampoline<P, F: Fn(&P) + 'static>(
544            this: *mut gio_sys::GMount,
545            f: glib_sys::gpointer,
546        ) where
547            P: IsA<Mount>,
548        {
549            let f: &F = &*(f as *const F);
550            f(&Mount::from_glib_borrow(this).unsafe_cast())
551        }
552        unsafe {
553            let f: Box_<F> = Box_::new(f);
554            connect_raw(
555                self.as_ptr() as *mut _,
556                b"pre-unmount\0".as_ptr() as *const _,
557                Some(transmute(pre_unmount_trampoline::<Self, F> as usize)),
558                Box_::into_raw(f),
559            )
560        }
561    }
562
563    fn connect_unmounted<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
564        unsafe extern "C" fn unmounted_trampoline<P, F: Fn(&P) + 'static>(
565            this: *mut gio_sys::GMount,
566            f: glib_sys::gpointer,
567        ) where
568            P: IsA<Mount>,
569        {
570            let f: &F = &*(f as *const F);
571            f(&Mount::from_glib_borrow(this).unsafe_cast())
572        }
573        unsafe {
574            let f: Box_<F> = Box_::new(f);
575            connect_raw(
576                self.as_ptr() as *mut _,
577                b"unmounted\0".as_ptr() as *const _,
578                Some(transmute(unmounted_trampoline::<Self, F> as usize)),
579                Box_::into_raw(f),
580            )
581        }
582    }
583}
584
585impl fmt::Display for Mount {
586    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
587        write!(f, "Mount")
588    }
589}