From 5be045d612aaae45c9e8a9ec4c922536abe85623 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 22 Sep 2014 16:55:44 -0700 Subject: [PATCH] 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"