~gabriel1984sibiu/clipgrab/trunk

« back to all changes in this revision

Viewing changes to http_handler.h

  • Committer: Grevutiu Gabriel
  • Date: 2015-04-23 16:13:23 UTC
  • Revision ID: gabriel1984sibiu@gmail.com-20150423161323-63h88qa11tvxqcrd
original upstream source code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    ClipGrab³
 
3
    Copyright (C) Philipp Schmieder
 
4
    http://clipgrab.de
 
5
    feedback [at] clipgrab [dot] de
 
6
 
 
7
    This file is part of ClipGrab.
 
8
    ClipGrab is free software: you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation, either version 3 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    ClipGrab is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License
 
19
    along with ClipGrab.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
 
 
23
 
 
24
#ifndef HTTP_HANDLER_H
 
25
#define HTTP_HANDLER_H
 
26
 
 
27
#include <QtNetwork>
 
28
#include <QTemporaryFile>
 
29
#include <QDebug>
 
30
 
 
31
struct download
 
32
{
 
33
 
 
34
    download()
 
35
    {
 
36
        size = 0;
 
37
        currentProgress = 0;
 
38
        progress = 0;
 
39
                chunked = false;
 
40
                finished = false;
 
41
                redirectLevel = 0;
 
42
                tempFile = NULL;
 
43
                reply = NULL;
 
44
    }
 
45
 
 
46
    QNetworkReply* reply;
 
47
 
 
48
    QTemporaryFile* tempFile;
 
49
 
 
50
    qint64 size;
 
51
    qint64 progress;
 
52
 
 
53
    qint64 currentProgress;
 
54
    bool chunked;
 
55
 
 
56
    int redirectLevel;
 
57
    bool finished;
 
58
 
 
59
    qint64 getProgress()
 
60
    {
 
61
        return currentProgress + progress;
 
62
    };
 
63
};
 
64
 
 
65
class http_handler : public QObject
 
66
{
 
67
    Q_OBJECT
 
68
 
 
69
    public:
 
70
    http_handler();
 
71
 
 
72
 
 
73
    QNetworkReply* addDownload(QString, bool chunked=false, QByteArray postData=NULL);
 
74
    void continueDownload(download*);
 
75
    void cancelAllDownloads();
 
76
    void clearDownloads();
 
77
    QList<download*> downloads;
 
78
 
 
79
    QNetworkAccessManager* networkAccessManager;
 
80
 
 
81
    QNetworkRequest createRequest(QUrl);
 
82
    download* getDownload(QNetworkReply*);
 
83
 
 
84
    protected slots:
 
85
        void dataHandler();
 
86
        void handleFinishedDownload(download* );
 
87
        void handleNetworkReply(QNetworkReply*);
 
88
        void handleSSLError(QNetworkReply* reply, const QList<QSslError> & errors);
 
89
 
 
90
 
 
91
    signals:
 
92
        void error(QString);
 
93
        void downloadProgress(qint64, qint64);
 
94
 
 
95
        void downloadFinished(download*);
 
96
        void allDownloadsFinished();
 
97
        void progressChanged(qint64 bytesReceived, qint64 bytesTotal);
 
98
};
 
99
 
 
100
#endif // HTTP_HANDLER_H