From ff51b22bfeb2a95da2a3f76e464ed128f00c8136 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 30 Apr 2014 09:39:48 -0700 Subject: [PATCH] Add Menu::goToUrl --- interface/src/Menu.cpp | 70 ++++++++++++++++++++++-------------------- interface/src/Menu.h | 1 + 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 44117df55c..ca969832b3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -927,44 +927,48 @@ void Menu::goTo() { int dialogReturn = gotoDialog.exec(); if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) { QString desiredDestination = gotoDialog.textValue(); - - if (desiredDestination.startsWith(CUSTOM_URL_SCHEME + "//")) { - QStringList urlParts = desiredDestination.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts); - - if (urlParts.count() > 1) { - // if url has 2 or more parts, the first one is domain name - QString domain = urlParts[0]; - - // second part is either a destination coordinate or - // a place name - QString destination = urlParts[1]; - - // any third part is an avatar orientation. - QString orientation = urlParts.count() > 2 ? urlParts[2] : QString(); - - goToDomain(domain); - - // goto either @user, #place, or x-xx,y-yy,z-zz - // style co-ordinate. - goTo(destination); - - if (!orientation.isEmpty()) { - // location orientation - goToOrientation(orientation); - } - } else if (urlParts.count() == 1) { - // location coordinates or place name - QString destination = urlParts[0]; - goTo(destination); - } - - } else { - goToUser(gotoDialog.textValue()); + if (!goToURL(desiredDestination)) {; + goTo(desiredDestination); } } sendFakeEnterEvent(); } +bool Menu::goToURL(QString location) { + if (location.startsWith(CUSTOM_URL_SCHEME + "//")) { + QStringList urlParts = location.remove(0, CUSTOM_URL_SCHEME.length() + 2).split('/', QString::SkipEmptyParts); + + if (urlParts.count() > 1) { + // if url has 2 or more parts, the first one is domain name + QString domain = urlParts[0]; + + // second part is either a destination coordinate or + // a place name + QString destination = urlParts[1]; + + // any third part is an avatar orientation. + QString orientation = urlParts.count() > 2 ? urlParts[2] : QString(); + + goToDomain(domain); + + // goto either @user, #place, or x-xx,y-yy,z-zz + // style co-ordinate. + goTo(destination); + + if (!orientation.isEmpty()) { + // location orientation + goToOrientation(orientation); + } + } else if (urlParts.count() == 1) { + // location coordinates or place name + QString destination = urlParts[0]; + goTo(destination); + } + return true; + } + return false; +} + void Menu::goToUser(const QString& user) { LocationManager* manager = &LocationManager::getInstance(); manager->goTo(user); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index bc70f8f83f..c2f4937dc2 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -152,6 +152,7 @@ public slots: void importSettings(); void exportSettings(); void goTo(); + bool goToURL(QString location); void goToUser(const QString& user); void pasteToVoxel(); void openUrl(const QUrl& url);