@@ -41,6 +41,8 @@ static const char* SettingName(OptionsModel::OptionID option)
41
41
case OptionsModel::ThreadsScriptVerif: return " par" ;
42
42
case OptionsModel::SpendZeroConfChange: return " spendzeroconfchange" ;
43
43
case OptionsModel::ExternalSignerPath: return " signer" ;
44
+ case OptionsModel::MapPortUPnP: return " upnp" ;
45
+ case OptionsModel::MapPortNatpmp: return " natpmp" ;
44
46
default : throw std::logic_error (strprintf (" GUI option %i has no corresponding node setting." , option));
45
47
}
46
48
}
@@ -128,7 +130,8 @@ bool OptionsModel::Init(bilingual_str& error)
128
130
129
131
// These are shared with the core or have a command-line parameter
130
132
// and we want command-line parameters to overwrite the GUI settings.
131
- for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath}) {
133
+ for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
134
+ MapPortNatpmp}) {
132
135
std::string setting = SettingName (option);
133
136
if (node ().isSettingIgnored (setting)) addOverriddenOption (" -" + setting);
134
137
try {
@@ -165,18 +168,6 @@ bool OptionsModel::Init(bilingual_str& error)
165
168
#endif
166
169
167
170
// Network
168
- if (!settings.contains (" fUseUPnP" ))
169
- settings.setValue (" fUseUPnP" , DEFAULT_UPNP);
170
- if (!gArgs .SoftSetBoolArg (" -upnp" , settings.value (" fUseUPnP" ).toBool ()))
171
- addOverriddenOption (" -upnp" );
172
-
173
- if (!settings.contains (" fUseNatpmp" )) {
174
- settings.setValue (" fUseNatpmp" , DEFAULT_NATPMP);
175
- }
176
- if (!gArgs .SoftSetBoolArg (" -natpmp" , settings.value (" fUseNatpmp" ).toBool ())) {
177
- addOverriddenOption (" -natpmp" );
178
- }
179
-
180
171
if (!settings.contains (" fListen" ))
181
172
settings.setValue (" fListen" , DEFAULT_LISTEN);
182
173
const bool listen{settings.value (" fListen" ).toBool ()};
@@ -390,13 +381,13 @@ QVariant OptionsModel::getOption(OptionID option) const
390
381
return fMinimizeToTray ;
391
382
case MapPortUPnP:
392
383
#ifdef USE_UPNP
393
- return settings. value ( " fUseUPnP " );
384
+ return SettingToBool ( setting (), DEFAULT_UPNP );
394
385
#else
395
386
return false ;
396
387
#endif // USE_UPNP
397
388
case MapPortNatpmp:
398
389
#ifdef USE_NATPMP
399
- return settings. value ( " fUseNatpmp " );
390
+ return SettingToBool ( setting (), DEFAULT_NATPMP );
400
391
#else
401
392
return false ;
402
393
#endif // USE_NATPMP
@@ -478,10 +469,16 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
478
469
settings.setValue (" fMinimizeToTray" , fMinimizeToTray );
479
470
break ;
480
471
case MapPortUPnP: // core option - can be changed on-the-fly
481
- settings.setValue (" fUseUPnP" , value.toBool ());
472
+ if (changed ()) {
473
+ update (value.toBool ());
474
+ node ().mapPort (value.toBool (), getOption (MapPortNatpmp).toBool ());
475
+ }
482
476
break ;
483
477
case MapPortNatpmp: // core option - can be changed on-the-fly
484
- settings.setValue (" fUseNatpmp" , value.toBool ());
478
+ if (changed ()) {
479
+ update (value.toBool ());
480
+ node ().mapPort (getOption (MapPortUPnP).toBool (), value.toBool ());
481
+ }
485
482
break ;
486
483
case MinimizeOnClose:
487
484
fMinimizeOnClose = value.toBool ();
@@ -698,4 +695,6 @@ void OptionsModel::checkAndMigrate()
698
695
migrate_setting (SpendZeroConfChange, " bSpendZeroConfChange" );
699
696
migrate_setting (ExternalSignerPath, " external_signer_path" );
700
697
#endif
698
+ migrate_setting (MapPortUPnP, " fUseUPnP" );
699
+ migrate_setting (MapPortNatpmp, " fUseNatpmp" );
701
700
}
0 commit comments