Dash Core  0.12.2.1
P2P Digital Currency
optionsdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
6 #include "config/dash-config.h"
7 #endif
8 
9 #include "optionsdialog.h"
10 #include "ui_optionsdialog.h"
11 
12 #include "bitcoinunits.h"
13 #include "guiutil.h"
14 #include "optionsmodel.h"
15 
16 #include "validation.h" // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS
17 #include "netbase.h"
18 #include "txdb.h" // for -dbcache defaults
19 
20 #ifdef ENABLE_WALLET
21 #include "wallet/wallet.h" // for CWallet::GetRequiredFee()
22 #endif
23 
24 #include "privatesend-client.h"
25 
26 #include <boost/thread.hpp>
27 
28 #include <QDataWidgetMapper>
29 #include <QDir>
30 #include <QIntValidator>
31 #include <QLocale>
32 #include <QMessageBox>
33 #include <QTimer>
34 
35 extern CWallet* pwalletMain;
36 
37 OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
38  QDialog(parent),
39  ui(new Ui::OptionsDialog),
40  model(0),
41  mapper(0)
42 {
43  ui->setupUi(this);
44 
45  /* Main elements init */
46  ui->databaseCache->setMinimum(nMinDbCache);
47  ui->databaseCache->setMaximum(nMaxDbCache);
48  ui->threadsScriptVerif->setMinimum(-GetNumCores());
50 
51  /* Network elements init */
52 #ifndef USE_UPNP
53  ui->mapPortUpnp->setEnabled(false);
54 #endif
55 
56  ui->proxyIp->setEnabled(false);
57  ui->proxyPort->setEnabled(false);
58  ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
59 
60  ui->proxyIpTor->setEnabled(false);
61  ui->proxyPortTor->setEnabled(false);
62  ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));
63 
64  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
65  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
66  connect(ui->connectSocks, SIGNAL(toggled(bool)), this, SLOT(updateProxyValidationState()));
67 
68  connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyIpTor, SLOT(setEnabled(bool)));
69  connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyPortTor, SLOT(setEnabled(bool)));
70  connect(ui->connectSocksTor, SIGNAL(toggled(bool)), this, SLOT(updateProxyValidationState()));
71 
72  /* Window elements init */
73 #ifdef Q_OS_MAC
74  /* remove Window tab on Mac */
75  ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));
76 #endif
77 
78  /* remove Wallet tab in case of -disablewallet */
79  if (!enableWallet) {
80  ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWallet));
81  }
82 
83  /* Display elements init */
84 
85  /* Number of displayed decimal digits selector */
86  QString digits;
87  for(int index = 2; index <=8; index++){
88  digits.setNum(index);
89  ui->digits->addItem(digits, digits);
90  }
91 
92  /* Theme selector */
93  ui->theme->addItem(QString("DASH-light"), QVariant("light"));
94  ui->theme->addItem(QString("DASH-light-hires"), QVariant("light-hires"));
95  ui->theme->addItem(QString("DASH-blue"), QVariant("drkblue"));
96  ui->theme->addItem(QString("DASH-Crownium"), QVariant("crownium"));
97  ui->theme->addItem(QString("DASH-traditional"), QVariant("trad"));
98 
99  /* Language selector */
100  QDir translations(":translations");
101  ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
102  Q_FOREACH(const QString &langStr, translations.entryList())
103  {
104  QLocale locale(langStr);
105 
107  if(langStr.contains("_"))
108  {
109 #if QT_VERSION >= 0x040800
110 
111  ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + locale.nativeCountryName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
112 #else
113 
114  ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" - ") + QLocale::countryToString(locale.country()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
115 #endif
116  }
117  else
118  {
119 #if QT_VERSION >= 0x040800
120 
121  ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
122 #else
123 
124  ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
125 #endif
126  }
127  }
128 #if QT_VERSION >= 0x040700
129  ui->thirdPartyTxUrls->setPlaceholderText("https://example.com/tx/%s");
130 #endif
131 
132  ui->unit->setModel(new BitcoinUnits(this));
133 
134  /* Widget-to-option mapper */
135  mapper = new QDataWidgetMapper(this);
136  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
137  mapper->setOrientation(Qt::Vertical);
138 
139  /* setup/change UI elements when proxy IPs are invalid/valid */
142  connect(ui->proxyIp, SIGNAL(validationDidChange(QValidatedLineEdit *)), this, SLOT(updateProxyValidationState()));
143  connect(ui->proxyIpTor, SIGNAL(validationDidChange(QValidatedLineEdit *)), this, SLOT(updateProxyValidationState()));
144  connect(ui->proxyPort, SIGNAL(textChanged(const QString&)), this, SLOT(updateProxyValidationState()));
145  connect(ui->proxyPortTor, SIGNAL(textChanged(const QString&)), this, SLOT(updateProxyValidationState()));
146 }
147 
149 {
150  delete ui;
151 }
152 
154 {
155  this->model = model;
156 
157  if(model)
158  {
159  /* check if client restart is needed and show persistent message */
160  if (model->isRestartRequired())
161  showRestartWarning(true);
162 
163  QString strLabel = model->getOverriddenByCommandLine();
164  if (strLabel.isEmpty())
165  strLabel = tr("none");
166  ui->overriddenByCommandLineLabel->setText(strLabel);
167 
168  mapper->setModel(model);
169  setMapper();
170  mapper->toFirst();
171 
173  }
174 
175  /* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
176 
177  /* Main */
178  connect(ui->databaseCache, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
179  connect(ui->threadsScriptVerif, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
180  /* Wallet */
181  connect(ui->showMasternodesTab, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
182  connect(ui->spendZeroConfChange, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
183  /* Network */
184  connect(ui->allowIncoming, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
185  connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
186  connect(ui->connectSocksTor, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
187  /* Display */
188  connect(ui->digits, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
189  connect(ui->theme, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
190  connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
191  connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
192 }
193 
195 {
196  /* Main */
200 
201  /* Wallet */
210 
211  /* Network */
214 
216  mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
218 
222 
223  /* Window */
224 #ifndef Q_OS_MAC
228 #endif
229 
230  /* Display */
231  mapper->addMapping(ui->digits, OptionsModel::Digits);
232  mapper->addMapping(ui->theme, OptionsModel::Theme);
233  mapper->addMapping(ui->lang, OptionsModel::Language);
234  mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
236 
237 }
238 
240 {
241  ui->okButton->setEnabled(fState);
242 }
243 
245 {
246  if(model)
247  {
248  // confirmation dialog
249  QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"),
250  tr("Client restart required to activate changes.") + "<br><br>" + tr("Client will be shut down. Do you want to proceed?"),
251  QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
252 
253  if(btnRetVal == QMessageBox::Cancel)
254  return;
255 
256  /* reset all options and close GUI */
257  model->Reset();
258  QApplication::quit();
259  }
260 }
261 
263 {
264  mapper->submit();
265  privateSendClient.nCachedNumBlocks = std::numeric_limits<int>::max();
267  accept();
269 }
270 
272 {
273  reject();
274 }
275 
277 {
278  if(fState)
279  {
280  ui->minimizeToTray->setChecked(false);
281  ui->minimizeToTray->setEnabled(false);
282  }
283  else
284  {
285  ui->minimizeToTray->setEnabled(true);
286  }
287 }
288 
289 void OptionsDialog::showRestartWarning(bool fPersistent)
290 {
291  ui->statusLabel->setStyleSheet("QLabel { color: red; }");
292 
293  if(fPersistent)
294  {
295  ui->statusLabel->setText(tr("Client restart required to activate changes."));
296  }
297  else
298  {
299  ui->statusLabel->setText(tr("This change would require a client restart."));
300  // clear non-persistent status label after 10 seconds
301  // Todo: should perhaps be a class attribute, if we extend the use of statusLabel
302  QTimer::singleShot(10000, this, SLOT(clearStatusLabel()));
303  }
304 }
305 
307 {
308  ui->statusLabel->clear();
309 }
310 
312 {
313  QValidatedLineEdit *pUiProxyIp = ui->proxyIp;
314  QValidatedLineEdit *otherProxyWidget = (pUiProxyIp == ui->proxyIpTor) ? ui->proxyIp : ui->proxyIpTor;
315  if (pUiProxyIp->isValid() && (!ui->proxyPort->isEnabled() || ui->proxyPort->text().toInt() > 0) && (!ui->proxyPortTor->isEnabled() || ui->proxyPortTor->text().toInt() > 0))
316  {
317  setOkButtonState(otherProxyWidget->isValid()); //only enable ok button if both proxys are valid
318  ui->statusLabel->clear();
319  }
320  else
321  {
322  setOkButtonState(false);
323  ui->statusLabel->setStyleSheet("QLabel { color: red; }");
324  ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
325  }
326 }
327 
329 {
330  proxyType proxy;
331  std::string strProxy;
332  QString strDefaultProxyGUI;
333 
334  GetProxy(NET_IPV4, proxy);
335  strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
336  strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
337  (strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv4->setChecked(true) : ui->proxyReachIPv4->setChecked(false);
338 
339  GetProxy(NET_IPV6, proxy);
340  strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
341  strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
342  (strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv6->setChecked(true) : ui->proxyReachIPv6->setChecked(false);
343 
344  GetProxy(NET_TOR, proxy);
345  strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
346  strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
347  (strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachTor->setChecked(true) : ui->proxyReachTor->setChecked(false);
348 }
349 
351 QValidator(parent)
352 {
353 }
354 
355 QValidator::State ProxyAddressValidator::validate(QString &input, int &pos) const
356 {
357  Q_UNUSED(pos);
358  // Validate the proxy
359  CService serv(LookupNumeric(input.toStdString().c_str(), 9050));
360  proxyType addrProxy = proxyType(serv, true);
361  if (addrProxy.IsValid())
362  return QValidator::Acceptable;
363 
364  return QValidator::Invalid;
365 }
QValueComboBox * lang
QCheckBox * showMasternodesTab
bool IsValid() const
Definition: netbase.h:34
QCheckBox * proxyReachTor
bool isRestartRequired()
QCheckBox * lowKeysWarning
void on_cancelButton_clicked()
void setOkButtonState(bool fState)
QCheckBox * bitcoinAtStartup
QLabel * overriddenByCommandLineLabel
std::string ToStringIP(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:241
CService LookupNumeric(const char *pszName, int portDefault)
Definition: netbase.cpp:228
void updateProxyValidationState()
OptionsDialog(QWidget *parent, bool enableWallet)
QCheckBox * connectSocksTor
QCheckBox * showAdvancedPSUI
void on_okButton_clicked()
static const int64_t nMinDbCache
min. -dbcache in (MiB)
Definition: txdb.h:36
void setupUi(QDialog *OptionsDialog)
OptionsModel * model
Definition: optionsdialog.h:66
void showRestartWarning(bool fPersistent=false)
QCheckBox * spendZeroConfChange
CService proxy
Definition: netbase.h:36
QTabWidget * tabWidget
void on_resetButton_clicked()
QPushButton * okButton
QCheckBox * hideTrayIcon
QCheckBox * privateSendMultiSession
QSpinBox * privateSendAmount
QSpinBox * threadsScriptVerif
QCheckBox * minimizeOnClose
ProxyAddressValidator(QObject *parent)
State validate(QString &input, int &pos) const
QValueComboBox * digits
void setCheckValidator(const QValidator *v)
CWallet * pwalletMain
std::string ToStringPort() const
Definition: netaddress.cpp:554
void MarkDirty()
Definition: wallet.cpp:868
QValidatedLineEdit * proxyIp
void clearStatusLabel()
void on_hideTrayIcon_stateChanged(int fState)
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:78
QCheckBox * minimizeToTray
CPrivateSendClient privateSendClient
Ui::OptionsDialog * ui
Definition: optionsdialog.h:65
QCheckBox * connectSocks
QCheckBox * proxyReachIPv6
static const int64_t nMaxDbCache
max. -dbcache in (MiB)
Definition: txdb.h:34
QCheckBox * proxyReachIPv4
QDataWidgetMapper * mapper
Definition: optionsdialog.h:67
QValueComboBox * unit
QCheckBox * mapPortUpnp
bool GetProxy(enum Network net, proxyType &proxyInfoOut)
Definition: netbase.cpp:536
QCheckBox * coinControlFeatures
QSpinBox * privateSendRounds
QCheckBox * allowIncoming
int GetNumCores()
Definition: util.cpp:948
QValidatedLineEdit * proxyIpTor
QLineEdit * proxyPortTor
QValueComboBox * theme
void setModel(OptionsModel *model)
QLineEdit * proxyPort
void setEnabled(bool enabled)
void updateDefaultProxyNets()
static const int MAX_SCRIPTCHECK_THREADS
Definition: validation.h:83
QLineEdit * thirdPartyTxUrls
QSpinBox * databaseCache