1 /*
2     SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "storage/datastore.h"
10 
11 namespace Akonadi
12 {
13 namespace Server
14 {
15 class FakeAkonadiServer;
16 
17 class FakeDataStoreFactory : public DataStoreFactory
18 {
19 public:
20     FakeDataStoreFactory(FakeAkonadiServer &akonadi);
21     DataStore *createStore() override;
22 
23 private:
24     FakeAkonadiServer &m_akonadi;
25 };
26 
27 class FakeDataStore : public DataStore
28 {
29     Q_OBJECT
30     friend class FakeDataStoreFactory;
31 
32 public:
33     ~FakeDataStore() override;
34 
35     bool init() override;
36 
changes()37     QMap<QString, QVariantList> changes() const
38     {
39         return mChanges;
40     }
41 
42     bool setItemsFlags(const PimItem::List &items,
43                        const QVector<Flag> *currentFlags,
44                        const QVector<Flag> &flags,
45                        bool *flagsChanged = nullptr,
46                        const Collection &col = Collection(),
47                        bool silent = false) override;
48     bool appendItemsFlags(const PimItem::List &items,
49                           const QVector<Flag> &flags,
50                           bool *flagsChanged = nullptr,
51                           bool checkIfExists = true,
52                           const Collection &col = Collection(),
53                           bool silent = false) override;
54     bool removeItemsFlags(const PimItem::List &items,
55                           const QVector<Flag> &flags,
56                           bool *flagsChanged = nullptr,
57                           const Collection &col = Collection(),
58                           bool silent = false) override;
59 
60     bool setItemsTags(const PimItem::List &items, const Tag::List &tags, bool *tagsChanged = nullptr, bool silent = false) override;
61     bool appendItemsTags(const PimItem::List &items,
62                          const Tag::List &tags,
63                          bool *tagsChanged = nullptr,
64                          bool checkIfExists = true,
65                          const Collection &col = Collection(),
66                          bool silent = false) override;
67     bool removeItemsTags(const PimItem::List &items, const Tag::List &tags, bool *tagsChanged = nullptr, bool silent = false) override;
68 
69     bool removeItemParts(const PimItem &item, const QSet<QByteArray> &parts) override;
70 
71     bool invalidateItemCache(const PimItem &item) override;
72 
73     bool appendCollection(Collection &collection, const QStringList &mimeTypes, const QMap<QByteArray, QByteArray> &attributes) override;
74 
75     bool cleanupCollection(Collection &collection) override;
76     bool cleanupCollection_slow(Collection &collection) override;
77 
78     bool moveCollection(Collection &collection, const Collection &newParent) override;
79 
80     bool appendMimeTypeForCollection(qint64 collectionId, const QStringList &mimeTypes) override;
81 
82     void activeCachePolicy(Collection &col) override;
83 
84     bool appendPimItem(QVector<Part> &parts,
85                        const QVector<Flag> &flags,
86                        const MimeType &mimetype,
87                        const Collection &collection,
88                        const QDateTime &dateTime,
89                        const QString &remote_id,
90                        const QString &remoteRevision,
91                        const QString &gid,
92                        PimItem &pimItem) override;
93 
94     bool cleanupPimItems(const PimItem::List &items, bool silent = false) override;
95 
96     bool unhidePimItem(PimItem &pimItem) override;
97     bool unhideAllPimItems() override;
98 
99     bool addCollectionAttribute(const Collection &col, const QByteArray &key, const QByteArray &value, bool silent = false) override;
100     bool removeCollectionAttribute(const Collection &col, const QByteArray &key) override;
101 
102     bool beginTransaction(const QString &name = QString()) override;
103     bool rollbackTransaction() override;
104     bool commitTransaction() override;
105 
106     void setPopulateDb(bool populate);
107 
108 protected:
109     FakeDataStore(FakeAkonadiServer &akonadi);
110 
111     QMap<QString, QVariantList> mChanges;
112 
113 private:
114     bool mPopulateDb;
115 };
116 
117 }
118 }
119 
120