Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
optionsdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 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 "bitcoin-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 "monitoreddatamapper.h"
15 #include "optionsmodel.h"
16 
17 #include "main.h" // for CTransaction::nMinTxFee and MAX_SCRIPTCHECK_THREADS
18 #include "netbase.h"
19 #include "txdb.h" // for -dbcache defaults
20 
21 #include <QDir>
22 #include <QIntValidator>
23 #include <QLocale>
24 #include <QMessageBox>
25 #include <QTimer>
26 
28  QDialog(parent),
29  ui(new Ui::OptionsDialog),
30  model(0),
31  mapper(0),
32  fProxyIpValid(true)
33 {
34  ui->setupUi(this);
35  GUIUtil::restoreWindowGeometry("nOptionsDialogWindow", this->size(), this);
36 
37  /* Main elements init */
38  ui->databaseCache->setMinimum(nMinDbCache);
39  ui->databaseCache->setMaximum(nMaxDbCache);
40  ui->threadsScriptVerif->setMinimum(-(int)boost::thread::hardware_concurrency());
42 
43  /* Network elements init */
44 #ifndef USE_UPNP
45  ui->mapPortUpnp->setEnabled(false);
46 #endif
47 
48  ui->proxyIp->setEnabled(false);
49  ui->proxyPort->setEnabled(false);
50  ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
51 
53  ui->socksVersion->setEnabled(false);
54  ui->socksVersion->addItem("5", 5);
55  ui->socksVersion->addItem("4", 4);
56  ui->socksVersion->setCurrentIndex(0);
57 
58  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
59  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
60  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool)));
61 
62  ui->proxyIp->installEventFilter(this);
63 
64  /* Window elements init */
65 #ifdef Q_OS_MAC
66  /* remove Window tab on Mac */
67  ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));
68 #endif
69 
70  /* Display elements init */
71  QDir translations(":translations");
72  ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
73  foreach(const QString &langStr, translations.entryList())
74  {
75  QLocale locale(langStr);
76 
78  if(langStr.contains("_"))
79  {
80 #if QT_VERSION >= 0x040800
81 
82  ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + locale.nativeCountryName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
83 #else
84 
85  ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" - ") + QLocale::countryToString(locale.country()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
86 #endif
87  }
88  else
89  {
90 #if QT_VERSION >= 0x040800
91 
92  ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
93 #else
94 
95  ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
96 #endif
97  }
98  }
99 #if QT_VERSION >= 0x040700
100  ui->thirdPartyTxUrls->setPlaceholderText("https://example.com/tx/%s");
101 #endif
102 
103  ui->unit->setModel(new BitcoinUnits(this));
105 
106  /* Widget-to-option mapper */
107  mapper = new MonitoredDataMapper(this);
108  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
109  mapper->setOrientation(Qt::Vertical);
110 
111  /* setup/change UI elements when proxy IP is invalid/valid */
112  connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int)));
113 }
114 
116 {
117  GUIUtil::saveWindowGeometry("nOptionsDialogWindow", this);
118  delete ui;
119 }
120 
122 {
123  this->model = model;
124 
125  if(model)
126  {
127  /* check if client restart is needed and show persistent message */
128  if (model->isRestartRequired())
129  showRestartWarning(true);
130 
131  QString strLabel = model->getOverriddenByCommandLine();
132  if (strLabel.isEmpty())
133  strLabel = tr("none");
134  ui->overriddenByCommandLineLabel->setText(strLabel);
135 
136  connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
137 
138  mapper->setModel(model);
139  setMapper();
140  mapper->toFirst();
141  }
142 
143  /* update the display unit, to not use the default ("BTC") */
145 
146  /* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
147 
148  /* Main */
149  connect(ui->databaseCache, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
150  connect(ui->threadsScriptVerif, SIGNAL(valueChanged(int)), this, SLOT(showRestartWarning()));
151  /* Wallet */
152  connect(ui->spendZeroConfChange, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
153  /* Network */
154  connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
155  /* Display */
156  connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
157  connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
158 }
159 
161 {
162  /* Main */
166 
167  /* Wallet */
171 
172  /* Network */
174 
179 
180  /* Window */
181 #ifndef Q_OS_MAC
184 #endif
185 
186  /* Display */
191 }
192 
194 {
195  /* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */
196  if(fProxyIpValid)
197  setOkButtonState(true);
198 }
199 
201 {
202  setOkButtonState(false);
203 }
204 
206 {
207  ui->okButton->setEnabled(fState);
208 }
209 
211 {
212  if(model)
213  {
214  // confirmation dialog
215  QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"),
216  tr("Client restart required to activate changes.") + "<br><br>" + tr("Client will be shutdown, do you want to proceed?"),
217  QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
218 
219  if(btnRetVal == QMessageBox::Cancel)
220  return;
221 
222  /* reset all options and close GUI */
223  model->Reset();
224  QApplication::quit();
225  }
226 }
227 
229 {
230  mapper->submit();
231  accept();
232 }
233 
235 {
236  reject();
237 }
238 
239 void OptionsDialog::showRestartWarning(bool fPersistent)
240 {
241  ui->statusLabel->setStyleSheet("QLabel { color: red; }");
242 
243  if(fPersistent)
244  {
245  ui->statusLabel->setText(tr("Client restart required to activate changes."));
246  }
247  else
248  {
249  ui->statusLabel->setText(tr("This change would require a client restart."));
250  // clear non-persistent status label after 10 seconds
251  // Todo: should perhaps be a class attribute, if we extend the use of statusLabel
252  QTimer::singleShot(10000, this, SLOT(clearStatusLabel()));
253  }
254 }
255 
257 {
258  ui->statusLabel->clear();
259 }
260 
262 {
263  if(model)
264  {
265  /* Update transactionFee with the current unit */
267  }
268 }
269 
270 void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort)
271 {
272  Q_UNUSED(nProxyPort);
273 
274  const std::string strAddrProxy = pUiProxyIp->text().toStdString();
275  CService addrProxy;
276 
277  /* Check for a valid IPv4 / IPv6 address */
278  if (!(fProxyIpValid = LookupNumeric(strAddrProxy.c_str(), addrProxy)))
279  {
280  disableOkButton();
281  pUiProxyIp->setValid(false);
282  ui->statusLabel->setStyleSheet("QLabel { color: red; }");
283  ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
284  }
285  else
286  {
287  enableOkButton();
288  ui->statusLabel->clear();
289  }
290 }
291 
292 bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
293 {
294  if(event->type() == QEvent::FocusOut)
295  {
296  if(object == ui->proxyIp)
297  {
298  emit proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt());
299  }
300  }
301  return QDialog::eventFilter(object, event);
302 }
QCheckBox * spendZeroConfChange
QTabWidget * tabWidget
Ui::OptionsDialog * ui
Definition: optionsdialog.h:53
OptionsDialog(QWidget *parent)
Bitcoin unit definitions.
Definition: bitcoinunits.h:14
QSpinBox * threadsScriptVerif
void setupUi(QDialog *OptionsDialog)
void setOkButtonState(bool fState)
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:63
bool LookupNumeric(const char *pszName, CService &addr, int portDefault)
Definition: netbase.cpp:161
static const int64_t nMinDbCache
Definition: txdb.h:26
QCheckBox * minimizeToTray
QValueComboBox * unit
void on_resetButton_clicked()
Line edit that can be marked as "invalid" to show input validation feedback.
QValueComboBox * socksVersion
static int64_t nMinTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) ...
Definition: core.h:186
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Definition: guiutil.cpp:732
void updateDisplayUnit()
OptionsModel * model
Definition: optionsdialog.h:54
MonitoredDataMapper * mapper
Definition: optionsdialog.h:55
QCheckBox * connectSocks
QCheckBox * displayAddresses
BitcoinAmountField * transactionFee
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:94
void setModel(OptionsModel *model)
void on_okButton_clicked()
int getDisplayUnit()
Definition: optionsmodel.h:58
QCheckBox * mapPortUpnp
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Definition: guiutil.cpp:739
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort)
QValueComboBox * lang
QLabel * overriddenByCommandLineLabel
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of script-checking threads allowed.
Definition: main.h:62
QPushButton * okButton
QCheckBox * minimizeOnClose
QLineEdit * thirdPartyTxUrls
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:20
void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort)
void addMapping(QWidget *widget, int section)
QLineEdit * proxyPort
QCheckBox * bitcoinAtStartup
bool eventFilter(QObject *object, QEvent *event)
static const int64_t nMaxDbCache
Definition: txdb.h:24
QSpinBox * databaseCache
void setSingleStep(qint64 step)
Set single step in satoshis.
void showRestartWarning(bool fPersistent=false)
void setEnabled(bool enabled)
Data to Widget mapper that watches for edits and notifies listeners when a field is edited...
void on_cancelButton_clicked()
QValidatedLineEdit * proxyIp
Preferences dialog.
Definition: optionsdialog.h:19
void clearStatusLabel()
bool isRestartRequired()
void setDisplayUnit(int unit)
Change unit used to display amount.
QCheckBox * coinControlFeatures
void setValid(bool valid)
void disableOkButton()