Akonadi Mime

sentbehaviourattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "sentbehaviourattribute.h"
8
9using namespace Akonadi;
10
11class Akonadi::SentBehaviourAttributePrivate
12{
13public:
14 SentBehaviourAttributePrivate() = default;
15
17 Akonadi::Collection mMoveToCollection;
18 bool mSilent = false;
19};
20
21SentBehaviourAttribute::SentBehaviourAttribute(SentBehaviour beh, const Collection &moveToCollection, bool sendSilently)
22 : d(new SentBehaviourAttributePrivate)
23{
24 d->mBehaviour = beh;
25 d->mMoveToCollection = moveToCollection;
26 d->mSilent = sendSilently;
27}
28
30
31SentBehaviourAttribute *SentBehaviourAttribute::clone() const
32{
33 return new SentBehaviourAttribute(d->mBehaviour, d->mMoveToCollection, d->mSilent);
34}
35
36QByteArray SentBehaviourAttribute::type() const
37{
38 static const QByteArray sType("SentBehaviourAttribute");
39 return sType;
40}
41
42QByteArray SentBehaviourAttribute::serialized() const
43{
44 QByteArray out;
45
46 switch (d->mBehaviour) {
47 case Delete:
48 out = QByteArrayLiteral("delete");
49 break;
51 out = QByteArrayLiteral("moveTo") + QByteArray::number(d->mMoveToCollection.id());
52 break;
54 out = QByteArrayLiteral("moveToDefault");
55 break;
56 default:
57 Q_ASSERT(false);
58 return {};
59 }
60
61 if (d->mSilent) {
62 out += QByteArrayLiteral(",silent");
63 }
64
65 return out;
66}
67
68void SentBehaviourAttribute::deserialize(const QByteArray &data)
69{
70 const QByteArrayList in = data.split(',');
71 Q_ASSERT(!in.isEmpty());
72
73 const QByteArray attr0 = in[0];
74 d->mMoveToCollection = Akonadi::Collection(-1);
75 if (attr0 == "delete") {
76 d->mBehaviour = Delete;
77 } else if (attr0 == "moveToDefault") {
78 d->mBehaviour = MoveToDefaultSentCollection;
79 } else if (attr0.startsWith(QByteArrayLiteral("moveTo"))) {
80 d->mBehaviour = MoveToCollection;
81 d->mMoveToCollection = Akonadi::Collection(attr0.mid(6).toLongLong());
82 // NOTE: 6 is the strlen of "moveTo".
83 } else {
84 Q_ASSERT(false);
85 }
86
87 if (in.size() == 2 && in[1] == "silent") {
88 d->mSilent = true;
89 }
90}
91
96
98{
99 d->mBehaviour = beh;
100}
101
103{
104 return d->mMoveToCollection;
105}
106
108{
109 d->mMoveToCollection = moveToCollection;
110}
111
113{
114 return d->mSilent;
115}
116
118{
119 d->mSilent = sendSilently;
120}
Attribute determining what will happen to a message after it is sent.
void setMoveToCollection(const Akonadi::Collection &moveToCollection)
Sets the collection to which the item should be moved after it is sent.
SentBehaviour
What to do with the item in the outbox after it has been sent successfully.
@ MoveToDefaultSentCollection
Move the item to the default sent-mail collection.
@ MoveToCollection
Move the item to a custom collection.
@ Delete
Delete the item from the outbox.
void setSentBehaviour(SentBehaviour beh)
Sets the sent-behaviour of the message.
void setSendSilently(bool sendSilently)
Set whether a notification should be shown after the email is sent.
bool sendSilently() const
Returns whether a notification should be shown after the email is sent.
SentBehaviour sentBehaviour() const
Returns the sent-behaviour of the message.
SentBehaviourAttribute(SentBehaviour beh=MoveToDefaultSentCollection, const Akonadi::Collection &moveToCollection=Akonadi::Collection(-1), bool sendSilently=false)
Creates a new SentBehaviourAttribute.
~SentBehaviourAttribute() override
Destroys the SentBehaviourAttribute.
Akonadi::Collection moveToCollection() const
Returns the collection to which the item should be moved after it is sent.
QByteArray mid(qsizetype pos, qsizetype len) const const
QByteArray number(double n, char format, int precision)
QList< QByteArray > split(char sep) const const
bool startsWith(QByteArrayView bv) const const
qlonglong toLongLong(bool *ok, int base) const const
bool isEmpty() const const
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Apr 27 2024 22:16:20 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.