diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index cf36fdbffb..15025831e7 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -86,7 +86,7 @@ keyboard.onKeyRelease = function(event) { var textLines = textText.split("\n"); var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width; - var usernameLine = "--" + GlobalServices.myUsername; + var usernameLine = "--" + GlobalServices.username; var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; if (maxLineWidth < usernameWidth) { maxLineWidth = usernameWidth; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 172f0c94a5..6945e88949 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -87,6 +87,7 @@ #include "Application.h" #include "AudioClient.h" +#include "DiscoverabilityManager.h" #include "InterfaceVersion.h" #include "LODManager.h" #include "Menu.h" @@ -246,6 +247,7 @@ bool setupEssentials(int& argc, char** argv) { #if defined(Q_OS_MAC) || defined(Q_OS_WIN) auto speechRecognizer = DependencyManager::set(); #endif + auto discoverabilityManager = DependencyManager::set(); return true; } @@ -367,11 +369,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(&domainHandler, &DomainHandler::hostnameChanged, DependencyManager::get().data(), &AddressManager::storeCurrentAddress); - // update our location every 5 seconds in the data-server, assuming that we are authenticated with one + // update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000; locationUpdateTimer = new QTimer(this); - connect(locationUpdateTimer, &QTimer::timeout, this, &Application::updateLocationInServer); + auto discoverabilityManager = DependencyManager::get(); + connect(locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation); locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS); connect(nodeList.data(), &NodeList::nodeAdded, this, &Application::nodeAdded); @@ -3191,45 +3194,6 @@ void Application::updateWindowTitle(){ _window->setWindowTitle(title); } -void Application::updateLocationInServer() { - - AccountManager& accountManager = AccountManager::getInstance(); - auto addressManager = DependencyManager::get(); - DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); - - if (accountManager.isLoggedIn() && domainHandler.isConnected() - && (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) { - - // construct a QJsonObject given the user's current address information - QJsonObject rootObject; - - QJsonObject locationObject; - - QString pathString = addressManager->currentPath(); - - const QString LOCATION_KEY_IN_ROOT = "location"; - - const QString PATH_KEY_IN_LOCATION = "path"; - locationObject.insert(PATH_KEY_IN_LOCATION, pathString); - - if (!addressManager->getRootPlaceID().isNull()) { - const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; - locationObject.insert(PLACE_ID_KEY_IN_LOCATION, - uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); - - } else { - const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; - locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, - uuidStringWithoutCurlyBraces(domainHandler.getUUID())); - } - - rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); - - accountManager.authenticatedRequest("/api/v1/user/location", QNetworkAccessManager::PutOperation, - JSONCallbackParameters(), QJsonDocument(rootObject).toJson()); - } -} - void Application::clearDomainOctreeDetails() { qDebug() << "Clearing domain octree details..."; // reset the environment so that we don't erroneously end up with multiple diff --git a/interface/src/Application.h b/interface/src/Application.h index ce4bae45b9..1da5f430b6 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -318,7 +318,6 @@ signals: public slots: void domainChanged(const QString& domainHostname); void updateWindowTitle(); - void updateLocationInServer(); void nodeAdded(SharedNodePointer node); void nodeKilled(SharedNodePointer node); void packetSent(quint64 length); diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp new file mode 100644 index 0000000000..49850e4ef6 --- /dev/null +++ b/interface/src/DiscoverabilityManager.cpp @@ -0,0 +1,88 @@ +// +// DiscoverabilityManager.cpp +// interface/src +// +// Created by Stephen Birarda on 2015-03-09. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include +#include +#include +#include +#include + +#include "DiscoverabilityManager.h" + +const Discoverability::Mode DEFAULT_DISCOVERABILITY_MODE = Discoverability::All; + +DiscoverabilityManager::DiscoverabilityManager() : + _mode("discoverabilityMode", DEFAULT_DISCOVERABILITY_MODE) +{ + +} + +const QString API_USER_LOCATION_PATH = "/api/v1/user/location"; + +void DiscoverabilityManager::updateLocation() { + if (_mode.get() != Discoverability::None) { + AccountManager& accountManager = AccountManager::getInstance(); + auto addressManager = DependencyManager::get(); + DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); + + if (accountManager.isLoggedIn() && domainHandler.isConnected() + && (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) { + + // construct a QJsonObject given the user's current address information + QJsonObject rootObject; + + QJsonObject locationObject; + + QString pathString = addressManager->currentPath(); + + const QString LOCATION_KEY_IN_ROOT = "location"; + + const QString PATH_KEY_IN_LOCATION = "path"; + locationObject.insert(PATH_KEY_IN_LOCATION, pathString); + + if (!addressManager->getRootPlaceID().isNull()) { + const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; + locationObject.insert(PLACE_ID_KEY_IN_LOCATION, + uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); + + } else { + const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; + locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, + uuidStringWithoutCurlyBraces(domainHandler.getUUID())); + } + + rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); + + accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::PutOperation, + JSONCallbackParameters(), QJsonDocument(rootObject).toJson()); + } + } +} + +void DiscoverabilityManager::removeLocation() { + AccountManager& accountManager = AccountManager::getInstance(); + accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::DeleteOperation); +} + +void DiscoverabilityManager::setDiscoverabilityMode(Discoverability::Mode discoverabilityMode) { + if (static_cast(_mode.get()) != discoverabilityMode) { + + // update the setting to the new value + _mode.set(static_cast(discoverabilityMode)); + + if (static_cast(_mode.get()) == Discoverability::None) { + // if we just got set to no discoverability, make sure that we delete our location in DB + removeLocation(); + } + } +} \ No newline at end of file diff --git a/interface/src/DiscoverabilityManager.h b/interface/src/DiscoverabilityManager.h new file mode 100644 index 0000000000..1dac7d63eb --- /dev/null +++ b/interface/src/DiscoverabilityManager.h @@ -0,0 +1,45 @@ +// +// DiscoverabilityManager.h +// interface/src +// +// Created by Stephen Birarda on 2015-03-09. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_DiscoverabilityManager_h +#define hifi_DiscoverabilityManager_h + +#include +#include + +namespace Discoverability { + enum Mode { + None, + Friends, + All + }; +} + +Q_DECLARE_METATYPE(Discoverability::Mode); + +class DiscoverabilityManager : public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY + +public slots: + void updateLocation(); + void removeLocation(); + + Discoverability::Mode getDiscoverabilityMode() { return static_cast(_mode.get()); } + void setDiscoverabilityMode(Discoverability::Mode discoverabilityMode); + +private: + DiscoverabilityManager(); + + Setting::Handle _mode; +}; + +#endif // hifi_DiscoverabilityManager_h \ No newline at end of file diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.cpp b/interface/src/scripting/GlobalServicesScriptingInterface.cpp index 478b708e53..d39da47e78 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.cpp +++ b/interface/src/scripting/GlobalServicesScriptingInterface.cpp @@ -11,6 +11,7 @@ #include "AccountManager.h" #include "Application.h" +#include "DiscoverabilityManager.h" #include "ResourceCache.h" #include "GlobalServicesScriptingInterface.h" @@ -36,7 +37,7 @@ GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance( return &sharedInstance; } -QString GlobalServicesScriptingInterface::getMyUsername() { +const QString& GlobalServicesScriptingInterface::getUsername() const { return AccountManager::getInstance().getAccountInfo().getUsername(); } @@ -44,6 +45,32 @@ void GlobalServicesScriptingInterface::loggedOut() { emit GlobalServicesScriptingInterface::disconnected(QString("logout")); } +QString GlobalServicesScriptingInterface::getFindableBy() const { + auto discoverabilityManager = DependencyManager::get(); + + if (discoverabilityManager->getDiscoverabilityMode() == Discoverability::None) { + return "none"; + } else if (discoverabilityManager->getDiscoverabilityMode() == Discoverability::Friends) { + return "friends"; + } else { + return "all"; + } +} + +void GlobalServicesScriptingInterface::setFindableBy(const QString& discoverabilityMode) { + auto discoverabilityManager = DependencyManager::get(); + + if (discoverabilityMode.toLower() == "none") { + discoverabilityManager->setDiscoverabilityMode(Discoverability::None); + } else if (discoverabilityMode.toLower() == "friends") { + discoverabilityManager->setDiscoverabilityMode(Discoverability::Friends); + } else if (discoverabilityMode.toLower() == "all") { + discoverabilityManager->setDiscoverabilityMode(Discoverability::All); + } else { + qDebug() << "GlobalServices setFindableBy called with an unrecognized value. Did not change discoverability."; + } +} + DownloadInfoResult::DownloadInfoResult() : downloading(QList()), pending(0.0f) diff --git a/interface/src/scripting/GlobalServicesScriptingInterface.h b/interface/src/scripting/GlobalServicesScriptingInterface.h index a71446a970..a39219ba40 100644 --- a/interface/src/scripting/GlobalServicesScriptingInterface.h +++ b/interface/src/scripting/GlobalServicesScriptingInterface.h @@ -31,16 +31,16 @@ Q_DECLARE_METATYPE(DownloadInfoResult) QScriptValue DownloadInfoResultToScriptValue(QScriptEngine* engine, const DownloadInfoResult& result); void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoResult& result); - class GlobalServicesScriptingInterface : public QObject { Q_OBJECT - Q_PROPERTY(QString myUsername READ getMyUsername) - GlobalServicesScriptingInterface(); - ~GlobalServicesScriptingInterface(); + + Q_PROPERTY(QString username READ getUsername) + Q_PROPERTY(QString findableBy READ getFindableBy WRITE setFindableBy) + public: static GlobalServicesScriptingInterface* getInstance(); - QString getMyUsername(); + const QString& getUsername() const; public slots: DownloadInfoResult getDownloadInfo(); @@ -49,16 +49,20 @@ public slots: private slots: void loggedOut(); void checkDownloadInfo(); + + QString getFindableBy() const; + void setFindableBy(const QString& discoverabilityMode); signals: void connected(); void disconnected(const QString& reason); - void incomingMessage(const QString& username, const QString& message); - void onlineUsersChanged(const QStringList& usernames); void myUsernameChanged(const QString& username); void downloadInfoChanged(DownloadInfoResult info); private: + GlobalServicesScriptingInterface(); + ~GlobalServicesScriptingInterface(); + bool _downloading; };