diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/gpg/GpgConstants.cpp | 20 | ||||
-rw-r--r-- | src/gpg/model/GpgKey.h | 2 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 22 | ||||
-rw-r--r-- | src/ui/settings/SettingsSendMail.cpp | 287 | ||||
-rw-r--r-- | src/ui/settings/SettingsSendMail.h | 18 | ||||
-rw-r--r-- | src/ui/smtp/SendMailDialog.cpp | 6 |
8 files changed, 201 insertions, 159 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a0f7eb8..346b1524 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -204,7 +204,7 @@ if (APPLICATION_BUILD) set(GPGFRONTEND_BEFORE_UI_LIBS ${GPGFRONTEND_BEFORE_UI_LIBS} server) endif () if (SMTP_SUPPORT) - set(GPGFRONTEND_AFTER_UI_LIBS ${GPGFRONTEND_AFTER_UI_LIBS} server) + set(GPGFRONTEND_BEFORE_UI_LIBS ${GPGFRONTEND_BEFORE_UI_LIBS} smtp) endif () set(GPGFRONTEND_LIBS ${GPGFRONTEND_AFTER_UI_LIBS} gpgfrontend-ui gpg_core ${GPGFRONTEND_BEFORE_UI_LIBS} easy_logging_pp) diff --git a/src/gpg/GpgConstants.cpp b/src/gpg/GpgConstants.cpp index d38cafe3..fd3c56b4 100644 --- a/src/gpg/GpgConstants.cpp +++ b/src/gpg/GpgConstants.cpp @@ -47,9 +47,9 @@ const char* GpgFrontend::GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD = gpgme_error_t GpgFrontend::check_gpg_error(gpgme_error_t err) { if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - LOG(ERROR) << "[Error " << gpg_err_code(err) - << "] Source: " << gpgme_strsource(err) - << " Description: " << gpgme_strerror(err); + LOG(ERROR) << "[" << _("Error") << " " << gpg_err_code(err) << "] " + << _("Source: ") << gpgme_strsource(err) << " " + << _("Description: ") << gpgme_strerror(err); } return err; } @@ -58,9 +58,9 @@ gpg_err_code_t GpgFrontend::check_gpg_error_2_err_code(gpgme_error_t err, gpgme_error_t predict) { auto err_code = gpg_err_code(err); if (err_code != predict) { - LOG(ERROR) << "[Error " << gpg_err_code(err) - << "] Source: " << gpgme_strsource(err) - << " Description: " << gpgme_strerror(err); + LOG(ERROR) << "[" << _("Error") << " " << gpg_err_code(err) << "] " + << _("Source: ") << gpgme_strsource(err) << " " + << _("Description: ") << gpgme_strerror(err); } return err_code; } @@ -69,9 +69,9 @@ gpg_err_code_t GpgFrontend::check_gpg_error_2_err_code(gpgme_error_t err, gpgme_error_t GpgFrontend::check_gpg_error(gpgme_error_t err, const std::string& comment) { if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - LOG(ERROR) << "[Error " << gpg_err_code(err) - << "] Source: " << gpgme_strsource(err) - << " Description: " << gpgme_strerror(err) << " " << comment; + LOG(ERROR) << "[" << _("Error") << " " << gpg_err_code(err) << "] " + << _("Source: ") << gpgme_strsource(err) << " " + << _("Description: ") << gpgme_strerror(err); } return err; } @@ -216,6 +216,6 @@ GpgFrontend::GpgVerifyResult GpgFrontend::_new_result( } void GpgFrontend::_result_ref_deletor::operator()(void* _result) { - DLOG(INFO) << "Called" << _result; + DLOG(INFO) << _("Called") << _result; if (_result != nullptr) gpgme_result_unref(_result); } diff --git a/src/gpg/model/GpgKey.h b/src/gpg/model/GpgKey.h index 5ddfa94b..4acfa45f 100644 --- a/src/gpg/model/GpgKey.h +++ b/src/gpg/model/GpgKey.h @@ -153,7 +153,7 @@ class GpgKey { private: struct _key_ref_deletor { void operator()(gpgme_key_t _key) { - DLOG(INFO) << "Called" << _key; + DLOG(INFO) << _("Called") << _key; if (_key != nullptr) gpgme_key_unref(_key); } }; diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 7c6bf732..529921e0 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -9,7 +9,6 @@ aux_source_directory(./function UI_SOURCE) aux_source_directory(./details UI_SOURCE) if (SMTP_SUPPORT) - message(STATUS "Build SMTP Support") aux_source_directory(./smtp UI_SOURCE) endif () @@ -18,6 +17,6 @@ set(GPGFRONTEND_UI_LIB_NAME gpgfrontend-ui) target_link_libraries(${GPGFRONTEND_UI_LIB_NAME} Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) target_include_directories(gpgfrontend-ui PUBLIC - ${CMAKE_CURRENT_BINARY_DIR}/${GPGFRONTEND_UI_LIB_NAME}_autogen/include) + ${CMAKE_CURRENT_BINARY_DIR}/${GPGFRONTEND_UI_LIB_NAME}_autogen/include) target_compile_features(gpgfrontend-ui PUBLIC cxx_std_17)
\ No newline at end of file diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 6f51bfcf..8ef66cfa 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -40,6 +40,7 @@ #include "gpg/function/GpgKeyImportExportor.h" #include "ui/UserInterfaceUtils.h" #include "ui/help/AboutDialog.h" +#include "ui/settings/GlobalSettingStation.h" #include "ui/widgets/SignersPicker.h" namespace GpgFrontend::UI { @@ -114,7 +115,16 @@ void MainWindow::slotEncrypt() { if (resultAnalyse.getStatus() >= 0) { infoBoard->resetOptionActionsMenu(); infoBoard->addOptionalAction("Send Mail", [this]() { - if (settings.value("sendMail/enable", false).toBool()) + bool smtp_enabled = false; + try { + smtp_enabled = + GlobalSettingStation::GetInstance().GetUISettings().lookup( + "smtp.enable"); + } catch (...) { + LOG(INFO) << "Reading smtp settings error"; + } + + if (smtp_enabled) new SendMailDialog(edit->curTextPage()->toPlainText(), this); else { QMessageBox::warning(nullptr, _("Function Disabled"), @@ -357,7 +367,15 @@ void MainWindow::slotEncryptSign() { #ifdef SMTP_SUPPORT infoBoard->resetOptionActionsMenu(); infoBoard->addOptionalAction("Send Mail", [this]() { - if (settings.value("sendMail/enable", false).toBool()) + bool smtp_enabled = false; + try { + smtp_enabled = + GlobalSettingStation::GetInstance().GetUISettings().lookup( + "smtp.enable"); + } catch (...) { + LOG(INFO) << "Reading smtp settings error"; + } + if (smtp_enabled) new SendMailDialog(edit->curTextPage()->toPlainText(), this); else { QMessageBox::warning(nullptr, _("Function Disabled"), diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp index 2518991d..bbcf74bc 100644 --- a/src/ui/settings/SettingsSendMail.cpp +++ b/src/ui/settings/SettingsSendMail.cpp @@ -28,126 +28,174 @@ #include "smtp/SmtpMime" #endif +#include "ui/settings/GlobalSettingStation.h" +#include "ui_SendMailSettings.h" + namespace GpgFrontend::UI { SendMailTab::SendMailTab(QWidget* parent) - : QWidget(parent), - appPath(qApp->applicationDirPath()), - settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", - QSettings::IniFormat) { - enableCheckBox = new QCheckBox(_("Enable")); - enableCheckBox->setTristate(false); - - smtpAddress = new QLineEdit(); - username = new QLineEdit(); - password = new QLineEdit(); - password->setEchoMode(QLineEdit::Password); - - portSpin = new QSpinBox(); - portSpin->setMinimum(1); - portSpin->setMaximum(65535); - connectionTypeComboBox = new QComboBox(); - connectionTypeComboBox->addItem("None"); - connectionTypeComboBox->addItem("SSL"); - connectionTypeComboBox->addItem("TLS"); - connectionTypeComboBox->addItem("STARTTLS"); - - defaultSender = new QLineEdit(); - ; - checkConnectionButton = new QPushButton(_("Check Connection")); - - auto generalGroupBox = new QGroupBox(_("General")); - auto connectGroupBox = new QGroupBox(_("Connection")); - auto preferenceGroupBox = new QGroupBox(_("Preference")); - - auto generalLayout = new QGridLayout(); - generalLayout->addWidget(enableCheckBox); - - auto connectLayout = new QGridLayout(); - connectLayout->addWidget(new QLabel(_("SMTP Address")), 1, 0); - connectLayout->addWidget(smtpAddress, 1, 1, 1, 4); - connectLayout->addWidget(new QLabel(_("Username")), 2, 0); - connectLayout->addWidget(username, 2, 1, 1, 4); - connectLayout->addWidget(new QLabel(_("Password")), 3, 0); - connectLayout->addWidget(password, 3, 1, 1, 4); - connectLayout->addWidget(new QLabel(_("Port")), 4, 0); - connectLayout->addWidget(portSpin, 4, 1, 1, 1); - connectLayout->addWidget(new QLabel(_("Connection Security")), 5, 0); - connectLayout->addWidget(connectionTypeComboBox, 5, 1, 1, 1); - connectLayout->addWidget(checkConnectionButton, 6, 0); - - auto preferenceLayout = new QGridLayout(); - - preferenceLayout->addWidget(new QLabel(_("Default Sender")), 0, 0); - preferenceLayout->addWidget(defaultSender, 0, 1, 1, 4); - - generalGroupBox->setLayout(generalLayout); - connectGroupBox->setLayout(connectLayout); - preferenceGroupBox->setLayout(preferenceLayout); - - auto vBox = new QVBoxLayout(); - vBox->addWidget(generalGroupBox); - vBox->addWidget(connectGroupBox); - vBox->addWidget(preferenceGroupBox); - vBox->addStretch(0); - - connect(enableCheckBox, SIGNAL(stateChanged(int)), this, - SLOT(slotCheckBoxSetEnableDisable(int))); - - this->setLayout(vBox); + : 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->checkConnectionButton->setDisabled(state != Qt::Checked); + ui->senTestMailButton->setDisabled(state != Qt::Checked); + }); + + connect(ui->checkConnectionButton, &QPushButton::clicked, this, + &SendMailTab::slotCheckConnection); + + connect(ui->identityCheckBox, &QCheckBox::stateChanged, this, [=](int state) { + ui->usernameEdit->setDisabled(state != Qt::Checked); + ui->passwordEdit->setDisabled(state != Qt::Checked); + }); + setSettings(); } -/********************************** - * Read the settings from config - * and set the buttons and checkboxes - * appropriately - **********************************/ void SendMailTab::setSettings() { - if (settings.value("sendMail/enable", false).toBool()) - enableCheckBox->setCheckState(Qt::Checked); - else { - enableCheckBox->setCheckState(Qt::Unchecked); - smtpAddress->setDisabled(true); - username->setDisabled(true); - password->setDisabled(true); - portSpin->setDisabled(true); - connectionTypeComboBox->setDisabled(true); - defaultSender->setDisabled(true); - checkConnectionButton->setDisabled(true); - } - - smtpAddress->setText( - settings.value("sendMail/smtpAddress", QString()).toString()); - username->setText(settings.value("sendMail/username", QString()).toString()); - password->setText(settings.value("sendMail/password", QString()).toString()); - portSpin->setValue(settings.value("sendMail/port", 25).toInt()); - connectionTypeComboBox->setCurrentText( - settings.value("sendMail/connectionType", "None").toString()); - defaultSender->setText( - settings.value("sendMail/defaultSender", QString()).toString()); + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + + ui->enableCheckBox->setCheckState(Qt::Unchecked); + try { + bool smtp_enable = settings.lookup("smtp.enable"); + if (smtp_enable) ui->enableCheckBox->setCheckState(Qt::Checked); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("save_key_checked"); + } + + ui->identityCheckBox->setCheckState(Qt::Unchecked); + try { + bool identity_enable = settings.lookup("smtp.identity_enable"); + if (identity_enable) ui->identityCheckBox->setCheckState(Qt::Checked); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("identity_enable"); + } + + try { + std::string mail_address = settings.lookup("smtp.mail_address"); + ui->smtpServerAddressEdit->setText(mail_address.c_str()); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("mail_address"); + } + + try { + std::string std_username = settings.lookup("smtp.username"); + ui->usernameEdit->setText(std_username.c_str()); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("username"); + } + + try { + std::string std_password = settings.lookup("smtp.password"); + ui->passwordEdit->setText(std_password.c_str()); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("password"); + } + + try { + int port = settings.lookup("smtp.port"); + ui->portSpin->setValue(port); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("port"); + } + + ui->connextionSecurityComboBox->setCurrentText("None"); + try { + std::string connection_type = settings.lookup("smtp.connection_type"); + ui->connextionSecurityComboBox->setCurrentText(connection_type.c_str()); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("connection_type"); + } + + try { + std::string default_sender = settings.lookup("smtp.default_sender"); + ui->defaultSenderEmailEdit->setText(default_sender.c_str()); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("default_sender"); + } } -/*********************************** - * get the values of the buttons and - * write them to settings-file - *************************************/ void SendMailTab::applySettings() { - settings.setValue("sendMail/smtpAddress", smtpAddress->text()); - settings.setValue("sendMail/username", username->text()); - settings.setValue("sendMail/password", password->text()); - settings.setValue("sendMail/port", portSpin->value()); - settings.setValue("sendMail/connectionType", - connectionTypeComboBox->currentText()); - settings.setValue("sendMail/defaultSender", defaultSender->text()); - - settings.setValue("sendMail/enable", enableCheckBox->isChecked()); + auto& settings = + GpgFrontend::UI::GlobalSettingStation::GetInstance().GetUISettings(); + + if (!settings.exists("smtp") || + settings.lookup("smtp").getType() != libconfig::Setting::TypeGroup) + settings.add("smtp", libconfig::Setting::TypeGroup); + + auto& smtp = settings["smtp"]; + + if (!smtp.exists("mail_address")) + smtp.add("mail_address", libconfig::Setting::TypeString) = + ui->smtpServerAddressEdit->text().toStdString(); + else { + smtp["mail_address"] = ui->smtpServerAddressEdit->text().toStdString(); + } + + if (!smtp.exists("username")) + smtp.add("username", libconfig::Setting::TypeString) = + ui->usernameEdit->text().toStdString(); + else { + smtp["username"] = ui->usernameEdit->text().toStdString(); + } + + if (!smtp.exists("password")) + smtp.add("password", libconfig::Setting::TypeString) = + ui->passwordEdit->text().toStdString(); + else { + smtp["password"] = ui->passwordEdit->text().toStdString(); + } + + if (!smtp.exists("port")) + smtp.add("port", libconfig::Setting::TypeInt) = ui->portSpin->value(); + else { + smtp["port"] = ui->portSpin->value(); + } + + if (!smtp.exists("connection_type")) + smtp.add("connection_type", libconfig::Setting::TypeString) = + ui->connextionSecurityComboBox->currentText().toStdString(); + else { + smtp["connection_type"] = + ui->connextionSecurityComboBox->currentText().toStdString(); + } + + if (!smtp.exists("default_sender")) + smtp.add("default_sender", libconfig::Setting::TypeString) = + ui->defaultSenderEmailEdit->text().toStdString(); + else { + smtp["default_sender"] = ui->defaultSenderEmailEdit->text().toStdString(); + } + + if (!smtp.exists("identity_enable")) + smtp.add("identity_enable", libconfig::Setting::TypeBoolean) = + ui->identityCheckBox->isChecked(); + else { + smtp["identity_enable"] = ui->identityCheckBox->isChecked(); + } + + if (!smtp.exists("enable")) + smtp.add("enable", libconfig::Setting::TypeBoolean) = + ui->enableCheckBox->isChecked(); + else { + smtp["enable"] = ui->enableCheckBox->isChecked(); + } } #ifdef SMTP_SUPPORT void SendMailTab::slotCheckConnection() { SmtpClient::ConnectionType connectionType; - const auto selectedConnType = connectionTypeComboBox->currentText(); + const auto selectedConnType = ui->connextionSecurityComboBox->currentText(); if (selectedConnType == "SSL") { connectionType = SmtpClient::ConnectionType::SslConnection; } else if (selectedConnType == "TLS" || selectedConnType == "STARTTLS") { @@ -156,10 +204,13 @@ void SendMailTab::slotCheckConnection() { connectionType = SmtpClient::ConnectionType::TcpConnection; } - SmtpClient smtp(smtpAddress->text(), portSpin->value(), connectionType); + SmtpClient smtp(ui->smtpServerAddressEdit->text(), ui->portSpin->value(), + connectionType); - smtp.setUser(username->text()); - smtp.setPassword(password->text()); + if (ui->identityCheckBox->isChecked()) { + smtp.setUser(ui->usernameEdit->text()); + smtp.setPassword(ui->passwordEdit->text()); + } bool if_success = true; @@ -178,24 +229,6 @@ void SendMailTab::slotCheckConnection() { } #endif -void SendMailTab::slotCheckBoxSetEnableDisable(int state) { - if (state == Qt::Checked) { - smtpAddress->setEnabled(true); - username->setEnabled(true); - password->setEnabled(true); - portSpin->setEnabled(true); - connectionTypeComboBox->setEnabled(true); - defaultSender->setEnabled(true); - checkConnectionButton->setEnabled(true); - } else { - smtpAddress->setDisabled(true); - username->setDisabled(true); - password->setDisabled(true); - portSpin->setDisabled(true); - connectionTypeComboBox->setDisabled(true); - defaultSender->setDisabled(true); - checkConnectionButton->setDisabled(true); - } -} +void SendMailTab::slotCheckBoxSetEnableDisable(int state) {} } // namespace GpgFrontend::UI diff --git a/src/ui/settings/SettingsSendMail.h b/src/ui/settings/SettingsSendMail.h index ec8f83c9..be1a9b7c 100644 --- a/src/ui/settings/SettingsSendMail.h +++ b/src/ui/settings/SettingsSendMail.h @@ -7,6 +7,8 @@ #include "ui/GpgFrontendUI.h" +class Ui_SendMailSettings; + namespace GpgFrontend::UI { class SendMailTab : public QWidget { Q_OBJECT @@ -22,20 +24,10 @@ class SendMailTab : public QWidget { void slotCheckBoxSetEnableDisable(int state); - private: - QString appPath; - QSettings settings; - - QCheckBox* enableCheckBox; + void slotCheckConnection(); - QLineEdit* smtpAddress; - QLineEdit* username; - QLineEdit* password; - QSpinBox* portSpin; - QComboBox* connectionTypeComboBox; - QLineEdit* defaultSender; - - QPushButton* checkConnectionButton; + private: + std::shared_ptr<Ui_SendMailSettings> ui; signals: diff --git a/src/ui/smtp/SendMailDialog.cpp b/src/ui/smtp/SendMailDialog.cpp index 7c8933a0..40939242 100644 --- a/src/ui/smtp/SendMailDialog.cpp +++ b/src/ui/smtp/SendMailDialog.cpp @@ -26,7 +26,7 @@ #include <utility> -#ifdef STMP_ENABLED +#ifdef SMTP_SUPPORT #include "smtp/SmtpMime" #endif @@ -72,7 +72,7 @@ SendMailDialog::SendMailDialog(QString text, QWidget* parent) layout->addWidget(confirmButton, 3, 1); layout->addWidget(errorLabel, 4, 0, 1, 2); -#ifdef STMP_ENABLED +#ifdef SMTP_SUPPORT connect(confirmButton, SIGNAL(clicked(bool)), this, SLOT(slotConfirm())); #endif @@ -87,7 +87,7 @@ bool SendMailDialog::check_email_address(const QString& str) { return re_email.match(str).hasMatch(); } -#ifdef STMP_ENABLED +#ifdef SMTP_SUPPORT void SendMailDialog::slotConfirm() { QString errString; |