Browse Source

Use TorrentTempData for overriding "add torrents paused" functionality

adaptive-webui-19844
Nick Tiskov 11 years ago
parent
commit
9a87afb562
  1. 3
      src/addnewtorrentdialog.cpp
  2. 25
      src/qtlibtorrent/qbtsession.cpp
  3. 8
      src/torrentpersistentdata.cpp
  4. 6
      src/torrentpersistentdata.h

3
src/addnewtorrentdialog.cpp

@ -560,7 +560,6 @@ void AddNewTorrentDialog::accept()
// TODO: Check if destination actually exists // TODO: Check if destination actually exists
TorrentTempData::setSeedingMode(m_hash, true); TorrentTempData::setSeedingMode(m_hash, true);
} }
pref->addTorrentsInPause(!ui->start_torrent_cb->isChecked());
// Label // Label
const QString label = ui->label_combo->currentText(); const QString label = ui->label_combo->currentText();
@ -575,6 +574,8 @@ void AddNewTorrentDialog::accept()
if (m_hasRenamedFile) if (m_hasRenamedFile)
TorrentTempData::setFilesPath(m_hash, m_filesPath); TorrentTempData::setFilesPath(m_hash, m_filesPath);
TorrentTempData::setAddPaused(m_hash, !ui->start_torrent_cb->isChecked());
// Add torrent // Add torrent
if (m_isMagnet) if (m_isMagnet)
QBtSession::instance()->unhideMagnet(m_hash); QBtSession::instance()->unhideMagnet(m_hash);

25
src/qtlibtorrent/qbtsession.cpp

@ -995,7 +995,10 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
loadTorrentSettings(h); loadTorrentSettings(h);
// Load filtered files // Load filtered files
bool add_paused = pref->addTorrentsInPause();
if (!resumed) { if (!resumed) {
if (TorrentTempData::hasTempData(hash))
add_paused = TorrentTempData::isAddPaused(hash);
loadTorrentTempData(h, savePath, true); loadTorrentTempData(h, savePath, true);
} }
if (HiddenData::hasData(hash) && pref->isQueueingSystemEnabled()) { if (HiddenData::hasData(hash) && pref->isQueueingSystemEnabled()) {
@ -1014,7 +1017,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
s->set_settings(sessionSettings); s->set_settings(sessionSettings);
h.queue_position_top(); 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 // Start torrent because it was added in paused state
h.resume(); h.resume();
} }
@ -1182,8 +1185,12 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
loadTorrentSettings(h); loadTorrentSettings(h);
bool add_paused = pref->addTorrentsInPause();
if (!resumed) { if (!resumed) {
qDebug("This is a NEW torrent (first time)..."); qDebug("This is a NEW torrent (first time)...");
if (TorrentTempData::hasTempData(hash))
add_paused = TorrentTempData::isAddPaused(hash);
loadTorrentTempData(h, savePath, false); loadTorrentTempData(h, savePath, false);
// Append .!qB to incomplete files // Append .!qB to incomplete files
@ -1199,7 +1206,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
exportTorrentFile(h); exportTorrentFile(h);
} }
if (!fastResume && !pref->addTorrentsInPause()) { if (!fastResume && !add_paused) {
// Start torrent because it was added in paused state // Start torrent because it was added in paused state
h.resume(); h.resume();
} }
@ -2912,10 +2919,7 @@ void QBtSession::processDownloadedFile(QString url, QString file_path) {
emit newDownloadedTorrent(file_path, url); emit newDownloadedTorrent(file_path, url);
} else { } else {
url_skippingDlg.removeAt(index); url_skippingDlg.removeAt(index);
QTorrentHandle h = addTorrent(file_path, false, url, false); addTorrent(file_path, false, url, false);
// Pause torrent if necessary
if (h.is_valid() && pref->addTorrentsInPause() && pref->useAdditionDialog())
h.pause();
emit newDownloadedTorrentFromRss(url); emit newDownloadedTorrentFromRss(url);
} }
} }
@ -3093,6 +3097,11 @@ void QBtSession::unhideMagnet(const QString &hash) {
return; return;
} }
bool add_paused = pref->addTorrentsInPause();
if (TorrentTempData::hasTempData(hash)) {
add_paused = TorrentTempData::isAddPaused(hash);
}
if (!h.has_metadata()) { if (!h.has_metadata()) {
if (pref->isQueueingSystemEnabled()) { if (pref->isQueueingSystemEnabled()) {
//Internally decrease the queue limits to ensure that other queued items aren't started //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; sessionSettings.active_limit = max_active;
s->set_settings(sessionSettings); s->set_settings(sessionSettings);
} }
if (pref->addTorrentsInPause()) if (add_paused)
h.pause(); h.pause();
} }
h.queue_position_bottom(); h.queue_position_bottom();
loadTorrentTempData(h, h.save_path(), !h.has_metadata()); //TempData are deleted by a call to TorrentPersistentData::saveTorrentPersistentData() 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.resume();
h.move_storage(save_path); h.move_storage(save_path);

8
src/torrentpersistentdata.cpp

@ -160,6 +160,14 @@ QString TorrentTempData::getQueuedPath(const QString &hash) {
return i->queuedPath; 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) { void HiddenData::addData(const QString &hash) {
data[hash] = false; data[hash] = false;
} }

6
src/torrentpersistentdata.h

@ -34,6 +34,7 @@
#include <QHash> #include <QHash>
#include <QStringList> #include <QStringList>
#include <vector> #include <vector>
#include "preferences.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDateTime; class QDateTime;
@ -65,16 +66,19 @@ public:
static QString getOldPath(const QString &hash); static QString getOldPath(const QString &hash);
static QString getNewPath(const QString &hash); static QString getNewPath(const QString &hash);
static QString getQueuedPath(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: private:
struct TorrentData { struct TorrentData {
TorrentData(): sequential(false), seed(false) {} TorrentData(): sequential(false), seed(false), add_paused(Preferences::instance()->addTorrentsInPause()) {}
std::vector<int> files_priority; std::vector<int> files_priority;
QStringList path_list; QStringList path_list;
QString save_path; QString save_path;
QString label; QString label;
bool sequential; bool sequential;
bool seed; bool seed;
bool add_paused;
}; };
struct TorrentMoveState { struct TorrentMoveState {

Loading…
Cancel
Save