File indexing completed on 2024-11-24 04:39:26

0001 /*
0002     This file is part of Akonadi Contact.
0003 
0004     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "akonadi-contact-core_export.h"
0012 
0013 #include <Akonadi/Item>
0014 #include <Akonadi/ItemSearchJob>
0015 #include <KContacts/ContactGroup>
0016 
0017 #include <memory>
0018 
0019 namespace Akonadi
0020 {
0021 class ContactGroupSearchJobPrivate;
0022 
0023 /**
0024  * @short Job that searches for contact groups in the Akonadi storage.
0025  *
0026  * This job searches for contact groups that match given search criteria and returns
0027  * the list of contact groups.
0028  *
0029  * @code
0030  *
0031  * Akonadi::ContactGroupSearchJob *job = new Akonadi::ContactGroupSearchJob();
0032  * job->setQuery( Akonadi::ContactGroupSearchJob::Name, "Family Members" );
0033  * connect( job, SIGNAL(result(KJob*)), this, SLOT(searchResult(KJob*)) );
0034  *
0035  * ...
0036  *
0037  * MyClass::searchResult( KJob *job )
0038  * {
0039  *   Akonadi::ContactGroupSearchJob *searchJob = qobject_cast<Akonadi::ContactGroupSearchJob*>( job );
0040  *   const KContacts::ContactGroup::List contactGroups = searchJob->contactGroups();
0041  *   // do something with the contact groups
0042  * }
0043  *
0044  * @endcode
0045  *
0046  * @author Tobias Koenig <tokoe@kde.org>
0047  * @since 4.4
0048  */
0049 class AKONADI_CONTACT_CORE_EXPORT ContactGroupSearchJob : public ItemSearchJob
0050 {
0051     Q_OBJECT
0052 
0053 public:
0054     /**
0055      * Creates a new contact group search job.
0056      *
0057      * @param parent The parent object.
0058      */
0059     explicit ContactGroupSearchJob(QObject *parent = nullptr);
0060 
0061     /**
0062      * Destroys the contact group search job.
0063      */
0064     ~ContactGroupSearchJob() override;
0065 
0066     /**
0067      * Describes the criteria that can be searched for.
0068      */
0069     enum Criterion {
0070         Name ///< The name of the contact group.
0071     };
0072 
0073     /**
0074      * Describes the type of pattern matching that shall be used.
0075      *
0076      * @since 4.5
0077      */
0078     enum Match {
0079         ExactMatch, ///< The result must match exactly the pattern (case sensitive).
0080         StartsWithMatch, ///< The result must start with the pattern (case insensitive).
0081         ContainsMatch ///< The result must contain the pattern (case insensitive).
0082     };
0083 
0084     /**
0085      * Sets the @p criterion and @p value for the search.
0086      */
0087     void setQuery(Criterion criterion, const QString &value);
0088 
0089     /**
0090      * Sets the @p criterion and @p value for the search with @p match.
0091      * @param criterion the query criterion to compare with
0092      * @param value the value to match against
0093      * @param match how to match the given value
0094      * @since 4.5
0095      */
0096     void setQuery(Criterion criterion, const QString &value, Match match);
0097 
0098     /**
0099      * Sets a @p limit on how many results will be returned by this search job.
0100      * This is useful in situation where for example only the first search result is needed anyway,
0101      * setting a limit of 1 here will greatly reduce the resource usage during the
0102      * search.
0103      * @param limit the limit to set
0104      * @note this needs to be called before calling setQuery() to have an effect.
0105      * By default, the number of results is unlimited.
0106      *
0107      * @since 4.4.3
0108      */
0109     void setLimit(int limit);
0110 
0111     /**
0112      * Returns the contact groups that matched the search criteria.
0113      */
0114     [[nodiscard]] KContacts::ContactGroup::List contactGroups() const;
0115 
0116 private:
0117     //@cond PRIVATE
0118     std::unique_ptr<ContactGroupSearchJobPrivate> const d;
0119     //@endcond
0120 };
0121 }