@@ -109,13 +109,6 @@ void OptionsModel::addOverriddenOption(const std::string &option)
109
109
bool OptionsModel::Init (bilingual_str& error)
110
110
{
111
111
// Initialize display settings from stored settings.
112
- m_prune_size_gb = PruneSizeGB (node ().getPersistentSetting (" prune" ));
113
- ProxySetting proxy = ParseProxyString (SettingToString (node ().getPersistentSetting (" proxy" ), GetDefaultProxyAddress ().toStdString ()));
114
- m_proxy_ip = proxy.ip ;
115
- m_proxy_port = proxy.port ;
116
- ProxySetting onion = ParseProxyString (SettingToString (node ().getPersistentSetting (" onion" ), GetDefaultProxyAddress ().toStdString ()));
117
- m_onion_ip = onion.ip ;
118
- m_onion_port = onion.port ;
119
112
language = QString::fromStdString (SettingToString (node ().getPersistentSetting (" lang" ), " " ));
120
113
121
114
checkAndMigrate ();
@@ -290,8 +283,6 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
290
283
const util::SettingsValue cur_value = node ().getPersistentSetting (" prune" );
291
284
const util::SettingsValue new_value = PruneSetting (prune_target_gb > 0 , prune_target_gb);
292
285
293
- m_prune_size_gb = prune_target_gb;
294
-
295
286
// Force setting to take effect. It is still safe to change the value at
296
287
// this point because this function is only called after the intro screen is
297
288
// shown, before the node starts.
@@ -306,6 +297,11 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
306
297
// RestartRequired flag
307
298
node ().updateSetting (" prune" , new_value);
308
299
}
300
+
301
+ // Keep previous pruning size, if pruning was disabled.
302
+ if (PruneEnabled (cur_value)) {
303
+ node ().updateSetting (" prune-prev" , PruneEnabled (new_value) ? util::SettingsValue{} : cur_value);
304
+ }
309
305
}
310
306
311
307
// read QSettings values and return them
@@ -332,9 +328,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
332
328
return successful;
333
329
}
334
330
335
- QVariant OptionsModel::getOption (OptionID option) const
331
+ QVariant OptionsModel::getOption (OptionID option, const std::string& suffix ) const
336
332
{
337
- auto setting = [&]{ return node ().getPersistentSetting (SettingName (option)); };
333
+ auto setting = [&]{ return node ().getPersistentSetting (SettingName (option) + suffix ); };
338
334
339
335
QSettings settings;
340
336
switch (option) {
@@ -361,19 +357,30 @@ QVariant OptionsModel::getOption(OptionID option) const
361
357
362
358
// default proxy
363
359
case ProxyUse:
360
+ case ProxyUseTor:
364
361
return ParseProxyString (SettingToString (setting (), " " )).is_set ;
365
362
case ProxyIP:
366
- return m_proxy_ip;
363
+ case ProxyIPTor: {
364
+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
365
+ if (proxy.is_set ) {
366
+ return proxy.ip ;
367
+ } else if (suffix.empty ()) {
368
+ return getOption (option, " -prev" );
369
+ } else {
370
+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).ip ;
371
+ }
372
+ }
367
373
case ProxyPort:
368
- return m_proxy_port;
369
-
370
- // separate Tor proxy
371
- case ProxyUseTor:
372
- return ParseProxyString (SettingToString (setting (), " " )).is_set ;
373
- case ProxyIPTor:
374
- return m_onion_ip;
375
- case ProxyPortTor:
376
- return m_onion_port;
374
+ case ProxyPortTor: {
375
+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
376
+ if (proxy.is_set ) {
377
+ return proxy.port ;
378
+ } else if (suffix.empty ()) {
379
+ return getOption (option, " -prev" );
380
+ } else {
381
+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).port ;
382
+ }
383
+ }
377
384
378
385
#ifdef ENABLE_WALLET
379
386
case SpendZeroConfChange:
@@ -398,7 +405,9 @@ QVariant OptionsModel::getOption(OptionID option) const
398
405
case Prune:
399
406
return PruneEnabled (setting ());
400
407
case PruneSize:
401
- return m_prune_size_gb;
408
+ return PruneEnabled (setting ()) ? PruneSizeGB (setting ()) :
409
+ suffix.empty () ? getOption (option, " -prev" ) :
410
+ DEFAULT_PRUNE_TARGET_GB;
402
411
case DatabaseCache:
403
412
return qlonglong (SettingToInt (setting (), nDefaultDbCache));
404
413
case ThreadsScriptVerif:
@@ -412,10 +421,10 @@ QVariant OptionsModel::getOption(OptionID option) const
412
421
}
413
422
}
414
423
415
- bool OptionsModel::setOption (OptionID option, const QVariant& value)
424
+ bool OptionsModel::setOption (OptionID option, const QVariant& value, const std::string& suffix )
416
425
{
417
- auto changed = [&] { return value.isValid () && value != getOption (option); };
418
- auto update = [&](const util::SettingsValue& value) { return node ().updateSetting (SettingName (option), value); };
426
+ auto changed = [&] { return value.isValid () && value != getOption (option, suffix ); };
427
+ auto update = [&](const util::SettingsValue& value) { return node ().updateSetting (SettingName (option) + suffix , value); };
419
428
420
429
bool successful = true ; /* set to false on parse error */
421
430
QSettings settings;
@@ -453,51 +462,59 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
453
462
// default proxy
454
463
case ProxyUse:
455
464
if (changed ()) {
456
- update (ProxyString (value.toBool (), m_proxy_ip, m_proxy_port));
457
- setRestartRequired (true );
465
+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
466
+ update (ProxyString (value.toBool (), getOption (ProxyIP).toString (), getOption (ProxyPort).toString ()));
467
+ if (suffix.empty () && value.toBool ()) setOption (option, false , " -prev" );
468
+ if (suffix.empty ()) setRestartRequired (true );
458
469
}
459
470
break ;
460
471
case ProxyIP:
461
472
if (changed ()) {
462
- m_proxy_ip = value.toString ();
463
- if (getOption (ProxyUse).toBool ()) {
464
- update (ProxyString (true , m_proxy_ip, m_proxy_port));
465
- setRestartRequired (true );
473
+ if (!suffix.empty () || getOption (ProxyUse).toBool ()) {
474
+ update (ProxyString (true , value.toString (), getOption (ProxyPort).toString ()));
475
+ if (suffix.empty ()) setRestartRequired (true );
476
+ } else {
477
+ setOption (option, value, " -prev" );
466
478
}
467
479
}
468
480
break ;
469
481
case ProxyPort:
470
482
if (changed ()) {
471
- m_proxy_port = value.toString ();
472
- if (getOption (ProxyUse).toBool ()) {
473
- update (ProxyString (true , m_proxy_ip, m_proxy_port));
474
- setRestartRequired (true );
483
+ if (!suffix.empty () || getOption (ProxyUse).toBool ()) {
484
+ update (ProxyString (true , getOption (ProxyIP).toString (), value.toString ()));
485
+ if (suffix.empty ()) setRestartRequired (true );
486
+ } else {
487
+ setOption (option, value, " -prev" );
475
488
}
476
489
}
477
490
break ;
478
491
479
492
// separate Tor proxy
480
493
case ProxyUseTor:
481
494
if (changed ()) {
482
- update (ProxyString (value.toBool (), m_onion_ip, m_onion_port));
483
- setRestartRequired (true );
495
+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
496
+ update (ProxyString (value.toBool (), getOption (ProxyIPTor).toString (), getOption (ProxyPortTor).toString ()));
497
+ if (suffix.empty () && value.toBool ()) setOption (option, false , " -prev" );
498
+ if (suffix.empty ()) setRestartRequired (true );
484
499
}
485
500
break ;
486
501
case ProxyIPTor:
487
502
if (changed ()) {
488
- m_onion_ip = value.toString ();
489
- if (getOption (ProxyUseTor).toBool ()) {
490
- update (ProxyString (true , m_onion_ip, m_onion_port));
491
- setRestartRequired (true );
503
+ if (!suffix.empty () || getOption (ProxyUseTor).toBool ()) {
504
+ update (ProxyString (true , value.toString (), getOption (ProxyPortTor).toString ()));
505
+ if (suffix.empty ()) setRestartRequired (true );
506
+ } else {
507
+ setOption (option, value, " -prev" );
492
508
}
493
509
}
494
510
break ;
495
511
case ProxyPortTor:
496
512
if (changed ()) {
497
- m_onion_port = value.toString ();
498
- if (getOption (ProxyUseTor).toBool ()) {
499
- update (ProxyString (true , m_onion_ip, m_onion_port));
500
- setRestartRequired (true );
513
+ if (!suffix.empty () || getOption (ProxyUseTor).toBool ()) {
514
+ update (ProxyString (true , getOption (ProxyIPTor).toString (), value.toString ()));
515
+ if (suffix.empty ()) setRestartRequired (true );
516
+ } else {
517
+ setOption (option, value, " -prev" );
501
518
}
502
519
}
503
520
break ;
@@ -552,16 +569,19 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
552
569
break ;
553
570
case Prune:
554
571
if (changed ()) {
555
- update (PruneSetting (value.toBool (), m_prune_size_gb));
556
- setRestartRequired (true );
572
+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
573
+ update (PruneSetting (value.toBool (), getOption (PruneSize).toInt ()));
574
+ if (suffix.empty () && value.toBool ()) setOption (option, false , " -prev" );
575
+ if (suffix.empty ()) setRestartRequired (true );
557
576
}
558
577
break ;
559
578
case PruneSize:
560
579
if (changed ()) {
561
- m_prune_size_gb = ParsePruneSizeGB (value);
562
- if (getOption (Prune).toBool ()) {
563
- update (PruneSetting (true , m_prune_size_gb));
564
- setRestartRequired (true );
580
+ if (!suffix.empty () || getOption (Prune).toBool ()) {
581
+ update (PruneSetting (true , ParsePruneSizeGB (value)));
582
+ if (suffix.empty ()) setRestartRequired (true );
583
+ } else {
584
+ setOption (option, value, " -prev" );
565
585
}
566
586
}
567
587
break ;
0 commit comments