feat: enhance login and settings functionality with credential validation and UI improvements

- Added credential validation in login and settings windows to ensure non-empty and ASCII-only username/password.
- Introduced a checkbox to toggle password visibility in both login and settings interfaces.
- Updated UI elements for better layout and user experience, including adjustments to labels and button properties.
- Refactored signal connections for button actions to improve clarity and functionality.
This commit is contained in:
Chenx Dust
2025-01-09 15:57:30 +08:00
parent f6aa51384a
commit 2788f6b2cc
6 changed files with 203 additions and 193 deletions

View File

@@ -38,14 +38,14 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) :
auto applySettings = [&]()
{
if (settings->value("Common/AutoStart").toBool() != (ui->autoStartComboBox->currentText() == ""))
Utils::setAutoStart(ui->autoStartComboBox->currentText() == "");
if (settings->value("Common/AutoStart").toBool() != ui->autoStartCheckBox->isChecked())
Utils::setAutoStart(ui->autoStartCheckBox->isChecked());
settings->setValue("Common/Username", ui->usernameLineEdit->text());
settings->setValue("Common/Password", QString(ui->passwordLineEdit->text().toUtf8().toBase64()));
settings->setValue("Common/AutoStart", ui->autoStartComboBox->currentText() == "");
settings->setValue("Common/ConnectAfterStart", ui->connectAfterStartComboBox->currentText() == "");
settings->setValue("Common/checkUpdateAfterStart", ui->checkUpdateAfterStartComboBox->currentText() == "");
settings->setValue("Common/AutoStart", ui->autoStartCheckBox->isChecked());
settings->setValue("Common/ConnectAfterStart", ui->connectAfterStartCheckBox->isChecked());
settings->setValue("Common/checkUpdateAfterStart", ui->checkUpdateAfterStartCheckBox->isChecked());
settings->setValue("ZJUConnect/ServerAddress", ui->serverAddressLineEdit->text());
settings->setValue("ZJUConnect/ServerPort", ui->serverPortSpinBox->value());
@@ -71,9 +71,18 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) :
settings->sync();
};
connect(ui->buttonBox, &QDialogButtonBox::accepted, applySettings);
connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, [&, applySettings](){
if (!Utils::credentialCheck(ui->usernameLineEdit->text(), ui->passwordLineEdit->text()))
return;
applySettings();
accept();
});
connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, applySettings);
connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, [&, applySettings](){
if (!Utils::credentialCheck(ui->usernameLineEdit->text(), ui->passwordLineEdit->text()))
return;
applySettings();
});
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked,
[&]()
@@ -93,6 +102,12 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) :
ui->routeCheckBox->setEnabled(checked);
ui->dnsHijackCheckBox->setEnabled(checked);
});
connect(ui->passwordVisibleCheckBox, &QCheckBox::checkStateChanged,
[&](Qt::CheckState state)
{
ui->passwordLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password);
});
}
SettingWindow::~SettingWindow()
@@ -107,12 +122,9 @@ void SettingWindow::loadSettings()
QByteArray::fromBase64(settings->value("Common/Password", "").toString().toUtf8())
);
ui->autoStartComboBox->setCurrentText(
settings->value("Common/AutoStart", false).toBool() ? "" : "");
ui->connectAfterStartComboBox->setCurrentText(
settings->value("Common/ConnectAfterStart", false).toBool() ? "" : "");
ui->checkUpdateAfterStartComboBox->setCurrentText(
settings->value("Common/checkUpdateAfterStart", true).toBool() ? "" : "");
ui->autoStartCheckBox->setChecked(settings->value("Common/AutoStart", false).toBool());
ui->connectAfterStartCheckBox->setChecked(settings->value("Common/ConnectAfterStart", false).toBool());
ui->checkUpdateAfterStartCheckBox->setChecked(settings->value("Common/checkUpdateAfterStart", true).toBool());
ui->serverAddressLineEdit->setText(settings->value("ZJUConnect/ServerAddress", "vpn.hitsz.edu.cn").toString());
ui->serverPortSpinBox->setValue(settings->value("ZJUConnect/ServerPort", 443).toInt());