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