-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilelistmodel.h
65 lines (49 loc) · 1.73 KB
/
filelistmodel.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef FILELISTMODEL_H
#define FILELISTMODEL_H
#include "datequeue.h"
#include "downloadqueue.h"
#include <QAbstractTableModel>
#include <QNetworkAccessManager>
class FileInfo;
class QNetworkReply;
class QObject;
class FileListModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit FileListModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const override;
QVariant headerData(int /*section*/, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
void append(FileInfo *value);
bool urlExists(FileInfo *info) const;
QString getSavePrefix() const;
void setSavePrefix(const QString &value);
bool getRun() const;
void setRun(bool value);
signals:
void downloadProgress(const QString &name, int percent, double rate);
void globalDownloadProgress(int downloadedFiles, int totalFiles);
void connectionLost();
private slots:
void onDownloadProgress(const QString &name, int percent, double rate);
void onFileDownloaded(FileInfo *fileinfo);
void onNetworkManagerFinished(QNetworkReply *reply);
void onTimerTimeout();
void onTimeout();
private:
void update(FileInfo *fileinfo, const QVector<int> &roles = QVector<int>());
void setDownloaded(FileInfo *info);
QNetworkAccessManager networkManager{this};
QNetworkReply *listReply{nullptr};
QString savePrefix;
DateQueue pendingList;
DownloadQueue downloadList;
QList<FileInfo *> fileList;
QTimer timer{this};
QTimer timeout{this};
};
#endif // FILELISTMODEL_H