- Timestamp:
- Sep 17, 2015, 9:11:21 PM (11 years ago)
- Branches:
- master
- Children:
- a2330fc
- Parents:
- e498070
- Location:
- src/lib
- Files:
-
- 3 edited
-
silibconfig.h.in (modified) (1 diff)
-
siwebserviceclient.cpp (modified) (4 diffs)
-
siwebserviceclient.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/lib/silibconfig.h.in
re498070 r915dc18 1 1 /* 2 Copyright (C) 201 0 - 2012EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.2 Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 3 3 4 4 This library is free software; you can redistribute it and/or -
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 -
src/lib/siwebserviceclient.h
re498070 r915dc18 48 48 * @brief Registers a station at the server and emits error() or finishedStationsRegister() if finished. 49 49 */ 50 ReplyType stationsRegister( SiWeatherStation station, QString &error);50 ReplyType stationsRegister(const SiWeather::Library::SiWeatherStation& station, QString& error); 51 51 52 52 signals: 53 void error( ReplyType replyType, const QString &errorMessage) const;53 void error(SiWeather::Library::SiWebserviceClient::ReplyType replyType, const QString &errorMessage) const; 54 54 /** 55 55 * @brief Generic finish signal for all requests. Use specialized finished signals instead! … … 57 57 * @see finishedStationsRegister 58 58 */ 59 void finished( ReplyType replyType, const QByteArray &data) const;59 void finished(SiWeather::Library::SiWebserviceClient::ReplyType replyType, bool result, const QByteArray &data) const; 60 60 void finishedStationsRegister(bool result, const QUuid &uuid, const QString &message) const; 61 61
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)