Allow bandwidth values up to 65535 KiB/s

The slider has a max value, but it's changed whenever a value greater
than it is specified.

Note: 65535 is the maximum value allowed by libtorrent.

Closes #2373.
This commit is contained in:
Gabriele 2015-01-07 16:53:03 +01:00
parent 737f6c5b4e
commit c5db1157f1
3 changed files with 15 additions and 16 deletions

View file

@ -38,7 +38,7 @@
<string/> <string/>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>10000</number> <number>65535</number>
</property> </property>
<property name="value"> <property name="value">
<number>0</number> <number>0</number>

View file

@ -50,8 +50,7 @@ long SpeedLimitDialog::askSpeedLimit(bool *ok, QString title, long default_value
{ {
SpeedLimitDialog dlg; SpeedLimitDialog dlg;
dlg.setWindowTitle(title); dlg.setWindowTitle(title);
dlg.setMaxValue(max_value / 1024.); dlg.setupDialog(max_value / 1024., default_value / 1024.);
dlg.setDefaultValue(default_value / 1024.);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
*ok = true; *ok = true;
int val = dlg.getSpeedLimit(); int val = dlg.getSpeedLimit();
@ -86,6 +85,8 @@ void SpeedLimitDialog::updateSliderValue(int val) const
spinBandwidth->setSpecialValueText(QString::fromUtf8("")); spinBandwidth->setSpecialValueText(QString::fromUtf8(""));
spinBandwidth->setSuffix(QString::fromUtf8("")); spinBandwidth->setSuffix(QString::fromUtf8(""));
} }
if (val > bandwidthSlider->maximum())
bandwidthSlider->setMaximum(val);
bandwidthSlider->setValue(val); bandwidthSlider->setValue(val);
} }
@ -97,18 +98,17 @@ long SpeedLimitDialog::getSpeedLimit() const
return -1; return -1;
} }
void SpeedLimitDialog::setMaxValue(long val) const void SpeedLimitDialog::setupDialog(long max_slider, long val) const
{ {
if (val > 0) { if (val < 0)
bandwidthSlider->setMaximum(val); val = 0;
spinBandwidth->setMaximum(val); if (max_slider < 0)
} max_slider = 1000;
} // This can happen for example if global rate limit is lower
// than torrent rate limit.
void SpeedLimitDialog::setDefaultValue(long val) const if (val > max_slider)
{ max_slider = val;
if (val < 0) val = 0; bandwidthSlider->setMaximum(max_slider);
if (val > bandwidthSlider->maximum()) val = bandwidthSlider->maximum();
bandwidthSlider->setValue(val); bandwidthSlider->setValue(val);
updateSpinValue(val); updateSpinValue(val);
} }

View file

@ -48,8 +48,7 @@ protected slots:
void updateSpinValue(int val) const; void updateSpinValue(int val) const;
void updateSliderValue(int val) const; void updateSliderValue(int val) const;
long getSpeedLimit() const; long getSpeedLimit() const;
void setMaxValue(long val) const; void setupDialog(long max_slider, long val) const;
void setDefaultValue(long val) const;
}; };
#endif #endif