@@ -45,6 +45,12 @@ static const char* SettingName(OptionsModel::OptionID option)
45
45
case OptionsModel::MapPortNatpmp: return " natpmp" ;
46
46
case OptionsModel::Listen: return " listen" ;
47
47
case OptionsModel::Server: return " server" ;
48
+ case OptionsModel::ProxyIP: return " proxy" ;
49
+ case OptionsModel::ProxyPort: return " proxy" ;
50
+ case OptionsModel::ProxyUse: return " proxy" ;
51
+ case OptionsModel::ProxyIPTor: return " onion" ;
52
+ case OptionsModel::ProxyPortTor: return " onion" ;
53
+ case OptionsModel::ProxyUseTor: return " onion" ;
48
54
default : throw std::logic_error (strprintf (" GUI option %i has no corresponding node setting." , option));
49
55
}
50
56
}
@@ -68,6 +74,14 @@ static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID optio
68
74
}
69
75
}
70
76
77
+ struct ProxySetting {
78
+ bool is_set;
79
+ QString ip;
80
+ QString port;
81
+ };
82
+ static ProxySetting ParseProxyString (const std::string& proxy);
83
+ static std::string ProxyString (bool is_set, QString ip, QString port);
84
+
71
85
OptionsModel::OptionsModel (interfaces::Node& node, QObject *parent) :
72
86
QAbstractListModel(parent), m_node{node}
73
87
{
@@ -81,6 +95,14 @@ void OptionsModel::addOverriddenOption(const std::string &option)
81
95
// Writes all missing QSettings with their default values
82
96
bool OptionsModel::Init (bilingual_str& error)
83
97
{
98
+ // Initialize display settings from stored settings.
99
+ ProxySetting proxy = ParseProxyString (SettingToString (node ().getPersistentSetting (" proxy" ), GetDefaultProxyAddress ().toStdString ()));
100
+ m_proxy_ip = proxy.ip ;
101
+ m_proxy_port = proxy.port ;
102
+ ProxySetting onion = ParseProxyString (SettingToString (node ().getPersistentSetting (" onion" ), GetDefaultProxyAddress ().toStdString ()));
103
+ m_onion_ip = onion.ip ;
104
+ m_onion_port = onion.port ;
105
+
84
106
checkAndMigrate ();
85
107
86
108
QSettings settings;
@@ -133,7 +155,7 @@ bool OptionsModel::Init(bilingual_str& error)
133
155
// These are shared with the core or have a command-line parameter
134
156
// and we want command-line parameters to overwrite the GUI settings.
135
157
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
136
- MapPortNatpmp, Listen, Server}) {
158
+ MapPortNatpmp, Listen, Server, ProxyUse, ProxyUseTor }) {
137
159
std::string setting = SettingName (option);
138
160
if (node ().isSettingIgnored (setting)) addOverriddenOption (" -" + setting);
139
161
try {
@@ -169,28 +191,6 @@ bool OptionsModel::Init(bilingual_str& error)
169
191
m_sub_fee_from_amount = settings.value (" SubFeeFromAmount" , false ).toBool ();
170
192
#endif
171
193
172
- // Network
173
-
174
- if (!settings.contains (" fUseProxy" ))
175
- settings.setValue (" fUseProxy" , false );
176
- if (!settings.contains (" addrProxy" ))
177
- settings.setValue (" addrProxy" , GetDefaultProxyAddress ());
178
- // Only try to set -proxy, if user has enabled fUseProxy
179
- if ((settings.value (" fUseProxy" ).toBool () && !gArgs .SoftSetArg (" -proxy" , settings.value (" addrProxy" ).toString ().toStdString ())))
180
- addOverriddenOption (" -proxy" );
181
- else if (!settings.value (" fUseProxy" ).toBool () && !gArgs .GetArg (" -proxy" , " " ).empty ())
182
- addOverriddenOption (" -proxy" );
183
-
184
- if (!settings.contains (" fUseSeparateProxyTor" ))
185
- settings.setValue (" fUseSeparateProxyTor" , false );
186
- if (!settings.contains (" addrSeparateProxyTor" ))
187
- settings.setValue (" addrSeparateProxyTor" , GetDefaultProxyAddress ());
188
- // Only try to set -onion, if user has enabled fUseSeparateProxyTor
189
- if ((settings.value (" fUseSeparateProxyTor" ).toBool () && !gArgs .SoftSetArg (" -onion" , settings.value (" addrSeparateProxyTor" ).toString ().toStdString ())))
190
- addOverriddenOption (" -onion" );
191
- else if (!settings.value (" fUseSeparateProxyTor" ).toBool () && !gArgs .GetArg (" -onion" , " " ).empty ())
192
- addOverriddenOption (" -onion" );
193
-
194
194
// Display
195
195
if (!settings.contains (" language" ))
196
196
settings.setValue (" language" , " " );
@@ -257,31 +257,30 @@ int OptionsModel::rowCount(const QModelIndex & parent) const
257
257
return OptionIDRowCount;
258
258
}
259
259
260
- struct ProxySetting {
261
- bool is_set;
262
- QString ip;
263
- QString port;
264
- };
265
-
266
- static ProxySetting GetProxySetting (QSettings &settings, const QString &name)
260
+ static ProxySetting ParseProxyString (const QString& proxy)
267
261
{
268
262
static const ProxySetting default_val = {false , DEFAULT_GUI_PROXY_HOST, QString (" %1" ).arg (DEFAULT_GUI_PROXY_PORT)};
269
263
// Handle the case that the setting is not set at all
270
- if (!settings. contains (name )) {
264
+ if (proxy. isEmpty ( )) {
271
265
return default_val;
272
266
}
273
267
// contains IP at index 0 and port at index 1
274
- QStringList ip_port = GUIUtil::SplitSkipEmptyParts (settings. value (name). toString () , " :" );
268
+ QStringList ip_port = GUIUtil::SplitSkipEmptyParts (proxy , " :" );
275
269
if (ip_port.size () == 2 ) {
276
270
return {true , ip_port.at (0 ), ip_port.at (1 )};
277
271
} else { // Invalid: return default
278
272
return default_val;
279
273
}
280
274
}
281
275
282
- static void SetProxySetting (QSettings &settings, const QString &name, const ProxySetting &ip_port )
276
+ static ProxySetting ParseProxyString ( const std::string& proxy )
283
277
{
284
- settings.setValue (name, QString{ip_port.ip + QLatin1Char (' :' ) + ip_port.port });
278
+ return ParseProxyString (QString::fromStdString (proxy));
279
+ }
280
+
281
+ static std::string ProxyString (bool is_set, QString ip, QString port)
282
+ {
283
+ return is_set ? QString (ip + " :" + port).toStdString () : " " ;
285
284
}
286
285
287
286
static const QString GetDefaultProxyAddress ()
@@ -367,19 +366,19 @@ QVariant OptionsModel::getOption(OptionID option) const
367
366
368
367
// default proxy
369
368
case ProxyUse:
370
- return settings. value ( " fUseProxy " , false ) ;
369
+ return ParseProxyString ( SettingToString ( setting (), " " )). is_set ;
371
370
case ProxyIP:
372
- return GetProxySetting (settings, " addrProxy " ). ip ;
371
+ return m_proxy_ip ;
373
372
case ProxyPort:
374
- return GetProxySetting (settings, " addrProxy " ). port ;
373
+ return m_proxy_port ;
375
374
376
375
// separate Tor proxy
377
376
case ProxyUseTor:
378
- return settings. value ( " fUseSeparateProxyTor " , false ) ;
377
+ return ParseProxyString ( SettingToString ( setting (), " " )). is_set ;
379
378
case ProxyIPTor:
380
- return GetProxySetting (settings, " addrSeparateProxyTor " ). ip ;
379
+ return m_onion_ip ;
381
380
case ProxyPortTor:
382
- return GetProxySetting (settings, " addrSeparateProxyTor " ). port ;
381
+ return m_onion_port ;
383
382
384
383
#ifdef ENABLE_WALLET
385
384
case SpendZeroConfChange:
@@ -458,55 +457,55 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
458
457
459
458
// default proxy
460
459
case ProxyUse:
461
- if (settings. value ( " fUseProxy " ) != value ) {
462
- settings. setValue ( " fUseProxy " , value.toBool ());
460
+ if (changed () ) {
461
+ update ( ProxyString ( value.toBool (), m_proxy_ip, m_proxy_port ));
463
462
setRestartRequired (true );
464
463
}
465
464
break ;
466
- case ProxyIP: {
467
- auto ip_port = GetProxySetting (settings, " addrProxy" );
468
- if (!ip_port.is_set || ip_port.ip != value.toString ()) {
469
- ip_port.ip = value.toString ();
470
- SetProxySetting (settings, " addrProxy" , ip_port);
471
- setRestartRequired (true );
465
+ case ProxyIP:
466
+ if (changed ()) {
467
+ m_proxy_ip = value.toString ();
468
+ if (getOption (ProxyUse).toBool ()) {
469
+ update (ProxyString (true , m_proxy_ip, m_proxy_port));
470
+ setRestartRequired (true );
471
+ }
472
472
}
473
- }
474
- break ;
475
- case ProxyPort: {
476
- auto ip_port = GetProxySetting (settings, " addrProxy " );
477
- if (!ip_port. is_set || ip_port. port != value. toString ()) {
478
- ip_port. port = value. toString ( );
479
- SetProxySetting (settings, " addrProxy " , ip_port );
480
- setRestartRequired ( true );
473
+ break ;
474
+ case ProxyPort:
475
+ if ( changed ()) {
476
+ m_proxy_port = value. toString ( );
477
+ if ( getOption (ProxyUse). toBool ()) {
478
+ update ( ProxyString ( true , m_proxy_ip, m_proxy_port) );
479
+ setRestartRequired ( true );
480
+ }
481
481
}
482
- }
483
- break ;
482
+ break ;
484
483
485
484
// separate Tor proxy
486
485
case ProxyUseTor:
487
- if (settings. value ( " fUseSeparateProxyTor " ) != value ) {
488
- settings. setValue ( " fUseSeparateProxyTor " , value.toBool ());
486
+ if (changed () ) {
487
+ update ( ProxyString ( value.toBool (), m_onion_ip, m_onion_port ));
489
488
setRestartRequired (true );
490
489
}
491
490
break ;
492
- case ProxyIPTor: {
493
- auto ip_port = GetProxySetting (settings, " addrSeparateProxyTor" );
494
- if (!ip_port.is_set || ip_port.ip != value.toString ()) {
495
- ip_port.ip = value.toString ();
496
- SetProxySetting (settings, " addrSeparateProxyTor" , ip_port);
497
- setRestartRequired (true );
491
+ case ProxyIPTor:
492
+ if (changed ()) {
493
+ m_onion_ip = value.toString ();
494
+ if (getOption (ProxyUseTor).toBool ()) {
495
+ update (ProxyString (true , m_onion_ip, m_onion_port));
496
+ setRestartRequired (true );
497
+ }
498
498
}
499
- }
500
- break ;
501
- case ProxyPortTor: {
502
- auto ip_port = GetProxySetting (settings, " addrSeparateProxyTor " );
503
- if (!ip_port. is_set || ip_port. port != value. toString ()) {
504
- ip_port. port = value. toString ( );
505
- SetProxySetting (settings, " addrSeparateProxyTor " , ip_port );
506
- setRestartRequired ( true );
499
+ break ;
500
+ case ProxyPortTor:
501
+ if ( changed ()) {
502
+ m_onion_port = value. toString ( );
503
+ if ( getOption (ProxyUseTor). toBool ()) {
504
+ update ( ProxyString ( true , m_onion_ip, m_onion_port) );
505
+ setRestartRequired ( true );
506
+ }
507
507
}
508
- }
509
- break ;
508
+ break ;
510
509
511
510
#ifdef ENABLE_WALLET
512
511
case SpendZeroConfChange:
@@ -650,7 +649,17 @@ void OptionsModel::checkAndMigrate()
650
649
if (!settings.contains (qt_name)) return ;
651
650
QVariant value = settings.value (qt_name);
652
651
if (node ().getPersistentSetting (SettingName (option)).isNull ()) {
653
- setOption (option, value);
652
+ if (option == ProxyIP) {
653
+ ProxySetting parsed = ParseProxyString (value.toString ());
654
+ setOption (ProxyIP, parsed.ip );
655
+ setOption (ProxyPort, parsed.port );
656
+ } else if (option == ProxyIPTor) {
657
+ ProxySetting parsed = ParseProxyString (value.toString ());
658
+ setOption (ProxyIPTor, parsed.ip );
659
+ setOption (ProxyPortTor, parsed.port );
660
+ } else {
661
+ setOption (option, value);
662
+ }
654
663
}
655
664
settings.remove (qt_name);
656
665
};
@@ -665,6 +674,10 @@ void OptionsModel::checkAndMigrate()
665
674
migrate_setting (MapPortNatpmp, " fUseNatpmp" );
666
675
migrate_setting (Listen, " fListen" );
667
676
migrate_setting (Server, " server" );
677
+ migrate_setting (ProxyIP, " addrProxy" );
678
+ migrate_setting (ProxyUse, " fUseProxy" );
679
+ migrate_setting (ProxyIPTor, " addrSeparateProxyTor" );
680
+ migrate_setting (ProxyUseTor, " fUseSeparateProxyTor" );
668
681
669
682
// In case migrating QSettings caused any settings value to change, rerun
670
683
// parameter interaction code to update other settings. This is particularly
0 commit comments