From 76e6c9342f5e87a61ec55780eaaa0af0e2686c25 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 21 Feb 2014 14:41:43 -0800 Subject: [PATCH] parse username returned from data-server --- interface/src/Application.cpp | 3 ++- libraries/shared/src/AccountManager.cpp | 14 +++++++++++++- libraries/shared/src/AccountManager.h | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 526a4f848b..d6dc4c4591 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3928,7 +3928,8 @@ void Application::updateWindowTitle(){ QString buildVersion = " (build " + applicationVersion() + ")"; NodeList* nodeList = NodeList::getInstance(); - QString title = QString() + nodeList->getSessionUUID().toString() + QString username = AccountManager::getInstance().getUsername(); + QString title = QString() + (!username.isEmpty() ? username : "") + nodeList->getSessionUUID().toString() + " @ " + nodeList->getDomainInfo().getHostname() + buildVersion; qDebug("Application title set to: %s", title.toStdString().c_str()); diff --git a/libraries/shared/src/AccountManager.cpp b/libraries/shared/src/AccountManager.cpp index 05d66a61f4..bb9b40635b 100644 --- a/libraries/shared/src/AccountManager.cpp +++ b/libraries/shared/src/AccountManager.cpp @@ -58,7 +58,6 @@ AccountManager::AccountManager() : } void AccountManager::setRootURL(const QUrl& rootURL) { - if (_rootURL != rootURL) { _rootURL = rootURL; @@ -71,6 +70,16 @@ void AccountManager::setRootURL(const QUrl& rootURL) { } } +void AccountManager::setUsername(const QString& username) { + if (_username != username) { + _username = username; + + qDebug() << "Changing username to" << username; + + emit usernameChanged(username); + } +} + void AccountManager::authenticatedRequest(const QString& path, QNetworkAccessManager::Operation operation, const JSONCallbackParameters& callbackParams, const QByteArray& dataByteArray) { QMetaObject::invokeMethod(this, "invokedRequest", @@ -224,6 +233,9 @@ void AccountManager::requestFinished() { OAuthAccessToken freshAccessToken(rootObject); _accessTokens.insert(rootURL, freshAccessToken); + // pull username from the response + setUsername(rootObject["user"].toObject()["username"].toString()); + emit receivedAccessToken(rootURL); // store this access token into the local settings diff --git a/libraries/shared/src/AccountManager.h b/libraries/shared/src/AccountManager.h index 6479711754..92b0f46674 100644 --- a/libraries/shared/src/AccountManager.h +++ b/libraries/shared/src/AccountManager.h @@ -50,7 +50,7 @@ public: void requestAccessToken(const QString& login, const QString& password); const QString& getUsername() const { return _username; } - void setUsername(const QString& username) { _username = username; } + void setUsername(const QString& username); public slots: void requestFinished(); @@ -58,6 +58,7 @@ public slots: signals: void authenticationRequired(); void receivedAccessToken(const QUrl& rootURL); + void usernameChanged(const QString& username); private slots: void passSuccessToCallback(); void passErrorToCallback(QNetworkReply::NetworkError errorCode);