1 /***************************************************************************
2 * Copyright (C) 2007 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>
30 #include <kio/scheduler.h>
31 #include <kdemacros.h>
32 #include <plasma/dataengine.h>
40 //QString countryName; // USA
45 // Current observation information.
46 QString observationTime
;
48 QString temperature_F
;
49 QString temperature_C
;
52 QString windDirection
;
53 QString windSpeed
; // Float value
54 QString windGust
; // Float value
65 class KDE_EXPORT NOAAIon
: public IonInterface
70 NOAAIon(QObject
*parent
, const QVariantList
&args
);
72 void init(void); // Setup the city location, fetching the correct URL name.
73 bool metricUnit(void);
75 void setMeasureUnit(const QString
& unit
);
76 void setTimezoneFormat(const QString
& tz
);
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 */
91 QString
country(const QString
& source
);
92 QString
place(const QString
& source
);
93 QString
station(const QString
& source
);
95 // Current Conditions Weather info
96 QString
observationTime(const QString
& source
);
97 QString
condition(const QString
& source
);
98 QMap
<QString
, QString
> temperature(const QString
& source
);
99 QString
dewpoint(const QString
& source
);
100 QString
humidity(const QString
& source
);
101 QMap
<QString
, QString
> visibility(const QString
& source
);
102 QMap
<QString
, QString
> pressure(const QString
& source
);
103 QMap
<QString
, QString
> wind(const QString
& source
);
105 // Load and Parse the place XML listing
106 void getXMLSetup(void);
107 bool readXMLSetup(void);
109 // Load and parse the specific place(s)
110 void getXMLData(const QString
& source
);
111 bool readXMLData(const QString
& source
, QXmlStreamReader
& xml
);
113 // Check if place specified is valid or not
114 QStringList
validate(const QString
& source
) const;
116 // Catchall for unknown XML tags
117 void parseUnknownElement(QXmlStreamReader
& xml
);
119 // Parse weather XML data
120 WeatherData
parseWeatherSite(WeatherData
& data
, QXmlStreamReader
& xml
);
121 void parseStationID(void);
122 void parseStationList(void);
129 K_EXPORT_PLASMA_ION(noaa
, NOAAIon
)