libkcal Library API Documentation

incidencebase.cpp

00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2001,2004 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include <kglobal.h> 00023 #include <klocale.h> 00024 #include <kdebug.h> 00025 00026 #include "calformat.h" 00027 00028 #include "incidencebase.h" 00029 00030 using namespace KCal; 00031 00032 IncidenceBase::IncidenceBase() 00033 : mReadOnly( false ), mFloats( true ), mDuration( 0 ), mHasDuration( false ), 00034 mPilotId( 0 ), mSyncStatus( SYNCMOD ) 00035 { 00036 setUid( CalFormat::createUniqueId() ); 00037 00038 mAttendees.setAutoDelete( true ); 00039 } 00040 00041 IncidenceBase::IncidenceBase(const IncidenceBase &i) : 00042 CustomProperties( i ) 00043 { 00044 mReadOnly = i.mReadOnly; 00045 mDtStart = i.mDtStart; 00046 mDuration = i.mDuration; 00047 mHasDuration = i.mHasDuration; 00048 mOrganizer = i.mOrganizer; 00049 mUid = i.mUid; 00050 Attendee::List attendees = i.attendees(); 00051 Attendee::List::ConstIterator it; 00052 for( it = attendees.begin(); it != attendees.end(); ++it ) { 00053 mAttendees.append( new Attendee( *(*it) ) ); 00054 } 00055 mFloats = i.mFloats; 00056 mLastModified = i.mLastModified; 00057 mPilotId = i.mPilotId; 00058 mSyncStatus = i.mSyncStatus; 00059 00060 // The copied object is a new one, so it isn't observed by the observer 00061 // of the original object. 00062 mObservers.clear(); 00063 00064 mAttendees.setAutoDelete( true ); 00065 } 00066 00067 IncidenceBase::~IncidenceBase() 00068 { 00069 } 00070 00071 00072 bool IncidenceBase::operator==( const IncidenceBase& i2 ) const 00073 { 00074 if( attendees().count() != i2.attendees().count() ) { 00075 return false; // no need to check further 00076 } 00077 00078 Attendee::List al1 = attendees(); 00079 Attendee::List al2 = i2.attendees(); 00080 Attendee::List::ConstIterator a1 = al1.begin(); 00081 Attendee::List::ConstIterator a2 = al2.begin(); 00082 for( ; a1 != al1.end() && a2 != al2.end(); ++a1, ++a2 ) { 00083 if( **a1 == **a2 ) 00084 continue; 00085 else { 00086 return false; 00087 } 00088 } 00089 00090 return ( dtStart() == i2.dtStart() && 00091 organizer() == i2.organizer() && 00092 uid() == i2.uid() && 00093 // Don't compare lastModified, otherwise the operator is not 00094 // of much use. We are not comparing for identity, after all. 00095 doesFloat() == i2.doesFloat() && 00096 duration() == i2.duration() && 00097 hasDuration() == i2.hasDuration() && 00098 pilotId() == i2.pilotId() && 00099 syncStatus() == i2.syncStatus() ); 00100 // no need to compare mObserver 00101 } 00102 00103 00104 00105 00106 void IncidenceBase::setUid(const QString &uid) 00107 { 00108 mUid = uid; 00109 updated(); 00110 } 00111 00112 QString IncidenceBase::uid() const 00113 { 00114 return mUid; 00115 } 00116 00117 void IncidenceBase::setLastModified(const QDateTime &lm) 00118 { 00119 // DON'T! updated() because we call this from 00120 // Calendar::updateEvent(). 00121 00122 // Remove milliseconds part. 00123 QDateTime current = lm; 00124 QTime t = current.time(); 00125 t.setHMS( t.hour(), t.minute(), t.second(), 0 ); 00126 current.setTime( t ); 00127 00128 mLastModified = current; 00129 } 00130 00131 QDateTime IncidenceBase::lastModified() const 00132 { 00133 return mLastModified; 00134 } 00135 00136 void IncidenceBase::setOrganizer(const QString &o) 00137 { 00138 // we don't check for readonly here, because it is 00139 // possible that by setting the organizer we are changing 00140 // the event's readonly status... 00141 mOrganizer = o; 00142 if (mOrganizer.left(7).upper() == "MAILTO:") 00143 mOrganizer = mOrganizer.remove(0,7); 00144 00145 updated(); 00146 } 00147 00148 QString IncidenceBase::organizer() const 00149 { 00150 return mOrganizer; 00151 } 00152 00153 void IncidenceBase::setReadOnly( bool readOnly ) 00154 { 00155 mReadOnly = readOnly; 00156 } 00157 00158 void IncidenceBase::setDtStart(const QDateTime &dtStart) 00159 { 00160 // if (mReadOnly) return; 00161 mDtStart = dtStart; 00162 updated(); 00163 } 00164 00165 QDateTime IncidenceBase::dtStart() const 00166 { 00167 return mDtStart; 00168 } 00169 00170 QString IncidenceBase::dtStartTimeStr() const 00171 { 00172 return KGlobal::locale()->formatTime(dtStart().time()); 00173 } 00174 00175 QString IncidenceBase::dtStartDateStr(bool shortfmt) const 00176 { 00177 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 00178 } 00179 00180 QString IncidenceBase::dtStartStr() const 00181 { 00182 return KGlobal::locale()->formatDateTime(dtStart()); 00183 } 00184 00185 00186 bool IncidenceBase::doesFloat() const 00187 { 00188 return mFloats; 00189 } 00190 00191 void IncidenceBase::setFloats(bool f) 00192 { 00193 if (mReadOnly) return; 00194 mFloats = f; 00195 updated(); 00196 } 00197 00198 00199 void IncidenceBase::addComment(const QString& comment) 00200 { 00201 mComments += comment; 00202 } 00203 00204 bool IncidenceBase::removeComment(QString& comment) 00205 { 00206 bool found = false; 00207 QStringList::Iterator i; 00208 00209 for ( i = mComments.begin(); !found && i != mComments.end(); ++i ) { 00210 if ( (*i) == comment) { 00211 found = true; 00212 mComments.remove(i); 00213 } 00214 } 00215 00216 return found; 00217 } 00218 00219 void IncidenceBase::clearComments() 00220 { 00221 mComments.clear(); 00222 } 00223 00224 QStringList IncidenceBase::comments() const 00225 { 00226 return mComments; 00227 } 00228 00229 00230 void IncidenceBase::addAttendee(Attendee *a, bool doupdate) 00231 { 00232 // kdDebug(5800) << "IncidenceBase::addAttendee()" << endl; 00233 if (mReadOnly) return; 00234 // kdDebug(5800) << "IncidenceBase::addAttendee() weiter" << endl; 00235 if (a->name().left(7).upper() == "MAILTO:") 00236 a->setName(a->name().remove(0,7)); 00237 00238 mAttendees.append(a); 00239 if (doupdate) updated(); 00240 } 00241 00242 #if 0 00243 void IncidenceBase::removeAttendee(Attendee *a) 00244 { 00245 if (mReadOnly) return; 00246 mAttendees.removeRef(a); 00247 updated(); 00248 } 00249 00250 void IncidenceBase::removeAttendee(const char *n) 00251 { 00252 Attendee *a; 00253 00254 if (mReadOnly) return; 00255 for (a = mAttendees.first(); a; a = mAttendees.next()) 00256 if (a->getName() == n) { 00257 mAttendees.remove(); 00258 break; 00259 } 00260 } 00261 #endif 00262 00263 void IncidenceBase::clearAttendees() 00264 { 00265 if (mReadOnly) return; 00266 mAttendees.clear(); 00267 } 00268 00269 Attendee *IncidenceBase::attendeeByMail( const QString &email ) const 00270 { 00271 Attendee::List::ConstIterator it; 00272 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) { 00273 if ( (*it)->email() == email ) return *it; 00274 } 00275 00276 return 0; 00277 } 00278 00279 Attendee *IncidenceBase::attendeeByMails( const QStringList &emails, 00280 const QString &email) const 00281 { 00282 QStringList mails = emails; 00283 if ( !email.isEmpty() ) mails.append( email ); 00284 00285 Attendee::List::ConstIterator itA; 00286 for( itA = mAttendees.begin(); itA != mAttendees.end(); ++itA ) { 00287 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 00288 if ( (*itA)->email() == (*it) ) return *itA; 00289 } 00290 } 00291 00292 return 0; 00293 } 00294 00295 Attendee *IncidenceBase::attendeeByUid( const QString &uid ) const 00296 { 00297 Attendee::List::ConstIterator it; 00298 for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) { 00299 if ( (*it)->uid() == uid ) return *it; 00300 } 00301 00302 return 0; 00303 } 00304 00305 00306 void IncidenceBase::setDuration(int seconds) 00307 { 00308 mDuration = seconds; 00309 setHasDuration(true); 00310 updated(); 00311 } 00312 00313 int IncidenceBase::duration() const 00314 { 00315 return mDuration; 00316 } 00317 00318 void IncidenceBase::setHasDuration(bool hasDuration) 00319 { 00320 mHasDuration = hasDuration; 00321 } 00322 00323 bool IncidenceBase::hasDuration() const 00324 { 00325 return mHasDuration; 00326 } 00327 00328 void IncidenceBase::setSyncStatus(int stat) 00329 { 00330 if (mReadOnly) return; 00331 mSyncStatus = stat; 00332 } 00333 00334 int IncidenceBase::syncStatus() const 00335 { 00336 return mSyncStatus; 00337 } 00338 00339 void IncidenceBase::setPilotId( unsigned long id ) 00340 { 00341 if (mReadOnly) return; 00342 00343 mPilotId = id; 00344 } 00345 00346 unsigned long IncidenceBase::pilotId() const 00347 { 00348 return mPilotId; 00349 } 00350 00351 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 00352 { 00353 if( !mObservers.contains( observer ) ) mObservers.append( observer ); 00354 } 00355 00356 void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 00357 { 00358 mObservers.remove( observer ); 00359 } 00360 00361 void IncidenceBase::updated() 00362 { 00363 QPtrListIterator<Observer> it(mObservers); 00364 while( it.current() ) { 00365 Observer *o = it.current(); 00366 ++it; 00367 o->incidenceUpdated( this ); 00368 } 00369 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:42 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003