diff --git a/src/ui/form/opt/pages/basepage.cpp b/src/ui/form/opt/pages/basepage.cpp index dc7aeea1..911aa70c 100644 --- a/src/ui/form/opt/pages/basepage.cpp +++ b/src/ui/form/opt/pages/basepage.cpp @@ -1,5 +1,8 @@ #include "basepage.h" +#include +#include + #include "../optionscontroller.h" BasePage::BasePage(OptionsController *ctrl, @@ -50,3 +53,16 @@ void BasePage::setupController() connect(ctrl(), &OptionsController::retranslateUi, this, &BasePage::onRetranslateUi); } + +bool BasePage::openUrlExternally(const QUrl &url) +{ + return QDesktopServices::openUrl(url); +} + +void BasePage::onLinkClicked() +{ + auto button = qobject_cast(sender()); + if (button) { + openUrlExternally(QUrl::fromLocalFile(button->windowFilePath())); + } +} diff --git a/src/ui/form/opt/pages/basepage.h b/src/ui/form/opt/pages/basepage.h index 7c350e99..5d9d42f7 100644 --- a/src/ui/form/opt/pages/basepage.h +++ b/src/ui/form/opt/pages/basepage.h @@ -2,9 +2,11 @@ #define BASEPAGE_H #include +#include QT_FORWARD_DECLARE_CLASS(QCheckBox) QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QGroupBox) QT_FORWARD_DECLARE_CLASS(QLabel) QT_FORWARD_DECLARE_CLASS(QLineEdit) QT_FORWARD_DECLARE_CLASS(QPushButton) @@ -41,6 +43,9 @@ protected slots: virtual void onRetranslateUi() {} + bool openUrlExternally(const QUrl &url); + void onLinkClicked(); + private: void setupController(); diff --git a/src/ui/form/opt/pages/mainpage.cpp b/src/ui/form/opt/pages/mainpage.cpp index 2d063b6c..871bffe0 100644 --- a/src/ui/form/opt/pages/mainpage.cpp +++ b/src/ui/form/opt/pages/mainpage.cpp @@ -1,6 +1,5 @@ #include "mainpage.h" -#include #include #include #include @@ -8,8 +7,6 @@ #include #include "../../../fortsettings.h" -#include "../../../task/taskinfoupdatechecker.h" -#include "../../../task/taskmanager.h" #include "../../controls/controlutil.h" #include "../optionscontroller.h" #include "addressespage.h" @@ -18,15 +15,6 @@ #include "schedulepage.h" #include "statisticspage.h" -namespace { - -bool openUrlExternally(const QUrl &url) -{ - return QDesktopServices::openUrl(url); -} - -} - MainPage::MainPage(OptionsController *ctrl, QWidget *parent) : BasePage(ctrl, parent) @@ -46,21 +34,12 @@ void MainPage::onRetranslateUi() m_btProfile->setText(tr("Profile")); m_btStat->setText(tr("Statistics")); m_btReleases->setText(tr("Releases")); - m_btNewVersion->setText(tr("New Version!")); m_btOk->setText(tr("OK")); m_btApply->setText(tr("Apply")); m_btCancel->setText(tr("Cancel")); } -void MainPage::onLinkClicked() -{ - auto button = qobject_cast(sender()); - if (button) { - openUrlExternally(QUrl::fromLocalFile(button->windowFilePath())); - } -} - void MainPage::setupUi() { auto layout = new QVBoxLayout(); @@ -97,21 +76,16 @@ QLayout *MainPage::setupDialogButtons() m_btProfile = ControlUtil::createLinkButton(":/images/folder_user.png", settings()->profilePath()); m_btStat = ControlUtil::createLinkButton(":/images/folder_database.png", settings()->statPath()); m_btReleases = ControlUtil::createLinkButton(":/images/server_go.png", settings()->appUpdatesUrl()); - m_btNewVersion = ControlUtil::createLinkButton(":/images/server_compressed.png"); connect(m_btLogs, &QAbstractButton::clicked, this, &MainPage::onLinkClicked); connect(m_btProfile, &QAbstractButton::clicked, this, &MainPage::onLinkClicked); connect(m_btStat, &QAbstractButton::clicked, this, &MainPage::onLinkClicked); connect(m_btReleases, &QAbstractButton::clicked, this, &MainPage::onLinkClicked); - connect(m_btNewVersion, &QAbstractButton::clicked, this, &MainPage::onLinkClicked); - - setupNewVersionButton(); buttonsLayout->addWidget(m_btLogs); buttonsLayout->addWidget(m_btProfile); buttonsLayout->addWidget(m_btStat); buttonsLayout->addWidget(m_btReleases); - buttonsLayout->addWidget(m_btNewVersion); buttonsLayout->addStretch(1); @@ -132,21 +106,6 @@ QLayout *MainPage::setupDialogButtons() return buttonsLayout; } -void MainPage::setupNewVersionButton() -{ - const auto refreshNewVersionButton = [&] { - auto updateChecker = taskManager()->taskInfoUpdateChecker(); - m_btNewVersion->setVisible(!updateChecker->version().isEmpty()); - m_btNewVersion->setWindowFilePath(updateChecker->downloadUrl()); - m_btNewVersion->setToolTip(updateChecker->plainReleaseText()); - }; - - refreshNewVersionButton(); - - connect(taskManager()->taskInfoUpdateChecker(), &TaskInfoUpdateChecker::versionChanged, - this, refreshNewVersionButton); -} - void MainPage::setupOkApplyButtons() { const auto refreshOkApplyButtons = [&] { diff --git a/src/ui/form/opt/pages/mainpage.h b/src/ui/form/opt/pages/mainpage.h index bff4d323..340c3658 100644 --- a/src/ui/form/opt/pages/mainpage.h +++ b/src/ui/form/opt/pages/mainpage.h @@ -22,13 +22,9 @@ public: protected slots: void onRetranslateUi() override; -private slots: - void onLinkClicked(); - private: void setupUi(); QLayout *setupDialogButtons(); - void setupNewVersionButton(); void setupOkApplyButtons(); private: @@ -38,7 +34,6 @@ private: QPushButton *m_btProfile = nullptr; QPushButton *m_btStat = nullptr; QPushButton *m_btReleases = nullptr; - QPushButton *m_btNewVersion = nullptr; QPushButton *m_btOk = nullptr; QPushButton *m_btApply = nullptr; diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index bc7ef674..ea12da01 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -2,16 +2,19 @@ #include #include +#include #include #include #include #include #include -#include "../../../fortmanager.h" -#include "../../../fortsettings.h" #include "../../../conf/firewallconf.h" #include "../../../driver/drivermanager.h" +#include "../../../fortmanager.h" +#include "../../../fortsettings.h" +#include "../../../task/taskinfoupdatechecker.h" +#include "../../../task/taskmanager.h" #include "../../../translationmanager.h" #include "../../../util/stringutil.h" #include "../../controls/controlutil.h" @@ -54,6 +57,12 @@ void OptionsPage::onSaved() void OptionsPage::onRetranslateUi() { + m_gbStartup->setTitle(tr("Startup")); + m_gbTraffic->setTitle(tr("Traffic")); + m_gbGlobal->setTitle(tr("Global")); + m_gbDriver->setTitle(tr("Driver")); + m_gbNewVersion->setTitle(tr("New Version")); + m_cbStart->setText(tr("Start with Windows")); m_cbProvBoot->setText(tr("Stop traffic when Fort Firewall is not running")); m_cbFilterEnabled->setText(tr("Filter Enabled")); @@ -67,21 +76,18 @@ void OptionsPage::onRetranslateUi() m_labelLanguage->setText(tr("Language:")); - m_labelDriver->setText(tr("Driver:")); retranslateDriverMessage(); + m_btInstallDriver->setText(tr("Install")); + m_btRemoveDriver->setText(tr("Remove")); - m_installDriverButton->setText(tr("Install")); - m_removeDriverButton->setText(tr("Remove")); + m_btNewVersion->setText(tr("Download")); } void OptionsPage::setupUi() { - auto rowLayout = new QHBoxLayout(); - // Column #1 auto colLayout1 = new QVBoxLayout(); colLayout1->setSpacing(10); - rowLayout->addLayout(colLayout1); m_cbStart = ControlUtil::createCheckBox(settings()->startWithWindows(), [&](bool) { setIniEdited(true); @@ -110,13 +116,21 @@ void OptionsPage::setupUi() setIniEdited(true); }); - colLayout1->addWidget(m_cbStart); - colLayout1->addWidget(m_cbProvBoot); - colLayout1->addWidget(m_cbFilterEnabled); - colLayout1->addWidget(m_cbFilterLocals); - colLayout1->addWidget(m_cbStopTraffic); - colLayout1->addWidget(m_cbStopInetTraffic); - colLayout1->addWidget(m_cbHotKeys); + m_gbStartup = new QGroupBox(); + auto startupLayout = new QVBoxLayout(); + startupLayout->addWidget(m_cbStart); + startupLayout->addWidget(m_cbProvBoot); + m_gbStartup->setLayout(startupLayout); + colLayout1->addWidget(m_gbStartup); + + m_gbTraffic = new QGroupBox(); + auto trafficLayout = new QVBoxLayout(); + trafficLayout->addWidget(m_cbFilterEnabled); + trafficLayout->addWidget(m_cbFilterLocals); + trafficLayout->addWidget(m_cbStopTraffic); + trafficLayout->addWidget(m_cbStopInetTraffic); + m_gbTraffic->setLayout(trafficLayout); + colLayout1->addWidget(m_gbTraffic); // Password Row auto passwordLayout = new QHBoxLayout(); @@ -138,8 +152,6 @@ void OptionsPage::setupUi() passwordLayout->addWidget(m_editPassword); passwordLayout->addStretch(1); - colLayout1->addLayout(passwordLayout); - // Language Row auto langLayout = new QHBoxLayout(); langLayout->setSpacing(10); @@ -152,20 +164,36 @@ void OptionsPage::setupUi() langLayout->addWidget(m_comboLanguage); langLayout->addStretch(1); - colLayout1->addLayout(langLayout); + m_gbGlobal = new QGroupBox(); + auto globalLayout = new QVBoxLayout(); + globalLayout->addWidget(m_cbHotKeys); + globalLayout->addLayout(passwordLayout); + globalLayout->addLayout(langLayout); + m_gbGlobal->setLayout(globalLayout); + colLayout1->addWidget(m_gbGlobal); colLayout1->addStretch(1); // Column #2 auto colLayout2 = new QVBoxLayout(); colLayout2->setSpacing(10); - rowLayout->addLayout(colLayout2, 1); - auto driverFrame = setupDriverFrame(); + setupDriverBox(); - colLayout2->addWidget(driverFrame, 0, Qt::AlignHCenter); + setupNewVersionBox(); + setupNewVersionUpdate(); + + colLayout2->addWidget(m_gbDriver); + colLayout2->addWidget(m_gbNewVersion); colLayout2->addStretch(1); + // Row + auto rowLayout = new QHBoxLayout(); + rowLayout->addLayout(colLayout1); + rowLayout->addStretch(); + rowLayout->addLayout(colLayout2); + rowLayout->addStretch(); + this->setLayout(rowLayout); } @@ -213,35 +241,25 @@ void OptionsPage::setupComboLanguage() connect(translationManager(), &TranslationManager::languageChanged, this, refreshComboLanguage); } -QFrame *OptionsPage::setupDriverFrame() +void OptionsPage::setupDriverBox() { - auto frame = new QFrame(); - frame->setFrameShape(QFrame::Panel); + m_gbDriver = new QGroupBox(); auto colLayout = new QVBoxLayout(); - colLayout->setMargin(15); colLayout->setSpacing(10); - frame->setLayout(colLayout); + m_gbDriver->setLayout(colLayout); // Label Row auto labelLayout = new QHBoxLayout(); labelLayout->setSpacing(4); colLayout->addLayout(labelLayout); - m_labelDriver = new QLabel(); - { - QFont font; - font.setBold(true); - m_labelDriver->setFont(font); - } - m_labelDriverMessage = new QLabel(); setupDriverIcon(); labelLayout->addStretch(1); labelLayout->addWidget(m_iconDriver, 0, Qt::AlignTop); - labelLayout->addWidget(m_labelDriver); labelLayout->addWidget(m_labelDriverMessage); labelLayout->addStretch(1); @@ -250,23 +268,21 @@ QFrame *OptionsPage::setupDriverFrame() buttonsLayout->setSpacing(10); colLayout->addLayout(buttonsLayout); - m_installDriverButton = ControlUtil::createButton(QString(), [&] { + m_btInstallDriver = ControlUtil::createButton(QString(), [&] { if (fortManager()->showQuestionBox(tr("Install Driver?"))) { fortManager()->installDriver(); } }); - m_removeDriverButton = ControlUtil::createButton(QString(), [&] { + m_btRemoveDriver = ControlUtil::createButton(QString(), [&] { if (fortManager()->showQuestionBox(tr("Remove Driver?"))) { fortManager()->removeDriver(); } }); buttonsLayout->addStretch(1); - buttonsLayout->addWidget(m_installDriverButton); - buttonsLayout->addWidget(m_removeDriverButton); + buttonsLayout->addWidget(m_btInstallDriver); + buttonsLayout->addWidget(m_btRemoveDriver); buttonsLayout->addStretch(1); - - return frame; } void OptionsPage::setupDriverIcon() @@ -300,3 +316,41 @@ void OptionsPage::retranslateDriverMessage() m_labelDriverMessage->setText(text); } + +void OptionsPage::setupNewVersionBox() +{ + m_gbNewVersion = new QGroupBox(); + + auto colLayout = new QVBoxLayout(); + colLayout->setSpacing(10); + m_gbNewVersion->setLayout(colLayout); + + // Label + m_labelNewVersion = new QLabel(); + m_labelNewVersion->setTextFormat(Qt::MarkdownText); + m_labelNewVersion->setOpenExternalLinks(true); + colLayout->addWidget(m_labelNewVersion, 0, Qt::AlignHCenter); + + // Button + m_btNewVersion = ControlUtil::createLinkButton(":/images/server_compressed.png"); + + connect(m_btNewVersion, &QAbstractButton::clicked, this, &OptionsPage::onLinkClicked); + + colLayout->addWidget(m_btNewVersion, 0, Qt::AlignHCenter); +} + +void OptionsPage::setupNewVersionUpdate() +{ + const auto refreshNewVersion = [&] { + auto updateChecker = taskManager()->taskInfoUpdateChecker(); + m_gbNewVersion->setVisible(!updateChecker->version().isEmpty()); + m_labelNewVersion->setText(updateChecker->releaseText()); + m_btNewVersion->setWindowFilePath(updateChecker->downloadUrl()); + m_btNewVersion->setToolTip(updateChecker->downloadUrl()); + }; + + refreshNewVersion(); + + connect(taskManager()->taskInfoUpdateChecker(), &TaskInfoUpdateChecker::versionChanged, + this, refreshNewVersion); +} diff --git a/src/ui/form/opt/pages/optionspage.h b/src/ui/form/opt/pages/optionspage.h index 798e7838..acfa9665 100644 --- a/src/ui/form/opt/pages/optionspage.h +++ b/src/ui/form/opt/pages/optionspage.h @@ -25,13 +25,20 @@ private: void setupEditPassword(); void retranslateEditPassword(); void setupComboLanguage(); - QFrame *setupDriverFrame(); + void setupDriverBox(); void setupDriverIcon(); void retranslateDriverMessage(); + void setupNewVersionBox(); + void setupNewVersionUpdate(); private: bool m_iniEdited = false; + QGroupBox *m_gbStartup = nullptr; + QGroupBox *m_gbTraffic = nullptr; + QGroupBox *m_gbGlobal = nullptr; + QGroupBox *m_gbDriver = nullptr; + QGroupBox *m_gbNewVersion = nullptr; QCheckBox *m_cbStart = nullptr; QCheckBox *m_cbProvBoot = nullptr; QCheckBox *m_cbFilterEnabled = nullptr; @@ -44,10 +51,11 @@ private: QLabel *m_labelLanguage = nullptr; QComboBox *m_comboLanguage = nullptr; QLabel *m_iconDriver = nullptr; - QLabel *m_labelDriver = nullptr; QLabel *m_labelDriverMessage = nullptr; - QPushButton *m_installDriverButton = nullptr; - QPushButton *m_removeDriverButton = nullptr; + QPushButton *m_btInstallDriver = nullptr; + QPushButton *m_btRemoveDriver = nullptr; + QLabel *m_labelNewVersion = nullptr; + QPushButton *m_btNewVersion = nullptr; }; #endif // OPTIONSPAGE_H diff --git a/src/ui/task/taskinfoupdatechecker.cpp b/src/ui/task/taskinfoupdatechecker.cpp index 36ec46ea..40789660 100644 --- a/src/ui/task/taskinfoupdatechecker.cpp +++ b/src/ui/task/taskinfoupdatechecker.cpp @@ -1,7 +1,6 @@ #include "taskinfoupdatechecker.h" #include -#include #include "../../common/version.h" #include "../fortmanager.h" @@ -14,13 +13,6 @@ TaskInfoUpdateChecker::TaskInfoUpdateChecker(QObject *parent) : { } -QString TaskInfoUpdateChecker::plainReleaseText() const -{ - QTextDocument doc; - doc.setMarkdown(releaseText()); - return doc.toPlainText(); -} - QByteArray TaskInfoUpdateChecker::data() const { QByteArray data; diff --git a/src/ui/task/taskinfoupdatechecker.h b/src/ui/task/taskinfoupdatechecker.h index 56de5b3d..e050d6dc 100644 --- a/src/ui/task/taskinfoupdatechecker.h +++ b/src/ui/task/taskinfoupdatechecker.h @@ -16,7 +16,6 @@ public: QString version() const { return m_version; } QString downloadUrl() const { return m_downloadUrl; } QString releaseText() const { return m_releaseText; } - QString plainReleaseText() const; QByteArray data() const override; void setData(const QByteArray &data) override;