Newer
Older
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <QObject>
#include <QCoreApplication>
#include <QDebug>
#include "qtlib_file.h"
#include "qtlib_dir.h"
#include "qtlib_json.h"
#include "qtlib_config.h"
#include "qtlib_networkresource.h"
#include "qtlib_ocsapi.h"
#include "qtlib_package.h"
class Test : public QObject
{
public:
Test() {}
virtual ~Test() {}
void start() {
qDebug() << "Start";
qtlib::NetworkResource *resource = new qtlib::NetworkResource(
"LGPL-3.0",
QUrl("https://api.opensource.org/license/LGPL-3.0"),
false,
this);
QJsonObject result = qtlib::Json(resource->get()->readData()).toObject();
qDebug() << resource->id() << ":" << result["name"].toString();
resource->setUrl(QUrl(result["text"].toArray()[0].toObject()["url"].toString()));
resource->setAsync(true);
connect(resource, &qtlib::NetworkResource::finished, this, &Test::finished);
resource->get();
}
public slots:
void finished(qtlib::NetworkResource *resource) {
QString path = qtlib::Dir::tempPath() + "/" + resource->url().fileName();
resource->saveData(path);
resource->deleteLater();
qDebug() << "Downloaded" << resource->id() << ":" << path;
qDebug() << "Finished";
QCoreApplication::exit();
}
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Test test;
test.start();
return app.exec();
}