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

0001 /*
0002     SPDX-FileCopyrightText: 2007 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 "collection.h"
0011 #include "job.h"
0012 
0013 namespace Akonadi
0014 {
0015 class Collection;
0016 class SearchQuery;
0017 class SearchCreateJobPrivate;
0018 
0019 /**
0020  * @short Job that creates a virtual/search collection in the Akonadi storage.
0021  *
0022  * This job creates so called virtual or search collections, which don't contain
0023  * real data, but references to items that match a given search query.
0024  *
0025  * @code
0026  *
0027  * const QString name = "My search folder";
0028  * const QString query = "...";
0029  *
0030  * Akonadi::SearchCreateJob *job = new Akonadi::SearchCreateJob( name, query );
0031  * connect( job, SIGNAL(result(KJob*)), SLOT(jobFinished(KJob*)) );
0032  *
0033  * MyClass::jobFinished( KJob *job )
0034  * {
0035  *   if ( job->error() ) {
0036  *     qDebug() << "Error occurred";
0037  *     return;
0038  *   }
0039  *
0040  *   qDebug() << "Created search folder successfully";
0041  *   const Collection searchCollection = job->createdCollection();
0042  *   ...
0043  * }
0044  *
0045  * @endcode
0046  *
0047  * @author Volker Krause <vkrause@kde.org>
0048  */
0049 class AKONADICORE_EXPORT SearchCreateJob : public Job
0050 {
0051     Q_OBJECT
0052 
0053 public:
0054     /**
0055      * Creates a search create job
0056      *
0057      * @param name The name of the search collection
0058      * @param searchQuery The search query
0059      * @param parent The parent object
0060      * @since 4.13
0061      */
0062     SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent = nullptr);
0063 
0064     /**
0065      * Sets list of mime types of items that search results can contain
0066      *
0067      * @param mimeTypes Mime types of items to include in search
0068      * @since 4.13
0069      */
0070     void setSearchMimeTypes(const QStringList &mimeTypes);
0071 
0072     /**
0073      * Returns list of mime types that search results can contain
0074      *
0075      * @since 4.13
0076      */
0077     [[nodiscard]] QStringList searchMimeTypes() const;
0078 
0079     /**
0080      * Sets list of collections to search in.
0081      *
0082      * When an empty list is set (default value), the search will contain
0083      * results from all collections that contain given mime types.
0084      *
0085      * @param collections Collections to search in, or an empty list to search all
0086      * @since 4.13
0087      */
0088     void setSearchCollections(const QList<Collection> &collections);
0089 
0090     /**
0091      * Returns list of collections to search in
0092      *
0093      * @since 4.13
0094      */
0095     [[nodiscard]] QList<Collection> searchCollections() const;
0096 
0097     /**
0098      * Sets whether resources should be queried too.
0099      *
0100      * When set to true, Akonadi will search local indexed items and will also
0101      * query resources that support server-side search, to forward the query
0102      * to remote storage (for example using SEARCH feature on IMAP servers) and
0103      * merge their results with results from local index.
0104      *
0105      * This is useful especially when searching resources, that don't fetch full
0106      * payload by default, for example the IMAP resource, which only fetches headers
0107      * by default and the body is fetched on demand, which means that emails that
0108      * were not yet fully fetched cannot be indexed in local index, and thus cannot
0109      * be searched. With remote search, even those emails can be included in search
0110      * results.
0111      *
0112      * This feature is disabled by default.
0113      *
0114      * @param enabled Whether remote search is enabled
0115      * @since 4.13
0116      */
0117     void setRemoteSearchEnabled(bool enabled);
0118 
0119     /**
0120      * Returns whether remote search is enabled.
0121      *
0122      * @since 4.13
0123      */
0124     [[nodiscard]] bool isRemoteSearchEnabled() const;
0125 
0126     /**
0127      * Sets whether the search should recurse into collections
0128      *
0129      * When set to true, all child collections of the specific collections will
0130      * be search recursively.
0131      *
0132      * @param recursive Whether to search recursively
0133      * @since 4.13
0134      */
0135     void setRecursive(bool recursive);
0136 
0137     /**
0138      * Returns whether the search is recursive
0139      *
0140      * @since 4.13
0141      */
0142     [[nodiscard]] bool isRecursive() const;
0143 
0144     /**
0145      * Destroys the search create job.
0146      */
0147     ~SearchCreateJob() override;
0148 
0149     /**
0150      * Returns the newly created search collection once the job finished successfully. Returns an invalid
0151      * collection if the job has not yet finished or failed.
0152      *
0153      * @since 4.4
0154      */
0155     [[nodiscard]] Collection createdCollection() const;
0156 
0157 protected:
0158     /**
0159      * Reimplemented from Akonadi::Job
0160      */
0161     void doStart() override;
0162 
0163     /**
0164      * Reimplemented from Akonadi::Job
0165      */
0166     bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override;
0167 
0168 private:
0169     Q_DECLARE_PRIVATE(SearchCreateJob)
0170 };
0171 
0172 }