From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Wed, 4 Dec 2019 15:19:42 +0000 (+0100) Subject: Working on account switching X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~413^2~103 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3a4ca5e190a526f305b49828a36e9c645d4a4b9d;p=nextcloud-desktop.git Working on account switching Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index a7b39d606..faaf02d4c 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -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); diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 7823fe75f..3d328403c 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -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 diff --git a/src/gui/tray/UserLine.qml b/src/gui/tray/UserLine.qml index ffc988486..9489f077e 100644 --- a/src/gui/tray/UserLine.qml +++ b/src/gui/tray/UserLine.qml @@ -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 { diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 36709b316..a7db2dd0c 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -69,7 +69,7 @@ bool User::isConnected() const /*-------------------------------------------------------------------------------------*/ -UserModel* UserModel::_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()); diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 8e299690e..8e433385f 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -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 roleNames() const; @@ -66,6 +69,8 @@ private: UserModel(QObject *parent = 0); QList _users; User *_currentUser; + + void refreshUserList(); }; } diff --git a/src/gui/tray/window.qml b/src/gui/tray/window.qml index a6532af2e..f13012c20 100644 --- a/src/gui/tray/window.qml +++ b/src/gui/tray/window.qml @@ -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