1 | /* |
2 | SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de> |
3 | SPDX-License-Identifier: LGPL-2.0-or-later |
4 | */ |
5 | |
6 | #include <QFile> |
7 | #include <QFileInfo> |
8 | #include <QJsonDocument> |
9 | #include <QJsonObject> |
10 | #include <QString> |
11 | |
12 | int main(int argc, char **argv) |
13 | { |
14 | Q_ASSERT(argc == 3); |
15 | QString fileName = QString::fromLatin1(ba: argv[1]); |
16 | |
17 | QFile file(fileName); |
18 | bool isOpen = file.open(flags: QIODevice::ReadOnly); |
19 | if (!isOpen) { |
20 | qCritical() << "Could not open file" << fileName; |
21 | exit(status: 1); |
22 | } |
23 | QJsonDocument doc = QJsonDocument::fromJson(json: file.readAll()); |
24 | Q_ASSERT(doc.isObject()); |
25 | |
26 | const QJsonObject kplugin = doc.object().value(key: QLatin1String("KPlugin" )).toObject(); |
27 | const QLatin1String namePrefix("Name" ); |
28 | |
29 | QFile out(QString::fromLatin1(ba: argv[2])); |
30 | out.open(flags: QIODevice::WriteOnly); |
31 | out.write(data: "[Desktop Entry]\n" ); |
32 | out.write(data: "Type=Application\n" ); |
33 | out.write(data: "NoDisplay=true\n" ); |
34 | out.write(data: "X-KDE-AliasFor=systemsettings\n" ); |
35 | |
36 | QString executableProgram = QStringLiteral("systemsettings " ); |
37 | if (!doc.object().contains(key: QLatin1String("X-KDE-System-Settings-Parent-Category" ))) { |
38 | executableProgram = QStringLiteral("kcmshell6 " ); |
39 | } |
40 | |
41 | const QString exec = QLatin1String("Exec=" ) + executableProgram + QFileInfo(fileName).baseName() + QLatin1Char('\n'); |
42 | out.write(data: exec.toLatin1()); |
43 | const QString icon = QLatin1String("Icon=" ) + kplugin.value(key: QLatin1String("Icon" )).toString() + QLatin1Char('\n'); |
44 | out.write(data: icon.toLatin1()); |
45 | |
46 | for (auto it = kplugin.begin(), end = kplugin.end(); it != end; ++it) { |
47 | const QString key = it.key(); |
48 | if (key.startsWith(s: namePrefix)) { |
49 | const QString name = key + QLatin1Char('=') + it.value().toString() + QLatin1Char('\n'); |
50 | out.write(data: name.toLocal8Bit()); |
51 | } |
52 | } |
53 | } |
54 | |