]> git.sur5r.net Git - minitube/blob - src/http/src/throttledhttp.h
4173b37531c1e5c72aff79b908fd8ee4bd4f52bf
[minitube] / src / http / src / throttledhttp.h
1 #ifndef THROTTLEDHTTP_H
2 #define THROTTLEDHTTP_H
3
4 #include "http.h"
5 #include <QtCore>
6 #include <QtNetwork>
7
8 class ThrottledHttp : public Http {
9 public:
10     ThrottledHttp(Http &http = Http::instance());
11     void setMilliseconds(int milliseconds) { this->milliseconds = milliseconds; }
12     QObject *request(const HttpRequest &req);
13
14 private:
15     Http &http;
16     int milliseconds;
17     QElapsedTimer elapsedTimer;
18 };
19
20 class ThrottledHttpReply : public HttpReply {
21     Q_OBJECT
22
23 public:
24     ThrottledHttpReply(Http &http,
25                        const HttpRequest &req,
26                        int milliseconds,
27                        QElapsedTimer &elapsedTimer);
28     QUrl url() const { return req.url; }
29     int statusCode() const { return 200; }
30     QByteArray body() const { return QByteArray(); }
31
32 private slots:
33     void checkElapsed();
34
35 private:
36     void doRequest();
37     Http &http;
38     HttpRequest req;
39     int milliseconds;
40     QElapsedTimer &elapsedTimer;
41     QTimer *timer;
42 };
43
44 #endif // THROTTLEDHTTP_H