3030#include < util/strencodings.h>
3131#include < chrono>
3232#include < cmath>
33+ #include < regex>
3334#include < utility>
3435
3536#include < QApplication>
@@ -278,13 +279,33 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
278279 ui->proxyPortTor ->setEnabled (false );
279280 ui->proxyPortTor ->setValidator (new QIntValidator (1 , 65535 , this ));
280281
281- connect (ui->connectSocks , &QPushButton::toggled, ui->proxyIp , &QWidget::setEnabled);
282- connect (ui->connectSocks , &QPushButton::toggled, ui->proxyPort , &QWidget::setEnabled);
283- connect (ui->connectSocks , &QPushButton::toggled, this , &OptionsDialog::updateProxyValidationState);
284-
285- connect (ui->connectSocksTor , &QPushButton::toggled, ui->proxyIpTor , &QWidget::setEnabled);
286- connect (ui->connectSocksTor , &QPushButton::toggled, ui->proxyPortTor , &QWidget::setEnabled);
287- connect (ui->connectSocksTor , &QPushButton::toggled, this , &OptionsDialog::updateProxyValidationState);
282+ #if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
283+ connect (ui->connectSocks , &QCheckBox::checkStateChanged, [this ](const Qt::CheckState state){
284+ const bool enabled = (state == Qt::Checked);
285+ ui->proxyIp ->setEnabled (enabled);
286+ ui->proxyPort ->setEnabled (enabled);
287+ updateProxyValidationState ();
288+ });
289+ connect (ui->connectSocksTor , &QCheckBox::checkStateChanged, [this ](const Qt::CheckState state){
290+ const bool enabled = (state == Qt::Checked);
291+ ui->proxyIpTor ->setEnabled (enabled);
292+ ui->proxyPortTor ->setEnabled (enabled);
293+ updateProxyValidationState ();
294+ });
295+ #else
296+ connect (ui->connectSocks , &QCheckBox::stateChanged, [this ](int state){
297+ const bool enabled = (state == Qt::Checked);
298+ ui->proxyIp ->setEnabled (enabled);
299+ ui->proxyPort ->setEnabled (enabled);
300+ updateProxyValidationState ();
301+ });
302+ connect (ui->connectSocksTor , &QCheckBox::stateChanged, [this ](int state){
303+ const bool enabled = (state == Qt::Checked);
304+ ui->proxyIpTor ->setEnabled (enabled);
305+ ui->proxyPortTor ->setEnabled (enabled);
306+ updateProxyValidationState ();
307+ });
308+ #endif
288309
289310 ui->maxuploadtarget ->setMinimum (144 /* MiB/day */ );
290311 ui->maxuploadtarget ->setMaximum (std::numeric_limits<int >::max ());
@@ -720,10 +741,23 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
720741 /* setup/change UI elements when proxy IPs are invalid/valid */
721742 ui->proxyIp ->setCheckValidator (new ProxyAddressValidator (parent));
722743 ui->proxyIpTor ->setCheckValidator (new ProxyAddressValidator (parent));
744+
745+ // do not allow empty input for validation for all proxy fields
746+ ui->proxyIp ->setAllowEmptyInput (false );
747+ ui->proxyIpTor ->setAllowEmptyInput (false );
748+ ui->proxyPort ->setAllowEmptyInput (false );
749+ ui->proxyPortTor ->setAllowEmptyInput (false );
750+
751+ // Enable validation while typing for all proxy fields
752+ ui->proxyIp ->setAllowValidationWhileEditing (true );
753+ ui->proxyPort ->setAllowValidationWhileEditing (true );
754+ ui->proxyIpTor ->setAllowValidationWhileEditing (true );
755+ ui->proxyPortTor ->setAllowValidationWhileEditing (true );
756+
723757 connect (ui->proxyIp , &QValidatedLineEdit::validationDidChange, this , &OptionsDialog::updateProxyValidationState);
724758 connect (ui->proxyIpTor , &QValidatedLineEdit::validationDidChange, this , &OptionsDialog::updateProxyValidationState);
725- connect (ui->proxyPort , &QLineEdit::textChanged , this , &OptionsDialog::updateProxyValidationState);
726- connect (ui->proxyPortTor , &QLineEdit::textChanged , this , &OptionsDialog::updateProxyValidationState);
759+ connect (ui->proxyPort , &QValidatedLineEdit::validationDidChange , this , &OptionsDialog::updateProxyValidationState);
760+ connect (ui->proxyPortTor , &QValidatedLineEdit::validationDidChange , this , &OptionsDialog::updateProxyValidationState);
727761
728762 if (!QSystemTrayIcon::isSystemTrayAvailable ()) {
729763 ui->showTrayIcon ->setChecked (false );
@@ -1152,6 +1186,16 @@ void OptionsDialog::on_okButton_clicked()
11521186 model->setData (model->index (OptionsModel::dustdynamic, 0 ), " off" );
11531187 }
11541188
1189+ // Before mapper->submit()
1190+ if (!ui->connectSocks ->isChecked ()) {
1191+ ui->proxyIp ->clear ();
1192+ ui->proxyPort ->clear ();
1193+ }
1194+ if (!ui->connectSocksTor ->isChecked ()) {
1195+ ui->proxyIpTor ->clear ();
1196+ ui->proxyPortTor ->clear ();
1197+ }
1198+
11551199 mapper->submit ();
11561200 accept ();
11571201 updateDefaultProxyNets ();
@@ -1174,11 +1218,13 @@ void OptionsDialog::on_showTrayIcon_stateChanged(int state)
11741218
11751219void OptionsDialog::changeEvent (QEvent* e)
11761220{
1221+ // First let the base class update all child widget palettes
1222+ // required for qvalidatedlineedit invalid colors to update properly
1223+ QWidget::changeEvent (e);
11771224 if (e->type () == QEvent::PaletteChange) {
1225+ // Then update theme colors with the new palette
11781226 updateThemeColors ();
11791227 }
1180-
1181- QWidget::changeEvent (e);
11821228}
11831229
11841230void OptionsDialog::togglePruneWarning (bool enabled)
@@ -1211,17 +1257,51 @@ void OptionsDialog::clearStatusLabel()
12111257
12121258void OptionsDialog::updateProxyValidationState ()
12131259{
1214- QValidatedLineEdit *pUiProxyIp = ui->proxyIp ;
1215- QValidatedLineEdit *otherProxyWidget = (pUiProxyIp == ui->proxyIpTor ) ? ui->proxyIp : ui->proxyIpTor ;
1216- if (pUiProxyIp->isValid () && (!ui->proxyPort ->isEnabled () || ui->proxyPort ->text ().toInt () > 0 ) && (!ui->proxyPortTor ->isEnabled () || ui->proxyPortTor ->text ().toInt () > 0 ))
1260+ bool socksProxyEnabled = ui->connectSocks ->isChecked ();
1261+ bool torProxyEnabled = ui->connectSocksTor ->isChecked ();
1262+
1263+ bool proxyIpValid = ui->proxyIp ->isValid ();
1264+ bool proxyPortValid = ui->proxyPort ->isValid ();
1265+ bool proxyIpTorValid = ui->proxyIpTor ->isValid ();
1266+ bool proxyPortTorValid = ui->proxyPortTor ->isValid ();
1267+
1268+ // proxy is OK if: disabled OR (enabled AND valid ip and valid port)
1269+ bool socksProxyOk = !socksProxyEnabled || (proxyIpValid && proxyPortValid);
1270+ bool torProxyOk = !torProxyEnabled || (proxyIpTorValid && proxyPortTorValid);
1271+
1272+ // Both must be OK for the form to be valid
1273+ if (socksProxyOk && torProxyOk)
12171274 {
1218- setOkButtonState (otherProxyWidget-> isValid ()); // only enable ok button if both proxies are valid
1275+ setOkButtonState (true );
12191276 clearStatusLabel ();
12201277 }
12211278 else
12221279 {
12231280 setOkButtonState (false );
1224- ui->statusLabel ->setText (tr (" The supplied proxy address is invalid." ));
1281+ QStringList socksErrors;
1282+
1283+ if (socksProxyEnabled) {
1284+ if (!proxyIpValid && !proxyPortValid) {
1285+ socksErrors.append (tr (" The supplied proxy address and port are invalid." ));
1286+ } else if (!proxyIpValid) {
1287+ socksErrors.append (tr (" The supplied proxy address is invalid." ));
1288+ } else if (!proxyPortValid) {
1289+ socksErrors.append (tr (" The supplied proxy port is invalid." ));
1290+ }
1291+ }
1292+ if (torProxyEnabled) {
1293+ if (!proxyIpTorValid && !proxyPortTorValid) {
1294+ socksErrors.append (tr (" The supplied Tor proxy address and port are invalid." ));
1295+ } else if (!proxyIpTorValid) {
1296+ socksErrors.append (tr (" The supplied Tor proxy address is invalid." ));
1297+ } else if (!proxyPortTorValid) {
1298+ socksErrors.append (tr (" The supplied Tor proxy port is invalid." ));
1299+ }
1300+ }
1301+
1302+ if (socksErrors.size () > 0 ) {
1303+ ui->statusLabel ->setText (socksErrors.join (" " ));
1304+ }
12251305 }
12261306}
12271307
0 commit comments