Expose QML engine in systray

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-06-01 02:08:17 +08:00
parent dae1643542
commit 4b8338ce91
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 15 additions and 9 deletions

View file

@ -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<QQmlApplicationEngine>(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<QQmlComponent>(_trayEngine, QStringLiteral("qrc:/qml/src/gui/ResolveConflictsDialog.qml"));
const auto conflictsDialog = std::make_unique<QQmlComponent>(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);

View file

@ -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<QQmlApplicationEngine> _trayEngine;
std::unique_ptr<QQmlApplicationEngine> _trayEngine;
QPointer<QMenu> _contextMenu;
QSharedPointer<QQuickWindow> _trayWindow;