From 15ce9a7369ba9c8215245d9dde4483d0d13ba44b Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 15 Jul 2008 20:19:41 +0000 Subject: [PATCH] - Queueing systems now updates the number of active torrents in tab titles --- src/GUI.cpp | 14 ++++++++++++++ src/GUI.h | 2 ++ src/bittorrent.cpp | 12 ++++++++++++ src/bittorrent.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/src/GUI.cpp b/src/GUI.cpp index 0ec98b38a..d637af3a6 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -133,6 +133,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis connect(BTSession, SIGNAL(deletedTorrent(QString)), this, SLOT(deleteTorrent(QString))); connect(BTSession, SIGNAL(torrent_ratio_deleted(QString)), this, SLOT(deleteRatioTorrent(QString))); connect(BTSession, SIGNAL(pausedTorrent(QString)), this, SLOT(pauseTorrent(QString))); + connect(BTSession, SIGNAL(updateUnfinishedTorrentNumber()), this, SLOT(updateUnfinishedTorrentNumberCalc())); + connect(BTSession, SIGNAL(updateFinishedTorrentNumber()), this, SLOT(updateFinishedTorrentNumberCalc())); qDebug("create tabWidget"); tabs = new QTabWidget(); // Download torrents tab @@ -1142,11 +1144,23 @@ void GUI::updateUnfinishedTorrentNumber(unsigned int nb) { tabs->setTabText(0, tr("Downloads") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); } +void GUI::updateUnfinishedTorrentNumberCalc() { + unsigned int paused = BTSession->getUnfinishedPausedTorrentsNb(); + unsigned int nb = BTSession->getUnfinishedTorrents().size(); + tabs->setTabText(0, tr("Downloads") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); +} + void GUI::updateFinishedTorrentNumber(unsigned int nb) { unsigned int paused = BTSession->getFinishedPausedTorrentsNb(); tabs->setTabText(1, tr("Finished") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); } +void GUI::updateFinishedTorrentNumberCalc() { + unsigned int paused = BTSession->getFinishedPausedTorrentsNb(); + unsigned int nb = BTSession->getFinishedTorrents().size(); + tabs->setTabText(1, tr("Finished") +QString::fromUtf8(" (")+misc::toQString(nb-paused)+"/"+misc::toQString(nb)+QString::fromUtf8(")")); +} + // Allow to change action on double-click void GUI::torrentDoubleClicked(QString hash, bool finished) { int action; diff --git a/src/GUI.h b/src/GUI.h index 7b5c4fb82..8c0eb9e00 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -124,6 +124,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void readSettings(); void on_actionExit_triggered(); void createTrayIcon(); + void updateUnfinishedTorrentNumberCalc(); + void updateFinishedTorrentNumberCalc(); void updateUnfinishedTorrentNumber(unsigned int nb); void updateFinishedTorrentNumber(unsigned int nb); void fullDiskError(QTorrentHandle& h) const; diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 7e69d5a74..a5bf2e787 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -370,6 +370,7 @@ int bittorrent::getUpTorrentPriority(QString hash) const { void bittorrent::updateUploadQueue() { Q_ASSERT(queueingEnabled); + bool change = false; int maxActiveUploads = maxActiveTorrents - currentActiveDownloads; int currentActiveUploads = 0; // Check if it is necessary to queue uploads @@ -381,6 +382,7 @@ void bittorrent::updateUploadQueue() { } else { // Queue it h.pause(); + change = true; if(!queuedUploads->contains(hash)) { queuedUploads->append(hash); // Create .queued file @@ -395,6 +397,7 @@ void bittorrent::updateUploadQueue() { if(currentActiveUploads < maxActiveUploads && isUploadQueued(hash)) { QTorrentHandle h = getTorrentHandle(hash); h.resume(); + change = true; queuedUploads->removeAll(hash); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); ++currentActiveUploads; @@ -408,6 +411,7 @@ void bittorrent::updateUploadQueue() { if(uploadQueue->contains(hash)) { QTorrentHandle h = getTorrentHandle(hash); h.resume(); + change = true; queuedUploads->removeAll(hash); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); ++currentActiveUploads; @@ -417,10 +421,13 @@ void bittorrent::updateUploadQueue() { } } } + if(change) + emit updateFinishedTorrentNumber(); } void bittorrent::updateDownloadQueue() { Q_ASSERT(queueingEnabled); + bool change = false; currentActiveDownloads = 0; // Check if it is necessary to queue torrents foreach(QString hash, *downloadQueue) { @@ -431,6 +438,7 @@ void bittorrent::updateDownloadQueue() { } else { // Queue it h.pause(); + change = true; if(!queuedDownloads->contains(hash)) { queuedDownloads->append(hash); // Create .queued file @@ -445,6 +453,7 @@ void bittorrent::updateDownloadQueue() { if(currentActiveDownloads < maxActiveDownloads && isDownloadQueued(hash)) { QTorrentHandle h = getTorrentHandle(hash); h.resume(); + change = true; queuedDownloads->removeAll(hash); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); ++currentActiveDownloads; @@ -458,6 +467,7 @@ void bittorrent::updateDownloadQueue() { if(downloadQueue->contains(hash)) { QTorrentHandle h = getTorrentHandle(hash); h.resume(); + change = true; queuedDownloads->removeAll(hash); QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"); ++currentActiveDownloads; @@ -467,6 +477,8 @@ void bittorrent::updateDownloadQueue() { } } } + if(change) + emit updateUnfinishedTorrentNumber(); } // Calculate the ETA using GASA diff --git a/src/bittorrent.h b/src/bittorrent.h index 9ae290190..f6c2501dd 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -208,6 +208,8 @@ class bittorrent : public QObject{ void torrent_ratio_deleted(QString fileName); void UPnPError(QString msg); void UPnPSuccess(QString msg); + void updateFinishedTorrentNumber(); + void updateUnfinishedTorrentNumber(); }; #endif