From b547b2573e16b26b6d90bf6cab54be0b78f73238 Mon Sep 17 00:00:00 2001 From: vladest Date: Wed, 30 Aug 2017 23:15:39 +0200 Subject: [PATCH] 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