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 <QIODevice>
12 #include <QSharedData>
13 
14 using namespace Akonadi;
15 using namespace MailTransport;
16 
17 class MailTransport::SentActionAttributeActionPrivate : public QSharedData
18 {
19 public:
20  SentActionAttributeActionPrivate() = default;
21 
22  SentActionAttributeActionPrivate(const SentActionAttributeActionPrivate &other)
23 
24  = default;
25 
26  SentActionAttribute::Action::Type mType = SentActionAttribute::Action::Invalid;
27  QVariant mValue;
28 };
29 
30 SentActionAttribute::Action::Action()
31  : d(new SentActionAttributeActionPrivate)
32 {
33 }
34 
36  : d(new SentActionAttributeActionPrivate)
37 {
38  d->mType = type;
39  d->mValue = value;
40 }
41 
43 
44  = default;
45 
47 
49 {
50  return d->mType;
51 }
52 
54 {
55  return d->mValue;
56 }
57 
59 {
60  if (this != &other) {
61  d = other.d;
62  }
63 
64  return *this;
65 }
66 
68 {
69  return (d->mType == other.d->mType) && (d->mValue == other.d->mValue);
70 }
71 
72 class MailTransport::SentActionAttributePrivate
73 {
74 public:
76 };
77 
79  : d(new SentActionAttributePrivate)
80 {
81 }
82 
84 
86 {
87  d->mActions.append(Action(type, value));
88 }
89 
91 {
92  return d->mActions;
93 }
94 
95 SentActionAttribute *SentActionAttribute::clone() const
96 {
97  auto attribute = new SentActionAttribute;
98  attribute->d->mActions = d->mActions;
99 
100  return attribute;
101 }
102 
103 QByteArray SentActionAttribute::type() const
104 {
105  static const QByteArray sType("SentActionAttribute");
106  return sType;
107 }
108 
109 QByteArray SentActionAttribute::serialized() const
110 {
111  QVariantList list;
112  list.reserve(d->mActions.count());
113  for (const Action &action : std::as_const(d->mActions)) {
114  QVariantMap map;
115  map.insert(QString::number(action.type()), action.value());
116 
117  list << QVariant(map);
118  }
119 
120  QByteArray data;
121  QDataStream stream(&data, QIODevice::WriteOnly);
122  stream.setVersion(QDataStream::Qt_4_6);
123  stream << list;
124 
125  return data;
126 }
127 
128 void SentActionAttribute::deserialize(const QByteArray &data)
129 {
130  d->mActions.clear();
131 
132  QDataStream stream(data);
133  stream.setVersion(QDataStream::Qt_4_6);
134 
135  QVariantList list;
136  stream >> list;
137 
138  for (const QVariant &variant : std::as_const(list)) {
139  const QVariantMap map = variant.toMap();
141  const QMap<QString, QVariant>::const_iterator itEnd = map.cend();
142  for (; it != itEnd; ++it) {
143  d->mActions << Action(static_cast<Action::Type>(it.key().toInt()), it.value());
144  }
145  }
146 }
~SentActionAttribute() override
Destroys the sent action attribute.
QString number(int n, int base)
void addAction(Action::Type type, const QVariant &value)
Adds a new action to the attribute.
void clear()
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
Type type() const
Returns the type of the action.
Action::List actions() const
Returns the list of actions.
void reserve(int alloc)
bool operator==(const Action &other) const
An Attribute that stores the action to execute after sending.
SentActionAttribute()
Creates a new sent action attribute.
QVariant value() const
Returns the argument value of the action.
QFuture< void > map(Sequence &sequence, MapFunctor function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:58:25 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.