Akonadi Mime

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 "akonadi_mime_debug.h"
10 
11 #include <Akonadi/AttributeFactory>
12 
13 using namespace Akonadi;
14 
15 class Akonadi::DispatchModeAttributePrivate
16 {
17 public:
19  QDateTime mDueDate;
20 };
21 
23  : d(new DispatchModeAttributePrivate)
24 {
25  d->mMode = mode;
26 }
27 
29 
30 DispatchModeAttribute *DispatchModeAttribute::clone() const
31 {
32  auto const cloned = new DispatchModeAttribute(d->mMode);
33  cloned->setSendAfter(d->mDueDate);
34  return cloned;
35 }
36 
37 QByteArray DispatchModeAttribute::type() const
38 {
39  static const QByteArray sType("DispatchModeAttribute");
40  return sType;
41 }
42 
43 QByteArray 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 
60 void 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 
77 {
78  return d->mMode;
79 }
80 
82 {
83  d->mMode = mode;
84 }
85 
87 {
88  return d->mDueDate;
89 }
90 
92 {
93  d->mDueDate = date;
94 }
void setSendAfter(const QDateTime &date)
Sets the date and time when the message should be sent.
Attribute determining how and when a message from the outbox should be dispatched.
~DispatchModeAttribute() override
Destroys the DispatchModeAttribute.
void setDispatchMode(DispatchMode mode)
Sets the dispatch mode for the message.
@ Automatic
Send message as soon as possible, but no earlier than.
@ Manual
specified by setSendAfter()
DispatchMode
Determines how the message is sent.
DispatchMode dispatchMode() const
Returns the dispatch mode for the message.
QByteArray mid(int pos, int len) const const
bool startsWith(const QByteArray &ba) const const
QDateTime fromString(const QString &string, Qt::DateFormat format)
QDateTime sendAfter() const
Returns the date and time when the message should be sent.
QString fromLatin1(const char *str, int size)
DispatchModeAttribute(DispatchMode mode=Automatic)
Creates a new DispatchModeAttribute.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:53:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.