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

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Vte.Functions
    (

 -- * Methods
-- ** getEncodingSupported #method:getEncodingSupported#

    getEncodingSupported                    ,


-- ** getEncodings #method:getEncodings#

    getEncodings                            ,


-- ** getFeatures #method:getFeatures#

    getFeatures                             ,


-- ** getMajorVersion #method:getMajorVersion#

    getMajorVersion                         ,


-- ** getMicroVersion #method:getMicroVersion#

    getMicroVersion                         ,


-- ** getMinorVersion #method:getMinorVersion#

    getMinorVersion                         ,


-- ** getUserShell #method:getUserShell#

    getUserShell                            ,




    ) 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


-- function vte_get_user_shell
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TFileName)
-- throws : False
-- Skip return : False

foreign import ccall "vte_get_user_shell" vte_get_user_shell ::
    IO CString

{- |
Gets the user\'s shell, or 'Nothing'. In the latter case, the
system default (usually \"\/bin\/sh\") should be used.
-}
getUserShell ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m [Char]
    {- ^ __Returns:__ a newly allocated string with the
  user\'s shell, or 'Nothing' -}
getUserShell  = liftIO $ do
    result <- vte_get_user_shell
    checkUnexpectedReturnNULL "getUserShell" result
    result' <- cstringToString result
    freeMem result
    return result'


-- function vte_get_minor_version
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "vte_get_minor_version" vte_get_minor_version ::
    IO Word32

{- |
Returns the minor version of the VTE library at runtime.
Contrast this with 'GI.Vte.Constants.MINOR_VERSION' which represents
the version of the VTE library that the code was compiled
with.

/Since: 0.40/
-}
getMinorVersion ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Word32
    {- ^ __Returns:__ the minor version -}
getMinorVersion  = liftIO $ do
    result <- vte_get_minor_version
    return result


-- function vte_get_micro_version
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "vte_get_micro_version" vte_get_micro_version ::
    IO Word32

{- |
Returns the micro version of the VTE library at runtime.
Contrast this with 'GI.Vte.Constants.MICRO_VERSION' which represents
the version of the VTE library that the code was compiled
with.

/Since: 0.40/
-}
getMicroVersion ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Word32
    {- ^ __Returns:__ the micro version -}
getMicroVersion  = liftIO $ do
    result <- vte_get_micro_version
    return result


-- function vte_get_major_version
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "vte_get_major_version" vte_get_major_version ::
    IO Word32

{- |
Returns the major version of the VTE library at runtime.
Contrast this with 'GI.Vte.Constants.MAJOR_VERSION' which represents
the version of the VTE library that the code was compiled
with.

/Since: 0.40/
-}
getMajorVersion ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Word32
    {- ^ __Returns:__ the major version -}
getMajorVersion  = liftIO $ do
    result <- vte_get_major_version
    return result


-- function vte_get_features
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "vte_get_features" vte_get_features ::
    IO CString

{- |
Gets a list of features vte was compiled with.

/Since: 0.40/
-}
getFeatures ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m T.Text
    {- ^ __Returns:__ a string with features -}
getFeatures  = liftIO $ do
    result <- vte_get_features
    checkUnexpectedReturnNULL "getFeatures" result
    result' <- cstringToText result
    return result'


-- function vte_get_encodings
-- Args : [Arg {argCName = "include_aliases", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether to include alias names", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "vte_get_encodings" vte_get_encodings ::
    CInt ->                                 -- include_aliases : TBasicType TBoolean
    IO (Ptr CString)

{-# DEPRECATED getEncodings ["(Since version 0.60)"] #-}
{- |
Gets the list of supported legacy encodings.

If ICU support is not available, this returns an empty vector.
Note that UTF-8 is always supported; you can select it by
passing 'Nothing' to 'GI.Vte.Objects.Terminal.terminalSetEncoding'.

/Since: 0.60/
-}
getEncodings ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Bool
    {- ^ /@includeAliases@/: whether to include alias names -}
    -> m [T.Text]
    {- ^ __Returns:__ the list of supported encodings; free with
  'GI.GLib.Functions.strfreev' -}
getEncodings includeAliases = liftIO $ do
    let includeAliases' = (fromIntegral . fromEnum) includeAliases
    result <- vte_get_encodings includeAliases'
    checkUnexpectedReturnNULL "getEncodings" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    return result'


-- function vte_get_encoding_supported
-- Args : [Arg {argCName = "encoding", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the legacy encoding", 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 "vte_get_encoding_supported" vte_get_encoding_supported ::
    CString ->                              -- encoding : TBasicType TUTF8
    IO CInt

{-# DEPRECATED getEncodingSupported ["(Since version 0.60)"] #-}
{- |
Queries whether the legacy encoding /@encoding@/ is supported.

If ICU support is not available, this function always returns 'False'.

Note that UTF-8 is always supported; you can select it by
passing 'Nothing' to 'GI.Vte.Objects.Terminal.terminalSetEncoding'.

/Since: 0.60/
-}
getEncodingSupported ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@encoding@/: the name of the legacy encoding -}
    -> m Bool
    {- ^ __Returns:__ 'True' iff the legacy encoding /@encoding@/ is supported -}
getEncodingSupported encoding = liftIO $ do
    encoding' <- textToCString encoding
    result <- vte_get_encoding_supported encoding'
    let result' = (/= 0) result
    freeMem encoding'
    return result'