mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Added logged in property
This commit is contained in:
parent
903036a709
commit
b547b2573e
3 changed files with 32 additions and 5 deletions
|
@ -121,7 +121,7 @@ Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
RalewaySemiBold {
|
RalewaySemiBold {
|
||||||
text: Account.isLoggedIn() ? qsTr("Log out") : qsTr("Log in")
|
text: Account.loggedIn ? qsTr("Log out") : qsTr("Log in")
|
||||||
horizontalAlignment: Text.AlignRight
|
horizontalAlignment: Text.AlignRight
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
font.pixelSize: 20
|
font.pixelSize: 20
|
||||||
|
@ -129,9 +129,9 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
RalewaySemiBold {
|
RalewaySemiBold {
|
||||||
visible: Account.isLoggedIn()
|
visible: Account.loggedIn
|
||||||
height: Account.isLoggedIn() ? parent.height/2 - parent.spacing/2 : 0
|
height: Account.loggedIn ? parent.height/2 - parent.spacing/2 : 0
|
||||||
text: Account.isLoggedIn() ? "[" + tabletRoot.usernameShort + "]" : ""
|
text: Account.loggedIn ? "[" + tabletRoot.usernameShort + "]" : ""
|
||||||
horizontalAlignment: Text.AlignRight
|
horizontalAlignment: Text.AlignRight
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
font.pixelSize: 20
|
font.pixelSize: 20
|
||||||
|
@ -142,7 +142,7 @@ Item {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!Account.isLoggedIn()) {
|
if (!Account.loggedIn) {
|
||||||
DialogsManager.showLoginDialog()
|
DialogsManager.showLoginDialog()
|
||||||
} else {
|
} else {
|
||||||
Account.logOut()
|
Account.logOut()
|
||||||
|
|
|
@ -18,6 +18,8 @@ AccountScriptingInterface* AccountScriptingInterface::getInstance() {
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
QObject::connect(accountManager.data(), &AccountManager::profileChanged,
|
QObject::connect(accountManager.data(), &AccountManager::profileChanged,
|
||||||
&sharedInstance, &AccountScriptingInterface::usernameChanged);
|
&sharedInstance, &AccountScriptingInterface::usernameChanged);
|
||||||
|
QObject::connect(accountManager.data(), &AccountManager::usernameChanged,
|
||||||
|
&sharedInstance, &AccountScriptingInterface::onUsernameChanged);
|
||||||
return &sharedInstance;
|
return &sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +38,16 @@ void AccountScriptingInterface::logOut() {
|
||||||
return accountManager->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() {
|
QString AccountScriptingInterface::getUsername() {
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
if (accountManager->isLoggedIn()) {
|
if (accountManager->isLoggedIn()) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ class AccountScriptingInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged)
|
Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged)
|
||||||
|
Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged)
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @namespace Account
|
* @namespace Account
|
||||||
|
@ -32,6 +33,7 @@ signals:
|
||||||
* @return {Signal}
|
* @return {Signal}
|
||||||
*/
|
*/
|
||||||
void usernameChanged();
|
void usernameChanged();
|
||||||
|
void loggedInChanged(bool loggedIn);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static AccountScriptingInterface* getInstance();
|
static AccountScriptingInterface* getInstance();
|
||||||
|
@ -51,6 +53,19 @@ public slots:
|
||||||
bool isLoggedIn();
|
bool isLoggedIn();
|
||||||
bool checkAndSignalForAccessToken();
|
bool checkAndSignalForAccessToken();
|
||||||
void logOut();
|
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
|
#endif // hifi_AccountScriptingInterface_h
|
||||||
|
|
Loading…
Reference in a new issue