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

'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' provides access to the icons associated with
web sites.

WebKit will automatically look for available icons in link elements
on opened pages as well as an existing favicon.ico and load the
images found into a memory cache if possible. That cache is frozen
to an on-disk database for persistence.

The database is disabled by default. In order for icons to be
stored and accessed, you will need to set an icon database path
using 'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseSetPath'. Disable the database
again passing 'Nothing' to the previous call.

If WebKitWebSettings::enable-private-browsing is 'True' new icons
won\'t be added to the on-disk database and no existing icons will
be deleted from it. Nevertheless, WebKit will still store them in
the in-memory cache during the current execution.
-}

module GI.WebKit.Objects.FaviconDatabase
    ( 

-- * Exported types
    FaviconDatabase(..)                     ,
    IsFaviconDatabase                       ,
    toFaviconDatabase                       ,
    noFaviconDatabase                       ,


 -- * Methods
-- ** clear #method:clear#
    FaviconDatabaseClearMethodInfo          ,
    faviconDatabaseClear                    ,


-- ** getFaviconPixbuf #method:getFaviconPixbuf#
    FaviconDatabaseGetFaviconPixbufMethodInfo,
    faviconDatabaseGetFaviconPixbuf         ,


-- ** getFaviconPixbufFinish #method:getFaviconPixbufFinish#
    FaviconDatabaseGetFaviconPixbufFinishMethodInfo,
    faviconDatabaseGetFaviconPixbufFinish   ,


-- ** getFaviconUri #method:getFaviconUri#
    FaviconDatabaseGetFaviconUriMethodInfo  ,
    faviconDatabaseGetFaviconUri            ,


-- ** getPath #method:getPath#
    FaviconDatabaseGetPathMethodInfo        ,
    faviconDatabaseGetPath                  ,


-- ** setPath #method:setPath#
    FaviconDatabaseSetPathMethodInfo        ,
    faviconDatabaseSetPath                  ,


-- ** tryGetFaviconPixbuf #method:tryGetFaviconPixbuf#
    FaviconDatabaseTryGetFaviconPixbufMethodInfo,
    faviconDatabaseTryGetFaviconPixbuf      ,




 -- * Properties
-- ** path #attr:path#
    FaviconDatabasePathPropertyInfo         ,
    clearFaviconDatabasePath                ,
    constructFaviconDatabasePath            ,
    faviconDatabasePath                     ,
    getFaviconDatabasePath                  ,
    setFaviconDatabasePath                  ,




 -- * Signals
-- ** iconLoaded #signal:iconLoaded#
    C_FaviconDatabaseIconLoadedCallback     ,
    FaviconDatabaseIconLoadedCallback       ,
    FaviconDatabaseIconLoadedSignalInfo     ,
    afterFaviconDatabaseIconLoaded          ,
    genClosure_FaviconDatabaseIconLoaded    ,
    mk_FaviconDatabaseIconLoadedCallback    ,
    noFaviconDatabaseIconLoadedCallback     ,
    onFaviconDatabaseIconLoaded             ,
    wrap_FaviconDatabaseIconLoadedCallback  ,




    ) 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 qualified GI.GdkPixbuf.Objects.Pixbuf as GdkPixbuf.Pixbuf
import qualified GI.Gio.Callbacks as Gio.Callbacks
import qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

newtype FaviconDatabase = FaviconDatabase (ManagedPtr FaviconDatabase)
foreign import ccall "webkit_favicon_database_get_type"
    c_webkit_favicon_database_get_type :: IO GType

instance GObject FaviconDatabase where
    gobjectType _ = c_webkit_favicon_database_get_type
    

class GObject o => IsFaviconDatabase o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError FaviconDatabase a) =>
    IsFaviconDatabase a
#endif
instance IsFaviconDatabase FaviconDatabase
instance GObject.Object.IsObject FaviconDatabase

toFaviconDatabase :: IsFaviconDatabase o => o -> IO FaviconDatabase
toFaviconDatabase = unsafeCastTo FaviconDatabase

noFaviconDatabase :: Maybe FaviconDatabase
noFaviconDatabase = Nothing

type family ResolveFaviconDatabaseMethod (t :: Symbol) (o :: *) :: * where
    ResolveFaviconDatabaseMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFaviconDatabaseMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFaviconDatabaseMethod "clear" o = FaviconDatabaseClearMethodInfo
    ResolveFaviconDatabaseMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFaviconDatabaseMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFaviconDatabaseMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFaviconDatabaseMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFaviconDatabaseMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFaviconDatabaseMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFaviconDatabaseMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFaviconDatabaseMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveFaviconDatabaseMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveFaviconDatabaseMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFaviconDatabaseMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFaviconDatabaseMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFaviconDatabaseMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFaviconDatabaseMethod "tryGetFaviconPixbuf" o = FaviconDatabaseTryGetFaviconPixbufMethodInfo
    ResolveFaviconDatabaseMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFaviconDatabaseMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFaviconDatabaseMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFaviconDatabaseMethod "getFaviconPixbuf" o = FaviconDatabaseGetFaviconPixbufMethodInfo
    ResolveFaviconDatabaseMethod "getFaviconPixbufFinish" o = FaviconDatabaseGetFaviconPixbufFinishMethodInfo
    ResolveFaviconDatabaseMethod "getFaviconUri" o = FaviconDatabaseGetFaviconUriMethodInfo
    ResolveFaviconDatabaseMethod "getPath" o = FaviconDatabaseGetPathMethodInfo
    ResolveFaviconDatabaseMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFaviconDatabaseMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFaviconDatabaseMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFaviconDatabaseMethod "setPath" o = FaviconDatabaseSetPathMethodInfo
    ResolveFaviconDatabaseMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFaviconDatabaseMethod l o = O.MethodResolutionFailed l o

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

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

-- signal FaviconDatabase::icon-loaded
type FaviconDatabaseIconLoadedCallback =
    T.Text ->
    IO ()

noFaviconDatabaseIconLoadedCallback :: Maybe FaviconDatabaseIconLoadedCallback
noFaviconDatabaseIconLoadedCallback = Nothing

type C_FaviconDatabaseIconLoadedCallback =
    Ptr () ->                               -- object
    CString ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_FaviconDatabaseIconLoadedCallback :: C_FaviconDatabaseIconLoadedCallback -> IO (FunPtr C_FaviconDatabaseIconLoadedCallback)

genClosure_FaviconDatabaseIconLoaded :: FaviconDatabaseIconLoadedCallback -> IO Closure
genClosure_FaviconDatabaseIconLoaded cb = do
    let cb' = wrap_FaviconDatabaseIconLoadedCallback cb
    mk_FaviconDatabaseIconLoadedCallback cb' >>= newCClosure


wrap_FaviconDatabaseIconLoadedCallback ::
    FaviconDatabaseIconLoadedCallback ->
    Ptr () ->
    CString ->
    Ptr () ->
    IO ()
wrap_FaviconDatabaseIconLoadedCallback _cb _ frameUri _ = do
    frameUri' <- cstringToText frameUri
    _cb  frameUri'


onFaviconDatabaseIconLoaded :: (GObject a, MonadIO m) => a -> FaviconDatabaseIconLoadedCallback -> m SignalHandlerId
onFaviconDatabaseIconLoaded obj cb = liftIO $ connectFaviconDatabaseIconLoaded obj cb SignalConnectBefore
afterFaviconDatabaseIconLoaded :: (GObject a, MonadIO m) => a -> FaviconDatabaseIconLoadedCallback -> m SignalHandlerId
afterFaviconDatabaseIconLoaded obj cb = connectFaviconDatabaseIconLoaded obj cb SignalConnectAfter

connectFaviconDatabaseIconLoaded :: (GObject a, MonadIO m) =>
                                    a -> FaviconDatabaseIconLoadedCallback -> SignalConnectMode -> m SignalHandlerId
connectFaviconDatabaseIconLoaded obj cb after = liftIO $ do
    let cb' = wrap_FaviconDatabaseIconLoadedCallback cb
    cb'' <- mk_FaviconDatabaseIconLoadedCallback cb'
    connectSignalFunPtr obj "icon-loaded" cb'' after

-- VVV Prop "path"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Just False,Just True)

getFaviconDatabasePath :: (MonadIO m, IsFaviconDatabase o) => o -> m T.Text
getFaviconDatabasePath obj = liftIO $ checkUnexpectedNothing "getFaviconDatabasePath" $ getObjectPropertyString obj "path"

setFaviconDatabasePath :: (MonadIO m, IsFaviconDatabase o) => o -> T.Text -> m ()
setFaviconDatabasePath obj val = liftIO $ setObjectPropertyString obj "path" (Just val)

constructFaviconDatabasePath :: (IsFaviconDatabase o) => T.Text -> IO (GValueConstruct o)
constructFaviconDatabasePath val = constructObjectPropertyString "path" (Just val)

clearFaviconDatabasePath :: (MonadIO m, IsFaviconDatabase o) => o -> m ()
clearFaviconDatabasePath obj = liftIO $ setObjectPropertyString obj "path" (Nothing :: Maybe T.Text)

data FaviconDatabasePathPropertyInfo
instance AttrInfo FaviconDatabasePathPropertyInfo where
    type AttrAllowedOps FaviconDatabasePathPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FaviconDatabasePathPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint FaviconDatabasePathPropertyInfo = IsFaviconDatabase
    type AttrGetType FaviconDatabasePathPropertyInfo = T.Text
    type AttrLabel FaviconDatabasePathPropertyInfo = "path"
    type AttrOrigin FaviconDatabasePathPropertyInfo = FaviconDatabase
    attrGet _ = getFaviconDatabasePath
    attrSet _ = setFaviconDatabasePath
    attrConstruct _ = constructFaviconDatabasePath
    attrClear _ = clearFaviconDatabasePath

instance O.HasAttributeList FaviconDatabase
type instance O.AttributeList FaviconDatabase = FaviconDatabaseAttributeList
type FaviconDatabaseAttributeList = ('[ '("path", FaviconDatabasePathPropertyInfo)] :: [(Symbol, *)])

faviconDatabasePath :: AttrLabelProxy "path"
faviconDatabasePath = AttrLabelProxy

data FaviconDatabaseIconLoadedSignalInfo
instance SignalInfo FaviconDatabaseIconLoadedSignalInfo where
    type HaskellCallbackType FaviconDatabaseIconLoadedSignalInfo = FaviconDatabaseIconLoadedCallback
    connectSignal _ = connectFaviconDatabaseIconLoaded

type instance O.SignalList FaviconDatabase = FaviconDatabaseSignalList
type FaviconDatabaseSignalList = ('[ '("iconLoaded", FaviconDatabaseIconLoadedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method FaviconDatabase::clear
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_favicon_database_clear" webkit_favicon_database_clear :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    IO ()

{- |
Clears all icons from the database.

@since 1.8
-}
faviconDatabaseClear ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> m ()
faviconDatabaseClear database = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    webkit_favicon_database_clear database'
    touchManagedPtr database
    return ()

data FaviconDatabaseClearMethodInfo
instance (signature ~ (m ()), MonadIO m, IsFaviconDatabase a) => O.MethodInfo FaviconDatabaseClearMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseClear

-- method FaviconDatabase::get_favicon_pixbuf
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "page_uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "URI of the page containing the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "width", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the desired width for the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "height", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the desired height for the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A #GCancellable or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A #GAsyncReadyCallback to call when the request is\n           satisfied or %NULL if you don't care about the result.", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 6, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "The data to pass to @callback.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_favicon_database_get_favicon_pixbuf" webkit_favicon_database_get_favicon_pixbuf :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    CString ->                              -- page_uri : TBasicType TUTF8
    Word32 ->                               -- width : TBasicType TUInt
    Word32 ->                               -- height : TBasicType TUInt
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{- |
Asynchronously obtains a 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf' of the favicon for the given
page URI. The advantage of this method over
'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseTryGetFaviconPixbuf' is that it always returns the
cached icon if it\'s in the database asynchronously waiting for the
icon to be read from the database.

This is an asynchronous method. When the operation is finished, callback will
be invoked. You can then call 'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseGetFaviconPixbufFinish'
to get the result of the operation.
See also 'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseTryGetFaviconPixbuf'.

If /@width@/ and /@height@/ are both 0 then this method will return the
maximum available size for the icon. Note that if you specify a
different size the icon will be scaled each time you call this
function.

@since 1.8
-}
faviconDatabaseGetFaviconPixbuf ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> T.Text
    {- ^ /@pageUri@/: URI of the page containing the icon -}
    -> Word32
    {- ^ /@width@/: the desired width for the icon -}
    -> Word32
    {- ^ /@height@/: the desired height for the icon -}
    -> Maybe (b)
    {- ^ /@cancellable@/: A 'GI.Gio.Objects.Cancellable.Cancellable' or 'Nothing'. -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: A 'GI.Gio.Callbacks.AsyncReadyCallback' to call when the request is
           satisfied or 'Nothing' if you don\'t care about the result. -}
    -> m ()
faviconDatabaseGetFaviconPixbuf database pageUri width height cancellable callback = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    pageUri' <- textToCString pageUri
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
            poke ptrcallback jCallback'
            return jCallback'
    let userData = nullPtr
    webkit_favicon_database_get_favicon_pixbuf database' pageUri' width height maybeCancellable maybeCallback userData
    touchManagedPtr database
    whenJust cancellable touchManagedPtr
    freeMem pageUri'
    return ()

data FaviconDatabaseGetFaviconPixbufMethodInfo
instance (signature ~ (T.Text -> Word32 -> Word32 -> Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsFaviconDatabase a, Gio.Cancellable.IsCancellable b) => O.MethodInfo FaviconDatabaseGetFaviconPixbufMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseGetFaviconPixbuf

-- method FaviconDatabase::get_favicon_pixbuf_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GAsyncResult obtained from the #GAsyncReadyCallback passed to webkit_favicon_database_get_favicon_pixbuf()", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"}))
-- throws : True
-- Skip return : False

foreign import ccall "webkit_favicon_database_get_favicon_pixbuf_finish" webkit_favicon_database_get_favicon_pixbuf_finish :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GdkPixbuf.Pixbuf.Pixbuf)

{- |
Finishes an operation started with 'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseGetFaviconPixbuf'.

@since 1.8
-}
faviconDatabaseGetFaviconPixbufFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> b
    {- ^ /@result@/: A 'GI.Gio.Interfaces.AsyncResult.AsyncResult' obtained from the 'GI.Gio.Callbacks.AsyncReadyCallback' passed to 'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseGetFaviconPixbuf' -}
    -> m GdkPixbuf.Pixbuf.Pixbuf
    {- ^ __Returns:__ a new reference to a 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf', or 'Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
faviconDatabaseGetFaviconPixbufFinish database result_ = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    result_' <- unsafeManagedPtrCastPtr result_
    onException (do
        result <- propagateGError $ webkit_favicon_database_get_favicon_pixbuf_finish database' result_'
        checkUnexpectedReturnNULL "faviconDatabaseGetFaviconPixbufFinish" result
        result' <- (wrapObject GdkPixbuf.Pixbuf.Pixbuf) result
        touchManagedPtr database
        touchManagedPtr result_
        return result'
     ) (do
        return ()
     )

data FaviconDatabaseGetFaviconPixbufFinishMethodInfo
instance (signature ~ (b -> m GdkPixbuf.Pixbuf.Pixbuf), MonadIO m, IsFaviconDatabase a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo FaviconDatabaseGetFaviconPixbufFinishMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseGetFaviconPixbufFinish

-- method FaviconDatabase::get_favicon_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "page_uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "URI of the page containing the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "webkit_favicon_database_get_favicon_uri" webkit_favicon_database_get_favicon_uri :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    CString ->                              -- page_uri : TBasicType TUTF8
    IO CString

{- |
Obtains the URI for the favicon for the given page URI.
See also 'GI.WebKit.Objects.WebView.webViewGetIconUri'.

@since 1.8
-}
faviconDatabaseGetFaviconUri ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> T.Text
    {- ^ /@pageUri@/: URI of the page containing the icon -}
    -> m T.Text
    {- ^ __Returns:__ a newly allocated URI for the favicon, or 'Nothing' -}
faviconDatabaseGetFaviconUri database pageUri = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    pageUri' <- textToCString pageUri
    result <- webkit_favicon_database_get_favicon_uri database' pageUri'
    checkUnexpectedReturnNULL "faviconDatabaseGetFaviconUri" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr database
    freeMem pageUri'
    return result'

data FaviconDatabaseGetFaviconUriMethodInfo
instance (signature ~ (T.Text -> m T.Text), MonadIO m, IsFaviconDatabase a) => O.MethodInfo FaviconDatabaseGetFaviconUriMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseGetFaviconUri

-- method FaviconDatabase::get_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "webkit_favicon_database_get_path" webkit_favicon_database_get_path :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    IO CString

{- |
Determines the absolute path to the database folder on disk.

@since 1.8
-}
faviconDatabaseGetPath ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> m T.Text
    {- ^ __Returns:__ the absolute path of the database folder, or 'Nothing' -}
faviconDatabaseGetPath database = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    result <- webkit_favicon_database_get_path database'
    checkUnexpectedReturnNULL "faviconDatabaseGetPath" result
    result' <- cstringToText result
    touchManagedPtr database
    return result'

data FaviconDatabaseGetPathMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsFaviconDatabase a) => O.MethodInfo FaviconDatabaseGetPathMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseGetPath

-- method FaviconDatabase::set_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "an absolute path to the icon database folder\nor %NULL to disable the database", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_favicon_database_set_path" webkit_favicon_database_set_path :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    CString ->                              -- path : TBasicType TUTF8
    IO ()

{- |
Specifies the absolute path to the database folder on disk. The
icon database will only be enabled after a call to this method.

Passing 'Nothing' or \"\" as path disables the icon database.

@since 1.8
-}
faviconDatabaseSetPath ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> Maybe (T.Text)
    {- ^ /@path@/: an absolute path to the icon database folder
or 'Nothing' to disable the database -}
    -> m ()
faviconDatabaseSetPath database path = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    maybePath <- case path of
        Nothing -> return nullPtr
        Just jPath -> do
            jPath' <- textToCString jPath
            return jPath'
    webkit_favicon_database_set_path database' maybePath
    touchManagedPtr database
    freeMem maybePath
    return ()

data FaviconDatabaseSetPathMethodInfo
instance (signature ~ (Maybe (T.Text) -> m ()), MonadIO m, IsFaviconDatabase a) => O.MethodInfo FaviconDatabaseSetPathMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseSetPath

-- method FaviconDatabase::try_get_favicon_pixbuf
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "database", argType = TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitFaviconDatabase", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "page_uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "URI of the page containing the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "width", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the desired width for the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "height", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the desired height for the icon", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GdkPixbuf", name = "Pixbuf"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_favicon_database_try_get_favicon_pixbuf" webkit_favicon_database_try_get_favicon_pixbuf :: 
    Ptr FaviconDatabase ->                  -- database : TInterface (Name {namespace = "WebKit", name = "FaviconDatabase"})
    CString ->                              -- page_uri : TBasicType TUTF8
    Word32 ->                               -- width : TBasicType TUInt
    Word32 ->                               -- height : TBasicType TUInt
    IO (Ptr GdkPixbuf.Pixbuf.Pixbuf)

{- |
Obtains a 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf' of the favicon for the given page URI, or
'Nothing' if there is no icon for the given page or it hasn\'t been
loaded from disk yet. Use 'GI.WebKit.Objects.FaviconDatabase.faviconDatabaseGetFaviconUri'
if you need to distinguish these cases.  To make sure this method
will return a valid icon when the given URI has one, you should
connect to 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase'::@/icon-loaded/@ and use this function
in the callback.

If /@width@/ and /@height@/ ar both 0 then this method will return the
maximum available size for the icon. Note that if you specify a
different size the icon will be scaled each time you call this
function.

@since 1.8
-}
faviconDatabaseTryGetFaviconPixbuf ::
    (B.CallStack.HasCallStack, MonadIO m, IsFaviconDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.FaviconDatabase.FaviconDatabase' -}
    -> T.Text
    {- ^ /@pageUri@/: URI of the page containing the icon -}
    -> Word32
    {- ^ /@width@/: the desired width for the icon -}
    -> Word32
    {- ^ /@height@/: the desired height for the icon -}
    -> m GdkPixbuf.Pixbuf.Pixbuf
    {- ^ __Returns:__ a new reference to a 'GI.GdkPixbuf.Objects.Pixbuf.Pixbuf', or 'Nothing'
if the given URI doesn\'t have an icon or it hasn\'t been loaded yet. -}
faviconDatabaseTryGetFaviconPixbuf database pageUri width height = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    pageUri' <- textToCString pageUri
    result <- webkit_favicon_database_try_get_favicon_pixbuf database' pageUri' width height
    checkUnexpectedReturnNULL "faviconDatabaseTryGetFaviconPixbuf" result
    result' <- (wrapObject GdkPixbuf.Pixbuf.Pixbuf) result
    touchManagedPtr database
    freeMem pageUri'
    return result'

data FaviconDatabaseTryGetFaviconPixbufMethodInfo
instance (signature ~ (T.Text -> Word32 -> Word32 -> m GdkPixbuf.Pixbuf.Pixbuf), MonadIO m, IsFaviconDatabase a) => O.MethodInfo FaviconDatabaseTryGetFaviconPixbufMethodInfo a signature where
    overloadedMethod _ = faviconDatabaseTryGetFaviconPixbuf