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

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

glib::wrapper! {
    ///
    ///
    /// ## Properties
    ///
    ///
    /// #### `name`
    ///  Readable | Writeable | Construct Only
    ///
    /// ## Signals
    ///
    ///
    /// #### `shortcut-added`
    ///  Action
    ///
    ///
    /// #### `shortcut-removed`
    ///  Action
    ///
    /// # Implements
    ///
    /// [`ShortcutsProviderExt`][trait@crate::prelude::ShortcutsProviderExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "XfceShortcutsProvider")]
    pub struct ShortcutsProvider(Object<ffi::XfceShortcutsProvider, ffi::XfceShortcutsProviderClass>);

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

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

    ///
    /// # Returns
    ///
    /// A new [`ShortcutsProvider`][crate::ShortcutsProvider], which should be
    /// freed with `g_object_unref()` when no longer needed.
    #[doc(alias = "xfce_shortcuts_provider_new")]
    pub fn new(name: &str) -> ShortcutsProvider {
        unsafe { from_glib_full(ffi::xfce_shortcuts_provider_new(name.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// A `GList` of
    /// [`ShortcutsProvider`][crate::ShortcutsProvider] items, which should be freed with
    /// `xfce_shortcuts_provider_free_providers()` when no longer needed.
    #[doc(alias = "xfce_shortcuts_provider_get_providers")]
    #[doc(alias = "get_providers")]
    pub fn providers() -> Vec<ShortcutsProvider> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::xfce_shortcuts_provider_get_providers())
        }
    }
}

impl std::fmt::Display for ShortcutsProvider {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(&ShortcutsProviderExt::name(self))
    }
}

/// Trait containing all [`struct@ShortcutsProvider`] methods.
///
/// # Implementors
///
/// [`ShortcutsProvider`][struct@crate::ShortcutsProvider]
pub trait ShortcutsProviderExt: IsA<ShortcutsProvider> + 'static {
    #[doc(alias = "xfce_shortcuts_provider_clone_defaults")]
    fn clone_defaults(&self) {
        unsafe {
            ffi::xfce_shortcuts_provider_clone_defaults(self.as_ref().to_glib_none().0);
        }
    }

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

    ///
    /// # Returns
    ///
    /// A newly-allocated [`Shortcut`][crate::Shortcut], which
    /// should be freed with `xfce_shortcut_free()` when no longer needed.
    #[doc(alias = "xfce_shortcuts_provider_get_shortcut")]
    #[doc(alias = "get_shortcut")]
    fn shortcut(&self, shortcut: &str) -> Option<Shortcut> {
        unsafe {
            from_glib_full(ffi::xfce_shortcuts_provider_get_shortcut(
                self.as_ref().to_glib_none().0,
                shortcut.to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// A `GList` of
    /// [`Shortcut`][crate::Shortcut] items, which should be freed with `xfce_shortcuts_free()` when
    /// no longer needed.
    #[doc(alias = "xfce_shortcuts_provider_get_shortcuts")]
    #[doc(alias = "get_shortcuts")]
    fn shortcuts(&self) -> Vec<Shortcut> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::xfce_shortcuts_provider_get_shortcuts(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

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

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

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

    #[doc(alias = "xfce_shortcuts_provider_reset_to_defaults")]
    fn reset_to_defaults(&self) {
        unsafe {
            ffi::xfce_shortcuts_provider_reset_to_defaults(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "xfce_shortcuts_provider_set_shortcut")]
    fn set_shortcut(&self, shortcut: &str, command: &str, snotify: bool) {
        unsafe {
            ffi::xfce_shortcuts_provider_set_shortcut(
                self.as_ref().to_glib_none().0,
                shortcut.to_glib_none().0,
                command.to_glib_none().0,
                snotify.into_glib(),
            );
        }
    }

    #[cfg(not(feature = "v4_21_4"))]
    #[cfg_attr(docsrs, doc(cfg(not(feature = "v4_21_4"))))]
    fn name(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "name")
    }

    #[doc(alias = "shortcut-added")]
    fn connect_shortcut_added<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn shortcut_added_trampoline<
            P: IsA<ShortcutsProvider>,
            F: Fn(&P, &str) + 'static,
        >(
            this: *mut ffi::XfceShortcutsProvider,
            object: *mut std::ffi::c_char,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    ShortcutsProvider::from_glib_borrow(this).unsafe_cast_ref(),
                    &glib::GString::from_glib_borrow(object),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"shortcut-added".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    shortcut_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn emit_shortcut_added(&self, object: &str) {
        self.emit_by_name::<()>("shortcut-added", &[&object]);
    }

    #[doc(alias = "shortcut-removed")]
    fn connect_shortcut_removed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn shortcut_removed_trampoline<
            P: IsA<ShortcutsProvider>,
            F: Fn(&P, &str) + 'static,
        >(
            this: *mut ffi::XfceShortcutsProvider,
            object: *mut std::ffi::c_char,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    ShortcutsProvider::from_glib_borrow(this).unsafe_cast_ref(),
                    &glib::GString::from_glib_borrow(object),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"shortcut-removed".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    shortcut_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn emit_shortcut_removed(&self, object: &str) {
        self.emit_by_name::<()>("shortcut-removed", &[&object]);
    }
}

impl<O: IsA<ShortcutsProvider>> ShortcutsProviderExt for O {}
