diff --git a/src/core/bittorrent/session.cpp b/src/core/bittorrent/session.cpp index 9624a71bd..af4b9e916 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 @@ -619,6 +620,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()); @@ -2153,6 +2164,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 9e399d4d6..b1ec280ca 100644 --- a/src/core/bittorrent/session.h +++ b/src/core/bittorrent/session.h @@ -339,6 +339,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 4ede40b1c..710f34f0c 100644 --- a/src/core/preferences.cpp +++ b/src/core/preferences.cpp @@ -964,6 +964,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 546abb54d..afea5ad85 100644 --- a/src/core/preferences.h +++ b/src/core/preferences.h @@ -271,6 +271,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 beda4e089..1692b1865 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(static_cast(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());