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

Base class for output stream implementations that perform some
kind of filtering operation on a base stream. Typical examples
of filtering operations are character set conversion, compression
and byte order flipping.
-}

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

module GI.Gio.Objects.FilterOutputStream
    (

-- * Exported types
    FilterOutputStream(..)                  ,
    IsFilterOutputStream                    ,
    toFilterOutputStream                    ,
    noFilterOutputStream                    ,


 -- * Methods
-- ** getBaseStream #method:getBaseStream#

#if ENABLE_OVERLOADING
    FilterOutputStreamGetBaseStreamMethodInfo,
#endif
    filterOutputStreamGetBaseStream         ,


-- ** getCloseBaseStream #method:getCloseBaseStream#

#if ENABLE_OVERLOADING
    FilterOutputStreamGetCloseBaseStreamMethodInfo,
#endif
    filterOutputStreamGetCloseBaseStream    ,


-- ** setCloseBaseStream #method:setCloseBaseStream#

#if ENABLE_OVERLOADING
    FilterOutputStreamSetCloseBaseStreamMethodInfo,
#endif
    filterOutputStreamSetCloseBaseStream    ,




 -- * Properties
-- ** baseStream #attr:baseStream#
{- | /No description available in the introspection data./
-}
#if ENABLE_OVERLOADING
    FilterOutputStreamBaseStreamPropertyInfo,
#endif
    constructFilterOutputStreamBaseStream   ,
#if ENABLE_OVERLOADING
    filterOutputStreamBaseStream            ,
#endif
    getFilterOutputStreamBaseStream         ,


-- ** closeBaseStream #attr:closeBaseStream#
{- | /No description available in the introspection data./
-}
#if ENABLE_OVERLOADING
    FilterOutputStreamCloseBaseStreamPropertyInfo,
#endif
    constructFilterOutputStreamCloseBaseStream,
#if ENABLE_OVERLOADING
    filterOutputStreamCloseBaseStream       ,
#endif
    getFilterOutputStreamCloseBaseStream    ,




    ) 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
import {-# SOURCE #-} qualified GI.Gio.Objects.OutputStream as Gio.OutputStream

-- | Memory-managed wrapper type.
newtype FilterOutputStream = FilterOutputStream (ManagedPtr FilterOutputStream)
foreign import ccall "g_filter_output_stream_get_type"
    c_g_filter_output_stream_get_type :: IO GType

instance GObject FilterOutputStream where
    gobjectType _ = c_g_filter_output_stream_get_type


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

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

-- | A convenience alias for `Nothing` :: `Maybe` `FilterOutputStream`.
noFilterOutputStream :: Maybe FilterOutputStream
noFilterOutputStream = Nothing

#if ENABLE_OVERLOADING
type family ResolveFilterOutputStreamMethod (t :: Symbol) (o :: *) :: * where
    ResolveFilterOutputStreamMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveFilterOutputStreamMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveFilterOutputStreamMethod "clearPending" o = Gio.OutputStream.OutputStreamClearPendingMethodInfo
    ResolveFilterOutputStreamMethod "close" o = Gio.OutputStream.OutputStreamCloseMethodInfo
    ResolveFilterOutputStreamMethod "closeAsync" o = Gio.OutputStream.OutputStreamCloseAsyncMethodInfo
    ResolveFilterOutputStreamMethod "closeFinish" o = Gio.OutputStream.OutputStreamCloseFinishMethodInfo
    ResolveFilterOutputStreamMethod "flush" o = Gio.OutputStream.OutputStreamFlushMethodInfo
    ResolveFilterOutputStreamMethod "flushAsync" o = Gio.OutputStream.OutputStreamFlushAsyncMethodInfo
    ResolveFilterOutputStreamMethod "flushFinish" o = Gio.OutputStream.OutputStreamFlushFinishMethodInfo
    ResolveFilterOutputStreamMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveFilterOutputStreamMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveFilterOutputStreamMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveFilterOutputStreamMethod "hasPending" o = Gio.OutputStream.OutputStreamHasPendingMethodInfo
    ResolveFilterOutputStreamMethod "isClosed" o = Gio.OutputStream.OutputStreamIsClosedMethodInfo
    ResolveFilterOutputStreamMethod "isClosing" o = Gio.OutputStream.OutputStreamIsClosingMethodInfo
    ResolveFilterOutputStreamMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveFilterOutputStreamMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveFilterOutputStreamMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveFilterOutputStreamMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveFilterOutputStreamMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveFilterOutputStreamMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveFilterOutputStreamMethod "splice" o = Gio.OutputStream.OutputStreamSpliceMethodInfo
    ResolveFilterOutputStreamMethod "spliceAsync" o = Gio.OutputStream.OutputStreamSpliceAsyncMethodInfo
    ResolveFilterOutputStreamMethod "spliceFinish" o = Gio.OutputStream.OutputStreamSpliceFinishMethodInfo
    ResolveFilterOutputStreamMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveFilterOutputStreamMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveFilterOutputStreamMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveFilterOutputStreamMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveFilterOutputStreamMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveFilterOutputStreamMethod "write" o = Gio.OutputStream.OutputStreamWriteMethodInfo
    ResolveFilterOutputStreamMethod "writeAll" o = Gio.OutputStream.OutputStreamWriteAllMethodInfo
    ResolveFilterOutputStreamMethod "writeAllAsync" o = Gio.OutputStream.OutputStreamWriteAllAsyncMethodInfo
    ResolveFilterOutputStreamMethod "writeAllFinish" o = Gio.OutputStream.OutputStreamWriteAllFinishMethodInfo
    ResolveFilterOutputStreamMethod "writeAsync" o = Gio.OutputStream.OutputStreamWriteAsyncMethodInfo
    ResolveFilterOutputStreamMethod "writeBytes" o = Gio.OutputStream.OutputStreamWriteBytesMethodInfo
    ResolveFilterOutputStreamMethod "writeBytesAsync" o = Gio.OutputStream.OutputStreamWriteBytesAsyncMethodInfo
    ResolveFilterOutputStreamMethod "writeBytesFinish" o = Gio.OutputStream.OutputStreamWriteBytesFinishMethodInfo
    ResolveFilterOutputStreamMethod "writeFinish" o = Gio.OutputStream.OutputStreamWriteFinishMethodInfo
    ResolveFilterOutputStreamMethod "getBaseStream" o = FilterOutputStreamGetBaseStreamMethodInfo
    ResolveFilterOutputStreamMethod "getCloseBaseStream" o = FilterOutputStreamGetCloseBaseStreamMethodInfo
    ResolveFilterOutputStreamMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveFilterOutputStreamMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveFilterOutputStreamMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveFilterOutputStreamMethod "setCloseBaseStream" o = FilterOutputStreamSetCloseBaseStreamMethodInfo
    ResolveFilterOutputStreamMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveFilterOutputStreamMethod "setPending" o = Gio.OutputStream.OutputStreamSetPendingMethodInfo
    ResolveFilterOutputStreamMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveFilterOutputStreamMethod l o = O.MethodResolutionFailed l o

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

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

-- VVV Prop "base-stream"
   -- Type: TInterface (Name {namespace = "Gio", name = "OutputStream"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@base-stream@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' filterOutputStream #baseStream
@
-}
getFilterOutputStreamBaseStream :: (MonadIO m, IsFilterOutputStream o) => o -> m Gio.OutputStream.OutputStream
getFilterOutputStreamBaseStream obj = liftIO $ checkUnexpectedNothing "getFilterOutputStreamBaseStream" $ getObjectPropertyObject obj "base-stream" Gio.OutputStream.OutputStream

{- |
Construct a `GValueConstruct` with valid value for the “@base-stream@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructFilterOutputStreamBaseStream :: (IsFilterOutputStream o, Gio.OutputStream.IsOutputStream a) => a -> IO (GValueConstruct o)
constructFilterOutputStreamBaseStream val = constructObjectPropertyObject "base-stream" (Just val)

#if ENABLE_OVERLOADING
data FilterOutputStreamBaseStreamPropertyInfo
instance AttrInfo FilterOutputStreamBaseStreamPropertyInfo where
    type AttrAllowedOps FilterOutputStreamBaseStreamPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FilterOutputStreamBaseStreamPropertyInfo = Gio.OutputStream.IsOutputStream
    type AttrBaseTypeConstraint FilterOutputStreamBaseStreamPropertyInfo = IsFilterOutputStream
    type AttrGetType FilterOutputStreamBaseStreamPropertyInfo = Gio.OutputStream.OutputStream
    type AttrLabel FilterOutputStreamBaseStreamPropertyInfo = "base-stream"
    type AttrOrigin FilterOutputStreamBaseStreamPropertyInfo = FilterOutputStream
    attrGet _ = getFilterOutputStreamBaseStream
    attrSet _ = undefined
    attrConstruct _ = constructFilterOutputStreamBaseStream
    attrClear _ = undefined
#endif

-- VVV Prop "close-base-stream"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Just False)

{- |
Get the value of the “@close-base-stream@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' filterOutputStream #closeBaseStream
@
-}
getFilterOutputStreamCloseBaseStream :: (MonadIO m, IsFilterOutputStream o) => o -> m Bool
getFilterOutputStreamCloseBaseStream obj = liftIO $ getObjectPropertyBool obj "close-base-stream"

{- |
Construct a `GValueConstruct` with valid value for the “@close-base-stream@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
-}
constructFilterOutputStreamCloseBaseStream :: (IsFilterOutputStream o) => Bool -> IO (GValueConstruct o)
constructFilterOutputStreamCloseBaseStream val = constructObjectPropertyBool "close-base-stream" val

#if ENABLE_OVERLOADING
data FilterOutputStreamCloseBaseStreamPropertyInfo
instance AttrInfo FilterOutputStreamCloseBaseStreamPropertyInfo where
    type AttrAllowedOps FilterOutputStreamCloseBaseStreamPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint FilterOutputStreamCloseBaseStreamPropertyInfo = (~) Bool
    type AttrBaseTypeConstraint FilterOutputStreamCloseBaseStreamPropertyInfo = IsFilterOutputStream
    type AttrGetType FilterOutputStreamCloseBaseStreamPropertyInfo = Bool
    type AttrLabel FilterOutputStreamCloseBaseStreamPropertyInfo = "close-base-stream"
    type AttrOrigin FilterOutputStreamCloseBaseStreamPropertyInfo = FilterOutputStream
    attrGet _ = getFilterOutputStreamCloseBaseStream
    attrSet _ = undefined
    attrConstruct _ = constructFilterOutputStreamCloseBaseStream
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList FilterOutputStream
type instance O.AttributeList FilterOutputStream = FilterOutputStreamAttributeList
type FilterOutputStreamAttributeList = ('[ '("baseStream", FilterOutputStreamBaseStreamPropertyInfo), '("closeBaseStream", FilterOutputStreamCloseBaseStreamPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
filterOutputStreamBaseStream :: AttrLabelProxy "baseStream"
filterOutputStreamBaseStream = AttrLabelProxy

filterOutputStreamCloseBaseStream :: AttrLabelProxy "closeBaseStream"
filterOutputStreamCloseBaseStream = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList FilterOutputStream = FilterOutputStreamSignalList
type FilterOutputStreamSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method FilterOutputStream::get_base_stream
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "stream", argType = TInterface (Name {namespace = "Gio", name = "FilterOutputStream"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GFilterOutputStream.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "OutputStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_filter_output_stream_get_base_stream" g_filter_output_stream_get_base_stream ::
    Ptr FilterOutputStream ->               -- stream : TInterface (Name {namespace = "Gio", name = "FilterOutputStream"})
    IO (Ptr Gio.OutputStream.OutputStream)

{- |
Gets the base stream for the filter stream.
-}
filterOutputStreamGetBaseStream ::
    (B.CallStack.HasCallStack, MonadIO m, IsFilterOutputStream a) =>
    a
    {- ^ /@stream@/: a 'GI.Gio.Objects.FilterOutputStream.FilterOutputStream'. -}
    -> m Gio.OutputStream.OutputStream
    {- ^ __Returns:__ a 'GI.Gio.Objects.OutputStream.OutputStream'. -}
filterOutputStreamGetBaseStream stream = liftIO $ do
    stream' <- unsafeManagedPtrCastPtr stream
    result <- g_filter_output_stream_get_base_stream stream'
    checkUnexpectedReturnNULL "filterOutputStreamGetBaseStream" result
    result' <- (newObject Gio.OutputStream.OutputStream) result
    touchManagedPtr stream
    return result'

#if ENABLE_OVERLOADING
data FilterOutputStreamGetBaseStreamMethodInfo
instance (signature ~ (m Gio.OutputStream.OutputStream), MonadIO m, IsFilterOutputStream a) => O.MethodInfo FilterOutputStreamGetBaseStreamMethodInfo a signature where
    overloadedMethod _ = filterOutputStreamGetBaseStream

#endif

-- method FilterOutputStream::get_close_base_stream
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "stream", argType = TInterface (Name {namespace = "Gio", name = "FilterOutputStream"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GFilterOutputStream.", 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 "g_filter_output_stream_get_close_base_stream" g_filter_output_stream_get_close_base_stream ::
    Ptr FilterOutputStream ->               -- stream : TInterface (Name {namespace = "Gio", name = "FilterOutputStream"})
    IO CInt

{- |
Returns whether the base stream will be closed when /@stream@/ is
closed.
-}
filterOutputStreamGetCloseBaseStream ::
    (B.CallStack.HasCallStack, MonadIO m, IsFilterOutputStream a) =>
    a
    {- ^ /@stream@/: a 'GI.Gio.Objects.FilterOutputStream.FilterOutputStream'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the base stream will be closed. -}
filterOutputStreamGetCloseBaseStream stream = liftIO $ do
    stream' <- unsafeManagedPtrCastPtr stream
    result <- g_filter_output_stream_get_close_base_stream stream'
    let result' = (/= 0) result
    touchManagedPtr stream
    return result'

#if ENABLE_OVERLOADING
data FilterOutputStreamGetCloseBaseStreamMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsFilterOutputStream a) => O.MethodInfo FilterOutputStreamGetCloseBaseStreamMethodInfo a signature where
    overloadedMethod _ = filterOutputStreamGetCloseBaseStream

#endif

-- method FilterOutputStream::set_close_base_stream
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "stream", argType = TInterface (Name {namespace = "Gio", name = "FilterOutputStream"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GFilterOutputStream.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "close_base", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "%TRUE to close the base stream.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_filter_output_stream_set_close_base_stream" g_filter_output_stream_set_close_base_stream ::
    Ptr FilterOutputStream ->               -- stream : TInterface (Name {namespace = "Gio", name = "FilterOutputStream"})
    CInt ->                                 -- close_base : TBasicType TBoolean
    IO ()

{- |
Sets whether the base stream will be closed when /@stream@/ is closed.
-}
filterOutputStreamSetCloseBaseStream ::
    (B.CallStack.HasCallStack, MonadIO m, IsFilterOutputStream a) =>
    a
    {- ^ /@stream@/: a 'GI.Gio.Objects.FilterOutputStream.FilterOutputStream'. -}
    -> Bool
    {- ^ /@closeBase@/: 'True' to close the base stream. -}
    -> m ()
filterOutputStreamSetCloseBaseStream stream closeBase = liftIO $ do
    stream' <- unsafeManagedPtrCastPtr stream
    let closeBase' = (fromIntegral . fromEnum) closeBase
    g_filter_output_stream_set_close_base_stream stream' closeBase'
    touchManagedPtr stream
    return ()

#if ENABLE_OVERLOADING
data FilterOutputStreamSetCloseBaseStreamMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsFilterOutputStream a) => O.MethodInfo FilterOutputStreamSetCloseBaseStreamMethodInfo a signature where
    overloadedMethod _ = filterOutputStreamSetCloseBaseStream

#endif