• 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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:24:51 by doxygen 1.8.3.1 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