Skip to content

Commit 132e486

Browse files
committed
GUI/OptionsDialog: fix proxy field validation and checkbox handling
- Enable validation while typing for proxy fields (proxyIp, proxyPort, proxyIpTor, proxyPortTor) - Fix checkbox signal handling for Qt 6.7+ compatibility - Ensure proxy fields are properly enabled/disabled based on checkbox state
1 parent 2314eb0 commit 132e486

File tree

2 files changed

+97
-18
lines changed

2 files changed

+97
-18
lines changed

src/qt/forms/optionsdialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@
473473
</widget>
474474
</item>
475475
<item>
476-
<widget class="QLineEdit" name="proxyPort">
476+
<widget class="QValidatedLineEdit" name="proxyPort">
477477
<property name="minimumSize">
478478
<size>
479479
<width>55</width>
@@ -660,7 +660,7 @@
660660
</widget>
661661
</item>
662662
<item>
663-
<widget class="QLineEdit" name="proxyPortTor">
663+
<widget class="QValidatedLineEdit" name="proxyPortTor">
664664
<property name="minimumSize">
665665
<size>
666666
<width>55</width>

src/qt/optionsdialog.cpp

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,33 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
278278
ui->proxyPortTor->setEnabled(false);
279279
ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));
280280

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);
281+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
282+
connect(ui->connectSocks, &QCheckBox::checkStateChanged, [this](const Qt::CheckState state){
283+
const bool enabled = (state == Qt::Checked);
284+
ui->proxyIp->setEnabled(enabled);
285+
ui->proxyPort->setEnabled(enabled);
286+
updateProxyValidationState();
287+
});
288+
connect(ui->connectSocksTor, &QCheckBox::checkStateChanged, [this](const Qt::CheckState state){
289+
const bool enabled = (state == Qt::Checked);
290+
ui->proxyIpTor->setEnabled(enabled);
291+
ui->proxyPortTor->setEnabled(enabled);
292+
updateProxyValidationState();
293+
});
294+
#else
295+
connect(ui->connectSocks, &QCheckBox::stateChanged, [this](int state){
296+
const bool enabled = (state == Qt::Checked);
297+
ui->proxyIp->setEnabled(enabled);
298+
ui->proxyPort->setEnabled(enabled);
299+
updateProxyValidationState();
300+
});
301+
connect(ui->connectSocksTor, &QCheckBox::stateChanged, [this](int state){
302+
const bool enabled = (state == Qt::Checked);
303+
ui->proxyIpTor->setEnabled(enabled);
304+
ui->proxyPortTor->setEnabled(enabled);
305+
updateProxyValidationState();
306+
});
307+
#endif
288308

289309
ui->maxuploadtarget->setMinimum(144 /* MiB/day */);
290310
ui->maxuploadtarget->setMaximum(std::numeric_limits<int>::max());
@@ -720,10 +740,23 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
720740
/* setup/change UI elements when proxy IPs are invalid/valid */
721741
ui->proxyIp->setCheckValidator(new ProxyAddressValidator(parent));
722742
ui->proxyIpTor->setCheckValidator(new ProxyAddressValidator(parent));
743+
744+
// do not allow empty input for validation for all proxy fields
745+
ui->proxyIp->setAllowEmptyInput(false);
746+
ui->proxyIpTor->setAllowEmptyInput(false);
747+
ui->proxyPort->setAllowEmptyInput(false);
748+
ui->proxyPortTor->setAllowEmptyInput(false);
749+
750+
// Enable validation while typing for all proxy fields
751+
ui->proxyIp->setAllowValidationWhileEditing(true);
752+
ui->proxyPort->setAllowValidationWhileEditing(true);
753+
ui->proxyIpTor->setAllowValidationWhileEditing(true);
754+
ui->proxyPortTor->setAllowValidationWhileEditing(true);
755+
723756
connect(ui->proxyIp, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);
724757
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);
758+
connect(ui->proxyPort, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);
759+
connect(ui->proxyPortTor, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);
727760

728761
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
729762
ui->showTrayIcon->setChecked(false);
@@ -1152,6 +1185,16 @@ void OptionsDialog::on_okButton_clicked()
11521185
model->setData(model->index(OptionsModel::dustdynamic, 0), "off");
11531186
}
11541187

1188+
// Before mapper->submit()
1189+
if (!ui->connectSocks->isChecked()) {
1190+
ui->proxyIp->clear();
1191+
ui->proxyPort->clear();
1192+
}
1193+
if (!ui->connectSocksTor->isChecked()) {
1194+
ui->proxyIpTor->clear();
1195+
ui->proxyPortTor->clear();
1196+
}
1197+
11551198
mapper->submit();
11561199
accept();
11571200
updateDefaultProxyNets();
@@ -1174,11 +1217,13 @@ void OptionsDialog::on_showTrayIcon_stateChanged(int state)
11741217

11751218
void OptionsDialog::changeEvent(QEvent* e)
11761219
{
1220+
// First let the base class update all child widget palettes
1221+
// required for qvalidatedlineedit invalid colors to update properly
1222+
QWidget::changeEvent(e);
11771223
if (e->type() == QEvent::PaletteChange) {
1224+
// Then update theme colors with the new palette
11781225
updateThemeColors();
11791226
}
1180-
1181-
QWidget::changeEvent(e);
11821227
}
11831228

11841229
void OptionsDialog::togglePruneWarning(bool enabled)
@@ -1211,17 +1256,51 @@ void OptionsDialog::clearStatusLabel()
12111256

12121257
void OptionsDialog::updateProxyValidationState()
12131258
{
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))
1259+
bool socksProxyEnabled = ui->connectSocks->isChecked();
1260+
bool torProxyEnabled = ui->connectSocksTor->isChecked();
1261+
1262+
bool proxyIpValid = ui->proxyIp->isValid();
1263+
bool proxyPortValid = ui->proxyPort->isValid();
1264+
bool proxyIpTorValid = ui->proxyIpTor->isValid();
1265+
bool proxyPortTorValid = ui->proxyPortTor->isValid();
1266+
1267+
// proxy is OK if: disabled OR (enabled AND valid ip and valid port)
1268+
bool socksProxyOk = !socksProxyEnabled || (proxyIpValid && proxyPortValid);
1269+
bool torProxyOk = !torProxyEnabled || (proxyIpTorValid && proxyPortTorValid);
1270+
1271+
// Both must be OK for the form to be valid
1272+
if (socksProxyOk && torProxyOk)
12171273
{
1218-
setOkButtonState(otherProxyWidget->isValid()); //only enable ok button if both proxies are valid
1274+
setOkButtonState(true);
12191275
clearStatusLabel();
12201276
}
12211277
else
12221278
{
12231279
setOkButtonState(false);
1224-
ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
1280+
QStringList socksErrors;
1281+
1282+
if (socksProxyEnabled) {
1283+
if (!proxyIpValid && !proxyPortValid) {
1284+
socksErrors.append(tr("The supplied proxy address and port are invalid."));
1285+
} else if (!proxyIpValid) {
1286+
socksErrors.append(tr("The supplied proxy address is invalid."));
1287+
} else if (!proxyPortValid) {
1288+
socksErrors.append(tr("The supplied proxy port is invalid."));
1289+
}
1290+
}
1291+
if (torProxyEnabled) {
1292+
if (!proxyIpTorValid && !proxyPortTorValid) {
1293+
socksErrors.append(tr("The supplied Tor proxy address and port are invalid."));
1294+
} else if (!proxyIpTorValid) {
1295+
socksErrors.append(tr("The supplied Tor proxy address is invalid."));
1296+
} else if (!proxyPortTorValid) {
1297+
socksErrors.append(tr("The supplied Tor proxy port is invalid."));
1298+
}
1299+
}
1300+
1301+
if (socksErrors.size() > 0) {
1302+
ui->statusLabel->setText(socksErrors.join(" "));
1303+
}
12251304
}
12261305
}
12271306

0 commit comments

Comments
 (0)