xfce4-util 0.1.0

Xfce utility library
// 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 = "XfceSystemd")]
    pub struct Systemd(Object<ffi::XfceSystemd, ffi::XfceSystemdClass>);

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

impl Systemd {
    /// Ask systemd 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_systemd_hibernate")]
    pub fn hibernate(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_systemd_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 systemd 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_systemd_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_systemd_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 systemd 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_systemd_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_systemd_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 systemd 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_systemd_reboot")]
    pub fn reboot(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_systemd_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 systemd 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_systemd_suspend")]
    pub fn suspend(&self, polkit_interactive: bool) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::xfce_systemd_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 [`Systemd`][crate::Systemd] instance or increase reference count.
    ///
    /// # Returns
    ///
    /// A reference to the singleton object, to be released with `g_object_unref()`.
    #[doc(alias = "xfce_systemd_get")]
    pub fn get() -> Systemd {
        unsafe { from_glib_full(ffi::xfce_systemd_get()) }
    }
}