warehouse for ces2019
[apps/onscreenapp.git] / app / src / httpclient.h
1
2 #ifndef HTTPCLIENT_H
3 #define HTTPCLIENT_H
4
5 #include <functional>
6 #include <QtGlobal>
7
8 class QString;
9 class QByteArray;
10 class QNetworkRequest;
11 class QNetworkReply;
12 class QNetworkAccessManager;
13 class HttpClientPrivate;
14
15 class HttpClient {
16  public:
17   HttpClient(const QString& url);
18   ~HttpClient();
19
20   HttpClient& manager(QNetworkAccessManager* manager);
21
22   HttpClient& debug(bool debug);
23
24   HttpClient& param(const QString& name, const QString& value);
25
26   HttpClient& header(const QString& header, const QString& value);
27
28   void get(std::function<void(const QString&)> successHandler,
29            std::function<void(const QString&)> errorHandler = NULL,
30            const char* encoding = "UTF-8");
31
32   void download(
33       const QString& savePath,
34       std::function<void(const QString&)> successHandler = NULL,
35       std::function<void(const QString&)> errorHandler = NULL,
36       std::function<void(const qint64, const qint64)> progressHandler = NULL);
37
38   void download(
39       std::function<void(const QByteArray&)> readyRead,
40       std::function<void(const QString&)> successHandler = NULL,
41       std::function<void(const QString&)> errorHandler = NULL,
42       std::function<void(const qint64, const qint64)> progressHandler = NULL);
43
44  private:
45   HttpClientPrivate* d;
46 };
47
48 #endif  // !HTTPCLIENT_H