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
14using namespace Akonadi;
15
16class Akonadi::ContactSearchJobPrivate
17{
18public:
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
39static 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
52void 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"
void setQuery(Criterion criterion, const QString &value, Match match=ExactMatch)
Sets the criterion and value for the search with match.
Match
Describes the type of pattern matching that shall be used.
@ ExactMatch
The result must match exactly the pattern (case sensitive).
@ StartsWithMatch
The result must start with the pattern (case insensitive).
@ ContainsWordBoundaryMatch
The result must contain a word starting with the pattern (case insensitive).
@ ContainsMatch
The result must contain the pattern (case insensitive).
ContactSearchJob(QObject *parent=nullptr)
Creates a new contact search job.
Criterion
Describes the criteria that can be searched for.
@ Name
The name of the contact.
@ NameOrEmail
The name or email address of the contact.
@ Email
The email address of the contact.
@ NickName
The nickname of the contact.
@ ContactUid
The global unique identifier of the contact.
~ContactSearchJob() override
Destroys the contact search job.
KContacts::Addressee::List contacts() const
Returns the contacts that matched the search criteria.
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
void fetchFullPayload(bool fetch=true)
void setQuery(const SearchQuery &query)
ItemFetchScope & fetchScope()
void setMimeTypes(const QStringList &mimeTypes)
Item::List items() const
static QString mimeType()
AddresseeList List
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 Mon Nov 18 2024 12:08:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.