{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

A 'GI.Gio.Objects.Permission.Permission' represents the status of the caller\'s permission to
perform a certain action.

You can query if the action is currently allowed and if it is
possible to acquire the permission so that the action will be allowed
in the future.

There is also an API to actually acquire the permission and one to
release it.

As an example, a 'GI.Gio.Objects.Permission.Permission' might represent the ability for the
user to write to a 'GI.Gio.Objects.Settings.Settings' object.  This 'GI.Gio.Objects.Permission.Permission' object could
then be used to decide if it is appropriate to show a \"Click here to
unlock\" button in a dialog and to provide the mechanism to invoke
when that button is clicked.
-}

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Gio.Objects.Permission
    ( 

-- * Exported types
    Permission(..)                          ,
    IsPermission                            ,
    toPermission                            ,
    noPermission                            ,


 -- * Methods
-- ** acquire #method:acquire#

#if ENABLE_OVERLOADING
    PermissionAcquireMethodInfo             ,
#endif
    permissionAcquire                       ,


-- ** acquireAsync #method:acquireAsync#

#if ENABLE_OVERLOADING
    PermissionAcquireAsyncMethodInfo        ,
#endif
    permissionAcquireAsync                  ,


-- ** acquireFinish #method:acquireFinish#

#if ENABLE_OVERLOADING
    PermissionAcquireFinishMethodInfo       ,
#endif
    permissionAcquireFinish                 ,


-- ** getAllowed #method:getAllowed#

#if ENABLE_OVERLOADING
    PermissionGetAllowedMethodInfo          ,
#endif
    permissionGetAllowed                    ,


-- ** getCanAcquire #method:getCanAcquire#

#if ENABLE_OVERLOADING
    PermissionGetCanAcquireMethodInfo       ,
#endif
    permissionGetCanAcquire                 ,


-- ** getCanRelease #method:getCanRelease#

#if ENABLE_OVERLOADING
    PermissionGetCanReleaseMethodInfo       ,
#endif
    permissionGetCanRelease                 ,


-- ** implUpdate #method:implUpdate#

#if ENABLE_OVERLOADING
    PermissionImplUpdateMethodInfo          ,
#endif
    permissionImplUpdate                    ,


-- ** release #method:release#

#if ENABLE_OVERLOADING
    PermissionReleaseMethodInfo             ,
#endif
    permissionRelease                       ,


-- ** releaseAsync #method:releaseAsync#

#if ENABLE_OVERLOADING
    PermissionReleaseAsyncMethodInfo        ,
#endif
    permissionReleaseAsync                  ,


-- ** releaseFinish #method:releaseFinish#

#if ENABLE_OVERLOADING
    PermissionReleaseFinishMethodInfo       ,
#endif
    permissionReleaseFinish                 ,




 -- * Properties
-- ** allowed #attr:allowed#
{- | 'True' if the caller currently has permission to perform the action that
/@permission@/ represents the permission to perform.
-}
#if ENABLE_OVERLOADING
    PermissionAllowedPropertyInfo           ,
#endif
    getPermissionAllowed                    ,
#if ENABLE_OVERLOADING
    permissionAllowed                       ,
#endif


-- ** canAcquire #attr:canAcquire#
{- | 'True' if it is generally possible to acquire the permission by calling
'GI.Gio.Objects.Permission.permissionAcquire'.
-}
#if ENABLE_OVERLOADING
    PermissionCanAcquirePropertyInfo        ,
#endif
    getPermissionCanAcquire                 ,
#if ENABLE_OVERLOADING
    permissionCanAcquire                    ,
#endif


-- ** canRelease #attr:canRelease#
{- | 'True' if it is generally possible to release the permission by calling
'GI.Gio.Objects.Permission.permissionRelease'.
-}
#if ENABLE_OVERLOADING
    PermissionCanReleasePropertyInfo        ,
#endif
    getPermissionCanRelease                 ,
#if ENABLE_OVERLOADING
    permissionCanRelease                    ,
#endif




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import {-# SOURCE #-} qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

-- | Memory-managed wrapper type.
newtype Permission = Permission (ManagedPtr Permission)
foreign import ccall "g_permission_get_type"
    c_g_permission_get_type :: IO GType

instance GObject Permission where
    gobjectType :: Permission -> IO GType
gobjectType _ = IO GType
c_g_permission_get_type
    

-- | Type class for types which can be safely cast to `Permission`, for instance with `toPermission`.
class GObject o => IsPermission o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Permission a) =>
    IsPermission a
#endif
instance IsPermission Permission
instance GObject.Object.IsObject Permission

-- | Cast to `Permission`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toPermission :: (MonadIO m, IsPermission o) => o -> m Permission
toPermission :: o -> m Permission
toPermission = IO Permission -> m Permission
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Permission -> m Permission)
-> (o -> IO Permission) -> o -> m Permission
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Permission -> Permission) -> o -> IO Permission
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Permission -> Permission
Permission

-- | A convenience alias for `Nothing` :: `Maybe` `Permission`.
noPermission :: Maybe Permission
noPermission :: Maybe Permission
noPermission = Maybe Permission
forall a. Maybe a
Nothing

#if ENABLE_OVERLOADING
type family ResolvePermissionMethod (t :: Symbol) (o :: *) :: * where
    ResolvePermissionMethod "acquire" o = PermissionAcquireMethodInfo
    ResolvePermissionMethod "acquireAsync" o = PermissionAcquireAsyncMethodInfo
    ResolvePermissionMethod "acquireFinish" o = PermissionAcquireFinishMethodInfo
    ResolvePermissionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePermissionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePermissionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePermissionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePermissionMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolvePermissionMethod "implUpdate" o = PermissionImplUpdateMethodInfo
    ResolvePermissionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePermissionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePermissionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePermissionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePermissionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePermissionMethod "release" o = PermissionReleaseMethodInfo
    ResolvePermissionMethod "releaseAsync" o = PermissionReleaseAsyncMethodInfo
    ResolvePermissionMethod "releaseFinish" o = PermissionReleaseFinishMethodInfo
    ResolvePermissionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePermissionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePermissionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePermissionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePermissionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePermissionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePermissionMethod "getAllowed" o = PermissionGetAllowedMethodInfo
    ResolvePermissionMethod "getCanAcquire" o = PermissionGetCanAcquireMethodInfo
    ResolvePermissionMethod "getCanRelease" o = PermissionGetCanReleaseMethodInfo
    ResolvePermissionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePermissionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePermissionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePermissionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePermissionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePermissionMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePermissionMethod t Permission, O.MethodInfo info Permission p) => O.IsLabelProxy t (Permission -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolvePermissionMethod t Permission, O.MethodInfo info Permission p) => O.IsLabel t (Permission -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif

-- VVV Prop "allowed"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@allowed@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' permission #allowed
@
-}
getPermissionAllowed :: (MonadIO m, IsPermission o) => o -> m Bool
getPermissionAllowed :: o -> m Bool
getPermissionAllowed obj :: o
obj = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ o -> String -> IO Bool
forall a. GObject a => a -> String -> IO Bool
getObjectPropertyBool o
obj "allowed"

#if ENABLE_OVERLOADING
data PermissionAllowedPropertyInfo
instance AttrInfo PermissionAllowedPropertyInfo where
    type AttrAllowedOps PermissionAllowedPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint PermissionAllowedPropertyInfo = (~) ()
    type AttrBaseTypeConstraint PermissionAllowedPropertyInfo = IsPermission
    type AttrGetType PermissionAllowedPropertyInfo = Bool
    type AttrLabel PermissionAllowedPropertyInfo = "allowed"
    type AttrOrigin PermissionAllowedPropertyInfo = Permission
    attrGet _ = getPermissionAllowed
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

-- VVV Prop "can-acquire"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@can-acquire@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' permission #canAcquire
@
-}
getPermissionCanAcquire :: (MonadIO m, IsPermission o) => o -> m Bool
getPermissionCanAcquire :: o -> m Bool
getPermissionCanAcquire obj :: o
obj = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ o -> String -> IO Bool
forall a. GObject a => a -> String -> IO Bool
getObjectPropertyBool o
obj "can-acquire"

#if ENABLE_OVERLOADING
data PermissionCanAcquirePropertyInfo
instance AttrInfo PermissionCanAcquirePropertyInfo where
    type AttrAllowedOps PermissionCanAcquirePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint PermissionCanAcquirePropertyInfo = (~) ()
    type AttrBaseTypeConstraint PermissionCanAcquirePropertyInfo = IsPermission
    type AttrGetType PermissionCanAcquirePropertyInfo = Bool
    type AttrLabel PermissionCanAcquirePropertyInfo = "can-acquire"
    type AttrOrigin PermissionCanAcquirePropertyInfo = Permission
    attrGet _ = getPermissionCanAcquire
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

-- VVV Prop "can-release"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@can-release@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' permission #canRelease
@
-}
getPermissionCanRelease :: (MonadIO m, IsPermission o) => o -> m Bool
getPermissionCanRelease :: o -> m Bool
getPermissionCanRelease obj :: o
obj = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ o -> String -> IO Bool
forall a. GObject a => a -> String -> IO Bool
getObjectPropertyBool o
obj "can-release"

#if ENABLE_OVERLOADING
data PermissionCanReleasePropertyInfo
instance AttrInfo PermissionCanReleasePropertyInfo where
    type AttrAllowedOps PermissionCanReleasePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint PermissionCanReleasePropertyInfo = (~) ()
    type AttrBaseTypeConstraint PermissionCanReleasePropertyInfo = IsPermission
    type AttrGetType PermissionCanReleasePropertyInfo = Bool
    type AttrLabel PermissionCanReleasePropertyInfo = "can-release"
    type AttrOrigin PermissionCanReleasePropertyInfo = Permission
    attrGet _ = getPermissionCanRelease
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList Permission
type instance O.AttributeList Permission = PermissionAttributeList
type PermissionAttributeList = ('[ '("allowed", PermissionAllowedPropertyInfo), '("canAcquire", PermissionCanAcquirePropertyInfo), '("canRelease", PermissionCanReleasePropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
permissionAllowed :: AttrLabelProxy "allowed"
permissionAllowed = AttrLabelProxy

permissionCanAcquire :: AttrLabelProxy "canAcquire"
permissionCanAcquire = AttrLabelProxy

permissionCanRelease :: AttrLabelProxy "canRelease"
permissionCanRelease = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Permission = PermissionSignalList
type PermissionSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Permission::acquire
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_permission_acquire" g_permission_acquire :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Attempts to acquire the permission represented by /@permission@/.

The precise method by which this happens depends on the permission
and the underlying authentication mechanism.  A simple example is
that a dialog may appear asking the user to enter their password.

You should check with 'GI.Gio.Objects.Permission.permissionGetCanAcquire' before calling
this function.

If the permission is acquired then 'True' is returned.  Otherwise,
'False' is returned and /@error@/ is set appropriately.

This call is blocking, likely for a very long time (in the case that
user interaction is required).  See 'GI.Gio.Objects.Permission.permissionAcquireAsync' for
the non-blocking version.

/Since: 2.26/
-}
permissionAcquire ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
permissionAcquire :: a -> Maybe b -> m ()
permissionAcquire permission :: a
permission cancellable :: Maybe b
cancellable = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Permission -> Ptr Cancellable -> Ptr (Ptr GError) -> IO CInt
g_permission_acquire Ptr Permission
permission' Ptr Cancellable
maybeCancellable
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
        Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data PermissionAcquireMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PermissionAcquireMethodInfo a signature where
    overloadedMethod _ = permissionAcquire

#endif

-- method Permission::acquire_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the #GAsyncReadyCallback to call when done", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the user data to pass to @callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_permission_acquire_async" g_permission_acquire_async :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Attempts to acquire the permission represented by /@permission@/.

This is the first half of the asynchronous version of
'GI.Gio.Objects.Permission.permissionAcquire'.

/Since: 2.26/
-}
permissionAcquireAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: the 'GI.Gio.Callbacks.AsyncReadyCallback' to call when done -}
    -> m ()
permissionAcquireAsync :: a -> Maybe b -> Maybe AsyncReadyCallback -> m ()
permissionAcquireAsync permission :: a
permission cancellable :: Maybe b
cancellable callback :: Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Permission
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
g_permission_acquire_async Ptr Permission
permission' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
    Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data PermissionAcquireAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PermissionAcquireAsyncMethodInfo a signature where
    overloadedMethod _ = permissionAcquireAsync

#endif

-- method Permission::acquire_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GAsyncResult given to the #GAsyncReadyCallback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_permission_acquire_finish" g_permission_acquire_finish :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Collects the result of attempting to acquire the permission
represented by /@permission@/.

This is the second half of the asynchronous version of
'GI.Gio.Objects.Permission.permissionAcquire'.

/Since: 2.26/
-}
permissionAcquireFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> b
    {- ^ /@result@/: the 'GI.Gio.Interfaces.AsyncResult.AsyncResult' given to the 'GI.Gio.Callbacks.AsyncReadyCallback' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
permissionAcquireFinish :: a -> b -> m ()
permissionAcquireFinish permission :: a
permission result_ :: b
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    Ptr AsyncResult
result_' <- b -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
result_
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Permission -> Ptr AsyncResult -> Ptr (Ptr GError) -> IO CInt
g_permission_acquire_finish Ptr Permission
permission' Ptr AsyncResult
result_'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
        b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
result_
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data PermissionAcquireFinishMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsPermission a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo PermissionAcquireFinishMethodInfo a signature where
    overloadedMethod _ = permissionAcquireFinish

#endif

-- method Permission::get_allowed
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_permission_get_allowed" g_permission_get_allowed :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    IO CInt

{- |
Gets the value of the \'allowed\' property.  This property is 'True' if
the caller currently has permission to perform the action that
/@permission@/ represents the permission to perform.

/Since: 2.26/
-}
permissionGetAllowed ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> m Bool
    {- ^ __Returns:__ the value of the \'allowed\' property -}
permissionGetAllowed :: a -> m Bool
permissionGetAllowed permission :: a
permission = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    CInt
result <- Ptr Permission -> IO CInt
g_permission_get_allowed Ptr Permission
permission'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data PermissionGetAllowedMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsPermission a) => O.MethodInfo PermissionGetAllowedMethodInfo a signature where
    overloadedMethod _ = permissionGetAllowed

#endif

-- method Permission::get_can_acquire
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_permission_get_can_acquire" g_permission_get_can_acquire :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    IO CInt

{- |
Gets the value of the \'can-acquire\' property.  This property is 'True'
if it is generally possible to acquire the permission by calling
'GI.Gio.Objects.Permission.permissionAcquire'.

/Since: 2.26/
-}
permissionGetCanAcquire ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> m Bool
    {- ^ __Returns:__ the value of the \'can-acquire\' property -}
permissionGetCanAcquire :: a -> m Bool
permissionGetCanAcquire permission :: a
permission = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    CInt
result <- Ptr Permission -> IO CInt
g_permission_get_can_acquire Ptr Permission
permission'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data PermissionGetCanAcquireMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsPermission a) => O.MethodInfo PermissionGetCanAcquireMethodInfo a signature where
    overloadedMethod _ = permissionGetCanAcquire

#endif

-- method Permission::get_can_release
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_permission_get_can_release" g_permission_get_can_release :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    IO CInt

{- |
Gets the value of the \'can-release\' property.  This property is 'True'
if it is generally possible to release the permission by calling
'GI.Gio.Objects.Permission.permissionRelease'.

/Since: 2.26/
-}
permissionGetCanRelease ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> m Bool
    {- ^ __Returns:__ the value of the \'can-release\' property -}
permissionGetCanRelease :: a -> m Bool
permissionGetCanRelease permission :: a
permission = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    CInt
result <- Ptr Permission -> IO CInt
g_permission_get_can_release Ptr Permission
permission'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data PermissionGetCanReleaseMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsPermission a) => O.MethodInfo PermissionGetCanReleaseMethodInfo a signature where
    overloadedMethod _ = permissionGetCanRelease

#endif

-- method Permission::impl_update
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "allowed", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new value for the 'allowed' property", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "can_acquire", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new value for the 'can-acquire' property", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "can_release", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new value for the 'can-release' property", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_permission_impl_update" g_permission_impl_update :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    CInt ->                                 -- allowed : TBasicType TBoolean
    CInt ->                                 -- can_acquire : TBasicType TBoolean
    CInt ->                                 -- can_release : TBasicType TBoolean
    IO ()

{- |
This function is called by the 'GI.Gio.Objects.Permission.Permission' implementation to update
the properties of the permission.  You should never call this
function except from a 'GI.Gio.Objects.Permission.Permission' implementation.

GObject notify signals are generated, as appropriate.

/Since: 2.26/
-}
permissionImplUpdate ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> Bool
    {- ^ /@allowed@/: the new value for the \'allowed\' property -}
    -> Bool
    {- ^ /@canAcquire@/: the new value for the \'can-acquire\' property -}
    -> Bool
    {- ^ /@canRelease@/: the new value for the \'can-release\' property -}
    -> m ()
permissionImplUpdate :: a -> Bool -> Bool -> Bool -> m ()
permissionImplUpdate permission :: a
permission allowed :: Bool
allowed canAcquire :: Bool
canAcquire canRelease :: Bool
canRelease = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    let allowed' :: CInt
allowed' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
allowed
    let canAcquire' :: CInt
canAcquire' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
canAcquire
    let canRelease' :: CInt
canRelease' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
canRelease
    Ptr Permission -> CInt -> CInt -> CInt -> IO ()
g_permission_impl_update Ptr Permission
permission' CInt
allowed' CInt
canAcquire' CInt
canRelease'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data PermissionImplUpdateMethodInfo
instance (signature ~ (Bool -> Bool -> Bool -> m ()), MonadIO m, IsPermission a) => O.MethodInfo PermissionImplUpdateMethodInfo a signature where
    overloadedMethod _ = permissionImplUpdate

#endif

-- method Permission::release
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_permission_release" g_permission_release :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Attempts to release the permission represented by /@permission@/.

The precise method by which this happens depends on the permission
and the underlying authentication mechanism.  In most cases the
permission will be dropped immediately without further action.

You should check with 'GI.Gio.Objects.Permission.permissionGetCanRelease' before calling
this function.

If the permission is released then 'True' is returned.  Otherwise,
'False' is returned and /@error@/ is set appropriately.

This call is blocking, likely for a very long time (in the case that
user interaction is required).  See 'GI.Gio.Objects.Permission.permissionReleaseAsync' for
the non-blocking version.

/Since: 2.26/
-}
permissionRelease ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
permissionRelease :: a -> Maybe b -> m ()
permissionRelease permission :: a
permission cancellable :: Maybe b
cancellable = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Permission -> Ptr Cancellable -> Ptr (Ptr GError) -> IO CInt
g_permission_release Ptr Permission
permission' Ptr Cancellable
maybeCancellable
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
        Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data PermissionReleaseMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PermissionReleaseMethodInfo a signature where
    overloadedMethod _ = permissionRelease

#endif

-- method Permission::release_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GCancellable, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the #GAsyncReadyCallback to call when done", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the user data to pass to @callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_permission_release_async" g_permission_release_async :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Attempts to release the permission represented by /@permission@/.

This is the first half of the asynchronous version of
'GI.Gio.Objects.Permission.permissionRelease'.

/Since: 2.26/
-}
permissionReleaseAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: the 'GI.Gio.Callbacks.AsyncReadyCallback' to call when done -}
    -> m ()
permissionReleaseAsync :: a -> Maybe b -> Maybe AsyncReadyCallback -> m ()
permissionReleaseAsync permission :: a
permission cancellable :: Maybe b
cancellable callback :: Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Permission
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
g_permission_release_async Ptr Permission
permission' Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
    Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data PermissionReleaseAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsPermission a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PermissionReleaseAsyncMethodInfo a signature where
    overloadedMethod _ = permissionReleaseAsync

#endif

-- method Permission::release_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "permission", argType = TInterface (Name {namespace = "Gio", name = "Permission"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GPermission instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GAsyncResult given to the #GAsyncReadyCallback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_permission_release_finish" g_permission_release_finish :: 
    Ptr Permission ->                       -- permission : TInterface (Name {namespace = "Gio", name = "Permission"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Collects the result of attempting to release the permission
represented by /@permission@/.

This is the second half of the asynchronous version of
'GI.Gio.Objects.Permission.permissionRelease'.

/Since: 2.26/
-}
permissionReleaseFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsPermission a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@permission@/: a 'GI.Gio.Objects.Permission.Permission' instance -}
    -> b
    {- ^ /@result@/: the 'GI.Gio.Interfaces.AsyncResult.AsyncResult' given to the 'GI.Gio.Callbacks.AsyncReadyCallback' -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
permissionReleaseFinish :: a -> b -> m ()
permissionReleaseFinish permission :: a
permission result_ :: b
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Permission
permission' <- a -> IO (Ptr Permission)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
permission
    Ptr AsyncResult
result_' <- b -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
result_
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Permission -> Ptr AsyncResult -> Ptr (Ptr GError) -> IO CInt
g_permission_release_finish Ptr Permission
permission' Ptr AsyncResult
result_'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
permission
        b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
result_
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data PermissionReleaseFinishMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsPermission a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo PermissionReleaseFinishMethodInfo a signature where
    overloadedMethod _ = permissionReleaseFinish

#endif