@@ -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
@@ -60,12 +59,11 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
60
59
61
60
connect (ui->connectSocks , SIGNAL (toggled (bool )), ui->proxyIp , SLOT (setEnabled (bool )));
62
61
connect (ui->connectSocks , SIGNAL (toggled (bool )), ui->proxyPort , SLOT (setEnabled (bool )));
62
+ connect (ui->connectSocks , SIGNAL (toggled (bool )), this , SLOT (updateProxyValidationState ()));
63
63
64
64
connect (ui->connectSocksTor , SIGNAL (toggled (bool )), ui->proxyIpTor , SLOT (setEnabled (bool )));
65
65
connect (ui->connectSocksTor , SIGNAL (toggled (bool )), ui->proxyPortTor , SLOT (setEnabled (bool )));
66
-
67
- ui->proxyIp ->installEventFilter (this );
68
- ui->proxyIpTor ->installEventFilter (this );
66
+ connect (ui->connectSocksTor , SIGNAL (toggled (bool )), this , SLOT (updateProxyValidationState ()));
69
67
70
68
/* Window elements init */
71
69
#ifdef Q_OS_MAC
@@ -119,7 +117,12 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
119
117
mapper->setOrientation (Qt::Vertical);
120
118
121
119
/* setup/change UI elements when proxy IPs are invalid/valid */
122
- connect (this , SIGNAL (proxyIpChecks (QValidatedLineEdit *, int )), this , SLOT (doProxyIpChecks (QValidatedLineEdit *, int )));
120
+ ui->proxyIp ->setCheckValidator (new ProxyAddressValidator (parent));
121
+ ui->proxyIpTor ->setCheckValidator (new ProxyAddressValidator (parent));
122
+ connect (ui->proxyIp , SIGNAL (validationDidChange (QValidatedLineEdit *)), this , SLOT (updateProxyValidationState ()));
123
+ connect (ui->proxyIpTor , SIGNAL (validationDidChange (QValidatedLineEdit *)), this , SLOT (updateProxyValidationState ()));
124
+ connect (ui->proxyPort , SIGNAL (textChanged (const QString&)), this , SLOT (updateProxyValidationState ()));
125
+ connect (ui->proxyPortTor , SIGNAL (textChanged (const QString&)), this , SLOT (updateProxyValidationState ()));
123
126
}
124
127
125
128
OptionsDialog::~OptionsDialog ()
@@ -200,18 +203,6 @@ void OptionsDialog::setMapper()
200
203
mapper->addMapping (ui->thirdPartyTxUrls , OptionsModel::ThirdPartyTxUrls);
201
204
}
202
205
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
206
void OptionsDialog::setOkButtonState (bool fState )
216
207
{
217
208
ui->okButton ->setEnabled (fState );
@@ -269,24 +260,20 @@ void OptionsDialog::clearStatusLabel()
269
260
ui->statusLabel ->clear ();
270
261
}
271
262
272
- void OptionsDialog::doProxyIpChecks (QValidatedLineEdit *pUiProxyIp, int nProxyPort )
263
+ void OptionsDialog::updateProxyValidationState ( )
273
264
{
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)))
265
+ QValidatedLineEdit *pUiProxyIp = ui->proxyIp ;
266
+ QValidatedLineEdit *otherProxyWidget = (pUiProxyIp == ui->proxyIpTor ) ? ui->proxyIp : ui->proxyIpTor ;
267
+ if (pUiProxyIp->isValid () && (!ui->proxyPort ->isEnabled () || ui->proxyPort ->text ().toInt () > 0 ) && (!ui->proxyPortTor ->isEnabled () || ui->proxyPortTor ->text ().toInt () > 0 ))
280
268
{
281
- disableOkButton ();
282
- pUiProxyIp->setValid (false );
283
- ui->statusLabel ->setStyleSheet (" QLabel { color: red; }" );
284
- ui->statusLabel ->setText (tr (" The supplied proxy address is invalid." ));
269
+ setOkButtonState (otherProxyWidget->isValid ()); // only enable ok button if both proxys are valid
270
+ ui->statusLabel ->clear ();
285
271
}
286
272
else
287
273
{
288
- enableOkButton ();
289
- ui->statusLabel ->clear ();
274
+ setOkButtonState (false );
275
+ ui->statusLabel ->setStyleSheet (" QLabel { color: red; }" );
276
+ ui->statusLabel ->setText (tr (" The supplied proxy address is invalid." ));
290
277
}
291
278
}
292
279
@@ -312,18 +299,18 @@ void OptionsDialog::updateDefaultProxyNets()
312
299
(strProxy == strDefaultProxyGUI.toStdString ()) ? ui->proxyReachTor ->setChecked (true ) : ui->proxyReachTor ->setChecked (false );
313
300
}
314
301
315
- bool OptionsDialog::eventFilter (QObject *object, QEvent *event)
302
+ ProxyAddressValidator::ProxyAddressValidator (QObject *parent) :
303
+ QValidator(parent)
316
304
{
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);
305
+ }
306
+
307
+ QValidator::State ProxyAddressValidator::validate (QString &input, int &pos) const
308
+ {
309
+ Q_UNUSED (pos);
310
+ // Validate the proxy
311
+ proxyType addrProxy = proxyType (CService (input.toStdString (), 9050 ), true );
312
+ if (addrProxy.IsValid ())
313
+ return QValidator::Acceptable;
314
+
315
+ return QValidator::Invalid;
329
316
}
0 commit comments