Akonadi Calendar

itiphandler.h
1/*
2 SPDX-FileCopyrightText: 2002-2004 Klarälvdalens Datakonsult AB,
3 <info@klaralvdalens-datakonsult.se>
4
5 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
6 SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
7
8 SPDX-FileCopyrightText: 2012 SĂ©rgio Martins <iamsergio@gmail.com>
9
10 SPDX-License-Identifier: LGPL-2.0-or-later
11*/
12
13#pragma once
14
15#include "akonadi-calendar_export.h"
16#include "etmcalendar.h"
17
18#include <KCalendarCore/Incidence>
19#include <KCalendarCore/ScheduleMessage>
20
21#include <KGuiItem>
22#include <KLocalizedString>
23#include <KStandardGuiItem>
24
25#include <QObject>
26#include <QString>
27#include <QWidget>
28
29#include <memory>
30
31namespace Akonadi
32{
33class MessageQueueJob;
34}
35
36namespace KIdentityManagementCore
37{
38class Identity;
39}
40
41namespace Akonadi
42{
43class ITIPHandlerPrivate;
44
45/**
46 * @short Ui delegate for editing counter proposals.
47 * @since 4.11
48 */
49class AKONADI_CALENDAR_EXPORT GroupwareUiDelegate : public QObject
50{
51 Q_OBJECT
52public:
53 explicit GroupwareUiDelegate(QObject *parent = nullptr);
54 ~GroupwareUiDelegate() override;
55
56 virtual void requestIncidenceEditor(const Akonadi::Item &item) = 0;
57 virtual void setCalendar(const Akonadi::ETMCalendar::Ptr &calendar) = 0;
58 virtual void createCalendar() = 0;
59};
60
61/**
62 * @short Ui delegate for dialogs raised by the ITIPHandler and IncidenceChanger.
63 * @since 4.15
64 */
65class AKONADI_CALENDAR_EXPORT ITIPHandlerDialogDelegate : public QObject
66{
67 Q_OBJECT
68public:
69 // Possible default actions
70 enum Action {
71 ActionAsk, /**< Ask the user for a decision */
72 ActionSendMessage, /**< Answer with Yes */
73 ActionDontSendMessage /**< Answer with No */
74 };
75
76 // How will receive the mail afterwards
77 enum Recipient {
78 Organizer, /**< the organizer of the incidence */
79 Attendees /**< the attendees of the incidence */
80 };
81
82 enum DialogAction {
83 OkAction = 1,
84 CancelAction = 2,
85 PrimaryAction = 3,
86 SecondaryAction = 4,
87 ContinueAction = 5
88 };
89
90 /**
91 * Creates a new AskDelegator
92 */
94
95 /*
96 * Opens a Dialog, when an incidence is created
97 * The function must emit a dialogClosed signal with the user's answer
98 *
99 * @param recipient: to who the mail will be sent afterwards
100 * @param question: dialog's question
101 * @param action: Should the dialog been shown or should a default answer be returned
102 * @param buttonYes: dialog's yes answer
103 * @param buttonNo: dialog's no answer
104 */
105 virtual void openDialogIncidenceCreated(Recipient recipient,
106 const QString &question,
107 Action action = ActionAsk,
108 const KGuiItem &buttonYes = KGuiItem(i18nc("@action:button dialog positive answer", "Send Email")),
109 const KGuiItem &buttonNo = KGuiItem(i18nc("@action:button dialog negative answer", "Do Not Send")));
110
111 /*
112 * Opens a Dialog, when an incidence is modified
113 * The function must emit a dialogClosed signal with the user's answer
114 *
115 * @param attendeeStatusChanged: Only the status of the own attendeeStatus is changed
116 * @param recipient: to who the mail will be sent afterwards
117 * @param question: dialog's question
118 * @param action: Should the dialog been shown or should a default answer be returned
119 * @param buttonYes: dialog's yes answer
120 * @param buttonNo: dialog's no answer
121 */
122 virtual void openDialogIncidenceModified(bool attendeeStatusChanged,
123 Recipient recipient,
124 const QString &question,
125 Action action = ActionAsk,
126 const KGuiItem &buttonYes = KGuiItem(i18nc("@action:button dialog positive answer", "Send Email")),
127 const KGuiItem &buttonNo = KGuiItem(i18nc("@action:button dialog negative answer", "Do Not Send")));
128
129 /*
130 * Opens a Dialog, when an incidence is deleted
131 * The function must emit a dialogClosed signal with the user's answer
132 *
133 * @param recipient: to who the mail will be sent afterwards
134 * @param question: dialog's question
135 * @param action: Should the dialog been shown or should a default answer be returned
136 * @param buttonYes: dialog's yes answer
137 * @param buttonNo: dialog's no answer
138 */
139 virtual void openDialogIncidenceDeleted(Recipient recipient,
140 const QString &question,
141 Action action = ActionAsk,
142 const KGuiItem &buttonYes = KGuiItem(i18nc("@action:button dialog positive answer", "Send Email")),
143 const KGuiItem &buttonNo = KGuiItem(i18nc("@action:button dialog negative answer", "Do Not Send")));
144 /*
145 * Opens a Dialog, when mail was sended
146 * The function must emit a dialogClosed signal with the user's answer
147 *
148 * @param question: dialog's question
149 * @param action: Should the dialog been shown or should a default answer be returned
150 * @param buttonYes: dialog's yes answer
151 * @param buttonNo: dialog's no answer
152 */
153 virtual void openDialogSchedulerFinished(const QString &question,
154 Action action = ActionAsk,
155 const KGuiItem &buttonYes = KGuiItem(i18nc("@action:button dialog positive answer", "Send Email")),
156 const KGuiItem &buttonNo = KGuiItem(i18nc("@action:button dialog negative answer", "Do Not Send")));
157
158 /**
159 * Opens a warning message box with two accept actions and cancel action.
160 * @param text: dialog's text
161 * @param title: dialog's title
162 * @param primaryAction: dialog's primary action
163 * @param secondaryAction: dialog's secondary action
164 * @param cancelAction: dialog's cancel action
165 * @returns The button clicked by the user (KMessageBox::ButtonCode)
166 */
167 virtual int warningTwoActionsCancel(const QString &text,
168 const QString &title,
169 const KGuiItem &primaryAction,
170 const KGuiItem &secondaryAction,
171 const KGuiItem &cancelAction = KStandardGuiItem::cancel());
172 /**
173 * Opens a warning message box with a Continue and Cancel actions
174 * @param text: dialog's text
175 * @param title: dialog's title
176 * @param buttonContinue: dialog's continue answer
177 * @param buttonCancel: dialog's cancel answer.
178 * @returns The button clicked by the user (KMessageBox::ButtonCode)
179 */
180 [[nodiscard]] virtual int warningContinueCancel(const QString &text,
181 const QString &title,
182 const KGuiItem &buttonContinue = KStandardGuiItem::cont(),
183 const KGuiItem &buttonCancel = KStandardGuiItem::cancel());
184
185Q_SIGNALS:
186 /*
187 * Signal is emitted, when the user has answered the dialog or the defaultAction is used
188 * @param answer: answer should be part of KMessageBox:ButtonCode, keep in mind that it is a YesNoDialog so normally it should be KMessageBox::Yes or
189 * KMessageBox::No
190 * @param method: itip method
191 * @param incidence: purpose of the dialog
192 */
193 void dialogClosed(int answer, KCalendarCore::iTIPMethod method, const KCalendarCore::Incidence::Ptr &incidence);
194
195protected:
196 /*
197 * Opens a KMessageBox::questionYesNo with the question
198 *
199 * @return KMessageBox::Yes or KMessageBox::No
200 *
201 * @param question: dialog's question
202 * @param action: Should the dialog been shown or should a default answer be returned
203 * @param buttonYes: dialog's yes answer
204 * @param buttonNo: dialog's no answer
205 */
206 int askUserIfNeeded(const QString &question, Action action, const KGuiItem &buttonYes, const KGuiItem &buttonNo) const;
207
208 // parent of the dialog
209 QWidget *mParent = nullptr;
210
211 // Incidence related to the dialog
213
214 // ITIPMethod related to the dialog
216};
217
218/**
219 * @short Factory to create Akonadi::MessageQueueJob jobs or ITIPHandlerDialogDelegate objects.
220 * @since 4.15
221 */
222class AKONADI_CALENDAR_EXPORT ITIPHandlerComponentFactory : public QObject
223{
224 Q_OBJECT
225public:
226 /*
227 * Created a new ITIPHandlerComponentFactory object.
228 */
229 explicit ITIPHandlerComponentFactory(QObject *parent = nullptr);
230
231 /*
232 * deletes the object.
233 */
235
236 /*
237 * @return A new Akonadi::MessageQueueJob object
238 * @param incidence related to the mail
239 * @param identity that is the mail sender
240 * @param parent of the Akonadi::MessageQueueJob object
241 */
243 createMessageQueueJob(const KCalendarCore::IncidenceBase::Ptr &incidence, const KIdentityManagementCore::Identity &identity, QObject *parent = nullptr);
244
245 /*
246 * @return A new ITIPHandlerDialogDelegate object
247 * @param incidence the purpose of the dialogs
248 * @param method the ITIPMethod
249 * @parent parent of the AskDelegator
250 *
251 */
253 createITIPHanderDialogDelegate(const KCalendarCore::Incidence::Ptr &incidence, KCalendarCore::iTIPMethod method, QWidget *parent = nullptr);
254};
255
256/**
257 * @short Handles sending of iTip messages as well as processing incoming ones.
258 * @since 4.11
259 */
260class AKONADI_CALENDAR_EXPORT ITIPHandler : public QObject
261{
262 Q_OBJECT
263public:
264 enum Result {
265 ResultError, /**< An unexpected error occurred */
266 ResultSuccess, /**< The invitation was successfully handled. */
267 ResultCancelled /**< User cancelled the operation. @since 4.12 */
268 };
269
270 /**
271 * Creates a new ITIPHandler instance.
272 * creates a default ITIPHandlerComponentFactory object.
273 */
274 explicit ITIPHandler(QObject *parent = nullptr);
275
276 /**
277 * Create a new ITIPHandler instance.
278 * @param factory is set to 0 a new factory is created.
279 * @since 4.15
280 */
281 explicit ITIPHandler(ITIPHandlerComponentFactory *factory, QObject *parent);
282 /**
283 * Destroys this instance.
284 */
285 ~ITIPHandler() override;
286
287 /**
288 * Processes a received iTip message.
289 *
290 * @param receiver
291 * @param iCal
292 * @param type
293 *
294 * @see iTipMessageProcessed()
295 */
296 void processiTIPMessage(const QString &receiver, const QString &iCal, const QString &type);
297
298 /**
299 * Sends an iTip message.
300 *
301 * @param method iTip method
302 * @param incidence Incidence for which we're sending the iTip message.
303 * Should contain a list of attendees.
304 * @param parentWidget
305 */
306 void sendiTIPMessage(KCalendarCore::iTIPMethod method, const KCalendarCore::Incidence::Ptr &incidence, QWidget *parentWidget = nullptr);
307
308 /**
309 * Publishes incidence @p incidence.
310 * A publish dialog will prompt the user to input recipients.
311 * @see rfc2446 3.2.1
312 */
313 void publishInformation(const KCalendarCore::Incidence::Ptr &incidence, QWidget *parentWidget = nullptr);
314
315 /**
316 * Sends an e-mail with the incidence attached as iCalendar source.
317 * A dialog will prompt the user to input recipients.
318 */
319 void sendAsICalendar(const KCalendarCore::Incidence::Ptr &incidence, QWidget *parentWidget = nullptr);
320
321 /**
322 * Sets the UI delegate to edit counter proposals.
323 */
324 void setGroupwareUiDelegate(GroupwareUiDelegate *delegate);
325
326 /**
327 * Sets the calendar that the itip handler should use.
328 * The calendar should already be loaded.
329 *
330 * If none is set, a FetchJobCalendar will be created internally.
331 */
332 void setCalendar(const Akonadi::CalendarBase::Ptr &calendar);
333
334 /**
335 * Sets if the ITIP handler should show dialogs on error.
336 * Default is true, for compatibility reasons, but this will change in KDE5.
337 * TODO_KDE5: use message delegates
338 *
339 * @since 4.12
340 */
341 void setShowDialogsOnError(bool enable);
342
343 /**
344 * Returns the calendar used by this itip handler.
345 */
346 Akonadi::CalendarBase::Ptr calendar() const;
347
348Q_SIGNALS:
349 /**
350 * Sent after processing an incoming iTip message.
351 *
352 * @param result success of the operation.
353 * @param errorMessage translated error message suitable for user dialogs.
354 * Empty if the operation was successful
355 */
357
358 /**
359 * Signal emitted after an iTip message was sent through sendiTIPMessage()
360 */
362
363 /**
364 * Signal emitted after an incidence was published with publishInformation()
365 */
367
368 /**
369 * Signal emitted after an incidence was sent with sendAsICalendar()
370 */
372
373private:
374 Q_DISABLE_COPY(ITIPHandler)
375 std::unique_ptr<ITIPHandlerPrivate> const d;
376};
377}
Ui delegate for editing counter proposals.
Definition itiphandler.h:50
Factory to create Akonadi::MessageQueueJob jobs or ITIPHandlerDialogDelegate objects.
Ui delegate for dialogs raised by the ITIPHandler and IncidenceChanger.
Definition itiphandler.h:66
ITIPHandlerDialogDelegate(const KCalendarCore::Incidence::Ptr &incidence, KCalendarCore::iTIPMethod method, QWidget *parent=nullptr)
Creates a new AskDelegator.
virtual int warningTwoActionsCancel(const QString &text, const QString &title, const KGuiItem &primaryAction, const KGuiItem &secondaryAction, const KGuiItem &cancelAction=KStandardGuiItem::cancel())
Opens a warning message box with two accept actions and cancel action.
@ ActionAsk
Ask the user for a decision.
Definition itiphandler.h:71
@ ActionSendMessage
Answer with Yes.
Definition itiphandler.h:72
@ Organizer
the organizer of the incidence
Definition itiphandler.h:78
virtual int warningContinueCancel(const QString &text, const QString &title, const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel())
Opens a warning message box with a Continue and Cancel actions.
Handles sending of iTip messages as well as processing incoming ones.
~ITIPHandler() override
Destroys this instance.
@ ResultSuccess
The invitation was successfully handled.
@ ResultError
An unexpected error occurred.
void iTipMessageProcessed(Akonadi::ITIPHandler::Result result, const QString &errorMessage)
Sent after processing an incoming iTip message.
void iTipMessageSent(Akonadi::ITIPHandler::Result, const QString &errorMessage)
Signal emitted after an iTip message was sent through sendiTIPMessage()
void sentAsICalendar(Akonadi::ITIPHandler::Result, const QString &errorMessage)
Signal emitted after an incidence was sent with sendAsICalendar()
void informationPublished(Akonadi::ITIPHandler::Result, const QString &errorMessage)
Signal emitted after an incidence was published with publishInformation()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
FreeBusyManager::Singleton.
KGuiItem cont()
KGuiItem cancel()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.