{- |
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.Gio.Objects.AppLaunchContext
    ( 

-- * Exported types
    AppLaunchContext(..)                    ,
    AppLaunchContextK                       ,
    toAppLaunchContext                      ,
    noAppLaunchContext                      ,


 -- * Methods
-- ** appLaunchContextGetDisplay
    appLaunchContextGetDisplay              ,


-- ** appLaunchContextGetEnvironment
    appLaunchContextGetEnvironment          ,


-- ** appLaunchContextGetStartupNotifyId
    appLaunchContextGetStartupNotifyId      ,


-- ** appLaunchContextLaunchFailed
    appLaunchContextLaunchFailed            ,


-- ** appLaunchContextNew
    appLaunchContextNew                     ,


-- ** appLaunchContextSetenv
    appLaunchContextSetenv                  ,


-- ** appLaunchContextUnsetenv
    appLaunchContextUnsetenv                ,




 -- * Signals
-- ** LaunchFailed
    AppLaunchContextLaunchFailedCallback    ,
    AppLaunchContextLaunchFailedCallbackC   ,
    AppLaunchContextLaunchFailedSignalInfo  ,
    afterAppLaunchContextLaunchFailed       ,
    appLaunchContextLaunchFailedCallbackWrapper,
    appLaunchContextLaunchFailedClosure     ,
    mkAppLaunchContextLaunchFailedCallback  ,
    noAppLaunchContextLaunchFailedCallback  ,
    onAppLaunchContextLaunchFailed          ,


-- ** Launched
    AppLaunchContextLaunchedCallback        ,
    AppLaunchContextLaunchedCallbackC       ,
    AppLaunchContextLaunchedSignalInfo      ,
    afterAppLaunchContextLaunched           ,
    appLaunchContextLaunchedCallbackWrapper ,
    appLaunchContextLaunchedClosure         ,
    mkAppLaunchContextLaunchedCallback      ,
    noAppLaunchContextLaunchedCallback      ,
    onAppLaunchContextLaunched              ,




    ) 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.Gio.Types
import GI.Gio.Callbacks
import qualified GI.GObject as GObject

newtype AppLaunchContext = AppLaunchContext (ForeignPtr AppLaunchContext)
foreign import ccall "g_app_launch_context_get_type"
    c_g_app_launch_context_get_type :: IO GType

type instance ParentTypes AppLaunchContext = AppLaunchContextParentTypes
type AppLaunchContextParentTypes = '[GObject.Object]

instance GObject AppLaunchContext where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_app_launch_context_get_type
    

class GObject o => AppLaunchContextK o
instance (GObject o, IsDescendantOf AppLaunchContext o) => AppLaunchContextK o

toAppLaunchContext :: AppLaunchContextK o => o -> IO AppLaunchContext
toAppLaunchContext = unsafeCastTo AppLaunchContext

noAppLaunchContext :: Maybe AppLaunchContext
noAppLaunchContext = Nothing

-- signal AppLaunchContext::launch-failed
type AppLaunchContextLaunchFailedCallback =
    T.Text ->
    IO ()

noAppLaunchContextLaunchFailedCallback :: Maybe AppLaunchContextLaunchFailedCallback
noAppLaunchContextLaunchFailedCallback = Nothing

type AppLaunchContextLaunchFailedCallbackC =
    Ptr () ->                               -- object
    CString ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkAppLaunchContextLaunchFailedCallback :: AppLaunchContextLaunchFailedCallbackC -> IO (FunPtr AppLaunchContextLaunchFailedCallbackC)

appLaunchContextLaunchFailedClosure :: AppLaunchContextLaunchFailedCallback -> IO Closure
appLaunchContextLaunchFailedClosure cb = newCClosure =<< mkAppLaunchContextLaunchFailedCallback wrapped
    where wrapped = appLaunchContextLaunchFailedCallbackWrapper cb

appLaunchContextLaunchFailedCallbackWrapper ::
    AppLaunchContextLaunchFailedCallback ->
    Ptr () ->
    CString ->
    Ptr () ->
    IO ()
appLaunchContextLaunchFailedCallbackWrapper _cb _ startup_notify_id _ = do
    startup_notify_id' <- cstringToText startup_notify_id
    _cb  startup_notify_id'

onAppLaunchContextLaunchFailed :: (GObject a, MonadIO m) => a -> AppLaunchContextLaunchFailedCallback -> m SignalHandlerId
onAppLaunchContextLaunchFailed obj cb = liftIO $ connectAppLaunchContextLaunchFailed obj cb SignalConnectBefore
afterAppLaunchContextLaunchFailed :: (GObject a, MonadIO m) => a -> AppLaunchContextLaunchFailedCallback -> m SignalHandlerId
afterAppLaunchContextLaunchFailed obj cb = connectAppLaunchContextLaunchFailed obj cb SignalConnectAfter

connectAppLaunchContextLaunchFailed :: (GObject a, MonadIO m) =>
                                       a -> AppLaunchContextLaunchFailedCallback -> SignalConnectMode -> m SignalHandlerId
connectAppLaunchContextLaunchFailed obj cb after = liftIO $ do
    cb' <- mkAppLaunchContextLaunchFailedCallback (appLaunchContextLaunchFailedCallbackWrapper cb)
    connectSignalFunPtr obj "launch-failed" cb' after

-- signal AppLaunchContext::launched
type AppLaunchContextLaunchedCallback =
    AppInfo ->
    GVariant ->
    IO ()

noAppLaunchContextLaunchedCallback :: Maybe AppLaunchContextLaunchedCallback
noAppLaunchContextLaunchedCallback = Nothing

type AppLaunchContextLaunchedCallbackC =
    Ptr () ->                               -- object
    Ptr AppInfo ->
    Ptr GVariant ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkAppLaunchContextLaunchedCallback :: AppLaunchContextLaunchedCallbackC -> IO (FunPtr AppLaunchContextLaunchedCallbackC)

appLaunchContextLaunchedClosure :: AppLaunchContextLaunchedCallback -> IO Closure
appLaunchContextLaunchedClosure cb = newCClosure =<< mkAppLaunchContextLaunchedCallback wrapped
    where wrapped = appLaunchContextLaunchedCallbackWrapper cb

appLaunchContextLaunchedCallbackWrapper ::
    AppLaunchContextLaunchedCallback ->
    Ptr () ->
    Ptr AppInfo ->
    Ptr GVariant ->
    Ptr () ->
    IO ()
appLaunchContextLaunchedCallbackWrapper _cb _ info platform_data _ = do
    info' <- (newObject AppInfo) info
    platform_data' <- newGVariantFromPtr platform_data
    _cb  info' platform_data'

onAppLaunchContextLaunched :: (GObject a, MonadIO m) => a -> AppLaunchContextLaunchedCallback -> m SignalHandlerId
onAppLaunchContextLaunched obj cb = liftIO $ connectAppLaunchContextLaunched obj cb SignalConnectBefore
afterAppLaunchContextLaunched :: (GObject a, MonadIO m) => a -> AppLaunchContextLaunchedCallback -> m SignalHandlerId
afterAppLaunchContextLaunched obj cb = connectAppLaunchContextLaunched obj cb SignalConnectAfter

connectAppLaunchContextLaunched :: (GObject a, MonadIO m) =>
                                   a -> AppLaunchContextLaunchedCallback -> SignalConnectMode -> m SignalHandlerId
connectAppLaunchContextLaunched obj cb after = liftIO $ do
    cb' <- mkAppLaunchContextLaunchedCallback (appLaunchContextLaunchedCallbackWrapper cb)
    connectSignalFunPtr obj "launched" cb' after

type instance AttributeList AppLaunchContext = AppLaunchContextAttributeList
type AppLaunchContextAttributeList = ('[ ] :: [(Symbol, *)])

data AppLaunchContextLaunchFailedSignalInfo
instance SignalInfo AppLaunchContextLaunchFailedSignalInfo where
    type HaskellCallbackType AppLaunchContextLaunchFailedSignalInfo = AppLaunchContextLaunchFailedCallback
    connectSignal _ = connectAppLaunchContextLaunchFailed

data AppLaunchContextLaunchedSignalInfo
instance SignalInfo AppLaunchContextLaunchedSignalInfo where
    type HaskellCallbackType AppLaunchContextLaunchedSignalInfo = AppLaunchContextLaunchedCallback
    connectSignal _ = connectAppLaunchContextLaunched

type instance SignalList AppLaunchContext = AppLaunchContextSignalList
type AppLaunchContextSignalList = ('[ '("launch-failed", AppLaunchContextLaunchFailedSignalInfo), '("launched", AppLaunchContextLaunchedSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method AppLaunchContext::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- hInArgs : []
-- returnType : TInterface "Gio" "AppLaunchContext"
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_new" g_app_launch_context_new :: 
    IO (Ptr AppLaunchContext)


appLaunchContextNew ::
    (MonadIO m) =>
    m AppLaunchContext
appLaunchContextNew  = liftIO $ do
    result <- g_app_launch_context_new
    checkUnexpectedReturnNULL "g_app_launch_context_new" result
    result' <- (wrapObject AppLaunchContext) result
    return result'

-- method AppLaunchContext::get_display
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TInterface "Gio" "AppInfo", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "files", argType = TGList (TInterface "Gio" "File"), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TInterface "Gio" "AppInfo", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "files", argType = TGList (TInterface "Gio" "File"), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_get_display" g_app_launch_context_get_display :: 
    Ptr AppLaunchContext ->                 -- _obj : TInterface "Gio" "AppLaunchContext"
    Ptr AppInfo ->                          -- info : TInterface "Gio" "AppInfo"
    Ptr (GList (Ptr File)) ->               -- files : TGList (TInterface "Gio" "File")
    IO CString


appLaunchContextGetDisplay ::
    (MonadIO m, AppLaunchContextK a, AppInfoK b, FileK c) =>
    a ->                                    -- _obj
    b ->                                    -- info
    [c] ->                                  -- files
    m T.Text
appLaunchContextGetDisplay _obj info files = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let info' = unsafeManagedPtrCastPtr info
    let files' = map unsafeManagedPtrCastPtr files
    files'' <- packGList files'
    result <- g_app_launch_context_get_display _obj' info' files''
    checkUnexpectedReturnNULL "g_app_launch_context_get_display" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    touchManagedPtr info
    mapM_ touchManagedPtr files
    g_list_free files''
    return result'

-- method AppLaunchContext::get_environment
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TCArray True (-1) (-1) (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_get_environment" g_app_launch_context_get_environment :: 
    Ptr AppLaunchContext ->                 -- _obj : TInterface "Gio" "AppLaunchContext"
    IO (Ptr CString)


appLaunchContextGetEnvironment ::
    (MonadIO m, AppLaunchContextK a) =>
    a ->                                    -- _obj
    m [T.Text]
appLaunchContextGetEnvironment _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_app_launch_context_get_environment _obj'
    checkUnexpectedReturnNULL "g_app_launch_context_get_environment" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr _obj
    return result'

-- method AppLaunchContext::get_startup_notify_id
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TInterface "Gio" "AppInfo", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "files", argType = TGList (TInterface "Gio" "File"), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TInterface "Gio" "AppInfo", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "files", argType = TGList (TInterface "Gio" "File"), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_get_startup_notify_id" g_app_launch_context_get_startup_notify_id :: 
    Ptr AppLaunchContext ->                 -- _obj : TInterface "Gio" "AppLaunchContext"
    Ptr AppInfo ->                          -- info : TInterface "Gio" "AppInfo"
    Ptr (GList (Ptr File)) ->               -- files : TGList (TInterface "Gio" "File")
    IO CString


appLaunchContextGetStartupNotifyId ::
    (MonadIO m, AppLaunchContextK a, AppInfoK b, FileK c) =>
    a ->                                    -- _obj
    b ->                                    -- info
    [c] ->                                  -- files
    m T.Text
appLaunchContextGetStartupNotifyId _obj info files = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let info' = unsafeManagedPtrCastPtr info
    let files' = map unsafeManagedPtrCastPtr files
    files'' <- packGList files'
    result <- g_app_launch_context_get_startup_notify_id _obj' info' files''
    checkUnexpectedReturnNULL "g_app_launch_context_get_startup_notify_id" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr _obj
    touchManagedPtr info
    mapM_ touchManagedPtr files
    g_list_free files''
    return result'

-- method AppLaunchContext::launch_failed
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "startup_notify_id", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "startup_notify_id", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_launch_failed" g_app_launch_context_launch_failed :: 
    Ptr AppLaunchContext ->                 -- _obj : TInterface "Gio" "AppLaunchContext"
    CString ->                              -- startup_notify_id : TBasicType TUTF8
    IO ()


appLaunchContextLaunchFailed ::
    (MonadIO m, AppLaunchContextK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- startup_notify_id
    m ()
appLaunchContextLaunchFailed _obj startup_notify_id = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    startup_notify_id' <- textToCString startup_notify_id
    g_app_launch_context_launch_failed _obj' startup_notify_id'
    touchManagedPtr _obj
    freeMem startup_notify_id'
    return ()

-- method AppLaunchContext::setenv
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "variable", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "variable", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "value", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_setenv" g_app_launch_context_setenv :: 
    Ptr AppLaunchContext ->                 -- _obj : TInterface "Gio" "AppLaunchContext"
    CString ->                              -- variable : TBasicType TUTF8
    CString ->                              -- value : TBasicType TUTF8
    IO ()


appLaunchContextSetenv ::
    (MonadIO m, AppLaunchContextK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- variable
    T.Text ->                               -- value
    m ()
appLaunchContextSetenv _obj variable value = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    variable' <- textToCString variable
    value' <- textToCString value
    g_app_launch_context_setenv _obj' variable' value'
    touchManagedPtr _obj
    freeMem variable'
    freeMem value'
    return ()

-- method AppLaunchContext::unsetenv
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "variable", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AppLaunchContext", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "variable", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_app_launch_context_unsetenv" g_app_launch_context_unsetenv :: 
    Ptr AppLaunchContext ->                 -- _obj : TInterface "Gio" "AppLaunchContext"
    CString ->                              -- variable : TBasicType TUTF8
    IO ()


appLaunchContextUnsetenv ::
    (MonadIO m, AppLaunchContextK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- variable
    m ()
appLaunchContextUnsetenv _obj variable = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    variable' <- textToCString variable
    g_app_launch_context_unsetenv _obj' variable'
    touchManagedPtr _obj
    freeMem variable'
    return ()