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

use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute, ptr};

glib::wrapper! {
    #[doc(alias = "GnomeXkbInfo")]
    pub struct XkbInfo(Object<ffi::GnomeXkbInfo, ffi::GnomeXkbInfoClass>);

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

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

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

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

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::XkbInfo>> Sealed for T {}
}

pub trait XkbInfoExt: IsA<XkbInfo> + sealed::Sealed + 'static {
    #[doc(alias = "gnome_xkb_info_description_for_group")]
    fn description_for_group(&self, group_id: &str) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gnome_xkb_info_description_for_group(
                self.as_ref().to_glib_none().0,
                group_id.to_glib_none().0,
            ))
        }
    }

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

    #[doc(alias = "gnome_xkb_info_get_all_layouts")]
    #[doc(alias = "get_all_layouts")]
    fn all_layouts(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gnome_xkb_info_get_all_layouts(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_xkb_info_get_all_option_groups")]
    #[doc(alias = "get_all_option_groups")]
    fn all_option_groups(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gnome_xkb_info_get_all_option_groups(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_xkb_info_get_languages_for_layout")]
    #[doc(alias = "get_languages_for_layout")]
    fn languages_for_layout(&self, layout_id: &str) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gnome_xkb_info_get_languages_for_layout(
                self.as_ref().to_glib_none().0,
                layout_id.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_xkb_info_get_layout_info")]
    #[doc(alias = "get_layout_info")]
    fn layout_info(
        &self,
        id: &str,
    ) -> Option<(
        Option<glib::GString>,
        Option<glib::GString>,
        Option<glib::GString>,
        Option<glib::GString>,
    )> {
        unsafe {
            let mut display_name = ptr::null();
            let mut short_name = ptr::null();
            let mut xkb_layout = ptr::null();
            let mut xkb_variant = ptr::null();
            let ret = from_glib(ffi::gnome_xkb_info_get_layout_info(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                &mut display_name,
                &mut short_name,
                &mut xkb_layout,
                &mut xkb_variant,
            ));
            if ret {
                Some((
                    from_glib_none(display_name),
                    from_glib_none(short_name),
                    from_glib_none(xkb_layout),
                    from_glib_none(xkb_variant),
                ))
            } else {
                None
            }
        }
    }

    #[doc(alias = "gnome_xkb_info_get_layouts_for_country")]
    #[doc(alias = "get_layouts_for_country")]
    fn layouts_for_country(&self, country_code: &str) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gnome_xkb_info_get_layouts_for_country(
                self.as_ref().to_glib_none().0,
                country_code.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_xkb_info_get_layouts_for_language")]
    #[doc(alias = "get_layouts_for_language")]
    fn layouts_for_language(&self, language_code: &str) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gnome_xkb_info_get_layouts_for_language(
                self.as_ref().to_glib_none().0,
                language_code.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_xkb_info_get_options_for_group")]
    #[doc(alias = "get_options_for_group")]
    fn options_for_group(&self, group_id: &str) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gnome_xkb_info_get_options_for_group(
                self.as_ref().to_glib_none().0,
                group_id.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "layouts-changed")]
    fn connect_layouts_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn layouts_changed_trampoline<P: IsA<XkbInfo>, F: Fn(&P) + 'static>(
            this: *mut ffi::GnomeXkbInfo,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(XkbInfo::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"layouts-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    layouts_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<XkbInfo>> XkbInfoExt for O {}

impl fmt::Display for XkbInfo {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("XkbInfo")
    }
}
