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 #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
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
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
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 void Event::setDtEnd( const KDateTime &dtEnd )
00113 {
00114 if ( mReadOnly ) {
00115 return;
00116 }
00117
00118 d->mDtEnd = dtEnd;
00119 setHasEndDate( true );
00120 setHasDuration( false );
00121
00122 updated();
00123 }
00124
00125 KDateTime Event::dtEnd() const
00126 {
00127 if ( hasEndDate() ) {
00128 return d->mDtEnd;
00129 }
00130
00131 if ( hasDuration() ) {
00132 if ( allDay() ) {
00133
00134 KDateTime end = duration().end( dtStart() ).addDays( -1 );
00135 return end >= dtStart() ? end : dtStart();
00136 } else {
00137 return duration().end( dtStart() );
00138 }
00139 }
00140
00141
00142
00143 return dtStart();
00144 }
00145
00146 QDate Event::dateEnd() const
00147 {
00148 KDateTime end = dtEnd().toTimeSpec( dtStart() );
00149 if ( allDay() ) {
00150 return end.date();
00151 } else {
00152 return end.addSecs(-1).date();
00153 }
00154 }
00155
00156 QString Event::dtEndTimeStr( bool shortfmt, const KDateTime::Spec &spec ) const
00157 {
00158 if ( spec.isValid() ) {
00159
00160 QString timeZone;
00161 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00162 timeZone = ' ' + spec.timeZone().name();
00163 }
00164
00165 return KGlobal::locale()->formatTime(
00166 dtEnd().toTimeSpec( spec ).time(), !shortfmt ) + timeZone;
00167 } else {
00168 return KGlobal::locale()->formatTime( dtEnd().time(), !shortfmt );
00169 }
00170 }
00171
00172 QString Event::dtEndDateStr( 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()->formatDate(
00182 dtEnd().toTimeSpec( spec ).date(),
00183 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
00184 } else {
00185 return KGlobal::locale()->formatDate(
00186 dtEnd().date(),
00187 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00188 }
00189 }
00190
00191 QString Event::dtEndStr( bool shortfmt, const KDateTime::Spec &spec ) const
00192 {
00193 if ( allDay() ) {
00194 return IncidenceFormatter::dateToString( dtEnd(), shortfmt, spec );
00195 }
00196
00197 if ( spec.isValid() ) {
00198
00199 QString timeZone;
00200 if ( spec.timeZone() != KSystemTimeZones::local() ) {
00201 timeZone = ' ' + spec.timeZone().name();
00202 }
00203
00204 return KGlobal::locale()->formatDateTime(
00205 dtEnd().toTimeSpec( spec ).dateTime(),
00206 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone;
00207 } else {
00208 return KGlobal::locale()->formatDateTime(
00209 dtEnd().dateTime(),
00210 ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) );
00211 }
00212 }
00213
00214 void Event::setHasEndDate( bool b )
00215 {
00216 d->mHasEndDate = b;
00217 }
00218
00219 bool Event::hasEndDate() const
00220 {
00221 return d->mHasEndDate;
00222 }
00223
00224 bool Event::isMultiDay( const KDateTime::Spec &spec ) const
00225 {
00226
00227 KDateTime start, end;
00228 if ( spec.isValid() ) {
00229 start = dtStart().toTimeSpec( spec );
00230 end = dtEnd().toTimeSpec( spec );
00231 } else {
00232 start = dtStart();
00233 end = dtEnd();
00234 }
00235
00236 if ( !allDay() ) {
00237 end = end.addSecs( -1 );
00238 }
00239
00240 bool multi = ( start.date() != end.date() && start <= end );
00241 return multi;
00242 }
00243
00244 void Event::shiftTimes( const KDateTime::Spec &oldSpec,
00245 const KDateTime::Spec &newSpec )
00246 {
00247 Incidence::shiftTimes( oldSpec, newSpec );
00248 if ( hasEndDate() ) {
00249 d->mDtEnd = d->mDtEnd.toTimeSpec( oldSpec );
00250 d->mDtEnd.setTimeSpec( newSpec );
00251 }
00252 }
00253
00254 void Event::setTransparency( Event::Transparency transparency )
00255 {
00256 if ( mReadOnly ) {
00257 return;
00258 }
00259 d->mTransparency = transparency;
00260 updated();
00261 }
00262
00263 Event::Transparency Event::transparency() const
00264 {
00265 return d->mTransparency;
00266 }
00267
00268 void Event::setDuration( const Duration &duration )
00269 {
00270 setHasEndDate( false );
00271 Incidence::setDuration( duration );
00272 }
00273
00274 KDateTime Event::endDateRecurrenceBase() const
00275 {
00276 return dtEnd();
00277 }