File indexing completed on 2025-01-05 04:59:39

0001 /*
0002  * SPDX-FileCopyrightText: 2017 Kevin Ottens <ervin@kde.org>
0003  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004  */
0005 
0006 
0007 #ifndef AKONADI_CACHE_H
0008 #define AKONADI_CACHE_H
0009 
0010 #include <Akonadi/Collection>
0011 #include <Akonadi/Item>
0012 
0013 #include "akonadi/akonadimonitorinterface.h"
0014 #include "akonadi/akonadiserializerinterface.h"
0015 #include "akonadi/akonadistorageinterface.h"
0016 
0017 namespace Akonadi {
0018 
0019 class Cache : public QObject
0020 {
0021     Q_OBJECT
0022 public:
0023     typedef QSharedPointer<Cache> Ptr;
0024 
0025     explicit Cache(const SerializerInterface::Ptr &serializer,
0026                    const MonitorInterface::Ptr &monitor,
0027                    QObject *parent = nullptr);
0028 
0029     bool isCollectionListPopulated() const;
0030     Akonadi::Collection::List collections() const;
0031     Akonadi::Collection::List allCollections() const;
0032     bool isCollectionKnown(Collection::Id id) const;
0033     Collection collection(Collection::Id id) const;
0034     bool isCollectionPopulated(Collection::Id id) const;
0035     Item::List items(const Collection &collection) const;
0036 
0037     void setCollections(const Collection::List &collections);
0038     void populateCollection(const Collection &collection, const Item::List &items);
0039 
0040     Item item(Item::Id id) const;
0041 
0042 private slots:
0043     void onCollectionAdded(const Collection &collection);
0044     void onCollectionChanged(const Collection &collection);
0045     void onCollectionRemoved(const Collection &collection);
0046 
0047     void onItemAdded(const Item &item);
0048     void onItemChanged(const Item &item);
0049     void onItemRemoved(const Item &item);
0050 
0051 private:
0052     SerializerInterface::Ptr m_serializer;
0053     MonitorInterface::Ptr m_monitor;
0054 
0055     bool m_collectionListPopulated;
0056     Collection::List m_collections;
0057     QHash<Collection::Id, QList<Item::Id>> m_collectionItems;
0058 
0059     QHash<Item::Id, Item> m_items;
0060 };
0061 
0062 }
0063 
0064 #endif // AKONADI_CACHE_H