mirror of
https://github.com/chenx-dust/EZ4Connect.git
synced 2026-09-20 10:23:33 +08:00
refactor: 优化创建配置时的配置引导
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionValidator>
|
||||
#include <QSettings>
|
||||
#include <QSpinBox>
|
||||
@@ -38,14 +37,12 @@ QString normalizedAuthType(const QString &authType)
|
||||
|
||||
ConfigurationGuideDialog::ConfigurationGuideDialog(
|
||||
QWidget *parent,
|
||||
const QSettings *settings,
|
||||
bool requestProfileName
|
||||
const QSettings *settings
|
||||
)
|
||||
: QDialog(parent),
|
||||
sourceSettings(settings),
|
||||
requestProfileName(requestProfileName)
|
||||
sourceSettings(settings)
|
||||
{
|
||||
setWindowTitle(requestProfileName ? "新建配置" : "配置引导");
|
||||
setWindowTitle("配置引导");
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setMinimumSize(520, 340);
|
||||
|
||||
@@ -67,7 +64,7 @@ ConfigurationGuideDialog::ConfigurationGuideDialog(
|
||||
|
||||
pages = new QStackedWidget(this);
|
||||
pages->addWidget(createProtocolPage());
|
||||
pages->addWidget(createServerPage(requestProfileName));
|
||||
pages->addWidget(createServerPage());
|
||||
pages->addWidget(createAuthenticationPage());
|
||||
pages->addWidget(createCredentialsPage());
|
||||
layout->addWidget(pages, 1);
|
||||
@@ -146,11 +143,6 @@ ConfigurationGuideDialog::ConfigurationGuideDialog(
|
||||
updateNavigation();
|
||||
}
|
||||
|
||||
QString ConfigurationGuideDialog::profileName() const
|
||||
{
|
||||
return profileNameLineEdit->text().trimmed();
|
||||
}
|
||||
|
||||
void ConfigurationGuideDialog::applyTo(QSettings &settings) const
|
||||
{
|
||||
settings.setValue(
|
||||
@@ -207,20 +199,13 @@ void ConfigurationGuideDialog::applyTo(QSettings &settings) const
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
QWidget *ConfigurationGuideDialog::createServerPage(bool showProfileName)
|
||||
QWidget *ConfigurationGuideDialog::createServerPage()
|
||||
{
|
||||
auto *page = new QWidget(this);
|
||||
auto *pageLayout = new QVBoxLayout(page);
|
||||
auto *formLayout = new QFormLayout();
|
||||
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
||||
|
||||
profileNameLabel = new QLabel("配置名称", page);
|
||||
profileNameLineEdit = new QLineEdit(page);
|
||||
profileNameLineEdit->setPlaceholderText("例如:school_vpn");
|
||||
profileNameLabel->setVisible(showProfileName);
|
||||
profileNameLineEdit->setVisible(showProfileName);
|
||||
formLayout->addRow(profileNameLabel, profileNameLineEdit);
|
||||
|
||||
serverAddressLineEdit = new QLineEdit(page);
|
||||
serverAddressLineEdit->setPlaceholderText("例如:vpn.example.edu.cn");
|
||||
serverAddressLineEdit->setText(
|
||||
@@ -640,21 +625,6 @@ bool ConfigurationGuideDialog::validateCurrentPage()
|
||||
{
|
||||
if (pages->currentIndex() == 1)
|
||||
{
|
||||
if (requestProfileName)
|
||||
{
|
||||
const QString name = profileName();
|
||||
const QRegularExpression validName("^[a-zA-Z0-9_-]+$");
|
||||
if (!validName.match(name).hasMatch())
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this,
|
||||
"配置名称无效",
|
||||
"配置名称仅支持字母、数字、下划线和连字符。"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (serverAddressLineEdit->text().trimmed().isEmpty())
|
||||
{
|
||||
QMessageBox::warning(this, "服务器地址无效", "服务器地址不能为空。");
|
||||
|
||||
@@ -20,12 +20,9 @@ class ConfigurationGuideDialog : public QDialog
|
||||
public:
|
||||
explicit ConfigurationGuideDialog(
|
||||
QWidget *parent,
|
||||
const QSettings *settings,
|
||||
bool requestProfileName = false
|
||||
const QSettings *settings
|
||||
);
|
||||
|
||||
QString profileName() const;
|
||||
|
||||
void applyTo(QSettings &settings) const;
|
||||
|
||||
private slots:
|
||||
@@ -38,7 +35,7 @@ private slots:
|
||||
void fetchAuthenticationMethods();
|
||||
|
||||
private:
|
||||
QWidget *createServerPage(bool requestProfileName);
|
||||
QWidget *createServerPage();
|
||||
|
||||
QWidget *createProtocolPage();
|
||||
|
||||
@@ -63,7 +60,6 @@ private:
|
||||
QString authenticationMethodName(const QString &authType) const;
|
||||
|
||||
const QSettings *sourceSettings;
|
||||
bool requestProfileName;
|
||||
|
||||
QLabel *stepLabel;
|
||||
QLabel *titleLabel;
|
||||
@@ -72,8 +68,6 @@ private:
|
||||
QPushButton *backButton;
|
||||
QPushButton *nextButton;
|
||||
|
||||
QLabel *profileNameLabel;
|
||||
QLineEdit *profileNameLineEdit;
|
||||
QLineEdit *serverAddressLineEdit;
|
||||
QSpinBox *serverPortSpinBox;
|
||||
|
||||
|
||||
@@ -587,20 +587,26 @@ void MainWindow::createProfile()
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
const QString name = QInputDialog::getText(
|
||||
this,
|
||||
"新建配置",
|
||||
"请输入配置名称:\n(仅支持字母、数字、下划线和连字符)",
|
||||
QLineEdit::Normal,
|
||||
"",
|
||||
&ok
|
||||
);
|
||||
if (!ok)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (settingWindow != nullptr)
|
||||
{
|
||||
settingWindow->close();
|
||||
}
|
||||
|
||||
ConfigurationGuideDialog guide(this, settings, true);
|
||||
if (guide.exec() != QDialog::Accepted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const QString newProfileId = profileService->createAndSwitch(
|
||||
guide.profileName()
|
||||
);
|
||||
const QString newProfileId = profileService->createAndSwitch(name);
|
||||
if (newProfileId.isEmpty())
|
||||
{
|
||||
QMessageBox::critical(this, "创建失败", "无法创建新配置。");
|
||||
@@ -611,11 +617,15 @@ void MainWindow::createProfile()
|
||||
currentProfileId = profileService->currentProfileId();
|
||||
authenticationDialogs->setSettings(settings);
|
||||
upgradeSettings();
|
||||
guide.applyTo(*settings);
|
||||
updateVersionInfo();
|
||||
resetZjuConnectUi();
|
||||
clearLog();
|
||||
refreshProfileMenu();
|
||||
|
||||
promptConfigurationGuide(
|
||||
"配置已创建",
|
||||
"配置 \"" + newProfileId + "\" 已创建,是否现在使用配置引导完成设置?"
|
||||
);
|
||||
}
|
||||
|
||||
void MainWindow::openConfigurationGuide()
|
||||
@@ -677,19 +687,30 @@ void MainWindow::openConfigurationGuide()
|
||||
}
|
||||
|
||||
void MainWindow::promptFirstLaunchGuide()
|
||||
{
|
||||
promptConfigurationGuide(
|
||||
"欢迎使用 EZ4Connect",
|
||||
"检测到这是首次启动,是否现在配置 VPN 服务器?"
|
||||
);
|
||||
}
|
||||
|
||||
void MainWindow::promptConfigurationGuide(
|
||||
const QString &windowTitle,
|
||||
const QString &text
|
||||
)
|
||||
{
|
||||
QMessageBox messageBox(this);
|
||||
messageBox.setWindowTitle("欢迎使用 EZ4Connect");
|
||||
messageBox.setText("检测到这是首次启动,是否现在配置 VPN 服务器?");
|
||||
messageBox.setWindowTitle(windowTitle);
|
||||
messageBox.setText(text);
|
||||
messageBox.setInformativeText(
|
||||
"配置引导将协助你选择协议、填写服务器地址、认证方式和登录凭据。"
|
||||
);
|
||||
|
||||
QPushButton *startButton = messageBox.addButton(
|
||||
"开始配置",
|
||||
"使用配置引导",
|
||||
QMessageBox::AcceptRole
|
||||
);
|
||||
messageBox.addButton("稍后再说", QMessageBox::RejectRole);
|
||||
messageBox.addButton("稍后配置", QMessageBox::RejectRole);
|
||||
messageBox.setDefaultButton(startButton);
|
||||
messageBox.exec();
|
||||
|
||||
|
||||
@@ -69,6 +69,11 @@ private:
|
||||
|
||||
void openConfigurationGuide();
|
||||
|
||||
void promptConfigurationGuide(
|
||||
const QString &windowTitle,
|
||||
const QString &text
|
||||
);
|
||||
|
||||
void promptFirstLaunchGuide();
|
||||
|
||||
void renameCurrentProfile();
|
||||
|
||||
Reference in New Issue
Block a user