Merge pull request #11669 from dback2/mergeAccountGlobalServices

merge AccountScriptingInterface into GlobalServicesScriptingInterface
This commit is contained in:
David Back 2018-01-05 11:34:53 -08:00 committed by GitHub
commit ac1c398b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 59 deletions

View file

@ -154,7 +154,6 @@
#include "scripting/Audio.h" #include "scripting/Audio.h"
#include "networking/CloseEventSender.h" #include "networking/CloseEventSender.h"
#include "scripting/TestScriptingInterface.h" #include "scripting/TestScriptingInterface.h"
#include "scripting/AccountScriptingInterface.h"
#include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h"
#include "scripting/ClipboardScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h"
#include "scripting/DesktopScriptingInterface.h" #include "scripting/DesktopScriptingInterface.h"
@ -2372,7 +2371,7 @@ void Application::initializeUi() {
surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data()); surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data()); surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
surfaceContext->setContextProperty("Account", AccountScriptingInterface::getInstance()); surfaceContext->setContextProperty("Account", GlobalServicesScriptingInterface::getInstance());
surfaceContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface); surfaceContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface);
surfaceContext->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance()); surfaceContext->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance());
surfaceContext->setContextProperty("FaceTracker", DependencyManager::get<DdeFaceTracker>().data()); surfaceContext->setContextProperty("FaceTracker", DependencyManager::get<DdeFaceTracker>().data());
@ -5739,7 +5738,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCache>().data()); scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCache>().data());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data()); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Account", GlobalServicesScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface);
scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("GlobalServices", GlobalServicesScriptingInterface::getInstance());

View file

@ -12,47 +12,25 @@
#include "AccountManager.h" #include "AccountManager.h"
#include "AccountScriptingInterface.h" #include "AccountScriptingInterface.h"
#include "GlobalServicesScriptingInterface.h"
AccountScriptingInterface* AccountScriptingInterface::getInstance() { AccountScriptingInterface* AccountScriptingInterface::getInstance() {
static AccountScriptingInterface sharedInstance; static AccountScriptingInterface sharedInstance;
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; return &sharedInstance;
} }
bool AccountScriptingInterface::isLoggedIn() { bool AccountScriptingInterface::isLoggedIn() {
auto accountManager = DependencyManager::get<AccountManager>(); return GlobalServicesScriptingInterface::getInstance()->isLoggedIn();
return accountManager->isLoggedIn();
}
bool AccountScriptingInterface::checkAndSignalForAccessToken() {
auto accountManager = DependencyManager::get<AccountManager>();
return accountManager->checkAndSignalForAccessToken();
} }
void AccountScriptingInterface::logOut() { void AccountScriptingInterface::logOut() {
auto accountManager = DependencyManager::get<AccountManager>(); GlobalServicesScriptingInterface::getInstance()->logOut();
return accountManager->logout();
} }
AccountScriptingInterface::AccountScriptingInterface(QObject *parent): QObject(parent) { bool AccountScriptingInterface::loggedIn() const {
m_loggedIn = isLoggedIn(); return GlobalServicesScriptingInterface::getInstance()->loggedIn();
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>(); return GlobalServicesScriptingInterface::getInstance()->getUsername();
if (accountManager->isLoggedIn()) {
return accountManager->getAccountInfo().getUsername();
} else {
return "Unknown user";
}
} }

View file

@ -17,18 +17,12 @@
class AccountScriptingInterface : public QObject { class AccountScriptingInterface : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString username READ getUsername NOTIFY usernameChanged)
Q_PROPERTY(bool loggedIn READ loggedIn NOTIFY loggedInChanged)
/**jsdoc /**jsdoc
* @namespace Account * @namespace Account
* @property username {String} username if user is logged in, otherwise it returns "Unknown user" * @property username {String} username if user is logged in, otherwise it returns "Unknown user"
*/ */
Q_PROPERTY(QString username READ getUsername)
public: Q_PROPERTY(bool loggedIn READ loggedIn)
Q_PROPERTY(QUrl metaverseServerURL READ getMetaverseServerURL)
QUrl getMetaverseServerURL() { return DependencyManager::get<AccountManager>()->getMetaverseServerURL(); }
signals: signals:
@ -56,21 +50,11 @@ public slots:
* @return {bool} true when user is logged into the High Fidelity metaverse. * @return {bool} true when user is logged into the High Fidelity metaverse.
*/ */
bool isLoggedIn(); bool isLoggedIn();
bool checkAndSignalForAccessToken();
void logOut(); void logOut();
public: public:
AccountScriptingInterface(QObject* parent = nullptr); AccountScriptingInterface(QObject* parent = nullptr) {}
bool loggedIn() const { 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

View file

@ -18,7 +18,7 @@
GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
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::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut);
connect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected); connect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected);
@ -31,11 +31,14 @@ GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() {
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>(); auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
connect(discoverabilityManager.data(), &DiscoverabilityManager::discoverabilityModeChanged, connect(discoverabilityManager.data(), &DiscoverabilityManager::discoverabilityModeChanged,
this, &GlobalServicesScriptingInterface::discoverabilityModeChanged); this, &GlobalServicesScriptingInterface::discoverabilityModeChanged);
_loggedIn = isLoggedIn();
emit loggedInChanged(_loggedIn);
} }
GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
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::logoutComplete, this, &GlobalServicesScriptingInterface::loggedOut);
disconnect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected); disconnect(accountManager.data(), &AccountManager::loginComplete, this, &GlobalServicesScriptingInterface::connected);
} }
@ -45,8 +48,28 @@ GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance(
return &sharedInstance; return &sharedInstance;
} }
const QString& GlobalServicesScriptingInterface::getUsername() const { const QString GlobalServicesScriptingInterface::getUsername() const {
return DependencyManager::get<AccountManager>()->getAccountInfo().getUsername(); auto accountManager = DependencyManager::get<AccountManager>();
if (accountManager->isLoggedIn()) {
return accountManager->getAccountInfo().getUsername();
} else {
return "Unknown user";
}
}
bool GlobalServicesScriptingInterface::isLoggedIn() {
auto accountManager = DependencyManager::get<AccountManager>();
return accountManager->isLoggedIn();
}
bool GlobalServicesScriptingInterface::checkAndSignalForAccessToken() {
auto accountManager = DependencyManager::get<AccountManager>();
return accountManager->checkAndSignalForAccessToken();
}
void GlobalServicesScriptingInterface::logOut() {
auto accountManager = DependencyManager::get<AccountManager>();
return accountManager->logout();
} }
void GlobalServicesScriptingInterface::loggedOut() { void GlobalServicesScriptingInterface::loggedOut() {
@ -77,6 +100,12 @@ void GlobalServicesScriptingInterface::discoverabilityModeChanged(Discoverabilit
emit findableByChanged(DiscoverabilityManager::findableByString(discoverabilityMode)); emit findableByChanged(DiscoverabilityManager::findableByString(discoverabilityMode));
} }
void GlobalServicesScriptingInterface::onUsernameChanged(const QString& username) {
_loggedIn = (username != QString());
emit myUsernameChanged(username);
emit loggedInChanged(_loggedIn);
}
DownloadInfoResult::DownloadInfoResult() : DownloadInfoResult::DownloadInfoResult() :
downloading(QList<float>()), downloading(QList<float>()),
pending(0.0f) pending(0.0f)

View file

@ -35,17 +35,25 @@ void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoR
class GlobalServicesScriptingInterface : public QObject { class GlobalServicesScriptingInterface : public QObject {
Q_OBJECT 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) Q_PROPERTY(QString findableBy READ getFindableBy WRITE setFindableBy NOTIFY findableByChanged)
Q_PROPERTY(QUrl metaverseServerURL READ getMetaverseServerURL)
public: public:
static GlobalServicesScriptingInterface* getInstance(); static GlobalServicesScriptingInterface* getInstance();
const QString& getUsername() const; const QString getUsername() const;
bool loggedIn() const { return _loggedIn; }
QUrl getMetaverseServerURL() { return DependencyManager::get<AccountManager>()->getMetaverseServerURL(); }
public slots: public slots:
DownloadInfoResult getDownloadInfo(); DownloadInfoResult getDownloadInfo();
void updateDownloadInfo(); void updateDownloadInfo();
bool isLoggedIn();
bool checkAndSignalForAccessToken();
void logOut();
private slots: private slots:
void loggedOut(); void loggedOut();
@ -55,18 +63,22 @@ private slots:
void setFindableBy(const QString& discoverabilityMode); void setFindableBy(const QString& discoverabilityMode);
void discoverabilityModeChanged(Discoverability::Mode discoverabilityMode); void discoverabilityModeChanged(Discoverability::Mode discoverabilityMode);
void onUsernameChanged(const QString& username);
signals: signals:
void connected(); void connected();
void disconnected(const QString& reason); void disconnected(const QString& reason);
void myUsernameChanged(const QString& username); void myUsernameChanged(const QString& username);
void downloadInfoChanged(DownloadInfoResult info); void downloadInfoChanged(DownloadInfoResult info);
void findableByChanged(const QString& discoverabilityMode); void findableByChanged(const QString& discoverabilityMode);
void loggedInChanged(bool loggedIn);
private: private:
GlobalServicesScriptingInterface(); GlobalServicesScriptingInterface();
~GlobalServicesScriptingInterface(); ~GlobalServicesScriptingInterface();
bool _downloading; bool _downloading;
bool _loggedIn{ false };
}; };
#endif // hifi_GlobalServicesScriptingInterface_h #endif // hifi_GlobalServicesScriptingInterface_h

View file

@ -36,7 +36,6 @@
#include <UserActivityLoggerScriptingInterface.h> #include <UserActivityLoggerScriptingInterface.h>
#include <AbstractViewStateInterface.h> #include <AbstractViewStateInterface.h>
#include <AddressManager.h> #include <AddressManager.h>
#include "scripting/AccountScriptingInterface.h"
#include "scripting/HMDScriptingInterface.h" #include "scripting/HMDScriptingInterface.h"
#include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h"
#include "scripting/MenuScriptingInterface.h" #include "scripting/MenuScriptingInterface.h"
@ -193,7 +192,7 @@ void Web3DOverlay::setupQmlSurface() {
_webSurface->getSurfaceContext()->setContextProperty("offscreenFlags", flags); _webSurface->getSurfaceContext()->setContextProperty("offscreenFlags", flags);
_webSurface->getSurfaceContext()->setContextProperty("AddressManager", DependencyManager::get<AddressManager>().data()); _webSurface->getSurfaceContext()->setContextProperty("AddressManager", DependencyManager::get<AddressManager>().data());
_webSurface->getSurfaceContext()->setContextProperty("Account", AccountScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("Account", GlobalServicesScriptingInterface::getInstance());
// in Qt 5.10.0 there is already an "Audio" object in the QML context // in Qt 5.10.0 there is already an "Audio" object in the QML context
// though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface" // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface"