From 6b8521355fbed074dc817b8ac7e326ae6d8a4288 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 8 Nov 2009 13:19:00 +0000 Subject: [PATCH] - Managed to get the transfer list filters working :) --- src/TransferListDelegate.h | 11 +------- src/TransferListFiltersWidget.h | 4 +++ src/TransferListWidget.cpp | 50 +++++++++++++++++++++++++++------ src/TransferListWidget.h | 3 ++ 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/TransferListDelegate.h b/src/TransferListDelegate.h index 4f9810f23..8f386a04e 100644 --- a/src/TransferListDelegate.h +++ b/src/TransferListDelegate.h @@ -40,16 +40,7 @@ #include "misc.h" // Defines for download list list columns -#define NAME 0 -#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 +enum Column {NAME, SIZE, PROGRESS, DLSPEED, UPSPEED, SEEDSLEECH, RATIO, ETA, PRIORITY, HASH, STATUS}; class TransferListDelegate: public QItemDelegate { Q_OBJECT diff --git a/src/TransferListFiltersWidget.h b/src/TransferListFiltersWidget.h index 746f9c714..bc807025d 100644 --- a/src/TransferListFiltersWidget.h +++ b/src/TransferListFiltersWidget.h @@ -31,6 +31,10 @@ public: QListWidgetItem *inactive = new QListWidgetItem(this); inactive->setData(Qt::DisplayRole, tr("Inactive")); inactive->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/draw-rectangle.png")); + + // SIGNAL/SLOT + connect(this, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyFilter(int))); + // Load settings loadSettings(); } diff --git a/src/TransferListWidget.cpp b/src/TransferListWidget.cpp index 2a095b41a..2555d197e 100644 --- a/src/TransferListWidget.cpp +++ b/src/TransferListWidget.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): QTreeView(parent) { @@ -55,7 +56,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): setItemDelegate(listDelegate); // 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(SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); listModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded")); @@ -70,6 +71,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): proxyModel = new QSortFilterProxyModel(); proxyModel->setDynamicSortFilter(true); proxyModel->setSourceModel(listModel); + proxyModel->setFilterKeyColumn(STATUS); + proxyModel->setFilterRole(Qt::DisplayRole); setModel(proxyModel); // Visual settings @@ -78,6 +81,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): setSortingEnabled(true); hideColumn(PRIORITY); hideColumn(HASH); + hideColumn(STATUS); loadHiddenColumns(); // Load last columns width for transfer list if(!loadColWidthList()) { @@ -128,9 +132,11 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) { // Pause torrent if it is 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, STATUS), INACTIVE); //setRowColor(row, QString::fromUtf8("red")); }else{ 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")); } } catch(invalid_handle e) { @@ -140,7 +146,7 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) { } /*void TransferListWidget::setRowColor(int row, QColor color) { - unsigned int nbColumns = listModel->columnCount()-1; + unsigned int nbColumns = listModel->columnCount()-2; for(unsigned int i=0; isetData(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, ETA), QVariant((qlonglong)-1)); 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"))); //setRowColor(row, QString::fromUtf8("red")); } @@ -166,8 +173,10 @@ void TransferListWidget::pauseTorrent(int row) { void TransferListWidget::resumeTorrent(int row) { QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row)); 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, STATUS), COMPLETED); + } updateTorrent(row); } @@ -197,9 +206,11 @@ void TransferListWidget::updateTorrent(int row) { if(h.is_queued()) { 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, STATUS), INACTIVE); listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress())); }else { 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)); } // Reset speeds and seeds/leech @@ -221,6 +232,7 @@ void TransferListWidget::updateTorrent(int row) { case torrent_status::queued_for_checking: 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, STATUS), INACTIVE); //setRowColor(row, QString::fromUtf8("grey")); break; case torrent_status::downloading: @@ -234,6 +246,7 @@ void TransferListWidget::updateTorrent(int row) { listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); //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())); break; default: @@ -265,9 +278,11 @@ void TransferListWidget::setFinished(QTorrentHandle &h) { if(row >= 0) { if(h.is_paused()) { listModel->setData(listModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole); + listModel->setData(listModel->index(row, STATUS), INACTIVE); //setRowColor(row, "red"); }else{ listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole); + listModel->setData(listModel->index(row, STATUS), COMPLETED); //setRowColor(row, "orange"); } listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); @@ -531,7 +546,7 @@ void TransferListWidget::recheckSelectedTorrents() { void TransferListWidget::saveHiddenColumns() { QSettings settings("qBittorrent", "qBittorrent"); QStringList ishidden_list; - short nbColumns = listModel->columnCount()-1; + short nbColumns = listModel->columnCount()-2; for(short i=0; icolumnCount()-1) { + if(nbCol == (unsigned int)listModel->columnCount()-2) { for(unsigned int i=0; icolumnCount()-1; + short nbColumns = listModel->columnCount()-2; QString line = settings.value("TransferListColsWidth", QString()).toString(); if(!line.isEmpty()) { width_list = line.split(' '); @@ -717,7 +732,7 @@ bool TransferListWidget::loadColWidthList() { if(line.isEmpty()) return false; 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"); return false; } @@ -726,7 +741,7 @@ bool TransferListWidget::loadColWidthList() { header()->resizeSection(i, width_list.at(i).toInt()); } 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"); return false; } @@ -773,3 +788,22 @@ void TransferListWidget::loadLastSortedColumn() { 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()); + } +} diff --git a/src/TransferListWidget.h b/src/TransferListWidget.h index 5d616e09d..474f2bdc4 100644 --- a/src/TransferListWidget.h +++ b/src/TransferListWidget.h @@ -40,6 +40,8 @@ class QSortFilterProxyModel; class bittorrent; class QTimer; +enum TorrentFilter {ALL, DOWNLOADING, COMPLETED, ACTIVE, INACTIVE }; + class TransferListWidget: public QTreeView { Q_OBJECT @@ -97,6 +99,7 @@ public slots: void previewSelectedTorrents(); void hidePriorityColumn(bool hide); void displayDLHoSMenu(const QPoint&); + void applyFilter(int f); };