Akonadi

persistentsearchattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "persistentsearchattribute.h"
8 #include "collection.h"
9 
10 #include "private/imapparser_p.h"
11 
12 #include <QString>
13 #include <QStringList>
14 
15 using namespace Akonadi;
16 
17 class Akonadi::PersistentSearchAttributePrivate
18 {
19 public:
20  QString queryString;
21  QVector<qint64> queryCollections;
22  bool remote = false;
23  bool recursive = false;
24 };
25 
27  : d(new PersistentSearchAttributePrivate())
28 {
29 }
30 
32 
34 {
35  return d->queryString;
36 }
37 
39 {
40  d->queryString = query;
41 }
42 
44 {
45  return d->queryCollections;
46 }
47 
49 {
50  d->queryCollections.clear();
51  d->queryCollections.reserve(collections.count());
52  for (const Collection &collection : collections) {
53  d->queryCollections << collection.id();
54  }
55 }
56 
58 {
59  d->queryCollections = collectionsIds;
60 }
61 
63 {
64  return d->recursive;
65 }
66 
68 {
69  d->recursive = recursive;
70 }
71 
73 {
74  return d->remote;
75 }
76 
78 {
79  d->remote = enabled;
80 }
81 
83 {
84  static const QByteArray sType("PERSISTENTSEARCH");
85  return sType;
86 }
87 
89 {
90  auto attr = new PersistentSearchAttribute;
91  attr->setQueryString(queryString());
92  attr->setQueryCollections(queryCollections());
93  attr->setRecursive(isRecursive());
94  attr->setRemoteSearchEnabled(isRemoteSearchEnabled());
95  return attr;
96 }
97 
99 {
100  QStringList cols;
101  cols.reserve(d->queryCollections.count());
102  for (qint64 colId : std::as_const(d->queryCollections)) {
103  cols << QString::number(colId);
104  }
105 
107  // ### eventually replace with the AKONADI_PARAM_PERSISTENTSEARCH_XXX constants
108  l.append("QUERYSTRING");
109  l.append(ImapParser::quote(d->queryString.toUtf8()));
110  l.append("QUERYCOLLECTIONS");
111  l.append("(" + cols.join(QLatin1Char(' ')).toLatin1() + ')');
112  if (d->remote) {
113  l.append("REMOTE");
114  }
115  if (d->recursive) {
116  l.append("RECURSIVE");
117  }
118  return "(" + ImapParser::join(l, " ") + ')'; // krazy:exclude=doublequote_chars
119 }
120 
122 {
124  ImapParser::parseParenthesizedList(data, l);
125  const int listSize(l.size());
126  for (int i = 0; i < listSize; ++i) {
127  const QByteArray &key = l.at(i);
128  if (key == QByteArrayLiteral("QUERYLANGUAGE")) {
129  // Skip the value
130  ++i;
131  } else if (key == QByteArrayLiteral("QUERYSTRING")) {
132  d->queryString = QString::fromUtf8(l.at(i + 1));
133  ++i;
134  } else if (key == QByteArrayLiteral("QUERYCOLLECTIONS")) {
135  QList<QByteArray> ids;
136  ImapParser::parseParenthesizedList(l.at(i + 1), ids);
137  d->queryCollections.clear();
138  d->queryCollections.reserve(ids.count());
139  for (const QByteArray &id : std::as_const(ids)) {
140  d->queryCollections << id.toLongLong();
141  }
142  ++i;
143  } else if (key == QByteArrayLiteral("REMOTE")) {
144  d->remote = true;
145  } else if (key == QByteArrayLiteral("RECURSIVE")) {
146  d->recursive = true;
147  }
148  }
149 }
void append(const T &value)
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
QString number(int n, int base)
QString fromUtf8(const char *str, int size)
bool isRecursive() const
Returns whether the search is recursive.
QVector< qint64 > queryCollections() const
Returns IDs of collections that will be queried.
int count(const T &value) const const
virtual QByteArray type() const =0
Returns the type of the attribute.
Represents a collection of PIM items.
Definition: collection.h:61
~PersistentSearchAttribute() override
Destroys the persistent search attribute.
Provides interface for custom attributes for Entity.
Definition: attribute.h:124
PersistentSearchAttribute()
Creates a new persistent search attribute.
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
void reserve(int alloc)
virtual QByteArray serialized() const =0
Returns a QByteArray representation of the attribute which will be storaged.
int size() const const
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
void setQueryString(const QString &query)
Sets the query string to be used for this search.
void setQueryCollections(const QVector< Collection > &collections)
Sets collections to be queried.
const T & at(int i) const const
QString join(const QString &separator) const const
QString queryString() const
Returns the query string used for this search.
virtual Attribute * clone() const =0
Creates a copy of this attribute.
int count(const T &value) const const
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.