From a848538d66f3e457f20e69183a7af41d20af5d06 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 29 Dec 2008 18:36:54 +0000 Subject: [PATCH] - Pause / resume in Web UI now updates the GUI - Code cleanup --- src/FinishedTorrents.cpp | 7 ------ src/FinishedTorrents.h | 1 - src/GUI.cpp | 46 +++++++++++++++++++------------------ src/GUI.h | 2 ++ src/bittorrent.cpp | 13 +++++++---- src/bittorrent.h | 2 ++ src/downloadingTorrents.cpp | 7 ------ src/downloadingTorrents.h | 1 - 8 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index 8ce848ada..813516c36 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -289,13 +289,6 @@ void FinishedTorrents::pauseTorrent(QString hash) { setRowColor(row, QString::fromUtf8("red")); } -void FinishedTorrents::resumeTorrent(QString hash) { - int row = getRowFromHash(hash); - Q_ASSERT(row != -1); - finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))), Qt::DecorationRole); - setRowColor(row, QString::fromUtf8("orange")); -} - QString FinishedTorrents::getHashFromRow(unsigned int row) const { Q_ASSERT(row < (unsigned int)finishedListModel->rowCount()); return finishedListModel->data(finishedListModel->index(row, F_HASH)).toString(); diff --git a/src/FinishedTorrents.h b/src/FinishedTorrents.h index 924e527c8..9e2b896aa 100644 --- a/src/FinishedTorrents.h +++ b/src/FinishedTorrents.h @@ -78,7 +78,6 @@ class FinishedTorrents : public QWidget, public Ui::seeding { void addTorrent(QString hash); void updateTorrent(QTorrentHandle h); void pauseTorrent(QString hash); - void resumeTorrent(QString hash); void propertiesSelection(); void deleteTorrent(QString hash); void showPropertiesFromHash(QString hash); diff --git a/src/GUI.cpp b/src/GUI.cpp index 5786d011b..efe018667 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -122,6 +122,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis connect(BTSession, SIGNAL(fullDiskError(QTorrentHandle&)), this, SLOT(fullDiskError(QTorrentHandle&))); connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(finishedTorrent(QTorrentHandle&))); connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), this, SLOT(addedTorrent(QTorrentHandle&))); + connect(BTSession, SIGNAL(pausedTorrent(QTorrentHandle&)), this, SLOT(pausedTorrent(QTorrentHandle&))); + connect(BTSession, SIGNAL(resumedTorrent(QTorrentHandle&)), this, SLOT(resumedTorrent(QTorrentHandle&))); connect(BTSession, SIGNAL(torrentFinishedChecking(QTorrentHandle&)), this, SLOT(checkedTorrent(QTorrentHandle&))); connect(BTSession, SIGNAL(trackerAuthenticationRequired(QTorrentHandle&)), this, SLOT(trackerAuthenticationRequired(QTorrentHandle&))); connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString))); @@ -371,6 +373,22 @@ void GUI::addedTorrent(QTorrentHandle& h) const { } } +void GUI::pausedTorrent(QTorrentHandle& h) const { + if(h.is_seed()) { + finishedTorrentTab->pauseTorrent(h.hash()); + } else { + downloadingTorrentTab->pauseTorrent(h.hash()); + } +} + +void GUI::resumedTorrent(QTorrentHandle& h) const { + if(h.is_seed()) { + finishedTorrentTab->updateTorrent(h); + } else { + downloadingTorrentTab->updateTorrent(h); + } +} + void GUI::checkedTorrent(QTorrentHandle& h) const { if(h.is_seed()) { // Move torrent to finished tab @@ -1193,20 +1211,18 @@ void GUI::togglePausedState(QString hash) { QTorrentHandle h = BTSession->getTorrentHandle(hash); if(h.is_paused()) { h.resume(); + resumedTorrent(h); if(inDownloadList) { - downloadingTorrentTab->resumeTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); }else{ - finishedTorrentTab->resumeTorrent(hash); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); } }else{ h.pause(); + pausedTorrent(h); if(inDownloadList) { - downloadingTorrentTab->pauseTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); }else{ - finishedTorrentTab->pauseTorrent(hash); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); } } @@ -1222,13 +1238,7 @@ void GUI::on_actionPause_All_triggered() { if(!h.is_valid() || h.is_paused()) continue; change = true; h.pause(); - if(h.is_seed()) { - // Update in finished list - finishedTorrentTab->pauseTorrent(h.hash()); - } else { - // Update in download list - downloadingTorrentTab->pauseTorrent(h.hash()); - } + pausedTorrent(h); } if(change) { updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); @@ -1271,11 +1281,10 @@ void GUI::on_actionPause_triggered() { QTorrentHandle h = BTSession->getTorrentHandle(hash); if(!h.is_paused()){ h.pause(); + pausedTorrent(h); if(inDownloadList) { - downloadingTorrentTab->pauseTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); } else { - finishedTorrentTab->pauseTorrent(hash); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); } } @@ -1299,13 +1308,7 @@ void GUI::on_actionStart_All_triggered() { if(!h.is_valid() || !h.is_paused()) continue; change = true; h.resume(); - if(h.is_seed()) { - // Update in finished list - finishedTorrentTab->resumeTorrent(h.hash()); - } else { - // Update in download list - downloadingTorrentTab->resumeTorrent(h.hash()); - } + resumedTorrent(h); } if(change) { updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); @@ -1330,11 +1333,10 @@ void GUI::on_actionStart_triggered() { QTorrentHandle h = BTSession->getTorrentHandle(hash); if(h.is_paused()){ h.resume(); + resumedTorrent(h); if(inDownloadList) { - downloadingTorrentTab->resumeTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); } else { - finishedTorrentTab->resumeTorrent(hash); updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); } } diff --git a/src/GUI.h b/src/GUI.h index aed449f7b..a30a7a063 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -160,6 +160,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void finishedTorrent(QTorrentHandle& h) const; void addedTorrent(QTorrentHandle& h) const; void checkedTorrent(QTorrentHandle& h) const; + void pausedTorrent(QTorrentHandle& h) const; + void resumedTorrent(QTorrentHandle& h) const; void updateLists(bool force=false); bool initWebUi(QString username, QString password, int port); void pauseTorrent(QString hash); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 3aeca45ca..a72d8917b 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -287,6 +287,7 @@ void bittorrent::pauseAllTorrents() { if(!h.is_valid()) continue; if(!h.is_paused()) { h.pause(); + emit pausedTorrent(h); } } } @@ -299,20 +300,25 @@ void bittorrent::resumeAllTorrents() { if(!h.is_valid()) continue; if(h.is_paused()) { h.resume(); + emit resumedTorrent(h); } } } void bittorrent::pauseTorrent(QString hash) { QTorrentHandle h = getTorrentHandle(hash); - if(!h.is_paused()) + if(!h.is_paused()) { h.pause(); + emit pausedTorrent(h); + } } void bittorrent::resumeTorrent(QString hash) { QTorrentHandle h = getTorrentHandle(hash); - if(h.is_paused()) + if(h.is_paused()) { h.resume(); + emit resumedTorrent(h); + } } void bittorrent::loadWebSeeds(QString hash) { @@ -502,18 +508,17 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo } // Send torrent addition signal if(!from_url.isNull()) { - emit addedTorrent(h); if(fastResume) addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(from_url)); else addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url)); }else{ - emit addedTorrent(h); if(fastResume) addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(file)); else addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(file)); } + emit addedTorrent(h); } // Check in .priorities file if the user filtered files diff --git a/src/bittorrent.h b/src/bittorrent.h index 6b638e573..9cead6f7d 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -165,6 +165,8 @@ class bittorrent : public QObject { signals: void addedTorrent(QTorrentHandle& h); void deletedTorrent(QString hash); + void pausedTorrent(QTorrentHandle& h); + void resumedTorrent(QTorrentHandle& h); void finishedTorrent(QTorrentHandle& h); void fullDiskError(QTorrentHandle& h); void trackerError(QString hash, QString time, QString msg); diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index 0577a85d1..52135e9b9 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -168,13 +168,6 @@ void DownloadingTorrents::showPropertiesFromHash(QString hash) { prop->show(); } -void DownloadingTorrents::resumeTorrent(QString hash){ - int row = getRowFromHash(hash); - Q_ASSERT(row != -1); - DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole); - setRowColor(row, QString::fromUtf8("grey")); -} - // Remove a torrent from the download list but NOT from the BT Session void DownloadingTorrents::deleteTorrent(QString hash) { int row = getRowFromHash(hash); diff --git a/src/downloadingTorrents.h b/src/downloadingTorrents.h index 4650eae70..7f7aec459 100644 --- a/src/downloadingTorrents.h +++ b/src/downloadingTorrents.h @@ -86,7 +86,6 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{ public slots: bool updateTorrent(QTorrentHandle h); void pauseTorrent(QString hash); - void resumeTorrent(QString hash); void deleteTorrent(QString hash); void propertiesSelection(); void updateFileSizeAndProgress(QString hash);