From 4252832ba574cb4e708b3e56f1c396f2c5c8f812 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 22 Dec 2009 17:39:12 +0000 Subject: [PATCH] - Fix issue with speed limiting (Infinite value was not handled properly) - Improved bandwith limiting dialog by adding a SpinBox so that the user can input the value manually --- src/speedlimitdlg.h | 30 +++++++++++++++++++++++------- src/statusbar.h | 22 ++++++++++++++-------- src/ui/bandwidth_limit.ui | 30 ++++++++---------------------- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/speedlimitdlg.h b/src/speedlimitdlg.h index a6a18dd9c..8c21be7c1 100644 --- a/src/speedlimitdlg.h +++ b/src/speedlimitdlg.h @@ -48,7 +48,8 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg { setupUi(this); qDebug("Bandwidth allocation dialog creation"); // Connect to slots - connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBandwidthLabel(int))); + connect(bandwidthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateSpinValue(int))); + connect(spinBandwidth, SIGNAL(valueChanged(int)), this, SLOT(updateSliderValue(int))); } ~SpeedLimitDialog(){ @@ -62,7 +63,10 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg { dlg.setDefaultValue(default_value/1024.); if(dlg.exec() == QDialog::Accepted) { *ok = true; - return dlg.getSpeedLimit()*1024; + int val = dlg.getSpeedLimit(); + if(val <= 0) + return -1; + return val*1024; } else { *ok = false; return -2; @@ -70,16 +74,27 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg { } protected slots: - void updateBandwidthLabel(int val){ + void updateSpinValue(int val) const { + qDebug("Called updateSpinValue with %d", val); if(val <= 0){ - limit_lbl->setText(QString::fromUtf8("∞")); - kb_lbl->setText(QString::fromUtf8("")); + spinBandwidth->setValue(0); + spinBandwidth->setSpecialValueText(QString::fromUtf8("∞")); + spinBandwidth->setSuffix(QString::fromUtf8("")); }else{ - limit_lbl->setText(misc::toQString(val)); - kb_lbl->setText(tr("KiB/s")); + spinBandwidth->setValue(val); + spinBandwidth->setSuffix(" "+tr("KiB/s")); } } + void updateSliderValue(int val) const { + if(val <= 0) { + spinBandwidth->setValue(0); + spinBandwidth->setSpecialValueText(QString::fromUtf8("∞")); + spinBandwidth->setSuffix(QString::fromUtf8("")); + } + bandwidthSlider->setValue(val); + } + long getSpeedLimit() const { long val = bandwidthSlider->value(); if(val > 0) @@ -90,6 +105,7 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg { void setDefaultValue(long val) const { if(val < 0) val = 0; bandwidthSlider->setValue(val); + updateSpinValue(val); } }; diff --git a/src/statusbar.h b/src/statusbar.h index 04b91b6e0..0eaf2b713 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -168,12 +168,15 @@ public slots: bool ok = false; long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit()); if(ok) { - qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); - BTSession->getSession()->set_download_rate_limit(new_limit); - if(new_limit <= 0) + if(new_limit <= 0) { + qDebug("Setting global download rate limit to Unlimited"); + BTSession->getSession()->set_download_rate_limit(-1); Preferences::setGlobalDownloadLimit(-1); - else + } else { + qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); + BTSession->getSession()->set_download_rate_limit(new_limit); Preferences::setGlobalDownloadLimit(new_limit/1024.); + } } } @@ -181,12 +184,15 @@ public slots: bool ok = false; long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit()); if(ok) { - qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); - BTSession->getSession()->set_upload_rate_limit(new_limit); - if(new_limit <= 0) + if(new_limit <= 0) { + qDebug("Setting global upload rate limit to Unlimited"); + BTSession->getSession()->set_upload_rate_limit(-1); Preferences::setGlobalUploadLimit(-1); - else + } else { + qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); Preferences::setGlobalUploadLimit(new_limit/1024.); + BTSession->getSession()->set_upload_rate_limit(new_limit); + } } } }; diff --git a/src/ui/bandwidth_limit.ui b/src/ui/bandwidth_limit.ui index d41503cc9..25bf4caed 100644 --- a/src/ui/bandwidth_limit.ui +++ b/src/ui/bandwidth_limit.ui @@ -33,28 +33,17 @@ - - - 6 + + + - + + 10000 + + 0 - - - - - - - - - - - - - - - + @@ -69,9 +58,6 @@ - bandwidthSlider - buttonBox - kb_lbl