mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 04:03:59 +02:00
remove LocationManager and NamedLocation, replace with DataWebDialog
This commit is contained in:
parent
eb0f7da517
commit
5be045d612
12 changed files with 31 additions and 323 deletions
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<DataWebDialog> _newLocationDialog;
|
||||
QPointer<DataWebDialog> _userLocationsDialog;
|
||||
#ifdef Q_OS_MAC
|
||||
SpeechRecognizer _speechRecognizer;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 <qhttpmultipart.h>
|
||||
#include <qjsonobject.h>
|
||||
|
||||
#include <AccountManager.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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 <QtCore>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
#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
|
|
@ -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 <AddressManager.h>
|
||||
#include <UUID.h>
|
||||
|
||||
#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);
|
||||
}
|
|
@ -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 <glm/glm.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
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
|
|
@ -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();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QUrl>
|
||||
#include <qurlquery.h>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include <NetworkAccessManager.h>
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QtWebKitWidgets/QWebView>
|
||||
#include <qwebview.h>
|
||||
#include <qurlquery.h>
|
||||
|
||||
#include <AccountManager.h>
|
||||
|
||||
|
|
|
@ -14,10 +14,11 @@
|
|||
|
||||
#include "InterfaceConfig.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QFile>
|
||||
#include <qimage.h>
|
||||
#include <qfile.h>
|
||||
#include <qtemporaryfile.h>
|
||||
#include <QGLWidget>
|
||||
#include <QString>
|
||||
#include <qstring.h>
|
||||
|
||||
#include "avatar/Avatar.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue