File indexing completed on 2024-05-05 16:07:09
0001 /* 0002 SPDX-FileCopyrightText: 2015 Martin Klapetek <mklapetek@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef CALENDAREVENTSPLUGIN_H 0008 #define CALENDAREVENTSPLUGIN_H 0009 0010 #include <QCalendar> 0011 #include <QDateTime> 0012 #include <QMultiHash> 0013 #include <QObject> 0014 #include <QSharedDataPointer> 0015 0016 #include "calendarevents_export.h" 0017 0018 /** 0019 * The CalendarEvents namespace. 0020 */ 0021 namespace CalendarEvents 0022 { 0023 0024 /** 0025 * @class EventData calendareventsplugin.h <CalendarEvents/CalendarEventsPlugin> 0026 * 0027 * Data about an event. 0028 */ 0029 class CALENDAREVENTS_EXPORT EventData 0030 { 0031 public: 0032 enum EventType { 0033 Holiday, // Any holiday 0034 Event, // General event 0035 Todo, // A Todo item 0036 }; 0037 0038 EventData(); 0039 EventData(const EventData &other); 0040 ~EventData(); 0041 0042 EventData &operator=(const EventData &other); 0043 0044 /** 0045 * The start date and time of this event 0046 */ 0047 QDateTime startDateTime() const; 0048 0049 /** 0050 * Set the start date-time of this event 0051 * 0052 * @param startDateTime the date-time of when the event is starting 0053 */ 0054 void setStartDateTime(const QDateTime &startDateTime); 0055 0056 /** 0057 * The end date and time of this event 0058 */ 0059 QDateTime endDateTime() const; 0060 0061 /** 0062 * Set the end date-time of this event 0063 * 0064 * @param endDateTime the date-time of when the event is ending 0065 */ 0066 void setEndDateTime(const QDateTime &endDateTime); 0067 0068 /** 0069 * If true, this event goes on the whole day (eg. a holiday) 0070 */ 0071 bool isAllDay() const; 0072 0073 /** 0074 * If set to true, it will be displayed in the Calendar agenda 0075 * without any time besides it, marked as "going on all day" 0076 * 0077 * This is useful for single-day events only, for multiple-day 0078 * events, leave to false (default) 0079 * 0080 * @param isAllDay set to true if the event takes all day, false otherwise 0081 * (defaults to false) 0082 */ 0083 void setIsAllDay(bool isAllDay); 0084 0085 /** 0086 * If true, this event won't mark the day in the calendar grid 0087 * The main purpose for this flag is to support 0088 * namedays, where in some countries the calendars have 0089 * different name in them every day. This is just a minor holiday 0090 * and as such should not mark the calendar grid, otherwise 0091 * the whole grid would be in a different color. 0092 */ 0093 bool isMinor() const; 0094 0095 /** 0096 * If set to true, it won't be marked in the calendar grid 0097 * 0098 * @param isMinor true if it's a minor event (like a nameday holiday), 0099 * false otherwise (defaults to false) 0100 */ 0101 void setIsMinor(bool isMinor); 0102 0103 /** 0104 * Event title 0105 */ 0106 QString title() const; 0107 0108 /** 0109 * Sets the title of the event 0110 * 0111 * @param title The event title 0112 */ 0113 void setTitle(const QString &title); 0114 0115 /** 0116 * Event description, can provide more details about the event 0117 */ 0118 QString description() const; 0119 0120 /** 0121 * Sets the event description, which allows to add more details 0122 * about this event 0123 * 0124 * @param description The description 0125 */ 0126 void setDescription(const QString &description); 0127 0128 /** 0129 * Type of the current event, eg. a holiday, an event or a todo item 0130 */ 0131 EventType type() const; 0132 0133 /** 0134 * Sets the event type, eg. a holiday, an event or a todo item 0135 * 0136 * @param type The event type, 0137 */ 0138 void setEventType(EventType type); 0139 0140 /** 0141 * The color that should be used to mark this event with 0142 * It comes in the HTML hex format, eg. #AARRGGBB or #RRGGBB 0143 */ 0144 QString eventColor() const; 0145 0146 /** 0147 * This is to support various calendar colors the user might 0148 * have configured elsewhere 0149 * 0150 * @param color The color for this event in the HTML hex format 0151 * eg. #AARRGGBB or #RRGGBB (this is passed directly 0152 * to QML) 0153 */ 0154 void setEventColor(const QString &color); 0155 0156 /** 0157 * Unique ID of the event 0158 */ 0159 QString uid() const; 0160 0161 /** 0162 * Sets the uid of the event 0163 * 0164 * This is a mandatory field only if you want to use 0165 * the eventModified/eventRemoved signals, otherwise 0166 * setting it is optional 0167 * 0168 * @param uid A unique id, recommended is to use the plugin name as prefix (to keep it unique) 0169 */ 0170 void setUid(const QString &uid); 0171 0172 private: 0173 class Private; 0174 QSharedDataPointer<Private> d; 0175 }; 0176 0177 /** 0178 * @class CalendarEventsPlugin calendareventsplugin.h <CalendarEvents/CalendarEventsPlugin> 0179 * 0180 * Plugin for feeding events to a calendar instance. 0181 */ 0182 class CALENDAREVENTS_EXPORT CalendarEventsPlugin : public QObject 0183 { 0184 Q_OBJECT 0185 0186 public: 0187 enum class SubLabelPriority { 0188 Low, /**< Usually used in alternate calendars */ 0189 Default, /**< For holidays or normal events */ 0190 High, /**< For flagged or marked events */ 0191 Urgent, 0192 }; 0193 Q_ENUM(SubLabelPriority) 0194 0195 explicit CalendarEventsPlugin(QObject *parent = nullptr); 0196 ~CalendarEventsPlugin() override; 0197 0198 /** 0199 * When this is called, the plugin should load all events data 0200 * between those two date ranges. Once the data are ready, it should 0201 * just emit the dataReady() signal. The range is usually one month 0202 * 0203 * @param startDate the start of the range 0204 * @param endDate the end of the range 0205 */ 0206 virtual void loadEventsForDateRange(const QDate &startDate, const QDate &endDate) = 0; 0207 0208 struct SubLabel { 0209 QString label; /**< The label will be displayed in the tooltip or beside the full date */ 0210 QString yearLabel; /**< The label will be displayed under the year number */ 0211 QString monthLabel; /**< The label will be displayed under the month number */ 0212 QString dayLabel; /**< The label will be displayed under the day number */ 0213 SubLabelPriority priority = SubLabelPriority::Default; /**< The display priority of the sublabel */ 0214 }; 0215 0216 Q_SIGNALS: 0217 /** 0218 * Emitted when the plugin has loaded the events data 0219 * 0220 * @param data A hash containing a QDate key for the event 0221 * in the value, CalendarEvents::EventData, which holds all 0222 * the details for the given event 0223 * It's a multihash as there can be multiple events 0224 * in the same day 0225 * For multi-day events, insert just one with the key 0226 * being the startdate of the event 0227 */ 0228 void dataReady(const QMultiHash<QDate, CalendarEvents::EventData> &data); 0229 0230 /** 0231 * Should be emitted when there is a modification of an event 0232 * that was previously returned via the dataReady() signal 0233 * 0234 * @param event The modified event data 0235 */ 0236 void eventModified(const CalendarEvents::EventData &modifiedEvent); 0237 0238 /** 0239 * Should be emitted when the plugin removes some event 0240 * from its collection 0241 * 0242 * @param uid The uid of the event that was removed 0243 */ 0244 void eventRemoved(const QString &uid); 0245 0246 /** 0247 * Emitted when the plugin has loaded the alternate dates 0248 * 0249 * @param data A hash containing a QDate key from Gregorian calendar 0250 * for the alternate date in the value, QDate. 0251 * @since 5.95 0252 */ 0253 void alternateDateReady(const QHash<QDate, QDate> &data); 0254 0255 #if CALENDAREVENTS_ENABLE_DEPRECATED_SINCE(5, 106) 0256 /** 0257 * @since 5,102 0258 * @deprecated Do not use, accidentally added to KF5 API. 0259 */ 0260 CALENDAREVENTS_DEPRECATED_VERSION_BELATED(5, 106, 5, 102, "Keep using alternateDateReady(const QHash<QDate, QDate> &data).") 0261 void alternateCalendarDateReady(const QHash<QDate, QCalendar::YearMonthDay> &data); 0262 #endif 0263 0264 /** 0265 * Emitted when the plugin has loaded the sublabels 0266 * 0267 * @param data A hash containing a QDate key for the sublabels 0268 * in the value, SubLabel. 0269 * @since 5.95 0270 */ 0271 void subLabelReady(const QHash<QDate, SubLabel> &data); 0272 }; 0273 0274 /** 0275 * @class ShowEventInterface calendareventsplugin.h <CalendarEvents/CalendarEventsPlugin> 0276 * 0277 * Interface for displaying event details 0278 * 0279 * ShowEventInterface is an additional interface the CalendarEventsPlugin 0280 * implementations can implement if they support displaying details about 0281 * events (e.g. opening the event in KOrganizer). 0282 * 0283 * @since 5.61 0284 */ 0285 class CALENDAREVENTS_EXPORT ShowEventInterface 0286 { 0287 public: 0288 virtual ~ShowEventInterface(); 0289 0290 /** 0291 * When this is called, the plugin should show a window displaying the 0292 * full preview of the event. 0293 * 0294 * The plugin should return true if the event details can be displayed, false 0295 * otherwise. 0296 */ 0297 virtual bool showEvent(const QString &uid) = 0; 0298 }; 0299 0300 } 0301 0302 Q_DECLARE_INTERFACE(CalendarEvents::CalendarEventsPlugin, "org.kde.CalendarEventsPlugin") 0303 Q_DECLARE_INTERFACE(CalendarEvents::ShowEventInterface, "org.kde.CalendarEventsPlugin.ShowEventInterface") 0304 0305 #endif