~benoitg/akonadigoogle/master

« back to all changes in this revision

Viewing changes to calendar/defaultreminderattribute.cpp

  • Committer: Dan Vrátil
  • Date: 2012-04-29 19:24:42 UTC
  • Revision ID: git-v1:efb32159c283168cc2ab1a39e6fa3c8a30fbc941
Move the Akonadi Resources to kdepim-runtime

The resources have been moved to kdepim-runtime, this repo now only contains
the LibKGoogle library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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>
4
 
 
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.
9
 
 
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.
14
 
 
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
18
 
*/
19
 
 
20
 
 
21
 
#include "defaultreminderattribute.h"
22
 
 
23
 
#include <libkgoogle/objects/calendar.h>
24
 
 
25
 
#include <qjson/parser.h>
26
 
#include <qjson/serializer.h>
27
 
 
28
 
#include <QtCore/QVariant>
29
 
 
30
 
#ifdef WITH_KCAL
31
 
using namespace KCal;
32
 
#else
33
 
using namespace KCalCore;
34
 
#endif
35
 
 
36
 
using namespace KGoogle::Objects;
37
 
 
38
 
DefaultReminderAttribute::DefaultReminderAttribute (const Reminder::List& reminders):
39
 
    m_reminders(reminders)
40
 
{
41
 
 
42
 
}
43
 
 
44
 
Akonadi::Attribute* DefaultReminderAttribute::clone() const
45
 
{
46
 
    return new DefaultReminderAttribute(m_reminders);
47
 
}
48
 
 
49
 
void DefaultReminderAttribute::deserialize (const QByteArray& data)
50
 
{
51
 
    QJson::Parser parser;
52
 
    QVariantList list;
53
 
 
54
 
    list = parser.parse(data).toList();
55
 
    Q_FOREACH (const QVariant &l, list) {
56
 
        QVariantMap reminder = l.toMap();
57
 
 
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);
63
 
        }
64
 
 
65
 
        Duration offset(reminder["time"].toInt(), Duration::Seconds);
66
 
        rem->setStartOffset(offset);
67
 
 
68
 
        m_reminders << rem;
69
 
    }
70
 
}
71
 
 
72
 
QByteArray DefaultReminderAttribute::serialized() const
73
 
{
74
 
    QVariantList list;
75
 
 
76
 
    Q_FOREACH (Reminder::Ptr rem, m_reminders) {
77
 
        QVariantMap reminder;
78
 
 
79
 
        if (rem->type() == Alarm::Display) {
80
 
            reminder["type"] = "display";
81
 
        } else if (rem->type() == Alarm::Email) {
82
 
            reminder["type"] = "email";
83
 
        }
84
 
 
85
 
        reminder["time"] = rem->startOffset().asSeconds();
86
 
 
87
 
        list << reminder;
88
 
    }
89
 
 
90
 
    QJson::Serializer serializer;
91
 
    return serializer.serialize(list);
92
 
}
93
 
 
94
 
Alarm::List DefaultReminderAttribute::alarms(Incidence *incidence) const
95
 
{
96
 
    Alarm::List alarms;
97
 
 
98
 
    Q_FOREACH (const Reminder::Ptr &reminder, m_reminders) {
99
 
        AlarmPtr alarm(new Alarm(incidence));
100
 
 
101
 
        alarm->setType(reminder->type());
102
 
        alarm->setTime(incidence->dtStart());
103
 
        alarm->setStartOffset(reminder->startOffset());
104
 
        alarm->setEnabled(true);
105
 
 
106
 
        alarms << alarm;
107
 
    }
108
 
 
109
 
    return alarms;
110
 
}
111
 
 
112
 
 
113
 
QByteArray DefaultReminderAttribute::type() const
114
 
{
115
 
    return "defaultReminders";
116
 
}
117