-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadManager.h
More file actions
83 lines (64 loc) · 1.93 KB
/
Copy pathDownloadManager.h
File metadata and controls
83 lines (64 loc) · 1.93 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef EFDL_DOWNLOAD_MANAGER_H
#define EFDL_DOWNLOAD_MANAGER_H
#include <QQueue>
#include <QMutex>
#include <QObject>
#include <QDateTime>
#include <QNetworkReply>
#include <QCryptographicHash>
#include "Range.h"
namespace efdl {
class Downloader;
}
class Chunk {
public:
Chunk(efdl::Range range, QDateTime started)
: range{range}, started{started}
{ }
bool isDone() const {
return range.first > 0 && range.first == range.second;
}
efdl::Range range;
QDateTime started, ended;
};
typedef QPair<QCryptographicHash::Algorithm, QString> HashPair;
class DownloadManager : public QObject {
Q_OBJECT
public:
DownloadManager(bool dryRun = false, bool connProg = false);
~DownloadManager();
void add(efdl::Downloader *entry);
void setVerifcations(const QList<HashPair> &pairs);
void createChecksum(QCryptographicHash::Algorithm hashAlg);
signals:
void finished();
public slots:
void start();
private slots:
void next();
void onInformation(const QString &outputPath, qint64 size, int chunksAmount,
int conns, qint64 offset);
void onChunkStarted(int num);
void onChunkProgress(int num, qint64 received, qint64 total);
void onChunkFinished(int num, efdl::Range range);
void onChunkFailed(int num, efdl::Range range, int httpCode,
QNetworkReply::NetworkError error);
private:
void cleanup();
void updateChunkMap();
void updateProgress();
void verifyIntegrity(const HashPair &pair);
void printChecksum();
QQueue<efdl::Downloader*> queue;
bool dryRun, connProg, chksum;
QString outputPath;
int conns, chunksAmount, chunksFinished;
qint64 size, offset, bytesDown;
QDateTime started, lastProgress;
QList<HashPair> verifyList;
QCryptographicHash::Algorithm hashAlg;
efdl::Downloader *downloader;
QMutex chunkMutex;
QMap<int, Chunk*> chunkMap; // num -> download progress
};
#endif // EFDL_DOWNLOAD_MANAGER_H