polkit 0.19.0

High-level bindings for libpolkit-gobject-1
// Generated by gir (https://github.com/gtk-rs/gir @ 0e476ab5c1de)
// from /usr/share/gir-1.0 (@ ???)
// DO NOT EDIT

use crate::Details;
use glib::translate::*;

glib::wrapper! {
    /// This class represents the result you get when checking for an authorization.
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "PolkitAuthorizationResult")]
    pub struct AuthorizationResult(Object<ffi::PolkitAuthorizationResult, ffi::PolkitAuthorizationResultClass>);

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

impl AuthorizationResult {
    /// Creates a new [`AuthorizationResult`][crate::AuthorizationResult] object.
    /// ## `is_authorized`
    /// Whether the subject is authorized.
    /// ## `is_challenge`
    /// Whether the subject is authorized if more
    /// information is provided. Must be [`false`] unless `is_authorized` is
    /// [`true`].
    /// ## `details`
    /// Must be [`None`] unless `is_authorized` is [`true`]
    ///
    /// # Returns
    ///
    /// A [`AuthorizationResult`][crate::AuthorizationResult] object. Free with `g_object_unref()`.
    #[doc(alias = "polkit_authorization_result_new")]
    pub fn new(
        is_authorized: bool,
        is_challenge: bool,
        details: Option<&Details>,
    ) -> AuthorizationResult {
        unsafe {
            from_glib_full(ffi::polkit_authorization_result_new(
                is_authorized.into_glib(),
                is_challenge.into_glib(),
                details.to_glib_none().0,
            ))
        }
    }

    /// Gets the details about the result.
    ///
    /// # Returns
    ///
    /// A [`Details`][crate::Details] object or
    /// [`None`] if there are no details. This object is owned by `self` and
    /// should not be freed by the caller.
    #[doc(alias = "polkit_authorization_result_get_details")]
    #[doc(alias = "get_details")]
    pub fn details(&self) -> Option<Details> {
        unsafe {
            from_glib_none(ffi::polkit_authorization_result_get_details(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets whether the authentication request was dismissed / canceled by the user.
    ///
    /// This method simply reads the value of the key/value pair in `details` with the
    /// key `<literal>`polkit.dismissed`</literal>`.
    ///
    /// # Returns
    ///
    /// [`true`] if the authentication request was dismissed, [`false`] otherwise.
    #[cfg(feature = "v0_101")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_101")))]
    #[doc(alias = "polkit_authorization_result_get_dismissed")]
    #[doc(alias = "get_dismissed")]
    pub fn is_dismissed(&self) -> bool {
        unsafe {
            from_glib(ffi::polkit_authorization_result_get_dismissed(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets whether the subject is authorized.
    ///
    /// If the authorization is temporary, use [`temporary_authorization_id()`][Self::temporary_authorization_id()]
    /// to get the opaque identifier for the temporary authorization.
    ///
    /// # Returns
    ///
    /// Whether the subject is authorized.
    #[doc(alias = "polkit_authorization_result_get_is_authorized")]
    #[doc(alias = "get_is_authorized")]
    pub fn is_authorized(&self) -> bool {
        unsafe {
            from_glib(ffi::polkit_authorization_result_get_is_authorized(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets whether the subject is authorized if more information is provided.
    ///
    /// # Returns
    ///
    /// Whether the subject is authorized if more information is provided.
    #[doc(alias = "polkit_authorization_result_get_is_challenge")]
    #[doc(alias = "get_is_challenge")]
    pub fn is_challenge(&self) -> bool {
        unsafe {
            from_glib(ffi::polkit_authorization_result_get_is_challenge(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets whether authorization is retained if obtained via authentication. This can only be the case
    /// if `self` indicates that the subject can obtain authorization after challenge (cf.
    /// [`is_challenge()`][Self::is_challenge()]), e.g. when the subject is not already authorized (cf.
    /// [`is_authorized()`][Self::is_authorized()]).
    ///
    /// If the subject is already authorized, use [`temporary_authorization_id()`][Self::temporary_authorization_id()]
    /// to check if the authorization is temporary.
    ///
    /// This method simply reads the value of the key/value pair in `details` with the
    /// key `<literal>`polkit.retains_authorization_after_challenge`</literal>`.
    ///
    /// # Returns
    ///
    /// [`true`] if the authorization is or will be temporary.
    #[doc(alias = "polkit_authorization_result_get_retains_authorization")]
    #[doc(alias = "get_retains_authorization")]
    pub fn is_retains_authorization(&self) -> bool {
        unsafe {
            from_glib(ffi::polkit_authorization_result_get_retains_authorization(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the opaque temporary authorization id for `self` if `self` indicates the
    /// subject is authorized and the authorization is temporary rather than one-shot or
    /// permanent.
    ///
    /// You can use this string together with the result from
    /// [`Authority::enumerate_temporary_authorizations()`][crate::Authority::enumerate_temporary_authorizations()] to get more details
    /// about the temporary authorization or [`Authority::revoke_temporary_authorization_by_id()`][crate::Authority::revoke_temporary_authorization_by_id()]
    /// to revoke the temporary authorization.
    ///
    /// If the subject is not authorized, use [`is_retains_authorization()`][Self::is_retains_authorization()]
    /// to check if the authorization will be retained if obtained via authentication.
    ///
    /// This method simply reads the value of the key/value pair in `details` with the
    /// key `<literal>`polkit.temporary_authorization_id`</literal>`.
    ///
    /// # Returns
    ///
    /// The opaque temporary authorization id for
    ///  `self` or [`None`] if not available. Do not free this string, it
    ///  is owned by `self`.
    #[doc(alias = "polkit_authorization_result_get_temporary_authorization_id")]
    #[doc(alias = "get_temporary_authorization_id")]
    pub fn temporary_authorization_id(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(
                ffi::polkit_authorization_result_get_temporary_authorization_id(
                    self.to_glib_none().0,
                ),
            )
        }
    }
}