File indexing completed on 2024-06-16 04:50:12
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "akonaditests_export.h" 0011 #include "private/protocol_p.h" 0012 0013 class QSettings; 0014 class QFile; 0015 0016 namespace Akonadi 0017 { 0018 class AKONADI_TESTS_EXPORT ChangeRecorderJournalReader 0019 { 0020 public: 0021 enum LegacyType { 0022 InvalidType, 0023 Item, 0024 Collection, 0025 Tag, 0026 Relation, 0027 }; 0028 0029 // Ancient QSettings legacy store 0030 static Protocol::ChangeNotificationPtr loadQSettingsNotification(QSettings *settings); 0031 0032 static QQueue<Protocol::ChangeNotificationPtr> loadFrom(QFile *device, bool &needsFullSave); 0033 0034 private: 0035 enum LegacyOp { 0036 InvalidOp, 0037 Add, 0038 Modify, 0039 Move, 0040 Remove, 0041 Link, 0042 Unlink, 0043 Subscribe, 0044 Unsubscribe, 0045 ModifyFlags, 0046 ModifyTags, 0047 ModifyRelations, 0048 }; 0049 0050 static Protocol::ChangeNotificationPtr loadQSettingsItemNotification(QSettings *settings); 0051 static Protocol::ChangeNotificationPtr loadQSettingsCollectionNotification(QSettings *settings); 0052 0053 // More modern mechanisms 0054 static Protocol::ChangeNotificationPtr loadItemNotification(QDataStream &stream, quint64 version); 0055 static Protocol::ChangeNotificationPtr loadCollectionNotification(QDataStream &stream, quint64 version); 0056 static Protocol::ChangeNotificationPtr loadTagNotification(QDataStream &stream, quint64 version); 0057 static Protocol::ChangeNotificationPtr loadRelationNotification(QDataStream &stream, quint64 version); 0058 0059 static Protocol::ItemChangeNotification::Operation mapItemOperation(LegacyOp op); 0060 static Protocol::CollectionChangeNotification::Operation mapCollectionOperation(LegacyOp op); 0061 static Protocol::TagChangeNotification::Operation mapTagOperation(LegacyOp op); 0062 static Protocol::RelationChangeNotification::Operation mapRelationOperation(LegacyOp op); 0063 0064 static QSet<Protocol::ItemChangeNotification::Relation> extractRelations(QSet<QByteArray> &flags); 0065 }; 0066 0067 class AKONADI_TESTS_EXPORT ChangeRecorderJournalWriter 0068 { 0069 public: 0070 static void saveTo(const QQueue<Protocol::ChangeNotificationPtr> &changes, QIODevice *device); 0071 0072 private: 0073 static ChangeRecorderJournalReader::LegacyType mapToLegacyType(Protocol::Command::Type type); 0074 0075 static void saveItemNotification(QDataStream &stream, const Protocol::ItemChangeNotification &ntf); 0076 static void saveCollectionNotification(QDataStream &stream, const Protocol::CollectionChangeNotification &ntf); 0077 static void saveTagNotification(QDataStream &stream, const Protocol::TagChangeNotification &ntf); 0078 static void saveRelationNotification(QDataStream &stream, const Protocol::RelationChangeNotification &ntf); 0079 0080 static QSet<QByteArray> encodeRelations(const QSet<Protocol::ItemChangeNotification::Relation> &relations); 0081 }; 0082 0083 } // namespace