Akonadi Contacts

contactgroupsearchjob.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "contactgroupsearchjob.h"
10 
11 #include <Akonadi/ItemFetchScope>
12 #include <Akonadi/SearchQuery>
13 #include <QStringList>
14 
15 using namespace Akonadi;
16 
17 class Akonadi::ContactGroupSearchJobPrivate
18 {
19 public:
20  int mLimit = -1;
21 };
22 
24  : ItemSearchJob(parent)
25  , d(new ContactGroupSearchJobPrivate)
26 {
28  d->mLimit = -1;
29 
31 
32  // by default search for all contact groups
34  query.addTerm(ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual));
36 }
37 
39 
40 void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value)
41 {
42  // Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something
43  // else as default
44  setQuery(criterion, value, ExactMatch);
45 }
46 
47 static Akonadi::SearchTerm::Condition matchType(ContactGroupSearchJob::Match match)
48 {
49  switch (match) {
51  return Akonadi::SearchTerm::CondEqual;
54  return Akonadi::SearchTerm::CondContains;
55  }
56  return Akonadi::SearchTerm::CondEqual;
57 }
58 
59 void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value, Match match)
60 {
62  if (criterion == Name) {
63  query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
64  }
65 
66  query.setLimit(d->mLimit);
67 
69 }
70 
72 {
73  d->mLimit = limit;
74 }
75 
77 {
79  const Akonadi::Item::List lstItems = items();
80  for (const Item &item : lstItems) {
81  if (item.hasPayload<KContacts::ContactGroup>()) {
83  }
84  }
85 
86  return contactGroups;
87 }
Item::List items() const
void append(const T &value)
Match
Describes the type of pattern matching that shall be used.
void fetchFullPayload(bool fetch=true)
@ StartsWithMatch
The result must start with the pattern (case insensitive).
@ ExactMatch
The result must match exactly the pattern (case sensitive).
ContactGroupSearchJob(QObject *parent=nullptr)
Creates a new contact group search job.
@ ContainsMatch
The result must contain the pattern (case insensitive).
static QString mimeType()
void setQuery(const SearchQuery &query)
~ContactGroupSearchJob() override
Destroys the contact group search job.
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
void setQuery(Criterion criterion, const QString &value)
Sets the criterion and value for the search.
ItemFetchScope & fetchScope()
KContacts::ContactGroup::List contactGroups() const
Returns the contact groups that matched the search criteria.
@ Name
The name of the contact group.
void setMimeTypes(const QStringList &mimeTypes)
Criterion
Describes the criteria that can be searched for.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.