]> git.sur5r.net Git - minitube/blob - src/networkaccess.h
770818651bf4295e8de1dbfd45bc53e0391e2f76
[minitube] / src / networkaccess.h
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #ifndef NETWORKACCESS_H
22 #define NETWORKACCESS_H
23
24 #include <QtCore>
25 #include <QtNetwork>
26
27 namespace The {
28     QNetworkAccessManager* networkAccessManager();
29 }
30
31 class NetworkReply : public QObject {
32
33     Q_OBJECT
34
35 public:
36     NetworkReply(QNetworkReply* networkReply);
37     QNetworkReply* getNetworkReply() { return networkReply; }
38
39 signals:
40     void data(QByteArray);
41     void error(QNetworkReply*);
42     void finished(QNetworkReply*);
43
44 private slots:
45     void finished();
46     void requestError(QNetworkReply::NetworkError);
47     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
48     void readTimeout();
49
50 private:
51     void setupReply();
52     QNetworkReply *networkReply;
53     QTimer *readTimeoutTimer;
54     int retryCount;
55
56 };
57
58 class NetworkAccess : public QObject {
59
60     Q_OBJECT
61
62 public:
63     NetworkAccess(QObject* parent = 0);
64     QNetworkReply* request(QUrl url,
65                              int operation = QNetworkAccessManager::GetOperation,
66                              const QByteArray &body = QByteArray(), uint offset = 0);
67     NetworkReply* get(QUrl url);
68     NetworkReply* head(QUrl url);
69     NetworkReply* post(QUrl url, const QMap<QString, QString>& params);
70
71 private:
72     QNetworkRequest buildRequest(QUrl url);
73
74 };
75
76 #endif // NETWORKACCESS_H