use Cancellable;
use Drive;
use Error;
use File;
use Icon;
use MountMountFlags;
use MountOperation;
use MountUnmountFlags;
use Volume;
use ffi;
#[cfg(feature = "futures")]
use futures_core;
use glib::GString;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use std::ptr;
glib_wrapper! {
pub struct Mount(Interface<ffi::GMount>);
match fn {
get_type => || ffi::g_mount_get_type(),
}
}
pub const NONE_MOUNT: Option<&Mount> = None;
pub trait MountExt: 'static {
fn can_eject(&self) -> bool;
fn can_unmount(&self) -> bool;
fn eject_with_operation<'a, 'b, P: IsA<MountOperation> + 'a, Q: Into<Option<&'a P>>, R: IsA<Cancellable> + 'b, S: Into<Option<&'b R>>, T: FnOnce(Result<(), Error>) + Send + 'static>(&self, flags: MountUnmountFlags, mount_operation: Q, cancellable: S, callback: T);
#[cfg(feature = "futures")]
fn eject_with_operation_future<'a, P: IsA<MountOperation> + Clone + 'static, Q: Into<Option<&'a P>>>(&self, flags: MountUnmountFlags, mount_operation: Q) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone;
fn get_default_location(&self) -> Option<File>;
fn get_drive(&self) -> Option<Drive>;
fn get_icon(&self) -> Option<Icon>;
fn get_name(&self) -> Option<GString>;
fn get_root(&self) -> Option<File>;
fn get_sort_key(&self) -> Option<GString>;
fn get_symbolic_icon(&self) -> Option<Icon>;
fn get_uuid(&self) -> Option<GString>;
fn get_volume(&self) -> Option<Volume>;
fn guess_content_type<'a, P: IsA<Cancellable> + 'a, Q: Into<Option<&'a P>>, R: FnOnce(Result<Vec<GString>, Error>) + Send + 'static>(&self, force_rescan: bool, cancellable: Q, callback: R);
#[cfg(feature = "futures")]
fn guess_content_type_future(&self, force_rescan: bool) -> Box_<futures_core::Future<Item = (Self, Vec<GString>), Error = (Self, Error)>> where Self: Sized + Clone;
fn guess_content_type_sync<'a, P: IsA<Cancellable> + 'a, Q: Into<Option<&'a P>>>(&self, force_rescan: bool, cancellable: Q) -> Result<Vec<GString>, Error>;
fn is_shadowed(&self) -> bool;
fn remount<'a, 'b, P: IsA<MountOperation> + 'a, Q: Into<Option<&'a P>>, R: IsA<Cancellable> + 'b, S: Into<Option<&'b R>>, T: FnOnce(Result<(), Error>) + Send + 'static>(&self, flags: MountMountFlags, mount_operation: Q, cancellable: S, callback: T);
#[cfg(feature = "futures")]
fn remount_future<'a, P: IsA<MountOperation> + Clone + 'static, Q: Into<Option<&'a P>>>(&self, flags: MountMountFlags, mount_operation: Q) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone;
fn shadow(&self);
fn unmount_with_operation<'a, 'b, P: IsA<MountOperation> + 'a, Q: Into<Option<&'a P>>, R: IsA<Cancellable> + 'b, S: Into<Option<&'b R>>, T: FnOnce(Result<(), Error>) + Send + 'static>(&self, flags: MountUnmountFlags, mount_operation: Q, cancellable: S, callback: T);
#[cfg(feature = "futures")]
fn unmount_with_operation_future<'a, P: IsA<MountOperation> + Clone + 'static, Q: Into<Option<&'a P>>>(&self, flags: MountUnmountFlags, mount_operation: Q) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone;
fn unshadow(&self);
fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_pre_unmount<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_unmounted<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Mount>> MountExt for O {
fn can_eject(&self) -> bool {
unsafe {
from_glib(ffi::g_mount_can_eject(self.as_ref().to_glib_none().0))
}
}
fn can_unmount(&self) -> bool {
unsafe {
from_glib(ffi::g_mount_can_unmount(self.as_ref().to_glib_none().0))
}
}
fn eject_with_operation<'a, 'b, P: IsA<MountOperation> + 'a, Q: Into<Option<&'a P>>, R: IsA<Cancellable> + 'b, S: Into<Option<&'b R>>, T: FnOnce(Result<(), Error>) + Send + 'static>(&self, flags: MountUnmountFlags, mount_operation: Q, cancellable: S, callback: T) {
let mount_operation = mount_operation.into();
let cancellable = cancellable.into();
let user_data: Box<T> = Box::new(callback);
unsafe extern "C" fn eject_with_operation_trampoline<T: FnOnce(Result<(), Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer) {
let mut error = ptr::null_mut();
let _ = ffi::g_mount_eject_with_operation_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) };
let callback: Box<T> = Box::from_raw(user_data as *mut _);
callback(result);
}
let callback = eject_with_operation_trampoline::<T>;
unsafe {
ffi::g_mount_eject_with_operation(self.as_ref().to_glib_none().0, flags.to_glib(), mount_operation.map(|p| p.as_ref()).to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _);
}
}
#[cfg(feature = "futures")]
fn eject_with_operation_future<'a, P: IsA<MountOperation> + Clone + 'static, Q: Into<Option<&'a P>>>(&self, flags: MountUnmountFlags, mount_operation: Q) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone {
use GioFuture;
use fragile::Fragile;
let mount_operation = mount_operation.into();
let mount_operation = mount_operation.map(ToOwned::to_owned);
GioFuture::new(self, move |obj, send| {
let cancellable = Cancellable::new();
let send = Fragile::new(send);
let obj_clone = Fragile::new(obj.clone());
obj.eject_with_operation(
flags,
mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
Some(&cancellable),
move |res| {
let obj = obj_clone.into_inner();
let res = res.map(|v| (obj.clone(), v)).map_err(|v| (obj.clone(), v));
let _ = send.into_inner().send(res);
},
);
cancellable
})
}
fn get_default_location(&self) -> Option<File> {
unsafe {
from_glib_full(ffi::g_mount_get_default_location(self.as_ref().to_glib_none().0))
}
}
fn get_drive(&self) -> Option<Drive> {
unsafe {
from_glib_full(ffi::g_mount_get_drive(self.as_ref().to_glib_none().0))
}
}
fn get_icon(&self) -> Option<Icon> {
unsafe {
from_glib_full(ffi::g_mount_get_icon(self.as_ref().to_glib_none().0))
}
}
fn get_name(&self) -> Option<GString> {
unsafe {
from_glib_full(ffi::g_mount_get_name(self.as_ref().to_glib_none().0))
}
}
fn get_root(&self) -> Option<File> {
unsafe {
from_glib_full(ffi::g_mount_get_root(self.as_ref().to_glib_none().0))
}
}
fn get_sort_key(&self) -> Option<GString> {
unsafe {
from_glib_none(ffi::g_mount_get_sort_key(self.as_ref().to_glib_none().0))
}
}
fn get_symbolic_icon(&self) -> Option<Icon> {
unsafe {
from_glib_full(ffi::g_mount_get_symbolic_icon(self.as_ref().to_glib_none().0))
}
}
fn get_uuid(&self) -> Option<GString> {
unsafe {
from_glib_full(ffi::g_mount_get_uuid(self.as_ref().to_glib_none().0))
}
}
fn get_volume(&self) -> Option<Volume> {
unsafe {
from_glib_full(ffi::g_mount_get_volume(self.as_ref().to_glib_none().0))
}
}
fn guess_content_type<'a, P: IsA<Cancellable> + 'a, Q: Into<Option<&'a P>>, R: FnOnce(Result<Vec<GString>, Error>) + Send + 'static>(&self, force_rescan: bool, cancellable: Q, callback: R) {
let cancellable = cancellable.into();
let user_data: Box<R> = Box::new(callback);
unsafe extern "C" fn guess_content_type_trampoline<R: FnOnce(Result<Vec<GString>, Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer) {
let mut error = ptr::null_mut();
let ret = ffi::g_mount_guess_content_type_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() { Ok(FromGlibPtrContainer::from_glib_full(ret)) } else { Err(from_glib_full(error)) };
let callback: Box<R> = Box::from_raw(user_data as *mut _);
callback(result);
}
let callback = guess_content_type_trampoline::<R>;
unsafe {
ffi::g_mount_guess_content_type(self.as_ref().to_glib_none().0, force_rescan.to_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _);
}
}
#[cfg(feature = "futures")]
fn guess_content_type_future(&self, force_rescan: bool) -> Box_<futures_core::Future<Item = (Self, Vec<GString>), Error = (Self, Error)>> where Self: Sized + Clone {
use GioFuture;
use fragile::Fragile;
GioFuture::new(self, move |obj, send| {
let cancellable = Cancellable::new();
let send = Fragile::new(send);
let obj_clone = Fragile::new(obj.clone());
obj.guess_content_type(
force_rescan,
Some(&cancellable),
move |res| {
let obj = obj_clone.into_inner();
let res = res.map(|v| (obj.clone(), v)).map_err(|v| (obj.clone(), v));
let _ = send.into_inner().send(res);
},
);
cancellable
})
}
fn guess_content_type_sync<'a, P: IsA<Cancellable> + 'a, Q: Into<Option<&'a P>>>(&self, force_rescan: bool, cancellable: Q) -> Result<Vec<GString>, Error> {
let cancellable = cancellable.into();
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_mount_guess_content_type_sync(self.as_ref().to_glib_none().0, force_rescan.to_glib(), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
if error.is_null() { Ok(FromGlibPtrContainer::from_glib_full(ret)) } else { Err(from_glib_full(error)) }
}
}
fn is_shadowed(&self) -> bool {
unsafe {
from_glib(ffi::g_mount_is_shadowed(self.as_ref().to_glib_none().0))
}
}
fn remount<'a, 'b, P: IsA<MountOperation> + 'a, Q: Into<Option<&'a P>>, R: IsA<Cancellable> + 'b, S: Into<Option<&'b R>>, T: FnOnce(Result<(), Error>) + Send + 'static>(&self, flags: MountMountFlags, mount_operation: Q, cancellable: S, callback: T) {
let mount_operation = mount_operation.into();
let cancellable = cancellable.into();
let user_data: Box<T> = Box::new(callback);
unsafe extern "C" fn remount_trampoline<T: FnOnce(Result<(), Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer) {
let mut error = ptr::null_mut();
let _ = ffi::g_mount_remount_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) };
let callback: Box<T> = Box::from_raw(user_data as *mut _);
callback(result);
}
let callback = remount_trampoline::<T>;
unsafe {
ffi::g_mount_remount(self.as_ref().to_glib_none().0, flags.to_glib(), mount_operation.map(|p| p.as_ref()).to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _);
}
}
#[cfg(feature = "futures")]
fn remount_future<'a, P: IsA<MountOperation> + Clone + 'static, Q: Into<Option<&'a P>>>(&self, flags: MountMountFlags, mount_operation: Q) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone {
use GioFuture;
use fragile::Fragile;
let mount_operation = mount_operation.into();
let mount_operation = mount_operation.map(ToOwned::to_owned);
GioFuture::new(self, move |obj, send| {
let cancellable = Cancellable::new();
let send = Fragile::new(send);
let obj_clone = Fragile::new(obj.clone());
obj.remount(
flags,
mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
Some(&cancellable),
move |res| {
let obj = obj_clone.into_inner();
let res = res.map(|v| (obj.clone(), v)).map_err(|v| (obj.clone(), v));
let _ = send.into_inner().send(res);
},
);
cancellable
})
}
fn shadow(&self) {
unsafe {
ffi::g_mount_shadow(self.as_ref().to_glib_none().0);
}
}
fn unmount_with_operation<'a, 'b, P: IsA<MountOperation> + 'a, Q: Into<Option<&'a P>>, R: IsA<Cancellable> + 'b, S: Into<Option<&'b R>>, T: FnOnce(Result<(), Error>) + Send + 'static>(&self, flags: MountUnmountFlags, mount_operation: Q, cancellable: S, callback: T) {
let mount_operation = mount_operation.into();
let cancellable = cancellable.into();
let user_data: Box<T> = Box::new(callback);
unsafe extern "C" fn unmount_with_operation_trampoline<T: FnOnce(Result<(), Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer) {
let mut error = ptr::null_mut();
let _ = ffi::g_mount_unmount_with_operation_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) };
let callback: Box<T> = Box::from_raw(user_data as *mut _);
callback(result);
}
let callback = unmount_with_operation_trampoline::<T>;
unsafe {
ffi::g_mount_unmount_with_operation(self.as_ref().to_glib_none().0, flags.to_glib(), mount_operation.map(|p| p.as_ref()).to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box::into_raw(user_data) as *mut _);
}
}
#[cfg(feature = "futures")]
fn unmount_with_operation_future<'a, P: IsA<MountOperation> + Clone + 'static, Q: Into<Option<&'a P>>>(&self, flags: MountUnmountFlags, mount_operation: Q) -> Box_<futures_core::Future<Item = (Self, ()), Error = (Self, Error)>> where Self: Sized + Clone {
use GioFuture;
use fragile::Fragile;
let mount_operation = mount_operation.into();
let mount_operation = mount_operation.map(ToOwned::to_owned);
GioFuture::new(self, move |obj, send| {
let cancellable = Cancellable::new();
let send = Fragile::new(send);
let obj_clone = Fragile::new(obj.clone());
obj.unmount_with_operation(
flags,
mount_operation.as_ref().map(::std::borrow::Borrow::borrow),
Some(&cancellable),
move |res| {
let obj = obj_clone.into_inner();
let res = res.map(|v| (obj.clone(), v)).map_err(|v| (obj.clone(), v));
let _ = send.into_inner().send(res);
},
);
cancellable
})
}
fn unshadow(&self) {
unsafe {
ffi::g_mount_unshadow(self.as_ref().to_glib_none().0);
}
}
fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"changed\0".as_ptr() as *const _,
Some(transmute(changed_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_pre_unmount<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"pre-unmount\0".as_ptr() as *const _,
Some(transmute(pre_unmount_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
fn connect_unmounted<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"unmounted\0".as_ptr() as *const _,
Some(transmute(unmounted_trampoline::<Self, F> as usize)), Box_::into_raw(f))
}
}
}
unsafe extern "C" fn changed_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GMount, f: glib_ffi::gpointer)
where P: IsA<Mount> {
let f: &F = transmute(f);
f(&Mount::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn pre_unmount_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GMount, f: glib_ffi::gpointer)
where P: IsA<Mount> {
let f: &F = transmute(f);
f(&Mount::from_glib_borrow(this).unsafe_cast())
}
unsafe extern "C" fn unmounted_trampoline<P, F: Fn(&P) + 'static>(this: *mut ffi::GMount, f: glib_ffi::gpointer)
where P: IsA<Mount> {
let f: &F = transmute(f);
f(&Mount::from_glib_borrow(this).unsafe_cast())
}
impl fmt::Display for Mount {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Mount")
}
}