• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • contact
contactsearchjob.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "contactsearchjob.h"
23#include <searchquery.h>
24
25#include <akonadi/itemfetchscope.h>
26
27using namespace Akonadi;
28
29class ContactSearchJob::Private
30{
31 public:
32 int mLimit;
33};
34
35ContactSearchJob::ContactSearchJob( QObject * parent )
36 : ItemSearchJob( QString(), parent ), d( new Private() )
37{
38 fetchScope().fetchFullPayload();
39 d->mLimit = -1;
40
41 setMimeTypes( QStringList() << KABC::Addressee::mimeType() );
42
43 // by default search for all contacts
44 Akonadi::SearchQuery query;
45 query.addTerm( ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual) );
46 ItemSearchJob::setQuery( query );
47}
48
49ContactSearchJob::~ContactSearchJob()
50{
51 delete d;
52}
53
54void ContactSearchJob::setQuery( Criterion criterion, const QString &value )
55{
56 setQuery( criterion, value, ExactMatch );
57}
58
59static Akonadi::SearchTerm::Condition matchType( ContactSearchJob::Match match )
60{
61 switch ( match ) {
62 case ContactSearchJob::ExactMatch:
63 return Akonadi::SearchTerm::CondEqual;
64 case ContactSearchJob::StartsWithMatch:
65 case ContactSearchJob::ContainsWordBoundaryMatch:
66 case ContactSearchJob::ContainsMatch:
67 return Akonadi::SearchTerm::CondContains;
68 }
69 return Akonadi::SearchTerm::CondEqual;
70}
71
72void ContactSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
73{
74 Akonadi::SearchQuery query( SearchTerm::RelOr) ;
75
76 if ( criterion == Name ) {
77 query.addTerm( ContactSearchTerm( ContactSearchTerm::Name, value, matchType( match ) ) );
78 } else if ( criterion == Email ) {
79 query.addTerm( ContactSearchTerm( ContactSearchTerm::Email, value, matchType( match ) ) );
80 } else if ( criterion == NickName ) {
81 query.addTerm( ContactSearchTerm( ContactSearchTerm::Nickname, value, matchType( match ) ) );
82 } else if ( criterion == NameOrEmail ) {
83 query.addTerm( ContactSearchTerm( ContactSearchTerm::Name, value, matchType( match ) ) );
84 query.addTerm( ContactSearchTerm(ContactSearchTerm::Email, value, matchType( match ) ) );
85 } else if ( criterion == ContactUid ) {
86 query.addTerm( ContactSearchTerm( ContactSearchTerm::Uid, value, matchType( match ) ) );
87 }
88
89 query.setLimit( d->mLimit );
90
91 ItemSearchJob::setQuery( query );
92}
93
94void ContactSearchJob::setLimit( int limit )
95{
96 d->mLimit = limit;
97}
98
99KABC::Addressee::List ContactSearchJob::contacts() const
100{
101 KABC::Addressee::List contacts;
102
103 foreach ( const Item &item, items() ) {
104 if ( item.hasPayload<KABC::Addressee>() ) {
105 contacts.append( item.payload<KABC::Addressee>() );
106 }
107 }
108
109 return contacts;
110}
111
Akonadi::ContactSearchJob::~ContactSearchJob
~ContactSearchJob()
Destroys the contact search job.
Definition contactsearchjob.cpp:49
Akonadi::ContactSearchJob::Match
Match
Describes the type of pattern matching that shall be used.
Definition contactsearchjob.h:112
Akonadi::ContactSearchJob::ExactMatch
@ ExactMatch
The result must match exactly the pattern (case sensitive).
Definition contactsearchjob.h:113
Akonadi::ContactSearchJob::StartsWithMatch
@ StartsWithMatch
The result must start with the pattern (case insensitive).
Definition contactsearchjob.h:114
Akonadi::ContactSearchJob::ContainsWordBoundaryMatch
@ ContainsWordBoundaryMatch
The result must contain a word starting with the pattern (case insensitive).
Definition contactsearchjob.h:116
Akonadi::ContactSearchJob::ContainsMatch
@ ContainsMatch
The result must contain the pattern (case insensitive).
Definition contactsearchjob.h:115
Akonadi::ContactSearchJob::setQuery
void setQuery(Criterion criterion, const QString &value)
Sets the criterion and value for the search.
Definition contactsearchjob.cpp:54
Akonadi::ContactSearchJob::Criterion
Criterion
Describes the criteria that can be searched for.
Definition contactsearchjob.h:99
Akonadi::ContactSearchJob::Name
@ Name
The name of the contact.
Definition contactsearchjob.h:100
Akonadi::ContactSearchJob::NameOrEmail
@ NameOrEmail
The name or email address of the contact.
Definition contactsearchjob.h:103
Akonadi::ContactSearchJob::NickName
@ NickName
The nickname of the contact.
Definition contactsearchjob.h:102
Akonadi::ContactSearchJob::ContactUid
@ ContactUid
The global unique identifier of the contact.
Definition contactsearchjob.h:104
Akonadi::ContactSearchJob::contacts
KABC::Addressee::List contacts() const
Returns the contacts that matched the search criteria.
Definition contactsearchjob.cpp:99
Akonadi::ContactSearchJob::ContactSearchJob
ContactSearchJob(QObject *parent=0)
Creates a new contact search job.
Definition contactsearchjob.cpp:35
Akonadi::ContactSearchJob::setLimit
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
Definition contactsearchjob.cpp:94
Akonadi::ContactSearchTerm
A search term for a contact field.
Definition searchquery.h:250
Akonadi::ItemFetchScope::fetchFullPayload
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Definition itemfetchscope.cpp:70
Akonadi::ItemSearchJob
Job that searches for items in the Akonadi storage.
Definition itemsearchjob.h:68
Akonadi::ItemSearchJob::setQuery
void AKONADI_DEPRECATED setQuery(const QString &query)
Sets the search query in Akonadi search metalanguage format (JSON)
Definition itemsearchjob.cpp:138
Akonadi::ItemSearchJob::fetchScope
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition itemsearchjob.cpp:159
Akonadi::ItemSearchJob::setMimeTypes
void setMimeTypes(const QStringList &mimeTypes)
Search only for items of given mime types.
Definition itemsearchjob.cpp:178
Akonadi::ItemSearchJob::items
Item::List items() const
Returns the items that matched the search query.
Definition itemsearchjob.cpp:271
Akonadi::SearchQuery
A query that can be passed to ItemSearchJob or others.
Definition searchquery.h:129
Akonadi::SearchQuery::addTerm
void addTerm(const QString &key, const QVariant &value, SearchTerm::Condition condition=SearchTerm::CondEqual)
Adds a new term.
Definition searchquery.cpp:255
Akonadi::SearchQuery::setLimit
void setLimit(int limit)
Sets the maximum number of results.
Definition searchquery.cpp:270
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal