Update LocationManager::goTo to use new addresses API

The new API address is now used for goTo when # or @ isn't present
Fixed the multiple locations popup to show when multiple locations are
found
This commit is contained in:
Ryan Huffman 2014-06-16 10:43:13 -07:00
parent 7ad6850327
commit af3b2a9d0f
5 changed files with 58 additions and 79 deletions

View file

@ -1002,7 +1002,9 @@ bool Menu::goToDestination(QString destination) {
} }
void Menu::goTo(QString destination) { void Menu::goTo(QString destination) {
LocationManager::getInstance().goTo(destination); LocationManager* manager = &LocationManager::getInstance();
manager->goTo(destination);
connect(manager, &LocationManager::multipleDestinationsFound, getInstance(), &Menu::multipleDestinationsDecision);
} }
void Menu::goTo() { void Menu::goTo() {
@ -1091,9 +1093,9 @@ void Menu::multipleDestinationsDecision(const QJsonObject& userData, const QJson
int userResponse = msgBox.exec(); int userResponse = msgBox.exec();
if (userResponse == QMessageBox::Ok) { if (userResponse == QMessageBox::Ok) {
Application::getInstance()->getAvatar()->goToLocationFromResponse(userData); Application::getInstance()->getAvatar()->goToLocationFromAddress(userData["address"].toObject());
} else if (userResponse == QMessageBox::Open) { } else if (userResponse == QMessageBox::Open) {
Application::getInstance()->getAvatar()->goToLocationFromResponse(userData); Application::getInstance()->getAvatar()->goToLocationFromAddress(placeData["address"].toObject());
} }
LocationManager* manager = reinterpret_cast<LocationManager*>(sender()); LocationManager* manager = reinterpret_cast<LocationManager*>(sender());

View file

@ -1626,44 +1626,46 @@ void MyAvatar::resetSize() {
} }
void MyAvatar::goToLocationFromResponse(const QJsonObject& jsonObject) { void MyAvatar::goToLocationFromResponse(const QJsonObject& jsonObject) {
if (jsonObject["status"].toString() == "success") { if (jsonObject["status"].toString() == "success") {
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
sendKillAvatar();
QJsonObject locationObject = jsonObject["data"].toObject()["address"].toObject(); QJsonObject locationObject = jsonObject["data"].toObject()["address"].toObject();
QString positionString = locationObject["position"].toString(); goToLocationFromAddress(locationObject);
QString orientationString = locationObject["orientation"].toString();
QString domainHostnameString = locationObject["domain"].toString();
qDebug() << "Changing domain to" << domainHostnameString <<
", position to" << positionString <<
", and orientation to" << orientationString;
QStringList coordinateItems = positionString.split(',');
QStringList orientationItems = orientationString.split(',');
NodeList::getInstance()->getDomainHandler().setHostname(domainHostnameString);
// orient the user to face the target
glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
orientationItems[1].toFloat(),
orientationItems[2].toFloat())))
* glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
setOrientation(newOrientation);
// move the user a couple units away
const float DISTANCE_TO_USER = 2.0f;
glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
setPosition(newPosition);
emit transformChanged();
} else { } else {
QMessageBox::warning(Application::getInstance()->getWindow(), "", "That user or location could not be found."); QMessageBox::warning(Application::getInstance()->getWindow(), "", "That user or location could not be found.");
} }
} }
void MyAvatar::goToLocationFromAddress(const QJsonObject& locationObject) {
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
sendKillAvatar();
QString positionString = locationObject["position"].toString();
QString orientationString = locationObject["orientation"].toString();
QString domainHostnameString = locationObject["domain"].toString();
qDebug() << "Changing domain to" << domainHostnameString <<
", position to" << positionString <<
", and orientation to" << orientationString;
QStringList coordinateItems = positionString.split(',');
QStringList orientationItems = orientationString.split(',');
NodeList::getInstance()->getDomainHandler().setHostname(domainHostnameString);
// orient the user to face the target
glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
orientationItems[1].toFloat(),
orientationItems[2].toFloat())))
* glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
setOrientation(newOrientation);
// move the user a couple units away
const float DISTANCE_TO_USER = 2.0f;
glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
setPosition(newPosition);
emit transformChanged();
}
void MyAvatar::updateMotionBehaviorsFromMenu() { void MyAvatar::updateMotionBehaviorsFromMenu() {
Menu* menu = Menu::getInstance(); Menu* menu = Menu::getInstance();
if (menu->isOptionChecked(MenuOption::ObeyEnvironmentalGravity)) { if (menu->isOptionChecked(MenuOption::ObeyEnvironmentalGravity)) {

View file

@ -129,6 +129,7 @@ public slots:
void resetSize(); void resetSize();
void goToLocationFromResponse(const QJsonObject& jsonObject); void goToLocationFromResponse(const QJsonObject& jsonObject);
void goToLocationFromAddress(const QJsonObject& jsonObject);
// Set/Get update the thrust that will move the avatar around // Set/Get update the thrust that will move the avatar around
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };

View file

@ -16,10 +16,11 @@
const QString GET_USER_ADDRESS = "/api/v1/users/%1/address"; const QString GET_USER_ADDRESS = "/api/v1/users/%1/address";
const QString GET_PLACE_ADDRESS = "/api/v1/places/%1/address"; const QString GET_PLACE_ADDRESS = "/api/v1/places/%1/address";
const QString GET_ADDRESSES = "/api/v1/addresses/%1";
const QString POST_PLACE_CREATE = "/api/v1/places/"; const QString POST_PLACE_CREATE = "/api/v1/places/";
LocationManager::LocationManager() : _userData(), _placeData() { LocationManager::LocationManager() {
}; };
@ -74,59 +75,37 @@ void LocationManager::goTo(QString destination) {
// go to coordinate destination or to Username // go to coordinate destination or to Username
if (!goToDestination(destination)) { if (!goToDestination(destination)) {
// reset data on local variables
_userData = QJsonObject();
_placeData = QJsonObject();
destination = QString(QUrl::toPercentEncoding(destination)); destination = QString(QUrl::toPercentEncoding(destination));
JSONCallbackParameters callbackParams; JSONCallbackParameters callbackParams;
callbackParams.jsonCallbackReceiver = this; callbackParams.jsonCallbackReceiver = this;
callbackParams.jsonCallbackMethod = "goToUserFromResponse"; callbackParams.jsonCallbackMethod = "goToAddressFromResponse";
AccountManager::getInstance().authenticatedRequest(GET_USER_ADDRESS.arg(destination), AccountManager::getInstance().authenticatedRequest(GET_ADDRESSES.arg(destination),
QNetworkAccessManager::GetOperation,
callbackParams);
callbackParams.jsonCallbackMethod = "goToLocationFromResponse";
AccountManager::getInstance().authenticatedRequest(GET_PLACE_ADDRESS.arg(destination),
QNetworkAccessManager::GetOperation, QNetworkAccessManager::GetOperation,
callbackParams); callbackParams);
} }
} }
void LocationManager::goToUserFromResponse(const QJsonObject& jsonObject) { void LocationManager::goToAddressFromResponse(const QJsonObject& responseData) {
_userData = jsonObject; QJsonValue status = responseData["status"];
checkForMultipleDestinations(); qDebug() << responseData;
} if (!status.isUndefined() && status.toString() == "success") {
const QJsonObject& data = responseData["data"].toObject();
const QJsonValue& userObject = data["user"];
const QJsonValue& placeObject = data["place"];
void LocationManager::goToLocationFromResponse(const QJsonObject& jsonObject) { if (!placeObject.isUndefined() && !userObject.isUndefined()) {
_placeData = jsonObject; emit multipleDestinationsFound(userObject.toObject(), placeObject.toObject());
checkForMultipleDestinations(); } else if (placeObject.isUndefined()) {
} Application::getInstance()->getAvatar()->goToLocationFromAddress(userObject.toObject()["address"].toObject());
} else {
void LocationManager::checkForMultipleDestinations() { Application::getInstance()->getAvatar()->goToLocationFromAddress(placeObject.toObject()["address"].toObject());
if (!_userData.isEmpty() && !_placeData.isEmpty()) {
if (_userData.contains("status") && _userData["status"].toString() == "success" &&
_placeData.contains("status") && _placeData["status"].toString() == "success") {
emit multipleDestinationsFound(_userData, _placeData);
return;
} }
} else {
if (_userData.contains("status") && _userData["status"].toString() == "success") {
Application::getInstance()->getAvatar()->goToLocationFromResponse(_userData);
return;
}
if (_placeData.contains("status") && _placeData["status"].toString() == "success") {
Application::getInstance()->getAvatar()->goToLocationFromResponse(_placeData);
return;
}
QMessageBox::warning(Application::getInstance()->getWindow(), "", "That user or location could not be found."); QMessageBox::warning(Application::getInstance()->getWindow(), "", "That user or location could not be found.");
} }
} }
void LocationManager::goToUser(QString userName) { void LocationManager::goToUser(QString userName) {
JSONCallbackParameters callbackParams; JSONCallbackParameters callbackParams;
callbackParams.jsonCallbackReceiver = Application::getInstance()->getAvatar(); callbackParams.jsonCallbackReceiver = Application::getInstance()->getAvatar();
callbackParams.jsonCallbackMethod = "goToLocationFromResponse"; callbackParams.jsonCallbackMethod = "goToLocationFromResponse";

View file

@ -39,11 +39,7 @@ public:
bool goToDestination(QString destination); bool goToDestination(QString destination);
private: private:
QJsonObject _userData;
QJsonObject _placeData;
void replaceLastOccurrence(const QChar search, const QChar replace, QString& string); void replaceLastOccurrence(const QChar search, const QChar replace, QString& string);
void checkForMultipleDestinations();
signals: signals:
void creationCompleted(LocationManager::NamedLocationCreateResponse response); void creationCompleted(LocationManager::NamedLocationCreateResponse response);
@ -52,8 +48,7 @@ signals:
private slots: private slots:
void namedLocationDataReceived(const QJsonObject& data); void namedLocationDataReceived(const QJsonObject& data);
void errorDataReceived(QNetworkReply::NetworkError error, const QString& message); void errorDataReceived(QNetworkReply::NetworkError error, const QString& message);
void goToLocationFromResponse(const QJsonObject& jsonObject); void goToAddressFromResponse(const QJsonObject& jsonObject);
void goToUserFromResponse(const QJsonObject& jsonObject);
}; };