History

centralize path creation from position and orientation to AddressManager

Stephen Birarda committed 12 years ago

Commit b56ea5c1 parent 23a0ef210 files · +187 −223Browse files

Showing the changes to interface/src/Application.cpp (1 of 10 files). Show all

Unified · Split

interface/src/Application.cpp+39−26
@@ -84,7 +84,6 @@ · 83 unmodified lines
8484 #include "scripting/MenuScriptingInterface.h"
8585 #include "scripting/SettingsScriptingInterface.h"
8686 #include "scripting/WindowScriptingInterface.h"
87−#include "scripting/LocationScriptingInterface.h"
8887
8988 #include "ui/InfoView.h"
9089 #include "ui/OAuthWebViewHandler.h"
@@ -408,7 +407,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 317 unmodified lines
408407 _runningScriptsWidget, &RunningScriptsWidget::setBoundary);
409408
410409 // connect to the domainChangeRequired signal on AddressManager
411− connect(&AddressManager::getInstance(), &AddressManager::domainChangeRequired, this, &Application::changeDomainHostname);
410+ connect(&AddressManager::getInstance(), &AddressManager::possibleDomainChangeRequired,
411+ this, &Application::changeDomainHostname);
412412
413413 //When -url in command line, teleport to location
414414 urlGoTo(argc, constArgv);
@@ -811,7 +811,7 @@ bool Application::event(QEvent* event) { · 396 unmodified lines
811811 // handle custom URL
812812 if (event->type() == QEvent::FileOpen) {
813813 QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
814− bool isHifiSchemeURL = !fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(CUSTOM_URL_SCHEME);
814+ bool isHifiSchemeURL = !fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(HIFI_URL_SCHEME);
815815 if (isHifiSchemeURL) {
816816 // Menu::getInstance()->goToURL(fileEvent->url().toLocalFile());
817817 }
@@ -3376,31 +3376,44 @@ void Application::updateWindowTitle(){ · 2558 unmodified lines
33763376 void Application::updateLocationInServer() {
33773377
33783378 AccountManager& accountManager = AccountManager::getInstance();
3379−
3380− if (accountManager.isLoggedIn()) {
3379+ const QUuid& domainUUID = NodeList::getInstance()->getDomainHandler().getUUID();
3380+
3381+ if (accountManager.isLoggedIn() && !domainUUID.isNull()) {
33813382
33823383 // construct a QJsonObject given the user's current address information
3383− QJsonObject updatedLocationObject;
3384+ QJsonObject rootObject;
33843385
3385− QJsonObject addressObject;
3386− addressObject.insert("position", QString(createByteArray(_myAvatar->getPosition())));
3387− addressObject.insert("orientation", QString(createByteArray(glm::degrees(safeEulerAngles(_myAvatar->getOrientation())))));
3388− addressObject.insert("domain", NodeList::getInstance()->getDomainHandler().getHostname());
3386+ QJsonObject locationObject;
3387+
3388+ QString pathString = AddressManager::pathForPositionAndOrientation(_myAvatar->getPosition(),
3389+ true,
3390+ _myAvatar->getOrientation());
3391+
3392+ const QString LOCATION_KEY_IN_ROOT = "location";
3393+ const QString PATH_KEY_IN_LOCATION = "path";
3394+ const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
3395+
3396+ locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
3397+ locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, domainUUID.toString());
33893398
3390− updatedLocationObject.insert("address", addressObject);
3399+ rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
33913400
3392− accountManager.authenticatedRequest("/api/v1/users/address", QNetworkAccessManager::PutOperation,
3393− JSONCallbackParameters(), QJsonDocument(updatedLocationObject).toJson());
3401+ accountManager.authenticatedRequest("/api/v1/users/location", QNetworkAccessManager::PutOperation,
3402+ JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
33943403 }
33953404 }
33963405
33973406 void Application::changeDomainHostname(const QString &newDomainHostname) {
3398− // tell the MyAvatar object to send a kill packet so that it dissapears from its old avatar mixer immediately
3399− _myAvatar->sendKillAvatar();
3407+ NodeList* nodeList = NodeList::getInstance();
34003408
3401− // call the domain hostname change as a queued connection on the nodelist
3402− QMetaObject::invokeMethod(&NodeList::getInstance()->getDomainHandler(), "setHostname",
3403− Q_ARG(const QString&, newDomainHostname));
3409+ if (!nodeList->getDomainHandler().isCurrentHostname(newDomainHostname)) {
3410+ // tell the MyAvatar object to send a kill packet so that it dissapears from its old avatar mixer immediately
3411+ _myAvatar->sendKillAvatar();
3412+
3413+ // call the domain hostname change as a queued connection on the nodelist
3414+ QMetaObject::invokeMethod(&NodeList::getInstance()->getDomainHandler(), "setHostname",
3415+ Q_ARG(const QString&, newDomainHostname));
3416+ }
34043417 }
34053418
34063419 void Application::domainChanged(const QString& domainHostname) {
@@ -3785,12 +3798,12 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 378 unmodified lines
37853798 scriptEngine->registerGlobalObject("Overlays", &_overlays);
37863799
37873800 QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
3788− scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
3789− LocationScriptingInterface::locationSetter, windowValue);
3790−
3791− // register `location` on the global object.
3792− scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
3793− LocationScriptingInterface::locationSetter);
3801+// scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
3802+// LocationScriptingInterface::locationSetter, windowValue);
3803+//
3804+// // register `location` on the global object.
3805+// scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
3806+// LocationScriptingInterface::locationSetter);
37943807
37953808 scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
37963809 scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
@@ -4111,8 +4124,8 @@ void Application::takeSnapshot() { · 314 unmodified lines
41114124 void Application::urlGoTo(int argc, const char * constArgv[]) {
41124125 //Gets the url (hifi://domain/destination/orientation)
41134126 QString customUrl = getCmdOption(argc, constArgv, "-url");
4114− if(customUrl.startsWith(CUSTOM_URL_SCHEME + "//")) {
4115− QStringList urlParts = customUrl.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts);
4127+ if(customUrl.startsWith(HIFI_URL_SCHEME + "//")) {
4128+ QStringList urlParts = customUrl.remove(0, HIFI_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts);
41164129 if (urlParts.count() == 1) {
41174130 // location coordinates or place name
41184131 QString domain = urlParts[0];

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t