File indexing completed on 2024-11-24 04:44:34

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0003     SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "storeinterface.h"
0011 
0012 #include <Akonadi/Collection>
0013 #include <Akonadi/Item>
0014 
0015 #include <QObject>
0016 
0017 #include <memory>
0018 
0019 namespace Akonadi
0020 {
0021 namespace FileStore
0022 {
0023 class AbstractLocalStorePrivate;
0024 
0025 /**
0026  */
0027 class AKONADI_FILESTORE_EXPORT AbstractLocalStore : public QObject, public StoreInterface
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     AbstractLocalStore();
0033     ~AbstractLocalStore() override;
0034 
0035     virtual void setPath(const QString &path);
0036     QString path() const;
0037 
0038     Collection topLevelCollection() const override;
0039 
0040     CollectionCreateJob *createCollection(const Collection &collection, const Collection &targetParent) override;
0041 
0042     CollectionFetchJob *fetchCollections(const Collection &collection, CollectionFetchJob::Type type = CollectionFetchJob::FirstLevel) const override;
0043 
0044     CollectionDeleteJob *deleteCollection(const Collection &collection) override;
0045 
0046     CollectionModifyJob *modifyCollection(const Collection &collection) override;
0047 
0048     CollectionMoveJob *moveCollection(const Collection &collection, const Collection &targetParent) override;
0049 
0050     ItemFetchJob *fetchItems(const Collection &collection) const override;
0051 
0052     ItemFetchJob *fetchItems(const Item::List &items) const override;
0053 
0054     ItemFetchJob *fetchItem(const Item &item) const override;
0055 
0056     ItemCreateJob *createItem(const Item &item, const Collection &collection) override;
0057 
0058     ItemModifyJob *modifyItem(const Item &item) override;
0059 
0060     ItemDeleteJob *deleteItem(const Item &item) override;
0061 
0062     ItemMoveJob *moveItem(const Item &item, const Collection &targetParent) override;
0063 
0064     StoreCompactJob *compactStore() override;
0065 
0066 protected: // job processing
0067     virtual void processJob(Job *job) = 0;
0068 
0069     Job *currentJob() const;
0070 
0071     void notifyError(int errorCode, const QString &errorText) const;
0072 
0073     void notifyCollectionsProcessed(const Collection::List &collections) const;
0074 
0075     void notifyItemsProcessed(const Item::List &items) const;
0076 
0077 protected: // template methods
0078     void setTopLevelCollection(const Collection &collection) override;
0079 
0080     virtual void checkCollectionCreate(CollectionCreateJob *job, int &errorCode, QString &errorText) const;
0081 
0082     virtual void checkCollectionDelete(CollectionDeleteJob *job, int &errorCode, QString &errorText) const;
0083 
0084     virtual void checkCollectionFetch(CollectionFetchJob *job, int &errorCode, QString &errorText) const;
0085 
0086     virtual void checkCollectionModify(CollectionModifyJob *job, int &errorCode, QString &errorText) const;
0087 
0088     virtual void checkCollectionMove(CollectionMoveJob *job, int &errorCode, QString &errorText) const;
0089 
0090     virtual void checkItemCreate(ItemCreateJob *job, int &errorCode, QString &errorText) const;
0091 
0092     virtual void checkItemDelete(ItemDeleteJob *job, int &errorCode, QString &errorText) const;
0093 
0094     virtual void checkItemFetch(ItemFetchJob *job, int &errorCode, QString &errorText) const;
0095 
0096     virtual void checkItemModify(ItemModifyJob *job, int &errorCode, QString &errorText) const;
0097 
0098     virtual void checkItemMove(ItemMoveJob *job, int &errorCode, QString &errorText) const;
0099 
0100     virtual void checkStoreCompact(StoreCompactJob *job, int &errorCode, QString &errorText) const;
0101 
0102 private:
0103     friend class AbstractLocalStorePrivate;
0104     std::unique_ptr<AbstractLocalStorePrivate> const d;
0105 };
0106 }
0107 }