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 "indexpolicyattribute.h"
21
22#include <akonadi/private/imapparser_p.h>
23
24#include <QtCore/QString>
25
26using namespace Akonadi;
27
28class IndexPolicyAttribute::Private
29{
30public:
31 Private()
32 : enable(true)
33 {
34 }
35 bool enable;
36};
37
38IndexPolicyAttribute::IndexPolicyAttribute()
39 : d(new Private)
40{
41}
42
43IndexPolicyAttribute::~IndexPolicyAttribute()
44{
45 delete d;
46}
47
48bool IndexPolicyAttribute::indexingEnabled() const
49{
50 return d->enable;
51}
52
53void IndexPolicyAttribute::setIndexingEnabled(bool enable)
54{
55 d->enable = enable;
56}
57
58QByteArray IndexPolicyAttribute::type() const
59{
60 return "INDEXPOLICY";
61}
62
63Attribute *IndexPolicyAttribute::clone() const
64{
65 IndexPolicyAttribute *attr = new IndexPolicyAttribute;
66 attr->setIndexingEnabled(indexingEnabled());
67 return attr;
68}
69
70QByteArray IndexPolicyAttribute::serialized() const
71{
72 QList<QByteArray> l;
73 l.append("ENABLE");
74 l.append(d->enable ? "true" : "false");
75 return "(" + ImapParser::join(l, " ") + ')'; //krazy:exclude=doublequote_chars
76}
77
78void IndexPolicyAttribute::deserialize(const QByteArray &data)
79{
80 QList<QByteArray> l;
81 ImapParser::parseParenthesizedList(data, l);
82 for (int i = 0; i < l.size() - 1; i += 2) {
83 const QByteArray key = l.at(i);
84 if (key == "ENABLE") {
85 d->enable = l.at(i + 1) == "true";
86 }
87 }
88}
89