File indexing completed on 2024-12-22 04:57:39

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2007 Till Adam <adam@kde.org>
0003     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
0004     SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <Akonadi/ResourceBase>
0012 
0013 #include <QStringList>
0014 
0015 class CompactChangeHelper;
0016 class MixedMaildirStore;
0017 
0018 class MixedMaildirResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::ObserverV2
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit MixedMaildirResource(const QString &id);
0024     ~MixedMaildirResource() override;
0025 
0026 protected Q_SLOTS:
0027     void retrieveCollections() override;
0028     void retrieveItems(const Akonadi::Collection &col) override;
0029     bool retrieveItems(const Akonadi::Item::List &items, const QSet<QByteArray> &parts) override;
0030 
0031 protected:
0032     void aboutToQuit() override;
0033 
0034     void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) override;
0035     void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
0036     void itemMoved(const Akonadi::Item &item, const Akonadi::Collection &source, const Akonadi::Collection &dest) override;
0037     void itemRemoved(const Akonadi::Item &item) override;
0038 
0039     void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent) override;
0040     void collectionChanged(const Akonadi::Collection &collection) override;
0041     void collectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &changedAttributes) override;
0042     void collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &dest) override;
0043     void collectionRemoved(const Akonadi::Collection &collection) override;
0044 
0045 private:
0046     bool ensureDirExists();
0047     bool ensureSaneConfiguration();
0048 
0049     void checkForInvalidatedIndexCollections(KJob *job);
0050 
0051 private Q_SLOTS:
0052     void reapplyConfiguration();
0053 
0054     void retrieveCollectionsResult(KJob *job);
0055     void retrieveItemsResult(KJob *job);
0056     void retrieveItemResult(KJob *job);
0057 
0058     void itemAddedResult(KJob *job);
0059     void itemChangedResult(KJob *job);
0060     void itemMovedResult(KJob *job);
0061     void itemRemovedResult(KJob *job);
0062 
0063     void itemsDeleted(KJob *job);
0064 
0065     void collectionAddedResult(KJob *job);
0066     void collectionChangedResult(KJob *job);
0067     void collectionMovedResult(KJob *job);
0068     void collectionRemovedResult(KJob *job);
0069 
0070     void compactStore(const QVariant &arg);
0071     void compactStoreResult(KJob *job);
0072 
0073     void restoreTags(const QVariant &arg);
0074     void processNextTagContext();
0075     void tagFetchJobResult(KJob *job);
0076 
0077 private:
0078     MixedMaildirStore *mStore = nullptr;
0079 
0080     struct TagContext {
0081         Akonadi::Item mItem;
0082         QStringList mTagList;
0083     };
0084 
0085     using TagContextList = QList<TagContext>;
0086     QHash<Akonadi::Collection::Id, TagContextList> mTagContextByColId;
0087     TagContextList mPendingTagContexts;
0088 
0089     QSet<Akonadi::Collection::Id> mSynchronizedCollections;
0090     QSet<Akonadi::Collection::Id> mPendingSynchronizeCollections;
0091 
0092     CompactChangeHelper *mCompactHelper = nullptr;
0093 };