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 * Copyright © 2010-2011 by David Jarvie <djarvie@kde.org>
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
21 */
22
23#include "eventattribute.h"
24
25#include <QList>
26#include <QByteArray>
27
28namespace KAlarmCal
29{
30
31class EventAttribute::Private
32{
33 public:
34 Private() : mCommandError(KAEvent::CMD_NO_ERROR) {}
35
36 KAEvent::CmdErrType mCommandError; // the last command execution error for the alarm
37};
38
39EventAttribute::EventAttribute()
40 : d(new Private)
41{
42}
43
44EventAttribute::EventAttribute(const EventAttribute& rhs)
45 : Akonadi::Attribute(rhs),
46 d(new Private(*rhs.d))
47{
48}
49
50EventAttribute::~EventAttribute()
51{
52 delete d;
53}
54
55EventAttribute& EventAttribute::operator=(const EventAttribute& other)
56{
57 if (&other != this)
58 {
59 Attribute::operator=(other);
60 *d = *other.d;
61 }
62 return *this;
63}
64
65KAEvent::CmdErrType EventAttribute::commandError() const
66{
67 return d->mCommandError;
68}
69
70void EventAttribute::setCommandError(KAEvent::CmdErrType err)
71{
72 d->mCommandError = err;
73}
74
75QByteArray EventAttribute::type() const
76{
77 return "KAlarmEvent";
78}
79
80EventAttribute* EventAttribute::clone() const
81{
82 return new EventAttribute(*this);
83}
84
85QByteArray EventAttribute::serialized() const
86{
87 QByteArray v = QByteArray::number(d->mCommandError);
88 kDebug() << v;
89 return v;
90}
91
92void EventAttribute::deserialize(const QByteArray& data)
93{
94 kDebug() << data;
95
96 // Set default values
97 d->mCommandError = KAEvent::CMD_NO_ERROR;
98
99 bool ok;
100 int c[1];
101 const QList<QByteArray> items = data.simplified().split(' ');
102 switch (items.count())
103 {
104 case 1:
105 c[0] = items[0].toInt(&ok);
106 if (!ok || (c[0] & ~(KAEvent::CMD_ERROR | KAEvent::CMD_ERROR_PRE | KAEvent::CMD_ERROR_POST)))
107 return;
108 d->mCommandError = static_cast<KAEvent::CmdErrType>(c[0]);
109 break;
110
111 default:
112 break;
113 }
114}
115
116} // namespace KAlarmCal
117
118// vim: et sw=4:
119