From d68d44faa8d87f1bca2c781546656786baab1e8c Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 18 May 2020 21:20:23 +0200 Subject: [PATCH] Refactor file download --- src/fetcher.cpp | 13 +++++++++---- src/fetcher.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 49bf20f0..58ce8da8 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -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) diff --git a/src/fetcher.h b/src/fetcher.h index a6ee1cf4..204d3a20 100644 --- a/src/fetcher.h +++ b/src/fetcher.h @@ -37,6 +37,7 @@ public: void fetch(QUrl); QString image(QString); void removeImage(QString); + void download(QString url); private: Fetcher();