History

repairs for new location lookup

Stephen Birarda committed 12 years ago

Commit 74295a31 parent 745edb84 files · +31 −25Browse files

Showing the changes to interface/src/UserLocationsModel.cpp (1 of 4 files). Show all

Unified · Split

interface/src/UserLocationsModel.cpp+23−18
@@ -18,14 +18,13 @@ · 17 unmodified lines
1818 #include "Application.h"
1919 #include "UserLocationsModel.h"
2020
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";
2423
25−UserLocation::UserLocation(QString id, QString name, QString location) :
24+UserLocation::UserLocation(const QString& id, const QString& name, const QString& address) :
2625 _id(id),
2726 _name(name),
28− _location(location),
27+ _address(address),
2928 _previousName(name),
3029 _updating(false) {
3130 }
@@ -35,10 +34,15 @@ void UserLocation::requestRename(const QString& newName) { · 3 unmodified lines
3534 _updating = true;
3635
3736 JSONCallbackParameters callbackParams(this, "handleRenameResponse", this, "handleRenameError");
37+
3838 QJsonObject jsonNameObject;
39− jsonNameObject.insert("name", QJsonValue(newName));
39+ jsonNameObject.insert("name", newName);
40+
41+ QJsonObject locationObject;
42+ locationObject.insert("location", jsonNameObject);
43+
4044 QJsonDocument jsonDocument(jsonNameObject);
41− AccountManager::getInstance().authenticatedRequest(PLACES_UPDATE.arg(_id),
45+ AccountManager::getInstance().authenticatedRequest(LOCATION_UPDATE_OR_DELETE.arg(_id),
4246 QNetworkAccessManager::PutOperation,
4347 callbackParams,
4448 jsonDocument.toJson());
@@ -54,7 +58,9 @@ void UserLocation::handleRenameResponse(const QJsonObject& responseData) { · 9 unmodified lines
5458
5559 QJsonValue status = responseData["status"];
5660 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;
5864 _name = updatedName;
5965 } else {
6066 _name = _previousName;
@@ -90,7 +96,7 @@ void UserLocation::requestDelete() { · 29 unmodified lines
9096 _updating = true;
9197
9298 JSONCallbackParameters callbackParams(this, "handleDeleteResponse", this, "handleDeleteError");
93− AccountManager::getInstance().authenticatedRequest(PLACES_DELETE.arg(_id),
99+ AccountManager::getInstance().authenticatedRequest(LOCATION_UPDATE_OR_DELETE.arg(_id),
94100 QNetworkAccessManager::DeleteOperation,
95101 callbackParams);
96102 }
@@ -153,7 +159,7 @@ void UserLocationsModel::refresh() { · 56 unmodified lines
153159 endResetModel();
154160
155161 JSONCallbackParameters callbackParams(this, "handleLocationsResponse");
156− AccountManager::getInstance().authenticatedRequest(PLACES_GET,
162+ AccountManager::getInstance().authenticatedRequest(LOCATIONS_GET,
157163 QNetworkAccessManager::GetOperation,
158164 callbackParams);
159165 }
@@ -165,14 +171,13 @@ void UserLocationsModel::handleLocationsResponse(const QJsonObject& responseData · 5 unmodified lines
165171 QJsonValue status = responseData["status"];
166172 if (!status.isUndefined() && status.toString() == "success") {
167173 beginResetModel();
168− QJsonArray locations = responseData["data"].toObject()["places"].toArray();
174+ QJsonArray locations = responseData["data"].toObject()["locations"].toArray();
169175 for (QJsonArray::const_iterator it = locations.constBegin(); it != locations.constEnd(); it++) {
170176 QJsonObject location = (*it).toObject();
171− QJsonObject address = location["address"].toObject();
177+ QString locationAddress = "hifi://" + location["domain"].toObject()["name"].toString()
178+ + location["path"].toString();
172179 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);
176181 _locations.append(userLocation);
177182 connect(userLocation, &UserLocation::deleted, this, &UserLocationsModel::removeLocation);
178183 connect(userLocation, &UserLocation::updated, this, &UserLocationsModel::update);
@@ -214,8 +219,8 @@ QVariant UserLocationsModel::data(const QModelIndex& index, int role) const { · 35 unmodified lines
214219 return QVariant();
215220 } else if (index.column() == NameColumn) {
216221 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());
219224 }
220225 }
221226
@@ -226,7 +231,7 @@ QVariant UserLocationsModel::headerData(int section, Qt::Orientation orientation · 4 unmodified lines
226231 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
227232 switch (section) {
228233 case NameColumn: return "Name";
229− case LocationColumn: return "Location";
234+ case AddressColumn: return "Address";
230235 default: return QVariant();
231236 }
232237 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t