File indexing completed on 2025-01-19 04:46:50
0001 /* 0002 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <MimeTreeParser/BodyPart> 0010 0011 #include <KCalendarCore/Event> 0012 #include <KItinerary/ExtractorPostprocessor> 0013 0014 #include <QList> 0015 #include <QSet> 0016 #include <QVariant> 0017 0018 #include <vector> 0019 0020 namespace KPkPass 0021 { 0022 class Pass; 0023 } 0024 0025 namespace KMime 0026 { 0027 class ContentIndex; 0028 } 0029 0030 class QDateTime; 0031 0032 /** Memento holding the itinerary information extracted for an email. */ 0033 class ItineraryMemento : public MimeTreeParser::Interface::BodyPartMemento 0034 { 0035 public: 0036 ItineraryMemento(); 0037 ~ItineraryMemento() override = default; 0038 void detach() override; 0039 0040 static const char *identifier(); 0041 0042 [[nodiscard]] bool isParsed(const KMime::ContentIndex &index) const; 0043 void setParsed(const KMime::ContentIndex &index); 0044 0045 void setMessageDate(const QDateTime &contextDt); 0046 void appendData(const QList<QVariant> &data); 0047 0048 [[nodiscard]] bool hasData() const; 0049 struct TripData { 0050 QList<QVariant> reservations; 0051 KCalendarCore::Event::Ptr event; 0052 bool expanded; 0053 }; 0054 [[nodiscard]] QList<TripData> data(); 0055 void toggleExpanded(int index); 0056 0057 void addPass(KPkPass::Pass *pass, const QByteArray &rawData); 0058 QByteArray rawPassData(const QString &passTypeIdentifier, const QString &serialNumber) const; 0059 0060 struct PassData { 0061 QString passTypeIdentifier; 0062 QString serialNumber; 0063 QByteArray rawData; 0064 }; 0065 const std::vector<PassData> &passData() const 0066 { 0067 return m_passes; 0068 } 0069 0070 struct DocumentData { 0071 QString docId; 0072 QVariant docInfo; 0073 QByteArray rawData; 0074 }; 0075 const std::vector<DocumentData> &documentData() const 0076 { 0077 return m_docs; 0078 } 0079 0080 void addDocument(const QString &docId, const QVariant &docInfo, const QByteArray &docData); 0081 0082 /** At least one reservation has enough information to add it to the calendar. */ 0083 bool canAddToCalendar() const; 0084 /** Start date of the reservation data. 0085 * TODO this eventually should include the end date too, for showing the full range in the calendar, 0086 * but KOrganizer doesn't support that yet 0087 */ 0088 QDate startDate() const; 0089 0090 private: 0091 QSet<KMime::ContentIndex> m_parsedParts; 0092 KItinerary::ExtractorPostprocessor m_postProc; 0093 QList<TripData> m_data; 0094 std::vector<PassData> m_passes; 0095 std::vector<DocumentData> m_docs; 0096 };