2
Copyright (c) 2010 Frederik Gladhorn <gladhorn@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "eventdatacontainer.h"
22
#include <KSystemTimeZones>
24
#include <KCalCore/Calendar>
25
#include <KCalCore/Event>
26
#include <KCalCore/Todo>
27
#include <KCalCore/Journal>
28
#include <KCalUtils/Stringify>
30
#include "akonadi/calendar.h"
31
#include "akonadi/calendarmodel.h"
33
using namespace Akonadi;
34
using namespace CalendarSupport;
36
EventDataContainer::EventDataContainer(CalendarSupport::Calendar* calendar, const QString& name, const KDateTime& start, const KDateTime& end, QObject* parent)
37
: Plasma::DataContainer(parent),
43
// name under which this dataEngine source appears
46
// Connect directly to the calendar for now
47
connect(calendar, SIGNAL(calendarChanged()), this, SLOT(updateData()));
49
// create the initial data
53
void EventDataContainer::updateData()
62
void EventDataContainer::updateEventData()
64
Akonadi::Item::List events = m_calendar->events(m_startDate.date(), m_endDate.date(), m_calendar->timeSpec());
66
foreach (const Akonadi::Item &item, events) {
67
Q_ASSERT(item.hasPayload<KCalCore::Event::Ptr>());
68
const KCalCore::Event::Ptr event = item.payload<KCalCore::Event::Ptr>();
70
Plasma::DataEngine::Data eventData;
72
populateIncidenceData(event, eventData);
74
// Event specific fields
75
eventData["EventMultiDay"] = event->allDay();
76
eventData["EventHasEndDate"] = event->hasEndDate();
77
if (event->transparency() == KCalCore::Event::Opaque) {
78
eventData["EventTransparency"] = "Opaque";
79
} else if (event->transparency() == KCalCore::Event::Transparent) {
80
eventData["EventTransparency"] = "Transparent";
82
eventData["EventTransparency"] = "Unknown";
85
setData(event->uid(), eventData);
89
void EventDataContainer::updateTodoData()
91
QDate todoDate = m_startDate.date();
92
while(todoDate <= m_endDate.date()) {
93
Akonadi::Item::List todos = m_calendar->todos(todoDate);
95
foreach (const Akonadi::Item &item, todos) {
96
Q_ASSERT(item.hasPayload<KCalCore::Todo::Ptr>());
97
const KCalCore::Todo::Ptr todo = item.payload<KCalCore::Todo::Ptr>();
99
Plasma::DataEngine::Data todoData;
101
populateIncidenceData(todo, todoData);
104
// Todo specific fields
105
todoData["TodoHasStartDate"] = todo->hasStartDate();
106
todoData["TodoIsOpenEnded"] = todo->isOpenEnded();
107
todoData["TodoHasDueDate"] = todo->hasDueDate();
108
var.setValue(todo->dtDue());
109
todoData["TodoDueDate"] = var;
110
todoData["TodoIsCompleted"] = todo->isCompleted();
111
todoData["TodoIsInProgress"] = todo->isInProgress(false); // ???
112
todoData["TodoIsNotStarted"] = todo->isNotStarted(false); // ???
113
todoData["TodoPercentComplete"] = todo->percentComplete();
114
todoData["TodoHasCompletedDate"] = todo->hasCompletedDate();
115
var.setValue(todo->completed());
116
todoData["TodoCompletedDate"] = var;
118
setData(todo->uid(), todoData);
121
todoDate = todoDate.addDays(1);
125
void EventDataContainer::updateJournalData()
127
QDate journalDate = m_startDate.date();
128
while(journalDate <= m_endDate.date()) {
129
Akonadi::Item::List journals = m_calendar->journals(journalDate);
131
foreach (const Akonadi::Item &item, journals) {
132
Q_ASSERT(item.hasPayload<KCalCore::Journal::Ptr>());
133
const KCalCore::Journal::Ptr journal = item.payload<KCalCore::Journal::Ptr>();
135
Plasma::DataEngine::Data journalData;
137
populateIncidenceData(journal, journalData);
139
// No Journal specific fields
141
setData(journal->uid(), journalData);
144
journalDate = journalDate.addDays(1);
148
void EventDataContainer::populateIncidenceData(KCalCore::Incidence::Ptr incidence, Plasma::DataEngine::Data &incidenceData)
151
incidenceData["UID"] = incidence->uid();
152
incidenceData["Type"] = incidence->typeStr();
153
incidenceData["Summary"] = incidence->summary();
154
incidenceData["Description"] = incidence->description();
155
incidenceData["Comments"] = incidence->comments();
156
incidenceData["Location"] = incidence->location();
157
incidenceData["OrganizerName"] = incidence->organizer()->name();
158
incidenceData["OrganizerEmail"] = incidence->organizer()->email();
159
incidenceData["Priority"] = incidence->priority();
160
var.setValue(incidence->dtStart());
161
incidenceData["StartDate"] = var;
163
KCalCore::Event* event = dynamic_cast<KCalCore::Event*>(incidence.data());
165
var.setValue(event->dtEnd());
166
incidenceData["EndDate"] = var;
168
// Build the Occurance Index, this lists all occurences of the Incidence in the required range
169
// Single occurance events just repeat the standard start/end dates
170
// Recurring Events use each recurrence start/end date
171
// The OccurenceUid is redundant, but it makes it easy for clients to just take() the data structure intact as a separate index
172
QList<QVariant> occurences;
173
// Build the recurrence list of start dates only for recurring incidences only
174
QList<QVariant> recurrences;
175
if (incidence->recurs()) {
176
KCalCore::DateTimeList recurList = incidence->recurrence()->timesInInterval(m_startDate, m_endDate);
177
foreach(const KDateTime &recurDateTime, recurList) {
178
var.setValue(recurDateTime);
179
recurrences.append(var);
180
Plasma::DataEngine::Data occurence;
181
occurence.insert("OccurrenceUid", incidence->uid());
182
occurence.insert("OccurrenceStartDate", var);
183
var.setValue(incidence->endDateForStart(recurDateTime));
184
occurence.insert("OccurrenceEndDate", var);
185
occurences.append(QVariant(occurence));
188
Plasma::DataEngine::Data occurence;
189
occurence.insert("OccurrenceUid", incidence->uid());
190
var.setValue(incidence->dtStart());
191
occurence.insert("OccurrenceStartDate", var);
193
var.setValue(event->dtEnd());
194
occurence.insert("OccurrenceEndDate", var);
196
occurences.append(QVariant(occurence));
198
incidenceData["RecurrenceDates"] = QVariant(recurrences);
199
incidenceData["Occurrences"] = QVariant(occurences);
200
if (incidence->status() == KCalCore::Incidence::StatusNone) {
201
incidenceData["Status"] = "None";
202
} else if (incidence->status() == KCalCore::Incidence::StatusTentative) {
203
incidenceData["Status"] = "Tentative";
204
} else if (incidence->status() == KCalCore::Incidence::StatusConfirmed) {
205
incidenceData["Status"] = "Confirmed";
206
} else if (incidence->status() == KCalCore::Incidence::StatusDraft) {
207
incidenceData["Status"] = "Draft";
208
} else if (incidence->status() == KCalCore::Incidence::StatusFinal) {
209
incidenceData["Status"] = "Final";
210
} else if (incidence->status() == KCalCore::Incidence::StatusCompleted) {
211
incidenceData["Status"] = "Completed";
212
} else if (incidence->status() == KCalCore::Incidence::StatusInProcess) {
213
incidenceData["Status"] = "InProcess";
214
} else if (incidence->status() == KCalCore::Incidence::StatusCanceled) {
215
incidenceData["Status"] = "Cancelled";
216
} else if (incidence->status() == KCalCore::Incidence::StatusNeedsAction) {
217
incidenceData["Status"] = "NeedsAction";
218
} else if (incidence->status() == KCalCore::Incidence::StatusX) {
219
incidenceData["Status"] = "NonStandard";
221
incidenceData["Status"] = "Unknown";
223
incidenceData["StatusName"] = KCalUtils::Stringify::incidenceStatus( incidence->status() );
225
if (incidence->secrecy() == KCalCore::Incidence::SecrecyPublic) {
226
incidenceData["Secrecy"] = "Public";
227
} else if (incidence->secrecy() == KCalCore::Incidence::SecrecyPrivate) {
228
incidenceData["Secrecy"] = "Private";
229
} else if (incidence->secrecy() == KCalCore::Incidence::SecrecyConfidential) {
230
incidenceData["Secrecy"] = "Confidential";
232
incidenceData["Secrecy"] = "Unknown";
234
incidenceData["SecrecyName"] = KCalUtils::Stringify::secrecyName( incidence->secrecy() );
235
incidenceData["Recurs"] = incidence->recurs();
236
incidenceData["AllDay"] = incidence->allDay();
237
incidenceData["Categories"] = incidence->categories();
238
incidenceData["Resources"] = incidence->resources();
239
incidenceData["DurationDays"] = incidence->duration().asDays();
240
incidenceData["DurationSeconds"] = incidence->duration().asSeconds();
246
//TODO Custom Properties
248
//TODO Collection/Source
251
#include "eventdatacontainer.moc"