diff --git a/src/GUI.cpp b/src/GUI.cpp index 3c4f652a1..11f520387 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -127,7 +127,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString))); connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString))); connect(BTSession, SIGNAL(deletedTorrent(QString)), this, SLOT(deleteTorrent(QString))); - connect(BTSession, SIGNAL(pausedTorrent(QString)), this, SLOT(pauseTorrent(QString))); qDebug("create tabWidget"); tabs = new QTabWidget(); // Download torrents tab @@ -1185,8 +1184,8 @@ void GUI::togglePausedState(QString hash) { if(tabs->currentIndex() == 1) inDownloadList = false; QTorrentHandle h = BTSession->getTorrentHandle(hash); - if(BTSession->isPaused(hash)) { - BTSession->resumeTorrent(hash); + if(h.is_paused()) { + h.resume(); if(inDownloadList) { downloadingTorrentTab->resumeTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); @@ -1195,7 +1194,7 @@ void GUI::togglePausedState(QString hash) { updateFinishedTorrentNumber(finishedTorrentTab->getNbTorrentsInList()); } }else{ - BTSession->pauseTorrent(hash); + h.pause(); if(inDownloadList) { downloadingTorrentTab->pauseTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); @@ -1262,7 +1261,9 @@ void GUI::on_actionPause_triggered() { } QString hash; foreach(hash, hashes) { - if(BTSession->pauseTorrent(hash)){ + QTorrentHandle h = BTSession->getTorrentHandle(hash); + if(!h.is_paused()){ + h.pause(); if(inDownloadList) { downloadingTorrentTab->pauseTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); @@ -1319,7 +1320,9 @@ void GUI::on_actionStart_triggered() { } QString hash; foreach(hash, hashes) { - if(BTSession->resumeTorrent(hash)){ + QTorrentHandle h = BTSession->getTorrentHandle(hash); + if(!h.is_paused()){ + h.resume(); if(inDownloadList) { downloadingTorrentTab->resumeTorrent(hash); updateUnfinishedTorrentNumber(downloadingTorrentTab->getNbTorrentsInList()); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index e809e1f08..0b747b8ec 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -225,17 +225,6 @@ QTorrentHandle bittorrent::getTorrentHandle(QString hash) const{ return QTorrentHandle(s->find_torrent(misc::fromString((hash.toStdString())))); } -// Return true if the torrent corresponding to the -// hash is paused -bool bittorrent::isPaused(QString hash) const{ - QTorrentHandle h = getTorrentHandle(hash); - if(!h.is_valid()) { - qDebug("/!\\ Error: Invalid handle"); - return true; - } - return h.is_paused(); -} - unsigned int bittorrent::getFinishedPausedTorrentsNb() const { unsigned int nbPaused = 0; std::vector torrents = getTorrents(); @@ -298,53 +287,6 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) { emit deletedTorrent(hash); } -// Pause a running torrent -bool bittorrent::pauseTorrent(QString hash) { - bool change = false; - QTorrentHandle h = getTorrentHandle(hash); - if(h.is_valid() && !h.is_paused()) { - h.pause(); - change = true; - // Save fast resume data - saveFastResumeData(hash); - qDebug("Torrent paused successfully"); - emit pausedTorrent(hash); - }else{ - if(!h.is_valid()) { - qDebug("Could not pause torrent %s, reason: invalid", hash.toUtf8().data()); - }else{ - qDebug("Could not pause torrent %s, reason: already paused", hash.toUtf8().data()); - } - } - // Create .paused file if necessary - QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); - paused_file.open(QIODevice::WriteOnly | QIODevice::Text); - paused_file.write(QByteArray::number((double)h.progress())); - paused_file.close(); - if(change) { - addConsoleMessage(tr("'%1' paused.", "e.g: xxx.avi paused.").arg(h.name())); - } - return change; -} - -// Resume a torrent in paused state -bool bittorrent::resumeTorrent(QString hash) { - bool change = false; - QTorrentHandle h = getTorrentHandle(hash); - if(h.is_valid() && h.is_paused()) { - h.resume(); - change = true; - emit resumedTorrent(hash); - } - // Delete .paused file - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); - if(change) { - addConsoleMessage(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(h.name())); - } - return change; -} - void bittorrent::pauseAllTorrents() { std::vector torrents = getTorrents(); std::vector::iterator torrentIT; diff --git a/src/bittorrent.h b/src/bittorrent.h index a5b0414b5..9e76e0592 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -76,7 +76,6 @@ class bittorrent : public QObject { ~bittorrent(); QTorrentHandle getTorrentHandle(QString hash) const; std::vector getTorrents() const; - bool isPaused(QString hash) const; bool isFilePreviewPossible(QString fileHash) const; bool isDHTEnabled() const; float getPayloadDownloadRate() const; @@ -107,8 +106,6 @@ class bittorrent : public QObject { void downloadFromUrl(QString url); void downloadFromURLList(const QStringList& url_list); void deleteTorrent(QString hash, bool permanent = false); - bool pauseTorrent(QString hash); - bool resumeTorrent(QString hash); void pauseAllTorrents(); void resumeAllTorrents(); void saveDHTEntry(); diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index 6faf46181..f7c66e6db 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -589,8 +589,8 @@ void DownloadingTorrents::addTorrent(QString hash) { if(BTSession->isQueueingEnabled()) DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash)); - // Pause torrent if it was paused last time - if(BTSession->isPaused(hash)) { + // Pause torrent if it is + if(h.is_paused()) { DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)BTSession->getUncheckedTorrentProgress(hash))); DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole); setRowColor(row, QString::fromUtf8("red"));