libappstream 0.4.0

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

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

glib::wrapper! {
    #[doc(alias = "AsCategory")]
    pub struct Category(Object<ffi::AsCategory, ffi::AsCategoryClass>);

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

impl Category {
    pub const NONE: Option<&'static Category> = None;

    #[doc(alias = "as_category_new")]
    pub fn new() -> Category {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::as_category_new()) }
    }
}

impl Default for Category {
    fn default() -> Self {
        Self::new()
    }
}

pub trait CategoryExt: IsA<Category> + 'static {
    #[doc(alias = "as_category_add_child")]
    fn add_child(&self, subcat: &impl IsA<Category>) {
        unsafe {
            ffi::as_category_add_child(
                self.as_ref().to_glib_none().0,
                subcat.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "as_category_add_component")]
    fn add_component(&self, cpt: &impl IsA<Component>) {
        unsafe {
            ffi::as_category_add_component(
                self.as_ref().to_glib_none().0,
                cpt.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "as_category_add_desktop_group")]
    fn add_desktop_group(&self, group_name: &str) {
        unsafe {
            ffi::as_category_add_desktop_group(
                self.as_ref().to_glib_none().0,
                group_name.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "as_category_get_children")]
    #[doc(alias = "get_children")]
    fn children(&self) -> Vec<Category> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::as_category_get_children(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_category_get_components")]
    #[doc(alias = "get_components")]
    fn components(&self) -> Vec<Component> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::as_category_get_components(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_category_get_desktop_groups")]
    #[doc(alias = "get_desktop_groups")]
    fn desktop_groups(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::as_category_get_desktop_groups(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_category_get_icon")]
    #[doc(alias = "get_icon")]
    fn icon(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_category_get_icon(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "as_category_get_id")]
    #[doc(alias = "get_id")]
    fn id(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_category_get_id(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "as_category_get_name")]
    #[doc(alias = "get_name")]
    fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_category_get_name(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "as_category_get_summary")]
    #[doc(alias = "get_summary")]
    fn summary(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::as_category_get_summary(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "as_category_has_children")]
    fn has_children(&self) -> bool {
        unsafe {
            from_glib(ffi::as_category_has_children(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_category_has_component")]
    fn has_component(&self, cpt: &impl IsA<Component>) -> bool {
        unsafe {
            from_glib(ffi::as_category_has_component(
                self.as_ref().to_glib_none().0,
                cpt.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "as_category_remove_child")]
    fn remove_child(&self, subcat: &impl IsA<Category>) {
        unsafe {
            ffi::as_category_remove_child(
                self.as_ref().to_glib_none().0,
                subcat.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "as_category_set_icon")]
    #[doc(alias = "icon")]
    fn set_icon(&self, value: &str) {
        unsafe {
            ffi::as_category_set_icon(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    #[doc(alias = "as_category_set_id")]
    #[doc(alias = "id")]
    fn set_id(&self, id: &str) {
        unsafe {
            ffi::as_category_set_id(self.as_ref().to_glib_none().0, id.to_glib_none().0);
        }
    }

    #[doc(alias = "as_category_set_name")]
    #[doc(alias = "name")]
    fn set_name(&self, value: &str) {
        unsafe {
            ffi::as_category_set_name(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    #[doc(alias = "as_category_set_summary")]
    fn set_summary(&self, value: &str) {
        unsafe {
            ffi::as_category_set_summary(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

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

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

    #[doc(alias = "id")]
    fn connect_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_id_trampoline<P: IsA<Category>, F: Fn(&P) + 'static>(
            this: *mut ffi::AsCategory,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Category::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::id".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_id_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<Category>, F: Fn(&P) + 'static>(
            this: *mut ffi::AsCategory,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Category::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() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

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

impl<O: IsA<Category>> CategoryExt for O {}