Akonadi Contacts

contactsearchjob.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "contactsearchjob.h"
10 #include <Akonadi/SearchQuery>
11 
12 #include <Akonadi/ItemFetchScope>
13 
14 using namespace Akonadi;
15 
16 class Akonadi::ContactSearchJobPrivate
17 {
18 public:
19  int mLimit = -1;
20 };
21 
23  : ItemSearchJob(parent)
24  , d(new ContactSearchJobPrivate())
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 static Akonadi::SearchTerm::Condition matchType(ContactSearchJob::Match match)
40 {
41  switch (match) {
43  return Akonadi::SearchTerm::CondEqual;
47  return Akonadi::SearchTerm::CondContains;
48  }
49  return Akonadi::SearchTerm::CondEqual;
50 }
51 
52 void ContactSearchJob::setQuery(Criterion criterion, const QString &value, Match match)
53 {
54  Akonadi::SearchQuery query(SearchTerm::RelOr);
55 
56  if (criterion == Name) {
57  query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
58  } else if (criterion == Email) {
59  query.addTerm(ContactSearchTerm(ContactSearchTerm::Email, value, matchType(match)));
60  } else if (criterion == NickName) {
61  query.addTerm(ContactSearchTerm(ContactSearchTerm::Nickname, value, matchType(match)));
62  } else if (criterion == NameOrEmail) {
63  query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
64  query.addTerm(ContactSearchTerm(ContactSearchTerm::Email, value, matchType(match)));
65  } else if (criterion == ContactUid) {
66  query.addTerm(ContactSearchTerm(ContactSearchTerm::Uid, value, matchType(match)));
67  }
68 
69  query.setLimit(d->mLimit);
70 
72 }
73 
75 {
76  d->mLimit = limit;
77 }
78 
80 {
82 
83  const Akonadi::Item::List lstItems = items();
84  for (const Item &item : lstItems) {
85  if (item.hasPayload<KContacts::Addressee>()) {
86  contacts.append(item.payload<KContacts::Addressee>());
87  }
88  }
89 
90  return contacts;
91 }
92 
93 #include "moc_contactsearchjob.cpp"
@ ContactUid
The global unique identifier of the contact.
Item::List items() const
@ ContainsMatch
The result must contain the pattern (case insensitive).
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
~ContactSearchJob() override
Destroys the contact search job.
void fetchFullPayload(bool fetch=true)
void setQuery(Criterion criterion, const QString &value, Match match=ExactMatch)
Sets the criterion and value for the search with match.
@ ContainsWordBoundaryMatch
The result must contain a word starting with the pattern (case insensitive).
@ StartsWithMatch
The result must start with the pattern (case insensitive).
@ Email
The email address of the contact.
void setQuery(const SearchQuery &query)
KContacts::Addressee::List contacts() const
Returns the contacts that matched the search criteria.
ContactSearchJob(QObject *parent=nullptr)
Creates a new contact search job.
Match
Describes the type of pattern matching that shall be used.
@ NameOrEmail
The name or email address of the contact.
ItemFetchScope & fetchScope()
@ Name
The name of the contact.
AddresseeList List
@ NickName
The nickname of the contact.
void setMimeTypes(const QStringList &mimeTypes)
Criterion
Describes the criteria that can be searched for.
static QString mimeType()
@ ExactMatch
The result must match exactly the pattern (case sensitive).
A widget for editing the display name of a contact.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 04:00:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.