History

Merge pull request #3404 from birarda/data-web-domain-lookup

initial transition to new metaverse API

Brad Hefta-Gaub committed 12 years ago

Commit b209b702 parents fc33de2 b0593bc31 files · +597 −610Browse files

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

Unified · Split

interface/src/Application.cpp+67−64
@@ -51,6 +51,7 @@ · 50 unmodified lines
5151 #include <QMimeData>
5252 #include <QMessageBox>
5353
54+#include <AddressManager.h>
5455 #include <AccountManager.h>
5556 #include <AudioInjector.h>
5657 #include <EntityScriptingInterface.h>
@@ -80,10 +81,10 @@ · 23 unmodified lines
8081 #include "scripting/AccountScriptingInterface.h"
8182 #include "scripting/AudioDeviceScriptingInterface.h"
8283 #include "scripting/ClipboardScriptingInterface.h"
84+#include "scripting/LocationScriptingInterface.h"
8385 #include "scripting/MenuScriptingInterface.h"
8486 #include "scripting/SettingsScriptingInterface.h"
8587 #include "scripting/WindowScriptingInterface.h"
86−#include "scripting/LocationScriptingInterface.h"
8788
8889 #include "ui/InfoView.h"
8990 #include "ui/OAuthWebViewHandler.h"
@@ -358,9 +359,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 268 unmodified lines
358359 Particle::setVoxelEditPacketSender(&_voxelEditSender);
359360 Particle::setParticleEditPacketSender(&_particleEditSender);
360361
361− // when -url in command line, teleport to location
362− urlGoTo(argc, constArgv);
363−
364362 // For now we're going to set the PPS for outbound packets to be super high, this is
365363 // probably not the right long term solution. But for now, we're going to do this to
366364 // allow you to move a particle around in your hand
@@ -405,9 +403,15 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 38 unmodified lines
405403
406404 connect(_window, &MainWindow::windowGeometryChanged,
407405 _runningScriptsWidget, &RunningScriptsWidget::setBoundary);
406+
407+ AddressManager& addressManager = AddressManager::getInstance();
408408
409− //When -url in command line, teleport to location
410− urlGoTo(argc, constArgv);
409+ // connect to the domainChangeRequired signal on AddressManager
410+ connect(&addressManager, &AddressManager::possibleDomainChangeRequired,
411+ this, &Application::changeDomainHostname);
412+
413+ // when -url in command line, teleport to location
414+ addressManager.handleLookupString(getCmdOption(argc, constArgv, "-url"));
411415
412416 // call the OAuthWebviewHandler static getter so that its instance lives in our thread
413417 OAuthWebViewHandler::getInstance();
@@ -807,12 +811,14 @@ bool Application::event(QEvent* event) { · 393 unmodified lines
807811 // handle custom URL
808812 if (event->type() == QEvent::FileOpen) {
809813 QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
810− bool isHifiSchemeURL = !fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(CUSTOM_URL_SCHEME);
811− if (isHifiSchemeURL) {
812− Menu::getInstance()->goToURL(fileEvent->url().toLocalFile());
814+
815+ if (!fileEvent->url().isEmpty()) {
816+ AddressManager::getInstance().handleLookupString(fileEvent->url().toLocalFile());
813817 }
818+
814819 return false;
815820 }
821+
816822 return QApplication::event(event);
817823 }
818824
@@ -912,7 +918,12 @@ void Application::keyPressEvent(QKeyEvent* event) { · 93 unmodified lines
912918
913919 case Qt::Key_Return:
914920 case Qt::Key_Enter:
915− Menu::getInstance()->triggerOption(MenuOption::Chat);
921+ if (isMeta) {
922+ Menu::getInstance()->triggerOption(MenuOption::AddressBar);
923+ } else {
924+ Menu::getInstance()->triggerOption(MenuOption::Chat);
925+ }
926+
916927 break;
917928
918929 case Qt::Key_Up:
@@ -1059,10 +1070,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 140 unmodified lines
10591070 case Qt::Key_Equal:
10601071 _myAvatar->resetSize();
10611072 break;
1062−
1063− case Qt::Key_At:
1064− Menu::getInstance()->goTo();
1065− break;
10661073 default:
10671074 event->ignore();
10681075 break;
@@ -1321,7 +1328,7 @@ void Application::dropEvent(QDropEvent *event) { · 252 unmodified lines
13211328 SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
13221329 if (snapshotData) {
13231330 if (!snapshotData->getDomain().isEmpty()) {
1324− Menu::getInstance()->goToDomain(snapshotData->getDomain());
1331+ changeDomainHostname(snapshotData->getDomain());
13251332 }
13261333
13271334 _myAvatar->setPosition(snapshotData->getLocation());
@@ -3377,31 +3384,53 @@ void Application::updateWindowTitle(){ · 2049 unmodified lines
33773384 #ifndef WIN32
33783385 // crashes with vs2013/win32
33793386 qDebug("Application title set to: %s", title.toStdString().c_str());
3380−#endif //!WIN32
3387+#endif
33813388 _window->setWindowTitle(title);
33823389 }
33833390
33843391 void Application::updateLocationInServer() {
33853392
33863393 AccountManager& accountManager = AccountManager::getInstance();
3387−
3388− if (accountManager.isLoggedIn()) {
3394+ const QUuid& domainUUID = NodeList::getInstance()->getDomainHandler().getUUID();
3395+
3396+ if (accountManager.isLoggedIn() && !domainUUID.isNull()) {
33893397
33903398 // construct a QJsonObject given the user's current address information
3391− QJsonObject updatedLocationObject;
3399+ QJsonObject rootObject;
33923400
3393− QJsonObject addressObject;
3394− addressObject.insert("position", QString(createByteArray(_myAvatar->getPosition())));
3395− addressObject.insert("orientation", QString(createByteArray(glm::degrees(safeEulerAngles(_myAvatar->getOrientation())))));
3396− addressObject.insert("domain", NodeList::getInstance()->getDomainHandler().getHostname());
3401+ QJsonObject locationObject;
3402+
3403+ QString pathString = AddressManager::pathForPositionAndOrientation(_myAvatar->getPosition(),
3404+ true,
3405+ _myAvatar->getOrientation());
3406+
3407+ const QString LOCATION_KEY_IN_ROOT = "location";
3408+ const QString PATH_KEY_IN_LOCATION = "path";
3409+ const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
3410+
3411+ locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
3412+ locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, domainUUID.toString());
33973413
3398− updatedLocationObject.insert("address", addressObject);
3414+ rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
33993415
3400− accountManager.authenticatedRequest("/api/v1/users/address", QNetworkAccessManager::PutOperation,
3401− JSONCallbackParameters(), QJsonDocument(updatedLocationObject).toJson());
3416+ accountManager.authenticatedRequest("/api/v1/users/location", QNetworkAccessManager::PutOperation,
3417+ JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
34023418 }
34033419 }
34043420
3421+void Application::changeDomainHostname(const QString &newDomainHostname) {
3422+ NodeList* nodeList = NodeList::getInstance();
3423+
3424+ if (!nodeList->getDomainHandler().isCurrentHostname(newDomainHostname)) {
3425+ // tell the MyAvatar object to send a kill packet so that it dissapears from its old avatar mixer immediately
3426+ _myAvatar->sendKillAvatar();
3427+
3428+ // call the domain hostname change as a queued connection on the nodelist
3429+ QMetaObject::invokeMethod(&NodeList::getInstance()->getDomainHandler(), "setHostname",
3430+ Q_ARG(const QString&, newDomainHostname));
3431+ }
3432+}
3433+
34053434 void Application::domainChanged(const QString& domainHostname) {
34063435 updateWindowTitle();
34073436
@@ -3785,12 +3814,11 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 377 unmodified lines
37853814
37863815 QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
37873816 scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
3788− LocationScriptingInterface::locationSetter, windowValue);
3789−
3817+ LocationScriptingInterface::locationSetter, windowValue);
37903818 // register `location` on the global object.
37913819 scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
3792− LocationScriptingInterface::locationSetter);
3793−
3820+ LocationScriptingInterface::locationSetter);
3821+
37943822 scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
37953823 scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
37963824 scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
@@ -3918,6 +3946,15 @@ void Application::uploadAttachment() { · 121 unmodified lines
39183946 uploadModel(ATTACHMENT_MODEL);
39193947 }
39203948
3949+void Application::openUrl(const QUrl& url) {
3950+ if (url.scheme() == HIFI_URL_SCHEME) {
3951+ AddressManager::getInstance().handleLookupString(url.toString());
3952+ } else {
3953+ // address manager did not handle - ask QDesktopServices to handle
3954+ QDesktopServices::openUrl(url);
3955+ }
3956+}
3957+
39213958 void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) {
39223959
39233960 // from the domain-handler, figure out the satoshi cost per voxel and per meter cubed
@@ -4114,37 +4151,3 @@ void Application::takeSnapshot() { · 190 unmodified lines
41144151 }
41154152 _snapshotShareDialog->show();
41164153 }
4117−
4118−void Application::urlGoTo(int argc, const char * constArgv[]) {
4119− //Gets the url (hifi://domain/destination/orientation)
4120− QString customUrl = getCmdOption(argc, constArgv, "-url");
4121− if(customUrl.startsWith(CUSTOM_URL_SCHEME + "//")) {
4122− QStringList urlParts = customUrl.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts);
4123− if (urlParts.count() == 1) {
4124− // location coordinates or place name
4125− QString domain = urlParts[0];
4126− Menu::goToDomain(domain);
4127− } else if (urlParts.count() > 1) {
4128− // if url has 2 or more parts, the first one is domain name
4129− QString domain = urlParts[0];
4130−
4131− // second part is either a destination coordinate or
4132− // a place name
4133− QString destination = urlParts[1];
4134−
4135− // any third part is an avatar orientation.
4136− QString orientation = urlParts.count() > 2 ? urlParts[2] : QString();
4137−
4138− Menu::goToDomain(domain);
4139−
4140− // goto either @user, #place, or x-xx,y-yy,z-zz
4141− // style co-ordinate.
4142− Menu::goTo(destination);
4143−
4144− if (!orientation.isEmpty()) {
4145− // location orientation
4146− Menu::goToOrientation(orientation);
4147− }
4148− }
4149− }
4150−}

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