From d12e510fadbffb2420c45000fa7956ca4321053d Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 30 Jun 2007 18:56:49 +0000 Subject: [PATCH] Improved start_All and resume_All functions to detect if a torrent's state changed or not. This way, it doesn't flood the GUI if the user keeps on clicking on those buttons --- src/GUI.cpp | 66 ++++++++++++++++++++++++---------------------- src/bittorrent.cpp | 10 +++++-- src/bittorrent.h | 4 +-- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index 482fc80b1..caf5121d3 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -1300,25 +1300,26 @@ void GUI::configureSession(bool deleteOptions){ void GUI::on_actionPause_All_triggered(){ QString fileHash; // Pause all torrents - BTSession.pauseAllTorrents(); - // update download list - unsigned int nbRows = DLListModel->rowCount(); - for(unsigned int i=0; idata(DLListModel->index(i, HASH)).toString(); - // Create .paused file - QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); - paused_file.open(QIODevice::WriteOnly | QIODevice::Text); - paused_file.close(); - // Update DL list items - DLListModel->setData(DLListModel->index(i, DLSPEED), QVariant((double)0.)); - DLListModel->setData(DLListModel->index(i, UPSPEED), QVariant((double)0.)); - DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Paused"))); - DLListModel->setData(DLListModel->index(i, ETA), QVariant((qlonglong)-1)); - DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole); - DLListModel->setData(DLListModel->index(i, SEEDSLEECH), QVariant("0/0")); - setRowColor(i, "red"); - } - setInfoBar(tr("All downloads were paused.")); + if(BTSession.pauseAllTorrents()){ + // update download list + unsigned int nbRows = DLListModel->rowCount(); + for(unsigned int i=0; idata(DLListModel->index(i, HASH)).toString(); + // Create .paused file + QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); + paused_file.open(QIODevice::WriteOnly | QIODevice::Text); + paused_file.close(); + // Update DL list items + DLListModel->setData(DLListModel->index(i, DLSPEED), QVariant((double)0.)); + DLListModel->setData(DLListModel->index(i, UPSPEED), QVariant((double)0.)); + DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Paused"))); + DLListModel->setData(DLListModel->index(i, ETA), QVariant((qlonglong)-1)); + DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole); + DLListModel->setData(DLListModel->index(i, SEEDSLEECH), QVariant("0/0")); + setRowColor(i, "red"); + } + setInfoBar(tr("All downloads were paused.")); + } } // pause selected items in the list @@ -1351,19 +1352,20 @@ void GUI::on_actionPause_triggered(){ void GUI::on_actionStart_All_triggered(){ QString fileHash; // Pause all torrents - BTSession.resumeAllTorrents(); - // update download list - unsigned int nbRows = DLListModel->rowCount(); - for(unsigned int i=0; idata(DLListModel->index(i, HASH)).toString(); - // Remove .paused file - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); - // Update DL list items - DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Connecting...", "i.e: Connecting to the tracker..."))); - DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole); - setRowColor(i, "grey"); - } - setInfoBar(tr("All downloads were resumed.")); + if(BTSession.resumeAllTorrents()){ + // update download list + unsigned int nbRows = DLListModel->rowCount(); + for(unsigned int i=0; idata(DLListModel->index(i, HASH)).toString(); + // Remove .paused file + QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); + // Update DL list items + DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Connecting...", "i.e: Connecting to the tracker..."))); + DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole); + setRowColor(i, "grey"); + } + setInfoBar(tr("All downloads were resumed.")); + } } // start selected items in the list diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 753ffeee1..0d42b888e 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -612,25 +612,31 @@ void bittorrent::saveTrackerFile(const QString& hash){ } // Pause all torrents in session -void bittorrent::pauseAllTorrents(){ +bool bittorrent::pauseAllTorrents(){ + bool paused_torrents = false; std::vector handles = s->get_torrents(); for(unsigned int i=0; i handles = s->get_torrents(); for(unsigned int i=0; i