File indexing completed on 2024-11-24 04:43:38

0001 /*
0002     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <Akonadi/ResourceBase>
0010 
0011 #include <KContacts/Addressee>
0012 #include <KContacts/ContactGroup>
0013 #include <KContacts/ContactGroupTool>
0014 #include <KContacts/VCardConverter>
0015 
0016 class QDir;
0017 
0018 class ContactsResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::ObserverV2
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit ContactsResource(const QString &id);
0024     ~ContactsResource() override;
0025 
0026 public Q_SLOTS:
0027     void aboutToQuit() override;
0028 
0029 protected:
0030     using ResourceBase::retrieveItems; // suppress -Woverload-virtual warnings
0031 
0032 protected Q_SLOTS:
0033     void retrieveCollections() override;
0034     void retrieveItems(const Akonadi::Collection &collection) override;
0035     bool retrieveItems(const Akonadi::Item::List &items, const QSet<QByteArray> &parts) override;
0036     bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
0037 
0038 protected:
0039     void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) override;
0040     void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
0041     void itemRemoved(const Akonadi::Item &item) override;
0042 
0043     void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent) override;
0044     void collectionChanged(const Akonadi::Collection &collection) override;
0045     // do not hide the other variant, use implementation from base class
0046     // which just forwards to the one above
0047     using Akonadi::AgentBase::ObserverV2::collectionChanged;
0048     void collectionRemoved(const Akonadi::Collection &collection) override;
0049 
0050     void itemMoved(const Akonadi::Item &item, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination) override;
0051     void collectionMoved(const Akonadi::Collection &collection,
0052                          const Akonadi::Collection &collectionSource,
0053                          const Akonadi::Collection &collectionDestination) override;
0054 
0055 private:
0056     void slotReloadConfig();
0057     [[nodiscard]] Akonadi::Collection::List createCollectionsForDirectory(const QDir &parentDirectory, const Akonadi::Collection &parentCollection) const;
0058     [[nodiscard]] QString baseDirectoryPath() const;
0059     void initializeDirectory(const QString &path) const;
0060     [[nodiscard]] Akonadi::Collection::Rights supportedRights(bool isResourceCollection) const;
0061     [[nodiscard]] QString directoryForCollection(const Akonadi::Collection &collection) const;
0062     [[nodiscard]] bool doRetrieveItem(Akonadi::Item &item);
0063 
0064 private:
0065     QStringList mSupportedMimeTypes;
0066 };