mirror of
https://github.com/KDE/kasts.git
synced 2024-12-25 16:02:54 +01:00
Refactor file download
This commit is contained in:
parent
b338f017c9
commit
d68d44faa8
@ -149,11 +149,18 @@ QString Fetcher::image(QString url)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
download(url);
|
||||||
|
|
||||||
|
return QLatin1String("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fetcher::download(QString url)
|
||||||
|
{
|
||||||
QNetworkRequest request((QUrl(url)));
|
QNetworkRequest request((QUrl(url)));
|
||||||
QNetworkReply *reply = manager->get(request);
|
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();
|
QByteArray data = reply->readAll();
|
||||||
QFile file(path);
|
QFile file(filePath(url));
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
file.write(data);
|
file.write(data);
|
||||||
file.close();
|
file.close();
|
||||||
@ -161,8 +168,6 @@ QString Fetcher::image(QString url)
|
|||||||
emit updated();
|
emit updated();
|
||||||
delete reply;
|
delete reply;
|
||||||
});
|
});
|
||||||
|
|
||||||
return QLatin1String("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fetcher::removeImage(QString url)
|
void Fetcher::removeImage(QString url)
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
void fetch(QUrl);
|
void fetch(QUrl);
|
||||||
QString image(QString);
|
QString image(QString);
|
||||||
void removeImage(QString);
|
void removeImage(QString);
|
||||||
|
void download(QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Fetcher();
|
Fetcher();
|
||||||
|
Loading…
Reference in New Issue
Block a user