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 <searchquery.h>
12 #include <itemfetchscope.h>
13 #include <QStringList>
14 
15 using namespace Akonadi;
16 
17 class Q_DECL_HIDDEN ContactGroupSearchJob::Private
18 {
19 public:
20  int mLimit = -1;
21 };
22 
24  : ItemSearchJob(parent)
25  , d(new Private)
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  delete d;
41 }
42 
43 void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value)
44 {
45  // Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something
46  // else as default
47  setQuery(criterion, value, ExactMatch);
48 }
49 
50 static Akonadi::SearchTerm::Condition matchType(ContactGroupSearchJob::Match match)
51 {
52  switch (match) {
54  return Akonadi::SearchTerm::CondEqual;
57  return Akonadi::SearchTerm::CondContains;
58  }
59  return Akonadi::SearchTerm::CondEqual;
60 }
61 
62 void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value, Match match)
63 {
65  if (criterion == Name) {
66  query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
67  }
68 
69  query.setLimit(d->mLimit);
70 
72 }
73 
75 {
76  d->mLimit = limit;
77 }
78 
80 {
82  const Akonadi::Item::List lstItems = items();
83  for (const Item &item : lstItems) {
84  if (item.hasPayload<KContacts::ContactGroup>()) {
85  contactGroups.append(item.payload<KContacts::ContactGroup>());
86  }
87  }
88 
89  return contactGroups;
90 }
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
Criterion
Describes the criteria that can be searched for.
void append(const T &value)
Item::List items() const
void setQuery(Criterion criterion, const QString &value)
Sets the criterion and value for the search.
The result must start with the pattern (case insensitive).
Match
Describes the type of pattern matching that shall be used.
void fetchFullPayload(bool fetch=true)
void addTerm(const QString &key, const QVariant &value, SearchTerm::Condition condition=SearchTerm::CondEqual)
static QString mimeType()
ContactGroupSearchJob(QObject *parent=nullptr)
Creates a new contact group search job.
Job that searches for contact groups in the Akonadi storage.
ItemFetchScope & fetchScope()
KContacts::ContactGroup::List contactGroups() const
Returns the contact groups that matched the search criteria.
The result must match exactly the pattern (case sensitive).
~ContactGroupSearchJob()
Destroys the contact group search job.
The result must contain the pattern (case insensitive).
void setQuery(const SearchQuery &query)
void setLimit(int limit)
The name of the contact group.
void setMimeTypes(const QStringList &mimeTypes)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 23:07:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.