From 6f8ffc03577379ebbc6dbf86e424d15e315d947e Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Mon, 30 Dec 2019 11:52:07 +0100 Subject: [PATCH] Backend code separation & structure cleanup Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- src/gui/owncloudgui.cpp | 2 +- src/gui/systray.cpp | 8 +++----- src/gui/systray.h | 6 +++--- src/gui/tray/UserModel.h | 3 --- src/gui/tray/window.qml | 34 +++++++++++++++++++--------------- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index dd48dc0a3..c975a162e 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -188,7 +188,7 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason) raiseDialog(_settingsDialog.data()); } #else - UserModel::instance()->showWindow(); + _tray->showWindow(); //slotOpenSettingsDialog(); #endif } diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 3e12e8363..97f513706 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -37,7 +37,6 @@ Systray::Systray() // TODO: make singleton, provide ::instance() : _currentAccount(nullptr) , _trayComponent(nullptr) , _trayContext(nullptr) - , _accountMenuModel(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 @@ -45,10 +44,9 @@ Systray::Systray() // TODO: make singleton, provide ::instance() _trayComponent = new QQmlComponent(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml"))); _trayContext = engine->contextForObject(_trayComponent->create()); - _accountMenuModel = UserModel::instance(); - engine->addImageProvider("avatars", new ImageProvider); - engine->rootContext()->setContextProperty("systrayBackend", _accountMenuModel); + engine->rootContext()->setContextProperty("userModelBackend", UserModel::instance()); + engine->rootContext()->setContextProperty("systrayBackend", this); // TODO: hack to pass the icon to QML //ctxt->setContextProperty("theme", QLatin1String("colored")); @@ -60,7 +58,7 @@ Systray::Systray() // TODO: make singleton, provide ::instance() //connect(AccountManager::instance(), &AccountManager::accountAdded, // this, &Systray::slotChangeActivityModel); - UserModel::instance()->hideWindow(); + hideWindow(); } Systray::~Systray() diff --git a/src/gui/systray.h b/src/gui/systray.h index bf532d0d7..dde45be1a 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -47,12 +47,13 @@ public: ~Systray(); void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000); void setToolTip(const QString &tip); - void showWindow(); - void hideWindow(); signals: void currentUserChanged(); + Q_INVOKABLE void hideWindow(); + Q_INVOKABLE void showWindow(); + private slots: void slotChangeActivityModel(const AccountStatePtr account); @@ -60,7 +61,6 @@ private: AccountStatePtr _currentAccount; QQmlComponent *_trayComponent; QQmlContext *_trayContext; - UserModel *_accountMenuModel; }; } // namespace OCC diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index aeb2716ee..d6a3ec7c7 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -72,9 +72,6 @@ signals: Q_INVOKABLE void newUserSelected(); Q_INVOKABLE void refreshUserMenu(); - Q_INVOKABLE void hideWindow(); - Q_INVOKABLE void showWindow(); - protected: QHash roleNames() const; diff --git a/src/gui/tray/window.qml b/src/gui/tray/window.qml index e59ae314b..12eb10e7f 100644 --- a/src/gui/tray/window.qml +++ b/src/gui/tray/window.qml @@ -29,15 +29,19 @@ Window { } Connections { - target: systrayBackend + target: userModelBackend onRefreshCurrentUserGui: { - currentAccountAvatar.source = systrayBackend.currentUserAvatar() - currentAccountUser.text = systrayBackend.currentUserName() - currentAccountServer.text = systrayBackend.currentUserServer() + currentAccountAvatar.source = userModelBackend.currentUserAvatar() + currentAccountUser.text = userModelBackend.currentUserName() + currentAccountServer.text = userModelBackend.currentUserServer() } onNewUserSelected: { accountMenu.close() } + } + + Connections { + target: systrayBackend onShowWindow: { trayWindow.show(); trayWindow.requestActivate(); @@ -102,7 +106,7 @@ Window { } Instantiator { - model: systrayBackend + model: userModelBackend delegate: UserLine {} onObjectAdded: accountMenu.insertItem(index, object) onObjectRemoved: accountMenu.removeItem(object) @@ -111,22 +115,22 @@ Window { MenuSeparator { id: accountMenuSeparator } MenuItem { - text: (systrayBackend.isCurrentUserConnected() ? "Logout" : "Login") - onClicked: (systrayBackend.isCurrentUserConnected() - ? systrayBackend.logout() - : systrayBackend.login() ) + text: (userModelBackend.isCurrentUserConnected() ? "Logout" : "Login") + onClicked: (userModelBackend.isCurrentUserConnected() + ? userModelBackend.logout() + : userModelBackend.login() ) } MenuItem { text: "Add Account" - onClicked: systrayBackend.addAccount() + onClicked: userModelBackend.addAccount() } MenuItem { text: "Remove Account" - onClicked: systrayBackend.removeAccount() + onClicked: userModelBackend.removeAccount() } Component.onCompleted: { - if(systrayBackend.numUsers() === 0) { + if(userModelBackend.numUsers() === 0) { accountMenuSeparator.height = 0 } else { accountMenuSeparator.height = 13 @@ -190,7 +194,7 @@ Window { id: currentAccountAvatar Layout.leftMargin: 8 verticalAlignment: Qt.AlignCenter - source: systrayBackend.currentUserAvatar() + source: userModelBackend.currentUserAvatar() Layout.preferredHeight: (trayWindowHeaderBackground.height -16) Layout.preferredWidth: (trayWindowHeaderBackground.height -16) } @@ -202,14 +206,14 @@ Window { Layout.leftMargin: 6 Label { id: currentAccountUser - text: systrayBackend.currentUserName() + text: userModelBackend.currentUserName() color: "white" font.pointSize: 9 font.bold: true } Label { id: currentAccountServer - text: systrayBackend.currentUserServer() + text: userModelBackend.currentUserServer() color: "white" font.pointSize: 8 } -- 2.30.2