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 
00120   // Remove milliseconds part.
00121   QDateTime current = lm;
00122   QTime t = current.time();
00123   t.setHMS( t.hour(), t.minute(), t.second(), 0 );
00124   current.setTime( t );
00125 
00126   mLastModified = current;
00127 }
00128 
00129 QDateTime IncidenceBase::lastModified() const
00130 {
00131   return mLastModified;
00132 }
00133 
00134 void IncidenceBase::setOrganizer(const QString &o)
00135 {
00136   // we don't check for readonly here, because it is
00137   // possible that by setting the organizer we are changing
00138   // the event's readonly status...
00139   mOrganizer = o;
00140   if (mOrganizer.left(7).upper() == "MAILTO:")
00141     mOrganizer = mOrganizer.remove(0,7);
00142 
00143   updated();
00144 }
00145 
00146 QString IncidenceBase::organizer() const
00147 {
00148   return mOrganizer;
00149 }
00150 
00151 void IncidenceBase::setReadOnly( bool readOnly )
00152 {
00153   mReadOnly = readOnly;
00154 }
00155 
00156 void IncidenceBase::setDtStart(const QDateTime &dtStart)
00157 {
00158 //  if (mReadOnly) return;
00159   mDtStart = dtStart;
00160   updated();
00161 }
00162 
00163 QDateTime IncidenceBase::dtStart() const
00164 {
00165   return mDtStart;
00166 }
00167 
00168 QString IncidenceBase::dtStartTimeStr() const
00169 {
00170   return KGlobal::locale()->formatTime(dtStart().time());
00171 }
00172 
00173 QString IncidenceBase::dtStartDateStr(bool shortfmt) const
00174 {
00175   return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
00176 }
00177 
00178 QString IncidenceBase::dtStartStr() const
00179 {
00180   return KGlobal::locale()->formatDateTime(dtStart());
00181 }
00182 
00183 
00184 bool IncidenceBase::doesFloat() const
00185 {
00186   return mFloats;
00187 }
00188 
00189 void IncidenceBase::setFloats(bool f)
00190 {
00191   if (mReadOnly) return;
00192   mFloats = f;
00193   updated();
00194 }
00195 
00196 
00197 void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
00198 {
00199 //  kdDebug(5800) << "IncidenceBase::addAttendee()" << endl;
00200   if (mReadOnly) return;
00201 //  kdDebug(5800) << "IncidenceBase::addAttendee() weiter" << endl;
00202   if (a->name().left(7).upper() == "MAILTO:")
00203     a->setName(a->name().remove(0,7));
00204 
00205   mAttendees.append(a);
00206   if (doupdate) updated();
00207 }
00208 
00209 #if 0
00210 void IncidenceBase::removeAttendee(Attendee *a)
00211 {
00212   if (mReadOnly) return;
00213   mAttendees.removeRef(a);
00214   updated();
00215 }
00216 
00217 void IncidenceBase::removeAttendee(const char *n)
00218 {
00219   Attendee *a;
00220 
00221   if (mReadOnly) return;
00222   for (a = mAttendees.first(); a; a = mAttendees.next())
00223     if (a->getName() == n) {
00224       mAttendees.remove();
00225       break;
00226     }
00227 }
00228 #endif
00229 
00230 void IncidenceBase::clearAttendees()
00231 {
00232   if (mReadOnly) return;
00233   mAttendees.clear();
00234 }
00235 
00236 Attendee *IncidenceBase::attendeeByMail( const QString &email )
00237 {
00238   Attendee::List::ConstIterator it;
00239   for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00240     if ( (*it)->email() == email ) return *it;
00241   }
00242 
00243   return 0;
00244 }
00245 
00246 Attendee *IncidenceBase::attendeeByMails( const QStringList &emails,
00247                                           const QString &email)
00248 {
00249   QStringList mails = emails;
00250   if ( !email.isEmpty() ) mails.append( email );
00251 
00252   Attendee::List::ConstIterator itA;
00253   for( itA = mAttendees.begin(); itA != mAttendees.end(); ++itA ) {
00254     for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
00255       if ( (*itA)->email() == email ) return *itA;
00256     }
00257   }
00258 
00259   return 0;
00260 }
00261 
00262 void IncidenceBase::setDuration(int seconds)
00263 {
00264   mDuration = seconds;
00265   setHasDuration(true);
00266 }
00267 
00268 int IncidenceBase::duration() const
00269 {
00270   return mDuration;
00271 }
00272 
00273 void IncidenceBase::setHasDuration(bool)
00274 {
00275   mHasDuration = true;
00276 }
00277 
00278 bool IncidenceBase::hasDuration() const
00279 {
00280   return mHasDuration;
00281 }
00282 
00283 void IncidenceBase::setSyncStatus(int stat)
00284 {
00285   if (mReadOnly) return;
00286   mSyncStatus = stat;
00287 }
00288 
00289 int IncidenceBase::syncStatus() const
00290 {
00291   return mSyncStatus;
00292 }
00293 
00294 void IncidenceBase::setPilotId( int id )
00295 {
00296   if (mReadOnly) return;
00297 
00298   mPilotId = id;
00299 }
00300 
00301 int IncidenceBase::pilotId() const
00302 {
00303   return mPilotId;
00304 }
00305 
00306 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
00307 {
00308   if( !mObservers.contains(observer) ) mObservers.append( observer );
00309 }
00310 
00311 void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
00312 {
00313   mObservers.remove( observer );
00314 }
00315 
00316 void IncidenceBase::updated()
00317 {
00318   QPtrListIterator<Observer> it(mObservers);
00319   while( it.current() ) {
00320     Observer *o = it.current();
00321     ++it;
00322     o->incidenceUpdated( this );
00323   }
00324 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:22 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003