Akonadi

entitydeletedattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Christian Mollekopf <[email protected]>
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 
16 using namespace Akonadi;
17 
18 class Akonadi::EntityDeletedAttributePrivate
19 {
20 public:
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 }
void deserialize(const QByteArray &data) override
Reimplemented from Attribute.
EntityDeletedAttribute()
Creates a new entity deleted attribute.
QString fromUtf8(const char *str, int size)
QByteArray number(int n, int base)
Represents a collection of PIM items.
Definition: collection.h:61
QByteArray type() const override
Reimplemented from Attribute.
Collection restoreCollection() const
Returns the original collection of an item that has been moved to trash using a TrashJob.
int size() const const
EntityDeletedAttribute * clone() const override
Reimplemented from Attribute.
bool isEmpty() const const
void setRestoreCollection(const Collection &col)
Sets the collection used to restore items which have been moved to trash using a TrashJob If the Reso...
const T & at(int i) const const
QByteArray serialized() const override
Reimplemented from Attribute.
~EntityDeletedAttribute() override
Destroys the entity deleted attribute.
int toInt(bool *ok, int base) const const
QString restoreResource() const
Returns the resource of the restoreCollection.
An Attribute that marks that an entity was marked as deleted.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:01:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.