From e178e700533fd11ad6521a009c329cb1fdd5c3ce Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 30 Dec 2016 13:34:10 +0800 Subject: [PATCH 1/3] Code rewrite, no behavior change --- src/gui/transferlistwidget.cpp | 79 +++++++++++++++------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index ae193f55c..871d294e0 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -428,65 +428,56 @@ void TransferListWidget::previewSelectedTorrents() void TransferListWidget::setDlLimitSelectedTorrents() { - QList selected_torrents; - bool first = true; - bool all_same_limit = true; + QList TorrentsList; foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { - if (!torrent->isSeed()) { - selected_torrents << torrent; - // Determine current limit for selected torrents - if (first) - first = false; - else if (all_same_limit && (torrent->downloadLimit() != selected_torrents.first()->downloadLimit())) - all_same_limit = false; + if (torrent->isSeed()) + continue; + TorrentsList += torrent; + } + if (TorrentsList.empty()) return; + + int oldLimit = TorrentsList.first()->downloadLimit(); + foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) { + if (torrent->downloadLimit() != oldLimit) { + oldLimit = -1; + break; } } - if (selected_torrents.empty()) return; - bool ok = false; - int default_limit = -1; - if (all_same_limit) - default_limit = selected_torrents.first()->downloadLimit(); - const long new_limit = SpeedLimitDialog::askSpeedLimit( - &ok, tr("Torrent Download Speed Limiting"), default_limit + const long newLimit = SpeedLimitDialog::askSpeedLimit( + &ok, tr("Torrent Download Speed Limiting"), oldLimit , BitTorrent::Session::instance()->globalDownloadSpeedLimit()); - if (ok) { - foreach (BitTorrent::TorrentHandle *const torrent, selected_torrents) { - qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit / 1024.), qPrintable(torrent->hash())); - torrent->setDownloadLimit(new_limit); - } + if (!ok) return; + + foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) { + qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long) (newLimit / 1024.), qPrintable(torrent->hash())); + torrent->setDownloadLimit(newLimit); } } void TransferListWidget::setUpLimitSelectedTorrents() { - QList selected_torrents; - bool first = true; - bool all_same_limit = true; - foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { - selected_torrents << torrent; - // Determine current limit for selected torrents - if (first) - first = false; - else if (all_same_limit && (torrent->uploadLimit() != selected_torrents.first()->uploadLimit())) - all_same_limit = false; + QList TorrentsList = getSelectedTorrents(); + if (TorrentsList.empty()) return; + + int oldLimit = TorrentsList.first()->uploadLimit(); + foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) { + if (torrent->uploadLimit() != oldLimit) { + oldLimit = -1; + break; + } } - if (selected_torrents.empty()) return; - bool ok = false; - int default_limit = -1; - if (all_same_limit) - default_limit = selected_torrents.first()->uploadLimit(); - const long new_limit = SpeedLimitDialog::askSpeedLimit( - &ok, tr("Torrent Upload Speed Limiting"), default_limit + const long newLimit = SpeedLimitDialog::askSpeedLimit( + &ok, tr("Torrent Upload Speed Limiting"), oldLimit , BitTorrent::Session::instance()->globalUploadSpeedLimit()); - if (ok) { - foreach (BitTorrent::TorrentHandle *const torrent, selected_torrents) { - qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit / 1024.), qPrintable(torrent->hash())); - torrent->setUploadLimit(new_limit); - } + if (!ok) return; + + foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) { + qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long) (newLimit / 1024.), qPrintable(torrent->hash())); + torrent->setUploadLimit(newLimit); } } From 14a39ba3c34eafa9dfed33127d1d9e033a7ffb2e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 30 Dec 2016 13:39:26 +0800 Subject: [PATCH 2/3] Speedlimitdlg: raise slider default value to 10000. Closes #6150. Old value 1000 (KB/s) can be a bit small for modern internet. --- src/gui/speedlimitdlg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/speedlimitdlg.cpp b/src/gui/speedlimitdlg.cpp index d90cc1534..25c780cae 100644 --- a/src/gui/speedlimitdlg.cpp +++ b/src/gui/speedlimitdlg.cpp @@ -104,7 +104,7 @@ void SpeedLimitDialog::setupDialog(long max_slider, long val) const if (val < 0) val = 0; if (max_slider <= 0) - max_slider = 1000; + max_slider = 10000; // This can happen for example if global rate limit is lower // than torrent rate limit. if (val > max_slider) From d52a74092b07bce598cfa857f4c824b3fa54be9e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 19 Jan 2017 23:42:12 +0800 Subject: [PATCH 3/3] Reset values to default, these are controled elsewhere. --- src/gui/bandwidth_limit.ui | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/gui/bandwidth_limit.ui b/src/gui/bandwidth_limit.ui index de114a61f..6fd700bef 100644 --- a/src/gui/bandwidth_limit.ui +++ b/src/gui/bandwidth_limit.ui @@ -18,15 +18,6 @@ - - 0 - - - 1000 - - - 0 - Qt::Horizontal