{- |
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.CharsetConverter
    ( 

-- * Exported types
    CharsetConverter(..)                    ,
    CharsetConverterK                       ,
    toCharsetConverter                      ,
    noCharsetConverter                      ,


 -- * Methods
-- ** charsetConverterGetNumFallbacks
    charsetConverterGetNumFallbacks         ,


-- ** charsetConverterGetUseFallback
    charsetConverterGetUseFallback          ,


-- ** charsetConverterNew
    charsetConverterNew                     ,


-- ** charsetConverterSetUseFallback
    charsetConverterSetUseFallback          ,




 -- * Properties
-- ** FromCharset
    CharsetConverterFromCharsetPropertyInfo ,
    constructCharsetConverterFromCharset    ,
    getCharsetConverterFromCharset          ,


-- ** ToCharset
    CharsetConverterToCharsetPropertyInfo   ,
    constructCharsetConverterToCharset      ,
    getCharsetConverterToCharset            ,


-- ** UseFallback
    CharsetConverterUseFallbackPropertyInfo ,
    constructCharsetConverterUseFallback    ,
    getCharsetConverterUseFallback          ,
    setCharsetConverterUseFallback          ,




    ) 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 CharsetConverter = CharsetConverter (ForeignPtr CharsetConverter)
foreign import ccall "g_charset_converter_get_type"
    c_g_charset_converter_get_type :: IO GType

type instance ParentTypes CharsetConverter = CharsetConverterParentTypes
type CharsetConverterParentTypes = '[GObject.Object, Converter, Initable]

instance GObject CharsetConverter where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_charset_converter_get_type
    

class GObject o => CharsetConverterK o
instance (GObject o, IsDescendantOf CharsetConverter o) => CharsetConverterK o

toCharsetConverter :: CharsetConverterK o => o -> IO CharsetConverter
toCharsetConverter = unsafeCastTo CharsetConverter

noCharsetConverter :: Maybe CharsetConverter
noCharsetConverter = Nothing

-- VVV Prop "from-charset"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getCharsetConverterFromCharset :: (MonadIO m, CharsetConverterK o) => o -> m T.Text
getCharsetConverterFromCharset obj = liftIO $ getObjectPropertyString obj "from-charset"

constructCharsetConverterFromCharset :: T.Text -> IO ([Char], GValue)
constructCharsetConverterFromCharset val = constructObjectPropertyString "from-charset" val

data CharsetConverterFromCharsetPropertyInfo
instance AttrInfo CharsetConverterFromCharsetPropertyInfo where
    type AttrAllowedOps CharsetConverterFromCharsetPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CharsetConverterFromCharsetPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint CharsetConverterFromCharsetPropertyInfo = CharsetConverterK
    type AttrGetType CharsetConverterFromCharsetPropertyInfo = T.Text
    type AttrLabel CharsetConverterFromCharsetPropertyInfo = "CharsetConverter::from-charset"
    attrGet _ = getCharsetConverterFromCharset
    attrSet _ = undefined
    attrConstruct _ = constructCharsetConverterFromCharset

-- VVV Prop "to-charset"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getCharsetConverterToCharset :: (MonadIO m, CharsetConverterK o) => o -> m T.Text
getCharsetConverterToCharset obj = liftIO $ getObjectPropertyString obj "to-charset"

constructCharsetConverterToCharset :: T.Text -> IO ([Char], GValue)
constructCharsetConverterToCharset val = constructObjectPropertyString "to-charset" val

data CharsetConverterToCharsetPropertyInfo
instance AttrInfo CharsetConverterToCharsetPropertyInfo where
    type AttrAllowedOps CharsetConverterToCharsetPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CharsetConverterToCharsetPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint CharsetConverterToCharsetPropertyInfo = CharsetConverterK
    type AttrGetType CharsetConverterToCharsetPropertyInfo = T.Text
    type AttrLabel CharsetConverterToCharsetPropertyInfo = "CharsetConverter::to-charset"
    attrGet _ = getCharsetConverterToCharset
    attrSet _ = undefined
    attrConstruct _ = constructCharsetConverterToCharset

-- VVV Prop "use-fallback"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstruct]

getCharsetConverterUseFallback :: (MonadIO m, CharsetConverterK o) => o -> m Bool
getCharsetConverterUseFallback obj = liftIO $ getObjectPropertyBool obj "use-fallback"

setCharsetConverterUseFallback :: (MonadIO m, CharsetConverterK o) => o -> Bool -> m ()
setCharsetConverterUseFallback obj val = liftIO $ setObjectPropertyBool obj "use-fallback" val

constructCharsetConverterUseFallback :: Bool -> IO ([Char], GValue)
constructCharsetConverterUseFallback val = constructObjectPropertyBool "use-fallback" val

data CharsetConverterUseFallbackPropertyInfo
instance AttrInfo CharsetConverterUseFallbackPropertyInfo where
    type AttrAllowedOps CharsetConverterUseFallbackPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CharsetConverterUseFallbackPropertyInfo = (~) Bool
    type AttrBaseTypeConstraint CharsetConverterUseFallbackPropertyInfo = CharsetConverterK
    type AttrGetType CharsetConverterUseFallbackPropertyInfo = Bool
    type AttrLabel CharsetConverterUseFallbackPropertyInfo = "CharsetConverter::use-fallback"
    attrGet _ = getCharsetConverterUseFallback
    attrSet _ = setCharsetConverterUseFallback
    attrConstruct _ = constructCharsetConverterUseFallback

type instance AttributeList CharsetConverter = CharsetConverterAttributeList
type CharsetConverterAttributeList = ('[ '("from-charset", CharsetConverterFromCharsetPropertyInfo), '("to-charset", CharsetConverterToCharsetPropertyInfo), '("use-fallback", CharsetConverterUseFallbackPropertyInfo)] :: [(Symbol, *)])

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

-- method CharsetConverter::new
-- method type : Constructor
-- Args : [Arg {argName = "to_charset", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "from_charset", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "to_charset", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "from_charset", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "CharsetConverter"
-- throws : True
-- Skip return : False

foreign import ccall "g_charset_converter_new" g_charset_converter_new :: 
    CString ->                              -- to_charset : TBasicType TUTF8
    CString ->                              -- from_charset : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr CharsetConverter)


charsetConverterNew ::
    (MonadIO m) =>
    T.Text ->                               -- to_charset
    T.Text ->                               -- from_charset
    m CharsetConverter
charsetConverterNew to_charset from_charset = liftIO $ do
    to_charset' <- textToCString to_charset
    from_charset' <- textToCString from_charset
    onException (do
        result <- propagateGError $ g_charset_converter_new to_charset' from_charset'
        checkUnexpectedReturnNULL "g_charset_converter_new" result
        result' <- (wrapObject CharsetConverter) result
        freeMem to_charset'
        freeMem from_charset'
        return result'
     ) (do
        freeMem to_charset'
        freeMem from_charset'
     )

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

foreign import ccall "g_charset_converter_get_num_fallbacks" g_charset_converter_get_num_fallbacks :: 
    Ptr CharsetConverter ->                 -- _obj : TInterface "Gio" "CharsetConverter"
    IO Word32


charsetConverterGetNumFallbacks ::
    (MonadIO m, CharsetConverterK a) =>
    a ->                                    -- _obj
    m Word32
charsetConverterGetNumFallbacks _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_charset_converter_get_num_fallbacks _obj'
    touchManagedPtr _obj
    return result

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

foreign import ccall "g_charset_converter_get_use_fallback" g_charset_converter_get_use_fallback :: 
    Ptr CharsetConverter ->                 -- _obj : TInterface "Gio" "CharsetConverter"
    IO CInt


charsetConverterGetUseFallback ::
    (MonadIO m, CharsetConverterK a) =>
    a ->                                    -- _obj
    m Bool
charsetConverterGetUseFallback _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_charset_converter_get_use_fallback _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "g_charset_converter_set_use_fallback" g_charset_converter_set_use_fallback :: 
    Ptr CharsetConverter ->                 -- _obj : TInterface "Gio" "CharsetConverter"
    CInt ->                                 -- use_fallback : TBasicType TBoolean
    IO ()


charsetConverterSetUseFallback ::
    (MonadIO m, CharsetConverterK a) =>
    a ->                                    -- _obj
    Bool ->                                 -- use_fallback
    m ()
charsetConverterSetUseFallback _obj use_fallback = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let use_fallback' = (fromIntegral . fromEnum) use_fallback
    g_charset_converter_set_use_fallback _obj' use_fallback'
    touchManagedPtr _obj
    return ()