-
Notifications
You must be signed in to change notification settings - Fork 39
/
filedownloader.cpp
39 lines (32 loc) · 1.03 KB
/
filedownloader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "filedownloader.h"
FileDownloader::FileDownloader(int id, QUrl imageUrl, QObject *parent) : QObject(parent) {
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply *)), this, SLOT(fileDownloaded(QNetworkReply *)));
myUrl = imageUrl;
myId = id;
//Refresh(); // Commented out to avoid downloading upon creation
}
void FileDownloader::Refresh() {
QNetworkRequest request(myUrl);
m_WebCtrl.get(request);
}
FileDownloader::~FileDownloader() { }
void FileDownloader::fileDownloaded(QNetworkReply *pReply) {
if(pReply->error() != QNetworkReply::NoError) {
qDebug() << "FileDownloader: Get Request Error!";
emit downloaded(-1); // Signal error
} else {
m_DownloadedData = pReply->readAll();
emit downloaded(myId);
}
pReply->deleteLater();
}
void FileDownloader::newUrl(const QUrl &value) {
myUrl = value;
Refresh();
}
QByteArray FileDownloader::downloadedData() const {
return m_DownloadedData;
}
QUrl FileDownloader::CurrentUrl() const {
return myUrl;
}