1 /*
2  * SPDX-FileCopyrightText: 2017 Kevin Ottens <ervin@kde.org>
3  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
4  */
5 
6 
7 #ifndef AKONADI_CACHE_H
8 #define AKONADI_CACHE_H
9 
10 #include <AkonadiCore/Akonadi/Collection>
11 #include <AkonadiCore/Akonadi/Item>
12 
13 #include "akonadi/akonadimonitorinterface.h"
14 #include "akonadi/akonadiserializerinterface.h"
15 #include "akonadi/akonadistorageinterface.h"
16 
17 namespace Akonadi {
18 
19 class Cache : public QObject
20 {
21     Q_OBJECT
22 public:
23     typedef QSharedPointer<Cache> Ptr;
24 
25     explicit Cache(const SerializerInterface::Ptr &serializer,
26                    const MonitorInterface::Ptr &monitor,
27                    QObject *parent = nullptr);
28 
29     bool isCollectionListPopulated() const;
30     Akonadi::Collection::List collections() const;
31     Akonadi::Collection::List allCollections() const;
32     bool isCollectionKnown(Collection::Id id) const;
33     Collection collection(Collection::Id id) const;
34     bool isCollectionPopulated(Collection::Id id) const;
35     Item::List items(const Collection &collection) const;
36 
37     void setCollections(const Collection::List &collections);
38     void populateCollection(const Collection &collection, const Item::List &items);
39 
40     Item item(Item::Id id) const;
41 
42 private slots:
43     void onCollectionAdded(const Collection &collection);
44     void onCollectionChanged(const Collection &collection);
45     void onCollectionRemoved(const Collection &collection);
46 
47     void onItemAdded(const Item &item);
48     void onItemChanged(const Item &item);
49     void onItemRemoved(const Item &item);
50 
51 private:
52     SerializerInterface::Ptr m_serializer;
53     MonitorInterface::Ptr m_monitor;
54 
55     bool m_collectionListPopulated;
56     Collection::List m_collections;
57     QHash<Collection::Id, QVector<Item::Id>> m_collectionItems;
58 
59     QHash<Item::Id, Item> m_items;
60 };
61 
62 }
63 
64 #endif // AKONADI_CACHE_H
65