File indexing completed on 2024-11-10 04:40:28
0001 /* 0002 SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 #include "attribute.h" 0011 0012 #include <memory> 0013 0014 namespace Akonadi 0015 { 0016 class Collection; 0017 class PersistentSearchAttributePrivate; 0018 0019 /** 0020 * @short An attribute to store query properties of persistent search collections. 0021 * 0022 * This attribute is attached to persistent search collections automatically when 0023 * creating a new persistent search with SearchCreateJob. 0024 * Later on the search query can be changed by modifying this attribute of the 0025 * persistent search collection with an CollectionModifyJob. 0026 * 0027 * Example: 0028 * 0029 * @code 0030 * 0031 * const QString name = "My search folder"; 0032 * const QString query = "..."; 0033 * 0034 * Akonadi::SearchCreateJob *job = new Akonadi::SearchCreateJob( name, query ); 0035 * connect( job, SIGNAL(result(KJob*)), SLOT(jobFinished(KJob*)) ); 0036 * 0037 * MyClass::jobFinished( KJob *job ) 0038 * { 0039 * if ( job->error() ) { 0040 * qDebug() << "Error occurred"; 0041 * return; 0042 * } 0043 * 0044 * const Collection searchCollection = job->createdCollection(); 0045 * ... 0046 * 0047 * // now let's change the query 0048 * if ( searchCollection.hasAttribute<Akonadi::PersistentSearchAttribute>() ) { 0049 * Akonadi::PersistentSearchAttribute *attribute = searchCollection.attribute<Akonadi::PersistentSearchAttribute>(); 0050 * attribute->setQueryString( "... another query string ..." ); 0051 * 0052 * Akonadi::CollectionModifyJob *modifyJob = new Akonadi::CollectionModifyJob( searchCollection ); 0053 * connect( modifyJob, SIGNAL(result(KJob*)), SLOT(modifyFinished(KJob*)) ); 0054 * } 0055 * ... 0056 * } 0057 * 0058 * @endcode 0059 * 0060 * @author Volker Krause <vkrause@kde.org> 0061 * @since 4.5 0062 */ 0063 class AKONADICORE_EXPORT PersistentSearchAttribute : public Akonadi::Attribute 0064 { 0065 public: 0066 /** 0067 * Creates a new persistent search attribute. 0068 */ 0069 explicit PersistentSearchAttribute(); 0070 0071 /** 0072 * Destroys the persistent search attribute. 0073 */ 0074 ~PersistentSearchAttribute() override; 0075 0076 /** 0077 * Returns the query string used for this search. 0078 */ 0079 [[nodiscard]] QString queryString() const; 0080 0081 /** 0082 * Sets the query string to be used for this search. 0083 * @param query The query string. 0084 */ 0085 void setQueryString(const QString &query); 0086 0087 /** 0088 * Returns IDs of collections that will be queried 0089 * @since 4.13 0090 */ 0091 [[nodiscard]] QList<qint64> queryCollections() const; 0092 0093 /** 0094 * Sets collections to be queried. 0095 * @param collections List of collections to be queries 0096 * @since 4.13 0097 */ 0098 void setQueryCollections(const QList<Collection> &collections); 0099 0100 /** 0101 * Sets IDs of collections to be queries 0102 * @param collectionsIds IDs of collections to query 0103 * @since 4.13 0104 */ 0105 void setQueryCollections(const QList<qint64> &collectionsIds); 0106 0107 /** 0108 * Sets whether resources should be queried too. 0109 * 0110 * When set to true, Akonadi will search local indexed items and will also 0111 * query resources that support server-side search, to forward the query 0112 * to remote storage (for example using SEARCH feature on IMAP servers) and 0113 * merge their results with results from local index. 0114 * 0115 * This is useful especially when searching resources, that don't fetch full 0116 * payload by default, for example the IMAP resource, which only fetches headers 0117 * by default and the body is fetched on demand, which means that emails that 0118 * were not yet fully fetched cannot be indexed in local index, and thus cannot 0119 * be searched. With remote search, even those emails can be included in search 0120 * results. 0121 * 0122 * @param enabled Whether remote search is enabled 0123 * @since 4.13 0124 */ 0125 void setRemoteSearchEnabled(bool enabled); 0126 0127 /** 0128 * Returns whether remote search is enabled. 0129 * 0130 * @since 4.13 0131 */ 0132 bool isRemoteSearchEnabled() const; 0133 0134 /** 0135 * Sets whether the search should recurse into collections 0136 * 0137 * When set to true, all child collections of the specific collections will 0138 * be search recursively. 0139 * 0140 * @param recursive Whether to search recursively 0141 * @since 4.13 0142 */ 0143 void setRecursive(bool recursive); 0144 0145 /** 0146 * Returns whether the search is recursive 0147 * 0148 * @since 4.13 0149 */ 0150 [[nodiscard]] bool isRecursive() const; 0151 0152 /// @cond PRIVATE 0153 QByteArray type() const override; 0154 Attribute *clone() const override; 0155 QByteArray serialized() const override; 0156 void deserialize(const QByteArray &data) override; 0157 /// @endcond 0158 0159 private: 0160 /// @cond PRIVATE 0161 const std::unique_ptr<PersistentSearchAttributePrivate> d; 0162 /// @endcond 0163 }; 0164 0165 } // namespace Akonadi