Commit fe0fdc21 authored by Allen Winter's avatar Allen Winter
Browse files

mailclient, alarmdialog.cpp - add errormessage to notification

if sending the mail reminder fails add an error message
to the notification.

coding style: reducing very long lines
parent f033df10
......@@ -385,7 +385,9 @@ static QString cleanSummary(const QString &summary)
return retStr;
}
void AlarmDialog::addIncidence(const Akonadi::Item &incidenceitem, const QDateTime &reminderAt, const QString &displayText)
void AlarmDialog::addIncidence(const Akonadi::Item &incidenceitem,
const QDateTime &reminderAt,
const QString &displayText)
{
Incidence::Ptr incidence = CalendarSupport::incidence(incidenceitem);
ReminderTreeItem *item = searchByItem(incidenceitem);
......@@ -780,11 +782,15 @@ void AlarmDialog::eventNotification()
}
//TODO: support attachments
KOrg::MailClient mailer;
if (!mailer.send(id, from, to, QString(), subject, body, true, false, QString(),
MailTransport::TransportManager::self()->defaultTransportName())) {
const bool sendStatus =
mailer.send(id, from, to, QString(), subject, body, true, false, QString(),
MailTransport::TransportManager::self()->defaultTransportName());
if (!sendStatus) {
KNotification::event(QStringLiteral("mailremindersent"),
QString(),
i18nc("@info", "<warning>Failed to send the Email reminder for %1</warning>", subject),
i18nc("@info email subject, error message",
"<warning>Failed to send the Email reminder for %1. %2</warning>",
subject, mailer.errorMsg()),
QStringLiteral("korgac"),
nullptr,
KNotification::CloseOnTimeout,
......@@ -845,10 +851,9 @@ void AlarmDialog::wakeUp()
Q_EMIT reminderCount(activeCount());
}
void AlarmDialog::slotDBusNotificationsPropertiesChanged(
const QString& interface,
const QVariantMap& changedProperties,
const QStringList& invalidatedProperties)
void AlarmDialog::slotDBusNotificationsPropertiesChanged(const QString &interface,
const QVariantMap &changedProperties,
const QStringList &invalidatedProperties)
{
Q_UNUSED(interface); // always "org.freedesktop.Notifications"
Q_UNUSED(invalidatedProperties);
......@@ -1018,7 +1023,9 @@ void AlarmDialog::accept()
}
/** static */
QDateTime AlarmDialog::triggerDateForIncidence(const Incidence::Ptr &incidence, const QDateTime &reminderAt, QString &displayStr)
QDateTime AlarmDialog::triggerDateForIncidence(const Incidence::Ptr &incidence,
const QDateTime &reminderAt,
QString &displayStr)
{
QDateTime result;
......
......@@ -61,10 +61,19 @@ MailClient::~MailClient()
{
}
bool MailClient::mailAttendees(const KCalendarCore::IncidenceBase::Ptr &incidence, const KIdentityManagement::Identity &identity, bool bccMe, const QString &attachment, const QString &mailTransport)
QString const MailClient::errorMsg()
{
return errorString;
}
bool MailClient::mailAttendees(const KCalendarCore::IncidenceBase::Ptr &incidence,
const KIdentityManagement::Identity &identity, bool bccMe,
const QString &attachment,
const QString &mailTransport)
{
const KCalendarCore::Attendee::List attendees = incidence->attendees();
if (attendees.isEmpty()) {
errorString = i18n("No attendees specified");
qCWarning(KOALARMCLIENT_LOG) << "There are no attendees to e-mail";
return false;
}
......@@ -106,6 +115,7 @@ bool MailClient::mailAttendees(const KCalendarCore::IncidenceBase::Ptr &incidenc
if (toList.isEmpty() && ccList.isEmpty()) {
// Not really to be called a groupware meeting, eh
qCDebug(KOALARMCLIENT_LOG) << "There are really no attendees to e-mail";
errorString = i18n("No attendees specified");
return false;
}
QString to;
......@@ -132,7 +142,11 @@ bool MailClient::mailAttendees(const KCalendarCore::IncidenceBase::Ptr &incidenc
bccMe, attachment, mailTransport);
}
bool MailClient::mailOrganizer(const KCalendarCore::IncidenceBase::Ptr &incidence, const KIdentityManagement::Identity &identity, const QString &from, bool bccMe, const QString &attachment, const QString &sub, const QString &mailTransport)
bool MailClient::mailOrganizer(const KCalendarCore::IncidenceBase::Ptr &incidence,
const KIdentityManagement::Identity &identity,
const QString &from, bool bccMe,
const QString &attachment, const QString &sub,
const QString &mailTransport)
{
const QString to = incidence->organizer().fullName();
QString subject = sub;
......@@ -152,7 +166,11 @@ bool MailClient::mailOrganizer(const KCalendarCore::IncidenceBase::Ptr &incidenc
bccMe, attachment, mailTransport);
}
bool MailClient::mailTo(const KCalendarCore::IncidenceBase::Ptr &incidence, const KIdentityManagement::Identity &identity, const QString &from, bool bccMe, const QString &recipients, const QString &attachment, const QString &mailTransport)
bool MailClient::mailTo(const KCalendarCore::IncidenceBase::Ptr &incidence,
const KIdentityManagement::Identity &identity,
const QString &from, bool bccMe,
const QString &recipients, const QString &attachment,
const QString &mailTransport)
{
QString subject;
......@@ -175,19 +193,25 @@ QStringList extractEmailAndNormalize(const QString &email)
QStringList normalizedEmail;
normalizedEmail.reserve(splittedEmail.count());
for (const QString &email : splittedEmail) {
const QString str = KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(
email));
const QString str =
KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(email));
normalizedEmail << str;
}
return normalizedEmail;
}
bool MailClient::send(const KIdentityManagement::Identity &identity, const QString &from, const QString &_to, const QString &cc, const QString &subject, const QString &body, bool hidden, bool bccMe, const QString &attachment, const QString &mailTransport)
bool MailClient::send(const KIdentityManagement::Identity &identity,
const QString &from, const QString &_to, const QString &cc,
const QString &subject, const QString &body,
bool hidden, bool bccMe,
const QString &attachment,
const QString &mailTransport)
{
Q_UNUSED(hidden);
if (!MailTransport::TransportManager::self()->showTransportCreationDialog(
nullptr, MailTransport::TransportManager::IfNoTransportExists)) {
errorString = i18n("Unable to start the transport manager");
return false;
}
......@@ -222,6 +246,7 @@ bool MailClient::send(const KIdentityManagement::Identity &identity, const QStri
<< mailTransport
<< MailTransport::TransportManager::self()->
defaultTransportName();
errorString = i18n("Unable to determine a mail transport");
return false;
}
......@@ -357,6 +382,7 @@ bool MailClient::send(const KIdentityManagement::Identity &identity, const QStri
qjob->setMessage(message);
if (!qjob->exec()) {
qCDebug(KOALARMCLIENT_LOG) << "Error queuing message in outbox:" << qjob->errorText();
errorString = i18n("Unable to queue the message in the outbox");
return false;
}
......
......@@ -47,11 +47,29 @@ public:
MailClient();
~MailClient();
Q_REQUIRED_RESULT bool mailAttendees(const KCalendarCore::IncidenceBase::Ptr &, const KIdentityManagement::Identity &identity, bool bccMe, const QString &attachment = QString(), const QString &mailTransport = QString());
/**
* Return the error description string.
* Empty if there are no errors.
*/
Q_REQUIRED_RESULT const QString errorMsg();
Q_REQUIRED_RESULT bool mailAttendees(const KCalendarCore::IncidenceBase::Ptr &,
const KIdentityManagement::Identity &identity, bool bccMe,
const QString &attachment = QString(),
const QString &mailTransport = QString());
Q_REQUIRED_RESULT bool mailOrganizer(const KCalendarCore::IncidenceBase::Ptr &, const KIdentityManagement::Identity &identity, const QString &from, bool bccMe, const QString &attachment = QString(), const QString &sub = QString(), const QString &mailTransport = QString());
Q_REQUIRED_RESULT bool mailOrganizer(const KCalendarCore::IncidenceBase::Ptr &,
const KIdentityManagement::Identity &identity,
const QString &from, bool bccMe,
const QString &attachment = QString(),
const QString &sub = QString(),
const QString &mailTransport = QString());
Q_REQUIRED_RESULT bool mailTo(const KCalendarCore::IncidenceBase::Ptr &, const KIdentityManagement::Identity &identity, const QString &from, bool bccMe, const QString &recipients, const QString &attachment = QString(), const QString &mailTransport = QString());
Q_REQUIRED_RESULT bool mailTo(const KCalendarCore::IncidenceBase::Ptr &,
const KIdentityManagement::Identity &identity,
const QString &from, bool bccMe, const QString &recipients,
const QString &attachment = QString(),
const QString &mailTransport = QString());
/**
Sends mail with specified from, to and subject field and body as text.
......@@ -70,7 +88,15 @@ public:
@param mailTransport defines the mail transport method. See here the
kdepimlibs/mailtransport library.
*/
Q_REQUIRED_RESULT bool send(const KIdentityManagement::Identity &identity, const QString &from, const QString &to, const QString &cc, const QString &subject, const QString &body, bool hidden = false, bool bccMe = false, const QString &attachment = QString(), const QString &mailTransport = QString());
Q_REQUIRED_RESULT bool send(const KIdentityManagement::Identity &identity,
const QString &from, const QString &to, const QString &cc,
const QString &subject, const QString &body,
bool hidden = false, bool bccMe = false,
const QString &attachment = QString(),
const QString &mailTransport = QString());
private:
QString errorString;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment