1 /***************************************************************************
2 * Copyright (C) 2007-2008 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>
31 #include <kio/scheduler.h>
32 #include <kdemacros.h>
33 #include <plasma/dataengine.h>
35 #include "weatherutils.h"
41 // WeatherEvent can have more than one, especially in Canada, eh? :)
52 QString forecastPeriod
;
53 QString forecastSummary
;
55 QString shortForecast
;
57 QString forecastTempHigh
;
58 QString forecastTempLow
;
62 QString precipForecast
;
64 QString precipTotalExpected
;
69 QString longTerritoryName
;
70 QString shortTerritoryName
;
75 // Current observation information.
78 // Icon info to aproximate periods
86 // In winter windchill, in summer, humidex
90 QString pressureTendency
;
97 QString windDirection
;
100 QVector
<WeatherData::WeatherEvent
*> watches
;
101 QVector
<WeatherData::WeatherEvent
*> warnings
;
106 QString forecastTimestamp
;
112 QVector
<WeatherData::ForecastInfo
*> forecasts
;
114 // Historical data from previous day.
117 QString prevPrecipType
;
118 QString prevPrecipTotal
;
121 QString sunriseTimestamp
;
122 QString sunsetTimestamp
;
123 QString moonriseTimestamp
;
124 QString moonsetTimestamp
;
126 // Historical Records
133 class KDE_EXPORT EnvCanadaIon
: public IonInterface
138 EnvCanadaIon(QObject
*parent
, const QVariantList
&args
);
140 bool updateIonSource(const QString
& source
); // Sync data source with Applet
141 void updateWeather(const QString
& source
);
144 void init(); // Setup the city location, fetching the correct URL name.
147 void setup_slotDataArrived(KIO::Job
*, const QByteArray
&);
148 void setup_slotJobFinished(KJob
*);
150 void slotDataArrived(KIO::Job
*, const QByteArray
&);
151 void slotJobFinished(KJob
*);
154 /* Environment Canada Methods - Internal for Ion */
156 QMap
<QString
, ConditionIcons
> setupConditionIconMappings(void);
157 QMap
<QString
, ConditionIcons
> setupForecastIconMappings(void);
159 QMap
<QString
, ConditionIcons
> const& conditionIcons(void);
160 QMap
<QString
, ConditionIcons
> const& forecastIcons(void);
163 QString
country(const QString
& source
);
164 QString
territory(const QString
& source
);
165 QString
city(const QString
& source
);
166 QString
region(const QString
& source
);
167 QString
station(const QString
& source
);
169 // Current Conditions Weather info
170 QString
observationTime(const QString
& source
);
171 //bool night(const QString& source);
172 int periodHour(const QString
& source
);
173 QMap
<QString
, QString
> watches(const QString
& source
);
174 QMap
<QString
, QString
> warnings(const QString
& source
);
175 QString
condition(const QString
& source
);
176 QMap
<QString
, QString
> temperature(const QString
& source
);
177 QString
dewpoint(const QString
& source
);
178 QString
humidity(const QString
& source
);
179 QMap
<QString
, QString
> visibility(const QString
& source
);
180 QMap
<QString
, QString
> pressure(const QString
& source
);
181 QMap
<QString
, QString
> wind(const QString
& source
);
182 QMap
<QString
, QString
> regionalTemperatures(const QString
& source
);
183 QMap
<QString
, QString
> uvIndex(const QString
& source
);
184 QVector
<QString
> forecasts(const QString
& source
);
185 QMap
<QString
, QString
> yesterdayWeather(const QString
& source
);
186 QMap
<QString
, QString
> sunriseSet(const QString
& source
);
187 QMap
<QString
, QString
> moonriseSet(const QString
& source
);
188 QMap
<QString
, QString
> weatherRecords(const QString
& source
);
190 // Load and Parse the place XML listing
191 void getXMLSetup(void);
192 bool readXMLSetup(void);
194 // Load and parse the specific place(s)
195 void getXMLData(const QString
& source
);
196 bool readXMLData(const QString
& source
, QXmlStreamReader
& xml
);
198 // Check if place specified is valid or not
199 QStringList
validate(const QString
& source
) const;
201 // Catchall for unknown XML tags
202 void parseUnknownElement(QXmlStreamReader
& xml
);
204 // Parse weather XML data
205 WeatherData
parseWeatherSite(WeatherData
& data
, QXmlStreamReader
& xml
);
206 void parseDateTime(WeatherData
& data
, QXmlStreamReader
& xml
, WeatherData::WeatherEvent
* event
= NULL
);
207 void parseLocations(WeatherData
& data
, QXmlStreamReader
& xml
);
208 void parseConditions(WeatherData
& data
, QXmlStreamReader
& xml
);
209 void parseWarnings(WeatherData
& data
, QXmlStreamReader
& xml
);
210 void parseWindInfo(WeatherData
& data
, QXmlStreamReader
& xml
);
211 void parseWeatherForecast(WeatherData
& data
, QXmlStreamReader
& xml
);
212 void parseRegionalNormals(WeatherData
& data
, QXmlStreamReader
& xml
);
213 void parseForecast(WeatherData
& data
, QXmlStreamReader
& xml
, WeatherData::ForecastInfo
* forecast
);
214 void parseShortForecast(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
215 void parseForecastTemperatures(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
216 void parseWindForecast(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
217 void parsePrecipitationForecast(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
218 void parsePrecipTotals(WeatherData::ForecastInfo
* forecast
, QXmlStreamReader
& xml
);
219 void parseUVIndex(WeatherData
& data
, QXmlStreamReader
& xml
);
220 void parseYesterdayWeather(WeatherData
& data
, QXmlStreamReader
& xml
);
221 void parseAstronomicals(WeatherData
& data
, QXmlStreamReader
& xml
);
222 void parseWeatherRecords(WeatherData
& data
, QXmlStreamReader
& xml
);
229 K_EXPORT_PLASMA_DATAENGINE(envcan
, EnvCanadaIon
)