File indexing completed on 2024-05-12 05:11:18

0001 /*
0002  * This file is part of the KDE Akonadi Search Project
0003  * SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  *
0007  */
0008 
0009 #pragma once
0010 
0011 #include <QObject>
0012 #include <QString>
0013 #include <QUrl>
0014 
0015 #include "search_core_export.h"
0016 
0017 namespace Akonadi
0018 {
0019 /** Akonadi search infrastructure. */
0020 namespace Search
0021 {
0022 class Query;
0023 
0024 /** Search store. */
0025 class AKONADI_SEARCH_CORE_EXPORT SearchStore : public QObject
0026 {
0027     Q_OBJECT
0028 public:
0029     explicit SearchStore(QObject *parent = nullptr);
0030     ~SearchStore() override;
0031 
0032     /**
0033      * Override search stores for testing
0034      */
0035     static void overrideSearchStores(const QList<SearchStore *> &overrideSearchStores);
0036 
0037     using List = QList<QSharedPointer<SearchStore>>;
0038 
0039     /**
0040      * Gives a list of available search stores. These stores must be managed and
0041      * deleted by the caller
0042      */
0043     static List searchStores();
0044 
0045     /**
0046      * Returns a list of types which can be searched for
0047      * in this store
0048      */
0049     virtual QStringList types() = 0;
0050 
0051     /**
0052      * Executes the particular query synchronously.
0053      *
0054      * \return Returns a integer representing the integer
0055      */
0056     virtual int exec(const Query &query) = 0;
0057     virtual bool next(int queryId) = 0;
0058     virtual void close(int queryId) = 0;
0059 
0060     virtual QByteArray id(int queryId) = 0;
0061 
0062     virtual QUrl url(int queryId);
0063     virtual QString text(int queryId);
0064     virtual QString icon(int queryId);
0065     virtual QString property(int queryId, const QString &propName);
0066 };
0067 
0068 //
0069 // Convenience functions
0070 //
0071 inline QByteArray serialize(const QByteArray &namespace_, int id)
0072 {
0073     return namespace_ + ':' + QByteArray::number(id);
0074 }
0075 
0076 inline int deserialize(const QByteArray &namespace_, const QByteArray &str)
0077 {
0078     // The +1 is for the ':'
0079     return str.mid(namespace_.size() + 1).toInt();
0080 }
0081 } // namespace Search
0082 } // namespace Akonadi
0083 
0084 Q_DECLARE_INTERFACE(Akonadi::Search::SearchStore, "org.kde.Akonadi.Search.SearchStore")