Added logged in property

This commit is contained in:
vladest 2017-08-30 23:15:39 +02:00
parent 903036a709
commit b547b2573e
3 changed files with 32 additions and 5 deletions

View file

@ -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()

View file

@ -18,6 +18,8 @@ AccountScriptingInterface* AccountScriptingInterface::getInstance() {
auto accountManager = DependencyManager::get<AccountManager>();
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<AccountManager>();
if (accountManager->isLoggedIn()) {

View file

@ -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