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

A proxy object representing a prompt that the Secret Service will display
to the user.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Secret.Objects.Prompt
    (

-- * Exported types
    Prompt(..)                              ,
    IsPrompt                                ,
    toPrompt                                ,
    noPrompt                                ,


 -- * Methods
-- ** perform #method:perform#

#if ENABLE_OVERLOADING
    PromptPerformMethodInfo                 ,
#endif
    promptPerform                           ,


-- ** performFinish #method:performFinish#

#if ENABLE_OVERLOADING
    PromptPerformFinishMethodInfo           ,
#endif
    promptPerformFinish                     ,


-- ** performSync #method:performSync#

#if ENABLE_OVERLOADING
    PromptPerformSyncMethodInfo             ,
#endif
    promptPerformSync                       ,


-- ** run #method:run#

#if ENABLE_OVERLOADING
    PromptRunMethodInfo                     ,
#endif
    promptRun                               ,




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
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 GHC.OverloadedLabels as OL

import qualified GI.GLib.Structs.VariantType as GLib.VariantType
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import qualified GI.Gio.Interfaces.AsyncInitable as Gio.AsyncInitable
import qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import qualified GI.Gio.Interfaces.DBusInterface as Gio.DBusInterface
import qualified GI.Gio.Interfaces.Initable as Gio.Initable
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
import qualified GI.Gio.Objects.DBusProxy as Gio.DBusProxy

-- | Memory-managed wrapper type.
newtype Prompt = Prompt (ManagedPtr Prompt)
foreign import ccall "secret_prompt_get_type"
    c_secret_prompt_get_type :: IO GType

instance GObject Prompt where
    gobjectType = c_secret_prompt_get_type


-- | Type class for types which can be safely cast to `Prompt`, for instance with `toPrompt`.
class (GObject o, O.IsDescendantOf Prompt o) => IsPrompt o
instance (GObject o, O.IsDescendantOf Prompt o) => IsPrompt o

instance O.HasParentTypes Prompt
type instance O.ParentTypes Prompt = '[Gio.DBusProxy.DBusProxy, GObject.Object.Object, Gio.AsyncInitable.AsyncInitable, Gio.DBusInterface.DBusInterface, Gio.Initable.Initable]

-- | Cast to `Prompt`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toPrompt :: (MonadIO m, IsPrompt o) => o -> m Prompt
toPrompt = liftIO . unsafeCastTo Prompt

-- | A convenience alias for `Nothing` :: `Maybe` `Prompt`.
noPrompt :: Maybe Prompt
noPrompt = Nothing

#if ENABLE_OVERLOADING
type family ResolvePromptMethod (t :: Symbol) (o :: *) :: * where
    ResolvePromptMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePromptMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePromptMethod "call" o = Gio.DBusProxy.DBusProxyCallMethodInfo
    ResolvePromptMethod "callFinish" o = Gio.DBusProxy.DBusProxyCallFinishMethodInfo
    ResolvePromptMethod "callSync" o = Gio.DBusProxy.DBusProxyCallSyncMethodInfo
    ResolvePromptMethod "callWithUnixFdList" o = Gio.DBusProxy.DBusProxyCallWithUnixFdListMethodInfo
    ResolvePromptMethod "callWithUnixFdListFinish" o = Gio.DBusProxy.DBusProxyCallWithUnixFdListFinishMethodInfo
    ResolvePromptMethod "callWithUnixFdListSync" o = Gio.DBusProxy.DBusProxyCallWithUnixFdListSyncMethodInfo
    ResolvePromptMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePromptMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePromptMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolvePromptMethod "init" o = Gio.Initable.InitableInitMethodInfo
    ResolvePromptMethod "initAsync" o = Gio.AsyncInitable.AsyncInitableInitAsyncMethodInfo
    ResolvePromptMethod "initFinish" o = Gio.AsyncInitable.AsyncInitableInitFinishMethodInfo
    ResolvePromptMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePromptMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePromptMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePromptMethod "perform" o = PromptPerformMethodInfo
    ResolvePromptMethod "performFinish" o = PromptPerformFinishMethodInfo
    ResolvePromptMethod "performSync" o = PromptPerformSyncMethodInfo
    ResolvePromptMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePromptMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePromptMethod "run" o = PromptRunMethodInfo
    ResolvePromptMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePromptMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePromptMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePromptMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePromptMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePromptMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePromptMethod "getCachedProperty" o = Gio.DBusProxy.DBusProxyGetCachedPropertyMethodInfo
    ResolvePromptMethod "getCachedPropertyNames" o = Gio.DBusProxy.DBusProxyGetCachedPropertyNamesMethodInfo
    ResolvePromptMethod "getConnection" o = Gio.DBusProxy.DBusProxyGetConnectionMethodInfo
    ResolvePromptMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePromptMethod "getDefaultTimeout" o = Gio.DBusProxy.DBusProxyGetDefaultTimeoutMethodInfo
    ResolvePromptMethod "getFlags" o = Gio.DBusProxy.DBusProxyGetFlagsMethodInfo
    ResolvePromptMethod "getInfo" o = Gio.DBusInterface.DBusInterfaceGetInfoMethodInfo
    ResolvePromptMethod "getInterfaceInfo" o = Gio.DBusProxy.DBusProxyGetInterfaceInfoMethodInfo
    ResolvePromptMethod "getInterfaceName" o = Gio.DBusProxy.DBusProxyGetInterfaceNameMethodInfo
    ResolvePromptMethod "getName" o = Gio.DBusProxy.DBusProxyGetNameMethodInfo
    ResolvePromptMethod "getNameOwner" o = Gio.DBusProxy.DBusProxyGetNameOwnerMethodInfo
    ResolvePromptMethod "getObject" o = Gio.DBusInterface.DBusInterfaceGetObjectMethodInfo
    ResolvePromptMethod "getObjectPath" o = Gio.DBusProxy.DBusProxyGetObjectPathMethodInfo
    ResolvePromptMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePromptMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePromptMethod "setCachedProperty" o = Gio.DBusProxy.DBusProxySetCachedPropertyMethodInfo
    ResolvePromptMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePromptMethod "setDefaultTimeout" o = Gio.DBusProxy.DBusProxySetDefaultTimeoutMethodInfo
    ResolvePromptMethod "setInterfaceInfo" o = Gio.DBusProxy.DBusProxySetInterfaceInfoMethodInfo
    ResolvePromptMethod "setObject" o = Gio.DBusInterface.DBusInterfaceSetObjectMethodInfo
    ResolvePromptMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePromptMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePromptMethod t Prompt, O.MethodInfo info Prompt p) => OL.IsLabel t (Prompt -> 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

#if ENABLE_OVERLOADING
instance O.HasAttributeList Prompt
type instance O.AttributeList Prompt = PromptAttributeList
type PromptAttributeList = ('[ '("gBusType", Gio.DBusProxy.DBusProxyGBusTypePropertyInfo), '("gConnection", Gio.DBusProxy.DBusProxyGConnectionPropertyInfo), '("gDefaultTimeout", Gio.DBusProxy.DBusProxyGDefaultTimeoutPropertyInfo), '("gFlags", Gio.DBusProxy.DBusProxyGFlagsPropertyInfo), '("gInterfaceInfo", Gio.DBusProxy.DBusProxyGInterfaceInfoPropertyInfo), '("gInterfaceName", Gio.DBusProxy.DBusProxyGInterfaceNamePropertyInfo), '("gName", Gio.DBusProxy.DBusProxyGNamePropertyInfo), '("gNameOwner", Gio.DBusProxy.DBusProxyGNameOwnerPropertyInfo), '("gObjectPath", Gio.DBusProxy.DBusProxyGObjectPathPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Prompt = PromptSignalList
type PromptSignalList = ('[ '("gPropertiesChanged", Gio.DBusProxy.DBusProxyGPropertiesChangedSignalInfo), '("gSignal", Gio.DBusProxy.DBusProxyGSignalSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Prompt::perform
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Secret", name = "Prompt"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a prompt", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "window_id", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "string form of XWindow id for parent window to be transient for", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "return_type", argType = TInterface (Name {namespace = "GLib", name = "VariantType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the variant type of the prompt result", 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 "optional cancellation object", 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 "called when the operation completes", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 5, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data to be passed to the callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "secret_prompt_perform" secret_prompt_perform ::
    Ptr Prompt ->                           -- self : TInterface (Name {namespace = "Secret", name = "Prompt"})
    CString ->                              -- window_id : TBasicType TUTF8
    Ptr GLib.VariantType.VariantType ->     -- return_type : TInterface (Name {namespace = "GLib", name = "VariantType"})
    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 ()

{- |
Runs a prompt and performs the prompting. Returns 'True' if the prompt
was completed and not dismissed.

If /@windowId@/ is non-null then it is used as an XWindow id on Linux. The API
expects this id to be converted to a string using the \<literal>@/d/@\<\/literal>
printf format. The Secret Service can make its prompt transient for the window
with this id. In some Secret Service implementations this is not possible, so
the behavior depending on this should degrade gracefully.

This method will return immediately and complete asynchronously.
-}
promptPerform ::
    (B.CallStack.HasCallStack, MonadIO m, IsPrompt a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@self@/: a prompt -}
    -> Maybe (T.Text)
    {- ^ /@windowId@/: string form of XWindow id for parent window to be transient for -}
    -> GLib.VariantType.VariantType
    {- ^ /@returnType@/: the variant type of the prompt result -}
    -> Maybe (b)
    {- ^ /@cancellable@/: optional cancellation object -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: called when the operation completes -}
    -> m ()
promptPerform self windowId returnType cancellable callback = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    maybeWindowId <- case windowId of
        Nothing -> return nullPtr
        Just jWindowId -> do
            jWindowId' <- textToCString jWindowId
            return jWindowId'
    returnType' <- unsafeManagedPtrGetPtr returnType
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
            poke ptrcallback jCallback'
            return jCallback'
    let userData = nullPtr
    secret_prompt_perform self' maybeWindowId returnType' maybeCancellable maybeCallback userData
    touchManagedPtr self
    touchManagedPtr returnType
    whenJust cancellable touchManagedPtr
    freeMem maybeWindowId
    return ()

#if ENABLE_OVERLOADING
data PromptPerformMethodInfo
instance (signature ~ (Maybe (T.Text) -> GLib.VariantType.VariantType -> Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsPrompt a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PromptPerformMethodInfo a signature where
    overloadedMethod _ = promptPerform

#endif

-- method Prompt::perform_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Secret", name = "Prompt"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a prompt", 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 asynchronous result passed to the callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just TVariant
-- throws : True
-- Skip return : False

foreign import ccall "secret_prompt_perform_finish" secret_prompt_perform_finish ::
    Ptr Prompt ->                           -- self : TInterface (Name {namespace = "Secret", name = "Prompt"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GVariant)

{- |
Complete asynchronous operation to run a prompt and perform the prompting.

Returns a variant result if the prompt was completed and not dismissed. The
type of result depends on the action the prompt is completing, and is
defined in the Secret Service DBus API specification.
-}
promptPerformFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsPrompt a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@self@/: a prompt -}
    -> b
    {- ^ /@result@/: the asynchronous result passed to the callback -}
    -> m GVariant
    {- ^ __Returns:__ 'Nothing' if the prompt was dismissed or an error occurred,
         a variant result if the prompt was successful /(Can throw 'Data.GI.Base.GError.GError')/ -}
promptPerformFinish self result_ = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    result_' <- unsafeManagedPtrCastPtr result_
    onException (do
        result <- propagateGError $ secret_prompt_perform_finish self' result_'
        checkUnexpectedReturnNULL "promptPerformFinish" result
        result' <- B.GVariant.wrapGVariantPtr result
        touchManagedPtr self
        touchManagedPtr result_
        return result'
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data PromptPerformFinishMethodInfo
instance (signature ~ (b -> m GVariant), MonadIO m, IsPrompt a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo PromptPerformFinishMethodInfo a signature where
    overloadedMethod _ = promptPerformFinish

#endif

-- method Prompt::perform_sync
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Secret", name = "Prompt"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a prompt", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "window_id", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "string form of XWindow id for parent window to be transient for", 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 "optional cancellation object", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "return_type", argType = TInterface (Name {namespace = "GLib", name = "VariantType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the variant type of the prompt result", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just TVariant
-- throws : True
-- Skip return : False

foreign import ccall "secret_prompt_perform_sync" secret_prompt_perform_sync ::
    Ptr Prompt ->                           -- self : TInterface (Name {namespace = "Secret", name = "Prompt"})
    CString ->                              -- window_id : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr GLib.VariantType.VariantType ->     -- return_type : TInterface (Name {namespace = "GLib", name = "VariantType"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GVariant)

{- |
Runs a prompt and performs the prompting. Returns a variant result if the
prompt was completed and not dismissed. The type of result depends on the
action the prompt is completing, and is defined in the Secret Service DBus
API specification.

If /@windowId@/ is non-null then it is used as an XWindow id on Linux. The API
expects this id to be converted to a string using the \<literal>@/d/@\<\/literal>
printf format. The Secret Service can make its prompt transient for the window
with this id. In some Secret Service implementations this is not possible,
so the behavior depending on this should degrade gracefully.

This method may block indefinitely and should not be used in user interface
threads.
-}
promptPerformSync ::
    (B.CallStack.HasCallStack, MonadIO m, IsPrompt a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@self@/: a prompt -}
    -> Maybe (T.Text)
    {- ^ /@windowId@/: string form of XWindow id for parent window to be transient for -}
    -> Maybe (b)
    {- ^ /@cancellable@/: optional cancellation object -}
    -> GLib.VariantType.VariantType
    {- ^ /@returnType@/: the variant type of the prompt result -}
    -> m GVariant
    {- ^ __Returns:__ 'Nothing' if the prompt was dismissed or an error occurred /(Can throw 'Data.GI.Base.GError.GError')/ -}
promptPerformSync self windowId cancellable returnType = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    maybeWindowId <- case windowId of
        Nothing -> return nullPtr
        Just jWindowId -> do
            jWindowId' <- textToCString jWindowId
            return jWindowId'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    returnType' <- unsafeManagedPtrGetPtr returnType
    onException (do
        result <- propagateGError $ secret_prompt_perform_sync self' maybeWindowId maybeCancellable returnType'
        checkUnexpectedReturnNULL "promptPerformSync" result
        result' <- B.GVariant.wrapGVariantPtr result
        touchManagedPtr self
        whenJust cancellable touchManagedPtr
        touchManagedPtr returnType
        freeMem maybeWindowId
        return result'
     ) (do
        freeMem maybeWindowId
     )

#if ENABLE_OVERLOADING
data PromptPerformSyncMethodInfo
instance (signature ~ (Maybe (T.Text) -> Maybe (b) -> GLib.VariantType.VariantType -> m GVariant), MonadIO m, IsPrompt a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PromptPerformSyncMethodInfo a signature where
    overloadedMethod _ = promptPerformSync

#endif

-- method Prompt::run
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "self", argType = TInterface (Name {namespace = "Secret", name = "Prompt"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a prompt", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "window_id", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "string form of XWindow id for parent window to be transient for", 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 "optional cancellation object", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "return_type", argType = TInterface (Name {namespace = "GLib", name = "VariantType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the variant type of the prompt result", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just TVariant
-- throws : True
-- Skip return : False

foreign import ccall "secret_prompt_run" secret_prompt_run ::
    Ptr Prompt ->                           -- self : TInterface (Name {namespace = "Secret", name = "Prompt"})
    CString ->                              -- window_id : TBasicType TUTF8
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr GLib.VariantType.VariantType ->     -- return_type : TInterface (Name {namespace = "GLib", name = "VariantType"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GVariant)

{- |
Runs a prompt and performs the prompting. Returns a variant result if the
prompt was completed and not dismissed. The type of result depends on the
action the prompt is completing, and is defined in the Secret Service DBus
API specification.

If /@windowId@/ is non-null then it is used as an XWindow id on Linux. The API
expects this id to be converted to a string using the \<literal>@/d/@\<\/literal>
printf format. The Secret Service can make its prompt transient for the window
with this id. In some Secret Service implementations this is not possible, so
the behavior depending on this should degrade gracefully.

This runs the dialog in a recursive mainloop. When run from a user interface
thread, this means the user interface will remain responsive. Care should be
taken that appropriate user interface actions are disabled while running the
prompt.
-}
promptRun ::
    (B.CallStack.HasCallStack, MonadIO m, IsPrompt a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@self@/: a prompt -}
    -> Maybe (T.Text)
    {- ^ /@windowId@/: string form of XWindow id for parent window to be transient for -}
    -> Maybe (b)
    {- ^ /@cancellable@/: optional cancellation object -}
    -> GLib.VariantType.VariantType
    {- ^ /@returnType@/: the variant type of the prompt result -}
    -> m GVariant
    {- ^ __Returns:__ 'Nothing' if the prompt was dismissed or an error occurred /(Can throw 'Data.GI.Base.GError.GError')/ -}
promptRun self windowId cancellable returnType = liftIO $ do
    self' <- unsafeManagedPtrCastPtr self
    maybeWindowId <- case windowId of
        Nothing -> return nullPtr
        Just jWindowId -> do
            jWindowId' <- textToCString jWindowId
            return jWindowId'
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    returnType' <- unsafeManagedPtrGetPtr returnType
    onException (do
        result <- propagateGError $ secret_prompt_run self' maybeWindowId maybeCancellable returnType'
        checkUnexpectedReturnNULL "promptRun" result
        result' <- B.GVariant.wrapGVariantPtr result
        touchManagedPtr self
        whenJust cancellable touchManagedPtr
        touchManagedPtr returnType
        freeMem maybeWindowId
        return result'
     ) (do
        freeMem maybeWindowId
     )

#if ENABLE_OVERLOADING
data PromptRunMethodInfo
instance (signature ~ (Maybe (T.Text) -> Maybe (b) -> GLib.VariantType.VariantType -> m GVariant), MonadIO m, IsPrompt a, Gio.Cancellable.IsCancellable b) => O.MethodInfo PromptRunMethodInfo a signature where
    overloadedMethod _ = promptRun

#endif