UserLine drafting, bugfixes, restuctures

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
Dominique Fuchs 2020-01-10 16:28:53 +01:00
parent 6ac1a4a353
commit 9c0221a0fa
6 changed files with 93 additions and 38 deletions

View file

@ -232,8 +232,6 @@ void AccountSettings::createAccountToolbox()
menu->addAction(action); menu->addAction(action);
connect(action, &QAction::triggered, this, &AccountSettings::slotDeleteAccount); connect(action, &QAction::triggered, this, &AccountSettings::slotDeleteAccount);
connect(UserModel::instance(), &UserModel::removeAccount,
this, &AccountSettings::slotOpenAccountWizard);
_ui->_accountToolbox->setText(tr("Account") + QLatin1Char(' ')); _ui->_accountToolbox->setText(tr("Account") + QLatin1Char(' '));
_ui->_accountToolbox->setMenu(menu); _ui->_accountToolbox->setMenu(menu);

View file

@ -110,12 +110,6 @@ ownCloudGui::ownCloudGui(Application *parent)
this, &ownCloudGui::slotShowOptionalTrayMessage); this, &ownCloudGui::slotShowOptionalTrayMessage);
connect(Logger::instance(), &Logger::guiMessage, connect(Logger::instance(), &Logger::guiMessage,
this, &ownCloudGui::slotShowGuiMessage); this, &ownCloudGui::slotShowGuiMessage);
connect(UserModel::instance(), &UserModel::login,
this, &ownCloudGui::slotLogin);
connect(UserModel::instance(), &UserModel::logout,
this, &ownCloudGui::slotLogout);
} }
#ifdef WITH_LIBCLOUDPROVIDERS #ifdef WITH_LIBCLOUDPROVIDERS

View file

@ -4,33 +4,19 @@ import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2 import QtQuick.Layouts 1.2
MenuItem { MenuItem {
Connections {
target: userModelBackend
onRefreshUserMenu: {
}
}
id: userLine id: userLine
width: 220
height: 60 height: 60
Rectangle {
id: userLineBackground
height: userLine.height
anchors.fill: parent
color: "transparent"
RowLayout { RowLayout {
id: userLineLayout id: userLineLayout
spacing: 0 spacing: 0
anchors.fill: parent width: 220
height: 60
Button { Button {
id: accountButton id: accountButton
anchors.centerIn: parent Layout.preferredWidth: (userLineLayout.width * (5/6))
Layout.preferredWidth: (userLine.width - 4) Layout.preferredHeight: (userLineLayout.height)
Layout.preferredHeight: (userLineBackground.height - 2)
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
flat: true flat: true
@ -49,21 +35,22 @@ MenuItem {
spacing: 0 spacing: 0
Image { Image {
id: accountAvatar id: accountAvatar
Layout.leftMargin: 2 Layout.leftMargin: 4
verticalAlignment: Qt.AlignCenter verticalAlignment: Qt.AlignCenter
cache: false
source: ("image://avatars/" + index) source: ("image://avatars/" + index)
Layout.preferredHeight: (userLineBackground.height -16) Layout.preferredHeight: (userLineLayout.height -16)
Layout.preferredWidth: (userLineBackground.height -16) Layout.preferredWidth: (userLineLayout.height -16)
} }
Column { Column {
id: accountLabels id: accountLabels
spacing: 4 spacing: 4
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
Layout.leftMargin: 12 Layout.leftMargin: 6
Label { Label {
id: accountUser id: accountUser
width: 120 width: 128
text: name text: name
elide: Text.ElideRight elide: Text.ElideRight
color: "black" color: "black"
@ -72,7 +59,7 @@ MenuItem {
} }
Label { Label {
id: accountServer id: accountServer
width: 120 width: 128
text: server text: server
elide: Text.ElideRight elide: Text.ElideRight
color: "black" color: "black"
@ -81,6 +68,51 @@ MenuItem {
} }
} }
} // accountButton } // 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 } // MenuItem userLine

View file

@ -43,6 +43,16 @@ void User::openLocalFolder()
QDesktopServices::openUrl(this->getFolder()->path()); QDesktopServices::openUrl(this->getFolder()->path());
} }
void User::login() const
{
_account->signIn();
}
void User::logout() const
{
_account->signOutByUi();
}
QString User::name() const QString User::name() const
{ {
// If davDisplayName is empty (can be several reasons, simplest is missing login at startup), fall back to username // 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(); 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 int UserModel::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);

View file

@ -31,6 +31,8 @@ public:
bool hasActivities() const; bool hasActivities() const;
QImage avatar() const; QImage avatar() const;
QString id() const; QString id() const;
void login() const;
void logout() const;
private: private:
AccountStatePtr _account; AccountStatePtr _account;
@ -65,6 +67,9 @@ public:
Q_INVOKABLE bool currentUserHasActivities(); Q_INVOKABLE bool currentUserHasActivities();
Q_INVOKABLE bool currentServerHasTalk(); Q_INVOKABLE bool currentServerHasTalk();
Q_INVOKABLE void switchCurrentUser(const int &id); 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(); ActivityListModel *currentActivityModel();
@ -76,11 +81,7 @@ public:
}; };
signals: signals:
Q_INVOKABLE void login();
Q_INVOKABLE void logout();
Q_INVOKABLE void addAccount(); Q_INVOKABLE void addAccount();
Q_INVOKABLE void removeAccount();
Q_INVOKABLE void refreshCurrentUserGui(); Q_INVOKABLE void refreshCurrentUserGui();
Q_INVOKABLE void newUserSelected(); Q_INVOKABLE void newUserSelected();
Q_INVOKABLE void refreshUserMenu(); Q_INVOKABLE void refreshUserMenu();

View file

@ -108,7 +108,7 @@ Window {
id: accountMenu id: accountMenu
x: (currentAccountButton.x + 2) x: (currentAccountButton.x + 2)
y: (currentAccountButton.y + currentAccountButton.height + 2) y: (currentAccountButton.y + currentAccountButton.height + 2)
width: (currentAccountButton.width) width: (currentAccountButton.width - 2)
closePolicy: "CloseOnPressOutside" closePolicy: "CloseOnPressOutside"
background: Rectangle { background: Rectangle {
@ -116,7 +116,13 @@ Window {
radius: 2 radius: 2
} }
onClosed: {
userLineInstantiator.active = false;
userLineInstantiator.active = true;
}
Instantiator { Instantiator {
id: userLineInstantiator
model: userModelBackend model: userModelBackend
delegate: UserLine {} delegate: UserLine {}
onObjectAdded: accountMenu.insertItem(index, object) onObjectAdded: accountMenu.insertItem(index, object)