File indexing completed on 2024-11-10 04:40:07

0001 /*
0002     SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
0003     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "collection.h"
0011 #include "item.h"
0012 #include "resourcebase.h"
0013 
0014 #include "agentsearchinterface.h"
0015 #include "searchquery.h"
0016 #include "xmldocument.h"
0017 
0018 #include "settings.h"
0019 
0020 class QFileSystemWatcher;
0021 
0022 class KnutResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::ObserverV2, public Akonadi::AgentSearchInterface
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     using Akonadi::AgentBase::ObserverV2::collectionChanged; // So we don't trigger -Woverloaded-virtual
0028     explicit KnutResource(const QString &id);
0029     ~KnutResource() override;
0030 
0031 public Q_SLOTS:
0032     void configure(WId windowId) override;
0033 
0034 protected:
0035     void retrieveCollections() override;
0036     void retrieveItems(const Akonadi::Collection &collection) override;
0037 #ifdef DO_IT_THE_OLD_WAY
0038     bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
0039 #endif
0040     bool retrieveItems(const Akonadi::Item::List &items, const QSet<QByteArray> &parts) override;
0041 
0042     void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent) override;
0043     void collectionChanged(const Akonadi::Collection &collection) override;
0044     void collectionRemoved(const Akonadi::Collection &collection) override;
0045 
0046     void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) override;
0047     void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
0048     void itemRemoved(const Akonadi::Item &ref) override;
0049     void itemMoved(const Akonadi::Item &item, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination) override;
0050 
0051     void search(const QString &query, const Akonadi::Collection &collection) override;
0052     void addSearch(const QString &query, const QString &queryLanguage, const Akonadi::Collection &resultCollection) override;
0053     void removeSearch(const Akonadi::Collection &resultCollection) override;
0054 
0055 private:
0056     static QSet<qint64> parseQuery(const QString &queryString);
0057 
0058 private Q_SLOTS:
0059     void load();
0060     void save();
0061 
0062 private:
0063     Akonadi::XmlDocument mDocument;
0064     QFileSystemWatcher *mWatcher = nullptr;
0065     KnutSettings *mSettings = nullptr;
0066 };