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

This object allows you to query information about the plugins found
by the engine while scanning the usual directories. You can then
use the 'GI.WebKit.Objects.WebPlugin.WebPlugin' objects to get more information or
enable\/disable individual plugins.
-}

module GI.WebKit.Objects.WebPluginDatabase
    ( 

-- * Exported types
    WebPluginDatabase(..)                   ,
    IsWebPluginDatabase                     ,
    toWebPluginDatabase                     ,
    noWebPluginDatabase                     ,


 -- * Methods
-- ** getPluginForMimetype #method:getPluginForMimetype#
    WebPluginDatabaseGetPluginForMimetypeMethodInfo,
    webPluginDatabaseGetPluginForMimetype   ,


-- ** getPlugins #method:getPlugins#
    WebPluginDatabaseGetPluginsMethodInfo   ,
    webPluginDatabaseGetPlugins             ,


-- ** pluginsListFree #method:pluginsListFree#
    webPluginDatabasePluginsListFree        ,


-- ** refresh #method:refresh#
    WebPluginDatabaseRefreshMethodInfo      ,
    webPluginDatabaseRefresh                ,




    ) 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.WebKit.Objects.WebPlugin as WebKit.WebPlugin

newtype WebPluginDatabase = WebPluginDatabase (ManagedPtr WebPluginDatabase)
foreign import ccall "webkit_web_plugin_database_get_type"
    c_webkit_web_plugin_database_get_type :: IO GType

instance GObject WebPluginDatabase where
    gobjectType _ = c_webkit_web_plugin_database_get_type
    

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

toWebPluginDatabase :: IsWebPluginDatabase o => o -> IO WebPluginDatabase
toWebPluginDatabase = unsafeCastTo WebPluginDatabase

noWebPluginDatabase :: Maybe WebPluginDatabase
noWebPluginDatabase = Nothing

type family ResolveWebPluginDatabaseMethod (t :: Symbol) (o :: *) :: * where
    ResolveWebPluginDatabaseMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveWebPluginDatabaseMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveWebPluginDatabaseMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveWebPluginDatabaseMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveWebPluginDatabaseMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveWebPluginDatabaseMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveWebPluginDatabaseMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveWebPluginDatabaseMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveWebPluginDatabaseMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveWebPluginDatabaseMethod "refresh" o = WebPluginDatabaseRefreshMethodInfo
    ResolveWebPluginDatabaseMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveWebPluginDatabaseMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveWebPluginDatabaseMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveWebPluginDatabaseMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveWebPluginDatabaseMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveWebPluginDatabaseMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveWebPluginDatabaseMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveWebPluginDatabaseMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveWebPluginDatabaseMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveWebPluginDatabaseMethod "getPluginForMimetype" o = WebPluginDatabaseGetPluginForMimetypeMethodInfo
    ResolveWebPluginDatabaseMethod "getPlugins" o = WebPluginDatabaseGetPluginsMethodInfo
    ResolveWebPluginDatabaseMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveWebPluginDatabaseMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveWebPluginDatabaseMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveWebPluginDatabaseMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveWebPluginDatabaseMethod l o = O.MethodResolutionFailed l o

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

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

instance O.HasAttributeList WebPluginDatabase
type instance O.AttributeList WebPluginDatabase = WebPluginDatabaseAttributeList
type WebPluginDatabaseAttributeList = ('[ ] :: [(Symbol, *)])

type instance O.SignalList WebPluginDatabase = WebPluginDatabaseSignalList
type WebPluginDatabaseSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

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

foreign import ccall "webkit_web_plugin_database_get_plugin_for_mimetype" webkit_web_plugin_database_get_plugin_for_mimetype :: 
    Ptr WebPluginDatabase ->                -- database : TInterface (Name {namespace = "WebKit", name = "WebPluginDatabase"})
    CString ->                              -- mime_type : TBasicType TUTF8
    IO (Ptr WebKit.WebPlugin.WebPlugin)

{- |
Returns the 'GI.WebKit.Objects.WebPlugin.WebPlugin' that is handling /@mimeType@/ in the
/@database@/, or 'Nothing' if there\'s none doing so.

@since 1.3.8
-}
webPluginDatabaseGetPluginForMimetype ::
    (B.CallStack.HasCallStack, MonadIO m, IsWebPluginDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.WebPluginDatabase.WebPluginDatabase' -}
    -> T.Text
    {- ^ /@mimeType@/: a mime type -}
    -> m WebKit.WebPlugin.WebPlugin
    {- ^ __Returns:__ a 'GI.WebKit.Objects.WebPlugin.WebPlugin' -}
webPluginDatabaseGetPluginForMimetype database mimeType = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    mimeType' <- textToCString mimeType
    result <- webkit_web_plugin_database_get_plugin_for_mimetype database' mimeType'
    checkUnexpectedReturnNULL "webPluginDatabaseGetPluginForMimetype" result
    result' <- (wrapObject WebKit.WebPlugin.WebPlugin) result
    touchManagedPtr database
    freeMem mimeType'
    return result'

data WebPluginDatabaseGetPluginForMimetypeMethodInfo
instance (signature ~ (T.Text -> m WebKit.WebPlugin.WebPlugin), MonadIO m, IsWebPluginDatabase a) => O.MethodInfo WebPluginDatabaseGetPluginForMimetypeMethodInfo a signature where
    overloadedMethod _ = webPluginDatabaseGetPluginForMimetype

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

foreign import ccall "webkit_web_plugin_database_get_plugins" webkit_web_plugin_database_get_plugins :: 
    Ptr WebPluginDatabase ->                -- database : TInterface (Name {namespace = "WebKit", name = "WebPluginDatabase"})
    IO (Ptr (GSList (Ptr WebKit.WebPlugin.WebPlugin)))

{- |
Returns all 'GI.WebKit.Objects.WebPlugin.WebPlugin' available in /@database@/.
The returned list must be freed with 'GI.WebKit.Objects.WebPluginDatabase.webPluginDatabasePluginsListFree'

@since 1.3.8
-}
webPluginDatabaseGetPlugins ::
    (B.CallStack.HasCallStack, MonadIO m, IsWebPluginDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.WebPluginDatabase.WebPluginDatabase' -}
    -> m [WebKit.WebPlugin.WebPlugin]
    {- ^ __Returns:__ a 'GI.GLib.Structs.SList.SList' of 'GI.WebKit.Objects.WebPlugin.WebPlugin' -}
webPluginDatabaseGetPlugins database = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    result <- webkit_web_plugin_database_get_plugins database'
    result' <- unpackGSList result
    result'' <- mapM (wrapObject WebKit.WebPlugin.WebPlugin) result'
    g_slist_free result
    touchManagedPtr database
    return result''

data WebPluginDatabaseGetPluginsMethodInfo
instance (signature ~ (m [WebKit.WebPlugin.WebPlugin]), MonadIO m, IsWebPluginDatabase a) => O.MethodInfo WebPluginDatabaseGetPluginsMethodInfo a signature where
    overloadedMethod _ = webPluginDatabaseGetPlugins

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

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

{- |
Refreshes /@database@/ adding new plugins that are now in use and
removing those that have been disabled or are otherwise no longer
available.

@since 1.3.8
-}
webPluginDatabaseRefresh ::
    (B.CallStack.HasCallStack, MonadIO m, IsWebPluginDatabase a) =>
    a
    {- ^ /@database@/: a 'GI.WebKit.Objects.WebPluginDatabase.WebPluginDatabase' -}
    -> m ()
webPluginDatabaseRefresh database = liftIO $ do
    database' <- unsafeManagedPtrCastPtr database
    webkit_web_plugin_database_refresh database'
    touchManagedPtr database
    return ()

data WebPluginDatabaseRefreshMethodInfo
instance (signature ~ (m ()), MonadIO m, IsWebPluginDatabase a) => O.MethodInfo WebPluginDatabaseRefreshMethodInfo a signature where
    overloadedMethod _ = webPluginDatabaseRefresh

-- method WebPluginDatabase::plugins_list_free
-- method type : MemberFunction
-- Args : [Arg {argCName = "list", argType = TGSList (TInterface (Name {namespace = "WebKit", name = "WebPlugin"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSList of #WebKitWebPlugin", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_web_plugin_database_plugins_list_free" webkit_web_plugin_database_plugins_list_free :: 
    Ptr (GSList (Ptr WebKit.WebPlugin.WebPlugin)) -> -- list : TGSList (TInterface (Name {namespace = "WebKit", name = "WebPlugin"}))
    IO ()

{- |
Frees /@list@/.

@since 1.3.8
-}
webPluginDatabasePluginsListFree ::
    (B.CallStack.HasCallStack, MonadIO m, WebKit.WebPlugin.IsWebPlugin a) =>
    [a]
    {- ^ /@list@/: a 'GI.GLib.Structs.SList.SList' of 'GI.WebKit.Objects.WebPlugin.WebPlugin' -}
    -> m ()
webPluginDatabasePluginsListFree list = liftIO $ do
    list' <- mapM unsafeManagedPtrCastPtr list
    list'' <- packGSList list'
    webkit_web_plugin_database_plugins_list_free list''
    mapM_ touchManagedPtr list
    g_slist_free list''
    return ()