mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-12 19:20:42 +02:00
Merge 7107 via qtnetworkport-28+knots
This commit is contained in:
commit
77f2e52bf2
@ -16,6 +16,7 @@
|
||||
#include <util/fs.h>
|
||||
#include <util/fs_helpers.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <codecvt> /* for codecvt_utf8_utf16 */
|
||||
@ -559,6 +560,11 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
|
||||
ForceSetArgV(strArg, common::SettingsValue{strValue});
|
||||
}
|
||||
|
||||
void ArgsManager::ForceSetArg(const std::string& arg, const int64_t value)
|
||||
{
|
||||
ForceSetArg(arg, util::ToString(value));
|
||||
}
|
||||
|
||||
void ArgsManager::ForceSetArgV(const std::string& arg, const common::SettingsValue& value)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
|
@ -325,6 +325,7 @@ protected:
|
||||
// Forces an arg setting. Called by SoftSetArg() if the arg hasn't already
|
||||
// been set. Also called directly in testing.
|
||||
void ForceSetArg(const std::string& arg, const std::string& value);
|
||||
void ForceSetArg(const std::string& arg, int64_t value);
|
||||
void ForceSetArgV(const std::string& arg, const common::SettingsValue& value);
|
||||
|
||||
/**
|
||||
|
24
src/net.cpp
24
src/net.cpp
@ -3254,7 +3254,29 @@ bool CConnman::InitBinds(const Options& options)
|
||||
inaddr_any.s_addr = htonl(INADDR_ANY);
|
||||
const CService ipv4_any{inaddr_any, GetListenPort()}; // 0.0.0.0
|
||||
if (!Bind(ipv4_any, BF_REPORT_ERROR, NetPermissionFlags::None)) {
|
||||
return false;
|
||||
int defaultPort = Params().GetDefaultPort();
|
||||
// If listening failed and another port than the standard port was specified,
|
||||
// ask if the user wants to connect via the standard port for the network instead
|
||||
if (GetListenPort() != defaultPort) {
|
||||
bool fRet = uiInterface.ThreadSafeQuestion(
|
||||
strprintf(_("Do you want to use the standard network port for %s (port %s) instead?"), PACKAGE_NAME, defaultPort),
|
||||
strprintf(_("Listen on port %s failed.").translated, GetListenPort()),
|
||||
"", CClientUIInterface::MSG_INFORMATION | CClientUIInterface::MODAL | CClientUIInterface::BTN_OK | CClientUIInterface::BTN_ABORT);
|
||||
|
||||
if (fRet) {
|
||||
// FIXME: Unbind IPv6 on the other port
|
||||
|
||||
gArgs.ForceSetArg("-port", defaultPort);
|
||||
// Attempt to use standard port
|
||||
struct in6_addr inaddr6_any = IN6ADDR_ANY_INIT;
|
||||
Bind(CService(inaddr6_any, defaultPort), BF_NONE, NetPermissionFlags::None);
|
||||
struct in_addr inaddr_any;
|
||||
inaddr_any.s_addr = INADDR_ANY;
|
||||
if (!Bind(CService(inaddr_any, defaultPort), BF_REPORT_ERROR, NetPermissionFlags::None)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -315,6 +315,55 @@
|
||||
<string>&Network</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_Network">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Network_Port">
|
||||
<item>
|
||||
<widget class="QLabel" name="networkPortLabel">
|
||||
<property name="text">
|
||||
<string>Network &port</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>networkPort</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="networkPort">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>55</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>55</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Network port (e.g. 8333)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_Network_Port">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="mapPortUpnp">
|
||||
<property name="toolTip">
|
||||
|
@ -105,6 +105,9 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
|
||||
ui->pruneSize->setEnabled(false);
|
||||
connect(ui->prune, &QPushButton::toggled, ui->pruneSize, &QWidget::setEnabled);
|
||||
|
||||
ui->networkPort->setValidator(new QIntValidator(1024, 65535, this));
|
||||
connect(ui->networkPort, SIGNAL(textChanged(const QString&)), this, SLOT(checkLineEdit()));
|
||||
|
||||
/* Network elements init */
|
||||
#ifndef USE_UPNP
|
||||
ui->mapPortUpnp->setEnabled(false);
|
||||
@ -270,6 +273,7 @@ void OptionsDialog::setModel(OptionsModel *_model)
|
||||
/* Wallet */
|
||||
connect(ui->spendZeroConfChange, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
||||
/* Network */
|
||||
connect(ui->networkPort, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
|
||||
connect(ui->allowIncoming, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
||||
connect(ui->enableServer, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
||||
connect(ui->connectSocks, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
||||
@ -306,6 +310,7 @@ void OptionsDialog::setMapper()
|
||||
mapper->addMapping(ui->m_enable_psbt_controls, OptionsModel::EnablePSBTControls);
|
||||
|
||||
/* Network */
|
||||
mapper->addMapping(ui->networkPort, OptionsModel::NetworkPort);
|
||||
mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);
|
||||
mapper->addMapping(ui->mapPortNatpmp, OptionsModel::MapPortNatpmp);
|
||||
mapper->addMapping(ui->allowIncoming, OptionsModel::Listen);
|
||||
@ -335,6 +340,16 @@ void OptionsDialog::setMapper()
|
||||
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
|
||||
}
|
||||
|
||||
void OptionsDialog::checkLineEdit()
|
||||
{
|
||||
QLineEdit * const lineedit = qobject_cast<QLineEdit*>(QObject::sender());
|
||||
if (lineedit->hasAcceptableInput()) {
|
||||
lineedit->setStyleSheet("");
|
||||
} else {
|
||||
lineedit->setStyleSheet("color: red;");
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsDialog::setOkButtonState(bool fState)
|
||||
{
|
||||
ui->okButton->setEnabled(fState);
|
||||
@ -394,6 +409,25 @@ void OptionsDialog::on_openBitcoinConfButton_clicked()
|
||||
|
||||
void OptionsDialog::on_okButton_clicked()
|
||||
{
|
||||
for (int i = 0; i < ui->tabWidget->count(); ++i) {
|
||||
QWidget * const tab = ui->tabWidget->widget(i);
|
||||
Q_FOREACH(QObject* o, tab->children()) {
|
||||
QLineEdit * const lineedit = qobject_cast<QLineEdit*>(o);
|
||||
if (lineedit && !lineedit->hasAcceptableInput()) {
|
||||
int row = mapper->mappedSection(lineedit);
|
||||
if (model->data(model->index(row, 0), Qt::EditRole) == lineedit->text()) {
|
||||
// Allow unchanged fields through
|
||||
continue;
|
||||
}
|
||||
ui->tabWidget->setCurrentWidget(tab);
|
||||
lineedit->setFocus(Qt::OtherFocusReason);
|
||||
lineedit->selectAll();
|
||||
QMessageBox::critical(this, tr("Invalid setting"), tr("The value entered is invalid."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model->setData(model->index(OptionsModel::FontForMoney, 0), ui->moneyFont->itemData(ui->moneyFont->currentIndex()));
|
||||
model->setData(model->index(OptionsModel::FontForQRCodes, 0), ui->qrFont->itemData(ui->qrFont->currentIndex()));
|
||||
|
||||
|
@ -67,6 +67,7 @@ private Q_SLOTS:
|
||||
void updateProxyValidationState();
|
||||
/* query the networks, for which the default proxy is used */
|
||||
void updateDefaultProxyNets();
|
||||
void checkLineEdit();
|
||||
|
||||
Q_SIGNALS:
|
||||
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, uint16_t nProxyPort);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <qt/guiconstants.h>
|
||||
#include <qt/guiutil.h>
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <common/args.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <mapport.h>
|
||||
@ -244,6 +245,12 @@ bool OptionsModel::Init(bilingual_str& error)
|
||||
m_sub_fee_from_amount = settings.value("SubFeeFromAmount", false).toBool();
|
||||
#endif
|
||||
|
||||
// Network
|
||||
if (!settings.contains("nNetworkPort"))
|
||||
settings.setValue("nNetworkPort", (quint16)Params().GetDefaultPort());
|
||||
if (!gArgs.SoftSetArg("-port", settings.value("nNetworkPort").toString().toStdString()))
|
||||
addOverriddenOption("-port");
|
||||
|
||||
// Display
|
||||
if (settings.contains("FontForMoney")) {
|
||||
m_font_money = FontChoiceFromString(settings.value("FontForMoney").toString());
|
||||
@ -423,6 +430,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
|
||||
return m_show_tray_icon;
|
||||
case MinimizeToTray:
|
||||
return fMinimizeToTray;
|
||||
case NetworkPort:
|
||||
return settings.value("nNetworkPort");
|
||||
case MapPortUPnP:
|
||||
#ifdef USE_UPNP
|
||||
return SettingToBool(setting(), DEFAULT_UPNP);
|
||||
@ -549,6 +558,18 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std::
|
||||
fMinimizeToTray = value.toBool();
|
||||
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
||||
break;
|
||||
case NetworkPort:
|
||||
if (settings.value("nNetworkPort") != value) {
|
||||
// If the port input box is empty, set to default port
|
||||
if (value.toString().isEmpty()) {
|
||||
settings.setValue("nNetworkPort", (quint16)Params().GetDefaultPort());
|
||||
}
|
||||
else {
|
||||
settings.setValue("nNetworkPort", (quint16)value.toInt());
|
||||
}
|
||||
setRestartRequired(true);
|
||||
}
|
||||
break;
|
||||
case MapPortUPnP: // core option - can be changed on-the-fly
|
||||
if (changed()) {
|
||||
update(value.toBool());
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
StartAtStartup, // bool
|
||||
ShowTrayIcon, // bool
|
||||
MinimizeToTray, // bool
|
||||
NetworkPort, // int
|
||||
MapPortUPnP, // bool
|
||||
MapPortNatpmp, // bool
|
||||
MinimizeOnClose, // bool
|
||||
|
Loading…
Reference in New Issue
Block a user