Akonadi Mime

dispatchmodeattribute.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 "dispatchmodeattribute.h"
8
9#include "akonadi_mime_debug.h"
10
11#include <Akonadi/AttributeFactory>
12
13using namespace Akonadi;
14
15class Akonadi::DispatchModeAttributePrivate
16{
17public:
19 QDateTime mDueDate;
20};
21
23 : d(new DispatchModeAttributePrivate)
24{
25 d->mMode = mode;
26}
27
29
30DispatchModeAttribute *DispatchModeAttribute::clone() const
31{
32 auto const cloned = new DispatchModeAttribute(d->mMode);
33 cloned->setSendAfter(d->mDueDate);
34 return cloned;
35}
36
37QByteArray DispatchModeAttribute::type() const
38{
39 static const QByteArray sType("DispatchModeAttribute");
40 return sType;
41}
42
43QByteArray DispatchModeAttribute::serialized() const
44{
45 switch (d->mMode) {
46 case Automatic:
47 if (!d->mDueDate.isValid()) {
48 return "immediately";
49 } else {
50 return "after" + d->mDueDate.toString(Qt::ISODate).toLatin1();
51 }
52 case Manual:
53 return "never";
54 }
55
56 Q_ASSERT(false);
57 return {}; // suppress control-reaches-end-of-non-void-function warning
58}
59
60void DispatchModeAttribute::deserialize(const QByteArray &data)
61{
62 d->mDueDate = QDateTime();
63 if (data == "immediately") {
64 d->mMode = Automatic;
65 } else if (data == "never") {
66 d->mMode = Manual;
67 } else if (data.startsWith(QByteArrayLiteral("after"))) {
68 d->mMode = Automatic;
70 // NOTE: 5 is the strlen of "after".
71 } else {
72 qCWarning(AKONADIMIME_LOG) << "Failed to deserialize data [" << data << "]";
73 }
74}
75
80
82{
83 d->mMode = mode;
84}
85
87{
88 return d->mDueDate;
89}
90
92{
93 d->mDueDate = date;
94}
Attribute determining how and when a message from the outbox should be dispatched.
QDateTime sendAfter() const
Returns the date and time when the message should be sent.
DispatchMode dispatchMode() const
Returns the dispatch mode for the message.
void setDispatchMode(DispatchMode mode)
Sets the dispatch mode for the message.
~DispatchModeAttribute() override
Destroys the DispatchModeAttribute.
DispatchMode
Determines how the message is sent.
@ Manual
specified by setSendAfter()
@ Automatic
Send message as soon as possible, but no earlier than.
void setSendAfter(const QDateTime &date)
Sets the date and time when the message should be sent.
DispatchModeAttribute(DispatchMode mode=Automatic)
Creates a new DispatchModeAttribute.
QByteArray mid(qsizetype pos, qsizetype len) const const
bool startsWith(QByteArrayView bv) const const
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QString fromLatin1(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.