use crate::{ffi, MainChannel};
use glib::{
object::ObjectType as _,
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "SpiceFileTransferTask")]
pub struct FileTransferTask(Object<ffi::SpiceFileTransferTask, ffi::SpiceFileTransferTaskClass>);
match fn {
type_ => || ffi::spice_file_transfer_task_get_type(),
}
}
impl FileTransferTask {
#[doc(alias = "spice_file_transfer_task_cancel")]
pub fn cancel(&self) {
unsafe {
ffi::spice_file_transfer_task_cancel(self.to_glib_none().0);
}
}
#[doc(alias = "spice_file_transfer_task_get_filename")]
#[doc(alias = "get_filename")]
pub fn filename(&self) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::spice_file_transfer_task_get_filename(
self.to_glib_none().0,
))
}
}
#[doc(alias = "spice_file_transfer_task_get_progress")]
#[doc(alias = "get_progress")]
pub fn progress(&self) -> f64 {
unsafe { ffi::spice_file_transfer_task_get_progress(self.to_glib_none().0) }
}
#[doc(alias = "spice_file_transfer_task_get_total_bytes")]
#[doc(alias = "get_total_bytes")]
#[doc(alias = "total-bytes")]
pub fn total_bytes(&self) -> u64 {
unsafe { ffi::spice_file_transfer_task_get_total_bytes(self.to_glib_none().0) }
}
#[doc(alias = "spice_file_transfer_task_get_transferred_bytes")]
#[doc(alias = "get_transferred_bytes")]
#[doc(alias = "transferred-bytes")]
pub fn transferred_bytes(&self) -> u64 {
unsafe { ffi::spice_file_transfer_task_get_transferred_bytes(self.to_glib_none().0) }
}
pub fn cancellable(&self) -> Option<gio::Cancellable> {
ObjectExt::property(self, "cancellable")
}
pub fn channel(&self) -> Option<MainChannel> {
ObjectExt::property(self, "channel")
}
pub fn file(&self) -> Option<gio::File> {
ObjectExt::property(self, "file")
}
pub fn id(&self) -> u32 {
ObjectExt::property(self, "id")
}
#[doc(alias = "finished")]
pub fn connect_finished<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn finished_trampoline<
F: Fn(&FileTransferTask, &glib::Error) + 'static,
>(
this: *mut ffi::SpiceFileTransferTask,
object: *mut glib::ffi::GError,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(object))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"finished".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
finished_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "progress")]
pub fn connect_progress_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_progress_trampoline<F: Fn(&FileTransferTask) + 'static>(
this: *mut ffi::SpiceFileTransferTask,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::progress".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_progress_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "total-bytes")]
pub fn connect_total_bytes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_total_bytes_trampoline<F: Fn(&FileTransferTask) + 'static>(
this: *mut ffi::SpiceFileTransferTask,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::total-bytes".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_total_bytes_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "transferred-bytes")]
pub fn connect_transferred_bytes_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_transferred_bytes_trampoline<
F: Fn(&FileTransferTask) + 'static,
>(
this: *mut ffi::SpiceFileTransferTask,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::transferred-bytes".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_transferred_bytes_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}