handle place creation at new API endpoint

This commit is contained in:
Stephen Birarda 2014-09-11 17:33:01 -07:00
parent b56ea5c936
commit 7964180905
9 changed files with 43 additions and 191 deletions

View file

@ -155,7 +155,7 @@ public slots:
void decreaseSize();
void resetSize();
void goToLocation(const glm::vec3& newPosition, bool hasOrientation, const glm::vec3& newOrientation);
void goToLocation(const glm::vec3& newPosition, bool hasOrientation = false, const glm::vec3& newOrientation = glm::vec3());
// Set/Get update the thrust that will move the avatar around
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };

View file

@ -9,14 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QMessageBox>
#include <AccountManager.h>
#include "Application.h"
#include "LocationManager.h"
#include <UserActivityLogger.h>
const QString POST_PLACE_CREATE = "/api/v1/places/";
const QString POST_LOCATION_CREATE = "/api/v1/locations/";
LocationManager& LocationManager::getInstance() {
static LocationManager sharedInstance;
@ -44,145 +41,7 @@ void LocationManager::createNamedLocation(NamedLocation* namedLocation) {
callbackParams.errorCallbackReceiver = this;
callbackParams.errorCallbackMethod = "errorDataReceived";
accountManager.authenticatedRequest(POST_PLACE_CREATE, QNetworkAccessManager::PostOperation,
accountManager.authenticatedRequest(POST_LOCATION_CREATE, QNetworkAccessManager::PostOperation,
callbackParams, namedLocation->toJsonString().toUtf8());
}
}
void LocationManager::goToUrl(const QUrl& url) {
// if (location.startsWith(CUSTOM_URL_SCHEME + "/")) {
// QStringList urlParts = location.remove(0, CUSTOM_URL_SCHEME.length()).split('/', QString::SkipEmptyParts);
//
// if (urlParts.count() > 1) {
// // if url has 2 or more parts, the first one is domain name
// QString domain = urlParts[0];
//
// // second part is either a destination coordinate or
// // a place name
// QString destination = urlParts[1];
//
// // any third part is an avatar orientation.
// QString orientation = urlParts.count() > 2 ? urlParts[2] : QString();
//
// goToDomain(domain);
//
// // goto either @user, #place, or x-xx,y-yy,z-zz
// // style co-ordinate.
// goTo(destination);
//
// if (!orientation.isEmpty()) {
// // location orientation
// goToOrientation(orientation);
// }
// } else if (urlParts.count() == 1) {
// QString destination = urlParts[0];
//
// // If this starts with # or @, treat it as a user/location, otherwise treat it as a domain
// if (destination[0] == '#' || destination[0] == '@') {
// goTo(destination);
// } else {
// goToDomain(destination);
// }
// }
// return true;
// }
// return false;
}
void LocationManager::goToOrientation(QString orientation) {
if (orientation.isEmpty()) {
return;
}
QStringList orientationItems = orientation.remove(' ').split(QRegExp("_|,"), QString::SkipEmptyParts);
const int NUMBER_OF_ORIENTATION_ITEMS = 4;
const int W_ITEM = 0;
const int X_ITEM = 1;
const int Y_ITEM = 2;
const int Z_ITEM = 3;
if (orientationItems.size() == NUMBER_OF_ORIENTATION_ITEMS) {
// replace last occurrence of '_' with decimal point
replaceLastOccurrence('-', '.', orientationItems[W_ITEM]);
replaceLastOccurrence('-', '.', orientationItems[X_ITEM]);
replaceLastOccurrence('-', '.', orientationItems[Y_ITEM]);
replaceLastOccurrence('-', '.', orientationItems[Z_ITEM]);
double w = orientationItems[W_ITEM].toDouble();
double x = orientationItems[X_ITEM].toDouble();
double y = orientationItems[Y_ITEM].toDouble();
double z = orientationItems[Z_ITEM].toDouble();
glm::quat newAvatarOrientation(w, x, y, z);
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
glm::quat avatarOrientation = myAvatar->getOrientation();
if (newAvatarOrientation != avatarOrientation) {
myAvatar->setOrientation(newAvatarOrientation);
emit myAvatar->transformChanged();
}
}
}
bool LocationManager::goToDestination(QString destination) {
QStringList coordinateItems = destination.remove(' ').split(QRegExp("_|,"), QString::SkipEmptyParts);
const int NUMBER_OF_COORDINATE_ITEMS = 3;
const int X_ITEM = 0;
const int Y_ITEM = 1;
const int Z_ITEM = 2;
if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) {
// replace last occurrence of '_' with decimal point
replaceLastOccurrence('-', '.', coordinateItems[X_ITEM]);
replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM]);
replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM]);
double x = coordinateItems[X_ITEM].toDouble();
double y = coordinateItems[Y_ITEM].toDouble();
double z = coordinateItems[Z_ITEM].toDouble();
glm::vec3 newAvatarPos(x, y, z);
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
glm::vec3 avatarPos = myAvatar->getPosition();
if (newAvatarPos != avatarPos) {
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
MyAvatar::sendKillAvatar();
qDebug("Going To Location: %f, %f, %f...", x, y, z);
myAvatar->slamPosition(newAvatarPos);
emit myAvatar->transformChanged();
}
return true;
}
// no coordinates were parsed
return false;
}
void LocationManager::handleAddressLookupError(QNetworkReply::NetworkError networkError,
const QString& errorString) {
QString messageBoxString;
if (networkError == QNetworkReply::ContentNotFoundError) {
messageBoxString = "That address could not be found.";
} else {
messageBoxString = errorString;
}
QMessageBox::warning(Application::getInstance()->getWindow(), "", messageBoxString);
}
void LocationManager::replaceLastOccurrence(const QChar search, const QChar replace, QString& string) {
int lastIndex;
lastIndex = string.lastIndexOf(search);
if (lastIndex > 0) {
lastIndex = string.lastIndexOf(search);
string.replace(lastIndex, 1, replace);
}
}

View file

@ -14,7 +14,6 @@
#include <QtCore>
#include "AccountManager.h"
#include "NamedLocation.h"
class LocationManager : public QObject {
@ -30,19 +29,6 @@ public:
};
void createNamedLocation(NamedLocation* namedLocation);
void goTo(QString destination);
void goToUser(QString userName);
void goToPlace(QString placeName);
void goToUrl(const QUrl& url);
void goToOrientation(QString orientation);
bool goToDestination(QString destination);
public slots:
void handleAddressLookupError(QNetworkReply::NetworkError networkError, const QString& errorString);
private:
void replaceLastOccurrence(const QChar search, const QChar replace, QString& string);
signals:
void creationCompleted(LocationManager::NamedLocationCreateResponse response);

View file

@ -9,19 +9,25 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <AddressManager.h>
#include <UUID.h>
#include "NamedLocation.h"
const QString JSON_FORMAT = "{\"address\":{\"position\":\"%1,%2,%3\","
"\"orientation\":\"%4,%5,%6,%7\",\"domain\":\"%8\"},\"name\":\"%9\"}";
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(QString::number(_location.x),
QString::number(_location.y),
QString::number(_location.z),
QString::number(_orientation.w),
QString::number(_orientation.x),
QString::number(_orientation.y),
QString::number(_orientation.z),
_domain,
_locationName);
return JSON_FORMAT.arg(AddressManager::pathForPositionAndOrientation(_position, true, _orientation),
uuidStringWithoutCurlyBraces(_domainID), _name);
}

View file

@ -22,39 +22,33 @@ class NamedLocation : public QObject {
Q_OBJECT
public:
NamedLocation(QString locationName, glm::vec3 location, glm::quat orientation, QString domain) {
_locationName = locationName;
_location = location;
_orientation = orientation;
_domain = domain;
}
NamedLocation(const QString& name, const glm::vec3& position, const glm::quat& orientation, const QUuid& domainID);
QString toJsonString();
bool isEmpty() { return _locationName.isNull() || _locationName.isEmpty(); }
bool isEmpty() { return _name.isNull() || _name.isEmpty(); }
void setLocationName(QString locationName) { _locationName = locationName; }
QString locationName() { return _locationName; }
void setName(QString name) { _name = name; }
const QString& getName() const { return _name; }
void setLocation(glm::vec3 location) { _location = location; }
glm::vec3 location() { return _location; }
void setLocation(glm::vec3 position) { _position = position; }
const glm::vec3& getPosition() const { return _position; }
void setOrientation(glm::quat orentation) { _orientation = orentation; }
glm::quat orientation() { return _orientation; }
void setOrientation(const glm::quat& orentation) { _orientation = orentation; }
const glm::quat& getOrientation() const { return _orientation; }
void setDomain(QString domain) { _domain = domain; }
QString domain() { return _domain; }
void setDomainID(const QUuid& domainID) { _domainID = domainID; }
const QUuid& getDomainID() const { return _domainID; }
signals:
void dataReceived(bool locationExists);
private:
QString _locationName;
QString _name;
QString _createdBy;
glm::vec3 _location;
glm::vec3 _position;
glm::quat _orientation;
QString _domain;
QUuid _domainID;
};

View file

@ -17,6 +17,8 @@
#include <QSizePolicy>
#include <QTimer>
#include <AccountManager.h>
#include "Application.h"
#include "ChatMessageArea.h"
#include "FlowLayout.h"
@ -28,7 +30,6 @@
#include "ChatWindow.h"
const int NUM_MESSAGES_TO_TIME_STAMP = 20;
const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?)|(?:hifi))://\\S+)");

View file

@ -11,6 +11,8 @@
#include <QtWebKitWidgets/QWebView>
#include <AccountManager.h>
#include "Application.h"
#include "OAuthWebViewHandler.h"

View file

@ -23,6 +23,8 @@
#include <QTimer>
#include <QWidget>
#include <NetworkAccessManager.h>
#include "Application.h"
#include "ScriptHighlighting.h"

View file

@ -9,7 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "../../Application.h"
#include <NetworkAccessManager.h>
#include "Application.h"
#include "BillboardOverlay.h"