Akonadi

entitydeletedattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Christian Mollekopf <chrigi_1@fastmail.fm>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "entitydeletedattribute.h"
8
9#include "private/imapparser_p.h"
10
11#include "akonadicore_debug.h"
12
13#include <QByteArray>
14#include <QString>
15
16using namespace Akonadi;
17
18class Akonadi::EntityDeletedAttributePrivate
19{
20public:
21 Collection restoreCollection;
22 QString restoreResource;
23};
24
26 : d(new EntityDeletedAttributePrivate())
27{
28}
29
31
33{
34 if (!collection.isValid()) {
35 qCWarning(AKONADICORE_LOG) << "invalid collection" << collection;
36 }
37 Q_ASSERT(collection.isValid());
38 d->restoreCollection = collection;
39 if (collection.resource().isEmpty()) {
40 qCWarning(AKONADICORE_LOG) << "no resource set";
41 }
42 d->restoreResource = collection.resource();
43}
44
46{
47 return d->restoreCollection;
48}
49
51{
52 return d->restoreResource;
53}
54
56{
57 return QByteArrayLiteral("DELETED");
58}
59
61{
62 auto attr = new EntityDeletedAttribute();
63 attr->d->restoreCollection = d->restoreCollection;
64 attr->d->restoreResource = d->restoreResource;
65 return attr;
66}
67
69{
71 l << ImapParser::quote(d->restoreResource.toUtf8());
72 QList<QByteArray> components;
73 components << QByteArray::number(d->restoreCollection.id());
74
75 l << '(' + ImapParser::join(components, " ") + ')';
76 return '(' + ImapParser::join(l, " ") + ')';
77}
78
80{
82 ImapParser::parseParenthesizedList(data, l);
83 if (l.size() != 2) {
84 qCWarning(AKONADICORE_LOG) << "invalid size";
85 return;
86 }
87 d->restoreResource = QString::fromUtf8(l[0]);
88
89 if (!l[1].isEmpty()) {
90 QList<QByteArray> componentData;
91 ImapParser::parseParenthesizedList(l[1], componentData);
92 if (componentData.size() != 1) {
93 return;
94 }
95 bool ok;
96 const int components = componentData.at(0).toInt(&ok);
97 if (!ok) {
98 return;
99 }
100 d->restoreCollection = Collection(components);
101 }
102}
Represents a collection of PIM items.
Definition collection.h:62
An Attribute that marks that an entity was marked as deleted.
QString restoreResource() const
Returns the resource of the restoreCollection.
QByteArray type() const override
Reimplemented from Attribute.
QByteArray serialized() const override
Reimplemented from Attribute.
void setRestoreCollection(const Collection &col)
Sets the collection used to restore items which have been moved to trash using a TrashJob If the Reso...
EntityDeletedAttribute * clone() const override
Reimplemented from Attribute.
EntityDeletedAttribute()
Creates a new entity deleted attribute.
Collection restoreCollection() const
Returns the original collection of an item that has been moved to trash using a TrashJob.
~EntityDeletedAttribute() override
Destroys the entity deleted attribute.
void deserialize(const QByteArray &data) override
Reimplemented from Attribute.
Helper integration between Akonadi and Qt.
QByteArray number(double n, char format, int precision)
const_reference at(qsizetype i) const const
qsizetype size() const const
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.