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

akonadi/contact

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
27 using namespace Akonadi;
28 
29 class ContactSearchJob::Private
30 {
31  public:
32  int mLimit;
33 };
34 
35 ContactSearchJob::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 
49 ContactSearchJob::~ContactSearchJob()
50 {
51  delete d;
52 }
53 
54 void ContactSearchJob::setQuery( Criterion criterion, const QString &value )
55 {
56  setQuery( criterion, value, ExactMatch );
57 }
58 
59 static 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 
72 void 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 
94 void ContactSearchJob::setLimit( int limit )
95 {
96  d->mLimit = limit;
97 }
98 
99 KABC::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::Match
Match
Describes the type of pattern matching that shall be used.
Definition: contactsearchjob.h:112
Akonadi::ContactSearchJob::ContainsMatch
The result must contain the pattern (case insensitive).
Definition: contactsearchjob.h:115
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::ContactSearchJob::NickName
The nickname of the contact.
Definition: contactsearchjob.h:102
Akonadi::ContactSearchJob::NameOrEmail
The name or email address of the contact.
Definition: contactsearchjob.h:103
QObject
Akonadi::ContactSearchJob::ContactSearchJob
ContactSearchJob(QObject *parent=0)
Creates a new contact search job.
Definition: contactsearchjob.cpp:35
Akonadi::ContactSearchJob::StartsWithMatch
The result must start with the pattern (case insensitive).
Definition: contactsearchjob.h:114
Akonadi::ContactSearchJob::~ContactSearchJob
~ContactSearchJob()
Destroys the contact search job.
Definition: contactsearchjob.cpp:49
Akonadi::ContactSearchJob::contacts
KABC::Addressee::List contacts() const
Returns the contacts that matched the search criteria.
Definition: contactsearchjob.cpp:99
QString
QStringList
Akonadi::ContactSearchJob::Email
The email address of the contact.
Definition: contactsearchjob.h:101
Akonadi::ContactSearchJob::setQuery
void setQuery(Criterion criterion, const QString &value)
Sets the criterion and value for the search.
Definition: contactsearchjob.cpp:54
Akonadi::ContactSearchJob::ContactUid
The global unique identifier of the contact.
Definition: contactsearchjob.h:104
Akonadi::ContactSearchJob::Criterion
Criterion
Describes the criteria that can be searched for.
Definition: contactsearchjob.h:99
Akonadi::ContactSearchJob::Name
The name of the contact.
Definition: contactsearchjob.h:100
Akonadi::ContactSearchJob::ContainsWordBoundaryMatch
The result must contain a word starting with the pattern (case insensitive).
Definition: contactsearchjob.h:116
QVariant
Akonadi::ContactSearchJob::ExactMatch
The result must match exactly the pattern (case sensitive).
Definition: contactsearchjob.h:113
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

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

kdepimlibs API Reference

Skip menu "kdepimlibs 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

Search



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