File indexing completed on 2024-05-12 05:10:47

0001 /*
0002   SPDX-FileCopyrightText: 2012 Sérgio Martins <iamsergio@gmail.com>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "calendarbase.h"
0010 #include "itiphandler.h"
0011 #include "itiphandlerhelper_p.h"
0012 #include "mailscheduler_p.h"
0013 
0014 #include <KCalendarCore/ScheduleMessage>
0015 
0016 #include <QObject>
0017 #include <QPointer>
0018 #include <QString>
0019 
0020 namespace Akonadi
0021 {
0022 struct Invitation {
0023     QString receiver;
0024     QString iCal;
0025     QString action;
0026     KCalendarCore::iTIPMethod method;
0027     KCalendarCore::Incidence::Ptr incidence;
0028 };
0029 
0030 /**
0031  * Our API has two methods, one to process received invitations and another one to send them.
0032  * These operations are async and we don't want them to be called before the other has finished.
0033  * This enum is just to Q_ASSERT that.
0034  */
0035 enum Operation { OperationNone, OperationProcessiTIPMessage, OperationSendiTIPMessage, OperationPublishInformation, OperationSendAsICalendar };
0036 
0037 class ITIPHandlerPrivate : public QObject
0038 {
0039     Q_OBJECT
0040 public:
0041     ITIPHandlerPrivate(ITIPHandlerComponentFactory *factory, ITIPHandler *q);
0042 
0043     void finishProcessiTIPMessage(Akonadi::MailScheduler::Result, const QString &errorMessage);
0044     void finishSendiTIPMessage(Akonadi::MailScheduler::Result, const QString &errorMessage);
0045     void finishPublishInformation(Akonadi::MailScheduler::Result, const QString &errorMessage);
0046 
0047     /**
0048      * Returns the calendar.
0049      * Creates a new one, if none is set.
0050      */
0051     CalendarBase::Ptr calendar();
0052     bool isLoaded(); // don't make const
0053 
0054     Invitation m_queuedInvitation;
0055     bool m_calendarLoadError = false;
0056     CalendarBase::Ptr m_calendar;
0057     ITIPHandlerComponentFactory *m_factory = nullptr;
0058     MailScheduler *m_scheduler = nullptr;
0059     KCalendarCore::Incidence::Ptr m_incidence;
0060     KCalendarCore::iTIPMethod m_method; // METHOD field of ical rfc of incoming invitation
0061     ITIPHandlerHelper *m_helper = nullptr;
0062     Operation m_currentOperation;
0063     QPointer<QWidget> m_parentWidget; // To be used for KMessageBoxes
0064     GroupwareUiDelegate *m_uiDelegate = nullptr;
0065     bool m_showDialogsOnError = true;
0066     ITIPHandler *const q;
0067 
0068     void finishSendAsICalendar(Akonadi::MailClient::Result, const QString &errorMessage);
0069 
0070 private:
0071     void onLoadFinished(bool success, const QString &errorMessage);
0072     void onSchedulerFinished(Akonadi::Scheduler::Result, const QString &errorMessage);
0073     void onHelperFinished(Akonadi::ITIPHandlerHelper::SendResult result, const QString &errorMessage);
0074 
0075     void onHelperModifyDialogClosed(ITIPHandlerHelper::SendResult result, KCalendarCore::iTIPMethod method, const KCalendarCore::Incidence::Ptr &incidence);
0076 
0077     void onCounterProposalDelegateFinished(bool success, const QString &errorMessage);
0078 };
0079 }