From 2e5e0c94f13ab3cfed9bd1583a17a003de2003d8 Mon Sep 17 00:00:00 2001 From: vladest Date: Fri, 18 Aug 2017 15:34:15 +0200 Subject: [PATCH 1/4] Added login button to Tablet --- .../resources/qml/hifi/tablet/Tablet.qml | 28 ++++++++++++++----- .../DialogsManagerScriptingInterface.cpp | 7 ++++- .../DialogsManagerScriptingInterface.h | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/Tablet.qml b/interface/resources/qml/hifi/tablet/Tablet.qml index 43672190dd..521c3b2e14 100644 --- a/interface/resources/qml/hifi/tablet/Tablet.qml +++ b/interface/resources/qml/hifi/tablet/Tablet.qml @@ -109,15 +109,29 @@ Item { } } - RalewaySemiBold { - id: usernameText - text: tabletRoot.username - anchors.verticalCenter: parent.verticalCenter + Item { + width: 150 + height: 50 anchors.right: parent.right anchors.rightMargin: 20 - horizontalAlignment: Text.AlignRight - font.pixelSize: 20 - color: "#afafaf" + anchors.verticalCenter: parent.verticalCenter + + RalewaySemiBold { + id: usernameText + text: Account.isLoggedIn() ? tabletRoot.username : qsTr("Log in") + anchors.verticalCenter: parent.verticalCenter + horizontalAlignment: Text.AlignRight + anchors.right: parent.right + font.pixelSize: 20 + color: "#afafaf" + } + MouseArea { + anchors.fill: parent + enabled: !Account.isLoggedIn() + onClicked: { + DialogsManager.showLoginDialog() + } + } } } diff --git a/interface/src/scripting/DialogsManagerScriptingInterface.cpp b/interface/src/scripting/DialogsManagerScriptingInterface.cpp index 0fb6078290..596320eb3c 100644 --- a/interface/src/scripting/DialogsManagerScriptingInterface.cpp +++ b/interface/src/scripting/DialogsManagerScriptingInterface.cpp @@ -33,7 +33,12 @@ void DialogsManagerScriptingInterface::showAddressBar() { void DialogsManagerScriptingInterface::hideAddressBar() { QMetaObject::invokeMethod(DependencyManager::get().data(), - "hideAddressBar", Qt::QueuedConnection); + "hideAddressBar", Qt::QueuedConnection); +} + +void DialogsManagerScriptingInterface::showLoginDialog() { + QMetaObject::invokeMethod(DependencyManager::get().data(), + "showLoginDialog", Qt::QueuedConnection); } void DialogsManagerScriptingInterface::showFeed() { diff --git a/interface/src/scripting/DialogsManagerScriptingInterface.h b/interface/src/scripting/DialogsManagerScriptingInterface.h index e4dd18aedf..b223799cfe 100644 --- a/interface/src/scripting/DialogsManagerScriptingInterface.h +++ b/interface/src/scripting/DialogsManagerScriptingInterface.h @@ -24,6 +24,7 @@ public: public slots: void showAddressBar(); void hideAddressBar(); + void showLoginDialog(); signals: void addressBarShown(bool visible); From bad8c39444384aa3853815bc54e011c1d9dc4293 Mon Sep 17 00:00:00 2001 From: vladest Date: Sat, 19 Aug 2017 17:46:52 +0200 Subject: [PATCH 2/4] Align user/login text right border with tablet buttons --- interface/resources/qml/hifi/tablet/Tablet.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/tablet/Tablet.qml b/interface/resources/qml/hifi/tablet/Tablet.qml index 521c3b2e14..a99df632e5 100644 --- a/interface/resources/qml/hifi/tablet/Tablet.qml +++ b/interface/resources/qml/hifi/tablet/Tablet.qml @@ -113,7 +113,7 @@ Item { width: 150 height: 50 anchors.right: parent.right - anchors.rightMargin: 20 + anchors.rightMargin: 30 anchors.verticalCenter: parent.verticalCenter RalewaySemiBold { From 26026cb2b578e5394a6d80522749e64746168935 Mon Sep 17 00:00:00 2001 From: vladest Date: Fri, 25 Aug 2017 17:37:10 +0200 Subject: [PATCH 3/4] Added logout. Truncate username to 8 characters --- .../resources/qml/hifi/tablet/Tablet.qml | 37 ++++++++++++++----- .../resources/qml/hifi/tablet/TabletRoot.qml | 6 +++ .../scripting/AccountScriptingInterface.cpp | 5 +++ .../src/scripting/AccountScriptingInterface.h | 1 + 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/Tablet.qml b/interface/resources/qml/hifi/tablet/Tablet.qml index a99df632e5..3005fee4dd 100644 --- a/interface/resources/qml/hifi/tablet/Tablet.qml +++ b/interface/resources/qml/hifi/tablet/Tablet.qml @@ -1,5 +1,6 @@ import QtQuick 2.5 import QtGraphicalEffects 1.0 +import QtQuick.Layouts 1.3 import "../../styles-uit" import "../audio" as HifiAudio @@ -116,20 +117,36 @@ Item { anchors.rightMargin: 30 anchors.verticalCenter: parent.verticalCenter - RalewaySemiBold { - id: usernameText - text: Account.isLoggedIn() ? tabletRoot.username : qsTr("Log in") - anchors.verticalCenter: parent.verticalCenter - horizontalAlignment: Text.AlignRight - anchors.right: parent.right - font.pixelSize: 20 - color: "#afafaf" + ColumnLayout { + anchors.fill: parent + + RalewaySemiBold { + text: Account.isLoggedIn() ? qsTr("Log out") : qsTr("Log in") + horizontalAlignment: Text.AlignRight + anchors.right: parent.right + font.pixelSize: 20 + color: "#afafaf" + } + + RalewaySemiBold { + visible: Account.isLoggedIn() + height: Account.isLoggedIn() ? parent.height/2 - parent.spacing/2 : 0 + text: Account.isLoggedIn() ? "[" + tabletRoot.usernameShort + "]" : "" + horizontalAlignment: Text.AlignRight + anchors.right: parent.right + font.pixelSize: 20 + color: "#afafaf" + } } + MouseArea { anchors.fill: parent - enabled: !Account.isLoggedIn() onClicked: { - DialogsManager.showLoginDialog() + if (!Account.isLoggedIn()) { + DialogsManager.showLoginDialog() + } else { + Account.logOut() + } } } } diff --git a/interface/resources/qml/hifi/tablet/TabletRoot.qml b/interface/resources/qml/hifi/tablet/TabletRoot.qml index bbf56c7827..683b181422 100644 --- a/interface/resources/qml/hifi/tablet/TabletRoot.qml +++ b/interface/resources/qml/hifi/tablet/TabletRoot.qml @@ -8,6 +8,7 @@ Item { id: tabletRoot objectName: "tabletRoot" property string username: "Unknown user" + property string usernameShort: "Unknown user" property var rootMenu; property var openModal: null; property var openMessage: null; @@ -157,6 +158,11 @@ Item { function setUsername(newUsername) { username = newUsername; + usernameShort = newUsername.substring(0, 8); + + if (newUsername.length > 8) { + usernameShort = usernameShort + "..." + } } ListModel { diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index d8533bb769..4587d74893 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -31,6 +31,11 @@ bool AccountScriptingInterface::checkAndSignalForAccessToken() { return accountManager->checkAndSignalForAccessToken(); } +void AccountScriptingInterface::logOut() { + auto accountManager = DependencyManager::get(); + return accountManager->logout(); +} + QString AccountScriptingInterface::getUsername() { auto accountManager = DependencyManager::get(); if (accountManager->isLoggedIn()) { diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 748f110356..098d2c8ad9 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -50,6 +50,7 @@ public slots: */ bool isLoggedIn(); bool checkAndSignalForAccessToken(); + void logOut(); }; #endif // hifi_AccountScriptingInterface_h From b547b2573e16b26b6d90bf6cab54be0b78f73238 Mon Sep 17 00:00:00 2001 From: vladest Date: Wed, 30 Aug 2017 23:15:39 +0200 Subject: [PATCH 4/4] Added logged in property --- interface/resources/qml/hifi/tablet/Tablet.qml | 10 +++++----- .../src/scripting/AccountScriptingInterface.cpp | 12 ++++++++++++ .../src/scripting/AccountScriptingInterface.h | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/Tablet.qml b/interface/resources/qml/hifi/tablet/Tablet.qml index 3005fee4dd..66e3dfdbbb 100644 --- a/interface/resources/qml/hifi/tablet/Tablet.qml +++ b/interface/resources/qml/hifi/tablet/Tablet.qml @@ -121,7 +121,7 @@ Item { anchors.fill: parent RalewaySemiBold { - text: Account.isLoggedIn() ? qsTr("Log out") : qsTr("Log in") + text: Account.loggedIn ? qsTr("Log out") : qsTr("Log in") horizontalAlignment: Text.AlignRight anchors.right: parent.right font.pixelSize: 20 @@ -129,9 +129,9 @@ Item { } RalewaySemiBold { - visible: Account.isLoggedIn() - height: Account.isLoggedIn() ? parent.height/2 - parent.spacing/2 : 0 - text: Account.isLoggedIn() ? "[" + tabletRoot.usernameShort + "]" : "" + visible: Account.loggedIn + height: Account.loggedIn ? parent.height/2 - parent.spacing/2 : 0 + text: Account.loggedIn ? "[" + tabletRoot.usernameShort + "]" : "" horizontalAlignment: Text.AlignRight anchors.right: parent.right font.pixelSize: 20 @@ -142,7 +142,7 @@ Item { MouseArea { anchors.fill: parent onClicked: { - if (!Account.isLoggedIn()) { + if (!Account.loggedIn) { DialogsManager.showLoginDialog() } else { Account.logOut() diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index 4587d74893..068cccdc50 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -18,6 +18,8 @@ AccountScriptingInterface* AccountScriptingInterface::getInstance() { auto accountManager = DependencyManager::get(); QObject::connect(accountManager.data(), &AccountManager::profileChanged, &sharedInstance, &AccountScriptingInterface::usernameChanged); + QObject::connect(accountManager.data(), &AccountManager::usernameChanged, + &sharedInstance, &AccountScriptingInterface::onUsernameChanged); return &sharedInstance; } @@ -36,6 +38,16 @@ void AccountScriptingInterface::logOut() { return accountManager->logout(); } +AccountScriptingInterface::AccountScriptingInterface(QObject *parent): QObject(parent) { + m_loggedIn = isLoggedIn(); + emit loggedInChanged(m_loggedIn); +} + +void AccountScriptingInterface::onUsernameChanged(QString username) { + m_loggedIn = (username != QString()); + emit loggedInChanged(m_loggedIn); +} + QString AccountScriptingInterface::getUsername() { auto accountManager = DependencyManager::get(); if (accountManager->isLoggedIn()) { diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 098d2c8ad9..4f87e02dce 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -18,6 +18,7 @@ class AccountScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged) + Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged) /**jsdoc * @namespace Account @@ -32,6 +33,7 @@ signals: * @return {Signal} */ void usernameChanged(); + void loggedInChanged(bool loggedIn); public slots: static AccountScriptingInterface* getInstance(); @@ -51,6 +53,19 @@ public slots: bool isLoggedIn(); bool checkAndSignalForAccessToken(); void logOut(); + +public: + AccountScriptingInterface(QObject* parent = nullptr); + bool loggedIn() const { + return m_loggedIn; + } + +private slots: + void onUsernameChanged(QString username); + +private: + bool m_loggedIn { false }; + }; #endif // hifi_AccountScriptingInterface_h