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
00061
00062
00063 mObservers.clear();
00064
00065 mAttendees.setAutoDelete( true );
00066 }
00067
00068 IncidenceBase::~IncidenceBase()
00069 {
00070 }
00071
00072
00073 bool IncidenceBase::operator==( const IncidenceBase& i2 ) const
00074 {
00075 if( attendees().count() != i2.attendees().count() ) {
00076 return false;
00077 }
00078
00079 Attendee::List al1 = attendees();
00080 Attendee::List al2 = i2.attendees();
00081 Attendee::List::ConstIterator a1 = al1.begin();
00082 Attendee::List::ConstIterator a2 = al2.begin();
00083 for( ; a1 != al1.end() && a2 != al2.end(); ++a1, ++a2 ) {
00084 if( **a1 == **a2 )
00085 continue;
00086 else {
00087 return false;
00088 }
00089 }
00090
00091 if ( !CustomProperties::operator==(i2) )
00092 return false;
00093
00094 return ( dtStart() == i2.dtStart() &&
00095 organizer() == i2.organizer() &&
00096 uid() == i2.uid() &&
00097
00098
00099 doesFloat() == i2.doesFloat() &&
00100 duration() == i2.duration() &&
00101 hasDuration() == i2.hasDuration() &&
00102 pilotId() == i2.pilotId() &&
00103 syncStatus() == i2.syncStatus() );
00104
00105 }
00106
00107
00108
00109
00110 void IncidenceBase::setUid(const QString &uid)
00111 {
00112 mUid = uid;
00113 updated();
00114 }
00115
00116 QString IncidenceBase::uid() const
00117 {
00118 return mUid;
00119 }
00120
00121 void IncidenceBase::setLastModified(const QDateTime &lm)
00122 {
00123
00124
00125
00126
00127 QDateTime current = lm;
00128 QTime t = current.time();
00129 t.setHMS( t.hour(), t.minute(), t.second(), 0 );
00130 current.setTime( t );
00131
00132 mLastModified = current;
00133 }
00134
00135 QDateTime IncidenceBase::lastModified() const
00136 {
00137 return mLastModified;
00138 }
00139
00140 void IncidenceBase::setOrganizer( const Person &o )
00141 {
00142
00143
00144
00145 mOrganizer = o;
00146
00147 updated();
00148 }
00149
00150 void IncidenceBase::setOrganizer(const QString &o)
00151 {
00152 QString mail( o );
00153 if ( mail.startsWith("MAILTO:", false) )
00154 mail = mail.remove( 0, 7 );
00155
00156 Person organizer( mail );
00157 setOrganizer( organizer );
00158 }
00159
00160 Person IncidenceBase::organizer() const
00161 {
00162 return mOrganizer;
00163 }
00164
00165 void IncidenceBase::setReadOnly( bool readOnly )
00166 {
00167 mReadOnly = readOnly;
00168 }
00169
00170 void IncidenceBase::setDtStart(const QDateTime &dtStart)
00171 {
00172
00173 mDtStart = dtStart;
00174 updated();
00175 }
00176
00177 QDateTime IncidenceBase::dtStart() const
00178 {
00179 return mDtStart;
00180 }
00181
00182 QString IncidenceBase::dtStartTimeStr() const
00183 {
00184 return KGlobal::locale()->formatTime(dtStart().time());
00185 }
00186
00187 QString IncidenceBase::dtStartDateStr(bool shortfmt) const
00188 {
00189 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
00190 }
00191
00192 QString IncidenceBase::dtStartStr() const
00193 {
00194 return KGlobal::locale()->formatDateTime(dtStart());
00195 }
00196
00197
00198 bool IncidenceBase::doesFloat() const
00199 {
00200 return mFloats;
00201 }
00202
00203 void IncidenceBase::setFloats(bool f)
00204 {
00205 if (mReadOnly) return;
00206 mFloats = f;
00207 updated();
00208 }
00209
00210
00211 void IncidenceBase::addComment(const QString& comment)
00212 {
00213 mComments += comment;
00214 }
00215
00216 bool IncidenceBase::removeComment( const QString& comment)
00217 {
00218 bool found = false;
00219 QStringList::Iterator i;
00220
00221 for ( i = mComments.begin(); !found && i != mComments.end(); ++i ) {
00222 if ( (*i) == comment ) {
00223 found = true;
00224 mComments.remove(i);
00225 }
00226 }
00227
00228 return found;
00229 }
00230
00231 void IncidenceBase::clearComments()
00232 {
00233 mComments.clear();
00234 }
00235
00236 QStringList IncidenceBase::comments() const
00237 {
00238 return mComments;
00239 }
00240
00241
00242 void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
00243 {
00244
00245 if (mReadOnly) return;
00246
00247 if (a->name().left(7).upper() == "MAILTO:")
00248 a->setName(a->name().remove(0,7));
00249
00250 mAttendees.append(a);
00251 if (doupdate) updated();
00252 }
00253
00254 #if 0
00255 void IncidenceBase::removeAttendee(Attendee *a)
00256 {
00257 if (mReadOnly) return;
00258 mAttendees.removeRef(a);
00259 updated();
00260 }
00261
00262 void IncidenceBase::removeAttendee(const char *n)
00263 {
00264 Attendee *a;
00265
00266 if (mReadOnly) return;
00267 for (a = mAttendees.first(); a; a = mAttendees.next())
00268 if (a->getName() == n) {
00269 mAttendees.remove();
00270 break;
00271 }
00272 }
00273 #endif
00274
00275 void IncidenceBase::clearAttendees()
00276 {
00277 if (mReadOnly) return;
00278 mAttendees.clear();
00279 }
00280
00281 Attendee *IncidenceBase::attendeeByMail( const QString &email ) const
00282 {
00283 Attendee::List::ConstIterator it;
00284 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00285 if ( (*it)->email() == email ) return *it;
00286 }
00287
00288 return 0;
00289 }
00290
00291 Attendee *IncidenceBase::attendeeByMails( const QStringList &emails,
00292 const QString &email) const
00293 {
00294 QStringList mails = emails;
00295 if ( !email.isEmpty() ) mails.append( email );
00296
00297 Attendee::List::ConstIterator itA;
00298 for( itA = mAttendees.begin(); itA != mAttendees.end(); ++itA ) {
00299 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
00300 if ( (*itA)->email() == (*it) ) return *itA;
00301 }
00302 }
00303
00304 return 0;
00305 }
00306
00307 Attendee *IncidenceBase::attendeeByUid( const QString &uid ) const
00308 {
00309 Attendee::List::ConstIterator it;
00310 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00311 if ( (*it)->uid() == uid ) return *it;
00312 }
00313
00314 return 0;
00315 }
00316
00317
00318 void IncidenceBase::setDuration(int seconds)
00319 {
00320 mDuration = seconds;
00321 setHasDuration(true);
00322 updated();
00323 }
00324
00325 int IncidenceBase::duration() const
00326 {
00327 return mDuration;
00328 }
00329
00330 void IncidenceBase::setHasDuration(bool hasDuration)
00331 {
00332 mHasDuration = hasDuration;
00333 }
00334
00335 bool IncidenceBase::hasDuration() const
00336 {
00337 return mHasDuration;
00338 }
00339
00340 void IncidenceBase::setSyncStatus(int stat)
00341 {
00342 if (mReadOnly) return;
00343 mSyncStatus = stat;
00344 }
00345
00346 int IncidenceBase::syncStatus() const
00347 {
00348 return mSyncStatus;
00349 }
00350
00351 void IncidenceBase::setPilotId( unsigned long id )
00352 {
00353 if (mReadOnly) return;
00354 mPilotId = id;
00355 updated();
00356 }
00357
00358 unsigned long IncidenceBase::pilotId() const
00359 {
00360 return mPilotId;
00361 }
00362
00363 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
00364 {
00365 if( !mObservers.contains( observer ) ) mObservers.append( observer );
00366 }
00367
00368 void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
00369 {
00370 mObservers.remove( observer );
00371 }
00372
00373 void IncidenceBase::updated()
00374 {
00375 QPtrListIterator<Observer> it(mObservers);
00376 while( it.current() ) {
00377 Observer *o = it.current();
00378 ++it;
00379 o->incidenceUpdated( this );
00380 }
00381 }
00382
00383 void IncidenceBase::customPropertyUpdated()
00384 {
00385 updated();
00386 }
|