~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2007-2009 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
 ***************************************************************************/
 
19
 
 
20
/* Ion for BBC Weather from UKMET Office */
 
21
 
 
22
#ifndef ION_BBCUKMET_H
 
23
#define ION_BBCUKMET_H
 
24
 
 
25
#include <QtXml/QXmlStreamReader>
 
26
#include <QDateTime>
 
27
 
 
28
#include "../ion.h"
 
29
#include "../dataengineconsumer.h"
 
30
 
 
31
class KJob;
 
32
namespace KIO
 
33
{
 
34
    class Job;
 
35
    class TransferJob;
 
36
}
 
37
 
 
38
class WeatherData
 
39
{
 
40
 
 
41
public:
 
42
    QString place;
 
43
    QString stationName;
 
44
    // Current observation information.
 
45
    QString obsTime;
 
46
    int iconPeriodHour;
 
47
    int iconPeriodMinute;
 
48
    double longitude;
 
49
    double latitude;
 
50
 
 
51
    QString condition;
 
52
    QString conditionIcon;
 
53
    QString temperature_C;
 
54
    QString windDirection;
 
55
    QString windSpeed_miles;
 
56
    QString humidity;
 
57
    QString pressure;
 
58
    QString pressureTendency;
 
59
    QString visibilityStr;
 
60
 
 
61
    // Five day forecast
 
62
    struct ForecastInfo {
 
63
        QString period;
 
64
        QString iconName;
 
65
        QString summary;
 
66
        int tempHigh;
 
67
        int tempLow;
 
68
        int windSpeed;
 
69
        QString windDirection;
 
70
    };
 
71
 
 
72
    // 5 day Forecast
 
73
    QVector <WeatherData::ForecastInfo *> forecasts;
 
74
};
 
75
 
 
76
class KDE_EXPORT UKMETIon : public IonInterface, public Plasma::DataEngineConsumer
 
77
{
 
78
    Q_OBJECT
 
79
 
 
80
public:
 
81
    UKMETIon(QObject *parent, const QVariantList &args);
 
82
    ~UKMETIon();
 
83
    void init();  // Setup the city location, fetching the correct URL name.
 
84
    bool updateIonSource(const QString& source);
 
85
    void updateWeather(const QString& source);
 
86
 
 
87
    QString place(const QString& source) const;
 
88
    QString station(const QString& source) const;
 
89
    QString observationTime(const QString& source) const;
 
90
    //bool night(const QString& source) const;
 
91
    int periodHour(const QString& source) const;
 
92
    int periodMinute(const QString& source) const;
 
93
    double periodLatitude(const QString& source) const;
 
94
    double periodLongitude(const QString& source) const;
 
95
    QString condition(const QString& source) const;
 
96
    QMap<QString, QString> temperature(const QString& source) const;
 
97
    QMap<QString, QString> wind(const QString& source) const;
 
98
    QMap<QString, QString> humidity(const QString& source) const;
 
99
    QString visibility(const QString& source) const;
 
100
    QMap<QString, QString> pressure(const QString& source) const;
 
101
    QVector<QString> forecasts(const QString& source);
 
102
 
 
103
public Q_SLOTS:
 
104
    virtual void reset();
 
105
 
 
106
protected Q_SLOTS:
 
107
    void setup_slotDataArrived(KIO::Job *, const QByteArray &);
 
108
    void setup_slotJobFinished(KJob *);
 
109
    //void setup_slotRedirected(KIO::Job *, const KUrl &url);
 
110
    void observation_slotDataArrived(KIO::Job *, const QByteArray &);
 
111
    void observation_slotJobFinished(KJob *);
 
112
    void forecast_slotDataArrived(KIO::Job *, const QByteArray &);
 
113
    void forecast_slotJobFinished(KJob *);
 
114
 
 
115
private:
 
116
    /* UKMET Methods - Internal for Ion */
 
117
 
 
118
    QMap<QString, ConditionIcons> setupDayIconMappings(void) const;
 
119
    QMap<QString, ConditionIcons> setupNightIconMappings(void) const;
 
120
 
 
121
    QMap<QString, ConditionIcons> const& nightIcons(void) const;
 
122
    QMap<QString, ConditionIcons> const& dayIcons(void) const;
 
123
 
 
124
    // Load and Parse the place search XML listings
 
125
    void findPlace(const QString& place, const QString& source);
 
126
    void validate(const QString& source); // Sync data source with Applet
 
127
    void getFiveDayForecast(const QString& source);
 
128
    void getXMLData(const QString& source);
 
129
    void readSearchHTMLData(const QString& source, const QByteArray& html);
 
130
    bool readFiveDayForecastXMLData(const QString& source, QXmlStreamReader& xml);
 
131
    void parseSearchLocations(const QString& source, QXmlStreamReader& xml);
 
132
 
 
133
    // Observation parsing methods
 
134
    bool readObservationXMLData(const QString& source, QXmlStreamReader& xml);
 
135
    void parsePlaceObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml);
 
136
    void parseWeatherChannel(const QString& source, WeatherData& data, QXmlStreamReader& xml);
 
137
    void parseWeatherObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml);
 
138
    void parseFiveDayForecast(const QString& source, QXmlStreamReader& xml);
 
139
    void parsePlaceForecast(const QString& source, QXmlStreamReader& xml);
 
140
    void parseWeatherForecast(const QString& source, QXmlStreamReader& xml);
 
141
    void parseUnknownElement(QXmlStreamReader& xml) const;
 
142
 
 
143
    void deleteForecasts();
 
144
 
 
145
    struct XMLMapInfo {
 
146
        QString place;
 
147
        QString XMLurl;
 
148
        QString forecastHTMLUrl;
 
149
        QString XMLforecastURL;
 
150
    };
 
151
 
 
152
    // Key dicts
 
153
    QHash<QString, UKMETIon::XMLMapInfo> m_place;
 
154
    QVector<QString> m_locations;
 
155
 
 
156
    // Weather information
 
157
    QHash<QString, WeatherData> m_weatherData;
 
158
 
 
159
    // Store KIO jobs - Search list
 
160
    QMap<KJob *, QByteArray *> m_jobHtml;
 
161
    QMap<KJob *, QString> m_jobList;
 
162
 
 
163
    QMap<KJob *, QXmlStreamReader*> m_obsJobXml;
 
164
    QMap<KJob *, QString> m_obsJobList;
 
165
 
 
166
    QMap<KJob *, QXmlStreamReader *> m_forecastJobXml;
 
167
    QMap<KJob *, QString> m_forecastJobList;
 
168
 
 
169
    KIO::TransferJob *m_job;
 
170
    Plasma::DataEngine *m_timeEngine;
 
171
 
 
172
    QDateTime m_dateFormat;
 
173
    QStringList m_sourcesToReset;
 
174
};
 
175
 
 
176
K_EXPORT_PLASMA_DATAENGINE(bbcukmet, UKMETIon)
 
177
 
 
178
#endif