libflatpak 0.7.0

libflatpak bindings
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::ffi;
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "FlatpakTransactionProgress")]
    pub struct TransactionProgress(Object<ffi::FlatpakTransactionProgress, ffi::FlatpakTransactionProgressClass>);

    match fn {
        type_ => || ffi::flatpak_transaction_progress_get_type(),
    }
}

impl TransactionProgress {
    #[cfg(feature = "v1_1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1_2")))]
    #[doc(alias = "flatpak_transaction_progress_get_bytes_transferred")]
    #[doc(alias = "get_bytes_transferred")]
    pub fn bytes_transferred(&self) -> u64 {
        unsafe { ffi::flatpak_transaction_progress_get_bytes_transferred(self.to_glib_none().0) }
    }

    #[doc(alias = "flatpak_transaction_progress_get_is_estimating")]
    #[doc(alias = "get_is_estimating")]
    pub fn is_estimating(&self) -> bool {
        unsafe {
            from_glib(ffi::flatpak_transaction_progress_get_is_estimating(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "flatpak_transaction_progress_get_progress")]
    #[doc(alias = "get_progress")]
    pub fn progress(&self) -> i32 {
        unsafe { ffi::flatpak_transaction_progress_get_progress(self.to_glib_none().0) }
    }

    #[cfg(feature = "v1_1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1_2")))]
    #[doc(alias = "flatpak_transaction_progress_get_start_time")]
    #[doc(alias = "get_start_time")]
    pub fn start_time(&self) -> u64 {
        unsafe { ffi::flatpak_transaction_progress_get_start_time(self.to_glib_none().0) }
    }

    #[doc(alias = "flatpak_transaction_progress_get_status")]
    #[doc(alias = "get_status")]
    pub fn status(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::flatpak_transaction_progress_get_status(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "flatpak_transaction_progress_set_update_frequency")]
    pub fn set_update_frequency(&self, update_interval: u32) {
        unsafe {
            ffi::flatpak_transaction_progress_set_update_frequency(
                self.to_glib_none().0,
                update_interval,
            );
        }
    }

    #[doc(alias = "changed")]
    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn changed_trampoline<F: Fn(&TransactionProgress) + 'static>(
            this: *mut ffi::FlatpakTransactionProgress,
            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 _,
                c"changed".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    changed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}