Browse Source

- 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
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
4252832ba5
  1. 30
      src/speedlimitdlg.h
  2. 22
      src/statusbar.h
  3. 30
      src/ui/bandwidth_limit.ui

30
src/speedlimitdlg.h

@ -48,7 +48,8 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg {
setupUi(this); setupUi(this);
qDebug("Bandwidth allocation dialog creation"); qDebug("Bandwidth allocation dialog creation");
// Connect to slots // 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(){ ~SpeedLimitDialog(){
@ -62,7 +63,10 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg {
dlg.setDefaultValue(default_value/1024.); dlg.setDefaultValue(default_value/1024.);
if(dlg.exec() == QDialog::Accepted) { if(dlg.exec() == QDialog::Accepted) {
*ok = true; *ok = true;
return dlg.getSpeedLimit()*1024; int val = dlg.getSpeedLimit();
if(val <= 0)
return -1;
return val*1024;
} else { } else {
*ok = false; *ok = false;
return -2; return -2;
@ -70,16 +74,27 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg {
} }
protected slots: protected slots:
void updateBandwidthLabel(int val){ void updateSpinValue(int val) const {
qDebug("Called updateSpinValue with %d", val);
if(val <= 0){ if(val <= 0){
limit_lbl->setText(QString::fromUtf8("")); spinBandwidth->setValue(0);
kb_lbl->setText(QString::fromUtf8("")); spinBandwidth->setSpecialValueText(QString::fromUtf8(""));
spinBandwidth->setSuffix(QString::fromUtf8(""));
}else{ }else{
limit_lbl->setText(misc::toQString(val)); spinBandwidth->setValue(val);
kb_lbl->setText(tr("KiB/s")); 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 getSpeedLimit() const {
long val = bandwidthSlider->value(); long val = bandwidthSlider->value();
if(val > 0) if(val > 0)
@ -90,6 +105,7 @@ class SpeedLimitDialog : public QDialog, private Ui_bandwidth_dlg {
void setDefaultValue(long val) const { void setDefaultValue(long val) const {
if(val < 0) val = 0; if(val < 0) val = 0;
bandwidthSlider->setValue(val); bandwidthSlider->setValue(val);
updateSpinValue(val);
} }
}; };

22
src/statusbar.h

@ -168,12 +168,15 @@ public slots:
bool ok = false; bool ok = false;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit()); long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), BTSession->getSession()->download_rate_limit());
if(ok) { if(ok) {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); if(new_limit <= 0) {
BTSession->getSession()->set_download_rate_limit(new_limit); qDebug("Setting global download rate limit to Unlimited");
if(new_limit <= 0) BTSession->getSession()->set_download_rate_limit(-1);
Preferences::setGlobalDownloadLimit(-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.); Preferences::setGlobalDownloadLimit(new_limit/1024.);
}
} }
} }
@ -181,12 +184,15 @@ public slots:
bool ok = false; bool ok = false;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit()); long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), BTSession->getSession()->upload_rate_limit());
if(ok) { if(ok) {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); if(new_limit <= 0) {
BTSession->getSession()->set_upload_rate_limit(new_limit); qDebug("Setting global upload rate limit to Unlimited");
if(new_limit <= 0) BTSession->getSession()->set_upload_rate_limit(-1);
Preferences::setGlobalUploadLimit(-1); Preferences::setGlobalUploadLimit(-1);
else } else {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
Preferences::setGlobalUploadLimit(new_limit/1024.); Preferences::setGlobalUploadLimit(new_limit/1024.);
BTSession->getSession()->set_upload_rate_limit(new_limit);
}
} }
} }
}; };

30
src/ui/bandwidth_limit.ui

@ -33,28 +33,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <widget class="QSpinBox" name="spinBandwidth">
<property name="spacing"> <property name="suffix">
<number>6</number> <string/>
</property> </property>
<property name="margin"> <property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>0</number> <number>0</number>
</property> </property>
<item> </widget>
<widget class="QLabel" name="limit_lbl">
<property name="text">
<string notr="true">∞</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="kb_lbl">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
@ -69,9 +58,6 @@
</widget> </widget>
</item> </item>
</layout> </layout>
<zorder>bandwidthSlider</zorder>
<zorder>buttonBox</zorder>
<zorder>kb_lbl</zorder>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>

Loading…
Cancel
Save