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

module GI.Soup.Interfaces.PasswordManager
    ( 

-- * Exported types
    PasswordManager(..)                     ,
    noPasswordManager                       ,
    PasswordManagerK                        ,
    toPasswordManager                       ,


 -- * Methods
-- ** passwordManagerGetPasswordsAsync
    passwordManagerGetPasswordsAsync        ,


-- ** passwordManagerGetPasswordsSync
    passwordManagerGetPasswordsSync         ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Soup.Types
import GI.Soup.Callbacks
import qualified GI.GLib as GLib
import qualified GI.GObject as GObject
import qualified GI.Gio as Gio

-- interface PasswordManager 

newtype PasswordManager = PasswordManager (ForeignPtr PasswordManager)
noPasswordManager :: Maybe PasswordManager
noPasswordManager = Nothing

type instance AttributeList PasswordManager = PasswordManagerAttributeList
type PasswordManagerAttributeList = ('[ ] :: [(Symbol, *)])

type instance SignalList PasswordManager = PasswordManagerSignalList
type PasswordManagerSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "soup_password_manager_get_type"
    c_soup_password_manager_get_type :: IO GType

type instance ParentTypes PasswordManager = PasswordManagerParentTypes
type PasswordManagerParentTypes = '[SessionFeature, GObject.Object]

instance GObject PasswordManager where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_soup_password_manager_get_type
    

class GObject o => PasswordManagerK o
instance (GObject o, IsDescendantOf PasswordManager o) => PasswordManagerK o

toPasswordManager :: PasswordManagerK o => o -> IO PasswordManager
toPasswordManager = unsafeCastTo PasswordManager

-- method PasswordManager::get_passwords_async
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "PasswordManager", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "msg", argType = TInterface "Soup" "Message", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "auth", argType = TInterface "Soup" "Auth", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "retrying", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "async_context", argType = TInterface "GLib" "MainContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Soup" "PasswordManagerCallback", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeAsync, argClosure = 7, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "PasswordManager", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "msg", argType = TInterface "Soup" "Message", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "auth", argType = TInterface "Soup" "Auth", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "retrying", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "async_context", argType = TInterface "GLib" "MainContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Soup" "PasswordManagerCallback", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeAsync, argClosure = 7, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_password_manager_get_passwords_async" soup_password_manager_get_passwords_async :: 
    Ptr PasswordManager ->                  -- _obj : TInterface "Soup" "PasswordManager"
    Ptr Message ->                          -- msg : TInterface "Soup" "Message"
    Ptr Auth ->                             -- auth : TInterface "Soup" "Auth"
    CInt ->                                 -- retrying : TBasicType TBoolean
    Ptr GLib.MainContext ->                 -- async_context : TInterface "GLib" "MainContext"
    Ptr Gio.Cancellable ->                  -- cancellable : TInterface "Gio" "Cancellable"
    FunPtr PasswordManagerCallbackC ->      -- callback : TInterface "Soup" "PasswordManagerCallback"
    Ptr () ->                               -- user_data : TBasicType TVoid
    IO ()


passwordManagerGetPasswordsAsync ::
    (MonadIO m, PasswordManagerK a, MessageK b, AuthK c, Gio.CancellableK d) =>
    a ->                                    -- _obj
    b ->                                    -- msg
    c ->                                    -- auth
    Bool ->                                 -- retrying
    GLib.MainContext ->                     -- async_context
    Maybe (d) ->                            -- cancellable
    PasswordManagerCallback ->              -- callback
    m ()
passwordManagerGetPasswordsAsync _obj msg auth retrying async_context cancellable callback = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let msg' = unsafeManagedPtrCastPtr msg
    let auth' = unsafeManagedPtrCastPtr auth
    let retrying' = (fromIntegral . fromEnum) retrying
    let async_context' = unsafeManagedPtrGetPtr async_context
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr PasswordManagerCallbackC))
    callback' <- mkPasswordManagerCallback (passwordManagerCallbackWrapper (Just ptrcallback) callback)
    poke ptrcallback callback'
    let user_data = nullPtr
    soup_password_manager_get_passwords_async _obj' msg' auth' retrying' async_context' maybeCancellable callback' user_data
    touchManagedPtr _obj
    touchManagedPtr msg
    touchManagedPtr auth
    touchManagedPtr async_context
    whenJust cancellable touchManagedPtr
    return ()

-- method PasswordManager::get_passwords_sync
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Soup" "PasswordManager", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "msg", argType = TInterface "Soup" "Message", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "auth", argType = TInterface "Soup" "Auth", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Soup" "PasswordManager", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "msg", argType = TInterface "Soup" "Message", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "auth", argType = TInterface "Soup" "Auth", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "soup_password_manager_get_passwords_sync" soup_password_manager_get_passwords_sync :: 
    Ptr PasswordManager ->                  -- _obj : TInterface "Soup" "PasswordManager"
    Ptr Message ->                          -- msg : TInterface "Soup" "Message"
    Ptr Auth ->                             -- auth : TInterface "Soup" "Auth"
    Ptr Gio.Cancellable ->                  -- cancellable : TInterface "Gio" "Cancellable"
    IO ()


passwordManagerGetPasswordsSync ::
    (MonadIO m, PasswordManagerK a, MessageK b, AuthK c, Gio.CancellableK d) =>
    a ->                                    -- _obj
    b ->                                    -- msg
    c ->                                    -- auth
    Maybe (d) ->                            -- cancellable
    m ()
passwordManagerGetPasswordsSync _obj msg auth cancellable = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let msg' = unsafeManagedPtrCastPtr msg
    let auth' = unsafeManagedPtrCastPtr auth
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    soup_password_manager_get_passwords_sync _obj' msg' auth' maybeCancellable
    touchManagedPtr _obj
    touchManagedPtr msg
    touchManagedPtr auth
    whenJust cancellable touchManagedPtr
    return ()