Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
FrzMtrsprt committed Jun 26, 2023
1 parent ef23d6b commit 966fc27
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 79 deletions.
56 changes: 40 additions & 16 deletions locale/QtUnblockNeteaseMusic_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,28 @@ Please run QtUnblockNeteaseMusic as Administrator from context menu.</source>
请从右键菜单以管理员身份运行 QtUnblockNeteaseMusic。</translation>
</message>
<message>
<source>Unable to convert CA certificate.</source>
<translation>无法转换证书。</translation>
<source>Error %1: %2</source>
<translation>错误 %1:%2</translation>
</message>
<message>
<source>Unable to open CA certificate store.</source>
<translation>无法打开证书存储。</translation>
<source>The certificate is installed.</source>
<translation>证书安装成功。</translation>
</message>
<message>
<source>Unable to add CA certificate to store.</source>
<translation>无法添加证书至存储。</translation>
</message>
<message>
<source>Error %1: %2</source>
<translation>错误 %1:%2</translation>
<source>Unable to convert CA certificate.</source>
<translation>无法转换证书。</translation>
</message>
<message>
<source>The certificate is installed.</source>
<translation>证书安装成功。</translation>
<source>Unable to open CA certificate store.</source>
<translation>无法打开证书存储。</translation>
</message>
<message>
<source>Unable to read CA certificate.</source>
<translation>无法读取证书。</translation>
</message>
</context>
<context>
Expand Down Expand Up @@ -284,17 +288,17 @@ Please change the arguments or check port usage and try again.</source>
<source>&amp;Install</source>
<translation>安装(&amp;I)</translation>
</message>
<message>
<source>Please select the certificate to install.</source>
<translation>请选择要安装的证书。</translation>
</message>
</context>
<context>
<name>WizardPage2</name>
<message>
<source>Browse...</source>
<translation>浏览…</translation>
</message>
<message>
<source>Select certificate file</source>
<translation>选择证书文件</translation>
</message>
<message>
<source>Certificate files (*.crt)</source>
<translation>证书文件 (*.crt)</translation>
Expand All @@ -303,16 +307,36 @@ Please change the arguments or check port usage and try again.</source>
<source>&amp;Install</source>
<translation>安装(&amp;I)</translation>
</message>
<message>
<source>Please select the certificate file to install.</source>
<translation>请选择要安装的证书文件。</translation>
</message>
<message>
<source>Select file</source>
<translation>选择文件</translation>
</message>
</context>
<context>
<name>WizardPage3</name>
<message>
<source>Success</source>
<translation>成功</translation>
<source>Details</source>
<translation>详细信息</translation>
</message>
<message>
<source>Install failed</source>
<translation>安装失败</translation>
</message>
<message>
<source>Install succeeded</source>
<translation>安装成功</translation>
</message>
<message>
<source>The certificate has been added to the root certificate store.</source>
<translation>证书已被添加至根证书存储中。</translation>
</message>
<message>
<source>Failed</source>
<translation>失败</translation>
<source>The certificate could not be added to the root certificate store.</source>
<translation>证书无法被添加至根证书存储中。</translation>
</message>
</context>
</TS>
38 changes: 14 additions & 24 deletions src/envdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@
<string>Parameters</string>
</attribute>
<layout class="QGridLayout">
<item row="4" column="1" rowspan="2">
<widget class="QPlainTextEdit" name="otherEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>-option1 parameter1
-option2 parameter2</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="tokenEdit"/>
</item>
Expand Down Expand Up @@ -65,20 +51,24 @@
<property name="text">
<string>Other</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="4" column="1">
<widget class="QPlainTextEdit" name="otherEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
<property name="placeholderText">
<string>-option1 parameter1
-option2 parameter2</string>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ void MainWindow::on_installCA()
wizard->addPage(new WizardPage3(wizard));

wizard->setAttribute(Qt::WA_DeleteOnClose);
wizard->setPixmap(QWizard::LogoPixmap,
style()->standardIcon(QStyle::SP_FileIcon).pixmap(64, 64));
wizard->setWindowTitle(tr("Install certificate"));
wizard->setWizardStyle(QWizard::ModernStyle);

Expand Down
44 changes: 17 additions & 27 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
<property name="text">
<string>Sources</string>
</property>
</widget>
</item>
<item row="6" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</spacer>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="urlLabel">
Expand Down Expand Up @@ -88,7 +84,7 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="6" column="0">
<widget class="QLabel" name="strictLabel">
<property name="statusTip">
<string>Enable proxy limitation</string>
Expand All @@ -98,19 +94,6 @@
</property>
</widget>
</item>
<item row="5" column="1" rowspan="2" colspan="2">
<widget class="QTextEdit" name="sourceEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="statusTip">
<string>Set priority of sources</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="httpsEdit">
<property name="sizePolicy">
Expand All @@ -122,9 +105,6 @@
<property name="statusTip">
<string>Specify server HTTPS port</string>
</property>
<property name="placeholderText">
<string notr="true">HTTPS</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
Expand All @@ -150,7 +130,7 @@
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<item row="6" column="1" colspan="2">
<widget class="QCheckBox" name="strictCheckBox">
<property name="statusTip">
<string>Enable proxy limitation</string>
Expand All @@ -174,8 +154,18 @@
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string notr="true">HTTP</string>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QTextEdit" name="sourceEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="statusTip">
<string>Set priority of sources</string>
</property>
</widget>
</item>
Expand Down
4 changes: 4 additions & 0 deletions src/utils/winutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ std::tuple<bool, QString, QString> WinUtils::installCA(const QString &caPath)
caFile.open(QIODevice::ReadOnly);
const QByteArray caData = caFile.readAll();
caFile.close();
if(caData.isEmpty())
{
return {false, QObject::tr("Unable to read CA certificate."), QString()};
}

// Convert CA certificate to binary
// Reference: https://stackoverflow.com/a/34643021
Expand Down
44 changes: 32 additions & 12 deletions src/wizardpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "utils/winutils.h"
#endif

#include <QBoxLayout>
#include <QButtonGroup>
#include <QCommandLinkButton>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
Expand Down Expand Up @@ -39,6 +40,7 @@ WizardPage1::WizardPage1(QWidget *parent)

setLayout(vboxLayout);
setTitle(tr("Select certificate"));
setSubTitle(tr("Please select the certificate to install."));

connect(buttonGroup, &QButtonGroup::buttonClicked,
this, &WizardPage1::on_clicked);
Expand Down Expand Up @@ -92,18 +94,19 @@ WizardPage2::WizardPage2(QWidget *parent)
{
QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setReadOnly(true);
QPushButton *toolButton = new QPushButton(this);
toolButton->setText(tr("Browse..."));
QPushButton *browseButton = new QPushButton(this);
browseButton->setText(tr("Browse..."));

QHBoxLayout *hboxLayout = new QHBoxLayout(this);
hboxLayout->addWidget(lineEdit);
hboxLayout->addWidget(toolButton);
hboxLayout->addWidget(browseButton);

setLayout(hboxLayout);
setTitle(tr("Select certificate file"));
setTitle(tr("Select file"));
setSubTitle(tr("Please select the certificate file to install."));
setButtonText(QWizard::NextButton, tr("&Install"));

connect(toolButton, &QPushButton::clicked,
connect(browseButton, &QPushButton::clicked,
this, &WizardPage2::on_browse);
connect(lineEdit, &QLineEdit::textChanged,
this, &QWizardPage::completeChanged);
Expand Down Expand Up @@ -139,12 +142,27 @@ void WizardPage2::on_browse()
WizardPage3::WizardPage3(QWidget *parent)
: QWizardPage(parent)
{
QPlainTextEdit *detailsEdit = new QPlainTextEdit(this);
detailsEdit->setReadOnly(true);
QLabel *errorLabel = new QLabel(this);
errorLabel->setObjectName(u"errorLabel"_s);

QLabel *detailsEdit = new QLabel(this);
detailsEdit->setObjectName(u"detailsEdit"_s);
detailsEdit->setAlignment(Qt::AlignTop);
detailsEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
detailsEdit->setTextInteractionFlags(Qt::TextSelectableByMouse);

QVBoxLayout *detailsLayout = new QVBoxLayout(this);
detailsLayout->addWidget(detailsEdit);

QGroupBox *detailsBox = new QGroupBox(this);
detailsBox->setTitle(tr("Details"));
detailsBox->setLayout(detailsLayout);

QVBoxLayout *vboxLayout = new QVBoxLayout(this);
vboxLayout->addWidget(errorLabel);
vboxLayout->addWidget(detailsEdit);
vboxLayout->addWidget(detailsBox);

setLayout(vboxLayout);
}

WizardPage3::~WizardPage3()
Expand All @@ -159,7 +177,9 @@ void WizardPage3::initializePage()
#else
const auto [succeed, error, detail] = std::make_tuple(false, u"Unsupported"_s, QString());
#endif
setTitle(succeed ? tr("Success") : tr("Failed"));
findChild<QLabel *>()->setText(error);
findChild<QPlainTextEdit *>()->setPlainText(detail);
setTitle(succeed ? tr("Install succeeded") : tr("Install failed"));
setSubTitle(succeed ? tr("The certificate has been added to the root certificate store.")
: tr("The certificate could not be added to the root certificate store."));
findChild<QLabel *>(u"errorLabel"_s)->setText(error);
findChild<QLabel *>(u"detailsEdit"_s)->setText(detail);
}

0 comments on commit 966fc27

Please sign in to comment.