1 /***************************************************************************
2 * Copyright (C) 2007 by Shawn Starr <shawn.starr@rogers.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
18 ***************************************************************************/
20 /* Ion for Environment Canada XML data */
22 #ifndef _ION_ENVCAN_H_
23 #define _ION_ENVCAN_H_
25 #include <QtXml/QXmlStreamReader>
26 #include <QtCore/QStringList>
30 #include <kio/scheduler.h>
31 #include <kdemacros.h>
32 #include <plasma/dataengine.h>
40 // Warning info, can have more than one, especially in Canada, eh? :)
51 QString forecastPeriod
;
52 QString forecastSummary
;
53 QString shortForecast
;
55 QString forecastTempHigh
;
56 QString forecastTempLow
;
60 QString precipForecast
;
62 QString precipTotalExpected
;
67 QString longTerritoryName
;
68 QString shortTerritoryName
;
73 // Current observation information.
79 // In winter windchill, in summer, humidex
83 QString pressureTendency
;
90 QString windDirection
;
92 QVector
<WeatherData::WarningInfo
*> warnings
;
97 QString forecastTimestamp
;
103 QVector
<WeatherData::ForecastInfo
*> forecasts
;
105 // Historical data from previous day.
108 QString prevPrecipType
;
109 QString prevPrecipTotal
;
112 QString sunriseTimestamp
;
113 QString sunsetTimestamp
;
114 QString moonriseTimestamp
;
115 QString moonsetTimestamp
;
117 // Historical Records
124 class KDE_EXPORT EnvCanadaIon
: public IonInterface
129 EnvCanadaIon(QObject
*parent
, const QVariantList
&args
);
131 void init(); // Setup the city location, fetching the correct URL name.
132 bool updateIonSource(const QString
& source
); // Sync data source with Applet
134 bool metricUnit(void);
136 void setMeasureUnit(const QString
& unit
);
137 void setTimezoneFormat(const QString
& tz
);
139 void updateWeather(const QString
& source
);
141 static const int MAX_WARNINGS
= 4;
144 void setup_slotDataArrived(KIO::Job
*, const QByteArray
&);
145 void setup_slotJobFinished(KJob
*);
147 void slotDataArrived(KIO::Job
*, const QByteArray
&);
148 void slotJobFinished(KJob
*);
151 /* Environment Canada Methods - Internal for Ion */
154 QString
country(const QString
& source
);
155 QString
territory(const QString
& source
);
156 QString
city(const QString
& source
);
157 QString
region(const QString
& source
);
158 QString
station(const QString
& source
);
160 // Current Conditions Weather info
161 QString
observationTime(const QString
& source
);
162 QMap
<QString
, QString
> warnings(const QString
& source
);
163 QString
condition(const QString
& source
);
164 QMap
<QString
, QString
> temperature(const QString
& source
);
165 QString
dewpoint(const QString
& source
);
166 QString
humidity(const QString
& source
);
167 QMap
<QString
, QString
> visibility(const QString
& source
);
168 QMap
<QString
, QString
> pressure(const QString
& source
);
169 QMap
<QString
, QString
> wind(const QString
& source
);
170 QMap
<QString
, QString
> regionalTemperatures(const QString
& source
);
171 QMap
<QString
, QString
> uvIndex(const QString
& source
);
172 QVector
<QString
> forecasts(const QString
& source
);
173 QMap
<QString
, QString
> yesterdayWeather(const QString
& source
);
174 QMap
<QString
, QString
> sunriseSet(const QString
& source
);
175 QMap
<QString
, QString
> moonriseSet(const QString
& source
);
176 QMap
<QString
, QString
> weatherRecords(const QString
& source
);
178 // Load and Parse the place XML listing
179 void getXMLSetup(void);
180 bool readXMLSetup(void);
182 // Load and parse the specific place(s)
183 void getXMLData(const QString
& source
);
184 bool readXMLData(const QString
& source
, QXmlStreamReader
& xml
);
186 // Check if place specified is valid or not
187 QStringList
validate(const QString
& source
) const;
189 // Catchall for unknown XML tags
190 void parseUnknownElement(QXmlStreamReader
& xml
);
192 // Parse weather XML data
193 WeatherData
parseWeatherSite(WeatherData
& data
, QXmlStreamReader
& xml
);
194 void parseDateTime(WeatherData
& data
, QXmlStreamReader
& xml
, WeatherData::WarningInfo
* warning
= NULL
);
195 void parseLocations(WeatherData
& data
, QXmlStreamReader
& xml
);
196 void parseConditions(WeatherData
& data
, QXmlStreamReader
& xml
);
197 void parseWarnings(WeatherData
& data
, QXmlStreamReader
& xml
);
198 void parseWindInfo(WeatherData
& data
, QXmlStreamReader
& xml
);
199 void parseWeatherForecast(WeatherData
& data
, QXmlStreamReader
& xml
);
200 void parseRegionalNormals(WeatherData
& data
, QXmlStreamReader
& xml
);
201 void parseForecast(WeatherData
& data
, QXmlStreamReader
& xml
, WeatherData::ForecastInfo
* forecast
);
202 void parseShortForecast(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
203 void parseForecastTemperatures(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
204 void parseWindForecast(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
205 void parsePrecipitationForecast(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
206 void parsePrecipTotals(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
207 void parseUVIndex(WeatherData
& data
, QXmlStreamReader
& xml
);
208 void parseYesterdayWeather(WeatherData
& data
, QXmlStreamReader
& xml
);
209 void parseAstronomicals(WeatherData
& data
, QXmlStreamReader
& xml
);
210 void parseWeatherRecords(WeatherData
& data
, QXmlStreamReader
& xml
);
217 K_EXPORT_PLASMA_ION(envcan
, EnvCanadaIon
)