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

KCalCore Library

  • 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 using namespace KCalCore;
38 
43 //@cond PRIVATE
44 class KCalCore::Event::Private
45 {
46  public:
47  Private()
48  : mHasEndDate( false ),
49  mTransparency( Opaque ),
50  mMultiDayValid( false ),
51  mMultiDay( false )
52  {}
53  Private( const KCalCore::Event::Private &other )
54  : mDtEnd( other.mDtEnd ),
55  mHasEndDate( other.mHasEndDate ),
56  mTransparency( other.mTransparency ),
57  mMultiDayValid( false ),
58  mMultiDay( false )
59  {}
60 
61  KDateTime mDtEnd;
62  bool mHasEndDate;
63  Transparency mTransparency;
64  bool mMultiDayValid;
65  bool mMultiDay;
66 };
67 //@endcond
68 
69 Event::Event()
70  : d( new KCalCore::Event::Private )
71 {
72 }
73 
74 Event::Event( const Event &other )
75  : Incidence( other ), d( new KCalCore::Event::Private( *other.d ) )
76 {
77 }
78 
79 Event::~Event()
80 {
81  delete d;
82 }
83 
84 Event *Event::clone() const
85 {
86  return new Event( *this );
87 }
88 
89 IncidenceBase &Event::assign( const IncidenceBase &other )
90 {
91  if ( &other != this ) {
92  Incidence::assign( other );
93  const Event *e = static_cast<const Event*>( &other );
94  *d = *( e->d );
95  }
96  return *this;
97 }
98 
99 bool Event::equals( const IncidenceBase &event ) const
100 {
101  if ( !Incidence::equals( event ) ) {
102  return false;
103  } else {
104  // If they weren't the same type IncidenceBase::equals would had returned false already
105  const Event *e = static_cast<const Event*>( &event );
106  return
107  ( ( dtEnd() == e->dtEnd() ) ||
108  ( !dtEnd().isValid() && !e->dtEnd().isValid() ) ) &&
109  hasEndDate() == e->hasEndDate() &&
110  transparency() == e->transparency();
111  }
112 }
113 
114 Incidence::IncidenceType Event::type() const
115 {
116  return TypeEvent;
117 }
118 
119 QByteArray Event::typeStr() const
120 {
121  return "Event";
122 }
123 
124 void Event::setDtStart( const KDateTime &dt )
125 {
126  d->mMultiDayValid = false;
127  Incidence::setDtStart( dt );
128 }
129 
130 void Event::setDtEnd( const KDateTime &dtEnd )
131 {
132  if ( mReadOnly ) {
133  return;
134  }
135 
136  update();
137 
138  d->mDtEnd = dtEnd;
139  d->mMultiDayValid = false;
140  setHasEndDate( true );
141  setHasDuration( false );
142  setFieldDirty( FieldDtEnd );
143  updated();
144 }
145 
146 KDateTime Event::dtEnd() const
147 {
148  if ( hasEndDate() ) {
149  return d->mDtEnd;
150  }
151 
152  if ( hasDuration() ) {
153  if ( allDay() ) {
154  // For all day events, dtEnd is always inclusive
155  KDateTime end = duration().end( dtStart() ).addDays( -1 );
156  return end >= dtStart() ? end : dtStart();
157  } else {
158  return duration().end( dtStart() );
159  }
160  }
161 
162  // It is valid for a VEVENT to be without a DTEND. See RFC2445, Sect4.6.1.
163  // Be careful to use Event::dateEnd() as appropriate due to this possibility.
164  return dtStart();
165 }
166 
167 QDate Event::dateEnd() const
168 {
169  KDateTime end = dtEnd().toTimeSpec( dtStart() );
170  if ( allDay() ) {
171  return end.date();
172  } else {
173  return end.addSecs( -1 ).date();
174  }
175 }
176 
177 void Event::setHasEndDate( bool b )
178 {
179  d->mHasEndDate = b;
180  setFieldDirty( FieldDtEnd );
181 }
182 
183 bool Event::hasEndDate() const
184 {
185  return d->mHasEndDate;
186 }
187 
188 bool Event::isMultiDay( const KDateTime::Spec &spec ) const
189 {
190  // First off, if spec's not valid, we can check for cache
191  if ( ( !spec.isValid() ) && d->mMultiDayValid ) {
192  return d->mMultiDay;
193  }
194 
195  // Not in cache -> do it the hard way
196  KDateTime start, end;
197 
198  if ( !spec.isValid() ) {
199  start = dtStart();
200  end = dtEnd();
201  } else {
202  start = dtStart().toTimeSpec( spec );
203  end = dtEnd().toTimeSpec( spec );
204  }
205 
206  // End date is non inclusive, so subtract 1 second... except if we
207  // got the event from some braindead implementation which gave us
208  // start == end one (those do happen)
209  if ( start != end ) {
210  end = end.addSecs( -1 );
211  }
212 
213  const bool multi = ( start.date() != end.date() && start <= end );
214 
215  // Update the cache
216  if ( spec.isValid() ) {
217  d->mMultiDayValid = true;
218  d->mMultiDay = multi;
219  }
220  return multi;
221 }
222 
223 void Event::shiftTimes( const KDateTime::Spec &oldSpec,
224  const KDateTime::Spec &newSpec )
225 {
226  Incidence::shiftTimes( oldSpec, newSpec );
227  if ( hasEndDate() ) {
228  d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
229  d->mDtEnd.setTimeSpec( newSpec );
230  }
231 }
232 
233 void Event::setTransparency( Event::Transparency transparency )
234 {
235  if ( mReadOnly ) {
236  return;
237  }
238  update();
239  d->mTransparency = transparency;
240  setFieldDirty( FieldTransparency );
241  updated();
242 }
243 
244 Event::Transparency Event::transparency() const
245 {
246  return d->mTransparency;
247 }
248 
249 void Event::setDuration( const Duration &duration )
250 {
251  setHasEndDate( false );
252  Incidence::setDuration( duration );
253 }
254 
255 void Event::setAllDay( bool allday )
256 {
257  if ( allday != allDay() && !mReadOnly ) {
258  setFieldDirty( FieldDtEnd );
259  Incidence::setAllDay( allday );
260  }
261 }
262 
263 bool Event::accept( Visitor &v, IncidenceBase::Ptr incidence )
264 {
265  return v.visit( incidence.staticCast<Event>() );
266 }
267 
268 KDateTime Event::dateTime( DateTimeRole role ) const
269 {
270  switch ( role ) {
271  case RoleRecurrenceStart:
272  case RoleAlarmStartOffset:
273  case RoleStartTimeZone:
274  case RoleSort:
275  return dtStart();
276  case RoleCalendarHashing:
277  return !recurs() && !isMultiDay() ? dtStart() :
278  KDateTime();
279  case RoleAlarmEndOffset:
280  case RoleEndTimeZone:
281  case RoleEndRecurrenceBase:
282  case RoleEnd:
283  case RoleDisplayEnd:
284  return dtEnd();
285  case RoleDisplayStart:
286  return dtStart();
287  case RoleAlarm:
288  if ( alarms().isEmpty() ) {
289  return KDateTime();
290  } else {
291  Alarm::Ptr alarm = alarms().first();
292  return alarm->hasStartOffset() ? dtStart() : dtEnd();
293  }
294  break;
295  default:
296  return KDateTime();
297  }
298 }
299 
300 void Event::setDateTime( const KDateTime &dateTime, DateTimeRole role )
301 {
302  switch ( role ) {
303  case RoleDnD:
304  {
305  const int duration = dtStart().secsTo( dtEnd() );
306  setDtStart( dateTime );
307  setDtEnd( dateTime.addSecs( duration ) );
308  break;
309  }
310  default:
311  kDebug() << "Unhandled role" << role;
312  }
313 }
314 
315 void Event::virtual_hook( int id, void *data )
316 {
317  Q_UNUSED( id );
318  Q_UNUSED( data );
319  Q_ASSERT( false );
320 }
321 
322 QLatin1String KCalCore::Event::mimeType() const
323 {
324  return Event::eventMimeType();
325 }
326 
327 QLatin1String Event::eventMimeType()
328 {
329  return QLatin1String( "application/x-vnd.akonadi.calendar.event" );
330 }
331 
332 QLatin1String Event::iconName( const KDateTime & ) const
333 {
334  return QLatin1String( "view-calendar-day" );
335 }
KCalCore::Incidence::equals
virtual bool equals(const IncidenceBase &incidence) const
Compares this with Incidence incidence for equality.
Definition: incidence.cpp:224
KCalCore::Event::shiftTimes
virtual void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Definition: event.cpp:223
KCalCore::IncidenceBase::duration
Duration duration() const
Returns the length of the incidence duration.
Definition: incidencebase.cpp:534
KCalCore::IncidenceBase::RoleCalendarHashing
Role for looking up an incidence in a Calendar.
Definition: incidencebase.h:135
KCalCore::Event::equals
virtual bool equals(const IncidenceBase &event) const
Compares two events for equality.
Definition: event.cpp:99
KCalCore::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:52
KCalCore::Alarm::Ptr
QSharedPointer< Alarm > Ptr
A shared pointer to an Alarm object.
Definition: alarm.h:76
KCalCore::IncidenceBase::RoleAlarm
Role for determining the date/time of the first alarm.
Definition: incidencebase.h:143
KCalCore::IncidenceBase::FieldDtEnd
Field representing the DTSTART component.
Definition: incidencebase.h:157
KCalCore::Incidence::setAllDay
void setAllDay(bool allDay)
Definition: incidence.cpp:329
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:188
KCalCore::IncidenceBase
An abstract class that provides a common base for all calendar incidence classes. ...
Definition: incidencebase.h:107
KCalCore::IncidenceBase::RoleEndTimeZone
Role for determining an incidence&#39;s ending timezone.
Definition: incidencebase.h:137
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:114
KCalCore::IncidenceBase::update
void update()
Call this to notify the observers after the IncidenceBase object will be changed. ...
Definition: incidencebase.cpp:561
KCalCore::Event::setAllDay
void setAllDay(bool allDay)
Definition: event.cpp:255
KCalCore::IncidenceBase::RoleEnd
Role for determining an incidence&#39;s dtEnd, will return an invalid KDateTime if the incidence does not...
Definition: incidencebase.h:139
KCalCore::Event::assign
virtual IncidenceBase & assign(const IncidenceBase &other)
Definition: event.cpp:89
KCalCore::Event::dateTime
KDateTime dateTime(DateTimeRole role) const
Definition: event.cpp:268
KCalCore::IncidenceBase::IncidenceType
IncidenceType
The different types of incidences, per RFC2445.
Definition: incidencebase.h:119
KCalCore::IncidenceBase::hasDuration
bool hasDuration() const
Returns true if the incidence has a duration; false otherwise.
Definition: incidencebase.cpp:544
KCalCore::IncidenceBase::setHasDuration
void setHasDuration(bool hasDuration)
Sets if the incidence has a duration.
Definition: incidencebase.cpp:539
KCalCore::IncidenceBase::RoleDnD
Role for determining new start and end dates after a DnD.
Definition: incidencebase.h:152
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:182
KCalCore::IncidenceBase::RoleDisplayEnd
Role used for display purposes, represents the end boundary if an incidence supports dtEnd...
Definition: incidencebase.h:141
KCalCore::IncidenceBase::setDuration
virtual void setDuration(const Duration &duration)
Sets the incidence duration.
Definition: incidencebase.cpp:525
KCalCore::Event::setDtStart
virtual void setDtStart(const KDateTime &dt)
Sets the incidence starting date/time.
Definition: event.cpp:124
KCalCore::Incidence::alarms
Alarm::List alarms() const
Returns a list of all incidence alarms.
Definition: incidence.cpp:860
KCalCore::IncidenceBase::updated
void updated()
Call this to notify the observers after the IncidenceBase object has changed.
Definition: incidencebase.cpp:572
KCalCore::Event::dtEnd
virtual KDateTime dtEnd() const
Returns the event end date and time.
Definition: event.cpp:146
KCalCore::IncidenceBase::Ptr
QSharedPointer< IncidenceBase > Ptr
A shared pointer to an IncidenceBase.
Definition: incidencebase.h:113
KCalCore::Event::Transparency
Transparency
The different Event transparency types.
Definition: event.h:47
KCalCore::Event::Event
Event()
Constructs an event.
Definition: event.cpp:69
KCalCore::Incidence::setDtStart
virtual void setDtStart(const KDateTime &dt)
Sets the incidence starting date/time.
Definition: incidence.cpp:376
KCalCore::IncidenceBase::allDay
bool allDay() const
Returns true or false depending on whether the incidence is all-day.
Definition: incidencebase.cpp:305
KCalCore::Event::clone
Event * clone() const
Returns an exact copy of this Event.
Definition: event.cpp:84
KCalCore::Event::setTransparency
void setTransparency(Transparency transparency)
Sets the event&#39;s time transparency level.
Definition: event.cpp:233
KCalCore::IncidenceBase::setFieldDirty
void setFieldDirty(IncidenceBase::Field field)
Marks Field field as dirty.
Definition: incidencebase.cpp:625
KCalCore::IncidenceBase::RoleSort
Role for an incidence&#39;s date/time used when sorting.
Definition: incidencebase.h:134
KCalCore::Event::dateEnd
QDate dateEnd() const
Returns the date when the event ends.
Definition: event.cpp:167
KCalCore::Incidence::shiftTimes
virtual void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Definition: incidence.cpp:385
KCalCore::Event::setHasEndDate
void setHasEndDate(bool b)
Sets whether the event has an end date/time.
Definition: event.cpp:177
KCalCore::Event::iconName
QLatin1String iconName(const KDateTime &recurrenceId=KDateTime()) const
Definition: event.cpp:332
KCalCore::IncidenceBase::DateTimeRole
DateTimeRole
The different types of incidence date/times roles.
Definition: incidencebase.h:131
KCalCore::IncidenceBase::RoleAlarmEndOffset
Role for an incidence alarm&#39;s ending offset date/time.
Definition: incidencebase.h:133
KCalCore::Event::eventMimeType
static QLatin1String eventMimeType()
Returns the Akonadi specific sub MIME type of a KCalCore::Event.
Definition: event.cpp:327
KCalCore::Incidence::assign
virtual IncidenceBase & assign(const IncidenceBase &other)
Definition: incidence.cpp:211
KCalCore::Event::~Event
~Event()
Destroys the event.
Definition: event.cpp:79
KCalCore::IncidenceBase::RoleStartTimeZone
Role for determining an incidence&#39;s starting timezone.
Definition: incidencebase.h:136
KCalCore::Event::hasEndDate
bool hasEndDate() const
Returns whether the event has an end date/time.
Definition: event.cpp:183
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&#39;s time transparency level.
Definition: event.cpp:244
KCalCore::IncidenceBase::TypeEvent
Type is an event.
Definition: incidencebase.h:120
KCalCore::Event
This class provides an Event in the sense of RFC2445.
Definition: event.h:41
KCalCore::Incidence::recurs
bool recurs() const
Definition: incidence.cpp:563
KCalCore::Event::typeStr
QByteArray typeStr() const
Definition: event.cpp:119
KCalCore::IncidenceBase::mReadOnly
bool mReadOnly
Identifies a read-only incidence.
Definition: incidencebase.h:705
KCalCore::Event::mimeType
QLatin1String mimeType() const
Definition: event.cpp:322
KCalCore::IncidenceBase::RoleAlarmStartOffset
Role for an incidence alarm&#39;s starting offset date/time.
Definition: incidencebase.h:132
KCalCore::IncidenceBase::FieldTransparency
Field representing the STATUS component.
Definition: incidencebase.h:171
KCalCore::Event::virtual_hook
virtual void virtual_hook(int id, void *data)
Definition: event.cpp:315
KCalCore::Event::setDateTime
void setDateTime(const KDateTime &dateTime, DateTimeRole role)
Definition: event.cpp:300
KCalCore::Event::setDtEnd
void setDtEnd(const KDateTime &dtEnd)
Sets the event end date and time.
Definition: event.cpp:130
KCalCore::Event::setDuration
void setDuration(const Duration &duration)
Sets the duration of this event.
Definition: event.cpp:249
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&#39;s starting date/time as a KDateTime.
Definition: incidencebase.cpp:300
KCalCore::IncidenceBase::RoleRecurrenceStart
Role for determining the start of the recurrence.
Definition: incidencebase.h:145
KCalCore::IncidenceBase::RoleDisplayStart
Role for display purposes, represents the start boundary of an incidence.
Definition: incidencebase.h:150
This file is part of the KDE documentation.
Documentation copyright © 1996-2017 The KDE developers.
Generated on Sat Feb 25 2017 07:46:09 by doxygen 1.8.5 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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
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