diff options
Diffstat (limited to 'utils/rbutilqt/base/httpget.h')
-rw-r--r-- | utils/rbutilqt/base/httpget.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/httpget.h b/utils/rbutilqt/base/httpget.h new file mode 100644 index 0000000000..dfd7b87c89 --- /dev/null +++ b/utils/rbutilqt/base/httpget.h | |||
@@ -0,0 +1,111 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Riebeling | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | |||
22 | #ifndef HTTPGET_H | ||
23 | #define HTTPGET_H | ||
24 | |||
25 | #include <QtCore> | ||
26 | #include <QtNetwork> | ||
27 | #include <QNetworkAccessManager> | ||
28 | #include "Logger.h" | ||
29 | |||
30 | class HttpGet : public QObject | ||
31 | { | ||
32 | Q_OBJECT | ||
33 | |||
34 | public: | ||
35 | HttpGet(QObject *parent = nullptr); | ||
36 | |||
37 | void getFile(const QUrl &url); | ||
38 | void setProxy(const QUrl &url); | ||
39 | void setProxy(bool); | ||
40 | QString errorString(void); | ||
41 | void setFile(QFile*); | ||
42 | void setCache(const QDir&); | ||
43 | void setCache(bool); | ||
44 | int httpResponse(void); | ||
45 | QByteArray readAll(void); | ||
46 | bool isCached() | ||
47 | { return m_lastRequestCached; } | ||
48 | QDateTime timestamp(void) | ||
49 | { return m_lastServerTimestamp; } | ||
50 | //< set global cache path | ||
51 | static void setGlobalCache(const QDir& d) | ||
52 | { | ||
53 | LOG_INFO() << "Global cache set to" << d.absolutePath(); | ||
54 | m_globalCache = d; | ||
55 | } | ||
56 | //< set global proxy value | ||
57 | static void setGlobalProxy(const QUrl& p) | ||
58 | { | ||
59 | LOG_INFO() << "setting global proxy" << p; | ||
60 | if(!p.isValid() || p.isEmpty()) { | ||
61 | HttpGet::m_globalProxy.setType(QNetworkProxy::NoProxy); | ||
62 | } | ||
63 | else { | ||
64 | HttpGet::m_globalProxy.setType(QNetworkProxy::HttpProxy); | ||
65 | HttpGet::m_globalProxy.setHostName(p.host()); | ||
66 | HttpGet::m_globalProxy.setPort(p.port()); | ||
67 | HttpGet::m_globalProxy.setUser(p.userName()); | ||
68 | HttpGet::m_globalProxy.setPassword(p.password()); | ||
69 | } | ||
70 | QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); | ||
71 | QNetworkProxy::setApplicationProxy(HttpGet::m_globalProxy); | ||
72 | } | ||
73 | //< set global user agent string | ||
74 | static void setGlobalUserAgent(const QString& u) | ||
75 | { m_globalUserAgent = u; } | ||
76 | |||
77 | public slots: | ||
78 | void abort(void); | ||
79 | |||
80 | signals: | ||
81 | void done(bool); | ||
82 | void dataReadProgress(int, int); | ||
83 | void requestFinished(int, bool); | ||
84 | void headerFinished(void); | ||
85 | |||
86 | private slots: | ||
87 | void requestFinished(QNetworkReply* reply); | ||
88 | void startRequest(QUrl url); | ||
89 | void downloadProgress(qint64 received, qint64 total); | ||
90 | void networkError(QNetworkReply::NetworkError error); | ||
91 | |||
92 | private: | ||
93 | static QString m_globalUserAgent; | ||
94 | static QNetworkProxy m_globalProxy; | ||
95 | QNetworkAccessManager m_mgr; | ||
96 | QNetworkReply *m_reply; | ||
97 | QNetworkDiskCache *m_cache; | ||
98 | QDir m_cachedir; | ||
99 | static QDir m_globalCache; //< global cache path value | ||
100 | QByteArray m_data; | ||
101 | QFile *m_outputFile; | ||
102 | int m_lastStatusCode; | ||
103 | QString m_lastErrorString; | ||
104 | QDateTime m_lastServerTimestamp; | ||
105 | bool m_lastRequestCached; | ||
106 | QNetworkProxy m_proxy; | ||
107 | }; | ||
108 | |||
109 | |||
110 | #endif | ||
111 | |||