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
Nested ClassesModifier and TypeClassDescriptionstatic classDownload.Builder<B extends Download.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theCreatedDestinationCallbackcallback.static interfaceFunctional interface declaration of theDecideDestinationCallbackcallback.static classstatic interfaceFunctional interface declaration of theFailedCallbackcallback.static interfaceFunctional interface declaration of theFinishedCallbackcallback.static interfaceFunctional interface declaration of theReceivedDataCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionDownload()Creates a new Download.Download(MemorySegment address) Create a Download proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected DownloadasParent()Returns this instance as if it were its parent type.static Download.Builder<? extends Download.Builder> builder()ADownload.Builderobject constructs aDownloadwith the specified properties.voidcancel()Cancels the download.voidemitCreatedDestination(String destination) Emits the "created-destination" signal.booleanemitDecideDestination(String suggestedFilename) Emits the "decide-destination" signal.voidemitFailed(@Nullable GError error) Emits the "failed" signal.voidEmits the "finished" signal.voidemitReceivedData(long dataLength) Emits the "received-data" signal.booleanReturns the current value of theWebKitDownload:allow-overwrite property.@Nullable StringObtains the destination to which the downloaded file will be written.doubleGets the elapsed time in seconds, including any fractional part.doubleGets the value of theWebKitDownload:estimated-progress property.longGets the length of the data already downloaded fordownload.Retrieves theWebKitURIRequestobject that backs the download process.Retrieves theWebKitURIResponseobject that backs the download process.static @Nullable TypegetType()Get the GType of the Download classGet theWebKitWebViewthat 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.voidsetAllowOverwrite(boolean allowed) Sets theWebKitDownload:allow-overwrite property.voidsetDestination(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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
-
Download
public Download()Creates a new Download.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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_USERerror. -
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 - Since:
- 2.6
-
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 ofdownload.- 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 fordownload.Gets the length of the data already downloaded for this Download in bytes.
- Returns:
- the amount of bytes already downloaded.
-
getRequest
Retrieves theWebKitURIRequestobject that backs the download process.- Returns:
- the
WebKitURIRequestof this Download
-
getResponse
Retrieves theWebKitURIResponseobject that backs the download process.Retrieves the
WebKitURIResponseobject that backs the download process. This method returnsnullif 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, ornullif the response hasn't been received yet.
-
getWebView
Get theWebKitWebViewthat initiated the download.- Returns:
- the
WebKitWebViewthat initiateddownload,ornullif 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- Since:
- 2.6
-
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_DOWNLOADdirectory.- 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.webkitgtk.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_DOWNLOADdirectory usingsuggestedFilename.Since 2.40, you may handle this signal asynchronously by returning
truewithout 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.webkitgtk.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.webkitgtk.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.webkitgtk.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.webkitgtk.Download.ReceivedDataCallback). -
builder
ADownload.Builderobject constructs aDownloadwith the specified properties. Use the variousset...()methods to set properties, and finish construction withDownload.Builder.build().- Returns:
- the builder object
-