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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • 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  static const QByteArray sType( "PERSISTENTSEARCH" );
116  return sType;
117 }
118 
119 Attribute *PersistentSearchAttribute::clone() const
120 {
121  PersistentSearchAttribute *attr = new PersistentSearchAttribute;
122  attr->setQueryString(queryString());
123  attr->setQueryCollections(queryCollections());
124  attr->setRecursive(isRecursive());
125  attr->setRemoteSearchEnabled(isRemoteSearchEnabled());
126  return attr;
127 }
128 
129 QByteArray PersistentSearchAttribute::serialized() const
130 {
131  QStringList cols;
132  Q_FOREACH (qint64 colId, d->queryCollections) {
133  cols << QString::number(colId);
134  }
135 
136  QList<QByteArray> l;
137  // ### eventually replace with the AKONADI_PARAM_PERSISTENTSEARCH_XXX constants
138  l.append("QUERYSTRING");
139  l.append(ImapParser::quote(d->queryString.toUtf8()));
140  l.append("QUERYCOLLECTIONS");
141  l.append("(" + cols.join(QLatin1String(" ")).toLatin1() + ")");
142  if (d->remote) {
143  l.append("REMOTE");
144  }
145  if (d->recursive) {
146  l.append("RECURSIVE");
147  }
148  return "(" + ImapParser::join(l, " ") + ')'; //krazy:exclude=doublequote_chars
149 }
150 
151 void PersistentSearchAttribute::deserialize(const QByteArray &data)
152 {
153  QList<QByteArray> l;
154  ImapParser::parseParenthesizedList(data, l);
155  for (int i = 0; i < l.size() - 1; ++i) {
156  const QByteArray key = l.at(i);
157  if (key == "QUERYLANGUAGE") {
158  // Skip the value
159  ++i;
160  } else if (key == "QUERYSTRING") {
161  d->queryString = QString::fromUtf8(l.at(i + 1));
162  ++i;
163  } else if (key == "QUERYCOLLECTIONS") {
164  QList<QByteArray> ids;
165  ImapParser::parseParenthesizedList(l.at(i + 1), ids);
166  d->queryCollections.clear();
167  Q_FOREACH (const QByteArray &id, ids) {
168  d->queryCollections << id.toLongLong();
169  }
170  ++i;
171  } else if (key == "REMOTE") {
172  d->remote = true;
173  } else if (key == "RECURSIVE") {
174  d->recursive = true;
175  }
176  }
177 }
QList::clear
void clear()
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
QByteArray
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
QList::at
const T & at(int i) const
Akonadi::Attribute::deserialize
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
QStringList::join
QString join(const QString &separator) const
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
QList::size
int size() const
Akonadi::PersistentSearchAttribute
An attribute to store query properties of persistent search collections.
Definition: persistentsearchattribute.h:73
QString::number
QString number(int n, int base)
QList::append
void append(const T &value)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
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
QString
QList< qint64 >
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
QStringList
Akonadi::PersistentSearchAttribute::setRemoteSearchEnabled
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
Definition: persistentsearchattribute.cpp:108
QString::toLatin1
QByteArray toLatin1() const
QLatin1String
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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