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 EntityDeletedAttribute::EntityDeletedAttributePrivate
19 {
20 public:
21  EntityDeletedAttributePrivate() {}
22 
25 };
26 
28  : d_ptr(new EntityDeletedAttributePrivate())
29 {
30 
31 }
32 
34 {
35  delete d_ptr;
36 }
37 
39 {
41  if (!collection.isValid()) {
42  qCWarning(AKONADICORE_LOG) << "invalid collection" << collection;
43  }
44  Q_ASSERT(collection.isValid());
45  d->restoreCollection = collection;
46  if (collection.resource().isEmpty()) {
47  qCWarning(AKONADICORE_LOG) << "no resource set";
48  }
49  d->restoreResource = collection.resource();
50 }
51 
53 {
54  Q_D(const EntityDeletedAttribute);
55  return d->restoreCollection;
56 }
57 
59 {
60  Q_D(const EntityDeletedAttribute);
61  return d->restoreResource;
62 }
63 
65 {
66  static const QByteArray sType("DELETED");
67  return sType;
68 }
69 
71 {
72  const Q_D(EntityDeletedAttribute);
74  attr->d_ptr->restoreCollection = d->restoreCollection;
75  attr->d_ptr->restoreResource = d->restoreResource;
76  return attr;
77 }
78 
80 {
81  const Q_D(EntityDeletedAttribute);
82 
84  l << ImapParser::quote(d->restoreResource.toUtf8());
85  QList<QByteArray> components;
86  components << QByteArray::number(d->restoreCollection.id());
87 
88  l << '(' + ImapParser::join(components, " ") + ')';
89  return '(' + ImapParser::join(l, " ") + ')';
90 }
91 
93 {
95 
97  ImapParser::parseParenthesizedList(data, l);
98  if (l.size() != 2) {
99  qCWarning(AKONADICORE_LOG) << "invalid size";
100  return;
101  }
102  d->restoreResource = QString::fromUtf8(l[0]);
103 
104  if (!l[1].isEmpty()) {
105  QList<QByteArray> componentData;
106  ImapParser::parseParenthesizedList(l[1], componentData);
107  if (componentData.size() != 1) {
108  return;
109  }
110  bool ok;
111  const int components = componentData.at(0).toInt(&ok);
112  if (!ok) {
113  return;
114  }
115  d->restoreCollection = Collection(components);
116  }
117 }
EntityDeletedAttribute()
Creates a new entity deleted attribute.
bool isValid() const
Returns whether the collection is valid.
Definition: collection.cpp:124
Collection restoreCollection() const
Returns the original collection of an item that has been moved to trash using a TrashJob.
EntityDeletedAttribute * clone() const override
Reimplemented from Attribute.
Represents a collection of PIM items.
Definition: collection.h:63
const T & at(int i) const const
~EntityDeletedAttribute() override
Destroys the entity deleted attribute.
QByteArray type() const override
Reimplemented from Attribute.
int size() const const
QString fromUtf8(const char *str, int size)
bool isEmpty() const const
QByteArray number(int n, int base)
An Attribute that marks that an entity was marked as deleted.
QString restoreResource() const
Returns the resource of the restoreCollection.
Helper integration between Akonadi and Qt.
void deserialize(const QByteArray &data) override
Reimplemented from Attribute.
QByteArray serialized() const override
Reimplemented from Attribute.
QString resource() const
Returns the identifier of the resource owning the collection.
Definition: collection.cpp:305
void setRestoreCollection(const Collection &col)
Sets the collection used to restore items which have been moved to trash using a TrashJob If the Reso...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jul 8 2020 23:15:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.