Changeset 17ef75d
- Timestamp:
- Sep 23, 2015, 6:35:24 PM (11 years ago)
- Branches:
- master
- Children:
- f8c242e
- Parents:
- 93ea008
- Location:
- src
- Files:
-
- 6 edited
-
clientcommandline/inputoutputhandler.cpp (modified) (1 diff)
-
clientcommandline/inputoutputhandler.h (modified) (1 diff)
-
clientcommandline/siweatherclientconfig.h.in (modified) (1 diff)
-
clientcommandline/stationsregister.cpp (modified) (3 diffs)
-
clientcommandline/stationsregister.h (modified) (2 diffs)
-
lib/siwebserviceclient.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/clientcommandline/inputoutputhandler.cpp
r93ea008 r17ef75d 46 46 return QString(); 47 47 48 _in->skipWhiteSpace(); //Important line! 49 return _in->readLine(); 48 QString line = _in->readLine(); 49 return line.trimmed(); 50 } 51 52 void InputOutputHandler::setFieldWidth(int columns) 53 { 54 if(!_out) 55 return; 56 _out->setFieldWidth(columns); 57 _out->setFieldAlignment(QTextStream::AlignLeft); 50 58 } 51 59 -
src/clientcommandline/inputoutputhandler.h
r93ea008 r17ef75d 30 30 public: 31 31 InputOutputHandler(QObject *parent = NULL); 32 ~InputOutputHandler();32 ~InputOutputHandler(); 33 33 34 34 QString readLine(); 35 void setFieldWidth(int columns); 35 36 36 37 InputOutputHandler& operator<<(const QString &output); -
src/clientcommandline/siweatherclientconfig.h.in
r93ea008 r17ef75d 21 21 #define SIWEATHERCLIENTCONFIG_H 22 22 23 #cmakedefine WEBSERVICE_BASE_URL "@WEBSERVICE_BASE_URL_COMPLETE@" 23 24 #cmakedefine VERSION "@VERSION@" 24 25 #cmakedefine WEBSERVICE_API_VERSION "@WEBSERVICE_API_VERSION@" -
src/clientcommandline/stationsregister.cpp
r93ea008 r17ef75d 22 22 23 23 #include "inputoutputhandler.h" 24 #include "siweatherclientconfig.h" 24 25 25 26 #include <siweatherstation.h> … … 37 38 void StationsRegister::registerStation() 38 39 { 39 QUrl baseUrl("http://localhost:9999/0.1/"); 40 registerStation(SiWeatherStation()); 41 } 42 43 void StationsRegister::webserviceError(SiWeather::Library::SiWebserviceClient::ReplyType replyType, const QString& message) 44 { 45 if(replyType != SiWebserviceClient::StationsRegister) 46 return; 47 48 *_ioHandler << " "+ tr("FAILED") << endl; 49 *_ioHandler << " "+ message << endl; 40 50 51 QString result = getValue(tr("Do you want to change the station and try it again? (Y/n)"), "Y"); 52 if(result != "Y"){ 53 *_ioHandler << tr("Aborting!") << endl; 54 qApp->quit(); 55 return; 56 } 57 registerStation(_lastStation); 58 } 59 60 void StationsRegister::webserviceFinished(bool result, const QUuid& stationUuid, const QString& message) 61 { 62 if(!result){ 63 *_ioHandler << " "+ tr("FAILED") << endl; 64 *_ioHandler << " "+ message << endl; 65 QString result = getValue(tr("Do you want to change the station and try it again? (Y/n)"), "Y"); 66 if(result != "Y"){ 67 *_ioHandler << tr("Aborting!") << endl; 68 qApp->quit(); 69 return; 70 } 71 registerStation(_lastStation); 72 return; 73 } 74 75 *_ioHandler << " "+ tr("SUCCESS") << endl; 76 *_ioHandler << " "+ tr("Registered station with uuid %1").arg(stationUuid.toString()) << endl; 77 *_ioHandler << " "+ message << endl; 78 qApp->quit(); 79 } 80 81 void StationsRegister::registerStation(SiWeatherStation station) 82 { 83 if(!_ioHandler) 84 return; 85 86 QUrl baseUrl(QString(WEBSERVICE_BASE_URL)); 87 41 88 *_ioHandler << tr("Please enter some data to describe your station") << endl; 42 SiWeatherStation station;43 89 44 *_ioHandler << tr("Name") +": "; 45 station.setName(_ioHandler->readLine()); 90 station.setName(getValue(tr("Name"), station.name())); 91 station.setCity(getValue(tr("City"), station.city())); 92 station.setLatitude(getCoordinate(tr("Latitude"), station.latitude()).toDouble()); 93 station.setLongitude(getCoordinate(tr("Longitude"), station.longitude()).toDouble()); 46 94 47 *_ioHandler << tr("City") +": "; 48 station.setCity(_ioHandler->readLine()); 95 station.setEMail(getValue(tr("Your E-Mail Address"), station.eMail())); 96 QString defaultType = "siweatherstation 1"; 97 if(!station.type().isEmpty()) 98 defaultType = station.type(); 99 station.setType(getValue(tr("Type, describing your station"), defaultType)); 100 station.setTypeUrl(getValue(tr("Url with information about your type (optional)"), station.typeUrl().toString())); 49 101 50 station.setLatitude(getCoordinate(tr("Latitude")).toDouble()); 51 station.setLongitude(getCoordinate(tr("Longitude")).toDouble()); 52 53 *_ioHandler << tr("Your E-Mail Address") +": "; 54 station.setEMail(_ioHandler->readLine()); 55 56 QString defaultType = "siweatherstation 1"; 57 *_ioHandler << tr("Type, describing your station") +" ["+ defaultType +"]: "; 58 QString type = _ioHandler->readLine(); 59 if(type.isEmpty()) 60 type = defaultType; 61 station.setType(type); 62 63 *_ioHandler << tr("Url with information about your type (optional)") + ": "; 64 station.setTypeUrl(_ioHandler->readLine()); 65 102 *_ioHandler << tr("Your station is defined as follows:") << endl; 103 _ioHandler->setFieldWidth(20); 104 *_ioHandler << endl; 105 *_ioHandler << tr("Name:") << station.name() << endl; 106 *_ioHandler << tr("City:") << station.city() << endl; 107 *_ioHandler << tr("Latitude:") << coordinateToString(station.latitude()) << endl; 108 *_ioHandler << tr("Longitude:") << coordinateToString(station.longitude()) << endl; 109 *_ioHandler << tr("Type:") << station.type() << endl; 110 *_ioHandler << tr("Type Url:") << station.typeUrl().toString() << endl; 111 *_ioHandler << tr("E-Mail:") << station.eMail() << endl; 112 _ioHandler->setFieldWidth(0); 113 *_ioHandler << endl; 114 66 115 if(!station.isValidForRegister()){ 67 116 *_ioHandler << tr("Your station is not valid for register at the webservice.") << endl; 68 117 *_ioHandler << tr("This means, the name, city, e-mail address or type is empty.") << endl; 118 QString result = getValue(tr("Do you want to change the station? (Y/n)"), "Y"); 119 if(result != "Y"){ 120 *_ioHandler << tr("Aborting!") << endl; 121 qApp->quit(); 122 return; 123 } 124 registerStation(station); 125 return; 69 126 } 70 127 else{ 71 *_ioHandler << tr("Your station is defined as follows:") << endl; 72 *_ioHandler << " "+ tr("Name: ") + station.name() << endl; 73 *_ioHandler << " "+ tr("City: ") + station.city() << endl; 74 *_ioHandler << " "+ tr("Latitude: ") + QString::number(station.latitude()) << endl; 75 *_ioHandler << " "+ tr("Longitude: ") + QString::number(station.longitude()) << endl; 76 *_ioHandler << " "+ tr("Type: ") + station.type() << endl; 77 *_ioHandler << " "+ tr("Type Url: ") + station.typeUrl().toString() << endl; 78 *_ioHandler << " "+ tr("E-Mail: ") + station.eMail() << endl; 79 *_ioHandler << tr("Do you want to register this station at %1? (Y/n) [n]").arg(baseUrl.host()) +": "; 80 if(_ioHandler->readLine() != "Y"){ 128 QString result = getValue(tr("Do you want to register this station at %1? (Y/e/n)").arg(baseUrl.host()), "n"); 129 if(result != "Y"){ 130 if(result == "e"){ 131 registerStation(station); 132 return; 133 } 134 81 135 *_ioHandler << tr("Aborting!") << endl; 82 136 qApp->quit(); … … 97 151 return; 98 152 } 153 _lastStation = station; 99 154 } 100 155 } 101 156 102 void StationsRegister::webserviceError(SiWeather::Library::SiWebserviceClient::ReplyType replyType, const QString& message)157 QString StationsRegister::getValue(const QString& label, const QString& defaultValue) 103 158 { 104 if( replyType != SiWebserviceClient::StationsRegister)105 return ;159 if(!_ioHandler) 160 return QString(); 106 161 107 *_ioHandler << " "+ tr("FAILED") << endl; 108 *_ioHandler << " "+ message << endl; 109 qApp->quit(); 162 QString defaultValueLabel; 163 if(!defaultValue.isEmpty()) 164 defaultValueLabel = QString(" [%1]").arg(defaultValue); 165 *_ioHandler << label + defaultValueLabel +": "; 166 QString value = _ioHandler->readLine(); 167 if(value.isEmpty()) 168 value = defaultValue; 169 return value; 110 170 } 111 171 112 void StationsRegister::webserviceFinished(bool result, const QUuid& stationUuid, const QString& message)172 QString StationsRegister::getCoordinate(const QString& type, double defaultValue) 113 173 { 114 if(!result){ 115 *_ioHandler << " "+ tr("FAILED") << endl; 116 *_ioHandler << " "+ message << endl; 117 qApp->quit(); 118 return; 119 } 120 121 *_ioHandler << " "+ tr("SUCCESS") << endl; 122 *_ioHandler << " "+ tr("Registered station with uuid %1").arg(stationUuid.toString()) << endl; 123 *_ioHandler << " "+ message << endl; 124 qApp->quit(); 125 } 174 if(!_ioHandler) 175 return QString(); 126 176 127 QString StationsRegister::getCoordinate(const QString& type) 128 { 129 *_ioHandler << tr("%1 (at least 4 digits, point as separator)").arg(type) +": "; 130 QString coordinate = _ioHandler->readLine(); 131 if(coordinate.right(5).left(1) != "."){ 177 QString coordinate = getValue(tr("%1 (at least 4 digits, point as separator)").arg(type), coordinateToString(defaultValue)); 178 if(coordinate.length() - coordinate.indexOf(".") < 5){ 132 179 *_ioHandler << tr("Your %1 does not contain 4 digits. Try it again!").arg(type) << endl; 133 return getCoordinate(type );180 return getCoordinate(type, defaultValue); 134 181 } 135 182 return coordinate; 136 183 } 184 185 QString StationsRegister::coordinateToString(double coordinate) const 186 { 187 return QString::number(coordinate, 'f', 4); 188 } -
src/clientcommandline/stationsregister.h
r93ea008 r17ef75d 24 24 25 25 #include <siwebserviceclient.h> 26 #include <siweatherstation.h> 26 27 27 28 #include <QPointer> … … 41 42 42 43 private: 43 QString getCoordinate(const QString &type); 44 void registerStation(SiWeather::Library::SiWeatherStation station); 45 QString getValue(const QString &label, const QString &defaultValue = QString()); 46 QString getCoordinate(const QString &type, double defaultValue); 47 QString coordinateToString(double coordinate) const; 44 48 45 49 QPointer<InputOutputHandler> _ioHandler; 50 SiWeather::Library::SiWeatherStation _lastStation; 46 51 }; 47 52 -
src/lib/siwebserviceclient.cpp
r93ea008 r17ef75d 102 102 return; 103 103 } 104 104 105 emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), json["message"].toString()); 105 106 emit finished(StationsRegister, false, data);
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)