WebDownloadRequest

Since: BlackBerry 10.0.0

#include <bb/cascades/WebDownloadRequest>

A request to download a file.

The WebDownloadRequest class is used with WebPage::download() to download a file to the local file system. You must ensure that the device has a working network connection before trying to download a file.

Specify the URL to download using url. Specify the location to download the file to using absoluteFilePath. The path must be an absolute path, including file name and extension. For example, "/accounts/1000/shared/downloads/mydownload.myextension". If the absoluteFilePath is empty, a file picker will be shown and the user can pick a location and file name.

WebDownloadRequest is normally used from C++ in advanced use cases, but here is an example of using WebDownloadRequest in QML.

import bb.cascades 1.4
import WebPageComponent 1.0
Page {
    Container {
        Label {
            id: label
            text: "Download Status Goes Here"
        }
        attachedObjects: [
            WebPage {
                id: page
                onInitialized: {
                    page.download(myDownloadRequest);
                }
            },
            WebDownloadRequest {
                id: myDownloadRequest
                url: "http://www.example.com/index.html"
                // Leave out the absoluteFilePath if you want to show a
                // file picker when the download is started and let the user
                // pick where to save the downloaded file.
                absoluteFilePath: "/accounts/1000/shared/downloads/index.html"
                onStarted: { label.text = "Download Started" }
                onSucceeded: { label.text = "Download Finished" }
                onFailed: { label.text = "Download Failed" }
            }
        ]
    }
}
This example assumes that you've registered both WebPage and WebDownloadRequest with QML. To register these classes with QML, add the following lines to your C++ main program:
class MyWebPage : public bb::cascades::WebPage {
    Q_OBJECT
public:
    MyWebPage(QObject* parent = 0)
        : bb::cascades::WebPage(parent)
    {
    }
    Q_INVOKABLE void download(bb::cascades::WebDownloadRequest* request)
    {
        bb::cascades::WebPage::download(request);
    }
};

int main(int argc, char** argv)
{

    qmlRegisterType<MyWebPage>("WebPageComponent", 1, 0, "WebPage");
    qmlRegisterType<bb::cascades::WebDownloadRequest>("WebPageComponent", 1, 0, "WebDownloadRequest");


Overview

QML properties

absoluteFilePath: QString
status: bb::cascades::WebLoadStatus::Type [read-only]
url: QUrl

Public Functions Index

WebDownloadRequest ()
WebDownloadRequest (const QUrl &url, QObject *parent=0)
virtual ~WebDownloadRequest ()
QStringabsoluteFilePath () const
bb::cascades::WebLoadStatus::Typestatus () const
QUrlurl () const

Public Slots Index

voidsetAbsoluteFilePath (const QString &absoluteFilePath)

Signals Index

voidabsoluteFilePathChanged (const QString &newAbsoluteFilePath)
voidfailed ()
voidstarted ()
voidstatusChanged (WebLoadStatus::Type newStatus)
voidsucceeded ()

Properties

QString absoluteFilePath

The path to download the file to.

Since:

BlackBerry 10.0.0

bb::cascades::WebLoadStatus::Type status[read-only]

The download status.

Since:

BlackBerry 10.0.0

QUrl url

The URL to download.

Since:

BlackBerry 10.0.0

Public Functions

WebDownloadRequest ()

Used for QML support only.

Since:

BlackBerry 10.0.0

WebDownloadRequest (

Constructs a new WebDownloadRequest for the provided URL.

Parameters
url

The URL to download.

parent

Optional parent for this object.

Since:

BlackBerry 10.0.0

virtual~WebDownloadRequest ()

Destructor.

QString absoluteFilePath ()

Retrieves the path to save the downloaded file to.

Return:

The path to save the downloaded file to.

Since:

BlackBerry 10.0.0

bb::cascades::WebLoadStatus::Type status ()

Retrieves the current status of this WebDownloadRequest.

Return:

The current download status.

Since:

BlackBerry 10.0.0

QUrl url ()

Retrieves the URL to download in this WebDownloadRequest.

Return:

url The URL to download.

Since:

BlackBerry 10.0.0

Public Slots

void setAbsoluteFilePath (

Sets the path to save the downloaded file to.

Parameters
absoluteFilePath

The new path.

Since:

BlackBerry 10.0.0

Signals

void absoluteFilePathChanged (
  • const QString &newAbsoluteFilePath)

Emitted when the path to download the file to changes.

Parameters
newAbsoluteFilePath

The new path.

Since:

BlackBerry 10.0.0

void failed ()

Emitted when download finishes because the download failed.

Since:

BlackBerry 10.0.0

void started ()

Emitted when download starts.

Since:

BlackBerry 10.0.0

void statusChanged (

Emitted when the download status changes.

Parameters
newStatus

The new status.

Since:

BlackBerry 10.0.0

void succeeded ()

Emitted when download finishes and the download was successful.

Since:

BlackBerry 10.0.0

Last modified: 2014-11-17



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus