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 NOAA's National Weather Service XML data */
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 //QString countryName; // USA
46 // Current observation information.
47 QString observationTime
;
48 QString iconPeriodHour
;
52 QString temperature_F
;
53 QString temperature_C
;
56 QString windDirection
;
57 QString windSpeed
; // Float value
58 QString windGust
; // Float value
69 class KDE_EXPORT NOAAIon
: public IonInterface
74 NOAAIon(QObject
*parent
, const QVariantList
&args
);
76 void init(void); // Setup the city location, fetching the correct URL name.
77 bool updateIonSource(const QString
& source
); // Sync data source with Applet
78 void updateWeather(const QString
& source
);
81 void setup_slotDataArrived(KIO::Job
*, const QByteArray
&);
82 void setup_slotJobFinished(KJob
*);
84 void slotDataArrived(KIO::Job
*, const QByteArray
&);
85 void slotJobFinished(KJob
*);
88 /* NOAA Methods - Internal for Ion */
89 QMap
<QString
, ConditionIcons
> setupConditionIconMappings(void);
90 QMap
<QString
, ConditionIcons
> const & conditionIcons(void);
91 QMap
<QString
, WindDirections
> setupWindIconMappings(void);
92 QMap
<QString
, WindDirections
> const& windIcons(void);
95 QString
country(const QString
& source
);
96 QString
place(const QString
& source
);
97 QString
station(const QString
& source
);
99 // Current Conditions Weather info
100 QString
observationTime(const QString
& source
);
101 //bool night(const QString& source);
102 int periodHour(const QString
& source
);
103 QString
condition(const QString
& source
);
104 QMap
<QString
, QString
> temperature(const QString
& source
);
105 QString
dewpoint(const QString
& source
);
106 QString
humidity(const QString
& source
);
107 QMap
<QString
, QString
> visibility(const QString
& source
);
108 QMap
<QString
, QString
> pressure(const QString
& source
);
109 QMap
<QString
, QString
> wind(const QString
& source
);
111 // Load and Parse the place XML listing
112 void getXMLSetup(void);
113 bool readXMLSetup(void);
115 // Load and parse the specific place(s)
116 void getXMLData(const QString
& source
);
117 bool readXMLData(const QString
& source
, QXmlStreamReader
& xml
);
119 // Check if place specified is valid or not
120 QStringList
validate(const QString
& source
) const;
122 // Catchall for unknown XML tags
123 void parseUnknownElement(QXmlStreamReader
& xml
);
125 // Parse weather XML data
126 WeatherData
parseWeatherSite(WeatherData
& data
, QXmlStreamReader
& xml
);
127 void parseStationID(void);
128 void parseStationList(void);
135 K_EXPORT_PLASMA_DATAENGINE(noaa
, NOAAIon
)