initial transition to new metaverse API
Showing the changes to interface/src/Application.cpp (1 of 31 files). Show all
Unified · Split
| @@ -51,6 +51,7 @@ · 50 unmodified lines | ||
| 51 | 51 | #include <QMimeData> |
| 52 | 52 | #include <QMessageBox> |
| 53 | 53 | |
| 54 | +#include <AddressManager.h> | |
| 54 | 55 | #include <AccountManager.h> |
| 55 | 56 | #include <AudioInjector.h> |
| 56 | 57 | #include <EntityScriptingInterface.h> |
| @@ -80,10 +81,10 @@ · 23 unmodified lines | ||
| 80 | 81 | #include "scripting/AccountScriptingInterface.h" |
| 81 | 82 | #include "scripting/AudioDeviceScriptingInterface.h" |
| 82 | 83 | #include "scripting/ClipboardScriptingInterface.h" |
| 84 | +#include "scripting/LocationScriptingInterface.h" | |
| 83 | 85 | #include "scripting/MenuScriptingInterface.h" |
| 84 | 86 | #include "scripting/SettingsScriptingInterface.h" |
| 85 | 87 | #include "scripting/WindowScriptingInterface.h" |
| 86 | −#include "scripting/LocationScriptingInterface.h" | |
| 87 | 88 | |
| 88 | 89 | #include "ui/InfoView.h" |
| 89 | 90 | #include "ui/OAuthWebViewHandler.h" |
| @@ -358,9 +359,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 268 unmodified lines | ||
| 358 | 359 | Particle::setVoxelEditPacketSender(&_voxelEditSender); |
| 359 | 360 | Particle::setParticleEditPacketSender(&_particleEditSender); |
| 360 | 361 | |
| 361 | − // when -url in command line, teleport to location | |
| 362 | − urlGoTo(argc, constArgv); | |
| 363 | − | |
| 364 | 362 | // For now we're going to set the PPS for outbound packets to be super high, this is |
| 365 | 363 | // probably not the right long term solution. But for now, we're going to do this to |
| 366 | 364 | // 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 | ||
| 405 | 403 | |
| 406 | 404 | connect(_window, &MainWindow::windowGeometryChanged, |
| 407 | 405 | _runningScriptsWidget, &RunningScriptsWidget::setBoundary); |
| 406 | + | |
| 407 | + AddressManager& addressManager = AddressManager::getInstance(); | |
| 408 | 408 | |
| 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")); | |
| 411 | 415 | |
| 412 | 416 | // call the OAuthWebviewHandler static getter so that its instance lives in our thread |
| 413 | 417 | OAuthWebViewHandler::getInstance(); |
| @@ -807,12 +811,14 @@ bool Application::event(QEvent* event) { · 393 unmodified lines | ||
| 807 | 811 | // handle custom URL |
| 808 | 812 | if (event->type() == QEvent::FileOpen) { |
| 809 | 813 | 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()); | |
| 813 | 817 | } |
| 818 | + | |
| 814 | 819 | return false; |
| 815 | 820 | } |
| 821 | + | |
| 816 | 822 | return QApplication::event(event); |
| 817 | 823 | } |
| 818 | 824 | |
| @@ -912,7 +918,12 @@ void Application::keyPressEvent(QKeyEvent* event) { · 93 unmodified lines | ||
| 912 | 918 | |
| 913 | 919 | case Qt::Key_Return: |
| 914 | 920 | 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 | + | |
| 916 | 927 | break; |
| 917 | 928 | |
| 918 | 929 | case Qt::Key_Up: |
| @@ -1059,10 +1070,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 140 unmodified lines | ||
| 1059 | 1070 | case Qt::Key_Equal: |
| 1060 | 1071 | _myAvatar->resetSize(); |
| 1061 | 1072 | break; |
| 1062 | − | |
| 1063 | − case Qt::Key_At: | |
| 1064 | − Menu::getInstance()->goTo(); | |
| 1065 | − break; | |
| 1066 | 1073 | default: |
| 1067 | 1074 | event->ignore(); |
| 1068 | 1075 | break; |
| @@ -1321,7 +1328,7 @@ void Application::dropEvent(QDropEvent *event) { · 252 unmodified lines | ||
| 1321 | 1328 | SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); |
| 1322 | 1329 | if (snapshotData) { |
| 1323 | 1330 | if (!snapshotData->getDomain().isEmpty()) { |
| 1324 | − Menu::getInstance()->goToDomain(snapshotData->getDomain()); | |
| 1331 | + changeDomainHostname(snapshotData->getDomain()); | |
| 1325 | 1332 | } |
| 1326 | 1333 | |
| 1327 | 1334 | _myAvatar->setPosition(snapshotData->getLocation()); |
| @@ -3377,31 +3384,53 @@ void Application::updateWindowTitle(){ · 2049 unmodified lines | ||
| 3377 | 3384 | #ifndef WIN32 |
| 3378 | 3385 | // crashes with vs2013/win32 |
| 3379 | 3386 | qDebug("Application title set to: %s", title.toStdString().c_str()); |
| 3380 | −#endif //!WIN32 | |
| 3387 | +#endif | |
| 3381 | 3388 | _window->setWindowTitle(title); |
| 3382 | 3389 | } |
| 3383 | 3390 | |
| 3384 | 3391 | void Application::updateLocationInServer() { |
| 3385 | 3392 | |
| 3386 | 3393 | AccountManager& accountManager = AccountManager::getInstance(); |
| 3387 | − | |
| 3388 | − if (accountManager.isLoggedIn()) { | |
| 3394 | + const QUuid& domainUUID = NodeList::getInstance()->getDomainHandler().getUUID(); | |
| 3395 | + | |
| 3396 | + if (accountManager.isLoggedIn() && !domainUUID.isNull()) { | |
| 3389 | 3397 | |
| 3390 | 3398 | // construct a QJsonObject given the user's current address information |
| 3391 | − QJsonObject updatedLocationObject; | |
| 3399 | + QJsonObject rootObject; | |
| 3392 | 3400 | |
| 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()); | |
| 3397 | 3413 | |
| 3398 | − updatedLocationObject.insert("address", addressObject); | |
| 3414 | + rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); | |
| 3399 | 3415 | |
| 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()); | |
| 3402 | 3418 | } |
| 3403 | 3419 | } |
| 3404 | 3420 | |
| 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 | + | |
| 3405 | 3434 | void Application::domainChanged(const QString& domainHostname) { |
| 3406 | 3435 | updateWindowTitle(); |
| 3407 | 3436 | |
| @@ -3785,12 +3814,11 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 377 unmodified lines | ||
| 3785 | 3814 | |
| 3786 | 3815 | QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance()); |
| 3787 | 3816 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 3788 | − LocationScriptingInterface::locationSetter, windowValue); | |
| 3789 | − | |
| 3817 | + LocationScriptingInterface::locationSetter, windowValue); | |
| 3790 | 3818 | // register `location` on the global object. |
| 3791 | 3819 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 3792 | − LocationScriptingInterface::locationSetter); | |
| 3793 | − | |
| 3820 | + LocationScriptingInterface::locationSetter); | |
| 3821 | + | |
| 3794 | 3822 | scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); |
| 3795 | 3823 | scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); |
| 3796 | 3824 | scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); |
| @@ -3918,6 +3946,15 @@ void Application::uploadAttachment() { · 121 unmodified lines | ||
| 3918 | 3946 | uploadModel(ATTACHMENT_MODEL); |
| 3919 | 3947 | } |
| 3920 | 3948 | |
| 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 | + | |
| 3921 | 3958 | void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) { |
| 3922 | 3959 | |
| 3923 | 3960 | // 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 | ||
| 4114 | 4151 | } |
| 4115 | 4152 | _snapshotShareDialog->show(); |
| 4116 | 4153 | } |
| 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 | −} | |