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

calendarsupport

  • sources
  • kde-4.12
  • kdepim
  • calendarsupport
  • next
incidencesearchjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
3 
4  Copyright (c) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5  Author: Sérgio Martins <sergio.martins@kdab.com>
6 
7  This library is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Library General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to the
19  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301, USA.
21 */
22 
23 #include "incidencesearchjob.h"
24 
25 #include <Akonadi/ItemFetchScope>
26 
27 using namespace CalendarSupport;
28 using namespace Akonadi;
29 
30 class IncidenceSearchJob::Private
31 {
32  public:
33  int mLimit;
34 };
35 
36 IncidenceSearchJob::IncidenceSearchJob( QObject *parent )
37  : ItemSearchJob( QString(), parent ), d( new Private() )
38 {
39  fetchScope().fetchFullPayload();
40  d->mLimit = -1;
41 
42  // by default search for all incidences
43  ItemSearchJob::setQuery( QLatin1String( ""
44 #ifdef AKONADI_USE_STRIGI_SEARCH
45  "<request>"
46  " <query>"
47  " <equals>"
48  " <field name=\"type\"/>"
49  " <string>UnionOfEventJournalTodo</string>"
50  " </equals>"
51  " </query>"
52  "</request>"
53 #else
54  "prefix ncal:<http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#>"
55  "prefix nao:<http://www.semanticdesktop.org/ontologies/2007/08/15/nao#>"
56  "SELECT DISTINCT ?r WHERE"
57  "{"
58  "?subclasses rdfs:subClassOf ncal:UnionOfEventJournalTodo ."
59  "?r a ?subclasses ."
60  "?r nao:hasSymbol \"view-pim-calendar\"^^<http://www.w3.org/2001/XMLSchema#string> ."
61  "?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
62  "}"
63 #endif
64  ) );
65 }
66 
67 IncidenceSearchJob::~IncidenceSearchJob()
68 {
69  delete d;
70 }
71 
72 void IncidenceSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
73 {
74  if ( match == StartsWithMatch && value.size() < 4 ) {
75  match = ExactMatch;
76  }
77 
78  QString query;
79 #ifndef AKONADI_USE_STRIGI_SEARCH
80  query = QString::fromLatin1( "prefix ncal:<http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#> " );
81 #endif
82 
83  if ( match == ExactMatch ) {
84  if ( criterion == IncidenceUid ) {
85  query += QString::fromLatin1(
86 #ifdef AKONADI_USE_STRIGI_SEARCH
87  "<request>"
88  " <query>"
89  " <and>"
90  " <equals>"
91  " <field name=\"type\"/>"
92  " <string>UnionOfEventJournalTodo</string>"
93  " </equals>"
94  " <equals>"
95  " <field name=\"uid\"/>"
96  " <string>%1</string>"
97  " </equals>"
98  " </and>"
99  " </query>"
100  "</request>"
101 #else
102  "SELECT ?r WHERE {"
103  "?subclasses rdfs:subClassOf ncal:UnionOfEventJournalTodo ."
104  "?r a ?subclasses ."
105  "?r nao:hasSymbol \"view-pim-calendar\"^^<http://www.w3.org/2001/XMLSchema#string> ."
106  "?r ncal:uid \"%1\"^^<http://www.w3.org/2001/XMLSchema#string> ."
107  "?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
108  "}"
109 #endif
110  );
111  }
112  } else if ( match == StartsWithMatch ) {
113  if ( criterion == IncidenceUid ) {
114  query += QString::fromLatin1(
115 #ifdef AKONADI_USE_STRIGI_SEARCH
116  "<request>"
117  " <query>"
118  " <and>"
119  " <equals>"
120  " <field name=\"type\"/>"
121  " <string>UnionOfEventJournalTodo</string>"
122  " </equals>"
123  " <startsWith>"
124  " <field name=\"uid\"/>"
125  " <string>%1</string>"
126  " </startsWith>"
127  " </and>"
128  " </query>"
129  "</request>"
130 #else
131  "SELECT ?r WHERE"
132  "{"
133  "?subclasses rdfs:subClassOf ncal:UnionOfEventJournalTodo ."
134  "?r a ?subclasses ."
135  "?r ncal:uid ?uid ."
136  "?r nao:hasSymbol \"view-pim-calendar\"^^<http://www.w3.org/2001/XMLSchema#string> ."
137  "?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
138  "FILTER REGEX( ?uid, \"^%1\", 'i')"
139  "}"
140 #endif
141  );
142  }
143  } else if ( match == ContainsMatch ) {
144  if ( criterion == IncidenceUid ) {
145  query += QString::fromLatin1(
146 #ifdef AKONADI_USE_STRIGI_SEARCH
147  "<request>"
148  " <query>"
149  " <and>"
150  " <equals>"
151  " <field name=\"type\"/>"
152  " <string>UnionOfEventJournalTodo</string>"
153  " </equals>"
154  " <contains>"
155  " <field name=\"uid\"/>"
156  " <string>%1</string>"
157  " </contains>"
158  " </and>"
159  " </query>"
160  "</request>"
161 #else
162  "SELECT ?r WHERE"
163  "{"
164  "?subclasses rdfs:subClassOf ncal:UnionOfEventJournalTodo ."
165  "?r a ?subclasses ."
166  "?r ncal:uid ?uid ."
167  "?r nao:hasSymbol \"view-pim-calendar\"^^<http://www.w3.org/2001/XMLSchema#string> ."
168  "?r <" + akonadiItemIdUri().toEncoded() + "> ?itemId . "
169  "FILTER REGEX( ?uid, \"%1\", 'i')"
170  "}"
171 #endif
172  );
173  }
174  }
175 
176  if ( d->mLimit != -1 ) {
177 #ifndef AKONADI_USE_STRIGI_SEARCH
178  query += QString::fromLatin1( " LIMIT %1" ).arg( d->mLimit );
179 #endif
180  }
181  query = query.arg( value );
182  ItemSearchJob::setQuery( query );
183 }
184 
185 void IncidenceSearchJob::setLimit( int limit )
186 {
187  d->mLimit = limit;
188 }
189 
190 KCalCore::Incidence::List IncidenceSearchJob::incidences() const
191 {
192  KCalCore::Incidence::List incidences;
193 
194  foreach ( const Item &item, items() ) {
195  if ( item.hasPayload<KCalCore::Incidence::Ptr>() ) {
196  incidences.append( item.payload<KCalCore::Incidence::Ptr>() );
197  }
198  }
199 
200  return incidences;
201 }
202 
203 #include "incidencesearchjob.moc"
CalendarSupport::IncidenceSearchJob::ContainsMatch
The result must contain the pattern (case insensitive).
Definition: incidencesearchjob.h:117
CalendarSupport::IncidenceSearchJob::incidences
KCalCore::Incidence::List incidences() const
Returns the incidences that matched the search criteria.
Definition: incidencesearchjob.cpp:190
CalendarSupport::IncidenceSearchJob::ExactMatch
The result must match exactly the pattern (case sensitive).
Definition: incidencesearchjob.h:115
CalendarSupport::IncidenceSearchJob::Match
Match
Describes the type of pattern matching that shall be used.
Definition: incidencesearchjob.h:114
CalendarSupport::IncidenceSearchJob::StartsWithMatch
The result must start with the pattern (case insensitive).
Definition: incidencesearchjob.h:116
CalendarSupport::IncidenceSearchJob::IncidenceUid
The global unique identifier of the incidence.
Definition: incidencesearchjob.h:106
QObject
CalendarSupport::IncidenceSearchJob::IncidenceSearchJob
IncidenceSearchJob(QObject *parent=0)
Creates a new incidence search job.
Definition: incidencesearchjob.cpp:36
CalendarSupport::IncidenceSearchJob::Criterion
Criterion
Describes the criteria that can be searched for.
Definition: incidencesearchjob.h:105
CalendarSupport::IncidenceSearchJob::setQuery
void setQuery(Criterion criterion, const QString &value, Match match)
Sets the criterion and value for the search with match.
Definition: incidencesearchjob.cpp:72
CalendarSupport::IncidenceSearchJob::setLimit
void setLimit(int limit)
Sets a limit on how many results will be returned by this search job.
Definition: incidencesearchjob.cpp:185
incidencesearchjob.h
CalendarSupport::IncidenceSearchJob::~IncidenceSearchJob
~IncidenceSearchJob()
Destroys the incidence search job.
Definition: incidencesearchjob.cpp:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

calendarsupport

Skip menu "calendarsupport"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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