| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 Bhushan Shah <bhush94@gmail.com> |
| 3 | SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org> |
| 4 | SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | |
| 9 | #include <QQmlEngine> |
| 10 | #include <QQmlExtensionPlugin> |
| 11 | |
| 12 | #include <KAboutData> |
| 13 | #include <KTextToHTML> |
| 14 | |
| 15 | class KTextToHtmlWrapper |
| 16 | { |
| 17 | Q_GADGET |
| 18 | Q_INVOKABLE [[nodiscard]] static QString |
| 19 | convertToHtml(const QString &plainText, const KTextToHTML::Options &options, int maxUrlLen = 4096, int maxAddressLen = 255) |
| 20 | { |
| 21 | return KTextToHTML::convertToHtml(plainText, options, maxUrlLen, maxAddressLen); |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | class KCoreAddonsPlugin : public QQmlExtensionPlugin |
| 26 | { |
| 27 | Q_OBJECT |
| 28 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" ) |
| 29 | |
| 30 | public: |
| 31 | /*! |
| 32 | * \qmltype AboutData |
| 33 | * \inqmlmodule org.kde.coreaddons |
| 34 | * \brief This type exposes project metadata set with KAboutData from the C++ side. |
| 35 | * |
| 36 | * This singleton exposes the following read-only properties: |
| 37 | * |
| 38 | * \list |
| 39 | * \li KAboutData::displayName as \c AboutData.displayName |
| 40 | * \li KAboutData::productName as \c AboutData.productName |
| 41 | * \li KAboutData::componentName as \c AboutData.componentName |
| 42 | * \li KAboutData::programLogo as \c AboutData.programLogo |
| 43 | * \li KAboutData::shortDescription as \c AboutData.shortDescription |
| 44 | * \li KAboutData::homepage as \c AboutData.homepage |
| 45 | * \li KAboutData::bugAddress as \c AboutData.bugAddress |
| 46 | * \li KAboutData::version as \c AboutData.version |
| 47 | * \li KAboutData::otherText as \c AboutData.otherText |
| 48 | * \li KAboutData::authors as \c AboutData.authors |
| 49 | * \li KAboutData::credits as \c AboutData.credits |
| 50 | * \li KAboutData::translators as \c AboutData.translators |
| 51 | * \li KAboutData::components as \c AboutData.components |
| 52 | * \li KAboutData::licenses as \c AboutData.licenses |
| 53 | * \li KAboutData::copyrightStatement as \c AboutData.copyrightStatement |
| 54 | * \li KAboutData::desktopFileName as \c AboutData.desktopFileName |
| 55 | * \endlist |
| 56 | * |
| 57 | * The KAboutData metadata is expected to be set in C++ (or equivalent KAboutData bindings). |
| 58 | * |
| 59 | * \sa KAboutData |
| 60 | */ |
| 61 | void registerTypes(const char *uri) override |
| 62 | { |
| 63 | qmlRegisterSingletonType(uri, versionMajor: 1, versionMinor: 0, typeName: "AboutData" , callback: [](QQmlEngine *engine, QJSEngine *) -> QJSValue { |
| 64 | return engine->toScriptValue(value: KAboutData::applicationData()); |
| 65 | }); |
| 66 | qmlRegisterSingletonType(uri, versionMajor: 1, versionMinor: 0, typeName: "KTextToHTML" , callback: [](QQmlEngine *engine, QJSEngine *) -> QJSValue { |
| 67 | return engine->toScriptValue(value: KTextToHtmlWrapper()); |
| 68 | }); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | #include "kcoreaddonsplugin.moc" |
| 73 | |