KCal Library
event.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00032 #include "event.h"
00033
00034 #include <kglobal.h>
00035 #include <klocale.h>
00036 #include <kdebug.h>
00037 #include <ksystemtimezone.h>
00038
00039 using namespace KCal;
00040
00045
00046 class KCal::Event::Private
00047 {
00048 public:
00049 Private()
00050 : mHasEndDate( false ),
00051 mTransparency( Opaque )
00052 {}
00053 Private( const KCal::Event::Private &other )
00054 : mDtEnd( other.mDtEnd ),
00055 mHasEndDate( other.mHasEndDate ),
00056 mTransparency( other.mTransparency )
00057 {}
00058
00059 KDateTime mDtEnd;
00060 bool mHasEndDate;
00061 Transparency mTransparency;
00062 };
00063
00064
00065 Event::Event()
00066 : d( new KCal::Event::Private )
00067 {
00068 }
00069
00070 Event::Event( const Event &other )
00071 : Incidence( other ), d( new KCal::Event::Private( *other.d ) )
00072 {
00073 }
00074
00075 Event::~Event()
00076 {
00077 delete d;
00078 }
00079
00080 Event *Event::clone()
00081 {
00082 return new Event( *this );
00083 }
00084
00085 Event &Event::operator=( const Event &other )
00086 {
00087 Incidence::operator=( other );
00088 *d = *other.d;
00089 return *this;
00090 }
00091
00092 bool Event::operator==( const Event &event ) const
00093 {
00094 return
00095 static_cast<const Incidence &>( *this ) == static_cast<const Incidence &>( event ) &&
00096 dtEnd() == event.dtEnd() &&
00097 hasEndDate() == event.hasEndDate() &&
00098 transparency() == event.transparency();
00099 }
00100
00101 QByteArray Event::type() const
00102 {
00103 return "Event";
00104 }
00105
00106 void Event::setDtEnd( const KDateTime &dtEnd )
00107 {
00108 if ( mReadOnly ) {
00109 return;
00110 }
00111
00112 d->mDtEnd = dtEnd;
00113 setHasEndDate( true );
00114 setHasDuration( false );
00115
00116 updated();
00117 }
00118
00119 KDateTime Event::dtEnd() const
00120 {
00121 if ( hasEndDate() ) {
00122 return d->mDtEnd;
00123 }
00124
00125 if ( hasDuration() ) {
00126 if ( allDay() ) {
00127
00128 KDateTime end = duration().end( dtStart() ).addDays( -1 );
00129 return end >= dtStart() ? end : dtStart();
00130 } else {
00131 return duration().end( dtStart() );
00132 }
00133 }
00134
00135 kDebug() << "Warning! Event '" << summary()
00136 << "' has neither end date nor duration.";
00137 return dtStart();
00138 }
00139
00140 QDate Event::dateEnd() const
00141 {
00142 KDateTime end = dtEnd().toTimeSpec( dtStart() );
00143 if ( allDay() ) {
00144 return end.date();
00145 } else {
00146 return end.addSecs(-1).date();
00147 }
00148 }
00149
00150 QString Event::dtEndTimeStr( bool shortfmt, const KDateTime::Spec &spec ) const
00151 {
00152 if ( spec.isValid() ) {
00153
00154 QString timeZone;
00155 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00156 timeZone = ' ' + spec.timeZone().name();
00157 }
00158
00159 return KGlobal::locale()->formatTime( dtEnd().toTimeSpec( spec ).time(), !shortfmt )
00160 + timeZone;
00161 } else {
00162 return KGlobal::locale()->formatTime( dtEnd().time(), !shortfmt );
00163 }
00164 }
00165
00166 QString Event::dtEndDateStr( bool shortfmt, const KDateTime::Spec &spec ) const
00167 {
00168 if ( spec.isValid() ) {
00169
00170 QString timeZone;
00171 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00172 timeZone = ' ' + spec.timeZone().name();
00173 }
00174
00175 return KGlobal::locale()->formatDate(
00176 dtEnd().toTimeSpec( spec ).date(),
00177 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) )
00178 + timeZone;
00179 } else {
00180 return KGlobal::locale()->formatDate(
00181 dtEnd().date(),
00182 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00183 }
00184 }
00185
00186 QString Event::dtEndStr( bool shortfmt, const KDateTime::Spec &spec ) const
00187 {
00188 if ( allDay() ) {
00189 return dtEndDateStr( shortfmt, spec );
00190 }
00191
00192 if ( spec.isValid() ) {
00193
00194 QString timeZone;
00195 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00196 timeZone = ' ' + spec.timeZone().name();
00197 }
00198
00199 return KGlobal::locale()->formatDateTime(
00200 dtEnd().toTimeSpec( spec ).dateTime(),
00201 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) )
00202 + timeZone;
00203 } else {
00204 return KGlobal::locale()->formatDateTime(
00205 dtEnd().dateTime(),
00206 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00207 }
00208 }
00209
00210 void Event::setHasEndDate( bool b )
00211 {
00212 d->mHasEndDate = b;
00213 }
00214
00215 bool Event::hasEndDate() const
00216 {
00217 return d->mHasEndDate;
00218 }
00219
00220 bool Event::isMultiDay( const KDateTime::Spec &spec ) const
00221 {
00222
00223 KDateTime start, end;
00224 if ( spec.isValid() ) {
00225 start = dtStart().toTimeSpec( spec );
00226 end = dtEnd().toTimeSpec( spec );
00227 } else {
00228 start = dtStart();
00229 end = dtEnd();
00230 }
00231
00232 if ( !allDay() ) {
00233 end = end.addSecs( -1 );
00234 }
00235
00236 bool multi = ( start.date() != end.date() && start <= end );
00237 return multi;
00238 }
00239
00240 void Event::shiftTimes( const KDateTime::Spec &oldSpec,
00241 const KDateTime::Spec &newSpec )
00242 {
00243 Incidence::shiftTimes( oldSpec, newSpec );
00244 if ( hasEndDate() ) {
00245 d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
00246 d->mDtEnd.setTimeSpec( newSpec );
00247 }
00248 }
00249
00250 void Event::setTransparency( Event::Transparency transparency )
00251 {
00252 if ( mReadOnly ) {
00253 return;
00254 }
00255 d->mTransparency = transparency;
00256 updated();
00257 }
00258
00259 Event::Transparency Event::transparency() const
00260 {
00261 return d->mTransparency;
00262 }
00263
00264 void Event::setDuration( const Duration &duration )
00265 {
00266 setHasEndDate( false );
00267 Incidence::setDuration( duration );
00268 }
00269
00270 KDateTime Event::endDateRecurrenceBase() const
00271 {
00272 return dtEnd();
00273 }