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