use std::boxed::Box;
use glib::{
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use crate::{CalendarCreationFlows, Collection, auto::traits::CollectionExt as _, ffi};
pub trait CollectionExtManual: IsA<Collection> + 'static {
#[doc(alias = "calendar-creation-flows")]
fn parsed_calendar_creation_flows(&self) -> Result<CalendarCreationFlows, serde_json::Error> {
serde_json::from_str(
self.calendar_creation_flows()
.as_deref()
.unwrap_or(r#"{"flows":[]}"#),
)
}
#[doc(alias = "name")]
fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_name_trampoline<P: IsA<Collection>, F: Fn(&P) + 'static>(
this: *mut ffi::ClepsydreCollection,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(Collection::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 = "calendar-creation-enabled")]
fn connect_calendar_creation_enabled_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_calendar_creation_enabled_trampoline<
P: IsA<Collection>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::ClepsydreCollection,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(Collection::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box<F> = Box::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::calendar-creation-enabled".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_calendar_creation_enabled_trampoline::<Self, F> as *const (),
)),
Box::into_raw(f),
)
}
}
#[doc(alias = "calendar-creation-flows")]
fn connect_calendar_creation_flows_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_calendar_creation_flows_trampoline<
P: IsA<Collection>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::ClepsydreCollection,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(Collection::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box<F> = Box::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::calendar-creation-flows".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_calendar_creation_flows_trampoline::<Self, F> as *const (),
)),
Box::into_raw(f),
)
}
}
}
impl<T: IsA<Collection>> CollectionExtManual for T {}