From 9c7bb08a034720b6d557ad341c99845035714765 Mon Sep 17 00:00:00 2001 From: ngosang Date: Tue, 30 Jun 2015 20:03:17 +0200 Subject: [PATCH] Automatically add trackers to new downloads. --- src/core/bittorrent/session.cpp | 14 ++++++++++++++ src/core/bittorrent/session.h | 1 + src/core/preferences.cpp | 20 ++++++++++++++++++++ src/core/preferences.h | 4 ++++ src/gui/options.ui | 31 +++++++++++++++++++++++++++++++ src/gui/options_imp.cpp | 6 ++++++ 6 files changed, 76 insertions(+) diff --git a/src/core/bittorrent/session.cpp b/src/core/bittorrent/session.cpp index e0458dc14..e3a2b7cef 100644 --- a/src/core/bittorrent/session.cpp +++ b/src/core/bittorrent/session.cpp @@ -1,3 +1,4 @@ + /* * Bittorrent Client using Qt and libtorrent. * Copyright (C) 2015 Vladimir Golovnev @@ -620,6 +621,16 @@ void Session::configure() qDebug("Applying encryption settings"); m_nativeSession->set_pe_settings(encryptionSettings); + // * Add trackers + m_additionalTrackers.empty(); + if (pref->isAddTrackersEnabled()) { + foreach (QString tracker, pref->getTrackersList().split("\n")) { + tracker = tracker.trimmed(); + if (!tracker.isEmpty()) + m_additionalTrackers << tracker; + } + } + // * Maximum ratio m_highRatioAction = pref->getMaxRatioAction(); setGlobalMaxRatio(pref->getGlobalMaxRatio()); @@ -2111,6 +2122,9 @@ void Session::handleAddTorrentAlert(libtorrent::add_torrent_alert *p) } } + if (pref->isAddTrackersEnabled() && !torrent->isPrivate()) + torrent->addTrackers(m_additionalTrackers); + bool addPaused = data.addPaused; if (data.addPaused == TriStateBool::Undefined) addPaused = pref->addTorrentsInPause(); diff --git a/src/core/bittorrent/session.h b/src/core/bittorrent/session.h index 78420e74e..1b5da0b39 100644 --- a/src/core/bittorrent/session.h +++ b/src/core/bittorrent/session.h @@ -330,6 +330,7 @@ namespace BitTorrent bool m_appendExtension; uint m_refreshInterval; MaxRatioAction m_highRatioAction; + QList m_additionalTrackers; QString m_defaultSavePath; QString m_tempPath; QString m_filterPath; diff --git a/src/core/preferences.cpp b/src/core/preferences.cpp index 1e02aa5a8..130ea4538 100644 --- a/src/core/preferences.cpp +++ b/src/core/preferences.cpp @@ -962,6 +962,26 @@ void Preferences::setEncryptionSetting(int val) setValue("Preferences/Bittorrent/Encryption", val); } +bool Preferences::isAddTrackersEnabled() const +{ + return value("Preferences/Bittorrent/AddTrackers", false).toBool(); +} + +void Preferences::setAddTrackersEnabled(bool enabled) +{ + setValue("Preferences/Bittorrent/AddTrackers", enabled); +} + +QString Preferences::getTrackersList() const +{ + return value("Preferences/Bittorrent/TrackersList").toString(); +} + +void Preferences::setTrackersList(const QString &val) +{ + setValue("Preferences/Bittorrent/TrackersList", val); +} + qreal Preferences::getGlobalMaxRatio() const { return value("Preferences/Bittorrent/MaxRatio", -1).toDouble(); diff --git a/src/core/preferences.h b/src/core/preferences.h index 1ff708344..52a835c09 100644 --- a/src/core/preferences.h +++ b/src/core/preferences.h @@ -270,6 +270,10 @@ public: void setLSDEnabled(bool enabled); int getEncryptionSetting() const; void setEncryptionSetting(int val); + bool isAddTrackersEnabled() const; + void setAddTrackersEnabled(bool enabled); + QString getTrackersList() const; + void setTrackersList(const QString &val); qreal getGlobalMaxRatio() const; void setGlobalMaxRatio(qreal ratio); MaxRatioAction getMaxRatioAction() const; diff --git a/src/gui/options.ui b/src/gui/options.ui index 64b24e3c8..a6758e12c 100644 --- a/src/gui/options.ui +++ b/src/gui/options.ui @@ -2273,6 +2273,37 @@ + + + + + 0 + 0 + + + + Automatically add these trackers to new downloads: + + + true + + + false + + + + + + true + + + Qt::StrongFocus + + + + + + diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index baabdc8fe..0a5f750c9 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -249,6 +249,8 @@ options_imp::options_imp(QWidget *parent) connect(spinMaxActiveUploads, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxActiveTorrents, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkIgnoreSlowTorrentsForQueueing, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); + connect(checkEnableAddTrackers, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); + connect(textTrackers, SIGNAL(textChanged()), this, SLOT(enableApplyButton())); #ifndef DISABLE_WEBUI // Web UI tab connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); @@ -468,6 +470,8 @@ void options_imp::saveOptions() pref->setLSDEnabled(isLSDEnabled()); pref->setEncryptionSetting(getEncryptionSetting()); pref->enableAnonymousMode(checkAnonymousMode->isChecked()); + pref->setAddTrackersEnabled(checkEnableAddTrackers->isChecked()); + pref->setTrackersList(textTrackers->toPlainText()); pref->setGlobalMaxRatio(getMaxRatio()); pref->setMaxRatioAction(comboRatioLimitAct->currentIndex()); // End Bittorrent preferences @@ -783,6 +787,8 @@ void options_imp::loadOptions() checkLSD->setChecked(pref->isLSDEnabled()); comboEncryption->setCurrentIndex(pref->getEncryptionSetting()); checkAnonymousMode->setChecked(pref->isAnonymousModeEnabled()); + checkEnableAddTrackers->setChecked(pref->isAddTrackersEnabled()); + textTrackers->setPlainText(pref->getTrackersList()); checkEnableQueueing->setChecked(pref->isQueueingSystemEnabled()); spinMaxActiveDownloads->setValue(pref->getMaxActiveDownloads());