Browse Source

Merge pull request #15229 from Chocobo1/port

Use spinbox special value to represent "Use any available port"
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
ce554e6c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/app/upgrade.cpp
  2. 16
      src/base/bittorrent/session.cpp
  3. 3
      src/base/bittorrent/session.h
  4. 7
      src/base/settingsstorage.cpp
  5. 1
      src/base/settingsstorage.h
  6. 7
      src/gui/optionsdialog.cpp
  7. 26
      src/gui/optionsdialog.ui
  8. 12
      src/webui/api/appcontroller.cpp
  9. 16
      src/webui/www/private/views/preferences.html

16
src/app/upgrade.cpp

@ -102,12 +102,28 @@ namespace @@ -102,12 +102,28 @@ namespace
settingsStorage->storeValue(newKey, Utils::String::fromEnum(torrentContentLayout));
settingsStorage->removeValue(oldKey);
}
void upgradeListenPortSettings()
{
const auto oldKey = QString::fromLatin1("BitTorrent/Session/UseRandomPort");
const auto newKey = QString::fromLatin1("Preferences/Connection/PortRangeMin");
auto *settingsStorage = SettingsStorage::instance();
if (settingsStorage->hasKey(oldKey))
{
if (settingsStorage->loadValue<bool>(oldKey))
settingsStorage->storeValue(newKey, 0);
settingsStorage->removeValue(oldKey);
}
}
}
bool upgrade(const bool /*ask*/)
{
exportWebUIHttpsFiles();
upgradeTorrentContentLayout();
upgradeListenPortSettings();
return true;
}

16
src/base/bittorrent/session.cpp

@ -408,7 +408,6 @@ Session::Session(QObject *parent) @@ -408,7 +408,6 @@ Session::Session(QObject *parent)
, m_isBandwidthSchedulerEnabled(BITTORRENT_SESSION_KEY("BandwidthSchedulerEnabled"), false)
, m_saveResumeDataInterval(BITTORRENT_SESSION_KEY("SaveResumeDataInterval"), 60)
, m_port(BITTORRENT_SESSION_KEY("Port"), -1)
, m_useRandomPort(BITTORRENT_SESSION_KEY("UseRandomPort"), false)
, m_networkInterface(BITTORRENT_SESSION_KEY("Interface"))
, m_networkInterfaceName(BITTORRENT_SESSION_KEY("InterfaceName"))
, m_networkInterfaceAddress(BITTORRENT_SESSION_KEY("InterfaceAddress"))
@ -1422,13 +1421,12 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack) @@ -1422,13 +1421,12 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack)
if (m_listenInterfaceConfigured)
return;
const int port = useRandomPort() ? 0 : this->port();
if (port > 0) // user specified port
if (port() > 0) // user has specified port number
settingsPack.set_int(lt::settings_pack::max_retry_port_bind, 0);
QStringList endpoints;
QStringList outgoingInterfaces;
const QString portString = ':' + QString::number(port);
const QString portString = ':' + QString::number(port());
for (const QString &ip : asConst(getListeningIPs()))
{
@ -2761,16 +2759,6 @@ void Session::setPort(const int port) @@ -2761,16 +2759,6 @@ void Session::setPort(const int port)
}
}
bool Session::useRandomPort() const
{
return m_useRandomPort;
}
void Session::setUseRandomPort(const bool value)
{
m_useRandomPort = value;
}
QString Session::networkInterface() const
{
return m_networkInterface;

3
src/base/bittorrent/session.h

@ -306,8 +306,6 @@ namespace BitTorrent @@ -306,8 +306,6 @@ namespace BitTorrent
void setSaveResumeDataInterval(int value);
int port() const;
void setPort(int port);
bool useRandomPort() const;
void setUseRandomPort(bool value);
QString networkInterface() const;
void setNetworkInterface(const QString &iface);
QString networkInterfaceName() const;
@ -722,7 +720,6 @@ namespace BitTorrent @@ -722,7 +720,6 @@ namespace BitTorrent
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<int> m_saveResumeDataInterval;
CachedSettingValue<int> m_port;
CachedSettingValue<bool> m_useRandomPort;
CachedSettingValue<QString> m_networkInterface;
CachedSettingValue<QString> m_networkInterfaceName;
CachedSettingValue<QString> m_networkInterfaceAddress;

7
src/base/settingsstorage.cpp

@ -234,6 +234,13 @@ void SettingsStorage::removeValue(const QString &key) @@ -234,6 +234,13 @@ void SettingsStorage::removeValue(const QString &key)
}
}
bool SettingsStorage::hasKey(const QString &key) const
{
const QString realKey = mapKey(key);
const QReadLocker locker {&m_lock};
return m_data.contains(realKey);
}
QVariantHash TransactionalSettings::read() const
{
QVariantHash res;

1
src/base/settingsstorage.h

@ -79,6 +79,7 @@ public: @@ -79,6 +79,7 @@ public:
}
void removeValue(const QString &key);
bool hasKey(const QString &key) const;
public slots:
bool save();

7
src/gui/optionsdialog.cpp

@ -301,7 +301,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -301,7 +301,6 @@ OptionsDialog::OptionsDialog(QWidget *parent)
void (QSpinBox::*qSpinBoxValueChanged)(int) = &QSpinBox::valueChanged;
connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::enableProxy);
connect(m_ui->checkRandomPort, &QAbstractButton::toggled, m_ui->spinPort, &ThisType::setDisabled);
// Apply button is activated when a value is changed
// Behavior tab
@ -409,7 +408,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -409,7 +408,6 @@ OptionsDialog::OptionsDialog(QWidget *parent)
// Connection tab
connect(m_ui->comboProtocol, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
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->spinUploadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
@ -775,7 +773,6 @@ void OptionsDialog::saveOptions() @@ -775,7 +773,6 @@ void OptionsDialog::saveOptions()
// Connection preferences
session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m_ui->comboProtocol->currentIndex()));
session->setPort(getPort());
session->setUseRandomPort(m_ui->checkRandomPort->isChecked());
Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024);
session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024);
@ -1072,10 +1069,8 @@ void OptionsDialog::loadOptions() @@ -1072,10 +1069,8 @@ void OptionsDialog::loadOptions()
// Connection preferences
m_ui->comboProtocol->setCurrentIndex(static_cast<int>(session->btProtocol()));
m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
m_ui->checkRandomPort->setChecked(session->useRandomPort());
m_ui->spinPort->setValue(session->port());
m_ui->spinPort->setDisabled(m_ui->checkRandomPort->isChecked());
m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
intValue = session->maxConnections();
if (intValue > 0)

26
src/gui/optionsdialog.ui

@ -1457,15 +1457,12 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s @@ -1457,15 +1457,12 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</item>
<item>
<widget class="QSpinBox" name="spinPort">
<property name="minimum">
<number>1</number>
<property name="specialValueText">
<string>Any</string>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>8999</number>
</property>
</widget>
</item>
<item>
@ -1500,13 +1497,6 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s @@ -1500,13 +1497,6 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkRandomPort">
<property name="text">
<string>Use different port on each startup</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -2673,14 +2663,7 @@ Disable encryption: Only connect to peers without protocol encryption</string> @@ -2673,14 +2663,7 @@ Disable encryption: Only connect to peers without protocol encryption</string>
</property>
<layout class="QGridLayout" name="gridLayout_16">
<item row="0" column="0">
<widget class="QPlainTextEdit" name="textTrackers">
<property name="enabled">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
<widget class="QPlainTextEdit" name="textTrackers"/>
</item>
</layout>
</widget>
@ -3288,7 +3271,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string> @@ -3288,7 +3271,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</layout>
</widget>
</item>
<item>
<item>
<widget class="QGroupBox" name="groupEnableReverseProxySupport">
<property name="title">
<string>Enable reverse proxy support</string>
@ -3527,7 +3510,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string> @@ -3527,7 +3510,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<tabstop>lineEditAutoRun</tabstop>
<tabstop>scrollArea_3</tabstop>
<tabstop>randomButton</tabstop>
<tabstop>checkRandomPort</tabstop>
<tabstop>checkMaxConnecs</tabstop>
<tabstop>spinMaxConnec</tabstop>
<tabstop>checkMaxConnecsPerTorrent</tabstop>

12
src/webui/api/appcontroller.cpp

@ -153,8 +153,8 @@ void AppController::preferencesAction() @@ -153,8 +153,8 @@ void AppController::preferencesAction()
// Connection
// Listening Port
data["listen_port"] = session->port();
data["random_port"] = (session->port() == 0); // deprecated
data["upnp"] = Net::PortForwarder::instance()->isEnabled();
data["random_port"] = session->useRandomPort();
// Connections Limits
data["max_connec"] = session->maxConnections();
data["max_connec_per_torrent"] = session->maxConnectionsPerTorrent();
@ -482,12 +482,16 @@ void AppController::setPreferencesAction() @@ -482,12 +482,16 @@ void AppController::setPreferencesAction()
// Connection
// Listening Port
if (hasKey("listen_port"))
if (hasKey("random_port") && it.value().toBool()) // deprecated
{
session->setPort(0);
}
else if (hasKey("listen_port"))
{
session->setPort(it.value().toInt());
}
if (hasKey("upnp"))
Net::PortForwarder::instance()->setEnabled(it.value().toBool());
if (hasKey("random_port"))
session->setUseRandomPort(it.value().toBool());
// Connections Limits
if (hasKey("max_connec"))
session->setMaxConnections(it.value().toInt());

16
src/webui/www/private/views/preferences.html

@ -238,10 +238,6 @@ @@ -238,10 +238,6 @@
<input type="checkbox" id="upnp_checkbox" />
<label for="upnp_checkbox">QBT_TR(Use UPnP / NAT-PMP port forwarding from my router)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
<div class="formRow">
<input type="checkbox" id="random_port_checkbox" onclick="qBittorrent.Preferences.updatePortValueEnabled();" />
<label for="random_port_checkbox">QBT_TR(Use different port on each startup)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
</fieldset>
<fieldset class="settings">
@ -1275,7 +1271,6 @@ @@ -1275,7 +1271,6 @@
updateMailAuthSettings: updateMailAuthSettings,
updateAutoRun: updateAutoRun,
generateRandomPort: generateRandomPort,
updatePortValueEnabled: updatePortValueEnabled,
updateMaxConnecEnabled: updateMaxConnecEnabled,
updateMaxConnecPerTorrentEnabled: updateMaxConnecPerTorrentEnabled,
updateMaxUploadsEnabled: updateMaxUploadsEnabled,
@ -1404,10 +1399,6 @@ @@ -1404,10 +1399,6 @@
};
// Connection tab
const updatePortValueEnabled = function() {
const checked = $('random_port_checkbox').getProperty('checked');
$('port_value').setProperty('disabled', checked);
};
const updateMaxConnecEnabled = function() {
const isMaxConnecEnabled = $('max_connec_checkbox').getProperty('checked');
@ -1708,8 +1699,6 @@ @@ -1708,8 +1699,6 @@
// Listening Port
$('port_value').setProperty('value', pref.listen_port.toInt());
$('upnp_checkbox').setProperty('checked', pref.upnp);
$('random_port_checkbox').setProperty('checked', pref.random_port);
updatePortValueEnabled();
// Connections Limits
const max_connec = pref.max_connec.toInt();
@ -2018,13 +2007,12 @@ @@ -2018,13 +2007,12 @@
// Connection tab
// Listening Port
const listen_port = $('port_value').getProperty('value').toInt();
if (isNaN(listen_port) || listen_port < 1 || listen_port > 65535) {
alert("QBT_TR(The port used for incoming connections must be between 1 and 65535.)QBT_TR[CONTEXT=HttpServer]");
if (isNaN(listen_port) || (listen_port < 0) || (listen_port > 65535)) {
alert("QBT_TR(The port used for incoming connections must be between 0 and 65535.)QBT_TR[CONTEXT=HttpServer]");
return;
}
settings.set('listen_port', listen_port);
settings.set('upnp', $('upnp_checkbox').getProperty('checked'));
settings.set('random_port', $('random_port_checkbox').getProperty('checked'));
// Connections Limits
let max_connec = -1;

Loading…
Cancel
Save