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

/No description available in the introspection data./
-}

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

module GI.WebKit2.Objects.AutomationSession
    (

-- * Exported types
    AutomationSession(..)                   ,
    IsAutomationSession                     ,
    toAutomationSession                     ,
    noAutomationSession                     ,


 -- * Methods
-- ** getApplicationInfo #method:getApplicationInfo#

#if ENABLE_OVERLOADING
    AutomationSessionGetApplicationInfoMethodInfo,
#endif
    automationSessionGetApplicationInfo     ,


-- ** getId #method:getId#

#if ENABLE_OVERLOADING
    AutomationSessionGetIdMethodInfo        ,
#endif
    automationSessionGetId                  ,


-- ** setApplicationInfo #method:setApplicationInfo#

#if ENABLE_OVERLOADING
    AutomationSessionSetApplicationInfoMethodInfo,
#endif
    automationSessionSetApplicationInfo     ,




 -- * Properties
-- ** id #attr:id#
{- | The session unique identifier.

/Since: 2.18/
-}
#if ENABLE_OVERLOADING
    AutomationSessionIdPropertyInfo         ,
#endif
#if ENABLE_OVERLOADING
    automationSessionId                     ,
#endif
    constructAutomationSessionId            ,
    getAutomationSessionId                  ,




 -- * Signals
-- ** createWebView #signal:createWebView#

    AutomationSessionCreateWebViewCallback  ,
#if ENABLE_OVERLOADING
    AutomationSessionCreateWebViewSignalInfo,
#endif
    C_AutomationSessionCreateWebViewCallback,
    afterAutomationSessionCreateWebView     ,
    genClosure_AutomationSessionCreateWebView,
    mk_AutomationSessionCreateWebViewCallback,
    noAutomationSessionCreateWebViewCallback,
    onAutomationSessionCreateWebView        ,
    wrap_AutomationSessionCreateWebViewCallback,




    ) 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.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.WebKit2.Objects.WebView as WebKit2.WebView
import {-# SOURCE #-} qualified GI.WebKit2.Structs.ApplicationInfo as WebKit2.ApplicationInfo

-- | Memory-managed wrapper type.
newtype AutomationSession = AutomationSession (ManagedPtr AutomationSession)
foreign import ccall "webkit_automation_session_get_type"
    c_webkit_automation_session_get_type :: IO GType

instance GObject AutomationSession where
    gobjectType = c_webkit_automation_session_get_type


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

instance O.HasParentTypes AutomationSession
type instance O.ParentTypes AutomationSession = '[GObject.Object.Object]

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

-- | A convenience alias for `Nothing` :: `Maybe` `AutomationSession`.
noAutomationSession :: Maybe AutomationSession
noAutomationSession = Nothing

#if ENABLE_OVERLOADING
type family ResolveAutomationSessionMethod (t :: Symbol) (o :: *) :: * where
    ResolveAutomationSessionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAutomationSessionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAutomationSessionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAutomationSessionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAutomationSessionMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveAutomationSessionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAutomationSessionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAutomationSessionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAutomationSessionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveAutomationSessionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAutomationSessionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAutomationSessionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAutomationSessionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAutomationSessionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAutomationSessionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveAutomationSessionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAutomationSessionMethod "getApplicationInfo" o = AutomationSessionGetApplicationInfoMethodInfo
    ResolveAutomationSessionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAutomationSessionMethod "getId" o = AutomationSessionGetIdMethodInfo
    ResolveAutomationSessionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAutomationSessionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAutomationSessionMethod "setApplicationInfo" o = AutomationSessionSetApplicationInfoMethodInfo
    ResolveAutomationSessionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAutomationSessionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAutomationSessionMethod l o = O.MethodResolutionFailed l o

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

-- signal AutomationSession::create-web-view
{- |
This signal is emitted when the automation client requests a new
browsing context to interact with it. The callback handler should
return a 'GI.WebKit2.Objects.WebView.WebView' created with 'GI.WebKit2.Objects.WebView.WebView':@/is-controlled-by-automation/@
construct property enabled. The returned 'GI.WebKit2.Objects.WebView.WebView' could be an existing
web view or a new one created and added to a new tab or window.

/Since: 2.18/
-}
type AutomationSessionCreateWebViewCallback =
    IO WebKit2.WebView.WebView
    {- ^ __Returns:__ a 'GI.WebKit2.Objects.WebView.WebView' widget. -}

-- | A convenience synonym for @`Nothing` :: `Maybe` `AutomationSessionCreateWebViewCallback`@.
noAutomationSessionCreateWebViewCallback :: Maybe AutomationSessionCreateWebViewCallback
noAutomationSessionCreateWebViewCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_AutomationSessionCreateWebViewCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO (Ptr WebKit2.WebView.WebView)

-- | Generate a function pointer callable from C code, from a `C_AutomationSessionCreateWebViewCallback`.
foreign import ccall "wrapper"
    mk_AutomationSessionCreateWebViewCallback :: C_AutomationSessionCreateWebViewCallback -> IO (FunPtr C_AutomationSessionCreateWebViewCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_AutomationSessionCreateWebView :: MonadIO m => AutomationSessionCreateWebViewCallback -> m (GClosure C_AutomationSessionCreateWebViewCallback)
genClosure_AutomationSessionCreateWebView cb = liftIO $ do
    let cb' = wrap_AutomationSessionCreateWebViewCallback cb
    mk_AutomationSessionCreateWebViewCallback cb' >>= B.GClosure.newGClosure


-- | Wrap a `AutomationSessionCreateWebViewCallback` into a `C_AutomationSessionCreateWebViewCallback`.
wrap_AutomationSessionCreateWebViewCallback ::
    AutomationSessionCreateWebViewCallback ->
    C_AutomationSessionCreateWebViewCallback
wrap_AutomationSessionCreateWebViewCallback _cb _ _ = do
    result <- _cb
    result' <- unsafeManagedPtrCastPtr result
    return result'


{- |
Connect a signal handler for the “@create-web-view@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' automationSession #createWebView callback
@
-}
onAutomationSessionCreateWebView :: (IsAutomationSession a, MonadIO m) => a -> AutomationSessionCreateWebViewCallback -> m SignalHandlerId
onAutomationSessionCreateWebView obj cb = liftIO $ do
    let cb' = wrap_AutomationSessionCreateWebViewCallback cb
    cb'' <- mk_AutomationSessionCreateWebViewCallback cb'
    connectSignalFunPtr obj "create-web-view" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@create-web-view@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' automationSession #createWebView callback
@
-}
afterAutomationSessionCreateWebView :: (IsAutomationSession a, MonadIO m) => a -> AutomationSessionCreateWebViewCallback -> m SignalHandlerId
afterAutomationSessionCreateWebView obj cb = liftIO $ do
    let cb' = wrap_AutomationSessionCreateWebViewCallback cb
    cb'' <- mk_AutomationSessionCreateWebViewCallback cb'
    connectSignalFunPtr obj "create-web-view" cb'' SignalConnectAfter


-- VVV Prop "id"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

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

@
'Data.GI.Base.Attributes.get' automationSession #id
@
-}
getAutomationSessionId :: (MonadIO m, IsAutomationSession o) => o -> m T.Text
getAutomationSessionId obj = liftIO $ checkUnexpectedNothing "getAutomationSessionId" $ B.Properties.getObjectPropertyString obj "id"

{- |
Construct a `GValueConstruct` with valid value for the “@id@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructAutomationSessionId :: (IsAutomationSession o) => T.Text -> IO (GValueConstruct o)
constructAutomationSessionId val = B.Properties.constructObjectPropertyString "id" (Just val)

#if ENABLE_OVERLOADING
data AutomationSessionIdPropertyInfo
instance AttrInfo AutomationSessionIdPropertyInfo where
    type AttrAllowedOps AutomationSessionIdPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint AutomationSessionIdPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint AutomationSessionIdPropertyInfo = IsAutomationSession
    type AttrGetType AutomationSessionIdPropertyInfo = T.Text
    type AttrLabel AutomationSessionIdPropertyInfo = "id"
    type AttrOrigin AutomationSessionIdPropertyInfo = AutomationSession
    attrGet _ = getAutomationSessionId
    attrSet _ = undefined
    attrConstruct _ = constructAutomationSessionId
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList AutomationSession
type instance O.AttributeList AutomationSession = AutomationSessionAttributeList
type AutomationSessionAttributeList = ('[ '("id", AutomationSessionIdPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
automationSessionId :: AttrLabelProxy "id"
automationSessionId = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
data AutomationSessionCreateWebViewSignalInfo
instance SignalInfo AutomationSessionCreateWebViewSignalInfo where
    type HaskellCallbackType AutomationSessionCreateWebViewSignalInfo = AutomationSessionCreateWebViewCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_AutomationSessionCreateWebViewCallback cb
        cb'' <- mk_AutomationSessionCreateWebViewCallback cb'
        connectSignalFunPtr obj "create-web-view" cb'' connectMode

type instance O.SignalList AutomationSession = AutomationSessionSignalList
type AutomationSessionSignalList = ('[ '("createWebView", AutomationSessionCreateWebViewSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method AutomationSession::get_application_info
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "session", argType = TInterface (Name {namespace = "WebKit2", name = "AutomationSession"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitAutomationSession", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit2", name = "ApplicationInfo"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_automation_session_get_application_info" webkit_automation_session_get_application_info ::
    Ptr AutomationSession ->                -- session : TInterface (Name {namespace = "WebKit2", name = "AutomationSession"})
    IO (Ptr WebKit2.ApplicationInfo.ApplicationInfo)

{- |
Get the 'GI.WebKit2.Objects.AutomationSession.AutomationSession' previously set with 'GI.WebKit2.Objects.AutomationSession.automationSessionSetApplicationInfo'.

/Since: 2.18/
-}
automationSessionGetApplicationInfo ::
    (B.CallStack.HasCallStack, MonadIO m, IsAutomationSession a) =>
    a
    {- ^ /@session@/: a 'GI.WebKit2.Objects.AutomationSession.AutomationSession' -}
    -> m (Maybe WebKit2.ApplicationInfo.ApplicationInfo)
    {- ^ __Returns:__ the 'GI.WebKit2.Objects.AutomationSession.AutomationSession' of /@session@/, or 'Nothing' if no one has been set. -}
automationSessionGetApplicationInfo session = liftIO $ do
    session' <- unsafeManagedPtrCastPtr session
    result <- webkit_automation_session_get_application_info session'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newBoxed WebKit2.ApplicationInfo.ApplicationInfo) result'
        return result''
    touchManagedPtr session
    return maybeResult

#if ENABLE_OVERLOADING
data AutomationSessionGetApplicationInfoMethodInfo
instance (signature ~ (m (Maybe WebKit2.ApplicationInfo.ApplicationInfo)), MonadIO m, IsAutomationSession a) => O.MethodInfo AutomationSessionGetApplicationInfoMethodInfo a signature where
    overloadedMethod _ = automationSessionGetApplicationInfo

#endif

-- method AutomationSession::get_id
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "session", argType = TInterface (Name {namespace = "WebKit2", name = "AutomationSession"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitAutomationSession", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "webkit_automation_session_get_id" webkit_automation_session_get_id ::
    Ptr AutomationSession ->                -- session : TInterface (Name {namespace = "WebKit2", name = "AutomationSession"})
    IO CString

{- |
Get the unique identifier of a 'GI.WebKit2.Objects.AutomationSession.AutomationSession'

/Since: 2.18/
-}
automationSessionGetId ::
    (B.CallStack.HasCallStack, MonadIO m, IsAutomationSession a) =>
    a
    {- ^ /@session@/: a 'GI.WebKit2.Objects.AutomationSession.AutomationSession' -}
    -> m T.Text
    {- ^ __Returns:__ the unique identifier of /@session@/ -}
automationSessionGetId session = liftIO $ do
    session' <- unsafeManagedPtrCastPtr session
    result <- webkit_automation_session_get_id session'
    checkUnexpectedReturnNULL "automationSessionGetId" result
    result' <- cstringToText result
    touchManagedPtr session
    return result'

#if ENABLE_OVERLOADING
data AutomationSessionGetIdMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsAutomationSession a) => O.MethodInfo AutomationSessionGetIdMethodInfo a signature where
    overloadedMethod _ = automationSessionGetId

#endif

-- method AutomationSession::set_application_info
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "session", argType = TInterface (Name {namespace = "WebKit2", name = "AutomationSession"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitAutomationSession", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "info", argType = TInterface (Name {namespace = "WebKit2", name = "ApplicationInfo"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitApplicationInfo", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_automation_session_set_application_info" webkit_automation_session_set_application_info ::
    Ptr AutomationSession ->                -- session : TInterface (Name {namespace = "WebKit2", name = "AutomationSession"})
    Ptr WebKit2.ApplicationInfo.ApplicationInfo -> -- info : TInterface (Name {namespace = "WebKit2", name = "ApplicationInfo"})
    IO ()

{- |
Set the application information to /@session@/. This information will be used by the driver service
to match the requested capabilities with the actual application information. If this information
is not provided to the session when a new automation session is requested, the creation might fail
if the client requested a specific browser name or version. This will not have any effect when called
after the automation session has been fully created, so this must be called in the callback of
'GI.WebKit2.Objects.WebContext.WebContext'::@/automation-started/@ signal.

/Since: 2.18/
-}
automationSessionSetApplicationInfo ::
    (B.CallStack.HasCallStack, MonadIO m, IsAutomationSession a) =>
    a
    {- ^ /@session@/: a 'GI.WebKit2.Objects.AutomationSession.AutomationSession' -}
    -> WebKit2.ApplicationInfo.ApplicationInfo
    {- ^ /@info@/: a 'GI.WebKit2.Structs.ApplicationInfo.ApplicationInfo' -}
    -> m ()
automationSessionSetApplicationInfo session info = liftIO $ do
    session' <- unsafeManagedPtrCastPtr session
    info' <- unsafeManagedPtrGetPtr info
    webkit_automation_session_set_application_info session' info'
    touchManagedPtr session
    touchManagedPtr info
    return ()

#if ENABLE_OVERLOADING
data AutomationSessionSetApplicationInfoMethodInfo
instance (signature ~ (WebKit2.ApplicationInfo.ApplicationInfo -> m ()), MonadIO m, IsAutomationSession a) => O.MethodInfo AutomationSessionSetApplicationInfoMethodInfo a signature where
    overloadedMethod _ = automationSessionSetApplicationInfo

#endif