Showing the changes to interface/src/UserLocationsModel.cpp (1 of 4 files). Show all
Unified · Split
| @@ -18,14 +18,13 @@ · 17 unmodified lines | |||
| 18 | #include "Application.h" | 18 | #include "Application.h" |
| 19 | #include "UserLocationsModel.h" | 19 | #include "UserLocationsModel.h" |
| 20 | 20 | ||
| 21 | static const QString PLACES_GET = "/api/v1/places"; | 21 | static const QString LOCATIONS_GET = "/api/v1/locations"; |
| 22 | static const QString PLACES_UPDATE = "/api/v1/places/%1"; | 22 | static const QString LOCATION_UPDATE_OR_DELETE = "/api/v1/locations/%1"; |
| 23 | static const QString PLACES_DELETE= "/api/v1/places/%1"; | ||
| 24 | 23 | ||
| 25 | UserLocation::UserLocation(QString id, QString name, QString location) : | 24 | UserLocation::UserLocation(const QString& id, const QString& name, const QString& address) : |
| 26 | _id(id), | 25 | _id(id), |
| 27 | _name(name), | 26 | _name(name), |
| 28 | _location(location), | 27 | _address(address), |
| 29 | _previousName(name), | 28 | _previousName(name), |
| 30 | _updating(false) { | 29 | _updating(false) { |
| 31 | } | 30 | } |
| @@ -35,10 +34,15 @@ void UserLocation::requestRename(const QString& newName) { · 3 unmodified lines | |||
| 35 | _updating = true; | 34 | _updating = true; |
| 36 | 35 | ||
| 37 | JSONCallbackParameters callbackParams(this, "handleRenameResponse", this, "handleRenameError"); | 36 | JSONCallbackParameters callbackParams(this, "handleRenameResponse", this, "handleRenameError"); |
| 37 | |||
| 38 | QJsonObject jsonNameObject; | 38 | QJsonObject jsonNameObject; |
| 39 | jsonNameObject.insert("name", QJsonValue(newName)); | 39 | jsonNameObject.insert("name", newName); |
| 40 | |||
| 41 | QJsonObject locationObject; | ||
| 42 | locationObject.insert("location", jsonNameObject); | ||
| 43 | |||
| 40 | QJsonDocument jsonDocument(jsonNameObject); | 44 | QJsonDocument jsonDocument(jsonNameObject); |
| 41 | AccountManager::getInstance().authenticatedRequest(PLACES_UPDATE.arg(_id), | 45 | AccountManager::getInstance().authenticatedRequest(LOCATION_UPDATE_OR_DELETE.arg(_id), |
| 42 | QNetworkAccessManager::PutOperation, | 46 | QNetworkAccessManager::PutOperation, |
| 43 | callbackParams, | 47 | callbackParams, |
| 44 | jsonDocument.toJson()); | 48 | jsonDocument.toJson()); |
| @@ -54,7 +58,9 @@ void UserLocation::handleRenameResponse(const QJsonObject& responseData) { · 9 unmodified lines | |||
| 54 | 58 | ||
| 55 | QJsonValue status = responseData["status"]; | 59 | QJsonValue status = responseData["status"]; |
| 56 | if (!status.isUndefined() && status.toString() == "success") { | 60 | if (!status.isUndefined() && status.toString() == "success") { |
| 57 | QString updatedName = responseData["data"].toObject()["name"].toString(); | 61 | qDebug() << responseData; |
| 62 | QString updatedName = responseData["data"].toObject()["location"].toObject()["name"].toString(); | ||
| 63 | qDebug() << "The updated name is" << updatedName; | ||
| 58 | _name = updatedName; | 64 | _name = updatedName; |
| 59 | } else { | 65 | } else { |
| 60 | _name = _previousName; | 66 | _name = _previousName; |
| @@ -90,7 +96,7 @@ void UserLocation::requestDelete() { · 29 unmodified lines | |||
| 90 | _updating = true; | 96 | _updating = true; |
| 91 | 97 | ||
| 92 | JSONCallbackParameters callbackParams(this, "handleDeleteResponse", this, "handleDeleteError"); | 98 | JSONCallbackParameters callbackParams(this, "handleDeleteResponse", this, "handleDeleteError"); |
| 93 | AccountManager::getInstance().authenticatedRequest(PLACES_DELETE.arg(_id), | 99 | AccountManager::getInstance().authenticatedRequest(LOCATION_UPDATE_OR_DELETE.arg(_id), |
| 94 | QNetworkAccessManager::DeleteOperation, | 100 | QNetworkAccessManager::DeleteOperation, |
| 95 | callbackParams); | 101 | callbackParams); |
| 96 | } | 102 | } |
| @@ -153,7 +159,7 @@ void UserLocationsModel::refresh() { · 56 unmodified lines | |||
| 153 | endResetModel(); | 159 | endResetModel(); |
| 154 | 160 | ||
| 155 | JSONCallbackParameters callbackParams(this, "handleLocationsResponse"); | 161 | JSONCallbackParameters callbackParams(this, "handleLocationsResponse"); |
| 156 | AccountManager::getInstance().authenticatedRequest(PLACES_GET, | 162 | AccountManager::getInstance().authenticatedRequest(LOCATIONS_GET, |
| 157 | QNetworkAccessManager::GetOperation, | 163 | QNetworkAccessManager::GetOperation, |
| 158 | callbackParams); | 164 | callbackParams); |
| 159 | } | 165 | } |
| @@ -165,14 +171,13 @@ void UserLocationsModel::handleLocationsResponse(const QJsonObject& responseData · 5 unmodified lines | |||
| 165 | QJsonValue status = responseData["status"]; | 171 | QJsonValue status = responseData["status"]; |
| 166 | if (!status.isUndefined() && status.toString() == "success") { | 172 | if (!status.isUndefined() && status.toString() == "success") { |
| 167 | beginResetModel(); | 173 | beginResetModel(); |
| 168 | QJsonArray locations = responseData["data"].toObject()["places"].toArray(); | 174 | QJsonArray locations = responseData["data"].toObject()["locations"].toArray(); |
| 169 | for (QJsonArray::const_iterator it = locations.constBegin(); it != locations.constEnd(); it++) { | 175 | for (QJsonArray::const_iterator it = locations.constBegin(); it != locations.constEnd(); it++) { |
| 170 | QJsonObject location = (*it).toObject(); | 176 | QJsonObject location = (*it).toObject(); |
| 171 | QJsonObject address = location["address"].toObject(); | 177 | QString locationAddress = "hifi://" + location["domain"].toObject()["name"].toString() |
| 178 | + location["path"].toString(); | ||
| 172 | UserLocation* userLocation = new UserLocation(location["id"].toString(), location["name"].toString(), | 179 | UserLocation* userLocation = new UserLocation(location["id"].toString(), location["name"].toString(), |
| 173 | "hifi://" + address["domain"].toString() | 180 | locationAddress); |
| 174 | + "/" + address["position"].toString() | ||
| 175 | + "/" + address["orientation"].toString()); | ||
| 176 | _locations.append(userLocation); | 181 | _locations.append(userLocation); |
| 177 | connect(userLocation, &UserLocation::deleted, this, &UserLocationsModel::removeLocation); | 182 | connect(userLocation, &UserLocation::deleted, this, &UserLocationsModel::removeLocation); |
| 178 | connect(userLocation, &UserLocation::updated, this, &UserLocationsModel::update); | 183 | connect(userLocation, &UserLocation::updated, this, &UserLocationsModel::update); |
| @@ -214,8 +219,8 @@ QVariant UserLocationsModel::data(const QModelIndex& index, int role) const { · 35 unmodified lines | |||
| 214 | return QVariant(); | 219 | return QVariant(); |
| 215 | } else if (index.column() == NameColumn) { | 220 | } else if (index.column() == NameColumn) { |
| 216 | return _locations[index.row()]->name(); | 221 | return _locations[index.row()]->name(); |
| 217 | } else if (index.column() == LocationColumn) { | 222 | } else if (index.column() == AddressColumn) { |
| 218 | return QVariant(_locations[index.row()]->location()); | 223 | return QVariant(_locations[index.row()]->address()); |
| 219 | } | 224 | } |
| 220 | } | 225 | } |
| 221 | 226 | ||
| @@ -226,7 +231,7 @@ QVariant UserLocationsModel::headerData(int section, Qt::Orientation orientation · 4 unmodified lines | |||
| 226 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { | 231 | if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { |
| 227 | switch (section) { | 232 | switch (section) { |
| 228 | case NameColumn: return "Name"; | 233 | case NameColumn: return "Name"; |
| 229 | case LocationColumn: return "Location"; | 234 | case AddressColumn: return "Address"; |
| 230 | default: return QVariant(); | 235 | default: return QVariant(); |
| 231 | } | 236 | } |
| 232 | } | 237 | } |