2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2022 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2006-2012 Christophe Dumez <chris@qbittorrent.org>
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.
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.
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.
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.
32 #include <QAbstractItemModel>
35 #include "base/indexrange.h"
36 #include "base/pathfwd.h"
37 #include "torrentcontentmodelitem.h"
39 class QFileIconProvider
;
43 class TorrentContentModelFile
;
47 class TorrentContentHandler
;
50 class TorrentContentModel final
: public QAbstractItemModel
53 Q_DISABLE_COPY_MOVE(TorrentContentModel
)
58 UnderlyingDataRole
= Qt::UserRole
61 explicit TorrentContentModel(QObject
*parent
= nullptr);
62 ~TorrentContentModel() override
;
64 void setContentHandler(BitTorrent::TorrentContentHandler
*contentHandler
);
65 BitTorrent::TorrentContentHandler
*contentHandler() const;
69 QVector
<BitTorrent::DownloadPriority
> getFilePriorities() const;
70 TorrentContentModelItem::ItemType
itemType(const QModelIndex
&index
) const;
71 int getFileIndex(const QModelIndex
&index
) const;
72 Path
getItemPath(const QModelIndex
&index
) const;
74 int columnCount(const QModelIndex
&parent
= {}) const override
;
75 bool setData(const QModelIndex
&index
, const QVariant
&value
, int role
= Qt::EditRole
) override
;
76 QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const override
;
77 Qt::ItemFlags
flags(const QModelIndex
&index
) const override
;
78 QVariant
headerData(int section
, Qt::Orientation orientation
, int role
) const override
;
79 QModelIndex
index(int row
, int column
, const QModelIndex
&parent
= {}) const override
;
80 QModelIndex
parent(const QModelIndex
&index
) const override
;
81 int rowCount(const QModelIndex
&parent
= {}) const override
;
84 void renameFailed(const QString
&errorMessage
);
87 using ColumnInterval
= IndexInterval
<int>;
90 void updateFilesProgress();
91 void updateFilesPriorities();
92 void updateFilesAvailability();
93 bool setItemPriority(const QModelIndex
&index
, BitTorrent::DownloadPriority priority
);
94 void notifySubtreeUpdated(const QModelIndex
&index
, const QVector
<ColumnInterval
> &columns
);
96 BitTorrent::TorrentContentHandler
*m_contentHandler
= nullptr;
97 TorrentContentModelFolder
*m_rootItem
= nullptr;
98 QVector
<TorrentContentModelFile
*> m_filesIndex
;
99 QFileIconProvider
*m_fileIconProvider
= nullptr;