30
30
#include < util/strencodings.h>
31
31
#include < chrono>
32
32
#include < cmath>
33
+ #include < regex>
33
34
#include < utility>
34
35
35
36
#include < QApplication>
@@ -278,13 +279,33 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
278
279
ui->proxyPortTor ->setEnabled (false );
279
280
ui->proxyPortTor ->setValidator (new QIntValidator (1 , 65535 , this ));
280
281
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
288
309
289
310
ui->maxuploadtarget ->setMinimum (144 /* MiB/day */ );
290
311
ui->maxuploadtarget ->setMaximum (std::numeric_limits<int >::max ());
@@ -720,10 +741,23 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
720
741
/* setup/change UI elements when proxy IPs are invalid/valid */
721
742
ui->proxyIp ->setCheckValidator (new ProxyAddressValidator (parent));
722
743
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
+
723
757
connect (ui->proxyIp , &QValidatedLineEdit::validationDidChange, this , &OptionsDialog::updateProxyValidationState);
724
758
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);
727
761
728
762
if (!QSystemTrayIcon::isSystemTrayAvailable ()) {
729
763
ui->showTrayIcon ->setChecked (false );
@@ -1152,6 +1186,16 @@ void OptionsDialog::on_okButton_clicked()
1152
1186
model->setData (model->index (OptionsModel::dustdynamic, 0 ), " off" );
1153
1187
}
1154
1188
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
+
1155
1199
mapper->submit ();
1156
1200
accept ();
1157
1201
updateDefaultProxyNets ();
@@ -1174,11 +1218,13 @@ void OptionsDialog::on_showTrayIcon_stateChanged(int state)
1174
1218
1175
1219
void OptionsDialog::changeEvent (QEvent* e)
1176
1220
{
1221
+ // First let the base class update all child widget palettes
1222
+ // required for qvalidatedlineedit invalid colors to update properly
1223
+ QWidget::changeEvent (e);
1177
1224
if (e->type () == QEvent::PaletteChange) {
1225
+ // Then update theme colors with the new palette
1178
1226
updateThemeColors ();
1179
1227
}
1180
-
1181
- QWidget::changeEvent (e);
1182
1228
}
1183
1229
1184
1230
void OptionsDialog::togglePruneWarning (bool enabled)
@@ -1211,17 +1257,51 @@ void OptionsDialog::clearStatusLabel()
1211
1257
1212
1258
void OptionsDialog::updateProxyValidationState ()
1213
1259
{
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)
1217
1274
{
1218
- setOkButtonState (otherProxyWidget-> isValid ()); // only enable ok button if both proxies are valid
1275
+ setOkButtonState (true );
1219
1276
clearStatusLabel ();
1220
1277
}
1221
1278
else
1222
1279
{
1223
1280
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
+ }
1225
1305
}
1226
1306
}
1227
1307
0 commit comments