From e09eef98f23cb0832c147785644bb0abae2dc855 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Sep 2014 17:17:33 -0700 Subject: [PATCH 1/8] add option to add javascript objects to a DataWebDialog --- interface/src/Menu.cpp | 5 ++++- interface/src/ui/DataWebDialog.cpp | 14 +++++++++++++- interface/src/ui/DataWebDialog.h | 9 ++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 454d21be20..284b02dbff 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -38,6 +38,7 @@ #include "Application.h" #include "AccountManager.h" #include "Menu.h" +#include "scripting/LocationScriptingInterface.h" #include "scripting/MenuScriptingInterface.h" #include "Util.h" #include "ui/AnimationsDialog.h" @@ -1217,7 +1218,9 @@ void Menu::displayNameLocationResponse(const QString& errorString) { void Menu::toggleLocationList() { if (!_userLocationsDialog) { - _userLocationsDialog = DataWebDialog::dialogForPath("/locations"); + JavascriptObjectMap locationObjectMap; + locationObjectMap.insert("InterfaceLocation", LocationScriptingInterface::getInstance()); + _userLocationsDialog = DataWebDialog::dialogForPath("/locations", locationObjectMap); } if (!_userLocationsDialog->isVisible()) { diff --git a/interface/src/ui/DataWebDialog.cpp b/interface/src/ui/DataWebDialog.cpp index 0f70537b26..2094fe2dbf 100644 --- a/interface/src/ui/DataWebDialog.cpp +++ b/interface/src/ui/DataWebDialog.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include @@ -33,9 +34,14 @@ DataWebDialog::DataWebDialog() { connect(this, &QWebView::linkClicked, Application::getInstance(), &Application::openUrl); } -DataWebDialog* DataWebDialog::dialogForPath(const QString& path) { +DataWebDialog* DataWebDialog::dialogForPath(const QString& path, + const JavascriptObjectMap& javascriptObjects) { DataWebDialog* dialogWebView = new DataWebDialog(); + dialogWebView->_javascriptObjects = javascriptObjects; + connect(dialogWebView->page()->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared, + dialogWebView, &DataWebDialog::addJavascriptObjectsToWindow); + QUrl dataWebUrl(DEFAULT_NODE_AUTH_URL); dataWebUrl.setPath(path); @@ -44,4 +50,10 @@ DataWebDialog* DataWebDialog::dialogForPath(const QString& path) { dialogWebView->load(dataWebUrl); return dialogWebView; +} + +void DataWebDialog::addJavascriptObjectsToWindow() { + foreach(const QString& name, _javascriptObjects.keys()) { + page()->mainFrame()->addToJavaScriptWindowObject(name, _javascriptObjects[name]); + } } \ No newline at end of file diff --git a/interface/src/ui/DataWebDialog.h b/interface/src/ui/DataWebDialog.h index c69a9207b9..219e674620 100644 --- a/interface/src/ui/DataWebDialog.h +++ b/interface/src/ui/DataWebDialog.h @@ -15,11 +15,18 @@ #include #include +typedef QMap JavascriptObjectMap; + class DataWebDialog : public QWebView { Q_OBJECT public: DataWebDialog(); - static DataWebDialog* dialogForPath(const QString& path); + static DataWebDialog* dialogForPath(const QString& path, + const JavascriptObjectMap& javascriptObjects = JavascriptObjectMap()); +private slots: + void addJavascriptObjectsToWindow(); +private: + JavascriptObjectMap _javascriptObjects; }; #endif // hifi_WebkitDialog_h \ No newline at end of file From 84df6058cb010d3790c18fd941db61c5d59473be Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 10:42:14 -0700 Subject: [PATCH 2/8] add domainID to location scripting interface --- interface/src/scripting/LocationScriptingInterface.cpp | 4 ++++ interface/src/scripting/LocationScriptingInterface.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/interface/src/scripting/LocationScriptingInterface.cpp b/interface/src/scripting/LocationScriptingInterface.cpp index bead12117d..e3085459aa 100644 --- a/interface/src/scripting/LocationScriptingInterface.cpp +++ b/interface/src/scripting/LocationScriptingInterface.cpp @@ -38,6 +38,10 @@ QString LocationScriptingInterface::getHostname() { return NodeList::getInstance()->getDomainHandler().getHostname(); } +QString LocationScriptingInterface::getDomainID() const { + return uuidStringWithoutCurlyBraces(NodeList::getInstance()->getDomainHandler().getUUID()); +} + void LocationScriptingInterface::assign(const QString& url) { QMetaObject::invokeMethod(&AddressManager::getInstance(), "handleLookupString", Q_ARG(const QString&, url)); } diff --git a/interface/src/scripting/LocationScriptingInterface.h b/interface/src/scripting/LocationScriptingInterface.h index 3d725776fd..a8081c0687 100644 --- a/interface/src/scripting/LocationScriptingInterface.h +++ b/interface/src/scripting/LocationScriptingInterface.h @@ -29,6 +29,7 @@ class LocationScriptingInterface : public QObject { Q_PROPERTY(QString protocol READ getProtocol) Q_PROPERTY(QString hostname READ getHostname) Q_PROPERTY(QString pathname READ getPathname) + Q_PROPERTY(QString domainID READ getDomainID) LocationScriptingInterface() { }; public: static LocationScriptingInterface* getInstance(); @@ -38,6 +39,7 @@ public: QString getProtocol() { return HIFI_URL_SCHEME; }; QString getPathname(); QString getHostname(); + QString getDomainID() const; static QScriptValue locationGetter(QScriptContext* context, QScriptEngine* engine); static QScriptValue locationSetter(QScriptContext* context, QScriptEngine* engine); From 523a4e6ba251982183b4324fcf09dc9137e1db04 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 11:58:23 -0700 Subject: [PATCH 3/8] allow moving of location from DataWebDialog for locations --- interface/src/ui/DataWebDialog.cpp | 9 +++------ interface/src/ui/DataWebPage.cpp | 31 ++++++++++++++++++++++++++++++ interface/src/ui/DataWebPage.h | 24 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 interface/src/ui/DataWebPage.cpp create mode 100644 interface/src/ui/DataWebPage.h diff --git a/interface/src/ui/DataWebDialog.cpp b/interface/src/ui/DataWebDialog.cpp index 2094fe2dbf..e28dcf8df7 100644 --- a/interface/src/ui/DataWebDialog.cpp +++ b/interface/src/ui/DataWebDialog.cpp @@ -14,9 +14,9 @@ #include #include -#include #include "Application.h" +#include "DataWebPage.h" #include "DataWebDialog.h" @@ -24,11 +24,8 @@ DataWebDialog::DataWebDialog() { // make sure the dialog deletes itself when it closes setAttribute(Qt::WA_DeleteOnClose); - // use an OAuthNetworkAccessManager instead of regular QNetworkAccessManager so our requests are authed - page()->setNetworkAccessManager(OAuthNetworkAccessManager::getInstance()); - - // have the page delegate external links so they can be captured by the Application in case they are a hifi link - page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); + // set our page to a DataWebPage + setPage(new DataWebPage(this)); // have the Application handle external links connect(this, &QWebView::linkClicked, Application::getInstance(), &Application::openUrl); diff --git a/interface/src/ui/DataWebPage.cpp b/interface/src/ui/DataWebPage.cpp new file mode 100644 index 0000000000..812489a34d --- /dev/null +++ b/interface/src/ui/DataWebPage.cpp @@ -0,0 +1,31 @@ +// +// DataWebPage.cpp +// interface/src/ui +// +// Created by Stephen Birarda on 2014-09-22. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "DataWebPage.h" + +DataWebPage::DataWebPage(QObject* parent) : + QWebPage(parent) +{ + // use an OAuthNetworkAccessManager instead of regular QNetworkAccessManager so our requests are authed + setNetworkAccessManager(OAuthNetworkAccessManager::getInstance()); + + // have the page delegate external links so they can be captured by the Application in case they are a hifi link + setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); + + // give the page an empty stylesheet + settings()->setUserStyleSheetUrl(QUrl()); +} + +void DataWebPage::javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) { + qDebug() << "JS console message at line" << lineNumber << "from" << sourceID << "-" << message; +} \ No newline at end of file diff --git a/interface/src/ui/DataWebPage.h b/interface/src/ui/DataWebPage.h new file mode 100644 index 0000000000..72fcbb5992 --- /dev/null +++ b/interface/src/ui/DataWebPage.h @@ -0,0 +1,24 @@ +// +// DataWebPage.h +// interface/src/ui +// +// Created by Stephen Birarda on 2014-09-22. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_DataWebPage_h +#define hifi_DataWebPage_h + +#include + +class DataWebPage : public QWebPage { +public: + DataWebPage(QObject* parent = 0); +protected: + void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); +}; + +#endif // hifi_DataWebPage_h \ No newline at end of file From e5a54116dcb89086e1d1f54090bce3136d23e2bd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 15:00:07 -0700 Subject: [PATCH 4/8] correctly return empty string for domain ID if it is null --- interface/src/scripting/LocationScriptingInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/LocationScriptingInterface.cpp b/interface/src/scripting/LocationScriptingInterface.cpp index e3085459aa..bf529fb593 100644 --- a/interface/src/scripting/LocationScriptingInterface.cpp +++ b/interface/src/scripting/LocationScriptingInterface.cpp @@ -39,7 +39,8 @@ QString LocationScriptingInterface::getHostname() { } QString LocationScriptingInterface::getDomainID() const { - return uuidStringWithoutCurlyBraces(NodeList::getInstance()->getDomainHandler().getUUID()); + const QUuid& domainID = NodeList::getInstance()->getDomainHandler().getUUID(); + return domainID.isNull() ? "" : uuidStringWithoutCurlyBraces(domainID); } void LocationScriptingInterface::assign(const QString& url) { From eb0f7da5172da308bf76534565024b799fe6bcc0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 16:14:06 -0700 Subject: [PATCH 5/8] cleanup to snapshot class to reduce passing of variables --- interface/src/Application.cpp | 2 +- interface/src/location/LocationManager.cpp | 6 ++---- interface/src/ui/Snapshot.cpp | 14 +++++++++----- interface/src/ui/Snapshot.h | 7 ++++--- libraries/networking/src/LimitedNodeList.cpp | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a20a6553d4..1d44e91120 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4158,7 +4158,7 @@ void Application::takeSnapshot() { player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); player->play(); - QString fileName = Snapshot::saveSnapshot(_glWidget, _myAvatar); + QString fileName = Snapshot::saveSnapshot(); AccountManager& accountManager = AccountManager::getInstance(); if (!accountManager.isLoggedIn()) { diff --git a/interface/src/location/LocationManager.cpp b/interface/src/location/LocationManager.cpp index ed27d9e49d..9b5dfa440f 100644 --- a/interface/src/location/LocationManager.cpp +++ b/interface/src/location/LocationManager.cpp @@ -101,10 +101,8 @@ void LocationManager::locationImageUpdateSuccess(const QJsonObject& rootObject) } void LocationManager::updateSnapshotForExistingLocation(const QString& locationID) { - // first create a snapshot and save it - Application* application = Application::getInstance(); - - QTemporaryFile* tempImageFile = Snapshot::saveTempSnapshot(application->getGLWidget(), application->getAvatar()); + // first create a snapshot and save it + QTemporaryFile* tempImageFile = Snapshot::saveTempSnapshot(); if (tempImageFile && tempImageFile->open()) { AccountManager& accountManager = AccountManager::getInstance(); diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 9fe1c332be..d68920a5f5 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -64,8 +64,8 @@ SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) { return data; } -QString Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { - QFile* snapshotFile = savedFileForSnapshot(widget, avatar, false); +QString Snapshot::saveSnapshot() { + QFile* snapshotFile = savedFileForSnapshot(false); // we don't need the snapshot file, so close it, grab its filename and delete it snapshotFile->close(); @@ -77,14 +77,18 @@ QString Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { return snapshotPath; } -QTemporaryFile* Snapshot::saveTempSnapshot(QGLWidget* widget, Avatar* avatar) { +QTemporaryFile* Snapshot::saveTempSnapshot() { // return whatever we get back from saved file for snapshot - return static_cast(savedFileForSnapshot(widget, avatar, true));; + return static_cast(savedFileForSnapshot(true));; } -QFile* Snapshot::savedFileForSnapshot(QGLWidget* widget, Avatar* avatar, bool isTemporary) { +QFile* Snapshot::savedFileForSnapshot(bool isTemporary) { + + QGLWidget* widget = Application::getInstance()->getGLWidget(); QImage shot = widget->grabFrameBuffer(); + Avatar* avatar = Application::getInstance()->getAvatar(); + glm::vec3 location = avatar->getPosition(); glm::quat orientation = avatar->getHead()->getOrientation(); diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h index 8f15532cb5..502bc39157 100644 --- a/interface/src/ui/Snapshot.h +++ b/interface/src/ui/Snapshot.h @@ -15,6 +15,7 @@ #include "InterfaceConfig.h" #include +#include #include #include @@ -41,12 +42,12 @@ private: class Snapshot { public: - static QString saveSnapshot(QGLWidget* widget, Avatar* avatar); - static QTemporaryFile* saveTempSnapshot(QGLWidget* widget, Avatar* avatar); + static QString saveSnapshot(); + static QTemporaryFile* saveTempSnapshot(); static SnapshotMetaData* parseSnapshotData(QString snapshotPath); private: - static QFile* savedFileForSnapshot(QGLWidget* widget, Avatar* avatar, bool isTemporary); + static QFile* savedFileForSnapshot(bool isTemporary); }; #endif // hifi_Snapshot_h diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index d42cab6210..bfdfc28d5e 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -33,7 +33,7 @@ const char SOLO_NODE_TYPES[2] = { NodeType::AudioMixer }; -const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://data.highfidelity.io"); +const QUrl DEFAULT_NODE_AUTH_URL = QUrl("http://localhost:3000"); LimitedNodeList* LimitedNodeList::_sharedInstance = NULL; From 5be045d612aaae45c9e8a9ec4c922536abe85623 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 16:55:44 -0700 Subject: [PATCH 6/8] remove LocationManager and NamedLocation, replace with DataWebDialog --- interface/src/Application.cpp | 3 - interface/src/Menu.cpp | 38 ++---- interface/src/Menu.h | 2 +- interface/src/ScriptsModel.cpp | 12 +- interface/src/location/LocationManager.cpp | 149 --------------------- interface/src/location/LocationManager.h | 47 ------- interface/src/location/NamedLocation.cpp | 33 ----- interface/src/location/NamedLocation.h | 55 -------- interface/src/ui/MetavoxelEditor.cpp | 4 +- interface/src/ui/ModelsBrowser.cpp | 1 + interface/src/ui/OAuthWebViewHandler.cpp | 3 +- interface/src/ui/Snapshot.h | 7 +- 12 files changed, 31 insertions(+), 323 deletions(-) delete mode 100644 interface/src/location/LocationManager.cpp delete mode 100644 interface/src/location/LocationManager.h delete mode 100644 interface/src/location/NamedLocation.cpp delete mode 100644 interface/src/location/NamedLocation.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1d44e91120..96d47c84b1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -293,9 +293,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // set the account manager's root URL and trigger a login request if we don't have the access token accountManager.setAuthURL(DEFAULT_NODE_AUTH_URL); UserActivityLogger::getInstance().launch(applicationVersion()); - - // grab the location manager instance early so it lives in our thread - LocationManager::getInstance(); // once the event loop has started, check and signal for an access token QMetaObject::invokeMethod(&accountManager, "checkAndSignalForAccessToken", Qt::QueuedConnection); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 284b02dbff..fc19bbc142 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -96,6 +96,7 @@ Menu::Menu() : _jsConsole(NULL), _octreeStatsDialog(NULL), _lodToolsDialog(NULL), + _newLocationDialog(NULL), _userLocationsDialog(NULL), #ifdef Q_OS_MAC _speechRecognizer(), @@ -1260,31 +1261,20 @@ void Menu::nameLocation() { return; } - - QInputDialog nameDialog(Application::getInstance()->getWindow()); - nameDialog.setWindowTitle("Name this location"); - nameDialog.setLabelText("Name this location, then share that name with others.\n" - "When they come here, they'll have the same viewpoint\n" - "(wherever you are standing and looking now) as you.\n\n" - "Location name:"); - - nameDialog.resize((int) (nameDialog.parentWidget()->size().width() * 0.30), nameDialog.size().height()); - - if (nameDialog.exec() == QDialog::Accepted) { - - QString locationName = nameDialog.textValue().trimmed(); - if (locationName.isEmpty()) { - return; - } - - MyAvatar* myAvatar = Application::getInstance()->getAvatar(); - LocationManager* manager = new LocationManager(); - connect(manager, &LocationManager::creationCompleted, this, &Menu::displayNameLocationResponse); - NamedLocation* location = new NamedLocation(locationName, - myAvatar->getPosition(), myAvatar->getOrientation(), - domainHandler.getUUID()); - manager->createNamedLocation(location); + + if (!_newLocationDialog) { + JavascriptObjectMap locationObjectMap; + locationObjectMap.insert("InterfaceLocation", LocationScriptingInterface::getInstance()); + _newLocationDialog = DataWebDialog::dialogForPath("/locations/new", locationObjectMap); } + + if (!_newLocationDialog->isVisible()) { + _newLocationDialog->show(); + } + + _newLocationDialog->raise(); + _newLocationDialog->activateWindow(); + _newLocationDialog->showNormal(); } void Menu::pasteToVoxel() { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 5a2240b3d8..074e9bcc6d 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -27,7 +27,6 @@ #include "SpeechRecognizer.h" #endif -#include "location/LocationManager.h" #include "ui/ChatWindow.h" #include "ui/DataWebDialog.h" #include "ui/JSConsole.h" @@ -273,6 +272,7 @@ private: QDialog* _jsConsole; OctreeStatsDialog* _octreeStatsDialog; LodToolsDialog* _lodToolsDialog; + QPointer _newLocationDialog; QPointer _userLocationsDialog; #ifdef Q_OS_MAC SpeechRecognizer _speechRecognizer; diff --git a/interface/src/ScriptsModel.cpp b/interface/src/ScriptsModel.cpp index cbdbb5bf54..9c206fe9f6 100644 --- a/interface/src/ScriptsModel.cpp +++ b/interface/src/ScriptsModel.cpp @@ -87,11 +87,13 @@ int ScriptsModel::rowCount(const QModelIndex& parent) const { void ScriptsModel::updateScriptsLocation(const QString& newPath) { _fsWatcher.removePath(_localDirectory.absolutePath()); - _localDirectory.setPath(newPath); - - if (!_localDirectory.absolutePath().isEmpty()) { - _fsWatcher.addPath(_localDirectory.absolutePath()); - } + if (!newPath.isEmpty()) { + _localDirectory.setPath(newPath); + + if (!_localDirectory.absolutePath().isEmpty()) { + _fsWatcher.addPath(_localDirectory.absolutePath()); + } + } reloadLocalFiles(); } diff --git a/interface/src/location/LocationManager.cpp b/interface/src/location/LocationManager.cpp deleted file mode 100644 index 9b5dfa440f..0000000000 --- a/interface/src/location/LocationManager.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// -// LocationManager.cpp -// interface/src/location -// -// Created by Stojce Slavkovski on 2/7/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include - -#include - -#include "Application.h" -#include "ui/Snapshot.h" - -#include "LocationManager.h" - -const QString POST_LOCATION_CREATE = "/api/v1/locations/"; - -LocationManager& LocationManager::getInstance() { - static LocationManager sharedInstance; - return sharedInstance; -} - -const QString UNKNOWN_ERROR_MESSAGE = "Unknown error creating named location. Please try again!"; - -const QString LOCATION_OBJECT_KEY = "location"; -const QString LOCATION_ID_KEY = "id"; - -void LocationManager::namedLocationDataReceived(const QJsonObject& rootObject) { - - if (rootObject.contains("status") && rootObject["status"].toString() == "success") { - emit creationCompleted(QString()); - - // successfuly created a location - grab the ID from the response and create a snapshot to upload - QString locationIDString = rootObject[LOCATION_OBJECT_KEY].toObject()[LOCATION_ID_KEY].toString(); - updateSnapshotForExistingLocation(locationIDString); - } else { - emit creationCompleted(UNKNOWN_ERROR_MESSAGE); - } -} - -void LocationManager::createNamedLocation(NamedLocation* namedLocation) { - AccountManager& accountManager = AccountManager::getInstance(); - if (accountManager.isLoggedIn()) { - JSONCallbackParameters callbackParams; - callbackParams.jsonCallbackReceiver = this; - callbackParams.jsonCallbackMethod = "namedLocationDataReceived"; - callbackParams.errorCallbackReceiver = this; - callbackParams.errorCallbackMethod = "errorDataReceived"; - - accountManager.authenticatedRequest(POST_LOCATION_CREATE, QNetworkAccessManager::PostOperation, - callbackParams, namedLocation->toJsonString().toUtf8()); - } -} - -void LocationManager::errorDataReceived(QNetworkReply& errorReply) { - - if (errorReply.header(QNetworkRequest::ContentTypeHeader).toString().startsWith("application/json")) { - // we have some JSON error data we can parse for our error message - QJsonDocument responseJson = QJsonDocument::fromJson(errorReply.readAll()); - - QJsonObject dataObject = responseJson.object()["data"].toObject(); - - qDebug() << dataObject; - - QString errorString = "There was a problem creating that location.\n"; - - // construct the error string from the returned attribute errors - foreach(const QString& key, dataObject.keys()) { - errorString += "\n\u2022 " + key + " - "; - - QJsonValue keyedErrorValue = dataObject[key]; - - if (keyedErrorValue.isArray()) { - foreach(const QJsonValue& attributeErrorValue, keyedErrorValue.toArray()) { - errorString += attributeErrorValue.toString() + ", "; - } - - // remove the trailing comma at end of error list - errorString.remove(errorString.length() - 2, 2); - } else if (keyedErrorValue.isString()) { - errorString += keyedErrorValue.toString(); - } - } - - // emit our creationCompleted signal with the error - emit creationCompleted(errorString); - - } else { - creationCompleted(UNKNOWN_ERROR_MESSAGE); - } -} - -void LocationManager::locationImageUpdateSuccess(const QJsonObject& rootObject) { - qDebug() << "Successfuly updated a location image."; -} - -void LocationManager::updateSnapshotForExistingLocation(const QString& locationID) { - // first create a snapshot and save it - QTemporaryFile* tempImageFile = Snapshot::saveTempSnapshot(); - - if (tempImageFile && tempImageFile->open()) { - AccountManager& accountManager = AccountManager::getInstance(); - - // setup a multipart that is in the AccountManager thread - we need this so it can be cleaned up after the QNetworkReply - QHttpMultiPart* imageFileMultiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); - imageFileMultiPart->moveToThread(accountManager.thread()); - - // parent the temp file to the QHttpMultipart after moving it to account manager thread - tempImageFile->moveToThread(accountManager.thread()); - tempImageFile->setParent(imageFileMultiPart); - - qDebug() << "Uploading a snapshot from" << QFileInfo(*tempImageFile).absoluteFilePath() - << "as location image for" << locationID; - - const QString LOCATION_IMAGE_NAME = "location[image]"; - - QHttpPart imagePart; - imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, - QVariant("form-data; name=\"" + LOCATION_IMAGE_NAME + "\";" - " filename=\"" + QFileInfo(tempImageFile->fileName()).fileName().toUtf8() + "\"")); - imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream")); - imagePart.setBodyDevice(tempImageFile); - - imageFileMultiPart->append(imagePart); - - const QString LOCATION_IMAGE_PUT_PATH = "api/v1/locations/%1/image"; - - JSONCallbackParameters imageCallbackParams; - imageCallbackParams.jsonCallbackReceiver = this; - imageCallbackParams.jsonCallbackMethod = "locationImageUpdateSuccess"; - - // make an authenticated request via account manager to upload the image - // don't do anything with error or success for now - AccountManager::getInstance().authenticatedRequest(LOCATION_IMAGE_PUT_PATH.arg(locationID), - QNetworkAccessManager::PutOperation, - JSONCallbackParameters(), QByteArray(), imageFileMultiPart); - } else { - qDebug() << "Couldn't open snapshot file to upload as location image. No location image will be stored."; - return; - } -} - - diff --git a/interface/src/location/LocationManager.h b/interface/src/location/LocationManager.h deleted file mode 100644 index 43431a83c9..0000000000 --- a/interface/src/location/LocationManager.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// LocationManager.h -// interface/src/location -// -// Created by Stojce Slavkovski on 2/7/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_LocationManager_h -#define hifi_LocationManager_h - -#include -#include - -#include "NamedLocation.h" - -class LocationManager : public QObject { - Q_OBJECT - -public: - static LocationManager& getInstance(); - - enum NamedLocationCreateResponse { - Created, - AlreadyExists, - SystemError - }; - - void createNamedLocation(NamedLocation* namedLocation); - -signals: - void creationCompleted(const QString& errorMessage); - -private slots: - void namedLocationDataReceived(const QJsonObject& jsonObject); - void errorDataReceived(QNetworkReply& errorReply); - void locationImageUpdateSuccess(const QJsonObject& jsonObject); - -private: - void updateSnapshotForExistingLocation(const QString& locationID); - -}; - -#endif // hifi_LocationManager_h diff --git a/interface/src/location/NamedLocation.cpp b/interface/src/location/NamedLocation.cpp deleted file mode 100644 index 7785edfea1..0000000000 --- a/interface/src/location/NamedLocation.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// -// NamedLocation.cpp -// interface/src/location -// -// Created by Stojce Slavkovski on 2/1/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include - -#include "NamedLocation.h" - -NamedLocation::NamedLocation(const QString& name, - const glm::vec3& position, const glm::quat& orientation, - const QUuid& domainID) : - _name(name), - _position(position), - _orientation(orientation), - _domainID(domainID) -{ - -} - -const QString JSON_FORMAT = "{\"location\":{\"path\":\"%1\",\"domain_id\":\"%2\",\"name\":\"%3\"}}"; - -QString NamedLocation::toJsonString() { - return JSON_FORMAT.arg(AddressManager::pathForPositionAndOrientation(_position, true, _orientation), - uuidStringWithoutCurlyBraces(_domainID), _name); -} diff --git a/interface/src/location/NamedLocation.h b/interface/src/location/NamedLocation.h deleted file mode 100644 index fca6852062..0000000000 --- a/interface/src/location/NamedLocation.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// NamedLocation.h -// interface/src/location -// -// Created by Stojce Slavkovski on 2/1/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_NamedLocation_h -#define hifi_NamedLocation_h - -#include -#include -#include - -#include - -class NamedLocation : public QObject { - Q_OBJECT - -public: - NamedLocation(const QString& name, const glm::vec3& position, const glm::quat& orientation, const QUuid& domainID); - - QString toJsonString(); - - bool isEmpty() { return _name.isNull() || _name.isEmpty(); } - - void setName(QString name) { _name = name; } - const QString& getName() const { return _name; } - - void setLocation(glm::vec3 position) { _position = position; } - const glm::vec3& getPosition() const { return _position; } - - void setOrientation(const glm::quat& orentation) { _orientation = orentation; } - const glm::quat& getOrientation() const { return _orientation; } - - void setDomainID(const QUuid& domainID) { _domainID = domainID; } - const QUuid& getDomainID() const { return _domainID; } - -signals: - void dataReceived(bool locationExists); - -private: - QString _name; - QString _createdBy; - glm::vec3 _position; - glm::quat _orientation; - QUuid _domainID; - -}; - -#endif // hifi_NamedLocation_h diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 64cf12373d..bb62bee9a1 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -1031,7 +1031,7 @@ void ImportHeightfieldTool::apply() { data.setRoot(AttributeRegistry::getInstance()->getHeightfieldColorAttribute(), new MetavoxelNode(AttributeValue( AttributeRegistry::getInstance()->getHeightfieldColorAttribute(), encodeInline(colorPointer)))); - int size = glm::sqrt(height.size()) + HeightfieldBuffer::SHARED_EDGE; + int size = glm::sqrt(float(height.size())) + HeightfieldBuffer::SHARED_EDGE; QByteArray material(size * size, 0); HeightfieldMaterialDataPointer materialPointer(new HeightfieldMaterialData(material)); data.setRoot(AttributeRegistry::getInstance()->getHeightfieldMaterialAttribute(), new MetavoxelNode(AttributeValue( @@ -1103,7 +1103,7 @@ void ImportHeightfieldTool::updateHeightImage() { if (_loadingImage) { return; } - int size = glm::sqrt(_rawHeight.size()); + int size = glm::sqrt(float(_rawHeight.size())); _heightImage = QImage(size, size, QImage::Format_RGB888); const quint16* src = _rawHeight.constData(); float scale = _heightScale->value(), offset = _heightOffset->value(); diff --git a/interface/src/ui/ModelsBrowser.cpp b/interface/src/ui/ModelsBrowser.cpp index 5e107677f0..9ff839256d 100644 --- a/interface/src/ui/ModelsBrowser.cpp +++ b/interface/src/ui/ModelsBrowser.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index 4cc5af07a6..86db54afb4 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -9,7 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include +#include #include diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h index 502bc39157..c29bdc41ff 100644 --- a/interface/src/ui/Snapshot.h +++ b/interface/src/ui/Snapshot.h @@ -14,10 +14,11 @@ #include "InterfaceConfig.h" -#include -#include +#include +#include +#include #include -#include +#include #include "avatar/Avatar.h" From 65a557b71a3dc21dc5ee28a80007f72017af794e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 16:59:32 -0700 Subject: [PATCH 7/8] don't change the NodeList auth URL --- libraries/networking/src/LimitedNodeList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index bfdfc28d5e..d42cab6210 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -33,7 +33,7 @@ const char SOLO_NODE_TYPES[2] = { NodeType::AudioMixer }; -const QUrl DEFAULT_NODE_AUTH_URL = QUrl("http://localhost:3000"); +const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://data.highfidelity.io"); LimitedNodeList* LimitedNodeList::_sharedInstance = NULL; From 7bae88e9969d708f772c24657a41f094e4744fdf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 23 Sep 2014 08:52:22 -0700 Subject: [PATCH 8/8] fix for calls to glm sqrt with ints --- interface/src/MetavoxelSystem.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index b0a1a3413d..1c17819707 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -636,9 +637,9 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, _heightTextureID(0), _colorTextureID(0), _materialTextureID(0), - _heightSize(glm::sqrt(height.size())), + _heightSize(glm::sqrt(float(height.size()))), _heightIncrement(scale / (_heightSize - HEIGHT_EXTENSION)), - _colorSize(glm::sqrt(color.size() / DataBlock::COLOR_BYTES)), + _colorSize(glm::sqrt(float(color.size() / DataBlock::COLOR_BYTES))), _colorIncrement(scale / (_colorSize - SHARED_EDGE)) { _heightBounds.minimum.x -= _heightIncrement * HEIGHT_BORDER; @@ -663,7 +664,7 @@ HeightfieldBuffer::~HeightfieldBuffer() { } QByteArray HeightfieldBuffer::getUnextendedHeight() const { - int srcSize = glm::sqrt(_height.size()); + int srcSize = glm::sqrt(float(_height.size())); int destSize = srcSize - 3; QByteArray unextended(destSize * destSize, 0); const char* src = _height.constData() + srcSize + 1; @@ -675,7 +676,7 @@ QByteArray HeightfieldBuffer::getUnextendedHeight() const { } QByteArray HeightfieldBuffer::getUnextendedColor() const { - int srcSize = glm::sqrt(_color.size() / DataBlock::COLOR_BYTES); + int srcSize = glm::sqrt(float(_color.size() / DataBlock::COLOR_BYTES)); int destSize = srcSize - 1; QByteArray unextended(destSize * destSize * DataBlock::COLOR_BYTES, 0); const char* src = _color.constData(); @@ -720,7 +721,7 @@ void HeightfieldBuffer::render(bool cursor) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR); } else { - int colorSize = glm::sqrt(_color.size() / DataBlock::COLOR_BYTES); + int colorSize = glm::sqrt(float(_color.size() / DataBlock::COLOR_BYTES)); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData()); } @@ -731,7 +732,7 @@ void HeightfieldBuffer::render(bool cursor) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - int materialSize = glm::sqrt(_material.size()); + int materialSize = glm::sqrt(float(_material.size())); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, materialSize, materialSize, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, _material.constData()); @@ -1270,7 +1271,7 @@ int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) { char* dest = _buffer->getHeight().data() + destY * heightSize + destX; const QByteArray& srcHeight = height->getContents(); - int srcSize = glm::sqrt(srcHeight.size()); + int srcSize = glm::sqrt(float(srcHeight.size())); float srcIncrement = info.size / srcSize; if (info.size == _buffer->getScale() && srcSize == (heightSize - HeightfieldBuffer::HEIGHT_EXTENSION)) { @@ -1323,7 +1324,7 @@ int HeightfieldFetchVisitor::visit(MetavoxelInfo& info) { int destBytes = destWidth * DataBlock::COLOR_BYTES; const QByteArray& srcColor = color->getContents(); - srcSize = glm::sqrt(srcColor.size() / DataBlock::COLOR_BYTES); + srcSize = glm::sqrt(float(srcColor.size() / DataBlock::COLOR_BYTES)); int srcStride = srcSize * DataBlock::COLOR_BYTES; srcIncrement = info.size / srcSize; @@ -1393,7 +1394,7 @@ int HeightfieldRegionVisitor::visit(MetavoxelInfo& info) { HeightfieldHeightDataPointer height = info.inputValues.at(0).getInlineValue(); if (height) { const QByteArray& heightContents = height->getContents(); - int size = glm::sqrt(heightContents.size()); + int size = glm::sqrt(float(heightContents.size())); int extendedSize = size + HeightfieldBuffer::HEIGHT_EXTENSION; int heightContentsSize = extendedSize * extendedSize; @@ -1401,7 +1402,7 @@ int HeightfieldRegionVisitor::visit(MetavoxelInfo& info) { int colorContentsSize = 0; if (color) { const QByteArray& colorContents = color->getContents(); - int colorSize = glm::sqrt(colorContents.size() / DataBlock::COLOR_BYTES); + int colorSize = glm::sqrt(float(colorContents.size() / DataBlock::COLOR_BYTES)); int extendedColorSize = colorSize + HeightfieldBuffer::SHARED_EDGE; colorContentsSize = extendedColorSize * extendedColorSize * DataBlock::COLOR_BYTES; }