Initial import
[medard] / src / medarddownloader.h
1 /*
2  *  Medard for Maemo.
3  *  Copyright (C) 2011 Roman Moravcik
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef MEDARDDOWNLOADER_H
21 #define MEDARDDOWNLOADER_H
22
23 #include <QObject>
24 #include <QDateTime>
25 #include <QString>
26 #include <QSize>
27 #include <QTimer>
28 #include <QtNetwork/QNetworkAccessManager>
29 #include <QtNetwork/QNetworkReply>
30
31 class MedardDownloader : public QObject
32 {
33     Q_OBJECT
34
35 public:
36     enum ForecastType {
37         SeaLevelPressure = 0,
38         Precipitation = 1,
39         WindVelocity = 2,
40         Cloudiness = 3,
41         Temperature  = 4
42     };
43
44     enum ForecastDomain {
45         Europe = 0,
46         CzechRepublic = 1
47     };
48
49     MedardDownloader();
50     ~MedardDownloader();
51
52     void setForecastType(ForecastType type);
53
54     void setForecastDomain(ForecastDomain domain);
55
56     void setForecastInitialDate(QDateTime date);
57     QDateTime getForecastInitialDate();
58     QDateTime getForecastDate();
59
60     void setForecastDateOffset(int offset);
61     int getForecastDateOffset();
62     int getMinForecastDateOffset();
63     int getMaxForecastDateOffset();
64
65     void downloadImage();
66
67     QSize getImageSize();
68
69 signals:
70     void downloadFinished(const QString &filename, const QDateTime &date);
71     void downloadFailed();
72
73 private slots:
74     void retryTimerEvent();
75     void clearDownloadRequest();
76
77     void downloadImageFinished();
78     void downloadImageError(QNetworkReply::NetworkError code);
79
80     void retrieveForecastInitialDateFinished();
81     void retrieveForecastInitialDateError(QNetworkReply::NetworkError code);
82
83 private:
84     void tryDownloadImageAgain();
85     bool isDownloaded(const QString filename);
86
87     void retrieveForecastInitialDate();
88
89     void createCacheDirectory();
90     void cleanCacheDirectory();
91
92 private:
93     QDateTime m_forecastInitialDate;
94     QString m_forecastInitialDateCode;
95     int m_forecastDateOffset;
96     QString m_forecastType;
97     QString m_forecastDomain;
98
99     QNetworkAccessManager *m_network;
100     QNetworkReply *m_reply;
101
102     int m_retryCounter;
103     QTimer *m_retryTimer;
104
105     QString m_cachePath;
106 };
107
108 #endif // MEDARDDOWNLOADER_H