-
Notifications
You must be signed in to change notification settings - Fork 12
/
DownloadManager.h
47 lines (40 loc) · 1.08 KB
/
DownloadManager.h
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
#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>
#include <QNetworkReply>
#include <QFile>
#include <QFileInfo>
#include <QDesktopServices>
#include <QQueue>
#include <QFileInfo>
#include <QStringList>
#include <QVariant>
#include <QPair>
#include <QUrl>
#define CACHE_SIZE 128 * 1024 * 1024
#define MAX_DOWNLOADS 16
class DownloadManager : public QObject
{
Q_OBJECT
public:
explicit DownloadManager(QObject *parent = 0);
public slots:
void append(const QStringList& urls);
void append(const QUrl& url, const QString& filename);
void remove(const QString& filename);
protected slots:
void nextDownload();
void readReady();
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void error(QNetworkReply::NetworkError code);
void finished();
private:
Q_DISABLE_COPY(DownloadManager)
QNetworkAccessManager manager;
QNetworkDiskCache cache;
QQueue<QPair<QUrl, QString> > queue;
QHash<QString, QFile *> downloads;
};
#endif // DOWNLOADMANAGER_H