File indexing completed on 2024-05-05 04:59:14

0001 /***************************************************************************
0002  *   Copyright (C) 2008 by Joris Guisson and Ivan Vasic                    *
0003  *   joris.guisson@gmail.com                                               *
0004  *   ivasic@gmail.com                                                      *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, write to the                         *
0018  *   Free Software Foundation, Inc.,                                       *
0019  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
0020  ***************************************************************************/
0021 #ifndef KTTRACKERMODEL_H
0022 #define KTTRACKERMODEL_H
0023 
0024 #include <QAbstractTableModel>
0025 #include <QList>
0026 #include <QUrl>
0027 
0028 #include <interfaces/trackerinterface.h>
0029 
0030 namespace bt
0031 {
0032 class TorrentInterface;
0033 }
0034 
0035 namespace kt
0036 {
0037 
0038 /**
0039     @author
0040 */
0041 class TrackerModel : public QAbstractTableModel
0042 {
0043     Q_OBJECT
0044 public:
0045     TrackerModel(QObject *parent);
0046     ~TrackerModel() override;
0047 
0048     void changeTC(bt::TorrentInterface *tc);
0049     void update();
0050 
0051     int rowCount(const QModelIndex &parent) const override;
0052     int columnCount(const QModelIndex &parent) const override;
0053     QVariant data(const QModelIndex &index, int role) const override;
0054     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0055     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0056     bool insertRows(int row, int count, const QModelIndex &parent) override;
0057     bool removeRows(int row, int count, const QModelIndex &parent) override;
0058     Qt::ItemFlags flags(const QModelIndex &index) const override;
0059     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0060 
0061     /// Get a tracker url given a model index
0062     QUrl trackerUrl(const QModelIndex &idx);
0063 
0064     /// Get a tracker given a model index
0065     bt::TrackerInterface *tracker(const QModelIndex &idx);
0066 
0067 private:
0068     struct Item {
0069         bt::TrackerInterface *trk;
0070         bt::TrackerStatus status;
0071         int seeders;
0072         int leechers;
0073         int times_downloaded;
0074         int time_to_next_update;
0075 
0076         Item(bt::TrackerInterface *tracker);
0077         bool update();
0078         QVariant displayData(int column) const;
0079         QVariant sortData(int column) const;
0080     };
0081 
0082     bt::TorrentInterface *tc;
0083     QList<Item *> trackers;
0084     bool running;
0085 };
0086 }
0087 
0088 #endif