Browse Source

Merge pull request #4528 from Chocobo1/pri_rename

Rename column header
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
ca4bbdd02b
  1. 75
      src/gui/torrentcontentmodel.cpp
  2. 2
      src/webui/www/public/properties_content.html

75
src/gui/torrentcontentmodel.cpp

@ -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,12 +72,11 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp) @@ -70,12 +72,11 @@ 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()));
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
}
void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
@ -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()) {
@ -136,7 +134,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu @@ -136,7 +134,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
item->setPriority(prio::NORMAL);
// Update folders progress in the tree
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();
}
return true;
@ -145,7 +143,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu @@ -145,7 +143,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
if (role == Qt::EditRole) {
Q_ASSERT(index.isValid());
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
switch(index.column()) {
switch (index.column()) {
case TorrentContentModelItem::COL_NAME:
item->setName(value.toString());
break;
@ -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();
@ -320,7 +318,7 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info) @@ -320,7 +318,7 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
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);
if (child->priority() == prio::IGNORED)
child->setPriority(prio::NORMAL);
@ -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()));
}

2
src/webui/www/public/properties_content.html

@ -97,7 +97,7 @@ @@ -97,7 +97,7 @@
<th>QBT_TR(Name)QBT_TR</th>
<th style="width: 150px;">QBT_TR(Size)QBT_TR</th>
<th style="width: 90px;">QBT_TR(Progress)QBT_TR</th>
<th style="width: 150px; border-right: 0">QBT_TR(Priority)QBT_TR</th>
<th style="width: 150px; border-right: 0">QBT_TR(Download Priority)QBT_TR</th>
</tr>
</thead>
<tbody id="filesTable"></tbody>

Loading…
Cancel
Save