diff --git a/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.h b/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.h --- a/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.h +++ b/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include namespace MessageViewer @@ -36,7 +36,7 @@ MemoryCalendarMemento(); bool finished() const; - KCalCore::MemoryCalendar::Ptr calendar() const; + Akonadi::CalendarBase::Ptr calendar() const; void detach() Q_DECL_OVERRIDE; @@ -50,7 +50,7 @@ private: bool mFinished; - KCalCore::MemoryCalendar::Ptr mCalendar; + Akonadi::CalendarBase::Ptr mCalendar; }; } diff --git a/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.cpp b/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.cpp --- a/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.cpp +++ b/plugins/messageviewer/bodypartformatter/calendar/memorycalendarmemento.cpp @@ -64,7 +64,7 @@ return mFinished; } -KCalCore::MemoryCalendar::Ptr MemoryCalendarMemento::calendar() const +Akonadi::CalendarBase::Ptr MemoryCalendarMemento::calendar() const { Q_ASSERT(mFinished); return mCalendar; diff --git a/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.h b/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.h --- a/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.h +++ b/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.h @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -43,7 +44,8 @@ Q_OBJECT public: SyncItipHandler(const QString &receiver, const QString &iCal, - const QString &type, QObject *parent = nullptr); + const QString &type, const Akonadi::CalendarBase::Ptr &calendar, + QObject *parent = nullptr); public Q_SLOTS: void onITipMessageProcessed(Akonadi::ITIPHandler::Result, const QString &errorMessage); diff --git a/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.cpp b/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.cpp --- a/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.cpp +++ b/plugins/messageviewer/bodypartformatter/calendar/syncitiphandler.cpp @@ -36,22 +36,17 @@ using namespace Akonadi; SyncItipHandler::SyncItipHandler(const QString &receiver, const QString &iCal, - const QString &type, QObject *parent) : QObject(parent) + const QString &type, const Akonadi::CalendarBase::Ptr &calendar, + QObject *parent) : QObject(parent) , m_result(Akonadi::ITIPHandler::ResultSuccess) { + Q_ASSERT(calendar); Akonadi::ITIPHandler *handler = new Akonadi::ITIPHandler(this); QObject::connect(handler, &Akonadi::ITIPHandler::iTipMessageProcessed, this, &SyncItipHandler::onITipMessageProcessed); m_counterProposalEditorDelegate = new IncidenceEditorNG::GroupwareUiDelegate(); handler->setGroupwareUiDelegate(m_counterProposalEditorDelegate); - - Akonadi::ETMCalendar::Ptr etmCalendar = CalendarSupport::calendarSingleton(/*createIfNull=*/false); - if (etmCalendar && etmCalendar->isLoaded()) { - qCDebug(TEXT_CALENDAR_LOG) << "Reusing exising ETM"; - handler->setCalendar(etmCalendar); - } else { - qCDebug(TEXT_CALENDAR_LOG) << "Not reusing any ETM"; - } + handler->setCalendar(calendar); handler->processiTIPMessage(receiver, iCal, type); diff --git a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp --- a/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp +++ b/plugins/messageviewer/bodypartformatter/calendar/text_calendar.cpp @@ -714,10 +714,12 @@ return mailICal(receiver, recv, msg, subject, status, type != Forward, viewerInstance); } - bool saveFile(const QString &receiver, const QString &iCal, const QString &type) const + bool saveFile(const QString &receiver, const QString &iCal, const QString &type, MimeTreeParser::Interface::BodyPart *bodyPart) const { + MemoryCalendarMemento *memento = dynamic_cast(bodyPart->memento()); // This will block. There's no way to make it async without refactoring the memento mechanism - SyncItipHandler *itipHandler = new SyncItipHandler(receiver, iCal, type); + + SyncItipHandler *itipHandler = new SyncItipHandler(receiver, iCal, type, memento->calendar()); // If result is ResultCancelled, then we don't show the message box and return false so kmail // doesn't delete the e-mail. @@ -908,7 +910,7 @@ } if (status != Attendee::Delegated) { // we do that below for delegated incidences - if (!saveFile(receiver, iCal, dir)) { + if (!saveFile(receiver, iCal, dir, part)) { return false; } } @@ -1009,7 +1011,7 @@ ICalFormat format; format.setTimeSpec(KSystemTimeZones::local()); const QString iCal = format.createScheduleMessage(incidence, iTIPRequest); - if (!saveFile(receiver, iCal, dir)) { + if (!saveFile(receiver, iCal, dir, part)) { return false; } @@ -1106,6 +1108,8 @@ // FIXME: this function should be inside a QObject, and async, // and Q_EMIT a signal when korg registered itself successfuly + // Or better, use DBus activation in all cases. + QString error; bool result = true; QString dbusService; @@ -1242,7 +1246,7 @@ // Don't delete the invitation here in any case, if the counter proposal // is declined you might need it again. - return saveFile(receiver, iCal, QStringLiteral("counter")); + return saveFile(receiver, iCal, QStringLiteral("counter"), part); } bool handleClick(Viewer *viewerInstance, @@ -1324,7 +1328,7 @@ } else if (path == QLatin1String("reply") || path == QLatin1String("cancel") || path == QLatin1String("accept_counter")) { // These should just be saved with their type as the dir const QString p = (path == QLatin1String("accept_counter") ? QStringLiteral("reply") : path); - if (saveFile(QStringLiteral("Receiver Not Searched"), iCal, p)) { + if (saveFile(QStringLiteral("Receiver Not Searched"), iCal, p, part)) { if (MessageViewer::MessageViewerSettings::self()->deleteInvitationEmailsAfterSendingReply()) { viewerInstance->deleteMessage(); } @@ -1364,7 +1368,7 @@ } //fall through case KMessageBox::Yes: // means "do not send" - if (saveFile(QStringLiteral("Receiver Not Searched"), iCal, QStringLiteral("reply"))) { + if (saveFile(QStringLiteral("Receiver Not Searched"), iCal, QStringLiteral("reply"), part)) { if (MessageViewer::MessageViewerSettings::self()->deleteInvitationEmailsAfterSendingReply()) { viewerInstance->deleteMessage(); result = true;