1 /*************************************************************************** 2 * Copyright (C) 2007 by Joris Guisson and Ivan Vasic * 3 * joris.guisson@gmail.com * 4 * ivasic@gmail.com * 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (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 * 18 * Free Software Foundation, Inc., * 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 20 ***************************************************************************/ 21 #ifndef KTTORRENTFILEMODEL_HH 22 #define KTTORRENTFILEMODEL_HH 23 24 #include <QAbstractItemModel> 25 #include <QByteArray> 26 27 #include <util/constants.h> 28 29 class QTreeView; 30 class QSortFilterProxyModel; 31 32 namespace bt 33 { 34 class TorrentInterface; 35 class TorrentFileInterface; 36 } 37 38 namespace kt 39 { 40 class TorrentFileModel : public QAbstractItemModel 41 { 42 Q_OBJECT 43 public: 44 enum DeselectMode 45 { 46 KEEP_FILES,DELETE_FILES 47 }; 48 TorrentFileModel(bt::TorrentInterface* tc,DeselectMode mode,QObject* parent); 49 ~TorrentFileModel() override; 50 51 52 /** 53 * Check all the files in the torrent. 54 */ 55 virtual void checkAll() = 0; 56 57 /** 58 * Uncheck all files in the torrent. 59 */ 60 virtual void uncheckAll() = 0; 61 62 /** 63 * Invert the check of each file of the torrent 64 */ 65 virtual void invertCheck() = 0; 66 67 /** 68 * Calculate the number of bytes to download 69 * @return Bytes to download 70 */ 71 virtual bt::Uint64 bytesToDownload() = 0; 72 73 /** 74 * Save which items are expanded. 75 * @param pm Proxy model of the view 76 * @param tv The QTreeView 77 * @return The expanded state encoded in a byte array 78 */ 79 virtual QByteArray saveExpandedState(QSortFilterProxyModel* pm,QTreeView* tv); 80 81 /** 82 * Restore the expanded state of the tree.in a QTreeView 83 * @param pm Proxy model of the view 84 * @param tv The QTreeView 85 * @param state The encoded expanded state 86 */ 87 virtual void loadExpandedState(QSortFilterProxyModel* pm,QTreeView* tv,const QByteArray & state); 88 89 /** 90 * Convert a model index to a file. 91 * @param idx The model index 92 * @return The file index or 0 for a directory 93 **/ 94 virtual bt::TorrentFileInterface* indexToFile(const QModelIndex & idx) = 0; 95 96 /** 97 * Get the path of a directory (root directory not included) 98 * @param idx The model index 99 * @return The path 100 */ 101 virtual QString dirPath(const QModelIndex & idx) = 0; 102 103 /** 104 * Change the priority of a bunch of items. 105 * @param indexes The list of items 106 * @param newpriority The new priority 107 */ 108 virtual void changePriority(const QModelIndexList & indexes,bt::Priority newpriority) = 0; 109 110 /** 111 * Missing files have been marked DND, update the preview and selection information. 112 */ 113 virtual void missingFilesMarkedDND(); 114 115 /** 116 * Update gui if necessary 117 */ 118 virtual void update(); 119 120 /** 121 * Codec has changed, so update the model. 122 */ 123 virtual void onCodecChange(); 124 125 /// Set the file names editable setFileNamesEditable(bool on)126 void setFileNamesEditable(bool on) {file_names_editable = on;} 127 128 /// Are the file names editable fileNamesEditable()129 bool fileNamesEditable() const {return file_names_editable;} 130 131 Qt::ItemFlags flags(const QModelIndex & index) const override; 132 133 virtual void filePercentageChanged(bt::TorrentFileInterface* file,float percentage); 134 virtual void filePreviewChanged(bt::TorrentFileInterface* file,bool preview); 135 Q_SIGNALS: 136 /** 137 * Emitted whenever one or more items changes check state 138 */ 139 void checkStateChanged(); 140 141 protected: 142 bt::TorrentInterface* tc; 143 DeselectMode mode; 144 bool file_names_editable; 145 }; 146 } 147 148 #endif 149