qBittorrent
transferlistmodel.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
4  * Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, the copyright holders give permission to
21  * link this program with the OpenSSL project's "OpenSSL" library (or with
22  * modified versions of it that use the same license as the "OpenSSL" library),
23  * and distribute the linked executables. You must obey the GNU General Public
24  * License in all respects for all of the code used other than "OpenSSL". If you
25  * modify file(s), you may extend this exception to your version of the file(s),
26  * but you are not obligated to do so. If you do not wish to do so, delete this
27  * exception statement from your version.
28  */
29 
30 #pragma once
31 
32 #include <QAbstractListModel>
33 #include <QColor>
34 #include <QHash>
35 #include <QList>
36 
38 
39 namespace BitTorrent
40 {
41  class InfoHash;
42 }
43 
44 class TransferListModel final : public QAbstractListModel
45 {
46  Q_OBJECT
47  Q_DISABLE_COPY_MOVE(TransferListModel)
48 
49 public:
50  enum Column
51  {
83 
85  };
86 
87  enum DataRole
88  {
89  UnderlyingDataRole = Qt::UserRole,
91  };
92 
93  explicit TransferListModel(QObject *parent = nullptr);
94 
95  int rowCount(const QModelIndex &parent = {}) const override;
96  int columnCount(const QModelIndex &parent = {}) const override;
97  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
98  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
99  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
100  Qt::ItemFlags flags(const QModelIndex &index) const override;
101 
102  BitTorrent::Torrent *torrentHandle(const QModelIndex &index) const;
103 
104 private slots:
105  void addTorrent(BitTorrent::Torrent *const torrent);
107  void handleTorrentStatusUpdated(BitTorrent::Torrent *const torrent);
108  void handleTorrentsUpdated(const QVector<BitTorrent::Torrent *> &torrents);
109 
110 private:
111  void configure();
112  QString displayValue(const BitTorrent::Torrent *torrent, int column) const;
113  QVariant internalValue(const BitTorrent::Torrent *torrent, int column, bool alt) const;
114 
115  QList<BitTorrent::Torrent *> m_torrentList; // maps row number to torrent handle
116  QHash<BitTorrent::Torrent *, int> m_torrentMap; // maps torrent handle to row number
117  const QHash<BitTorrent::TorrentState, QString> m_statusStrings;
118  // row text colors
119  const QHash<BitTorrent::TorrentState, QColor> m_stateThemeColors;
120 
122  {
123  Never,
124  Paused,
125  Always
126  };
127 
129 };
void handleTorrentStatusUpdated(BitTorrent::Torrent *const torrent)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
int rowCount(const QModelIndex &parent={}) const override
QHash< BitTorrent::Torrent *, int > m_torrentMap
const QHash< BitTorrent::TorrentState, QColor > m_stateThemeColors
HideZeroValuesMode m_hideZeroValuesMode
void addTorrent(BitTorrent::Torrent *const torrent)
QList< BitTorrent::Torrent * > m_torrentList
QString displayValue(const BitTorrent::Torrent *torrent, int column) const
const QHash< BitTorrent::TorrentState, QString > m_statusStrings
QVariant internalValue(const BitTorrent::Torrent *torrent, int column, bool alt) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
void handleTorrentsUpdated(const QVector< BitTorrent::Torrent * > &torrents)
BitTorrent::Torrent * torrentHandle(const QModelIndex &index) const
TransferListModel(QObject *parent=nullptr)
int columnCount(const QModelIndex &parent={}) const override
void handleTorrentAboutToBeRemoved(BitTorrent::Torrent *const torrent)
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64