Class Download
- All Implemented Interfaces:
Proxy
WebKitDownload
carries information about a download request and
response, including a WebKitURIRequest
and a WebKitURIResponse
objects. The application may use this object to control the
download process, or to simply figure out what is to be downloaded,
and handle the download process itself.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Download.Builder<B extends Download.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theCreatedDestinationCallback
callback.static interface
Functional interface declaration of theDecideDestinationCallback
callback.static class
static interface
Functional interface declaration of theFailedCallback
callback.static interface
Functional interface declaration of theFinishedCallback
callback.static interface
Functional interface declaration of theReceivedDataCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionDownload
(MemorySegment address) Create a Download proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Download
asParent()
Returns this instance as if it were its parent type.static Download.Builder
<? extends Download.Builder> builder()
ADownload.Builder
object constructs aDownload
with the specified properties.void
cancel()
Cancels the download.void
emitCreatedDestination
(String destination) Emits the "created-destination" signal.boolean
emitDecideDestination
(String suggestedFilename) Emits the "decide-destination" signal.void
emitFailed
(GError error) Emits the "failed" signal.void
Emits the "finished" signal.void
emitReceivedData
(long dataLength) Emits the "received-data" signal.boolean
Returns the current value of theWebKitDownload
:allow-overwrite property.Obtains the destination to which the downloaded file will be written.double
Gets the elapsed time in seconds, including any fractional part.double
Gets the value of theWebKitDownload
:estimated-progress property.long
Gets the length of the data already downloaded for this Download.Retrieves theWebKitURIRequest
object that backs the download process.Retrieves theWebKitURIResponse
object that backs the download process.static Type
getType()
Get the GType of the Download classGet theWebKitWebView
that initiated the download.This signal is emitted afterWebKitDownload
::decide-destination and beforeWebKitDownload
::received-data to notify that destination file has been created successfully atdestination
.This signal is emitted after response is received to decide a destination for the download using webkit_download_set_destination().onFailed
(Download.FailedCallback handler) This signal is emitted when an error occurs during the download operation.onFinished
(Download.FinishedCallback handler) This signal is emitted when download finishes successfully or due to an error.This signal is emitted after response is received, every time new data has been written to the destination.void
setAllowOverwrite
(boolean allowed) Sets theWebKitDownload
:allow-overwrite property.void
setDestination
(String destination) Sets the destination to which the downloaded file will be written.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Download
Create a Download proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
cancel
public void cancel()Cancels the download.When the ongoing download operation is effectively cancelled the signal
WebKitDownload
::failed is emitted withDownloadError.CANCELLED_BY_USER
error. -
getAllowOverwrite
public boolean getAllowOverwrite()Returns the current value of theWebKitDownload
:allow-overwrite property.Returns the current value of the
WebKitDownload
:allow-overwrite property, which determines whether the download will overwrite an existing file on disk, or if it will fail if the destination already exists.- Returns:
- the current value of the
WebKitDownload
:allow-overwrite property
-
getDestination
Obtains the destination to which the downloaded file will be written.You can connect to
WebKitDownload
::created-destination to make sure this method returns a valid destination.- Returns:
- the destination or
null
-
getElapsedTime
public double getElapsedTime()Gets the elapsed time in seconds, including any fractional part.If the download finished, had an error or was cancelled this is the time between its start and the event.
- Returns:
- seconds since the download was started
-
getEstimatedProgress
public double getEstimatedProgress()Gets the value of theWebKitDownload
:estimated-progress property. Gets the value of theWebKitDownload
:estimated-progress property. You can monitor the estimated progress of the download operation by connecting to the notify::estimated-progress signal of this Download.- Returns:
- an estimate of the of the percent complete for a download as a range from 0.0 to 1.0.
-
getReceivedDataLength
public long getReceivedDataLength()Gets the length of the data already downloaded for this Download.Gets the length of the data already downloaded for this Download in bytes.
- Returns:
- the amount of bytes already downloaded.
-
getRequest
Retrieves theWebKitURIRequest
object that backs the download process.- Returns:
- the
WebKitURIRequest
of this Download
-
getResponse
Retrieves theWebKitURIResponse
object that backs the download process.Retrieves the
WebKitURIResponse
object that backs the download process. This method returnsnull
if called before the response is received from the server. You can connect to notify::response signal to be notified when the response is received.- Returns:
- the
WebKitURIResponse
, ornull
if the response hasn't been received yet.
-
getWebView
Get theWebKitWebView
that initiated the download.- Returns:
- the
WebKitWebView
that initiated this Download, ornull
if this Download was not initiated by aWebKitWebView
.
-
setAllowOverwrite
public void setAllowOverwrite(boolean allowed) Sets theWebKitDownload
:allow-overwrite property.Sets the
WebKitDownload
:allow-overwrite property, which determines whether the download may overwrite an existing file on disk, or if it will fail if the destination already exists.- Parameters:
allowed
- the new value for theWebKitDownload
:allow-overwrite property
-
setDestination
Sets the destination to which the downloaded file will be written.This method should be called before the download transfer starts or it will not have any effect on the ongoing download operation. To set the destination using the filename suggested by the server connect to
WebKitDownload
::decide-destination signal and call webkit_download_set_destination(). If you want to set a fixed destination that doesn't depend on the suggested filename you can connect to notify::response signal and call webkit_download_set_destination().If
WebKitDownload
::decide-destination signal is not handled and destination is not set when the download transfer starts, the file will be saved with the filename suggested by the server inUserDirectory.DIRECTORY_DOWNLOAD
directory.- Parameters:
destination
- the destination
-
onCreatedDestination
public SignalConnection<Download.CreatedDestinationCallback> onCreatedDestination(Download.CreatedDestinationCallback handler) This signal is emitted afterWebKitDownload
::decide-destination and beforeWebKitDownload
::received-data to notify that destination file has been created successfully atdestination
.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitCreatedDestination
Emits the "created-destination" signal. SeeonCreatedDestination(org.gnome.webkit.Download.CreatedDestinationCallback)
. -
onDecideDestination
public SignalConnection<Download.DecideDestinationCallback> onDecideDestination(Download.DecideDestinationCallback handler) This signal is emitted after response is received to decide a destination for the download using webkit_download_set_destination(). If this signal is not handled, the file will be downloaded toUserDirectory.DIRECTORY_DOWNLOAD
directory usingsuggestedFilename
.Since 2.40, you may handle this signal asynchronously by returning
true
without calling webkit_download_set_destination(). This indicates intent to eventually call webkit_download_set_destination(). In this case, the download will not proceed until the destination is set or cancelled with webkit_download_cancel().- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDecideDestination
Emits the "decide-destination" signal. SeeonDecideDestination(org.gnome.webkit.Download.DecideDestinationCallback)
. -
onFailed
This signal is emitted when an error occurs during the download operation. The givenerror
, of the domainWEBKIT_DOWNLOAD_ERROR
, contains further details of the failure. If the download is cancelled with webkit_download_cancel(), this signal is emitted with errorDownloadError.CANCELLED_BY_USER
. The download operation finishes after an error andWebKitDownload
::finished signal is emitted after this one.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitFailed
Emits the "failed" signal. SeeonFailed(org.gnome.webkit.Download.FailedCallback)
. -
onFinished
This signal is emitted when download finishes successfully or due to an error. In case of errorsWebKitDownload
::failed signal is emitted before this one.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitFinished
public void emitFinished()Emits the "finished" signal. SeeonFinished(org.gnome.webkit.Download.FinishedCallback)
. -
onReceivedData
public SignalConnection<Download.ReceivedDataCallback> onReceivedData(Download.ReceivedDataCallback handler) This signal is emitted after response is received, every time new data has been written to the destination. It's useful to know the progress of the download operation.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitReceivedData
public void emitReceivedData(long dataLength) Emits the "received-data" signal. SeeonReceivedData(org.gnome.webkit.Download.ReceivedDataCallback)
. -
builder
ADownload.Builder
object constructs aDownload
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withDownload.Builder.build()
.
-