diff --git a/src/core/plugin.cpp b/src/core/plugin.cpp index 07c5012..4ef78f9 100644 --- a/src/core/plugin.cpp +++ b/src/core/plugin.cpp @@ -1,3 +1,23 @@ +/* + * Copyright (C) 2018-2025 Chupligin Sergey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + #include "plugin.h" #include "nemoimageprovider.h" #include "sizing.h" @@ -8,16 +28,5 @@ void QQuickNemoControlsExtensionPlugin::registerTypes(const char* uri) { Q_ASSERT(uri == QLatin1String("Nemo")); qmlRegisterModule(uri, 2, 0); -} - -void QQuickNemoControlsExtensionPlugin::initializeEngine(QQmlEngine* engine, const char* uri) -{ - Theme* theme = new Theme(); - - QQmlExtensionPlugin::initializeEngine(engine, uri); - QQmlContext* context = engine->rootContext(); - context->setContextProperty("size", theme->size()); - context->setContextProperty("Theme", theme); - - engine->addImageProvider(QLatin1String("theme"), new NemoImageProvider); + qmlRegisterSingletonType(uri, 1, 0, "Theme", &Theme::qmlInstance); } diff --git a/src/core/plugin.h b/src/core/plugin.h index d54472c..8ed3bb2 100644 --- a/src/core/plugin.h +++ b/src/core/plugin.h @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2018-2025 Chupligin Sergey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + #ifndef QQUICKNEMOCONTROLSEXTENSIONPLUGIN_H #define QQUICKNEMOCONTROLSEXTENSIONPLUGIN_H @@ -9,7 +28,6 @@ class QQuickNemoControlsExtensionPlugin : public QQmlExtensionPlugin { Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid FILE "nemo.json") public: void registerTypes(const char* uri); - void initializeEngine(QQmlEngine* engine, const char* uri); }; #endif // QQUICKNEMOCONTROLSEXTENSIONPLUGIN_H diff --git a/src/core/theme.cpp b/src/core/theme.cpp index cad66ab..7c7b244 100644 --- a/src/core/theme.cpp +++ b/src/core/theme.cpp @@ -26,6 +26,8 @@ #include #include +static Theme* themeInstance = 0; + Theme::Theme(QObject* parent) : QObject(parent) , m_size(new Sizing) @@ -45,6 +47,16 @@ Theme::Theme(QObject* parent) } } +QObject *Theme::qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + if(!themeInstance) { + themeInstance = new Theme(); + } + return themeInstance; +} + bool Theme::loadTheme(QString fileName) { QFile themeFile(fileName); diff --git a/src/core/theme.h b/src/core/theme.h index cf09375..6996b9f 100644 --- a/src/core/theme.h +++ b/src/core/theme.h @@ -22,11 +22,13 @@ #include #include +#include class Sizing; class Theme : public QObject { Q_OBJECT + Q_DISABLE_COPY(Theme) Q_PROPERTY(qreal iconSizeLauncher READ iconSizeLauncher NOTIFY themeUpdated) @@ -69,6 +71,8 @@ class Theme : public QObject { public: explicit Theme(QObject* parent = nullptr); + static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine); + Sizing* size() const { return m_size; } Q_INVOKABLE bool loadTheme(const QString fileName);