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 BBC Weather from UKMET Office */
22 #ifndef _ION_BBCUKMET_H
23 #define _ION_BBCUKMET_H
25 #include <QtXml/QXmlStreamReader>
27 #include <QtCore/QStringList>
32 #include <kio/scheduler.h>
33 #include <kdemacros.h>
34 #include <plasma/dataengine.h>
36 #include "weatherutils.h"
44 // Current observation information.
47 //QString iconPeriodAP;
50 QString conditionIcon
;
51 QString temperature_C
;
52 QString temperature_F
;
53 QString windDirection
;
54 QString windSpeed_miles
;
57 QString pressureTendency
;
58 QString visibilityStr
;
68 QString windDirection
;
72 QVector
<WeatherData::ForecastInfo
*> forecasts
;
75 class KDE_EXPORT UKMETIon
: public IonInterface
80 UKMETIon(QObject
*parent
, const QVariantList
&args
);
82 void init(); // Setup the city location, fetching the correct URL name.
83 bool updateIonSource(const QString
& source
);
84 void updateWeather(const QString
& source
);
86 QString
place(const QString
& source
);
87 QString
station(const QString
& source
);
88 QString
observationTime(const QString
& source
);
89 //bool night(const QString& source);
90 int periodHour(const QString
& source
);
91 QString
condition(const QString
& source
);
92 QMap
<QString
, QString
> temperature(const QString
& source
);
93 QMap
<QString
, QString
> wind(const QString
& source
);
94 QString
humidity(const QString
& source
);
95 QString
visibility(const QString
& source
);
96 QMap
<QString
, QString
> pressure(const QString
& source
);
97 QVector
<QString
> forecasts(const QString
& source
);
100 void setup_slotDataArrived(KIO::Job
*, const QByteArray
&);
101 void setup_slotJobFinished(KJob
*);
102 void setup_slotRedirected(KIO::Job
*, const KUrl
&url
);
103 void observation_slotDataArrived(KIO::Job
*, const QByteArray
&);
104 void observation_slotJobFinished(KJob
*);
105 void forecast_slotDataArrived(KIO::Job
*, const QByteArray
&);
106 void forecast_slotJobFinished(KJob
*);
109 /* UKMET Methods - Internal for Ion */
111 QMap
<QString
, ConditionIcons
> setupDayIconMappings(void);
112 QMap
<QString
, ConditionIcons
> setupNightIconMappings(void);
114 QMap
<QString
, ConditionIcons
> const& nightIcons(void);
115 QMap
<QString
, ConditionIcons
> const& dayIcons(void);
117 // Load and Parse the place search XML listings
118 void findPlace(const QString
& place
, const QString
& source
);
119 void validate(const QString
& source
); // Sync data source with Applet
120 void getFiveDayForecast(const QString
& source
);
121 void getXMLData(const QString
& source
);
122 bool readSearchXMLData(const QString
& source
, QXmlStreamReader
& xml
);
123 bool readFiveDayForecastXMLData(const QString
& source
, QXmlStreamReader
& xml
);
124 void parseSearchLocations(const QString
& source
, QXmlStreamReader
& xml
);
126 // Observation parsing methods
127 bool readObservationXMLData(const QString
& source
, QXmlStreamReader
& xml
);
128 void parsePlaceObservation(const QString
& source
, WeatherData
& data
, QXmlStreamReader
& xml
);
129 void parseWeatherChannel(const QString
& source
, WeatherData
& data
, QXmlStreamReader
& xml
);
130 void parseWeatherObservation(const QString
& source
, WeatherData
& data
, QXmlStreamReader
& xml
);
131 void parseFiveDayForecast(const QString
& source
, QXmlStreamReader
& xml
);
132 void parseUnknownElement(QXmlStreamReader
& xml
);
139 K_EXPORT_PLASMA_DATAENGINE(bbcukmet
, UKMETIon
)