mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Use spinbox special value to represent "Use any available port"
WebAPI functionality is preserved (deprecated) for now and should be removed in the future.
This commit is contained in:
parent
09e558ae0b
commit
49aab492e0
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +407,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_useAnyAvailablePort(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"))
|
||||||
@ -1421,13 +1420,12 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack)
|
|||||||
if (m_listenInterfaceConfigured)
|
if (m_listenInterfaceConfigured)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int port = useAnyAvailablePort() ? 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()))
|
||||||
{
|
{
|
||||||
@ -2751,16 +2749,6 @@ void Session::setPort(const int port)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Session::useAnyAvailablePort() const
|
|
||||||
{
|
|
||||||
return m_useAnyAvailablePort;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::setUseAnyAvailablePort(const bool value)
|
|
||||||
{
|
|
||||||
m_useAnyAvailablePort = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Session::networkInterface() const
|
QString Session::networkInterface() const
|
||||||
{
|
{
|
||||||
return m_networkInterface;
|
return m_networkInterface;
|
||||||
|
@ -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 useAnyAvailablePort() const;
|
|
||||||
void setUseAnyAvailablePort(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_useAnyAvailablePort;
|
|
||||||
CachedSettingValue<QString> m_networkInterface;
|
CachedSettingValue<QString> m_networkInterface;
|
||||||
CachedSettingValue<QString> m_networkInterfaceName;
|
CachedSettingValue<QString> m_networkInterfaceName;
|
||||||
CachedSettingValue<QString> m_networkInterfaceAddress;
|
CachedSettingValue<QString> m_networkInterfaceAddress;
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
|
@ -300,7 +300,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->useAnyPort, &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
|
||||||
@ -408,7 +407,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->useAnyPort, &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);
|
||||||
@ -770,7 +768,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->setUseAnyAvailablePort(m_ui->useAnyPort->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);
|
||||||
@ -1067,10 +1064,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->useAnyPort->setChecked(session->useAnyAvailablePort());
|
|
||||||
m_ui->spinPort->setValue(session->port());
|
m_ui->spinPort->setValue(session->port());
|
||||||
m_ui->spinPort->setDisabled(m_ui->useAnyPort->isChecked());
|
m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
|
||||||
|
|
||||||
intValue = session->maxConnections();
|
intValue = session->maxConnections();
|
||||||
if (intValue > 0)
|
if (intValue > 0)
|
||||||
|
@ -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>
|
||||||
@ -1490,13 +1487,6 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually</s
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="useAnyPort">
|
|
||||||
<property name="text">
|
|
||||||
<string>Use any available port</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkUPnP">
|
<widget class="QCheckBox" name="checkUPnP">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -3469,7 +3459,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
|
|||||||
<tabstop>customThemeFilePath</tabstop>
|
<tabstop>customThemeFilePath</tabstop>
|
||||||
<tabstop>checkStartPaused</tabstop>
|
<tabstop>checkStartPaused</tabstop>
|
||||||
<tabstop>spinPort</tabstop>
|
<tabstop>spinPort</tabstop>
|
||||||
<tabstop>useAnyPort</tabstop>
|
|
||||||
<tabstop>checkUPnP</tabstop>
|
<tabstop>checkUPnP</tabstop>
|
||||||
<tabstop>textWebUiUsername</tabstop>
|
<tabstop>textWebUiUsername</tabstop>
|
||||||
<tabstop>checkWebUi</tabstop>
|
<tabstop>checkWebUi</tabstop>
|
||||||
|
@ -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->useAnyAvailablePort();
|
|
||||||
// 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->setUseAnyAvailablePort(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());
|
||||||
|
@ -234,10 +234,6 @@
|
|||||||
<input type="text" id="port_value" style="width: 4em;" />
|
<input type="text" id="port_value" style="width: 4em;" />
|
||||||
<button style="margin-left: 1em;" onclick="qBittorrent.Preferences.generateRandomPort();">QBT_TR(Random)QBT_TR[CONTEXT=OptionsDialog]</button>
|
<button style="margin-left: 1em;" onclick="qBittorrent.Preferences.generateRandomPort();">QBT_TR(Random)QBT_TR[CONTEXT=OptionsDialog]</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="formRow">
|
|
||||||
<input type="checkbox" id="useAnyPortCheckbox" onclick="qBittorrent.Preferences.updatePortValueEnabled();" />
|
|
||||||
<label for="useAnyPortCheckbox">QBT_TR(Use any available port)QBT_TR[CONTEXT=OptionsDialog]</label>
|
|
||||||
</div>
|
|
||||||
<div class="formRow">
|
<div class="formRow">
|
||||||
<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>
|
||||||
@ -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 = $('useAnyPortCheckbox').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);
|
||||||
$('useAnyPortCheckbox').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', $('useAnyPortCheckbox').getProperty('checked'));
|
|
||||||
|
|
||||||
// Connections Limits
|
// Connections Limits
|
||||||
let max_connec = -1;
|
let max_connec = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user