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 bool Event::operator==( const Event &other ) const
00086 {
00087 return
00088 static_cast<const Incidence &>( *this ) == static_cast<const Incidence &>( other ) &&
00089 dtEnd() == other.dtEnd() &&
00090 hasEndDate() == other.hasEndDate() &&
00091 transparency() == other.transparency();
00092 }
00093
00094 QByteArray Event::type() const
00095 {
00096 return "Event";
00097 }
00098
00099 void Event::setDtEnd( const KDateTime &dtEnd )
00100 {
00101 if ( mReadOnly ) {
00102 return;
00103 }
00104
00105 d->mDtEnd = dtEnd;
00106 setHasEndDate( true );
00107 setHasDuration( false );
00108
00109 updated();
00110 }
00111
00112 KDateTime Event::dtEnd() const
00113 {
00114 if ( hasEndDate() ) {
00115 return d->mDtEnd;
00116 }
00117 if ( hasDuration() ) {
00118 return duration().end( dtStart() );
00119 }
00120
00121 kDebug(5800) << "Warning! Event '" << summary()
00122 << "' has neither end date nor duration.";
00123 return dtStart();
00124 }
00125
00126 QDate Event::dateEnd() const
00127 {
00128 KDateTime end = dtEnd().toTimeSpec( dtStart() );
00129 if ( allDay() ) {
00130 return end.date();
00131 } else {
00132 return end.addSecs(-1).date();
00133 }
00134 }
00135
00136 QString Event::dtEndTimeStr( bool shortfmt, const KDateTime::Spec &spec ) const
00137 {
00138 if ( spec.isValid() ) {
00139
00140 QString timeZone;
00141 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00142 timeZone = ' ' + spec.timeZone().name();
00143 }
00144
00145 return KGlobal::locale()->formatTime( dtEnd().toTimeSpec( spec ).time(), shortfmt )
00146 + timeZone;
00147 } else {
00148 return KGlobal::locale()->formatTime( dtEnd().time(), shortfmt );
00149 }
00150 }
00151
00152 QString Event::dtEndDateStr( bool shortfmt, const KDateTime::Spec &spec ) const
00153 {
00154 if ( spec.isValid() ) {
00155
00156 QString timeZone;
00157 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00158 timeZone = ' ' + spec.timeZone().name();
00159 }
00160
00161 return KGlobal::locale()->formatDate(
00162 dtEnd().toTimeSpec( spec ).date(),
00163 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) )
00164 + timeZone;
00165 } else {
00166 return KGlobal::locale()->formatDate(
00167 dtEnd().date(),
00168 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00169 }
00170 }
00171
00172 QString Event::dtEndStr( bool shortfmt, const KDateTime::Spec &spec ) const
00173 {
00174 if ( spec.isValid() ) {
00175
00176 QString timeZone;
00177 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00178 timeZone = ' ' + spec.timeZone().name();
00179 }
00180
00181 return KGlobal::locale()->formatDateTime(
00182 dtEnd().toTimeSpec( spec ).dateTime(),
00183 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) )
00184 + timeZone;
00185 } else {
00186 return KGlobal::locale()->formatDateTime(
00187 dtEnd().dateTime(),
00188 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00189 }
00190 }
00191
00192 void Event::setHasEndDate( bool b )
00193 {
00194 d->mHasEndDate = b;
00195 }
00196
00197 bool Event::hasEndDate() const
00198 {
00199 return d->mHasEndDate;
00200 }
00201
00202 bool Event::isMultiDay( const KDateTime::Spec &spec ) const
00203 {
00204
00205 KDateTime start, end;
00206 if ( spec.isValid() ) {
00207 start = dtStart().toTimeSpec( spec );
00208 end = dtEnd().toTimeSpec( spec );
00209 } else {
00210 start = dtStart();
00211 end = dtEnd();
00212 }
00213
00214 if ( !allDay() ) {
00215 end = end.addSecs( -1 );
00216 }
00217
00218 bool multi = ( start.date() != end.date() && start <= end );
00219 return multi;
00220 }
00221
00222 void Event::shiftTimes( const KDateTime::Spec &oldSpec,
00223 const KDateTime::Spec &newSpec )
00224 {
00225 Incidence::shiftTimes( oldSpec, newSpec );
00226 if ( hasEndDate() ) {
00227 d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
00228 d->mDtEnd.setTimeSpec( newSpec );
00229 }
00230 }
00231
00232 void Event::setTransparency( Event::Transparency transparency )
00233 {
00234 if ( mReadOnly ) {
00235 return;
00236 }
00237 d->mTransparency = transparency;
00238 updated();
00239 }
00240
00241 Event::Transparency Event::transparency() const
00242 {
00243 return d->mTransparency;
00244 }
00245
00246 void Event::setDuration( const Duration &duration )
00247 {
00248 setHasEndDate( false );
00249 Incidence::setDuration( duration );
00250 }
00251
00252 KDateTime Event::endDateRecurrenceBase() const
00253 {
00254 return dtEnd();
00255 }