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

-- * Exported types
    Plugin(..)                              ,
    IsPlugin                                ,
    toPlugin                                ,
    noPlugin                                ,


 -- * Methods
-- ** getDescription #method:getDescription#
    PluginGetDescriptionMethodInfo          ,
    pluginGetDescription                    ,


-- ** getMimeInfoList #method:getMimeInfoList#
    PluginGetMimeInfoListMethodInfo         ,
    pluginGetMimeInfoList                   ,


-- ** getName #method:getName#
    PluginGetNameMethodInfo                 ,
    pluginGetName                           ,


-- ** getPath #method:getPath#
    PluginGetPathMethodInfo                 ,
    pluginGetPath                           ,




    ) 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.WebKit2.Structs.MimeInfo as WebKit2.MimeInfo

newtype Plugin = Plugin (ManagedPtr Plugin)
foreign import ccall "webkit_plugin_get_type"
    c_webkit_plugin_get_type :: IO GType

instance GObject Plugin where
    gobjectType _ = c_webkit_plugin_get_type
    

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

toPlugin :: IsPlugin o => o -> IO Plugin
toPlugin = unsafeCastTo Plugin

noPlugin :: Maybe Plugin
noPlugin = Nothing

type family ResolvePluginMethod (t :: Symbol) (o :: *) :: * where
    ResolvePluginMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePluginMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePluginMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePluginMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePluginMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePluginMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePluginMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePluginMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePluginMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePluginMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolvePluginMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolvePluginMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePluginMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePluginMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePluginMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePluginMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePluginMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePluginMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePluginMethod "getDescription" o = PluginGetDescriptionMethodInfo
    ResolvePluginMethod "getMimeInfoList" o = PluginGetMimeInfoListMethodInfo
    ResolvePluginMethod "getName" o = PluginGetNameMethodInfo
    ResolvePluginMethod "getPath" o = PluginGetPathMethodInfo
    ResolvePluginMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePluginMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePluginMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePluginMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePluginMethod l o = O.MethodResolutionFailed l o

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

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

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

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

-- method Plugin::get_description
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "plugin", argType = TInterface (Name {namespace = "WebKit2", name = "Plugin"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitPlugin", 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_plugin_get_description" webkit_plugin_get_description :: 
    Ptr Plugin ->                           -- plugin : TInterface (Name {namespace = "WebKit2", name = "Plugin"})
    IO CString

{- |
/No description available in the introspection data./
-}
pluginGetDescription ::
    (B.CallStack.HasCallStack, MonadIO m, IsPlugin a) =>
    a
    {- ^ /@plugin@/: a 'GI.WebKit2.Objects.Plugin.Plugin' -}
    -> m T.Text
    {- ^ __Returns:__ the description of the plugin. -}
pluginGetDescription plugin = liftIO $ do
    plugin' <- unsafeManagedPtrCastPtr plugin
    result <- webkit_plugin_get_description plugin'
    checkUnexpectedReturnNULL "pluginGetDescription" result
    result' <- cstringToText result
    touchManagedPtr plugin
    return result'

data PluginGetDescriptionMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsPlugin a) => O.MethodInfo PluginGetDescriptionMethodInfo a signature where
    overloadedMethod _ = pluginGetDescription

-- method Plugin::get_mime_info_list
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "plugin", argType = TInterface (Name {namespace = "WebKit2", name = "Plugin"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitPlugin", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TGList (TInterface (Name {namespace = "WebKit2", name = "MimeInfo"})))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_plugin_get_mime_info_list" webkit_plugin_get_mime_info_list :: 
    Ptr Plugin ->                           -- plugin : TInterface (Name {namespace = "WebKit2", name = "Plugin"})
    IO (Ptr (GList (Ptr WebKit2.MimeInfo.MimeInfo)))

{- |
Get information about MIME types handled by the plugin,
as a list of 'GI.WebKit2.Structs.MimeInfo.MimeInfo'.
-}
pluginGetMimeInfoList ::
    (B.CallStack.HasCallStack, MonadIO m, IsPlugin a) =>
    a
    {- ^ /@plugin@/: a 'GI.WebKit2.Objects.Plugin.Plugin' -}
    -> m [WebKit2.MimeInfo.MimeInfo]
    {- ^ __Returns:__ a 'GI.GLib.Structs.List.List' of 'GI.WebKit2.Structs.MimeInfo.MimeInfo'. -}
pluginGetMimeInfoList plugin = liftIO $ do
    plugin' <- unsafeManagedPtrCastPtr plugin
    result <- webkit_plugin_get_mime_info_list plugin'
    result' <- unpackGList result
    result'' <- mapM (newBoxed WebKit2.MimeInfo.MimeInfo) result'
    touchManagedPtr plugin
    return result''

data PluginGetMimeInfoListMethodInfo
instance (signature ~ (m [WebKit2.MimeInfo.MimeInfo]), MonadIO m, IsPlugin a) => O.MethodInfo PluginGetMimeInfoListMethodInfo a signature where
    overloadedMethod _ = pluginGetMimeInfoList

-- method Plugin::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "plugin", argType = TInterface (Name {namespace = "WebKit2", name = "Plugin"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitPlugin", 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_plugin_get_name" webkit_plugin_get_name :: 
    Ptr Plugin ->                           -- plugin : TInterface (Name {namespace = "WebKit2", name = "Plugin"})
    IO CString

{- |
/No description available in the introspection data./
-}
pluginGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsPlugin a) =>
    a
    {- ^ /@plugin@/: a 'GI.WebKit2.Objects.Plugin.Plugin' -}
    -> m T.Text
    {- ^ __Returns:__ the name of the plugin. -}
pluginGetName plugin = liftIO $ do
    plugin' <- unsafeManagedPtrCastPtr plugin
    result <- webkit_plugin_get_name plugin'
    checkUnexpectedReturnNULL "pluginGetName" result
    result' <- cstringToText result
    touchManagedPtr plugin
    return result'

data PluginGetNameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsPlugin a) => O.MethodInfo PluginGetNameMethodInfo a signature where
    overloadedMethod _ = pluginGetName

-- method Plugin::get_path
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "plugin", argType = TInterface (Name {namespace = "WebKit2", name = "Plugin"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitPlugin", 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_plugin_get_path" webkit_plugin_get_path :: 
    Ptr Plugin ->                           -- plugin : TInterface (Name {namespace = "WebKit2", name = "Plugin"})
    IO CString

{- |
/No description available in the introspection data./
-}
pluginGetPath ::
    (B.CallStack.HasCallStack, MonadIO m, IsPlugin a) =>
    a
    {- ^ /@plugin@/: a 'GI.WebKit2.Objects.Plugin.Plugin' -}
    -> m T.Text
    {- ^ __Returns:__ the absolute path where the plugin is installed. -}
pluginGetPath plugin = liftIO $ do
    plugin' <- unsafeManagedPtrCastPtr plugin
    result <- webkit_plugin_get_path plugin'
    checkUnexpectedReturnNULL "pluginGetPath" result
    result' <- cstringToText result
    touchManagedPtr plugin
    return result'

data PluginGetPathMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsPlugin a) => O.MethodInfo PluginGetPathMethodInfo a signature where
    overloadedMethod _ = pluginGetPath