Changeset 915dc18 for src/lib/siwebserviceclient.cpp
- Timestamp:
- Sep 17, 2015, 9:11:21 PM (11 years ago)
- Branches:
- master
- Children:
- a2330fc
- Parents:
- e498070
- File:
-
- 1 edited
-
src/lib/siwebserviceclient.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/lib/siwebserviceclient.cpp
re498070 r915dc18 45 45 } 46 46 47 SiWebserviceClient::ReplyType SiWebserviceClient::stationsRegister( SiWeatherStationstation, QString &error)47 SiWebserviceClient::ReplyType SiWebserviceClient::stationsRegister(const SiWeatherStation &station, QString &error) 48 48 { 49 49 if(!_networkManager) 50 50 return Error; 51 51 52 if(station.name().isEmpty() || station.city().isEmpty() || station.eMail().isEmpty() ){52 if(station.name().isEmpty() || station.city().isEmpty() || station.eMail().isEmpty() || station.type().isEmpty()){ 53 53 error = tr("Station has empty name, city or eMail address. All of these are needed!"); 54 54 return Error; … … 61 61 jsonStation["latitude"] = Library::geoCoordinateToString(station.latitude()); 62 62 jsonStation["email"] = station.eMail(); 63 jsonStation["type"] = station.type(); 64 jsonStation["typeUrl"] = station.typeUrl().toString(); 63 65 QJsonDocument jsonDocument(jsonStation); 64 66 65 67 QNetworkRequest request; 66 request.setUrl(QString("%1%2").arg(_baseUrl.toString()).arg(" /stations/register"));68 request.setUrl(QString("%1%2").arg(_baseUrl.toString()).arg("index.php/stations/register")); 67 69 request.setRawHeader("User-Agent", QString("SiWeather Library %1").arg(Library::version()).toUtf8()); 68 70 request.setHeader(QNetworkRequest::ContentTypeHeader, … … 81 83 82 84 QByteArray data = reply->readAll(); 83 QJsonDocument jsonDocument = QJsonDocument::fromBinaryData(data); 85 reply->deleteLater(); 86 87 QJsonDocument jsonDocument = QJsonDocument::fromJson(data); 84 88 QJsonObject json = jsonDocument.object(); 85 89 if(!json.contains("result")){ 86 90 emit finishedStationsRegister(false, "", tr("No result in response found")); 91 emit finished(StationsRegister, false, data); 87 92 return; 88 93 } 89 94 if(json["result"].toString() != "success"){ 90 95 emit finishedStationsRegister(false, "", tr("Operation failed for reason: %1").arg(json["message"].toString())); 96 emit finished(StationsRegister, false, data); 91 97 return; 92 98 } 93 99 if(!json.contains("uuid")){ 94 100 emit finishedStationsRegister(false, "", tr("No uuid in response found")); 101 emit finished(StationsRegister, false, data); 95 102 return; 96 103 } 97 emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), ""); 98 emit finished(StationsRegister, data); 99 reply->deleteLater(); 104 emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), json["message"].toString()); 105 emit finished(StationsRegister, false, data); 100 106 } 101 107 … … 120 126 return reply; 121 127 } 122
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/siweather/chrome/site/your_project_logo.png)