From 132b1f7ffebc9b6ad667be28c6bb4b8d371205ae Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 30 Dec 2009 16:18:50 +0000 Subject: [PATCH] - Use global maximum transfer rates as maximum values in per-torrent speed limiting dialogs --- src/speedlimitdlg.h | 11 ++++++++++- src/transferlistwidget.cpp | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/speedlimitdlg.h b/src/speedlimitdlg.h index 8c21be7c1..395836c41 100644 --- a/src/speedlimitdlg.h +++ b/src/speedlimitdlg.h @@ -57,9 +57,10 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg { } // -2: if cancel - static long askSpeedLimit(bool *ok, QString title, long default_value) { + static long askSpeedLimit(bool *ok, QString title, long default_value, long max_value=1024000) { SpeedLimitDialog dlg; dlg.setWindowTitle(title); + dlg.setMaxValue(max_value/1024.); dlg.setDefaultValue(default_value/1024.); if(dlg.exec() == QDialog::Accepted) { *ok = true; @@ -102,8 +103,16 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg { return -1; } + void setMaxValue(long val) const { + if(val > 0) { + bandwidthSlider->setMaximum(val); + spinBandwidth->setMaximum(val); + } + } + void setDefaultValue(long val) const { if(val < 0) val = 0; + if(val > bandwidthSlider->maximum()) val = bandwidthSlider->maximum(); bandwidthSlider->setValue(val); updateSpinValue(val); } diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index a3978bd4f..5b711f916 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -36,6 +36,7 @@ #include "speedlimitdlg.h" #include "options_imp.h" #include "GUI.h" +#include "preferences.h" #include "deletionconfirmationdlg.h" #include #include @@ -700,7 +701,7 @@ void TransferListWidget::setDlLimitSelectedTorrents() { int default_limit = -1; if(all_same_limit) default_limit = selected_torrents.first().download_limit(); - long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit); + long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences::getGlobalDownloadLimit()*1024.); if(ok) { foreach(QTorrentHandle h, selected_torrents) { qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data()); @@ -736,7 +737,7 @@ void TransferListWidget::setUpLimitSelectedTorrents() { int default_limit = -1; if(all_same_limit) default_limit = selected_torrents.first().upload_limit(); - long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit); + long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences::getGlobalUploadLimit()*1024.); if(ok) { foreach(QTorrentHandle h, selected_torrents) { qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());