{- |
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(..)                         ,
    IsCookieJarDB                           ,
    toCookieJarDB                           ,
    noCookieJarDB                           ,


 -- * Methods
-- ** new #method:new#
    cookieJarDBNew                          ,




 -- * Properties
-- ** filename #attr:filename#
    CookieJarDBFilenamePropertyInfo         ,
    constructCookieJarDBFilename            ,
    cookieJarDBFilename                     ,
    getCookieJarDBFilename                  ,




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

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Soup.Interfaces.SessionFeature as Soup.SessionFeature
import {-# SOURCE #-} qualified GI.Soup.Objects.CookieJar as Soup.CookieJar

newtype CookieJarDB = CookieJarDB (ManagedPtr CookieJarDB)
foreign import ccall "soup_cookie_jar_db_get_type"
    c_soup_cookie_jar_db_get_type :: IO GType

instance GObject CookieJarDB where
    gobjectType _ = c_soup_cookie_jar_db_get_type
    

class GObject o => IsCookieJarDB o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError CookieJarDB a) =>
    IsCookieJarDB a
#endif
instance IsCookieJarDB CookieJarDB
instance Soup.CookieJar.IsCookieJar CookieJarDB
instance GObject.Object.IsObject CookieJarDB
instance Soup.SessionFeature.IsSessionFeature CookieJarDB

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

noCookieJarDB :: Maybe CookieJarDB
noCookieJarDB = Nothing

type family ResolveCookieJarDBMethod (t :: Symbol) (o :: *) :: * where
    ResolveCookieJarDBMethod "addCookie" o = Soup.CookieJar.CookieJarAddCookieMethodInfo
    ResolveCookieJarDBMethod "addCookieWithFirstParty" o = Soup.CookieJar.CookieJarAddCookieWithFirstPartyMethodInfo
    ResolveCookieJarDBMethod "addFeature" o = Soup.SessionFeature.SessionFeatureAddFeatureMethodInfo
    ResolveCookieJarDBMethod "allCookies" o = Soup.CookieJar.CookieJarAllCookiesMethodInfo
    ResolveCookieJarDBMethod "attach" o = Soup.SessionFeature.SessionFeatureAttachMethodInfo
    ResolveCookieJarDBMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCookieJarDBMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCookieJarDBMethod "deleteCookie" o = Soup.CookieJar.CookieJarDeleteCookieMethodInfo
    ResolveCookieJarDBMethod "detach" o = Soup.SessionFeature.SessionFeatureDetachMethodInfo
    ResolveCookieJarDBMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCookieJarDBMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCookieJarDBMethod "hasFeature" o = Soup.SessionFeature.SessionFeatureHasFeatureMethodInfo
    ResolveCookieJarDBMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCookieJarDBMethod "isPersistent" o = Soup.CookieJar.CookieJarIsPersistentMethodInfo
    ResolveCookieJarDBMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCookieJarDBMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCookieJarDBMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveCookieJarDBMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCookieJarDBMethod "removeFeature" o = Soup.SessionFeature.SessionFeatureRemoveFeatureMethodInfo
    ResolveCookieJarDBMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveCookieJarDBMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveCookieJarDBMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCookieJarDBMethod "save" o = Soup.CookieJar.CookieJarSaveMethodInfo
    ResolveCookieJarDBMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCookieJarDBMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCookieJarDBMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCookieJarDBMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveCookieJarDBMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCookieJarDBMethod "getAcceptPolicy" o = Soup.CookieJar.CookieJarGetAcceptPolicyMethodInfo
    ResolveCookieJarDBMethod "getCookieList" o = Soup.CookieJar.CookieJarGetCookieListMethodInfo
    ResolveCookieJarDBMethod "getCookies" o = Soup.CookieJar.CookieJarGetCookiesMethodInfo
    ResolveCookieJarDBMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCookieJarDBMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCookieJarDBMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCookieJarDBMethod "setAcceptPolicy" o = Soup.CookieJar.CookieJarSetAcceptPolicyMethodInfo
    ResolveCookieJarDBMethod "setCookie" o = Soup.CookieJar.CookieJarSetCookieMethodInfo
    ResolveCookieJarDBMethod "setCookieWithFirstParty" o = Soup.CookieJar.CookieJarSetCookieWithFirstPartyMethodInfo
    ResolveCookieJarDBMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCookieJarDBMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCookieJarDBMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCookieJarDBMethod t CookieJarDB, O.MethodInfo info CookieJarDB p) => O.IsLabelProxy t (CookieJarDB -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveCookieJarDBMethod t CookieJarDB, O.MethodInfo info CookieJarDB p) => O.IsLabel t (CookieJarDB -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

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

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

constructCookieJarDBFilename :: (IsCookieJarDB o) => T.Text -> IO (GValueConstruct o)
constructCookieJarDBFilename val = constructObjectPropertyString "filename" (Just val)

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

instance O.HasAttributeList CookieJarDB
type instance O.AttributeList CookieJarDB = CookieJarDBAttributeList
type CookieJarDBAttributeList = ('[ '("acceptPolicy", Soup.CookieJar.CookieJarAcceptPolicyPropertyInfo), '("filename", CookieJarDBFilenamePropertyInfo), '("readOnly", Soup.CookieJar.CookieJarReadOnlyPropertyInfo)] :: [(Symbol, *)])

cookieJarDBFilename :: AttrLabelProxy "filename"
cookieJarDBFilename = AttrLabelProxy

type instance O.SignalList CookieJarDB = CookieJarDBSignalList
type CookieJarDBSignalList = ('[ '("changed", Soup.CookieJar.CookieJarChangedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method CookieJarDB::new
-- method type : Constructor
-- Args : [Arg {argCName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the filename to read to/write from, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "read_only", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "%TRUE if @filename is read-only", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "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)

{- |
Creates a 'GI.Soup.Objects.CookieJarDB.CookieJarDB'.

/@filename@/ will be read in at startup to create an initial set of
cookies. If /@readOnly@/ is 'False', then the non-session cookies will
be written to /@filename@/ when the \'changed\' signal is emitted from
the jar. (If /@readOnly@/ is 'True', then the cookie jar will only be
used for this session, and changes made to it will be lost when the
jar is destroyed.)

@since 2.42
-}
cookieJarDBNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@filename@/: the filename to read to\/write from, or 'Nothing' -}
    -> Bool
    {- ^ /@readOnly@/: 'True' if /@filename@/ is read-only -}
    -> m CookieJarDB
    {- ^ __Returns:__ the new 'GI.Soup.Objects.CookieJar.CookieJar' -}
cookieJarDBNew filename readOnly = liftIO $ do
    filename' <- textToCString filename
    let readOnly' = (fromIntegral . fromEnum) readOnly
    result <- soup_cookie_jar_db_new filename' readOnly'
    checkUnexpectedReturnNULL "cookieJarDBNew" result
    result' <- (wrapObject CookieJarDB) result
    freeMem filename'
    return result'