MailTransport

dispatchmodeattribute.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "dispatchmodeattribute.h"
8 
9 #include "mailtransportakonadi_debug.h"
10 
11 #include <Akonadi/AttributeFactory>
12 
13 using namespace Akonadi;
14 using namespace MailTransport;
15 
16 class MailTransport::DispatchModeAttributePrivate
17 {
18 public:
20  QDateTime mDueDate;
21 };
22 
23 DispatchModeAttribute::DispatchModeAttribute(DispatchMode mode)
24  : d(new DispatchModeAttributePrivate)
25 {
26  d->mMode = mode;
27 }
28 
30 
31 DispatchModeAttribute *DispatchModeAttribute::clone() const
32 {
33  auto const cloned = new DispatchModeAttribute(d->mMode);
34  cloned->setSendAfter(d->mDueDate);
35  return cloned;
36 }
37 
38 QByteArray DispatchModeAttribute::type() const
39 {
40  static const QByteArray sType("DispatchModeAttribute");
41  return sType;
42 }
43 
44 QByteArray DispatchModeAttribute::serialized() const
45 {
46  switch (d->mMode) {
47  case Automatic:
48  if (!d->mDueDate.isValid()) {
49  return "immediately";
50  } else {
51  return "after" + d->mDueDate.toString(Qt::ISODate).toLatin1();
52  }
53  case Manual:
54  return "never";
55  }
56 
57  Q_ASSERT(false);
58  return {}; // suppress control-reaches-end-of-non-void-function warning
59 }
60 
61 void DispatchModeAttribute::deserialize(const QByteArray &data)
62 {
63  d->mDueDate = QDateTime();
64  if (data == "immediately") {
65  d->mMode = Automatic;
66  } else if (data == "never") {
67  d->mMode = Manual;
68  } else if (data.startsWith(QByteArrayLiteral("after"))) {
69  d->mMode = Automatic;
71  // NOTE: 5 is the strlen of "after".
72  } else {
73  qCWarning(MAILTRANSPORTAKONADI_LOG) << "Failed to deserialize data [" << data << "]";
74  }
75 }
76 
78 {
79  return d->mMode;
80 }
81 
83 {
84  d->mMode = mode;
85 }
86 
88 {
89  return d->mDueDate;
90 }
91 
93 {
94  d->mDueDate = date;
95 }
DispatchMode dispatchMode() const
Returns the dispatch mode for the message.
DispatchMode
Determines how the message is sent.
Attribute determining how and when a message from the outbox should be dispatched.
QByteArray mid(int pos, int len) const const
bool startsWith(const QByteArray &ba) const const
QDateTime fromString(const QString &string, Qt::DateFormat format)
DispatchModeAttribute(DispatchMode mode=Automatic)
Creates a new DispatchModeAttribute.
@ Manual
specified by setSendAfter()
void setSendAfter(const QDateTime &date)
Sets the date and time when the message should be sent.
@ Automatic
Send message as soon as possible, but no earlier than.
QDateTime sendAfter() const
Returns the date and time when the message should be sent.
QString fromLatin1(const char *str, int size)
void setDispatchMode(DispatchMode mode)
Sets the dispatch mode for the message.
~DispatchModeAttribute() override
Destroys the DispatchModeAttribute.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:58:25 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.