blob: 3448bc542b5d120ee0a754bef3e85c7f073bf1a2 (
plain)
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
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "language.h"
#include "request.h"
#include <QUrlQuery>
namespace CompilerExplorer::Api {
QFuture<Languages> languages(const Config &config)
{
QUrl url = config.url({"api/languages"});
url.setQuery(QUrlQuery{{"fields", "id,name,extensions,logoUrl"}});
return jsonRequest<Languages>(config.networkManager, url, [](const QJsonDocument &doc) {
const QJsonArray languages = doc.array();
Languages result;
for (const auto &language : languages) {
QJsonObject obj = language.toObject();
Language l;
l.id = obj["id"].toString();
l.name = obj["name"].toString();
l.logoUrl = obj["logoUrl"].toString();
const QJsonArray extensions = obj["extensions"].toArray();
for (const auto &extension : extensions) {
l.extensions.append(extension.toString());
}
result.append(l);
}
std::sort(result.begin(), result.end(), [](const Language &a, const Language &b) {
return a.name < b.name;
});
return result;
});
}
} // namespace CompilerExplorer::Api
|