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

akonadi

  • 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  "prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>"
53  "SELECT ?r WHERE { ?r a nco:ContactGroup }"
54 #endif
55  ) );
56 }
57 
58 ContactGroupSearchJob::~ContactGroupSearchJob()
59 {
60  delete d;
61 }
62 
63 void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value )
64 {
65  // Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something
66  // else as default
67  setQuery( criterion, value, ExactMatch );
68 }
69 
70 void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
71 {
72  QString query;
73 
74 #ifndef AKONADI_USE_STRIGI_SEARCH
75  query = QString::fromLatin1( "prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>" );
76 #endif
77 
78  if ( match == ExactMatch ) {
79  if ( criterion == Name ) {
80  query += QString::fromLatin1(
81 #ifdef AKONADI_USE_STRIGI_SEARCH
82  "<request>"
83  " <query>"
84  " <and>"
85  " <equals>"
86  " <field name=\"type\"/>"
87  " <string>ContactGroup</string>"
88  " </equals>"
89  " <equals>"
90  " <field name=\"contactGroupName\"/>"
91  " <string>%1</string>"
92  " </equals>"
93  " </and>"
94  " </query>"
95  "</request>"
96 #else
97  "SELECT DISTINCT ?group "
98  "WHERE { "
99  " graph ?g { "
100  " ?group <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
101  " ?group nco:contactGroupName \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>."
102  " } "
103  "}"
104 #endif
105  );
106  }
107  } else if ( match == ContainsMatch ) {
108  if ( criterion == Name ) {
109  query += QString::fromLatin1(
110 #ifdef AKONADI_USE_STRIGI_SEARCH
111  "<request>"
112  " <query>"
113  " <and>"
114  " <equals>"
115  " <field name=\"type\"/>"
116  " <string>ContactGroup</string>"
117  " </equals>"
118  " <contains>"
119  " <field name=\"contactGroupName\"/>"
120  " <string>%1</string>"
121  " </contains>"
122  " </and>"
123  " </query>"
124  "</request>"
125 #else
126  "SELECT DISTINCT ?group "
127  "WHERE { "
128  " graph ?g { "
129  " ?group <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
130  " ?group nco:contactGroupName ?v . "
131  " ?v bif:contains \"'%1'\""
132  " } "
133  "}"
134 #endif
135  );
136  }
137  } else if ( match == StartsWithMatch ) {
138  if ( criterion == Name ) {
139  query += QString::fromLatin1(
140 #ifdef AKONADI_USE_STRIGI_SEARCH
141  "<request>"
142  " <query>"
143  " <and>"
144  " <equals>"
145  " <field name=\"type\"/>"
146  " <string>ContactGroup</string>"
147  " </equals>"
148  " <startsWith>"
149  " <field name=\"contactGroupName\"/>"
150  " <string>%1</string>"
151  " </startsWith>"
152  " </and>"
153  " </query>"
154  "</request>"
155 #else
156  "SELECT DISTINCT ?group "
157  "WHERE { "
158  " graph ?g { "
159  " ?group <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
160  " ?group nco:contactGroupName ?v . "
161  " ?v bif:contains \"'%1*'\""
162  " } "
163  "}"
164 #endif
165  );
166  }
167  }
168 
169  if ( d->mLimit != -1 ) {
170 #ifndef AKONADI_USE_STRIGI_SEARCH
171  query += QString::fromLatin1( " LIMIT %1" ).arg( d->mLimit );
172 #endif
173  }
174 
175  query = query.arg( value );
176 
177  ItemSearchJob::setQuery( query );
178 }
179 
180 void ContactGroupSearchJob::setLimit( int limit )
181 {
182  d->mLimit = limit;
183 }
184 
185 KABC::ContactGroup::List ContactGroupSearchJob::contactGroups() const
186 {
187  KABC::ContactGroup::List contactGroups;
188 
189  foreach ( const Item &item, items() ) {
190  if ( item.hasPayload<KABC::ContactGroup>() )
191  contactGroups.append( item.payload<KABC::ContactGroup>() );
192  }
193 
194  return contactGroups;
195 }
196 
197 #include "contactgroupsearchjob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:06:25 by doxygen 1.8.1.1 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-4.9.1 API Reference

Skip menu "kdepimlibs-4.9.1 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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