Akonadi

collectionannotationsattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Omat Holding B.V. <info@omat.nl>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "collectionannotationsattribute.h"
8
9#include <QByteArray>
10
11using namespace Akonadi;
12
13CollectionAnnotationsAttribute::CollectionAnnotationsAttribute() = default;
14
15CollectionAnnotationsAttribute::CollectionAnnotationsAttribute(const QMap<QByteArray, QByteArray> &annotations)
16 : mAnnotations(annotations)
17{
18}
19
20void CollectionAnnotationsAttribute::setAnnotations(const QMap<QByteArray, QByteArray> &annotations)
21{
22 mAnnotations = annotations;
23}
24
25QMap<QByteArray, QByteArray> CollectionAnnotationsAttribute::annotations() const
26{
27 return mAnnotations;
28}
29
31{
32 static const QByteArray sType("collectionannotations");
33 return sType;
34}
35
40
42{
43 QByteArray result;
44 for (auto it = mAnnotations.cbegin(), end = mAnnotations.cend(); it != end; ++it) {
45 result += it.key();
46 result += ' ';
47 result += it.value();
48 result += " % "; // We use this separator as '%' is not allowed in keys or values
49 }
50 result.chop(3);
51
52 return result;
53}
54
56{
57 mAnnotations.clear();
58 const QList<QByteArray> lines = data.split('%');
59
60 for (int i = 0; i < lines.size(); ++i) {
61 QByteArray line = lines[i];
62 if (i != 0 && line.startsWith(' ')) {
63 line.remove(0, 1);
64 }
65 if (i != lines.size() - 1 && line.endsWith(' ')) {
66 line.chop(1);
67 }
68 if (line.trimmed().isEmpty()) {
69 continue;
70 }
71 int wsIndex = line.indexOf(' ');
72 if (wsIndex > 0) {
73 const QByteArray key = line.mid(0, wsIndex);
74 const QByteArray value = line.mid(wsIndex + 1);
75 mAnnotations[key] = value;
76 } else {
77 mAnnotations.insert(line, QByteArray());
78 }
79 }
80}
81
82bool CollectionAnnotationsAttribute::operator==(const CollectionAnnotationsAttribute &other) const
83{
84 return mAnnotations == other.annotations();
85}
void deserialize(const QByteArray &data) override
Sets the data of this attribute, using the same encoding as returned by toByteArray().
CollectionAnnotationsAttribute * clone() const override
Creates a copy of this attribute.
QByteArray serialized() const override
Returns a QByteArray representation of the attribute which will be storaged.
QByteArray type() const override
Returns the type of the attribute.
Helper integration between Akonadi and Qt.
void chop(qsizetype n)
bool endsWith(QByteArrayView bv) const const
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
bool isEmpty() const const
QByteArray mid(qsizetype pos, qsizetype len) const const
QByteArray & remove(qsizetype pos, qsizetype len)
QList< QByteArray > split(char sep) const const
bool startsWith(QByteArrayView bv) const const
QByteArray trimmed() const const
qsizetype size() const const
const_iterator cbegin() const const
const_iterator cend() const const
void clear()
iterator insert(const Key &key, const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.