delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / workspace / plasma / dataengines / weather / ions / ion_envcan.h
blob173864ea9c831c700f8c137c244b0acbc135eb6a
1 /***************************************************************************
2 * Copyright (C) 2007-2008 by Shawn Starr <shawn.starr@rogers.com> *
3 * *
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. *
8 * *
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. *
13 * *
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>
27 #include <QDateTime>
28 #include <QDebug>
29 #include <kurl.h>
30 #include <kio/job.h>
31 #include <kio/scheduler.h>
32 #include <kdemacros.h>
33 #include <plasma/dataengine.h>
34 #include "ion.h"
35 #include "weatherutils.h"
37 class WeatherData
40 public:
41 // WeatherEvent can have more than one, especially in Canada, eh? :)
42 struct WeatherEvent {
43 QString url;
44 QString type;
45 QString priority;
46 QString description;
47 QString timestamp;
50 // Five day forecast
51 struct ForecastInfo {
52 QString forecastPeriod;
53 QString forecastSummary;
54 QString iconName;
55 QString shortForecast;
57 QString forecastTempHigh;
58 QString forecastTempLow;
59 QString popPrecent;
60 QString windForecast;
62 QString precipForecast;
63 QString precipType;
64 QString precipTotalExpected;
65 int forecastHumidity;
68 QString countryName;
69 QString longTerritoryName;
70 QString shortTerritoryName;
71 QString cityName;
72 QString regionName;
73 QString stationID;
75 // Current observation information.
76 QString obsTimestamp;
78 // Icon info to aproximate periods
79 int iconPeriodHour;
80 QString iconPeriodAP;
82 QString condition;
83 QString temperature;
84 QString dewpoint;
86 // In winter windchill, in summer, humidex
87 QString comforttemp;
89 float pressure;
90 QString pressureTendency;
92 float visibility;
93 QString humidity;
95 QString windSpeed;
96 QString windGust;
97 QString windDirection;
98 QString windDegrees;
100 QVector <WeatherData::WeatherEvent *> watches;
101 QVector <WeatherData::WeatherEvent *> warnings;
103 QString normalHigh;
104 QString normalLow;
106 QString forecastTimestamp;
108 QString UVIndex;
109 QString UVRating;
111 // 5 day Forecast
112 QVector <WeatherData::ForecastInfo *> forecasts;
114 // Historical data from previous day.
115 QString prevHigh;
116 QString prevLow;
117 QString prevPrecipType;
118 QString prevPrecipTotal;
120 // Almanac info
121 QString sunriseTimestamp;
122 QString sunsetTimestamp;
123 QString moonriseTimestamp;
124 QString moonsetTimestamp;
126 // Historical Records
127 float recordHigh;
128 float recordLow;
129 float recordRain;
130 float recordSnow;
133 class KDE_EXPORT EnvCanadaIon : public IonInterface
135 Q_OBJECT
137 public:
138 EnvCanadaIon(QObject *parent, const QVariantList &args);
139 ~EnvCanadaIon();
140 bool updateIonSource(const QString& source); // Sync data source with Applet
141 void updateWeather(const QString& source);
143 protected:
144 void init(); // Setup the city location, fetching the correct URL name.
146 protected slots:
147 void setup_slotDataArrived(KIO::Job *, const QByteArray &);
148 void setup_slotJobFinished(KJob *);
150 void slotDataArrived(KIO::Job *, const QByteArray &);
151 void slotJobFinished(KJob *);
153 private:
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);
162 // Place information
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);
224 private:
225 class Private;
226 Private *const d;
229 K_EXPORT_PLASMA_DATAENGINE(envcan, EnvCanadaIon)
231 #endif