2
<one line to give the library's name and an idea of what it does.>
3
Copyright (C) 2012 Dan Vratil <dan@progdan.cz>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "defaultreminderattribute.h"
23
#include <libkgoogle/objects/calendar.h>
25
#include <qjson/parser.h>
26
#include <qjson/serializer.h>
28
#include <QtCore/QVariant>
33
using namespace KCalCore;
36
using namespace KGoogle::Objects;
38
DefaultReminderAttribute::DefaultReminderAttribute (const Reminder::List& reminders):
39
m_reminders(reminders)
44
Akonadi::Attribute* DefaultReminderAttribute::clone() const
46
return new DefaultReminderAttribute(m_reminders);
49
void DefaultReminderAttribute::deserialize (const QByteArray& data)
54
list = parser.parse(data).toList();
55
Q_FOREACH (const QVariant &l, list) {
56
QVariantMap reminder = l.toMap();
58
Reminder::Ptr rem(new Reminder);
59
if (reminder["type"].toString() == "display") {
60
rem->setType(Alarm::Display);
61
} else if (reminder["type"].toString() == "email") {
62
rem->setType(Alarm::Email);
65
Duration offset(reminder["time"].toInt(), Duration::Seconds);
66
rem->setStartOffset(offset);
72
QByteArray DefaultReminderAttribute::serialized() const
76
Q_FOREACH (Reminder::Ptr rem, m_reminders) {
79
if (rem->type() == Alarm::Display) {
80
reminder["type"] = "display";
81
} else if (rem->type() == Alarm::Email) {
82
reminder["type"] = "email";
85
reminder["time"] = rem->startOffset().asSeconds();
90
QJson::Serializer serializer;
91
return serializer.serialize(list);
94
Alarm::List DefaultReminderAttribute::alarms(Incidence *incidence) const
98
Q_FOREACH (const Reminder::Ptr &reminder, m_reminders) {
99
AlarmPtr alarm(new Alarm(incidence));
101
alarm->setType(reminder->type());
102
alarm->setTime(incidence->dtStart());
103
alarm->setStartOffset(reminder->startOffset());
104
alarm->setEnabled(true);
113
QByteArray DefaultReminderAttribute::type() const
115
return "defaultReminders";