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. 20
      src/statusbar.h
  3. 28
      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,14 +74,25 @@ 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 {
@ -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);
} }
}; };

20
src/statusbar.h

@ -168,25 +168,31 @@ 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) {
if(new_limit <= 0) {
qDebug("Setting global download rate limit to Unlimited");
BTSession->getSession()->set_download_rate_limit(-1);
Preferences::setGlobalDownloadLimit(-1);
} else {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
BTSession->getSession()->set_download_rate_limit(new_limit); BTSession->getSession()->set_download_rate_limit(new_limit);
if(new_limit <= 0)
Preferences::setGlobalDownloadLimit(-1);
else
Preferences::setGlobalDownloadLimit(new_limit/1024.); Preferences::setGlobalDownloadLimit(new_limit/1024.);
} }
} }
}
void capUploadSpeed() { void capUploadSpeed() {
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);
}
} }
} }
}; };

28
src/ui/bandwidth_limit.ui

@ -33,31 +33,20 @@
</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 name="margin">
<number>0</number>
</property> </property>
<item> <property name="maximum">
<widget class="QLabel" name="limit_lbl"> <number>10000</number>
<property name="text">
<string notr="true">∞</string>
</property> </property>
</widget> <property name="value">
</item> <number>0</number>
<item>
<widget class="QLabel" name="kb_lbl">
<property name="text">
<string/>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
@ -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