Akonadi Mime

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 
16 class Akonadi::SentActionAttributeActionPrivate : public QSharedData
17 {
18 public:
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 
48 {
49  return d->mType;
50 }
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 
71 class Akonadi::SentActionAttributePrivate
72 {
73 public:
75 };
76 
78  : d(new SentActionAttributePrivate)
79 {
80 }
81 
83 
85 {
86  d->mActions.append(Action(type, value));
87 }
88 
90 {
91  return d->mActions;
92 }
93 
94 SentActionAttribute *SentActionAttribute::clone() const
95 {
96  auto attribute = new SentActionAttribute;
97  attribute->d->mActions = d->mActions;
98 
99  return attribute;
100 }
101 
102 QByteArray SentActionAttribute::type() const
103 {
104  static const QByteArray sType("SentActionAttribute");
105  return sType;
106 }
107 
108 QByteArray 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 
127 void 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 }
An Attribute that stores the action to execute after sending.
QString number(int n, int base)
Action()
Creates a new invalid action.
Action & operator=(const Action &other)
bool operator==(const Action &other) const
void addAction(Action::Type type, const QVariant &value)
Adds a new action to the attribute.
~SentActionAttribute() override
Destroys the sent action attribute.
void clear()
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
void reserve(int alloc)
Action::List actions() const
Returns the list of actions.
Type type() const
Returns the type of the action.
QVariant value() const
Returns the argument value of the action.
SentActionAttribute()
Creates a new sent action attribute.
QFuture< void > map(Sequence &sequence, MapFunctor function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Dec 7 2023 04:11:43 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.