fakedatastore.h 4.82 KB
Newer Older
1
/*
2
3
4
    SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>

    SPDX-License-Identifier: LGPL-2.0-or-later
5
6
7
8
9
10
11
12
13
14
*/

#ifndef AKONADI_SERVER_FAKEDATASTORE_H
#define AKONADI_SERVER_FAKEDATASTORE_H

#include "storage/datastore.h"

namespace Akonadi {
namespace Server {

15
16
17
18
19
20
21
22
23
24
25
class FakeAkonadiServer;

class FakeDataStoreFactory : public DataStoreFactory
{
public:
    FakeDataStoreFactory(FakeAkonadiServer &akonadi);
    DataStore *createStore() override;
private:
    FakeAkonadiServer &m_akonadi;
};

26
class FakeDataStore : public DataStore
27
28
{
    Q_OBJECT
29
    friend class FakeDataStoreFactory;
30
public:
Laurent Montel's avatar
Laurent Montel committed
31
    ~FakeDataStore() override;
32

33
    bool init() override;
34

35
36
37
38
39
    QMap<QString, QVariantList> changes() const
    {
        return mChanges;
    }

Laurent Montel's avatar
Laurent Montel committed
40
    bool setItemsFlags(const PimItem::List &items,
41
                               const QVector<Flag> *currentFlags,
42
                               const QVector<Flag> &flags,
Laurent Montel's avatar
Laurent Montel committed
43
                               bool *flagsChanged = nullptr,
Daniel Vrátil's avatar
Daniel Vrátil committed
44
                               const Collection &col = Collection(),
45
                               bool silent = false) override;
Laurent Montel's avatar
Laurent Montel committed
46
    bool appendItemsFlags(const PimItem::List &items,
47
                                  const QVector<Flag> &flags,
Laurent Montel's avatar
Laurent Montel committed
48
                                  bool *flagsChanged = nullptr,
49
                                  bool checkIfExists = true,
50
                                  const Collection &col = Collection(),
51
                                  bool silent = false) override;
Laurent Montel's avatar
Laurent Montel committed
52
    bool removeItemsFlags(const PimItem::List &items,
53
                                  const QVector<Flag> &flags,
Laurent Montel's avatar
Laurent Montel committed
54
                                  bool *flagsChanged = nullptr,
Daniel Vrátil's avatar
Daniel Vrátil committed
55
                                  const Collection &col = Collection(),
56
                                  bool silent = false) override;
57

Laurent Montel's avatar
Laurent Montel committed
58
    bool setItemsTags(const PimItem::List &items,
59
                              const Tag::List &tags,
Laurent Montel's avatar
Laurent Montel committed
60
                              bool *tagsChanged = nullptr,
61
                              bool silent = false) override;
Laurent Montel's avatar
Laurent Montel committed
62
    bool appendItemsTags(const PimItem::List &items,
63
                                 const Tag::List &tags,
Laurent Montel's avatar
Laurent Montel committed
64
                                 bool *tagsChanged = nullptr,
65
66
                                 bool checkIfExists = true,
                                 const Collection &col = Collection(),
67
                                 bool silent = false) override;
Laurent Montel's avatar
Laurent Montel committed
68
    bool removeItemsTags(const PimItem::List &items,
69
                                 const Tag::List &tags,
Laurent Montel's avatar
Laurent Montel committed
70
                                 bool *tagsChanged = nullptr,
71
                                 bool silent = false) override;
72

Laurent Montel's avatar
Laurent Montel committed
73
    bool removeItemParts(const PimItem &item,
74
                                 const QSet<QByteArray> &parts)  override;
75

Laurent Montel's avatar
Laurent Montel committed
76
    bool invalidateItemCache(const PimItem &item) override;
77

Laurent Montel's avatar
Laurent Montel committed
78
    bool appendCollection(Collection &collection,
79
80
                                  const QStringList &mimeTypes,
                                  const QMap<QByteArray, QByteArray> &attributes) override;
81

Laurent Montel's avatar
Laurent Montel committed
82
83
    bool cleanupCollection(Collection &collection) override;
    bool cleanupCollection_slow(Collection &collection) override;
84

Laurent Montel's avatar
Laurent Montel committed
85
    bool moveCollection(Collection &collection,
86
                                const Collection &newParent) override;
87

88
    virtual bool appendMimeTypeForCollection(qint64 collectionId,
89
                                             const QStringList &mimeTypes) override;
90

Laurent Montel's avatar
Laurent Montel committed
91
    void activeCachePolicy(Collection &col) override;
92

Laurent Montel's avatar
Laurent Montel committed
93
    bool appendPimItem(QVector<Part> &parts,
94
                               const QVector<Flag> &flags,
95
96
97
98
99
100
                               const MimeType &mimetype,
                               const Collection &collection,
                               const QDateTime &dateTime,
                               const QString &remote_id,
                               const QString &remoteRevision,
                               const QString &gid,
101
                               PimItem &pimItem) override;
102

103
    bool cleanupPimItems(const PimItem::List &items, bool silent = false) override;
104

Laurent Montel's avatar
Laurent Montel committed
105
106
    bool unhidePimItem(PimItem &pimItem) override;
    bool unhideAllPimItems() override;
107

Laurent Montel's avatar
Laurent Montel committed
108
    bool addCollectionAttribute(const Collection &col,
109
                                        const QByteArray &key,
110
111
                                        const QByteArray &value,
                                        bool silent = false) override;
Laurent Montel's avatar
Laurent Montel committed
112
    bool removeCollectionAttribute(const Collection &col,
113
                                           const QByteArray &key) override;
114

Laurent Montel's avatar
Laurent Montel committed
115
116
117
    bool beginTransaction(const QString &name = QString()) override;
    bool rollbackTransaction() override;
    bool commitTransaction() override;
118

119
120
    void setPopulateDb(bool populate);

121
protected:
122
    FakeDataStore(FakeAkonadiServer &akonadi);
123
124
125

    QMap<QString, QVariantList> mChanges;

126
private:
127
    bool mPopulateDb;
128
129
130
131
132
133
134

};

}
}

#endif // AKONADI_SERVER_FAKEDATASTORE_H