Akonadi

persistentsearchattribute.cpp
1 /*
2  Copyright (c) 2010 Volker Krause <[email protected]>
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 
24 #include "private/imapparser_p.h"
25 
26 #include <QString>
27 #include <QStringList>
28 
29 using namespace Akonadi;
30 
31 class Q_DECL_HIDDEN PersistentSearchAttribute::Private
32 {
33 public:
34  Private()
35  : remote(false)
36  , recursive(false)
37  {
38  }
39 
40  QString queryString;
41  QVector<qint64> queryCollections;
42  bool remote;
43  bool recursive;
44 };
45 
47  : d(new Private)
48 {
49 }
50 
52 {
53  delete d;
54 }
55 
57 {
58  return d->queryString;
59 }
60 
62 {
63  d->queryString = query;
64 }
65 
67 {
68  return d->queryCollections;
69 }
70 
72 {
73  d->queryCollections.clear();
74  d->queryCollections.reserve(collections.count());
75  for (const Collection &collection : collections) {
76  d->queryCollections << collection.id();
77  }
78 }
79 
81 {
82  d->queryCollections = collectionsIds;
83 }
84 
86 {
87  return d->recursive;
88 }
89 
91 {
92  d->recursive = recursive;
93 }
94 
96 {
97  return d->remote;
98 }
99 
101 {
102  d->remote = enabled;
103 }
104 
106 {
107  static const QByteArray sType("PERSISTENTSEARCH");
108  return sType;
109 }
110 
112 {
114  attr->setQueryString(queryString());
116  attr->setRecursive(isRecursive());
118  return attr;
119 }
120 
122 {
123  QStringList cols;
124  cols.reserve(d->queryCollections.count());
125  for (qint64 colId : qAsConst(d->queryCollections)) {
126  cols << QString::number(colId);
127  }
128 
130  // ### eventually replace with the AKONADI_PARAM_PERSISTENTSEARCH_XXX constants
131  l.append("QUERYSTRING");
132  l.append(ImapParser::quote(d->queryString.toUtf8()));
133  l.append("QUERYCOLLECTIONS");
134  l.append("(" + cols.join(QLatin1Char(' ')).toLatin1() + ')');
135  if (d->remote) {
136  l.append("REMOTE");
137  }
138  if (d->recursive) {
139  l.append("RECURSIVE");
140  }
141  return "(" + ImapParser::join(l, " ") + ')'; //krazy:exclude=doublequote_chars
142 }
143 
145 {
147  ImapParser::parseParenthesizedList(data, l);
148  const int listSize(l.size());
149  for (int i = 0; i < listSize; ++i) {
150  const QByteArray key = l.at(i);
151  if (key == QByteArrayLiteral("QUERYLANGUAGE")) {
152  // Skip the value
153  ++i;
154  } else if (key == QByteArrayLiteral("QUERYSTRING")) {
155  d->queryString = QString::fromUtf8(l.at(i + 1));
156  ++i;
157  } else if (key == QByteArrayLiteral("QUERYCOLLECTIONS")) {
158  QList<QByteArray> ids;
159  ImapParser::parseParenthesizedList(l.at(i + 1), ids);
160  d->queryCollections.clear();
161  d->queryCollections.reserve(ids.count());
162  for (const QByteArray &id : qAsConst(ids)) {
163  d->queryCollections << id.toLongLong();
164  }
165  ++i;
166  } else if (key == QByteArrayLiteral("REMOTE")) {
167  d->remote = true;
168  } else if (key == QByteArrayLiteral("RECURSIVE")) {
169  d->recursive = true;
170  }
171  }
172 }
void clear()
bool isRecursive() const
Returns whether the search is recursive.
PersistentSearchAttribute()
Creates a new persistent search attribute.
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
void reserve(int alloc)
Represents a collection of PIM items.
Definition: collection.h:76
const T & at(int i) const const
void setQueryCollections(const QVector< Collection > &collections)
Sets collections to be queried.
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
QString join(const QString &separator) const const
QVector< qint64 > queryCollections() const
Returns IDs of collections that will be queried.
Provides interface for custom attributes for Entity.
Definition: attribute.h:139
void setQueryString(const QString &query)
Sets the query string to be used for this search.
virtual QByteArray type() const =0
Returns the type of the attribute.
int size() const const
An attribute to store query properties of persistent search collections.
QString number(int n, int base)
int count(const T &value) const const
void append(const T &value)
QString fromUtf8(const char *str, int size)
QString queryString() const
Returns the query string used for this search.
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
QByteArray toLatin1() const const
virtual Attribute * clone() const =0
Creates a copy of this attribute.
Helper integration between Akonadi and Qt.
int count(const T &value) const const
virtual QByteArray serialized() const =0
Returns a QByteArray representation of the attribute which will be storaged.
~PersistentSearchAttribute() override
Destroys the persistent search attribute.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.