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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
  • contact
contactgroupsearchjob.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 "contactgroupsearchjob.h"
23 
24 #include <akonadi/itemfetchscope.h>
25 
26 using namespace Akonadi;
27 
28 class ContactGroupSearchJob::Private
29 {
30  public:
31  int mLimit;
32 };
33 
34 ContactGroupSearchJob::ContactGroupSearchJob( QObject * parent )
35  : ItemSearchJob( QString(), parent ), d( new Private )
36 {
37  fetchScope().fetchFullPayload();
38  d->mLimit = -1;
39 
40  // by default search for all contact groups
41  ItemSearchJob::setQuery( QLatin1String( ""
42 #ifdef AKONADI_USE_STRIGI_SEARCH
43  "<request>"
44  " <query>"
45  " <equals>"
46  " <field name=\"type\"/>"
47  " <string>ContactGroup</string>"
48  " </equals>"
49  " </query>"
50  "</request>"
51 #else
52  "SELECT ?r WHERE { ?r a nco:ContactGroup }"
53 #endif
54  ) );
55 }
56 
57 ContactGroupSearchJob::~ContactGroupSearchJob()
58 {
59  delete d;
60 }
61 
62 void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value )
63 {
64  // Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something
65  // else as default
66  setQuery( criterion, value, ExactMatch );
67 }
68 
69 void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
70 {
71  QString query;
72 
73  if ( match == ExactMatch ) {
74  if ( criterion == Name ) {
75  query += QString::fromLatin1(
76 #ifdef AKONADI_USE_STRIGI_SEARCH
77  "<request>"
78  " <query>"
79  " <and>"
80  " <equals>"
81  " <field name=\"type\"/>"
82  " <string>ContactGroup</string>"
83  " </equals>"
84  " <equals>"
85  " <field name=\"contactGroupName\"/>"
86  " <string>%1</string>"
87  " </equals>"
88  " </and>"
89  " </query>"
90  "</request>"
91 #else
92  "SELECT DISTINCT ?group "
93  "WHERE { "
94  " graph ?g { "
95  " ?group <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
96  " ?group nco:contactGroupName \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>."
97  " } "
98  "}"
99 #endif
100  );
101  }
102  } else if ( match == ContainsMatch ) {
103  if ( criterion == Name ) {
104  query += QString::fromLatin1(
105 #ifdef AKONADI_USE_STRIGI_SEARCH
106  "<request>"
107  " <query>"
108  " <and>"
109  " <equals>"
110  " <field name=\"type\"/>"
111  " <string>ContactGroup</string>"
112  " </equals>"
113  " <contains>"
114  " <field name=\"contactGroupName\"/>"
115  " <string>%1</string>"
116  " </contains>"
117  " </and>"
118  " </query>"
119  "</request>"
120 #else
121  "SELECT DISTINCT ?group "
122  "WHERE { "
123  " graph ?g { "
124  " ?group <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
125  " ?group nco:contactGroupName ?v . "
126  " ?v bif:contains \"'%1'\""
127  " } "
128  "}"
129 #endif
130  );
131  }
132  } else if ( match == StartsWithMatch ) {
133  if ( criterion == Name ) {
134  query += QString::fromLatin1(
135 #ifdef AKONADI_USE_STRIGI_SEARCH
136  "<request>"
137  " <query>"
138  " <and>"
139  " <equals>"
140  " <field name=\"type\"/>"
141  " <string>ContactGroup</string>"
142  " </equals>"
143  " <startsWith>"
144  " <field name=\"contactGroupName\"/>"
145  " <string>%1</string>"
146  " </startsWith>"
147  " </and>"
148  " </query>"
149  "</request>"
150 #else
151  "SELECT DISTINCT ?group "
152  "WHERE { "
153  " graph ?g { "
154  " ?group <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
155  " ?group nco:contactGroupName ?v . "
156  " ?v bif:contains \"'%1*'\""
157  " } "
158  "}"
159 #endif
160  );
161  }
162  }
163 
164  if ( d->mLimit != -1 ) {
165 #ifndef AKONADI_USE_STRIGI_SEARCH
166  query += QString::fromLatin1( " LIMIT %1" ).arg( d->mLimit );
167 #endif
168  }
169 
170  query = query.arg( value );
171 
172  ItemSearchJob::setQuery( query );
173 }
174 
175 void ContactGroupSearchJob::setLimit( int limit )
176 {
177  d->mLimit = limit;
178 }
179 
180 KABC::ContactGroup::List ContactGroupSearchJob::contactGroups() const
181 {
182  KABC::ContactGroup::List contactGroups;
183 
184  foreach ( const Item &item, items() ) {
185  if ( item.hasPayload<KABC::ContactGroup>() ) {
186  contactGroups.append( item.payload<KABC::ContactGroup>() );
187  }
188  }
189 
190  return contactGroups;
191 }
192 
Akonadi::ContactGroupSearchJob::setLimit
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
Definition: contactgroupsearchjob.cpp:175
Akonadi::ContactGroupSearchJob::Criterion
Criterion
Describes the criteria that can be searched for.
Definition: contactgroupsearchjob.h:79
Akonadi::ItemSearchJob::items
Item::List items() const
Returns the items that matched the search query.
Definition: itemsearchjob.cpp:154
Akonadi::ContactGroupSearchJob::setQuery
void setQuery(Criterion criterion, const QString &value)
Sets the criterion and value for the search.
Definition: contactgroupsearchjob.cpp:62
Akonadi::ContactGroupSearchJob::StartsWithMatch
The result must start with the pattern (case insensitive).
Definition: contactgroupsearchjob.h:90
Akonadi::ContactGroupSearchJob::ContactGroupSearchJob
ContactGroupSearchJob(QObject *parent=0)
Creates a new contact group search job.
Definition: contactgroupsearchjob.cpp:34
Akonadi::ContactGroupSearchJob::Match
Match
Describes the type of pattern matching that shall be used.
Definition: contactgroupsearchjob.h:88
Akonadi::ItemFetchScope::fetchFullPayload
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Definition: itemfetchscope.cpp:68
Akonadi::ItemSearchJob::fetchScope
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition: itemsearchjob.cpp:109
Akonadi::ItemSearchJob::akonadiItemIdUri
static QUrl akonadiItemIdUri()
Returns an URI that represents a predicate that is always added to the Nepomuk resource by the Akonad...
Definition: itemsearchjob.cpp:161
Akonadi::ContactGroupSearchJob::ExactMatch
The result must match exactly the pattern (case sensitive).
Definition: contactgroupsearchjob.h:89
Akonadi::ContactGroupSearchJob::~ContactGroupSearchJob
~ContactGroupSearchJob()
Destroys the contact group search job.
Definition: contactgroupsearchjob.cpp:57
Akonadi::ContactGroupSearchJob::ContainsMatch
The result must contain the pattern (case insensitive).
Definition: contactgroupsearchjob.h:91
Akonadi::ItemSearchJob::setQuery
void setQuery(const QString &query)
Sets the search query in SPARQL format.
Definition: itemsearchjob.cpp:95
Akonadi::ContactGroupSearchJob::Name
The name of the contact group.
Definition: contactgroupsearchjob.h:80
Akonadi::ContactGroupSearchJob::contactGroups
KABC::ContactGroup::List contactGroups() const
Returns the contact groups that matched the search criteria.
Definition: contactgroupsearchjob.cpp:180
Akonadi::ItemSearchJob
Job that searches for items in the Akonadi storage.
Definition: itemsearchjob.h:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 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
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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