|
|
|
@ -39,21 +39,24 @@
@@ -39,21 +39,24 @@
|
|
|
|
|
#include "torrentcontentmodelfolder.h" |
|
|
|
|
#include "torrentcontentmodelfile.h" |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
QIcon get_directory_icon() { |
|
|
|
|
namespace |
|
|
|
|
{ |
|
|
|
|
QIcon get_directory_icon() |
|
|
|
|
{ |
|
|
|
|
static QIcon cached = GuiIconProvider::instance()->getIcon("inode-directory"); |
|
|
|
|
return cached; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QIcon get_file_icon() { |
|
|
|
|
QIcon get_file_icon() |
|
|
|
|
{ |
|
|
|
|
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") |
|
|
|
|
TorrentContentModel::TorrentContentModel(QObject *parent) |
|
|
|
|
: QAbstractItemModel(parent) |
|
|
|
|
, m_rootItem(new TorrentContentModelFolder(QList<QVariant>() << tr("Name") << tr("Size") |
|
|
|
|
<< tr("Progress") << tr("Download Priority"))) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
@ -70,9 +73,8 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
@@ -70,9 +73,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 +88,8 @@ void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
@@ -86,9 +88,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 +97,16 @@ QVector<int> TorrentContentModel::getFilePriorities() const
@@ -96,18 +97,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 +123,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
@@ -124,7 +123,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 +179,13 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
@@ -180,13 +179,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(); |
|
|
|
|
else |
|
|
|
|
return get_file_icon(); |
|
|
|
|
} |
|
|
|
|
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 +211,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const
@@ -212,7 +211,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 +219,7 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
@@ -220,7 +219,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) |
|
|
|
@ -330,8 +329,7 @@ void TorrentContentModel::selectAll()
@@ -330,8 +329,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())); |
|
|
|
|
} |
|
|
|
|