module GI.WebKit.Objects.Download
(
Download(..) ,
DownloadK ,
toDownload ,
noDownload ,
downloadCancel ,
downloadGetCurrentSize ,
downloadGetDestinationUri ,
downloadGetElapsedTime ,
downloadGetNetworkRequest ,
downloadGetNetworkResponse ,
downloadGetProgress ,
downloadGetStatus ,
downloadGetSuggestedFilename ,
downloadGetTotalSize ,
downloadGetUri ,
downloadNew ,
downloadSetDestinationUri ,
downloadStart ,
DownloadCurrentSizePropertyInfo ,
getDownloadCurrentSize ,
DownloadDestinationUriPropertyInfo ,
constructDownloadDestinationUri ,
getDownloadDestinationUri ,
setDownloadDestinationUri ,
DownloadNetworkRequestPropertyInfo ,
constructDownloadNetworkRequest ,
getDownloadNetworkRequest ,
DownloadNetworkResponsePropertyInfo ,
constructDownloadNetworkResponse ,
getDownloadNetworkResponse ,
DownloadProgressPropertyInfo ,
getDownloadProgress ,
DownloadStatusPropertyInfo ,
getDownloadStatus ,
DownloadSuggestedFilenamePropertyInfo ,
getDownloadSuggestedFilename ,
DownloadTotalSizePropertyInfo ,
getDownloadTotalSize ,
DownloadErrorCallback ,
DownloadErrorCallbackC ,
DownloadErrorSignalInfo ,
afterDownloadError ,
downloadErrorCallbackWrapper ,
downloadErrorClosure ,
mkDownloadErrorCallback ,
noDownloadErrorCallback ,
onDownloadError ,
) 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.WebKit.Types
import GI.WebKit.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
type DownloadErrorCallback =
Int32 ->
Int32 ->
T.Text ->
IO Bool
noDownloadErrorCallback :: Maybe DownloadErrorCallback
noDownloadErrorCallback = Nothing
type DownloadErrorCallbackC =
Ptr () ->
Int32 ->
Int32 ->
CString ->
Ptr () ->
IO CInt
foreign import ccall "wrapper"
mkDownloadErrorCallback :: DownloadErrorCallbackC -> IO (FunPtr DownloadErrorCallbackC)
downloadErrorClosure :: DownloadErrorCallback -> IO Closure
downloadErrorClosure cb = newCClosure =<< mkDownloadErrorCallback wrapped
where wrapped = downloadErrorCallbackWrapper cb
downloadErrorCallbackWrapper ::
DownloadErrorCallback ->
Ptr () ->
Int32 ->
Int32 ->
CString ->
Ptr () ->
IO CInt
downloadErrorCallbackWrapper _cb _ error_code error_detail reason _ = do
reason' <- cstringToText reason
result <- _cb error_code error_detail reason'
let result' = (fromIntegral . fromEnum) result
return result'
onDownloadError :: (GObject a, MonadIO m) => a -> DownloadErrorCallback -> m SignalHandlerId
onDownloadError obj cb = liftIO $ connectDownloadError obj cb SignalConnectBefore
afterDownloadError :: (GObject a, MonadIO m) => a -> DownloadErrorCallback -> m SignalHandlerId
afterDownloadError obj cb = connectDownloadError obj cb SignalConnectAfter
connectDownloadError :: (GObject a, MonadIO m) =>
a -> DownloadErrorCallback -> SignalConnectMode -> m SignalHandlerId
connectDownloadError obj cb after = liftIO $ do
cb' <- mkDownloadErrorCallback (downloadErrorCallbackWrapper cb)
connectSignalFunPtr obj "error" cb' after
getDownloadCurrentSize :: (MonadIO m, DownloadK o) => o -> m Word64
getDownloadCurrentSize obj = liftIO $ getObjectPropertyUInt64 obj "current-size"
data DownloadCurrentSizePropertyInfo
instance AttrInfo DownloadCurrentSizePropertyInfo where
type AttrAllowedOps DownloadCurrentSizePropertyInfo = '[ 'AttrGet]
type AttrSetTypeConstraint DownloadCurrentSizePropertyInfo = (~) ()
type AttrBaseTypeConstraint DownloadCurrentSizePropertyInfo = DownloadK
type AttrGetType DownloadCurrentSizePropertyInfo = Word64
type AttrLabel DownloadCurrentSizePropertyInfo = "Download::current-size"
attrGet _ = getDownloadCurrentSize
attrSet _ = undefined
attrConstruct _ = undefined
getDownloadDestinationUri :: (MonadIO m, DownloadK o) => o -> m T.Text
getDownloadDestinationUri obj = liftIO $ getObjectPropertyString obj "destination-uri"
setDownloadDestinationUri :: (MonadIO m, DownloadK o) => o -> T.Text -> m ()
setDownloadDestinationUri obj val = liftIO $ setObjectPropertyString obj "destination-uri" val
constructDownloadDestinationUri :: T.Text -> IO ([Char], GValue)
constructDownloadDestinationUri val = constructObjectPropertyString "destination-uri" val
data DownloadDestinationUriPropertyInfo
instance AttrInfo DownloadDestinationUriPropertyInfo where
type AttrAllowedOps DownloadDestinationUriPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
type AttrSetTypeConstraint DownloadDestinationUriPropertyInfo = (~) T.Text
type AttrBaseTypeConstraint DownloadDestinationUriPropertyInfo = DownloadK
type AttrGetType DownloadDestinationUriPropertyInfo = T.Text
type AttrLabel DownloadDestinationUriPropertyInfo = "Download::destination-uri"
attrGet _ = getDownloadDestinationUri
attrSet _ = setDownloadDestinationUri
attrConstruct _ = constructDownloadDestinationUri
getDownloadNetworkRequest :: (MonadIO m, DownloadK o) => o -> m NetworkRequest
getDownloadNetworkRequest obj = liftIO $ getObjectPropertyObject obj "network-request" NetworkRequest
constructDownloadNetworkRequest :: (NetworkRequestK a) => a -> IO ([Char], GValue)
constructDownloadNetworkRequest val = constructObjectPropertyObject "network-request" val
data DownloadNetworkRequestPropertyInfo
instance AttrInfo DownloadNetworkRequestPropertyInfo where
type AttrAllowedOps DownloadNetworkRequestPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
type AttrSetTypeConstraint DownloadNetworkRequestPropertyInfo = NetworkRequestK
type AttrBaseTypeConstraint DownloadNetworkRequestPropertyInfo = DownloadK
type AttrGetType DownloadNetworkRequestPropertyInfo = NetworkRequest
type AttrLabel DownloadNetworkRequestPropertyInfo = "Download::network-request"
attrGet _ = getDownloadNetworkRequest
attrSet _ = undefined
attrConstruct _ = constructDownloadNetworkRequest
getDownloadNetworkResponse :: (MonadIO m, DownloadK o) => o -> m NetworkResponse
getDownloadNetworkResponse obj = liftIO $ getObjectPropertyObject obj "network-response" NetworkResponse
constructDownloadNetworkResponse :: (NetworkResponseK a) => a -> IO ([Char], GValue)
constructDownloadNetworkResponse val = constructObjectPropertyObject "network-response" val
data DownloadNetworkResponsePropertyInfo
instance AttrInfo DownloadNetworkResponsePropertyInfo where
type AttrAllowedOps DownloadNetworkResponsePropertyInfo = '[ 'AttrConstruct, 'AttrGet]
type AttrSetTypeConstraint DownloadNetworkResponsePropertyInfo = NetworkResponseK
type AttrBaseTypeConstraint DownloadNetworkResponsePropertyInfo = DownloadK
type AttrGetType DownloadNetworkResponsePropertyInfo = NetworkResponse
type AttrLabel DownloadNetworkResponsePropertyInfo = "Download::network-response"
attrGet _ = getDownloadNetworkResponse
attrSet _ = undefined
attrConstruct _ = constructDownloadNetworkResponse
getDownloadProgress :: (MonadIO m, DownloadK o) => o -> m Double
getDownloadProgress obj = liftIO $ getObjectPropertyDouble obj "progress"
data DownloadProgressPropertyInfo
instance AttrInfo DownloadProgressPropertyInfo where
type AttrAllowedOps DownloadProgressPropertyInfo = '[ 'AttrGet]
type AttrSetTypeConstraint DownloadProgressPropertyInfo = (~) ()
type AttrBaseTypeConstraint DownloadProgressPropertyInfo = DownloadK
type AttrGetType DownloadProgressPropertyInfo = Double
type AttrLabel DownloadProgressPropertyInfo = "Download::progress"
attrGet _ = getDownloadProgress
attrSet _ = undefined
attrConstruct _ = undefined
getDownloadStatus :: (MonadIO m, DownloadK o) => o -> m DownloadStatus
getDownloadStatus obj = liftIO $ getObjectPropertyEnum obj "status"
data DownloadStatusPropertyInfo
instance AttrInfo DownloadStatusPropertyInfo where
type AttrAllowedOps DownloadStatusPropertyInfo = '[ 'AttrGet]
type AttrSetTypeConstraint DownloadStatusPropertyInfo = (~) ()
type AttrBaseTypeConstraint DownloadStatusPropertyInfo = DownloadK
type AttrGetType DownloadStatusPropertyInfo = DownloadStatus
type AttrLabel DownloadStatusPropertyInfo = "Download::status"
attrGet _ = getDownloadStatus
attrSet _ = undefined
attrConstruct _ = undefined
getDownloadSuggestedFilename :: (MonadIO m, DownloadK o) => o -> m T.Text
getDownloadSuggestedFilename obj = liftIO $ getObjectPropertyString obj "suggested-filename"
data DownloadSuggestedFilenamePropertyInfo
instance AttrInfo DownloadSuggestedFilenamePropertyInfo where
type AttrAllowedOps DownloadSuggestedFilenamePropertyInfo = '[ 'AttrGet]
type AttrSetTypeConstraint DownloadSuggestedFilenamePropertyInfo = (~) ()
type AttrBaseTypeConstraint DownloadSuggestedFilenamePropertyInfo = DownloadK
type AttrGetType DownloadSuggestedFilenamePropertyInfo = T.Text
type AttrLabel DownloadSuggestedFilenamePropertyInfo = "Download::suggested-filename"
attrGet _ = getDownloadSuggestedFilename
attrSet _ = undefined
attrConstruct _ = undefined
getDownloadTotalSize :: (MonadIO m, DownloadK o) => o -> m Word64
getDownloadTotalSize obj = liftIO $ getObjectPropertyUInt64 obj "total-size"
data DownloadTotalSizePropertyInfo
instance AttrInfo DownloadTotalSizePropertyInfo where
type AttrAllowedOps DownloadTotalSizePropertyInfo = '[ 'AttrGet]
type AttrSetTypeConstraint DownloadTotalSizePropertyInfo = (~) ()
type AttrBaseTypeConstraint DownloadTotalSizePropertyInfo = DownloadK
type AttrGetType DownloadTotalSizePropertyInfo = Word64
type AttrLabel DownloadTotalSizePropertyInfo = "Download::total-size"
attrGet _ = getDownloadTotalSize
attrSet _ = undefined
attrConstruct _ = undefined
type instance AttributeList Download = DownloadAttributeList
type DownloadAttributeList = ('[ '("current-size", DownloadCurrentSizePropertyInfo), '("destination-uri", DownloadDestinationUriPropertyInfo), '("network-request", DownloadNetworkRequestPropertyInfo), '("network-response", DownloadNetworkResponsePropertyInfo), '("progress", DownloadProgressPropertyInfo), '("status", DownloadStatusPropertyInfo), '("suggested-filename", DownloadSuggestedFilenamePropertyInfo), '("total-size", DownloadTotalSizePropertyInfo)] :: [(Symbol, *)])
data DownloadErrorSignalInfo
instance SignalInfo DownloadErrorSignalInfo where
type HaskellCallbackType DownloadErrorSignalInfo = DownloadErrorCallback
connectSignal _ = connectDownloadError
type instance SignalList Download = DownloadSignalList
type DownloadSignalList = ('[ '("error", DownloadErrorSignalInfo), '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])
foreign import ccall "webkit_download_new" webkit_download_new ::
Ptr NetworkRequest ->
IO (Ptr Download)
downloadNew ::
(MonadIO m, NetworkRequestK a) =>
a ->
m Download
downloadNew request = liftIO $ do
let request' = unsafeManagedPtrCastPtr request
result <- webkit_download_new request'
checkUnexpectedReturnNULL "webkit_download_new" result
result' <- (wrapObject Download) result
touchManagedPtr request
return result'
foreign import ccall "webkit_download_cancel" webkit_download_cancel ::
Ptr Download ->
IO ()
downloadCancel ::
(MonadIO m, DownloadK a) =>
a ->
m ()
downloadCancel _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
webkit_download_cancel _obj'
touchManagedPtr _obj
return ()
foreign import ccall "webkit_download_get_current_size" webkit_download_get_current_size ::
Ptr Download ->
IO Word64
downloadGetCurrentSize ::
(MonadIO m, DownloadK a) =>
a ->
m Word64
downloadGetCurrentSize _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_current_size _obj'
touchManagedPtr _obj
return result
foreign import ccall "webkit_download_get_destination_uri" webkit_download_get_destination_uri ::
Ptr Download ->
IO CString
downloadGetDestinationUri ::
(MonadIO m, DownloadK a) =>
a ->
m T.Text
downloadGetDestinationUri _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_destination_uri _obj'
checkUnexpectedReturnNULL "webkit_download_get_destination_uri" result
result' <- cstringToText result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_get_elapsed_time" webkit_download_get_elapsed_time ::
Ptr Download ->
IO CDouble
downloadGetElapsedTime ::
(MonadIO m, DownloadK a) =>
a ->
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'
foreign import ccall "webkit_download_get_network_request" webkit_download_get_network_request ::
Ptr Download ->
IO (Ptr NetworkRequest)
downloadGetNetworkRequest ::
(MonadIO m, DownloadK a) =>
a ->
m NetworkRequest
downloadGetNetworkRequest _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_network_request _obj'
checkUnexpectedReturnNULL "webkit_download_get_network_request" result
result' <- (newObject NetworkRequest) result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_get_network_response" webkit_download_get_network_response ::
Ptr Download ->
IO (Ptr NetworkResponse)
downloadGetNetworkResponse ::
(MonadIO m, DownloadK a) =>
a ->
m NetworkResponse
downloadGetNetworkResponse _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_network_response _obj'
checkUnexpectedReturnNULL "webkit_download_get_network_response" result
result' <- (newObject NetworkResponse) result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_get_progress" webkit_download_get_progress ::
Ptr Download ->
IO CDouble
downloadGetProgress ::
(MonadIO m, DownloadK a) =>
a ->
m Double
downloadGetProgress _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_progress _obj'
let result' = realToFrac result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_get_status" webkit_download_get_status ::
Ptr Download ->
IO CUInt
downloadGetStatus ::
(MonadIO m, DownloadK a) =>
a ->
m DownloadStatus
downloadGetStatus _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_status _obj'
let result' = (toEnum . fromIntegral) result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_get_suggested_filename" webkit_download_get_suggested_filename ::
Ptr Download ->
IO CString
downloadGetSuggestedFilename ::
(MonadIO m, DownloadK a) =>
a ->
m T.Text
downloadGetSuggestedFilename _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_suggested_filename _obj'
checkUnexpectedReturnNULL "webkit_download_get_suggested_filename" result
result' <- cstringToText result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_get_total_size" webkit_download_get_total_size ::
Ptr Download ->
IO Word64
downloadGetTotalSize ::
(MonadIO m, DownloadK a) =>
a ->
m Word64
downloadGetTotalSize _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_total_size _obj'
touchManagedPtr _obj
return result
foreign import ccall "webkit_download_get_uri" webkit_download_get_uri ::
Ptr Download ->
IO CString
downloadGetUri ::
(MonadIO m, DownloadK a) =>
a ->
m T.Text
downloadGetUri _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
result <- webkit_download_get_uri _obj'
checkUnexpectedReturnNULL "webkit_download_get_uri" result
result' <- cstringToText result
touchManagedPtr _obj
return result'
foreign import ccall "webkit_download_set_destination_uri" webkit_download_set_destination_uri ::
Ptr Download ->
CString ->
IO ()
downloadSetDestinationUri ::
(MonadIO m, DownloadK a) =>
a ->
T.Text ->
m ()
downloadSetDestinationUri _obj destination_uri = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
destination_uri' <- textToCString destination_uri
webkit_download_set_destination_uri _obj' destination_uri'
touchManagedPtr _obj
freeMem destination_uri'
return ()
foreign import ccall "webkit_download_start" webkit_download_start ::
Ptr Download ->
IO ()
downloadStart ::
(MonadIO m, DownloadK a) =>
a ->
m ()
downloadStart _obj = liftIO $ do
let _obj' = unsafeManagedPtrCastPtr _obj
webkit_download_start _obj'
touchManagedPtr _obj
return ()