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

KCal Library

  • kcal
event.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcal 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 "incidenceformatter.h"
34 
35 #include <kglobal.h>
36 #include <klocale.h>
37 #include <klocalizedstring.h>
38 #include <kdebug.h>
39 #include <ksystemtimezone.h>
40 
41 using namespace KCal;
42 
47 //@cond PRIVATE
48 class KCal::Event::Private
49 {
50  public:
51  Private()
52  : mHasEndDate( false ),
53  mTransparency( Opaque )
54  {}
55  Private( const KCal::Event::Private &other )
56  : mDtEnd( other.mDtEnd ),
57  mHasEndDate( other.mHasEndDate ),
58  mTransparency( other.mTransparency )
59  {}
60 
61  KDateTime mDtEnd;
62  bool mHasEndDate;
63  Transparency mTransparency;
64 };
65 //@endcond
66 
67 Event::Event()
68  : d( new KCal::Event::Private )
69 {
70 }
71 
72 Event::Event( const Event &other )
73  : Incidence( other ), d( new KCal::Event::Private( *other.d ) )
74 {
75 }
76 
77 Event::~Event()
78 {
79  delete d;
80 }
81 
82 Event *Event::clone()
83 {
84  return new Event( *this );
85 }
86 
87 Event &Event::operator=( const Event &other )
88 {
89  // check for self assignment
90  if ( &other == this ) {
91  return *this;
92  }
93 
94  Incidence::operator=( other );
95  *d = *other.d;
96  return *this;
97 }
98 
99 bool Event::operator==( const Event &event ) const
100 {
101  return
102  Incidence::operator==( event ) &&
103  dtEnd() == event.dtEnd() &&
104  hasEndDate() == event.hasEndDate() &&
105  transparency() == event.transparency();
106 }
107 
108 QByteArray Event::type() const
109 {
110  return "Event";
111 }
112 
113 //KDE5:
114 //QString Event::typeStr() const
115 //{
116 // return i18nc( "incidence type is event", "event" );
117 //}
118 
119 void Event::setDtEnd( const KDateTime &dtEnd )
120 {
121  if ( mReadOnly ) {
122  return;
123  }
124 
125  d->mDtEnd = dtEnd;
126  setHasEndDate( true );
127  setHasDuration( false );
128 
129  updated();
130 }
131 
132 KDateTime Event::dtEnd() const
133 {
134  if ( hasEndDate() ) {
135  return d->mDtEnd;
136  }
137 
138  if ( hasDuration() ) {
139  if ( allDay() ) {
140  // For all day events, dtEnd is always inclusive
141  KDateTime end = duration().end( dtStart() ).addDays( -1 );
142  return end >= dtStart() ? end : dtStart();
143  } else {
144  return duration().end( dtStart() );
145  }
146  }
147 
148  // It is valid for a VEVENT to be without a DTEND. See RFC2445, Sect4.6.1.
149  // Be careful to use Event::dateEnd() as appropriate due to this possibility.
150  return dtStart();
151 }
152 
153 QDate Event::dateEnd() const
154 {
155  KDateTime end = dtEnd().toTimeSpec( dtStart() );
156  if ( allDay() ) {
157  return end.date();
158  } else {
159  return end.addSecs(-1).date();
160  }
161 }
162 
163 QString Event::dtEndTimeStr( bool shortfmt, const KDateTime::Spec &spec ) const
164 {
165  if ( spec.isValid() ) {
166 
167  QString timeZone;
168  if ( spec.timeZone() != KSystemTimeZones::local() ) {
169  timeZone = ' ' + spec.timeZone().name();
170  }
171 
172  return KGlobal::locale()->formatTime(
173  dtEnd().toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
174  } else {
175  return KGlobal::locale()->formatTime( dtEnd().time(), !shortfmt );
176  }
177 }
178 
179 QString Event::dtEndDateStr( bool shortfmt, const KDateTime::Spec &spec ) const
180 {
181  if ( spec.isValid() ) {
182 
183  QString timeZone;
184  if ( spec.timeZone() != KSystemTimeZones::local() ) {
185  timeZone = ' ' + spec.timeZone().name();
186  }
187 
188  return KGlobal::locale()->formatDate(
189  dtEnd().toTimeSpec( spec ).date(),
190  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
191  } else {
192  return KGlobal::locale()->formatDate(
193  dtEnd().date(),
194  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
195  }
196 }
197 
198 QString Event::dtEndStr( bool shortfmt, const KDateTime::Spec &spec ) const
199 {
200  if ( allDay() ) {
201  return IncidenceFormatter::dateToString( dtEnd(), shortfmt, spec );
202  }
203 
204  if ( spec.isValid() ) {
205 
206  QString timeZone;
207  if ( spec.timeZone() != KSystemTimeZones::local() ) {
208  timeZone = ' ' + spec.timeZone().name();
209  }
210 
211  return KGlobal::locale()->formatDateTime(
212  dtEnd().toTimeSpec( spec ).dateTime(),
213  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
214  } else {
215  return KGlobal::locale()->formatDateTime(
216  dtEnd().dateTime(),
217  ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
218  }
219 }
220 
221 void Event::setHasEndDate( bool b )
222 {
223  d->mHasEndDate = b;
224 }
225 
226 bool Event::hasEndDate() const
227 {
228  return d->mHasEndDate;
229 }
230 
231 bool Event::isMultiDay( const KDateTime::Spec &spec ) const
232 {
233  // End date is non inclusive, so subtract 1 second...
234  KDateTime start, end;
235  if ( spec.isValid() ) {
236  start = dtStart().toTimeSpec( spec );
237  end = dtEnd().toTimeSpec( spec );
238  } else {
239  start = dtStart();
240  end = dtEnd();
241  }
242 
243  if ( !allDay() ) {
244  end = end.addSecs( -1 );
245  }
246 
247  bool multi = ( start.date() != end.date() && start <= end );
248  return multi;
249 }
250 
251 void Event::shiftTimes( const KDateTime::Spec &oldSpec,
252  const KDateTime::Spec &newSpec )
253 {
254  Incidence::shiftTimes( oldSpec, newSpec );
255  if ( hasEndDate() ) {
256  d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
257  d->mDtEnd.setTimeSpec( newSpec );
258  }
259 }
260 
261 void Event::setTransparency( Event::Transparency transparency )
262 {
263  if ( mReadOnly ) {
264  return;
265  }
266  d->mTransparency = transparency;
267  updated();
268 }
269 
270 Event::Transparency Event::transparency() const
271 {
272  return d->mTransparency;
273 }
274 
275 void Event::setDuration( const Duration &duration )
276 {
277  setHasEndDate( false );
278  Incidence::setDuration( duration );
279 }
280 
281 KDateTime Event::endDateRecurrenceBase() const
282 {
283  return dtEnd();
284 }
KCal::Duration
Represents a span of time measured in seconds or days.
Definition: duration.h:53
KCal::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:183
KCal::Event
This class provides an Event in the sense of RFC2445.
Definition: event.h:42
KCal::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:231
KCal::Event::dtEndDateStr
KCAL_DEPRECATED QString dtEndDateStr(bool shortfmt=true, const KDateTime::Spec &spec=KDateTime::Spec()) const
Returns the event end date as a string formatted according to the user's locale settings.
Definition: event.cpp:179
KCal::Event::shiftTimes
virtual void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Definition: event.cpp:251
KCal::Event::operator==
bool operator==(const Event &event) const
Compares two events for equality.
Definition: event.cpp:99
KCal::Event::setDtEnd
void setDtEnd(const KDateTime &dtEnd)
Sets the event end date and time.
Definition: event.cpp:119
KCal::Event::dtEnd
virtual KDateTime dtEnd() const
Returns the event end date and time.
Definition: event.cpp:132
KCal::Event::setDuration
void setDuration(const Duration &duration)
Sets the duration of this event.
Definition: event.cpp:275
KCal::Event::setTransparency
void setTransparency(Transparency transparency)
Sets the event's time transparency level.
Definition: event.cpp:261
KCal::Event::type
QByteArray type() const
Definition: event.cpp:108
KCal::Event::Event
Event()
Constructs an event.
Definition: event.cpp:67
KCal::Event::~Event
~Event()
Destroys the event.
Definition: event.cpp:77
KCal::Event::dateEnd
QDate dateEnd() const
Returns the date when the event ends.
Definition: event.cpp:153
KCal::Event::transparency
Transparency transparency() const
Returns the event's time transparency level.
Definition: event.cpp:270
KCal::Event::operator=
Event & operator=(const Event &other)
Assignment operator.
Definition: event.cpp:87
KCal::Event::Transparency
Transparency
The different Event transparency types.
Definition: event.h:47
KCal::Event::Opaque
@ Opaque
Event appears in free/busy time.
Definition: event.h:48
KCal::Event::dtEndStr
KCAL_DEPRECATED QString dtEndStr(bool shortfmt=true, const KDateTime::Spec &spec=KDateTime::Spec()) const
Returns the event end date/time as string formatted according to the user's locale settings.
Definition: event.cpp:198
KCal::Event::clone
Event * clone()
Definition: event.cpp:82
KCal::Event::endDateRecurrenceBase
virtual KDateTime endDateRecurrenceBase() const
Returns the end date/time of the base incidence.
Definition: event.cpp:281
KCal::Event::dtEndTimeStr
KCAL_DEPRECATED QString dtEndTimeStr(bool shortfmt=true, const KDateTime::Spec &spec=KDateTime::Spec()) const
Returns the event end time as a string formatted according to the user's locale settings.
Definition: event.cpp:163
KCal::Event::setHasEndDate
void setHasEndDate(bool b)
Sets whether the event has an end date/time.
Definition: event.cpp:221
KCal::Event::hasEndDate
bool hasEndDate() const
Returns whether the event has an end date/time.
Definition: event.cpp:226
KCal::IncidenceBase::mReadOnly
bool mReadOnly
Identifies a read-only incidence.
Definition: incidencebase.h:577
KCal::IncidenceBase::updated
void updated()
Call this to notify the observers after the IncidenceBase object has changed.
Definition: incidencebase.cpp:475
KCal::IncidenceBase::allDay
bool allDay() const
Returns true or false depending on whether the incidence is all-day.
Definition: incidencebase.cpp:310
KCal::IncidenceBase::duration
Duration duration() const
Returns the length of the incidence duration.
Definition: incidencebase.cpp:448
KCal::IncidenceBase::dtStart
virtual KDateTime dtStart() const
Returns an incidence's starting date/time as a KDateTime.
Definition: incidencebase.cpp:248
KCal::IncidenceBase::setDuration
virtual void setDuration(const Duration &duration)
Sets the incidence duration.
Definition: incidencebase.cpp:441
KCal::IncidenceBase::setHasDuration
void setHasDuration(bool hasDuration)
Sets if the incidence has a duration.
Definition: incidencebase.cpp:453
KCal::IncidenceBase::hasDuration
bool hasDuration() const
Returns true if the incidence has a duration; false otherwise.
Definition: incidencebase.cpp:458
KCal::Incidence
Provides the abstract base class common to non-FreeBusy (Events, To-dos, Journals) calendar component...
Definition: incidence.h:70
KCal::Incidence::operator==
bool operator==(const Incidence &incidence) const
Compares this with Incidence ib for equality.
Definition: incidence.cpp:235
KCal::Incidence::shiftTimes
virtual void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
Definition: incidence.cpp:363
KCal::Incidence::operator=
Incidence & operator=(const Incidence &other)
Assignment operator.
Definition: incidence.cpp:221
event.h
This file is part of the API for handling calendar data and defines the Event class.
incidenceformatter.h
This file is part of the API for handling calendar data and provides static functions for formatting ...
KCal::IncidenceFormatter::dateToString
KCAL_DEPRECATED_EXPORT QString dateToString(const KDateTime &date, bool shortfmt=true, const KDateTime::Spec &spec=KDateTime::Spec())
Build a QString date representation of a KDateTime object.
Definition: incidenceformatter.cpp:3737
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jul 22 2021 00:00:00 by doxygen 1.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

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

kdepimlibs-4.14.10 API Reference

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