KCal Library
event.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcal library. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00032 #include "event.h" 00033 #include "incidenceformatter.h" 00034 00035 #include <kglobal.h> 00036 #include <klocale.h> 00037 #include <kdebug.h> 00038 #include <ksystemtimezone.h> 00039 00040 using namespace KCal; 00041 00046 //@cond PRIVATE 00047 class KCal::Event::Private 00048 { 00049 public: 00050 Private() 00051 : mHasEndDate( false ), 00052 mTransparency( Opaque ) 00053 {} 00054 Private( const KCal::Event::Private &other ) 00055 : mDtEnd( other.mDtEnd ), 00056 mHasEndDate( other.mHasEndDate ), 00057 mTransparency( other.mTransparency ) 00058 {} 00059 00060 KDateTime mDtEnd; 00061 bool mHasEndDate; 00062 Transparency mTransparency; 00063 }; 00064 //@endcond 00065 00066 Event::Event() 00067 : d( new KCal::Event::Private ) 00068 { 00069 } 00070 00071 Event::Event( const Event &other ) 00072 : Incidence( other ), d( new KCal::Event::Private( *other.d ) ) 00073 { 00074 } 00075 00076 Event::~Event() 00077 { 00078 delete d; 00079 } 00080 00081 Event *Event::clone() 00082 { 00083 return new Event( *this ); 00084 } 00085 00086 Event &Event::operator=( const Event &other ) 00087 { 00088 // check for self assignment 00089 if ( &other == this ) { 00090 return *this; 00091 } 00092 00093 Incidence::operator=( other ); 00094 *d = *other.d; 00095 return *this; 00096 } 00097 00098 bool Event::operator==( const Event &event ) const 00099 { 00100 return 00101 Incidence::operator==( event ) && 00102 dtEnd() == event.dtEnd() && 00103 hasEndDate() == event.hasEndDate() && 00104 transparency() == event.transparency(); 00105 } 00106 00107 QByteArray Event::type() const 00108 { 00109 return "Event"; 00110 } 00111 00112 //KDE5: 00113 //QString Event::typeStr() const 00114 //{ 00115 // return i18nc( "incidence type is event", "event" ); 00116 //} 00117 00118 void Event::setDtEnd( const KDateTime &dtEnd ) 00119 { 00120 if ( mReadOnly ) { 00121 return; 00122 } 00123 00124 d->mDtEnd = dtEnd; 00125 setHasEndDate( true ); 00126 setHasDuration( false ); 00127 00128 updated(); 00129 } 00130 00131 KDateTime Event::dtEnd() const 00132 { 00133 if ( hasEndDate() ) { 00134 return d->mDtEnd; 00135 } 00136 00137 if ( hasDuration() ) { 00138 if ( allDay() ) { 00139 // For all day events, dtEnd is always inclusive 00140 KDateTime end = duration().end( dtStart() ).addDays( -1 ); 00141 return end >= dtStart() ? end : dtStart(); 00142 } else { 00143 return duration().end( dtStart() ); 00144 } 00145 } 00146 00147 // It is valid for a VEVENT to be without a DTEND. See RFC2445, Sect4.6.1. 00148 // Be careful to use Event::dateEnd() as appropriate due to this possibility. 00149 return dtStart(); 00150 } 00151 00152 QDate Event::dateEnd() const 00153 { 00154 KDateTime end = dtEnd().toTimeSpec( dtStart() ); 00155 if ( allDay() ) { 00156 return end.date(); 00157 } else { 00158 return end.addSecs(-1).date(); 00159 } 00160 } 00161 00162 QString Event::dtEndTimeStr( bool shortfmt, const KDateTime::Spec &spec ) const 00163 { 00164 if ( spec.isValid() ) { 00165 00166 QString timeZone; 00167 if ( spec.timeZone() != KSystemTimeZones::local() ) { 00168 timeZone = ' ' + spec.timeZone().name(); 00169 } 00170 00171 return KGlobal::locale()->formatTime( 00172 dtEnd().toTimeSpec( spec ).time(), !shortfmt ) + timeZone; 00173 } else { 00174 return KGlobal::locale()->formatTime( dtEnd().time(), !shortfmt ); 00175 } 00176 } 00177 00178 QString Event::dtEndDateStr( bool shortfmt, const KDateTime::Spec &spec ) const 00179 { 00180 if ( spec.isValid() ) { 00181 00182 QString timeZone; 00183 if ( spec.timeZone() != KSystemTimeZones::local() ) { 00184 timeZone = ' ' + spec.timeZone().name(); 00185 } 00186 00187 return KGlobal::locale()->formatDate( 00188 dtEnd().toTimeSpec( spec ).date(), 00189 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone; 00190 } else { 00191 return KGlobal::locale()->formatDate( 00192 dtEnd().date(), 00193 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ); 00194 } 00195 } 00196 00197 QString Event::dtEndStr( bool shortfmt, const KDateTime::Spec &spec ) const 00198 { 00199 if ( allDay() ) { 00200 return IncidenceFormatter::dateToString( dtEnd(), shortfmt, spec ); 00201 } 00202 00203 if ( spec.isValid() ) { 00204 00205 QString timeZone; 00206 if ( spec.timeZone() != KSystemTimeZones::local() ) { 00207 timeZone = ' ' + spec.timeZone().name(); 00208 } 00209 00210 return KGlobal::locale()->formatDateTime( 00211 dtEnd().toTimeSpec( spec ).dateTime(), 00212 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone; 00213 } else { 00214 return KGlobal::locale()->formatDateTime( 00215 dtEnd().dateTime(), 00216 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ); 00217 } 00218 } 00219 00220 void Event::setHasEndDate( bool b ) 00221 { 00222 d->mHasEndDate = b; 00223 } 00224 00225 bool Event::hasEndDate() const 00226 { 00227 return d->mHasEndDate; 00228 } 00229 00230 bool Event::isMultiDay( const KDateTime::Spec &spec ) const 00231 { 00232 // End date is non inclusive, so subtract 1 second... 00233 KDateTime start, end; 00234 if ( spec.isValid() ) { 00235 start = dtStart().toTimeSpec( spec ); 00236 end = dtEnd().toTimeSpec( spec ); 00237 } else { 00238 start = dtStart(); 00239 end = dtEnd(); 00240 } 00241 00242 if ( !allDay() ) { 00243 end = end.addSecs( -1 ); 00244 } 00245 00246 bool multi = ( start.date() != end.date() && start <= end ); 00247 return multi; 00248 } 00249 00250 void Event::shiftTimes( const KDateTime::Spec &oldSpec, 00251 const KDateTime::Spec &newSpec ) 00252 { 00253 Incidence::shiftTimes( oldSpec, newSpec ); 00254 if ( hasEndDate() ) { 00255 d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec ); 00256 d->mDtEnd.setTimeSpec( newSpec ); 00257 } 00258 } 00259 00260 void Event::setTransparency( Event::Transparency transparency ) 00261 { 00262 if ( mReadOnly ) { 00263 return; 00264 } 00265 d->mTransparency = transparency; 00266 updated(); 00267 } 00268 00269 Event::Transparency Event::transparency() const 00270 { 00271 return d->mTransparency; 00272 } 00273 00274 void Event::setDuration( const Duration &duration ) 00275 { 00276 setHasEndDate( false ); 00277 Incidence::setDuration( duration ); 00278 } 00279 00280 KDateTime Event::endDateRecurrenceBase() const 00281 { 00282 return dtEnd(); 00283 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:42 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:42 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.