{- |
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.WebKit2WebExtension.Objects.URIRequest
    ( 

-- * Exported types
    URIRequest(..)                          ,
    URIRequestK                             ,
    toURIRequest                            ,
    noURIRequest                            ,


 -- * Methods
-- ** uRIRequestGetHttpHeaders
    uRIRequestGetHttpHeaders                ,


-- ** uRIRequestGetUri
    uRIRequestGetUri                        ,


-- ** uRIRequestNew
    uRIRequestNew                           ,


-- ** uRIRequestSetUri
    uRIRequestSetUri                        ,




 -- * Properties
-- ** Uri
    URIRequestUriPropertyInfo               ,
    constructURIRequestUri                  ,
    getURIRequestUri                        ,
    setURIRequestUri                        ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.WebKit2WebExtension.Types
import GI.WebKit2WebExtension.Callbacks
import qualified GI.GObject as GObject
import qualified GI.Soup as Soup

newtype URIRequest = URIRequest (ForeignPtr URIRequest)
foreign import ccall "webkit_uri_request_get_type"
    c_webkit_uri_request_get_type :: IO GType

type instance ParentTypes URIRequest = URIRequestParentTypes
type URIRequestParentTypes = '[GObject.Object]

instance GObject URIRequest where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_webkit_uri_request_get_type
    

class GObject o => URIRequestK o
instance (GObject o, IsDescendantOf URIRequest o) => URIRequestK o

toURIRequest :: URIRequestK o => o -> IO URIRequest
toURIRequest = unsafeCastTo URIRequest

noURIRequest :: Maybe URIRequest
noURIRequest = Nothing

-- VVV Prop "uri"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstruct]

getURIRequestUri :: (MonadIO m, URIRequestK o) => o -> m T.Text
getURIRequestUri obj = liftIO $ getObjectPropertyString obj "uri"

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

constructURIRequestUri :: T.Text -> IO ([Char], GValue)
constructURIRequestUri val = constructObjectPropertyString "uri" val

data URIRequestUriPropertyInfo
instance AttrInfo URIRequestUriPropertyInfo where
    type AttrAllowedOps URIRequestUriPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint URIRequestUriPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint URIRequestUriPropertyInfo = URIRequestK
    type AttrGetType URIRequestUriPropertyInfo = T.Text
    type AttrLabel URIRequestUriPropertyInfo = "URIRequest::uri"
    attrGet _ = getURIRequestUri
    attrSet _ = setURIRequestUri
    attrConstruct _ = constructURIRequestUri

type instance AttributeList URIRequest = URIRequestAttributeList
type URIRequestAttributeList = ('[ '("uri", URIRequestUriPropertyInfo)] :: [(Symbol, *)])

type instance SignalList URIRequest = URIRequestSignalList
type URIRequestSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method URIRequest::new
-- method type : Constructor
-- Args : [Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "WebKit2WebExtension" "URIRequest"
-- throws : False
-- Skip return : False

foreign import ccall "webkit_uri_request_new" webkit_uri_request_new :: 
    CString ->                              -- uri : TBasicType TUTF8
    IO (Ptr URIRequest)


uRIRequestNew ::
    (MonadIO m) =>
    T.Text ->                               -- uri
    m URIRequest
uRIRequestNew uri = liftIO $ do
    uri' <- textToCString uri
    result <- webkit_uri_request_new uri'
    checkUnexpectedReturnNULL "webkit_uri_request_new" result
    result' <- (wrapObject URIRequest) result
    freeMem uri'
    return result'

-- method URIRequest::get_http_headers
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2WebExtension" "URIRequest", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "WebKit2WebExtension" "URIRequest", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Soup" "MessageHeaders"
-- throws : False
-- Skip return : False

foreign import ccall "webkit_uri_request_get_http_headers" webkit_uri_request_get_http_headers :: 
    Ptr URIRequest ->                       -- _obj : TInterface "WebKit2WebExtension" "URIRequest"
    IO (Ptr Soup.MessageHeaders)


uRIRequestGetHttpHeaders ::
    (MonadIO m, URIRequestK a) =>
    a ->                                    -- _obj
    m Soup.MessageHeaders
uRIRequestGetHttpHeaders _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_uri_request_get_http_headers _obj'
    checkUnexpectedReturnNULL "webkit_uri_request_get_http_headers" result
    result' <- (wrapBoxed Soup.MessageHeaders) result
    touchManagedPtr _obj
    return result'

-- method URIRequest::get_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2WebExtension" "URIRequest", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "WebKit2WebExtension" "URIRequest", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TUTF8
-- throws : False
-- Skip return : False

foreign import ccall "webkit_uri_request_get_uri" webkit_uri_request_get_uri :: 
    Ptr URIRequest ->                       -- _obj : TInterface "WebKit2WebExtension" "URIRequest"
    IO CString


uRIRequestGetUri ::
    (MonadIO m, URIRequestK a) =>
    a ->                                    -- _obj
    m T.Text
uRIRequestGetUri _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_uri_request_get_uri _obj'
    checkUnexpectedReturnNULL "webkit_uri_request_get_uri" result
    result' <- cstringToText result
    touchManagedPtr _obj
    return result'

-- method URIRequest::set_uri
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2WebExtension" "URIRequest", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "WebKit2WebExtension" "URIRequest", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "uri", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "webkit_uri_request_set_uri" webkit_uri_request_set_uri :: 
    Ptr URIRequest ->                       -- _obj : TInterface "WebKit2WebExtension" "URIRequest"
    CString ->                              -- uri : TBasicType TUTF8
    IO ()


uRIRequestSetUri ::
    (MonadIO m, URIRequestK a) =>
    a ->                                    -- _obj
    T.Text ->                               -- uri
    m ()
uRIRequestSetUri _obj uri = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    uri' <- textToCString uri
    webkit_uri_request_set_uri _obj' uri'
    touchManagedPtr _obj
    freeMem uri'
    return ()