File indexing completed on 2024-05-12 05:15:03
0001 /* 0002 This file is part of the kcalutils library. 0003 0004 SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 SPDX-FileCopyrightText: 2009-2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 /** 0011 @file 0012 This file is part of the API for handling calendar data and provides 0013 static functions for formatting Incidences for various purposes. 0014 0015 @author Cornelius Schumacher \<schumacher@kde.org\> 0016 @author Reinhold Kainhofer \<reinhold@kainhofer.com\> 0017 @author Allen Winter \<allen@kdab.com\> 0018 */ 0019 #pragma once 0020 0021 #include "kcalutils_export.h" 0022 0023 #include <KCalendarCore/Calendar> 0024 #include <KCalendarCore/Incidence> 0025 0026 #include <QDate> 0027 0028 #include <memory> 0029 0030 namespace KCalUtils 0031 { 0032 class InvitationFormatterHelperPrivate; 0033 0034 /** 0035 * @brief The InvitationFormatterHelper class 0036 */ 0037 class KCALUTILS_EXPORT InvitationFormatterHelper 0038 { 0039 public: 0040 InvitationFormatterHelper(); 0041 virtual ~InvitationFormatterHelper(); 0042 [[nodiscard]] virtual QString generateLinkURL(const QString &id); 0043 [[nodiscard]] virtual QString makeLink(const QString &id, const QString &text); 0044 [[nodiscard]] virtual KCalendarCore::Calendar::Ptr calendar() const; 0045 0046 private: 0047 //@cond PRIVATE 0048 Q_DISABLE_COPY(InvitationFormatterHelper) 0049 std::unique_ptr<InvitationFormatterHelperPrivate> const d; 0050 //@endcond 0051 }; 0052 0053 /** 0054 @brief 0055 Provides methods to format Incidences in various ways for display purposes. 0056 0057 Helpers that provides several static methods to format an Incidence in 0058 different ways: like an HTML representation for KMail, a representation 0059 for tool tips, or a representation for a viewer widget. 0060 0061 */ 0062 namespace IncidenceFormatter 0063 { 0064 /** 0065 Create a QString representation of an Incidence in a nice format 0066 suitable for using in a tooltip. 0067 All dates and times are converted to local time for display. 0068 @param sourceName where the incidence is from (e.g. resource name) 0069 @param incidence is a pointer to the Incidence to be formatted. 0070 @param date is the QDate for which the toolTip should be computed; used 0071 mainly for recurring incidences. Note: For to-dos, this a date between the 0072 start date and the due date (inclusive) of the occurrence. 0073 @param richText if yes, the QString will be created as RichText. 0074 */ 0075 KCALUTILS_EXPORT QString toolTipStr(const QString &sourceName, const KCalendarCore::IncidenceBase::Ptr &incidence, QDate date = QDate(), bool richText = true); 0076 0077 /** 0078 Create a RichText QString representation of an Incidence in a nice format 0079 suitable for using in a viewer widget. 0080 All dates and times are converted to local time for display. 0081 @param calendar is a pointer to the Calendar that owns the specified Incidence. 0082 @param incidence is a pointer to the Incidence to be formatted. 0083 @param date is the QDate for which the string representation should be computed; 0084 used mainly for recurring incidences. 0085 */ 0086 KCALUTILS_EXPORT QString extensiveDisplayStr(const KCalendarCore::Calendar::Ptr &calendar, 0087 const KCalendarCore::IncidenceBase::Ptr &incidence, 0088 QDate date = QDate()); 0089 0090 /** 0091 Create a RichText QString representation of an Incidence in a nice format 0092 suitable for using in a viewer widget. 0093 All dates and times are converted to local time for display. 0094 @param sourceName where the incidence is from (e.g. resource name) 0095 @param incidence is a pointer to the Incidence to be formatted. 0096 @param date is the QDate for which the string representation should be computed; 0097 used mainly for recurring incidences. 0098 */ 0099 KCALUTILS_EXPORT QString extensiveDisplayStr(const QString &sourceName, const KCalendarCore::IncidenceBase::Ptr &incidence, QDate date = QDate()); 0100 0101 /** 0102 Create a QString representation of an Incidence in format suitable for 0103 including inside a mail message. 0104 All dates and times are converted to local time for display. 0105 @param incidence is a pointer to the Incidence to be formatted. 0106 */ 0107 KCALUTILS_EXPORT QString mailBodyStr(const KCalendarCore::IncidenceBase::Ptr &incidence); 0108 0109 /** 0110 Deliver an HTML formatted string displaying an invitation. 0111 Use the time zone from mCalendar. 0112 0113 @param invitation a QString containing a string representation of a calendar Incidence 0114 which will be interpreted as an invitation. 0115 @param calendar is a pointer to the Calendar that owns the invitation. 0116 @param helper is a pointer to an InvitationFormatterHelper. 0117 0118 @since 5.23.0 0119 */ 0120 KCALUTILS_EXPORT QString formatICalInvitation(const QString &invitation, const KCalendarCore::Calendar::Ptr &calendar, InvitationFormatterHelper *helper); 0121 0122 /** 0123 Deliver an HTML formatted string displaying an invitation. 0124 Differs from formatICalInvitation() in that invitation details (summary, location, etc) 0125 have HTML formatting cleaned. 0126 Use the time zone from calendar. 0127 0128 @param invitation a QString containing a string representation of a calendar Incidence 0129 which will be interpreted as an invitation. 0130 @param calendar is a pointer to the Calendar that owns the invitation. 0131 @param helper is a pointer to an InvitationFormatterHelper. 0132 @param sender is a QString containing the email address of the person sending the invitation. 0133 0134 @since 5.23.0 0135 */ 0136 KCALUTILS_EXPORT QString formatICalInvitationNoHtml(const QString &invitation, 0137 const KCalendarCore::Calendar::Ptr &calendar, 0138 InvitationFormatterHelper *helper, 0139 const QString &sender); 0140 0141 /** 0142 Build a pretty QString representation of an Incidence's recurrence info. 0143 @param incidence is a pointer to the Incidence whose recurrence info 0144 is to be formatted. 0145 */ 0146 KCALUTILS_EXPORT QString recurrenceString(const KCalendarCore::Incidence::Ptr &incidence); 0147 0148 /** 0149 Returns a reminder string computed for the specified Incidence. 0150 Each item of the returning QStringList corresponds to a string 0151 representation of an reminder belonging to this incidence. 0152 @param incidence is a pointer to the Incidence. 0153 @param shortfmt if false, a short version of each reminder is printed; 0154 else a longer version of each reminder is printed. 0155 */ 0156 KCALUTILS_EXPORT QStringList reminderStringList(const KCalendarCore::Incidence::Ptr &incidence, bool shortfmt = true); 0157 0158 /** 0159 Build a QString time representation of a QTime object. 0160 @param time The time to be formatted. 0161 @param shortfmt If true, display info in short format. 0162 @see dateToString(), dateTimeToString(). 0163 */ 0164 KCALUTILS_EXPORT QString timeToString(QTime time, bool shortfmt = true); 0165 0166 /** 0167 Build a QString date representation of a QDate object. 0168 All dates and times are converted to local time for display. 0169 @param date The date to be formatted. 0170 @param shortfmt If true, display info in short format. 0171 @see dateToString(), dateTimeToString(). 0172 */ 0173 KCALUTILS_EXPORT QString dateToString(QDate date, bool shortfmt = true); 0174 0175 KCALUTILS_EXPORT QString formatStartEnd(const QDateTime &start, const QDateTime &end, bool isAllDay); 0176 0177 /** 0178 Build a QString date/time representation of a QDateTime object. 0179 All dates and times are converted to local time for display. 0180 @param date The date to be formatted. 0181 @param dateOnly If true, don't print the time fields; print the date fields only. 0182 @param shortfmt If true, display info in short format. 0183 @see dateToString(), timeToString(). 0184 */ 0185 KCALUTILS_EXPORT QString dateTimeToString(const QDateTime &date, bool dateOnly = false, bool shortfmt = true); 0186 0187 /** 0188 Returns a Calendar Resource label name for the specified Incidence. 0189 @param calendar is a pointer to the Calendar. 0190 @param incidence is a pointer to the Incidence. 0191 */ 0192 KCALUTILS_EXPORT QString resourceString(const KCalendarCore::Calendar::Ptr &calendar, const KCalendarCore::Incidence::Ptr &incidence); 0193 0194 /** 0195 Returns a duration string computed for the specified Incidence. 0196 Only makes sense for Events and Todos. 0197 @param incidence is a pointer to the Incidence. 0198 */ 0199 KCALUTILS_EXPORT QString durationString(const KCalendarCore::Incidence::Ptr &incidence); 0200 0201 class EventViewerVisitor; 0202 template<typename T> 0203 class ScheduleMessageVisitor; 0204 class InvitationHeaderVisitor; 0205 class InvitationBodyVisitor; 0206 class ToolTipVisitor; 0207 class MailBodyVisitor; 0208 } 0209 }