Akonadi Contacts

contactsearchjob.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 "contactsearchjob.h"
10 #include <searchquery.h>
11 
12 #include <itemfetchscope.h>
13 
14 using namespace Akonadi;
15 
16 class Q_DECL_HIDDEN ContactSearchJob::Private
17 {
18 public:
19  int mLimit = -1;
20 };
21 
23  : ItemSearchJob(parent)
24  , d(new Private())
25 {
27  d->mLimit = -1;
28 
30 
31  // by default search for all contacts
33  query.addTerm(ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual));
35 }
36 
38 {
39  delete d;
40 }
41 
42 static Akonadi::SearchTerm::Condition matchType(ContactSearchJob::Match match)
43 {
44  switch (match) {
46  return Akonadi::SearchTerm::CondEqual;
50  return Akonadi::SearchTerm::CondContains;
51  }
52  return Akonadi::SearchTerm::CondEqual;
53 }
54 
55 void ContactSearchJob::setQuery(Criterion criterion, const QString &value, Match match)
56 {
57  Akonadi::SearchQuery query(SearchTerm::RelOr);
58 
59  if (criterion == Name) {
60  query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
61  } else if (criterion == Email) {
62  query.addTerm(ContactSearchTerm(ContactSearchTerm::Email, value, matchType(match)));
63  } else if (criterion == NickName) {
64  query.addTerm(ContactSearchTerm(ContactSearchTerm::Nickname, value, matchType(match)));
65  } else if (criterion == NameOrEmail) {
66  query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
67  query.addTerm(ContactSearchTerm(ContactSearchTerm::Email, value, matchType(match)));
68  } else if (criterion == ContactUid) {
69  query.addTerm(ContactSearchTerm(ContactSearchTerm::Uid, value, matchType(match)));
70  }
71 
72  query.setLimit(d->mLimit);
73 
75 }
76 
78 {
79  d->mLimit = limit;
80 }
81 
83 {
85 
86  const Akonadi::Item::List lstItems = items();
87  for (const Item &item : lstItems) {
88  if (item.hasPayload<KContacts::Addressee>()) {
89  contacts.append(item.payload<KContacts::Addressee>());
90  }
91  }
92 
93  return contacts;
94 }
static QString mimeType()
Match
Describes the type of pattern matching that shall be used.
The result must contain the pattern (case insensitive).
Item::List items() const
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
void fetchFullPayload(bool fetch=true)
The nickname of the contact.
void addTerm(const QString &key, const QVariant &value, SearchTerm::Condition condition=SearchTerm::CondEqual)
The name or email address of the contact.
The result must start with the pattern (case insensitive).
~ContactSearchJob()
Destroys the contact search job.
ItemFetchScope & fetchScope()
Job that searches for contacts in the Akonadi storage.
The email address of the contact.
KContacts::Addressee::List contacts() const
Returns the contacts that matched the search criteria.
AddresseeList List
void setQuery(const SearchQuery &query)
void setLimit(int limit)
void setQuery(Criterion criterion, const QString &value, Match match=ExactMatch)
Sets the criterion and value for the search with match.
The global unique identifier of the contact.
ContactSearchJob(QObject *parent=nullptr)
Creates a new contact search job.
void setMimeTypes(const QStringList &mimeTypes)
Criterion
Describes the criteria that can be searched for.
The name of the contact.
The result must contain a word starting with the pattern (case insensitive).
The result must match exactly the pattern (case sensitive).
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jun 22 2021 23:08:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.