1 /*
2     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
3     SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 #include "akonaditests_export.h"
11 #include "private/protocol_p.h"
12 
13 class QSettings;
14 class QFile;
15 
16 namespace Akonadi
17 {
18 class AKONADI_TESTS_EXPORT ChangeRecorderJournalReader
19 {
20 public:
21     enum LegacyType {
22         InvalidType,
23         Item,
24         Collection,
25         Tag,
26         Relation,
27     };
28 
29     // Ancient QSettings legacy store
30     static Protocol::ChangeNotificationPtr loadQSettingsNotification(QSettings *settings);
31 
32     static QQueue<Protocol::ChangeNotificationPtr> loadFrom(QFile *device, bool &needsFullSave);
33 
34 private:
35     enum LegacyOp {
36         InvalidOp,
37         Add,
38         Modify,
39         Move,
40         Remove,
41         Link,
42         Unlink,
43         Subscribe,
44         Unsubscribe,
45         ModifyFlags,
46         ModifyTags,
47         ModifyRelations,
48     };
49 
50     static Protocol::ChangeNotificationPtr loadQSettingsItemNotification(QSettings *settings);
51     static Protocol::ChangeNotificationPtr loadQSettingsCollectionNotification(QSettings *settings);
52 
53     // More modern mechanisms
54     static Protocol::ChangeNotificationPtr loadItemNotification(QDataStream &stream, quint64 version);
55     static Protocol::ChangeNotificationPtr loadCollectionNotification(QDataStream &stream, quint64 version);
56     static Protocol::ChangeNotificationPtr loadTagNotification(QDataStream &stream, quint64 version);
57     static Protocol::ChangeNotificationPtr loadRelationNotification(QDataStream &stream, quint64 version);
58 
59     static Protocol::ItemChangeNotification::Operation mapItemOperation(LegacyOp op);
60     static Protocol::CollectionChangeNotification::Operation mapCollectionOperation(LegacyOp op);
61     static Protocol::TagChangeNotification::Operation mapTagOperation(LegacyOp op);
62     static Protocol::RelationChangeNotification::Operation mapRelationOperation(LegacyOp op);
63 
64     static QSet<Protocol::ItemChangeNotification::Relation> extractRelations(QSet<QByteArray> &flags);
65 };
66 
67 class AKONADI_TESTS_EXPORT ChangeRecorderJournalWriter
68 {
69 public:
70     static void saveTo(const QQueue<Protocol::ChangeNotificationPtr> &changes, QIODevice *device);
71 
72 private:
73     static ChangeRecorderJournalReader::LegacyType mapToLegacyType(Protocol::Command::Type type);
74 
75     static void saveItemNotification(QDataStream &stream, const Protocol::ItemChangeNotification &ntf);
76     static void saveCollectionNotification(QDataStream &stream, const Protocol::CollectionChangeNotification &ntf);
77     static void saveTagNotification(QDataStream &stream, const Protocol::TagChangeNotification &ntf);
78     static void saveRelationNotification(QDataStream &stream, const Protocol::RelationChangeNotification &ntf);
79 
80     static QSet<QByteArray> encodeRelations(const QSet<Protocol::ItemChangeNotification::Relation> &relations);
81 };
82 
83 } // namespace
84 
85