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

akonadi

  • akonadi
persistentsearchattribute.cpp
1 /*
2  Copyright (c) 2010 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "persistentsearchattribute.h"
21 #include "collection.h"
22 
23 #include <akonadi/private/imapparser_p.h>
24 
25 #include <QtCore/QString>
26 #include <QtCore/QStringList>
27 
28 using namespace Akonadi;
29 
30 class PersistentSearchAttribute::Private
31 {
32  public:
33  Private()
34  : remote( true )
35  , recursive( false )
36  {
37  }
38 
39  QString queryString;
40  QList<qint64> queryCollections;
41  bool remote;
42  bool recursive;
43 };
44 
45 PersistentSearchAttribute::PersistentSearchAttribute()
46  : d( new Private )
47 {
48 }
49 
50 PersistentSearchAttribute::~PersistentSearchAttribute()
51 {
52  delete d;
53 }
54 
55 QString PersistentSearchAttribute::queryLanguage() const
56 {
57  return QLatin1String( "SPARQL" );
58 }
59 
60 void PersistentSearchAttribute::setQueryLanguage( const QString &language )
61 {
62  Q_UNUSED( language );
63 }
64 
65 QString PersistentSearchAttribute::queryString() const
66 {
67  return d->queryString;
68 }
69 
70 void PersistentSearchAttribute::setQueryString( const QString &query )
71 {
72  d->queryString = query;
73 }
74 
75 QList<qint64> PersistentSearchAttribute::queryCollections() const
76 {
77  return d->queryCollections;
78 }
79 
80 void PersistentSearchAttribute::setQueryCollections( const QList<Collection> &collections )
81 {
82  d->queryCollections.clear();
83  Q_FOREACH ( const Collection &collection, collections ) {
84  d->queryCollections << collection.id();
85  }
86 }
87 
88 void PersistentSearchAttribute::setQueryCollections( const QList<qint64> &collectionsIds )
89 {
90  d->queryCollections = collectionsIds;
91 }
92 
93 bool PersistentSearchAttribute::isRecursive() const
94 {
95  return d->recursive;
96 }
97 
98 void PersistentSearchAttribute::setRecursive( bool recursive )
99 {
100  d->recursive = recursive;
101 }
102 
103 bool PersistentSearchAttribute::isRemoteSearchEnabled() const
104 {
105  return d->remote;
106 }
107 
108 void PersistentSearchAttribute::setRemoteSearchEnabled( bool enabled )
109 {
110  d->remote = enabled;
111 }
112 
113 QByteArray PersistentSearchAttribute::type() const
114 {
115  return "PERSISTENTSEARCH"; // ### should eventually be AKONADI_PARAM_PERSISTENTSEARCH
116 }
117 
118 Attribute* PersistentSearchAttribute::clone() const
119 {
120  PersistentSearchAttribute* attr = new PersistentSearchAttribute;
121  attr->setQueryString( queryString() );
122  attr->setQueryCollections( queryCollections() );
123  attr->setRecursive( isRecursive() );
124  attr->setRemoteSearchEnabled( isRemoteSearchEnabled() );
125  return attr;
126 }
127 
128 QByteArray PersistentSearchAttribute::serialized() const
129 {
130  QStringList cols;
131  Q_FOREACH ( qint64 colId, d->queryCollections ) {
132  cols << QString::number( colId );
133  }
134 
135  QList<QByteArray> l;
136  // ### eventually replace with the AKONADI_PARAM_PERSISTENTSEARCH_XXX constants
137  l.append( "QUERYSTRING" );
138  l.append( ImapParser::quote( d->queryString.toUtf8() ) );
139  l.append( "QUERYCOLLECTIONS" );
140  l.append( "(" + cols.join( QLatin1String( " " ) ).toLatin1() + ")" );
141  if ( d->remote ) {
142  l.append( "REMOTE" );
143  }
144  if ( d->recursive ) {
145  l.append( "RECURSIVE" );
146  }
147  return "(" + ImapParser::join( l, " " ) + ')'; //krazy:exclude=doublequote_chars
148 }
149 
150 void PersistentSearchAttribute::deserialize(const QByteArray& data)
151 {
152  QList<QByteArray> l;
153  ImapParser::parseParenthesizedList( data, l );
154  for ( int i = 0; i < l.size() - 1; ++i) {
155  const QByteArray key = l.at( i );
156  if ( key == "QUERYLANGUAGE" ) {
157  // Skip the value
158  ++i;
159  } else if ( key == "QUERYSTRING" ) {
160  d->queryString = QString::fromUtf8( l.at( i + 1 ) );
161  ++i;
162  } else if ( key == "QUERYCOLLECTIONS" ) {
163  QList<QByteArray> ids;
164  ImapParser::parseParenthesizedList( l.at ( i + 1 ), ids );
165  d->queryCollections.clear();
166  Q_FOREACH ( const QByteArray &id, ids ) {
167  d->queryCollections << id.toLongLong();
168  }
169  ++i;
170  } else if ( key == "REMOTE" ) {
171  d->remote = true;
172  } else if ( key == "RECURSIVE" ) {
173  d->recursive = true;
174  }
175  }
176 }
Akonadi::PersistentSearchAttribute::isRecursive
bool isRecursive() const
Returns whether the search is recursive.
Definition: persistentsearchattribute.cpp:93
Akonadi::PersistentSearchAttribute::~PersistentSearchAttribute
~PersistentSearchAttribute()
Destroys the persistent search attribute.
Definition: persistentsearchattribute.cpp:50
Akonadi::PersistentSearchAttribute::PersistentSearchAttribute
PersistentSearchAttribute()
Creates a new persistent search attribute.
Definition: persistentsearchattribute.cpp:45
Akonadi::PersistentSearchAttribute::queryCollections
QList< qint64 > queryCollections() const
Returns IDs of collections that will be queried.
Definition: persistentsearchattribute.cpp:75
Akonadi::PersistentSearchAttribute::isRemoteSearchEnabled
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
Definition: persistentsearchattribute.cpp:103
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Attribute::deserialize
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::PersistentSearchAttribute::setQueryString
void setQueryString(const QString &query)
Sets the query string to be used for this search.
Definition: persistentsearchattribute.cpp:70
Akonadi::PersistentSearchAttribute
An attribute to store query properties of persistent search collections.
Definition: persistentsearchattribute.h:73
Akonadi::PersistentSearchAttribute::queryLanguage
AKONADI_DEPRECATED QString queryLanguage() const
Returns the query language used for this search.
Definition: persistentsearchattribute.cpp:55
Akonadi::PersistentSearchAttribute::queryString
QString queryString() const
Returns the query string used for this search.
Definition: persistentsearchattribute.cpp:65
Akonadi::PersistentSearchAttribute::setRecursive
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
Definition: persistentsearchattribute.cpp:98
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::PersistentSearchAttribute::setRemoteSearchEnabled
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
Definition: persistentsearchattribute.cpp:108
Akonadi::Attribute::serialized
virtual QByteArray serialized() const =0
Returns a QByteArray representation of the attribute which will be storaged.
Akonadi::Attribute::clone
virtual Attribute * clone() const =0
Creates a copy of this attribute.
Akonadi::PersistentSearchAttribute::setQueryLanguage
AKONADI_DEPRECATED void setQueryLanguage(const QString &language)
Sets the query language used for this search.
Definition: persistentsearchattribute.cpp:60
Akonadi::Attribute::type
virtual QByteArray type() const =0
Returns the type of the attribute.
Akonadi::PersistentSearchAttribute::setQueryCollections
void setQueryCollections(const QList< Collection > &collections)
Sets collections to be queried.
Definition: persistentsearchattribute.cpp:80
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:54 by doxygen 1.8.6 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.13.3 API Reference

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