Rework and improve http download cache: check cache against file on the server and...
[Rockbox.git] / rbutil / rbutilqt / httpget.h
blobacf86ddb95f5cdf73028526aa1272f0fcc0f8545
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #ifndef HTTPGET_H
22 #define HTTPGET_H
24 #include <QtCore>
25 #include <QtNetwork>
27 class QUrl;
29 class HttpGet : public QObject
31 Q_OBJECT
33 public:
34 HttpGet(QObject *parent = 0);
36 bool getFile(const QUrl &url);
37 void setProxy(const QUrl &url);
38 void setProxy(bool);
39 QHttp::Error error(void);
40 QString errorString(void);
41 void setFile(QFile*);
42 void setCache(QDir);
43 void setCache(bool);
44 int httpResponse(void);
45 QByteArray readAll(void);
46 bool isCached() { return m_cached; }
47 void setNoHeaderCheck(bool b) { m_noHeaderCheck = b; } //< disable checking of http header timestamp for caching
48 static void setGlobalCache(const QDir d) //< set global cache path
49 { m_globalCache = d; }
50 static void setGlobalProxy(const QUrl p) //< set global proxy value
51 { m_globalProxy = p; }
53 public slots:
54 void abort(void);
56 signals:
57 void done(bool);
58 void dataReadProgress(int, int);
59 void requestFinished(int, bool);
60 void headerFinished(void);
62 private slots:
63 void httpDone(bool error);
64 void httpProgress(int, int);
65 void httpFinished(int, bool);
66 void httpResponseHeader(const QHttpResponseHeader&);
67 void httpState(int);
68 void httpStarted(int);
69 void getFileFinish(void);
71 private:
72 bool initializeCache(const QDir&);
73 QHttp http; //< download object
74 QFile *outputFile;
75 int m_response; //< http response
76 int getRequest; //! get file http request id
77 int headRequest; //! get http header request id
78 QByteArray dataBuffer;
79 bool outputToBuffer;
80 bool m_usecache;
81 QDir m_cachedir;
82 QString m_cachefile; // cached filename
83 bool m_cached;
84 QUrl m_proxy;
85 static QDir m_globalCache; //< global cache path value
86 static QUrl m_globalProxy; //< global proxy value
87 QDateTime m_serverTimestamp; //< timestamp of file on server
88 QString m_query; //< constructed query to pass http getter
89 QString m_path; //< constructed path to pass http getter
90 QString m_hash; //< caching hash
91 bool m_noHeaderCheck; //< true if caching should ignore the server header
94 #endif