// 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::ffi;
use glib::translate::*;

glib::wrapper! {
    ///
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "XfceConsolekit")]
    pub struct Consolekit(Object<ffi::XfceConsolekit, ffi::XfceConsolekitClass>);

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

impl Consolekit {
    /// Ask ConsoleKit to trigger Hibernate.
    /// ## `polkit_interactive`
    /// whether PolicyKit should ask the user to authenticate if needed
    ///
    /// # Returns
    ///
    /// [`true`] if the D-Bus request was successful, [`false`] otherwise and `error` is set.
    #[doc(alias = "xfce_consolekit_hibernate")]
    pub fn hibernate(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_consolekit_hibernate(
                self.to_glib_none().0,
                polkit_interactive.into_glib(),
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Ask ConsoleKit to trigger HybridSleep.
    /// ## `polkit_interactive`
    /// whether PolicyKit should ask the user to authenticate if needed
    ///
    /// # Returns
    ///
    /// [`true`] if the D-Bus request was successful, [`false`] otherwise and `error` is set.
    #[doc(alias = "xfce_consolekit_hybrid_sleep")]
    pub fn hybrid_sleep(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_consolekit_hybrid_sleep(
                self.to_glib_none().0,
                polkit_interactive.into_glib(),
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Ask ConsoleKit to trigger PowerOff.
    /// ## `polkit_interactive`
    /// whether PolicyKit should ask the user to authenticate if needed
    ///
    /// # Returns
    ///
    /// [`true`] if the D-Bus request was successful, [`false`] otherwise and `error` is set.
    #[doc(alias = "xfce_consolekit_power_off")]
    pub fn power_off(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_consolekit_power_off(
                self.to_glib_none().0,
                polkit_interactive.into_glib(),
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Ask ConsoleKit to trigger Reboot.
    /// ## `polkit_interactive`
    /// whether PolicyKit should ask the user to authenticate if needed
    ///
    /// # Returns
    ///
    /// [`true`] if the D-Bus request was successful, [`false`] otherwise and `error` is set.
    #[doc(alias = "xfce_consolekit_reboot")]
    pub fn reboot(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_consolekit_reboot(
                self.to_glib_none().0,
                polkit_interactive.into_glib(),
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Ask ConsoleKit to trigger Suspend.
    /// ## `polkit_interactive`
    /// whether PolicyKit should ask the user to authenticate if needed
    ///
    /// # Returns
    ///
    /// [`true`] if the D-Bus request was successful, [`false`] otherwise and `error` is set.
    #[doc(alias = "xfce_consolekit_suspend")]
    pub fn suspend(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_consolekit_suspend(
                self.to_glib_none().0,
                polkit_interactive.into_glib(),
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Create a new [`Consolekit`][crate::Consolekit] instance or increase reference count.
    ///
    /// # Returns
    ///
    /// A reference to the singleton object, to be released with `g_object_unref()`.
    #[doc(alias = "xfce_consolekit_get")]
    pub fn get() -> Consolekit {
        unsafe { from_glib_full(ffi::xfce_consolekit_get()) }
    }
}
