Browse Source

Allow SMTP sender to be set. Closes #7575.

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
fc0628d35b
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 24
      src/app/application.cpp
  2. 2
      src/app/application.h
  3. 10
      src/base/preferences.cpp
  4. 2
      src/base/preferences.h
  5. 3
      src/gui/optionsdlg.cpp
  6. 20
      src/gui/optionsdlg.ui
  7. 2
      src/webui/www/public/preferences_content.html

24
src/app/application.cpp

@ -307,22 +307,22 @@ void Application::runExternalProgram(BitTorrent::TorrentHandle *const torrent) c
#endif #endif
} }
void Application::sendNotificationEmail(BitTorrent::TorrentHandle *const torrent) void Application::sendNotificationEmail(const BitTorrent::TorrentHandle *torrent)
{ {
// Prepare mail content // Prepare mail content
QString content = QObject::tr("Torrent name: %1").arg(torrent->name()) + "\n"; const QString content = tr("Torrent name: %1").arg(torrent->name()) + "\n"
content += QObject::tr("Torrent size: %1").arg(Utils::Misc::friendlyUnit(torrent->wantedSize())) + "\n"; + tr("Torrent size: %1").arg(Utils::Misc::friendlyUnit(torrent->wantedSize())) + "\n"
content += QObject::tr("Save path: %1").arg(torrent->savePath()) + "\n\n"; + tr("Save path: %1").arg(torrent->savePath()) + "\n\n"
content += QObject::tr("The torrent was downloaded in %1.", + tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds")
"The torrent was downloaded in 1 hour and 20 seconds") .arg(Utils::Misc::userFriendlyDuration(torrent->activeTime())) + "\n\n\n"
.arg(Utils::Misc::userFriendlyDuration(torrent->activeTime())) + "\n\n\n"; + tr("Thank you for using qBittorrent.") + "\n";
content += QObject::tr("Thank you for using qBittorrent.") + "\n";
// Send the notification email // Send the notification email
Net::Smtp *sender = new Net::Smtp; const Preferences *pref = Preferences::instance();
sender->sendMail("notification@qbittorrent.org", Net::Smtp *smtp = new Net::Smtp(this);
Preferences::instance()->getMailNotificationEmail(), smtp->sendMail(pref->getMailNotificationSender(),
QObject::tr("[qBittorrent] '%1' has finished downloading").arg(torrent->name()), pref->getMailNotificationEmail(),
tr("[qBittorrent] '%1' has finished downloading").arg(torrent->name()),
content); content);
} }

2
src/app/application.h

@ -145,7 +145,7 @@ private:
void initializeTranslation(); void initializeTranslation();
void processParams(const QStringList &params); void processParams(const QStringList &params);
void runExternalProgram(BitTorrent::TorrentHandle *const torrent) const; void runExternalProgram(BitTorrent::TorrentHandle *const torrent) const;
void sendNotificationEmail(BitTorrent::TorrentHandle *const torrent); void sendNotificationEmail(const BitTorrent::TorrentHandle *torrent);
void validateCommandLineParameters(); void validateCommandLineParameters();
}; };

10
src/base/preferences.cpp

@ -308,6 +308,16 @@ void Preferences::setMailNotificationEnabled(bool enabled)
setValue("Preferences/MailNotification/enabled", 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 QString Preferences::getMailNotificationEmail() const
{ {
return value("Preferences/MailNotification/email").toString(); return value("Preferences/MailNotification/email").toString();

2
src/base/preferences.h

@ -139,6 +139,8 @@ public:
void setScanDirsLastPath(const QString &path); void setScanDirsLastPath(const QString &path);
bool isMailNotificationEnabled() const; bool isMailNotificationEnabled() const;
void setMailNotificationEnabled(bool enabled); void setMailNotificationEnabled(bool enabled);
QString getMailNotificationSender() const;
void setMailNotificationSender(const QString &mail);
QString getMailNotificationEmail() const; QString getMailNotificationEmail() const;
void setMailNotificationEmail(const QString &mail); void setMailNotificationEmail(const QString &mail);
QString getMailNotificationSMTP() const; QString getMailNotificationSMTP() const;

3
src/gui/optionsdlg.cpp

@ -248,6 +248,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->addScanFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton); connect(m_ui->addScanFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
connect(m_ui->removeScanFolderButton, &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->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->dest_email_txt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
connect(m_ui->smtp_server_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); connect(m_ui->checkSmtpSSL, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
@ -567,6 +568,7 @@ void OptionsDialog::saveOptions()
session->setTorrentExportDirectory(getTorrentExportDir()); session->setTorrentExportDirectory(getTorrentExportDir());
session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir()); session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked()); pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked());
pref->setMailNotificationSender(m_ui->senderEmailTxt->text());
pref->setMailNotificationEmail(m_ui->dest_email_txt->text()); pref->setMailNotificationEmail(m_ui->dest_email_txt->text());
pref->setMailNotificationSMTP(m_ui->smtp_server_txt->text()); pref->setMailNotificationSMTP(m_ui->smtp_server_txt->text());
pref->setMailNotificationSMTPSSL(m_ui->checkSmtpSSL->isChecked()); pref->setMailNotificationSMTPSSL(m_ui->checkSmtpSSL->isChecked());
@ -815,6 +817,7 @@ void OptionsDialog::loadOptions()
} }
m_ui->groupMailNotification->setChecked(pref->isMailNotificationEnabled()); m_ui->groupMailNotification->setChecked(pref->isMailNotificationEnabled());
m_ui->senderEmailTxt->setText(pref->getMailNotificationSender());
m_ui->dest_email_txt->setText(pref->getMailNotificationEmail()); m_ui->dest_email_txt->setText(pref->getMailNotificationEmail());
m_ui->smtp_server_txt->setText(pref->getMailNotificationSMTP()); m_ui->smtp_server_txt->setText(pref->getMailNotificationSMTP());
m_ui->checkSmtpSSL->setChecked(pref->getMailNotificationSMTPSSL()); m_ui->checkSmtpSSL->setChecked(pref->getMailNotificationSMTPSSL());

20
src/gui/optionsdlg.ui

@ -1119,26 +1119,36 @@
<layout class="QVBoxLayout" name="verticalLayout_171"> <layout class="QVBoxLayout" name="verticalLayout_171">
<item> <item>
<layout class="QGridLayout" name="gridLayout_9"> <layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="dest_email_txt"/> <widget class="QLineEdit" name="dest_email_txt"/>
</item> </item>
<item row="0" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Destination email:</string> <string>To:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>SMTP server:</string> <string>SMTP server:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="smtp_server_txt"/> <widget class="QLineEdit" name="smtp_server_txt"/>
</item> </item>
<item row="0" column="1">
<widget class="QLineEdit" name="senderEmailTxt"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_25">
<property name="text">
<string>From:</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

2
src/webui/www/public/preferences_content.html

@ -47,7 +47,7 @@
<legend><input type="checkbox" id="mail_notification_checkbox" onclick="updateMailNotification();"/> <legend><input type="checkbox" id="mail_notification_checkbox" onclick="updateMailNotification();"/>
<label for="mail_notification_checkbox">QBT_TR(Email notification upon download completion)QBT_TR[CONTEXT=OptionsDialog]</label></legend> <label for="mail_notification_checkbox">QBT_TR(Email notification upon download completion)QBT_TR[CONTEXT=OptionsDialog]</label></legend>
<div class="formRow"> <div class="formRow">
<label for="dest_email_txt" class="leftLabelLarge">QBT_TR(Destination email:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="dest_email_txt"/> <label for="dest_email_txt" class="leftLabelLarge">QBT_TR(To:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="dest_email_txt"/>
</div> </div>
<div class="formRow"> <div class="formRow">
<label for="smtp_server_txt" class="leftLabelLarge">QBT_TR(SMTP server:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="smtp_server_txt"/> <label for="smtp_server_txt" class="leftLabelLarge">QBT_TR(SMTP server:)QBT_TR[CONTEXT=OptionsDialog]</label><input type="text" id="smtp_server_txt"/>

Loading…
Cancel
Save