Akonadi Mime

mdnstateattribute.cpp
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org>
4 * SPDX-FileCopyrightText: 2010 KDAB
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 *
8 *****************************************************************************/
9
10#include "mdnstateattribute.h"
11
12#include <Akonadi/AttributeFactory>
13
14#include <QByteArray>
15
16using namespace Akonadi;
17
18/**
19 * @internal
20 */
21class Q_DECL_HIDDEN MDNStateAttribute::MDNStateAttributePrivate
22{
23public:
24 MDNSentState dataToState(const QByteArray &data)
25 {
26 MDNSentState state = MDNStateUnknown;
27
28 switch (data.at(0)) {
29 case 'N':
30 state = MDNNone;
31 break;
32 case 'I':
33 state = MDNIgnore;
34 break;
35 case 'R':
36 state = MDNDisplayed;
37 break;
38 case 'D':
39 state = MDNDeleted;
40 break;
41 case 'F':
42 state = MDNDispatched;
43 break;
44 case 'P':
45 state = MDNProcessed;
46 break;
47 case 'X':
48 state = MDNDenied;
49 break;
50 case 'E':
51 state = MDNFailed;
52 break;
53 case 'U':
54 default:
55 state = MDNStateUnknown;
56 break;
57 }
58
59 return state;
60 }
61
62 QByteArray stateToData(MDNSentState state)
63 {
64 QByteArray data = "U"; // Unknown
65
66 switch (state) {
67 case MDNNone:
68 data = "N";
69 break;
70 case MDNIgnore:
71 data = "I";
72 break;
73 case MDNDisplayed:
74 data = "R";
75 break;
76 case MDNDeleted:
77 data = "D";
78 break;
79 case MDNDispatched:
80 data = "F";
81 break;
82 case MDNProcessed:
83 data = "P";
84 break;
85 case MDNDenied:
86 data = "X";
87 break;
88 case MDNFailed:
89 data = "E";
90 break;
91 case MDNStateUnknown:
92 data = "U";
93 break;
94 }
95
96 return data;
97 }
98
99 QByteArray mSentState;
100};
101
103 : d(new MDNStateAttributePrivate)
104{
105 d->mSentState = d->stateToData(state);
106}
107
109 : d(new MDNStateAttributePrivate)
110{
111 d->mSentState = stateData;
112}
113
115
117{
118 return new MDNStateAttribute(d->mSentState);
119}
120
122{
123 static const QByteArray sType("MDNStateAttribute");
124 return sType;
125}
126
128{
129 return d->mSentState;
130}
131
133{
134 d->mSentState = data;
135}
136
138{
139 d->mSentState = d->stateToData(state);
140}
141
143{
144 return d->dataToState(d->mSentState);
145}
146
147bool MDNStateAttribute::operator==(const MDNStateAttribute &other) const
148{
149 return mdnState() == other.mdnState();
150}
151
152// Register the attribute when the library is loaded.
153namespace
154{
155bool dummyMDNStateAttribute()
156{
157 using namespace Akonadi;
159 return true;
160}
161
162const bool registeredMDNStateAttribute = dummyMDNStateAttribute();
163}
static void registerAttribute()
An Attribute that keeps track of the MDN state of a mail message.
MDNSentState
Describes the "MDN sent" state.
~MDNStateAttribute() override
Destroys the MDN state attribute.
QByteArray type() const override
Reimplemented from Attribute.
QByteArray serialized() const override
Reimplemented from Attribute.
MDNStateAttribute(MDNSentState state=MDNStateUnknown)
Creates a new MDN state attribute.
void deserialize(const QByteArray &data) override
Reimplemented from Attribute.
MDNStateAttribute::MDNSentState mdnState() const
Returns the MDN state.
void setMDNState(MDNSentState state)
Sets the MDN state.
MDNStateAttribute * clone() const override
Reimplemented from Attribute.
char at(qsizetype i) const const
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.