• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KCalCore Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kcalcore
event.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcalcore library.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
32 #include "event.h"
33 #include "visitor.h"
34 
35 #include <KDebug>
36 
37 #include <QDate>
38 
39 using namespace KCalCore;
40 
45 //@cond PRIVATE
46 class KCalCore::Event::Private
47 {
48 public:
49  Private()
50  : mHasEndDate(false),
51  mTransparency(Opaque),
52  mMultiDayValid(false),
53  mMultiDay(false)
54  {}
55  Private(const KCalCore::Event::Private &other)
56  : mDtEnd(other.mDtEnd),
57  mHasEndDate(other.mHasEndDate),
58  mTransparency(other.mTransparency),
59  mMultiDayValid(false),
60  mMultiDay(false)
61  {}
62 
63  KDateTime mDtEnd;
64  bool mHasEndDate;
65  Transparency mTransparency;
66  bool mMultiDayValid;
67  bool mMultiDay;
68 };
69 //@endcond
70 
71 Event::Event()
72  : d(new KCalCore::Event::Private)
73 {
74 }
75 
76 Event::Event(const Event &other)
77  : Incidence(other), d(new KCalCore::Event::Private(*other.d))
78 {
79 }
80 
81 Event::~Event()
82 {
83  delete d;
84 }
85 
86 Event *Event::clone() const
87 {
88  return new Event(*this);
89 }
90 
91 IncidenceBase &Event::assign(const IncidenceBase &other)
92 {
93  if (&other != this) {
94  Incidence::assign(other);
95  const Event *e = static_cast<const Event*>(&other);
96  *d = *(e->d);
97  }
98  return *this;
99 }
100 
101 bool Event::equals(const IncidenceBase &event) const
102 {
103  if (!Incidence::equals(event)) {
104  return false;
105  } else {
106  // If they weren't the same type IncidenceBase::equals would had returned false already
107  const Event *e = static_cast<const Event*>(&event);
108  return
109  ((dtEnd() == e->dtEnd()) ||
110  (!dtEnd().isValid() && !e->dtEnd().isValid())) &&
111  hasEndDate() == e->hasEndDate() &&
112  transparency() == e->transparency();
113  }
114 }
115 
116 Incidence::IncidenceType Event::type() const
117 {
118  return TypeEvent;
119 }
120 
121 QByteArray Event::typeStr() const
122 {
123  return "Event";
124 }
125 
126 void Event::setDtStart(const KDateTime &dt)
127 {
128  d->mMultiDayValid = false;
129  Incidence::setDtStart(dt);
130 }
131 
132 void Event::setDtEnd(const KDateTime &dtEnd)
133 {
134  if (mReadOnly) {
135  return;
136  }
137 
138  update();
139 
140  d->mDtEnd = dtEnd;
141  d->mMultiDayValid = false;
142  d->mHasEndDate = dtEnd.isValid();
143  if (d->mHasEndDate) {
144  setHasDuration(false);
145  }
146  setFieldDirty(FieldDtEnd);
147  updated();
148 }
149 
150 KDateTime Event::dtEnd() const
151 {
152  if (hasEndDate()) {
153  return d->mDtEnd;
154  }
155 
156  if (hasDuration()) {
157  if (allDay()) {
158  // For all day events, dtEnd is always inclusive
159  KDateTime end = duration().end(dtStart()).addDays(-1);
160  return end >= dtStart() ? end : dtStart();
161  } else {
162  return duration().end(dtStart());
163  }
164  }
165 
166  // It is valid for a VEVENT to be without a DTEND. See RFC2445, Sect4.6.1.
167  // Be careful to use Event::dateEnd() as appropriate due to this possibility.
168  return dtStart();
169 }
170 
171 QDate Event::dateEnd() const
172 {
173  KDateTime end = dtEnd().toTimeSpec(dtStart());
174  if (allDay()) {
175  return end.date();
176  } else {
177  return end.addSecs(-1).date();
178  }
179 }
180 
181 void Event::setHasEndDate(bool b)
182 {
183  d->mHasEndDate = b;
184  setFieldDirty(FieldDtEnd);
185 }
186 
187 bool Event::hasEndDate() const
188 {
189  return d->mHasEndDate;
190 }
191 
192 bool Event::isMultiDay(const KDateTime::Spec &spec) const
193 {
194  // First off, if spec's not valid, we can check for cache
195  if (!spec.isValid() && d->mMultiDayValid) {
196  return d->mMultiDay;
197  }
198 
199  // Not in cache -> do it the hard way
200  KDateTime start, end;
201 
202  if (!spec.isValid()) {
203  start = dtStart();
204  end = dtEnd();
205  } else {
206  start = dtStart().toTimeSpec(spec);
207  end = dtEnd().toTimeSpec(spec);
208  }
209 
210  // End date is non inclusive, so subtract 1 second... except if we
211  // got the event from some braindead implementation which gave us
212  // start == end one (those do happen)
213  if (start != end) {
214  end = end.addSecs(-1);
215  }
216 
217  const bool multi = (start.date() != end.date() && start <= end);
218 
219  // Update the cache
220  if (spec.isValid()) {
221  d->mMultiDayValid = true;
222  d->mMultiDay = multi;
223  }
224  return multi;
225 }
226 
227 void Event::shiftTimes(const KDateTime::Spec &oldSpec,
228  const KDateTime::Spec &newSpec)
229 {
230  Incidence::shiftTimes(oldSpec, newSpec);
231  if (hasEndDate()) {
232  d->mDtEnd = d->mDtEnd.toTimeSpec(oldSpec);
233  d->mDtEnd.setTimeSpec(newSpec);
234  }
235 }
236 
237 void Event::setTransparency(Event::Transparency transparency)
238 {
239  if (mReadOnly) {
240  return;
241  }
242  update();
243  d->mTransparency = transparency;
244  setFieldDirty(FieldTransparency);
245  updated();
246 }
247 
248 Event::Transparency Event::transparency() const
249 {
250  return d->mTransparency;
251 }
252 
253 void Event::setDuration(const Duration &duration)
254 {
255  setDtEnd(KDateTime());
256  Incidence::setDuration(duration);
257 }
258 
259 void Event::setAllDay(bool allday)
260 {
261  if (allday != allDay() && !mReadOnly) {
262  setFieldDirty(FieldDtEnd);
263  Incidence::setAllDay(allday);
264  }
265 }
266 
267 bool Event::accept(Visitor &v, IncidenceBase::Ptr incidence)
268 {
269  return v.visit(incidence.staticCast<Event>());
270 }
271 
272 KDateTime Event::dateTime(DateTimeRole role) const
273 {
274  switch (role) {
275  case RoleRecurrenceStart:
276  case RoleAlarmStartOffset:
277  case RoleStartTimeZone:
278  case RoleSort:
279  return dtStart();
280  case RoleCalendarHashing:
281  return !recurs() && !isMultiDay() ? dtStart() :
282  KDateTime();
283  case RoleAlarmEndOffset:
284  case RoleEndTimeZone:
285  case RoleEndRecurrenceBase:
286  case RoleEnd:
287  case RoleDisplayEnd:
288  return dtEnd();
289  case RoleDisplayStart:
290  return dtStart();
291  case RoleAlarm:
292  if (alarms().isEmpty()) {
293  return KDateTime();
294  } else {
295  Alarm::Ptr alarm = alarms().first();
296  return alarm->hasStartOffset() ? dtStart() : dtEnd();
297  }
298  break;
299  default:
300  return KDateTime();
301  }
302 }
303 
304 void Event::setDateTime(const KDateTime &dateTime, DateTimeRole role)
305 {
306  switch (role) {
307  case RoleDnD:
308  {
309  const int duration = dtStart().secsTo(dtEnd());
310 
311  setDtStart(dateTime);
312  setDtEnd(dateTime.addSecs(duration <= 0 ? 3600 : duration));
313  break;
314  }
315  case RoleEnd:
316  setDtEnd(dateTime);
317  break;
318  default:
319  kDebug() << "Unhandled role" << role;
320  }
321 }
322 
323 void Event::virtual_hook(int id, void *data)
324 {
325  switch (static_cast<IncidenceBase::VirtualHook>(id)) {
326  case IncidenceBase::SerializerHook:
327  serialize(*reinterpret_cast<QDataStream*>(data));
328  break;
329  case IncidenceBase::DeserializerHook:
330  deserialize(*reinterpret_cast<QDataStream*>(data));
331  break;
332  default:
333  Q_ASSERT(false);
334  }
335 }
336 
337 QLatin1String KCalCore::Event::mimeType() const
338 {
339  return Event::eventMimeType();
340 }
341 
342 QLatin1String Event::eventMimeType()
343 {
344  return QLatin1String("application/x-vnd.akonadi.calendar.event");
345 }
346 
347 QLatin1String Event::iconName(const KDateTime &) const
348 {
349  return QLatin1String("view-calendar-day");
350 }
351 
352 void Event::serialize(QDataStream &out)
353 {
354  Incidence::serialize(out);
355  out << d->mDtEnd << d->mHasEndDate << static_cast<quint32>(d->mTransparency) << d->mMultiDayValid << d->mMultiDay;
356 }
357 
358 void Event::deserialize(QDataStream &in)
359 {
360  Incidence::deserialize(in);
361  in >> d->mDtEnd >> d->mHasEndDate;
362  quint32 transp;
363  in >> transp;
364  d->mTransparency = static_cast<Transparency>(transp);
365  in >> d->mMultiDayValid >> d->mMultiDay;
366 }
KCalCore::Incidence::equals
virtual bool equals(const IncidenceBase &incidence) const
Compares this with Incidence incidence for equality.
Definition: incidence.cpp:231
KCalCore::Event::shiftTimes
virtual void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Definition: event.cpp:227
KCalCore::IncidenceBase::duration
Duration duration() const
Returns the length of the incidence duration.
Definition: incidencebase.cpp:555
KCalCore::IncidenceBase::RoleCalendarHashing
Role for looking up an incidence in a Calendar.
Definition: incidencebase.h:137
KCalCore::Event::equals
virtual bool equals(const IncidenceBase &event) const
Compares two events for equality.
Definition: event.cpp:101
KCalCore::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:55
KCalCore::Alarm::Ptr
QSharedPointer< Alarm > Ptr
A shared pointer to an Alarm object.
Definition: alarm.h:78
KCalCore::IncidenceBase::RoleAlarm
Role for determining the date/time of the first alarm.
Definition: incidencebase.h:145
KCalCore::IncidenceBase::FieldDtEnd
Field representing the DTSTART component.
Definition: incidencebase.h:162
KCalCore::Incidence::setAllDay
void setAllDay(bool allDay)
Definition: incidence.cpp:346
KCalCore::Visitor::visit
virtual bool visit(Event::Ptr event)
Reimplement this function in your concrete subclass of IncidenceBase::Visitor to perform actions on a...
Definition: visitor.cpp:42
KCalCore::Event::isMultiDay
bool isMultiDay(const KDateTime::Spec &spec=KDateTime::Spec()) const
Returns true if the event spans multiple days, otherwise return false.
Definition: event.cpp:192
KCalCore::IncidenceBase
An abstract class that provides a common base for all calendar incidence classes. ...
Definition: incidencebase.h:109
KCalCore::IncidenceBase::RoleEndTimeZone
Role for determining an incidence's ending timezone.
Definition: incidencebase.h:139
KCalCore::Visitor
This class provides the interface for a visitor of calendar components.
Definition: visitor.h:43
KCalCore::Event::type
IncidenceType type() const
Definition: event.cpp:116
KCalCore::IncidenceBase::update
void update()
Call this to notify the observers after the IncidenceBase object will be changed. ...
Definition: incidencebase.cpp:593
KCalCore::Event::setAllDay
void setAllDay(bool allDay)
Definition: event.cpp:259
KCalCore::IncidenceBase::RoleEnd
Role for determining an incidence's dtEnd, will return an invalid KDateTime if the incidence does not...
Definition: incidencebase.h:141
KCalCore::Event::assign
virtual IncidenceBase & assign(const IncidenceBase &other)
Definition: event.cpp:91
KCalCore::Event::dateTime
KDateTime dateTime(DateTimeRole role) const
Definition: event.cpp:272
KCalCore::IncidenceBase::IncidenceType
IncidenceType
The different types of incidences, per RFC2445.
Definition: incidencebase.h:121
KCalCore::IncidenceBase::hasDuration
bool hasDuration() const
Returns true if the incidence has a duration; false otherwise.
Definition: incidencebase.cpp:565
KCalCore::IncidenceBase::setHasDuration
void setHasDuration(bool hasDuration)
Sets if the incidence has a duration.
Definition: incidencebase.cpp:560
KCalCore::IncidenceBase::RoleDnD
Role for determining new start and end dates after a DnD.
Definition: incidencebase.h:154
KCalCore::Duration::end
KDateTime end(const KDateTime &start) const
Computes a duration end time by adding the number of seconds or days in the duration to the specified...
Definition: duration.cpp:184
KCalCore::IncidenceBase::RoleDisplayEnd
Role used for display purposes, represents the end boundary if an incidence supports dtEnd...
Definition: incidencebase.h:143
KCalCore::IncidenceBase::setDuration
virtual void setDuration(const Duration &duration)
Sets the incidence duration.
Definition: incidencebase.cpp:546
KCalCore::Event::setDtStart
virtual void setDtStart(const KDateTime &dt)
Sets the incidence starting date/time.
Definition: event.cpp:126
KCalCore::Event::Opaque
Event appears in free/busy time.
Definition: event.h:48
KCalCore::Incidence::alarms
Alarm::List alarms() const
Returns a list of all incidence alarms.
Definition: incidence.cpp:876
KCalCore::IncidenceBase::updated
void updated()
Call this to notify the observers after the IncidenceBase object has changed.
Definition: incidencebase.cpp:604
KCalCore::Event::dtEnd
virtual KDateTime dtEnd() const
Returns the event end date and time.
Definition: event.cpp:150
KCalCore::IncidenceBase::Ptr
QSharedPointer< IncidenceBase > Ptr
A shared pointer to an IncidenceBase.
Definition: incidencebase.h:115
KCalCore::Event::Transparency
Transparency
The different Event transparency types.
Definition: event.h:47
KCalCore::Event::Event
Event()
Constructs an event.
Definition: event.cpp:71
KCalCore::Incidence::setDtStart
virtual void setDtStart(const KDateTime &dt)
Sets the incidence starting date/time.
Definition: incidence.cpp:393
KCalCore::IncidenceBase::allDay
bool allDay() const
Returns true or false depending on whether the incidence is all-day.
Definition: incidencebase.cpp:326
KCalCore::Event::clone
Event * clone() const
Returns an exact copy of this Event.
Definition: event.cpp:86
KCalCore::Event::setTransparency
void setTransparency(Transparency transparency)
Sets the event's time transparency level.
Definition: event.cpp:237
KCalCore::IncidenceBase::setFieldDirty
void setFieldDirty(IncidenceBase::Field field)
Marks Field field as dirty.
Definition: incidencebase.cpp:657
KCalCore::IncidenceBase::RoleSort
Role for an incidence's date/time used when sorting.
Definition: incidencebase.h:136
KCalCore::Event::dateEnd
QDate dateEnd() const
Returns the date when the event ends.
Definition: event.cpp:171
KCalCore::Incidence::shiftTimes
virtual void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Shift the times of the incidence so that they appear at the same clock time as before but in a new ti...
Definition: incidence.cpp:401
KCalCore::Event::setHasEndDate
KCALCORE_DEPRECATED void setHasEndDate(bool b)
Sets whether the event has an end date/time.
Definition: event.cpp:181
KCalCore::Event::iconName
QLatin1String iconName(const KDateTime &recurrenceId=KDateTime()) const
Definition: event.cpp:347
KCalCore::IncidenceBase::DateTimeRole
DateTimeRole
The different types of incidence date/times roles.
Definition: incidencebase.h:133
KCalCore::IncidenceBase::RoleAlarmEndOffset
Role for an incidence alarm's ending offset date/time.
Definition: incidencebase.h:135
KCalCore::Event::eventMimeType
static QLatin1String eventMimeType()
Returns the Akonadi specific sub MIME type of a KCalCore::Event.
Definition: event.cpp:342
KCalCore::Incidence::assign
virtual IncidenceBase & assign(const IncidenceBase &other)
Provides polymorfic assignment.
Definition: incidence.cpp:218
KCalCore::Event::~Event
~Event()
Destroys the event.
Definition: event.cpp:81
KCalCore::IncidenceBase::RoleStartTimeZone
Role for determining an incidence's starting timezone.
Definition: incidencebase.h:138
KCalCore::Event::hasEndDate
bool hasEndDate() const
Returns whether the event has an end date/time.
Definition: event.cpp:187
event.h
This file is part of the API for handling calendar data and defines the Event class.
KCalCore::Event::transparency
Transparency transparency() const
Returns the event's time transparency level.
Definition: event.cpp:248
KCalCore::IncidenceBase::TypeEvent
Type is an event.
Definition: incidencebase.h:122
KCalCore::Event
This class provides an Event in the sense of RFC2445.
Definition: event.h:41
KCalCore::Incidence::recurs
bool recurs() const
Returns whether the event recurs at all.
Definition: incidence.cpp:579
KCalCore::Event::typeStr
QByteArray typeStr() const
Definition: event.cpp:121
KCalCore::IncidenceBase::mReadOnly
bool mReadOnly
Identifies a read-only incidence.
Definition: incidencebase.h:746
KCalCore::Event::mimeType
QLatin1String mimeType() const
Definition: event.cpp:337
KCalCore::IncidenceBase::RoleAlarmStartOffset
Role for an incidence alarm's starting offset date/time.
Definition: incidencebase.h:134
KCalCore::IncidenceBase::FieldTransparency
Field representing the STATUS component.
Definition: incidencebase.h:176
KCalCore::Event::virtual_hook
virtual void virtual_hook(int id, void *data)
Definition: event.cpp:323
KCalCore::Event::setDateTime
void setDateTime(const KDateTime &dateTime, DateTimeRole role)
Definition: event.cpp:304
KCalCore::Event::setDtEnd
void setDtEnd(const KDateTime &dtEnd)
Sets the event end date and time.
Definition: event.cpp:132
KCalCore::Event::setDuration
void setDuration(const Duration &duration)
Sets the duration of this event.
Definition: event.cpp:253
KCalCore::Incidence
Provides the abstract base class common to non-FreeBusy (Events, To-dos, Journals) calendar component...
Definition: incidence.h:68
KCalCore::IncidenceBase::dtStart
virtual KDateTime dtStart() const
Returns an incidence's starting date/time as a KDateTime.
Definition: incidencebase.cpp:321
KCalCore::IncidenceBase::RoleRecurrenceStart
Role for determining the start of the recurrence.
Definition: incidencebase.h:147
KCalCore::IncidenceBase::RoleDisplayStart
Role for display purposes, represents the start boundary of an incidence.
Definition: incidencebase.h:152
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalCore Library

Skip menu "KCalCore Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal