Simple file downloader with progress reporting.
More...
#include <downloader.h>
|
void | downloadFile (const QString &url, bool protected_contents=false, const QString &username=QString(), const QString &password=QString()) |
| Performs asynchronous download of given file. Redirections are handled. More...
|
|
void | uploadBundleFile (QString url, const QString &bundle_data, const QString &key, const QString &author_name, const QString &author_email, const QString &application_name, const QString &application_icon) |
| Uploads given bundle_data to store server via HTTP POST. More...
|
|
|
void | progress (qint64 bytes_received, qint64 bytes_total) |
| Emitted when new progress is known. More...
|
|
void | completed (QNetworkReply::NetworkError status, QByteArray contents=QByteArray()) |
| Emitted if file download or upload completes (un)successfully. More...
|
|
Simple file downloader with progress reporting.
Definition at line 47 of file downloader.h.
Downloader::Downloader |
( |
QObject * |
parent = 0 | ) |
|
|
explicit |
Constructor.
- Parameters
-
parent | Parent to this instance. |
Definition at line 40 of file downloader.cpp.
44 m_timer(
new QTimer(
this)) {
46 m_timer->setInterval(2000);
47 m_timer->setSingleShot(
true);
50 connect(m_downloadManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(finished(QNetworkReply*)));
Network access manager with supressed authentication dialogs.
void Downloader::completed |
( |
QNetworkReply::NetworkError |
status, |
|
|
QByteArray |
contents = QByteArray() |
|
) |
| |
|
signal |
Emitted if file download or upload completes (un)successfully.
- Parameters
-
status | Status of file download/upload. |
contents | QByteArray containing downloaded file (if any) or post reply. |
void Downloader::downloadFile |
( |
const QString & |
url, |
|
|
bool |
protected_contents = false , |
|
|
const QString & |
username = QString() , |
|
|
const QString & |
password = QString() |
|
) |
| |
|
slot |
Performs asynchronous download of given file. Redirections are handled.
- Parameters
-
url | URL of file to be downloaded. |
protected_contents | Are contents of URL protected? |
username | Username if contents are protected. |
password | Password if contents are protected. |
Definition at line 57 of file downloader.cpp.
59 QNetworkRequest request;
60 QObject originatingObject;
63 originatingObject.setProperty(
"protected", protected_contents);
64 originatingObject.setProperty(
"username", username);
65 originatingObject.setProperty(
"password", password);
66 request.setOriginatingObject(&originatingObject);
70 runGetRequest(request);
void Downloader::progress |
( |
qint64 |
bytes_received, |
|
|
qint64 |
bytes_total |
|
) |
| |
|
signal |
Emitted when new progress is known.
- Parameters
-
bytes_received | Number of bytes received. |
bytes_total | Number of bytes total. |
void Downloader::uploadBundleFile |
( |
QString |
url, |
|
|
const QString & |
bundle_data, |
|
|
const QString & |
key, |
|
|
const QString & |
author_name, |
|
|
const QString & |
author_email, |
|
|
const QString & |
application_name, |
|
|
const QString & |
application_icon |
|
) |
| |
|
slot |
Uploads given bundle_data to store server via HTTP POST.
- Parameters
-
url | URL to store server |
bundle_data | |
Definition at line 73 of file downloader.cpp.
77 QNetworkRequest request;
80 request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
85 data +=
"author_name=%2&";
86 data +=
"author_email=%3&";
87 data +=
"application_name=%4&";
88 data +=
"file_content=%5&";
89 data +=
"application_icon=%6";
92 data = data.arg(QUrl::toPercentEncoding(key),
93 QUrl::toPercentEncoding(author_name),
94 QUrl::toPercentEncoding(author_email),
95 QUrl::toPercentEncoding(application_name),
96 QUrl::toPercentEncoding(bundle_data),
105 runPostRequest(request, data.toLocal8Bit());
static QByteArray fileToBase64(const QString &file_name)
Takes input file and reads it into base64 byte array.
The documentation for this class was generated from the following files: