Refactor file download

This commit is contained in:
Tobias Fella 2020-05-18 21:20:23 +02:00
parent b338f017c9
commit d68d44faa8
2 changed files with 10 additions and 4 deletions

View File

@ -149,11 +149,18 @@ QString Fetcher::image(QString url)
return path;
}
download(url);
return QLatin1String("");
}
void Fetcher::download(QString url)
{
QNetworkRequest request((QUrl(url)));
QNetworkReply *reply = manager->get(request);
connect(reply, &QNetworkReply::finished, this, [this, url, reply, path]() {
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
QByteArray data = reply->readAll();
QFile file(path);
QFile file(filePath(url));
file.open(QIODevice::WriteOnly);
file.write(data);
file.close();
@ -161,8 +168,6 @@ QString Fetcher::image(QString url)
emit updated();
delete reply;
});
return QLatin1String("");
}
void Fetcher::removeImage(QString url)

View File

@ -37,6 +37,7 @@ public:
void fetch(QUrl);
QString image(QString);
void removeImage(QString);
void download(QString url);
private:
Fetcher();