From 9c0221a0fa14f6fdbb80ddada13e2c6d58e326b5 Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Fri, 10 Jan 2020 16:28:53 +0100 Subject: [PATCH] UserLine drafting, bugfixes, restuctures Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- src/gui/accountsettings.cpp | 2 - src/gui/owncloudgui.cpp | 6 --- src/gui/tray/UserLine.qml | 82 ++++++++++++++++++++++++++----------- src/gui/tray/UserModel.cpp | 24 +++++++++++ src/gui/tray/UserModel.h | 9 ++-- src/gui/tray/Window.qml | 8 +++- 6 files changed, 93 insertions(+), 38 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index a7fd0f5a1..604abace1 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -232,8 +232,6 @@ void AccountSettings::createAccountToolbox() 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 54dd1faac..96718c229 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -110,12 +110,6 @@ ownCloudGui::ownCloudGui(Application *parent) this, &ownCloudGui::slotShowOptionalTrayMessage); connect(Logger::instance(), &Logger::guiMessage, this, &ownCloudGui::slotShowGuiMessage); - - - connect(UserModel::instance(), &UserModel::login, - this, &ownCloudGui::slotLogin); - connect(UserModel::instance(), &UserModel::logout, - this, &ownCloudGui::slotLogout); } #ifdef WITH_LIBCLOUDPROVIDERS diff --git a/src/gui/tray/UserLine.qml b/src/gui/tray/UserLine.qml index be8a63775..aeabdfea5 100644 --- a/src/gui/tray/UserLine.qml +++ b/src/gui/tray/UserLine.qml @@ -4,33 +4,19 @@ import QtQuick.Controls 2.2 import QtQuick.Layouts 1.2 MenuItem { - - Connections { - target: userModelBackend - onRefreshUserMenu: { - } - } - id: userLine - width: 220 height: 60 - Rectangle { - id: userLineBackground - height: userLine.height - anchors.fill: parent - color: "transparent" - RowLayout { id: userLineLayout spacing: 0 - anchors.fill: parent + width: 220 + height: 60 Button { id: accountButton - anchors.centerIn: parent - Layout.preferredWidth: (userLine.width - 4) - Layout.preferredHeight: (userLineBackground.height - 2) + Layout.preferredWidth: (userLineLayout.width * (5/6)) + Layout.preferredHeight: (userLineLayout.height) display: AbstractButton.IconOnly flat: true @@ -49,21 +35,22 @@ MenuItem { spacing: 0 Image { id: accountAvatar - Layout.leftMargin: 2 + Layout.leftMargin: 4 verticalAlignment: Qt.AlignCenter + cache: false source: ("image://avatars/" + index) - Layout.preferredHeight: (userLineBackground.height -16) - Layout.preferredWidth: (userLineBackground.height -16) + Layout.preferredHeight: (userLineLayout.height -16) + Layout.preferredWidth: (userLineLayout.height -16) } Column { id: accountLabels spacing: 4 Layout.alignment: Qt.AlignLeft - Layout.leftMargin: 12 + Layout.leftMargin: 6 Label { id: accountUser - width: 120 + width: 128 text: name elide: Text.ElideRight color: "black" @@ -72,7 +59,7 @@ MenuItem { } Label { id: accountServer - width: 120 + width: 128 text: server elide: Text.ElideRight color: "black" @@ -81,6 +68,51 @@ MenuItem { } } } // accountButton + + Button { + id: userMoreButton + Layout.preferredWidth: (userLineLayout.width * (1/6)) + Layout.preferredHeight: userLineLayout.height + flat: true + + icon.source: "qrc:///client/resources/more.svg" + icon.color: "transparent" + + MouseArea { + id: userMoreButtonMouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: + { + userMoreButtonMenu.popup() + } + } + background: + Rectangle { + color: userMoreButtonMouseArea.containsMouse ? "grey" : "transparent" + opacity: 0.2 + } + + Menu { + id: userMoreButtonMenu + width: 100 + + background: Rectangle { + border.color: "#0082c9" + radius: 2 + } + + MenuItem { + text: userModelBackend.isCurrentUserConnected() ? "Log out" : "Log in" + onClicked: { + userModelBackend.isCurrentUserConnected() ? userModelBackend.logout(index) : userModelBackend.logout(index) + } + } + + MenuItem { + text: "Remove Account" + } + } + } } - } // Rectangle userLineBackground } // MenuItem userLine diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 22b49396b..1c285d0e1 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -43,6 +43,16 @@ void User::openLocalFolder() QDesktopServices::openUrl(this->getFolder()->path()); } +void User::login() const +{ + _account->signIn(); +} + +void User::logout() const +{ + _account->signOutByUi(); +} + QString User::name() const { // If davDisplayName is empty (can be several reasons, simplest is missing login at startup), fall back to username @@ -208,6 +218,20 @@ Q_INVOKABLE void UserModel::switchCurrentUser(const int &id) emit refreshCurrentUserGui(); } +Q_INVOKABLE void UserModel::login(const int &id) { + _users[id].login(); +} + +Q_INVOKABLE void UserModel::logout(const int &id) +{ + _users[id].logout(); +} + +Q_INVOKABLE void UserModel::removeAccount(const int &id) +{ + _users[id].logout(); +} + int UserModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index d68c2bc9b..fc6f63989 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -31,6 +31,8 @@ public: bool hasActivities() const; QImage avatar() const; QString id() const; + void login() const; + void logout() const; private: AccountStatePtr _account; @@ -65,6 +67,9 @@ public: Q_INVOKABLE bool currentUserHasActivities(); Q_INVOKABLE bool currentServerHasTalk(); Q_INVOKABLE void switchCurrentUser(const int &id); + Q_INVOKABLE void login(const int &id); + Q_INVOKABLE void logout(const int &id); + Q_INVOKABLE void removeAccount(const int &id); ActivityListModel *currentActivityModel(); @@ -76,11 +81,7 @@ public: }; signals: - Q_INVOKABLE void login(); - Q_INVOKABLE void logout(); Q_INVOKABLE void addAccount(); - Q_INVOKABLE void removeAccount(); - Q_INVOKABLE void refreshCurrentUserGui(); Q_INVOKABLE void newUserSelected(); Q_INVOKABLE void refreshUserMenu(); diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 2e918319d..9c54a4651 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -108,7 +108,7 @@ Window { id: accountMenu x: (currentAccountButton.x + 2) y: (currentAccountButton.y + currentAccountButton.height + 2) - width: (currentAccountButton.width) + width: (currentAccountButton.width - 2) closePolicy: "CloseOnPressOutside" background: Rectangle { @@ -116,7 +116,13 @@ Window { radius: 2 } + onClosed: { + userLineInstantiator.active = false; + userLineInstantiator.active = true; + } + Instantiator { + id: userLineInstantiator model: userModelBackend delegate: UserLine {} onObjectAdded: accountMenu.insertItem(index, object)