From c6285d8f676ac17234c9c161f41835523be2dc0c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 29 Jul 2007 14:14:57 +0000 Subject: [PATCH] - Improved start/Pause & start_all/pause_all functions --- TODO | 7 +++++- src/GUI.cpp | 55 +++++++++++++++++++------------------------- src/bittorrent.cpp | 57 ++++++++++++++++++---------------------------- src/bittorrent.h | 6 ++--- src/src.pro | 2 ++ 5 files changed, 56 insertions(+), 71 deletions(-) diff --git a/TODO b/TODO index 36a810433..e50c52af3 100644 --- a/TODO +++ b/TODO @@ -48,4 +48,9 @@ - Wait for some bug fixes in libtorrent : - upload/download limit per torrent - double free or corruption on exit - - Crash due to connection_queue \ No newline at end of file + - Crash due to connection_queue +LANGUAGES UPDATED: +- French +- English +- Japanese +- Swedish \ No newline at end of file diff --git a/src/GUI.cpp b/src/GUI.cpp index 111b54340..939e0206b 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -588,6 +588,8 @@ void GUI::updateDlList(bool force){ setRowColor(row, "red"); BTSession->pauseTorrent(fileHash); continue; + }else{ + qDebug("%s should be paused but it hasn't finished checking yet", (const char*)DLListModel->index(row, NAME).data().toString().toUtf8()); } } if(delayedSorting && BTSession->getUncheckedTorrentsList().indexOf(fileHash) != -1){ @@ -1370,16 +1372,12 @@ void GUI::configureSession(bool deleteOptions){ // Pause All Downloads in DL list void GUI::on_actionPause_All_triggered(){ QString fileHash; - // Pause all torrents - 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(); + bool change = false; + // update download list + unsigned int nbRows = DLListModel->rowCount(); + for(unsigned int i=0; idata(DLListModel->index(i, HASH)).toString(); + if(BTSession->pauseTorrent(fileHash)){ // Update DL list items DLListModel->setData(DLListModel->index(i, DLSPEED), QVariant((double)0.)); DLListModel->setData(DLListModel->index(i, UPSPEED), QVariant((double)0.)); @@ -1387,9 +1385,11 @@ void GUI::on_actionPause_All_triggered(){ 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"); + change = true; } - setInfoBar(tr("All downloads were paused.")); } + if(change) + setInfoBar(tr("All downloads were paused.")); } // pause selected items in the list @@ -1400,9 +1400,7 @@ void GUI::on_actionPause_triggered(){ if(index.column() == NAME){ // Get the file name QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); - if(!BTSession->isPaused(fileHash)){ - // Pause the torrent - BTSession->pauseTorrent(fileHash); + if(BTSession->pauseTorrent(fileHash)){ // Update DL status int row = index.row(); DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0)); @@ -1420,20 +1418,19 @@ void GUI::on_actionPause_triggered(){ // Resume All Downloads in DL list void GUI::on_actionStart_All_triggered(){ QString fileHash; - // Pause all torrents - 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 - if(QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused")){ - DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole); - setRowColor(i, "grey"); - } + unsigned int nbRows = DLListModel->rowCount(); + bool change = false; + for(unsigned int i=0; idata(DLListModel->index(i, HASH)).toString(); + // Remove .paused file + if(BTSession->resumeTorrent(fileHash)){ + DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole); + setRowColor(i, "grey"); + change = true; } - setInfoBar(tr("All downloads were resumed.")); } + if(change) + setInfoBar(tr("All downloads were resumed.")); } // start selected items in the list @@ -1444,11 +1441,7 @@ void GUI::on_actionStart_triggered(){ if(index.column() == NAME){ // Get the file name QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); - if(BTSession->isPaused(fileHash)){ - // Resume the torrent - BTSession->resumeTorrent(fileHash); - // Delete .paused file - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused"); + if(BTSession->resumeTorrent(fileHash)){ // Update DL status int row = index.row(); setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str()))); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 8c7493d53..7c197f4af 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -190,33 +190,48 @@ void bittorrent::cleanDeleter(deleteThread* deleter){ } // Pause a running torrent -void bittorrent::pauseTorrent(QString hash){ +bool bittorrent::pauseTorrent(QString hash){ + bool change = false; torrent_handle h = s->find_torrent(misc::fromString((hash.toStdString()))); if(h.is_valid() && !h.is_paused()){ h.pause(); - // Create .paused file - QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); - paused_file.open(QIODevice::WriteOnly | QIODevice::Text); - paused_file.close(); + change = true; qDebug("Torrent paused successfully"); }else{ qDebug("Could not pause torrent, invalid or already paused."); } + // Create .paused file if necessary + if(!QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")){ + QFile paused_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); + paused_file.open(QIODevice::WriteOnly | QIODevice::Text); + paused_file.close(); + } + // Remove from the list of torrents to pause after checking int index = torrentsToPauseAfterChecking.indexOf(hash); if(index != -1) { torrentsToPauseAfterChecking.removeAt(index); qDebug("A torrent was paused just after checking, good"); } + return change; } // Resume a torrent in paused state -void bittorrent::resumeTorrent(QString hash){ +bool bittorrent::resumeTorrent(QString hash){ + bool success = false; torrent_handle h = s->find_torrent(misc::fromString((hash.toStdString()))); if(h.is_valid() && h.is_paused()){ h.resume(); - // Delete .paused file + success = true; + } + // Delete .paused file + if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused"); + int index = torrentsToPauseAfterChecking.indexOf(hash); + if(index != -1){ + torrentsToPauseAfterChecking.removeAt(index); + success = true; } + return success; } void bittorrent::loadWebSeeds(QString fileHash){ @@ -811,34 +826,6 @@ void bittorrent::saveTrackerFile(QString hash){ tracker_file.close(); } -// Pause all torrents in session -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