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

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

glib::wrapper! {
    #[doc(alias = "PpsBookmarks")]
    pub struct Bookmarks(Object<ffi::PpsBookmarks, ffi::PpsBookmarksClass>);

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

impl Bookmarks {
    #[doc(alias = "pps_bookmarks_new")]
    pub fn new(metadata: &Metadata) -> Bookmarks {
        skip_assert_initialized!();
        unsafe { from_glib_full(ffi::pps_bookmarks_new(metadata.to_glib_none().0)) }
    }

    #[doc(alias = "pps_bookmarks_add")]
    pub fn add(&self, bookmark: &mut Bookmark) {
        unsafe {
            ffi::pps_bookmarks_add(self.to_glib_none().0, bookmark.to_glib_none_mut().0);
        }
    }

    #[doc(alias = "pps_bookmarks_delete")]
    pub fn delete(&self, bookmark: &mut Bookmark) {
        unsafe {
            ffi::pps_bookmarks_delete(self.to_glib_none().0, bookmark.to_glib_none_mut().0);
        }
    }

    #[doc(alias = "pps_bookmarks_get_bookmarks")]
    #[doc(alias = "get_bookmarks")]
    pub fn bookmarks(&self) -> Vec<Bookmark> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::pps_bookmarks_get_bookmarks(
                self.to_glib_none().0,
            ))
        }
    }

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

    #[doc(alias = "pps_bookmarks_update")]
    pub fn update(&self, bookmark: &mut Bookmark) {
        unsafe {
            ffi::pps_bookmarks_update(self.to_glib_none().0, bookmark.to_glib_none_mut().0);
        }
    }

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