- Make torrent status filters behave as in µTorrent

This commit is contained in:
Christophe Dumez 2009-11-21 13:51:15 +00:00
parent 46f081d888
commit d6e1dc9020
4 changed files with 85 additions and 39 deletions

View file

@ -41,7 +41,7 @@
#include "misc.h"
// Defines for download list list columns
enum TorrentState {STATE_STALLED, STATE_DOWNLOADING, STATE_SEEDING, STATE_PAUSED, STATE_QUEUED, STATE_CHECKING, STATE_INVALID};
enum TorrentState {STATE_DOWNLOADING, STATE_STALLED_DL, STATE_STALLED_UP, STATE_SEEDING, STATE_PAUSED_DL, STATE_PAUSED_UP, STATE_QUEUED_DL, STATE_QUEUED_UP, STATE_CHECKING_UP, STATE_CHECKING_DL, STATE_INVALID};
enum Column {TR_NAME, TR_PRIORITY, TR_SIZE, TR_PROGRESS, TR_STATUS, TR_SEEDS, TR_PEERS, TR_DLSPEED, TR_UPSPEED, TR_ETA, TR_RATIO, TR_HASH};
class TransferListDelegate: public QItemDelegate {
@ -86,19 +86,23 @@ public:
case STATE_DOWNLOADING:
display = tr("Downloading");
break;
case STATE_PAUSED:
case STATE_PAUSED_DL:
case STATE_PAUSED_UP:
display = tr("Paused");
break;
case STATE_QUEUED:
case STATE_QUEUED_DL:
case STATE_QUEUED_UP:
display = tr("Queued", "i.e. torrent is queued");
break;
case STATE_SEEDING:
case STATE_STALLED_UP:
display = tr("Seeding", "Torrent is complete and in upload-only mode");
break;
case STATE_STALLED:
case STATE_STALLED_DL:
display = tr("Stalled", "Torrent is waiting for download to begin");
break;
case STATE_CHECKING:
case STATE_CHECKING_DL:
case STATE_CHECKING_UP:
display = tr("Checking", "Torrent local data is being checked");
}
QItemDelegate::drawBackground(painter, opt, index);

View file

@ -65,7 +65,7 @@ public:
// SIGNAL/SLOT
connect(this, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyFilter(int)));
connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint)));
connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint, uint)));
// Load settings
loadSettings();
@ -88,8 +88,7 @@ public:
}
protected slots:
void updateTorrentNumbers(uint nb_downloading, uint nb_seeding, uint nb_inactive) {
uint nb_active = nb_downloading+nb_seeding;
void updateTorrentNumbers(uint nb_downloading, uint nb_seeding, uint nb_active, uint nb_inactive) {
item(FILTER_ALL)->setData(Qt::DisplayRole, tr("All")+" ("+QString::number(nb_active+nb_inactive)+")");
item(FILTER_DOWNLOADING)->setData(Qt::DisplayRole, tr("Downloading")+" ("+QString::number(nb_downloading)+")");
item(FILTER_COMPLETED)->setData(Qt::DisplayRole, tr("Completed")+" ("+QString::number(nb_seeding)+")");

View file

@ -152,11 +152,19 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
// Pause torrent if it is
if(h.is_paused()) {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED);
if(h.is_seed())
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_UP);
else
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_DL);
//setRowColor(row, QString::fromUtf8("red"));
}else{
if(h.is_seed()) {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_UP);
} else {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_DL);
}
//setRowColor(row, QString::fromUtf8("grey"));
}
// Select first torrent to be added
@ -188,11 +196,16 @@ void TransferListWidget::pauseTorrent(QTorrentHandle &h) {
}
void TransferListWidget::pauseTorrent(int row, bool refresh_list) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
listModel->setData(listModel->index(row, TR_DLSPEED), QVariant((double)0.0));
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)0.0));
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)-1));
listModel->setData(listModel->index(row, TR_NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED);
if(h.is_seed()) {
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_UP);
} else {
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_DL);
}
listModel->setData(listModel->index(row, TR_SEEDS), QVariant(0.0));
listModel->setData(listModel->index(row, TR_PEERS), QVariant(0.0));
//setRowColor(row, QString::fromUtf8("red"));
@ -210,10 +223,10 @@ void TransferListWidget::resumeTorrent(int row, bool refresh_list) {
if(!h.is_valid()) return;
if(h.is_seed()) {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_SEEDING);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_UP);
} else {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/stalled.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_DL);
}
if(refresh_list)
refreshList();
@ -246,12 +259,18 @@ int TransferListWidget::updateTorrent(int row) {
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
s = STATE_CHECKING;
if(h.is_seed())
s = STATE_CHECKING_UP;
else
s = STATE_CHECKING_DL;
listModel->setData(listModel->index(row, TR_STATUS), s);
}else {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/mail-queue.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)-1));
s = STATE_QUEUED;
if(h.is_seed())
s = STATE_QUEUED_UP;
else
s =STATE_QUEUED_DL;
listModel->setData(listModel->index(row, TR_STATUS), s);
}
// Reset speeds and seeds/leech
@ -263,7 +282,11 @@ int TransferListWidget::updateTorrent(int row) {
return s;
}
}
if(h.is_paused()) return STATE_PAUSED;
if(h.is_paused()) {
if(h.is_seed())
return STATE_PAUSED_UP;
return STATE_PAUSED_DL;
}
// Parse download state
switch(h.state()) {
@ -272,8 +295,11 @@ int TransferListWidget::updateTorrent(int row) {
case torrent_status::queued_for_checking:
case torrent_status::checking_resume_data:
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_CHECKING);
s = STATE_CHECKING;
if(h.is_seed())
s = STATE_CHECKING_UP;
else
s = STATE_CHECKING_DL;
listModel->setData(listModel->index(row, TR_STATUS), s);
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)-1));
//setRowColor(row, QString::fromUtf8("grey"));
break;
@ -282,24 +308,27 @@ int TransferListWidget::updateTorrent(int row) {
if(h.download_payload_rate() > 0) {
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)BTSession->getETA(hash)));
listModel->setData(listModel->index(row, TR_STATUS), STATE_DOWNLOADING);
s = STATE_DOWNLOADING;
//setRowColor(row, QString::fromUtf8("green"));
}else{
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)-1));
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED);
s = STATE_STALLED;
s = STATE_STALLED_DL;
//setRowColor(row, QApplication::palette().color(QPalette::WindowText));
}
listModel->setData(listModel->index(row, TR_STATUS), s);
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)h.upload_payload_rate()));
break;
case torrent_status::finished:
case torrent_status::seeding:
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)-1));
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)h.upload_payload_rate()));
listModel->setData(listModel->index(row, TR_STATUS), STATE_SEEDING);
if(h.upload_payload_rate() > 0) {
s = STATE_SEEDING;
} else {
s = STATE_STALLED_UP;
}
listModel->setData(listModel->index(row, TR_STATUS), s);
}
// Common to both downloads and uploads
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
@ -335,11 +364,11 @@ void TransferListWidget::setFinished(QTorrentHandle &h) {
if(row >= 0) {
if(h.is_paused()) {
listModel->setData(listModel->index(row, TR_NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED);
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_UP);
//setRowColor(row, "red");
}else{
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, TR_STATUS), STATE_SEEDING);
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_UP);
//setRowColor(row, "orange");
}
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)-1));
@ -357,27 +386,37 @@ void TransferListWidget::setRefreshInterval(int t) {
}
void TransferListWidget::refreshList() {
unsigned int nb_downloading = 0, nb_seeding=0, nb_inactive = 0;
unsigned int nb_downloading = 0, nb_seeding=0, nb_active=0, nb_inactive = 0;
for(int i=0; i<listModel->rowCount(); ++i) {
int s = updateTorrent(i);
switch(s) {
case STATE_DOWNLOADING:
case STATE_STALLED:
++nb_active;
++nb_downloading;
break;
case STATE_STALLED_DL:
case STATE_CHECKING_DL:
case STATE_PAUSED_DL:
case STATE_QUEUED_DL:
++nb_inactive;
++nb_downloading;
break;
case STATE_SEEDING:
++nb_active;
++nb_seeding;
break;
case STATE_CHECKING:
case STATE_PAUSED:
case STATE_QUEUED:
case STATE_STALLED_UP:
case STATE_CHECKING_UP:
case STATE_PAUSED_UP:
case STATE_QUEUED_UP:
++nb_seeding;
++nb_inactive;
break;
default:
break;
}
}
emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_inactive);
emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_active, nb_inactive);
}
int TransferListWidget::getRowFromHash(QString hash) const{
@ -1010,16 +1049,20 @@ void TransferListWidget::currentChanged(const QModelIndex& current, const QModel
void TransferListWidget::applyFilter(int f) {
switch(f) {
case FILTER_DOWNLOADING:
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_STALLED), Qt::CaseSensitive));
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_STALLED_DL)+"|"+
QString::number(STATE_PAUSED_DL)+"|"+QString::number(STATE_CHECKING_DL)+"|"+
QString::number(STATE_QUEUED_DL), Qt::CaseSensitive));
break;
case FILTER_COMPLETED:
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_SEEDING), Qt::CaseSensitive, QRegExp::FixedString));
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_SEEDING)+"|"+QString::number(STATE_STALLED_UP)+"|"+
QString::number(STATE_PAUSED_UP)+"|"+QString::number(STATE_CHECKING_UP)+"|"+
QString::number(STATE_QUEUED_UP), Qt::CaseSensitive));
break;
case FILTER_ACTIVE:
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_SEEDING)+"|"+QString::number(STATE_STALLED), Qt::CaseSensitive));
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_SEEDING), Qt::CaseSensitive));
break;
case FILTER_INACTIVE:
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_CHECKING)+"|"+QString::number(STATE_PAUSED)+"|"+QString::number(STATE_QUEUED), Qt::CaseSensitive));
proxyModel->setFilterRegExp(QRegExp("[^"+QString::number(STATE_DOWNLOADING)+QString::number(STATE_SEEDING)+"]", Qt::CaseSensitive));
break;
default:
proxyModel->setFilterRegExp(QRegExp());

View file

@ -110,7 +110,7 @@ public slots:
signals:
void currentTorrentChanged(QTorrentHandle &h);
void torrentStatusUpdate(unsigned int, unsigned int, unsigned int);
void torrentStatusUpdate(unsigned int nb_downloading, unsigned int nb_seeding, unsigned int nb_active, unsigned int nb_inactive);
};