diff options
author | Nicolas Fella <nicolas.fella@gmx.de> | 2020-03-22 18:14:26 +0300 |
---|---|---|
committer | Nicolas Fella <nicolas.fella@gmx.de> | 2020-03-22 18:14:56 +0300 |
commit | d54add6233cf3ce663f6f4f82689547f09cd5acf (patch) | |
tree | f5f833867875ec5060bca59e0a3c429e15241a74 /src/gui/systray.cpp | |
parent | 3ca586c464af9acd9506ad39232fd75251ee1636 (diff) |
Use QQmlApplicationEngine
This simplifies the code a bit.
Signed-off-by: Nicolas Fella <nicolas.fella@gmx.de>
Diffstat (limited to 'src/gui/systray.cpp')
-rw-r--r-- | src/gui/systray.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 081a90b0e..dc9ca6bed 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -22,7 +22,7 @@ #include <QDesktopServices> #include <QGuiApplication> #include <QQmlComponent> -#include <QQmlEngine> +#include <QQmlApplicationEngine> #include <QScreen> #ifdef USE_FDO_NOTIFICATIONS @@ -50,20 +50,14 @@ Systray *Systray::instance() Systray::Systray() : _isOpen(false) , _syncIsPaused(false) - , _trayComponent(nullptr) - , _trayContext(nullptr) { - // Create QML tray engine, build component, set C++ backend context used in window.qml - // Use pointer instead of engine() helper function until Qt 5.12 is minimum standard - _trayEngine = new QQmlEngine; + _trayEngine = new QQmlApplicationEngine; _trayEngine->addImportPath("qrc:/qml/theme"); _trayEngine->addImageProvider("avatars", new ImageProvider); _trayEngine->rootContext()->setContextProperty("userModelBackend", UserModel::instance()); _trayEngine->rootContext()->setContextProperty("appsMenuModelBackend", UserAppsModel::instance()); _trayEngine->rootContext()->setContextProperty("systrayBackend", this); - _trayComponent = new QQmlComponent(_trayEngine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/Window.qml"))); - connect(UserModel::instance(), &UserModel::newUserSelected, this, &Systray::slotNewUserSelected); @@ -73,13 +67,11 @@ Systray::Systray() void Systray::create() { - if (_trayContext == nullptr) { - if (!AccountManager::instance()->accounts().isEmpty()) { - _trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel()); - } - _trayContext = _trayEngine->contextForObject(_trayComponent->create()); - hideWindow(); + if (!AccountManager::instance()->accounts().isEmpty()) { + _trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel()); } + _trayEngine->load(QStringLiteral("qrc:/qml/src/gui/tray/Window.qml")); + hideWindow(); } void Systray::slotNewUserSelected() |