libkcal
incidencebase.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <kglobal.h>
00024 #include <klocale.h>
00025 #include <kdebug.h>
00026
00027 #include "calformat.h"
00028
00029 #include "incidencebase.h"
00030
00031 using namespace KCal;
00032
00033 IncidenceBase::IncidenceBase()
00034 : mReadOnly( false ), mFloats( true ), mDuration( 0 ), mHasDuration( false ),
00035 mPilotId( 0 ), mSyncStatus( SYNCMOD )
00036 {
00037 setUid( CalFormat::createUniqueId() );
00038
00039 mAttendees.setAutoDelete( true );
00040 }
00041
00042 IncidenceBase::IncidenceBase(const IncidenceBase &i) :
00043 CustomProperties( i )
00044 {
00045 mReadOnly = i.mReadOnly;
00046 mDtStart = i.mDtStart;
00047 mDuration = i.mDuration;
00048 mHasDuration = i.mHasDuration;
00049 mOrganizer = i.mOrganizer;
00050 mUid = i.mUid;
00051 Attendee::List attendees = i.attendees();
00052 Attendee::List::ConstIterator it;
00053 for( it = attendees.begin(); it != attendees.end(); ++it ) {
00054 mAttendees.append( new Attendee( *(*it) ) );
00055 }
00056 mFloats = i.mFloats;
00057 mLastModified = i.mLastModified;
00058 mPilotId = i.mPilotId;
00059 mSyncStatus = i.mSyncStatus;
00060 mComments = i.mComments;
00061
00062 mAttendees.setAutoDelete( true );
00063 }
00064
00065 IncidenceBase::~IncidenceBase()
00066 {
00067 }
00068
00069 IncidenceBase& IncidenceBase::operator=( const IncidenceBase& i )
00070 {
00071 CustomProperties::operator=( i );
00072 mReadOnly = i.mReadOnly;
00073 mDtStart = i.mDtStart;
00074 mDuration = i.mDuration;
00075 mHasDuration = i.mHasDuration;
00076 mOrganizer = i.mOrganizer;
00077 mUid = i.mUid;
00078 mAttendees.clear();
00079 Attendee::List attendees = i.attendees();
00080 Attendee::List::ConstIterator it;
00081 for( it = attendees.begin(); it != attendees.end(); ++it ) {
00082 mAttendees.append( new Attendee( *(*it) ) );
00083 }
00084 mFloats = i.mFloats;
00085 mLastModified = i.mLastModified;
00086 mPilotId = i.mPilotId;
00087 mSyncStatus = i.mSyncStatus;
00088 mComments = i.mComments;
00089
00090
00091
00092 mObservers.clear();
00093 return *this;
00094 }
00095
00096 bool IncidenceBase::operator==( const IncidenceBase& i2 ) const
00097 {
00098 if( attendees().count() != i2.attendees().count() ) {
00099 return false;
00100 }
00101
00102 Attendee::List al1 = attendees();
00103 Attendee::List al2 = i2.attendees();
00104 Attendee::List::ConstIterator a1 = al1.begin();
00105 Attendee::List::ConstIterator a2 = al2.begin();
00106 for( ; a1 != al1.end() && a2 != al2.end(); ++a1, ++a2 ) {
00107 if( **a1 == **a2 )
00108 continue;
00109 else {
00110 return false;
00111 }
00112 }
00113
00114 if ( !CustomProperties::operator==(i2) )
00115 return false;
00116
00117 return ( dtStart() == i2.dtStart() &&
00118 organizer() == i2.organizer() &&
00119 uid() == i2.uid() &&
00120
00121
00122 doesFloat() == i2.doesFloat() &&
00123 duration() == i2.duration() &&
00124 hasDuration() == i2.hasDuration() &&
00125 pilotId() == i2.pilotId() &&
00126 syncStatus() == i2.syncStatus() );
00127
00128 }
00129
00130
00131
00132
00133 void IncidenceBase::setUid(const QString &uid)
00134 {
00135 mUid = uid;
00136 updated();
00137 }
00138
00139 QString IncidenceBase::uid() const
00140 {
00141 return mUid;
00142 }
00143
00144 void IncidenceBase::setLastModified(const QDateTime &lm)
00145 {
00146
00147
00148
00149
00150 QDateTime current = lm;
00151 QTime t = current.time();
00152 t.setHMS( t.hour(), t.minute(), t.second(), 0 );
00153 current.setTime( t );
00154
00155 mLastModified = current;
00156 }
00157
00158 QDateTime IncidenceBase::lastModified() const
00159 {
00160 return mLastModified;
00161 }
00162
00163 void IncidenceBase::setOrganizer( const Person &o )
00164 {
00165
00166
00167
00168 mOrganizer = o;
00169
00170 updated();
00171 }
00172
00173 void IncidenceBase::setOrganizer(const QString &o)
00174 {
00175 QString mail( o );
00176 if ( mail.startsWith("MAILTO:", false) )
00177 mail = mail.remove( 0, 7 );
00178
00179 Person organizer( mail );
00180 setOrganizer( organizer );
00181 }
00182
00183 Person IncidenceBase::organizer() const
00184 {
00185 return mOrganizer;
00186 }
00187
00188 void IncidenceBase::setReadOnly( bool readOnly )
00189 {
00190 mReadOnly = readOnly;
00191 }
00192
00193 void IncidenceBase::setDtStart(const QDateTime &dtStart)
00194 {
00195
00196 mDtStart = dtStart;
00197 updated();
00198 }
00199
00200 QDateTime IncidenceBase::dtStart() const
00201 {
00202 return mDtStart;
00203 }
00204
00205 QString IncidenceBase::dtStartTimeStr() const
00206 {
00207 return KGlobal::locale()->formatTime(dtStart().time());
00208 }
00209
00210 QString IncidenceBase::dtStartDateStr(bool shortfmt) const
00211 {
00212 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
00213 }
00214
00215 QString IncidenceBase::dtStartStr() const
00216 {
00217 return KGlobal::locale()->formatDateTime(dtStart());
00218 }
00219
00220
00221 bool IncidenceBase::doesFloat() const
00222 {
00223 return mFloats;
00224 }
00225
00226 void IncidenceBase::setFloats(bool f)
00227 {
00228 if (mReadOnly) return;
00229 mFloats = f;
00230 updated();
00231 }
00232
00233
00234 void IncidenceBase::addComment(const QString& comment)
00235 {
00236 mComments += comment;
00237 }
00238
00239 bool IncidenceBase::removeComment( const QString& comment)
00240 {
00241 bool found = false;
00242 QStringList::Iterator i;
00243
00244 for ( i = mComments.begin(); !found && i != mComments.end(); ++i ) {
00245 if ( (*i) == comment ) {
00246 found = true;
00247 mComments.remove(i);
00248 }
00249 }
00250
00251 return found;
00252 }
00253
00254 void IncidenceBase::clearComments()
00255 {
00256 mComments.clear();
00257 }
00258
00259 QStringList IncidenceBase::comments() const
00260 {
00261 return mComments;
00262 }
00263
00264
00265 void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
00266 {
00267
00268 if (mReadOnly) return;
00269
00270 if (a->name().left(7).upper() == "MAILTO:")
00271 a->setName(a->name().remove(0,7));
00272
00273 mAttendees.append(a);
00274 if (doupdate) updated();
00275 }
00276
00277 #if 0
00278 void IncidenceBase::removeAttendee(Attendee *a)
00279 {
00280 if (mReadOnly) return;
00281 mAttendees.removeRef(a);
00282 updated();
00283 }
00284
00285 void IncidenceBase::removeAttendee(const char *n)
00286 {
00287 Attendee *a;
00288
00289 if (mReadOnly) return;
00290 for (a = mAttendees.first(); a; a = mAttendees.next())
00291 if (a->getName() == n) {
00292 mAttendees.remove();
00293 break;
00294 }
00295 }
00296 #endif
00297
00298 void IncidenceBase::clearAttendees()
00299 {
00300 if (mReadOnly) return;
00301 mAttendees.clear();
00302 }
00303
00304 Attendee *IncidenceBase::attendeeByMail( const QString &email ) const
00305 {
00306 Attendee::List::ConstIterator it;
00307 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00308 if ( (*it)->email() == email ) return *it;
00309 }
00310
00311 return 0;
00312 }
00313
00314 Attendee *IncidenceBase::attendeeByMails( const QStringList &emails,
00315 const QString &email) const
00316 {
00317 QStringList mails = emails;
00318 if ( !email.isEmpty() ) mails.append( email );
00319
00320 Attendee::List::ConstIterator itA;
00321 for( itA = mAttendees.begin(); itA != mAttendees.end(); ++itA ) {
00322 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
00323 if ( (*itA)->email() == (*it) ) return *itA;
00324 }
00325 }
00326
00327 return 0;
00328 }
00329
00330 Attendee *IncidenceBase::attendeeByUid( const QString &uid ) const
00331 {
00332 Attendee::List::ConstIterator it;
00333 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00334 if ( (*it)->uid() == uid ) return *it;
00335 }
00336
00337 return 0;
00338 }
00339
00340
00341 void IncidenceBase::setDuration(int seconds)
00342 {
00343 mDuration = seconds;
00344 setHasDuration(true);
00345 updated();
00346 }
00347
00348 int IncidenceBase::duration() const
00349 {
00350 return mDuration;
00351 }
00352
00353 void IncidenceBase::setHasDuration(bool hasDuration)
00354 {
00355 mHasDuration = hasDuration;
00356 }
00357
00358 bool IncidenceBase::hasDuration() const
00359 {
00360 return mHasDuration;
00361 }
00362
00363 void IncidenceBase::setSyncStatus(int stat)
00364 {
00365 if (mReadOnly) return;
00366 if ( mSyncStatus == stat ) return;
00367 mSyncStatus = stat;
00368 updatedSilent();
00369 }
00370 void IncidenceBase::setSyncStatusSilent(int stat)
00371 {
00372 if (mReadOnly) return;
00373 mSyncStatus = stat;
00374 }
00375
00376 int IncidenceBase::syncStatus() const
00377 {
00378 return mSyncStatus;
00379 }
00380
00381 void IncidenceBase::setPilotId( unsigned long id )
00382 {
00383 if (mReadOnly) return;
00384 if ( mPilotId == id) return;
00385 mPilotId = id;
00386 updatedSilent();
00387 }
00388
00389 unsigned long IncidenceBase::pilotId() const
00390 {
00391 return mPilotId;
00392 }
00393
00394 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
00395 {
00396 if( !mObservers.contains( observer ) ) mObservers.append( observer );
00397 }
00398
00399 void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
00400 {
00401 mObservers.remove( observer );
00402 }
00403
00404 void IncidenceBase::updated()
00405 {
00406 QPtrListIterator<Observer> it(mObservers);
00407 while( it.current() ) {
00408 Observer *o = it.current();
00409 ++it;
00410 o->incidenceUpdated( this );
00411 }
00412 }
00413
00414 void IncidenceBase::customPropertyUpdated()
00415 {
00416 updated();
00417 }
00418
00419 void IncidenceBase::updatedSilent()
00420 {
00421 QPtrListIterator<Observer> it(mObservers);
00422 while( it.current() ) {
00423 Observer *o = it.current();
00424 ++it;
00425 o->incidenceUpdatedSilent( this );
00426 }
00427 }
00428
|