Browse Source

Merge pull request #9799 from Chocobo1/removeCheckbox

Remove speed limit checkbox in Options dialog
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
2ce57b97be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/base/bittorrent/session.cpp
  2. 91
      src/gui/optionsdialog.cpp
  3. 2
      src/gui/optionsdialog.h
  4. 180
      src/gui/optionsdialog.ui
  5. 1
      src/gui/properties/peerlistwidget.cpp
  6. 64
      src/gui/speedlimitdialog.cpp
  7. 15
      src/gui/speedlimitdialog.h
  8. 9
      src/gui/speedlimitdialog.ui
  9. 25
      src/gui/statusbar.cpp
  10. 12
      src/webui/api/appcontroller.cpp
  11. 131
      src/webui/www/private/preferences_content.html

6
src/base/bittorrent/session.cpp

@ -2660,7 +2660,7 @@ int Session::downloadSpeedLimit() const
: globalDownloadSpeedLimit(); : globalDownloadSpeedLimit();
} }
void Session::setDownloadSpeedLimit(int limit) void Session::setDownloadSpeedLimit(const int limit)
{ {
if (isAltGlobalSpeedLimitEnabled()) if (isAltGlobalSpeedLimitEnabled())
setAltGlobalDownloadSpeedLimit(limit); setAltGlobalDownloadSpeedLimit(limit);
@ -2675,7 +2675,7 @@ int Session::uploadSpeedLimit() const
: globalUploadSpeedLimit(); : globalUploadSpeedLimit();
} }
void Session::setUploadSpeedLimit(int limit) void Session::setUploadSpeedLimit(const int limit)
{ {
if (isAltGlobalSpeedLimitEnabled()) if (isAltGlobalSpeedLimitEnabled())
setAltGlobalUploadSpeedLimit(limit); setAltGlobalUploadSpeedLimit(limit);
@ -2688,7 +2688,7 @@ bool Session::isAltGlobalSpeedLimitEnabled() const
return m_isAltGlobalSpeedLimitEnabled; return m_isAltGlobalSpeedLimitEnabled;
} }
void Session::setAltGlobalSpeedLimitEnabled(bool enabled) void Session::setAltGlobalSpeedLimitEnabled(const bool enabled)
{ {
if (enabled == isAltGlobalSpeedLimitEnabled()) return; if (enabled == isAltGlobalSpeedLimitEnabled()) return;

91
src/gui/optionsdialog.cpp

@ -306,10 +306,6 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->spinPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkRandomPort, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkRandomPort, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUploadLimit, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkDownloadLimit, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUploadLimitAlt, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkDownloadLimitAlt, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->spinUploadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinUploadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinUploadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinUploadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
@ -643,15 +639,13 @@ void OptionsDialog::saveOptions()
session->setPort(getPort()); session->setPort(getPort());
session->setUseRandomPort(m_ui->checkRandomPort->isChecked()); session->setUseRandomPort(m_ui->checkRandomPort->isChecked());
Net::PortForwarder::instance()->setEnabled(isUPnPEnabled()); Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
const QPair<int, int> downUpLimit = getGlobalBandwidthLimits(); session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024);
session->setGlobalDownloadSpeedLimit(downUpLimit.first); session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024);
session->setGlobalUploadSpeedLimit(downUpLimit.second); session->setAltGlobalDownloadSpeedLimit(m_ui->spinDownloadLimitAlt->value() * 1024);
session->setAltGlobalUploadSpeedLimit(m_ui->spinUploadLimitAlt->value() * 1024);
session->setUTPRateLimited(m_ui->checkLimituTPConnections->isChecked()); session->setUTPRateLimited(m_ui->checkLimituTPConnections->isChecked());
session->setIncludeOverheadInLimits(m_ui->checkLimitTransportOverhead->isChecked()); session->setIncludeOverheadInLimits(m_ui->checkLimitTransportOverhead->isChecked());
session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked()); session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked());
const QPair<int, int> altDownUpLimit = getAltGlobalBandwidthLimits();
session->setAltGlobalDownloadSpeedLimit(altDownUpLimit.first);
session->setAltGlobalUploadSpeedLimit(altDownUpLimit.second);
pref->setSchedulerStartTime(m_ui->timeEditScheduleFrom->time()); pref->setSchedulerStartTime(m_ui->timeEditScheduleFrom->time());
pref->setSchedulerEndTime(m_ui->timeEditScheduleTo->time()); pref->setSchedulerEndTime(m_ui->timeEditScheduleTo->time());
pref->setSchedulerDays(static_cast<SchedulerDays>(m_ui->comboBoxScheduleDays->currentIndex())); pref->setSchedulerDays(static_cast<SchedulerDays>(m_ui->comboBoxScheduleDays->currentIndex()));
@ -1010,55 +1004,10 @@ void OptionsDialog::loadOptions()
// End Connection preferences // End Connection preferences
// Speed preferences // Speed preferences
intValue = session->globalDownloadSpeedLimit() / 1024; m_ui->spinDownloadLimit->setValue(session->globalDownloadSpeedLimit() / 1024);
if (intValue > 0) { m_ui->spinUploadLimit->setValue(session->globalUploadSpeedLimit() / 1024);
// Enabled m_ui->spinDownloadLimitAlt->setValue(session->altGlobalDownloadSpeedLimit() / 1024);
m_ui->checkDownloadLimit->setChecked(true); m_ui->spinUploadLimitAlt->setValue(session->altGlobalUploadSpeedLimit() / 1024);
m_ui->spinDownloadLimit->setEnabled(true);
m_ui->spinDownloadLimit->setValue(intValue);
}
else {
// Disabled
m_ui->checkDownloadLimit->setChecked(false);
m_ui->spinDownloadLimit->setEnabled(false);
}
intValue = session->globalUploadSpeedLimit() / 1024;
if (intValue > 0) {
// Enabled
m_ui->checkUploadLimit->setChecked(true);
m_ui->spinUploadLimit->setEnabled(true);
m_ui->spinUploadLimit->setValue(intValue);
}
else {
// Disabled
m_ui->checkUploadLimit->setChecked(false);
m_ui->spinUploadLimit->setEnabled(false);
}
intValue = session->altGlobalDownloadSpeedLimit() / 1024;
if (intValue > 0) {
// Enabled
m_ui->checkDownloadLimitAlt->setChecked(true);
m_ui->spinDownloadLimitAlt->setEnabled(true);
m_ui->spinDownloadLimitAlt->setValue(intValue);
}
else {
// Disabled
m_ui->checkDownloadLimitAlt->setChecked(false);
m_ui->spinDownloadLimitAlt->setEnabled(false);
}
intValue = session->altGlobalUploadSpeedLimit() / 1024;
if (intValue > 0) {
// Enabled
m_ui->checkUploadLimitAlt->setChecked(true);
m_ui->spinUploadLimitAlt->setEnabled(true);
m_ui->spinUploadLimitAlt->setValue(intValue);
}
else {
// Disabled
m_ui->checkUploadLimitAlt->setChecked(false);
m_ui->spinUploadLimitAlt->setEnabled(false);
}
m_ui->checkLimituTPConnections->setChecked(session->isUTPRateLimited()); m_ui->checkLimituTPConnections->setChecked(session->isUTPRateLimited());
m_ui->checkLimitTransportOverhead->setChecked(session->includeOverheadInLimits()); m_ui->checkLimitTransportOverhead->setChecked(session->includeOverheadInLimits());
@ -1198,30 +1147,6 @@ bool OptionsDialog::isUPnPEnabled() const
return m_ui->checkUPnP->isChecked(); return m_ui->checkUPnP->isChecked();
} }
// Return Download & Upload limits in kbps
// [download,upload]
QPair<int, int> OptionsDialog::getGlobalBandwidthLimits() const
{
int DL = 0, UP = 0;
if (m_ui->checkDownloadLimit->isChecked())
DL = m_ui->spinDownloadLimit->value() * 1024;
if (m_ui->checkUploadLimit->isChecked())
UP = m_ui->spinUploadLimit->value() * 1024;
return qMakePair(DL, UP);
}
// Return alternate Download & Upload limits in kbps
// [download,upload]
QPair<int, int> OptionsDialog::getAltGlobalBandwidthLimits() const
{
int DL = 0, UP = 0;
if (m_ui->checkDownloadLimitAlt->isChecked())
DL = m_ui->spinDownloadLimitAlt->value() * 1024;
if (m_ui->checkUploadLimitAlt->isChecked())
UP = m_ui->spinUploadLimitAlt->value() * 1024;
return qMakePair(DL, UP);
}
bool OptionsDialog::startMinimized() const bool OptionsDialog::startMinimized() const
{ {
return m_ui->checkStartMinimized->isChecked(); return m_ui->checkStartMinimized->isChecked();

2
src/gui/optionsdialog.h

@ -137,8 +137,6 @@ private:
// Connection options // Connection options
int getPort() const; int getPort() const;
bool isUPnPEnabled() const; bool isUPnPEnabled() const;
QPair<int, int> getGlobalBandwidthLimits() const;
QPair<int, int> getAltGlobalBandwidthLimits() const;
// Bittorrent options // Bittorrent options
int getMaxConnecs() const; int getMaxConnecs() const;
int getMaxConnecsPerTorrent() const; int getMaxConnecsPerTorrent() const;

180
src/gui/optionsdialog.ui

@ -1812,15 +1812,12 @@
<layout class="QGridLayout" name="rateLimitBoxLayout"> <layout class="QGridLayout" name="rateLimitBoxLayout">
<item row="0" column="2"> <item row="0" column="2">
<widget class="QSpinBox" name="spinUploadLimit"> <widget class="QSpinBox" name="spinUploadLimit">
<property name="enabled"> <property name="specialValueText">
<bool>false</bool> <string>∞</string>
</property> </property>
<property name="suffix"> <property name="suffix">
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>1000000</number>
</property> </property>
@ -1829,24 +1826,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkUploadLimit">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QSpinBox" name="spinDownloadLimit"> <widget class="QSpinBox" name="spinDownloadLimit">
<property name="enabled"> <property name="specialValueText">
<bool>false</bool> <string>∞</string>
</property> </property>
<property name="suffix"> <property name="suffix">
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>1000000</number>
</property> </property>
@ -1858,13 +1845,6 @@
<item row="0" column="0" rowspan="2"> <item row="0" column="0" rowspan="2">
<widget class="QLabel" name="labelGlobalRate"/> <widget class="QLabel" name="labelGlobalRate"/>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkDownloadLimit">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
<item row="0" column="3"> <item row="0" column="3">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -1878,6 +1858,20 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="1">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -1887,6 +1881,22 @@
<string>Alternative Rate Limits</string> <string>Alternative Rate Limits</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="2">
<widget class="QSpinBox" name="spinDownloadLimitAlt">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="2"> <item row="0" column="0" rowspan="2">
<widget class="QLabel" name="labelAltRate"/> <widget class="QLabel" name="labelAltRate"/>
</item> </item>
@ -2001,50 +2011,14 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkUploadLimitAlt">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkDownloadLimitAlt">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QSpinBox" name="spinUploadLimitAlt"> <widget class="QSpinBox" name="spinUploadLimitAlt">
<property name="enabled"> <property name="specialValueText">
<bool>false</bool> <string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinDownloadLimitAlt">
<property name="enabled">
<bool>false</bool>
</property> </property>
<property name="suffix"> <property name="suffix">
<string> KiB/s</string> <string> KiB/s</string>
</property> </property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum"> <property name="maximum">
<number>1000000</number> <number>1000000</number>
</property> </property>
@ -2066,6 +2040,20 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="1">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Upload:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Download:</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -3432,15 +3420,11 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<tabstop>checkIpFilterTrackers</tabstop> <tabstop>checkIpFilterTrackers</tabstop>
<tabstop>scrollArea_9</tabstop> <tabstop>scrollArea_9</tabstop>
<tabstop>spinUploadLimit</tabstop> <tabstop>spinUploadLimit</tabstop>
<tabstop>checkUploadLimit</tabstop>
<tabstop>spinDownloadLimit</tabstop> <tabstop>spinDownloadLimit</tabstop>
<tabstop>checkDownloadLimit</tabstop>
<tabstop>groupBoxSchedule</tabstop> <tabstop>groupBoxSchedule</tabstop>
<tabstop>timeEditScheduleTo</tabstop> <tabstop>timeEditScheduleTo</tabstop>
<tabstop>timeEditScheduleFrom</tabstop> <tabstop>timeEditScheduleFrom</tabstop>
<tabstop>comboBoxScheduleDays</tabstop> <tabstop>comboBoxScheduleDays</tabstop>
<tabstop>checkUploadLimitAlt</tabstop>
<tabstop>checkDownloadLimitAlt</tabstop>
<tabstop>spinUploadLimitAlt</tabstop> <tabstop>spinUploadLimitAlt</tabstop>
<tabstop>spinDownloadLimitAlt</tabstop> <tabstop>spinDownloadLimitAlt</tabstop>
<tabstop>checkLimitLocalPeerRate</tabstop> <tabstop>checkLimitLocalPeerRate</tabstop>
@ -3476,38 +3460,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>checkUploadLimit</sender>
<signal>toggled(bool)</signal>
<receiver>spinUploadLimit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>367</x>
<y>61</y>
</hint>
<hint type="destinationlabel">
<x>448</x>
<y>62</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkDownloadLimit</sender>
<signal>toggled(bool)</signal>
<receiver>spinDownloadLimit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>377</x>
<y>81</y>
</hint>
<hint type="destinationlabel">
<x>430</x>
<y>87</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>checkMaxConnecs</sender> <sender>checkMaxConnecs</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
@ -3572,38 +3524,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>checkDownloadLimitAlt</sender>
<signal>toggled(bool)</signal>
<receiver>spinDownloadLimitAlt</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>547</x>
<y>415</y>
</hint>
<hint type="destinationlabel">
<x>815</x>
<y>413</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkUploadLimitAlt</sender>
<signal>toggled(bool)</signal>
<receiver>spinUploadLimitAlt</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>604</x>
<y>271</y>
</hint>
<hint type="destinationlabel">
<x>677</x>
<y>272</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>checkMaxRatio</sender> <sender>checkMaxRatio</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>

1
src/gui/properties/peerlistwidget.cpp

@ -40,6 +40,7 @@
#include <QWheelEvent> #include <QWheelEvent>
#include "base/bittorrent/peerinfo.h" #include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/net/geoipmanager.h" #include "base/net/geoipmanager.h"

64
src/gui/speedlimitdialog.cpp

@ -28,16 +28,14 @@
#include "speedlimitdialog.h" #include "speedlimitdialog.h"
#include "base/unicodestrings.h"
#include "ui_speedlimitdialog.h" #include "ui_speedlimitdialog.h"
#include "utils.h" #include "utils.h"
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_ui(new Ui::SpeedLimitDialog()) , m_ui(new Ui::SpeedLimitDialog)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
qDebug("Bandwidth allocation dialog creation");
// Connect to slots // Connect to slots
connect(m_ui->bandwidthSlider, &QSlider::valueChanged, this, &SpeedLimitDialog::updateSpinValue); connect(m_ui->bandwidthSlider, &QSlider::valueChanged, this, &SpeedLimitDialog::updateSpinValue);
@ -49,73 +47,59 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
SpeedLimitDialog::~SpeedLimitDialog() SpeedLimitDialog::~SpeedLimitDialog()
{ {
qDebug("Deleting bandwidth allocation dialog");
delete m_ui; delete m_ui;
} }
// -2: if cancel // -2: if cancel
long SpeedLimitDialog::askSpeedLimit(QWidget *parent, bool *ok, QString title, long defaultVal, long maxVal) long SpeedLimitDialog::askSpeedLimit(QWidget *parent, bool *ok, const QString &title, const long defaultVal, const long maxVal)
{ {
if (ok) *ok = false;
SpeedLimitDialog dlg(parent); SpeedLimitDialog dlg(parent);
dlg.setWindowTitle(title); dlg.setWindowTitle(title);
dlg.setupDialog(maxVal / 1024., defaultVal / 1024.); dlg.setupDialog((maxVal / 1024.), (defaultVal / 1024.));
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
*ok = true; if (ok) *ok = true;
int val = dlg.getSpeedLimit();
if (val <= 0) const int val = dlg.getSpeedLimit();
if (val < 0)
return 0; return 0;
return (val * 1024); return (val * 1024);
} }
else {
*ok = false;
return -2; return -2;
}
} }
void SpeedLimitDialog::updateSpinValue(int val) const void SpeedLimitDialog::updateSpinValue(const int value)
{ {
qDebug("Called updateSpinValue with %d", val); m_ui->spinBandwidth->setValue(value);
if (val <= 0) {
m_ui->spinBandwidth->setValue(0);
m_ui->spinBandwidth->setSpecialValueText(QString::fromUtf8(C_INFINITY));
m_ui->spinBandwidth->setSuffix("");
}
else {
m_ui->spinBandwidth->setValue(val);
m_ui->spinBandwidth->setSuffix(' ' + tr("KiB/s"));
}
} }
void SpeedLimitDialog::updateSliderValue(int val) const void SpeedLimitDialog::updateSliderValue(const int value)
{ {
if (val <= 0) { if (value > m_ui->bandwidthSlider->maximum())
m_ui->spinBandwidth->setValue(0); m_ui->bandwidthSlider->setMaximum(value);
m_ui->spinBandwidth->setSpecialValueText(QString::fromUtf8(C_INFINITY)); m_ui->bandwidthSlider->setValue(value);
m_ui->spinBandwidth->setSuffix("");
}
if (val > m_ui->bandwidthSlider->maximum())
m_ui->bandwidthSlider->setMaximum(val);
m_ui->bandwidthSlider->setValue(val);
} }
long SpeedLimitDialog::getSpeedLimit() const int SpeedLimitDialog::getSpeedLimit() const
{ {
long val = m_ui->bandwidthSlider->value(); return m_ui->spinBandwidth->value();
if (val > 0)
return val;
return -1;
} }
void SpeedLimitDialog::setupDialog(long maxSlider, long val) const void SpeedLimitDialog::setupDialog(long maxSlider, long val)
{ {
if (val < 0) val = qMax<long>(0, val);
val = 0;
if (maxSlider <= 0) if (maxSlider <= 0)
maxSlider = 10000; maxSlider = 10000;
// This can happen for example if global rate limit is lower // This can happen for example if global rate limit is lower
// than torrent rate limit. // than torrent rate limit.
if (val > maxSlider) if (val > maxSlider)
maxSlider = val; maxSlider = val;
m_ui->bandwidthSlider->setMaximum(maxSlider); m_ui->bandwidthSlider->setMaximum(maxSlider);
m_ui->bandwidthSlider->setValue(val); m_ui->bandwidthSlider->setValue(val);
updateSpinValue(val); updateSpinValue(val);

15
src/gui/speedlimitdialog.h

@ -31,9 +31,6 @@
#include <QDialog> #include <QDialog>
#include "base/bittorrent/session.h"
#include "base/utils/misc.h"
namespace Ui namespace Ui
{ {
class SpeedLimitDialog; class SpeedLimitDialog;
@ -46,15 +43,15 @@ class SpeedLimitDialog : public QDialog
public: public:
explicit SpeedLimitDialog(QWidget *parent); explicit SpeedLimitDialog(QWidget *parent);
~SpeedLimitDialog(); ~SpeedLimitDialog();
static long askSpeedLimit(QWidget *parent, bool *ok, QString title, long defaultVal, long maxVal=10240000); static long askSpeedLimit(QWidget *parent, bool *ok, const QString &title, long defaultVal, long maxVal = 10240000);
protected slots: private slots:
void updateSpinValue(int val) const; void updateSpinValue(int val);
void updateSliderValue(int val) const; void updateSliderValue(int val);
void setupDialog(long maxSlider, long val) const;
private: private:
long getSpeedLimit() const; void setupDialog(long maxSlider, long val);
int getSpeedLimit() const;
Ui::SpeedLimitDialog *m_ui; Ui::SpeedLimitDialog *m_ui;
}; };

9
src/gui/speedlimitdialog.ui

@ -22,12 +22,15 @@
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinBandwidth"> <widget class="QSpinBox" name="spinBandwidth">
<property name="specialValueText">
<string>∞</string>
</property>
<property name="suffix">
<string> KiB/s</string>
</property>
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>65535</number>
</property> </property>
<property name="value">
<number>0</number>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

25
src/gui/statusbar.cpp

@ -206,18 +206,19 @@ void StatusBar::updateSpeedLabels()
{ {
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status(); const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true); QString dlSpeedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true);
int speedLimit = BitTorrent::Session::instance()->downloadSpeedLimit(); const int dlSpeedLimit = BitTorrent::Session::instance()->downloadSpeedLimit();
if (speedLimit) if (dlSpeedLimit > 0)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + ']'; dlSpeedLbl += " [" + Utils::Misc::friendlyUnit(dlSpeedLimit, true) + ']';
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ')'; dlSpeedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ')';
m_dlSpeedLbl->setText(speedLbl); m_dlSpeedLbl->setText(dlSpeedLbl);
speedLimit = BitTorrent::Session::instance()->uploadSpeedLimit();
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true); QString upSpeedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true);
if (speedLimit) const int upSpeedLimit = BitTorrent::Session::instance()->uploadSpeedLimit();
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + ']'; if (upSpeedLimit > 0)
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ')'; upSpeedLbl += " [" + Utils::Misc::friendlyUnit(upSpeedLimit, true) + ']';
m_upSpeedLbl->setText(speedLbl); upSpeedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ')';
m_upSpeedLbl->setText(upSpeedLbl);
} }
void StatusBar::refresh() void StatusBar::refresh()

12
src/webui/api/appcontroller.cpp

@ -147,11 +147,11 @@ void AppController::preferencesAction()
// Global Rate Limits // Global Rate Limits
data["dl_limit"] = session->globalDownloadSpeedLimit(); data["dl_limit"] = session->globalDownloadSpeedLimit();
data["up_limit"] = session->globalUploadSpeedLimit(); data["up_limit"] = session->globalUploadSpeedLimit();
data["alt_dl_limit"] = session->altGlobalDownloadSpeedLimit();
data["alt_up_limit"] = session->altGlobalUploadSpeedLimit();
data["bittorrent_protocol"] = static_cast<int>(session->btProtocol()); data["bittorrent_protocol"] = static_cast<int>(session->btProtocol());
data["limit_utp_rate"] = session->isUTPRateLimited(); data["limit_utp_rate"] = session->isUTPRateLimited();
data["limit_tcp_overhead"] = session->includeOverheadInLimits(); data["limit_tcp_overhead"] = session->includeOverheadInLimits();
data["alt_dl_limit"] = session->altGlobalDownloadSpeedLimit();
data["alt_up_limit"] = session->altGlobalUploadSpeedLimit();
// Scheduling // Scheduling
data["scheduler_enabled"] = session->isBandwidthSchedulerEnabled(); data["scheduler_enabled"] = session->isBandwidthSchedulerEnabled();
const QTime start_time = pref->getSchedulerStartTime(); const QTime start_time = pref->getSchedulerStartTime();
@ -368,16 +368,16 @@ void AppController::setPreferencesAction()
session->setGlobalDownloadSpeedLimit(m["dl_limit"].toInt()); session->setGlobalDownloadSpeedLimit(m["dl_limit"].toInt());
if (m.contains("up_limit")) if (m.contains("up_limit"))
session->setGlobalUploadSpeedLimit(m["up_limit"].toInt()); session->setGlobalUploadSpeedLimit(m["up_limit"].toInt());
if (m.contains("alt_dl_limit"))
session->setAltGlobalDownloadSpeedLimit(m["alt_dl_limit"].toInt());
if (m.contains("alt_up_limit"))
session->setAltGlobalUploadSpeedLimit(m["alt_up_limit"].toInt());
if (m.contains("bittorrent_protocol")) if (m.contains("bittorrent_protocol"))
session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m["bittorrent_protocol"].toInt())); session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m["bittorrent_protocol"].toInt()));
if (m.contains("limit_utp_rate")) if (m.contains("limit_utp_rate"))
session->setUTPRateLimited(m["limit_utp_rate"].toBool()); session->setUTPRateLimited(m["limit_utp_rate"].toBool());
if (m.contains("limit_tcp_overhead")) if (m.contains("limit_tcp_overhead"))
session->setIncludeOverheadInLimits(m["limit_tcp_overhead"].toBool()); session->setIncludeOverheadInLimits(m["limit_tcp_overhead"].toBool());
if (m.contains("alt_dl_limit"))
session->setAltGlobalDownloadSpeedLimit(m["alt_dl_limit"].toInt());
if (m.contains("alt_up_limit"))
session->setAltGlobalUploadSpeedLimit(m["alt_up_limit"].toInt());
// Scheduling // Scheduling
if (m.contains("scheduler_enabled")) if (m.contains("scheduler_enabled"))
session->setBandwidthSchedulerEnabled(m["scheduler_enabled"].toBool()); session->setBandwidthSchedulerEnabled(m["scheduler_enabled"].toBool());

131
src/webui/www/private/preferences_content.html

@ -211,40 +211,30 @@
<legend>QBT_TR(Global Rate Limits)QBT_TR[CONTEXT=OptionsDialog]</legend> <legend>QBT_TR(Global Rate Limits)QBT_TR[CONTEXT=OptionsDialog]</legend>
<table> <table>
<tr> <tr>
<td> <td><label for="up_limit_value">QBT_TR(Upload:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
<input type="checkbox" id="up_limit_checkbox" onclick="updateUpLimitEnabled();" /> <td><input type="number" id="up_limit_value" style="width: 4em;" min="0" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
<label for="up_limit_checkbox">QBT_TR(Upload:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td><input type="text" id="up_limit_value" style="width: 4em;" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
</tr> </tr>
<tr> <tr>
<td> <td><label for="dl_limit_value">QBT_TR(Download:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
<input type="checkbox" id="dl_limit_checkbox" onclick="updateDlLimitEnabled();" /> <td><input type="number" id="dl_limit_value" style="width: 4em;" min="0" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
<label for="dl_limit_checkbox">QBT_TR(Download:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td><input type="text" id="dl_limit_value" style="width: 4em;" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
</tr> </tr>
</table> </table>
<i>QBT_TR(0 means unlimited)QBT_TR[CONTEXT=OptionsDialog]</i>
</fieldset> </fieldset>
<fieldset class="settings"> <fieldset class="settings">
<legend>QBT_TR(Alternative Rate Limits)QBT_TR[CONTEXT=OptionsDialog]</legend> <legend>QBT_TR(Alternative Rate Limits)QBT_TR[CONTEXT=OptionsDialog]</legend>
<table> <table>
<tr> <tr>
<td> <td><label for="alt_up_limit_value">QBT_TR(Upload:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
<input type="checkbox" id="alt_up_limit_checkbox" onclick="updateAltUpLimitEnabled();" /> <td><input type="number" id="alt_up_limit_value" style="width: 4em;" min="0" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
<label for="alt_up_limit_checkbox">QBT_TR(Upload:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td><input type="text" id="alt_up_limit_value" style="width: 4em;" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
</tr> </tr>
<tr> <tr>
<td> <td><label for="alt_dl_limit_value">QBT_TR(Download:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
<input type="checkbox" id="alt_dl_limit_checkbox" onclick="updateAltDlLimitEnabled();" /> <td><input type="number" id="alt_dl_limit_value" style="width: 4em;" min="0" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
<label for="alt_dl_limit_checkbox">QBT_TR(Download:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td><input type="text" id="alt_dl_limit_value" style="width: 4em;" />&nbsp;&nbsp;QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]</td>
</tr> </tr>
</table> </table>
<i>QBT_TR(0 means unlimited)QBT_TR[CONTEXT=OptionsDialog]</i>
<fieldset class="settings"> <fieldset class="settings">
<legend><input type="checkbox" id="limit_sheduling_checkbox" onclick="updateSchedulingEnabled();" /> <legend><input type="checkbox" id="limit_sheduling_checkbox" onclick="updateSchedulingEnabled();" />
@ -677,26 +667,6 @@
}; };
// Speed tab // Speed tab
updateUpLimitEnabled = function() {
var isUpLimitEnabled = $('up_limit_checkbox').getProperty('checked');
$('up_limit_value').setProperty('disabled', !isUpLimitEnabled);
};
updateDlLimitEnabled = function() {
var isDlLimitEnabled = $('dl_limit_checkbox').getProperty('checked');
$('dl_limit_value').setProperty('disabled', !isDlLimitEnabled);
};
updateAltUpLimitEnabled = function() {
var isAltUpLimitEnabled = $('alt_up_limit_checkbox').getProperty('checked');
$('alt_up_limit_value').setProperty('disabled', !isAltUpLimitEnabled);
};
updateAltDlLimitEnabled = function() {
var isAltDlLimitEnabled = $('alt_dl_limit_checkbox').getProperty('checked');
$('alt_dl_limit_value').setProperty('disabled', !isAltDlLimitEnabled);
};
updateSchedulingEnabled = function() { updateSchedulingEnabled = function() {
var isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked'); var isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked');
$('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled); $('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled);
@ -918,48 +888,16 @@
// Speed tab // Speed tab
// Global Rate Limits // Global Rate Limits
var up_limit = pref.up_limit.toInt() / 1024; $('up_limit_value').setProperty('value', (pref.up_limit.toInt() / 1024));
if (up_limit <= 0) { $('dl_limit_value').setProperty('value', (pref.dl_limit.toInt() / 1024));
$('up_limit_checkbox').setProperty('checked', false); // Alternative Global Rate Limits
} $('alt_up_limit_value').setProperty('value', (pref.alt_up_limit.toInt() / 1024));
else { $('alt_dl_limit_value').setProperty('value', (pref.alt_dl_limit.toInt() / 1024));
$('up_limit_checkbox').setProperty('checked', true);
$('up_limit_value').setProperty('value', up_limit);
}
updateUpLimitEnabled();
var dl_limit = pref.dl_limit.toInt() / 1024;
if (dl_limit <= 0) {
$('dl_limit_checkbox').setProperty('checked', false);
}
else {
$('dl_limit_checkbox').setProperty('checked', true);
$('dl_limit_value').setProperty('value', dl_limit);
}
updateDlLimitEnabled();
$('enable_protocol_combobox').setProperty('value', pref.bittorrent_protocol); $('enable_protocol_combobox').setProperty('value', pref.bittorrent_protocol);
$('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate); $('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate);
$('limit_tcp_overhead_checkbox').setProperty('checked', pref.limit_tcp_overhead); $('limit_tcp_overhead_checkbox').setProperty('checked', pref.limit_tcp_overhead);
// Alternative Global Rate Limits
var alt_up_limit = pref.alt_up_limit.toInt() / 1024;
if (alt_up_limit <= 0) {
$('alt_up_limit_checkbox').setProperty('checked', false);
}
else {
$('alt_up_limit_checkbox').setProperty('checked', true);
$('alt_up_limit_value').setProperty('value', alt_up_limit);
}
updateAltUpLimitEnabled();
var alt_dl_limit = pref.alt_dl_limit.toInt() / 1024;
if (alt_dl_limit <= 0) {
$('alt_dl_limit_checkbox').setProperty('checked', false);
}
else {
$('alt_dl_limit_checkbox').setProperty('checked', true);
$('alt_dl_limit_value').setProperty('value', alt_dl_limit);
}
updateAltDlLimitEnabled();
// Scheduling // Scheduling
$('limit_sheduling_checkbox').setProperty('checked', pref.scheduler_enabled); $('limit_sheduling_checkbox').setProperty('checked', pref.scheduler_enabled);
$('schedule_from_hour').setProperty('value', time_padding(pref.schedule_from_hour)); $('schedule_from_hour').setProperty('value', time_padding(pref.schedule_from_hour));
@ -1175,48 +1113,39 @@
// Speed tab // Speed tab
// Global Rate Limits // Global Rate Limits
var up_limit = -1; var up_limit = $('up_limit_value').getProperty('value').toInt() * 1024;
if ($('up_limit_checkbox').getProperty('checked')) { if (isNaN(up_limit) || up_limit < 0) {
up_limit = $('up_limit_value').getProperty('value').toInt() * 1024;
if (isNaN(up_limit) || up_limit <= 0) {
alert("QBT_TR(Global upload rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Global upload rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return; return;
} }
}
settings.set('up_limit', up_limit); settings.set('up_limit', up_limit);
var dl_limit = -1;
if ($('dl_limit_checkbox').getProperty('checked')) { var dl_limit = $('dl_limit_value').getProperty('value').toInt() * 1024;
dl_limit = $('dl_limit_value').getProperty('value').toInt() * 1024; if (isNaN(dl_limit) || dl_limit < 0) {
if (isNaN(dl_limit) || dl_limit <= 0) {
alert("QBT_TR(Global download rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Global download rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return; return;
} }
}
settings.set('dl_limit', dl_limit); settings.set('dl_limit', dl_limit);
settings.set('bittorrent_protocol', $('enable_protocol_combobox').getProperty('value'));
settings.set('limit_utp_rate', $('limit_utp_rate_checkbox').getProperty('checked'));
settings.set('limit_tcp_overhead', $('limit_tcp_overhead_checkbox').getProperty('checked'));
// Alternative Global Rate Limits // Alternative Global Rate Limits
var alt_up_limit = -1; var alt_up_limit = $('alt_up_limit_value').getProperty('value').toInt() * 1024;
if ($('alt_up_limit_checkbox').getProperty('checked')) { if (isNaN(alt_up_limit) || alt_up_limit < 0) {
alt_up_limit = $('alt_up_limit_value').getProperty('value').toInt() * 1024;
if (isNaN(alt_up_limit) || alt_up_limit <= 0) {
alert("QBT_TR(Alternative upload rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Alternative upload rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return; return;
} }
}
settings.set('alt_up_limit', alt_up_limit); settings.set('alt_up_limit', alt_up_limit);
var alt_dl_limit = -1;
if ($('alt_dl_limit_checkbox').getProperty('checked')) { var alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt() * 1024;
alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt() * 1024; if (isNaN(alt_dl_limit) || alt_dl_limit < 0) {
if (isNaN(alt_dl_limit) || alt_dl_limit <= 0) {
alert("QBT_TR(Alternative download rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]"); alert("QBT_TR(Alternative download rate limit must be greater than 0 or disabled.)QBT_TR[CONTEXT=HttpServer]");
return; return;
} }
}
settings.set('alt_dl_limit', alt_dl_limit); settings.set('alt_dl_limit', alt_dl_limit);
settings.set('bittorrent_protocol', $('enable_protocol_combobox').getProperty('value'));
settings.set('limit_utp_rate', $('limit_utp_rate_checkbox').getProperty('checked'));
settings.set('limit_tcp_overhead', $('limit_tcp_overhead_checkbox').getProperty('checked'));
// Scheduler // Scheduler
var scheduling_enabled = $('limit_sheduling_checkbox').getProperty('checked'); var scheduling_enabled = $('limit_sheduling_checkbox').getProperty('checked');
settings.set('scheduler_enabled', scheduling_enabled); settings.set('scheduler_enabled', scheduling_enabled);

Loading…
Cancel
Save