Backend code separation & structure cleanup
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Mon, 30 Dec 2019 10:52:07 +0000 (11:52 +0100)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Mon, 30 Dec 2019 10:52:07 +0000 (11:52 +0100)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/gui/owncloudgui.cpp
src/gui/systray.cpp
src/gui/systray.h
src/gui/tray/UserModel.h
src/gui/tray/window.qml

index dd48dc0a3de871e608f2198c6fc88c5a213a50f3..c975a162e458c37469f9834677de54ae83453f5f 100644 (file)
@@ -188,7 +188,7 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason)
                 raiseDialog(_settingsDialog.data());
             }
 #else
-            UserModel::instance()->showWindow();
+            _tray->showWindow();
             //slotOpenSettingsDialog();
 #endif
         }
index 3e12e83638de35444e5b96d84df0dc9f7b8f7332..97f51370625042ff423c3fc22e7e93caffe0eff2 100644 (file)
@@ -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()
index bf532d0d7281289c201aed439bb53096509201b8..dde45be1a9d621632b5f14fbbbb18da964259fef 100644 (file)
@@ -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
index aeb2716ee4e098b7c3b9a2fec2e9af78dc793827..d6a3ec7c704b7c0b8782f43800115435f0f93374 100644 (file)
@@ -72,9 +72,6 @@ signals:
     Q_INVOKABLE void newUserSelected();
     Q_INVOKABLE void refreshUserMenu();
 
-    Q_INVOKABLE void hideWindow();
-    Q_INVOKABLE void showWindow();
-
 protected:
     QHash<int, QByteArray> roleNames() const;
 
index e59ae314b535c4c1074e1857bb29b0463f849bdd..12eb10e7fa21004132b3bf1a1a94ee67abc92ae1 100644 (file)
@@ -29,15 +29,19 @@ Window {
     }\r
 \r
     Connections {\r
-        target: systrayBackend\r
+        target: userModelBackend\r
         onRefreshCurrentUserGui: {\r
-            currentAccountAvatar.source = systrayBackend.currentUserAvatar()\r
-            currentAccountUser.text = systrayBackend.currentUserName()\r
-            currentAccountServer.text = systrayBackend.currentUserServer()\r
+            currentAccountAvatar.source = userModelBackend.currentUserAvatar()\r
+            currentAccountUser.text = userModelBackend.currentUserName()\r
+            currentAccountServer.text = userModelBackend.currentUserServer()\r
         }\r
         onNewUserSelected: {\r
             accountMenu.close()\r
         }\r
+    }\r
+\r
+    Connections {\r
+        target: systrayBackend\r
         onShowWindow: {\r
             trayWindow.show();\r
             trayWindow.requestActivate();\r
@@ -102,7 +106,7 @@ Window {
                             }\r
 \r
                             Instantiator {\r
-                                model: systrayBackend\r
+                                model: userModelBackend\r
                                 delegate: UserLine {}\r
                                 onObjectAdded: accountMenu.insertItem(index, object)\r
                                 onObjectRemoved: accountMenu.removeItem(object)\r
@@ -111,22 +115,22 @@ Window {
                             MenuSeparator { id: accountMenuSeparator }\r
 \r
                             MenuItem {\r
-                                text: (systrayBackend.isCurrentUserConnected() ? "Logout" : "Login")\r
-                                onClicked: (systrayBackend.isCurrentUserConnected()\r
-                                            ? systrayBackend.logout()\r
-                                            : systrayBackend.login() )\r
+                                text: (userModelBackend.isCurrentUserConnected() ? "Logout" : "Login")\r
+                                onClicked: (userModelBackend.isCurrentUserConnected()\r
+                                            ? userModelBackend.logout()\r
+                                            : userModelBackend.login() )\r
                             }\r
                             MenuItem {\r
                                 text: "Add Account"\r
-                                onClicked: systrayBackend.addAccount()\r
+                                onClicked: userModelBackend.addAccount()\r
                             }\r
                             MenuItem {\r
                                 text: "Remove Account"\r
-                                onClicked: systrayBackend.removeAccount()\r
+                                onClicked: userModelBackend.removeAccount()\r
                             }\r
 \r
                             Component.onCompleted: {\r
-                                if(systrayBackend.numUsers() === 0) {\r
+                                if(userModelBackend.numUsers() === 0) {\r
                                     accountMenuSeparator.height = 0\r
                                 } else {\r
                                     accountMenuSeparator.height = 13\r
@@ -190,7 +194,7 @@ Window {
                             id: currentAccountAvatar\r
                             Layout.leftMargin: 8\r
                             verticalAlignment: Qt.AlignCenter\r
-                            source: systrayBackend.currentUserAvatar()\r
+                            source: userModelBackend.currentUserAvatar()\r
                             Layout.preferredHeight: (trayWindowHeaderBackground.height -16)\r
                             Layout.preferredWidth: (trayWindowHeaderBackground.height -16)\r
                         }\r
@@ -202,14 +206,14 @@ Window {
                             Layout.leftMargin: 6\r
                             Label {\r
                                 id: currentAccountUser\r
-                                text: systrayBackend.currentUserName()\r
+                                text: userModelBackend.currentUserName()\r
                                 color: "white"\r
                                 font.pointSize: 9\r
                                 font.bold: true\r
                             }\r
                             Label {\r
                                 id: currentAccountServer\r
-                                text: systrayBackend.currentUserServer()\r
+                                text: userModelBackend.currentUserServer()\r
                                 color: "white"\r
                                 font.pointSize: 8\r
                             }\r