• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Engines

ion_envcan.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007-2008 by Shawn Starr <shawn.starr@rogers.com>       *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
00018  ***************************************************************************/
00019 
00020 /* Ion for Environment Canada XML data */
00021 
00022 #ifndef _ION_ENVCAN_H_
00023 #define _ION_ENVCAN_H_
00024 
00025 #include <QtXml/QXmlStreamReader>
00026 #include <QtCore/QStringList>
00027 #include <QDateTime>
00028 #include <QDebug>
00029 #include <kurl.h>
00030 #include <kio/job.h>
00031 #include <kio/scheduler.h>
00032 #include <kdemacros.h>
00033 #include <plasma/dataengine.h>
00034 #include "ion.h"
00035 #include "weatherutils.h"
00036 
00037 class WeatherData
00038 {
00039 
00040 public:
00041     // WeatherEvent can have more than one, especially in Canada, eh? :)
00042     struct WeatherEvent {
00043         QString url;
00044         QString type;
00045         QString priority;
00046         QString description;
00047         QString timestamp;
00048     };
00049 
00050     // Five day forecast
00051     struct ForecastInfo {
00052         QString forecastPeriod;
00053         QString forecastSummary;
00054         QString iconName;
00055         QString shortForecast;
00056 
00057         QString forecastTempHigh;
00058         QString forecastTempLow;
00059         QString popPrecent;
00060         QString windForecast;
00061 
00062         QString precipForecast;
00063         QString precipType;
00064         QString precipTotalExpected;
00065         int forecastHumidity;
00066     };
00067 
00068     QString countryName;
00069     QString longTerritoryName;
00070     QString shortTerritoryName;
00071     QString cityName;
00072     QString regionName;
00073     QString stationID;
00074 
00075     // Current observation information.
00076     QString obsTimestamp;
00077 
00078     // Icon info to aproximate periods
00079     int iconPeriodHour;
00080     QString iconPeriodAP;
00081 
00082     QString condition;
00083     QString temperature;
00084     QString dewpoint;
00085 
00086     // In winter windchill, in summer, humidex
00087     QString comforttemp;
00088 
00089     float pressure;
00090     QString pressureTendency;
00091 
00092     float visibility;
00093     QString humidity;
00094 
00095     QString windSpeed;
00096     QString windGust;
00097     QString windDirection;
00098     QString windDegrees;
00099 
00100     QVector <WeatherData::WeatherEvent *> watches;
00101     QVector <WeatherData::WeatherEvent *> warnings;
00102 
00103     QString normalHigh;
00104     QString normalLow;
00105 
00106     QString forecastTimestamp;
00107 
00108     QString UVIndex;
00109     QString UVRating;
00110 
00111     // 5 day Forecast
00112     QVector <WeatherData::ForecastInfo *> forecasts;
00113 
00114     // Historical data from previous day.
00115     QString prevHigh;
00116     QString prevLow;
00117     QString prevPrecipType;
00118     QString prevPrecipTotal;
00119 
00120     // Almanac info
00121     QString sunriseTimestamp;
00122     QString sunsetTimestamp;
00123     QString moonriseTimestamp;
00124     QString moonsetTimestamp;
00125 
00126     // Historical Records
00127     float recordHigh;
00128     float recordLow;
00129     float recordRain;
00130     float recordSnow;
00131 };
00132 
00133 class KDE_EXPORT EnvCanadaIon : public IonInterface
00134 {
00135     Q_OBJECT
00136 
00137 public:
00138     EnvCanadaIon(QObject *parent, const QVariantList &args);
00139     ~EnvCanadaIon();
00140     bool updateIonSource(const QString& source); // Sync data source with Applet
00141     void updateWeather(const QString& source);
00142 
00143 protected:
00144     void init();  // Setup the city location, fetching the correct URL name.
00145 
00146 protected slots:
00147     void setup_slotDataArrived(KIO::Job *, const QByteArray &);
00148     void setup_slotJobFinished(KJob *);
00149 
00150     void slotDataArrived(KIO::Job *, const QByteArray &);
00151     void slotJobFinished(KJob *);
00152 
00153 private:
00154     /* Environment Canada Methods - Internal for Ion */
00155 
00156     QMap<QString, ConditionIcons> setupConditionIconMappings(void);
00157     QMap<QString, ConditionIcons> setupForecastIconMappings(void);
00158 
00159     QMap<QString, ConditionIcons> const& conditionIcons(void);
00160     QMap<QString, ConditionIcons> const& forecastIcons(void);
00161 
00162     // Place information
00163     QString country(const QString& source);
00164     QString territory(const QString& source);
00165     QString city(const QString& source);
00166     QString region(const QString& source);
00167     QString station(const QString& source);
00168 
00169     // Current Conditions Weather info
00170     QString observationTime(const QString& source);
00171     //bool night(const QString& source);
00172     int periodHour(const QString& source);
00173     QMap<QString, QString> watches(const QString& source);
00174     QMap<QString, QString> warnings(const QString& source);
00175     QString condition(const QString& source);
00176     QMap<QString, QString> temperature(const QString& source);
00177     QString dewpoint(const QString& source);
00178     QString humidity(const QString& source);
00179     QMap<QString, QString> visibility(const QString& source);
00180     QMap<QString, QString> pressure(const QString& source);
00181     QMap<QString, QString> wind(const QString& source);
00182     QMap<QString, QString> regionalTemperatures(const QString& source);
00183     QMap<QString, QString> uvIndex(const QString& source);
00184     QVector<QString> forecasts(const QString& source);
00185     QMap<QString, QString> yesterdayWeather(const QString& source);
00186     QMap<QString, QString> sunriseSet(const QString& source);
00187     QMap<QString, QString> moonriseSet(const QString& source);
00188     QMap<QString, QString> weatherRecords(const QString& source);
00189 
00190     // Load and Parse the place XML listing
00191     void getXMLSetup(void);
00192     bool readXMLSetup(void);
00193 
00194     // Load and parse the specific place(s)
00195     void getXMLData(const QString& source);
00196     bool readXMLData(const QString& source, QXmlStreamReader& xml);
00197 
00198     // Check if place specified is valid or not
00199     QStringList validate(const QString& source) const;
00200 
00201     // Catchall for unknown XML tags
00202     void parseUnknownElement(QXmlStreamReader& xml);
00203 
00204     // Parse weather XML data
00205     WeatherData parseWeatherSite(WeatherData& data, QXmlStreamReader& xml);
00206     void parseDateTime(WeatherData& data, QXmlStreamReader& xml, WeatherData::WeatherEvent* event = NULL);
00207     void parseLocations(WeatherData& data, QXmlStreamReader& xml);
00208     void parseConditions(WeatherData& data, QXmlStreamReader& xml);
00209     void parseWarnings(WeatherData& data, QXmlStreamReader& xml);
00210     void parseWindInfo(WeatherData& data, QXmlStreamReader& xml);
00211     void parseWeatherForecast(WeatherData& data, QXmlStreamReader& xml);
00212     void parseRegionalNormals(WeatherData& data, QXmlStreamReader& xml);
00213     void parseForecast(WeatherData& data, QXmlStreamReader& xml, WeatherData::ForecastInfo* forecast);
00214     void parseShortForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00215     void parseForecastTemperatures(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00216     void parseWindForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00217     void parsePrecipitationForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00218     void parsePrecipTotals(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00219     void parseUVIndex(WeatherData& data, QXmlStreamReader& xml);
00220     void parseYesterdayWeather(WeatherData& data, QXmlStreamReader& xml);
00221     void parseAstronomicals(WeatherData& data, QXmlStreamReader& xml);
00222     void parseWeatherRecords(WeatherData& data, QXmlStreamReader& xml);
00223 
00224 private:
00225     class Private;
00226     Private *const d;
00227 };
00228 
00229 K_EXPORT_PLASMA_DATAENGINE(envcan, EnvCanadaIon)
00230 
00231 #endif

Engines

Skip menu "Engines"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal