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
;
44 class TorrentContentModelFile
;
48 class TorrentContentHandler
;
51 class TorrentContentModel final
: public QAbstractItemModel
54 Q_DISABLE_COPY_MOVE(TorrentContentModel
)
59 UnderlyingDataRole
= Qt::UserRole
62 explicit TorrentContentModel(QObject
*parent
= nullptr);
63 ~TorrentContentModel() override
;
65 void setContentHandler(BitTorrent::TorrentContentHandler
*contentHandler
);
66 BitTorrent::TorrentContentHandler
*contentHandler() const;
70 QList
<BitTorrent::DownloadPriority
> getFilePriorities() const;
71 TorrentContentModelItem::ItemType
itemType(const QModelIndex
&index
) const;
72 int getFileIndex(const QModelIndex
&index
) const;
73 Path
getItemPath(const QModelIndex
&index
) const;
75 int columnCount(const QModelIndex
&parent
= {}) const override
;
76 bool setData(const QModelIndex
&index
, const QVariant
&value
, int role
= Qt::EditRole
) override
;
77 QVariant
data(const QModelIndex
&index
, int role
= Qt::DisplayRole
) const override
;
78 Qt::ItemFlags
flags(const QModelIndex
&index
) const override
;
79 QVariant
headerData(int section
, Qt::Orientation orientation
, int role
) const override
;
80 QModelIndex
index(int row
, int column
, const QModelIndex
&parent
= {}) const override
;
81 QModelIndex
parent(const QModelIndex
&index
) const override
;
82 int rowCount(const QModelIndex
&parent
= {}) const override
;
85 void renameFailed(const QString
&errorMessage
);
88 using ColumnInterval
= IndexInterval
<int>;
90 QMimeData
*mimeData(const QModelIndexList
&indexes
) const override
;
91 QStringList
mimeTypes() const override
;
93 void updateFilesProgress();
94 void updateFilesPriorities();
95 void updateFilesAvailability();
96 bool setItemPriority(const QModelIndex
&index
, BitTorrent::DownloadPriority priority
);
97 void notifySubtreeUpdated(const QModelIndex
&index
, const QList
<ColumnInterval
> &columns
);
99 BitTorrent::TorrentContentHandler
*m_contentHandler
= nullptr;
100 TorrentContentModelFolder
*m_rootItem
= nullptr;
101 QList
<TorrentContentModelFile
*> m_filesIndex
;
102 QFileIconProvider
*m_fileIconProvider
= nullptr;