Class Download

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class Download extends GObject

Object used to communicate with the application when downloading.

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.

  • Constructor Details

    • Download

      public Download(MemorySegment address)
      Create a Download instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Download

      public Download()
      Create a new Download.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Download class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Download asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • cancel

      public void cancel()

      Cancels the download.

      When the ongoing download operation is effectively cancelled the signal WebKitDownload::failed is emitted with DownloadError.CANCELLED_BY_USER error.

    • getAllowOverwrite

      public boolean getAllowOverwrite()

      Returns the current value of the WebKitDownload: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

      public @Nullable String 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 the WebKitDownload:estimated-progress property. Gets the value of the WebKitDownload:estimated-progress property. You can monitor the estimated progress of the download operation by connecting to the notify::estimated-progress signal of 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 download.

      Gets the length of the data already downloaded for this Download in bytes.

      Returns:
      the amount of bytes already downloaded.
    • getRequest

      public URIRequest getRequest()
      Retrieves the WebKitURIRequest object that backs the download process.
      Returns:
      the WebKitURIRequest of this Download
    • getResponse

      public URIResponse getResponse()

      Retrieves the WebKitURIResponse object that backs the download process.

      Retrieves the WebKitURIResponse object that backs the download process. This method returns null 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, or null if the response hasn't been received yet.
    • getWebView

      public WebView getWebView()
      Get the WebKitWebView that initiated the download.
      Returns:
      the WebKitWebView that initiated download, or null if this Download was not initiated by a WebKitWebView.
    • setAllowOverwrite

      public void setAllowOverwrite(boolean allowed)

      Sets the WebKitDownload: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 the WebKitDownload:allow-overwrite property
      Since:
      2.6
    • setDestination

      public void setDestination(String destination)

      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 in UserDirectory.DIRECTORY_DOWNLOAD directory.

      Parameters:
      destination - the destination
    • onCreatedDestination

      This signal is emitted after WebKitDownload::decide-destination and before WebKitDownload::received-data to notify that destination file has been created successfully at destination.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitCreatedDestination

      public void emitCreatedDestination(String destination)
      Emits the "created-destination" signal. See onCreatedDestination(Download.CreatedDestinationCallback).
    • onDecideDestination

      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 to UserDirectory.DIRECTORY_DOWNLOAD directory using suggestedFilename.

      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

      public boolean emitDecideDestination(String suggestedFilename)
      Emits the "decide-destination" signal. See onDecideDestination(Download.DecideDestinationCallback).
    • onFailed

      This signal is emitted when an error occurs during the download operation. The given error, of the domain WEBKIT_DOWNLOAD_ERROR, contains further details of the failure. If the download is cancelled with webkit_download_cancel(), this signal is emitted with error DownloadError.CANCELLED_BY_USER. The download operation finishes after an error and WebKitDownload::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

      public void emitFailed(@Nullable GError error)
      Emits the "failed" signal. See onFailed(Download.FailedCallback).
    • onFinished

      This signal is emitted when download finishes successfully or due to an error. In case of errors WebKitDownload::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. See onFinished(Download.FinishedCallback).
    • onReceivedData

      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. See onReceivedData(Download.ReceivedDataCallback).
    • builder

      public static Download.Builder<? extends Download.Builder> builder()
      A Download.Builder object constructs a Download with the specified properties. Use the various set...() methods to set properties, and finish construction with Download.Builder.build().
      Returns:
      the builder object