From 0e8c55b9f5025ff41afc3a7cb81eb82f9f1efda7 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 24 Jan 2010 15:26:29 +0000 Subject: [PATCH] FEATURE: Added back file prioritizing in a torrent (it seems users were using it after all) --- Changelog | 1 + src/proplistdelegate.h | 108 +++++++++++++++++++++++++++++++++------- src/torrentfilesmodel.h | 18 ++++--- 3 files changed, 101 insertions(+), 26 deletions(-) diff --git a/Changelog b/Changelog index 2a65dc9d7..ee2a09224 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ * Unreleased - Christophe Dumez - v2.2.0 - FEATURE: User can set alternative speed limits for fast toggling - FEATURE: Bandwidth scheduler (automatically use alternative speed limits for a given period) + - FEATURE: Added back file prioritizing in a torrent * Mon Jan 18 2010 - Christophe Dumez - v2.1.0 - FEATURE: Graphical User Interface can be disabled at compilation time (headless running) diff --git a/src/proplistdelegate.h b/src/proplistdelegate.h index 7dc038b2e..1c8d74ad1 100644 --- a/src/proplistdelegate.h +++ b/src/proplistdelegate.h @@ -44,7 +44,7 @@ #include "propertieswidget.h" // Defines for properties list columns -enum PropColumn {NAME, SIZE, PROGRESS}; +enum PropColumn {NAME, SIZE, PROGRESS, PRIORITY}; class PropListDelegate: public QItemDelegate { Q_OBJECT @@ -64,26 +64,47 @@ public: void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{ QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); switch(index.column()){ - case SIZE: + case SIZE: QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); break; - case PROGRESS:{ - QStyleOptionProgressBarV2 newopt; - float progress = index.data().toDouble()*100.; - newopt.rect = opt.rect; - newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); - newopt.progress = (int)progress; - newopt.maximum = 100; - newopt.minimum = 0; - newopt.state |= QStyle::State_Enabled; - newopt.textVisible = true; - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); - break; - } + case PROGRESS:{ + QStyleOptionProgressBarV2 newopt; + float progress = index.data().toDouble()*100.; + newopt.rect = opt.rect; + newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); + newopt.progress = (int)progress; + newopt.maximum = 100; + newopt.minimum = 0; + newopt.state |= QStyle::State_Enabled; + newopt.textVisible = true; + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); + break; + } + case PRIORITY: { + QItemDelegate::drawBackground(painter, opt, index); + QString text = ""; + switch(index.data().toInt()) { + case 0: + text = tr("Not downloaded"); + break; + case 2: + text = tr("High", "High priority"); + break; + case 7: + text = tr("Maximum", "Maximum priority"); + break; default: - QItemDelegate::paint(painter, option, index); + text = tr("Normal", "Normal priority"); + break; } + QItemDelegate::drawDisplay(painter, opt, option.rect, text); + break; + } + default: + QItemDelegate::paint(painter, option, index); + break; + } } QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{ @@ -96,8 +117,59 @@ public: return textRect.size(); } - QWidget* createEditor(QWidget *, const QStyleOptionViewItem &/* option */, const QModelIndex &) const { - return 0; + void setEditorData(QWidget *editor, const QModelIndex &index) const { + QComboBox *combobox = static_cast(editor); + // Set combobox index + switch(index.data().toInt()) { + case 2: + combobox->setCurrentIndex(1); + break; + case 7: + combobox->setCurrentIndex(2); + break; + default: + combobox->setCurrentIndex(0); + break; + } + } + + QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const { + if(index.column() != PRIORITY) return 0; + if(properties) { + QTorrentHandle h = properties->getCurrentTorrent(); + if(!h.is_valid() || h.get_torrent_handle().is_seed() || !h.has_metadata()) return 0; + } + if(index.data().toInt() == 0) { + // IGNORED + return 0; + } + QComboBox* editor = new QComboBox(parent); + editor->setFocusPolicy(Qt::StrongFocus); + editor->addItem(tr("Normal", "Normal (priority)")); + editor->addItem(tr("High", "High (priority)")); + editor->addItem(tr("Maximum", "Maximum (priority)")); + return editor; + } + +public slots: + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { + QComboBox *combobox = static_cast(editor); + int value = combobox->currentIndex(); + switch(value) { + case 1: + model->setData(index, 2); // HIGH + break; + case 2: + model->setData(index, 7); // MAX + break; + default: + model->setData(index, 1); // NORMAL + } + } + + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const { + qDebug("UpdateEditor Geometry called"); + editor->setGeometry(option.rect); } }; diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index 4302a2618..b4ce5084a 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -41,9 +41,8 @@ #include "misc.h" using namespace libtorrent; +enum FilePriority {IGNORED=0, NORMAL=1, HIGH=2, MAXIMUM=7}; enum TreeItemType {TFILE, FOLDER, ROOT}; -#define IGNORED 0 -#define NORMAL 1 class TreeItem { private: @@ -71,7 +70,7 @@ public: itemData << QVariant((qulonglong)f.size); total_done = 0; itemData << 0.; // Progress; - itemData << 1; // Priority + itemData << NORMAL; // Priority if(parent) { parent->appendChild(this); parent->updateSize(); @@ -89,7 +88,7 @@ public: itemData << 0.; // Size itemData << 0.; // Progress; total_done = 0; - itemData << 1; // Priority + itemData << NORMAL; // Priority if(parent) { parent->appendChild(this); } @@ -308,7 +307,7 @@ public: TorrentFilesModel(QObject *parent=0): QAbstractItemModel(parent) { files_index = 0; QList rootData; - rootData << tr("Name") << tr("Size") << tr("Progress"); + rootData << tr("Name") << tr("Size") << tr("Progress") << tr("Priority"); rootItem = new TreeItem(rootData); } @@ -360,9 +359,9 @@ public: TreeItem *item = static_cast(index.internalPointer()); if(item->getPriority() != value.toInt()) { if(value.toInt() == Qt::Checked) - item->setPriority(1); + item->setPriority(NORMAL); else - item->setPriority(0); + item->setPriority(IGNORED); emit filteredFilesChanged(); emit dataChanged(this->index(0,0), this->index(rowCount(), 0)); } @@ -380,6 +379,9 @@ public: case 2: item->setProgress(value.toDouble()); break; + case 3: + item->setPriority(value.toInt()); + break; default: return false; } @@ -410,7 +412,7 @@ public: return QIcon(":/Icons/oxygen/file.png"); } if(role == Qt::CheckStateRole) { - if(item->data(3).toInt() == 0) + if(item->data(3).toInt() == IGNORED) return Qt::Unchecked; return Qt::Checked; }