|
|
|
@ -39,22 +39,24 @@
@@ -39,22 +39,24 @@
|
|
|
|
|
#include "torrentcontentmodelfolder.h" |
|
|
|
|
#include "torrentcontentmodelfile.h" |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
QIcon get_directory_icon() { |
|
|
|
|
namespace |
|
|
|
|
{ |
|
|
|
|
QIcon getDirectoryIcon() |
|
|
|
|
{ |
|
|
|
|
static QIcon cached = GuiIconProvider::instance()->getIcon("inode-directory"); |
|
|
|
|
return cached; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QIcon get_file_icon() { |
|
|
|
|
QIcon getFileIcon() |
|
|
|
|
{ |
|
|
|
|
static QIcon cached = GuiIconProvider::instance()->getIcon("text-plain"); |
|
|
|
|
return cached; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TorrentContentModel::TorrentContentModel(QObject *parent): |
|
|
|
|
QAbstractItemModel(parent), |
|
|
|
|
m_rootItem(new TorrentContentModelFolder(QList<QVariant>() << tr("Name") << tr("Size") |
|
|
|
|
<< tr("Progress") << tr("Priority"))) |
|
|
|
|
TorrentContentModel::TorrentContentModel(QObject *parent) |
|
|
|
|
: QAbstractItemModel(parent) |
|
|
|
|
, m_rootItem(new TorrentContentModelFolder(QList<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority") }))) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -70,9 +72,8 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
@@ -70,9 +72,8 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
|
|
|
|
|
if (m_filesIndex.size() != fp.size()) return; |
|
|
|
|
|
|
|
|
|
emit layoutAboutToBeChanged(); |
|
|
|
|
for (int i = 0; i < fp.size(); ++i) { |
|
|
|
|
for (int i = 0; i < fp.size(); ++i) |
|
|
|
|
m_filesIndex[i]->setProgress(fp[i]); |
|
|
|
|
} |
|
|
|
|
// Update folders progress in the tree
|
|
|
|
|
m_rootItem->recalculateProgress(); |
|
|
|
|
emit dataChanged(index(0, 0), index(rowCount(), columnCount())); |
|
|
|
@ -86,9 +87,8 @@ void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
@@ -86,9 +87,8 @@ void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
emit layoutAboutToBeChanged(); |
|
|
|
|
for (int i = 0; i < fprio.size(); ++i) { |
|
|
|
|
for (int i = 0; i < fprio.size(); ++i) |
|
|
|
|
m_filesIndex[i]->setPriority(fprio[i]); |
|
|
|
|
} |
|
|
|
|
emit dataChanged(index(0, 0), index(rowCount(), columnCount())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -96,18 +96,16 @@ QVector<int> TorrentContentModel::getFilePriorities() const
@@ -96,18 +96,16 @@ QVector<int> TorrentContentModel::getFilePriorities() const
|
|
|
|
|
{ |
|
|
|
|
QVector<int> prio; |
|
|
|
|
prio.reserve(m_filesIndex.size()); |
|
|
|
|
foreach (const TorrentContentModelFile* file, m_filesIndex) { |
|
|
|
|
foreach (const TorrentContentModelFile* file, m_filesIndex) |
|
|
|
|
prio.push_back(file->priority()); |
|
|
|
|
} |
|
|
|
|
return prio; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool TorrentContentModel::allFiltered() const |
|
|
|
|
{ |
|
|
|
|
foreach (const TorrentContentModelFile* fileItem, m_filesIndex) { |
|
|
|
|
foreach (const TorrentContentModelFile* fileItem, m_filesIndex) |
|
|
|
|
if (fileItem->priority() != prio::IGNORED) |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -124,7 +122,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
@@ -124,7 +122,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
|
|
|
|
|
if (!index.isValid()) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (index.column() == 0 && role == Qt::CheckStateRole) { |
|
|
|
|
if ((index.column() == 0) && (role == Qt::CheckStateRole)) { |
|
|
|
|
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer()); |
|
|
|
|
qDebug("setData(%s, %d", qPrintable(item->name()), value.toInt()); |
|
|
|
|
if (item->priority() != value.toInt()) { |
|
|
|
@ -180,13 +178,13 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
@@ -180,13 +178,13 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
|
|
|
|
|
return QVariant(); |
|
|
|
|
|
|
|
|
|
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer()); |
|
|
|
|
if (index.column() == 0 && role == Qt::DecorationRole) { |
|
|
|
|
if ((index.column() == 0) && (role == Qt::DecorationRole)) { |
|
|
|
|
if (item->itemType() == TorrentContentModelItem::FolderType) |
|
|
|
|
return get_directory_icon(); |
|
|
|
|
return getDirectoryIcon(); |
|
|
|
|
else |
|
|
|
|
return get_file_icon(); |
|
|
|
|
return getFileIcon(); |
|
|
|
|
} |
|
|
|
|
if (index.column() == 0 && role == Qt::CheckStateRole) { |
|
|
|
|
if ((index.column() == 0) && (role == Qt::CheckStateRole)) { |
|
|
|
|
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED) |
|
|
|
|
return Qt::Unchecked; |
|
|
|
|
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::MIXED) |
|
|
|
@ -212,7 +210,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const
@@ -212,7 +210,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const
|
|
|
|
|
|
|
|
|
|
QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
|
|
|
{ |
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) |
|
|
|
|
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) |
|
|
|
|
return m_rootItem->data(section); |
|
|
|
|
|
|
|
|
|
return QVariant(); |
|
|
|
@ -220,7 +218,7 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
@@ -220,7 +218,7 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
|
|
|
|
|
|
|
|
|
|
QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& parent) const |
|
|
|
|
{ |
|
|
|
|
if (parent.isValid() && parent.column() != 0) |
|
|
|
|
if (parent.isValid() && (parent.column() != 0)) |
|
|
|
|
return QModelIndex(); |
|
|
|
|
|
|
|
|
|
if (column >= TorrentContentModelItem::NB_COL) |
|
|
|
@ -292,10 +290,10 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
@@ -292,10 +290,10 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
|
|
|
|
|
qDebug("Torrent contains %d files", info.filesCount()); |
|
|
|
|
m_filesIndex.reserve(info.filesCount()); |
|
|
|
|
|
|
|
|
|
TorrentContentModelFolder* current_parent; |
|
|
|
|
TorrentContentModelFolder* currentParent; |
|
|
|
|
// Iterate over files
|
|
|
|
|
for (int i = 0; i < info.filesCount(); ++i) { |
|
|
|
|
current_parent = m_rootItem; |
|
|
|
|
currentParent = m_rootItem; |
|
|
|
|
QString path = Utils::Fs::fromNativePath(info.filePath(i)); |
|
|
|
|
// Iterate of parts of the path to create necessary folders
|
|
|
|
|
QStringList pathFolders = path.split("/", QString::SkipEmptyParts); |
|
|
|
@ -303,16 +301,16 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
@@ -303,16 +301,16 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
|
|
|
|
|
foreach (const QString& pathPart, pathFolders) { |
|
|
|
|
if (pathPart == ".unwanted") |
|
|
|
|
continue; |
|
|
|
|
TorrentContentModelFolder* new_parent = current_parent->childFolderWithName(pathPart); |
|
|
|
|
if (!new_parent) { |
|
|
|
|
new_parent = new TorrentContentModelFolder(pathPart, current_parent); |
|
|
|
|
current_parent->appendChild(new_parent); |
|
|
|
|
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart); |
|
|
|
|
if (!newParent) { |
|
|
|
|
newParent = new TorrentContentModelFolder(pathPart, currentParent); |
|
|
|
|
currentParent->appendChild(newParent); |
|
|
|
|
} |
|
|
|
|
current_parent = new_parent; |
|
|
|
|
currentParent = newParent; |
|
|
|
|
} |
|
|
|
|
// Actually create the file
|
|
|
|
|
TorrentContentModelFile* fileItem = new TorrentContentModelFile(info.fileName(i), info.fileSize(i), current_parent, i); |
|
|
|
|
current_parent->appendChild(fileItem); |
|
|
|
|
TorrentContentModelFile* fileItem = new TorrentContentModelFile(info.fileName(i), info.fileSize(i), currentParent, i); |
|
|
|
|
currentParent->appendChild(fileItem); |
|
|
|
|
m_filesIndex.push_back(fileItem); |
|
|
|
|
} |
|
|
|
|
emit layoutChanged(); |
|
|
|
@ -330,8 +328,7 @@ void TorrentContentModel::selectAll()
@@ -330,8 +328,7 @@ void TorrentContentModel::selectAll()
|
|
|
|
|
|
|
|
|
|
void TorrentContentModel::selectNone() |
|
|
|
|
{ |
|
|
|
|
for (int i=0; i<m_rootItem->childCount(); ++i) { |
|
|
|
|
for (int i = 0; i < m_rootItem->childCount(); ++i) |
|
|
|
|
m_rootItem->child(i)->setPriority(prio::IGNORED); |
|
|
|
|
} |
|
|
|
|
emit dataChanged(index(0, 0), index(rowCount(), columnCount())); |
|
|
|
|
} |
|
|
|
|