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

This interface offers methods to query and manipulate parameter preset sets.
A preset is a bunch of property settings, together with meta data and a name.
The name of a preset serves as key for subsequent method calls to manipulate
single presets.
All instances of one type will share the list of presets. The list is created
on demand, if presets are not used, the list is not created.

The interface comes with a default implementation that serves most plugins.
Wrapper plugins will override most methods to implement support for the
native preset format of those wrapped plugins.
One method that is useful to be overridden is 'GI.Gst.Interfaces.Preset.presetGetPropertyNames'.
With that one can control which properties are saved and in which order.
When implementing support for read-only presets, one should set the vmethods
for 'GI.Gst.Interfaces.Preset.presetSavePreset' and 'GI.Gst.Interfaces.Preset.presetDeletePreset' to 'Nothing'.
Applications can use 'GI.Gst.Interfaces.Preset.presetIsEditable' to check for that.

The default implementation supports presets located in a system directory,
application specific directory and in the users home directory. When getting
a list of presets individual presets are read and overlaid in 1) system,
2) application and 3) user order. Whenever an earlier entry is newer, the
later entries will be updated. Since 1.8 you can also provide extra paths
where to find presets through the GST_PRESET_PATH environment variable.
Presets found in those paths will be considered as \"app presets\".
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Gst.Interfaces.Preset
    (

-- * Exported types
    Preset(..)                              ,
    noPreset                                ,
    IsPreset                                ,


 -- * Methods
-- ** deletePreset #method:deletePreset#

#if ENABLE_OVERLOADING
    PresetDeletePresetMethodInfo            ,
#endif
    presetDeletePreset                      ,


-- ** getAppDir #method:getAppDir#

    presetGetAppDir                         ,


-- ** getMeta #method:getMeta#

#if ENABLE_OVERLOADING
    PresetGetMetaMethodInfo                 ,
#endif
    presetGetMeta                           ,


-- ** getPresetNames #method:getPresetNames#

#if ENABLE_OVERLOADING
    PresetGetPresetNamesMethodInfo          ,
#endif
    presetGetPresetNames                    ,


-- ** getPropertyNames #method:getPropertyNames#

#if ENABLE_OVERLOADING
    PresetGetPropertyNamesMethodInfo        ,
#endif
    presetGetPropertyNames                  ,


-- ** isEditable #method:isEditable#

#if ENABLE_OVERLOADING
    PresetIsEditableMethodInfo              ,
#endif
    presetIsEditable                        ,


-- ** loadPreset #method:loadPreset#

#if ENABLE_OVERLOADING
    PresetLoadPresetMethodInfo              ,
#endif
    presetLoadPreset                        ,


-- ** renamePreset #method:renamePreset#

#if ENABLE_OVERLOADING
    PresetRenamePresetMethodInfo            ,
#endif
    presetRenamePreset                      ,


-- ** savePreset #method:savePreset#

#if ENABLE_OVERLOADING
    PresetSavePresetMethodInfo              ,
#endif
    presetSavePreset                        ,


-- ** setAppDir #method:setAppDir#

    presetSetAppDir                         ,


-- ** setMeta #method:setMeta#

#if ENABLE_OVERLOADING
    PresetSetMetaMethodInfo                 ,
#endif
    presetSetMeta                           ,




    ) 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.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
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 GHC.OverloadedLabels as OL


-- interface Preset 
-- | Memory-managed wrapper type.
newtype Preset = Preset (ManagedPtr Preset)
-- | A convenience alias for `Nothing` :: `Maybe` `Preset`.
noPreset :: Maybe Preset
noPreset = Nothing

#if ENABLE_OVERLOADING
type instance O.SignalList Preset = PresetSignalList
type PresetSignalList = ('[ ] :: [(Symbol, *)])

#endif

-- | Type class for types which implement `Preset`.
class ManagedPtrNewtype a => IsPreset a
instance IsPreset Preset
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr Preset where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing


#if ENABLE_OVERLOADING
type family ResolvePresetMethod (t :: Symbol) (o :: *) :: * where
    ResolvePresetMethod "deletePreset" o = PresetDeletePresetMethodInfo
    ResolvePresetMethod "isEditable" o = PresetIsEditableMethodInfo
    ResolvePresetMethod "loadPreset" o = PresetLoadPresetMethodInfo
    ResolvePresetMethod "renamePreset" o = PresetRenamePresetMethodInfo
    ResolvePresetMethod "savePreset" o = PresetSavePresetMethodInfo
    ResolvePresetMethod "getMeta" o = PresetGetMetaMethodInfo
    ResolvePresetMethod "getPresetNames" o = PresetGetPresetNamesMethodInfo
    ResolvePresetMethod "getPropertyNames" o = PresetGetPropertyNamesMethodInfo
    ResolvePresetMethod "setMeta" o = PresetSetMetaMethodInfo
    ResolvePresetMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePresetMethod t Preset, O.MethodInfo info Preset p) => OL.IsLabel t (Preset -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif

-- method Preset::delete_preset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "preset name to remove", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_delete_preset" gst_preset_delete_preset ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    CString ->                              -- name : TBasicType TUTF8
    IO CInt

{- |
Delete the given preset.
-}
presetDeletePreset ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> T.Text
    {- ^ /@name@/: preset name to remove -}
    -> m Bool
    {- ^ __Returns:__ 'True' for success, 'False' if e.g. there is no preset with that /@name@/ -}
presetDeletePreset preset name = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    name' <- textToCString name
    result <- gst_preset_delete_preset preset' name'
    let result' = (/= 0) result
    touchManagedPtr preset
    freeMem name'
    return result'

#if ENABLE_OVERLOADING
data PresetDeletePresetMethodInfo
instance (signature ~ (T.Text -> m Bool), MonadIO m, IsPreset a) => O.MethodInfo PresetDeletePresetMethodInfo a signature where
    overloadedMethod _ = presetDeletePreset

#endif

-- method Preset::get_meta
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "preset name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "tag", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "meta data item name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "value", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_get_meta" gst_preset_get_meta ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    CString ->                              -- name : TBasicType TUTF8
    CString ->                              -- tag : TBasicType TUTF8
    Ptr CString ->                          -- value : TBasicType TUTF8
    IO CInt

{- |
Gets the /@value@/ for an existing meta data /@tag@/. Meta data /@tag@/ names can be
something like e.g. \"comment\". Returned values need to be released when done.
-}
presetGetMeta ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> T.Text
    {- ^ /@name@/: preset name -}
    -> T.Text
    {- ^ /@tag@/: meta data item name -}
    -> m ((Bool, T.Text))
    {- ^ __Returns:__ 'True' for success, 'False' if e.g. there is no preset with that /@name@/
or no value for the given /@tag@/ -}
presetGetMeta preset name tag = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    name' <- textToCString name
    tag' <- textToCString tag
    value <- allocMem :: IO (Ptr CString)
    result <- gst_preset_get_meta preset' name' tag' value
    let result' = (/= 0) result
    value' <- peek value
    value'' <- cstringToText value'
    freeMem value'
    touchManagedPtr preset
    freeMem name'
    freeMem tag'
    freeMem value
    return (result', value'')

#if ENABLE_OVERLOADING
data PresetGetMetaMethodInfo
instance (signature ~ (T.Text -> T.Text -> m ((Bool, T.Text))), MonadIO m, IsPreset a) => O.MethodInfo PresetGetMetaMethodInfo a signature where
    overloadedMethod _ = presetGetMeta

#endif

-- method Preset::get_preset_names
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_get_preset_names" gst_preset_get_preset_names ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    IO (Ptr CString)

{- |
Get a copy of preset names as a 'Nothing' terminated string array.
-}
presetGetPresetNames ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> m [T.Text]
    {- ^ __Returns:__ 
    list with names, use 'GI.GLib.Functions.strfreev' after usage. -}
presetGetPresetNames preset = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    result <- gst_preset_get_preset_names preset'
    checkUnexpectedReturnNULL "presetGetPresetNames" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr preset
    return result'

#if ENABLE_OVERLOADING
data PresetGetPresetNamesMethodInfo
instance (signature ~ (m [T.Text]), MonadIO m, IsPreset a) => O.MethodInfo PresetGetPresetNamesMethodInfo a signature where
    overloadedMethod _ = presetGetPresetNames

#endif

-- method Preset::get_property_names
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_get_property_names" gst_preset_get_property_names ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    IO (Ptr CString)

{- |
Get a the names of the GObject properties that can be used for presets.
-}
presetGetPropertyNames ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> m [T.Text]
    {- ^ __Returns:__ an
  array of property names which should be freed with 'GI.GLib.Functions.strfreev' after use. -}
presetGetPropertyNames preset = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    result <- gst_preset_get_property_names preset'
    checkUnexpectedReturnNULL "presetGetPropertyNames" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr preset
    return result'

#if ENABLE_OVERLOADING
data PresetGetPropertyNamesMethodInfo
instance (signature ~ (m [T.Text]), MonadIO m, IsPreset a) => O.MethodInfo PresetGetPropertyNamesMethodInfo a signature where
    overloadedMethod _ = presetGetPropertyNames

#endif

-- method Preset::is_editable
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_is_editable" gst_preset_is_editable ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    IO CInt

{- |
Check if one can add new presets, change existing ones and remove presets.

/Since: 1.6/
-}
presetIsEditable ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if presets are editable or 'False' if they are static -}
presetIsEditable preset = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    result <- gst_preset_is_editable preset'
    let result' = (/= 0) result
    touchManagedPtr preset
    return result'

#if ENABLE_OVERLOADING
data PresetIsEditableMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsPreset a) => O.MethodInfo PresetIsEditableMethodInfo a signature where
    overloadedMethod _ = presetIsEditable

#endif

-- method Preset::load_preset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "preset name to load", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_load_preset" gst_preset_load_preset ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    CString ->                              -- name : TBasicType TUTF8
    IO CInt

{- |
Load the given preset.
-}
presetLoadPreset ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> T.Text
    {- ^ /@name@/: preset name to load -}
    -> m Bool
    {- ^ __Returns:__ 'True' for success, 'False' if e.g. there is no preset with that /@name@/ -}
presetLoadPreset preset name = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    name' <- textToCString name
    result <- gst_preset_load_preset preset' name'
    let result' = (/= 0) result
    touchManagedPtr preset
    freeMem name'
    return result'

#if ENABLE_OVERLOADING
data PresetLoadPresetMethodInfo
instance (signature ~ (T.Text -> m Bool), MonadIO m, IsPreset a) => O.MethodInfo PresetLoadPresetMethodInfo a signature where
    overloadedMethod _ = presetLoadPreset

#endif

-- method Preset::rename_preset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "old_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "current preset name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "new_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "new preset name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_rename_preset" gst_preset_rename_preset ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    CString ->                              -- old_name : TBasicType TUTF8
    CString ->                              -- new_name : TBasicType TUTF8
    IO CInt

{- |
Renames a preset. If there is already a preset by the /@newName@/ it will be
overwritten.
-}
presetRenamePreset ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> T.Text
    {- ^ /@oldName@/: current preset name -}
    -> T.Text
    {- ^ /@newName@/: new preset name -}
    -> m Bool
    {- ^ __Returns:__ 'True' for success, 'False' if e.g. there is no preset with /@oldName@/ -}
presetRenamePreset preset oldName newName = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    oldName' <- textToCString oldName
    newName' <- textToCString newName
    result <- gst_preset_rename_preset preset' oldName' newName'
    let result' = (/= 0) result
    touchManagedPtr preset
    freeMem oldName'
    freeMem newName'
    return result'

#if ENABLE_OVERLOADING
data PresetRenamePresetMethodInfo
instance (signature ~ (T.Text -> T.Text -> m Bool), MonadIO m, IsPreset a) => O.MethodInfo PresetRenamePresetMethodInfo a signature where
    overloadedMethod _ = presetRenamePreset

#endif

-- method Preset::save_preset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "preset name to save", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_save_preset" gst_preset_save_preset ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    CString ->                              -- name : TBasicType TUTF8
    IO CInt

{- |
Save the current object settings as a preset under the given name. If there
is already a preset by this /@name@/ it will be overwritten.
-}
presetSavePreset ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> T.Text
    {- ^ /@name@/: preset name to save -}
    -> m Bool
    {- ^ __Returns:__ 'True' for success, 'False' -}
presetSavePreset preset name = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    name' <- textToCString name
    result <- gst_preset_save_preset preset' name'
    let result' = (/= 0) result
    touchManagedPtr preset
    freeMem name'
    return result'

#if ENABLE_OVERLOADING
data PresetSavePresetMethodInfo
instance (signature ~ (T.Text -> m Bool), MonadIO m, IsPreset a) => O.MethodInfo PresetSavePresetMethodInfo a signature where
    overloadedMethod _ = presetSavePreset

#endif

-- method Preset::set_meta
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "preset", argType = TInterface (Name {namespace = "Gst", name = "Preset"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GObject that implements #GstPreset", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "preset name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "tag", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "meta data item name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "new value", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_set_meta" gst_preset_set_meta ::
    Ptr Preset ->                           -- preset : TInterface (Name {namespace = "Gst", name = "Preset"})
    CString ->                              -- name : TBasicType TUTF8
    CString ->                              -- tag : TBasicType TUTF8
    CString ->                              -- value : TBasicType TUTF8
    IO CInt

{- |
Sets a new /@value@/ for an existing meta data item or adds a new item. Meta
data /@tag@/ names can be something like e.g. \"comment\". Supplying 'Nothing' for the
/@value@/ will unset an existing value.
-}
presetSetMeta ::
    (B.CallStack.HasCallStack, MonadIO m, IsPreset a) =>
    a
    {- ^ /@preset@/: a 'GI.GObject.Objects.Object.Object' that implements 'GI.Gst.Interfaces.Preset.Preset' -}
    -> T.Text
    {- ^ /@name@/: preset name -}
    -> T.Text
    {- ^ /@tag@/: meta data item name -}
    -> Maybe (T.Text)
    {- ^ /@value@/: new value -}
    -> m Bool
    {- ^ __Returns:__ 'True' for success, 'False' if e.g. there is no preset with that /@name@/ -}
presetSetMeta preset name tag value = liftIO $ do
    preset' <- unsafeManagedPtrCastPtr preset
    name' <- textToCString name
    tag' <- textToCString tag
    maybeValue <- case value of
        Nothing -> return nullPtr
        Just jValue -> do
            jValue' <- textToCString jValue
            return jValue'
    result <- gst_preset_set_meta preset' name' tag' maybeValue
    let result' = (/= 0) result
    touchManagedPtr preset
    freeMem name'
    freeMem tag'
    freeMem maybeValue
    return result'

#if ENABLE_OVERLOADING
data PresetSetMetaMethodInfo
instance (signature ~ (T.Text -> T.Text -> Maybe (T.Text) -> m Bool), MonadIO m, IsPreset a) => O.MethodInfo PresetSetMetaMethodInfo a signature where
    overloadedMethod _ = presetSetMeta

#endif

-- method Preset::get_app_dir
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TFileName)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_get_app_dir" gst_preset_get_app_dir ::
    IO CString

{- |
Gets the directory for application specific presets if set by the
application.
-}
presetGetAppDir ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m (Maybe [Char])
    {- ^ __Returns:__ the directory or 'Nothing', don\'t free or modify
the string -}
presetGetAppDir  = liftIO $ do
    result <- gst_preset_get_app_dir
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToString result'
        return result''
    return maybeResult

#if ENABLE_OVERLOADING
#endif

-- method Preset::set_app_dir
-- method type : MemberFunction
-- Args : [Arg {argCName = "app_dir", argType = TBasicType TFileName, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the application specific preset dir", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_preset_set_app_dir" gst_preset_set_app_dir ::
    CString ->                              -- app_dir : TBasicType TFileName
    IO CInt

{- |
Sets an extra directory as an absolute path that should be considered when
looking for presets. Any presets in the application dir will shadow the
system presets.
-}
presetSetAppDir ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [Char]
    {- ^ /@appDir@/: the application specific preset dir -}
    -> m Bool
    {- ^ __Returns:__ 'True' for success, 'False' if the dir already has been set -}
presetSetAppDir appDir = liftIO $ do
    appDir' <- stringToCString appDir
    result <- gst_preset_set_app_dir appDir'
    let result' = (/= 0) result
    freeMem appDir'
    return result'

#if ENABLE_OVERLOADING
#endif