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