22 #include "contactgroupsearchjob.h"
24 #include <akonadi/itemfetchscope.h>
26 using namespace Akonadi;
28 class ContactGroupSearchJob::Private
34 ContactGroupSearchJob::ContactGroupSearchJob( QObject * parent )
35 : ItemSearchJob( QString(), parent ), d( new Private )
37 fetchScope().fetchFullPayload();
41 ItemSearchJob::setQuery( QLatin1String(
""
42 #ifdef AKONADI_USE_STRIGI_SEARCH
46 " <field name=\"type\"/>"
47 " <string>ContactGroup</string>"
52 "prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>"
53 "SELECT ?r WHERE { ?r a nco:ContactGroup }"
58 ContactGroupSearchJob::~ContactGroupSearchJob()
63 void ContactGroupSearchJob::setQuery( Criterion criterion,
const QString &value )
67 setQuery( criterion, value, ExactMatch );
70 void ContactGroupSearchJob::setQuery( Criterion criterion,
const QString &value, Match match )
74 #ifndef AKONADI_USE_STRIGI_SEARCH
75 query = QString::fromLatin1(
"prefix nco:<http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>" );
78 if ( match == ExactMatch ) {
79 if ( criterion == Name ) {
80 query += QString::fromLatin1(
81 #ifdef AKONADI_USE_STRIGI_SEARCH
86 " <field name=\"type\"/>"
87 " <string>ContactGroup</string>"
90 " <field name=\"contactGroupName\"/>"
91 " <string>%1</string>"
97 "SELECT DISTINCT ?group "
100 " ?group <" + akonadiItemIdUri().toEncoded() +
"> ?itemId . "
101 " ?group nco:contactGroupName \"%1\"^^<http://www.w3.org/2001/XMLSchema#string>."
107 }
else if ( match == ContainsMatch ) {
108 if ( criterion == Name ) {
109 query += QString::fromLatin1(
110 #ifdef AKONADI_USE_STRIGI_SEARCH
115 " <field name=\"type\"/>"
116 " <string>ContactGroup</string>"
119 " <field name=\"contactGroupName\"/>"
120 " <string>%1</string>"
126 "SELECT DISTINCT ?group "
129 " ?group <" + akonadiItemIdUri().toEncoded() +
"> ?itemId . "
130 " ?group nco:contactGroupName ?v . "
131 " ?v bif:contains \"'%1'\""
137 }
else if ( match == StartsWithMatch ) {
138 if ( criterion == Name ) {
139 query += QString::fromLatin1(
140 #ifdef AKONADI_USE_STRIGI_SEARCH
145 " <field name=\"type\"/>"
146 " <string>ContactGroup</string>"
149 " <field name=\"contactGroupName\"/>"
150 " <string>%1</string>"
156 "SELECT DISTINCT ?group "
159 " ?group <" + akonadiItemIdUri().toEncoded() +
"> ?itemId . "
160 " ?group nco:contactGroupName ?v . "
161 " ?v bif:contains \"'%1*'\""
169 if ( d->mLimit != -1 ) {
170 #ifndef AKONADI_USE_STRIGI_SEARCH
171 query += QString::fromLatin1(
" LIMIT %1" ).arg( d->mLimit );
175 query = query.arg( value );
177 ItemSearchJob::setQuery( query );
180 void ContactGroupSearchJob::setLimit(
int limit )
185 KABC::ContactGroup::List ContactGroupSearchJob::contactGroups()
const
187 KABC::ContactGroup::List contactGroups;
189 foreach (
const Item &item, items() ) {
190 if ( item.hasPayload<KABC::ContactGroup>() )
191 contactGroups.append( item.payload<KABC::ContactGroup>() );
194 return contactGroups;
197 #include "contactgroupsearchjob.moc"