From a0b4e54410330eca4642941f123f0584e14d2510 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 30 Dec 2008 00:34:41 +0000 Subject: [PATCH] - Got rid of .paused files, useless with new libtorrent --- src/bittorrent.cpp | 13 +++++++------ src/bittorrent.h | 2 +- src/qtorrenthandle.cpp | 10 ---------- src/torrentAddition.h | 12 +++--------- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 3c465c282..98988e6dd 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -353,7 +353,7 @@ void bittorrent::loadWebSeeds(QString hash) { } // Add a torrent to the bittorrent session -void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) { +QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) { QTorrentHandle h; bool fastResume=false; QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); @@ -370,7 +370,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo // Processing torrents file = path.trimmed().replace("file://", "", Qt::CaseInsensitive); if(file.isEmpty()) { - return; + return h; } Q_ASSERT(!file.startsWith("http://", Qt::CaseInsensitive) && !file.startsWith("https://", Qt::CaseInsensitive) && !file.startsWith("ftp://", Qt::CaseInsensitive)); qDebug("Adding %s to download list", file.toUtf8().data()); @@ -392,7 +392,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo // Remove file QFile::remove(file); } - return; + return h; } qDebug(" -> Hash: %s", misc::toString(t->info_hash()).c_str()); qDebug(" -> Name: %s", t->name().c_str()); @@ -422,7 +422,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo // Delete torrent from scan dir QFile::remove(file); } - return; + return h; } add_torrent_params p; //Getting fast resume data if existing @@ -464,7 +464,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo qDebug("/!\\ Error: Invalid handle"); // If download from url, remove temp file if(!from_url.isNull()) QFile::remove(file); - return; + return h; } // Connections limit per torrent h.set_max_connections(maxConnecsPerTorrent); @@ -496,7 +496,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo qDebug("Incremental download enabled for %s", t->name().c_str()); h.set_sequential_download(true); } - if((resumed || !addInPause) && !QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) { + if(!addInPause && !fastResume) { // Start torrent because it was added in paused state h.resume(); } @@ -519,6 +519,7 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(file)); } emit addedTorrent(h); + return h; } // Check in .priorities file if the user filtered files diff --git a/src/bittorrent.h b/src/bittorrent.h index fb6bc6a23..48ce825bb 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -99,7 +99,7 @@ class bittorrent : public QObject { qlonglong getETA(QString hash) const; public slots: - void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); + QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); void loadSessionState(); void saveSessionState(); void downloadFromUrl(QString url); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index a426d2782..b3044105c 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -319,22 +319,12 @@ void QTorrentHandle::pause() { Q_ASSERT(h.is_valid()); h.auto_managed(false); h.pause(); - // 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(); - } } void QTorrentHandle::resume() { Q_ASSERT(h.is_valid()); h.auto_managed(true); h.resume(); - // Delete .paused file if necessary - if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash()+".paused")) { - QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash()+".paused"); - } } void QTorrentHandle::remove_url_seed(QString seed) { diff --git a/src/torrentAddition.h b/src/torrentAddition.h index 75b16c64b..f36b10f5e 100644 --- a/src/torrentAddition.h +++ b/src/torrentAddition.h @@ -415,14 +415,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ }else{ QFile::remove(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".incremental")); } - // Create .paused file if necessary - if(addInPause->isChecked()){ - QFile paused_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".paused")); - paused_file.open(QIODevice::WriteOnly | QIODevice::Text); - paused_file.close(); - }else{ - QFile::remove(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".paused")); - } // Check if there is at least one selected file if(allFiltered()){ QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent")); @@ -431,7 +423,9 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ // save filtered files savePiecesPriorities(); // Add to download list - BTSession->addTorrent(filePath, false, from_url); + QTorrentHandle h = BTSession->addTorrent(filePath, false, from_url); + if(addInPause->isChecked() && h.is_valid()) + h.pause(); close(); } };