spice-client-glib 0.1.0

Rust bindings for the Spice client library
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::MainChannel;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

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")]
    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")]
    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> {
        unsafe {
            let mut value = glib::Value::from_type(<gio::Cancellable as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"cancellable\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `cancellable` getter")
        }
    }

    pub fn channel(&self) -> Option<MainChannel> {
        unsafe {
            let mut value = glib::Value::from_type(<MainChannel as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"channel\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `channel` getter")
        }
    }

    pub fn file(&self) -> Option<gio::File> {
        unsafe {
            let mut value = glib::Value::from_type(<gio::File as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"file\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `file` getter")
        }
    }

    pub fn id(&self) -> u32 {
        unsafe {
            let mut value = glib::Value::from_type(<u32 as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.as_ptr() as *mut glib::gobject_ffi::GObject,
                b"id\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value.get().expect("Return Value for property `id` getter")
        }
    }

    #[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,
        ) {
            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 _,
                b"finished\0".as_ptr() as *const _,
                Some(transmute::<_, 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,
        ) {
            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 _,
                b"notify::progress\0".as_ptr() as *const _,
                Some(transmute::<_, 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,
        ) {
            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 _,
                b"notify::total-bytes\0".as_ptr() as *const _,
                Some(transmute::<_, 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,
        ) {
            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 _,
                b"notify::transferred-bytes\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_transferred_bytes_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for FileTransferTask {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("FileTransferTask")
    }
}