Showing the changes to interface/src/Application.cpp (1 of 72 files). Show all
Unified · Split
| @@ -51,6 +51,7 @@ · 50 unmodified lines | |||
| 51 | #include <QMimeData> | 51 | #include <QMimeData> |
| 52 | #include <QMessageBox> | 52 | #include <QMessageBox> |
| 53 | 53 | ||
| 54 | #include <AddressManager.h> | ||
| 54 | #include <AccountManager.h> | 55 | #include <AccountManager.h> |
| 55 | #include <AudioInjector.h> | 56 | #include <AudioInjector.h> |
| 56 | #include <EntityScriptingInterface.h> | 57 | #include <EntityScriptingInterface.h> |
| @@ -80,10 +81,10 @@ · 23 unmodified lines | |||
| 80 | #include "scripting/AccountScriptingInterface.h" | 81 | #include "scripting/AccountScriptingInterface.h" |
| 81 | #include "scripting/AudioDeviceScriptingInterface.h" | 82 | #include "scripting/AudioDeviceScriptingInterface.h" |
| 82 | #include "scripting/ClipboardScriptingInterface.h" | 83 | #include "scripting/ClipboardScriptingInterface.h" |
| 84 | #include "scripting/LocationScriptingInterface.h" | ||
| 83 | #include "scripting/MenuScriptingInterface.h" | 85 | #include "scripting/MenuScriptingInterface.h" |
| 84 | #include "scripting/SettingsScriptingInterface.h" | 86 | #include "scripting/SettingsScriptingInterface.h" |
| 85 | #include "scripting/WindowScriptingInterface.h" | 87 | #include "scripting/WindowScriptingInterface.h" |
| 86 | #include "scripting/LocationScriptingInterface.h" | ||
| 87 | 88 | ||
| 88 | #include "ui/InfoView.h" | 89 | #include "ui/InfoView.h" |
| 89 | #include "ui/OAuthWebViewHandler.h" | 90 | #include "ui/OAuthWebViewHandler.h" |
| @@ -358,9 +359,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 268 unmodified lines | |||
| 358 | Particle::setVoxelEditPacketSender(&_voxelEditSender); | 359 | Particle::setVoxelEditPacketSender(&_voxelEditSender); |
| 359 | Particle::setParticleEditPacketSender(&_particleEditSender); | 360 | Particle::setParticleEditPacketSender(&_particleEditSender); |
| 360 | 361 | ||
| 361 | // when -url in command line, teleport to location | ||
| 362 | urlGoTo(argc, constArgv); | ||
| 363 | |||
| 364 | // For now we're going to set the PPS for outbound packets to be super high, this is | 362 | // For now we're going to set the PPS for outbound packets to be super high, this is |
| 365 | // probably not the right long term solution. But for now, we're going to do this to | 363 | // probably not the right long term solution. But for now, we're going to do this to |
| 366 | // allow you to move a particle around in your hand | 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 | connect(_window, &MainWindow::windowGeometryChanged, | 404 | connect(_window, &MainWindow::windowGeometryChanged, |
| 407 | _runningScriptsWidget, &RunningScriptsWidget::setBoundary); | 405 | _runningScriptsWidget, &RunningScriptsWidget::setBoundary); |
| 406 | |||
| 407 | AddressManager& addressManager = AddressManager::getInstance(); | ||
| 408 | 408 | ||
| 409 | //When -url in command line, teleport to location | 409 | // connect to the domainChangeRequired signal on AddressManager |
| 410 | urlGoTo(argc, constArgv); | 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 | // call the OAuthWebviewHandler static getter so that its instance lives in our thread | 416 | // call the OAuthWebviewHandler static getter so that its instance lives in our thread |
| 413 | OAuthWebViewHandler::getInstance(); | 417 | OAuthWebViewHandler::getInstance(); |
| @@ -807,12 +811,14 @@ bool Application::event(QEvent* event) { · 393 unmodified lines | |||
| 807 | // handle custom URL | 811 | // handle custom URL |
| 808 | if (event->type() == QEvent::FileOpen) { | 812 | if (event->type() == QEvent::FileOpen) { |
| 809 | QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event); | 813 | QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event); |
| 810 | bool isHifiSchemeURL = !fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(CUSTOM_URL_SCHEME); | 814 | |
| 811 | if (isHifiSchemeURL) { | 815 | if (!fileEvent->url().isEmpty()) { |
| 812 | Menu::getInstance()->goToURL(fileEvent->url().toLocalFile()); | 816 | AddressManager::getInstance().handleLookupString(fileEvent->url().toLocalFile()); |
| 813 | } | 817 | } |
| 818 | |||
| 814 | return false; | 819 | return false; |
| 815 | } | 820 | } |
| 821 | |||
| 816 | return QApplication::event(event); | 822 | return QApplication::event(event); |
| 817 | } | 823 | } |
| 818 | 824 | ||
| @@ -912,7 +918,12 @@ void Application::keyPressEvent(QKeyEvent* event) { · 93 unmodified lines | |||
| 912 | 918 | ||
| 913 | case Qt::Key_Return: | 919 | case Qt::Key_Return: |
| 914 | case Qt::Key_Enter: | 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 | break; | 927 | break; |
| 917 | 928 | ||
| 918 | case Qt::Key_Up: | 929 | case Qt::Key_Up: |
| @@ -1059,10 +1070,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 140 unmodified lines | |||
| 1059 | case Qt::Key_Equal: | 1070 | case Qt::Key_Equal: |
| 1060 | _myAvatar->resetSize(); | 1071 | _myAvatar->resetSize(); |
| 1061 | break; | 1072 | break; |
| 1062 | |||
| 1063 | case Qt::Key_At: | ||
| 1064 | Menu::getInstance()->goTo(); | ||
| 1065 | break; | ||
| 1066 | default: | 1073 | default: |
| 1067 | event->ignore(); | 1074 | event->ignore(); |
| 1068 | break; | 1075 | break; |
| @@ -1321,7 +1328,7 @@ void Application::dropEvent(QDropEvent *event) { · 252 unmodified lines | |||
| 1321 | SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); | 1328 | SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath); |
| 1322 | if (snapshotData) { | 1329 | if (snapshotData) { |
| 1323 | if (!snapshotData->getDomain().isEmpty()) { | 1330 | if (!snapshotData->getDomain().isEmpty()) { |
| 1324 | Menu::getInstance()->goToDomain(snapshotData->getDomain()); | 1331 | changeDomainHostname(snapshotData->getDomain()); |
| 1325 | } | 1332 | } |
| 1326 | 1333 | ||
| 1327 | _myAvatar->setPosition(snapshotData->getLocation()); | 1334 | _myAvatar->setPosition(snapshotData->getLocation()); |
| @@ -3387,31 +3394,53 @@ void Application::updateWindowTitle(){ · 2059 unmodified lines | |||
| 3387 | #ifndef WIN32 | 3394 | #ifndef WIN32 |
| 3388 | // crashes with vs2013/win32 | 3395 | // crashes with vs2013/win32 |
| 3389 | qDebug("Application title set to: %s", title.toStdString().c_str()); | 3396 | qDebug("Application title set to: %s", title.toStdString().c_str()); |
| 3390 | #endif //!WIN32 | 3397 | #endif |
| 3391 | _window->setWindowTitle(title); | 3398 | _window->setWindowTitle(title); |
| 3392 | } | 3399 | } |
| 3393 | 3400 | ||
| 3394 | void Application::updateLocationInServer() { | 3401 | void Application::updateLocationInServer() { |
| 3395 | 3402 | ||
| 3396 | AccountManager& accountManager = AccountManager::getInstance(); | 3403 | AccountManager& accountManager = AccountManager::getInstance(); |
| 3397 | 3404 | const QUuid& domainUUID = NodeList::getInstance()->getDomainHandler().getUUID(); | |
| 3398 | if (accountManager.isLoggedIn()) { | 3405 | |
| 3406 | if (accountManager.isLoggedIn() && !domainUUID.isNull()) { | ||
| 3399 | 3407 | ||
| 3400 | // construct a QJsonObject given the user's current address information | 3408 | // construct a QJsonObject given the user's current address information |
| 3401 | QJsonObject updatedLocationObject; | 3409 | QJsonObject rootObject; |
| 3402 | 3410 | ||
| 3403 | QJsonObject addressObject; | 3411 | QJsonObject locationObject; |
| 3404 | addressObject.insert("position", QString(createByteArray(_myAvatar->getPosition()))); | 3412 | |
| 3405 | addressObject.insert("orientation", QString(createByteArray(glm::degrees(safeEulerAngles(_myAvatar->getOrientation()))))); | 3413 | QString pathString = AddressManager::pathForPositionAndOrientation(_myAvatar->getPosition(), |
| 3406 | addressObject.insert("domain", NodeList::getInstance()->getDomainHandler().getHostname()); | 3414 | true, |
| 3415 | _myAvatar->getOrientation()); | ||
| 3416 | |||
| 3417 | const QString LOCATION_KEY_IN_ROOT = "location"; | ||
| 3418 | const QString PATH_KEY_IN_LOCATION = "path"; | ||
| 3419 | const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; | ||
| 3420 | |||
| 3421 | locationObject.insert(PATH_KEY_IN_LOCATION, pathString); | ||
| 3422 | locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, domainUUID.toString()); | ||
| 3407 | 3423 | ||
| 3408 | updatedLocationObject.insert("address", addressObject); | 3424 | rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); |
| 3409 | 3425 | ||
| 3410 | accountManager.authenticatedRequest("/api/v1/users/address", QNetworkAccessManager::PutOperation, | 3426 | accountManager.authenticatedRequest("/api/v1/users/location", QNetworkAccessManager::PutOperation, |
| 3411 | JSONCallbackParameters(), QJsonDocument(updatedLocationObject).toJson()); | 3427 | JSONCallbackParameters(), QJsonDocument(rootObject).toJson()); |
| 3412 | } | 3428 | } |
| 3413 | } | 3429 | } |
| 3414 | 3430 | ||
| 3431 | void Application::changeDomainHostname(const QString &newDomainHostname) { | ||
| 3432 | NodeList* nodeList = NodeList::getInstance(); | ||
| 3433 | |||
| 3434 | if (!nodeList->getDomainHandler().isCurrentHostname(newDomainHostname)) { | ||
| 3435 | // tell the MyAvatar object to send a kill packet so that it dissapears from its old avatar mixer immediately | ||
| 3436 | _myAvatar->sendKillAvatar(); | ||
| 3437 | |||
| 3438 | // call the domain hostname change as a queued connection on the nodelist | ||
| 3439 | QMetaObject::invokeMethod(&NodeList::getInstance()->getDomainHandler(), "setHostname", | ||
| 3440 | Q_ARG(const QString&, newDomainHostname)); | ||
| 3441 | } | ||
| 3442 | } | ||
| 3443 | |||
| 3415 | void Application::domainChanged(const QString& domainHostname) { | 3444 | void Application::domainChanged(const QString& domainHostname) { |
| 3416 | updateWindowTitle(); | 3445 | updateWindowTitle(); |
| 3417 | 3446 | ||
| @@ -3795,12 +3824,11 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 377 unmodified lines | |||
| 3795 | 3824 | ||
| 3796 | QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance()); | 3825 | QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance()); |
| 3797 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, | 3826 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 3798 | LocationScriptingInterface::locationSetter, windowValue); | 3827 | LocationScriptingInterface::locationSetter, windowValue); |
| 3799 | |||
| 3800 | // register `location` on the global object. | 3828 | // register `location` on the global object. |
| 3801 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, | 3829 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 3802 | LocationScriptingInterface::locationSetter); | 3830 | LocationScriptingInterface::locationSetter); |
| 3803 | 3831 | ||
| 3804 | scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); | 3832 | scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); |
| 3805 | scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); | 3833 | scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); |
| 3806 | scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); | 3834 | scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); |
| @@ -3928,6 +3956,15 @@ void Application::uploadAttachment() { · 121 unmodified lines | |||
| 3928 | uploadModel(ATTACHMENT_MODEL); | 3956 | uploadModel(ATTACHMENT_MODEL); |
| 3929 | } | 3957 | } |
| 3930 | 3958 | ||
| 3959 | void Application::openUrl(const QUrl& url) { | ||
| 3960 | if (url.scheme() == HIFI_URL_SCHEME) { | ||
| 3961 | AddressManager::getInstance().handleLookupString(url.toString()); | ||
| 3962 | } else { | ||
| 3963 | // address manager did not handle - ask QDesktopServices to handle | ||
| 3964 | QDesktopServices::openUrl(url); | ||
| 3965 | } | ||
| 3966 | } | ||
| 3967 | |||
| 3931 | void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) { | 3968 | void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) { |
| 3932 | 3969 | ||
| 3933 | // from the domain-handler, figure out the satoshi cost per voxel and per meter cubed | 3970 | // from the domain-handler, figure out the satoshi cost per voxel and per meter cubed |
| @@ -4098,6 +4135,14 @@ void Application::skipVersion(QString latestVersion) { · 164 unmodified lines | |||
| 4098 | skipFile.write(latestVersion.toStdString().c_str()); | 4135 | skipFile.write(latestVersion.toStdString().c_str()); |
| 4099 | } | 4136 | } |
| 4100 | 4137 | ||
| 4138 | void Application::setCursorVisible(bool visible) { | ||
| 4139 | if (visible) { | ||
| 4140 | restoreOverrideCursor(); | ||
| 4141 | } else { | ||
| 4142 | setOverrideCursor(Qt::BlankCursor); | ||
| 4143 | } | ||
| 4144 | } | ||
| 4145 | |||
| 4101 | void Application::takeSnapshot() { | 4146 | void Application::takeSnapshot() { |
| 4102 | QMediaPlayer* player = new QMediaPlayer(); | 4147 | QMediaPlayer* player = new QMediaPlayer(); |
| 4103 | QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav"); | 4148 | QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav"); |
| @@ -4116,37 +4161,3 @@ void Application::takeSnapshot() { · 12 unmodified lines | |||
| 4116 | } | 4161 | } |
| 4117 | _snapshotShareDialog->show(); | 4162 | _snapshotShareDialog->show(); |
| 4118 | } | 4163 | } |
| 4119 | |||
| 4120 | void Application::urlGoTo(int argc, const char * constArgv[]) { | ||
| 4121 | //Gets the url (hifi://domain/destination/orientation) | ||
| 4122 | QString customUrl = getCmdOption(argc, constArgv, "-url"); | ||
| 4123 | if(customUrl.startsWith(CUSTOM_URL_SCHEME + "//")) { | ||
| 4124 | QStringList urlParts = customUrl.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts); | ||
| 4125 | if (urlParts.count() == 1) { | ||
| 4126 | // location coordinates or place name | ||
| 4127 | QString domain = urlParts[0]; | ||
| 4128 | Menu::goToDomain(domain); | ||
| 4129 | } else if (urlParts.count() > 1) { | ||
| 4130 | // if url has 2 or more parts, the first one is domain name | ||
| 4131 | QString domain = urlParts[0]; | ||
| 4132 | |||
| 4133 | // second part is either a destination coordinate or | ||
| 4134 | // a place name | ||
| 4135 | QString destination = urlParts[1]; | ||
| 4136 | |||
| 4137 | // any third part is an avatar orientation. | ||
| 4138 | QString orientation = urlParts.count() > 2 ? urlParts[2] : QString(); | ||
| 4139 | |||
| 4140 | Menu::goToDomain(domain); | ||
| 4141 | |||
| 4142 | // goto either @user, #place, or x-xx,y-yy,z-zz | ||
| 4143 | // style co-ordinate. | ||
| 4144 | Menu::goTo(destination); | ||
| 4145 | |||
| 4146 | if (!orientation.isEmpty()) { | ||
| 4147 | // location orientation | ||
| 4148 | Menu::goToOrientation(orientation); | ||
| 4149 | } | ||
| 4150 | } | ||
| 4151 | } | ||
| 4152 | } | ||