incidencebase.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kglobal.h>
00022 #include <klocale.h>
00023 #include <kdebug.h>
00024
00025 #include "calformat.h"
00026
00027 #include "incidencebase.h"
00028
00029 using namespace KCal;
00030
00031 IncidenceBase::IncidenceBase() :
00032 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
00033 mPilotId(0), mSyncStatus(SYNCMOD)
00034 {
00035 setUid(CalFormat::createUniqueId());
00036
00037 mAttendees.setAutoDelete( true );
00038 }
00039
00040 IncidenceBase::IncidenceBase(const IncidenceBase &i) :
00041 CustomProperties( i )
00042 {
00043 mReadOnly = i.mReadOnly;
00044 mDtStart = i.mDtStart;
00045 mDuration = i.mDuration;
00046 mHasDuration = i.mHasDuration;
00047 mOrganizer = i.mOrganizer;
00048 mUid = i.mUid;
00049 Attendee::List attendees = i.attendees();
00050 Attendee::List::ConstIterator it;
00051 for( it = attendees.begin(); it != attendees.end(); ++it ) {
00052 mAttendees.append( new Attendee( *(*it) ) );
00053 }
00054 mFloats = i.mFloats;
00055 mLastModified = i.mLastModified;
00056 mPilotId = i.mPilotId;
00057 mSyncStatus = i.mSyncStatus;
00058
00059
00060
00061 mObservers.clear();
00062
00063 mAttendees.setAutoDelete( true );
00064 }
00065
00066 IncidenceBase::~IncidenceBase()
00067 {
00068 }
00069
00070
00071 bool IncidenceBase::operator==( const IncidenceBase& i2 ) const
00072 {
00073 if( attendees().count() != i2.attendees().count() ) {
00074 return false;
00075 }
00076
00077 Attendee::List al1 = attendees();
00078 Attendee::List al2 = i2.attendees();
00079 Attendee::List::ConstIterator a1 = al1.begin();
00080 Attendee::List::ConstIterator a2 = al2.begin();
00081 for( ; a1 != al1.end() && a2 != al2.end(); ++a1, ++a2 )
00082 if( **a1 == **a2 )
00083 continue;
00084 else {
00085 return false;
00086 }
00087
00088 return ( dtStart() == i2.dtStart() &&
00089 organizer() == i2.organizer() &&
00090 uid() == i2.uid() &&
00091
00092
00093 doesFloat() == i2.doesFloat() &&
00094 duration() == i2.duration() &&
00095 hasDuration() == i2.hasDuration() &&
00096 pilotId() == i2.pilotId() &&
00097 syncStatus() == i2.syncStatus() );
00098
00099 }
00100
00101
00102
00103
00104 void IncidenceBase::setUid(const QString &uid)
00105 {
00106 mUid = uid;
00107 updated();
00108 }
00109
00110 QString IncidenceBase::uid() const
00111 {
00112 return mUid;
00113 }
00114
00115 void IncidenceBase::setLastModified(const QDateTime &lm)
00116 {
00117
00118
00119 mLastModified = lm;
00120 }
00121
00122 QDateTime IncidenceBase::lastModified() const
00123 {
00124 return mLastModified;
00125 }
00126
00127 void IncidenceBase::setOrganizer(const QString &o)
00128 {
00129
00130
00131
00132 mOrganizer = o;
00133 if (mOrganizer.left(7).upper() == "MAILTO:")
00134 mOrganizer = mOrganizer.remove(0,7);
00135
00136 updated();
00137 }
00138
00139 QString IncidenceBase::organizer() const
00140 {
00141 return mOrganizer;
00142 }
00143
00144 void IncidenceBase::setReadOnly( bool readOnly )
00145 {
00146 mReadOnly = readOnly;
00147 }
00148
00149 void IncidenceBase::setDtStart(const QDateTime &dtStart)
00150 {
00151
00152 mDtStart = dtStart;
00153 updated();
00154 }
00155
00156 QDateTime IncidenceBase::dtStart() const
00157 {
00158 return mDtStart;
00159 }
00160
00161 QString IncidenceBase::dtStartTimeStr() const
00162 {
00163 return KGlobal::locale()->formatTime(dtStart().time());
00164 }
00165
00166 QString IncidenceBase::dtStartDateStr(bool shortfmt) const
00167 {
00168 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
00169 }
00170
00171 QString IncidenceBase::dtStartStr() const
00172 {
00173 return KGlobal::locale()->formatDateTime(dtStart());
00174 }
00175
00176
00177 bool IncidenceBase::doesFloat() const
00178 {
00179 return mFloats;
00180 }
00181
00182 void IncidenceBase::setFloats(bool f)
00183 {
00184 if (mReadOnly) return;
00185 mFloats = f;
00186 updated();
00187 }
00188
00189
00190 void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
00191 {
00192
00193 if (mReadOnly) return;
00194
00195 if (a->name().left(7).upper() == "MAILTO:")
00196 a->setName(a->name().remove(0,7));
00197
00198 mAttendees.append(a);
00199 if (doupdate) updated();
00200 }
00201
00202 #if 0
00203 void IncidenceBase::removeAttendee(Attendee *a)
00204 {
00205 if (mReadOnly) return;
00206 mAttendees.removeRef(a);
00207 updated();
00208 }
00209
00210 void IncidenceBase::removeAttendee(const char *n)
00211 {
00212 Attendee *a;
00213
00214 if (mReadOnly) return;
00215 for (a = mAttendees.first(); a; a = mAttendees.next())
00216 if (a->getName() == n) {
00217 mAttendees.remove();
00218 break;
00219 }
00220 }
00221 #endif
00222
00223 void IncidenceBase::clearAttendees()
00224 {
00225 if (mReadOnly) return;
00226 mAttendees.clear();
00227 }
00228
00229 Attendee *IncidenceBase::attendeeByMail( const QString &email )
00230 {
00231 Attendee::List::ConstIterator it;
00232 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00233 if ( (*it)->email() == email ) return *it;
00234 }
00235
00236 return 0;
00237 }
00238
00239 Attendee *IncidenceBase::attendeeByMails( const QStringList &emails,
00240 const QString &email)
00241 {
00242 QStringList mails = emails;
00243 if ( !email.isEmpty() ) mails.append( email );
00244
00245 Attendee::List::ConstIterator itA;
00246 for( itA = mAttendees.begin(); itA != mAttendees.end(); ++itA ) {
00247 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
00248 if ( (*itA)->email() == email ) return *itA;
00249 }
00250 }
00251
00252 return 0;
00253 }
00254
00255 void IncidenceBase::setDuration(int seconds)
00256 {
00257 mDuration = seconds;
00258 setHasDuration(true);
00259 }
00260
00261 int IncidenceBase::duration() const
00262 {
00263 return mDuration;
00264 }
00265
00266 void IncidenceBase::setHasDuration(bool)
00267 {
00268 mHasDuration = true;
00269 }
00270
00271 bool IncidenceBase::hasDuration() const
00272 {
00273 return mHasDuration;
00274 }
00275
00276 void IncidenceBase::setSyncStatus(int stat)
00277 {
00278 if (mReadOnly) return;
00279 mSyncStatus = stat;
00280 }
00281
00282 int IncidenceBase::syncStatus() const
00283 {
00284 return mSyncStatus;
00285 }
00286
00287 void IncidenceBase::setPilotId( int id )
00288 {
00289 if (mReadOnly) return;
00290
00291 mPilotId = id;
00292 }
00293
00294 int IncidenceBase::pilotId() const
00295 {
00296 return mPilotId;
00297 }
00298
00299 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
00300 {
00301 if( !mObservers.contains(observer) ) mObservers.append( observer );
00302 }
00303
00304 void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
00305 {
00306 mObservers.remove( observer );
00307 }
00308
00309 void IncidenceBase::updated()
00310 {
00311 QPtrListIterator<Observer> it(mObservers);
00312 while( it.current() ) {
00313 Observer *o = it.current();
00314 ++it;
00315 o->incidenceUpdated( this );
00316 }
00317 }
This file is part of the documentation for libkcal Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Mar 6 17:18:03 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003