Qdownloader is a service that simplify the download of remote resources (http(s)) locally. Build around 2 classes, it can be used in cpp or qml
- simple, just include the pri into your pro file
- made of only 2 simple classes
- register the service from a single method call
- multiple asynchronous download
- qml ready, just register the service, start a download with javascript, listen for connection or use one of the property
- take care of all the connection and download process
- notification ready (only sailfish os as v1.0)
Some example
You can use IconProvider from both Qt and Qml
Registering the service
// from the main process QScopedPointerapp(SailfishApp::application(argc, argv)); QScopedPointer view(SailfishApp::createView()); // register the locator into qml with the default service name QDownloaderService::init(view->rootContext());
from Qml
function myDownloadFunction() { if(qdownloader.start(sourceurl, targeturl, "my notification message") === false ) { // error detected before download (file already exist, r/w error etc...) // let's do something } } Connections { target: qdownloader onDownloading: { // url : url for the remote resource // read : bytes read // total : total byte for the file } onSuccess: { // url : url for the remote resource // target : url for the local file } onError: { // url : url for the remote resource // status : error code -> QNetworkReply::NetworkError } }
from QT
// register slot / signal to get response connect(&QDownloaderService::getInstance(), SIGNAL(success(QUrl,QString)), this, SLOT(success(QUrl,QString))); connect(&QDownloaderService::getInstance(), SIGNAL(error(QUrl,QNetworkReply::NetworkError)), this, SLOT(error(QUrl,QNetworkReply::NetworkError))); // start a download QDOWNSERVICE.start( sourceurl, targeturl, "my notification message" );
wherever your start a download, qml or cpp, all connections will receive callback
For additional information check the sample program (Full Sailfish app)
Install
Install is really simple and only require to add the lib to your project. Steps assume you use the default names and locations
- Copy the src/qdownloader directory into your src directory
- Edit the project's .pro file and include qdownloader.pri reference
From Github or inside the .tgz you will find a full qtcreator project.
Download
You can get QDownloader from the github repository
Editing .pro file
Here the .pro file for the sample application
TARGET = harbour-test_qdownload CONFIG += sailfishapp include(src/qdownloader/qdownloader.pri) SOURCES += src/harbour-test_qdownload.cpp DISTFILES += qml/harbour-test_qdownload.qml \ qml/cover/*.qml \ qml/pages/*.qml \ qml/composents/*.qml \ rpm/harbour-test_qdownload.changes \ rpm/harbour-test_qdownload.spec \ rpm/harbour-test_qdownload.yaml \ harbour-test_qdownload.desktop SAILFISHAPP_ICONS = 86x86 108x108 128x128 256x256