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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
};

22
src/statusbar.h

@ -168,12 +168,15 @@ public slots: @@ -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: @@ -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);
}
}
}
};

30
src/ui/bandwidth_limit.ui

@ -33,28 +33,17 @@ @@ -33,28 +33,17 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
<widget class="QSpinBox" name="spinBandwidth">
<property name="suffix">
<string/>
</property>
<property name="margin">
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>0</number>
</property>
<item>
<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>
</widget>
</item>
</layout>
</item>
@ -69,9 +58,6 @@ @@ -69,9 +58,6 @@
</widget>
</item>
</layout>
<zorder>bandwidthSlider</zorder>
<zorder>buttonBox</zorder>
<zorder>kb_lbl</zorder>
</widget>
<resources/>
<connections>

Loading…
Cancel
Save