History

Custom URL handler

stojce committed 12 years ago

Commit b05967a1 parent 7fc66394 files · +57 −49Browse files

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

Unified · Split

interface/src/Menu.cpp+36−48
@@ -913,6 +913,39 @@ void Menu::goToDomain() { · 912 unmodified lines
913913 sendFakeEnterEvent();
914914 }
915915
916+bool Menu::goToDestination(QString destination) {
917+
918+ QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts);
919+
920+ const int NUMBER_OF_COORDINATE_ITEMS = 3;
921+ const int X_ITEM = 0;
922+ const int Y_ITEM = 1;
923+ const int Z_ITEM = 2;
924+ if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
925+
926+ double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble();
927+ double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble();
928+ double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble();
929+
930+ glm::vec3 newAvatarPos(x, y, z);
931+
932+ MyAvatar* myAvatar = Application::getInstance()->getAvatar();
933+ glm::vec3 avatarPos = myAvatar->getPosition();
934+ if (newAvatarPos != avatarPos) {
935+ // send a node kill request, indicating to other clients that they should play the "disappeared" effect
936+ MyAvatar::sendKillAvatar();
937+
938+ qDebug("Going To Location: %f, %f, %f...", x, y, z);
939+ myAvatar->setPosition(newAvatarPos);
940+ }
941+
942+ return true;
943+ }
944+
945+ // no coordinates were parsed
946+ return false;
947+}
948+
916949 void Menu::goTo() {
917950
918951 QInputDialog gotoDialog(Application::getInstance()->getWindow());
@@ -928,31 +961,8 @@ void Menu::goTo() { · 9 unmodified lines
928961
929962 destination = gotoDialog.textValue();
930963
931− QStringList coordinateItems = destination.split(QRegExp("_|,"), QString::SkipEmptyParts);
932−
933− const int NUMBER_OF_COORDINATE_ITEMS = 3;
934− const int X_ITEM = 0;
935− const int Y_ITEM = 1;
936− const int Z_ITEM = 2;
937− if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
938−
939− double x = replaceLastOccurrence('-', '.', coordinateItems[X_ITEM].trimmed()).toDouble();
940− double y = replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM].trimmed()).toDouble();
941− double z = replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM].trimmed()).toDouble();
942−
943− glm::vec3 newAvatarPos(x, y, z);
944−
945− MyAvatar* myAvatar = Application::getInstance()->getAvatar();
946− glm::vec3 avatarPos = myAvatar->getPosition();
947− if (newAvatarPos != avatarPos) {
948− // send a node kill request, indicating to other clients that they should play the "disappeared" effect
949− MyAvatar::sendKillAvatar();
950−
951− qDebug("Going To Location: %f, %f, %f...", x, y, z);
952− myAvatar->setPosition(newAvatarPos);
953− }
954−
955− } else {
964+ // go to coordinate destination or to Username
965+ if (!goToDestination(destination)) {
956966 // there's a username entered by the user, make a request to the data-server
957967 DataServerClient::getValuesForKeysAndUserString(
958968 QStringList()
@@ -983,29 +993,7 @@ void Menu::goToLocation() { · 24 unmodified lines
983993
984994 int dialogReturn = coordinateDialog.exec();
985995 if (dialogReturn == QDialog::Accepted && !coordinateDialog.textValue().isEmpty()) {
986− QByteArray newCoordinates;
987−
988− QString delimiterPattern(",");
989− QStringList coordinateItems = coordinateDialog.textValue().split(delimiterPattern);
990−
991− const int NUMBER_OF_COORDINATE_ITEMS = 3;
992− const int X_ITEM = 0;
993− const int Y_ITEM = 1;
994− const int Z_ITEM = 2;
995− if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
996− double x = coordinateItems[X_ITEM].toDouble();
997− double y = coordinateItems[Y_ITEM].toDouble();
998− double z = coordinateItems[Z_ITEM].toDouble();
999− glm::vec3 newAvatarPos(x, y, z);
1000−
1001− if (newAvatarPos != avatarPos) {
1002− // send a node kill request, indicating to other clients that they should play the "disappeared" effect
1003− MyAvatar::sendKillAvatar();
1004−
1005− qDebug("Going To Location: %f, %f, %f...", x, y, z);
1006− myAvatar->setPosition(newAvatarPos);
1007− }
1008− }
996+ goToDestination(coordinateDialog.textValue());
1009997 }
1010998
1011999 sendFakeEnterEvent();