aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/settings/SettingsSendMail.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/settings/SettingsSendMail.cpp')
-rw-r--r--src/ui/settings/SettingsSendMail.cpp297
1 files changed, 153 insertions, 144 deletions
diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp
index a5e3274f..8db3cd0a 100644
--- a/src/ui/settings/SettingsSendMail.cpp
+++ b/src/ui/settings/SettingsSendMail.cpp
@@ -22,75 +22,81 @@
*
*/
-#include "ui/SettingsDialog.h"
+#ifdef SMTP_SUPPORT
#include "smtp/SmtpMime"
+#endif
+#include "ui/SettingsDialog.h"
-SendMailTab::SendMailTab(QWidget *parent)
- : QWidget(parent), appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
-
- enableCheckBox = new QCheckBox(tr("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(tr("Check Connection"));
-
- auto generalGroupBox = new QGroupBox(tr("General"));
- auto connectGroupBox = new QGroupBox(tr("Connection"));
- auto preferenceGroupBox = new QGroupBox(tr("Preference"));
-
- auto generalLayout = new QGridLayout();
- generalLayout->addWidget(enableCheckBox);
-
- auto connectLayout = new QGridLayout();
- connectLayout->addWidget(new QLabel(tr("SMTP Address")), 1, 0);
- connectLayout->addWidget(smtpAddress, 1, 1, 1, 4);
- connectLayout->addWidget(new QLabel(tr("Username")), 2, 0);
- connectLayout->addWidget(username, 2, 1, 1, 4);
- connectLayout->addWidget(new QLabel(tr("Password")), 3, 0);
- connectLayout->addWidget(password, 3, 1, 1, 4);
- connectLayout->addWidget(new QLabel(tr("Port")), 4, 0);
- connectLayout->addWidget(portSpin, 4, 1, 1, 1);
- connectLayout->addWidget(new QLabel(tr("Connection Security")), 5, 0);
- connectLayout->addWidget(connectionTypeComboBox, 5, 1, 1, 1);
- connectLayout->addWidget(checkConnectionButton, 6, 0);
-
- auto preferenceLayout = new QGridLayout();
-
- preferenceLayout->addWidget(new QLabel(tr("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)));
- connect(checkConnectionButton, SIGNAL(clicked(bool)), this, SLOT(slotCheckConnection()));
-
-
- this->setLayout(vBox);
- setSettings();
+namespace GpgFrontend::UI {
+
+SendMailTab::SendMailTab(QWidget* parent)
+ : QWidget(parent),
+ appPath(qApp->applicationDirPath()),
+ settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
+ QSettings::IniFormat) {
+ enableCheckBox = new QCheckBox(tr("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(tr("Check Connection"));
+
+ auto generalGroupBox = new QGroupBox(tr("General"));
+ auto connectGroupBox = new QGroupBox(tr("Connection"));
+ auto preferenceGroupBox = new QGroupBox(tr("Preference"));
+
+ auto generalLayout = new QGridLayout();
+ generalLayout->addWidget(enableCheckBox);
+
+ auto connectLayout = new QGridLayout();
+ connectLayout->addWidget(new QLabel(tr("SMTP Address")), 1, 0);
+ connectLayout->addWidget(smtpAddress, 1, 1, 1, 4);
+ connectLayout->addWidget(new QLabel(tr("Username")), 2, 0);
+ connectLayout->addWidget(username, 2, 1, 1, 4);
+ connectLayout->addWidget(new QLabel(tr("Password")), 3, 0);
+ connectLayout->addWidget(password, 3, 1, 1, 4);
+ connectLayout->addWidget(new QLabel(tr("Port")), 4, 0);
+ connectLayout->addWidget(portSpin, 4, 1, 1, 1);
+ connectLayout->addWidget(new QLabel(tr("Connection Security")), 5, 0);
+ connectLayout->addWidget(connectionTypeComboBox, 5, 1, 1, 1);
+ connectLayout->addWidget(checkConnectionButton, 6, 0);
+
+ auto preferenceLayout = new QGridLayout();
+
+ preferenceLayout->addWidget(new QLabel(tr("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)));
+ connect(checkConnectionButton, SIGNAL(clicked(bool)), this,
+ SLOT(slotCheckConnection()));
+
+ this->setLayout(vBox);
+ setSettings();
}
/**********************************
@@ -99,27 +105,28 @@ SendMailTab::SendMailTab(QWidget *parent)
* 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());
-
+ 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());
}
/***********************************
@@ -127,67 +134,69 @@ void SendMailTab::setSettings() {
* 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());
+ 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());
}
+#ifdef SMTP_SUPPORT
void SendMailTab::slotCheckConnection() {
-
- SmtpClient::ConnectionType connectionType;
- const auto selectedConnType = connectionTypeComboBox->currentText();
- if (selectedConnType == "SSL") {
- connectionType = SmtpClient::ConnectionType::SslConnection;
- } else if (selectedConnType == "TLS" || selectedConnType == "STARTTLS") {
- connectionType = SmtpClient::ConnectionType::TlsConnection;
- } else {
- connectionType = SmtpClient::ConnectionType::TcpConnection;
- }
-
- SmtpClient smtp(smtpAddress->text(), portSpin->value(), connectionType);
-
- smtp.setUser(username->text());
- smtp.setPassword(password->text());
-
- bool if_success = true;
-
- if (!smtp.connectToHost()) {
- QMessageBox::critical(this, tr("Fail"), tr("Fail to Connect SMTP Server"));
- if_success = false;
- }
- if (if_success && !smtp.login()) {
- QMessageBox::critical(this, tr("Fail"), tr("Fail to Login"));
- if_success = false;
- }
-
- if (if_success)
- QMessageBox::information(this, tr("Success"), tr("Succeed in connecting and login"));
-
+ SmtpClient::ConnectionType connectionType;
+ const auto selectedConnType = connectionTypeComboBox->currentText();
+ if (selectedConnType == "SSL") {
+ connectionType = SmtpClient::ConnectionType::SslConnection;
+ } else if (selectedConnType == "TLS" || selectedConnType == "STARTTLS") {
+ connectionType = SmtpClient::ConnectionType::TlsConnection;
+ } else {
+ connectionType = SmtpClient::ConnectionType::TcpConnection;
+ }
+
+ SmtpClient smtp(smtpAddress->text(), portSpin->value(), connectionType);
+
+ smtp.setUser(username->text());
+ smtp.setPassword(password->text());
+
+ bool if_success = true;
+
+ if (!smtp.connectToHost()) {
+ QMessageBox::critical(this, tr("Fail"), tr("Fail to Connect SMTP Server"));
+ if_success = false;
+ }
+ if (if_success && !smtp.login()) {
+ QMessageBox::critical(this, tr("Fail"), tr("Fail to Login"));
+ if_success = false;
+ }
+
+ if (if_success)
+ QMessageBox::information(this, tr("Success"),
+ tr("Succeed in connecting and login"));
}
+#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);
- }
+ 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);
+ }
}
+} // namespace GpgFrontend::UI