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 @@ @@ -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};
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, DLSPEED, UPSPEED, SEEDSLEECH, RATIO, ETA, PRIORITY, HASH, STATUS};

11
src/TransferListFiltersWidget.h

@ -65,6 +65,7 @@ public: @@ -65,6 +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)));
// Load settings
loadSettings();
@ -86,6 +87,16 @@ public: @@ -86,6 +87,16 @@ public:
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

85
src/TransferListWidget.cpp

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

13
src/TransferListWidget.h

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

Loading…
Cancel
Save