1 /* 2 SPDX-FileCopyrightText: 2008 Joris Guisson <joris.guisson@gmail.com> 3 SPDX-FileCopyrightText: 2008 Ivan Vasic <ivasic@gmail.com> 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef KTTRACKERMODEL_H 8 #define KTTRACKERMODEL_H 9 10 #include <QAbstractTableModel> 11 #include <QList> 12 #include <QUrl> 13 14 #include <interfaces/trackerinterface.h> 15 16 namespace bt 17 { 18 class TorrentInterface; 19 } 20 21 namespace kt 22 { 23 /** 24 @author 25 */ 26 class TrackerModel : public QAbstractTableModel 27 { 28 Q_OBJECT 29 public: 30 TrackerModel(QObject *parent); 31 ~TrackerModel() override; 32 33 void changeTC(bt::TorrentInterface *tc); 34 void update(); 35 36 int rowCount(const QModelIndex &parent) const override; 37 int columnCount(const QModelIndex &parent) const override; 38 QVariant data(const QModelIndex &index, int role) const override; 39 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 40 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 41 bool insertRows(int row, int count, const QModelIndex &parent) override; 42 bool removeRows(int row, int count, const QModelIndex &parent) override; 43 Qt::ItemFlags flags(const QModelIndex &index) const override; 44 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 45 46 /// Get a tracker url given a model index 47 QUrl trackerUrl(const QModelIndex &idx); 48 49 /// Get a tracker given a model index 50 bt::TrackerInterface *tracker(const QModelIndex &idx); 51 52 /// Add trackers to the model 53 void addTrackers(QList<bt::TrackerInterface *> &tracker_list); 54 55 private: 56 struct Item { 57 bt::TrackerInterface *trk; 58 bt::TrackerStatus status; 59 int seeders; 60 int leechers; 61 int times_downloaded; 62 unsigned int time_to_next_update; 63 64 Item(bt::TrackerInterface *tracker); 65 bool update(); 66 QVariant displayData(int column) const; 67 QVariant sortData(int column) const; 68 }; 69 70 bt::TorrentInterface *tc; 71 QList<Item *> trackers; 72 bool running; 73 }; 74 75 } 76 77 #endif 78