From 29dae39ad78d0e81851ab67853bd581e7debcba4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 12 Sep 2014 15:01:08 -0700 Subject: [PATCH] handle location lookup for offline user or not found --- interface/src/Application.cpp | 12 +++++++----- interface/src/Menu.cpp | 17 ++++++++++++++++- interface/src/Menu.h | 2 ++ libraries/networking/src/AddressManager.cpp | 20 ++++++++++++-------- libraries/networking/src/AddressManager.h | 1 + 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4a328562c7..1e8be6dca2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3947,11 +3947,13 @@ void Application::uploadAttachment() { } void Application::openUrl(const QUrl& url) { - if (url.scheme() == HIFI_URL_SCHEME) { - AddressManager::getInstance().handleLookupString(url.toString()); - } else { - // address manager did not handle - ask QDesktopServices to handle - QDesktopServices::openUrl(url); + if (!url.isEmpty()) { + if (url.scheme() == HIFI_URL_SCHEME) { + AddressManager::getInstance().handleLookupString(url.toString()); + } else { + // address manager did not handle - ask QDesktopServices to handle + QDesktopServices::openUrl(url); + } } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index c39e9abd3d..87290a3e64 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -142,9 +142,14 @@ Menu::Menu() : // call our toggle login function now so the menu option is setup properly toggleLoginMenuItem(); - // connect to the appropriate slots of the AccountManager so that we can change the Login/Logout menu item + // connect to the appropriate signal of the AccountManager so that we can change the Login/Logout menu item connect(&accountManager, &AccountManager::profileChanged, this, &Menu::toggleLoginMenuItem); connect(&accountManager, &AccountManager::logoutComplete, this, &Menu::toggleLoginMenuItem); + + // connect to signal of account manager so we can tell user when the user/place they looked at is offline + AddressManager& addressManager = AddressManager::getInstance(); + connect(&addressManager, &AddressManager::lookupResultIsOffline, this, &Menu::displayAddressOfflineMessage); + connect(&addressManager, &AddressManager::lookupResultIsNotFound, this, &Menu::displayAddressNotFoundMessage); addDisabledActionAndSeparator(fileMenu, "Scripts"); addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog())); @@ -1158,6 +1163,16 @@ void Menu::toggleAddressBar() { sendFakeEnterEvent(); } +void Menu::displayAddressOfflineMessage() { + QMessageBox::information(Application::getInstance()->getWindow(), "Address offline", + "That user or place is currently offline."); +} + +void Menu::displayAddressNotFoundMessage() { + QMessageBox::information(Application::getInstance()->getWindow(), "Address not found", + "There is no address information for that user or place."); +} + void Menu::muteEnvironment() { int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment); int packetSize = headerSize + sizeof(glm::vec3) + sizeof(float); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 307b011f74..b43e7cb75e 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -219,6 +219,8 @@ private slots: void toggleChat(); void audioMuteToggled(); void displayNameLocationResponse(const QString& errorString); + void displayAddressOfflineMessage(); + void displayAddressNotFoundMessage(); void muteEnvironment(); private: diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index f2e9ce64ab..8d35216558 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -59,8 +59,6 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) { // 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ) // 4. domain network address (IP or dns resolvable hostname) - qDebug() << lookupUrl; - if (lookupUrl.isRelative()) { // if this is a relative path then handle it as a relative viewpoint handleRelativeViewpoint(lookupUrl.path()); @@ -86,12 +84,14 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) { } void AddressManager::handleLookupString(const QString& lookupString) { - // we've verified that this is a valid hifi URL - hand it off to handleLookupString - QString sanitizedString = lookupString; - const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive); - sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX); - - handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString)); + if (!lookupString.isEmpty()) { + // make this a valid hifi URL and handle it off to handleUrl + QString sanitizedString = lookupString; + const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive); + sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX); + + handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString)); + } } void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) { @@ -141,6 +141,10 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) { void AddressManager::handleAPIError(QNetworkReply& errorReply) { qDebug() << "AddressManager API error -" << errorReply.error() << "-" << errorReply.errorString(); + + if (errorReply.error() == QNetworkReply::ContentNotFoundError) { + emit lookupResultIsNotFound(); + } } const QString GET_PLACE = "/api/v1/places/%1"; diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index f27fb475c2..e77fed67dc 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -38,6 +38,7 @@ public slots: void goToUser(const QString& username); signals: void lookupResultIsOffline(); + void lookupResultIsNotFound(); void possibleDomainChangeRequired(const QString& newHostname); void locationChangeRequired(const glm::vec3& newPosition, bool hasOrientationChange, const glm::vec3& newOrientation); private: