@@ -43,6 +43,8 @@ static const char* SettingName(OptionsModel::OptionID option)
4343 case OptionsModel::ExternalSignerPath: return " signer" ;
4444 case OptionsModel::MapPortUPnP: return " upnp" ;
4545 case OptionsModel::MapPortNatpmp: return " natpmp" ;
46+ case OptionsModel::Listen: return " listen" ;
47+ case OptionsModel::Server: return " server" ;
4648 default : throw std::logic_error (strprintf (" GUI option %i has no corresponding node setting." , option));
4749 }
4850}
@@ -131,7 +133,7 @@ bool OptionsModel::Init(bilingual_str& error)
131133 // These are shared with the core or have a command-line parameter
132134 // and we want command-line parameters to overwrite the GUI settings.
133135 for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
134- MapPortNatpmp}) {
136+ MapPortNatpmp, Listen, Server }) {
135137 std::string setting = SettingName (option);
136138 if (node ().isSettingIgnored (setting)) addOverriddenOption (" -" + setting);
137139 try {
@@ -168,37 +170,6 @@ bool OptionsModel::Init(bilingual_str& error)
168170#endif
169171
170172 // Network
171- if (!settings.contains (" fListen" ))
172- settings.setValue (" fListen" , DEFAULT_LISTEN);
173- const bool listen{settings.value (" fListen" ).toBool ()};
174- if (!gArgs .SoftSetBoolArg (" -listen" , listen)) {
175- addOverriddenOption (" -listen" );
176- } else if (!listen) {
177- // We successfully set -listen=0, thus mimic the logic from InitParameterInteraction():
178- // "parameter interaction: -listen=0 -> setting -listenonion=0".
179- //
180- // Both -listen and -listenonion default to true.
181- //
182- // The call order is:
183- //
184- // InitParameterInteraction()
185- // would set -listenonion=0 if it sees -listen=0, but for bitcoin-qt with
186- // fListen=false -listen is 1 at this point
187- //
188- // OptionsModel::Init()
189- // (this method) can flip -listen from 1 to 0 if fListen=false
190- //
191- // AppInitParameterInteraction()
192- // raises an error if -listen=0 and -listenonion=1
193- gArgs .SoftSetBoolArg (" -listenonion" , false );
194- }
195-
196- if (!settings.contains (" server" )) {
197- settings.setValue (" server" , false );
198- }
199- if (!gArgs .SoftSetBoolArg (" -server" , settings.value (" server" ).toBool ())) {
200- addOverriddenOption (" -server" );
201- }
202173
203174 if (!settings.contains (" fUseProxy" ))
204175 settings.setValue (" fUseProxy" , false );
@@ -439,9 +410,9 @@ QVariant OptionsModel::getOption(OptionID option) const
439410 case ThreadsScriptVerif:
440411 return qlonglong (SettingToInt (setting (), DEFAULT_SCRIPTCHECK_THREADS));
441412 case Listen:
442- return settings. value ( " fListen " );
413+ return SettingToBool ( setting (), DEFAULT_LISTEN );
443414 case Server:
444- return settings. value ( " server " );
415+ return SettingToBool ( setting (), false );
445416 default :
446417 return QVariant ();
447418 }
@@ -610,14 +581,9 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
610581 }
611582 break ;
612583 case Listen:
613- if (settings.value (" fListen" ) != value) {
614- settings.setValue (" fListen" , value);
615- setRestartRequired (true );
616- }
617- break ;
618584 case Server:
619- if (settings. value ( " server " ) != value ) {
620- settings. setValue ( " server " , value);
585+ if (changed () ) {
586+ update ( value. toBool () );
621587 setRestartRequired (true );
622588 }
623589 break ;
@@ -697,4 +663,13 @@ void OptionsModel::checkAndMigrate()
697663#endif
698664 migrate_setting (MapPortUPnP, " fUseUPnP" );
699665 migrate_setting (MapPortNatpmp, " fUseNatpmp" );
666+ migrate_setting (Listen, " fListen" );
667+ migrate_setting (Server, " server" );
668+
669+ // In case migrating QSettings caused any settings value to change, rerun
670+ // parameter interaction code to update other settings. This is particularly
671+ // important for the -listen setting, which should cause -listenonion, -upnp,
672+ // and other settings to default to false if it was set to false.
673+ // (https://github.com/bitcoin-core/gui/issues/567).
674+ node ().initParameterInteraction ();
700675}
0 commit comments