Commit 2b832b9d authored by Volker Krause's avatar Volker Krause
Browse files

Add more reminder notification text variants

- use past tense for past events
- handle all day events
- include the date if the event is not today
- also include the text if there is a dedicated alert message set
parent 0267603d
Pipeline #161307 passed with stage
in 2 minutes and 43 seconds
......@@ -57,22 +57,53 @@ void AlarmNotification::send(KalendarAlarmClient *client, const KCalendarCore::I
m_notification->setText(m_text);
m_notification->setDefaultAction(i18n("View"));
if (!m_text.isEmpty() && m_text != incidence->summary()) { // MS Teams sometimes repeats the summary as the alarm text, we don't need that
m_notification->setText(m_text);
} else if (incidence->type() == KCalendarCore::Incidence::TypeTodo && !incidence->dtStart().isValid()) {
QString text;
const auto now = QDateTime::currentDateTime();
const auto incidenceType = incidence->type() == KCalendarCore::Incidence::TypeTodo ? i18n("Task") : i18n("Event");
if (incidence->type() == KCalendarCore::Incidence::TypeTodo && !incidence->dtStart().isValid()) {
const auto todo = incidence.staticCast<KCalendarCore::Todo>();
m_notification->setText(i18n("Task due at %1", QLocale().toString(todo->dtDue().time(), QLocale::NarrowFormat)));
text = i18n("Task due at %1", QLocale().toString(todo->dtDue().time(), QLocale::NarrowFormat));
} else if (!incidence->allDay()) {
const QString incidenceType = incidence->type() == KCalendarCore::Incidence::TypeTodo ? i18n("Task") : i18n("Event");
const int startOffset = qRound(QDateTime::currentDateTime().secsTo(startTime) / 60.0);
const int startOffset = qRound(now.secsTo(startTime) / 60.0);
if (startOffset > 0 && startOffset < 60) {
m_notification->setText(i18ncp("Event starts in 5 minutes", "%2 starts in %1 minute", "%2 starts in %1 minutes", startOffset, incidenceType));
text = i18ncp("Event starts in 5 minutes", "%2 starts in %1 minute", "%2 starts in %1 minutes", startOffset, incidenceType);
} else if (startTime.date() == now.date()) {
// event is/was today
if (startTime >= now) {
text = i18nc("Event starts at 10:00", "%1 starts at %2", incidenceType, QLocale().toString(startTime.time(), QLocale::NarrowFormat));
} else {
text = i18nc("Event started at 10:00", "%1 started at %2", incidenceType, QLocale().toString(startTime.time(), QLocale::NarrowFormat));
}
} else {
// start time on a different day
if (startTime >= now) {
text = i18nc("Event starts on <DATE> at <TIME>",
"%1 starts on %2 at %3",
incidenceType,
QLocale().toString(startTime.date(), QLocale::NarrowFormat),
QLocale().toString(startTime.time(), QLocale::NarrowFormat));
} else {
text = i18nc("Event started on <DATE> at <TIME>",
"%1 started on %2 at %3",
incidenceType,
QLocale().toString(startTime.date(), QLocale::NarrowFormat),
QLocale().toString(startTime.time(), QLocale::NarrowFormat));
}
}
} else {
// all day events
if (startTime >= now) {
text = i18nc("Event starts on <DATE>", "%1 starts on %2", incidenceType, QLocale().toString(startTime.date(), QLocale::NarrowFormat));
} else {
m_notification->setText(
i18nc("Event starts at 10:00", "%1 starts at %2", incidenceType, QLocale().toString(startTime.time(), QLocale::NarrowFormat)));
text = i18nc("Event started on <DATE>", "%1 started on %2", incidenceType, QLocale().toString(startTime.date(), QLocale::NarrowFormat));
}
}
if (!m_text.isEmpty() && m_text != incidence->summary()) { // MS Teams sometimes repeats the summary as the alarm text, we don't need that
text = m_text + QLatin1Char('\n') + text;
}
m_notification->setText(text);
m_notification->setIconName(incidence->type() == KCalendarCore::Incidence::TypeTodo ? QStringLiteral("view-task")
: QStringLiteral("view-calendar-upcoming"));
......
Supports Markdown
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