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 = "ClepsydreIndexMapModel")]
    pub struct IndexMapModel(Object<ffi::ClepsydreIndexMapModel, ffi::ClepsydreIndexMapModelClass>) @implements gio::ListModel;

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

impl IndexMapModel {
    #[doc(alias = "clepsydre_index_map_model_append")]
    pub fn append(&self, uri: &str, item: &impl IsA<glib::Object>) {
        unsafe {
            ffi::clepsydre_index_map_model_append(
                self.to_glib_none().0,
                uri.to_glib_none().0,
                item.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "clepsydre_index_map_model_get")]
    pub fn get(&self, uri: &str) -> Option<glib::Object> {
        unsafe {
            from_glib_none(ffi::clepsydre_index_map_model_get(
                self.to_glib_none().0,
                uri.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "clepsydre_index_map_model_remove_by_uri")]
    pub fn remove_by_uri(&self, uri: &str) {
        unsafe {
            ffi::clepsydre_index_map_model_remove_by_uri(
                self.to_glib_none().0,
                uri.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "n-items")]
    pub fn n_items(&self) -> u32 {
        ObjectExt::property(self, "n-items")
    }

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