From b60bf4f8cb068e49f62f9289025d795d22146bee Mon Sep 17 00:00:00 2001 From: David Back Date: Tue, 24 Oct 2017 10:17:36 -0700 Subject: [PATCH 1/6] remove unused AccountScriptingInterface functions and merge/wrap the rest into GlobalServicesScriptingInterface --- .../scripting/AccountScriptingInterface.cpp | 34 ++++--------------- .../src/scripting/AccountScriptingInterface.h | 28 +++------------ .../GlobalServicesScriptingInterface.cpp | 28 +++++++++++++-- .../GlobalServicesScriptingInterface.h | 13 +++++++ 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index 068cccdc50..fd54198b3c 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -12,47 +12,25 @@ #include "AccountManager.h" #include "AccountScriptingInterface.h" +#include "GlobalServicesScriptingInterface.h" AccountScriptingInterface* AccountScriptingInterface::getInstance() { static AccountScriptingInterface sharedInstance; - auto accountManager = DependencyManager::get(); - QObject::connect(accountManager.data(), &AccountManager::profileChanged, - &sharedInstance, &AccountScriptingInterface::usernameChanged); - QObject::connect(accountManager.data(), &AccountManager::usernameChanged, - &sharedInstance, &AccountScriptingInterface::onUsernameChanged); return &sharedInstance; } bool AccountScriptingInterface::isLoggedIn() { - auto accountManager = DependencyManager::get(); - return accountManager->isLoggedIn(); -} - -bool AccountScriptingInterface::checkAndSignalForAccessToken() { - auto accountManager = DependencyManager::get(); - return accountManager->checkAndSignalForAccessToken(); + return GlobalServicesScriptingInterface::getInstance()->isLoggedIn(); } void AccountScriptingInterface::logOut() { - auto accountManager = DependencyManager::get(); - return accountManager->logout(); + GlobalServicesScriptingInterface::getInstance()->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); +bool AccountScriptingInterface::loggedIn() const { + return GlobalServicesScriptingInterface::getInstance()->loggedIn(); } QString AccountScriptingInterface::getUsername() { - auto accountManager = DependencyManager::get(); - if (accountManager->isLoggedIn()) { - return accountManager->getAccountInfo().getUsername(); - } else { - return "Unknown user"; - } + return GlobalServicesScriptingInterface::getInstance()->getUsername(); } diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 4f87e02dce..6af067e082 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -17,24 +17,14 @@ class AccountScriptingInterface : public QObject { Q_OBJECT - Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged) - Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged) + Q_PROPERTY(QString username READ getUsername) + Q_PROPERTY(bool loggedIn READ loggedIn) /**jsdoc * @namespace Account * @property username {String} username if user is logged in, otherwise it returns "Unknown user" */ -signals: - - /**jsdoc - * Triggered when username has changed. - * @function Account.usernameChanged - * @return {Signal} - */ - void usernameChanged(); - void loggedInChanged(bool loggedIn); - public slots: static AccountScriptingInterface* getInstance(); @@ -51,21 +41,11 @@ public slots: * @return {bool} true when user is logged into the High Fidelity metaverse. */ 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 }; - + AccountScriptingInterface(QObject* parent = nullptr) {} + bool loggedIn() const; }; #endif // hifi_AccountScriptingInterface_h diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.cpp b/interface/src/scripting/GlobalServicesScriptingInterface.cpp index f4a5ffb39c..ea7528b85d 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.cpp +++ b/interface/src/scripting/GlobalServicesScriptingInterface.cpp @@ -18,7 +18,7 @@ GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { auto accountManager = DependencyManager::get(); - connect(accountManager.data(), &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); + connect(accountManager.data(), &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::onUsernameChanged); connect(accountManager.data(), &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); connect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected); @@ -31,11 +31,14 @@ GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { auto discoverabilityManager = DependencyManager::get(); connect(discoverabilityManager.data(), &DiscoverabilityManager::discoverabilityModeChanged, this, &GlobalServicesScriptingInterface::discoverabilityModeChanged); + + _loggedIn = isLoggedIn(); + emit loggedInChanged(_loggedIn); } GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { auto accountManager = DependencyManager::get(); - disconnect(accountManager.data(), &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::myUsernameChanged); + disconnect(accountManager.data(), &AccountManager::usernameChanged, this, &GlobalServicesScriptingInterface::onUsernameChanged); disconnect(accountManager.data(), &AccountManager::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut); disconnect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected); } @@ -49,6 +52,21 @@ const QString& GlobalServicesScriptingInterface::getUsername() const { return DependencyManager::get()->getAccountInfo().getUsername(); } +bool GlobalServicesScriptingInterface::isLoggedIn() { + auto accountManager = DependencyManager::get(); + return accountManager->isLoggedIn(); +} + +bool GlobalServicesScriptingInterface::checkAndSignalForAccessToken() { + auto accountManager = DependencyManager::get(); + return accountManager->checkAndSignalForAccessToken(); +} + +void GlobalServicesScriptingInterface::logOut() { + auto accountManager = DependencyManager::get(); + return accountManager->logout(); +} + void GlobalServicesScriptingInterface::loggedOut() { emit GlobalServicesScriptingInterface::disconnected(QString("logout")); } @@ -77,6 +95,12 @@ void GlobalServicesScriptingInterface::discoverabilityModeChanged(Discoverabilit emit findableByChanged(DiscoverabilityManager::findableByString(discoverabilityMode)); } +void GlobalServicesScriptingInterface::onUsernameChanged(QString username) { + _loggedIn = (username != QString()); + emit myUsernameChanged(username); + emit loggedInChanged(_loggedIn); +} + DownloadInfoResult::DownloadInfoResult() : downloading(QList()), pending(0.0f) diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.h b/interface/src/scripting/GlobalServicesScriptingInterface.h index 63294fc656..799d5375b8 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.h +++ b/interface/src/scripting/GlobalServicesScriptingInterface.h @@ -36,16 +36,25 @@ class GlobalServicesScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(QString username READ getUsername) + Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged) Q_PROPERTY(QString findableBy READ getFindableBy WRITE setFindableBy NOTIFY findableByChanged) public: static GlobalServicesScriptingInterface* getInstance(); const QString& getUsername() const; + + bool loggedIn() const { + return _loggedIn; + } public slots: DownloadInfoResult getDownloadInfo(); void updateDownloadInfo(); + + bool isLoggedIn(); + bool checkAndSignalForAccessToken(); + void logOut(); private slots: void loggedOut(); @@ -55,18 +64,22 @@ private slots: void setFindableBy(const QString& discoverabilityMode); void discoverabilityModeChanged(Discoverability::Mode discoverabilityMode); + void onUsernameChanged(QString username); + signals: void connected(); void disconnected(const QString& reason); void myUsernameChanged(const QString& username); void downloadInfoChanged(DownloadInfoResult info); void findableByChanged(const QString& discoverabilityMode); + void loggedInChanged(bool loggedIn); private: GlobalServicesScriptingInterface(); ~GlobalServicesScriptingInterface(); bool _downloading; + bool _loggedIn{ false }; }; #endif // hifi_GlobalServicesScriptingInterface_h From f6f49fc2e525c2dbc5642d84ca64989130a2d08e Mon Sep 17 00:00:00 2001 From: David Back Date: Tue, 24 Oct 2017 13:26:28 -0700 Subject: [PATCH 2/6] account to global services merge tweaks --- interface/src/scripting/AccountScriptingInterface.h | 5 ++--- .../src/scripting/GlobalServicesScriptingInterface.cpp | 10 ++++++++-- .../src/scripting/GlobalServicesScriptingInterface.h | 9 +++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 6af067e082..93a48653b3 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -17,13 +17,12 @@ class AccountScriptingInterface : public QObject { Q_OBJECT - Q_PROPERTY(QString username READ getUsername) - Q_PROPERTY(bool loggedIn READ loggedIn) - /**jsdoc * @namespace Account * @property username {String} username if user is logged in, otherwise it returns "Unknown user" */ + Q_PROPERTY(QString username READ getUsername) + Q_PROPERTY(bool loggedIn READ loggedIn) public slots: static AccountScriptingInterface* getInstance(); diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.cpp b/interface/src/scripting/GlobalServicesScriptingInterface.cpp index ea7528b85d..8a48c7710e 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.cpp +++ b/interface/src/scripting/GlobalServicesScriptingInterface.cpp @@ -49,7 +49,13 @@ GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance( } const QString& GlobalServicesScriptingInterface::getUsername() const { - return DependencyManager::get()->getAccountInfo().getUsername(); + auto accountManager = DependencyManager::get(); + if (accountManager->isLoggedIn()) { + return accountManager->getAccountInfo().getUsername(); + } + else { + return "Unknown user"; + } } bool GlobalServicesScriptingInterface::isLoggedIn() { @@ -95,7 +101,7 @@ void GlobalServicesScriptingInterface::discoverabilityModeChanged(Discoverabilit emit findableByChanged(DiscoverabilityManager::findableByString(discoverabilityMode)); } -void GlobalServicesScriptingInterface::onUsernameChanged(QString username) { +void GlobalServicesScriptingInterface::onUsernameChanged(const QString& username) { _loggedIn = (username != QString()); emit myUsernameChanged(username); emit loggedInChanged(_loggedIn); diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.h b/interface/src/scripting/GlobalServicesScriptingInterface.h index 799d5375b8..b8744fe6fa 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.h +++ b/interface/src/scripting/GlobalServicesScriptingInterface.h @@ -35,7 +35,7 @@ void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoR class GlobalServicesScriptingInterface : public QObject { Q_OBJECT - Q_PROPERTY(QString username READ getUsername) + Q_PROPERTY(QString username READ getUsername NOTIFY myUsernameChanged) Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged) Q_PROPERTY(QString findableBy READ getFindableBy WRITE setFindableBy NOTIFY findableByChanged) @@ -43,10 +43,7 @@ public: static GlobalServicesScriptingInterface* getInstance(); const QString& getUsername() const; - - bool loggedIn() const { - return _loggedIn; - } + bool loggedIn() const { return _loggedIn; } public slots: DownloadInfoResult getDownloadInfo(); @@ -64,7 +61,7 @@ private slots: void setFindableBy(const QString& discoverabilityMode); void discoverabilityModeChanged(Discoverability::Mode discoverabilityMode); - void onUsernameChanged(QString username); + void onUsernameChanged(const QString& username); signals: void connected(); From cffcf2d8df42c9c7e22c5fa75c08f27d74cd9e86 Mon Sep 17 00:00:00 2001 From: David Back Date: Tue, 24 Oct 2017 13:44:00 -0700 Subject: [PATCH 3/6] point Account context to GlobalServices instead --- interface/src/Application.cpp | 5 ++--- interface/src/ui/overlays/Web3DOverlay.cpp | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0b99ce5004..018fdf8386 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -153,7 +153,6 @@ #include "scripting/Audio.h" #include "networking/CloseEventSender.h" #include "scripting/TestScriptingInterface.h" -#include "scripting/AccountScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" #include "scripting/DesktopScriptingInterface.h" @@ -2325,7 +2324,7 @@ void Application::initializeUi() { surfaceContext->setContextProperty("SoundCache", DependencyManager::get().data()); surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get().data()); - surfaceContext->setContextProperty("Account", AccountScriptingInterface::getInstance()); + surfaceContext->setContextProperty("Account", GlobalServicesScriptingInterface::getInstance()); surfaceContext->setContextProperty("Tablet", DependencyManager::get().data()); // Tablet inteference with Tablet.qml. Need to avoid this in QML space surfaceContext->setContextProperty("tabletInterface", DependencyManager::get().data()); @@ -5853,7 +5852,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); + scriptEngine->registerGlobalObject("Account", GlobalServicesScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance()); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 363c85b395..8b9bb51c6d 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -36,7 +36,6 @@ #include #include #include -#include "scripting/AccountScriptingInterface.h" #include "scripting/HMDScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/MenuScriptingInterface.h" @@ -224,7 +223,7 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("offscreenFlags", flags); _webSurface->getSurfaceContext()->setContextProperty("AddressManager", DependencyManager::get().data()); - _webSurface->getSurfaceContext()->setContextProperty("Account", AccountScriptingInterface::getInstance()); + _webSurface->getSurfaceContext()->setContextProperty("Account", GlobalServicesScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("Audio", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("AudioStats", DependencyManager::get()->getStats().data()); _webSurface->getSurfaceContext()->setContextProperty("HMD", DependencyManager::get().data()); From c8a0f9761a5670c370b1f6bb331f5718b9b64637 Mon Sep 17 00:00:00 2001 From: David Back Date: Tue, 24 Oct 2017 16:13:22 -0700 Subject: [PATCH 4/6] fix reference return for getUsername --- interface/src/scripting/GlobalServicesScriptingInterface.cpp | 2 +- interface/src/scripting/GlobalServicesScriptingInterface.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.cpp b/interface/src/scripting/GlobalServicesScriptingInterface.cpp index 8a48c7710e..dd2ead5580 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.cpp +++ b/interface/src/scripting/GlobalServicesScriptingInterface.cpp @@ -48,7 +48,7 @@ GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance( return &sharedInstance; } -const QString& GlobalServicesScriptingInterface::getUsername() const { +const QString GlobalServicesScriptingInterface::getUsername() const { auto accountManager = DependencyManager::get(); if (accountManager->isLoggedIn()) { return accountManager->getAccountInfo().getUsername(); diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.h b/interface/src/scripting/GlobalServicesScriptingInterface.h index b8744fe6fa..7f0f7859a5 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.h +++ b/interface/src/scripting/GlobalServicesScriptingInterface.h @@ -42,7 +42,7 @@ class GlobalServicesScriptingInterface : public QObject { public: static GlobalServicesScriptingInterface* getInstance(); - const QString& getUsername() const; + const QString getUsername() const; bool loggedIn() const { return _loggedIn; } public slots: From 5e1064800a1e5eec5dff0bb84eec8a868d53ded5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Dec 2017 18:39:17 -0800 Subject: [PATCH 5/6] fix marketplace --- interface/src/scripting/AccountScriptingInterface.h | 5 ----- interface/src/scripting/GlobalServicesScriptingInterface.h | 2 ++ 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 5a5502464d..10d33ffa36 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -24,11 +24,6 @@ class AccountScriptingInterface : public QObject { Q_PROPERTY(QString username READ getUsername) Q_PROPERTY(bool loggedIn READ loggedIn) -public: - - Q_PROPERTY(QUrl metaverseServerURL READ getMetaverseServerURL) - QUrl getMetaverseServerURL() { return DependencyManager::get()->getMetaverseServerURL(); } - signals: /**jsdoc diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.h b/interface/src/scripting/GlobalServicesScriptingInterface.h index 7f0f7859a5..93d35e9ce8 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.h +++ b/interface/src/scripting/GlobalServicesScriptingInterface.h @@ -38,12 +38,14 @@ class GlobalServicesScriptingInterface : public QObject { Q_PROPERTY(QString username READ getUsername NOTIFY myUsernameChanged) Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged) Q_PROPERTY(QString findableBy READ getFindableBy WRITE setFindableBy NOTIFY findableByChanged) + Q_PROPERTY(QUrl metaverseServerURL READ getMetaverseServerURL) public: static GlobalServicesScriptingInterface* getInstance(); const QString getUsername() const; bool loggedIn() const { return _loggedIn; } + QUrl getMetaverseServerURL() { return DependencyManager::get()->getMetaverseServerURL(); } public slots: DownloadInfoResult getDownloadInfo(); From be736373f29b77e24429eed651f2bd2b75f82730 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Dec 2017 17:52:27 -0800 Subject: [PATCH 6/6] fix if else convention --- interface/src/scripting/GlobalServicesScriptingInterface.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.cpp b/interface/src/scripting/GlobalServicesScriptingInterface.cpp index dd2ead5580..305bfa3e79 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.cpp +++ b/interface/src/scripting/GlobalServicesScriptingInterface.cpp @@ -52,8 +52,7 @@ const QString GlobalServicesScriptingInterface::getUsername() const { auto accountManager = DependencyManager::get(); if (accountManager->isLoggedIn()) { return accountManager->getAccountInfo().getUsername(); - } - else { + } else { return "Unknown user"; } }