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

Plasma

ion_envcan.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 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 <QDebug>
00028 #include <kurl.h>
00029 #include <kio/job.h>
00030 #include <kio/scheduler.h>
00031 #include <kdemacros.h>
00032 #include <plasma/dataengine.h>
00033 #include "ion.h"
00034 #include "formulas.h"
00035 
00036 class WeatherData
00037 {
00038 
00039 public:
00040     // Warning info, can have more than one, especially in Canada, eh? :)
00041     struct WarningInfo {
00042         QString url;
00043         QString type;
00044         QString priority;
00045         QString description;
00046         QString timestamp;
00047     };
00048 
00049     // Five day forecast
00050     struct ForecastInfo {
00051         QString forecastPeriod;
00052         QString forecastSummary;
00053         QString shortForecast;
00054 
00055         QString forecastTempHigh;
00056         QString forecastTempLow;
00057         QString popPrecent;
00058         QString windForecast;
00059 
00060         QString precipForecast;
00061         QString precipType;
00062         QString precipTotalExpected;
00063         int forecastHumidity;
00064     };
00065 
00066     QString countryName;
00067     QString longTerritoryName;
00068     QString shortTerritoryName;
00069     QString cityName;
00070     QString regionName;
00071     QString stationID;
00072 
00073     // Current observation information.
00074     QString obsTimestamp;
00075     QString condition;
00076     QString temperature;
00077     QString dewpoint;
00078 
00079     // In winter windchill, in summer, humidex
00080     QString comforttemp;
00081 
00082     float pressure;
00083     QString pressureTendency;
00084 
00085     float visibility;
00086     QString humidity;
00087 
00088     QString windSpeed;
00089     QString windGust;
00090     QString windDirection;
00091 
00092     QVector <WeatherData::WarningInfo *> warnings;
00093 
00094     QString normalHigh;
00095     QString normalLow;
00096 
00097     QString forecastTimestamp;
00098 
00099     QString UVIndex;
00100     QString UVRating;
00101 
00102     // 5 day Forecast
00103     QVector <WeatherData::ForecastInfo *> forecasts;
00104 
00105     // Historical data from previous day.
00106     QString prevHigh;
00107     QString prevLow;
00108     QString prevPrecipType;
00109     QString prevPrecipTotal;
00110 
00111     // Almanac info
00112     QString sunriseTimestamp;
00113     QString sunsetTimestamp;
00114     QString moonriseTimestamp;
00115     QString moonsetTimestamp;
00116 
00117     // Historical Records
00118     float recordHigh;
00119     float recordLow;
00120     float recordRain;
00121     float recordSnow;
00122 };
00123 
00124 class KDE_EXPORT EnvCanadaIon : public IonInterface
00125 {
00126     Q_OBJECT
00127 
00128 public:
00129     EnvCanadaIon(QObject *parent, const QVariantList &args);
00130     ~EnvCanadaIon();
00131     bool updateIonSource(const QString& source); // Sync data source with Applet
00132 
00133     bool metricUnit(void);
00134     bool timezone(void);
00135     void setMeasureUnit(const QString& unit);
00136     void setTimezoneFormat(const QString& tz);
00137 
00138     void updateWeather(const QString& source);
00139 
00140     static const int MAX_WARNINGS = 4;
00141 
00142 protected:
00143     void init();  // Setup the city location, fetching the correct URL name.
00144 
00145 protected slots:
00146     void setup_slotDataArrived(KIO::Job *, const QByteArray &);
00147     void setup_slotJobFinished(KJob *);
00148 
00149     void slotDataArrived(KIO::Job *, const QByteArray &);
00150     void slotJobFinished(KJob *);
00151 
00152 private:
00153     /* Environment Canada Methods - Internal for Ion */
00154 
00155     // Place information
00156     QString country(const QString& source);
00157     QString territory(const QString& source);
00158     QString city(const QString& source);
00159     QString region(const QString& source);
00160     QString station(const QString& source);
00161 
00162     // Current Conditions Weather info
00163     QString observationTime(const QString& source);
00164     QMap<QString, QString> warnings(const QString& source);
00165     QString condition(const QString& source);
00166     QMap<QString, QString> temperature(const QString& source);
00167     QString dewpoint(const QString& source);
00168     QString humidity(const QString& source);
00169     QMap<QString, QString> visibility(const QString& source);
00170     QMap<QString, QString> pressure(const QString& source);
00171     QMap<QString, QString> wind(const QString& source);
00172     QMap<QString, QString> regionalTemperatures(const QString& source);
00173     QMap<QString, QString> uvIndex(const QString& source);
00174     QVector<QString> forecasts(const QString& source);
00175     QMap<QString, QString> yesterdayWeather(const QString& source);
00176     QMap<QString, QString> sunriseSet(const QString& source);
00177     QMap<QString, QString> moonriseSet(const QString& source);
00178     QMap<QString, QString> weatherRecords(const QString& source);
00179 
00180     // Load and Parse the place XML listing
00181     void getXMLSetup(void);
00182     bool readXMLSetup(void);
00183 
00184     // Load and parse the specific place(s)
00185     void getXMLData(const QString& source);
00186     bool readXMLData(const QString& source, QXmlStreamReader& xml);
00187 
00188     // Check if place specified is valid or not
00189     QStringList validate(const QString& source) const;
00190 
00191     // Catchall for unknown XML tags
00192     void parseUnknownElement(QXmlStreamReader& xml);
00193 
00194     // Parse weather XML data
00195     WeatherData parseWeatherSite(WeatherData& data, QXmlStreamReader& xml);
00196     void parseDateTime(WeatherData& data, QXmlStreamReader& xml, WeatherData::WarningInfo* warning = NULL);
00197     void parseLocations(WeatherData& data, QXmlStreamReader& xml);
00198     void parseConditions(WeatherData& data, QXmlStreamReader& xml);
00199     void parseWarnings(WeatherData& data, QXmlStreamReader& xml);
00200     void parseWindInfo(WeatherData& data, QXmlStreamReader& xml);
00201     void parseWeatherForecast(WeatherData& data, QXmlStreamReader& xml);
00202     void parseRegionalNormals(WeatherData& data, QXmlStreamReader& xml);
00203     void parseForecast(WeatherData& data, QXmlStreamReader& xml, WeatherData::ForecastInfo* forecast);
00204     void parseShortForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00205     void parseForecastTemperatures(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00206     void parseWindForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00207     void parsePrecipitationForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00208     void parsePrecipTotals(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml);
00209     void parseUVIndex(WeatherData& data, QXmlStreamReader& xml);
00210     void parseYesterdayWeather(WeatherData& data, QXmlStreamReader& xml);
00211     void parseAstronomicals(WeatherData& data, QXmlStreamReader& xml);
00212     void parseWeatherRecords(WeatherData& data, QXmlStreamReader& xml);
00213 
00214 private:
00215     class Private;
00216     Private *const d;
00217 };
00218 
00219 K_EXPORT_PLASMA_ION(envcan, EnvCanadaIon)
00220 
00221 #endif

Plasma

Skip menu "Plasma"
  • 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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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