• 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.14
  • 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(const Incidence &other)
82  : Incidence(other)
83  , d(new KCalCore::Event::Private)
84 {
85 }
86 
87 Event::~Event()
88 {
89  delete d;
90 }
91 
92 Event *Event::clone() const
93 {
94  return new Event(*this);
95 }
96 
97 IncidenceBase &Event::assign(const IncidenceBase &other)
98 {
99  if (&other != this) {
100  Incidence::assign(other);
101  const Event *e = static_cast<const Event*>(&other);
102  *d = *(e->d);
103  }
104  return *this;
105 }
106 
107 bool Event::equals(const IncidenceBase &event) const
108 {
109  if (!Incidence::equals(event)) {
110  return false;
111  } else {
112  // If they weren't the same type IncidenceBase::equals would had returned false already
113  const Event *e = static_cast<const Event*>(&event);
114  return
115  ((dtEnd() == e->dtEnd()) ||
116  (!dtEnd().isValid() && !e->dtEnd().isValid())) &&
117  hasEndDate() == e->hasEndDate() &&
118  transparency() == e->transparency();
119  }
120 }
121 
122 Incidence::IncidenceType Event::type() const
123 {
124  return TypeEvent;
125 }
126 
127 QByteArray Event::typeStr() const
128 {
129  return "Event";
130 }
131 
132 void Event::setDtStart(const KDateTime &dt)
133 {
134  d->mMultiDayValid = false;
135  Incidence::setDtStart(dt);
136 }
137 
138 void Event::setDtEnd(const KDateTime &dtEnd)
139 {
140  if (mReadOnly) {
141  return;
142  }
143 
144  update();
145 
146  d->mDtEnd = dtEnd;
147  d->mMultiDayValid = false;
148  d->mHasEndDate = dtEnd.isValid();
149  if (d->mHasEndDate) {
150  setHasDuration(false);
151  }
152  setFieldDirty(FieldDtEnd);
153  updated();
154 }
155 
156 KDateTime Event::dtEnd() const
157 {
158  if (hasEndDate()) {
159  return d->mDtEnd;
160  }
161 
162  if (hasDuration()) {
163  if (allDay()) {
164  // For all day events, dtEnd is always inclusive
165  KDateTime end = duration().end(dtStart()).addDays(-1);
166  return end >= dtStart() ? end : dtStart();
167  } else {
168  return duration().end(dtStart());
169  }
170  }
171 
172  // It is valid for a VEVENT to be without a DTEND. See RFC2445, Sect4.6.1.
173  // Be careful to use Event::dateEnd() as appropriate due to this possibility.
174  return dtStart();
175 }
176 
177 QDate Event::dateEnd() const
178 {
179  KDateTime end = dtEnd().toTimeSpec(dtStart());
180  if (allDay()) {
181  return end.date();
182  } else {
183  return end.addSecs(-1).date();
184  }
185 }
186 
187 void Event::setHasEndDate(bool b)
188 {
189  d->mHasEndDate = b;
190  setFieldDirty(FieldDtEnd);
191 }
192 
193 bool Event::hasEndDate() const
194 {
195  return d->mHasEndDate;
196 }
197 
198 bool Event::isMultiDay(const KDateTime::Spec &spec) const
199 {
200  // First off, if spec's not valid, we can check for cache
201  if (!spec.isValid() && d->mMultiDayValid) {
202  return d->mMultiDay;
203  }
204 
205  // Not in cache -> do it the hard way
206  KDateTime start, end;
207 
208  if (!spec.isValid()) {
209  start = dtStart();
210  end = dtEnd();
211  } else {
212  start = dtStart().toTimeSpec(spec);
213  end = dtEnd().toTimeSpec(spec);
214  }
215 
216  // End date is non inclusive, so subtract 1 second... except if we
217  // got the event from some braindead implementation which gave us
218  // start == end one (those do happen)
219  if (start != end) {
220  end = end.addSecs(-1);
221  }
222 
223  const bool multi = (start.date() != end.date() && start <= end);
224 
225  // Update the cache
226  if (spec.isValid()) {
227  d->mMultiDayValid = true;
228  d->mMultiDay = multi;
229  }
230  return multi;
231 }
232 
233 void Event::shiftTimes(const KDateTime::Spec &oldSpec,
234  const KDateTime::Spec &newSpec)
235 {
236  Incidence::shiftTimes(oldSpec, newSpec);
237  if (hasEndDate()) {
238  d->mDtEnd = d->mDtEnd.toTimeSpec(oldSpec);
239  d->mDtEnd.setTimeSpec(newSpec);
240  }
241 }
242 
243 void Event::setTransparency(Event::Transparency transparency)
244 {
245  if (mReadOnly) {
246  return;
247  }
248  update();
249  d->mTransparency = transparency;
250  setFieldDirty(FieldTransparency);
251  updated();
252 }
253 
254 Event::Transparency Event::transparency() const
255 {
256  return d->mTransparency;
257 }
258 
259 void Event::setDuration(const Duration &duration)
260 {
261  setDtEnd(KDateTime());
262  Incidence::setDuration(duration);
263 }
264 
265 void Event::setAllDay(bool allday)
266 {
267  if (allday != allDay() && !mReadOnly) {
268  setFieldDirty(FieldDtEnd);
269  Incidence::setAllDay(allday);
270  }
271 }
272 
273 bool Event::accept(Visitor &v, IncidenceBase::Ptr incidence)
274 {
275  return v.visit(incidence.staticCast<Event>());
276 }
277 
278 KDateTime Event::dateTime(DateTimeRole role) const
279 {
280  switch (role) {
281  case RoleRecurrenceStart:
282  case RoleAlarmStartOffset:
283  case RoleStartTimeZone:
284  case RoleSort:
285  return dtStart();
286  case RoleCalendarHashing:
287  return !recurs() && !isMultiDay() ? dtStart() :
288  KDateTime();
289  case RoleAlarmEndOffset:
290  case RoleEndTimeZone:
291  case RoleEndRecurrenceBase:
292  case RoleEnd:
293  case RoleDisplayEnd:
294  return dtEnd();
295  case RoleDisplayStart:
296  return dtStart();
297  case RoleAlarm:
298  if (alarms().isEmpty()) {
299  return KDateTime();
300  } else {
301  Alarm::Ptr alarm = alarms().first();
302  return alarm->hasStartOffset() ? dtStart() : dtEnd();
303  }
304  break;
305  default:
306  return KDateTime();
307  }
308 }
309 
310 void Event::setDateTime(const KDateTime &dateTime, DateTimeRole role)
311 {
312  switch (role) {
313  case RoleDnD:
314  {
315  const int duration = dtStart().secsTo(dtEnd());
316 
317  setDtStart(dateTime);
318  setDtEnd(dateTime.addSecs(duration <= 0 ? 3600 : duration));
319  break;
320  }
321  case RoleEnd:
322  setDtEnd(dateTime);
323  break;
324  default:
325  kDebug() << "Unhandled role" << role;
326  }
327 }
328 
329 void Event::virtual_hook(int id, void *data)
330 {
331  switch (static_cast<IncidenceBase::VirtualHook>(id)) {
332  case IncidenceBase::SerializerHook:
333  serialize(*reinterpret_cast<QDataStream*>(data));
334  break;
335  case IncidenceBase::DeserializerHook:
336  deserialize(*reinterpret_cast<QDataStream*>(data));
337  break;
338  default:
339  Q_ASSERT(false);
340  }
341 }
342 
343 QLatin1String KCalCore::Event::mimeType() const
344 {
345  return Event::eventMimeType();
346 }
347 
348 QLatin1String Event::eventMimeType()
349 {
350  return QLatin1String("application/x-vnd.akonadi.calendar.event");
351 }
352 
353 QLatin1String Event::iconName(const KDateTime &) const
354 {
355  return QLatin1String("view-calendar-day");
356 }
357 
358 void Event::serialize(QDataStream &out)
359 {
360  Incidence::serialize(out);
361  out << d->mDtEnd << d->mHasEndDate << static_cast<quint32>(d->mTransparency) << d->mMultiDayValid << d->mMultiDay;
362 }
363 
364 void Event::deserialize(QDataStream &in)
365 {
366  Incidence::deserialize(in);
367  in >> d->mDtEnd >> d->mHasEndDate;
368  quint32 transp;
369  in >> transp;
370  d->mTransparency = static_cast<Transparency>(transp);
371  in >> d->mMultiDayValid >> d->mMultiDay;
372 }
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:233
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:107
QByteArray
KCalCore::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:55
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
QDataStream
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:198
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:122
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:265
KCalCore::IncidenceBase::RoleEnd
Role for determining an incidence's dtEnd, will return an invalid KDateTime if the incidence does not...
Definition: incidencebase.h:141
QVector::first
T & first()
KCalCore::Event::assign
virtual IncidenceBase & assign(const IncidenceBase &other)
Definition: event.cpp:97
KCalCore::Event::dateTime
KDateTime dateTime(DateTimeRole role) const
Definition: event.cpp:278
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:132
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
QSharedPointer
KCalCore::Event::dtEnd
virtual KDateTime dtEnd() const
Returns the event end date and time.
Definition: event.cpp:156
KCalCore::Event::Transparency
Transparency
The different Event transparency types.
Definition: event.h:47
KCalCore::Event::Event
Event()
Constructs an event.
Definition: event.cpp:71
QDate
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:92
KCalCore::Event::setTransparency
void setTransparency(Transparency transparency)
Sets the event's time transparency level.
Definition: event.cpp:243
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:177
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:187
KCalCore::Event::iconName
QLatin1String iconName(const KDateTime &recurrenceId=KDateTime()) const
Definition: event.cpp:353
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:348
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:87
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:193
QLatin1String
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:254
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:127
KCalCore::IncidenceBase::mReadOnly
bool mReadOnly
Identifies a read-only incidence.
Definition: incidencebase.h:746
KCalCore::Event::mimeType
QLatin1String mimeType() const
Definition: event.cpp:343
QSharedPointer::staticCast
QSharedPointer< X > staticCast() const
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:329
KCalCore::Event::setDateTime
void setDateTime(const KDateTime &dateTime, DateTimeRole role)
Definition: event.cpp:310
KCalCore::Event::setDtEnd
void setDtEnd(const KDateTime &dtEnd)
Sets the event end date and time.
Definition: event.cpp:138
KCalCore::Event::setDuration
void setDuration(const Duration &duration)
Sets the duration of this event.
Definition: event.cpp:259
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:36:53 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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