Akonadi Mime

sentactionattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
3 SPDX-FileContributor: Tobias Koenig <tokoe@kdab.com>
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
14using namespace Akonadi;
15
16class Akonadi::SentActionAttributeActionPrivate : public QSharedData
17{
18public:
19 SentActionAttributeActionPrivate() = default;
20
21 SentActionAttributeActionPrivate(const SentActionAttributeActionPrivate &other)
22
23 = default;
24
26 QVariant mValue;
27};
28
30 : d(new SentActionAttributeActionPrivate)
31{
32}
33
35 : d(new SentActionAttributeActionPrivate)
36{
37 d->mType = type;
38 d->mValue = value;
39}
40
42
43 = default;
44
46
51
53{
54 return d->mValue;
55}
56
58{
59 if (this != &other) {
60 d = other.d;
61 }
62
63 return *this;
64}
65
67{
68 return (d->mType == other.d->mType) && (d->mValue == other.d->mValue);
69}
70
71class Akonadi::SentActionAttributePrivate
72{
73public:
75};
76
78 : d(new SentActionAttributePrivate)
79{
80}
81
83
85{
86 d->mActions.append(Action(type, value));
87}
88
93
94SentActionAttribute *SentActionAttribute::clone() const
95{
96 auto attribute = new SentActionAttribute;
97 attribute->d->mActions = d->mActions;
98
99 return attribute;
100}
101
102QByteArray SentActionAttribute::type() const
103{
104 static const QByteArray sType("SentActionAttribute");
105 return sType;
106}
107
108QByteArray SentActionAttribute::serialized() const
109{
110 QVariantList list;
111 list.reserve(d->mActions.count());
112 for (const Action &action : std::as_const(d->mActions)) {
113 QVariantMap map;
114 map.insert(QString::number(action.type()), action.value());
115
116 list << QVariant(map);
117 }
118
119 QByteArray data;
120 QDataStream stream(&data, QIODevice::WriteOnly);
121 stream.setVersion(QDataStream::Qt_4_6);
122 stream << list;
123
124 return data;
125}
126
127void SentActionAttribute::deserialize(const QByteArray &data)
128{
129 d->mActions.clear();
130
131 QDataStream stream(data);
132 stream.setVersion(QDataStream::Qt_4_6);
133
134 QVariantList list;
135 stream >> list;
136
137 for (const QVariant &variant : std::as_const(list)) {
138 const QVariantMap map = variant.toMap();
140 const QMap<QString, QVariant>::const_iterator itEnd = map.cend();
141 for (; it != itEnd; ++it) {
142 d->mActions << Action(static_cast<Action::Type>(it.key().toInt()), it.value());
143 }
144 }
145}
Action & operator=(const Action &other)
Action()
Creates a new invalid action.
bool operator==(const Action &other) const
QVariant value() const
Returns the argument value of the action.
Type type() const
Returns the type of the action.
An Attribute that stores the action to execute after sending.
Action::List actions() const
Returns the list of actions.
SentActionAttribute()
Creates a new sent action attribute.
void addAction(Action::Type type, const QVariant &value)
Adds a new action to the attribute.
~SentActionAttribute() override
Destroys the sent action attribute.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void clear()
void reserve(qsizetype size)
QString number(double n, char format, int precision)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:32:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.