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>
00027 #include <QFont>
00028 #include <QList>
00029
00030 #include <kcal/person.h>
00031 #include <kcal/event.h>
00032 #include <kcal/duration.h>
00033 namespace KCal { class CalendarLocal; }
00034
00035 #include "datetime.h"
00036 #include "karecurrence.h"
00037 #include "kcalendar.h"
00038 #include "preferences.h"
00039
00040 class AlarmResource;
00041 class KARecurrence;
00042 struct AlarmData;
00043
00044
00045 typedef KCal::Person EmailAddress;
00046 class EmailAddressList : public QList<KCal::Person>
00047 {
00048 public:
00049 EmailAddressList() : QList<KCal::Person>() { }
00050 EmailAddressList(const QList<KCal::Person>& list) { operator=(list); }
00051 EmailAddressList& operator=(const QList<KCal::Person>&);
00052 operator QStringList() const;
00053 QString join(const QString& separator) const;
00054 private:
00055 QString address(int index) const;
00056 };
00057
00058
00059
00060 class KAAlarmEventBase
00061 {
00062 public:
00063 ~KAAlarmEventBase() { }
00064 const QString& cleanText() const { return mText; }
00065 QString message() const { return (mActionType == T_MESSAGE || mActionType == T_EMAIL) ? mText : QString(); }
00066 QString fileName() const { return (mActionType == T_FILE) ? mText : QString(); }
00067 QString command() const { return (mActionType == T_COMMAND) ? mText : QString(); }
00068 uint emailFromId() const { return mEmailFromIdentity; }
00069 const EmailAddressList& emailAddresses() const { return mEmailAddresses; }
00070 QString emailAddresses(const QString& sep) const { return mEmailAddresses.join(sep); }
00071 const QString& emailSubject() const { return mEmailSubject; }
00072 const QStringList& emailAttachments() const { return mEmailAttachments; }
00073 QString emailAttachments(const QString& sep) const { return mEmailAttachments.join(sep); }
00074 bool emailBcc() const { return mEmailBcc; }
00075 const QColor& bgColour() const { return mBgColour; }
00076 const QColor& fgColour() const { return mFgColour; }
00077 bool defaultFont() const { return mDefaultFont; }
00078 QFont font() const;
00079 int lateCancel() const { return mLateCancel; }
00080 bool autoClose() const { return mAutoClose; }
00081 bool commandScript() const { return mCommandScript; }
00082 bool confirmAck() const { return mConfirmAck; }
00083 bool repeatAtLogin() const { return mRepeatAtLogin; }
00084 int repeatCount() const { return mRepeatCount; }
00085 KCal::Duration repeatInterval() const { return mRepeatInterval; }
00086 bool displaying() const { return mDisplaying; }
00087 bool beep() const { return mBeep; }
00088 int flags() const;
00089 #ifdef NDEBUG
00090 void dumpDebug() const { }
00091 #else
00092 void dumpDebug() const;
00093 #endif
00094
00095 protected:
00096 enum Type { T_MESSAGE, T_FILE, T_COMMAND, T_AUDIO, T_EMAIL };
00097
00098 KAAlarmEventBase() : mRepeatCount(0), mRepeatInterval(0), mNextRepeat(0), mLateCancel(0),
00099 mAutoClose(false), mBeep(false), mRepeatAtLogin(false),
00100 mDisplaying(false), mEmailBcc(false), mConfirmAck(false) { }
00101 KAAlarmEventBase(const KAAlarmEventBase& rhs) { copy(rhs); }
00102 KAAlarmEventBase& operator=(const KAAlarmEventBase& rhs) { copy(rhs); return *this; }
00103 void copy(const KAAlarmEventBase&);
00104 void set(int flags);
00105
00106 QString mEventID;
00107 QString mText;
00108 DateTime mNextMainDateTime;
00109 QColor mBgColour;
00110 QColor mFgColour;
00111 QFont mFont;
00112 uint mEmailFromIdentity;
00113 EmailAddressList mEmailAddresses;
00114 QString mEmailSubject;
00115 QStringList mEmailAttachments;
00116 float mSoundVolume;
00117 float mFadeVolume;
00118 int mFadeSeconds;
00119 Type mActionType;
00120 int mRepeatCount;
00121 KCal::Duration mRepeatInterval;
00122 int mNextRepeat;
00123 int mLateCancel;
00124 bool mAutoClose;
00125 bool mCommandScript;
00126 bool mBeep;
00127 bool mRepeatSound;
00128 bool mRepeatAtLogin;
00129 bool mDisplaying;
00130 bool mEmailBcc;
00131 bool mConfirmAck;
00132 bool mDefaultFont;
00133
00134 friend struct AlarmData;
00135 };
00136
00137
00138
00139
00140 class KAAlarm : public KAAlarmEventBase
00141 {
00142 public:
00143
00144 enum Action
00145 {
00146 MESSAGE = T_MESSAGE,
00147 FILE = T_FILE,
00148 COMMAND = T_COMMAND,
00149 EMAIL = T_EMAIL,
00150 AUDIO = T_AUDIO
00151 };
00152
00153
00154
00155 enum Type
00156 {
00157 INVALID_ALARM = 0,
00158 MAIN_ALARM = 1,
00159
00160 REMINDER_ALARM = 0x02,
00161 DEFERRED_ALARM = 0x04,
00162 DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM,
00163
00164
00165 AT_LOGIN_ALARM = 0x10,
00166 DISPLAYING_ALARM = 0x20,
00167
00168 AUDIO_ALARM = 0x30,
00169 PRE_ACTION_ALARM = 0x40,
00170 POST_ACTION_ALARM = 0x50
00171 };
00172 enum SubType
00173 {
00174 INVALID__ALARM = INVALID_ALARM,
00175 MAIN__ALARM = MAIN_ALARM,
00176
00177 REMINDER__ALARM = REMINDER_ALARM,
00178 TIMED_DEFERRAL_FLAG = 0x08,
00179 DEFERRED_DATE__ALARM = DEFERRED_ALARM,
00180 DEFERRED_TIME__ALARM = DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
00181 DEFERRED_REMINDER_DATE__ALARM = REMINDER_ALARM | DEFERRED_ALARM,
00182 DEFERRED_REMINDER_TIME__ALARM = REMINDER_ALARM | DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
00183
00184
00185 AT_LOGIN__ALARM = AT_LOGIN_ALARM,
00186 DISPLAYING__ALARM = DISPLAYING_ALARM,
00187
00188 AUDIO__ALARM = AUDIO_ALARM,
00189 PRE_ACTION__ALARM = PRE_ACTION_ALARM,
00190 POST_ACTION__ALARM = POST_ACTION_ALARM
00191 };
00192
00193 KAAlarm() : mType(INVALID__ALARM), mDeferred(false) { }
00194 KAAlarm(const KAAlarm&);
00195 ~KAAlarm() { }
00196 Action action() const { return (Action)mActionType; }
00197 bool valid() const { return mType != INVALID__ALARM; }
00198 Type type() const { return static_cast<Type>(mType & ~TIMED_DEFERRAL_FLAG); }
00199 SubType subType() const { return mType; }
00200 const QString& eventID() const { return mEventID; }
00201 DateTime dateTime(bool withRepeats = false) const
00202 { return (withRepeats && mNextRepeat && mRepeatInterval)
00203 ? (mRepeatInterval * mNextRepeat).end(mNextMainDateTime.kDateTime()) : mNextMainDateTime; }
00204 QDate date() const { return mNextMainDateTime.date(); }
00205 QTime time() const { return mNextMainDateTime.effectiveTime(); }
00206 QString audioFile() const { return (mActionType == T_AUDIO) && !mBeep ? mText : QString(); }
00207 float soundVolume() const { return (mActionType == T_AUDIO) && !mBeep && !mText.isEmpty() ? mSoundVolume : -1; }
00208 float fadeVolume() const { return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeSeconds && !mBeep && !mText.isEmpty() ? mFadeVolume : -1; }
00209 int fadeSeconds() const { return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeVolume >= 0 && !mBeep && !mText.isEmpty() ? mFadeSeconds : 0; }
00210 bool repeatSound() const { return (mActionType == T_AUDIO) && mRepeatSound && !mBeep && !mText.isEmpty(); }
00211 bool reminder() const { return mType == REMINDER__ALARM; }
00212 bool deferred() const { return mDeferred; }
00213 void setTime(const DateTime& dt) { mNextMainDateTime = dt; }
00214 void setTime(const KDateTime& dt) { mNextMainDateTime = dt; }
00215 int flags() const;
00216 #ifdef NDEBUG
00217 void dumpDebug() const { }
00218 static const char* debugType(Type) { return ""; }
00219 #else
00220 void dumpDebug() const;
00221 static const char* debugType(Type);
00222 #endif
00223
00224 private:
00225 SubType mType;
00226 bool mRecurs;
00227 bool mDeferred;
00228
00229 friend class KAEvent;
00230 };
00231
00232
00234 class KAEvent : public KAAlarmEventBase
00235 {
00236 public:
00237 typedef QList<KAEvent*> List;
00238 enum
00239 {
00240 BEEP = 0x02,
00241 REPEAT_AT_LOGIN = 0x04,
00242 ANY_TIME = 0x08,
00243 CONFIRM_ACK = 0x10,
00244 EMAIL_BCC = 0x20,
00245 DEFAULT_FONT = 0x40,
00246 REPEAT_SOUND = 0x80,
00247 DISABLED = 0x100,
00248 AUTO_CLOSE = 0x200,
00249 SCRIPT = 0x400,
00250 EXEC_IN_XTERM = 0x800,
00251 SPEAK = 0x1000,
00252 COPY_KORGANIZER = 0x2000,
00253 WORK_TIME_ONLY = 0x4000,
00254 DISPLAY_COMMAND = 0x8000,
00255
00256 REMINDER = 0x10000,
00257 DEFERRAL = 0x20000,
00258 TIMED_FLAG = 0x40000,
00259 DATE_DEFERRAL = DEFERRAL,
00260 TIME_DEFERRAL = DEFERRAL | TIMED_FLAG,
00261 DISPLAYING_ = 0x80000,
00262 READ_ONLY_FLAGS = 0xF0000
00263 };
00264 enum Action
00265 {
00266 MESSAGE = T_MESSAGE,
00267 FILE = T_FILE,
00268 COMMAND = T_COMMAND,
00269 EMAIL = T_EMAIL
00270 };
00271 enum OccurType
00272 {
00273 NO_OCCURRENCE = 0,
00274 FIRST_OR_ONLY_OCCURRENCE = 0x01,
00275 RECURRENCE_DATE = 0x02,
00276 RECURRENCE_DATE_TIME = 0x03,
00277 LAST_RECURRENCE = 0x04,
00278 OCCURRENCE_REPEAT = 0x10,
00279 FIRST_OR_ONLY_OCCURRENCE_REPEAT = OCCURRENCE_REPEAT | FIRST_OR_ONLY_OCCURRENCE,
00280 RECURRENCE_DATE_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE,
00281 RECURRENCE_DATE_TIME_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE_TIME,
00282 LAST_RECURRENCE_REPEAT = OCCURRENCE_REPEAT | LAST_RECURRENCE
00283 };
00284 enum OccurOption
00285 {
00286 IGNORE_REPETITION,
00287 RETURN_REPETITION,
00288 ALLOW_FOR_REPETITION
00289 };
00290 enum DeferLimitType
00291 {
00292 LIMIT_NONE,
00293 LIMIT_MAIN,
00294 LIMIT_RECURRENCE,
00295 LIMIT_REPETITION,
00296 LIMIT_REMINDER
00297 };
00298 enum TriggerType
00299 {
00300 ALL_TRIGGER,
00301 MAIN_TRIGGER,
00302 WORK_TRIGGER,
00303 ALL_WORK_TRIGGER,
00304 DISPLAY_TRIGGER
00305 };
00306
00307 KAEvent() : mReminderMinutes(0), mRevision(0), mRecurrence(0), mAlarmCount(0),
00308 mDeferral(NO_DEFERRAL), mChangeCount(0), mChanged(false), mWorkTimeOnly(false) { }
00309 KAEvent(const KDateTime& dt, const QString& message, const QColor& bg, const QColor& fg, const QFont& f, Action action, int lateCancel, int flags, bool changesPending = false)
00310 : mRecurrence(0) { set(dt, message, bg, fg, f, action, lateCancel, flags, changesPending); }
00311 explicit KAEvent(const KCal::Event* e) : mRecurrence(0) { set(e); }
00312 KAEvent(const KAEvent& e) : KAAlarmEventBase(e), mRecurrence(0) { copy(e); }
00313 ~KAEvent() { delete mRecurrence; }
00314 KAEvent& operator=(const KAEvent& e) { if (&e != this) copy(e); return *this; }
00315 void set(const KCal::Event*);
00316 void set(const KDateTime&, const QString& message, const QColor& bg, const QColor& fg, const QFont&, Action, int lateCancel, int flags, bool changesPending = false);
00317 void setEmail(uint from, const EmailAddressList&, const QString& subject, const QStringList& attachments);
00318 void setResource(AlarmResource* r) { mResource = r; }
00319 void setAudioFile(const QString& filename, float volume, float fadeVolume, int fadeSeconds);
00320 void setTemplate(const QString& name, int afterTime = -1);
00321 void setActions(const QString& pre, const QString& post, bool cancelOnError)
00322 { mPreAction = pre; mPostAction = post; mCancelOnPreActErr = cancelOnError; mUpdated = true; }
00323 OccurType setNextOccurrence(const KDateTime& preDateTime);
00324 void setFirstRecurrence();
00325 void setCategory(KCalEvent::Status);
00326 void setUid(KCalEvent::Status s) { mEventID = KCalEvent::uid(mEventID, s); mUpdated = true; }
00327 void setEventID(const QString& id) { mEventID = id; mUpdated = true; }
00328 void setTime(const KDateTime& dt) { mNextMainDateTime = dt; mUpdated = true; }
00329 void setSaveDateTime(const KDateTime& dt) { mSaveDateTime = dt; mUpdated = true; }
00330 void setLateCancel(int lc) { mLateCancel = lc; mUpdated = true; }
00331 void setAutoClose(bool ac) { mAutoClose = ac; mUpdated = true; }
00332 void setRepeatAtLogin(bool rl) { mRepeatAtLogin = rl; mUpdated = true; }
00333 void setWorkTimeOnly(bool wto) { mWorkTimeOnly = wto; }
00334 void setKMailSerialNumber(unsigned long n) { mKMailSerialNumber = n; }
00335 void setLogFile(const QString& logfile);
00336 void setReminder(int minutes, bool onceOnly);
00337 bool defer(const DateTime&, bool reminder, bool adjustRecurrence = false);
00338 void cancelDefer();
00339 void cancelCancelledDeferral();
00340 void setDeferDefaultMinutes(int minutes) { mDeferDefaultMinutes = minutes; mUpdated = true; }
00341 bool setDisplaying(const KAEvent&, KAAlarm::Type, const QString& resourceID, const KDateTime&, bool showEdit, bool showDefer);
00342 void reinstateFromDisplaying(const KCal::Event*, QString& resourceID, bool& showEdit, bool& showDefer);
00343 void setArchive() { mArchive = true; mUpdated = true; }
00344 void setEnabled(bool enable) { mEnabled = enable; mUpdated = true; }
00345 void startChanges() { ++mChangeCount; }
00346 void endChanges();
00347 void setUpdated() { mUpdated = true; }
00348 void clearUpdated() const { mUpdated = false; }
00349 void clearResourceID() { mResourceId.clear(); }
00350 void updateWorkHours() const { if (mWorkTimeOnly) calcTriggerTimes(); }
00351 void removeExpiredAlarm(KAAlarm::Type);
00352 void incrementRevision() { ++mRevision; mUpdated = true; }
00353
00354 bool isTemplate() const { return !mTemplateName.isEmpty(); }
00355 const QString& templateName() const { return mTemplateName; }
00356 bool usingDefaultTime() const { return mTemplateAfterTime == 0; }
00357 int templateAfterTime() const { return mTemplateAfterTime; }
00358 KAAlarm alarm(KAAlarm::Type) const;
00359 KAAlarm firstAlarm() const;
00360 KAAlarm nextAlarm(const KAAlarm& al) const { return nextAlarm(al.type()); }
00361 KAAlarm nextAlarm(KAAlarm::Type) const;
00362 KAAlarm convertDisplayingAlarm() const;
00363 bool updateKCalEvent(KCal::Event*, bool checkUid = true, bool original = false, bool cancelCancelledDefer = false) const;
00364 Action action() const { return (Action)mActionType; }
00365 bool displayAction() const { return mActionType == T_MESSAGE || mActionType == T_FILE || (mActionType == T_COMMAND && mCommandDisplay); }
00366 const QString& id() const { return mEventID; }
00367 bool valid() const { return mAlarmCount && (mAlarmCount != 1 || !mRepeatAtLogin); }
00368 int alarmCount() const { return mAlarmCount; }
00369 const DateTime& startDateTime() const { return mStartDateTime; }
00370 DateTime mainDateTime(bool withRepeats = false) const
00371 { return (withRepeats && mNextRepeat && mRepeatInterval)
00372 ? (mRepeatInterval * mNextRepeat).end(mNextMainDateTime.kDateTime()) : mNextMainDateTime; }
00373 QDate mainDate() const { return mNextMainDateTime.date(); }
00374 QTime mainTime() const { return mNextMainDateTime.effectiveTime(); }
00375 DateTime mainEndRepeatTime() const { return (mRepeatCount > 0 && mRepeatInterval)
00376 ? (mRepeatInterval * mRepeatCount).end(mNextMainDateTime.kDateTime()) : mNextMainDateTime; }
00377 DateTime nextTrigger(TriggerType) const;
00378 int reminder() const { return mReminderMinutes; }
00379 bool reminderOnceOnly() const { return mReminderOnceOnly; }
00380 bool reminderDeferral() const { return mDeferral == REMINDER_DEFERRAL; }
00381 int reminderArchived() const { return mArchiveReminderMinutes; }
00382 DateTime deferDateTime() const { return mDeferralTime; }
00383 DateTime deferralLimit(DeferLimitType* = 0) const;
00384 int deferDefaultMinutes() const { return mDeferDefaultMinutes; }
00385 const QString& messageFileOrCommand() const { return mText; }
00386 QString logFile() const { return mLogFile; }
00387 bool commandXterm() const { return mCommandXterm; }
00388 bool commandDisplay() const { return mCommandDisplay; }
00389 unsigned long kmailSerialNumber() const <