libkcal

incidence.cpp

00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <kglobal.h>
00024 #include <klocale.h>
00025 #include <kdebug.h>
00026 
00027 #include "calformat.h"
00028 
00029 #include "incidence.h"
00030 #include "calendar.h"
00031 
00032 using namespace KCal;
00033 
00034 Incidence::Incidence() :
00035   IncidenceBase(),
00036   mRelatedTo(0), mStatus(StatusNone), mSecrecy(SecrecyPublic),
00037   mPriority(0), mRecurrence(0),
00038   mHasRecurrenceID( false ), mChildRecurrenceEvents()
00039 {
00040   recreate();
00041 
00042   mAlarms.setAutoDelete(true);
00043   mAttachments.setAutoDelete(true);
00044 }
00045 
00046 Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ),Recurrence::Observer()
00047 {
00048 // TODO: reenable attributes currently commented out.
00049   mRevision = i.mRevision;
00050   mCreated = i.mCreated;
00051   mDescription = i.mDescription;
00052   mSummary = i.mSummary;
00053   mCategories = i.mCategories;
00054 //  Incidence *mRelatedTo;          Incidence *mRelatedTo;
00055   mRelatedTo = 0;
00056   mRelatedToUid = i.mRelatedToUid;
00057 //  Incidence::List mRelations;    Incidence::List mRelations;
00058   mResources = i.mResources;
00059   mStatusString = i.mStatusString;
00060   mStatus = i.mStatus;
00061   mSecrecy = i.mSecrecy;
00062   mPriority = i.mPriority;
00063   mLocation = i.mLocation;
00064   mRecurrenceID = i.mRecurrenceID;
00065   mHasRecurrenceID = i.mHasRecurrenceID;
00066   mChildRecurrenceEvents = i.mChildRecurrenceEvents;
00067 
00068   // Alarms and Attachments are stored in ListBase<...>, which is a TQValueList<...*>.
00069   // We need to really duplicate the objects stored therein, otherwise deleting
00070   // i will also delete all attachments from this object (setAutoDelete...)
00071   Alarm::List::ConstIterator it;
00072   for( it = i.mAlarms.begin(); it != i.mAlarms.end(); ++it ) {
00073     Alarm *b = new Alarm( **it );
00074     b->setParent( this );
00075     mAlarms.append( b );
00076   }
00077   mAlarms.setAutoDelete(true);
00078 
00079   Attachment::List::ConstIterator it1;
00080   for ( it1 = i.mAttachments.begin(); it1 != i.mAttachments.end(); ++it1 ) {
00081     Attachment *a = new Attachment( **it1 );
00082     mAttachments.append( a );
00083   }
00084   mAttachments.setAutoDelete( true );
00085 
00086   if (i.mRecurrence) {
00087     mRecurrence = new Recurrence( *(i.mRecurrence) );
00088     mRecurrence->addObserver( this );
00089   } else
00090     mRecurrence = 0;
00091 
00092   mSchedulingID = i.mSchedulingID;
00093 }
00094 
00095 Incidence::~Incidence()
00096 {
00097     Incidence::List Relations = mRelations;
00098     List::ConstIterator it;
00099     for ( it = Relations.begin(); it != Relations.end(); ++it ) {
00100         if ( (*it)->relatedTo() == this ) (*it)->mRelatedTo = 0;
00101     }
00102     if ( relatedTo() ) relatedTo()->removeRelation( this );
00103 
00104     delete mRecurrence;
00105 }
00106 
00107 // A string comparison that considers that null and empty are the same
00108 static bool stringCompare( const TQString& s1, const TQString& s2 )
00109 {
00110   return ( s1.isEmpty() && s2.isEmpty() ) || (s1 == s2);
00111 }
00112 
00113 Incidence& Incidence::operator=( const Incidence &i )
00114 {
00115   if ( &i == this )
00116     return *this;
00117   IncidenceBase::operator=( i );
00118   mRevision = i.mRevision;
00119   mCreated = i.mCreated;
00120   mDescription = i.mDescription;
00121   mSummary = i.mSummary;
00122   mCategories = i.mCategories;
00123   mRelatedTo = 0;
00124   mRelatedToUid = i.mRelatedToUid;
00125   mRelations.clear();
00126   mResources = i.mResources;
00127   mStatusString = i.mStatusString;
00128   mStatus = i.mStatus;
00129   mSecrecy = i.mSecrecy;
00130   mPriority = i.mPriority;
00131   mLocation = i.mLocation;
00132   mRecurrenceID = i.mRecurrenceID;
00133   mHasRecurrenceID = i.mHasRecurrenceID;
00134   mChildRecurrenceEvents = i.mChildRecurrenceEvents;
00135 
00136   mAlarms.clearAll();
00137   Alarm::List::ConstIterator it;
00138   for( it = i.mAlarms.begin(); it != i.mAlarms.end(); ++it ) {
00139     Alarm *b = new Alarm( **it );
00140     b->setParent( this );
00141     mAlarms.append( b );
00142   }
00143 
00144   mAttachments.clearAll();
00145   Attachment::List::ConstIterator it1;
00146   for ( it1 = i.mAttachments.begin(); it1 != i.mAttachments.end(); ++it1 ) {
00147     Attachment *a = new Attachment( **it1 );
00148     mAttachments.append( a );
00149   }
00150 
00151   delete mRecurrence;
00152   if (i.mRecurrence) {
00153     mRecurrence = new Recurrence( *(i.mRecurrence) );
00154     mRecurrence->addObserver( this );
00155   } else
00156     mRecurrence = 0;
00157 
00158   mSchedulingID = i.mSchedulingID;
00159   return *this;
00160 }
00161 
00162 bool Incidence::operator==( const Incidence& i2 ) const
00163 {
00164     if( alarms().count() != i2.alarms().count() ) {
00165         return false; // no need to check further
00166     }
00167 
00168     Alarm::List::ConstIterator a1 = alarms().begin();
00169     Alarm::List::ConstIterator a2 = i2.alarms().begin();
00170     for( ; a1 != alarms().end() && a2 != i2.alarms().end(); ++a1, ++a2 )
00171         if( **a1 == **a2 )
00172             continue;
00173         else {
00174             return false;
00175         }
00176 
00177     if ( !IncidenceBase::operator==(i2) )
00178         return false;
00179 
00180     bool recurrenceEqual = ( mRecurrence == 0 && i2.mRecurrence == 0 );
00181     if ( !recurrenceEqual )
00182     {
00183         recurrenceEqual = mRecurrence != 0 &&
00184                           i2.mRecurrence != 0 &&
00185                           *mRecurrence == *i2.mRecurrence;
00186     }
00187 
00188     return
00189         recurrenceEqual &&
00190         created() == i2.created() &&
00191         stringCompare( description(), i2.description() ) &&
00192         stringCompare( summary(), i2.summary() ) &&
00193         categories() == i2.categories() &&
00194         // no need to compare mRelatedTo
00195         stringCompare( relatedToUid(), i2.relatedToUid() ) &&
00196         relations() == i2.relations() &&
00197         attachments() == i2.attachments() &&
00198         resources() == i2.resources() &&
00199         mStatus == i2.mStatus &&
00200         ( mStatus == StatusNone || stringCompare( mStatusString, i2.mStatusString ) ) &&
00201         secrecy() == i2.secrecy() &&
00202         priority() == i2.priority() &&
00203         stringCompare( location(), i2.location() ) &&
00204         stringCompare( schedulingID(), i2.schedulingID() );
00205 }
00206 
00207 
00208 void Incidence::recreate()
00209 {
00210   setCreated(TQDateTime::currentDateTime());
00211 
00212   setUid(CalFormat::createUniqueId());
00213   setSchedulingID( TQString::null );
00214 
00215   setRevision(0);
00216 
00217   setLastModified(TQDateTime::currentDateTime());
00218   setPilotId( 0 );
00219   setSyncStatus( SYNCNONE );
00220 }
00221 
00222 void Incidence::setReadOnly( bool readOnly )
00223 {
00224   IncidenceBase::setReadOnly( readOnly );
00225   if ( mRecurrence )
00226     mRecurrence->setRecurReadOnly( readOnly );
00227 }
00228 
00229 void Incidence::setFloats(bool f)
00230 {
00231   if (mReadOnly) return;
00232   if ( recurrence() )
00233     recurrence()->setFloats( f );
00234   IncidenceBase::setFloats( f );
00235 }
00236 
00237 void Incidence::setCreated( const TQDateTime &created )
00238 {
00239   if (mReadOnly) return;
00240   mCreated = created;
00241 
00242 // FIXME: Shouldn't we call updated for the creation date, too?
00243 //  updated();
00244 }
00245 
00246 TQDateTime Incidence::created() const
00247 {
00248   return mCreated;
00249 }
00250 
00251 void Incidence::setRevision( int rev )
00252 {
00253   if (mReadOnly) return;
00254   mRevision = rev;
00255 
00256   updated();
00257 }
00258 
00259 int Incidence::revision() const
00260 {
00261   return mRevision;
00262 }
00263 
00264 void Incidence::setDtStart(const TQDateTime &dtStart)
00265 {
00266   if ( mRecurrence ) {
00267     mRecurrence->setStartDateTime( dtStart );
00268     mRecurrence->setFloats( doesFloat() );
00269   }
00270   IncidenceBase::setDtStart( dtStart );
00271 }
00272 
00273 void Incidence::setDescription(const TQString &description)
00274 {
00275   if (mReadOnly) return;
00276   mDescription = description;
00277   updated();
00278 }
00279 
00280 TQString Incidence::description() const
00281 {
00282   return mDescription;
00283 }
00284 
00285 
00286 void Incidence::setSummary(const TQString &summary)
00287 {
00288   if (mReadOnly) return;
00289   mSummary = summary;
00290   updated();
00291 }
00292 
00293 TQString Incidence::summary() const
00294 {
00295   return mSummary;
00296 }
00297 
00298 void Incidence::setCategories(const TQStringList &categories)
00299 {
00300   if (mReadOnly) return;
00301   mCategories = categories;
00302   updated();
00303 }
00304 
00305 // TODO: remove setCategories(TQString) function
00306 void Incidence::setCategories(const TQString &catStr)
00307 {
00308   if (mReadOnly) return;
00309   mCategories.clear();
00310 
00311   if (catStr.isEmpty()) return;
00312 
00313   mCategories = TQStringList::split(",",catStr);
00314 
00315   TQStringList::Iterator it;
00316   for(it = mCategories.begin();it != mCategories.end(); ++it) {
00317     *it = (*it).stripWhiteSpace();
00318   }
00319 
00320   updated();
00321 }
00322 
00323 TQStringList Incidence::categories() const
00324 {
00325   return mCategories;
00326 }
00327 
00328 TQString Incidence::categoriesStr() const
00329 {
00330   return mCategories.join(",");
00331 }
00332 
00333 void Incidence::setRelatedToUid(const TQString &relatedToUid)
00334 {
00335   if ( mReadOnly || mRelatedToUid == relatedToUid ) return;
00336   mRelatedToUid = relatedToUid;
00337   updated();
00338 }
00339 
00340 TQString Incidence::relatedToUid() const
00341 {
00342   return mRelatedToUid;
00343 }
00344 
00345 void Incidence::setRelatedTo(Incidence *relatedTo)
00346 {
00347   if (mReadOnly || mRelatedTo == relatedTo) return;
00348   if(mRelatedTo)
00349     mRelatedTo->removeRelation(this);
00350   mRelatedTo = relatedTo;
00351   if (mRelatedTo) {
00352     mRelatedTo->addRelation(this);
00353     if ( mRelatedTo->uid() != mRelatedToUid )
00354       setRelatedToUid( mRelatedTo->uid() );
00355   } else {
00356     setRelatedToUid( TQString::null );
00357   }
00358 }
00359 
00360 Incidence *Incidence::relatedTo() const
00361 {
00362   return mRelatedTo;
00363 }
00364 
00365 Incidence::List Incidence::relations() const
00366 {
00367   return mRelations;
00368 }
00369 
00370 void Incidence::addRelation( Incidence *event )
00371 {
00372   if ( mRelations.find( event ) == mRelations.end() ) {
00373     mRelations.append( event );
00374   }
00375 }
00376 
00377 void Incidence::removeRelation(Incidence *event)
00378 // Remove the relation of our incident. E.g. if you have a task t and a
00379 // subtask, the subtask will have its relation to the task t.
00380 {
00381   mRelations.removeRef(event);
00382 //  if (event->getRelatedTo() == this) event->setRelatedTo(0);
00383   mRelatedToUid=TQString();
00384 }
00385 
00386 
00387 // %%%%%%%%%%%%  Recurrence-related methods %%%%%%%%%%%%%%%%%%%%
00388 
00389 
00390 Recurrence *Incidence::recurrence() const
00391 {
00392   if (!mRecurrence)
00393   {
00394     const_cast<KCal::Incidence*>(this)->mRecurrence = new Recurrence();
00395     mRecurrence->setStartDateTime( IncidenceBase::dtStart() );
00396     mRecurrence->setFloats( doesFloat() );
00397     mRecurrence->setRecurReadOnly( mReadOnly );
00398     mRecurrence->addObserver( const_cast<KCal::Incidence*>(this) );
00399   }
00400 
00401   return mRecurrence;
00402 }
00403 
00404 void Incidence::clearRecurrence()
00405 {
00406   delete mRecurrence;
00407   mRecurrence = 0;
00408 }
00409 
00410 uint Incidence::recurrenceType() const
00411 {
00412   if ( mRecurrence ) return mRecurrence->recurrenceType();
00413   else return Recurrence::rNone;
00414 }
00415 
00416 bool Incidence::doesRecur() const
00417 {
00418   if ( mRecurrence ) return mRecurrence->doesRecur();
00419   else return false;
00420 }
00421 
00422 bool Incidence::recursOn(const TQDate &qd) const
00423 {
00424   bool doesRecur = false;
00425   doesRecur = mRecurrence && mRecurrence->recursOn(qd);
00426 
00427   return doesRecur;
00428 }
00429 
00430 bool Incidence::recursAt(const TQDateTime &qdt) const
00431 {
00432   bool doesRecur = false;
00433   doesRecur = mRecurrence && mRecurrence->recursAt(qdt);
00434 
00435   return doesRecur;
00436 }
00437 
00438 bool Incidence::recursOn(const TQDate &qd, Calendar *cal) const
00439 {
00440   bool doesRecur = false;
00441   doesRecur = mRecurrence && mRecurrence->recursOn(qd);
00442 
00443   // Make sure that this instance has not been moved through a RECURRENCE-ID statement
00444   if (hasRecurrenceID() == false) {
00445     IncidenceList il = childIncidences();
00446     IncidenceListIterator it;
00447     for ( it = il.begin(); it != il.end(); ++it ) {
00448       QDateTime modifiedDt = cal->incidence(*it)->recurrenceID();
00449       modifiedDt.setTime(QTime());
00450       if (QDateTime(qd) == modifiedDt) {
00451         doesRecur = false;
00452       }
00453     }
00454   }
00455 
00456   return doesRecur;
00457 }
00458 
00459 bool Incidence::recursAt(const TQDateTime &qdt, Calendar *cal) const
00460 {
00461   bool doesRecur = false;
00462   doesRecur = mRecurrence && mRecurrence->recursAt(qdt);
00463 
00464   // Make sure that this instance has not been moved through a RECURRENCE-ID statement
00465   if (hasRecurrenceID() == false) {
00466     IncidenceList il = childIncidences();
00467     IncidenceListIterator it;
00468     for ( it = il.begin(); it != il.end(); ++it ) {
00469       if (qdt == cal->incidence(*it)->recurrenceID()) {
00470         doesRecur = false;
00471       }
00472     }
00473   }
00474 
00475   return doesRecur;
00476 }
00477 
00486 TQValueList<TQDateTime> Incidence::startDateTimesForDate( const TQDate &date ) const
00487 {
00488 //kdDebug(5800) << "Incidence::startDateTimesForDate " << date << ", incidence=" << summary() << endl;
00489   TQDateTime start = dtStart();
00490   TQDateTime end = endDateRecurrenceBase();
00491 
00492   TQValueList<TQDateTime> result;
00493 
00494   // TODO_Recurrence: Also work if only due date is given...
00495   if ( !start.isValid() && ! end.isValid() ) {
00496     return result;
00497   }
00498 
00499   // if the incidence doesn't recur,
00500   if ( !doesRecur() ) {
00501     if ( !(start.date() > date || end.date() < date ) ) {
00502       result << start;
00503     }
00504     return result;
00505   }
00506 
00507   int days = start.daysTo( end );
00508   // Account for possible recurrences going over midnight, while the original event doesn't
00509   TQDate tmpday( date.addDays( -days - 1 ) );
00510   TQDateTime tmp;
00511   while ( tmpday <= date ) {
00512     if ( recurrence()->recursOn( tmpday ) ) {
00513       TQValueList<TQTime> times = recurrence()->recurTimesOn( tmpday );
00514       for ( TQValueList<TQTime>::ConstIterator it = times.begin(); it != times.end(); ++it ) {
00515         tmp = TQDateTime( tmpday, *it );
00516         if ( endDateForStart( tmp ).date() >= date )
00517           result << tmp;
00518       }
00519     }
00520     tmpday = tmpday.addDays( 1 );
00521   }
00522   return result;
00523 }
00524 
00533 TQValueList<TQDateTime> Incidence::startDateTimesForDateTime( const TQDateTime &datetime ) const
00534 {
00535 // kdDebug(5800) << "Incidence::startDateTimesForDateTime " << datetime << ", incidence=" << summary() << endl;
00536   TQDateTime start = dtStart();
00537   TQDateTime end = endDateRecurrenceBase();
00538 
00539   TQValueList<TQDateTime> result;
00540 
00541   // TODO_Recurrence: Also work if only due date is given...
00542   if ( !start.isValid() && ! end.isValid() ) {
00543     return result;
00544   }
00545 
00546   // if the incidence doesn't recur,
00547   if ( !doesRecur() ) {
00548     if ( !(start > datetime || end < datetime ) ) {
00549       result << start;
00550     }
00551     return result;
00552   }
00553 
00554   int days = start.daysTo( end );
00555   // Account for possible recurrences going over midnight, while the original event doesn't
00556   TQDate tmpday( datetime.date().addDays( -days - 1 ) );
00557   TQDateTime tmp;
00558   while ( tmpday <= datetime.date() ) {
00559     if ( recurrence()->recursOn( tmpday ) ) {
00560       TQValueList<TQTime> times = recurrence()->recurTimesOn( tmpday );
00561       for ( TQValueList<TQTime>::ConstIterator it = times.begin(); it != times.end(); ++it ) {
00562         tmp = TQDateTime( tmpday, *it );
00563         if ( !(tmp > datetime || endDateForStart( tmp ) < datetime ) )
00564           result << tmp;
00565       }
00566     }
00567     tmpday = tmpday.addDays( 1 );
00568   }
00569   return result;
00570 }
00571 
00573 TQDateTime Incidence::endDateForStart( const TQDateTime &startDt ) const
00574 {
00575   TQDateTime start = dtStart();
00576   TQDateTime end = endDateRecurrenceBase();
00577   if ( !end.isValid() ) return start;
00578   if ( !start.isValid() ) return end;
00579 
00580   return startDt.addSecs( start.secsTo( end ) );
00581 }
00582 
00583 // %%%%%%%%%%%%%%%%% begin:RecurrenceRule %%%%%%%%%%%%%%%%%
00584 
00585 // Exception Dates
00586 /*void Incidence::setExDates(const DateList &exDates)
00587 {
00588   if ( mReadOnly ) return;
00589   recurrence()->setExDates( exDates );
00590   updated();
00591 }
00592 
00593 void Incidence::addExDate( const TQDate &date )
00594 {
00595   if ( mReadOnly ) return;
00596   recurrence()->addExDate( date );
00597   updated();
00598 }
00599 
00600 DateList Incidence::exDates() const
00601 {
00602   if ( mRecurrence ) return mRecurrence->exDates();
00603   else return DateList();
00604 }
00605 
00606 
00607 // Exception DateTimes
00608 void Incidence::setExDateTimes( const DateTimeList &exDates )
00609 {
00610   if ( mReadOnly ) return;
00611   recurrence()->setExDateTimes( exDates );
00612   updated();
00613 }
00614 
00615 void Incidence::addExDateTime( const TQDateTime &date )
00616 {
00617   if ( mReadOnly ) return;
00618   recurrence()->addExDateTime( date );
00619   updated();
00620 }
00621 
00622 DateTimeList Incidence::exDateTimes() const
00623 {
00624   if ( mRecurrence ) return mRecurrence->exDateTimes();
00625   else return DateTimeList();
00626 }
00627 
00628 
00629 // Recurrence Dates
00630 void Incidence::setRDates(const DateList &exDates)
00631 {
00632   if ( mReadOnly ) return;
00633   recurrence()->setRDates( exDates );
00634   updated();
00635 }
00636 
00637 void Incidence::addRDate( const TQDate &date )
00638 {
00639   if ( mReadOnly ) return;
00640   recurrence()->addRDate( date );
00641   updated();
00642 }
00643 
00644 DateList Incidence::rDates() const
00645 {
00646   if ( mRecurrence ) return mRecurrence->rDates();
00647   else return DateList();
00648 }
00649 
00650 
00651 // Recurrence DateTimes
00652 void Incidence::setRDateTimes( const DateTimeList &exDates )
00653 {
00654   if ( mReadOnly ) return;
00655   recurrence()->setRDateTimes( exDates );
00656   updated();
00657 }
00658 
00659 void Incidence::addRDateTime( const TQDateTime &date )
00660 {
00661   if ( mReadOnly ) return;
00662   recurrence()->addRDateTime( date );
00663   updated();
00664 }
00665 
00666 DateTimeList Incidence::rDateTimes() const
00667 {
00668   if ( mRecurrence ) return mRecurrence->rDateTimes();
00669   else return DateTimeList();
00670 }*/
00671 
00672 // %%%%%%%%%%%%%%%%% end:RecurrenceRule %%%%%%%%%%%%%%%%%
00673 
00674 void Incidence::addAttachment(Attachment *attachment)
00675 {
00676   if (mReadOnly || !attachment) return;
00677   mAttachments.append(attachment);
00678   updated();
00679 }
00680 
00681 void Incidence::deleteAttachment(Attachment *attachment)
00682 {
00683   mAttachments.removeRef(attachment);
00684 }
00685 
00686 void Incidence::deleteAttachments( const TQString &mime )
00687 {
00688   Attachment::List::Iterator it = mAttachments.begin();
00689   while( it != mAttachments.end() ) {
00690     if ( (*it)->mimeType() == mime ) mAttachments.remove( it );
00691     else ++it;
00692   }
00693 }
00694 
00695 Attachment::List Incidence::attachments() const
00696 {
00697   return mAttachments;
00698 }
00699 
00700 Attachment::List Incidence::attachments(const TQString& mime) const
00701 {
00702   Attachment::List attachments;
00703   Attachment::List::ConstIterator it;
00704   for( it = mAttachments.begin(); it != mAttachments.end(); ++it ) {
00705     if ( (*it)->mimeType() == mime ) attachments.append( *it );
00706   }
00707 
00708   return attachments;
00709 }
00710 
00711 void Incidence::clearAttachments()
00712 {
00713   mAttachments.clearAll();
00714 }
00715 
00716 void Incidence::setResources(const TQStringList &resources)
00717 {
00718   if (mReadOnly) return;
00719   mResources = resources;
00720   updated();
00721 }
00722 
00723 TQStringList Incidence::resources() const
00724 {
00725   return mResources;
00726 }
00727 
00728 
00729 void Incidence::setPriority(int priority)
00730 {
00731   if (mReadOnly) return;
00732   mPriority = priority;
00733   updated();
00734 }
00735 
00736 int Incidence::priority() const
00737 {
00738   return mPriority;
00739 }
00740 
00741 void Incidence::setStatus(Incidence::Status status)
00742 {
00743   if (mReadOnly || status == StatusX) return;
00744   mStatus = status;
00745   mStatusString = TQString::null;
00746   updated();
00747 }
00748 
00749 void Incidence::setCustomStatus(const TQString &status)
00750 {
00751   if (mReadOnly) return;
00752   mStatus = status.isEmpty() ? StatusNone : StatusX;
00753   mStatusString = status;
00754   updated();
00755 }
00756 
00757 Incidence::Status Incidence::status() const
00758 {
00759   return mStatus;
00760 }
00761 
00762 TQString Incidence::statusStr() const
00763 {
00764   if (mStatus == StatusX)
00765     return mStatusString;
00766   return statusName(mStatus);
00767 }
00768 
00769 TQString Incidence::statusName(Incidence::Status status)
00770 {
00771   switch (status) {
00772     case StatusTentative:    return i18n("incidence status", "Tentative");
00773     case StatusConfirmed:    return i18n("Confirmed");
00774     case StatusCompleted:    return i18n("Completed");
00775     case StatusNeedsAction:  return i18n("Needs-Action");
00776     case StatusCanceled:     return i18n("Canceled");
00777     case StatusInProcess:    return i18n("In-Process");
00778     case StatusDraft:        return i18n("Draft");
00779     case StatusFinal:        return i18n("Final");
00780     case StatusX:
00781     case StatusNone:
00782     default:                 return TQString::null;
00783   }
00784 }
00785 
00786 void Incidence::setSecrecy(int sec)
00787 {
00788   if (mReadOnly) return;
00789   mSecrecy = sec;
00790   updated();
00791 }
00792 
00793 int Incidence::secrecy() const
00794 {
00795   return mSecrecy;
00796 }
00797 
00798 TQString Incidence::secrecyStr() const
00799 {
00800   return secrecyName(mSecrecy);
00801 }
00802 
00803 TQString Incidence::secrecyName(int secrecy)
00804 {
00805   switch (secrecy) {
00806     case SecrecyPublic:
00807       return i18n("Public");
00808     case SecrecyPrivate:
00809       return i18n("Private");
00810     case SecrecyConfidential:
00811       return i18n("Confidential");
00812     default:
00813       return i18n("Undefined");
00814   }
00815 }
00816 
00817 TQStringList Incidence::secrecyList()
00818 {
00819   TQStringList list;
00820   list << secrecyName(SecrecyPublic);
00821   list << secrecyName(SecrecyPrivate);
00822   list << secrecyName(SecrecyConfidential);
00823 
00824   return list;
00825 }
00826 
00827 
00828 const Alarm::List &Incidence::alarms() const
00829 {
00830   return mAlarms;
00831 }
00832 
00833 Alarm* Incidence::newAlarm()
00834 {
00835   Alarm* alarm = new Alarm(this);
00836   mAlarms.append(alarm);
00837 //  updated();
00838   return alarm;
00839 }
00840 
00841 void Incidence::addAlarm(Alarm *alarm)
00842 {
00843   mAlarms.append(alarm);
00844   updated();
00845 }
00846 
00847 void Incidence::removeAlarm(Alarm *alarm)
00848 {
00849   mAlarms.removeRef(alarm);
00850   updated();
00851 }
00852 
00853 void Incidence::clearAlarms()
00854 {
00855   mAlarms.clearAll();
00856   updated();
00857 }
00858 
00859 bool Incidence::isAlarmEnabled() const
00860 {
00861   Alarm::List::ConstIterator it;
00862   for( it = mAlarms.begin(); it != mAlarms.end(); ++it ) {
00863     if ( (*it)->enabled() ) return true;
00864   }
00865   return false;
00866 }
00867 
00868 void Incidence::setLocation(const TQString &location)
00869 {
00870   if (mReadOnly) return;
00871   mLocation = location;
00872   updated();
00873 }
00874 
00875 TQString Incidence::location() const
00876 {
00877   return mLocation;
00878 }
00879 
00880 void Incidence::setSchedulingID( const TQString& sid )
00881 {
00882   mSchedulingID = sid;
00883 }
00884 
00885 TQString Incidence::schedulingID() const
00886 {
00887   if ( mSchedulingID.isNull() )
00888     // Nothing set, so use the normal uid
00889     return uid();
00890   return mSchedulingID;
00891 }
00892 
00893 bool Incidence::hasRecurrenceID() const
00894 {
00895   return mHasRecurrenceID;
00896 }
00897 
00898 void Incidence::setHasRecurrenceID( bool hasRecurrenceID )
00899 {
00900   if ( mReadOnly ) {
00901     return;
00902   }
00903 
00904   mHasRecurrenceID = hasRecurrenceID;
00905   updated();
00906 }
00907 
00908 TQDateTime Incidence::recurrenceID() const
00909 {
00910   return mRecurrenceID;
00911 }
00912 
00913 void Incidence::setRecurrenceID( const TQDateTime &recurrenceID )
00914 {
00915   if ( mReadOnly ) {
00916     return;
00917   }
00918 
00919 //   update();
00920   mRecurrenceID = recurrenceID;
00921   updated();
00922 }
00923 
00924 void Incidence::addChildIncidence( TQString childIncidence )
00925 {
00926   mChildRecurrenceEvents.append(childIncidence);
00927 }
00928 
00929 void Incidence::deleteChildIncidence( TQString childIncidence )
00930 {
00931   mChildRecurrenceEvents.remove(childIncidence);
00932 }
00933 
00934 IncidenceList Incidence::childIncidences() const
00935 {
00936   return mChildRecurrenceEvents;
00937 }
00938 
00942 void Incidence::recurrenceUpdated( Recurrence *recurrence )
00943 {
00944   if ( recurrence == mRecurrence )
00945     updated();
00946 }
00947