Migrate -upnp and -natpmp settings from QSettings to settings.json
This also effectively reverts 58e8364dcdc4e57b0caac09f8402e6535301de9b from #18077, applying upnp and natpmp settings from the optionsmodel class instead of the optionsdialog class. This makes sense because model code, not view code is responsible for applying all other settings, and because leaving these settings half-applied in optionsmodel seems error prone and could lead to bugs. (These things were discussed a little in https://github.com/bitcoin/bitcoin/pull/18077#discussion_r560381734)
This commit is contained in:
parent
1dc4fc29c1
commit
d2ada6e635
@ -26,7 +26,6 @@
|
||||
#include <QIntValidator>
|
||||
#include <QLocale>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
|
||||
@ -56,10 +55,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
|
||||
#ifndef USE_NATPMP
|
||||
ui->mapPortNatpmp->setEnabled(false);
|
||||
#endif
|
||||
connect(this, &QDialog::accepted, [this](){
|
||||
QSettings settings;
|
||||
model->node().mapPort(settings.value("fUseUPnP").toBool(), settings.value("fUseNatpmp").toBool());
|
||||
});
|
||||
|
||||
ui->proxyIp->setEnabled(false);
|
||||
ui->proxyPort->setEnabled(false);
|
||||
|
||||
@ -41,6 +41,8 @@ static const char* SettingName(OptionsModel::OptionID option)
|
||||
case OptionsModel::ThreadsScriptVerif: return "par";
|
||||
case OptionsModel::SpendZeroConfChange: return "spendzeroconfchange";
|
||||
case OptionsModel::ExternalSignerPath: return "signer";
|
||||
case OptionsModel::MapPortUPnP: return "upnp";
|
||||
case OptionsModel::MapPortNatpmp: return "natpmp";
|
||||
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
|
||||
}
|
||||
}
|
||||
@ -128,7 +130,8 @@ bool OptionsModel::Init(bilingual_str& error)
|
||||
|
||||
// These are shared with the core or have a command-line parameter
|
||||
// and we want command-line parameters to overwrite the GUI settings.
|
||||
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath}) {
|
||||
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
|
||||
MapPortNatpmp}) {
|
||||
std::string setting = SettingName(option);
|
||||
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
|
||||
try {
|
||||
@ -165,18 +168,6 @@ bool OptionsModel::Init(bilingual_str& error)
|
||||
#endif
|
||||
|
||||
// Network
|
||||
if (!settings.contains("fUseUPnP"))
|
||||
settings.setValue("fUseUPnP", DEFAULT_UPNP);
|
||||
if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
||||
addOverriddenOption("-upnp");
|
||||
|
||||
if (!settings.contains("fUseNatpmp")) {
|
||||
settings.setValue("fUseNatpmp", DEFAULT_NATPMP);
|
||||
}
|
||||
if (!gArgs.SoftSetBoolArg("-natpmp", settings.value("fUseNatpmp").toBool())) {
|
||||
addOverriddenOption("-natpmp");
|
||||
}
|
||||
|
||||
if (!settings.contains("fListen"))
|
||||
settings.setValue("fListen", DEFAULT_LISTEN);
|
||||
const bool listen{settings.value("fListen").toBool()};
|
||||
@ -390,13 +381,13 @@ QVariant OptionsModel::getOption(OptionID option) const
|
||||
return fMinimizeToTray;
|
||||
case MapPortUPnP:
|
||||
#ifdef USE_UPNP
|
||||
return settings.value("fUseUPnP");
|
||||
return SettingToBool(setting(), DEFAULT_UPNP);
|
||||
#else
|
||||
return false;
|
||||
#endif // USE_UPNP
|
||||
case MapPortNatpmp:
|
||||
#ifdef USE_NATPMP
|
||||
return settings.value("fUseNatpmp");
|
||||
return SettingToBool(setting(), DEFAULT_NATPMP);
|
||||
#else
|
||||
return false;
|
||||
#endif // USE_NATPMP
|
||||
@ -478,10 +469,16 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
|
||||
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
||||
break;
|
||||
case MapPortUPnP: // core option - can be changed on-the-fly
|
||||
settings.setValue("fUseUPnP", value.toBool());
|
||||
if (changed()) {
|
||||
update(value.toBool());
|
||||
node().mapPort(value.toBool(), getOption(MapPortNatpmp).toBool());
|
||||
}
|
||||
break;
|
||||
case MapPortNatpmp: // core option - can be changed on-the-fly
|
||||
settings.setValue("fUseNatpmp", value.toBool());
|
||||
if (changed()) {
|
||||
update(value.toBool());
|
||||
node().mapPort(getOption(MapPortUPnP).toBool(), value.toBool());
|
||||
}
|
||||
break;
|
||||
case MinimizeOnClose:
|
||||
fMinimizeOnClose = value.toBool();
|
||||
@ -698,4 +695,6 @@ void OptionsModel::checkAndMigrate()
|
||||
migrate_setting(SpendZeroConfChange, "bSpendZeroConfChange");
|
||||
migrate_setting(ExternalSignerPath, "external_signer_path");
|
||||
#endif
|
||||
migrate_setting(MapPortUPnP, "fUseUPnP");
|
||||
migrate_setting(MapPortNatpmp, "fUseNatpmp");
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ void OptionTests::migrateSettings()
|
||||
QSettings settings;
|
||||
settings.setValue("nDatabaseCache", 600);
|
||||
settings.setValue("nThreadsScriptVerif", 12);
|
||||
settings.setValue("fUseUPnP", false);
|
||||
|
||||
settings.sync();
|
||||
|
||||
@ -42,6 +43,7 @@ void OptionTests::migrateSettings()
|
||||
QVERIFY(options.Init(error));
|
||||
QVERIFY(!settings.contains("nDatabaseCache"));
|
||||
QVERIFY(!settings.contains("nThreadsScriptVerif"));
|
||||
QVERIFY(!settings.contains("fUseUPnP"));
|
||||
|
||||
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
|
||||
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user