-
Notifications
You must be signed in to change notification settings - Fork 1
/
qtorrentlistmodel.h
executable file
·54 lines (46 loc) · 1.6 KB
/
qtorrentlistmodel.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
#ifndef QTORRENTLISTMODEL_H
#define QTORRENTLISTMODEL_H
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include <QHash>
#include <QSharedPointer>
#include "qtorrentobject.h"
#include "ArgoLoader.h"
class QTorrentListModel : public QAbstractListModel
{
Q_OBJECT
public:
Q_PROPERTY(int count READ count NOTIFY countChanged)
enum RoleNames {
NameRole = Qt::UserRole,
SpeedRole = Qt::UserRole+2,
TotalBytesRole = Qt::UserRole+3,
BytesDownloadedRole = Qt::UserRole+4,
dateTimeAddedRole = Qt::UserRole+5,
torrentStatusRole = Qt::UserRole+6
};
explicit QTorrentListModel(QObject *parent = 0);
~QTorrentListModel() {}
public:
// This is the interface for QAbstractListModel
// How many rows do we have (optimized rendering)
virtual int rowCount(const QModelIndex &parent) const override;
// Return data from the role and index given
virtual QVariant data(const QModelIndex &index, int role) const override;
// Add insertion
bool insert(int insert_index, QSharedPointer<QTorrentObject> torrent);
bool append(QSharedPointer<QTorrentObject> torrent);
QSharedPointer<QTorrentObject> get(int index);
int count();
void notifyOfUpdate(QSharedPointer<QTorrentObject> torrent);
QSharedPointer<QTorrentObject> lookupTorrent(const Argo::SHA1Hash& hash);
protected:
virtual QHash<int, QByteArray> roleNames() const override;
signals:
void countChanged(int newCount);
private:
QList<QSharedPointer<QTorrentObject>> m_torrents;
QHash<int, QByteArray> m_roleNames;
};
#endif // QTORRENTLISTMODEL_H