MailTransport

sentactionattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3  SPDX-FileContributor: Tobias Koenig <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "sentactionattribute.h"
9 
10 #include <QDataStream>
11 #include <QSharedData>
12 
13 using namespace Akonadi;
14 using namespace MailTransport;
15 
16 class SentActionAttribute::Action::Private : public QSharedData
17 {
18 public:
19  Private()
20  {
21  }
22 
23  Private(const Private &other)
24  : QSharedData(other)
25  {
26  mType = other.mType;
27  mValue = other.mValue;
28  }
29 
30  Type mType = Invalid;
31  QVariant mValue;
32 };
33 
34 SentActionAttribute::Action::Action()
35  : d(new Private)
36 {
37 }
38 
40  : d(new Private)
41 {
42  d->mType = type;
43  d->mValue = value;
44 }
45 
47  : d(other.d)
48 {
49 }
50 
52 {
53 }
54 
56 {
57  return d->mType;
58 }
59 
61 {
62  return d->mValue;
63 }
64 
66 {
67  if (this != &other) {
68  d = other.d;
69  }
70 
71  return *this;
72 }
73 
75 {
76  return (d->mType == other.d->mType) && (d->mValue == other.d->mValue);
77 }
78 
79 class Q_DECL_HIDDEN SentActionAttribute::Private
80 {
81 public:
82  Action::List mActions;
83 };
84 
86  : d(new Private)
87 {
88 }
89 
91 {
92  delete d;
93 }
94 
96 {
97  d->mActions.append(Action(type, value));
98 }
99 
101 {
102  return d->mActions;
103 }
104 
105 SentActionAttribute *SentActionAttribute::clone() const
106 {
107  auto attribute = new SentActionAttribute;
108  attribute->d->mActions = d->mActions;
109 
110  return attribute;
111 }
112 
113 QByteArray SentActionAttribute::type() const
114 {
115  static const QByteArray sType("SentActionAttribute");
116  return sType;
117 }
118 
119 QByteArray SentActionAttribute::serialized() const
120 {
121  QVariantList list;
122  list.reserve(d->mActions.count());
123  for (const Action &action : std::as_const(d->mActions)) {
124  QVariantMap map;
125  map.insert(QString::number(action.type()), action.value());
126 
127  list << QVariant(map);
128  }
129 
130  QByteArray data;
131  QDataStream stream(&data, QIODevice::WriteOnly);
133  stream << list;
134 
135  return data;
136 }
137 
138 void SentActionAttribute::deserialize(const QByteArray &data)
139 {
140  d->mActions.clear();
141 
142  QDataStream stream(data);
144 
145  QVariantList list;
146  stream >> list;
147 
148  for (const QVariant &variant : std::as_const(list)) {
149  const QVariantMap map = variant.toMap();
150  QMap<QString, QVariant>::const_iterator it = map.cbegin();
151  const QMap<QString, QVariant>::const_iterator itEnd = map.cend();
152  for (; it != itEnd; ++it) {
153  d->mActions << Action(static_cast<Action::Type>(it.key().toInt()), it.value());
154  }
155  }
156 }
~SentActionAttribute() override
Destroys the sent action attribute.
void clear()
Action::List actions() const
Returns the list of actions.
void reserve(int alloc)
QVariant value() const
Returns the argument value of the action.
SentActionAttribute()
Creates a new sent action attribute.
bool operator==(const Action &other) const
QString number(int n, int base)
void addAction(Action::Type type, const QVariant &value)
Adds a new action to the attribute.
void setVersion(int v)
An Attribute that stores the action to execute after sending.
Type type() const
Returns the type of the action.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jul 29 2021 23:19:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.