File indexing completed on 2024-04-28 15:29:22

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2020 Friedrich W. H. Kossebau <kossebau@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "partmetadatautil_p.h"
0009 
0010 // KF
0011 #include <KAboutData>
0012 #include <KPluginMetaData>
0013 // Qt
0014 #include <QJsonArray>
0015 #include <QJsonObject>
0016 
0017 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
0018 
0019 namespace PartMetaDataUtil
0020 {
0021 static QJsonArray jsonArrayFromKAboutPersonList(const QList<KAboutPerson> &persons)
0022 {
0023     QJsonArray array;
0024     for (const auto &person : persons) {
0025         QJsonObject authorsObject;
0026         authorsObject[QStringLiteral("Name")] = person.name();
0027         authorsObject[QStringLiteral("Email")] = person.emailAddress();
0028         authorsObject[QStringLiteral("Website")] = person.webAddress();
0029         authorsObject[QStringLiteral("Task")] = person.task();
0030         authorsObject[QStringLiteral("UserName")] = person.ocsUsername();
0031         array.append(authorsObject);
0032     }
0033     return array;
0034 }
0035 
0036 KPluginMetaData fromKAboutData(const KAboutData &aboutData)
0037 {
0038     QJsonObject kplugin;
0039     kplugin[QStringLiteral("Id")] = aboutData.componentName();
0040     kplugin[QStringLiteral("Name")] = aboutData.displayName();
0041     kplugin[QStringLiteral("Description")] = aboutData.shortDescription();
0042     kplugin[QStringLiteral("Version")] = aboutData.version();
0043     const auto licenses = aboutData.licenses();
0044     if (!licenses.isEmpty()) {
0045         kplugin[QStringLiteral("License")] = licenses.first().spdx();
0046     }
0047     kplugin[QStringLiteral("Copyright")] = aboutData.copyrightStatement();
0048     kplugin[QStringLiteral("ExtraInformation")] = aboutData.otherText();
0049     kplugin[QStringLiteral("Website")] = aboutData.homepage();
0050 #if KCOREADDONS_BUILD_DEPRECATED_SINCE(5, 2)
0051     QT_WARNING_PUSH
0052     QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
0053     QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
0054     kplugin[QStringLiteral("Icon")] = aboutData.programIconName();
0055     QT_WARNING_POP
0056 #endif
0057 
0058     kplugin[QStringLiteral("Authors")] = jsonArrayFromKAboutPersonList(aboutData.authors());
0059     kplugin[QStringLiteral("Translators")] = jsonArrayFromKAboutPersonList(aboutData.translators());
0060     kplugin[QStringLiteral("OtherContributors")] = jsonArrayFromKAboutPersonList(aboutData.credits());
0061 
0062     QJsonObject json;
0063     json[QStringLiteral("KPlugin")] = kplugin;
0064 
0065     KPluginMetaData metaData(json, QString());
0066     return metaData;
0067 }
0068 
0069 }
0070 
0071 #endif