From fbe784155eaf07a73da222584bee9371d19a7c78 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 Aug 2016 11:18:42 -0700 Subject: [PATCH] add a shareable address return to address manager --- interface/src/DiscoverabilityManager.cpp | 2 +- libraries/networking/src/AddressManager.cpp | 32 +++++++++++++++++---- libraries/networking/src/AddressManager.h | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index dd80dadca7..9b61770a3e 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -111,7 +111,7 @@ void DiscoverabilityManager::updateLocation() { } // Update Steam - SteamClient::updateLocation(domainHandler.getHostname(), addressManager->currentFacingAddress()); + SteamClient::updateLocation(domainHandler.getHostname(), addressManager->currentShareableAddress()); } void DiscoverabilityManager::handleHeartbeatResponse(QNetworkReply& requestReply) { diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index b2f1fc39b5..c9c9d73394 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -63,15 +63,31 @@ QUrl AddressManager::currentAddress() const { } QUrl AddressManager::currentFacingAddress() const { - QUrl hifiURL; + auto hifiURL = currentAddress(); + hifiURL.setPath(currentFacingPath()); - hifiURL.setScheme(HIFI_URL_SCHEME); - hifiURL.setHost(_host); + return hifiURL; +} - if (_port != 0 && _port != DEFAULT_DOMAIN_SERVER_PORT) { - hifiURL.setPort(_port); + +QUrl AddressManager::currentShareableAddress() const { + if (!_shareablePlaceName.isEmpty()) { + // if we have a shareable place name use that instead of whatever the current host is + QUrl hifiURL; + + hifiURL.setScheme(HIFI_URL_SCHEME); + hifiURL.setHost(_shareablePlaceName); + + hifiURL.setPath(currentPath()); + + return hifiURL; + } else { + return currentAddress(); } +} +QUrl AddressManager::currentFacingShareableAddress() const { + auto hifiURL = currentShareableAddress(); hifiURL.setPath(currentFacingPath()); return hifiURL; @@ -372,9 +388,12 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const if (placeName.isEmpty()) { // we didn't get a set place name, check if there is a default or temporary domain name to use const QString TEMPORARY_DOMAIN_NAME_KEY = "name"; + const QString DEFAULT_DOMAIN_NAME_KEY = "default_place_name"; if (domainObject.contains(TEMPORARY_DOMAIN_NAME_KEY)) { placeName = domainObject[TEMPORARY_DOMAIN_NAME_KEY].toString(); + } else if (domainObject.contains(DEFAULT_DOMAIN_NAME_KEY)) { + placeName = domainObject[DEFAULT_DOMAIN_NAME_KEY].toString(); } } @@ -714,7 +733,8 @@ void AddressManager::refreshPreviousLookup() { } void AddressManager::copyAddress() { - QApplication::clipboard()->setText(currentAddress().toString()); + // assume that the address is being copied because the user wants a shareable address + QApplication::clipboard()->setText(currentShareableAddress().toString()); } void AddressManager::copyPath() { diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index 74cc431448..296abbb36c 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -59,6 +59,8 @@ public: QUrl currentAddress() const; QUrl currentFacingAddress() const; + QUrl currentShareableAddress() const; + QUrl currentFacingShareableAddress() const; QString currentPath(bool withOrientation = true) const; QString currentFacingPath() const;