diff options
author | Saturneric <[email protected]> | 2022-01-04 15:49:00 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2022-01-04 15:49:00 +0000 |
commit | 952d0424ab1a130d4365bd9995b03a9fc1ddd81b (patch) | |
tree | 4c5e5d3b7b41a3e3ac1da007c47a0189e0e1df0f | |
parent | <feature, fix, refactor>(core, ui): fixed known bugs for v2.0.4-beta.1 and ad... (diff) | |
download | GpgFrontend-952d0424ab1a130d4365bd9995b03a9fc1ddd81b.tar.gz GpgFrontend-952d0424ab1a130d4365bd9995b03a9fc1ddd81b.zip |
<fix, refactor>(core, ui): fixed known bugs for v2.0.4-beta.1.
1. fixed proxy settings ui.
2. fixed send mail settings ui.
3. fixed uncaught exception handling.
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/ui/MainWindow.cpp | 25 | ||||
-rw-r--r-- | src/ui/MainWindow.h | 1 | ||||
-rw-r--r-- | src/ui/function/ProxyConnectionTestThread.cpp | 4 | ||||
-rw-r--r-- | src/ui/settings/SettingsNetwork.cpp | 129 | ||||
-rw-r--r-- | src/ui/settings/SettingsNetwork.h | 2 | ||||
-rw-r--r-- | src/ui/settings/SettingsSendMail.cpp | 50 | ||||
-rw-r--r-- | src/ui/settings/SettingsSendMail.h | 5 | ||||
-rw-r--r-- | ui/NetworkSettings.ui | 2 |
9 files changed, 135 insertions, 84 deletions
diff --git a/src/main.cpp b/src/main.cpp index 149d9b9c..fa4195ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -173,6 +173,7 @@ int main(int argc, char* argv[]) { "program, and now it needs to be restarted. This is not a " "serious problem, it may be the negligence of the programmer, " "please report this problem if you can.")); + return_from_event_loop_code = RESTART_CODE; continue; } diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 44d8103d..2af6da78 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -116,16 +116,20 @@ void MainWindow::init() noexcept { emit loaded(); + // if not prohibit update checking + if (!prohibit_update_checking_) { #ifdef RELEASE - auto version_thread = new VersionCheckThread(); + auto version_thread = new VersionCheckThread(); - connect(version_thread, SIGNAL(finished()), version_thread, - SLOT(deleteLater())); - connect(version_thread, &VersionCheckThread::upgradeVersion, this, - &MainWindow::slotVersionUpgrade); + connect(version_thread, SIGNAL(finished()), version_thread, + SLOT(deleteLater())); + connect(version_thread, &VersionCheckThread::upgradeVersion, this, + &MainWindow::slotVersionUpgrade); - version_thread->start(); + version_thread->start(); #endif + } + } catch (...) { LOG(FATAL) << _("Critical error occur while loading GpgFrontend."); QMessageBox::critical(nullptr, _("Loading Failed"), @@ -301,6 +305,15 @@ void MainWindow::restoreSettings() { smtp.add("enable", libconfig::Setting::TypeBoolean) = true; } + prohibit_update_checking_ = false; + try { + prohibit_update_checking_ = + settings.lookup("network.prohibit_update_checking"); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") + << _("prohibit_update_checking"); + } + } catch (...) { LOG(ERROR) << "cannot resolve settings"; } diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index f5e644b3..5f9d9b50 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -398,6 +398,7 @@ class MainWindow : public QMainWindow { bool attachmentDockCreated{}; bool restartNeeded{}; + bool prohibit_update_checking_ = false; }; } // namespace GpgFrontend::UI diff --git a/src/ui/function/ProxyConnectionTestThread.cpp b/src/ui/function/ProxyConnectionTestThread.cpp index f644406d..76cf525e 100644 --- a/src/ui/function/ProxyConnectionTestThread.cpp +++ b/src/ui/function/ProxyConnectionTestThread.cpp @@ -43,8 +43,8 @@ void GpgFrontend::UI::ProxyConnectionTestThread::run() { auto _reply = manager->get(url_request); while (_reply->isRunning()) QApplication::processEvents(); - if (_reply->error() != QNetworkReply::NoError && - !_reply->readAll().isEmpty()) { + auto _buffer = _reply->readAll(); + if (_reply->error() == QNetworkReply::NoError && !_buffer.isEmpty()) { result_ = "Reachable"; } else { result_ = "Not Reachable"; diff --git a/src/ui/settings/SettingsNetwork.cpp b/src/ui/settings/SettingsNetwork.cpp index a64a9ea9..c457c1a0 100644 --- a/src/ui/settings/SettingsNetwork.cpp +++ b/src/ui/settings/SettingsNetwork.cpp @@ -33,44 +33,11 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent) ui->setupUi(this); connect(ui->enableProxyCheckBox, &QCheckBox::stateChanged, this, - [=](int state) { - ui->proxyServerAddressEdit->setDisabled(state != Qt::Checked); - ui->portSpin->setDisabled(state != Qt::Checked); - ui->proxyTypeComboBox->setDisabled(state != Qt::Checked); - - ui->usernameEdit->setDisabled(state != Qt::Checked); - ui->passwordEdit->setDisabled(state != Qt::Checked); - - ui->checkProxyConnectionButton->setDisabled(state != Qt::Checked); - - proxy_type_ = QNetworkProxy::NoProxy; - }); - - connect(ui->proxyTypeComboBox, &QComboBox::currentTextChanged, this, - [=](const QString ¤t_text) { - if (current_text == "HTTP") { - ui->proxyServerAddressEdit->setDisabled(true); - ui->portSpin->setDisabled(true); - ui->proxyTypeComboBox->setDisabled(true); - ui->usernameEdit->setDisabled(true); - ui->passwordEdit->setDisabled(true); - proxy_type_ = QNetworkProxy::HttpProxy; - } else if (current_text == "Socks5") { - ui->proxyServerAddressEdit->setDisabled(true); - ui->portSpin->setDisabled(true); - ui->proxyTypeComboBox->setDisabled(true); - ui->usernameEdit->setDisabled(true); - ui->passwordEdit->setDisabled(true); - proxy_type_ = QNetworkProxy::Socks5Proxy; - } else { - ui->proxyServerAddressEdit->setDisabled(false); - ui->portSpin->setDisabled(false); - ui->proxyTypeComboBox->setDisabled(false); - ui->usernameEdit->setDisabled(false); - ui->passwordEdit->setDisabled(false); - proxy_type_ = QNetworkProxy::DefaultProxy; - } - }); + [=](int state) { switch_ui_enabled(state == Qt::Checked); }); + + connect( + ui->proxyTypeComboBox, &QComboBox::currentTextChanged, this, + [=](const QString ¤t_text) { switch_ui_proxy_type(current_text); }); connect(ui->checkProxyConnectionButton, &QPushButton::clicked, this, &NetworkTab::slotTestProxyConnectionResult); @@ -89,7 +56,10 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent) ui->passwordLabel->setText(_("Password")); ui->forbidALLCheckBox->setText(_("Forbid all network connection.")); - ui->prohibitUpdateCheck->setText(_("Prohibit checking for updates.")); + ui->forbidALLCheckBox->setDisabled(true); + + ui->prohibitUpdateCheck->setText( + _("Prohibit checking for version updates when the program starts.")); ui->checkProxyConnectionButton->setText(_("Check Proxy Connection")); setSettings(); @@ -133,6 +103,7 @@ void GpgFrontend::UI::NetworkTab::setSettings() { } catch (...) { LOG(ERROR) << _("Setting Operation Error") << _("proxy_type"); } + switch_ui_proxy_type(ui->proxyTypeComboBox->currentText()); ui->enableProxyCheckBox->setCheckState(Qt::Unchecked); try { @@ -145,6 +116,11 @@ void GpgFrontend::UI::NetworkTab::setSettings() { LOG(ERROR) << _("Setting Operation Error") << _("proxy_enable"); } + { + auto state = ui->enableProxyCheckBox->checkState(); + switch_ui_enabled(state == Qt::Checked); + } + ui->forbidALLCheckBox->setCheckState(Qt::Unchecked); try { bool forbid_all_connection = @@ -159,17 +135,20 @@ void GpgFrontend::UI::NetworkTab::setSettings() { ui->prohibitUpdateCheck->setCheckState(Qt::Unchecked); try { - bool prohibit_update = settings.lookup("network.prohibit_update"); - if (prohibit_update) + bool prohibit_update_checking = + settings.lookup("network.prohibit_update_checking"); + if (prohibit_update_checking) ui->prohibitUpdateCheck->setCheckState(Qt::Checked); else ui->prohibitUpdateCheck->setCheckState(Qt::Unchecked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("prohibit_update"); + LOG(ERROR) << _("Setting Operation Error") << _("prohibit_update_checking"); } } void GpgFrontend::UI::NetworkTab::applySettings() { + LOG(INFO) << "called"; + auto &settings = GpgFrontend::UI::GlobalSettingStation::GetInstance().GetUISettings(); @@ -181,9 +160,9 @@ void GpgFrontend::UI::NetworkTab::applySettings() { if (!proxy.exists("proxy_host")) proxy.add("proxy_host", libconfig::Setting::TypeString) = - ui->proxyServerAddressLabel->text().toStdString(); + ui->proxyServerAddressEdit->text().toStdString(); else { - proxy["proxy_host"] = ui->proxyServerAddressLabel->text().toStdString(); + proxy["proxy_host"] = ui->proxyServerAddressEdit->text().toStdString(); } if (!proxy.exists("username")) @@ -220,6 +199,10 @@ void GpgFrontend::UI::NetworkTab::applySettings() { proxy["enable"] = ui->enableProxyCheckBox->isChecked(); } + if (!settings.exists("network") || + settings.lookup("network").getType() != libconfig::Setting::TypeGroup) + settings.add("network", libconfig::Setting::TypeGroup); + auto &network = settings["network"]; if (!network.exists("forbid_all_connection")) @@ -229,14 +212,16 @@ void GpgFrontend::UI::NetworkTab::applySettings() { network["forbid_all_connection"] = ui->forbidALLCheckBox->isChecked(); } - if (!network.exists("prohibit_update")) - network.add("prohibit_update", libconfig::Setting::TypeBoolean) = + if (!network.exists("prohibit_update_checking")) + network.add("prohibit_update_checking", libconfig::Setting::TypeBoolean) = ui->prohibitUpdateCheck->isChecked(); else { - network["prohibit_update"] = ui->prohibitUpdateCheck->isChecked(); + network["prohibit_update_checking"] = ui->prohibitUpdateCheck->isChecked(); } apply_proxy_settings(); + + LOG(INFO) << "done"; } void GpgFrontend::UI::NetworkTab::slotTestProxyConnectionResult() { @@ -253,14 +238,14 @@ void GpgFrontend::UI::NetworkTab::slotTestProxyConnectionResult() { signalProxyConnectionTestResult, this, [=](const QString &result) { if (result == "Reachable") { - QMessageBox::information( - this, _("Success"), - _("Successfully connected to the target server")); + QMessageBox::information(this, _("Success"), + _("Successfully connect to the target " + "server through the proxy server.")); } else { - QMessageBox::information( + QMessageBox::critical( this, _("Failed"), - _("Unable to connect to the target server. Proxy settings " - "may be invalid.")); + _("Unable to connect to the target server through the " + "proxy server. Proxy settings may be invalid.")); } }); connect(thread, &QThread::finished, thread, &QThread::deleteLater); @@ -308,14 +293,42 @@ void GpgFrontend::UI::NetworkTab::apply_proxy_settings() { _proxy.setUser(ui->usernameEdit->text()); _proxy.setPassword(ui->passwordEdit->text()); } - } - if (proxy_type_ == QNetworkProxy::DefaultProxy) { - ; } else { _proxy.setType(proxy_type_); } - LOG(INFO) << "proxy" << _proxy.hostName().toStdString() << _proxy.port() - << _proxy.type(); QNetworkProxy::setApplicationProxy(_proxy); } + +void GpgFrontend::UI::NetworkTab::switch_ui_enabled(bool enabled) { + ui->proxyServerAddressEdit->setDisabled(!enabled); + ui->portSpin->setDisabled(!enabled); + ui->proxyTypeComboBox->setDisabled(!enabled); + ui->usernameEdit->setDisabled(!enabled); + ui->passwordEdit->setDisabled(!enabled); + ui->checkProxyConnectionButton->setDisabled(!enabled); + if (!enabled) proxy_type_ = QNetworkProxy::NoProxy; +} + +void GpgFrontend::UI::NetworkTab::switch_ui_proxy_type( + const QString &type_text) { + if (type_text == "HTTP") { + ui->proxyServerAddressEdit->setDisabled(false); + ui->portSpin->setDisabled(false); + ui->usernameEdit->setDisabled(false); + ui->passwordEdit->setDisabled(false); + proxy_type_ = QNetworkProxy::HttpProxy; + } else if (type_text == "Socks5") { + ui->proxyServerAddressEdit->setDisabled(false); + ui->portSpin->setDisabled(false); + ui->usernameEdit->setDisabled(false); + ui->passwordEdit->setDisabled(false); + proxy_type_ = QNetworkProxy::Socks5Proxy; + } else { + ui->proxyServerAddressEdit->setDisabled(true); + ui->portSpin->setDisabled(true); + ui->usernameEdit->setDisabled(true); + ui->passwordEdit->setDisabled(true); + proxy_type_ = QNetworkProxy::DefaultProxy; + } +} diff --git a/src/ui/settings/SettingsNetwork.h b/src/ui/settings/SettingsNetwork.h index 66803970..cf136604 100644 --- a/src/ui/settings/SettingsNetwork.h +++ b/src/ui/settings/SettingsNetwork.h @@ -49,6 +49,8 @@ class NetworkTab : public QWidget { QNetworkProxy::ProxyType proxy_type_ = QNetworkProxy::HttpProxy; void apply_proxy_settings(); + void switch_ui_enabled(bool enabled); + void switch_ui_proxy_type(const QString& type_text); }; } // namespace GpgFrontend::UI diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp index e4ab9b0b..f0acb10d 100644 --- a/src/ui/settings/SettingsSendMail.cpp +++ b/src/ui/settings/SettingsSendMail.cpp @@ -39,19 +39,8 @@ SendMailTab::SendMailTab(QWidget* parent) : QWidget(parent), ui(std::make_shared<Ui_SendMailSettings>()) { ui->setupUi(this); - connect(ui->enableCheckBox, &QCheckBox::stateChanged, this, [=](int state) { - ui->smtpServerAddressEdit->setDisabled(state != Qt::Checked); - ui->portSpin->setDisabled(state != Qt::Checked); - ui->connextionSecurityComboBox->setDisabled(state != Qt::Checked); - - ui->identityCheckBox->setDisabled(state != Qt::Checked); - ui->usernameEdit->setDisabled(state != Qt::Checked); - ui->passwordEdit->setDisabled(state != Qt::Checked); - - ui->defaultSenderEmailEdit->setDisabled(state != Qt::Checked); - ui->gpgKeyIDEdit->setDisabled(state != Qt::Checked); - ui->checkConnectionButton->setDisabled(state != Qt::Checked); - }); + connect(ui->enableCheckBox, &QCheckBox::stateChanged, this, + [=](int state) { switch_ui_enabled(state == Qt::Checked); }); #ifdef SMTP_SUPPORT connect(ui->checkConnectionButton, &QPushButton::clicked, this, @@ -60,10 +49,8 @@ SendMailTab::SendMailTab(QWidget* parent) &SendMailTab::slotSendTestMail); #endif - connect(ui->identityCheckBox, &QCheckBox::stateChanged, this, [=](int state) { - ui->usernameEdit->setDisabled(state != Qt::Checked); - ui->passwordEdit->setDisabled(state != Qt::Checked); - }); + connect(ui->identityCheckBox, &QCheckBox::stateChanged, this, + [=](int state) { switch_ui_identity_enabled(state == Qt::Checked); }); connect(ui->connextionSecurityComboBox, &QComboBox::currentTextChanged, this, [=](const QString& current_text) { @@ -174,6 +161,11 @@ void SendMailTab::setSettings() { } catch (...) { LOG(ERROR) << _("Setting Operation Error") << _("identity_enable"); } + + { + auto state = ui->identityCheckBox->checkState(); + switch_ui_identity_enabled(state == Qt::Checked); + } ui->enableCheckBox->setCheckState(Qt::Unchecked); try { @@ -185,6 +177,11 @@ void SendMailTab::setSettings() { } catch (...) { LOG(ERROR) << _("Setting Operation Error") << _("save_key_checked"); } + + { + auto state = ui->enableCheckBox->checkState(); + switch_ui_enabled(state == Qt::Checked); + } } void SendMailTab::applySettings() { @@ -383,6 +380,25 @@ void SendMailTab::slotTestSMTPConnectionResult(const QString& result) { ui->senTestMailButton->setDisabled(true); } } + +void SendMailTab::switch_ui_enabled(bool enabled) { + ui->smtpServerAddressEdit->setDisabled(!enabled); + ui->portSpin->setDisabled(!enabled); + ui->connextionSecurityComboBox->setDisabled(!enabled); + + ui->identityCheckBox->setDisabled(!enabled); + ui->usernameEdit->setDisabled(!enabled); + ui->passwordEdit->setDisabled(!enabled); + + ui->defaultSenderEmailEdit->setDisabled(!enabled); + ui->gpgKeyIDEdit->setDisabled(!enabled); + ui->checkConnectionButton->setDisabled(!enabled); +} + +void SendMailTab::switch_ui_identity_enabled(bool enabled) { + ui->usernameEdit->setDisabled(!enabled); + ui->passwordEdit->setDisabled(!enabled); +} #endif } // namespace GpgFrontend::UI diff --git a/src/ui/settings/SettingsSendMail.h b/src/ui/settings/SettingsSendMail.h index 2e0302c8..c866fa5f 100644 --- a/src/ui/settings/SettingsSendMail.h +++ b/src/ui/settings/SettingsSendMail.h @@ -57,6 +57,11 @@ class SendMailTab : public QWidget { R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; SmtpClient::ConnectionType connection_type_ = SmtpClient::ConnectionType::TcpConnection; + + void switch_ui_enabled(bool enabled); + + void switch_ui_identity_enabled(bool enabled); + signals: void signalRestartNeeded(bool needed); diff --git a/ui/NetworkSettings.ui b/ui/NetworkSettings.ui index a288d440..9e27d11b 100644 --- a/ui/NetworkSettings.ui +++ b/ui/NetworkSettings.ui @@ -274,7 +274,7 @@ <item> <widget class="QCheckBox" name="prohibitUpdateCheck"> <property name="text"> - <string>Prohibit checking for updates.</string> + <string>Prohibit checking for version updates when the program starts.</string> </property> </widget> </item> |