clepsydre-rebind 0.1.0

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

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

glib::wrapper! {
    #[doc(alias = "ClepsydreTimeframe")]
    pub struct Timeframe(Object<ffi::ClepsydreTimeframe, ffi::ClepsydreTimeframeClass>);

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

impl Timeframe {
    #[doc(alias = "clepsydre_timeframe_new")]
    pub fn new(
        all_day: bool,
        start: &glib::DateTime,
        end: &glib::DateTime,
    ) -> Result<Timeframe, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::clepsydre_timeframe_new(
                all_day.into_glib(),
                start.to_glib_none().0,
                end.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "clepsydre_timeframe_equal")]
    pub fn equal(&self, timeframe2: &Timeframe) -> bool {
        unsafe {
            from_glib(ffi::clepsydre_timeframe_equal(
                self.to_glib_none().0,
                timeframe2.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "clepsydre_timeframe_get_all_day")]
    #[doc(alias = "get_all_day")]
    #[doc(alias = "all-day")]
    pub fn is_all_day(&self) -> bool {
        unsafe { from_glib(ffi::clepsydre_timeframe_get_all_day(self.to_glib_none().0)) }
    }

    #[doc(alias = "clepsydre_timeframe_get_end")]
    #[doc(alias = "get_end")]
    pub fn end(&self) -> Option<glib::DateTime> {
        unsafe { from_glib_full(ffi::clepsydre_timeframe_get_end(self.to_glib_none().0)) }
    }

    #[doc(alias = "clepsydre_timeframe_get_end_unix")]
    #[doc(alias = "get_end_unix")]
    pub fn end_unix(&self) -> i64 {
        unsafe { ffi::clepsydre_timeframe_get_end_unix(self.to_glib_none().0) }
    }

    #[doc(alias = "clepsydre_timeframe_get_start")]
    #[doc(alias = "get_start")]
    pub fn start(&self) -> Option<glib::DateTime> {
        unsafe { from_glib_full(ffi::clepsydre_timeframe_get_start(self.to_glib_none().0)) }
    }

    #[doc(alias = "clepsydre_timeframe_get_start_unix")]
    #[doc(alias = "get_start_unix")]
    pub fn start_unix(&self) -> i64 {
        unsafe { ffi::clepsydre_timeframe_get_start_unix(self.to_glib_none().0) }
    }

    pub fn representation(&self) -> Option<glib::GString> {
        ObjectExt::property(self, "representation")
    }

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