From 19b8f101d8994bd0f9b4a86a45fd0144ed9bc6eb Mon Sep 17 00:00:00 2001 From: James Brotchie Date: Tue, 1 Apr 2014 11:31:43 +1000 Subject: [PATCH] Improved hifi:// style URL scheme handling. First steps towards implementing #1463. - Moved url parsing code from Application::event to Menu::goTo(QString). - Handle destination component of URL as either a @username, #place, or x-xx,y-yy,z-zz style coordinate. - Added support for entering hifi:// style URL into @ invoked goto menu option. --- interface/interface_en.ts | 8 +++---- interface/src/Application.cpp | 27 ++++------------------ interface/src/Application.h | 1 + interface/src/Menu.cpp | 43 +++++++++++++++++++++++++++++++++-- interface/src/Menu.h | 1 + 5 files changed, 51 insertions(+), 29 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 7c5d1ecbcf..49906379c4 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -4,22 +4,22 @@ Application - + Export Voxels - + Sparse Voxel Octree Files (*.svo) - + Open Script - + JavaScript Files (*.js) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d91e686844..883da9b7bc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -112,8 +112,6 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D const int STATS_PELS_PER_LINE = 20; -const QString CUSTOM_URL_SCHEME = "hifi:"; - void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { if (message.size() > 0) { QString dateString = QDateTime::currentDateTime().toTimeSpec(Qt::LocalTime).toString(Qt::ISODate); @@ -676,30 +674,13 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod } bool Application::event(QEvent* event) { - + // handle custom URL if (event->type() == QEvent::FileOpen) { QFileOpenEvent* fileEvent = static_cast(event); - if (!fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(CUSTOM_URL_SCHEME)) { - QString destination = fileEvent->url().toLocalFile().remove(CUSTOM_URL_SCHEME); - QStringList urlParts = destination.split('/', QString::SkipEmptyParts); - - if (urlParts.count() > 1) { - // if url has 2 or more parts, the first one is domain name - Menu::getInstance()->goToDomain(urlParts[0]); - - // location coordinates - Menu::getInstance()->goToDestination(urlParts[1]); - if (urlParts.count() > 2) { - - // location orientation - Menu::getInstance()->goToOrientation(urlParts[2]); - } - } else if (urlParts.count() == 1) { - - // location coordinates - Menu::getInstance()->goToDestination(urlParts[0]); - } + bool isHifiSchemeURL = !fileEvent->url().isEmpty() && fileEvent->url().toLocalFile().startsWith(CUSTOM_URL_SCHEME); + if (isHifiSchemeURL) { + Menu::getInstance()->goTo(fileEvent->url().toString()); } return false; diff --git a/interface/src/Application.h b/interface/src/Application.h index bab7578ca4..a0b81a740e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -93,6 +93,7 @@ static const float NODE_KILLED_GREEN = 0.0f; static const float NODE_KILLED_BLUE = 0.0f; static const QString SNAPSHOT_EXTENSION = ".jpg"; +static const QString CUSTOM_URL_SCHEME = "hifi:"; static const float BILLBOARD_FIELD_OF_VIEW = 30.0f; // degrees static const float BILLBOARD_DISTANCE = 5.0f; // meters diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ec20401fef..31471ce60b 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -912,19 +912,58 @@ bool Menu::goToDestination(QString destination) { return LocationManager::getInstance().goToDestination(destination); } +void Menu::goTo(QString destination) { + LocationManager::getInstance().goTo(destination); +} + void Menu::goTo() { QInputDialog gotoDialog(Application::getInstance()->getWindow()); gotoDialog.setWindowTitle("Go to"); - gotoDialog.setLabelText("Destination:"); + gotoDialog.setLabelText("Destination or URL:\n @user, #place, hifi://domain/location/orientation"); QString destination = QString(); + gotoDialog.setTextValue(destination); gotoDialog.setWindowFlags(Qt::Sheet); gotoDialog.resize(gotoDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, gotoDialog.size().height()); int dialogReturn = gotoDialog.exec(); if (dialogReturn == QDialog::Accepted && !gotoDialog.textValue().isEmpty()) { - goToUser(gotoDialog.textValue()); + 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()); + } } sendFakeEnterEvent(); } diff --git a/interface/src/Menu.h b/interface/src/Menu.h index c7c4c6ecea..f31803e65d 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -110,6 +110,7 @@ public: bool goToDestination(QString destination); void goToOrientation(QString orientation); void goToDomain(const QString newDomain); + void goTo(QString destination); public slots: