From fc0628d35bd7fc60983e9ab555dcbddf53bab4f5 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 25 Oct 2017 20:58:01 +0800 Subject: [PATCH] Allow SMTP sender to be set. Closes #7575. --- src/app/application.cpp | 24 +++++++++---------- src/app/application.h | 2 +- src/base/preferences.cpp | 10 ++++++++ src/base/preferences.h | 2 ++ src/gui/optionsdlg.cpp | 3 +++ src/gui/optionsdlg.ui | 20 ++++++++++++---- src/webui/www/public/preferences_content.html | 2 +- 7 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 2eae2b087..86a5137cd 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -307,22 +307,22 @@ void Application::runExternalProgram(BitTorrent::TorrentHandle *const torrent) c #endif } -void Application::sendNotificationEmail(BitTorrent::TorrentHandle *const torrent) +void Application::sendNotificationEmail(const BitTorrent::TorrentHandle *torrent) { // Prepare mail content - QString content = QObject::tr("Torrent name: %1").arg(torrent->name()) + "\n"; - content += QObject::tr("Torrent size: %1").arg(Utils::Misc::friendlyUnit(torrent->wantedSize())) + "\n"; - content += QObject::tr("Save path: %1").arg(torrent->savePath()) + "\n\n"; - content += QObject::tr("The torrent was downloaded in %1.", - "The torrent was downloaded in 1 hour and 20 seconds") - .arg(Utils::Misc::userFriendlyDuration(torrent->activeTime())) + "\n\n\n"; - content += QObject::tr("Thank you for using qBittorrent.") + "\n"; + const QString content = tr("Torrent name: %1").arg(torrent->name()) + "\n" + + tr("Torrent size: %1").arg(Utils::Misc::friendlyUnit(torrent->wantedSize())) + "\n" + + tr("Save path: %1").arg(torrent->savePath()) + "\n\n" + + tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds") + .arg(Utils::Misc::userFriendlyDuration(torrent->activeTime())) + "\n\n\n" + + tr("Thank you for using qBittorrent.") + "\n"; // Send the notification email - Net::Smtp *sender = new Net::Smtp; - sender->sendMail("notification@qbittorrent.org", - Preferences::instance()->getMailNotificationEmail(), - QObject::tr("[qBittorrent] '%1' has finished downloading").arg(torrent->name()), + const Preferences *pref = Preferences::instance(); + Net::Smtp *smtp = new Net::Smtp(this); + smtp->sendMail(pref->getMailNotificationSender(), + pref->getMailNotificationEmail(), + tr("[qBittorrent] '%1' has finished downloading").arg(torrent->name()), content); } diff --git a/src/app/application.h b/src/app/application.h index f698a5e54..67675e2e8 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -145,7 +145,7 @@ private: void initializeTranslation(); void processParams(const QStringList ¶ms); void runExternalProgram(BitTorrent::TorrentHandle *const torrent) const; - void sendNotificationEmail(BitTorrent::TorrentHandle *const torrent); + void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent); void validateCommandLineParameters(); }; diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index f1a2884d7..ddf42f736 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -308,6 +308,16 @@ void Preferences::setMailNotificationEnabled(bool enabled) setValue("Preferences/MailNotification/enabled", enabled); } +QString Preferences::getMailNotificationSender() const +{ + return value("Preferences/MailNotification/sender", "qBittorrent_notification@example.com").toString(); +} + +void Preferences::setMailNotificationSender(const QString &mail) +{ + setValue("Preferences/MailNotification/sender", mail); +} + QString Preferences::getMailNotificationEmail() const { return value("Preferences/MailNotification/email").toString(); diff --git a/src/base/preferences.h b/src/base/preferences.h index 7654b94d9..a5057965c 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -139,6 +139,8 @@ public: void setScanDirsLastPath(const QString &path); bool isMailNotificationEnabled() const; void setMailNotificationEnabled(bool enabled); + QString getMailNotificationSender() const; + void setMailNotificationSender(const QString &mail); QString getMailNotificationEmail() const; void setMailNotificationEmail(const QString &mail); QString getMailNotificationSMTP() const; diff --git a/src/gui/optionsdlg.cpp b/src/gui/optionsdlg.cpp index aa7fa6e75..0c6565311 100644 --- a/src/gui/optionsdlg.cpp +++ b/src/gui/optionsdlg.cpp @@ -248,6 +248,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(m_ui->addScanFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton); connect(m_ui->removeScanFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton); connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton); + connect(m_ui->senderEmailTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->dest_email_txt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->smtp_server_txt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkSmtpSSL, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); @@ -567,6 +568,7 @@ void OptionsDialog::saveOptions() session->setTorrentExportDirectory(getTorrentExportDir()); session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir()); pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked()); + pref->setMailNotificationSender(m_ui->senderEmailTxt->text()); pref->setMailNotificationEmail(m_ui->dest_email_txt->text()); pref->setMailNotificationSMTP(m_ui->smtp_server_txt->text()); pref->setMailNotificationSMTPSSL(m_ui->checkSmtpSSL->isChecked()); @@ -815,6 +817,7 @@ void OptionsDialog::loadOptions() } m_ui->groupMailNotification->setChecked(pref->isMailNotificationEnabled()); + m_ui->senderEmailTxt->setText(pref->getMailNotificationSender()); m_ui->dest_email_txt->setText(pref->getMailNotificationEmail()); m_ui->smtp_server_txt->setText(pref->getMailNotificationSMTP()); m_ui->checkSmtpSSL->setChecked(pref->getMailNotificationSMTPSSL()); diff --git a/src/gui/optionsdlg.ui b/src/gui/optionsdlg.ui index a489b067d..7848d8513 100644 --- a/src/gui/optionsdlg.ui +++ b/src/gui/optionsdlg.ui @@ -1119,26 +1119,36 @@ - + - + - Destination email: + To: - + SMTP server: - + + + + + + + + From: + + + diff --git a/src/webui/www/public/preferences_content.html b/src/webui/www/public/preferences_content.html index 08de3291c..7b3007baf 100644 --- a/src/webui/www/public/preferences_content.html +++ b/src/webui/www/public/preferences_content.html @@ -47,7 +47,7 @@
- +