diff options
Diffstat (limited to 'staging/filterlist/test/main.cpp')
-rw-r--r-- | staging/filterlist/test/main.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/staging/filterlist/test/main.cpp b/staging/filterlist/test/main.cpp new file mode 100644 index 0000000..ccaae47 --- /dev/null +++ b/staging/filterlist/test/main.cpp @@ -0,0 +1,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(); +} |