{- |
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.WebKit2.Objects.Download
    ( 

-- * Exported types
    Download(..)                            ,
    DownloadK                               ,
    toDownload                              ,
    noDownload                              ,


 -- * Methods
-- ** downloadCancel
    downloadCancel                          ,


-- ** downloadGetAllowOverwrite
    downloadGetAllowOverwrite               ,


-- ** downloadGetDestination
    downloadGetDestination                  ,


-- ** downloadGetElapsedTime
    downloadGetElapsedTime                  ,


-- ** downloadGetEstimatedProgress
    downloadGetEstimatedProgress            ,


-- ** downloadGetReceivedDataLength
    downloadGetReceivedDataLength           ,


-- ** downloadGetRequest
    downloadGetRequest                      ,


-- ** downloadGetResponse
    downloadGetResponse                     ,


-- ** downloadGetWebView
    downloadGetWebView                      ,


-- ** downloadSetAllowOverwrite
    downloadSetAllowOverwrite               ,


-- ** downloadSetDestination
    downloadSetDestination                  ,




 -- * Properties
-- ** AllowOverwrite
    DownloadAllowOverwritePropertyInfo      ,
    constructDownloadAllowOverwrite         ,
    getDownloadAllowOverwrite               ,
    setDownloadAllowOverwrite               ,


-- ** Destination
    DownloadDestinationPropertyInfo         ,
    getDownloadDestination                  ,


-- ** EstimatedProgress
    DownloadEstimatedProgressPropertyInfo   ,
    getDownloadEstimatedProgress            ,


-- ** Response
    DownloadResponsePropertyInfo            ,
    getDownloadResponse                     ,




 -- * Signals
-- ** CreatedDestination
    DownloadCreatedDestinationCallback      ,
    DownloadCreatedDestinationCallbackC     ,
    DownloadCreatedDestinationSignalInfo    ,
    afterDownloadCreatedDestination         ,
    downloadCreatedDestinationCallbackWrapper,
    downloadCreatedDestinationClosure       ,
    mkDownloadCreatedDestinationCallback    ,
    noDownloadCreatedDestinationCallback    ,
    onDownloadCreatedDestination            ,


-- ** DecideDestination
    DownloadDecideDestinationCallback       ,
    DownloadDecideDestinationCallbackC      ,
    DownloadDecideDestinationSignalInfo     ,
    afterDownloadDecideDestination          ,
    downloadDecideDestinationCallbackWrapper,
    downloadDecideDestinationClosure        ,
    mkDownloadDecideDestinationCallback     ,
    noDownloadDecideDestinationCallback     ,
    onDownloadDecideDestination             ,


-- ** Failed
    DownloadFailedCallback                  ,
    DownloadFailedCallbackC                 ,
    DownloadFailedSignalInfo                ,
    afterDownloadFailed                     ,
    downloadFailedCallbackWrapper           ,
    downloadFailedClosure                   ,
    mkDownloadFailedCallback                ,
    noDownloadFailedCallback                ,
    onDownloadFailed                        ,


-- ** Finished
    DownloadFinishedCallback                ,
    DownloadFinishedCallbackC               ,
    DownloadFinishedSignalInfo              ,
    afterDownloadFinished                   ,
    downloadFinishedCallbackWrapper         ,
    downloadFinishedClosure                 ,
    mkDownloadFinishedCallback              ,
    noDownloadFinishedCallback              ,
    onDownloadFinished                      ,


-- ** ReceivedData
    DownloadReceivedDataCallback            ,
    DownloadReceivedDataCallbackC           ,
    DownloadReceivedDataSignalInfo          ,
    afterDownloadReceivedData               ,
    downloadReceivedDataCallbackWrapper     ,
    downloadReceivedDataClosure             ,
    mkDownloadReceivedDataCallback          ,
    noDownloadReceivedDataCallback          ,
    onDownloadReceivedData                  ,




    ) 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.WebKit2.Types
import GI.WebKit2.Callbacks
import qualified GI.GObject as GObject

newtype Download = Download (ForeignPtr Download)
foreign import ccall "webkit_download_get_type"
    c_webkit_download_get_type :: IO GType

type instance ParentTypes Download = DownloadParentTypes
type DownloadParentTypes = '[GObject.Object]

instance GObject Download where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_webkit_download_get_type
    

class GObject o => DownloadK o
instance (GObject o, IsDescendantOf Download o) => DownloadK o

toDownload :: DownloadK o => o -> IO Download
toDownload = unsafeCastTo Download

noDownload :: Maybe Download
noDownload = Nothing

-- signal Download::created-destination
type DownloadCreatedDestinationCallback =
    T.Text ->
    IO ()

noDownloadCreatedDestinationCallback :: Maybe DownloadCreatedDestinationCallback
noDownloadCreatedDestinationCallback = Nothing

type DownloadCreatedDestinationCallbackC =
    Ptr () ->                               -- object
    CString ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkDownloadCreatedDestinationCallback :: DownloadCreatedDestinationCallbackC -> IO (FunPtr DownloadCreatedDestinationCallbackC)

downloadCreatedDestinationClosure :: DownloadCreatedDestinationCallback -> IO Closure
downloadCreatedDestinationClosure cb = newCClosure =<< mkDownloadCreatedDestinationCallback wrapped
    where wrapped = downloadCreatedDestinationCallbackWrapper cb

downloadCreatedDestinationCallbackWrapper ::
    DownloadCreatedDestinationCallback ->
    Ptr () ->
    CString ->
    Ptr () ->
    IO ()
downloadCreatedDestinationCallbackWrapper _cb _ destination _ = do
    destination' <- cstringToText destination
    _cb  destination'

onDownloadCreatedDestination :: (GObject a, MonadIO m) => a -> DownloadCreatedDestinationCallback -> m SignalHandlerId
onDownloadCreatedDestination obj cb = liftIO $ connectDownloadCreatedDestination obj cb SignalConnectBefore
afterDownloadCreatedDestination :: (GObject a, MonadIO m) => a -> DownloadCreatedDestinationCallback -> m SignalHandlerId
afterDownloadCreatedDestination obj cb = connectDownloadCreatedDestination obj cb SignalConnectAfter

connectDownloadCreatedDestination :: (GObject a, MonadIO m) =>
                                     a -> DownloadCreatedDestinationCallback -> SignalConnectMode -> m SignalHandlerId
connectDownloadCreatedDestination obj cb after = liftIO $ do
    cb' <- mkDownloadCreatedDestinationCallback (downloadCreatedDestinationCallbackWrapper cb)
    connectSignalFunPtr obj "created-destination" cb' after

-- signal Download::decide-destination
type DownloadDecideDestinationCallback =
    T.Text ->
    IO Bool

noDownloadDecideDestinationCallback :: Maybe DownloadDecideDestinationCallback
noDownloadDecideDestinationCallback = Nothing

type DownloadDecideDestinationCallbackC =
    Ptr () ->                               -- object
    CString ->
    Ptr () ->                               -- user_data
    IO CInt

foreign import ccall "wrapper"
    mkDownloadDecideDestinationCallback :: DownloadDecideDestinationCallbackC -> IO (FunPtr DownloadDecideDestinationCallbackC)

downloadDecideDestinationClosure :: DownloadDecideDestinationCallback -> IO Closure
downloadDecideDestinationClosure cb = newCClosure =<< mkDownloadDecideDestinationCallback wrapped
    where wrapped = downloadDecideDestinationCallbackWrapper cb

downloadDecideDestinationCallbackWrapper ::
    DownloadDecideDestinationCallback ->
    Ptr () ->
    CString ->
    Ptr () ->
    IO CInt
downloadDecideDestinationCallbackWrapper _cb _ suggested_filename _ = do
    suggested_filename' <- cstringToText suggested_filename
    result <- _cb  suggested_filename'
    let result' = (fromIntegral . fromEnum) result
    return result'

onDownloadDecideDestination :: (GObject a, MonadIO m) => a -> DownloadDecideDestinationCallback -> m SignalHandlerId
onDownloadDecideDestination obj cb = liftIO $ connectDownloadDecideDestination obj cb SignalConnectBefore
afterDownloadDecideDestination :: (GObject a, MonadIO m) => a -> DownloadDecideDestinationCallback -> m SignalHandlerId
afterDownloadDecideDestination obj cb = connectDownloadDecideDestination obj cb SignalConnectAfter

connectDownloadDecideDestination :: (GObject a, MonadIO m) =>
                                    a -> DownloadDecideDestinationCallback -> SignalConnectMode -> m SignalHandlerId
connectDownloadDecideDestination obj cb after = liftIO $ do
    cb' <- mkDownloadDecideDestinationCallback (downloadDecideDestinationCallbackWrapper cb)
    connectSignalFunPtr obj "decide-destination" cb' after

-- signal Download::failed
type DownloadFailedCallback =
    Ptr () ->
    IO ()

noDownloadFailedCallback :: Maybe DownloadFailedCallback
noDownloadFailedCallback = Nothing

type DownloadFailedCallbackC =
    Ptr () ->                               -- object
    Ptr () ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkDownloadFailedCallback :: DownloadFailedCallbackC -> IO (FunPtr DownloadFailedCallbackC)

downloadFailedClosure :: DownloadFailedCallback -> IO Closure
downloadFailedClosure cb = newCClosure =<< mkDownloadFailedCallback wrapped
    where wrapped = downloadFailedCallbackWrapper cb

downloadFailedCallbackWrapper ::
    DownloadFailedCallback ->
    Ptr () ->
    Ptr () ->
    Ptr () ->
    IO ()
downloadFailedCallbackWrapper _cb _ error_ _ = do
    _cb  error_

onDownloadFailed :: (GObject a, MonadIO m) => a -> DownloadFailedCallback -> m SignalHandlerId
onDownloadFailed obj cb = liftIO $ connectDownloadFailed obj cb SignalConnectBefore
afterDownloadFailed :: (GObject a, MonadIO m) => a -> DownloadFailedCallback -> m SignalHandlerId
afterDownloadFailed obj cb = connectDownloadFailed obj cb SignalConnectAfter

connectDownloadFailed :: (GObject a, MonadIO m) =>
                         a -> DownloadFailedCallback -> SignalConnectMode -> m SignalHandlerId
connectDownloadFailed obj cb after = liftIO $ do
    cb' <- mkDownloadFailedCallback (downloadFailedCallbackWrapper cb)
    connectSignalFunPtr obj "failed" cb' after

-- signal Download::finished
type DownloadFinishedCallback =
    IO ()

noDownloadFinishedCallback :: Maybe DownloadFinishedCallback
noDownloadFinishedCallback = Nothing

type DownloadFinishedCallbackC =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkDownloadFinishedCallback :: DownloadFinishedCallbackC -> IO (FunPtr DownloadFinishedCallbackC)

downloadFinishedClosure :: DownloadFinishedCallback -> IO Closure
downloadFinishedClosure cb = newCClosure =<< mkDownloadFinishedCallback wrapped
    where wrapped = downloadFinishedCallbackWrapper cb

downloadFinishedCallbackWrapper ::
    DownloadFinishedCallback ->
    Ptr () ->
    Ptr () ->
    IO ()
downloadFinishedCallbackWrapper _cb _ _ = do
    _cb 

onDownloadFinished :: (GObject a, MonadIO m) => a -> DownloadFinishedCallback -> m SignalHandlerId
onDownloadFinished obj cb = liftIO $ connectDownloadFinished obj cb SignalConnectBefore
afterDownloadFinished :: (GObject a, MonadIO m) => a -> DownloadFinishedCallback -> m SignalHandlerId
afterDownloadFinished obj cb = connectDownloadFinished obj cb SignalConnectAfter

connectDownloadFinished :: (GObject a, MonadIO m) =>
                           a -> DownloadFinishedCallback -> SignalConnectMode -> m SignalHandlerId
connectDownloadFinished obj cb after = liftIO $ do
    cb' <- mkDownloadFinishedCallback (downloadFinishedCallbackWrapper cb)
    connectSignalFunPtr obj "finished" cb' after

-- signal Download::received-data
type DownloadReceivedDataCallback =
    Word64 ->
    IO ()

noDownloadReceivedDataCallback :: Maybe DownloadReceivedDataCallback
noDownloadReceivedDataCallback = Nothing

type DownloadReceivedDataCallbackC =
    Ptr () ->                               -- object
    Word64 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mkDownloadReceivedDataCallback :: DownloadReceivedDataCallbackC -> IO (FunPtr DownloadReceivedDataCallbackC)

downloadReceivedDataClosure :: DownloadReceivedDataCallback -> IO Closure
downloadReceivedDataClosure cb = newCClosure =<< mkDownloadReceivedDataCallback wrapped
    where wrapped = downloadReceivedDataCallbackWrapper cb

downloadReceivedDataCallbackWrapper ::
    DownloadReceivedDataCallback ->
    Ptr () ->
    Word64 ->
    Ptr () ->
    IO ()
downloadReceivedDataCallbackWrapper _cb _ data_length _ = do
    _cb  data_length

onDownloadReceivedData :: (GObject a, MonadIO m) => a -> DownloadReceivedDataCallback -> m SignalHandlerId
onDownloadReceivedData obj cb = liftIO $ connectDownloadReceivedData obj cb SignalConnectBefore
afterDownloadReceivedData :: (GObject a, MonadIO m) => a -> DownloadReceivedDataCallback -> m SignalHandlerId
afterDownloadReceivedData obj cb = connectDownloadReceivedData obj cb SignalConnectAfter

connectDownloadReceivedData :: (GObject a, MonadIO m) =>
                               a -> DownloadReceivedDataCallback -> SignalConnectMode -> m SignalHandlerId
connectDownloadReceivedData obj cb after = liftIO $ do
    cb' <- mkDownloadReceivedDataCallback (downloadReceivedDataCallbackWrapper cb)
    connectSignalFunPtr obj "received-data" cb' after

-- VVV Prop "allow-overwrite"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable,PropertyWritable]

getDownloadAllowOverwrite :: (MonadIO m, DownloadK o) => o -> m Bool
getDownloadAllowOverwrite obj = liftIO $ getObjectPropertyBool obj "allow-overwrite"

setDownloadAllowOverwrite :: (MonadIO m, DownloadK o) => o -> Bool -> m ()
setDownloadAllowOverwrite obj val = liftIO $ setObjectPropertyBool obj "allow-overwrite" val

constructDownloadAllowOverwrite :: Bool -> IO ([Char], GValue)
constructDownloadAllowOverwrite val = constructObjectPropertyBool "allow-overwrite" val

data DownloadAllowOverwritePropertyInfo
instance AttrInfo DownloadAllowOverwritePropertyInfo where
    type AttrAllowedOps DownloadAllowOverwritePropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint DownloadAllowOverwritePropertyInfo = (~) Bool
    type AttrBaseTypeConstraint DownloadAllowOverwritePropertyInfo = DownloadK
    type AttrGetType DownloadAllowOverwritePropertyInfo = Bool
    type AttrLabel DownloadAllowOverwritePropertyInfo = "Download::allow-overwrite"
    attrGet _ = getDownloadAllowOverwrite
    attrSet _ = setDownloadAllowOverwrite
    attrConstruct _ = constructDownloadAllowOverwrite

-- VVV Prop "destination"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable]

getDownloadDestination :: (MonadIO m, DownloadK o) => o -> m T.Text
getDownloadDestination obj = liftIO $ getObjectPropertyString obj "destination"

data DownloadDestinationPropertyInfo
instance AttrInfo DownloadDestinationPropertyInfo where
    type AttrAllowedOps DownloadDestinationPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DownloadDestinationPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DownloadDestinationPropertyInfo = DownloadK
    type AttrGetType DownloadDestinationPropertyInfo = T.Text
    type AttrLabel DownloadDestinationPropertyInfo = "Download::destination"
    attrGet _ = getDownloadDestination
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "estimated-progress"
   -- Type: TBasicType TDouble
   -- Flags: [PropertyReadable]

getDownloadEstimatedProgress :: (MonadIO m, DownloadK o) => o -> m Double
getDownloadEstimatedProgress obj = liftIO $ getObjectPropertyDouble obj "estimated-progress"

data DownloadEstimatedProgressPropertyInfo
instance AttrInfo DownloadEstimatedProgressPropertyInfo where
    type AttrAllowedOps DownloadEstimatedProgressPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DownloadEstimatedProgressPropertyInfo = (~) ()
    type AttrBaseTypeConstraint DownloadEstimatedProgressPropertyInfo = DownloadK
    type AttrGetType DownloadEstimatedProgressPropertyInfo = Double
    type AttrLabel DownloadEstimatedProgressPropertyInfo = "Download::estimated-progress"
    attrGet _ = getDownloadEstimatedProgress
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "response"
   -- Type: TInterface "WebKit2" "URIResponse"
   -- Flags: [PropertyReadable]

getDownloadResponse :: (MonadIO m, DownloadK o) => o -> m URIResponse
getDownloadResponse obj = liftIO $ getObjectPropertyObject obj "response" URIResponse

data DownloadResponsePropertyInfo
instance AttrInfo DownloadResponsePropertyInfo where
    type AttrAllowedOps DownloadResponsePropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint DownloadResponsePropertyInfo = (~) ()
    type AttrBaseTypeConstraint DownloadResponsePropertyInfo = DownloadK
    type AttrGetType DownloadResponsePropertyInfo = URIResponse
    type AttrLabel DownloadResponsePropertyInfo = "Download::response"
    attrGet _ = getDownloadResponse
    attrSet _ = undefined
    attrConstruct _ = undefined

type instance AttributeList Download = DownloadAttributeList
type DownloadAttributeList = ('[ '("allow-overwrite", DownloadAllowOverwritePropertyInfo), '("destination", DownloadDestinationPropertyInfo), '("estimated-progress", DownloadEstimatedProgressPropertyInfo), '("response", DownloadResponsePropertyInfo)] :: [(Symbol, *)])

data DownloadCreatedDestinationSignalInfo
instance SignalInfo DownloadCreatedDestinationSignalInfo where
    type HaskellCallbackType DownloadCreatedDestinationSignalInfo = DownloadCreatedDestinationCallback
    connectSignal _ = connectDownloadCreatedDestination

data DownloadDecideDestinationSignalInfo
instance SignalInfo DownloadDecideDestinationSignalInfo where
    type HaskellCallbackType DownloadDecideDestinationSignalInfo = DownloadDecideDestinationCallback
    connectSignal _ = connectDownloadDecideDestination

data DownloadFailedSignalInfo
instance SignalInfo DownloadFailedSignalInfo where
    type HaskellCallbackType DownloadFailedSignalInfo = DownloadFailedCallback
    connectSignal _ = connectDownloadFailed

data DownloadFinishedSignalInfo
instance SignalInfo DownloadFinishedSignalInfo where
    type HaskellCallbackType DownloadFinishedSignalInfo = DownloadFinishedCallback
    connectSignal _ = connectDownloadFinished

data DownloadReceivedDataSignalInfo
instance SignalInfo DownloadReceivedDataSignalInfo where
    type HaskellCallbackType DownloadReceivedDataSignalInfo = DownloadReceivedDataCallback
    connectSignal _ = connectDownloadReceivedData

type instance SignalList Download = DownloadSignalList
type DownloadSignalList = ('[ '("created-destination", DownloadCreatedDestinationSignalInfo), '("decide-destination", DownloadDecideDestinationSignalInfo), '("failed", DownloadFailedSignalInfo), '("finished", DownloadFinishedSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("received-data", DownloadReceivedDataSignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

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

foreign import ccall "webkit_download_cancel" webkit_download_cancel :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO ()


downloadCancel ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m ()
downloadCancel _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    webkit_download_cancel _obj'
    touchManagedPtr _obj
    return ()

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

foreign import ccall "webkit_download_get_allow_overwrite" webkit_download_get_allow_overwrite :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO CInt


downloadGetAllowOverwrite ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m Bool
downloadGetAllowOverwrite _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_allow_overwrite _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_download_get_destination" webkit_download_get_destination :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO CString


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

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

foreign import ccall "webkit_download_get_elapsed_time" webkit_download_get_elapsed_time :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO CDouble


downloadGetElapsedTime ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m Double
downloadGetElapsedTime _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_elapsed_time _obj'
    let result' = realToFrac result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_download_get_estimated_progress" webkit_download_get_estimated_progress :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO CDouble


downloadGetEstimatedProgress ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m Double
downloadGetEstimatedProgress _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_estimated_progress _obj'
    let result' = realToFrac result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "webkit_download_get_received_data_length" webkit_download_get_received_data_length :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO Word64


downloadGetReceivedDataLength ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m Word64
downloadGetReceivedDataLength _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_received_data_length _obj'
    touchManagedPtr _obj
    return result

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

foreign import ccall "webkit_download_get_request" webkit_download_get_request :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO (Ptr URIRequest)


downloadGetRequest ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m URIRequest
downloadGetRequest _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_request _obj'
    checkUnexpectedReturnNULL "webkit_download_get_request" result
    result' <- (newObject URIRequest) result
    touchManagedPtr _obj
    return result'

-- method Download::get_response
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "WebKit2" "URIResponse"
-- throws : False
-- Skip return : False

foreign import ccall "webkit_download_get_response" webkit_download_get_response :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO (Ptr URIResponse)


downloadGetResponse ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m URIResponse
downloadGetResponse _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_response _obj'
    checkUnexpectedReturnNULL "webkit_download_get_response" result
    result' <- (newObject URIResponse) result
    touchManagedPtr _obj
    return result'

-- method Download::get_web_view
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "WebKit2" "WebView"
-- throws : False
-- Skip return : False

foreign import ccall "webkit_download_get_web_view" webkit_download_get_web_view :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    IO (Ptr WebView)


downloadGetWebView ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    m WebView
downloadGetWebView _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- webkit_download_get_web_view _obj'
    checkUnexpectedReturnNULL "webkit_download_get_web_view" result
    result' <- (newObject WebView) result
    touchManagedPtr _obj
    return result'

-- method Download::set_allow_overwrite
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "allowed", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "allowed", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "webkit_download_set_allow_overwrite" webkit_download_set_allow_overwrite :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    CInt ->                                 -- allowed : TBasicType TBoolean
    IO ()


downloadSetAllowOverwrite ::
    (MonadIO m, DownloadK a) =>
    a ->                                    -- _obj
    Bool ->                                 -- allowed
    m ()
downloadSetAllowOverwrite _obj allowed = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let allowed' = (fromIntegral . fromEnum) allowed
    webkit_download_set_allow_overwrite _obj' allowed'
    touchManagedPtr _obj
    return ()

-- method Download::set_destination
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "WebKit2" "Download", 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 "WebKit2" "Download", 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_download_set_destination" webkit_download_set_destination :: 
    Ptr Download ->                         -- _obj : TInterface "WebKit2" "Download"
    CString ->                              -- uri : TBasicType TUTF8
    IO ()


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