mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Merge pull request #3483 from glassez/bandwidth
Fix Bandwidth Scheduler. Closes #3376.
This commit is contained in:
commit
675298bc73
@ -555,7 +555,7 @@ void Session::configure()
|
|||||||
if (pref->isSchedulerEnabled()) {
|
if (pref->isSchedulerEnabled()) {
|
||||||
if (!m_bwScheduler) {
|
if (!m_bwScheduler) {
|
||||||
m_bwScheduler = new BandwidthScheduler(this);
|
m_bwScheduler = new BandwidthScheduler(this);
|
||||||
connect(m_bwScheduler, SIGNAL(switchToAlternativeMode(bool)), this, SLOT(changeSpeedLimitMode(bool)));
|
connect(m_bwScheduler.data(), SIGNAL(switchToAlternativeMode(bool)), this, SLOT(switchToAlternativeMode(bool)));
|
||||||
}
|
}
|
||||||
m_bwScheduler->start();
|
m_bwScheduler->start();
|
||||||
}
|
}
|
||||||
@ -747,6 +747,11 @@ void Session::handleRedirectedToMagnet(const QString &url, const QString &magnet
|
|||||||
addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(magnetUri));
|
addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(magnetUri));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::switchToAlternativeMode(bool alternative)
|
||||||
|
{
|
||||||
|
changeSpeedLimitMode_impl(alternative);
|
||||||
|
}
|
||||||
|
|
||||||
// Add to BitTorrent session the downloaded torrent file
|
// Add to BitTorrent session the downloaded torrent file
|
||||||
void Session::handleDownloadFinished(const QString &url, const QString &filePath)
|
void Session::handleDownloadFinished(const QString &url, const QString &filePath)
|
||||||
{
|
{
|
||||||
@ -757,32 +762,14 @@ void Session::handleDownloadFinished(const QString &url, const QString &filePath
|
|||||||
|
|
||||||
void Session::changeSpeedLimitMode(bool alternative)
|
void Session::changeSpeedLimitMode(bool alternative)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << alternative;
|
|
||||||
// Save new state to remember it on startup
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
// Stop the scheduler when the user has manually changed the bandwidth mode
|
// Stop the scheduler when the user has manually changed the bandwidth mode
|
||||||
if (!pref->isSchedulerEnabled())
|
if (pref->isSchedulerEnabled()) {
|
||||||
|
pref->setSchedulerEnabled(false);
|
||||||
delete m_bwScheduler;
|
delete m_bwScheduler;
|
||||||
pref->setAltBandwidthEnabled(alternative);
|
}
|
||||||
|
|
||||||
// Apply settings to the bittorrent session
|
changeSpeedLimitMode_impl(alternative);
|
||||||
int downLimit = alternative ? pref->getAltGlobalDownloadLimit() : pref->getGlobalDownloadLimit();
|
|
||||||
if (downLimit <= 0)
|
|
||||||
downLimit = -1;
|
|
||||||
else
|
|
||||||
downLimit *= 1024;
|
|
||||||
setDownloadRateLimit(downLimit);
|
|
||||||
|
|
||||||
// Upload rate
|
|
||||||
int upLimit = alternative ? pref->getAltGlobalUploadLimit() : pref->getGlobalUploadLimit();
|
|
||||||
if (upLimit <= 0)
|
|
||||||
upLimit = -1;
|
|
||||||
else
|
|
||||||
upLimit *= 1024;
|
|
||||||
setUploadRateLimit(upLimit);
|
|
||||||
|
|
||||||
// Notify
|
|
||||||
emit speedLimitModeChanged(alternative);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the torrent handle, given its hash
|
// Return the torrent handle, given its hash
|
||||||
@ -1346,6 +1333,34 @@ void Session::enableDHT(bool enable)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::changeSpeedLimitMode_impl(bool alternative)
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << alternative;
|
||||||
|
Preferences* const pref = Preferences::instance();
|
||||||
|
|
||||||
|
// Save new state to remember it on startup
|
||||||
|
pref->setAltBandwidthEnabled(alternative);
|
||||||
|
|
||||||
|
// Apply settings to the bittorrent session
|
||||||
|
int downLimit = alternative ? pref->getAltGlobalDownloadLimit() : pref->getGlobalDownloadLimit();
|
||||||
|
if (downLimit <= 0)
|
||||||
|
downLimit = -1;
|
||||||
|
else
|
||||||
|
downLimit *= 1024;
|
||||||
|
setDownloadRateLimit(downLimit);
|
||||||
|
|
||||||
|
// Upload rate
|
||||||
|
int upLimit = alternative ? pref->getAltGlobalUploadLimit() : pref->getGlobalUploadLimit();
|
||||||
|
if (upLimit <= 0)
|
||||||
|
upLimit = -1;
|
||||||
|
else
|
||||||
|
upLimit *= 1024;
|
||||||
|
setUploadRateLimit(upLimit);
|
||||||
|
|
||||||
|
// Notify
|
||||||
|
emit speedLimitModeChanged(alternative);
|
||||||
|
}
|
||||||
|
|
||||||
void Session::generateResumeData(bool final)
|
void Session::generateResumeData(bool final)
|
||||||
{
|
{
|
||||||
foreach (TorrentHandle *const torrent, m_torrents) {
|
foreach (TorrentHandle *const torrent, m_torrents) {
|
||||||
|
@ -225,6 +225,7 @@ namespace BitTorrent
|
|||||||
void handleDownloadFinished(const QString &url, const QString &filePath);
|
void handleDownloadFinished(const QString &url, const QString &filePath);
|
||||||
void handleDownloadFailed(const QString &url, const QString &reason);
|
void handleDownloadFailed(const QString &url, const QString &reason);
|
||||||
void handleRedirectedToMagnet(const QString &url, const QString &magnetUri);
|
void handleRedirectedToMagnet(const QString &url, const QString &magnetUri);
|
||||||
|
void switchToAlternativeMode(bool alternative);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Session(QObject *parent = 0);
|
explicit Session(QObject *parent = 0);
|
||||||
@ -249,6 +250,7 @@ namespace BitTorrent
|
|||||||
void setMaxUploadsPerTorrent(int max);
|
void setMaxUploadsPerTorrent(int max);
|
||||||
void enableLSD(bool enable);
|
void enableLSD(bool enable);
|
||||||
void enableDHT(bool enable);
|
void enableDHT(bool enable);
|
||||||
|
void changeSpeedLimitMode_impl(bool alternative);
|
||||||
|
|
||||||
void setAppendLabelToSavePath(bool append);
|
void setAppendLabelToSavePath(bool append);
|
||||||
void setAppendExtension(bool append);
|
void setAppendExtension(bool append);
|
||||||
|
@ -208,10 +208,8 @@ void StatusBar::updateAltSpeedsBtn(bool alternative) {
|
|||||||
|
|
||||||
void StatusBar::toggleAlternativeSpeeds() {
|
void StatusBar::toggleAlternativeSpeeds() {
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
if (pref->isSchedulerEnabled()) {
|
if (pref->isSchedulerEnabled())
|
||||||
pref->setSchedulerEnabled(false);
|
|
||||||
m_bar->showMessage(tr("Manual change of rate limits mode. The scheduler is disabled."), 5000);
|
m_bar->showMessage(tr("Manual change of rate limits mode. The scheduler is disabled."), 5000);
|
||||||
}
|
|
||||||
BitTorrent::Session::instance()->changeSpeedLimitMode(!pref->isAltBandwidthEnabled());
|
BitTorrent::Session::instance()->changeSpeedLimitMode(!pref->isAltBandwidthEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user