mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 15:24:03 +02:00
Merge pull request #4402 from birarda/master
add underlying controls for user discoverability
This commit is contained in:
commit
a758ccd75a
7 changed files with 178 additions and 51 deletions
|
@ -86,7 +86,7 @@ keyboard.onKeyRelease = function(event) {
|
||||||
|
|
||||||
var textLines = textText.split("\n");
|
var textLines = textText.split("\n");
|
||||||
var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width;
|
var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width;
|
||||||
var usernameLine = "--" + GlobalServices.myUsername;
|
var usernameLine = "--" + GlobalServices.username;
|
||||||
var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width;
|
var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width;
|
||||||
if (maxLineWidth < usernameWidth) {
|
if (maxLineWidth < usernameWidth) {
|
||||||
maxLineWidth = usernameWidth;
|
maxLineWidth = usernameWidth;
|
||||||
|
|
|
@ -87,6 +87,7 @@
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "AudioClient.h"
|
#include "AudioClient.h"
|
||||||
|
#include "DiscoverabilityManager.h"
|
||||||
#include "InterfaceVersion.h"
|
#include "InterfaceVersion.h"
|
||||||
#include "LODManager.h"
|
#include "LODManager.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
@ -246,6 +247,7 @@ bool setupEssentials(int& argc, char** argv) {
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||||
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
||||||
#endif
|
#endif
|
||||||
|
auto discoverabilityManager = DependencyManager::set<DiscoverabilityManager>();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -367,11 +369,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
connect(&domainHandler, &DomainHandler::hostnameChanged,
|
connect(&domainHandler, &DomainHandler::hostnameChanged,
|
||||||
DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);
|
DependencyManager::get<AddressManager>().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;
|
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000;
|
||||||
|
|
||||||
locationUpdateTimer = new QTimer(this);
|
locationUpdateTimer = new QTimer(this);
|
||||||
connect(locationUpdateTimer, &QTimer::timeout, this, &Application::updateLocationInServer);
|
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
|
||||||
|
connect(locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
|
||||||
locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
|
locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
|
||||||
|
|
||||||
connect(nodeList.data(), &NodeList::nodeAdded, this, &Application::nodeAdded);
|
connect(nodeList.data(), &NodeList::nodeAdded, this, &Application::nodeAdded);
|
||||||
|
@ -3191,45 +3194,6 @@ void Application::updateWindowTitle(){
|
||||||
_window->setWindowTitle(title);
|
_window->setWindowTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::updateLocationInServer() {
|
|
||||||
|
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
|
||||||
auto addressManager = DependencyManager::get<AddressManager>();
|
|
||||||
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->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() {
|
void Application::clearDomainOctreeDetails() {
|
||||||
qDebug() << "Clearing domain octree details...";
|
qDebug() << "Clearing domain octree details...";
|
||||||
// reset the environment so that we don't erroneously end up with multiple
|
// reset the environment so that we don't erroneously end up with multiple
|
||||||
|
|
|
@ -318,7 +318,6 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
void updateLocationInServer();
|
|
||||||
void nodeAdded(SharedNodePointer node);
|
void nodeAdded(SharedNodePointer node);
|
||||||
void nodeKilled(SharedNodePointer node);
|
void nodeKilled(SharedNodePointer node);
|
||||||
void packetSent(quint64 length);
|
void packetSent(quint64 length);
|
||||||
|
|
88
interface/src/DiscoverabilityManager.cpp
Normal file
88
interface/src/DiscoverabilityManager.cpp
Normal file
|
@ -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 <QtCore/QJsonDocument>
|
||||||
|
|
||||||
|
#include <AccountManager.h>
|
||||||
|
#include <AddressManager.h>
|
||||||
|
#include <DomainHandler.h>
|
||||||
|
#include <NodeList.h>
|
||||||
|
#include <UUID.h>
|
||||||
|
|
||||||
|
#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<AddressManager>();
|
||||||
|
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->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<Discoverability::Mode>(_mode.get()) != discoverabilityMode) {
|
||||||
|
|
||||||
|
// update the setting to the new value
|
||||||
|
_mode.set(static_cast<int>(discoverabilityMode));
|
||||||
|
|
||||||
|
if (static_cast<int>(_mode.get()) == Discoverability::None) {
|
||||||
|
// if we just got set to no discoverability, make sure that we delete our location in DB
|
||||||
|
removeLocation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
interface/src/DiscoverabilityManager.h
Normal file
45
interface/src/DiscoverabilityManager.h
Normal file
|
@ -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 <DependencyManager.h>
|
||||||
|
#include <SettingHandle.h>
|
||||||
|
|
||||||
|
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<Discoverability::Mode>(_mode.get()); }
|
||||||
|
void setDiscoverabilityMode(Discoverability::Mode discoverabilityMode);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DiscoverabilityManager();
|
||||||
|
|
||||||
|
Setting::Handle<int> _mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_DiscoverabilityManager_h
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "AccountManager.h"
|
#include "AccountManager.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "DiscoverabilityManager.h"
|
||||||
#include "ResourceCache.h"
|
#include "ResourceCache.h"
|
||||||
|
|
||||||
#include "GlobalServicesScriptingInterface.h"
|
#include "GlobalServicesScriptingInterface.h"
|
||||||
|
@ -36,7 +37,7 @@ GlobalServicesScriptingInterface* GlobalServicesScriptingInterface::getInstance(
|
||||||
return &sharedInstance;
|
return &sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GlobalServicesScriptingInterface::getMyUsername() {
|
const QString& GlobalServicesScriptingInterface::getUsername() const {
|
||||||
return AccountManager::getInstance().getAccountInfo().getUsername();
|
return AccountManager::getInstance().getAccountInfo().getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +45,32 @@ void GlobalServicesScriptingInterface::loggedOut() {
|
||||||
emit GlobalServicesScriptingInterface::disconnected(QString("logout"));
|
emit GlobalServicesScriptingInterface::disconnected(QString("logout"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GlobalServicesScriptingInterface::getFindableBy() const {
|
||||||
|
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
|
||||||
|
|
||||||
|
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<DiscoverabilityManager>();
|
||||||
|
|
||||||
|
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() :
|
DownloadInfoResult::DownloadInfoResult() :
|
||||||
downloading(QList<float>()),
|
downloading(QList<float>()),
|
||||||
pending(0.0f)
|
pending(0.0f)
|
||||||
|
|
|
@ -31,16 +31,16 @@ Q_DECLARE_METATYPE(DownloadInfoResult)
|
||||||
QScriptValue DownloadInfoResultToScriptValue(QScriptEngine* engine, const DownloadInfoResult& result);
|
QScriptValue DownloadInfoResultToScriptValue(QScriptEngine* engine, const DownloadInfoResult& result);
|
||||||
void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoResult& result);
|
void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoResult& result);
|
||||||
|
|
||||||
|
|
||||||
class GlobalServicesScriptingInterface : public QObject {
|
class GlobalServicesScriptingInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString myUsername READ getMyUsername)
|
|
||||||
GlobalServicesScriptingInterface();
|
Q_PROPERTY(QString username READ getUsername)
|
||||||
~GlobalServicesScriptingInterface();
|
Q_PROPERTY(QString findableBy READ getFindableBy WRITE setFindableBy)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static GlobalServicesScriptingInterface* getInstance();
|
static GlobalServicesScriptingInterface* getInstance();
|
||||||
|
|
||||||
QString getMyUsername();
|
const QString& getUsername() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
DownloadInfoResult getDownloadInfo();
|
DownloadInfoResult getDownloadInfo();
|
||||||
|
@ -49,16 +49,20 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void loggedOut();
|
void loggedOut();
|
||||||
void checkDownloadInfo();
|
void checkDownloadInfo();
|
||||||
|
|
||||||
|
QString getFindableBy() const;
|
||||||
|
void setFindableBy(const QString& discoverabilityMode);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connected();
|
void connected();
|
||||||
void disconnected(const QString& reason);
|
void disconnected(const QString& reason);
|
||||||
void incomingMessage(const QString& username, const QString& message);
|
|
||||||
void onlineUsersChanged(const QStringList& usernames);
|
|
||||||
void myUsernameChanged(const QString& username);
|
void myUsernameChanged(const QString& username);
|
||||||
void downloadInfoChanged(DownloadInfoResult info);
|
void downloadInfoChanged(DownloadInfoResult info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GlobalServicesScriptingInterface();
|
||||||
|
~GlobalServicesScriptingInterface();
|
||||||
|
|
||||||
bool _downloading;
|
bool _downloading;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue