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

    Completes partial file and directory names given a partial string by
    looking in the file system for clues. Can return a list of possible
    completion strings for widget implementations.
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Gio.Objects.FilenameCompleter
        (

    -- * Exported types
        FilenameCompleter(..)                   ,
        IsFilenameCompleter                     ,
        toFilenameCompleter                     ,
        noFilenameCompleter                     ,

     -- * Methods
    -- ** getCompletionSuffix #method:getCompletionSuffix#

    #if ENABLE_OVERLOADING
        FilenameCompleterGetCompletionSuffixMethodInfo,
    #endif
        filenameCompleterGetCompletionSuffix    ,

    -- ** getCompletions #method:getCompletions#

    #if ENABLE_OVERLOADING
        FilenameCompleterGetCompletionsMethodInfo,
    #endif
        filenameCompleterGetCompletions         ,

    -- ** new #method:new#

        filenameCompleterNew                    ,

    -- ** setDirsOnly #method:setDirsOnly#

    #if ENABLE_OVERLOADING
        FilenameCompleterSetDirsOnlyMethodInfo  ,
    #endif
        filenameCompleterSetDirsOnly            ,

     -- * Signals
    -- ** gotCompletionData #signal:gotCompletionData#

        C_FilenameCompleterGotCompletionDataCallback,
        FilenameCompleterGotCompletionDataCallback,
    #if ENABLE_OVERLOADING
        FilenameCompleterGotCompletionDataSignalInfo,
    #endif
        afterFilenameCompleterGotCompletionData ,
        genClosure_FilenameCompleterGotCompletionData,
        mk_FilenameCompleterGotCompletionDataCallback,
        noFilenameCompleterGotCompletionDataCallback,
        onFilenameCompleterGotCompletionData    ,
        wrap_FilenameCompleterGotCompletionDataCallback,

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

    -- | Memory-managed wrapper type.
    newtype FilenameCompleter = FilenameCompleter (ManagedPtr FilenameCompleter)
    foreign import ccall "g_filename_completer_get_type"
        c_g_filename_completer_get_type :: IO GType

    instance GObject FilenameCompleter where
        gobjectType _ = c_g_filename_completer_get_type

    -- | Type class for types which can be safely cast to `FilenameCompleter`, for instance with `toFilenameCompleter`.
    class GObject o => IsFilenameCompleter o
    #if MIN_VERSION_base(4,9,0)
    instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError FilenameCompleter a) =>
        IsFilenameCompleter a
    #endif
    instance IsFilenameCompleter FilenameCompleter
    instance GObject.Object.IsObject FilenameCompleter

    -- | Cast to `FilenameCompleter`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
    toFilenameCompleter :: (MonadIO m, IsFilenameCompleter o) => o -> m FilenameCompleter
    toFilenameCompleter = liftIO . unsafeCastTo FilenameCompleter

    -- | A convenience alias for `Nothing` :: `Maybe` `FilenameCompleter`.
    noFilenameCompleter :: Maybe FilenameCompleter
    noFilenameCompleter = Nothing

    #if ENABLE_OVERLOADING
    type family ResolveFilenameCompleterMethod (t :: Symbol) (o :: *) :: * where
        ResolveFilenameCompleterMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
        ResolveFilenameCompleterMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
        ResolveFilenameCompleterMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
        ResolveFilenameCompleterMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
        ResolveFilenameCompleterMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
        ResolveFilenameCompleterMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
        ResolveFilenameCompleterMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
        ResolveFilenameCompleterMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
        ResolveFilenameCompleterMethod "ref" o = GObject.Object.ObjectRefMethodInfo
        ResolveFilenameCompleterMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
        ResolveFilenameCompleterMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
        ResolveFilenameCompleterMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
        ResolveFilenameCompleterMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
        ResolveFilenameCompleterMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
        ResolveFilenameCompleterMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
        ResolveFilenameCompleterMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
        ResolveFilenameCompleterMethod "getCompletionSuffix" o = FilenameCompleterGetCompletionSuffixMethodInfo
        ResolveFilenameCompleterMethod "getCompletions" o = FilenameCompleterGetCompletionsMethodInfo
        ResolveFilenameCompleterMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
        ResolveFilenameCompleterMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
        ResolveFilenameCompleterMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
        ResolveFilenameCompleterMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
        ResolveFilenameCompleterMethod "setDirsOnly" o = FilenameCompleterSetDirsOnlyMethodInfo
        ResolveFilenameCompleterMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
        ResolveFilenameCompleterMethod l o = O.MethodResolutionFailed l o

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

    #if MIN_VERSION_base(4,9,0)
    instance (info ~ ResolveFilenameCompleterMethod t FilenameCompleter, O.MethodInfo info FilenameCompleter p) => O.IsLabel t (FilenameCompleter -> 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

    #endif

    -- signal FilenameCompleter::got-completion-data
    {- |
    Emitted when the file name completion information comes available.
    -}
    type FilenameCompleterGotCompletionDataCallback =
        IO ()

    -- | A convenience synonym for @`Nothing` :: `Maybe` `FilenameCompleterGotCompletionDataCallback`@.
    noFilenameCompleterGotCompletionDataCallback :: Maybe FilenameCompleterGotCompletionDataCallback
    noFilenameCompleterGotCompletionDataCallback = Nothing

    -- | Type for the callback on the (unwrapped) C side.
    type C_FilenameCompleterGotCompletionDataCallback =
        Ptr () ->                               -- object
        Ptr () ->                               -- user_data
        IO ()

    -- | Generate a function pointer callable from C code, from a `C_FilenameCompleterGotCompletionDataCallback`.
    foreign import ccall "wrapper"
        mk_FilenameCompleterGotCompletionDataCallback :: C_FilenameCompleterGotCompletionDataCallback -> IO (FunPtr C_FilenameCompleterGotCompletionDataCallback)

    -- | Wrap the callback into a `Closure`.
    genClosure_FilenameCompleterGotCompletionData :: FilenameCompleterGotCompletionDataCallback -> IO Closure
    genClosure_FilenameCompleterGotCompletionData cb = do
        let cb' = wrap_FilenameCompleterGotCompletionDataCallback cb
        mk_FilenameCompleterGotCompletionDataCallback cb' >>= newCClosure

    -- | Wrap a `FilenameCompleterGotCompletionDataCallback` into a `C_FilenameCompleterGotCompletionDataCallback`.
    wrap_FilenameCompleterGotCompletionDataCallback ::
        FilenameCompleterGotCompletionDataCallback ->
        C_FilenameCompleterGotCompletionDataCallback
    wrap_FilenameCompleterGotCompletionDataCallback _cb _ _ = do
        _cb

    {- |
    Connect a signal handler for the “@got-completion-data@” signal, to be run before the default handler.
    When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

    @
    'Data.GI.Base.Signals.on' filenameCompleter #gotCompletionData callback
    @
    -}
    onFilenameCompleterGotCompletionData :: (IsFilenameCompleter a, MonadIO m) => a -> FilenameCompleterGotCompletionDataCallback -> m SignalHandlerId
    onFilenameCompleterGotCompletionData obj cb = liftIO $ do
        let cb' = wrap_FilenameCompleterGotCompletionDataCallback cb
        cb'' <- mk_FilenameCompleterGotCompletionDataCallback cb'
        connectSignalFunPtr obj "got-completion-data" cb'' SignalConnectBefore

    {- |
    Connect a signal handler for the “@got-completion-data@” signal, to be run after the default handler.
    When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

    @
    'Data.GI.Base.Signals.after' filenameCompleter #gotCompletionData callback
    @
    -}
    afterFilenameCompleterGotCompletionData :: (IsFilenameCompleter a, MonadIO m) => a -> FilenameCompleterGotCompletionDataCallback -> m SignalHandlerId
    afterFilenameCompleterGotCompletionData obj cb = liftIO $ do
        let cb' = wrap_FilenameCompleterGotCompletionDataCallback cb
        cb'' <- mk_FilenameCompleterGotCompletionDataCallback cb'
        connectSignalFunPtr obj "got-completion-data" cb'' SignalConnectAfter

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList FilenameCompleter
    type instance O.AttributeList FilenameCompleter = FilenameCompleterAttributeList
    type FilenameCompleterAttributeList = ('[ ] :: [(Symbol, *)])
    #endif

    #if ENABLE_OVERLOADING
    #endif

    #if ENABLE_OVERLOADING
    data FilenameCompleterGotCompletionDataSignalInfo
    instance SignalInfo FilenameCompleterGotCompletionDataSignalInfo where
        type HaskellCallbackType FilenameCompleterGotCompletionDataSignalInfo = FilenameCompleterGotCompletionDataCallback
        connectSignal _ obj cb connectMode = do
            let cb' = wrap_FilenameCompleterGotCompletionDataCallback cb
            cb'' <- mk_FilenameCompleterGotCompletionDataCallback cb'
            connectSignalFunPtr obj "got-completion-data" cb'' connectMode

    type instance O.SignalList FilenameCompleter = FilenameCompleterSignalList
    type FilenameCompleterSignalList = ('[ '("gotCompletionData", FilenameCompleterGotCompletionDataSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

    #endif

    -- method FilenameCompleter::new
    -- method type : Constructor
    -- Args : []
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "Gio", name = "FilenameCompleter"}))
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_filename_completer_new" g_filename_completer_new ::
        IO (Ptr FilenameCompleter)

    {- |
    Creates a new filename completer.
    -}
    filenameCompleterNew ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        m FilenameCompleter
        {- ^ __Returns:__ a 'GI.Gio.Objects.FilenameCompleter.FilenameCompleter'. -}
    filenameCompleterNew  = liftIO $ do
        result <- g_filename_completer_new
        checkUnexpectedReturnNULL "filenameCompleterNew" result
        result' <- (wrapObject FilenameCompleter) result
        return result'

    #if ENABLE_OVERLOADING
    #endif

    -- method FilenameCompleter::get_completion_suffix
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "completer", argType = TInterface (Name {namespace = "Gio", name = "FilenameCompleter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the filename completer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "initial_text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "text to be completed.", 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 "g_filename_completer_get_completion_suffix" g_filename_completer_get_completion_suffix ::
        Ptr FilenameCompleter ->                -- completer : TInterface (Name {namespace = "Gio", name = "FilenameCompleter"})
        CString ->                              -- initial_text : TBasicType TUTF8
        IO CString

    {- |
    Obtains a completion for /@initialText@/ from /@completer@/.
    -}
    filenameCompleterGetCompletionSuffix ::
        (B.CallStack.HasCallStack, MonadIO m, IsFilenameCompleter a) =>
        a
        {- ^ /@completer@/: the filename completer. -}
        -> T.Text
        {- ^ /@initialText@/: text to be completed. -}
        -> m T.Text
        {- ^ __Returns:__ a completed string, or 'Nothing' if no completion exists.
        This string is not owned by GIO, so remember to 'GI.GLib.Functions.free' it
        when finished. -}
    filenameCompleterGetCompletionSuffix completer initialText = liftIO $ do
        completer' <- unsafeManagedPtrCastPtr completer
        initialText' <- textToCString initialText
        result <- g_filename_completer_get_completion_suffix completer' initialText'
        checkUnexpectedReturnNULL "filenameCompleterGetCompletionSuffix" result
        result' <- cstringToText result
        freeMem result
        touchManagedPtr completer
        freeMem initialText'
        return result'

    #if ENABLE_OVERLOADING
    data FilenameCompleterGetCompletionSuffixMethodInfo
    instance (signature ~ (T.Text -> m T.Text), MonadIO m, IsFilenameCompleter a) => O.MethodInfo FilenameCompleterGetCompletionSuffixMethodInfo a signature where
        overloadedMethod _ = filenameCompleterGetCompletionSuffix

    #endif

    -- method FilenameCompleter::get_completions
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "completer", argType = TInterface (Name {namespace = "Gio", name = "FilenameCompleter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the filename completer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "initial_text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "text to be completed.", 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 "g_filename_completer_get_completions" g_filename_completer_get_completions ::
        Ptr FilenameCompleter ->                -- completer : TInterface (Name {namespace = "Gio", name = "FilenameCompleter"})
        CString ->                              -- initial_text : TBasicType TUTF8
        IO (Ptr CString)

    {- |
    Gets an array of completion strings for a given initial text.
    -}
    filenameCompleterGetCompletions ::
        (B.CallStack.HasCallStack, MonadIO m, IsFilenameCompleter a) =>
        a
        {- ^ /@completer@/: the filename completer. -}
        -> T.Text
        {- ^ /@initialText@/: text to be completed. -}
        -> m [T.Text]
        {- ^ __Returns:__ array of strings with possible completions for /@initialText@/.
    This array must be freed by 'GI.GLib.Functions.strfreev' when finished. -}
    filenameCompleterGetCompletions completer initialText = liftIO $ do
        completer' <- unsafeManagedPtrCastPtr completer
        initialText' <- textToCString initialText
        result <- g_filename_completer_get_completions completer' initialText'
        checkUnexpectedReturnNULL "filenameCompleterGetCompletions" result
        result' <- unpackZeroTerminatedUTF8CArray result
        mapZeroTerminatedCArray freeMem result
        freeMem result
        touchManagedPtr completer
        freeMem initialText'
        return result'

    #if ENABLE_OVERLOADING
    data FilenameCompleterGetCompletionsMethodInfo
    instance (signature ~ (T.Text -> m [T.Text]), MonadIO m, IsFilenameCompleter a) => O.MethodInfo FilenameCompleterGetCompletionsMethodInfo a signature where
        overloadedMethod _ = filenameCompleterGetCompletions

    #endif

    -- method FilenameCompleter::set_dirs_only
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "completer", argType = TInterface (Name {namespace = "Gio", name = "FilenameCompleter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the filename completer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dirs_only", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #gboolean.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_filename_completer_set_dirs_only" g_filename_completer_set_dirs_only ::
        Ptr FilenameCompleter ->                -- completer : TInterface (Name {namespace = "Gio", name = "FilenameCompleter"})
        CInt ->                                 -- dirs_only : TBasicType TBoolean
        IO ()

    {- |
    If /@dirsOnly@/ is 'True', /@completer@/ will only
    complete directory names, and not file names.
    -}
    filenameCompleterSetDirsOnly ::
        (B.CallStack.HasCallStack, MonadIO m, IsFilenameCompleter a) =>
        a
        {- ^ /@completer@/: the filename completer. -}
        -> Bool
        {- ^ /@dirsOnly@/: a 'Bool'. -}
        -> m ()
    filenameCompleterSetDirsOnly completer dirsOnly = liftIO $ do
        completer' <- unsafeManagedPtrCastPtr completer
        let dirsOnly' = (fromIntegral . fromEnum) dirsOnly
        g_filename_completer_set_dirs_only completer' dirsOnly'
        touchManagedPtr completer
        return ()

    #if ENABLE_OVERLOADING
    data FilenameCompleterSetDirsOnlyMethodInfo
    instance (signature ~ (Bool -> m ()), MonadIO m, IsFilenameCompleter a) => O.MethodInfo FilenameCompleterSetDirsOnlyMethodInfo a signature where
        overloadedMethod _ = filenameCompleterSetDirsOnly

    #endif