libkcal Library API Documentation

incidencebase.cpp

00001 /*
00002     This file is part of libkcal.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
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   // The copied object is a new one, so it isn't observed by the observer
00060   // of the original object.
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; // no need to check further
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              // Don't compare lastModified, otherwise the operator is not
00092              // of much use. We are not comparing for identity, after all.
00093              doesFloat() == i2.doesFloat() &&
00094              duration() == i2.duration() &&
00095              hasDuration() == i2.hasDuration() &&
00096              pilotId() == i2.pilotId() &&
00097              syncStatus() == i2.syncStatus() );
00098     // no need to compare mObserver
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   // DON'T! updated() because we call this from
00118   // Calendar::updateEvent().
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   // we don't check for readonly here, because it is
00130   // possible that by setting the organizer we are changing
00131   // the event's readonly status...
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 //  if (mReadOnly) return;
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 //  kdDebug(5800) << "IncidenceBase::addAttendee()" << endl;
00193   if (mReadOnly) return;
00194 //  kdDebug(5800) << "IncidenceBase::addAttendee() weiter" << endl;
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 }
KDE Logo
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