Browse Source

FEATURE: Added back file prioritizing in a torrent (it seems users were using it after all)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
0e8c55b9f5
  1. 1
      Changelog
  2. 76
      src/proplistdelegate.h
  3. 18
      src/torrentfilesmodel.h

1
Changelog

@ -1,6 +1,7 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.2.0 * Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.2.0
- FEATURE: User can set alternative speed limits for fast toggling - FEATURE: User can set alternative speed limits for fast toggling
- FEATURE: Bandwidth scheduler (automatically use alternative speed limits for a given period) - 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 <chris@qbittorrent.org> - v2.1.0 * Mon Jan 18 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.1.0
- FEATURE: Graphical User Interface can be disabled at compilation time (headless running) - FEATURE: Graphical User Interface can be disabled at compilation time (headless running)

76
src/proplistdelegate.h

@ -44,7 +44,7 @@
#include "propertieswidget.h" #include "propertieswidget.h"
// Defines for properties list columns // Defines for properties list columns
enum PropColumn {NAME, SIZE, PROGRESS}; enum PropColumn {NAME, SIZE, PROGRESS, PRIORITY};
class PropListDelegate: public QItemDelegate { class PropListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT
@ -81,8 +81,29 @@ public:
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
break; 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:
text = tr("Normal", "Normal priority");
break;
}
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
break;
}
default: default:
QItemDelegate::paint(painter, option, index); QItemDelegate::paint(painter, option, index);
break;
} }
} }
@ -96,9 +117,60 @@ public:
return textRect.size(); return textRect.size();
} }
QWidget* createEditor(QWidget *, const QStyleOptionViewItem &/* option */, const QModelIndex &) const { void setEditorData(QWidget *editor, const QModelIndex &index) const {
QComboBox *combobox = static_cast<QComboBox*>(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; 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<QComboBox*>(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);
}
}; };

18
src/torrentfilesmodel.h

@ -41,9 +41,8 @@
#include "misc.h" #include "misc.h"
using namespace libtorrent; using namespace libtorrent;
enum FilePriority {IGNORED=0, NORMAL=1, HIGH=2, MAXIMUM=7};
enum TreeItemType {TFILE, FOLDER, ROOT}; enum TreeItemType {TFILE, FOLDER, ROOT};
#define IGNORED 0
#define NORMAL 1
class TreeItem { class TreeItem {
private: private:
@ -71,7 +70,7 @@ public:
itemData << QVariant((qulonglong)f.size); itemData << QVariant((qulonglong)f.size);
total_done = 0; total_done = 0;
itemData << 0.; // Progress; itemData << 0.; // Progress;
itemData << 1; // Priority itemData << NORMAL; // Priority
if(parent) { if(parent) {
parent->appendChild(this); parent->appendChild(this);
parent->updateSize(); parent->updateSize();
@ -89,7 +88,7 @@ public:
itemData << 0.; // Size itemData << 0.; // Size
itemData << 0.; // Progress; itemData << 0.; // Progress;
total_done = 0; total_done = 0;
itemData << 1; // Priority itemData << NORMAL; // Priority
if(parent) { if(parent) {
parent->appendChild(this); parent->appendChild(this);
} }
@ -308,7 +307,7 @@ public:
TorrentFilesModel(QObject *parent=0): QAbstractItemModel(parent) { TorrentFilesModel(QObject *parent=0): QAbstractItemModel(parent) {
files_index = 0; files_index = 0;
QList<QVariant> rootData; QList<QVariant> rootData;
rootData << tr("Name") << tr("Size") << tr("Progress"); rootData << tr("Name") << tr("Size") << tr("Progress") << tr("Priority");
rootItem = new TreeItem(rootData); rootItem = new TreeItem(rootData);
} }
@ -360,9 +359,9 @@ public:
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if(item->getPriority() != value.toInt()) { if(item->getPriority() != value.toInt()) {
if(value.toInt() == Qt::Checked) if(value.toInt() == Qt::Checked)
item->setPriority(1); item->setPriority(NORMAL);
else else
item->setPriority(0); item->setPriority(IGNORED);
emit filteredFilesChanged(); emit filteredFilesChanged();
emit dataChanged(this->index(0,0), this->index(rowCount(), 0)); emit dataChanged(this->index(0,0), this->index(rowCount(), 0));
} }
@ -380,6 +379,9 @@ public:
case 2: case 2:
item->setProgress(value.toDouble()); item->setProgress(value.toDouble());
break; break;
case 3:
item->setPriority(value.toInt());
break;
default: default:
return false; return false;
} }
@ -410,7 +412,7 @@ public:
return QIcon(":/Icons/oxygen/file.png"); return QIcon(":/Icons/oxygen/file.png");
} }
if(role == Qt::CheckStateRole) { if(role == Qt::CheckStateRole) {
if(item->data(3).toInt() == 0) if(item->data(3).toInt() == IGNORED)
return Qt::Unchecked; return Qt::Unchecked;
return Qt::Checked; return Qt::Checked;
} }

Loading…
Cancel
Save