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

-- * Exported types
    Cache(..)                               ,
    CacheK                                  ,
    toCache                                 ,
    noCache                                 ,


 -- * Methods
-- ** cacheClear
    cacheClear                              ,


-- ** cacheDump
    cacheDump                               ,


-- ** cacheFlush
    cacheFlush                              ,


-- ** cacheGetMaxSize
    cacheGetMaxSize                         ,


-- ** cacheLoad
    cacheLoad                               ,


-- ** cacheNew
    cacheNew                                ,


-- ** cacheSetMaxSize
    cacheSetMaxSize                         ,




 -- * Properties
-- ** CacheDir
    CacheCacheDirPropertyInfo               ,
    constructCacheCacheDir                  ,
    getCacheCacheDir                        ,


-- ** CacheType
    CacheCacheTypePropertyInfo              ,
    constructCacheCacheType                 ,
    getCacheCacheType                       ,




    ) 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.GObject as GObject

newtype Cache = Cache (ForeignPtr Cache)
foreign import ccall "soup_cache_get_type"
    c_soup_cache_get_type :: IO GType

type instance ParentTypes Cache = CacheParentTypes
type CacheParentTypes = '[GObject.Object, SessionFeature]

instance GObject Cache where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_soup_cache_get_type
    

class GObject o => CacheK o
instance (GObject o, IsDescendantOf Cache o) => CacheK o

toCache :: CacheK o => o -> IO Cache
toCache = unsafeCastTo Cache

noCache :: Maybe Cache
noCache = Nothing

-- VVV Prop "cache-dir"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getCacheCacheDir :: (MonadIO m, CacheK o) => o -> m T.Text
getCacheCacheDir obj = liftIO $ getObjectPropertyString obj "cache-dir"

constructCacheCacheDir :: T.Text -> IO ([Char], GValue)
constructCacheCacheDir val = constructObjectPropertyString "cache-dir" val

data CacheCacheDirPropertyInfo
instance AttrInfo CacheCacheDirPropertyInfo where
    type AttrAllowedOps CacheCacheDirPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CacheCacheDirPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint CacheCacheDirPropertyInfo = CacheK
    type AttrGetType CacheCacheDirPropertyInfo = T.Text
    type AttrLabel CacheCacheDirPropertyInfo = "Cache::cache-dir"
    attrGet _ = getCacheCacheDir
    attrSet _ = undefined
    attrConstruct _ = constructCacheCacheDir

-- VVV Prop "cache-type"
   -- Type: TInterface "Soup" "CacheType"
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getCacheCacheType :: (MonadIO m, CacheK o) => o -> m CacheType
getCacheCacheType obj = liftIO $ getObjectPropertyEnum obj "cache-type"

constructCacheCacheType :: CacheType -> IO ([Char], GValue)
constructCacheCacheType val = constructObjectPropertyEnum "cache-type" val

data CacheCacheTypePropertyInfo
instance AttrInfo CacheCacheTypePropertyInfo where
    type AttrAllowedOps CacheCacheTypePropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CacheCacheTypePropertyInfo = (~) CacheType
    type AttrBaseTypeConstraint CacheCacheTypePropertyInfo = CacheK
    type AttrGetType CacheCacheTypePropertyInfo = CacheType
    type AttrLabel CacheCacheTypePropertyInfo = "Cache::cache-type"
    attrGet _ = getCacheCacheType
    attrSet _ = undefined
    attrConstruct _ = constructCacheCacheType

type instance AttributeList Cache = CacheAttributeList
type CacheAttributeList = ('[ '("cache-dir", CacheCacheDirPropertyInfo), '("cache-type", CacheCacheTypePropertyInfo)] :: [(Symbol, *)])

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

-- method Cache::new
-- method type : Constructor
-- Args : [Arg {argName = "cache_dir", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cache_type", argType = TInterface "Soup" "CacheType", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "cache_dir", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cache_type", argType = TInterface "Soup" "CacheType", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "Cache"
-- throws : False
-- Skip return : False

foreign import ccall "soup_cache_new" soup_cache_new :: 
    CString ->                              -- cache_dir : TBasicType TUTF8
    CUInt ->                                -- cache_type : TInterface "Soup" "CacheType"
    IO (Ptr Cache)


cacheNew ::
    (MonadIO m) =>
    T.Text ->                               -- cache_dir
    CacheType ->                            -- cache_type
    m Cache
cacheNew cache_dir cache_type = liftIO $ do
    cache_dir' <- textToCString cache_dir
    let cache_type' = (fromIntegral . fromEnum) cache_type
    result <- soup_cache_new cache_dir' cache_type'
    checkUnexpectedReturnNULL "soup_cache_new" result
    result' <- (wrapObject Cache) result
    freeMem cache_dir'
    return result'

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

foreign import ccall "soup_cache_clear" soup_cache_clear :: 
    Ptr Cache ->                            -- _obj : TInterface "Soup" "Cache"
    IO ()


cacheClear ::
    (MonadIO m, CacheK a) =>
    a ->                                    -- _obj
    m ()
cacheClear _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    soup_cache_clear _obj'
    touchManagedPtr _obj
    return ()

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

foreign import ccall "soup_cache_dump" soup_cache_dump :: 
    Ptr Cache ->                            -- _obj : TInterface "Soup" "Cache"
    IO ()


cacheDump ::
    (MonadIO m, CacheK a) =>
    a ->                                    -- _obj
    m ()
cacheDump _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    soup_cache_dump _obj'
    touchManagedPtr _obj
    return ()

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

foreign import ccall "soup_cache_flush" soup_cache_flush :: 
    Ptr Cache ->                            -- _obj : TInterface "Soup" "Cache"
    IO ()


cacheFlush ::
    (MonadIO m, CacheK a) =>
    a ->                                    -- _obj
    m ()
cacheFlush _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    soup_cache_flush _obj'
    touchManagedPtr _obj
    return ()

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

foreign import ccall "soup_cache_get_max_size" soup_cache_get_max_size :: 
    Ptr Cache ->                            -- _obj : TInterface "Soup" "Cache"
    IO Word32


cacheGetMaxSize ::
    (MonadIO m, CacheK a) =>
    a ->                                    -- _obj
    m Word32
cacheGetMaxSize _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- soup_cache_get_max_size _obj'
    touchManagedPtr _obj
    return result

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

foreign import ccall "soup_cache_load" soup_cache_load :: 
    Ptr Cache ->                            -- _obj : TInterface "Soup" "Cache"
    IO ()


cacheLoad ::
    (MonadIO m, CacheK a) =>
    a ->                                    -- _obj
    m ()
cacheLoad _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    soup_cache_load _obj'
    touchManagedPtr _obj
    return ()

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

foreign import ccall "soup_cache_set_max_size" soup_cache_set_max_size :: 
    Ptr Cache ->                            -- _obj : TInterface "Soup" "Cache"
    Word32 ->                               -- max_size : TBasicType TUInt32
    IO ()


cacheSetMaxSize ::
    (MonadIO m, CacheK a) =>
    a ->                                    -- _obj
    Word32 ->                               -- max_size
    m ()
cacheSetMaxSize _obj max_size = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    soup_cache_set_max_size _obj' max_size
    touchManagedPtr _obj
    return ()