Akonadi

persistentsearchattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org>
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
15using namespace Akonadi;
16
17class Akonadi::PersistentSearchAttributePrivate
18{
19public:
20 QString queryString;
21 QList<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")) {
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}
Provides interface for custom attributes for Entity.
Definition attribute.h:132
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
virtual QByteArray serialized() const =0
Returns a QByteArray representation of the attribute which will be storaged.
virtual Attribute * clone() const =0
Creates a copy of this attribute.
virtual QByteArray type() const =0
Returns the type of the attribute.
Represents a collection of PIM items.
Definition collection.h:62
bool isRecursive() const
Returns whether the search is recursive.
PersistentSearchAttribute()
Creates a new persistent search attribute.
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
~PersistentSearchAttribute() override
Destroys the persistent search attribute.
QList< qint64 > queryCollections() const
Returns IDs of collections that will be queried.
void setQueryCollections(const QList< Collection > &collections)
Sets collections to be queried.
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
QString queryString() const
Returns the query string used for this search.
void setQueryString(const QString &query)
Sets the query string to be used for this search.
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
Helper integration between Akonadi and Qt.
A glue between Qt and the standard library.
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
void clear()
qsizetype count() const const
void reserve(qsizetype size)
qsizetype size() const const
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
QString join(QChar separator) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.