diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index fe27f6ef5..7867875a8 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2652,7 +2652,7 @@ int Session::downloadSpeedLimit() const : globalDownloadSpeedLimit(); } -void Session::setDownloadSpeedLimit(int limit) +void Session::setDownloadSpeedLimit(const int limit) { if (isAltGlobalSpeedLimitEnabled()) setAltGlobalDownloadSpeedLimit(limit); @@ -2667,7 +2667,7 @@ int Session::uploadSpeedLimit() const : globalUploadSpeedLimit(); } -void Session::setUploadSpeedLimit(int limit) +void Session::setUploadSpeedLimit(const int limit) { if (isAltGlobalSpeedLimitEnabled()) setAltGlobalUploadSpeedLimit(limit); @@ -2680,7 +2680,7 @@ bool Session::isAltGlobalSpeedLimitEnabled() const return m_isAltGlobalSpeedLimitEnabled; } -void Session::setAltGlobalSpeedLimitEnabled(bool enabled) +void Session::setAltGlobalSpeedLimitEnabled(const bool enabled) { if (enabled == isAltGlobalSpeedLimitEnabled()) return; diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index ffb880824..1f440c176 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -306,10 +306,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(m_ui->spinPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkRandomPort, &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->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinUploadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); @@ -643,15 +639,13 @@ void OptionsDialog::saveOptions() session->setPort(getPort()); session->setUseRandomPort(m_ui->checkRandomPort->isChecked()); Net::PortForwarder::instance()->setEnabled(isUPnPEnabled()); - const QPair downUpLimit = getGlobalBandwidthLimits(); - session->setGlobalDownloadSpeedLimit(downUpLimit.first); - session->setGlobalUploadSpeedLimit(downUpLimit.second); + session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024); + session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024); + session->setAltGlobalDownloadSpeedLimit(m_ui->spinDownloadLimitAlt->value() * 1024); + session->setAltGlobalUploadSpeedLimit(m_ui->spinUploadLimitAlt->value() * 1024); session->setUTPRateLimited(m_ui->checkLimituTPConnections->isChecked()); session->setIncludeOverheadInLimits(m_ui->checkLimitTransportOverhead->isChecked()); session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked()); - const QPair altDownUpLimit = getAltGlobalBandwidthLimits(); - session->setAltGlobalDownloadSpeedLimit(altDownUpLimit.first); - session->setAltGlobalUploadSpeedLimit(altDownUpLimit.second); pref->setSchedulerStartTime(m_ui->timeEditScheduleFrom->time()); pref->setSchedulerEndTime(m_ui->timeEditScheduleTo->time()); pref->setSchedulerDays(static_cast(m_ui->comboBoxScheduleDays->currentIndex())); @@ -1010,55 +1004,10 @@ void OptionsDialog::loadOptions() // End Connection preferences // Speed preferences - intValue = session->globalDownloadSpeedLimit() / 1024; - if (intValue > 0) { - // Enabled - m_ui->checkDownloadLimit->setChecked(true); - 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->spinDownloadLimit->setValue(session->globalDownloadSpeedLimit() / 1024); + m_ui->spinUploadLimit->setValue(session->globalUploadSpeedLimit() / 1024); + m_ui->spinDownloadLimitAlt->setValue(session->altGlobalDownloadSpeedLimit() / 1024); + m_ui->spinUploadLimitAlt->setValue(session->altGlobalUploadSpeedLimit() / 1024); m_ui->checkLimituTPConnections->setChecked(session->isUTPRateLimited()); m_ui->checkLimitTransportOverhead->setChecked(session->includeOverheadInLimits()); @@ -1198,30 +1147,6 @@ bool OptionsDialog::isUPnPEnabled() const return m_ui->checkUPnP->isChecked(); } -// Return Download & Upload limits in kbps -// [download,upload] -QPair 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 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 { return m_ui->checkStartMinimized->isChecked(); diff --git a/src/gui/optionsdialog.h b/src/gui/optionsdialog.h index bac2945d7..d4a7a9c74 100644 --- a/src/gui/optionsdialog.h +++ b/src/gui/optionsdialog.h @@ -137,8 +137,6 @@ private: // Connection options int getPort() const; bool isUPnPEnabled() const; - QPair getGlobalBandwidthLimits() const; - QPair getAltGlobalBandwidthLimits() const; // Bittorrent options int getMaxConnecs() const; int getMaxConnecsPerTorrent() const; diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index a24bd9d3b..36eb69d11 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -1812,15 +1812,12 @@ - - false + + KiB/s - - 1 - 1000000 @@ -1829,24 +1826,14 @@ - - - - Upload: - - - - - false + + KiB/s - - 1 - 1000000 @@ -1858,13 +1845,6 @@ - - - - Download: - - - @@ -1878,6 +1858,20 @@ + + + + Upload: + + + + + + + Download: + + + @@ -1887,6 +1881,22 @@ Alternative Rate Limits + + + + + + + KiB/s + + + 1000000 + + + 10 + + + @@ -2001,50 +2011,14 @@ - - - - Upload: - - - - - - - Download: - - - - - false - - - KiB/s - - - 1 - - - 1000000 - - - 10 - - - - - - - false + + KiB/s - - 1 - 1000000 @@ -2066,6 +2040,20 @@ + + + + Upload: + + + + + + + Download: + + + @@ -3432,15 +3420,11 @@ Use ';' to split multiple entries. Can use wildcard '*'. checkIpFilterTrackers scrollArea_9 spinUploadLimit - checkUploadLimit spinDownloadLimit - checkDownloadLimit groupBoxSchedule timeEditScheduleTo timeEditScheduleFrom comboBoxScheduleDays - checkUploadLimitAlt - checkDownloadLimitAlt spinUploadLimitAlt spinDownloadLimitAlt checkLimitLocalPeerRate @@ -3476,38 +3460,6 @@ Use ';' to split multiple entries. Can use wildcard '*'. - - checkUploadLimit - toggled(bool) - spinUploadLimit - setEnabled(bool) - - - 367 - 61 - - - 448 - 62 - - - - - checkDownloadLimit - toggled(bool) - spinDownloadLimit - setEnabled(bool) - - - 377 - 81 - - - 430 - 87 - - - checkMaxConnecs toggled(bool) @@ -3572,38 +3524,6 @@ Use ';' to split multiple entries. Can use wildcard '*'. - - checkDownloadLimitAlt - toggled(bool) - spinDownloadLimitAlt - setEnabled(bool) - - - 547 - 415 - - - 815 - 413 - - - - - checkUploadLimitAlt - toggled(bool) - spinUploadLimitAlt - setEnabled(bool) - - - 604 - 271 - - - 677 - 272 - - - checkMaxRatio toggled(bool) diff --git a/src/gui/statusbar.cpp b/src/gui/statusbar.cpp index 52a1c3b40..7711d8b64 100644 --- a/src/gui/statusbar.cpp +++ b/src/gui/statusbar.cpp @@ -206,18 +206,19 @@ void StatusBar::updateSpeedLabels() { const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status(); - QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true); - int speedLimit = BitTorrent::Session::instance()->downloadSpeedLimit(); - if (speedLimit) - speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + ']'; - speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ')'; - m_dlSpeedLbl->setText(speedLbl); - speedLimit = BitTorrent::Session::instance()->uploadSpeedLimit(); - speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true); - if (speedLimit) - speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + ']'; - speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ')'; - m_upSpeedLbl->setText(speedLbl); + QString dlSpeedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true); + const int dlSpeedLimit = BitTorrent::Session::instance()->downloadSpeedLimit(); + if (dlSpeedLimit > 0) + dlSpeedLbl += " [" + Utils::Misc::friendlyUnit(dlSpeedLimit, true) + ']'; + dlSpeedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ')'; + m_dlSpeedLbl->setText(dlSpeedLbl); + + QString upSpeedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true); + const int upSpeedLimit = BitTorrent::Session::instance()->uploadSpeedLimit(); + if (upSpeedLimit > 0) + upSpeedLbl += " [" + Utils::Misc::friendlyUnit(upSpeedLimit, true) + ']'; + upSpeedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ')'; + m_upSpeedLbl->setText(upSpeedLbl); } void StatusBar::refresh() diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index fad7bc23e..445a3dd44 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -147,11 +147,11 @@ void AppController::preferencesAction() // Global Rate Limits data["dl_limit"] = session->globalDownloadSpeedLimit(); data["up_limit"] = session->globalUploadSpeedLimit(); + data["alt_dl_limit"] = session->altGlobalDownloadSpeedLimit(); + data["alt_up_limit"] = session->altGlobalUploadSpeedLimit(); data["bittorrent_protocol"] = static_cast(session->btProtocol()); data["limit_utp_rate"] = session->isUTPRateLimited(); data["limit_tcp_overhead"] = session->includeOverheadInLimits(); - data["alt_dl_limit"] = session->altGlobalDownloadSpeedLimit(); - data["alt_up_limit"] = session->altGlobalUploadSpeedLimit(); // Scheduling data["scheduler_enabled"] = session->isBandwidthSchedulerEnabled(); const QTime start_time = pref->getSchedulerStartTime(); @@ -368,16 +368,16 @@ void AppController::setPreferencesAction() session->setGlobalDownloadSpeedLimit(m["dl_limit"].toInt()); if (m.contains("up_limit")) 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")) session->setBTProtocol(static_cast(m["bittorrent_protocol"].toInt())); if (m.contains("limit_utp_rate")) session->setUTPRateLimited(m["limit_utp_rate"].toBool()); if (m.contains("limit_tcp_overhead")) 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 if (m.contains("scheduler_enabled")) session->setBandwidthSchedulerEnabled(m["scheduler_enabled"].toBool()); diff --git a/src/webui/www/private/preferences_content.html b/src/webui/www/private/preferences_content.html index 4ec2b46b9..4d20e021e 100644 --- a/src/webui/www/private/preferences_content.html +++ b/src/webui/www/private/preferences_content.html @@ -211,40 +211,30 @@ QBT_TR(Global Rate Limits)QBT_TR[CONTEXT=OptionsDialog] - - + + - - + +
- - -   QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]  QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]
- - -   QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]  QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]
+ QBT_TR(0 means unlimited)QBT_TR[CONTEXT=OptionsDialog]
QBT_TR(Alternative Rate Limits)QBT_TR[CONTEXT=OptionsDialog] - - + + - - + +
- - -   QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]  QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]
- - -   QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]  QBT_TR(KiB/s)QBT_TR[CONTEXT=OptionsDialog]
+ QBT_TR(0 means unlimited)QBT_TR[CONTEXT=OptionsDialog]
@@ -677,26 +667,6 @@ }; // 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() { var isLimitSchedulingEnabled = $('limit_sheduling_checkbox').getProperty('checked'); $('schedule_from_hour').setProperty('disabled', !isLimitSchedulingEnabled); @@ -918,48 +888,16 @@ // Speed tab // Global Rate Limits - var up_limit = pref.up_limit.toInt() / 1024; - if (up_limit <= 0) { - $('up_limit_checkbox').setProperty('checked', false); - } - else { - $('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(); + $('up_limit_value').setProperty('value', (pref.up_limit.toInt() / 1024)); + $('dl_limit_value').setProperty('value', (pref.dl_limit.toInt() / 1024)); + // Alternative Global Rate Limits + $('alt_up_limit_value').setProperty('value', (pref.alt_up_limit.toInt() / 1024)); + $('alt_dl_limit_value').setProperty('value', (pref.alt_dl_limit.toInt() / 1024)); + $('enable_protocol_combobox').setProperty('value', pref.bittorrent_protocol); $('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate); $('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 $('limit_sheduling_checkbox').setProperty('checked', pref.scheduler_enabled); $('schedule_from_hour').setProperty('value', time_padding(pref.schedule_from_hour)); @@ -1175,48 +1113,39 @@ // Speed tab // Global Rate Limits - var up_limit = -1; - if ($('up_limit_checkbox').getProperty('checked')) { - 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]"); - return; - } + var 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]"); + return; } settings.set('up_limit', up_limit); - var dl_limit = -1; - if ($('dl_limit_checkbox').getProperty('checked')) { - dl_limit = $('dl_limit_value').getProperty('value').toInt() * 1024; - 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]"); - return; - } + + var dl_limit = $('dl_limit_value').getProperty('value').toInt() * 1024; + 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]"); + return; } 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 - var alt_up_limit = -1; - if ($('alt_up_limit_checkbox').getProperty('checked')) { - 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]"); - return; - } + var 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]"); + return; } settings.set('alt_up_limit', alt_up_limit); - var alt_dl_limit = -1; - if ($('alt_dl_limit_checkbox').getProperty('checked')) { - alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt() * 1024; - 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]"); - return; - } + + var alt_dl_limit = $('alt_dl_limit_value').getProperty('value').toInt() * 1024; + 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]"); + return; } 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 var scheduling_enabled = $('limit_sheduling_checkbox').getProperty('checked'); settings.set('scheduler_enabled', scheduling_enabled);