diff options
-rw-r--r-- | rbutil/rbutilqt/base/httpget.cpp | 37 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/httpget.h | 2 |
2 files changed, 33 insertions, 6 deletions
diff --git a/rbutil/rbutilqt/base/httpget.cpp b/rbutil/rbutilqt/base/httpget.cpp index 4d10301bc0..476da87bad 100644 --- a/rbutil/rbutilqt/base/httpget.cpp +++ b/rbutil/rbutilqt/base/httpget.cpp | |||
@@ -44,8 +44,9 @@ HttpGet::HttpGet(QObject *parent) | |||
44 | } | 44 | } |
45 | 45 | ||
46 | 46 | ||
47 | //! @brief set cache path | 47 | /** @brief set cache path |
48 | // @param d new directory to use as cache path | 48 | * @param d new directory to use as cache path |
49 | */ | ||
49 | void HttpGet::setCache(const QDir& d) | 50 | void HttpGet::setCache(const QDir& d) |
50 | { | 51 | { |
51 | if(m_cache && m_cachedir == d.absolutePath()) | 52 | if(m_cache && m_cachedir == d.absolutePath()) |
@@ -95,6 +96,9 @@ QByteArray HttpGet::readAll() | |||
95 | } | 96 | } |
96 | 97 | ||
97 | 98 | ||
99 | /** @brief Set and enable Proxy to use. | ||
100 | * @param proxy Proxy URL. | ||
101 | */ | ||
98 | void HttpGet::setProxy(const QUrl &proxy) | 102 | void HttpGet::setProxy(const QUrl &proxy) |
99 | { | 103 | { |
100 | LOG_INFO() << "Proxy set to" << proxy; | 104 | LOG_INFO() << "Proxy set to" << proxy; |
@@ -107,6 +111,9 @@ void HttpGet::setProxy(const QUrl &proxy) | |||
107 | } | 111 | } |
108 | 112 | ||
109 | 113 | ||
114 | /** @brief Enable or disable use of previously set proxy. | ||
115 | * @param enable Enable proxy. | ||
116 | */ | ||
110 | void HttpGet::setProxy(bool enable) | 117 | void HttpGet::setProxy(bool enable) |
111 | { | 118 | { |
112 | if(enable) m_mgr->setProxy(m_proxy); | 119 | if(enable) m_mgr->setProxy(m_proxy); |
@@ -114,6 +121,14 @@ void HttpGet::setProxy(bool enable) | |||
114 | } | 121 | } |
115 | 122 | ||
116 | 123 | ||
124 | /** @brief Set output file. | ||
125 | * | ||
126 | * Set filename for storing the downloaded file to. If no file is set the | ||
127 | * downloaded file will not be stored to disk but kept in memory. The result | ||
128 | * can then be retrieved using readAll(). | ||
129 | * | ||
130 | * @param file Output file. | ||
131 | */ | ||
117 | void HttpGet::setFile(QFile *file) | 132 | void HttpGet::setFile(QFile *file) |
118 | { | 133 | { |
119 | m_outputFile = file; | 134 | m_outputFile = file; |
@@ -202,22 +217,34 @@ void HttpGet::networkError(QNetworkReply::NetworkError error) | |||
202 | } | 217 | } |
203 | 218 | ||
204 | 219 | ||
205 | bool HttpGet::getFile(const QUrl &url) | 220 | /** @brief Retrieve the file pointed to by url. |
221 | * | ||
222 | * Note: This also handles file:// URLs. Be aware that QUrl requires file:// | ||
223 | * URLs to be absolute, i.e. file://filename.txt doesn't work. Use | ||
224 | * QDir::absoluteFilePath() to convert to an absolute path first. | ||
225 | * | ||
226 | * @param url URL to download. | ||
227 | */ | ||
228 | void HttpGet::getFile(const QUrl &url) | ||
206 | { | 229 | { |
207 | LOG_INFO() << "Get URI" << url.toString(); | 230 | LOG_INFO() << "Get URI" << url.toString(); |
208 | m_data.clear(); | 231 | m_data.clear(); |
209 | startRequest(url); | 232 | startRequest(url); |
210 | |||
211 | return false; | ||
212 | } | 233 | } |
213 | 234 | ||
214 | 235 | ||
236 | /** @brief Retrieve string representation for most recent error. | ||
237 | * @return Error string. | ||
238 | */ | ||
215 | QString HttpGet::errorString(void) | 239 | QString HttpGet::errorString(void) |
216 | { | 240 | { |
217 | return m_lastErrorString; | 241 | return m_lastErrorString; |
218 | } | 242 | } |
219 | 243 | ||
220 | 244 | ||
245 | /** @brief Return last HTTP response code. | ||
246 | * @return Response code. | ||
247 | */ | ||
221 | int HttpGet::httpResponse(void) | 248 | int HttpGet::httpResponse(void) |
222 | { | 249 | { |
223 | return m_lastStatusCode; | 250 | return m_lastStatusCode; |
diff --git a/rbutil/rbutilqt/base/httpget.h b/rbutil/rbutilqt/base/httpget.h index 8c62157e5f..0bd3d284ac 100644 --- a/rbutil/rbutilqt/base/httpget.h +++ b/rbutil/rbutilqt/base/httpget.h | |||
@@ -34,7 +34,7 @@ class HttpGet : public QObject | |||
34 | public: | 34 | public: |
35 | HttpGet(QObject *parent = 0); | 35 | HttpGet(QObject *parent = 0); |
36 | 36 | ||
37 | bool getFile(const QUrl &url); | 37 | void getFile(const QUrl &url); |
38 | void setProxy(const QUrl &url); | 38 | void setProxy(const QUrl &url); |
39 | void setProxy(bool); | 39 | void setProxy(bool); |
40 | QString errorString(void); | 40 | QString errorString(void); |