Browse Source

- Managed to get the transfer list filters working :)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
6b8521355f
  1. 11
      src/TransferListDelegate.h
  2. 4
      src/TransferListFiltersWidget.h
  3. 50
      src/TransferListWidget.cpp
  4. 3
      src/TransferListWidget.h

11
src/TransferListDelegate.h

@ -40,16 +40,7 @@
#include "misc.h" #include "misc.h"
// Defines for download list list columns // Defines for download list list columns
#define NAME 0 enum Column {NAME, SIZE, PROGRESS, DLSPEED, UPSPEED, SEEDSLEECH, RATIO, ETA, PRIORITY, HASH, STATUS};
#define SIZE 1
#define PROGRESS 2
#define DLSPEED 3
#define UPSPEED 4
#define SEEDSLEECH 5
#define RATIO 6
#define ETA 7
#define PRIORITY 8
#define HASH 9
class TransferListDelegate: public QItemDelegate { class TransferListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT

4
src/TransferListFiltersWidget.h

@ -31,6 +31,10 @@ public:
QListWidgetItem *inactive = new QListWidgetItem(this); QListWidgetItem *inactive = new QListWidgetItem(this);
inactive->setData(Qt::DisplayRole, tr("Inactive")); inactive->setData(Qt::DisplayRole, tr("Inactive"));
inactive->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/draw-rectangle.png")); inactive->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/draw-rectangle.png"));
// SIGNAL/SLOT
connect(this, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyFilter(int)));
// Load settings // Load settings
loadSettings(); loadSettings();
} }

50
src/TransferListWidget.cpp

@ -44,6 +44,7 @@
#include <QColor> #include <QColor>
#include <QUrl> #include <QUrl>
#include <QMenu> #include <QMenu>
#include <QRegExp>
#include <vector> #include <vector>
TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): QTreeView(parent) { TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): QTreeView(parent) {
@ -55,7 +56,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession):
setItemDelegate(listDelegate); setItemDelegate(listDelegate);
// Create transfer list model // Create transfer list model
listModel = new QStandardItemModel(0,10); listModel = new QStandardItemModel(0,11);
listModel->setHeaderData(NAME, Qt::Horizontal, tr("Name", "i.e: file name")); listModel->setHeaderData(NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
listModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); listModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
listModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded")); listModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
@ -70,6 +71,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession):
proxyModel = new QSortFilterProxyModel(); proxyModel = new QSortFilterProxyModel();
proxyModel->setDynamicSortFilter(true); proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(listModel); proxyModel->setSourceModel(listModel);
proxyModel->setFilterKeyColumn(STATUS);
proxyModel->setFilterRole(Qt::DisplayRole);
setModel(proxyModel); setModel(proxyModel);
// Visual settings // Visual settings
@ -78,6 +81,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession):
setSortingEnabled(true); setSortingEnabled(true);
hideColumn(PRIORITY); hideColumn(PRIORITY);
hideColumn(HASH); hideColumn(HASH);
hideColumn(STATUS);
loadHiddenColumns(); loadHiddenColumns();
// Load last columns width for transfer list // Load last columns width for transfer list
if(!loadColWidthList()) { if(!loadColWidthList()) {
@ -128,9 +132,11 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
// Pause torrent if it is // Pause torrent if it is
if(h.is_paused()) { if(h.is_paused()) {
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), INACTIVE);
//setRowColor(row, QString::fromUtf8("red")); //setRowColor(row, QString::fromUtf8("red"));
}else{ }else{
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), DOWNLOADING);
//setRowColor(row, QString::fromUtf8("grey")); //setRowColor(row, QString::fromUtf8("grey"));
} }
} catch(invalid_handle e) { } catch(invalid_handle e) {
@ -140,7 +146,7 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
} }
/*void TransferListWidget::setRowColor(int row, QColor color) { /*void TransferListWidget::setRowColor(int row, QColor color) {
unsigned int nbColumns = listModel->columnCount()-1; unsigned int nbColumns = listModel->columnCount()-2;
for(unsigned int i=0; i<nbColumns; ++i) { for(unsigned int i=0; i<nbColumns; ++i) {
listModel->setData(listModel->index(row, i), QVariant(color), Qt::ForegroundRole); listModel->setData(listModel->index(row, i), QVariant(color), Qt::ForegroundRole);
} }
@ -159,6 +165,7 @@ void TransferListWidget::pauseTorrent(int row) {
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)0.0)); listModel->setData(listModel->index(row, UPSPEED), QVariant((double)0.0));
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
listModel->setData(listModel->index(row, NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), INACTIVE);
listModel->setData(listModel->index(row, SEEDSLEECH), QVariant(QString::fromUtf8("0/0"))); listModel->setData(listModel->index(row, SEEDSLEECH), QVariant(QString::fromUtf8("0/0")));
//setRowColor(row, QString::fromUtf8("red")); //setRowColor(row, QString::fromUtf8("red"));
} }
@ -166,8 +173,10 @@ void TransferListWidget::pauseTorrent(int row) {
void TransferListWidget::resumeTorrent(int row) { void TransferListWidget::resumeTorrent(int row) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row)); QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
if(!h.is_valid()) return; if(!h.is_valid()) return;
if(h.is_seed()) if(h.is_seed()) {
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), COMPLETED);
}
updateTorrent(row); updateTorrent(row);
} }
@ -197,9 +206,11 @@ void TransferListWidget::updateTorrent(int row) {
if(h.is_queued()) { if(h.is_queued()) {
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) { if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) {
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), INACTIVE);
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress())); listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress()));
}else { }else {
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/mail-queue.png"))), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/mail-queue.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), INACTIVE);
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
} }
// Reset speeds and seeds/leech // Reset speeds and seeds/leech
@ -221,6 +232,7 @@ void TransferListWidget::updateTorrent(int row) {
case torrent_status::queued_for_checking: case torrent_status::queued_for_checking:
case torrent_status::checking_resume_data: case torrent_status::checking_resume_data:
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), INACTIVE);
//setRowColor(row, QString::fromUtf8("grey")); //setRowColor(row, QString::fromUtf8("grey"));
break; break;
case torrent_status::downloading: case torrent_status::downloading:
@ -234,6 +246,7 @@ void TransferListWidget::updateTorrent(int row) {
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
//setRowColor(row, QApplication::palette().color(QPalette::WindowText)); //setRowColor(row, QApplication::palette().color(QPalette::WindowText));
} }
listModel->setData(listModel->index(row, STATUS), DOWNLOADING);
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate())); listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate()));
break; break;
default: default:
@ -265,9 +278,11 @@ void TransferListWidget::setFinished(QTorrentHandle &h) {
if(row >= 0) { if(row >= 0) {
if(h.is_paused()) { if(h.is_paused()) {
listModel->setData(listModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), INACTIVE);
//setRowColor(row, "red"); //setRowColor(row, "red");
}else{ }else{
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), COMPLETED);
//setRowColor(row, "orange"); //setRowColor(row, "orange");
} }
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
@ -531,7 +546,7 @@ void TransferListWidget::recheckSelectedTorrents() {
void TransferListWidget::saveHiddenColumns() { void TransferListWidget::saveHiddenColumns() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
QStringList ishidden_list; QStringList ishidden_list;
short nbColumns = listModel->columnCount()-1; short nbColumns = listModel->columnCount()-2;
for(short i=0; i<nbColumns; ++i){ for(short i=0; i<nbColumns; ++i){
if(isColumnHidden(i)) { if(isColumnHidden(i)) {
@ -552,7 +567,7 @@ bool TransferListWidget::loadHiddenColumns() {
QStringList ishidden_list; QStringList ishidden_list;
ishidden_list = line.split(' '); ishidden_list = line.split(' ');
unsigned int nbCol = ishidden_list.size(); unsigned int nbCol = ishidden_list.size();
if(nbCol == (unsigned int)listModel->columnCount()-1) { if(nbCol == (unsigned int)listModel->columnCount()-2) {
for(unsigned int i=0; i<nbCol; ++i){ for(unsigned int i=0; i<nbCol; ++i){
if(ishidden_list.at(i) == "0") { if(ishidden_list.at(i) == "0") {
setColumnHidden(i, true); setColumnHidden(i, true);
@ -682,7 +697,7 @@ void TransferListWidget::saveColWidthList() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList width_list; QStringList width_list;
QStringList new_width_list; QStringList new_width_list;
short nbColumns = listModel->columnCount()-1; short nbColumns = listModel->columnCount()-2;
QString line = settings.value("TransferListColsWidth", QString()).toString(); QString line = settings.value("TransferListColsWidth", QString()).toString();
if(!line.isEmpty()) { if(!line.isEmpty()) {
width_list = line.split(' '); width_list = line.split(' ');
@ -717,7 +732,7 @@ bool TransferListWidget::loadColWidthList() {
if(line.isEmpty()) if(line.isEmpty())
return false; return false;
QStringList width_list = line.split(QString::fromUtf8(" ")); QStringList width_list = line.split(QString::fromUtf8(" "));
if(width_list.size() != listModel->columnCount()-1) { if(width_list.size() != listModel->columnCount()-2) {
qDebug("Corrupted values for download list columns sizes"); qDebug("Corrupted values for download list columns sizes");
return false; return false;
} }
@ -726,7 +741,7 @@ bool TransferListWidget::loadColWidthList() {
header()->resizeSection(i, width_list.at(i).toInt()); header()->resizeSection(i, width_list.at(i).toInt());
} }
QVariantList visualIndexes = settings.value(QString::fromUtf8("TransferListVisualIndexes"), QVariantList()).toList(); QVariantList visualIndexes = settings.value(QString::fromUtf8("TransferListVisualIndexes"), QVariantList()).toList();
if(visualIndexes.size() != listModel->columnCount()-1) { if(visualIndexes.size() != listModel->columnCount()-2) {
qDebug("Corrupted values for download list columns sizes"); qDebug("Corrupted values for download list columns sizes");
return false; return false;
} }
@ -773,3 +788,22 @@ void TransferListWidget::loadLastSortedColumn() {
sortByColumn(index, sortOrder); sortByColumn(index, sortOrder);
} }
} }
void TransferListWidget::applyFilter(int f) {
switch(f) {
case DOWNLOADING:
proxyModel->setFilterRegExp(QRegExp(QString::number(DOWNLOADING), Qt::CaseSensitive, QRegExp::FixedString));
break;
case COMPLETED:
proxyModel->setFilterRegExp(QRegExp(QString::number(COMPLETED), Qt::CaseSensitive, QRegExp::FixedString));
break;
case ACTIVE:
proxyModel->setFilterRegExp(QRegExp(QString::number(DOWNLOADING)+"|"+QString::number(COMPLETED), Qt::CaseSensitive));
break;
case INACTIVE:
proxyModel->setFilterRegExp(QRegExp(QString::number(INACTIVE), Qt::CaseSensitive, QRegExp::FixedString));
break;
default:
proxyModel->setFilterRegExp(QRegExp());
}
}

3
src/TransferListWidget.h

@ -40,6 +40,8 @@ class QSortFilterProxyModel;
class bittorrent; class bittorrent;
class QTimer; class QTimer;
enum TorrentFilter {ALL, DOWNLOADING, COMPLETED, ACTIVE, INACTIVE };
class TransferListWidget: public QTreeView { class TransferListWidget: public QTreeView {
Q_OBJECT Q_OBJECT
@ -97,6 +99,7 @@ public slots:
void previewSelectedTorrents(); void previewSelectedTorrents();
void hidePriorityColumn(bool hide); void hidePriorityColumn(bool hide);
void displayDLHoSMenu(const QPoint&); void displayDLHoSMenu(const QPoint&);
void applyFilter(int f);
}; };

Loading…
Cancel
Save