@@ -34,8 +34,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
34
34
QDialog(parent),
35
35
ui(new Ui::OptionsDialog),
36
36
model(0 ),
37
- mapper(0 ),
38
- fProxyIpsValid(true )
37
+ mapper(0 )
39
38
{
40
39
ui->setupUi (this );
41
40
@@ -64,9 +63,6 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
64
63
connect (ui->connectSocksTor , SIGNAL (toggled (bool )), ui->proxyIpTor , SLOT (setEnabled (bool )));
65
64
connect (ui->connectSocksTor , SIGNAL (toggled (bool )), ui->proxyPortTor , SLOT (setEnabled (bool )));
66
65
67
- ui->proxyIp ->installEventFilter (this );
68
- ui->proxyIpTor ->installEventFilter (this );
69
-
70
66
/* Window elements init */
71
67
#ifdef Q_OS_MAC
72
68
/* remove Window tab on Mac */
@@ -119,7 +115,10 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
119
115
mapper->setOrientation (Qt::Vertical);
120
116
121
117
/* setup/change UI elements when proxy IPs are invalid/valid */
122
- connect (this , SIGNAL (proxyIpChecks (QValidatedLineEdit *, int )), this , SLOT (doProxyIpChecks (QValidatedLineEdit *, int )));
118
+ ui->proxyIp ->setCheckValidator (new ProxyAddressValidator (parent));
119
+ ui->proxyIpTor ->setCheckValidator (new ProxyAddressValidator (parent));
120
+ connect (ui->proxyIp , SIGNAL (validationDidChange (QValidatedLineEdit *)), this , SLOT (updateProxyValidationState (QValidatedLineEdit *)));
121
+ connect (ui->proxyIpTor , SIGNAL (validationDidChange (QValidatedLineEdit *)), this , SLOT (updateProxyValidationState (QValidatedLineEdit *)));
123
122
}
124
123
125
124
OptionsDialog::~OptionsDialog ()
@@ -200,18 +199,6 @@ void OptionsDialog::setMapper()
200
199
mapper->addMapping (ui->thirdPartyTxUrls , OptionsModel::ThirdPartyTxUrls);
201
200
}
202
201
203
- void OptionsDialog::enableOkButton ()
204
- {
205
- /* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */
206
- if (fProxyIpsValid )
207
- setOkButtonState (true );
208
- }
209
-
210
- void OptionsDialog::disableOkButton ()
211
- {
212
- setOkButtonState (false );
213
- }
214
-
215
202
void OptionsDialog::setOkButtonState (bool fState )
216
203
{
217
204
ui->okButton ->setEnabled (fState );
@@ -269,24 +256,19 @@ void OptionsDialog::clearStatusLabel()
269
256
ui->statusLabel ->clear ();
270
257
}
271
258
272
- void OptionsDialog::doProxyIpChecks (QValidatedLineEdit *pUiProxyIp, int nProxyPort )
259
+ void OptionsDialog::updateProxyValidationState (QValidatedLineEdit *pUiProxyIp)
273
260
{
274
- Q_UNUSED (nProxyPort);
275
-
276
- CService addrProxy;
277
-
278
- /* Check for a valid IPv4 / IPv6 address */
279
- if (!(fProxyIpsValid = LookupNumeric (pUiProxyIp->text ().toStdString ().c_str (), addrProxy)))
261
+ QValidatedLineEdit *otherProxyWidget = (pUiProxyIp == ui->proxyIpTor ) ? ui->proxyIp : ui->proxyIpTor ;
262
+ if (pUiProxyIp->isValid ())
280
263
{
281
- disableOkButton ();
282
- pUiProxyIp->setValid (false );
283
- ui->statusLabel ->setStyleSheet (" QLabel { color: red; }" );
284
- ui->statusLabel ->setText (tr (" The supplied proxy address is invalid." ));
264
+ setOkButtonState (otherProxyWidget->isValid ()); // only enable ok button if both proxys are valid
265
+ ui->statusLabel ->clear ();
285
266
}
286
267
else
287
268
{
288
- enableOkButton ();
289
- ui->statusLabel ->clear ();
269
+ setOkButtonState (false );
270
+ ui->statusLabel ->setStyleSheet (" QLabel { color: red; }" );
271
+ ui->statusLabel ->setText (tr (" The supplied proxy address is invalid." ));
290
272
}
291
273
}
292
274
@@ -312,18 +294,18 @@ void OptionsDialog::updateDefaultProxyNets()
312
294
(strProxy == strDefaultProxyGUI.toStdString ()) ? ui->proxyReachTor ->setChecked (true ) : ui->proxyReachTor ->setChecked (false );
313
295
}
314
296
315
- bool OptionsDialog::eventFilter (QObject *object, QEvent *event)
297
+ ProxyAddressValidator::ProxyAddressValidator (QObject *parent) :
298
+ QValidator(parent)
316
299
{
317
- if (event->type () == QEvent::FocusOut)
318
- {
319
- if (object == ui->proxyIp )
320
- {
321
- Q_EMIT proxyIpChecks (ui->proxyIp , ui->proxyPort ->text ().toInt ());
322
- }
323
- else if (object == ui->proxyIpTor )
324
- {
325
- Q_EMIT proxyIpChecks (ui->proxyIpTor , ui->proxyPortTor ->text ().toInt ());
326
- }
327
- }
328
- return QDialog::eventFilter (object, event);
300
+ }
301
+
302
+ QValidator::State ProxyAddressValidator::validate (QString &input, int &pos) const
303
+ {
304
+ Q_UNUSED (pos);
305
+ // Validate the proxy
306
+ proxyType addrProxy = proxyType (CService (input.toStdString (), 9050 ), true );
307
+ if (addrProxy.IsValid ())
308
+ return QValidator::Acceptable;
309
+
310
+ return QValidator::Invalid;
329
311
}
0 commit comments