File indexing completed on 2024-11-10 05:11:10

0001 /*
0002  * Copyright 2018 by Marco Martin <mart@kde.org>
0003  * Copyright 2018 David Edmundson <davidedmundson@kde.org>
0004  * Copyright 2018 Aditya Mehra <aix.m@outlook.com>
0005  *
0006  * Licensed under the Apache License, Version 2.0 (the "License");
0007  * you may not use this file except in compliance with the License.
0008  * You may obtain a copy of the License at
0009  *
0010  *    http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
0017  *
0018  */
0019 
0020 #include "mycroftplugin.h"
0021 
0022 #include "mycroftcontroller.h"
0023 #include "globalsettings.h"
0024 #include "filereader.h"
0025 #include "abstractdelegate.h"
0026 #include "abstractskillview.h"
0027 #include "activeskillsmodel.h"
0028 #include "delegatesmodel.h"
0029 #include "sessiondatamap.h"
0030 #include "audiorec.h"
0031 #include "mediaservice.h"
0032 
0033 #include <QQmlEngine>
0034 #include <QQmlContext>
0035 #include <QQuickItem>
0036 
0037 static QObject *fileReaderSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
0038 {
0039     Q_UNUSED(engine)
0040     Q_UNUSED(scriptEngine)
0041 
0042     return new FileReader;
0043 }
0044 
0045 static QObject *globalSettingsSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
0046 {
0047     Q_UNUSED(engine)
0048     Q_UNUSED(scriptEngine)
0049 
0050     return new GlobalSettings;
0051 }
0052 
0053 static QObject *mycroftControllerSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
0054 {
0055     Q_UNUSED(scriptEngine);
0056 
0057     //singleton managed internally, qml should never delete it
0058     engine->setObjectOwnership(MycroftController::instance(), QQmlEngine::CppOwnership);
0059     return MycroftController::instance();
0060 }
0061 
0062 static QObject *audioRecSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
0063 {
0064     Q_UNUSED(engine)
0065     Q_UNUSED(scriptEngine)
0066 
0067     return new AudioRec;
0068 }
0069 
0070 static QObject *mediaServiceSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
0071 {
0072     Q_UNUSED(engine)
0073     Q_UNUSED(scriptEngine)
0074 
0075     return new MediaService;
0076 }
0077 
0078 void MycroftPlugin::registerTypes(const char *uri)
0079 {
0080     // QLatin1String is deprecated in Qt 6, so fix this 
0081     Q_ASSERT(QLatin1String(uri) == QLatin1String("Mycroft"));
0082 
0083     qmlRegisterSingletonType<MycroftController>(uri, 1, 0, "MycroftController", mycroftControllerSingletonProvider);
0084     qmlRegisterSingletonType<GlobalSettings>(uri, 1, 0, "GlobalSettings", globalSettingsSingletonProvider);
0085     qmlRegisterSingletonType<FileReader>(uri, 1, 0, "FileReader", fileReaderSingletonProvider);
0086     qmlRegisterSingletonType<AudioRec>(uri, 1, 0, "AudioRec", audioRecSingletonProvider);
0087     qmlRegisterSingletonType<MediaService>(uri, 1, 0, "MediaService", mediaServiceSingletonProvider);
0088     qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/qml/Units.qml")), uri, 1, 0, "Units");
0089     qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/qml/SoundEffects.qml")), uri, 1, 0, "SoundEffects");
0090     qmlRegisterType<AbstractSkillView>(uri, 1, 0, "AbstractSkillView");
0091     qmlRegisterType<AbstractDelegate>(uri, 1, 0, "AbstractDelegate");
0092     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/AudioPlayer.qml")), uri, 1, 0, "AudioPlayer");
0093     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/AutoFitLabel.qml")), uri, 1, 0, "AutoFitLabel");
0094     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/Delegate.qml")), uri, 1, 0, "Delegate");
0095     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/PaginatedText.qml")), uri, 1, 0, "PaginatedText");
0096     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/ProportionalDelegate.qml")), uri, 1, 0, "ProportionalDelegate");
0097     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/ScrollableDelegate.qml")), uri, 1, 0, "ScrollableDelegate");
0098     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/SkillView.qml")), uri, 1, 0, "SkillView");
0099     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/SlideShow.qml")), uri, 1, 0, "SlideShow");
0100     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/SlidingImage.qml")), uri, 1, 0, "SlidingImage");
0101     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/StatusIndicator.qml")), uri, 1, 0, "StatusIndicator");
0102     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/VideoPlayer.qml")), uri, 1, 0, "VideoPlayer");
0103     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/BoxLayout.qml")), uri, 1, 0, "BoxLayout");
0104     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/CardDelegate.qml")), uri, 1, 0, "CardDelegate");
0105     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/BusyIndicator.qml")), uri, 1, 0, "BusyIndicator");
0106     qmlRegisterType(QUrl(QStringLiteral("qrc:/qml/MarqueeText.qml")), uri, 1, 0, "MarqueeText");
0107 
0108     qmlRegisterUncreatableType<ActiveSkillsModel>(uri, 1, 0, "ActiveSkillsModel", QStringLiteral("You cannot instantiate items of type ActiveSkillsModel"));
0109     qmlRegisterUncreatableType<DelegatesModel>(uri, 1, 0, "DelegatesModel", QStringLiteral("You cannot instantiate items of type DelegatesModel"));
0110     qmlRegisterUncreatableType<SessionDataMap>(uri, 1, 0, "SessionDataMap", QStringLiteral("You cannot instantiate items of type SessionDataMap"));
0111 
0112     //use this only when all qml files are registered by the plugin
0113    // qmlProtectModule(uri, 1);
0114 }
0115 
0116 #include "moc_mycroftplugin.cpp"
0117