Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
optionsdialog.cpp
Go to the documentation of this file.
1 #include "optionsdialog.h"
2 #include "ui_optionsdialog.h"
3 
4 #include "bitcoinunits.h"
5 #include "monitoreddatamapper.h"
6 #include "netbase.h"
7 #include "optionsmodel.h"
8 
9 #include <QDir>
10 #include <QIntValidator>
11 #include <QLocale>
12 #include <QMessageBox>
13 
14 OptionsDialog::OptionsDialog(QWidget *parent) :
15  QDialog(parent),
16  ui(new Ui::OptionsDialog),
17  model(0),
18  mapper(0),
19  fRestartWarningDisplayed_Proxy(false),
20  fRestartWarningDisplayed_Lang(false),
21  fProxyIpValid(true)
22 {
23  ui->setupUi(this);
24 
25  /* Network elements init */
26 #ifndef USE_UPNP
27  ui->mapPortUpnp->setEnabled(false);
28 #endif
29 
30  ui->proxyIp->setEnabled(false);
31  ui->proxyPort->setEnabled(false);
32  ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
33 
34  ui->socksVersion->setEnabled(false);
35  ui->socksVersion->addItem("5", 5);
36  ui->socksVersion->addItem("4", 4);
37  ui->socksVersion->setCurrentIndex(0);
38 
39  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
40  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
41  connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool)));
42  connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Proxy()));
43 
44  ui->proxyIp->installEventFilter(this);
45 
46  /* Window elements init */
47 #ifdef Q_OS_MAC
48  /* remove Window tab on Mac */
49  ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));
50 #endif
51 
52  /* Display elements init */
53  QDir translations(":translations");
54  ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
55  foreach(const QString &langStr, translations.entryList())
56  {
57  QLocale locale(langStr);
58 
60  if(langStr.contains("_"))
61  {
62 #if QT_VERSION >= 0x040800
63 
64  ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + locale.nativeCountryName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
65 #else
66 
67  ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" - ") + QLocale::countryToString(locale.country()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
68 #endif
69  }
70  else
71  {
72 #if QT_VERSION >= 0x040800
73 
74  ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
75 #else
76 
77  ui->lang->addItem(QLocale::languageToString(locale.language()) + QString(" (") + langStr + QString(")"), QVariant(langStr));
78 #endif
79  }
80  }
81 
82  ui->unit->setModel(new BitcoinUnits(this));
83 
84  /* Widget-to-option mapper */
85  mapper = new MonitoredDataMapper(this);
86  mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
87  mapper->setOrientation(Qt::Vertical);
88 
89  /* enable apply button when data modified */
90  connect(mapper, SIGNAL(viewModified()), this, SLOT(enableApplyButton()));
91  /* disable apply button when new data loaded */
92  connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApplyButton()));
93  /* setup/change UI elements when proxy IP is invalid/valid */
94  connect(this, SIGNAL(proxyIpValid(QValidatedLineEdit *, bool)), this, SLOT(handleProxyIpValid(QValidatedLineEdit *, bool)));
95 }
96 
98 {
99  delete ui;
100 }
101 
103 {
104  this->model = model;
105 
106  if(model)
107  {
108  connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
109 
110  mapper->setModel(model);
111  setMapper();
112  mapper->toFirst();
113  }
114 
115  /* update the display unit, to not use the default ("BTC") */
117 
118  /* warn only when language selection changes by user action (placed here so init via mapper doesn't trigger this) */
119  connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning_Lang()));
120 
121  /* disable apply button after settings are loaded as there is nothing to save */
123 }
124 
126 {
127  /* Main */
128  mapper->addMapping(ui->transactionFee, OptionsModel::Fee);
129  mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup);
130 
131  /* Network */
133 
134  mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse);
138 
139  /* Window */
140 #ifndef Q_OS_MAC
143 #endif
144 
145  /* Display */
148  mapper->addMapping(ui->displayAddresses, OptionsModel::DisplayAddresses);
149  mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures);
150 }
151 
153 {
154  ui->applyButton->setEnabled(true);
155 }
156 
158 {
159  ui->applyButton->setEnabled(false);
160 }
161 
163 {
164  /* prevent enabling of the save buttons when data modified, if there is an invalid proxy address present */
165  if(fProxyIpValid)
166  setSaveButtonState(true);
167 }
168 
170 {
171  setSaveButtonState(false);
172 }
173 
175 {
176  ui->applyButton->setEnabled(fState);
177  ui->okButton->setEnabled(fState);
178 }
179 
181 {
182  if(model)
183  {
184  // confirmation dialog
185  QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"),
186  tr("Some settings may require a client restart to take effect.") + "<br><br>" + tr("Do you want to proceed?"),
187  QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
188 
189  if(btnRetVal == QMessageBox::Cancel)
190  return;
191 
193 
194  /* disable restart warning messages display */
196 
197  /* reset all options and save the default values (QSettings) */
198  model->Reset();
199  mapper->toFirst();
200  mapper->submit();
201 
202  /* re-enable restart warning messages display */
204  }
205 }
206 
208 {
209  mapper->submit();
210  accept();
211 }
212 
214 {
215  reject();
216 }
217 
219 {
220  mapper->submit();
222 }
223 
225 {
227  {
228  QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Feathercoin."), QMessageBox::Ok);
230  }
231 }
232 
234 {
236  {
237  QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Feathercoin."), QMessageBox::Ok);
239  }
240 }
241 
243 {
244  if(model)
245  {
246  /* Update transactionFee with the current unit */
247  ui->transactionFee->setDisplayUnit(model->getDisplayUnit());
248  }
249 }
250 
252 {
253  // this is used in a check before re-enabling the save buttons
254  fProxyIpValid = fState;
255 
256  if(fProxyIpValid)
257  {
259  ui->statusLabel->clear();
260  }
261  else
262  {
264  object->setValid(fProxyIpValid);
265  ui->statusLabel->setStyleSheet("QLabel { color: red; }");
266  ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
267  }
268 }
269 
270 bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
271 {
272  if(event->type() == QEvent::FocusOut)
273  {
274  if(object == ui->proxyIp)
275  {
276  CService addr;
277  /* Check proxyIp for a valid IPv4/IPv6 address and emit the proxyIpValid signal */
278  emit proxyIpValid(ui->proxyIp, LookupNumeric(ui->proxyIp->text().toStdString().c_str(), addr));
279  }
280  }
281  return QDialog::eventFilter(object, event);
282 }
Ui::OptionsDialog * ui
Definition: optionsdialog.h:53
Bitcoin unit definitions.
Definition: bitcoinunits.h:10
bool fRestartWarningDisplayed_Lang
Definition: optionsdialog.h:57
Definition: aboutdialog.h:6
bool LookupNumeric(const char *pszName, CService &addr, int portDefault)
Definition: netbase.cpp:161
void on_resetButton_clicked()
Line edit that can be marked as "invalid" to show input validation feedback.
bool fRestartWarningDisplayed_Proxy
Definition: optionsdialog.h:56
void enableSaveButtons()
void updateDisplayUnit()
OptionsModel * model
Definition: optionsdialog.h:54
void showRestartWarning_Proxy()
MonitoredDataMapper * mapper
Definition: optionsdialog.h:55
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:90
void disableSaveButtons()
void disableApplyButton()
void setModel(OptionsModel *model)
void on_okButton_clicked()
int getDisplayUnit()
Definition: optionsmodel.h:50
OptionsDialog(QWidget *parent=0)
void on_applyButton_clicked()
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:12
void addMapping(QWidget *widget, int section)
void enableApplyButton()
bool eventFilter(QObject *object, QEvent *event)
void setSaveButtonState(bool fState)
void proxyIpValid(QValidatedLineEdit *object, bool fValid)
Data to Widget mapper that watches for edits and notifies listeners when a field is edited...
void on_cancelButton_clicked()
Preferences dialog.
Definition: optionsdialog.h:14
void showRestartWarning_Lang()
void handleProxyIpValid(QValidatedLineEdit *object, bool fState)