Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

optionsmodel.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2019 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #if defined(HAVE_CONFIG_H)
7 #include <config/dash-config.h>
8 #endif
9 
10 #include <qt/optionsmodel.h>
11 
12 #include <qt/bitcoinunits.h>
13 #include <qt/guiutil.h>
14 
15 #include <init.h>
16 #include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
17 #include <net.h>
18 #include <netbase.h>
19 #include <txdb.h> // for -dbcache defaults
20 
21 #ifdef ENABLE_WALLET
22 #include <wallet/wallet.h>
23 #include <wallet/walletdb.h>
24 
26 #endif
27 
28 #include <QNetworkProxy>
29 #include <QSettings>
30 #include <QStringList>
31 
32 const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
33 
34 static const QString GetDefaultProxyAddress();
35 
36 OptionsModel::OptionsModel(QObject *parent, bool resetSettings) :
37  QAbstractListModel(parent)
38 {
39  Init(resetSettings);
40 }
41 
42 void OptionsModel::addOverriddenOption(const std::string &option)
43 {
44  strOverriddenByCommandLine += QString::fromStdString(option) + "=" + QString::fromStdString(gArgs.GetArg(option, "")) + " ";
45 }
46 
47 // Writes all missing QSettings with their default values
48 void OptionsModel::Init(bool resetSettings)
49 {
50  if (resetSettings)
51  Reset();
52 
54 
55  QSettings settings;
56 
57  // Ensure restart flag is unset on client startup
58  setRestartRequired(false);
59 
60  // These are Qt-only settings:
61 
62  // Window
63  if (!settings.contains("fHideTrayIcon"))
64  settings.setValue("fHideTrayIcon", false);
65  fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
67 
68  if (!settings.contains("fMinimizeToTray"))
69  settings.setValue("fMinimizeToTray", false);
70  fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
71 
72  if (!settings.contains("fMinimizeOnClose"))
73  settings.setValue("fMinimizeOnClose", false);
74  fMinimizeOnClose = settings.value("fMinimizeOnClose").toBool();
75 
76  // Display
77  if (!settings.contains("nDisplayUnit"))
78  settings.setValue("nDisplayUnit", BitcoinUnits::DASH);
79  nDisplayUnit = settings.value("nDisplayUnit").toInt();
80 
81  if (!settings.contains("strThirdPartyTxUrls"))
82  settings.setValue("strThirdPartyTxUrls", "");
83  strThirdPartyTxUrls = settings.value("strThirdPartyTxUrls", "").toString();
84 
85  // Appearance
86  if (!settings.contains("theme"))
87  settings.setValue("theme", GUIUtil::getDefaultTheme());
88 
89  if (!settings.contains("fontFamily"))
90  settings.setValue("fontFamily", GUIUtil::fontFamilyToString(GUIUtil::getFontFamilyDefault()));
91 
92  if (!settings.contains("fontScale"))
93  settings.setValue("fontScale", GUIUtil::getFontScaleDefault());
94  if (!gArgs.SoftSetArg("-font-scale", settings.value("fontScale").toString().toStdString()))
95  addOverriddenOption("-font-scale");
96 
97  if (!settings.contains("fontWeightNormal"))
98  settings.setValue("fontWeightNormal", GUIUtil::weightToArg(GUIUtil::getFontWeightNormalDefault()));
99  if (!gArgs.SoftSetArg("-font-weight-normal", settings.value("fontWeightNormal").toString().toStdString()))
100  addOverriddenOption("-font-weight-normal");
101 
102  if (!settings.contains("fontWeightBold"))
103  settings.setValue("fontWeightBold", GUIUtil::weightToArg(GUIUtil::getFontWeightBoldDefault()));
104  if (!gArgs.SoftSetArg("-font-weight-bold", settings.value("fontWeightBold").toString().toStdString()))
105  addOverriddenOption("-font-weight-bold");
106 
107 #ifdef ENABLE_WALLET
108  if (!settings.contains("fCoinControlFeatures"))
109  settings.setValue("fCoinControlFeatures", false);
110  fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
111 
112  if (!settings.contains("digits"))
113  settings.setValue("digits", "2");
114 
115  // PrivateSend
116  if (!settings.contains("fPrivateSendEnabled")) {
117  settings.setValue("fPrivateSendEnabled", true);
118  }
119  if (!gArgs.SoftSetBoolArg("-enableprivatesend", settings.value("fPrivateSendEnabled").toBool())) {
120  addOverriddenOption("-enableprivatesend");
121  }
122 
123  if (!settings.contains("fShowAdvancedPSUI"))
124  settings.setValue("fShowAdvancedPSUI", false);
125  fShowAdvancedPSUI = settings.value("fShowAdvancedPSUI", false).toBool();
126 
127  if (!settings.contains("fShowPrivateSendPopups"))
128  settings.setValue("fShowPrivateSendPopups", true);
129 
130  if (!settings.contains("fLowKeysWarning"))
131  settings.setValue("fLowKeysWarning", true);
132 #endif // ENABLE_WALLET
133 
134  // These are shared with the core or have a command-line parameter
135  // and we want command-line parameters to overwrite the GUI settings.
136  //
137  // If setting doesn't exist create it with defaults.
138  //
139  // If gArgs.SoftSetArg() or gArgs.SoftSetBoolArg() return false we were overridden
140  // by command-line and show this in the UI.
141 
142  // Main
143  if (!settings.contains("nDatabaseCache"))
144  settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
145  if (!gArgs.SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
146  addOverriddenOption("-dbcache");
147 
148  if (!settings.contains("nThreadsScriptVerif"))
149  settings.setValue("nThreadsScriptVerif", DEFAULT_SCRIPTCHECK_THREADS);
150  if (!gArgs.SoftSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString()))
151  addOverriddenOption("-par");
152 
153  // Wallet
154 #ifdef ENABLE_WALLET
155  if (!settings.contains("bSpendZeroConfChange"))
156  settings.setValue("bSpendZeroConfChange", true);
157  if (!gArgs.SoftSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool()))
158  addOverriddenOption("-spendzeroconfchange");
159 
160  // PrivateSend
161  if (!settings.contains("nPrivateSendRounds"))
162  settings.setValue("nPrivateSendRounds", DEFAULT_PRIVATESEND_ROUNDS);
163  if (!gArgs.SoftSetArg("-privatesendrounds", settings.value("nPrivateSendRounds").toString().toStdString()))
164  addOverriddenOption("-privatesendrounds");
165  privateSendClient.nPrivateSendRounds = settings.value("nPrivateSendRounds").toInt();
166 
167  if (!settings.contains("nPrivateSendAmount")) {
168  // for migration from old settings
169  if (!settings.contains("nAnonymizeDashAmount"))
170  settings.setValue("nPrivateSendAmount", DEFAULT_PRIVATESEND_AMOUNT);
171  else
172  settings.setValue("nPrivateSendAmount", settings.value("nAnonymizeDashAmount").toInt());
173  }
174  if (!gArgs.SoftSetArg("-privatesendamount", settings.value("nPrivateSendAmount").toString().toStdString()))
175  addOverriddenOption("-privatesendamount");
176  privateSendClient.nPrivateSendAmount = settings.value("nPrivateSendAmount").toInt();
177 
178  if (!settings.contains("fPrivateSendMultiSession"))
179  settings.setValue("fPrivateSendMultiSession", DEFAULT_PRIVATESEND_MULTISESSION);
180  if (!gArgs.SoftSetBoolArg("-privatesendmultisession", settings.value("fPrivateSendMultiSession").toBool()))
181  addOverriddenOption("-privatesendmultisession");
182  privateSendClient.fPrivateSendMultiSession = settings.value("fPrivateSendMultiSession").toBool();
183 #endif
184 
185  // Network
186  if (!settings.contains("fUseUPnP"))
187  settings.setValue("fUseUPnP", DEFAULT_UPNP);
188  if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
189  addOverriddenOption("-upnp");
190 
191  if (!settings.contains("fListen"))
192  settings.setValue("fListen", DEFAULT_LISTEN);
193  if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool()))
194  addOverriddenOption("-listen");
195 
196  if (!settings.contains("fUseProxy"))
197  settings.setValue("fUseProxy", false);
198  if (!settings.contains("addrProxy"))
199  settings.setValue("addrProxy", GetDefaultProxyAddress());
200  // Only try to set -proxy, if user has enabled fUseProxy
201  if (settings.value("fUseProxy").toBool() && !gArgs.SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
202  addOverriddenOption("-proxy");
203  else if(!settings.value("fUseProxy").toBool() && !gArgs.GetArg("-proxy", "").empty())
204  addOverriddenOption("-proxy");
205 
206  if (!settings.contains("fUseSeparateProxyTor"))
207  settings.setValue("fUseSeparateProxyTor", false);
208  if (!settings.contains("addrSeparateProxyTor"))
209  settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
210  // Only try to set -onion, if user has enabled fUseSeparateProxyTor
211  if (settings.value("fUseSeparateProxyTor").toBool() && !gArgs.SoftSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString()))
212  addOverriddenOption("-onion");
213  else if(!settings.value("fUseSeparateProxyTor").toBool() && !gArgs.GetArg("-onion", "").empty())
214  addOverriddenOption("-onion");
215 
216  // Display
217  if (!settings.contains("language"))
218  settings.setValue("language", "");
219  if (!gArgs.SoftSetArg("-lang", settings.value("language").toString().toStdString()))
220  addOverriddenOption("-lang");
221 
222  language = settings.value("language").toString();
223 }
224 
228 static void CopySettings(QSettings& dst, const QSettings& src)
229 {
230  for (const QString& key : src.allKeys()) {
231  dst.setValue(key, src.value(key));
232  }
233 }
234 
236 static void BackupSettings(const fs::path& filename, const QSettings& src)
237 {
238  qWarning() << "Backing up GUI settings to" << GUIUtil::boostPathToQString(filename);
239  QSettings dst(GUIUtil::boostPathToQString(filename), QSettings::IniFormat);
240  dst.clear();
241  CopySettings(dst, src);
242 }
243 
245 {
246  QSettings settings;
247 
248  // Backup old settings to chain-specific datadir for troubleshooting
249  BackupSettings(GetDataDir(true) / "guisettings.ini.bak", settings);
250 
251  // Remove all entries from our QSettings object
252  settings.clear();
253 
254  // default setting for OptionsModel::StartAtStartup - disabled
257 }
258 
259 int OptionsModel::rowCount(const QModelIndex & parent) const
260 {
261  return OptionIDRowCount;
262 }
263 
264 struct ProxySetting {
265  bool is_set;
266  QString ip;
267  QString port;
268 };
269 
270 static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
271 {
272  static const ProxySetting default_val = {false, DEFAULT_GUI_PROXY_HOST, QString("%1").arg(DEFAULT_GUI_PROXY_PORT)};
273  // Handle the case that the setting is not set at all
274  if (!settings.contains(name)) {
275  return default_val;
276  }
277  // contains IP at index 0 and port at index 1
278  QStringList ip_port = settings.value(name).toString().split(":", QString::SkipEmptyParts);
279  if (ip_port.size() == 2) {
280  return {true, ip_port.at(0), ip_port.at(1)};
281  } else { // Invalid: return default
282  return default_val;
283  }
284 }
285 
286 static void SetProxySetting(QSettings &settings, const QString &name, const ProxySetting &ip_port)
287 {
288  settings.setValue(name, ip_port.ip + ":" + ip_port.port);
289 }
290 
291 static const QString GetDefaultProxyAddress()
292 {
293  return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
294 }
295 
296 // read QSettings values and return them
297 QVariant OptionsModel::data(const QModelIndex & index, int role) const
298 {
299  if(role == Qt::EditRole)
300  {
301  QSettings settings;
302  switch(index.row())
303  {
304  case StartAtStartup:
306  case HideTrayIcon:
307  return fHideTrayIcon;
308  case MinimizeToTray:
309  return fMinimizeToTray;
310  case MapPortUPnP:
311 #ifdef USE_UPNP
312  return settings.value("fUseUPnP");
313 #else
314  return false;
315 #endif
316  case MinimizeOnClose:
317  return fMinimizeOnClose;
318 
319  // default proxy
320  case ProxyUse:
321  return settings.value("fUseProxy", false);
322  case ProxyIP:
323  return GetProxySetting(settings, "addrProxy").ip;
324  case ProxyPort:
325  return GetProxySetting(settings, "addrProxy").port;
326 
327  // separate Tor proxy
328  case ProxyUseTor:
329  return settings.value("fUseSeparateProxyTor", false);
330  case ProxyIPTor:
331  return GetProxySetting(settings, "addrSeparateProxyTor").ip;
332  case ProxyPortTor:
333  return GetProxySetting(settings, "addrSeparateProxyTor").port;
334 
335 #ifdef ENABLE_WALLET
336  case SpendZeroConfChange:
337  return settings.value("bSpendZeroConfChange");
338  case ShowMasternodesTab:
339  return settings.value("fShowMasternodesTab");
340  case PrivateSendEnabled:
341  return settings.value("fPrivateSendEnabled");
342  case ShowAdvancedPSUI:
343  return fShowAdvancedPSUI;
345  return settings.value("fShowPrivateSendPopups");
346  case LowKeysWarning:
347  return settings.value("fLowKeysWarning");
348  case PrivateSendRounds:
349  return settings.value("nPrivateSendRounds");
350  case PrivateSendAmount:
351  return settings.value("nPrivateSendAmount");
353  return settings.value("fPrivateSendMultiSession");
354 #endif
355  case DisplayUnit:
356  return nDisplayUnit;
357  case ThirdPartyTxUrls:
358  return strThirdPartyTxUrls;
359 #ifdef ENABLE_WALLET
360  case Digits:
361  return settings.value("digits");
362 #endif // ENABLE_WALLET
363  case Theme:
364  return settings.value("theme");
365  case FontFamily:
366  return settings.value("fontFamily");
367  case FontScale:
368  return settings.value("fontScale");
369  case FontWeightNormal: {
370  QFont::Weight weight;
371  GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight);
372  return GUIUtil::supportedWeightToIndex(weight);
373  }
374  case FontWeightBold: {
375  QFont::Weight weight;
376  GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight);
377  return GUIUtil::supportedWeightToIndex(weight);
378  }
379  case Language:
380  return settings.value("language");
381 #ifdef ENABLE_WALLET
382  case CoinControlFeatures:
383  return fCoinControlFeatures;
384 #endif // ENABLE_WALLET
385  case DatabaseCache:
386  return settings.value("nDatabaseCache");
387  case ThreadsScriptVerif:
388  return settings.value("nThreadsScriptVerif");
389  case Listen:
390  return settings.value("fListen");
391  default:
392  return QVariant();
393  }
394  }
395  return QVariant();
396 }
397 
398 // write QSettings values
399 bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
400 {
401  bool successful = true; /* set to false on parse error */
402  if(role == Qt::EditRole)
403  {
404  QSettings settings;
405  switch(index.row())
406  {
407  case StartAtStartup:
408  successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
409  break;
410  case HideTrayIcon:
411  fHideTrayIcon = value.toBool();
412  settings.setValue("fHideTrayIcon", fHideTrayIcon);
414  break;
415  case MinimizeToTray:
416  fMinimizeToTray = value.toBool();
417  settings.setValue("fMinimizeToTray", fMinimizeToTray);
418  break;
419  case MapPortUPnP: // core option - can be changed on-the-fly
420  settings.setValue("fUseUPnP", value.toBool());
421  MapPort(value.toBool());
422  break;
423  case MinimizeOnClose:
424  fMinimizeOnClose = value.toBool();
425  settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
426  break;
427 
428  // default proxy
429  case ProxyUse:
430  if (settings.value("fUseProxy") != value) {
431  settings.setValue("fUseProxy", value.toBool());
432  setRestartRequired(true);
433  }
434  break;
435  case ProxyIP: {
436  auto ip_port = GetProxySetting(settings, "addrProxy");
437  if (!ip_port.is_set || ip_port.ip != value.toString()) {
438  ip_port.ip = value.toString();
439  SetProxySetting(settings, "addrProxy", ip_port);
440  setRestartRequired(true);
441  }
442  }
443  break;
444  case ProxyPort: {
445  auto ip_port = GetProxySetting(settings, "addrProxy");
446  if (!ip_port.is_set || ip_port.port != value.toString()) {
447  ip_port.port = value.toString();
448  SetProxySetting(settings, "addrProxy", ip_port);
449  setRestartRequired(true);
450  }
451  }
452  break;
453 
454  // separate Tor proxy
455  case ProxyUseTor:
456  if (settings.value("fUseSeparateProxyTor") != value) {
457  settings.setValue("fUseSeparateProxyTor", value.toBool());
458  setRestartRequired(true);
459  }
460  break;
461  case ProxyIPTor: {
462  auto ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
463  if (!ip_port.is_set || ip_port.ip != value.toString()) {
464  ip_port.ip = value.toString();
465  SetProxySetting(settings, "addrSeparateProxyTor", ip_port);
466  setRestartRequired(true);
467  }
468  }
469  break;
470  case ProxyPortTor: {
471  auto ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
472  if (!ip_port.is_set || ip_port.port != value.toString()) {
473  ip_port.port = value.toString();
474  SetProxySetting(settings, "addrSeparateProxyTor", ip_port);
475  setRestartRequired(true);
476  }
477  }
478  break;
479 
480 #ifdef ENABLE_WALLET
481  case SpendZeroConfChange:
482  if (settings.value("bSpendZeroConfChange") != value) {
483  settings.setValue("bSpendZeroConfChange", value);
484  setRestartRequired(true);
485  }
486  break;
487  case ShowMasternodesTab:
488  if (settings.value("fShowMasternodesTab") != value) {
489  settings.setValue("fShowMasternodesTab", value);
490  setRestartRequired(true);
491  }
492  break;
493  case PrivateSendEnabled:
494  if (settings.value("fPrivateSendEnabled") != value) {
495  settings.setValue("fPrivateSendEnabled", value.toBool());
496  Q_EMIT privateSendEnabledChanged();
497  }
498  break;
499  case ShowAdvancedPSUI:
500  if (settings.value("fShowAdvancedPSUI") != value) {
501  fShowAdvancedPSUI = value.toBool();
502  settings.setValue("fShowAdvancedPSUI", fShowAdvancedPSUI);
504  }
505  break;
507  settings.setValue("fShowPrivateSendPopups", value);
508  break;
509  case LowKeysWarning:
510  settings.setValue("fLowKeysWarning", value);
511  break;
512  case PrivateSendRounds:
513  if (settings.value("nPrivateSendRounds") != value)
514  {
515  privateSendClient.nPrivateSendRounds = value.toInt();
516  settings.setValue("nPrivateSendRounds", privateSendClient.nPrivateSendRounds);
517  Q_EMIT privateSendRoundsChanged();
518  }
519  break;
520  case PrivateSendAmount:
521  if (settings.value("nPrivateSendAmount") != value)
522  {
523  privateSendClient.nPrivateSendAmount = value.toInt();
524  settings.setValue("nPrivateSendAmount", privateSendClient.nPrivateSendAmount);
525  Q_EMIT privateSentAmountChanged();
526  }
527  break;
529  if (settings.value("fPrivateSendMultiSession") != value)
530  {
532  settings.setValue("fPrivateSendMultiSession", privateSendClient.fPrivateSendMultiSession);
533  }
534  break;
535 #endif
536  case DisplayUnit:
537  setDisplayUnit(value);
538  break;
539  case ThirdPartyTxUrls:
540  if (strThirdPartyTxUrls != value.toString()) {
541  strThirdPartyTxUrls = value.toString();
542  settings.setValue("strThirdPartyTxUrls", strThirdPartyTxUrls);
543  setRestartRequired(true);
544  }
545  break;
546 #ifdef ENABLE_WALLET
547  case Digits:
548  if (settings.value("digits") != value) {
549  settings.setValue("digits", value);
550  setRestartRequired(true);
551  }
552  break;
553 #endif // ENABLE_WALLET
554  case Theme:
555  // Set in AppearanceWidget::updateTheme slot now
556  // to allow instant theme changes.
557  break;
558  case FontFamily:
559  if (settings.value("fontFamily") != value) {
560  settings.setValue("fontFamily", value);
561  }
562  break;
563  case FontScale:
564  if (settings.value("fontScale") != value) {
565  settings.setValue("fontScale", value);
566  }
567  break;
568  case FontWeightNormal: {
569  int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromIndex(value.toInt()));
570  if (settings.value("fontWeightNormal") != nWeight) {
571  settings.setValue("fontWeightNormal", nWeight);
572  }
573  break;
574  }
575  case FontWeightBold: {
576  int nWeight = GUIUtil::weightToArg(GUIUtil::supportedWeightFromIndex(value.toInt()));
577  if (settings.value("fontWeightBold") != nWeight) {
578  settings.setValue("fontWeightBold", nWeight);
579  }
580  break;
581  }
582  case Language:
583  if (settings.value("language") != value) {
584  settings.setValue("language", value);
585  setRestartRequired(true);
586  }
587  break;
588 #ifdef ENABLE_WALLET
589  case CoinControlFeatures:
590  fCoinControlFeatures = value.toBool();
591  settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
593  break;
594 #endif // ENABLE_WALLET
595  case DatabaseCache:
596  if (settings.value("nDatabaseCache") != value) {
597  settings.setValue("nDatabaseCache", value);
598  setRestartRequired(true);
599  }
600  break;
601  case ThreadsScriptVerif:
602  if (settings.value("nThreadsScriptVerif") != value) {
603  settings.setValue("nThreadsScriptVerif", value);
604  setRestartRequired(true);
605  }
606  break;
607  case Listen:
608  if (settings.value("fListen") != value) {
609  settings.setValue("fListen", value);
610  setRestartRequired(true);
611  }
612  break;
613  default:
614  break;
615  }
616  }
617 
618  Q_EMIT dataChanged(index, index);
619 
620  return successful;
621 }
622 
624 void OptionsModel::setDisplayUnit(const QVariant &value)
625 {
626  if (!value.isNull())
627  {
628  QSettings settings;
629  nDisplayUnit = value.toInt();
630  settings.setValue("nDisplayUnit", nDisplayUnit);
632  }
633 }
634 
635 bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
636 {
637  // Directly query current base proxy, because
638  // GUI settings can be overridden with -proxy.
639  proxyType curProxy;
640  if (GetProxy(NET_IPV4, curProxy)) {
641  proxy.setType(QNetworkProxy::Socks5Proxy);
642  proxy.setHostName(QString::fromStdString(curProxy.proxy.ToStringIP()));
643  proxy.setPort(curProxy.proxy.GetPort());
644 
645  return true;
646  }
647  else
648  proxy.setType(QNetworkProxy::NoProxy);
649 
650  return false;
651 }
652 
654 {
655  Q_EMIT privateSendEnabledChanged();
656 }
657 
659 {
660  QSettings settings;
661  return settings.setValue("fRestartRequired", fRequired);
662 }
663 
665 {
666  QSettings settings;
667  return settings.value("fRestartRequired", false).toBool();
668 }
669 
671 {
672  // Migration of default values
673  // Check if the QSettings container was already loaded with this client version
674  QSettings settings;
675  static const char strSettingsVersionKey[] = "nSettingsVersion";
676  int settingsVersion = settings.contains(strSettingsVersionKey) ? settings.value(strSettingsVersionKey).toInt() : 0;
677  if (settingsVersion < CLIENT_VERSION)
678  {
679  // -dbcache was bumped from 100 to 300 in 0.13
680  // see https://github.com/bitcoin/bitcoin/pull/8273
681  // force people to upgrade to the new value if they are using 100MB
682  if (settingsVersion < 130000 && settings.contains("nDatabaseCache") && settings.value("nDatabaseCache").toLongLong() == 100)
683  settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
684 
685  settings.setValue(strSettingsVersionKey, CLIENT_VERSION);
686  }
687 
688  // Overwrite the 'addrProxy' setting in case it has been set to an illegal
689  // default value (see issue #12623; PR #12650).
690  if (settings.contains("addrProxy") && settings.value("addrProxy").toString().endsWith("%2")) {
691  settings.setValue("addrProxy", GetDefaultProxyAddress());
692  }
693 
694  // Overwrite the 'addrSeparateProxyTor' setting in case it has been set to an illegal
695  // default value (see issue #12623; PR #12650).
696  if (settings.contains("addrSeparateProxyTor") && settings.value("addrSeparateProxyTor").toString().endsWith("%2")) {
697  settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
698  }
699 }
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:85
unsigned short GetPort() const
Definition: netaddress.cpp:512
bool weightFromArg(int nArg, QFont::Weight &weight)
Convert weight value from args (0-8) to QFont::Weight.
Definition: guiutil.cpp:1313
FontFamily getFontFamilyDefault()
set/get font family: GUIUtil::fontFamily
Definition: guiutil.cpp:1303
int weightToArg(const QFont::Weight weight)
Convert QFont::Weight to an arg value (0-8)
Definition: guiutil.cpp:1334
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
static void BackupSettings(const fs::path &filename, const QSettings &src)
Back up a QSettings to an ini-formatted file.
QFont::Weight supportedWeightFromIndex(int nIndex)
Convert an index to a weight in the supported weights vector.
Definition: guiutil.cpp:1751
void addOverriddenOption(const std::string &option)
void hideTrayIconChanged(bool)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: util.cpp:840
bool getProxySettings(QNetworkProxy &proxy) const
static void CopySettings(QSettings &dst, const QSettings &src)
Helper function to copy contents from one QSettings to another.
static const int DEFAULT_PRIVATESEND_AMOUNT
QFont::Weight getFontWeightNormalDefault()
set/get normal font weight: GUIUtil::fontWeightNormal
Definition: guiutil.cpp:1351
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:76
QString language
Definition: optionsmodel.h:100
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:1103
void coinControlFeaturesChanged(bool)
QFont::Weight getFontWeightBoldDefault()
set/get bold font weight: GUIUtil::fontWeightBold
Definition: guiutil.cpp:1372
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn&#39;t already have a value.
Definition: util.cpp:832
bool fShowAdvancedPSUI
Definition: optionsmodel.h:104
std::string ToStringIP(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:261
const QString getDefaultTheme()
Return the name of the default theme `.
Definition: guiutil.cpp:1150
bool fMinimizeOnClose
Definition: optionsmodel.h:99
void MapPort(bool)
Definition: net.cpp:2065
void privateSentAmountChanged()
bool isRestartRequired() const
static const int DEFAULT_PRIVATESEND_ROUNDS
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
bool fHideTrayIcon
Definition: optionsmodel.h:97
OptionsModel(QObject *parent=0, bool resetSettings=false)
const char * name
Definition: rest.cpp:36
bool fMinimizeToTray
Definition: optionsmodel.h:98
QString fontFamilyToString(FontFamily family)
Definition: guiutil.cpp:1284
const char * DEFAULT_GUI_PROXY_HOST
int supportedWeightToIndex(QFont::Weight weight)
Convert a weight to an index in the supported weights vector.
Definition: guiutil.cpp:1758
static const int64_t nDefaultDbCache
-dbcache default (MiB)
Definition: txdb.h:29
void privateSendEnabledChanged()
void Init(bool resetSettings=false)
void displayUnitChanged(int unit)
bool fCoinControlFeatures
Definition: optionsmodel.h:103
void checkAndMigrate()
void advancedPSUIChanged(bool)
ArgsManager gArgs
Definition: util.cpp:108
CService proxy
Definition: netbase.h:37
void setRestartRequired(bool fRequired)
CPrivateSendClientManager privateSendClient
QString strThirdPartyTxUrls
Definition: optionsmodel.h:102
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
int getFontScaleDefault()
set/get font scale: GUIUtil::fontScale
Definition: guiutil.cpp:1388
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: util.cpp:808
void emitPrivateSendEnabledChanged()
static const bool DEFAULT_UPNP
-upnp default
Definition: net.h:81
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:556
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:1104
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:928
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:1828
int rowCount(const QModelIndex &parent=QModelIndex()) const
static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
static const int CLIENT_VERSION
dashd-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:38
void privateSendRoundsChanged()
static const bool DEFAULT_PRIVATESEND_MULTISESSION
static const QString GetDefaultProxyAddress()
static constexpr unsigned short DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:17
QString strOverriddenByCommandLine
Definition: optionsmodel.h:106
static void SetProxySetting(QSettings &settings, const QString &name, const ProxySetting &ip_port)
Released under the MIT license