mainwindow: update environment variable http_proxy to qt_http_proxy
[apps/thermostat-demo.git] / webdataengine / openweathermapdataengine.h
1 #ifndef OPENWEATHERMAPDATAENGINE_H
2 #define OPENWEATHERMAPDATAENGINE_H
4 #include <QHash>
6 #include "webdataengine.h"
8 class OpenWeatherMapDataEngine : public WebDataEngine
9 {
10     Q_OBJECT
11 public:
12     explicit OpenWeatherMapDataEngine(QNetworkAccessManager *manager, QObject *parent = 0);
13     
14     void setCity(QString city);
15     void dispatchRequest();
16     void loadLocalData();
18     QString licenseString();
20 signals:
21     
22 public slots:
23     void responseReceived();
24     void currentWeatherResponseReceived();
25     void forecastResponseReceived();
26     void handleNetworkTimeout();
28 private:
30     bool readFromCache(QString alternateCachePath = "");
31     bool writeToCache();
33     WeatherData* m_weatherData;
35     void dispatchWeatherDataRequests();
37     qint64 parseCityInformation(QString jsonData);
38     bool parseJSONWeatherData(QString* jsonData, WeatherData* weatherData);
39     bool parseJSONForecastData(QString* jsonData, WeatherData* weatherData);
40     void generateJSONWeatherLookupTables();
41     void checkIfDone();
43     qint64 m_cityId;
44     QNetworkReply *m_forecastReply;
45     QTimer m_forecastNetworkTimer;
47     QHash<int, QString> m_iconNameToWeatherHash;
48     QHash<QString, int> m_weatherPriorityHash;
50     //for some reason api returns temp in kelvin
51     int kelvinToFahrenheit(double k);
53     //api gives back image url that we can convert to use meaningful weather names
54     int convertImageNameToIndex(QString img);
56     //flags to make sure we've received both portions of the weather data
57     bool m_forecastReceived;
58     bool m_weatherReceived;
60     QString m_rawJSONWeatherString;
61     QString m_rawJSONForecastString;
62 };
64 #endif // OPENWEATHERMAPDATAENGINE_H