• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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
28using namespace Akonadi;
29
30class PersistentSearchAttribute::Private
31{
32public:
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
45PersistentSearchAttribute::PersistentSearchAttribute()
46 : d(new Private)
47{
48}
49
50PersistentSearchAttribute::~PersistentSearchAttribute()
51{
52 delete d;
53}
54
55QString PersistentSearchAttribute::queryLanguage() const
56{
57 return QLatin1String("SPARQL");
58}
59
60void PersistentSearchAttribute::setQueryLanguage(const QString &language)
61{
62 Q_UNUSED(language);
63}
64
65QString PersistentSearchAttribute::queryString() const
66{
67 return d->queryString;
68}
69
70void PersistentSearchAttribute::setQueryString(const QString &query)
71{
72 d->queryString = query;
73}
74
75QList<qint64> PersistentSearchAttribute::queryCollections() const
76{
77 return d->queryCollections;
78}
79
80void 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
88void PersistentSearchAttribute::setQueryCollections(const QList<qint64> &collectionsIds)
89{
90 d->queryCollections = collectionsIds;
91}
92
93bool PersistentSearchAttribute::isRecursive() const
94{
95 return d->recursive;
96}
97
98void PersistentSearchAttribute::setRecursive(bool recursive)
99{
100 d->recursive = recursive;
101}
102
103bool PersistentSearchAttribute::isRemoteSearchEnabled() const
104{
105 return d->remote;
106}
107
108void PersistentSearchAttribute::setRemoteSearchEnabled(bool enabled)
109{
110 d->remote = enabled;
111}
112
113QByteArray PersistentSearchAttribute::type() const
114{
115 static const QByteArray sType( "PERSISTENTSEARCH" );
116 return sType;
117}
118
119Attribute *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
129QByteArray 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
151void 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}
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:139
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::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::Attribute::type
virtual QByteArray type() const =0
Returns the type of the attribute.
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::PersistentSearchAttribute
An attribute to store query properties of persistent search collections.
Definition: persistentsearchattribute.h:74
Akonadi::PersistentSearchAttribute::~PersistentSearchAttribute
~PersistentSearchAttribute()
Destroys the persistent search attribute.
Definition: persistentsearchattribute.cpp:50
Akonadi::PersistentSearchAttribute::isRecursive
bool isRecursive() const
Returns whether the search is recursive.
Definition: persistentsearchattribute.cpp:93
Akonadi::PersistentSearchAttribute::PersistentSearchAttribute
PersistentSearchAttribute()
Creates a new persistent search attribute.
Definition: persistentsearchattribute.cpp:45
Akonadi::PersistentSearchAttribute::setRecursive
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
Definition: persistentsearchattribute.cpp:98
Akonadi::PersistentSearchAttribute::queryCollections
QList< qint64 > queryCollections() const
Returns IDs of collections that will be queried.
Definition: persistentsearchattribute.cpp:75
Akonadi::PersistentSearchAttribute::setQueryCollections
void setQueryCollections(const QList< Collection > &collections)
Sets collections to be queried.
Definition: persistentsearchattribute.cpp:80
Akonadi::PersistentSearchAttribute::isRemoteSearchEnabled
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
Definition: persistentsearchattribute.cpp:103
Akonadi::PersistentSearchAttribute::setQueryLanguage
AKONADI_DEPRECATED void setQueryLanguage(const QString &language)
Sets the query language used for this search.
Definition: persistentsearchattribute.cpp:60
Akonadi::PersistentSearchAttribute::queryString
QString queryString() const
Returns the query string used for this search.
Definition: persistentsearchattribute.cpp:65
Akonadi::PersistentSearchAttribute::setQueryString
void setQueryString(const QString &query)
Sets the query string to be used for this search.
Definition: persistentsearchattribute.cpp:70
Akonadi::PersistentSearchAttribute::queryLanguage
AKONADI_DEPRECATED QString queryLanguage() const
Returns the query language used for this search.
Definition: persistentsearchattribute.cpp:55
Akonadi::PersistentSearchAttribute::setRemoteSearchEnabled
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
Definition: persistentsearchattribute.cpp:108
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

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