[pim/kcalutils] /: Separate parsing and invitation formatting
Allen Winter <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit f2c731857af8301335b944c7aa9993408a1d10e9 by Allen Winter, on behalf of Volker Krause.
Committed on 05/08/2026 at 19:46.
Pushed by winterz into branch 'master'.
Separate parsing and invitation formatting
This avoids having to do the parsing multiple times.
This also prepares for the removal of the two different HTML variants, as
only the "no HTML" one is used.
M +1 -1 CMakeLists.txt
M +5 -1 autotests/testincidenceformatter.cpp
M +17 -0 src/incidenceformatter.cpp
M +18 -4 src/incidenceformatter.h
https://invent.kde.org/pim/kcalutils/-/commit/f2c731857af8301335b944c7aa9993408a1d10e9
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2fdbfad77..a3e11c8ee 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.29)
-set(PIM_VERSION "6.8.40")
+set(PIM_VERSION "6.8.41")
project(KCalUtils VERSION ${PIM_VERSION})
# ECM setup
diff --git a/autotests/testincidenceformatter.cpp b/autotests/testincidenceformatter.cpp
index 9b6a1e4a1..5cdf93540 100644
--- a/autotests/testincidenceformatter.cpp
+++ b/autotests/testincidenceformatter.cpp
@@ -425,7 +425,11 @@ void IncidenceFormatterTest::testFormatIcalInvitation()
QVERIFY(eventFile.open(QIODevice::ReadOnly));
const QByteArray data = eventFile.readAll();
- const QString html = IncidenceFormatter::formatICalInvitation(QString::fromUtf8(data), calendar, &helper)
+ KCalendarCore::ICalFormat format;
+ const ScheduleMessage::Ptr message = format.parseScheduleMessage(calendar, QString::fromUtf8(data));
+ QVERIFY(message);
+
+ const QString html = IncidenceFormatter::formatICalInvitation(message, &helper, QString())
.replace(btnBg, QStringLiteral("btnBg"))
.replace(btnFg, QStringLiteral("btnFg"))
.replace(btnBdr, QStringLiteral("btnBdr"));
diff --git a/src/incidenceformatter.cpp b/src/incidenceformatter.cpp
index 48ce2d1a1..6f4c83183 100644
--- a/src/incidenceformatter.cpp
+++ b/src/incidenceformatter.cpp
@@ -25,6 +25,7 @@
#include "stringify.h"
#include <KCalendarCore/Event>
+#include <KCalendarCore/Exceptions>
#include <KCalendarCore/FreeBusy>
#include <KCalendarCore/ICalFormat>
#include <KCalendarCore/Journal>
@@ -1985,6 +1986,9 @@ Calendar::Ptr InvitationFormatterHelper::calendar() const
return Calendar::Ptr();
}
+static QString
+formatICalInvitationHelper(const KCalendarCore::ScheduleMessage::Ptr &msg, InvitationFormatterHelper *helper, bool noHtmlMode, const QString &sender);
+
static QString
formatICalInvitationHelper(const QString &invitation, const Calendar::Ptr &mCalendar, InvitationFormatterHelper *helper, bool noHtmlMode, const QString &sender)
{
@@ -2008,6 +2012,14 @@ formatICalInvitationHelper(const QString &invitation, const Calendar::Ptr &mCale
incBase->shiftTimes(mCalendar->timeZone(), QTimeZone::systemTimeZone());
+ return formatICalInvitationHelper(msg, helper, noHtmlMode, sender);
+}
+
+static QString
+formatICalInvitationHelper(const KCalendarCore::ScheduleMessage::Ptr &msg, InvitationFormatterHelper *helper, bool noHtmlMode, const QString &sender)
+{
+ IncidenceBase::Ptr const incBase = msg->event();
+
// Determine if this incidence is in my calendar (and owned by me)
Incidence::Ptr existingIncidence;
if (incBase && helper->calendar()) {
@@ -2273,6 +2285,11 @@ QString IncidenceFormatter::formatICalInvitationNoHtml(const QString &invitation
return formatICalInvitationHelper(invitation, calendar, helper, true, sender);
}
+QString IncidenceFormatter::formatICalInvitation(const KCalendarCore::ScheduleMessage::Ptr &message, InvitationFormatterHelper *helper, const QString &sender)
+{
+ return formatICalInvitationHelper(message, helper, true, sender);
+}
+
/*******************************************************************
* Helper functions for the Incidence tooltips
*******************************************************************/
diff --git a/src/incidenceformatter.h b/src/incidenceformatter.h
index 38397ffe6..b6d386cf2 100644
--- a/src/incidenceformatter.h
+++ b/src/incidenceformatter.h
@@ -22,6 +22,7 @@
#include <KCalendarCore/Calendar>
#include <KCalendarCore/Incidence>
+#include <KCalendarCore/ScheduleMessage>
#include <QDate>
@@ -133,6 +134,7 @@ KCALUTILS_EXPORT QString mailBodyStr(const KCalendarCore::IncidenceBase::Ptr &in
\since 5.23.0
*/
+[[deprecated("use the KCalendarCore::ScheduleMessage overload")]]
KCALUTILS_EXPORT QString formatICalInvitation(const QString &invitation, const KCalendarCore::Calendar::Ptr &calendar, InvitationFormatterHelper *helper);
/*!
@@ -150,10 +152,22 @@ KCALUTILS_EXPORT QString formatICalInvitation(const QString &invitation, const K
\since 5.23.0
*/
-KCALUTILS_EXPORT QString formatICalInvitationNoHtml(const QString &invitation,
- const KCalendarCore::Calendar::Ptr &calendar,
- InvitationFormatterHelper *helper,
- const QString &sender);
+[[deprecated("use the KCalendarCore::ScheduleMessage overload")]]
+KCALUTILS_EXPORT QString
+formatICalInvitationNoHtml(const QString &invitation, const KCalendarCore::Calendar::Ptr &calendar, InvitationFormatterHelper *helper, const QString &sender);
+
+/*!
+ Deliver an HTML formatted string displaying an invitation.
+
+ \param message an iCal schedule message ("invitation")
+ \param calendar a pointer to the Calendar that owns the invitation.
+ \param helper a pointer to an InvitationFormatterHelper.
+ \param sender a QString containing the email address of the person sending the invitation.
+ \return the formatted HTML invitation string
+
+ \since 26.12
+*/
+KCALUTILS_EXPORT QString formatICalInvitation(const KCalendarCore::ScheduleMessage::Ptr &message, InvitationFormatterHelper *helper, const QString &sender);
/*!
Build a pretty QString representation of an Incidence's recurrence info.