File indexing completed on 2024-04-21 15:02:25

0001 /*
0002     SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "qmlplugin.h"
0008 
0009 #include "author.h"
0010 #include "categoriesmodel.h"
0011 #include "commentsmodel.h"
0012 #include "downloadlinkinfo.h"
0013 #include "entrywrapper.h"
0014 #include "quickengine.h"
0015 #include "quickitemsmodel.h"
0016 #include "quickquestionlistener.h"
0017 #include "quicksettings.h"
0018 #include "searchpresetmodel.h"
0019 
0020 #include "provider.h"
0021 #include "providersmodel.h"
0022 #include "question.h"
0023 
0024 #include <QQmlEngine>
0025 #include <qqml.h>
0026 
0027 void QmlPlugins::initializeEngine(QQmlEngine *engine, const char *)
0028 {
0029     Q_UNUSED(engine);
0030 }
0031 
0032 void QmlPlugins::registerTypes(const char *uri)
0033 {
0034     const char *coreUri{"org.kde.newstuff.core"};
0035 
0036     // Initial version
0037     qmlRegisterType<Engine>(uri, 1, 0, "Engine");
0038     qmlRegisterType<ItemsModel>(uri, 1, 0, "ItemsModel");
0039 
0040     // Version 1.62
0041     qmlRegisterType<KNewStuffQuick::Author>(uri, 1, 62, "Author");
0042     qmlRegisterType<KNewStuffQuick::CommentsModel>(uri, 1, 62, "CommentsModel");
0043     qmlRegisterUncreatableType<DownloadLinkInfo>(
0044         uri,
0045         1,
0046         0,
0047         "DownloadLinkInfo",
0048         QStringLiteral("This should only be created by the ItemsModel, and is associated with one entry in that model"));
0049     qmlRegisterUncreatableType<CategoriesModel>(
0050         uri,
0051         1,
0052         0,
0053         "CategoriesModel",
0054         QStringLiteral("This should only be created by the Engine, and provides the categories available in that engine"));
0055     qmlRegisterUncreatableMetaObject(KNSCore::Provider::staticMetaObject,
0056                                      coreUri,
0057                                      1,
0058                                      62,
0059                                      "Provider",
0060                                      QStringLiteral("Error: this only exists to forward enums"));
0061     qmlRegisterUncreatableMetaObject(KNSCore::Question::staticMetaObject,
0062                                      coreUri,
0063                                      1,
0064                                      62,
0065                                      "Question",
0066                                      QStringLiteral("Error: this only exists to forward enums"));
0067     qmlRegisterSingletonType<KNewStuffQuick::QuickQuestionListener>(uri,
0068                                                                     1,
0069                                                                     62,
0070                                                                     "QuickQuestionListener",
0071                                                                     [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
0072                                                                         Q_UNUSED(scriptEngine)
0073                                                                         engine->setObjectOwnership(KNewStuffQuick::QuickQuestionListener::instance(),
0074                                                                                                    QQmlEngine::CppOwnership);
0075                                                                         return KNewStuffQuick::QuickQuestionListener::instance();
0076                                                                     });
0077     qmlRegisterUncreatableType<KNSCore::EntryInternal>(uri, 1, 91, "Entry", QStringLiteral("Entries should only be created by the engine"));
0078 
0079     // Version 1.67
0080     qmlRegisterUncreatableType<KNSCore::EntryWrapper>(
0081         coreUri,
0082         1,
0083         67,
0084         "EntryWrapper",
0085         QStringLiteral("This should only be created by the Engine, and wraps EntryInternal objects for passing through Qt Quick"));
0086 
0087     // Version 1.81
0088     qmlRegisterSingletonType<KNewStuffQuick::Settings>(uri, 1, 81, "Settings", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
0089         Q_UNUSED(scriptEngine)
0090         engine->setObjectOwnership(KNewStuffQuick::Settings::instance(), QQmlEngine::CppOwnership);
0091         return KNewStuffQuick::Settings::instance();
0092     });
0093     // Version 1.83
0094     qmlRegisterUncreatableType<SearchPresetModel>(
0095         uri,
0096         1,
0097         83,
0098         "SearchPresetModel",
0099         QStringLiteral("This should only be created by the Engine, and provides the SearchPresets available in that engine"));
0100 
0101     // Version 1.85
0102     qmlRegisterType<KNSCore::ProvidersModel>(uri, 1, 85, "ProvidersModel");
0103 }
0104 
0105 #include "moc_qmlplugin.cpp"