source: trunk/qt/TorrentModel.h @ 14539

Last change on this file since 14539 was 14539, checked in by mikedld, 6 years ago

Unify/prettify Qt client headers style

  • Property svn:keywords set to Date Rev Author Id
File size: 1.7 KB
Line 
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 14539 2015-06-12 22:12:12Z 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
18class Prefs;
19class Speed;
20class Torrent;
21
22extern "C"
23{
24  struct tr_variant;
25}
26
27class 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  signals:
55    void torrentsAdded (QSet<int>);
56
57  public slots:
58    void updateTorrents (tr_variant * torrentList, bool isCompleteList);
59    void removeTorrents (tr_variant * torrentList);
60    void removeTorrent (int id);
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
Note: See TracBrowser for help on using the repository browser.