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