-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownloader.h
More file actions
51 lines (47 loc) · 1.22 KB
/
downloader.h
File metadata and controls
51 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QUrl>
#include <QQueue>
#include <QMap>
#include <QTimer>
#include <QNetworkReply>
#include "output.h"
struct Download
{
QUrl url;
QString description;
QNetworkReply* reply;
bool operator ==(const Download& other);
};
class Downloader : public QObject
{
Q_OBJECT
int lastLength;
QTimer timer;
QList<Download> downloadQueue;
QNetworkAccessManager* manager;
QMap<QNetworkReply*,QUrl> replyUrlMap;
QMap<QUrl,QUrl> redirectMapping;
int maxConnections;
int numConnections;
QList<Download> currentDownloads;
void continueQueue();
void printProgress();
QUrl getUnredirectedUrl(QUrl url);
int getDownloadIndexByReply(QNetworkReply *reply);
public:
explicit Downloader(QObject *parent = 0);
void load(const QUrl& url, const QString& description);
int getMaxConnections() const;
void setMaxConnections(int value);
void abort(const QUrl& url);
signals:
void downloadSuccess(const QUrl& url, const QByteArray& data);
void downloadFailed(const QUrl& url, QNetworkReply::NetworkError error);
void queueEmpty();
private slots:
void downloadFinished(QNetworkReply* reply);
};
#endif // DOWNLOADER_H