From 81ba875ad2e1b8c968de701232f44cf87f03b8a7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Apr 2018 12:39:49 -0700 Subject: [PATCH 1/4] currentShareableAddress wont return file: urls. copy-current-address menu item uses non-shareable version --- libraries/networking/src/AddressManager.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 7d7c2e682b..541b564317 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -60,6 +60,7 @@ QUrl AddressManager::currentFacingAddress() const { } QUrl AddressManager::currentShareableAddress(bool domainOnly) const { + QUrl shareableAddress; if (!_shareablePlaceName.isEmpty()) { // if we have a shareable place name use that instead of whatever the current host is QUrl hifiURL; @@ -71,10 +72,16 @@ QUrl AddressManager::currentShareableAddress(bool domainOnly) const { hifiURL.setPath(currentPath()); } - return hifiURL; + shareableAddress = hifiURL; } else { - return currentAddress(domainOnly); + shareableAddress = currentAddress(domainOnly); } + + if (shareableAddress.scheme() == URL_SCHEME_HIFI) { + return QUrl(); // file: urls aren't shareable + } + + return shareableAddress; } QUrl AddressManager::currentFacingShareableAddress() const { @@ -288,6 +295,7 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { // lookupUrl.scheme() == URL_SCHEME_HTTP || // lookupUrl.scheme() == URL_SCHEME_HTTPS || _previousLookup.clear(); + _shareablePlaceName.clear(); QUrl domainURL = PathUtils::expandToLocalDataAbsolutePath(lookupUrl); setDomainInfo(domainURL, trigger); emit lookupResultsFinished(); @@ -818,7 +826,7 @@ void AddressManager::copyAddress() { } // assume that the address is being copied because the user wants a shareable address - QGuiApplication::clipboard()->setText(currentShareableAddress().toString()); + QGuiApplication::clipboard()->setText(currentFacingAddress().toString()); } void AddressManager::copyPath() { From 1de878eb9c9b0ddfc5b0acb32645ce8caef5c737 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Apr 2018 12:43:03 -0700 Subject: [PATCH 2/4] fix logic --- libraries/networking/src/AddressManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 541b564317..443626ab52 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -77,7 +77,7 @@ QUrl AddressManager::currentShareableAddress(bool domainOnly) const { shareableAddress = currentAddress(domainOnly); } - if (shareableAddress.scheme() == URL_SCHEME_HIFI) { + if (shareableAddress.scheme() != URL_SCHEME_HIFI) { return QUrl(); // file: urls aren't shareable } From 148007435e7aeb784823898fa322d5d478d7dded Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Apr 2018 13:01:31 -0700 Subject: [PATCH 3/4] update comment --- libraries/networking/src/AddressManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 443626ab52..45e46c70ac 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -825,7 +825,7 @@ void AddressManager::copyAddress() { return; } - // assume that the address is being copied because the user wants a shareable address + // currentShareableAddress will be blank for serverless domains, so use currentFacingAddress here QGuiApplication::clipboard()->setText(currentFacingAddress().toString()); } From 8de545acdf5907a2add6f6f12fe36c33cc2281ae Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Apr 2018 13:39:51 -0700 Subject: [PATCH 4/4] add new address accessor for 'public' addresses, use it for snapshot and stream --- interface/src/DiscoverabilityManager.cpp | 2 +- interface/src/ui/Snapshot.cpp | 2 +- libraries/networking/src/AddressManager.cpp | 29 ++++++++++++++++----- libraries/networking/src/AddressManager.h | 2 ++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/interface/src/DiscoverabilityManager.cpp b/interface/src/DiscoverabilityManager.cpp index e2d47bf844..33cfc481d7 100644 --- a/interface/src/DiscoverabilityManager.cpp +++ b/interface/src/DiscoverabilityManager.cpp @@ -129,7 +129,7 @@ void DiscoverabilityManager::updateLocation() { // Update Steam if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) { - steamClient->updateLocation(domainHandler.getHostname(), addressManager->currentFacingShareableAddress()); + steamClient->updateLocation(domainHandler.getHostname(), addressManager->currentFacingPublicAddress()); } } diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 9b3089d78d..69103a40b5 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -95,7 +95,7 @@ QTemporaryFile* Snapshot::saveTempSnapshot(QImage image) { QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary, const QString& userSelectedFilename) { // adding URL to snapshot - QUrl currentURL = DependencyManager::get()->currentShareableAddress(); + QUrl currentURL = DependencyManager::get()->currentPublicAddress(); shot.setText(URL, currentURL.toString()); QString username = DependencyManager::get()->getAccountInfo().getUsername(); diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 45e46c70ac..cfe05941c0 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -60,7 +60,6 @@ QUrl AddressManager::currentFacingAddress() const { } QUrl AddressManager::currentShareableAddress(bool domainOnly) const { - QUrl shareableAddress; if (!_shareablePlaceName.isEmpty()) { // if we have a shareable place name use that instead of whatever the current host is QUrl hifiURL; @@ -72,18 +71,23 @@ QUrl AddressManager::currentShareableAddress(bool domainOnly) const { hifiURL.setPath(currentPath()); } - shareableAddress = hifiURL; + return hifiURL; } else { - shareableAddress = currentAddress(domainOnly); + return currentAddress(domainOnly); } +} +QUrl AddressManager::currentPublicAddress(bool domainOnly) const { + // return an address that can be used by others to visit this client's current location. If + // in a serverless domain (which can't be visited) return an empty URL. + QUrl shareableAddress = currentShareableAddress(domainOnly); if (shareableAddress.scheme() != URL_SCHEME_HIFI) { - return QUrl(); // file: urls aren't shareable + return QUrl(); // file: urls aren't public } - return shareableAddress; } + QUrl AddressManager::currentFacingShareableAddress() const { auto hifiURL = currentShareableAddress(); if (hifiURL.scheme() == URL_SCHEME_HIFI) { @@ -93,6 +97,17 @@ QUrl AddressManager::currentFacingShareableAddress() const { return hifiURL; } +QUrl AddressManager::currentFacingPublicAddress() const { + // return an address that can be used by others to visit this client's current location. If + // in a serverless domain (which can't be visited) return an empty URL. + QUrl shareableAddress = currentFacingShareableAddress(); + if (shareableAddress.scheme() != URL_SCHEME_HIFI) { + return QUrl(); // file: urls aren't public + } + return shareableAddress; +} + + void AddressManager::loadSettings(const QString& lookupString) { #if defined(USE_GLES) && defined(Q_OS_WIN) handleUrl(QUrl("hifi://127.0.0.0"), LookupTrigger::StartupFromSettings); @@ -825,8 +840,8 @@ void AddressManager::copyAddress() { return; } - // currentShareableAddress will be blank for serverless domains, so use currentFacingAddress here - QGuiApplication::clipboard()->setText(currentFacingAddress().toString()); + // assume that the address is being copied because the user wants a shareable address + QGuiApplication::clipboard()->setText(currentShareableAddress().toString()); } void AddressManager::copyPath() { diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index dc1046bf51..4add1e9414 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -150,7 +150,9 @@ public: QUrl currentAddress(bool domainOnly = false) const; QUrl currentFacingAddress() const; QUrl currentShareableAddress(bool domainOnly = false) const; + QUrl currentPublicAddress(bool domainOnly = false) const; QUrl currentFacingShareableAddress() const; + QUrl currentFacingPublicAddress() const; QString currentPath(bool withOrientation = true) const; QString currentFacingPath() const;