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

-- * Exported types
    CookieJarDB(..)                         ,
    CookieJarDBK                            ,
    toCookieJarDB                           ,
    noCookieJarDB                           ,


 -- * Methods
-- ** cookieJarDBNew
    cookieJarDBNew                          ,




 -- * Properties
-- ** Filename
    CookieJarDBFilenamePropertyInfo         ,
    constructCookieJarDBFilename            ,
    getCookieJarDBFilename                  ,




    ) 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 CookieJarDB = CookieJarDB (ForeignPtr CookieJarDB)
foreign import ccall "soup_cookie_jar_db_get_type"
    c_soup_cookie_jar_db_get_type :: IO GType

type instance ParentTypes CookieJarDB = CookieJarDBParentTypes
type CookieJarDBParentTypes = '[CookieJar, GObject.Object, SessionFeature]

instance GObject CookieJarDB where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_soup_cookie_jar_db_get_type
    

class GObject o => CookieJarDBK o
instance (GObject o, IsDescendantOf CookieJarDB o) => CookieJarDBK o

toCookieJarDB :: CookieJarDBK o => o -> IO CookieJarDB
toCookieJarDB = unsafeCastTo CookieJarDB

noCookieJarDB :: Maybe CookieJarDB
noCookieJarDB = Nothing

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

getCookieJarDBFilename :: (MonadIO m, CookieJarDBK o) => o -> m T.Text
getCookieJarDBFilename obj = liftIO $ getObjectPropertyString obj "filename"

constructCookieJarDBFilename :: T.Text -> IO ([Char], GValue)
constructCookieJarDBFilename val = constructObjectPropertyString "filename" val

data CookieJarDBFilenamePropertyInfo
instance AttrInfo CookieJarDBFilenamePropertyInfo where
    type AttrAllowedOps CookieJarDBFilenamePropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint CookieJarDBFilenamePropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint CookieJarDBFilenamePropertyInfo = CookieJarDBK
    type AttrGetType CookieJarDBFilenamePropertyInfo = T.Text
    type AttrLabel CookieJarDBFilenamePropertyInfo = "CookieJarDB::filename"
    attrGet _ = getCookieJarDBFilename
    attrSet _ = undefined
    attrConstruct _ = constructCookieJarDBFilename

type instance AttributeList CookieJarDB = CookieJarDBAttributeList
type CookieJarDBAttributeList = ('[ '("accept-policy", CookieJarAcceptPolicyPropertyInfo), '("filename", CookieJarDBFilenamePropertyInfo), '("read-only", CookieJarReadOnlyPropertyInfo)] :: [(Symbol, *)])

type instance SignalList CookieJarDB = CookieJarDBSignalList
type CookieJarDBSignalList = ('[ '("changed", CookieJarChangedSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

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

foreign import ccall "soup_cookie_jar_db_new" soup_cookie_jar_db_new :: 
    CString ->                              -- filename : TBasicType TUTF8
    CInt ->                                 -- read_only : TBasicType TBoolean
    IO (Ptr CookieJarDB)


cookieJarDBNew ::
    (MonadIO m) =>
    T.Text ->                               -- filename
    Bool ->                                 -- read_only
    m CookieJarDB
cookieJarDBNew filename read_only = liftIO $ do
    filename' <- textToCString filename
    let read_only' = (fromIntegral . fromEnum) read_only
    result <- soup_cookie_jar_db_new filename' read_only'
    checkUnexpectedReturnNULL "soup_cookie_jar_db_new" result
    result' <- (wrapObject CookieJarDB) result
    freeMem filename'
    return result'