clepsydre-rebind 0.1.0

Safe bindings for libclepsydre
use crate::{Event, ffi};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box;

pub trait EventExtManual: IsA<Event> + 'static {
    #[doc(alias = "attendees")]
    fn connect_attendees_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_attendees_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::attendees".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_attendees_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "conference")]
    fn connect_conference_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_conference_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::conference".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_conference_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "description")]
    fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_description_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::description".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_description_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "editable")]
    fn connect_editable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_editable_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::editable".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_editable_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "has-recurrence")]
    fn connect_has_recurrence_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_has_recurrence_trampoline<
            P: IsA<Event>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::has-recurrence".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_has_recurrence_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "location")]
    fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_location_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::location".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_location_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "name")]
    fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_name_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::name".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "organizer")]
    fn connect_organizer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_organizer_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::organizer".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_organizer_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "removable")]
    fn connect_removable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_removable_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::removable".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_removable_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }

    #[doc(alias = "timeframe")]
    fn connect_timeframe_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_timeframe_trampoline<P: IsA<Event>, F: Fn(&P) + 'static>(
            this: *mut ffi::ClepsydreEvent,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(Event::from_glib_borrow(this).unsafe_cast_ref())
            }
        }
        unsafe {
            let f: Box<F> = Box::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::timeframe".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_timeframe_trampoline::<Self, F> as *const (),
                )),
                Box::into_raw(f),
            )
        }
    }
}

impl<T: IsA<Event>> EventExtManual for T {}