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
40
41
42
43
44
|
#include "downloadmanager.h"
#include <QtCore>
int main(int argc, char **argv)
{
if(argc != 2) {
qDebug("Usage: %s filters.txt", argv[0]);
return 77;
}
QCoreApplication app(argc, argv);
DownloadManager manager;
QSettings listconf(argv[1], QSettings::IniFormat);
QVector<QNetworkReply *> downloads;
qDebug("Filters:");
for(auto &g : listconf.childGroups()) {
listconf.beginGroup(g);
const auto url = listconf.value("Href").toUrl();
qDebug("|%s |%s|", qUtf8Printable(g.leftJustified(16, ' ', true)), qUtf8Printable(listconf.value("Href").toString().leftJustified(100, ' ', true)));
auto *reply = manager.download(url);
downloads.append(reply);
QObject::connect(reply, &QNetworkReply::finished, [&downloads, reply]() {
if(reply->error() == QNetworkReply::NoError) {
qDebug("downloaded %s", qUtf8Printable(reply->url().toString()));
} else {
qDebug("failed %s", qUtf8Printable(reply->url().toString()));
qDebug("error [%i]: %s", reply->error(), qUtf8Printable(reply->errorString()));
}
downloads.removeAll(reply);
if(downloads.isEmpty()) {
QCoreApplication::instance()->quit();
}
});
listconf.endGroup();
}
qDebug("---");
return app.exec();
}
|