From d1617d6d2d0e5dea88e32e3634bfa8f552235617 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Sun, 4 Oct 2020 19:51:17 +0200 Subject: [PATCH] Port away from deprecated KDeclarative::setupContext() NO_CHANGELOG --- src/declarativeimports/core/CMakeLists.txt | 1 + src/declarativeimports/core/corebindingsplugin.cpp | 10 ++++++---- src/plasmaquick/configview.cpp | 11 ++++++----- src/plasmaquick/view.cpp | 10 ++++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/declarativeimports/core/CMakeLists.txt b/src/declarativeimports/core/CMakeLists.txt index 26b5829f6..23fd30075 100644 --- a/src/declarativeimports/core/CMakeLists.txt +++ b/src/declarativeimports/core/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries(corebindingsplugin Qt5::Qml KF5::Declarative KF5::IconThemes + KF5::I18n KF5::Service #for kplugininfo.h KF5::WindowSystem KF5::Plasma diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index edc61adcf..7e9b9f94f 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -11,6 +11,8 @@ #include +#include + #include #include @@ -48,10 +50,10 @@ void CoreBindingsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) context->setContextProperty(QStringLiteral("units"), &Units::instance()); - if (!engine->rootContext()->contextObject()) { - KDeclarative::KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(engine); - kdeclarative.setupContext(); + if (!context->contextObject()) { + KLocalizedContext *localizedContextObject = new KLocalizedContext(engine); + context->setContextObject(localizedContextObject); + KDeclarative::KDeclarative::setupEngine(engine); } } diff --git a/src/plasmaquick/configview.cpp b/src/plasmaquick/configview.cpp index 0b20bedac..12d1c2c74 100644 --- a/src/plasmaquick/configview.cpp +++ b/src/plasmaquick/configview.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -80,15 +81,15 @@ void ConfigViewPrivate::init() applet.data()->setUserConfiguring(true); - KDeclarative::KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(q->engine()); + KLocalizedContext *localizedContextObject = new KLocalizedContext(q->engine()); const QString rootPath = applet.data()->pluginMetaData().value(QStringLiteral("X-Plasma-RootPath")); if (!rootPath.isEmpty()) { - kdeclarative.setTranslationDomain(QStringLiteral("plasma_applet_") + rootPath); + localizedContextObject->setTranslationDomain(QStringLiteral("plasma_applet_") + rootPath); } else { - kdeclarative.setTranslationDomain(QStringLiteral("plasma_applet_") + applet.data()->pluginMetaData().pluginId()); + localizedContextObject->setTranslationDomain(QStringLiteral("plasma_applet_") + applet.data()->pluginMetaData().pluginId()); } - kdeclarative.setupContext(); + q->engine()->rootContext()->setContextObject(localizedContextObject); + KDeclarative::KDeclarative::setupEngine(q->engine()); // ### how to make sure to do this only once per engine? //FIXME: problem on nvidia, all windows should be transparent or won't show diff --git a/src/plasmaquick/view.cpp b/src/plasmaquick/view.cpp index 7eb067fed..d3d07e6f5 100644 --- a/src/plasmaquick/view.cpp +++ b/src/plasmaquick/view.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include "plasma/pluginloader.h" #include #include @@ -182,11 +184,11 @@ View::View(Plasma::Corona *corona, QWindow *parent) interceptor->setForcePlasmaStyle(true); engine()->setUrlInterceptor(interceptor); - KDeclarative::KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(engine()); + KLocalizedContext *localizedContextObject = new KLocalizedContext(engine()); + localizedContextObject->setTranslationDomain(QStringLiteral("plasma_shell_") + pkg.metadata().pluginId()); + engine()->rootContext()->setContextObject(localizedContextObject); + //binds things like kconfig and icons - kdeclarative.setTranslationDomain(QStringLiteral("plasma_shell_") + pkg.metadata().pluginId()); - kdeclarative.setupContext(); KDeclarative::KDeclarative::setupEngine(engine()); // ### how to make sure to do this only once per engine? } else { qWarning() << "Invalid home screen package";