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

0001 /***************************************************************************
0002  *   Copyright (C) 2007 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 KTCHUNKDOWNLOADMODEL_H
0022 #define KTCHUNKDOWNLOADMODEL_H
0023 
0024 #include <QAbstractTableModel>
0025 #include <interfaces/chunkdownloadinterface.h>
0026 
0027 namespace bt
0028 {
0029 class TorrentInterface;
0030 }
0031 
0032 namespace kt
0033 {
0034 
0035 /**
0036     @author
0037 */
0038 class ChunkDownloadModel : public QAbstractTableModel
0039 {
0040     Q_OBJECT
0041 public:
0042     ChunkDownloadModel(QObject *parent);
0043     ~ChunkDownloadModel() override;
0044 
0045     /// A peer has been added
0046     void downloadAdded(bt::ChunkDownloadInterface *cd);
0047 
0048     /// A download has been removed
0049     void downloadRemoved(bt::ChunkDownloadInterface *cd);
0050 
0051     /// change the current torrent
0052     void changeTC(bt::TorrentInterface *tc);
0053 
0054     /**
0055      * Update the model
0056      */
0057     void update();
0058 
0059     void clear();
0060 
0061     int rowCount(const QModelIndex &parent) const override;
0062     int columnCount(const QModelIndex &parent) const override;
0063     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0064     QVariant data(const QModelIndex &index, int role) const override;
0065     bool removeRows(int row, int count, const QModelIndex &parent) override;
0066     bool insertRows(int row, int count, const QModelIndex &parent) override;
0067     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0068 
0069 public Q_SLOTS:
0070     void sort(int col, Qt::SortOrder order) override;
0071 
0072 public:
0073     struct Item {
0074         mutable bt::ChunkDownloadInterface::Stats stats;
0075         bt::ChunkDownloadInterface *cd;
0076         QString files;
0077 
0078         Item(bt::ChunkDownloadInterface *cd, const QString &files);
0079 
0080         bool changed(int col, bool &modified) const;
0081         QVariant data(int col) const;
0082         bool lessThan(int col, const Item *other) const;
0083     };
0084 
0085 private:
0086     QList<Item *> items;
0087     bt::TorrentInterface *tc;
0088     int sort_column;
0089     Qt::SortOrder sort_order;
0090 };
0091 }
0092 
0093 #endif