Merge pull request #3332 from ngosang/addtrackers2

Automatically add trackers to new downloads. Closes #262
This commit is contained in:
sledgehammer999
2015-11-02 10:51:59 -06:00
6 changed files with 76 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
@@ -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();

View File

@@ -339,6 +339,7 @@ namespace BitTorrent
bool m_appendExtension;
uint m_refreshInterval;
MaxRatioAction m_highRatioAction;
QList<BitTorrent::TrackerEntry> m_additionalTrackers;
QString m_defaultSavePath;
QString m_tempPath;
QString m_filterPath;

View File

@@ -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();

View File

@@ -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;