KAlarmCal

eventattribute.cpp
1 /*
2  * eventattribute.cpp - per-user attributes for individual events
3  * This file is part of kalarmcal library, which provides access to KAlarm
4  * calendar data.
5  * SPDX-FileCopyrightText: 2010-2011 David Jarvie <[email protected]>
6  *
7  * SPDX-License-Identifier: LGPL-2.0-or-later
8  */
9 
10 #include "eventattribute.h"
11 #include "kalarmcal_debug.h"
12 
13 #include <QList>
14 #include <QByteArray>
15 
16 namespace KAlarmCal
17 {
18 
19 class Q_DECL_HIDDEN EventAttribute::Private
20 {
21 public:
22  KAEvent::CmdErrType mCommandError = KAEvent::CMD_NO_ERROR; // the last command execution error for the alarm
23 };
24 
25 EventAttribute::EventAttribute()
26  : d(new Private)
27 {
28 }
29 
30 EventAttribute::EventAttribute(const EventAttribute &rhs)
31  : Akonadi::Attribute(rhs),
32  d(new Private(*rhs.d))
33 {
34 }
35 
36 EventAttribute::~EventAttribute()
37 {
38  delete d;
39 }
40 
42 {
43  if (&other != this) {
44  Attribute::operator=(other);
45  *d = *other.d;
46  }
47  return *this;
48 }
49 
51 {
52  return d->mCommandError;
53 }
54 
56 {
57  d->mCommandError = err;
58 }
59 
60 QByteArray EventAttribute::type() const
61 {
62  static const QByteArray attType("KAlarmEvent");
63  return attType;
64 }
65 
66 EventAttribute *EventAttribute::clone() const
67 {
68  return new EventAttribute(*this);
69 }
70 
71 QByteArray EventAttribute::serialized() const
72 {
73  const QByteArray v = QByteArray::number(d->mCommandError);
74  qCDebug(KALARMCAL_LOG) << v;
75  return v;
76 }
77 
78 void EventAttribute::deserialize(const QByteArray &data)
79 {
80  qCDebug(KALARMCAL_LOG) << data;
81 
82  // Set default values
83  d->mCommandError = KAEvent::CMD_NO_ERROR;
84 
85  bool ok;
86  int c[1];
87  const QList<QByteArray> items = data.simplified().split(' ');
88  switch (items.count()) {
89  case 1:
90  c[0] = items[0].toInt(&ok);
92  return;
93  }
94  d->mCommandError = static_cast<KAEvent::CmdErrType>(c[0]);
95  break;
96 
97  default:
98  break;
99  }
100 }
101 
102 } // namespace KAlarmCal
103 
104 // vim: et sw=4:
QList< QByteArray > split(char sep) const const
void setCommandError(KAEvent::CmdErrType err)
Set the last command execution error for the item.
post-alarm command execution failed
Definition: kaevent.h:303
int count(const T &value) const const
QByteArray number(int n, int base)
pre-alarm command execution failed
Definition: kaevent.h:302
CmdErrType
Command execution error type for last time the alarm was triggered.
Definition: kaevent.h:299
KAEvent::CmdErrType commandError() const
Return the last command execution error for the item.
QByteArray simplified() const const
command alarm execution failed
Definition: kaevent.h:301
EventAttribute & operator=(const EventAttribute &other)
Assignment operator.
An Attribute containing status information for a KAlarm item.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Mar 2 2021 02:55:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.