mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
fix error handling for location naming
This commit is contained in:
parent
5f6563f4c9
commit
745edb8b0a
10 changed files with 63 additions and 42 deletions
|
@ -154,11 +154,6 @@ Menu::Menu() :
|
|||
appInstance, SLOT(toggleRunningScriptsWidget()));
|
||||
|
||||
addDisabledActionAndSeparator(fileMenu, "Go");
|
||||
addActionToQMenuAndActionHash(fileMenu,
|
||||
MenuOption::GoHome,
|
||||
Qt::CTRL | Qt::Key_G,
|
||||
appInstance->getAvatar(),
|
||||
SLOT(goHome()));
|
||||
addActionToQMenuAndActionHash(fileMenu,
|
||||
MenuOption::NameLocation,
|
||||
Qt::CTRL | Qt::Key_N,
|
||||
|
@ -1183,23 +1178,13 @@ void Menu::muteEnvironment() {
|
|||
free(packet);
|
||||
}
|
||||
|
||||
void Menu::namedLocationCreated(LocationManager::NamedLocationCreateResponse response) {
|
||||
void Menu::displayNameLocationResponse(const QString& errorString) {
|
||||
|
||||
if (response == LocationManager::Created) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox msgBox;
|
||||
switch (response) {
|
||||
case LocationManager::AlreadyExists:
|
||||
msgBox.setText("That name has been already claimed, try something else.");
|
||||
break;
|
||||
default:
|
||||
msgBox.setText("An unexpected error has occurred, please try again later.");
|
||||
break;
|
||||
}
|
||||
|
||||
msgBox.exec();
|
||||
if (!errorString.isEmpty()) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(errorString);
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::toggleLocationList() {
|
||||
|
@ -1259,7 +1244,7 @@ void Menu::nameLocation() {
|
|||
|
||||
MyAvatar* myAvatar = Application::getInstance()->getAvatar();
|
||||
LocationManager* manager = new LocationManager();
|
||||
connect(manager, &LocationManager::creationCompleted, this, &Menu::namedLocationCreated);
|
||||
connect(manager, &LocationManager::creationCompleted, this, &Menu::displayNameLocationResponse);
|
||||
NamedLocation* location = new NamedLocation(locationName,
|
||||
myAvatar->getPosition(), myAvatar->getOrientation(),
|
||||
domainHandler.getUUID());
|
||||
|
|
|
@ -216,7 +216,7 @@ private slots:
|
|||
void toggleConsole();
|
||||
void toggleChat();
|
||||
void audioMuteToggled();
|
||||
void namedLocationCreated(LocationManager::NamedLocationCreateResponse response);
|
||||
void displayNameLocationResponse(const QString& errorString);
|
||||
void muteEnvironment();
|
||||
|
||||
private:
|
||||
|
@ -390,7 +390,6 @@ namespace MenuOption {
|
|||
const QString FullscreenMirror = "Fullscreen Mirror";
|
||||
const QString GlowMode = "Cycle Glow Mode";
|
||||
const QString GlowWhenSpeaking = "Glow When Speaking";
|
||||
const QString GoHome = "Go Home";
|
||||
const QString HeadMouse = "Head Mouse";
|
||||
const QString IncreaseAvatarSize = "Increase Avatar Size";
|
||||
const QString IncreaseVoxelSize = "Increase Voxel Size";
|
||||
|
|
|
@ -75,10 +75,10 @@ void UserLocation::handleRenameResponse(const QJsonObject& responseData) {
|
|||
emit updated(_name);
|
||||
}
|
||||
|
||||
void UserLocation::handleRenameError(QNetworkReply::NetworkError error, const QString& errorString) {
|
||||
void UserLocation::handleRenameError(QNetworkReply& errorReply) {
|
||||
_updating = false;
|
||||
|
||||
QString msg = "There was an error renaming location '" + _name + "': " + errorString;
|
||||
QString msg = "There was an error renaming location '" + _name + "': " + errorReply.errorString();
|
||||
qDebug() << msg;
|
||||
QMessageBox::warning(Application::getInstance()->getWindow(), "Error", msg);
|
||||
|
||||
|
@ -109,10 +109,10 @@ void UserLocation::handleDeleteResponse(const QJsonObject& responseData) {
|
|||
}
|
||||
}
|
||||
|
||||
void UserLocation::handleDeleteError(QNetworkReply::NetworkError error, const QString& errorString) {
|
||||
void UserLocation::handleDeleteError(QNetworkReply& errorReply) {
|
||||
_updating = false;
|
||||
|
||||
QString msg = "There was an error deleting location '" + _name + "': " + errorString;
|
||||
QString msg = "There was an error deleting location '" + _name + "': " + errorReply.errorString();
|
||||
qDebug() << msg;
|
||||
QMessageBox::warning(Application::getInstance()->getWindow(), "Error", msg);
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ public:
|
|||
|
||||
public slots:
|
||||
void handleRenameResponse(const QJsonObject& responseData);
|
||||
void handleRenameError(QNetworkReply::NetworkError error, const QString& errorString);
|
||||
void handleRenameError(QNetworkReply& errorReply);
|
||||
void handleDeleteResponse(const QJsonObject& responseData);
|
||||
void handleDeleteError(QNetworkReply::NetworkError error, const QString& errorString);
|
||||
void handleDeleteError(QNetworkReply& errorReply);
|
||||
|
||||
signals:
|
||||
void updated(const QString& name);
|
||||
|
|
|
@ -1778,11 +1778,6 @@ void MyAvatar::maybeUpdateBillboard() {
|
|||
sendBillboardPacket();
|
||||
}
|
||||
|
||||
void MyAvatar::goHome() {
|
||||
qDebug("Going Home!");
|
||||
slamPosition(START_LOCATION);
|
||||
}
|
||||
|
||||
void MyAvatar::increaseSize() {
|
||||
if ((1.0f + SCALING_RATIO) * _targetScale < MAX_AVATAR_SCALE) {
|
||||
_targetScale *= (1.0f + SCALING_RATIO);
|
||||
|
|
|
@ -150,7 +150,6 @@ public:
|
|||
const PlayerPointer getPlayer() const { return _player; }
|
||||
|
||||
public slots:
|
||||
void goHome();
|
||||
void increaseSize();
|
||||
void decreaseSize();
|
||||
void resetSize();
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <qjsonobject.h>
|
||||
|
||||
#include <AccountManager.h>
|
||||
|
||||
#include "LocationManager.h"
|
||||
|
@ -20,15 +22,17 @@ LocationManager& LocationManager::getInstance() {
|
|||
return sharedInstance;
|
||||
}
|
||||
|
||||
const QString UNKNOWN_ERROR_MESSAGE = "Unknown error creating named location. Please try again!";
|
||||
|
||||
void LocationManager::namedLocationDataReceived(const QJsonObject& data) {
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.contains("status") && data["status"].toString() == "success") {
|
||||
emit creationCompleted(LocationManager::Created);
|
||||
emit creationCompleted(QString());
|
||||
} else {
|
||||
emit creationCompleted(LocationManager::AlreadyExists);
|
||||
emit creationCompleted(UNKNOWN_ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,3 +49,41 @@ void LocationManager::createNamedLocation(NamedLocation* namedLocation) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define hifi_LocationManager_h
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
#include "NamedLocation.h"
|
||||
|
||||
|
@ -31,10 +32,11 @@ public:
|
|||
void createNamedLocation(NamedLocation* namedLocation);
|
||||
|
||||
signals:
|
||||
void creationCompleted(LocationManager::NamedLocationCreateResponse response);
|
||||
void creationCompleted(const QString& errorMessage);
|
||||
|
||||
private slots:
|
||||
void namedLocationDataReceived(const QJsonObject& data);
|
||||
void errorDataReceived(QNetworkReply& errorReply);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ NamedLocation::NamedLocation(const QString& name,
|
|||
|
||||
}
|
||||
|
||||
const QString JSON_FORMAT = "{\"location\":{\"path\":\"%1\",\"domain_id\":\"%2\"},\"name\":\"%3\"}";
|
||||
const QString JSON_FORMAT = "{\"location\":{\"path\":\"%1\",\"domain_id\":\"%2\",\"name\":\"%3\"}}";
|
||||
|
||||
QString NamedLocation::toJsonString() {
|
||||
return JSON_FORMAT.arg(AddressManager::pathForPositionAndOrientation(_position, true, _orientation),
|
||||
|
|
|
@ -292,8 +292,7 @@ void AccountManager::passErrorToCallback(QNetworkReply* requestReply) {
|
|||
if (callbackParams.errorCallbackReceiver) {
|
||||
// invoke the right method on the callback receiver
|
||||
QMetaObject::invokeMethod(callbackParams.errorCallbackReceiver, qPrintable(callbackParams.errorCallbackMethod),
|
||||
Q_ARG(QNetworkReply::NetworkError, requestReply->error()),
|
||||
Q_ARG(const QString&, requestReply->errorString()));
|
||||
Q_ARG(QNetworkReply&, *requestReply));
|
||||
|
||||
// remove the related reply-callback group from the map
|
||||
_pendingCallbackMap.remove(requestReply);
|
||||
|
|
Loading…
Reference in a new issue