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
settingsStorage->storeValue(newKey, Utils::String::fromEnum(torrentContentLayout)); settingsStorage->storeValue(newKey, Utils::String::fromEnum(torrentContentLayout));
settingsStorage->removeValue(oldKey); 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*/) bool upgrade(const bool /*ask*/)
{ {
exportWebUIHttpsFiles(); exportWebUIHttpsFiles();
upgradeTorrentContentLayout(); upgradeTorrentContentLayout();
upgradeListenPortSettings();
return true; return true;
} }

16
src/base/bittorrent/session.cpp

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

3
src/base/bittorrent/session.h

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

7
src/base/settingsstorage.cpp

@ -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 TransactionalSettings::read() const
{ {
QVariantHash res; QVariantHash res;

1
src/base/settingsstorage.h

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

7
src/gui/optionsdialog.cpp

@ -301,7 +301,6 @@ OptionsDialog::OptionsDialog(QWidget *parent)
void (QSpinBox::*qSpinBoxValueChanged)(int) = &QSpinBox::valueChanged; void (QSpinBox::*qSpinBoxValueChanged)(int) = &QSpinBox::valueChanged;
connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::enableProxy); 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 // Apply button is activated when a value is changed
// Behavior tab // Behavior tab
@ -409,7 +408,6 @@ OptionsDialog::OptionsDialog(QWidget *parent)
// Connection tab // Connection tab
connect(m_ui->comboProtocol, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton); connect(m_ui->comboProtocol, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
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->checkUPnP, &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->spinUploadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
@ -775,7 +773,6 @@ void OptionsDialog::saveOptions()
// Connection preferences // Connection preferences
session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m_ui->comboProtocol->currentIndex())); session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m_ui->comboProtocol->currentIndex()));
session->setPort(getPort()); session->setPort(getPort());
session->setUseRandomPort(m_ui->checkRandomPort->isChecked());
Net::PortForwarder::instance()->setEnabled(isUPnPEnabled()); Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024); session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024);
session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024); session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024);
@ -1072,10 +1069,8 @@ void OptionsDialog::loadOptions()
// Connection preferences // Connection preferences
m_ui->comboProtocol->setCurrentIndex(static_cast<int>(session->btProtocol())); 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->setValue(session->port());
m_ui->spinPort->setDisabled(m_ui->checkRandomPort->isChecked()); m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
intValue = session->maxConnections(); intValue = session->maxConnections();
if (intValue > 0) 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
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinPort"> <widget class="QSpinBox" name="spinPort">
<property name="minimum"> <property name="specialValueText">
<number>1</number> <string>Any</string>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>65535</number>
</property> </property>
<property name="value">
<number>8999</number>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -1500,13 +1497,6 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkRandomPort">
<property name="text">
<string>Use different port on each startup</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -2673,14 +2663,7 @@ Disable encryption: Only connect to peers without protocol encryption</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_16"> <layout class="QGridLayout" name="gridLayout_16">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QPlainTextEdit" name="textTrackers"> <widget class="QPlainTextEdit" name="textTrackers"/>
<property name="enabled">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -3288,7 +3271,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupEnableReverseProxySupport"> <widget class="QGroupBox" name="groupEnableReverseProxySupport">
<property name="title"> <property name="title">
<string>Enable reverse proxy support</string> <string>Enable reverse proxy support</string>
@ -3527,7 +3510,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<tabstop>lineEditAutoRun</tabstop> <tabstop>lineEditAutoRun</tabstop>
<tabstop>scrollArea_3</tabstop> <tabstop>scrollArea_3</tabstop>
<tabstop>randomButton</tabstop> <tabstop>randomButton</tabstop>
<tabstop>checkRandomPort</tabstop>
<tabstop>checkMaxConnecs</tabstop> <tabstop>checkMaxConnecs</tabstop>
<tabstop>spinMaxConnec</tabstop> <tabstop>spinMaxConnec</tabstop>
<tabstop>checkMaxConnecsPerTorrent</tabstop> <tabstop>checkMaxConnecsPerTorrent</tabstop>

12
src/webui/api/appcontroller.cpp

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

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

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

Loading…
Cancel
Save