00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KALARMEVENT_H
00022 #define KALARMEVENT_H
00023
00026 #include <qcolor.h>
00027 #include <qfont.h>
00028
00029 #include <libkcal/person.h>
00030 #include <libkcal/event.h>
00031 namespace KCal {
00032 class Calendar;
00033 class CalendarLocal;
00034 }
00035
00036 #include "datetime.h"
00037 #include "karecurrence.h"
00038
00039 class AlarmCalendar;
00040 class KARecurrence;
00041 struct AlarmData;
00042
00043
00044 typedef KCal::Person EmailAddress;
00045 class EmailAddressList : public QValueList<KCal::Person>
00046 {
00047 public:
00048 EmailAddressList() : QValueList<KCal::Person>() { }
00049 EmailAddressList(const QValueList<KCal::Person>& list) { operator=(list); }
00050 EmailAddressList& operator=(const QValueList<KCal::Person>&);
00051 QString join(const QString& separator) const;
00052 };
00053
00054
00055
00056 class KAAlarmEventBase
00057 {
00058 public:
00059 ~KAAlarmEventBase() { }
00060 const QString& cleanText() const { return mText; }
00061 QString message() const { return (mActionType == T_MESSAGE || mActionType == T_EMAIL) ? mText : QString::null; }
00062 QString fileName() const { return (mActionType == T_FILE) ? mText : QString::null; }
00063 QString command() const { return (mActionType == T_COMMAND) ? mText : QString::null; }
00064 uint emailFromId() const { return mEmailFromIdentity; }
00065 const EmailAddressList& emailAddresses() const { return mEmailAddresses; }
00066 QString emailAddresses(const QString& sep) const { return mEmailAddresses.join(sep); }
00067 const QString& emailSubject() const { return mEmailSubject; }
00068 const QStringList& emailAttachments() const { return mEmailAttachments; }
00069 QString emailAttachments(const QString& sep) const { return mEmailAttachments.join(sep); }
00070 bool emailBcc() const { return mEmailBcc; }
00071 const QColor& bgColour() const { return mBgColour; }
00072 const QColor& fgColour() const { return mFgColour; }
00073 bool defaultFont() const { return mDefaultFont; }
00074 const QFont& font() const;
00075 int lateCancel() const { return mLateCancel; }
00076 bool autoClose() const { return mAutoClose; }
00077 bool commandScript() const { return mCommandScript; }
00078 bool confirmAck() const { return mConfirmAck; }
00079 bool repeatAtLogin() const { return mRepeatAtLogin; }
00080 int repeatCount() const { return mRepeatCount; }
00081 int repeatInterval() const { return mRepeatInterval; }
00082 bool displaying() const { return mDisplaying; }
00083 bool beep() const { return mBeep; }
00084 bool speak() const { return (mActionType == T_MESSAGE) && mSpeak; }
00085 int flags() const;
00086 #ifdef NDEBUG
00087 void dumpDebug() const { }
00088 #else
00089 void dumpDebug() const;
00090 #endif
00091
00092 protected:
00093 enum Type { T_MESSAGE, T_FILE, T_COMMAND, T_AUDIO, T_EMAIL };
00094
00095 KAAlarmEventBase() : mRepeatCount(0), mLateCancel(0), mAutoClose(false), mBeep(false), mRepeatAtLogin(false),
00096 mDisplaying(false), mEmailBcc(false), mConfirmAck(false) { }
00097 KAAlarmEventBase(const KAAlarmEventBase& rhs) { copy(rhs); }
00098 KAAlarmEventBase& operator=(const KAAlarmEventBase& rhs) { copy(rhs); return *this; }
00099 void copy(const KAAlarmEventBase&);
00100 void set(int flags);
00101
00102 QString mEventID;
00103 QString mText;
00104 DateTime mNextMainDateTime;
00105 QColor mBgColour;
00106 QColor mFgColour;
00107 QFont mFont;
00108 uint mEmailFromIdentity;
00109 EmailAddressList mEmailAddresses;
00110 QString mEmailSubject;
00111 QStringList mEmailAttachments;
00112 float mSoundVolume;
00113 float mFadeVolume;
00114 int mFadeSeconds;
00115 Type mActionType;
00116 int mRepeatCount;
00117 int mRepeatInterval;
00118 int mNextRepeat;
00119 int mLateCancel;
00120 bool mAutoClose;
00121 bool mCommandScript;
00122 bool mBeep;
00123 bool mSpeak;
00124 bool mRepeatSound;
00125 bool mRepeatAtLogin;
00126 bool mDisplaying;
00127 bool mEmailBcc;
00128 bool mConfirmAck;
00129 bool mDefaultFont;
00130
00131 friend class AlarmData;
00132 };
00133
00134
00135
00136
00137 class KAAlarm : public KAAlarmEventBase
00138 {
00139 public:
00140
00141 enum Action
00142 {
00143 MESSAGE = T_MESSAGE,
00144 FILE = T_FILE,
00145 COMMAND = T_COMMAND,
00146 EMAIL = T_EMAIL,
00147 AUDIO = T_AUDIO
00148 };
00149
00150
00151
00152 enum Type
00153 {
00154 INVALID_ALARM = 0,
00155 MAIN_ALARM = 1,
00156
00157 REMINDER_ALARM = 0x02,
00158 DEFERRED_ALARM = 0x04,
00159 DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM,
00160
00161
00162 AT_LOGIN_ALARM = 0x10,
00163 DISPLAYING_ALARM = 0x20,
00164
00165 AUDIO_ALARM = 0x30,
00166 PRE_ACTION_ALARM = 0x40,
00167 POST_ACTION_ALARM = 0x50
00168 };
00169 enum SubType
00170 {
00171 INVALID__ALARM = INVALID_ALARM,
00172 MAIN__ALARM = MAIN_ALARM,
00173
00174 REMINDER__ALARM = REMINDER_ALARM,
00175 TIMED_DEFERRAL_FLAG = 0x08,
00176 DEFERRED_DATE__ALARM = DEFERRED_ALARM,
00177 DEFERRED_TIME__ALARM = DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
00178 DEFERRED_REMINDER_DATE__ALARM = REMINDER_ALARM | DEFERRED_ALARM,
00179 DEFERRED_REMINDER_TIME__ALARM = REMINDER_ALARM | DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
00180
00181
00182 AT_LOGIN__ALARM = AT_LOGIN_ALARM,
00183 DISPLAYING__ALARM = DISPLAYING_ALARM,
00184
00185 AUDIO__ALARM = AUDIO_ALARM,
00186 PRE_ACTION__ALARM = PRE_ACTION_ALARM,
00187 POST_ACTION__ALARM = POST_ACTION_ALARM
00188 };
00189
00190 KAAlarm() : mType(INVALID__ALARM), mDeferred(false) { }
00191 KAAlarm(const KAAlarm&);
00192 ~KAAlarm() { }
00193 Action action() const { return (Action)mActionType; }
00194 bool valid() const { return mType != INVALID__ALARM; }
00195 Type type() const { return static_cast<Type>(mType & ~TIMED_DEFERRAL_FLAG); }
00196 SubType subType() const { return mType; }
00197 const QString& eventID() const { return mEventID; }
00198 DateTime dateTime(bool withRepeats = false) const
00199 { return (withRepeats && mNextRepeat && mRepeatInterval)
00200 ? mNextMainDateTime.addSecs(mNextRepeat * mRepeatInterval * 60) : mNextMainDateTime; }
00201 QDate date() const { return mNextMainDateTime.date(); }
00202 QTime time() const { return mNextMainDateTime.time(); }
00203 QString audioFile() const { return (mActionType == T_AUDIO) && !mBeep ? mText : QString::null; }
00204 float soundVolume() const { return (mActionType == T_AUDIO) && !mBeep && !mText.isEmpty() ? mSoundVolume : -1; }
00205 float fadeVolume() const { return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeSeconds && !mBeep && !mText.isEmpty() ? mFadeVolume : -1; }
00206 int fadeSeconds() const { return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeVolume >= 0 && !mBeep && !mText.isEmpty() ? mFadeSeconds : 0; }
00207 bool repeatSound() const { return (mActionType == T_AUDIO) && mRepeatSound && !mBeep && !mText.isEmpty(); }
00208 bool reminder() const { return mType == REMINDER__ALARM; }
00209 bool deferred() const { return mDeferred; }
00210 void setTime(const DateTime& dt) { mNextMainDateTime = dt; }
00211 void setTime(const QDateTime& dt) { mNextMainDateTime = dt; }
00212 int flags() const;
00213 #ifdef NDEBUG
00214 void dumpDebug() const { }
00215 static const char* debugType(Type) { return ""; }
00216 #else
00217 void dumpDebug() const;
00218 static const char* debugType(Type);
00219 #endif
00220
00221 private:
00222 SubType mType;
00223 bool mRecurs;
00224 bool mDeferred;
00225
00226 friend class KAEvent;
00227 };
00228
00229
00231 class KAEvent : public KAAlarmEventBase
00232 {
00233 public:
00234 enum
00235 {
00236 #ifdef OLD_DCOP
00237
00238
00239
00240 LATE_CANCEL = 0x01,
00241 #endif
00242 BEEP = 0x02,
00243 REPEAT_AT_LOGIN = 0x04,
00244 ANY_TIME = 0x08,
00245 CONFIRM_ACK = 0x10,
00246 EMAIL_BCC = 0x20,
00247 DEFAULT_FONT = 0x40,
00248 REPEAT_SOUND = 0x80,
00249 DISABLED = 0x100,
00250 AUTO_CLOSE = 0x200,
00251 SCRIPT = 0x400,
00252 EXEC_IN_XTERM = 0x800,
00253 SPEAK = 0x1000,
00254 COPY_KORGANIZER = 0x2000,
00255 #ifdef OLD_DCOP
00256
00257 #else
00258
00259 #endif
00260 REMINDER = 0x10000,
00261 DEFERRAL = 0x20000,
00262 TIMED_FLAG = 0x40000,
00263 DATE_DEFERRAL = DEFERRAL,
00264 TIME_DEFERRAL = DEFERRAL | TIMED_FLAG,
00265 DISPLAYING_ = 0x80000,
00266 READ_ONLY_FLAGS = 0xF0000
00267 };
00269 enum Status
00270 {
00271 ACTIVE,
00272 EXPIRED,
00273 DISPLAYING,
00274 TEMPLATE,
00275 KORGANIZER
00276 };
00277 enum Action
00278 {
00279 MESSAGE = T_MESSAGE,
00280 FILE = T_FILE,
00281 COMMAND = T_COMMAND,
00282 EMAIL = T_EMAIL
00283 };
00284 enum OccurType
00285 {
00286 NO_OCCURRENCE = 0,
00287 FIRST_OR_ONLY_OCCURRENCE = 0x01,
00288 RECURRENCE_DATE = 0x02,
00289 RECURRENCE_DATE_TIME = 0x03,
00290 LAST_RECURRENCE = 0x04,
00291 OCCURRENCE_REPEAT = 0x10,
00292 FIRST_OR_ONLY_OCCURRENCE_REPEAT = OCCURRENCE_REPEAT | FIRST_OR_ONLY_OCCURRENCE,
00293 RECURRENCE_DATE_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE,
00294 RECURRENCE_DATE_TIME_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE_TIME,
00295 LAST_RECURRENCE_REPEAT = OCCURRENCE_REPEAT | LAST_RECURRENCE
00296 };
00297 enum OccurOption
00298 {
00299 IGNORE_REPETITION,
00300 RETURN_REPETITION,
00301 ALLOW_FOR_REPETITION
00302 };
00303 enum DeferLimitType
00304 {
00305 LIMIT_NONE,
00306 LIMIT_MAIN,
00307 LIMIT_RECURRENCE,
00308 LIMIT_REPETITION,
00309 LIMIT_REMINDER
00310 };
00311
00312 KAEvent() : mRevision(0), mRecurrence(0), mAlarmCount(0) { }
00313 KAEvent(const QDateTime& dt, const QString& message, const QColor& bg, const QColor& fg, const QFont& f, Action action, int lateCancel, int flags)
00314 : mRecurrence(0) { set(dt, message, bg, fg, f, action, lateCancel, flags); }
00315 explicit KAEvent(const KCal::Event& e) : mRecurrence(0) { set(e); }
00316 KAEvent(const KAEvent& e) : KAAlarmEventBase(e), mRecurrence(0) { copy(e); }
00317 ~KAEvent() { delete mRecurrence; }
00318 KAEvent& operator=(const KAEvent& e) { if (&e != this) copy(e); return *this; }
00319 void set(const KCal::Event&);
00320 void set(const QDateTime&, const QString& message, const QColor& bg, const QColor& fg, const QFont&, Action, int lateCancel, int flags);
00321 void setEmail(uint from, const EmailAddressList&, const QString& subject, const QStringList& attachments);
00322 void setAudioFile(const QString& filename, float volume, float fadeVolume, int fadeSeconds);
00323 void setTemplate(const QString& name, int afterTime = -1) { mTemplateName = name; mTemplateAfterTime = afterTime; mUpdated = true; }
00324 void setActions(const QString& pre, const QString& post) { mPreAction = pre; mPostAction = post; mUpdated = true; }
00325 OccurType setNextOccurrence(const QDateTime& preDateTime);
00326 void setFirstRecurrence();
00327 void setEventID(const QString& id) { mEventID = id; mUpdated = true; }
00328 void setDate(const QDate& d) { mNextMainDateTime.set(d); mUpdated = true; }
00329 void setTime(const QDateTime& dt) { mNextMainDateTime.set(dt); mUpdated = true; }
00330 void setSaveDateTime(const QDateTime& dt) { mSaveDateTime = dt; mUpdated = true; }
00331 void setLateCancel(int lc) { mLateCancel = lc; mUpdated = true; }
00332 void setAutoClose(bool ac) { mAutoClose = ac; mUpdated = true; }
00333 void setRepeatAtLogin(bool rl) { mRepeatAtLogin = rl; mUpdated = true; }
00334 void setUid(Status s) { mEventID = uid(mEventID, s); mUpdated = true; }
00335 void setKMailSerialNumber(unsigned long n) { mKMailSerialNumber = n; }
00336 void setLogFile(const QString& logfile);
00337 void setReminder(int minutes, bool onceOnly);
00338 bool defer(const DateTime&, bool reminder, bool adjustRecurrence = false);
00339 void cancelDefer();
00340 void cancelCancelledDeferral();
00341 void setDeferDefaultMinutes(int minutes) { mDeferDefaultMinutes = minutes; mUpdated = true; }
00342 bool setDisplaying(const KAEvent&, KAAlarm::Type, const QDateTime&);
00343 void reinstateFromDisplaying(const KAEvent& dispEvent);
00344 void setArchive() { mArchive = true; mUpdated = true; }
00345 void setEnabled(bool enable) { mEnabled = enable; mUpdated = true; }
00346 void setUpdated() { mUpdated = true; }
00347 void clearUpdated() const { mUpdated = false; }
00348 void removeExpiredAlarm(KAAlarm::Type);
00349 void incrementRevision() { ++mRevision; mUpdated = true; }
00350
00351 KCal::Event* event() const;
00352 bool isTemplate() const { return !mTemplateName.isEmpty(); }
00353 const QString& templateName() const { return mTemplateName; }
00354 bool usingDefaultTime() const { return mTemplateAfterTime == 0; }
00355 int templateAfterTime() const { return mTemplateAfterTime; }
00356 KAAlarm alarm(KAAlarm::Type) const;
00357 KAAlarm firstAlarm() const;
00358 KAAlarm nextAlarm(const KAAlarm& al) const { return nextAlarm(al.type()); }
00359 KAAlarm nextAlarm(KAAlarm::Type) const;
00360 KAAlarm convertDisplayingAlarm() const;
00361 bool updateKCalEvent(KCal::Event&, bool checkUid = true, bool original = false, bool cancelCancelledDefer = false) const;
00362 Action action() const { return (Action)mActionType; }
00363 bool displayAction() const { return mActionType == T_MESSAGE || mActionType == T_FILE; }
00364 const QString& id() const { return mEventID; }
00365 bool valid() const { return mAlarmCount && (mAlarmCount != 1 || !mRepeatAtLogin); }
00366 int alarmCount() const { return mAlarmCount; }
00367 const DateTime& startDateTime() const { return mStartDateTime; }
00368 DateTime mainDateTime(bool withRepeats = false) const
00369 { return (withRepeats && mNextRepeat && mRepeatInterval)
00370 ? mNextMainDateTime.addSecs(mNextRepeat * mRepeatInterval * 60) : mNextMainDateTime; }
00371 QDate mainDate() const { return mNextMainDateTime.date(); }
00372 QTime mainTime() const { return mNextMainDateTime.time(); }
00373 DateTime mainEndRepeatTime() const { return (mRepeatCount > 0 && mRepeatInterval)
00374 ? mNextMainDateTime.addSecs(mRepeatCount * mRepeatInterval * 60) : mNextMainDateTime; }
00375 int reminder() const { return mReminderMinutes; }
00376 bool reminderOnceOnly() const { return mReminderOnceOnly; }
00377 bool reminderDeferral() const { return mDeferral == REMINDER_DEFERRAL; }
00378 int reminderArchived() const { return mArchiveReminderMinutes; }
00379 DateTime deferDateTime() const { return mDeferralTime; }
00380 DateTime deferralLimit(DeferLimitType* = 0) const;
00381 int deferDefaultMinutes() const { return mDeferDefaultMinutes; }
00382 DateTime displayDateTime() const;
00383 const QString& messageFileOrCommand() const { return mText; }
00384 QString logFile() const { return mLogFile; }
00385 bool commandXterm() const { return mCommandXterm; }
00386 unsigned long kmailSerialNumber() const { return mKMailSerialNumber; }
00387 bool copyToKOrganizer() const { return mCopyToKOrganizer; }
00388 const QString& audioFile() const { return mAudioFile; }
00389 float soundVolume() const { return !mAudioFile.isEmpty() ? mSoundVolume : -1; }
00390 float fadeVolume() const { return !mAudioFile.isEmpty() && mSoundVolume >= 0 && mFadeSeconds ? mFadeVolume : -1; }
00391 int fadeSeconds() const { return !mAudioFile.isEmpty() && mSoundVolume >= 0 && mFadeVolume >= 0 ? mFadeSeconds : 0; }
00392 bool repeatSound() const { return mRepeatSound && !mAudioFile.isEmpty(); }
00393 const QString& preAction() const { return mPreAction; }
00394 const QString& postAction() const { return mPostAction; }
00395 bool recurs() const { return checkRecur() != KARecurrence::NO_RECUR; }
00396 KARecurrence::Type recurType() const { return checkRecur(); }
00397 KARecurrence* recurrence() const { return mRecurrence; }
00398 int recurInterval() const;
00399 int longestRecurrenceInterval() const { return mRecurrence ? mRecurrence->longestInterval() : 0; }
00400 QString recurrenceText(bool brief = false) const;
00401 QString repetitionText(bool brief = false) const;
00402 bool occursAfter(const QDateTime& preDateTime, bool includeRepetitions) const;
00403 OccurType nextOccurrence(const QDateTime& preDateTime, DateTime& result, OccurOption = IGNORE_REPETITION) const;
00404 OccurType previousOccurrence(const QDateTime& afterDateTime, DateTime& result, bool includeRepetitions = false) const;
00405 int flags() const;
00406 bool deferred() const { return mDeferral > 0; }
00407 bool toBeArchived() const { return mArchive; }
00408 bool enabled() const { return mEnabled; }
00409 bool updated() const { return mUpdated; }
00410 bool mainExpired() const { return mMainExpired; }
00411 bool expired() const { return mDisplaying && mMainExpired || uidStatus(mEventID) == EXPIRED; }
00412 Status uidStatus() const { return uidStatus(mEventID); }
00413 static Status uidStatus(const QString& uid);
00414 static QString uid(const QString& id, Status);
00415 static KAEvent findTemplateName(AlarmCalendar&, const QString& name);
00416
00417 struct MonthPos
00418 {
00419 MonthPos() : days(7) { }
00420 int weeknum;
00421 QBitArray days;
00422 };
00423 bool setRepetition(int interval, int count);
00424 void setNoRecur() { clearRecur(); }
00425 void setRecurrence(const KARecurrence&);
00426 bool setRecurMinutely(int freq, int count, const QDateTime& end);
00427 bool setRecurDaily(int freq, const QBitArray& days, int count, const QDate& end);
00428 bool setRecurWeekly(int freq, const QBitArray& days, int count, const QDate& end);
00429 bool setRecurMonthlyByDate(int freq, const QValueList<int>& days, int count, const QDate& end);
00430 bool setRecurMonthlyByPos(int freq, const QValueList<MonthPos>& pos, int count, const QDate& end);
00431 bool setRecurAnnualByDate(int freq, const QValueList<int>& months, int day, KARecurrence::Feb29Type, int count, const QDate& end);
00432 bool setRecurAnnualByPos(int freq, const QValueList<MonthPos>& pos, const QValueList<int>& months, int count, const QDate& end);
00433
00434 #ifdef NDEBUG
00435 void dumpDebug() const { }
00436 #else
00437 void dumpDebug() const;
00438 #endif
00439 static int calVersion();
00440 static QString calVersionString();
00441 static bool adjustStartOfDay(const KCal::Event::List&);
00442 static void convertKCalEvents(KCal::Calendar&, int version, bool adjustSummerTime);
00443 static void convertRepetitions(KCal::CalendarLocal&);
00444
00445 private:
00446 enum DeferType {
00447 CANCEL_DEFERRAL = -1,
00448 NO_DEFERRAL = 0,
00449 NORMAL_DEFERRAL,
00450 REMINDER_DEFERRAL
00451 };
00452
00453 void copy(const KAEvent&);
00454 bool setRecur(KCal::RecurrenceRule::PeriodType, int freq, int count, const QDateTime& end, KARecurrence::Feb29Type = KARecurrence::FEB29_FEB29);
00455 void clearRecur();
00456 KARecurrence::Type checkRecur() const;
00457 void checkRepetition() const;
00458 OccurType nextRecurrence(const QDateTime& preDateTime, DateTime& result) const;
00459 OccurType previousRecurrence(const QDateTime& afterDateTime, DateTime& result) const;
00460 static bool convertRepetition(KCal::Event*);
00461 KCal::Alarm* initKCalAlarm(KCal::Event&, const DateTime&, const QStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM) const;
00462 KCal::Alarm* initKCalAlarm(KCal::Event&, int startOffsetSecs, const QStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM) const;
00463 static DateTime readDateTime(const KCal::Event&, bool dateOnly, DateTime& start);
00464 static void readAlarms(const KCal::Event&, void* alarmMap);
00465 static void readAlarm(const KCal::Alarm&, AlarmData&);
00466 inline void set_deferral(DeferType);
00467 inline void set_reminder(int minutes);
00468 inline void set_archiveReminder();
00469
00470 QString mTemplateName;
00471 QString mAudioFile;
00472 QString mPreAction;
00473 QString mPostAction;
00474 DateTime mStartDateTime;
00475 QDateTime mSaveDateTime;
00476 QDateTime mAtLoginDateTime;
00477 DateTime mDeferralTime;
00478 DateTime mDisplayingTime;
00479 int mDisplayingFlags;
00480 int mReminderMinutes;
00481 int mArchiveReminderMinutes;
00482 int mDeferDefaultMinutes;
00483 int mRevision;
00484 KARecurrence* mRecurrence;
00485 int mAlarmCount;
00486 DeferType mDeferral;
00487 unsigned long mKMailSerialNumber;
00488 int mTemplateAfterTime;
00489 QString mLogFile;
00490 bool mCommandXterm;
00491 bool mCopyToKOrganizer;
00492 bool mReminderOnceOnly;
00493 bool mMainExpired;
00494 bool mArchiveRepeatAtLogin;
00495 bool mArchive;
00496 bool mEnabled;
00497 mutable bool mUpdated;
00498 };
00499
00500 #endif // KALARMEVENT_H