Simplify progress emit in httpget class a bit.
[Rockbox.git] / rbutil / rbutilqt / httpget.h
blob0afd448bcd44b2c39c94710d9e74b8f71f044b3f
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()
47 { return m_cached; }
48 QDateTime timestamp(void)
49 { return m_serverTimestamp; }
50 void setDumbCache(bool b) //< disable checking of http header timestamp for caching
51 { m_dumbCache = b; }
52 static void setGlobalCache(const QDir d) //< set global cache path
53 { m_globalCache = d; }
54 static void setGlobalProxy(const QUrl p) //< set global proxy value
55 { m_globalProxy = p; }
56 static void setGlobalDumbCache(bool b) //< set "dumb" (ignore server status) caching mode
57 { m_globalDumbCache = b; }
59 public slots:
60 void abort(void);
62 signals:
63 void done(bool);
64 void dataReadProgress(int, int);
65 void requestFinished(int, bool);
66 void headerFinished(void);
68 private slots:
69 void httpDone(bool error);
70 void httpFinished(int, bool);
71 void httpResponseHeader(const QHttpResponseHeader&);
72 void httpState(int);
73 void httpStarted(int);
74 void getFileFinish(void);
76 private:
77 bool initializeCache(const QDir&);
78 QHttp http; //< download object
79 QFile *outputFile;
80 int m_response; //< http response
81 int getRequest; //! get file http request id
82 int headRequest; //! get http header request id
83 QByteArray dataBuffer;
84 bool outputToBuffer;
85 bool m_usecache;
86 QDir m_cachedir;
87 QString m_cachefile; // cached filename
88 bool m_cached;
89 QUrl m_proxy;
90 static QDir m_globalCache; //< global cache path value
91 static QUrl m_globalProxy; //< global proxy value
92 static bool m_globalDumbCache; //< cache "dumb" mode global setting
93 QDateTime m_serverTimestamp; //< timestamp of file on server
94 QString m_query; //< constructed query to pass http getter
95 QString m_path; //< constructed path to pass http getter
96 QString m_hash; //< caching hash
97 bool m_dumbCache; //< true if caching should ignore the server header
100 #endif