From 4b8338ce9117798d7ed25704f3961eda08e4aead Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 1 Jun 2023 02:08:17 +0800 Subject: [PATCH] Expose QML engine in systray Signed-off-by: Claudio Cambra --- src/gui/systray.cpp | 17 +++++++++++------ src/gui/systray.h | 7 ++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 510435ebf..fd526682d 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -59,9 +59,14 @@ Systray *Systray::instance() return _instance; } +QQmlApplicationEngine *Systray::trayEngine() const +{ + return _trayEngine.get(); +} + void Systray::setTrayEngine(QQmlApplicationEngine *trayEngine) { - _trayEngine = trayEngine; + _trayEngine = std::make_unique(trayEngine); _trayEngine->setNetworkAccessManagerFactory(&_accessManagerFactory); @@ -112,7 +117,7 @@ void Systray::create() _trayEngine->rootContext()->setContextProperty("activityModel", UserModel::instance()->currentActivityModel()); } - QQmlComponent trayWindowComponent(_trayEngine, QStringLiteral("qrc:/qml/src/gui/tray/Window.qml")); + QQmlComponent trayWindowComponent(trayEngine(), QStringLiteral("qrc:/qml/src/gui/tray/Window.qml")); if(trayWindowComponent.isError()) { qCWarning(lcSystray) << trayWindowComponent.errorString(); @@ -243,7 +248,7 @@ void Systray::createCallDialog(const Activity &callNotification, const AccountSt {"link", callNotification._link}, }; - const auto callDialog = new QQmlComponent(_trayEngine, QStringLiteral("qrc:/qml/src/gui/tray/CallNotificationDialog.qml")); + const auto callDialog = new QQmlComponent(trayEngine(), QStringLiteral("qrc:/qml/src/gui/tray/CallNotificationDialog.qml")); if(callDialog->isError()) { qCWarning(lcSystray) << callDialog->errorString(); @@ -265,7 +270,7 @@ void Systray::createEditFileLocallyLoadingDialog(const QString &fileName) qCDebug(lcSystray) << "Opening a file local editing dialog..."; - const auto editFileLocallyLoadingDialog = new QQmlComponent(_trayEngine, QStringLiteral("qrc:/qml/src/gui/tray/EditFileLocallyLoadingDialog.qml")); + const auto editFileLocallyLoadingDialog = new QQmlComponent(trayEngine(), QStringLiteral("qrc:/qml/src/gui/tray/EditFileLocallyLoadingDialog.qml")); if (editFileLocallyLoadingDialog->isError()) { qCWarning(lcSystray) << editFileLocallyLoadingDialog->errorString(); @@ -287,7 +292,7 @@ void Systray::destroyEditFileLocallyLoadingDialog() void Systray::createResolveConflictsDialog(const OCC::ActivityList &allConflicts) { - const auto conflictsDialog = std::make_unique(_trayEngine, QStringLiteral("qrc:/qml/src/gui/ResolveConflictsDialog.qml")); + const auto conflictsDialog = std::make_unique(trayEngine(), QStringLiteral("qrc:/qml/src/gui/ResolveConflictsDialog.qml")); const QVariantMap initialProperties{ {"allConflicts", QVariant::fromValue(allConflicts)}, }; @@ -378,7 +383,7 @@ void Systray::createFileDetailsDialog(const QString &localPath) {"localPath", localPath}, }; - QQmlComponent fileDetailsDialog(_trayEngine, QStringLiteral("qrc:/qml/src/gui/filedetails/FileDetailsWindow.qml")); + QQmlComponent fileDetailsDialog(trayEngine(), QStringLiteral("qrc:/qml/src/gui/filedetails/FileDetailsWindow.qml")); if (!fileDetailsDialog.isError()) { const auto createdDialog = fileDetailsDialog.createWithInitialProperties(initialProperties); diff --git a/src/gui/systray.h b/src/gui/systray.h index 87592e935..605286084 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -60,8 +60,7 @@ double menuBarThickness(); * @brief The Systray class * @ingroup gui */ -class Systray - : public QSystemTrayIcon +class Systray : public QSystemTrayIcon { Q_OBJECT @@ -97,6 +96,8 @@ public: bool raiseDialogs(); + [[nodiscard]] QQmlApplicationEngine* trayEngine() const; + signals: void currentUserChanged(); void openAccountWizard(); @@ -176,7 +177,7 @@ private: bool _isOpen = false; bool _syncIsPaused = true; - QPointer _trayEngine; + std::unique_ptr _trayEngine; QPointer _contextMenu; QSharedPointer _trayWindow;