Browse Source

Merge pull request #7643 from Chocobo1/email

Allow SMTP sender to be set. Closes #7575.
adaptive-webui-19844
Mike Tzou 7 years ago committed by GitHub
parent
commit
e8cf351b6a
  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 @@ -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);
}

2
src/app/application.h

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

10
src/base/preferences.cpp

@ -308,6 +308,16 @@ void Preferences::setMailNotificationEnabled(bool enabled) @@ -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();

2
src/base/preferences.h

@ -139,6 +139,8 @@ public: @@ -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;

3
src/gui/optionsdlg.cpp

@ -248,6 +248,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -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() @@ -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() @@ -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());

20
src/gui/optionsdlg.ui

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

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

@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
<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>
<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 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"/>

Loading…
Cancel
Save