From 74295a3869baff209f6e12db6515819249ce540d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 12 Sep 2014 09:52:34 -0700 Subject: [PATCH] repairs for new location lookup --- interface/src/Menu.h | 1 + interface/src/UserLocationsModel.cpp | 41 +++++++++++++----------- interface/src/UserLocationsModel.h | 12 +++---- interface/src/ui/UserLocationsDialog.cpp | 2 +- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/interface/src/Menu.h b/interface/src/Menu.h index d8658f956e..fabaa0dce7 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -390,6 +390,7 @@ namespace MenuOption { const QString FullscreenMirror = "Fullscreen Mirror"; const QString GlowMode = "Cycle Glow Mode"; const QString GlowWhenSpeaking = "Glow When Speaking"; + const QString GoToUser = "Go To User"; const QString HeadMouse = "Head Mouse"; const QString IncreaseAvatarSize = "Increase Avatar Size"; const QString IncreaseVoxelSize = "Increase Voxel Size"; diff --git a/interface/src/UserLocationsModel.cpp b/interface/src/UserLocationsModel.cpp index 0a035faedd..0fae0d8800 100644 --- a/interface/src/UserLocationsModel.cpp +++ b/interface/src/UserLocationsModel.cpp @@ -18,14 +18,13 @@ #include "Application.h" #include "UserLocationsModel.h" -static const QString PLACES_GET = "/api/v1/places"; -static const QString PLACES_UPDATE = "/api/v1/places/%1"; -static const QString PLACES_DELETE= "/api/v1/places/%1"; +static const QString LOCATIONS_GET = "/api/v1/locations"; +static const QString LOCATION_UPDATE_OR_DELETE = "/api/v1/locations/%1"; -UserLocation::UserLocation(QString id, QString name, QString location) : +UserLocation::UserLocation(const QString& id, const QString& name, const QString& address) : _id(id), _name(name), - _location(location), + _address(address), _previousName(name), _updating(false) { } @@ -35,10 +34,15 @@ void UserLocation::requestRename(const QString& newName) { _updating = true; JSONCallbackParameters callbackParams(this, "handleRenameResponse", this, "handleRenameError"); + QJsonObject jsonNameObject; - jsonNameObject.insert("name", QJsonValue(newName)); + jsonNameObject.insert("name", newName); + + QJsonObject locationObject; + locationObject.insert("location", jsonNameObject); + QJsonDocument jsonDocument(jsonNameObject); - AccountManager::getInstance().authenticatedRequest(PLACES_UPDATE.arg(_id), + AccountManager::getInstance().authenticatedRequest(LOCATION_UPDATE_OR_DELETE.arg(_id), QNetworkAccessManager::PutOperation, callbackParams, jsonDocument.toJson()); @@ -54,7 +58,9 @@ void UserLocation::handleRenameResponse(const QJsonObject& responseData) { QJsonValue status = responseData["status"]; if (!status.isUndefined() && status.toString() == "success") { - QString updatedName = responseData["data"].toObject()["name"].toString(); + qDebug() << responseData; + QString updatedName = responseData["data"].toObject()["location"].toObject()["name"].toString(); + qDebug() << "The updated name is" << updatedName; _name = updatedName; } else { _name = _previousName; @@ -90,7 +96,7 @@ void UserLocation::requestDelete() { _updating = true; JSONCallbackParameters callbackParams(this, "handleDeleteResponse", this, "handleDeleteError"); - AccountManager::getInstance().authenticatedRequest(PLACES_DELETE.arg(_id), + AccountManager::getInstance().authenticatedRequest(LOCATION_UPDATE_OR_DELETE.arg(_id), QNetworkAccessManager::DeleteOperation, callbackParams); } @@ -153,7 +159,7 @@ void UserLocationsModel::refresh() { endResetModel(); JSONCallbackParameters callbackParams(this, "handleLocationsResponse"); - AccountManager::getInstance().authenticatedRequest(PLACES_GET, + AccountManager::getInstance().authenticatedRequest(LOCATIONS_GET, QNetworkAccessManager::GetOperation, callbackParams); } @@ -165,14 +171,13 @@ void UserLocationsModel::handleLocationsResponse(const QJsonObject& responseData QJsonValue status = responseData["status"]; if (!status.isUndefined() && status.toString() == "success") { beginResetModel(); - QJsonArray locations = responseData["data"].toObject()["places"].toArray(); + QJsonArray locations = responseData["data"].toObject()["locations"].toArray(); for (QJsonArray::const_iterator it = locations.constBegin(); it != locations.constEnd(); it++) { QJsonObject location = (*it).toObject(); - QJsonObject address = location["address"].toObject(); + QString locationAddress = "hifi://" + location["domain"].toObject()["name"].toString() + + location["path"].toString(); UserLocation* userLocation = new UserLocation(location["id"].toString(), location["name"].toString(), - "hifi://" + address["domain"].toString() - + "/" + address["position"].toString() - + "/" + address["orientation"].toString()); + locationAddress); _locations.append(userLocation); connect(userLocation, &UserLocation::deleted, this, &UserLocationsModel::removeLocation); connect(userLocation, &UserLocation::updated, this, &UserLocationsModel::update); @@ -214,8 +219,8 @@ QVariant UserLocationsModel::data(const QModelIndex& index, int role) const { return QVariant(); } else if (index.column() == NameColumn) { return _locations[index.row()]->name(); - } else if (index.column() == LocationColumn) { - return QVariant(_locations[index.row()]->location()); + } else if (index.column() == AddressColumn) { + return QVariant(_locations[index.row()]->address()); } } @@ -226,7 +231,7 @@ QVariant UserLocationsModel::headerData(int section, Qt::Orientation orientation if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { switch (section) { case NameColumn: return "Name"; - case LocationColumn: return "Location"; + case AddressColumn: return "Address"; default: return QVariant(); } } diff --git a/interface/src/UserLocationsModel.h b/interface/src/UserLocationsModel.h index 4a1eb9fd0a..54518d72e1 100644 --- a/interface/src/UserLocationsModel.h +++ b/interface/src/UserLocationsModel.h @@ -20,14 +20,14 @@ class UserLocation : public QObject { Q_OBJECT public: - UserLocation(QString id, QString name, QString location); + UserLocation(const QString& id, const QString& name, const QString& address); bool isUpdating() { return _updating; } void requestRename(const QString& newName); void requestDelete(); - QString id() { return _id; } - QString name() { return _name; } - QString location() { return _location; } + const QString& id() { return _id; } + const QString& name() { return _name; } + const QString& address() { return _address; } public slots: void handleRenameResponse(const QJsonObject& responseData); @@ -42,7 +42,7 @@ signals: private: QString _id; QString _name; - QString _location; + QString _address; QString _previousName; bool _updating; @@ -65,7 +65,7 @@ public: enum Columns { NameColumn = 0, - LocationColumn + AddressColumn }; public slots: diff --git a/interface/src/ui/UserLocationsDialog.cpp b/interface/src/ui/UserLocationsDialog.cpp index ca1a9b5ad6..5aed0c3df4 100644 --- a/interface/src/ui/UserLocationsDialog.cpp +++ b/interface/src/ui/UserLocationsDialog.cpp @@ -51,7 +51,7 @@ void UserLocationsDialog::updateEnabled() { } void UserLocationsDialog::goToModelIndex(const QModelIndex& index) { - QVariant location = _proxyModel.data(index.sibling(index.row(), UserLocationsModel::LocationColumn)); + QVariant location = _proxyModel.data(index.sibling(index.row(), UserLocationsModel::AddressColumn)); // Menu::getInstance()->goToURL(location.toString()); }