diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-03-05 21:12:24 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-03-05 21:12:24 +0000 |
commit | 5a75184c4abfd2c8fa2a3ee705b94fc800d7b918 (patch) | |
tree | dcbb9529aafc259fd8922b471c8ff537bb48a8fe /rbutil/rbutilqt/httpget.cpp | |
parent | 0def1dd23cf1990536122d35ed040173ddaa06ba (diff) | |
download | rockbox-5a75184c4abfd2c8fa2a3ee705b94fc800d7b918.tar.gz rockbox-5a75184c4abfd2c8fa2a3ee705b94fc800d7b918.zip |
add global proxy / cache settings to httpget class. This removes the need of passing proxy / cache values around all the time. Each object can still override the global values.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16530 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/httpget.cpp')
-rw-r--r-- | rbutil/rbutilqt/httpget.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/rbutil/rbutilqt/httpget.cpp b/rbutil/rbutilqt/httpget.cpp index acd8940b77..a45769c246 100644 --- a/rbutil/rbutilqt/httpget.cpp +++ b/rbutil/rbutilqt/httpget.cpp | |||
@@ -23,6 +23,8 @@ | |||
23 | 23 | ||
24 | #include "httpget.h" | 24 | #include "httpget.h" |
25 | 25 | ||
26 | QDir HttpGet::m_globalCache; | ||
27 | QUrl HttpGet::m_globalProxy; | ||
26 | 28 | ||
27 | HttpGet::HttpGet(QObject *parent) | 29 | HttpGet::HttpGet(QObject *parent) |
28 | : QObject(parent) | 30 | : QObject(parent) |
@@ -36,6 +38,14 @@ HttpGet::HttpGet(QObject *parent) | |||
36 | // hint about this in the http response instead of nonsense. | 38 | // hint about this in the http response instead of nonsense. |
37 | response = -1; | 39 | response = -1; |
38 | 40 | ||
41 | // default to global proxy / cache if not empty. | ||
42 | // proxy is automatically enabled, disable it by setting an empty proxy | ||
43 | // cache is enabled to be in line, can get disabled with setCache(bool) | ||
44 | qDebug() << "setting global proxy / cache"; | ||
45 | if(!m_globalProxy.isEmpty()) | ||
46 | setProxy(m_globalProxy); | ||
47 | m_usecache = false; | ||
48 | m_cachedir = m_globalCache; | ||
39 | connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool))); | 49 | connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool))); |
40 | connect(&http, SIGNAL(dataReadProgress(int, int)), this, SLOT(httpProgress(int, int))); | 50 | connect(&http, SIGNAL(dataReadProgress(int, int)), this, SLOT(httpProgress(int, int))); |
41 | connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpFinished(int, bool))); | 51 | connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpFinished(int, bool))); |
@@ -60,13 +70,14 @@ void HttpGet::setCache(QDir d) | |||
60 | result = m_cachedir.mkdir("rbutil-cache"); | 70 | result = m_cachedir.mkdir("rbutil-cache"); |
61 | } | 71 | } |
62 | else result = false; | 72 | else result = false; |
63 | qDebug() << "HttpGet::setCache(QDir)" << result; | 73 | qDebug() << "HttpGet::setCache(QDir)" << d << result; |
64 | m_usecache = result; | 74 | m_usecache = result; |
65 | } | 75 | } |
66 | 76 | ||
67 | 77 | ||
68 | void HttpGet::setCache(bool c) | 78 | void HttpGet::setCache(bool c) |
69 | { | 79 | { |
80 | qDebug() << "setCache(bool)" << c; | ||
70 | m_usecache = c; | 81 | m_usecache = c; |
71 | } | 82 | } |
72 | 83 | ||
@@ -91,8 +102,19 @@ void HttpGet::httpProgress(int read, int total) | |||
91 | 102 | ||
92 | void HttpGet::setProxy(const QUrl &proxy) | 103 | void HttpGet::setProxy(const QUrl &proxy) |
93 | { | 104 | { |
94 | qDebug() << "HttpGet::setProxy" << proxy.toString(); | 105 | qDebug() << "HttpGet::setProxy(QUrl)" << proxy.toString(); |
95 | http.setProxy(proxy.host(), proxy.port(), proxy.userName(), proxy.password()); | 106 | m_proxy = proxy; |
107 | http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); | ||
108 | } | ||
109 | |||
110 | |||
111 | void HttpGet::setProxy(bool enable) | ||
112 | { | ||
113 | qDebug() << "HttpGet::setProxy(bool)" << enable; | ||
114 | if(enable) | ||
115 | http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); | ||
116 | else | ||
117 | http.setProxy("", 0); | ||
96 | } | 118 | } |
97 | 119 | ||
98 | 120 | ||
@@ -171,6 +193,7 @@ bool HttpGet::getFile(const QUrl &url) | |||
171 | else { | 193 | else { |
172 | qDebug() << "[HTTP] cache DISABLED"; | 194 | qDebug() << "[HTTP] cache DISABLED"; |
173 | } | 195 | } |
196 | |||
174 | http.setHost(url.host(), url.port(80)); | 197 | http.setHost(url.host(), url.port(80)); |
175 | // construct query (if any) | 198 | // construct query (if any) |
176 | QList<QPair<QString, QString> > qitems = url.queryItems(); | 199 | QList<QPair<QString, QString> > qitems = url.queryItems(); |