{- |
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 class represents the network related aspects of a navigation
response.
-}

module GI.WebKit.Objects.NetworkResponse
    ( 

-- * Exported types
    NetworkResponse(..)                     ,
    IsNetworkResponse                       ,
    toNetworkResponse                       ,
    noNetworkResponse                       ,


 -- * Methods
-- ** getMessage #method:getMessage#
    NetworkResponseGetMessageMethodInfo     ,
    networkResponseGetMessage               ,


-- ** getSuggestedFilename #method:getSuggestedFilename#
    NetworkResponseGetSuggestedFilenameMethodInfo,
    networkResponseGetSuggestedFilename     ,


-- ** getUri #method:getUri#
    NetworkResponseGetUriMethodInfo         ,
    networkResponseGetUri                   ,


-- ** new #method:new#
    networkResponseNew                      ,


-- ** setUri #method:setUri#
    NetworkResponseSetUriMethodInfo         ,
    networkResponseSetUri                   ,




 -- * Properties
-- ** message #attr:message#
    NetworkResponseMessagePropertyInfo      ,
    constructNetworkResponseMessage         ,
    getNetworkResponseMessage               ,
    networkResponseMessage                  ,


-- ** suggestedFilename #attr:suggestedFilename#
    NetworkResponseSuggestedFilenamePropertyInfo,
    getNetworkResponseSuggestedFilename     ,
    networkResponseSuggestedFilename        ,


-- ** uri #attr:uri#
    NetworkResponseUriPropertyInfo          ,
    constructNetworkResponseUri             ,
    getNetworkResponseUri                   ,
    networkResponseUri                      ,
    setNetworkResponseUri                   ,




    ) 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 qualified GI.Soup.Objects.Message as Soup.Message

newtype NetworkResponse = NetworkResponse (ManagedPtr NetworkResponse)
foreign import ccall "webkit_network_response_get_type"
    c_webkit_network_response_get_type :: IO GType

instance GObject NetworkResponse where
    gobjectType _ = c_webkit_network_response_get_type
    

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

toNetworkResponse :: IsNetworkResponse o => o -> IO NetworkResponse
toNetworkResponse = unsafeCastTo NetworkResponse

noNetworkResponse :: Maybe NetworkResponse
noNetworkResponse = Nothing

type family ResolveNetworkResponseMethod (t :: Symbol) (o :: *) :: * where
    ResolveNetworkResponseMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveNetworkResponseMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveNetworkResponseMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveNetworkResponseMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveNetworkResponseMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveNetworkResponseMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveNetworkResponseMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveNetworkResponseMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveNetworkResponseMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveNetworkResponseMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveNetworkResponseMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveNetworkResponseMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveNetworkResponseMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveNetworkResponseMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveNetworkResponseMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveNetworkResponseMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveNetworkResponseMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveNetworkResponseMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveNetworkResponseMethod "getMessage" o = NetworkResponseGetMessageMethodInfo
    ResolveNetworkResponseMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveNetworkResponseMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveNetworkResponseMethod "getSuggestedFilename" o = NetworkResponseGetSuggestedFilenameMethodInfo
    ResolveNetworkResponseMethod "getUri" o = NetworkResponseGetUriMethodInfo
    ResolveNetworkResponseMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveNetworkResponseMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveNetworkResponseMethod "setUri" o = NetworkResponseSetUriMethodInfo
    ResolveNetworkResponseMethod l o = O.MethodResolutionFailed l o

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

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

-- VVV Prop "message"
   -- Type: TInterface (Name {namespace = "Soup", name = "Message"})
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
   -- Nullable: (Just False,Nothing)

getNetworkResponseMessage :: (MonadIO m, IsNetworkResponse o) => o -> m Soup.Message.Message
getNetworkResponseMessage obj = liftIO $ checkUnexpectedNothing "getNetworkResponseMessage" $ getObjectPropertyObject obj "message" Soup.Message.Message

constructNetworkResponseMessage :: (IsNetworkResponse o, Soup.Message.IsMessage a) => a -> IO (GValueConstruct o)
constructNetworkResponseMessage val = constructObjectPropertyObject "message" (Just val)

data NetworkResponseMessagePropertyInfo
instance AttrInfo NetworkResponseMessagePropertyInfo where
    type AttrAllowedOps NetworkResponseMessagePropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint NetworkResponseMessagePropertyInfo = Soup.Message.IsMessage
    type AttrBaseTypeConstraint NetworkResponseMessagePropertyInfo = IsNetworkResponse
    type AttrGetType NetworkResponseMessagePropertyInfo = Soup.Message.Message
    type AttrLabel NetworkResponseMessagePropertyInfo = "message"
    type AttrOrigin NetworkResponseMessagePropertyInfo = NetworkResponse
    attrGet _ = getNetworkResponseMessage
    attrSet _ = undefined
    attrConstruct _ = constructNetworkResponseMessage
    attrClear _ = undefined

-- VVV Prop "suggested-filename"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getNetworkResponseSuggestedFilename :: (MonadIO m, IsNetworkResponse o) => o -> m T.Text
getNetworkResponseSuggestedFilename obj = liftIO $ checkUnexpectedNothing "getNetworkResponseSuggestedFilename" $ getObjectPropertyString obj "suggested-filename"

data NetworkResponseSuggestedFilenamePropertyInfo
instance AttrInfo NetworkResponseSuggestedFilenamePropertyInfo where
    type AttrAllowedOps NetworkResponseSuggestedFilenamePropertyInfo = '[ 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint NetworkResponseSuggestedFilenamePropertyInfo = (~) ()
    type AttrBaseTypeConstraint NetworkResponseSuggestedFilenamePropertyInfo = IsNetworkResponse
    type AttrGetType NetworkResponseSuggestedFilenamePropertyInfo = T.Text
    type AttrLabel NetworkResponseSuggestedFilenamePropertyInfo = "suggested-filename"
    type AttrOrigin NetworkResponseSuggestedFilenamePropertyInfo = NetworkResponse
    attrGet _ = getNetworkResponseSuggestedFilename
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined

-- VVV Prop "uri"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Just False,Just False)

getNetworkResponseUri :: (MonadIO m, IsNetworkResponse o) => o -> m T.Text
getNetworkResponseUri obj = liftIO $ checkUnexpectedNothing "getNetworkResponseUri" $ getObjectPropertyString obj "uri"

setNetworkResponseUri :: (MonadIO m, IsNetworkResponse o) => o -> T.Text -> m ()
setNetworkResponseUri obj val = liftIO $ setObjectPropertyString obj "uri" (Just val)

constructNetworkResponseUri :: (IsNetworkResponse o) => T.Text -> IO (GValueConstruct o)
constructNetworkResponseUri val = constructObjectPropertyString "uri" (Just val)

data NetworkResponseUriPropertyInfo
instance AttrInfo NetworkResponseUriPropertyInfo where
    type AttrAllowedOps NetworkResponseUriPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint NetworkResponseUriPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint NetworkResponseUriPropertyInfo = IsNetworkResponse
    type AttrGetType NetworkResponseUriPropertyInfo = T.Text
    type AttrLabel NetworkResponseUriPropertyInfo = "uri"
    type AttrOrigin NetworkResponseUriPropertyInfo = NetworkResponse
    attrGet _ = getNetworkResponseUri
    attrSet _ = setNetworkResponseUri
    attrConstruct _ = constructNetworkResponseUri
    attrClear _ = undefined

instance O.HasAttributeList NetworkResponse
type instance O.AttributeList NetworkResponse = NetworkResponseAttributeList
type NetworkResponseAttributeList = ('[ '("message", NetworkResponseMessagePropertyInfo), '("suggestedFilename", NetworkResponseSuggestedFilenamePropertyInfo), '("uri", NetworkResponseUriPropertyInfo)] :: [(Symbol, *)])

networkResponseMessage :: AttrLabelProxy "message"
networkResponseMessage = AttrLabelProxy

networkResponseSuggestedFilename :: AttrLabelProxy "suggestedFilename"
networkResponseSuggestedFilename = AttrLabelProxy

networkResponseUri :: AttrLabelProxy "uri"
networkResponseUri = AttrLabelProxy

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

-- method NetworkResponse::new
-- method type : Constructor
-- Args : [Arg {argCName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an URI", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "WebKit", name = "NetworkResponse"}))
-- throws : False
-- Skip return : False

foreign import ccall "webkit_network_response_new" webkit_network_response_new :: 
    CString ->                              -- uri : TBasicType TUTF8
    IO (Ptr NetworkResponse)

{- |
Creates a new 'GI.WebKit.Objects.NetworkResponse.NetworkResponse' initialized with an URI.

@since 1.1.14
-}
networkResponseNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@uri@/: an URI -}
    -> m NetworkResponse
    {- ^ __Returns:__ a new 'GI.WebKit.Objects.NetworkResponse.NetworkResponse', or 'Nothing' if the URI is
invalid. -}
networkResponseNew uri = liftIO $ do
    uri' <- textToCString uri
    result <- webkit_network_response_new uri'
    checkUnexpectedReturnNULL "networkResponseNew" result
    result' <- (wrapObject NetworkResponse) result
    freeMem uri'
    return result'

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

foreign import ccall "webkit_network_response_get_message" webkit_network_response_get_message :: 
    Ptr NetworkResponse ->                  -- response : TInterface (Name {namespace = "WebKit", name = "NetworkResponse"})
    IO (Ptr Soup.Message.Message)

{- |
Obtains the 'GI.Soup.Objects.Message.Message' that represents the given response. Notice
that only the response side of the HTTP conversation is
represented.

@since 1.1.14
-}
networkResponseGetMessage ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkResponse a) =>
    a
    {- ^ /@response@/: a 'GI.WebKit.Objects.NetworkResponse.NetworkResponse' -}
    -> m Soup.Message.Message
    {- ^ __Returns:__ the 'GI.Soup.Objects.Message.Message' -}
networkResponseGetMessage response = liftIO $ do
    response' <- unsafeManagedPtrCastPtr response
    result <- webkit_network_response_get_message response'
    checkUnexpectedReturnNULL "networkResponseGetMessage" result
    result' <- (newObject Soup.Message.Message) result
    touchManagedPtr response
    return result'

data NetworkResponseGetMessageMethodInfo
instance (signature ~ (m Soup.Message.Message), MonadIO m, IsNetworkResponse a) => O.MethodInfo NetworkResponseGetMessageMethodInfo a signature where
    overloadedMethod _ = networkResponseGetMessage

-- method NetworkResponse::get_suggested_filename
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "response", argType = TInterface (Name {namespace = "WebKit", name = "NetworkResponse"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitNetworkResponse", 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_network_response_get_suggested_filename" webkit_network_response_get_suggested_filename :: 
    Ptr NetworkResponse ->                  -- response : TInterface (Name {namespace = "WebKit", name = "NetworkResponse"})
    IO CString

{- |
Obtains the suggested filename for the given network response. The
suggested filename is taken from the \'Content-Disposition\' HTTP
header, but this is not always present, and this method will return
'Nothing' in such case.

@since 1.10
-}
networkResponseGetSuggestedFilename ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkResponse a) =>
    a
    {- ^ /@response@/: a 'GI.WebKit.Objects.NetworkResponse.NetworkResponse' -}
    -> m T.Text
    {- ^ __Returns:__ the suggested filename or 'Nothing' if not present -}
networkResponseGetSuggestedFilename response = liftIO $ do
    response' <- unsafeManagedPtrCastPtr response
    result <- webkit_network_response_get_suggested_filename response'
    checkUnexpectedReturnNULL "networkResponseGetSuggestedFilename" result
    result' <- cstringToText result
    touchManagedPtr response
    return result'

data NetworkResponseGetSuggestedFilenameMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsNetworkResponse a) => O.MethodInfo NetworkResponseGetSuggestedFilenameMethodInfo a signature where
    overloadedMethod _ = networkResponseGetSuggestedFilename

-- method NetworkResponse::get_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "response", argType = TInterface (Name {namespace = "WebKit", name = "NetworkResponse"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitNetworkResponse", 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_network_response_get_uri" webkit_network_response_get_uri :: 
    Ptr NetworkResponse ->                  -- response : TInterface (Name {namespace = "WebKit", name = "NetworkResponse"})
    IO CString

{- |
/No description available in the introspection data./

@since 1.1.14
-}
networkResponseGetUri ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkResponse a) =>
    a
    {- ^ /@response@/: a 'GI.WebKit.Objects.NetworkResponse.NetworkResponse' -}
    -> m T.Text
    {- ^ __Returns:__ the URI of the 'GI.WebKit.Objects.NetworkResponse.NetworkResponse' -}
networkResponseGetUri response = liftIO $ do
    response' <- unsafeManagedPtrCastPtr response
    result <- webkit_network_response_get_uri response'
    checkUnexpectedReturnNULL "networkResponseGetUri" result
    result' <- cstringToText result
    touchManagedPtr response
    return result'

data NetworkResponseGetUriMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsNetworkResponse a) => O.MethodInfo NetworkResponseGetUriMethodInfo a signature where
    overloadedMethod _ = networkResponseGetUri

-- method NetworkResponse::set_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "response", argType = TInterface (Name {namespace = "WebKit", name = "NetworkResponse"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #WebKitNetworkResponse", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an URI", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "webkit_network_response_set_uri" webkit_network_response_set_uri :: 
    Ptr NetworkResponse ->                  -- response : TInterface (Name {namespace = "WebKit", name = "NetworkResponse"})
    CString ->                              -- uri : TBasicType TUTF8
    IO ()

{- |
Sets the URI held and used by the given response. When the response
has an associated 'GI.Soup.Objects.Message.Message', its URI will also be set by this
call.

@since 1.1.14
-}
networkResponseSetUri ::
    (B.CallStack.HasCallStack, MonadIO m, IsNetworkResponse a) =>
    a
    {- ^ /@response@/: a 'GI.WebKit.Objects.NetworkResponse.NetworkResponse' -}
    -> T.Text
    {- ^ /@uri@/: an URI -}
    -> m ()
networkResponseSetUri response uri = liftIO $ do
    response' <- unsafeManagedPtrCastPtr response
    uri' <- textToCString uri
    webkit_network_response_set_uri response' uri'
    touchManagedPtr response
    freeMem uri'
    return ()

data NetworkResponseSetUriMethodInfo
instance (signature ~ (T.Text -> m ()), MonadIO m, IsNetworkResponse a) => O.MethodInfo NetworkResponseSetUriMethodInfo a signature where
    overloadedMethod _ = networkResponseSetUri