Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / plasma / dataengines / weather / ions / ion_bbcukmet.h
blob3eb94283ec01d44b4201030523c5edf425f32e6d
1 /***************************************************************************
2 * Copyright (C) 2007 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 BBC Weather from UKMET Office */
22 #ifndef _ION_BBCUKMET_H
23 #define _ION_BBCUKMET_H
25 #include <QtXml/QXmlStreamReader>
26 #include <QRegExp>
27 #include <QtCore/QStringList>
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 "formulas.h"
37 class WeatherData
40 public:
41 QString place;
42 QString stationName;
43 // Current observation information.
44 QString obsTime;
45 QString condition;
46 QString temperature_C;
47 QString temperature_F;
48 QString windDirection;
49 QString windSpeed_miles;
50 QString humidity;
51 QString pressure;
52 QString pressureTendency;
53 QString visibilityStr;
55 // Five day forecast
56 struct ForecastInfo {
57 QString period;
58 QString summary;
59 int tempHigh;
60 int tempLow;
61 int windSpeed;
62 QString windDirection;
65 // 5 day Forecast
66 QVector <WeatherData::ForecastInfo *> forecasts;
69 class KDE_EXPORT UKMETIon : public IonInterface
71 Q_OBJECT
73 public:
74 UKMETIon(QObject *parent, const QVariantList &args);
75 ~UKMETIon();
76 void init(); // Setup the city location, fetching the correct URL name.
77 bool metricUnit(void);
78 bool timezone(void);
79 void setMeasureUnit(const QString& unit);
80 void setTimezoneFormat(const QString& tz);
81 bool updateIonSource(const QString& source);
82 void updateWeather(const QString& source);
84 QString place(const QString& source);
85 QString station(const QString& source);
86 QString observationTime(const QString& source);
87 QString condition(const QString& source);
88 QMap<QString, QString> temperature(const QString& source);
89 QMap<QString, QString> wind(const QString& source);
90 QString humidity(const QString& source);
91 QString visibility(const QString& source);
92 QMap<QString, QString> pressure(const QString& source);
93 QVector<QString> forecasts(const QString& source);
95 protected slots:
96 void setup_slotDataArrived(KIO::Job *, const QByteArray &);
97 void setup_slotJobFinished(KJob *);
98 void setup_slotRedirected(KIO::Job *, const KUrl &url);
99 void observation_slotDataArrived(KIO::Job *, const QByteArray &);
100 void observation_slotJobFinished(KJob *);
101 void forecast_slotDataArrived(KIO::Job *, const QByteArray &);
102 void forecast_slotJobFinished(KJob *);
104 private:
105 /* UKMET Methods - Internal for Ion */
107 // Load and Parse the place search XML listings
108 void findPlace(const QString& place, const QString& source);
109 void validate(const QString& source); // Sync data source with Applet
110 void getFiveDayForecast(const QString& source);
111 void getXMLData(const QString& source);
112 bool readSearchXMLData(const QString& source, QXmlStreamReader& xml);
113 bool readFiveDayForecastXMLData(const QString& source, QXmlStreamReader& xml);
114 void parseSearchLocations(const QString& source, QXmlStreamReader& xml);
116 // Observation parsing methods
117 bool readObservationXMLData(const QString& source, QXmlStreamReader& xml);
118 void parsePlaceObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml);
119 void parseWeatherChannel(const QString& source, WeatherData& data, QXmlStreamReader& xml);
120 void parseWeatherObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml);
121 void parseFiveDayForecast(const QString& source, QXmlStreamReader& xml);
122 void parseUnknownElement(QXmlStreamReader& xml);
124 private:
125 class Private;
126 Private *const d;
129 K_EXPORT_PLASMA_ION(bbcukmet, UKMETIon)
131 #endif