Browse Source

- Display the number of torrents in earch status filter

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

2
src/TransferListDelegate.h

@ -41,7 +41,7 @@
#include "misc.h" #include "misc.h"
// Defines for download list list columns // Defines for download list list columns
enum TorrentState {STATE_STALLED, STATE_DOWNLOADING, STATE_SEEDING, STATE_PAUSED, STATE_QUEUED, STATE_CHECKING}; enum TorrentState {STATE_STALLED, STATE_DOWNLOADING, STATE_SEEDING, STATE_PAUSED, STATE_QUEUED, STATE_CHECKING, STATE_INVALID};
enum Column {NAME, SIZE, PROGRESS, STATUS, SEEDS, PEERS, DLSPEED, UPSPEED, ETA, RATIO, PRIORITY, HASH}; enum Column {NAME, SIZE, PROGRESS, STATUS, SEEDS, PEERS, DLSPEED, UPSPEED, ETA, RATIO, PRIORITY, HASH};
//enum Column {NAME, SIZE, PROGRESS, DLSPEED, UPSPEED, SEEDSLEECH, RATIO, ETA, PRIORITY, HASH, STATUS}; //enum Column {NAME, SIZE, PROGRESS, DLSPEED, UPSPEED, SEEDSLEECH, RATIO, ETA, PRIORITY, HASH, STATUS};

11
src/TransferListFiltersWidget.h

@ -65,6 +65,7 @@ public:
// SIGNAL/SLOT // SIGNAL/SLOT
connect(this, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyFilter(int))); connect(this, SIGNAL(currentRowChanged(int)), transferList, SLOT(applyFilter(int)));
connect(transferList, SIGNAL(torrentStatusUpdate(uint,uint,uint)), this, SLOT(updateTorrentNumbers(uint, uint, uint)));
// Load settings // Load settings
loadSettings(); loadSettings();
@ -86,6 +87,16 @@ public:
setCurrentRow(settings.value("selectedFilterIndex", 0).toInt()); setCurrentRow(settings.value("selectedFilterIndex", 0).toInt());
} }
protected slots:
void updateTorrentNumbers(uint nb_downloading, uint nb_seeding, uint nb_inactive) {
uint nb_active = nb_downloading+nb_seeding;
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)+")");
item(FILTER_ACTIVE)->setData(Qt::DisplayRole, tr("Active")+" ("+QString::number(nb_active)+")");
item(FILTER_INACTIVE)->setData(Qt::DisplayRole, tr("Inactive")+" ("+QString::number(nb_inactive)+")");
}
}; };
#endif // TRANSFERLISTFILTERSWIDGET_H #endif // TRANSFERLISTFILTERSWIDGET_H

85
src/TransferListWidget.cpp

@ -29,9 +29,9 @@
*/ */
#include "TransferListWidget.h" #include "TransferListWidget.h"
#include "TransferListDelegate.h"
#include "bittorrent.h" #include "bittorrent.h"
#include "torrentPersistentData.h" #include "torrentPersistentData.h"
#include "TransferListDelegate.h"
#include "previewSelect.h" #include "previewSelect.h"
#include "speedlimitdlg.h" #include "speedlimitdlg.h"
#include "options_imp.h" #include "options_imp.h"
@ -174,8 +174,10 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) {
} }
}*/ }*/
void TransferListWidget::deleteTorrent(int row) { void TransferListWidget::deleteTorrent(int row, bool refresh_list) {
listModel->removeRow(row); listModel->removeRow(row);
if(refresh_list)
refreshList();
} }
// Wrapper slot for bittorrent signal // Wrapper slot for bittorrent signal
@ -183,7 +185,7 @@ void TransferListWidget::pauseTorrent(QTorrentHandle &h) {
pauseTorrent(getRowFromHash(h.hash())); pauseTorrent(getRowFromHash(h.hash()));
} }
void TransferListWidget::pauseTorrent(int row) { void TransferListWidget::pauseTorrent(int row, bool refresh_list) {
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.0)); listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.0));
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));
@ -192,6 +194,8 @@ void TransferListWidget::pauseTorrent(int row) {
listModel->setData(listModel->index(row, SEEDS), QVariant(0.0)); listModel->setData(listModel->index(row, SEEDS), QVariant(0.0));
listModel->setData(listModel->index(row, PEERS), QVariant(0.0)); listModel->setData(listModel->index(row, PEERS), QVariant(0.0));
//setRowColor(row, QString::fromUtf8("red")); //setRowColor(row, QString::fromUtf8("red"));
if(refresh_list)
refreshList();
} }
// Wrapper slot for bittorrent signal // Wrapper slot for bittorrent signal
@ -199,7 +203,7 @@ void TransferListWidget::resumeTorrent(QTorrentHandle &h) {
resumeTorrent(getRowFromHash(h.hash())); resumeTorrent(getRowFromHash(h.hash()));
} }
void TransferListWidget::resumeTorrent(int row) { void TransferListWidget::resumeTorrent(int row, bool refresh_list) {
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()) {
@ -209,7 +213,8 @@ void TransferListWidget::resumeTorrent(int row) {
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/stalled.png")), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/stalled.png")), Qt::DecorationRole);
listModel->setData(listModel->index(row, STATUS), STATE_STALLED); listModel->setData(listModel->index(row, STATUS), STATE_STALLED);
} }
updateTorrent(row); if(refresh_list)
refreshList();
} }
void TransferListWidget::updateMetadata(QTorrentHandle &h) { void TransferListWidget::updateMetadata(QTorrentHandle &h) {
@ -222,13 +227,14 @@ void TransferListWidget::updateMetadata(QTorrentHandle &h) {
} }
} }
void TransferListWidget::updateTorrent(int row) { int TransferListWidget::updateTorrent(int row) {
TorrentState s = STATE_INVALID;
QString hash = getHashFromRow(row); QString hash = getHashFromRow(row);
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(!h.is_valid()) { if(!h.is_valid()) {
// Delete torrent // Delete torrent
deleteTorrent(row); deleteTorrent(row, false);
return; return s;
} }
try { try {
if(!h.is_seed()) { if(!h.is_seed()) {
@ -238,26 +244,23 @@ 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), STATE_QUEUED);
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), STATE_QUEUED);
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
} }
s = STATE_QUEUED;
listModel->setData(listModel->index(row, STATUS), STATE_QUEUED);
// Reset speeds and seeds/leech // Reset speeds and seeds/leech
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.)); listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.));
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)0.)); listModel->setData(listModel->index(row, UPSPEED), QVariant((double)0.));
listModel->setData(listModel->index(row, SEEDS), QVariant(0.0)); listModel->setData(listModel->index(row, SEEDS), QVariant(0.0));
listModel->setData(listModel->index(row, PEERS), QVariant(0.0)); listModel->setData(listModel->index(row, PEERS), QVariant(0.0));
//setRowColor(row, QString::fromUtf8("grey")); //setRowColor(row, QString::fromUtf8("grey"));
return; return s;
} }
} }
if(h.is_paused()) return; if(h.is_paused()) return STATE_PAUSED;
// Update
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress()));
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)h.download_payload_rate()));
// Parse download state // Parse download state
switch(h.state()) { switch(h.state()) {
@ -267,6 +270,7 @@ void TransferListWidget::updateTorrent(int row) {
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), STATE_CHECKING); listModel->setData(listModel->index(row, STATUS), STATE_CHECKING);
s = STATE_CHECKING;
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
//setRowColor(row, QString::fromUtf8("grey")); //setRowColor(row, QString::fromUtf8("grey"));
break; break;
@ -276,11 +280,13 @@ void TransferListWidget::updateTorrent(int row) {
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole); listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole);
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(hash))); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(hash)));
listModel->setData(listModel->index(row, STATUS), STATE_DOWNLOADING); listModel->setData(listModel->index(row, STATUS), STATE_DOWNLOADING);
s = STATE_DOWNLOADING;
//setRowColor(row, QString::fromUtf8("green")); //setRowColor(row, QString::fromUtf8("green"));
}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, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
listModel->setData(listModel->index(row, STATUS), STATE_STALLED); listModel->setData(listModel->index(row, STATUS), STATE_STALLED);
s = STATE_STALLED;
//setRowColor(row, QApplication::palette().color(QPalette::WindowText)); //setRowColor(row, QApplication::palette().color(QPalette::WindowText));
} }
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate())); listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate()));
@ -290,10 +296,13 @@ void TransferListWidget::updateTorrent(int row) {
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1)); listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate())); listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate()));
listModel->setData(listModel->index(row, STATUS), STATE_SEEDING); listModel->setData(listModel->index(row, STATUS), STATE_SEEDING);
s = STATE_SEEDING;
} }
} }
// Common to both downloads and uploads // Common to both downloads and uploads
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress()));
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)h.download_payload_rate()));
// Connected_seeds*100000+total_seeds*10 (if total_seeds is available) // Connected_seeds*100000+total_seeds*10 (if total_seeds is available)
// Connected_seeds*100000+1 (if total_seeds is unavailable) // Connected_seeds*100000+1 (if total_seeds is unavailable)
qulonglong seeds = h.num_seeds()*100000; qulonglong seeds = h.num_seeds()*100000;
@ -311,9 +320,11 @@ void TransferListWidget::updateTorrent(int row) {
// Share ratio // Share ratio
listModel->setData(listModel->index(row, RATIO), QVariant(BTSession->getRealRatio(hash))); listModel->setData(listModel->index(row, RATIO), QVariant(BTSession->getRealRatio(hash)));
}catch(invalid_handle e) { }catch(invalid_handle e) {
deleteTorrent(row); deleteTorrent(row, false);
s = STATE_INVALID;
qDebug("Caught Invalid handle exception, lucky us."); qDebug("Caught Invalid handle exception, lucky us.");
} }
return s;
} }
void TransferListWidget::setFinished(QTorrentHandle &h) { void TransferListWidget::setFinished(QTorrentHandle &h) {
@ -345,9 +356,27 @@ void TransferListWidget::setRefreshInterval(int t) {
} }
void TransferListWidget::refreshList() { void TransferListWidget::refreshList() {
unsigned int nb_downloading = 0, nb_seeding=0, nb_inactive = 0;
for(int i=0; i<listModel->rowCount(); ++i) { for(int i=0; i<listModel->rowCount(); ++i) {
updateTorrent(i); int s = updateTorrent(i);
switch(s) {
case STATE_DOWNLOADING:
case STATE_STALLED:
++nb_downloading;
break;
case STATE_SEEDING:
++nb_seeding;
break;
case STATE_CHECKING:
case STATE_PAUSED:
case STATE_QUEUED:
++nb_inactive;
break;
default:
break;
}
} }
emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_inactive);
} }
int TransferListWidget::getRowFromHash(QString hash) const{ int TransferListWidget::getRowFromHash(QString hash) const{
@ -399,9 +428,11 @@ void TransferListWidget::startSelectedTorrents() {
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.is_paused()) { if(h.is_valid() && h.is_paused()) {
h.resume(); h.resume();
resumeTorrent(row); resumeTorrent(row, false);
} }
} }
if(!selectedIndexes.empty())
refreshList();
} }
void TransferListWidget::startAllTorrents() { void TransferListWidget::startAllTorrents() {
@ -409,9 +440,10 @@ void TransferListWidget::startAllTorrents() {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i)); QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i));
if(h.is_valid() && h.is_paused()) { if(h.is_valid() && h.is_paused()) {
h.resume(); h.resume();
resumeTorrent(i); resumeTorrent(i, false);
} }
} }
refreshList();
} }
void TransferListWidget::pauseSelectedTorrents() { void TransferListWidget::pauseSelectedTorrents() {
@ -423,9 +455,11 @@ void TransferListWidget::pauseSelectedTorrents() {
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_paused()) { if(h.is_valid() && !h.is_paused()) {
h.pause(); h.pause();
pauseTorrent(row); pauseTorrent(row, false);
} }
} }
if(!selectedIndexes.empty())
refreshList();
} }
void TransferListWidget::pauseAllTorrents() { void TransferListWidget::pauseAllTorrents() {
@ -433,9 +467,10 @@ void TransferListWidget::pauseAllTorrents() {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i)); QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i));
if(h.is_valid() && !h.is_paused()) { if(h.is_valid() && !h.is_paused()) {
h.pause(); h.pause();
pauseTorrent(i); pauseTorrent(i, false);
} }
} }
refreshList();
} }
void TransferListWidget::deleteSelectedTorrents() { void TransferListWidget::deleteSelectedTorrents() {
@ -454,9 +489,10 @@ void TransferListWidget::deleteSelectedTorrents() {
hashes << getHashFromRow(proxyModel->mapToSource(index).row()); hashes << getHashFromRow(proxyModel->mapToSource(index).row());
} }
foreach(const QString &hash, hashes) { foreach(const QString &hash, hashes) {
deleteTorrent(getRowFromHash(hash)); deleteTorrent(getRowFromHash(hash), false);
BTSession->deleteTorrent(hash, false); BTSession->deleteTorrent(hash, false);
} }
refreshList();
} }
} }
@ -476,9 +512,10 @@ void TransferListWidget::deletePermSelectedTorrents() {
hashes << getHashFromRow(proxyModel->mapToSource(index).row()); hashes << getHashFromRow(proxyModel->mapToSource(index).row());
} }
foreach(const QString &hash, hashes) { foreach(const QString &hash, hashes) {
deleteTorrent(getRowFromHash(hash)); deleteTorrent(getRowFromHash(hash), false);
BTSession->deleteTorrent(hash, true); BTSession->deleteTorrent(hash, true);
} }
refreshList();
} }
} }
@ -593,7 +630,7 @@ void TransferListWidget::setDlLimitSelectedTorrents() {
} }
void TransferListWidget::setUpLimitSelectedTorrents() { void TransferListWidget::setUpLimitSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows(); QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList hashes; QStringList hashes;
QList<QTorrentHandle> selected_torrents; QList<QTorrentHandle> selected_torrents;
bool first = true; bool first = true;

13
src/TransferListWidget.h

@ -34,13 +34,13 @@
#include<QTreeView> #include<QTreeView>
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
class TransferListDelegate;
class QStandardItemModel; class QStandardItemModel;
class QSortFilterProxyModel; class QSortFilterProxyModel;
class bittorrent; class bittorrent;
class QTimer; class QTimer;
class TransferListDelegate;
enum TorrentFilter {FILTER_ALL, FILTER_DOWNLOADING, FILTER_COMPLETED, FILTER_ACTIVE, FILTER_INACTIVE }; enum TorrentFilter {FILTER_ALL, FILTER_DOWNLOADING, FILTER_COMPLETED, FILTER_ACTIVE, FILTER_INACTIVE};
class TransferListWidget: public QTreeView { class TransferListWidget: public QTreeView {
Q_OBJECT Q_OBJECT
@ -65,10 +65,10 @@ protected:
void loadLastSortedColumn(); void loadLastSortedColumn();
protected slots: protected slots:
void updateTorrent(int row); int updateTorrent(int row);
void deleteTorrent(int row); void deleteTorrent(int row, bool refresh_list=true);
void pauseTorrent(int row); void pauseTorrent(int row, bool refresh_list=true);
void resumeTorrent(int row); void resumeTorrent(int row, bool refresh_list=true);
void torrentDoubleClicked(QModelIndex index); void torrentDoubleClicked(QModelIndex index);
bool loadHiddenColumns(); bool loadHiddenColumns();
void saveHiddenColumns(); void saveHiddenColumns();
@ -106,6 +106,7 @@ public slots:
signals: signals:
void currentTorrentChanged(QTorrentHandle &h); void currentTorrentChanged(QTorrentHandle &h);
void torrentStatusUpdate(unsigned int, unsigned int, unsigned int);
}; };

Loading…
Cancel
Save