Working on account switching
authorDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Wed, 4 Dec 2019 15:19:42 +0000 (16:19 +0100)
committerDominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Wed, 4 Dec 2019 15:19:42 +0000 (16:19 +0100)
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
src/gui/accountsettings.cpp
src/gui/owncloudgui.cpp
src/gui/tray/UserLine.qml
src/gui/tray/UserModel.cpp
src/gui/tray/UserModel.h
src/gui/tray/window.qml

index a7b39d60642304d045bd9da63dec819b49df7fe6..faaf02d4ce5d0220a514688a35d519429ba928e0 100644 (file)
@@ -217,7 +217,10 @@ void AccountSettings::createAccountToolbox()
 
     _addAccountAction = new QAction(tr("Add new"), this);
     menu->addAction(_addAccountAction);
+    
     connect(_addAccountAction, &QAction::triggered, this, &AccountSettings::slotOpenAccountWizard);
+    connect(UserModel::instance(), &UserModel::addAccount,
+        this, &AccountSettings::slotOpenAccountWizard);
 
     _toggleSignInOutAction = new QAction(tr("Log out"), this);
     connect(_toggleSignInOutAction, &QAction::triggered, this, &AccountSettings::slotToggleSignInState);
@@ -225,7 +228,10 @@ void AccountSettings::createAccountToolbox()
 
     QAction *action = new QAction(tr("Remove"), this);
     menu->addAction(action);
+
     connect(action, &QAction::triggered, this, &AccountSettings::slotDeleteAccount);
+    connect(UserModel::instance(), &UserModel::removeAccount,
+        this, &AccountSettings::slotOpenAccountWizard);
 
     ui->_accountToolbox->setText(tr("Account") + QLatin1Char(' '));
     ui->_accountToolbox->setMenu(menu);
index 7823fe75f90c631acf694d51a68dedd9b02cdb0e..3d328403cf0d199628f930336b753fb0dc181477 100644 (file)
@@ -119,8 +119,6 @@ ownCloudGui::ownCloudGui(Application *parent)
         this, &ownCloudGui::slotLogin);
     connect(UserModel::instance(), &UserModel::logout,
         this, &ownCloudGui::slotLogout);
-    connect(UserModel::instance(), &UserModel::addAccount,
-        this, &ownCloudGui::slotNewAccountWizard);
 }
 
 #ifdef WITH_LIBCLOUDPROVIDERS
index ffc9884864c9403bfed30e4f1e0c506110c337d6..9489f077eefa353b76917f5e2a804bf14c0af4a2 100644 (file)
@@ -7,7 +7,7 @@ MenuItem {
 
     id: userLine
     visible: true
-    width: 220
+    width: 216
     height: 60
     //color: "transparent"
 
@@ -24,21 +24,18 @@ MenuItem {
 
             Button {
                 id: accountButton
-                Layout.preferredWidth: 220
-                Layout.preferredHeight: (userLineBackground.height)
+                anchors.centerIn: parent
+                Layout.preferredWidth: (userLine.width - 4)
+                Layout.preferredHeight: (userLineBackground.height - 2)
                 display: AbstractButton.IconOnly
                 flat: true
 
-                MouseArea {
-                    id: accountBtnMouseArea
-                    anchors.centerIn: parent
-                    Layout.preferredWidth: (accountButton.width - 4)
-                    Layout.preferredHeight: (accountButton.height - 4)
-                    hoverEnabled: true
-                    onClicked:
-                    {
-                        //
-                    }
+                background: Rectangle {
+                    color: "transparent"
+                }
+
+                onClicked: {
+                    systrayBackend.switchUser(index)
                 }
 
                 RowLayout {
index 36709b31620eb131ed0929739b91833e94e91421..a7db2dd0cbf2ce522ed97f20b2298b9b0db26a21 100644 (file)
@@ -69,7 +69,7 @@ bool User::isConnected() const
 
 /*-------------------------------------------------------------------------------------*/
 
-UserModelUserModel::_instance = nullptr;
+UserModel *UserModel::_instance = nullptr;
 
 UserModel *UserModel::instance()
 {
@@ -91,9 +91,14 @@ UserModel::UserModel(QObject *parent)
         return;
     }
 
+    refreshUserList();
+}
+
+void UserModel::refreshUserList()
+{
     for (int i = 0; i < AccountManager::instance()->accounts().size(); i++) {
         auto user = AccountManager::instance()->accounts().at(i);
-        if (user->account()->id() != _currentUser->id()) {
+        if ((user->account()->id() != _currentUser->id())) {
             addUser(user);
         }
     }
@@ -125,6 +130,13 @@ Q_INVOKABLE QString UserModel::currentUserServer()
     return _currentUser->server();
 }
 
+Q_INVOKABLE void UserModel::switchUser(const int id)
+{
+    addCurrentUser(_users.at(id));
+    refreshUserList();
+    emit refreshCurrentUserGui();
+}
+
 void UserModel::addUser(const User &user)
 {
     beginInsertRows(QModelIndex(), rowCount(), rowCount());
index 8e299690e3eafc2e354463a11e5ee9e68579d539..8e433385f611e0fd006ccadaba77dce77627675a 100644 (file)
@@ -45,6 +45,7 @@ public:
     Q_INVOKABLE QString currentUserAvatar();
     Q_INVOKABLE QString currentUserName();
     Q_INVOKABLE QString currentUserServer();
+    Q_INVOKABLE void switchUser(const int id);
 
     enum UserRoles {
         NameRole = Qt::UserRole + 1,
@@ -58,6 +59,8 @@ signals:
     Q_INVOKABLE void addAccount();
     Q_INVOKABLE void removeAccount();
 
+    Q_INVOKABLE void refreshCurrentUserGui();
+
 protected:
     QHash<int, QByteArray> roleNames() const;
 
@@ -66,6 +69,8 @@ private:
     UserModel(QObject *parent = 0);
     QList<User> _users;
     User *_currentUser;
+
+    void refreshUserList();
 };
 
 }
index a6532af2ed286bc3164cf95025350aec55c362a7..f13012c2025283bd47ffc59ddc8cfc0886fc642a 100644 (file)
@@ -22,6 +22,15 @@ Window {
         //setY(Screen.desktopAvailableHeight + height);
     }
 
+    Connections {
+        target: systrayBackend
+        onRefreshCurrentUserGui: {
+            currentAccountAvatar.source = systrayBackend.currentUserAvatar()
+            currentAccountUser.text = systrayBackend.currentUserName()
+            currentAccountServer.text = systrayBackend.currentUserServer()
+        }
+    }
+
     Rectangle {
         id: trayWindowBackground
         anchors.fill: parent
@@ -190,10 +199,6 @@ Window {
                             }
                         }
 
-                        /*Item {
-                            Layout.preferredWidth: 6
-                        }*/
-
                         Image {
                             Layout.alignment: Qt.AlignLeft
                             verticalAlignment: Qt.AlignCenter