1 | /* |
---|
2 | * This file Copyright (C) 2010-2015 Mnemosyne LLC |
---|
3 | * |
---|
4 | * It may be used under the GNU GPL versions 2 or 3 |
---|
5 | * or any future license endorsed by Mnemosyne LLC. |
---|
6 | * |
---|
7 | * $Id: TorrentModel.h 14540 2015-06-12 22:41:36Z mikedld $ |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef QTR_TORRENT_MODEL_H |
---|
11 | #define QTR_TORRENT_MODEL_H |
---|
12 | |
---|
13 | #include <QAbstractListModel> |
---|
14 | #include <QMap> |
---|
15 | #include <QSet> |
---|
16 | #include <QVector> |
---|
17 | |
---|
18 | class Prefs; |
---|
19 | class Speed; |
---|
20 | class Torrent; |
---|
21 | |
---|
22 | extern "C" |
---|
23 | { |
---|
24 | struct tr_variant; |
---|
25 | } |
---|
26 | |
---|
27 | class TorrentModel: public QAbstractListModel |
---|
28 | { |
---|
29 | Q_OBJECT |
---|
30 | |
---|
31 | public: |
---|
32 | enum Role |
---|
33 | { |
---|
34 | TorrentRole = Qt::UserRole |
---|
35 | }; |
---|
36 | |
---|
37 | public: |
---|
38 | TorrentModel (const Prefs& prefs); |
---|
39 | virtual ~TorrentModel (); |
---|
40 | |
---|
41 | void clear (); |
---|
42 | bool hasTorrent (const QString& hashString) const; |
---|
43 | |
---|
44 | Torrent * getTorrentFromId (int id); |
---|
45 | const Torrent * getTorrentFromId (int id) const; |
---|
46 | |
---|
47 | void getTransferSpeed (Speed& uploadSpeed, size_t& uploadPeerCount, |
---|
48 | Speed& downloadSpeed, size_t& downloadPeerCount); |
---|
49 | |
---|
50 | // QAbstractItemModel |
---|
51 | virtual int rowCount (const QModelIndex& parent = QModelIndex ()) const; |
---|
52 | virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; |
---|
53 | |
---|
54 | public slots: |
---|
55 | void updateTorrents (tr_variant * torrentList, bool isCompleteList); |
---|
56 | void removeTorrents (tr_variant * torrentList); |
---|
57 | void removeTorrent (int id); |
---|
58 | |
---|
59 | signals: |
---|
60 | void torrentsAdded (QSet<int>); |
---|
61 | |
---|
62 | private: |
---|
63 | typedef QMap<int, int> id_to_row_t; |
---|
64 | typedef QMap<int, Torrent*> id_to_torrent_t; |
---|
65 | typedef QVector<Torrent*> torrents_t; |
---|
66 | |
---|
67 | private: |
---|
68 | void addTorrent (Torrent *); |
---|
69 | QSet<int> getIds () const; |
---|
70 | |
---|
71 | private slots: |
---|
72 | void onTorrentChanged (int propertyId); |
---|
73 | |
---|
74 | private: |
---|
75 | const Prefs& myPrefs; |
---|
76 | |
---|
77 | id_to_row_t myIdToRow; |
---|
78 | id_to_torrent_t myIdToTorrent; |
---|
79 | torrents_t myTorrents; |
---|
80 | }; |
---|
81 | |
---|
82 | #endif // QTR_TORRENT_MODEL_H |
---|