23 #include <tdeglobal.h> 24 #include <tdelocale.h> 27 #include "calformat.h" 29 #include "incidence.h" 34 Incidence::Incidence() :
36 mRelatedTo(0), mStatus(StatusNone), mSecrecy(SecrecyPublic),
37 mPriority(0), mRecurrence(0),
38 mHasRecurrenceID( false ), mChildRecurrenceEvents()
42 mAlarms.setAutoDelete(
true);
43 mAttachments.setAutoDelete(
true);
49 mRevision = i.mRevision;
50 mCreated = i.mCreated;
51 mDescription = i.mDescription;
52 mSummary = i.mSummary;
53 mCategories = i.mCategories;
56 mRelatedToUid = i.mRelatedToUid;
58 mResources = i.mResources;
59 mStatusString = i.mStatusString;
61 mSecrecy = i.mSecrecy;
62 mPriority = i.mPriority;
63 mLocation = i.mLocation;
64 mRecurrenceID = i.mRecurrenceID;
65 mHasRecurrenceID = i.mHasRecurrenceID;
66 mChildRecurrenceEvents = i.mChildRecurrenceEvents;
71 Alarm::List::ConstIterator it;
72 for( it = i.mAlarms.begin(); it != i.mAlarms.end(); ++it ) {
77 mAlarms.setAutoDelete(
true);
79 Attachment::List::ConstIterator it1;
80 for ( it1 = i.mAttachments.begin(); it1 != i.mAttachments.end(); ++it1 ) {
82 mAttachments.append( a );
84 mAttachments.setAutoDelete(
true );
87 mRecurrence =
new Recurrence( *(i.mRecurrence) );
88 mRecurrence->addObserver(
this );
92 mSchedulingID = i.mSchedulingID;
95 Incidence::~Incidence()
98 List::ConstIterator it;
99 for ( it = Relations.begin(); it != Relations.end(); ++it ) {
100 if ( (*it)->relatedTo() == this ) (*it)->mRelatedTo = 0;
102 if ( relatedTo() ) relatedTo()->removeRelation(
this );
108 static bool stringCompare(
const TQString& s1,
const TQString& s2 )
110 return ( s1.isEmpty() && s2.isEmpty() ) || (s1 == s2);
117 IncidenceBase::operator=( i );
118 mRevision = i.mRevision;
119 mCreated = i.mCreated;
120 mDescription = i.mDescription;
121 mSummary = i.mSummary;
122 mCategories = i.mCategories;
124 mRelatedToUid = i.mRelatedToUid;
126 mResources = i.mResources;
127 mStatusString = i.mStatusString;
129 mSecrecy = i.mSecrecy;
130 mPriority = i.mPriority;
131 mLocation = i.mLocation;
132 mRecurrenceID = i.mRecurrenceID;
133 mHasRecurrenceID = i.mHasRecurrenceID;
134 mChildRecurrenceEvents = i.mChildRecurrenceEvents;
137 Alarm::List::ConstIterator it;
138 for( it = i.mAlarms.begin(); it != i.mAlarms.end(); ++it ) {
144 mAttachments.clearAll();
145 Attachment::List::ConstIterator it1;
146 for ( it1 = i.mAttachments.begin(); it1 != i.mAttachments.end(); ++it1 ) {
148 mAttachments.append( a );
153 mRecurrence =
new Recurrence( *(i.mRecurrence) );
154 mRecurrence->addObserver(
this );
158 mSchedulingID = i.mSchedulingID;
162 bool Incidence::operator==(
const Incidence& i2 )
const 164 if( alarms().count() != i2.
alarms().count() ) {
168 Alarm::List::ConstIterator a1 = alarms().begin();
169 Alarm::List::ConstIterator a2 = i2.
alarms().begin();
170 for( ; a1 != alarms().end() && a2 != i2.
alarms().end(); ++a1, ++a2 )
177 if ( !IncidenceBase::operator==(i2) )
180 bool recurrenceEqual = ( mRecurrence == 0 && i2.mRecurrence == 0 );
181 if ( !recurrenceEqual )
183 recurrenceEqual = mRecurrence != 0 &&
184 i2.mRecurrence != 0 &&
185 *mRecurrence == *i2.mRecurrence;
191 stringCompare( description(), i2.
description() ) &&
192 stringCompare( summary(), i2.
summary() ) &&
199 mStatus == i2.mStatus &&
200 ( mStatus == StatusNone || stringCompare( mStatusString, i2.mStatusString ) ) &&
203 stringCompare( location(), i2.
location() ) &&
210 setCreated(TQDateTime::currentDateTime());
213 setSchedulingID( TQString() );
217 setLastModified(TQDateTime::currentDateTime());
219 setSyncStatus( SYNCNONE );
226 mRecurrence->setRecurReadOnly( readOnly );
231 if (mReadOnly)
return;
233 recurrence()->setFloats( f );
239 if (mReadOnly)
return;
253 if (mReadOnly)
return;
267 mRecurrence->setStartDateTime( dtStart );
268 mRecurrence->setFloats( doesFloat() );
275 if (mReadOnly)
return;
276 mDescription = description;
288 if (mReadOnly)
return;
300 if (mReadOnly)
return;
301 mCategories = categories;
308 if (mReadOnly)
return;
311 if (catStr.isEmpty())
return;
313 mCategories = TQStringList::split(
",",catStr);
315 TQStringList::Iterator it;
316 for(it = mCategories.begin();it != mCategories.end(); ++it) {
317 *it = (*it).stripWhiteSpace();
330 return mCategories.join(
",");
335 if ( mReadOnly || mRelatedToUid == relatedToUid )
return;
336 mRelatedToUid = relatedToUid;
342 return mRelatedToUid;
347 if (mReadOnly || mRelatedTo == relatedTo)
return;
349 mRelatedTo->removeRelation(
this);
350 mRelatedTo = relatedTo;
353 if ( mRelatedTo->uid() != mRelatedToUid )
354 setRelatedToUid( mRelatedTo->uid() );
356 setRelatedToUid( TQString() );
372 if ( mRelations.find( event ) == mRelations.end() ) {
373 mRelations.append( event );
381 mRelations.removeRef(event);
383 mRelatedToUid=TQString();
396 mRecurrence->setFloats( doesFloat() );
397 mRecurrence->setRecurReadOnly( mReadOnly );
398 mRecurrence->addObserver( const_cast<KCal::Incidence*>(
this) );
410 uint Incidence::recurrenceType()
const 412 if ( mRecurrence )
return mRecurrence->recurrenceType();
413 else return Recurrence::rNone;
418 if ( mRecurrence )
return mRecurrence->doesRecur();
424 bool doesRecur =
false;
425 doesRecur = mRecurrence && mRecurrence->recursOn(qd);
432 bool doesRecur =
false;
433 doesRecur = mRecurrence && mRecurrence->recursAt(qdt);
440 bool doesRecur =
false;
441 doesRecur = mRecurrence && mRecurrence->recursOn(qd);
444 if (hasRecurrenceID() ==
false) {
445 IncidenceList il = childIncidences();
446 IncidenceListIterator it;
447 for ( it = il.begin(); it != il.end(); ++it ) {
449 modifiedDt.setTime(TQTime());
450 if (TQDateTime(qd) == modifiedDt) {
461 bool doesRecur =
false;
462 doesRecur = mRecurrence && mRecurrence->recursAt(qdt);
465 if (hasRecurrenceID() ==
false) {
466 IncidenceList il = childIncidences();
467 IncidenceListIterator it;
468 for ( it = il.begin(); it != il.end(); ++it ) {
489 TQDateTime start = dtStart();
490 TQDateTime end = endDateRecurrenceBase();
492 TQValueList<TQDateTime> result;
495 if ( !start.isValid() && ! end.isValid() ) {
500 if ( !doesRecur() ) {
501 if ( !(start.date() > date || end.date() < date ) ) {
507 int days = start.daysTo( end );
509 TQDate tmpday( date.addDays( -days - 1 ) );
511 while ( tmpday <= date ) {
512 if ( recurrence()->recursOn( tmpday ) ) {
513 TQValueList<TQTime> times = recurrence()->recurTimesOn( tmpday );
514 for ( TQValueList<TQTime>::ConstIterator it = times.begin(); it != times.end(); ++it ) {
515 tmp = TQDateTime( tmpday, *it );
516 if ( endDateForStart( tmp ).date() >= date )
520 tmpday = tmpday.addDays( 1 );
536 TQDateTime start = dtStart();
537 TQDateTime end = endDateRecurrenceBase();
539 TQValueList<TQDateTime> result;
542 if ( !start.isValid() && ! end.isValid() ) {
547 if ( !doesRecur() ) {
548 if ( !(start > datetime || end < datetime ) ) {
554 int days = start.daysTo( end );
556 TQDate tmpday( datetime.date().addDays( -days - 1 ) );
558 while ( tmpday <= datetime.date() ) {
559 if ( recurrence()->recursOn( tmpday ) ) {
560 TQValueList<TQTime> times = recurrence()->recurTimesOn( tmpday );
561 for ( TQValueList<TQTime>::ConstIterator it = times.begin(); it != times.end(); ++it ) {
562 tmp = TQDateTime( tmpday, *it );
563 if ( !(tmp > datetime || endDateForStart( tmp ) < datetime ) )
567 tmpday = tmpday.addDays( 1 );
575 TQDateTime start = dtStart();
576 TQDateTime end = endDateRecurrenceBase();
577 if ( !end.isValid() )
return start;
578 if ( !start.isValid() )
return end;
580 return startDt.addSecs( start.secsTo( end ) );
676 if (mReadOnly || !attachment)
return;
677 mAttachments.append(attachment);
683 mAttachments.removeRef(attachment);
688 Attachment::List::Iterator it = mAttachments.begin();
689 while( it != mAttachments.end() ) {
690 if ( (*it)->mimeType() == mime ) mAttachments.remove( it );
703 Attachment::List::ConstIterator it;
704 for( it = mAttachments.begin(); it != mAttachments.end(); ++it ) {
705 if ( (*it)->mimeType() == mime ) attachments.append( *it );
713 mAttachments.clearAll();
718 if (mReadOnly)
return;
719 mResources = resources;
731 if (mReadOnly)
return;
732 mPriority = priority;
743 if (mReadOnly || status == StatusX)
return;
745 mStatusString = TQString();
751 if (mReadOnly)
return;
752 mStatus = status.isEmpty() ? StatusNone : StatusX;
753 mStatusString = status;
764 if (mStatus == StatusX)
765 return mStatusString;
766 return statusName(mStatus);
772 case StatusTentative:
return i18n(
"incidence status",
"Tentative");
773 case StatusConfirmed:
return i18n(
"Confirmed");
774 case StatusCompleted:
return i18n(
"Completed");
775 case StatusNeedsAction:
return i18n(
"Needs-Action");
776 case StatusCanceled:
return i18n(
"Canceled");
777 case StatusInProcess:
return i18n(
"In-Process");
778 case StatusDraft:
return i18n(
"Draft");
779 case StatusFinal:
return i18n(
"Final");
782 default:
return TQString();
788 if (mReadOnly)
return;
800 return secrecyName(mSecrecy);
807 return i18n(
"Public");
809 return i18n(
"Private");
810 case SecrecyConfidential:
811 return i18n(
"Confidential");
813 return i18n(
"Undefined");
820 list << secrecyName(SecrecyPublic);
821 list << secrecyName(SecrecyPrivate);
822 list << secrecyName(SecrecyConfidential);
836 mAlarms.append(alarm);
843 mAlarms.append(alarm);
849 mAlarms.removeRef(alarm);
861 Alarm::List::ConstIterator it;
862 for( it = mAlarms.begin(); it != mAlarms.end(); ++it ) {
863 if ( (*it)->enabled() )
return true;
870 if (mReadOnly)
return;
871 mLocation = location;
887 if ( mSchedulingID.isNull() )
890 return mSchedulingID;
895 return mHasRecurrenceID;
904 mHasRecurrenceID = hasRecurrenceID;
910 return mRecurrenceID;
920 mRecurrenceID = recurrenceID;
926 mChildRecurrenceEvents.append(childIncidence);
931 mChildRecurrenceEvents.remove(childIncidence);
936 return mChildRecurrenceEvents;
944 if ( recurrence == mRecurrence )
void setFloats(bool f)
Set whether the incidence floats, i.e.
virtual TQDateTime dtStart() const
returns an event's starting date/time as a TQDateTime.
void clearAlarms()
Remove all alarms that are associated with this incidence.
const Alarm::List & alarms() const
All alarms that are associated with this incidence.
void setSecrecy(int)
Sets secrecy status.
void deleteAttachment(Attachment *attachment)
Remove and delete a specific attachment.
virtual void recurrenceUpdated(Recurrence *)
Observer interface for the recurrence class.
int revision() const
Return the number of revisions this event has seen.
TQString summary() const
Return short summary.
virtual TQValueList< TQDateTime > startDateTimesForDate(const TQDate &date) const
Calculates the start date/time for all recurrences that happen at some time on the given date (might ...
This is the main "calendar" object class.
This class provides the base class common to all calendar components.
TQString secrecyStr() const
Return secrecy as translated string.
bool hasRecurrenceID() const
Returns true if the incidence has recurrenceID, otherwise return false.
void recreate()
Recreate event.
TQString description() const
Return long description.
virtual void setReadOnly(bool)
Set readonly status.
int secrecy() const
Return the event's secrecy.
void setSummary(const TQString &summary)
Set short summary.
void clearRecurrence()
Removes all recurrence and exception rules and dates.
TQStringList categories() const
Return categories as a list of strings.
bool recursAt(const TQDateTime &qdt) const
Returns true if the date/time specified is one on which the incidence will recur. ...
void clearAttachments()
Remove and delete all attachments.
void setRelatedToUid(const TQString &)
Point at some other event to which the event relates.
void deleteAttachments(const TQString &mime)
Remove and delete all attachments with this mime type.
bool isAlarmEnabled() const
Return whether any alarm associated with this incidence is enabled.
void removeRelation(Incidence *)
Remove event that is related to this event.
TQString relatedToUid() const
What event does this one relate to? This function should only be used when constructing a calendar be...
TQString statusStr() const
Return the event's status string.
virtual TQDateTime endDateForStart(const TQDateTime &startDt) const
Return the end time of the occurrence if it starts at the given date/time.
Status
Enumeration for describing an event's status.
TQString categoriesStr() const
Return categories as a comma separated string.
void setRelatedTo(Incidence *relatedTo)
Point at some other event to which the event relates.
TQStringList resources() const
Return list of current resources.
Alarm * newAlarm()
Create a new alarm which is associated with this incidence.
void setResources(const TQStringList &resources)
Set resources used, such as Office, Car, etc.
void setRecurrenceID(const TQDateTime &recurrenceID)
Set the incidences recurrenceID.
void setHasRecurrenceID(bool hasRecurrenceID)
Sets if the incidence has recurrenceID.
TQDateTime created() const
Return time and date of creation.
Recurrence * recurrence() const
Return the recurrence rule associated with this incidence.
void setCategories(const TQStringList &categories)
Set categories.
void addRelation(Incidence *)
Add an event which is related to this event.
bool doesRecur() const
Forward to Recurrence::doesRecur().
Provides the main "calendar" object class.
void setStatus(Status status)
Sets the incidence status to a standard status value.
static TQStringList secrecyList()
Return list of all available secrecy states as list of translated strings.
This class provides the base class common to all calendar components.
void deleteChildIncidence(TQString childIncidence)
Detach a child incidence from its parent incidence.
TQDateTime recurrenceID() const
Returns the incidence recurrenceID.
Status status() const
Return the event's status.
Incidence * incidence(const TQString &uid)
Returns the Incidence associated with the given unique identifier.
This class represents information related to an attachment.
virtual bool recursOn(const TQDate &qd) const
Returns true if the date specified is one on which the incidence will recur.
virtual void setDtStart(const TQDateTime &dtStart)
for setting the event's starting date/time with a TQDateTime.
void addAttachment(Attachment *attachment)
Add attachment.
void setStartDateTime(const TQDateTime &start)
Set start of recurrence, as a date and time.
TQString schedulingID() const
Return the event's/todo's scheduling ID.
void setReadOnly(bool readonly)
Set readonly state of incidence.
void setSchedulingID(const TQString &sid)
Set the event's/todo's scheduling ID.
Namespace KCal is for global classes, objects and/or functions in libkcal.
void setCreated(const TQDateTime &)
Set creation date.
void addChildIncidence(TQString childIncidence)
Attach a child incidence to a parent incidence.
void removeAlarm(Alarm *)
Remove an alarm that is associated with this incidence.
void setRevision(int rev)
Set the number of revisions this event has seen.
void setLocation(const TQString &location)
Set the event's/todo's location.
int priority() const
Return priority.
void setDescription(const TQString &description)
Set the long description.
Attachment::List attachments() const
Return list of all associated attachments.
void addAlarm(Alarm *)
Add an alarm which is associated with this incidence.
static TQString statusName(Status)
Return human-readable translated name of status value.
TQString location() const
Return the event's/todo's location.
static TQString secrecyName(int)
Return human-readable translated name of secrecy class.
void setPriority(int priority)
Set the incidences priority.
void setParent(Incidence *)
Set the alarm's parent incidence.
Incidence::List relations() const
All events that are related to this event.
This class represents an alarm notification.
void setCustomStatus(const TQString &status)
Sets the incidence status to a non-standard status value.
Incidence * relatedTo() const
What event does this one relate to?
IncidenceList childIncidences() const
Returns an EventList of all child incidences.
virtual TQValueList< TQDateTime > startDateTimesForDateTime(const TQDateTime &datetime) const
Calculates the start date/time for all recurrences that happen at the given time. ...
void setFloats(bool f)
Set whether the incidence floats, i.e.
This class represents a recurrence rule for a calendar incidence.
virtual void setDtStart(const TQDateTime &dtStart)
Set starting date/time.