aboutsummaryrefslogtreecommitdiff
path: root/src/qt/optionsmodel.cpp
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2022-04-18 19:19:02 -0400
committerRyan Ofsky <ryan@ofsky.org>2022-05-26 11:05:10 -0400
commitd2ada6e63583cad91e92b49c4dbf8c7ff086a758 (patch)
treeceb02927072e15fa83e0cbead1bdcec9a78ae8e6 /src/qt/optionsmodel.cpp
parent1dc4fc29c1086420b7dc51b20c0b7a18fecb4462 (diff)
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)
Diffstat (limited to 'src/qt/optionsmodel.cpp')
-rw-r--r--src/qt/optionsmodel.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index ba5c5e03e9..52327dd9f9 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -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");
}