From 9a87afb562ae5ac6705413a89a151393257ea865 Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Sun, 30 Mar 2014 16:29:51 +0400 Subject: [PATCH] Use TorrentTempData for overriding "add torrents paused" functionality --- src/addnewtorrentdialog.cpp | 3 ++- src/qtlibtorrent/qbtsession.cpp | 25 +++++++++++++++++-------- src/torrentpersistentdata.cpp | 8 ++++++++ src/torrentpersistentdata.h | 6 +++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index bea92a70e..e0ac8af2e 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -560,7 +560,6 @@ void AddNewTorrentDialog::accept() // TODO: Check if destination actually exists TorrentTempData::setSeedingMode(m_hash, true); } - pref->addTorrentsInPause(!ui->start_torrent_cb->isChecked()); // Label const QString label = ui->label_combo->currentText(); @@ -575,6 +574,8 @@ void AddNewTorrentDialog::accept() if (m_hasRenamedFile) TorrentTempData::setFilesPath(m_hash, m_filesPath); + TorrentTempData::setAddPaused(m_hash, !ui->start_torrent_cb->isChecked()); + // Add torrent if (m_isMagnet) QBtSession::instance()->unhideMagnet(m_hash); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 5d3b9b18a..72e5576cf 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -995,7 +995,10 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f loadTorrentSettings(h); // Load filtered files + bool add_paused = pref->addTorrentsInPause(); if (!resumed) { + if (TorrentTempData::hasTempData(hash)) + add_paused = TorrentTempData::isAddPaused(hash); loadTorrentTempData(h, savePath, true); } if (HiddenData::hasData(hash) && pref->isQueueingSystemEnabled()) { @@ -1014,7 +1017,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f s->set_settings(sessionSettings); h.queue_position_top(); } - if (!pref->addTorrentsInPause() || HiddenData::hasData(hash)) { + if (!add_paused || HiddenData::hasData(hash)) { // Start torrent because it was added in paused state h.resume(); } @@ -1182,8 +1185,12 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr loadTorrentSettings(h); + bool add_paused = pref->addTorrentsInPause(); if (!resumed) { qDebug("This is a NEW torrent (first time)..."); + if (TorrentTempData::hasTempData(hash)) + add_paused = TorrentTempData::isAddPaused(hash); + loadTorrentTempData(h, savePath, false); // Append .!qB to incomplete files @@ -1199,7 +1206,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr exportTorrentFile(h); } - if (!fastResume && !pref->addTorrentsInPause()) { + if (!fastResume && !add_paused) { // Start torrent because it was added in paused state h.resume(); } @@ -2912,10 +2919,7 @@ void QBtSession::processDownloadedFile(QString url, QString file_path) { emit newDownloadedTorrent(file_path, url); } else { url_skippingDlg.removeAt(index); - QTorrentHandle h = addTorrent(file_path, false, url, false); - // Pause torrent if necessary - if (h.is_valid() && pref->addTorrentsInPause() && pref->useAdditionDialog()) - h.pause(); + addTorrent(file_path, false, url, false); emit newDownloadedTorrentFromRss(url); } } @@ -3093,6 +3097,11 @@ void QBtSession::unhideMagnet(const QString &hash) { return; } + bool add_paused = pref->addTorrentsInPause(); + if (TorrentTempData::hasTempData(hash)) { + add_paused = TorrentTempData::isAddPaused(hash); + } + if (!h.has_metadata()) { if (pref->isQueueingSystemEnabled()) { //Internally decrease the queue limits to ensure that other queued items aren't started @@ -3109,13 +3118,13 @@ void QBtSession::unhideMagnet(const QString &hash) { sessionSettings.active_limit = max_active; s->set_settings(sessionSettings); } - if (pref->addTorrentsInPause()) + if (add_paused) h.pause(); } h.queue_position_bottom(); loadTorrentTempData(h, h.save_path(), !h.has_metadata()); //TempData are deleted by a call to TorrentPersistentData::saveTorrentPersistentData() - if (!pref->addTorrentsInPause()) + if (!add_paused) h.resume(); h.move_storage(save_path); diff --git a/src/torrentpersistentdata.cpp b/src/torrentpersistentdata.cpp index bb562214b..12cd30c9d 100644 --- a/src/torrentpersistentdata.cpp +++ b/src/torrentpersistentdata.cpp @@ -160,6 +160,14 @@ QString TorrentTempData::getQueuedPath(const QString &hash) { return i->queuedPath; } +void TorrentTempData::setAddPaused(const QString &hash, const bool &paused) { + data[hash].add_paused = paused; +} + +bool TorrentTempData::isAddPaused(const QString &hash) { + return data.value(hash).add_paused; +} + void HiddenData::addData(const QString &hash) { data[hash] = false; } diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index b5ef335bb..c46eb11bf 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -34,6 +34,7 @@ #include #include #include +#include "preferences.h" QT_BEGIN_NAMESPACE class QDateTime; @@ -65,16 +66,19 @@ public: static QString getOldPath(const QString &hash); static QString getNewPath(const QString &hash); static QString getQueuedPath(const QString &hash); + static void setAddPaused(const QString &hash, const bool &paused); + static bool isAddPaused(const QString &hash); private: struct TorrentData { - TorrentData(): sequential(false), seed(false) {} + TorrentData(): sequential(false), seed(false), add_paused(Preferences::instance()->addTorrentsInPause()) {} std::vector files_priority; QStringList path_list; QString save_path; QString label; bool sequential; bool seed; + bool add_paused; }; struct TorrentMoveState {