File indexing completed on 2024-05-12 05:11:16
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 * 0006 */ 0007 0008 #pragma once 0009 0010 #include "abstractindexer.h" 0011 #include "collectionindexer.h" 0012 #include <Akonadi/Collection> 0013 #include <Akonadi/Item> 0014 #include <QObject> 0015 #include <QTimer> 0016 namespace Akonadi 0017 { 0018 namespace Search 0019 { 0020 namespace PIM 0021 { 0022 class IndexedItems; 0023 } 0024 } 0025 } 0026 /** 0027 * Maintains the various indexers and databases 0028 */ 0029 class Index : public QObject 0030 { 0031 Q_OBJECT 0032 public: 0033 explicit Index(QObject *parent = nullptr); 0034 ~Index() override; 0035 0036 virtual void removeDatabase(); 0037 virtual bool createIndexers(); 0038 0039 virtual void index(const Akonadi::Item &item); 0040 virtual void move(const Akonadi::Item::List &items, const Akonadi::Collection &from, const Akonadi::Collection &to); 0041 virtual void updateFlags(const Akonadi::Item::List &items, const QSet<QByteArray> &addedFlags, const QSet<QByteArray> &removed); 0042 virtual void remove(const QSet<Akonadi::Item::Id> &ids, const QStringList &mimeTypes); 0043 virtual void remove(const Akonadi::Item::List &items); 0044 0045 virtual void index(const Akonadi::Collection &collection); 0046 virtual void change(const Akonadi::Collection &collection); 0047 virtual void remove(const Akonadi::Collection &col); 0048 virtual void move(const Akonadi::Collection &collection, const Akonadi::Collection &from, const Akonadi::Collection &to); 0049 0050 virtual bool haveIndexerForMimeTypes(const QStringList &); 0051 virtual qlonglong indexedItems(const qlonglong id); 0052 virtual void findIndexed(QSet<Akonadi::Item::Id> &indexed, Akonadi::Collection::Id); 0053 virtual void scheduleCommit(); 0054 0055 /// For testing 0056 void setOverrideDbPrefixPath(const QString &path); 0057 0058 void setRespectDiacriticAndAccents(bool b); 0059 public Q_SLOTS: 0060 virtual void commit(); 0061 0062 private: 0063 void addIndexer(std::shared_ptr<AbstractIndexer> indexer); 0064 std::shared_ptr<AbstractIndexer> indexerForItem(const Akonadi::Item &item) const; 0065 QList<std::shared_ptr<AbstractIndexer>> indexersForMimetypes(const QStringList &mimeTypes) const; 0066 0067 QList<std::shared_ptr<AbstractIndexer>> m_listIndexer; 0068 QHash<QString, std::shared_ptr<AbstractIndexer>> m_indexer; 0069 Akonadi::Search::PIM::IndexedItems *m_indexedItems = nullptr; 0070 QTimer m_commitTimer; 0071 std::unique_ptr<CollectionIndexer> m_collectionIndexer = nullptr; 0072 bool mRespectDiacriticAndAccents = true; 0073 };