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), mObserver(0)
00034 {
00035   setUid(CalFormat::createUniqueId());
00036 
00037   mAttendees.setAutoDelete( true );
00038 }
00039 
00040 IncidenceBase::IncidenceBase(const IncidenceBase &i)
00041 {
00042   mReadOnly = i.mReadOnly;
00043   mDtStart = i.mDtStart;
00044   mDuration = i.mDuration;
00045   mHasDuration = i.mHasDuration;
00046   mOrganizer = i.mOrganizer;
00047   mUid = i.mUid;
00048   QPtrList<Attendee> attendees = i.attendees();
00049   for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
00050     mAttendees.append( new Attendee( *a ) );
00051   }
00052   mFloats = i.mFloats;
00053   mLastModified = i.mLastModified;
00054   mPilotId = i.mPilotId;
00055   mSyncStatus = i.mSyncStatus;
00056 
00057   // The copied object is a new one, so it isn't observed by the observer
00058   // of the original object.
00059   mObserver = 0;
00060   
00061   mAttendees.setAutoDelete( true );
00062 }
00063 
00064 IncidenceBase::~IncidenceBase()
00065 {
00066 }
00067 
00068 void IncidenceBase::setUid(const QString &uid)
00069 {
00070   mUid = uid;
00071   updated();
00072 }
00073 
00074 QString IncidenceBase::uid() const
00075 {
00076   return mUid;
00077 }
00078 
00079 void IncidenceBase::setLastModified(const QDateTime &lm)
00080 {
00081   // DON'T! updated() because we call this from
00082   // Calendar::updateEvent().
00083   mLastModified = lm;
00084 }
00085 
00086 QDateTime IncidenceBase::lastModified() const
00087 {
00088   return mLastModified;
00089 }
00090 
00091 void IncidenceBase::setOrganizer(const QString &o)
00092 {
00093   // we don't check for readonly here, because it is
00094   // possible that by setting the organizer we are changing
00095   // the event's readonly status...
00096   mOrganizer = o;
00097   if (mOrganizer.left(7).upper() == "MAILTO:")
00098     mOrganizer = mOrganizer.remove(0,7);
00099 
00100   updated();
00101 }
00102 
00103 QString IncidenceBase::organizer() const
00104 {
00105   return mOrganizer;
00106 }
00107 
00108 void IncidenceBase::setReadOnly( bool readOnly )
00109 {
00110   mReadOnly = readOnly;
00111 }
00112 
00113 void IncidenceBase::setDtStart(const QDateTime &dtStart)
00114 {
00115 //  if (mReadOnly) return;
00116   mDtStart = dtStart;
00117   updated();
00118 }
00119 
00120 QDateTime IncidenceBase::dtStart() const
00121 {
00122   return mDtStart;
00123 }
00124 
00125 QString IncidenceBase::dtStartTimeStr() const
00126 {
00127   return KGlobal::locale()->formatTime(dtStart().time());
00128 }
00129 
00130 QString IncidenceBase::dtStartDateStr(bool shortfmt) const
00131 {
00132   return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
00133 }
00134 
00135 QString IncidenceBase::dtStartStr() const
00136 {
00137   return KGlobal::locale()->formatDateTime(dtStart());
00138 }
00139 
00140 
00141 bool IncidenceBase::doesFloat() const
00142 {
00143   return mFloats;
00144 }
00145 
00146 void IncidenceBase::setFloats(bool f)
00147 {
00148   if (mReadOnly) return;
00149   mFloats = f;
00150   updated();
00151 }
00152 
00153 
00154 void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
00155 {
00156 //  kdDebug(5800) << "IncidenceBase::addAttendee()" << endl;
00157   if (mReadOnly) return;
00158 //  kdDebug(5800) << "IncidenceBase::addAttendee() weiter" << endl;
00159   if (a->name().left(7).upper() == "MAILTO:")
00160     a->setName(a->name().remove(0,7));
00161 
00162   mAttendees.append(a);
00163   if (doupdate) updated();
00164 }
00165 
00166 #if 0
00167 void IncidenceBase::removeAttendee(Attendee *a)
00168 {
00169   if (mReadOnly) return;
00170   mAttendees.removeRef(a);
00171   updated();
00172 }
00173 
00174 void IncidenceBase::removeAttendee(const char *n)
00175 {
00176   Attendee *a;
00177 
00178   if (mReadOnly) return;
00179   for (a = mAttendees.first(); a; a = mAttendees.next())
00180     if (a->getName() == n) {
00181       mAttendees.remove();
00182       break;
00183     }
00184 }
00185 #endif
00186 
00187 void IncidenceBase::clearAttendees()
00188 {
00189   if (mReadOnly) return;
00190   mAttendees.clear();
00191 }
00192 
00193 #if 0
00194 Attendee *IncidenceBase::getAttendee(const char *n) const
00195 {
00196   QPtrListIterator<Attendee> qli(mAttendees);
00197 
00198   qli.toFirst();
00199   while (qli) {
00200     if (qli.current()->getName() == n)
00201       return qli.current();
00202     ++qli;
00203   }
00204   return 0L;
00205 }
00206 #endif
00207 
00208 Attendee *IncidenceBase::attendeeByMail(const QString &email)
00209 {
00210   QPtrListIterator<Attendee> qli(mAttendees);
00211 
00212   qli.toFirst();
00213   while (qli) {
00214     if (qli.current()->email() == email)
00215       return qli.current();
00216     ++qli;
00217   }
00218   return 0L;
00219 }
00220 
00221 Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, QString email)
00222 {
00223   QPtrListIterator<Attendee> qli(mAttendees);
00224 
00225   QStringList mails = emails;
00226   if (!email.isEmpty()) {
00227     mails.append(email);
00228   }
00229   qli.toFirst();
00230   while (qli) {
00231     for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
00232       if (qli.current()->email() == *it)
00233         return qli.current();
00234      }
00235 
00236     ++qli;
00237   }
00238   return 0L;
00239 }
00240 
00241 void IncidenceBase::setDuration(int seconds)
00242 {
00243   mDuration = seconds;
00244   setHasDuration(true);
00245 }
00246 
00247 int IncidenceBase::duration() const
00248 {
00249   return mDuration;
00250 }
00251 
00252 void IncidenceBase::setHasDuration(bool)
00253 {
00254   mHasDuration = true;
00255 }
00256 
00257 bool IncidenceBase::hasDuration() const
00258 {
00259   return mHasDuration;
00260 }
00261 
00262 void IncidenceBase::setSyncStatus(int stat)
00263 {
00264   if (mReadOnly) return;
00265   mSyncStatus = stat;
00266 }
00267 
00268 int IncidenceBase::syncStatus() const
00269 {
00270   return mSyncStatus;
00271 }
00272 
00273 void IncidenceBase::setPilotId( int id )
00274 {
00275   if (mReadOnly) return;
00276 
00277   mPilotId = id;
00278 }
00279 
00280 int IncidenceBase::pilotId() const
00281 {
00282   return mPilotId;
00283 }
00284 
00285 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
00286 {
00287   mObserver = observer;
00288 }
00289 
00290 void IncidenceBase::updated()
00291 {
00292   if ( mObserver ) {
00293     mObserver->incidenceUpdated( this );
00294   }
00295 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:27 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001