29 #include <libkcal/person.h>
30 #include <libkcal/event.h>
37 #include "karecurrence.h"
45 class EmailAddressList :
public TQValueList<KCal::Person>
48 EmailAddressList() : TQValueList<KCal::Person>() { }
49 EmailAddressList(
const TQValueList<KCal::Person>& list) { operator=(list); }
50 EmailAddressList& operator=(
const TQValueList<KCal::Person>&);
51 TQString join(
const TQString& separator)
const;
56 class KAAlarmEventBase
59 ~KAAlarmEventBase() { }
60 const TQString& cleanText()
const {
return mText; }
61 TQString message()
const {
return (mActionType == T_MESSAGE || mActionType == T_EMAIL) ? mText : TQString(); }
62 TQString fileName()
const {
return (mActionType == T_FILE) ? mText : TQString(); }
63 TQString command()
const {
return (mActionType == T_COMMAND) ? mText : TQString(); }
64 uint emailFromId()
const {
return mEmailFromIdentity; }
65 const EmailAddressList& emailAddresses()
const {
return mEmailAddresses; }
66 TQString emailAddresses(
const TQString& sep)
const {
return mEmailAddresses.join(sep); }
67 const TQString& emailSubject()
const {
return mEmailSubject; }
68 const TQStringList& emailAttachments()
const {
return mEmailAttachments; }
69 TQString emailAttachments(
const TQString& sep)
const {
return mEmailAttachments.join(sep); }
70 bool emailBcc()
const {
return mEmailBcc; }
71 const TQColor& bgColour()
const {
return mBgColour; }
72 const TQColor& fgColour()
const {
return mFgColour; }
73 bool defaultFont()
const {
return mDefaultFont; }
74 const TQFont& font()
const;
75 int lateCancel()
const {
return mLateCancel; }
76 bool autoClose()
const {
return mAutoClose; }
77 bool commandScript()
const {
return mCommandScript; }
78 bool confirmAck()
const {
return mConfirmAck; }
79 bool repeatAtLogin()
const {
return mRepeatAtLogin; }
80 int repeatCount()
const {
return mRepeatCount; }
81 int repeatInterval()
const {
return mRepeatInterval; }
82 bool displaying()
const {
return mDisplaying; }
83 bool beep()
const {
return mBeep; }
84 bool speak()
const {
return (mActionType == T_MESSAGE) && mSpeak; }
87 void dumpDebug()
const { }
89 void dumpDebug()
const;
93 enum Type { T_MESSAGE, T_FILE, T_COMMAND, T_AUDIO, T_EMAIL };
95 KAAlarmEventBase() : mRepeatCount(0), mLateCancel(0), mAutoClose(false), mBeep(false), mRepeatAtLogin(false),
96 mDisplaying(false), mEmailBcc(false), mConfirmAck(false) { }
97 KAAlarmEventBase(
const KAAlarmEventBase& rhs) { copy(rhs); }
98 KAAlarmEventBase& operator=(
const KAAlarmEventBase& rhs) { copy(rhs);
return *
this; }
99 void copy(
const KAAlarmEventBase&);
104 DateTime mNextMainDateTime;
108 uint mEmailFromIdentity;
109 EmailAddressList mEmailAddresses;
110 TQString mEmailSubject;
111 TQStringList mEmailAttachments;
131 friend class AlarmData;
137 class KAAlarm :
public KAAlarmEventBase
157 REMINDER_ALARM = 0x02,
158 DEFERRED_ALARM = 0x04,
159 DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM,
162 AT_LOGIN_ALARM = 0x10,
163 DISPLAYING_ALARM = 0x20,
166 PRE_ACTION_ALARM = 0x40,
167 POST_ACTION_ALARM = 0x50
171 INVALID__ALARM = INVALID_ALARM,
172 MAIN__ALARM = MAIN_ALARM,
174 REMINDER__ALARM = REMINDER_ALARM,
175 TIMED_DEFERRAL_FLAG = 0x08,
176 DEFERRED_DATE__ALARM = DEFERRED_ALARM,
177 DEFERRED_TIME__ALARM = DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
178 DEFERRED_REMINDER_DATE__ALARM = REMINDER_ALARM | DEFERRED_ALARM,
179 DEFERRED_REMINDER_TIME__ALARM = REMINDER_ALARM | DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
182 AT_LOGIN__ALARM = AT_LOGIN_ALARM,
183 DISPLAYING__ALARM = DISPLAYING_ALARM,
185 AUDIO__ALARM = AUDIO_ALARM,
186 PRE_ACTION__ALARM = PRE_ACTION_ALARM,
187 POST_ACTION__ALARM = POST_ACTION_ALARM
190 KAAlarm() : mType(INVALID__ALARM), mDeferred(false) { }
191 KAAlarm(
const KAAlarm&);
193 Action action()
const {
return (Action)mActionType; }
194 bool valid()
const {
return mType != INVALID__ALARM; }
195 Type type()
const {
return static_cast<Type
>(mType & ~TIMED_DEFERRAL_FLAG); }
196 SubType subType()
const {
return mType; }
197 const TQString& eventID()
const {
return mEventID; }
198 DateTime dateTime(
bool withRepeats =
false)
const
199 {
return (withRepeats && mNextRepeat && mRepeatInterval)
200 ? mNextMainDateTime.addSecs(mNextRepeat * mRepeatInterval * 60) : mNextMainDateTime; }
201 TQDate date()
const {
return mNextMainDateTime.date(); }
202 TQTime time()
const {
return mNextMainDateTime.time(); }
203 TQString audioFile()
const {
return (mActionType == T_AUDIO) && !mBeep ? mText : TQString(); }
204 float soundVolume()
const {
return (mActionType == T_AUDIO) && !mBeep && !mText.isEmpty() ? mSoundVolume : -1; }
205 float fadeVolume()
const {
return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeSeconds && !mBeep && !mText.isEmpty() ? mFadeVolume : -1; }
206 int fadeSeconds()
const {
return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeVolume >= 0 && !mBeep && !mText.isEmpty() ? mFadeSeconds : 0; }
207 bool repeatSound()
const {
return (mActionType == T_AUDIO) && mRepeatSound && !mBeep && !mText.isEmpty(); }
208 bool reminder()
const {
return mType == REMINDER__ALARM; }
209 bool deferred()
const {
return mDeferred; }
210 void setTime(
const DateTime& dt) { mNextMainDateTime = dt; }
211 void setTime(
const TQDateTime& dt) { mNextMainDateTime = dt; }
214 void dumpDebug()
const { }
215 static const char* debugType(Type) {
return ""; }
217 void dumpDebug()
const;
218 static const char* debugType(Type);
243 REPEAT_AT_LOGIN = 0x04,
252 EXEC_IN_XTERM = 0x800,
254 COPY_KORGANIZER = 0x2000,
262 TIMED_FLAG = 0x40000,
263 DATE_DEFERRAL = DEFERRAL,
264 TIME_DEFERRAL = DEFERRAL | TIMED_FLAG,
265 DISPLAYING_ = 0x80000,
266 READ_ONLY_FLAGS = 0xF0000
287 FIRST_OR_ONLY_OCCURRENCE = 0x01,
288 RECURRENCE_DATE = 0x02,
289 RECURRENCE_DATE_TIME = 0x03,
290 LAST_RECURRENCE = 0x04,
291 OCCURRENCE_REPEAT = 0x10,
292 FIRST_OR_ONLY_OCCURRENCE_REPEAT = OCCURRENCE_REPEAT | FIRST_OR_ONLY_OCCURRENCE,
293 RECURRENCE_DATE_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE,
294 RECURRENCE_DATE_TIME_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE_TIME,
295 LAST_RECURRENCE_REPEAT = OCCURRENCE_REPEAT | LAST_RECURRENCE
312 KAEvent() : mRevision(0), mRecurrence(0), mAlarmCount(0) { }
313 KAEvent(
const TQDateTime& dt,
const TQString& message,
const TQColor& bg,
const TQColor& fg,
const TQFont& f, Action action,
int lateCancel,
int flags)
314 : mRecurrence(0) { set(dt, message, bg, fg, f, action, lateCancel, flags); }
316 KAEvent(
const KAEvent& e) : KAAlarmEventBase(e), mRecurrence(0) { copy(e); }
317 ~
KAEvent() {
delete mRecurrence; }
318 KAEvent& operator=(
const KAEvent& e) {
if (&e !=
this) copy(e);
return *
this; }
320 void set(
const TQDateTime&,
const TQString& message,
const TQColor& bg,
const TQColor& fg,
const TQFont&, Action,
int lateCancel,
int flags);
321 void setEmail(uint from,
const EmailAddressList&,
const TQString& subject,
const TQStringList& attachments);
322 void setAudioFile(
const TQString& filename,
float volume,
float fadeVolume,
int fadeSeconds);
323 void setTemplate(
const TQString& name,
int afterTime = -1) { mTemplateName = name; mTemplateAfterTime = afterTime; mUpdated =
true; }
324 void setActions(
const TQString& pre,
const TQString& post) { mPreAction = pre; mPostAction = post; mUpdated =
true; }
325 OccurType setNextOccurrence(
const TQDateTime& preDateTime);
326 void setFirstRecurrence();
327 void setEventID(
const TQString&
id) { mEventID = id; mUpdated =
true; }
328 void setDate(
const TQDate& d) { mNextMainDateTime.set(d); mUpdated =
true; }
329 void setTime(
const TQDateTime& dt) { mNextMainDateTime.set(dt); mUpdated =
true; }
330 void setSaveDateTime(
const TQDateTime& dt) { mSaveDateTime = dt; mUpdated =
true; }
331 void setLateCancel(
int lc) { mLateCancel = lc; mUpdated =
true; }
332 void setAutoClose(
bool ac) { mAutoClose = ac; mUpdated =
true; }
333 void setRepeatAtLogin(
bool rl) { mRepeatAtLogin = rl; mUpdated =
true; }
334 void setUid(
Status s) { mEventID = uid(mEventID, s); mUpdated =
true; }
335 void setKMailSerialNumber(
unsigned long n) { mKMailSerialNumber = n; }
336 void setLogFile(
const TQString& logfile);
337 void setReminder(
int minutes,
bool onceOnly);
338 bool defer(
const DateTime&,
bool reminder,
bool adjustRecurrence =
false);
340 void cancelCancelledDeferral();
341 void setDeferDefaultMinutes(
int minutes) { mDeferDefaultMinutes = minutes; mUpdated =
true; }
342 bool setDisplaying(
const KAEvent&, KAAlarm::Type,
const TQDateTime&);
343 void reinstateFromDisplaying(
const KAEvent& dispEvent);
344 void setArchive() { mArchive =
true; mUpdated =
true; }
345 void setEnabled(
bool enable) { mEnabled = enable; mUpdated =
true; }
346 void setUpdated() { mUpdated =
true; }
347 void clearUpdated()
const { mUpdated =
false; }
348 void removeExpiredAlarm(KAAlarm::Type);
349 void incrementRevision() { ++mRevision; mUpdated =
true; }
352 bool isTemplate()
const {
return !mTemplateName.isEmpty(); }
353 const TQString& templateName()
const {
return mTemplateName; }
354 bool usingDefaultTime()
const {
return mTemplateAfterTime == 0; }
355 int templateAfterTime()
const {
return mTemplateAfterTime; }
356 KAAlarm alarm(KAAlarm::Type)
const;
357 KAAlarm firstAlarm()
const;
358 KAAlarm nextAlarm(
const KAAlarm& al)
const {
return nextAlarm(al.type()); }
359 KAAlarm nextAlarm(KAAlarm::Type)
const;
360 KAAlarm convertDisplayingAlarm()
const;
361 bool updateKCalEvent(
KCal::Event&,
bool checkUid =
true,
bool original =
false,
bool cancelCancelledDefer =
false)
const;
362 Action action()
const {
return (Action)mActionType; }
363 bool displayAction()
const {
return mActionType == T_MESSAGE || mActionType == T_FILE; }
364 const TQString& id()
const {
return mEventID; }
365 bool valid()
const {
return mAlarmCount && (mAlarmCount != 1 || !mRepeatAtLogin); }
366 int alarmCount()
const {
return mAlarmCount; }
367 const DateTime& startDateTime()
const {
return mStartDateTime; }
368 DateTime mainDateTime(
bool withRepeats =
false)
const
369 {
return (withRepeats && mNextRepeat && mRepeatInterval)
370 ? mNextMainDateTime.addSecs(mNextRepeat * mRepeatInterval * 60) : mNextMainDateTime; }
371 TQDate mainDate()
const {
return mNextMainDateTime.date(); }
372 TQTime mainTime()
const {
return mNextMainDateTime.time(); }
373 DateTime mainEndRepeatTime()
const {
return (mRepeatCount > 0 && mRepeatInterval)
374 ? mNextMainDateTime.addSecs(mRepeatCount * mRepeatInterval * 60) : mNextMainDateTime; }
375 int reminder()
const {
return mReminderMinutes; }
376 bool reminderOnceOnly()
const {
return mReminderOnceOnly; }
377 bool reminderDeferral()
const {
return mDeferral == REMINDER_DEFERRAL; }
378 int reminderArchived()
const {
return mArchiveReminderMinutes; }
379 DateTime deferDateTime()
const {
return mDeferralTime; }
380 DateTime deferralLimit(DeferLimitType* = 0)
const;
381 int deferDefaultMinutes()
const {
return mDeferDefaultMinutes; }
382 DateTime displayDateTime()
const;
383 const TQString& messageFileOrCommand()
const {
return mText; }
384 TQString logFile()
const {
return mLogFile; }
385 bool commandXterm()
const {
return mCommandXterm; }
386 unsigned long kmailSerialNumber()
const {
return mKMailSerialNumber; }
387 bool copyToKOrganizer()
const {
return mCopyToKOrganizer; }
388 const TQString& audioFile()
const {
return mAudioFile; }
389 float soundVolume()
const {
return !mAudioFile.isEmpty() ? mSoundVolume : -1; }
390 float fadeVolume()
const {
return !mAudioFile.isEmpty() && mSoundVolume >= 0 && mFadeSeconds ? mFadeVolume : -1; }
391 int fadeSeconds()
const {
return !mAudioFile.isEmpty() && mSoundVolume >= 0 && mFadeVolume >= 0 ? mFadeSeconds : 0; }
392 bool repeatSound()
const {
return mRepeatSound && !mAudioFile.isEmpty(); }
393 const TQString& preAction()
const {
return mPreAction; }
394 const TQString& postAction()
const {
return mPostAction; }
395 bool recurs()
const {
return checkRecur() != KARecurrence::NO_RECUR; }
396 KARecurrence::Type recurType()
const {
return checkRecur(); }
397 KARecurrence* recurrence()
const {
return mRecurrence; }
398 int recurInterval()
const;
399 int longestRecurrenceInterval()
const {
return mRecurrence ? mRecurrence->longestInterval() : 0; }
400 TQString recurrenceText(
bool brief =
false)
const;
401 TQString repetitionText(
bool brief =
false)
const;
402 bool occursAfter(
const TQDateTime& preDateTime,
bool includeRepetitions)
const;
403 OccurType nextOccurrence(
const TQDateTime& preDateTime, DateTime& result, OccurOption = IGNORE_REPETITION)
const;
404 OccurType previousOccurrence(
const TQDateTime& afterDateTime, DateTime& result,
bool includeRepetitions =
false)
const;
406 bool deferred()
const {
return mDeferral > 0; }
407 bool toBeArchived()
const {
return mArchive; }
408 bool enabled()
const {
return mEnabled; }
409 bool updated()
const {
return mUpdated; }
410 bool mainExpired()
const {
return mMainExpired; }
411 bool expired()
const {
return (mDisplaying && mMainExpired) || uidStatus(mEventID) == EXPIRED; }
412 Status uidStatus()
const {
return uidStatus(mEventID); }
413 static Status uidStatus(
const TQString& uid);
414 static TQString uid(
const TQString&
id,
Status);
419 MonthPos() : days(7) { }
423 bool setRepetition(
int interval,
int count);
424 void setNoRecur() { clearRecur(); }
425 void setRecurrence(
const KARecurrence&);
426 bool setRecurMinutely(
int freq,
int count,
const TQDateTime& end);
427 bool setRecurDaily(
int freq,
const TQBitArray& days,
int count,
const TQDate& end);
428 bool setRecurWeekly(
int freq,
const TQBitArray& days,
int count,
const TQDate& end);
429 bool setRecurMonthlyByDate(
int freq,
const TQValueList<int>& days,
int count,
const TQDate& end);
430 bool setRecurMonthlyByPos(
int freq,
const TQValueList<MonthPos>& pos,
int count,
const TQDate& end);
431 bool setRecurAnnualByDate(
int freq,
const TQValueList<int>& months,
int day, KARecurrence::Feb29Type,
int count,
const TQDate& end);
432 bool setRecurAnnualByPos(
int freq,
const TQValueList<MonthPos>& pos,
const TQValueList<int>& months,
int count,
const TQDate& end);
435 void dumpDebug()
const { }
437 void dumpDebug()
const;
439 static int calVersion();
440 static TQString calVersionString();
441 static bool adjustStartOfDay(
const KCal::Event::List&);
442 static void convertKCalEvents(
KCal::Calendar&,
int version,
bool adjustSummerTime);
447 CANCEL_DEFERRAL = -1,
456 KARecurrence::Type checkRecur()
const;
457 void checkRepetition()
const;
458 OccurType nextRecurrence(
const TQDateTime& preDateTime, DateTime& result)
const;
459 OccurType previousRecurrence(
const TQDateTime& afterDateTime, DateTime& result)
const;
461 KCal::Alarm* initKCalAlarm(
KCal::Event&,
const DateTime&,
const TQStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM)
const;
462 KCal::Alarm* initKCalAlarm(
KCal::Event&,
int startOffsetSecs,
const TQStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM)
const;
463 static DateTime readDateTime(
const KCal::Event&,
bool dateOnly, DateTime& start);
464 static void readAlarms(
const KCal::Event&,
void* alarmMap);
465 static void readAlarm(
const KCal::Alarm&, AlarmData&);
466 inline void set_deferral(DeferType);
467 inline void set_reminder(
int minutes);
468 inline void set_archiveReminder();
470 TQString mTemplateName;
473 TQString mPostAction;
474 DateTime mStartDateTime;
475 TQDateTime mSaveDateTime;
476 TQDateTime mAtLoginDateTime;
477 DateTime mDeferralTime;
478 DateTime mDisplayingTime;
479 int mDisplayingFlags;
480 int mReminderMinutes;
481 int mArchiveReminderMinutes;
482 int mDeferDefaultMinutes;
484 KARecurrence* mRecurrence;
487 unsigned long mKMailSerialNumber;
488 int mTemplateAfterTime;
491 bool mCopyToKOrganizer;
492 bool mReminderOnceOnly;
494 bool mArchiveRepeatAtLogin;
497 mutable bool mUpdated;
Provides read and write access to calendar files.
KAEvent corresponds to a KCal::Event instance.
Status
The category of an event, indicated by the middle part of its UID.