kalarm

alarmevent.h
Go to the documentation of this file.
00001 /*
00002  *  alarmevent.h  -  represents calendar alarms and events
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef KALARMEVENT_H
00022 #define KALARMEVENT_H
00023 
00026 #include <tqcolor.h>
00027 #include <tqfont.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 TQValueList<KCal::Person>
00046 {
00047     public:
00048         EmailAddressList() : TQValueList<KCal::Person>() { }
00049         EmailAddressList(const TQValueList<KCal::Person>& list)  { operator=(list); }
00050         EmailAddressList& operator=(const TQValueList<KCal::Person>&);
00051         TQString join(const TQString& separator) const;
00052 };
00053 
00054 
00055 // Base class containing data common to KAAlarm and KAEvent
00056 class KAAlarmEventBase
00057 {
00058     public:
00059         ~KAAlarmEventBase()  { }
00060         const TQString&     cleanText() const           { return mText; }
00061         TQString            message() const             { return (mActionType == T_MESSAGE || mActionType == T_EMAIL) ? mText : TQString(); }
00062         TQString            fileName() const            { return (mActionType == T_FILE) ? mText : TQString(); }
00063         TQString            command() const             { return (mActionType == T_COMMAND) ? mText : TQString(); }
00064         uint               emailFromId() const         { return mEmailFromIdentity; }
00065         const EmailAddressList& emailAddresses() const { return mEmailAddresses; }
00066         TQString            emailAddresses(const TQString& sep) const  { return mEmailAddresses.join(sep); }
00067         const TQString&     emailSubject() const        { return mEmailSubject; }
00068         const TQStringList& emailAttachments() const    { return mEmailAttachments; }
00069         TQString            emailAttachments(const TQString& sep) const  { return mEmailAttachments.join(sep); }
00070         bool               emailBcc() const            { return mEmailBcc; }
00071         const TQColor&      bgColour() const            { return mBgColour; }
00072         const TQColor&      fgColour() const            { return mFgColour; }
00073         bool               defaultFont() const         { return mDefaultFont; }
00074         const TQFont&       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         TQString            mEventID;          // UID: KCal::Event unique ID
00103         TQString            mText;             // message text, file URL, command, email body [or audio file for KAAlarm]
00104         DateTime           mNextMainDateTime; // next time to display the alarm, excluding repetitions
00105         TQColor             mBgColour;         // background colour of alarm message
00106         TQColor             mFgColour;         // foreground colour of alarm message, or invalid for default
00107         TQFont              mFont;             // font of alarm message (ignored if mDefaultFont true)
00108         uint               mEmailFromIdentity;// KMail identity for email 'From' field, or empty
00109         EmailAddressList   mEmailAddresses;   // ATTENDEE: addresses to send email to
00110         TQString            mEmailSubject;     // SUMMARY: subject line of email
00111         TQStringList        mEmailAttachments; // ATTACH: email attachment file names
00112         float              mSoundVolume;      // volume for sound file, or < 0 for unspecified
00113         float              mFadeVolume;       // initial volume for sound file, or < 0 for no fade
00114         int                mFadeSeconds;      // fade time for sound file, or 0 if none
00115         Type               mActionType;       // alarm action type
00116         int                mRepeatCount;      // sub-repetition count (excluding the first time)
00117         int                mRepeatInterval;   // sub-repetition interval (minutes)
00118         int                mNextRepeat;       // repetition count of next due sub-repetition
00119         int                mLateCancel;       // how many minutes late will cancel the alarm, or 0 for no cancellation
00120         bool               mAutoClose;        // whether to close the alarm window after the late-cancel period
00121         bool               mCommandScript;    // the command text is a script, not a shell command line
00122         bool               mBeep;             // whether to beep when the alarm is displayed
00123         bool               mSpeak;            // whether to speak the message when the alarm is displayed
00124         bool               mRepeatSound;      // whether to repeat the sound file while the alarm is displayed
00125         bool               mRepeatAtLogin;    // whether to repeat the alarm at every login
00126         bool               mDisplaying;       // whether the alarm is currently being displayed
00127         bool               mEmailBcc;         // blind copy the email to the user
00128         bool               mConfirmAck;       // alarm acknowledgement requires confirmation by user
00129         bool               mDefaultFont;      // use default message font, not mFont
00130 
00131     friend class AlarmData;
00132 };
00133 
00134 
00135 // KAAlarm corresponds to a single KCal::Alarm instance.
00136 // A KAEvent may contain multiple KAAlarm's.
00137 class KAAlarm : public KAAlarmEventBase
00138 {
00139     public:
00140         // Define the basic KAAlaem action types
00141         enum Action
00142         {
00143             MESSAGE = T_MESSAGE,   // KCal::Alarm::Display type: display a text message
00144             FILE    = T_FILE,      // KCal::Alarm::Display type: display a file (URL given by the alarm text)
00145             COMMAND = T_COMMAND,   // KCal::Alarm::Procedure type: execute a shell command
00146             EMAIL   = T_EMAIL,     // KCal::Alarm::Email type: send an email
00147             AUDIO   = T_AUDIO      // KCal::Alarm::Audio type: play a sound file
00148         };
00149         // Define the KAAlarm types.
00150         // KAAlarm's of different types may be contained in a KAEvent,
00151         // each defining a different component of the overall alarm.
00152         enum Type
00153         {
00154             INVALID_ALARM       = 0,     // not an alarm
00155             MAIN_ALARM          = 1,     // THE real alarm. Must be the first in the enumeration.
00156             // The following values may be used in combination as a bimask 0x0E
00157             REMINDER_ALARM      = 0x02,  // reminder in advance of main alarm
00158             DEFERRED_ALARM      = 0x04,  // deferred alarm
00159             DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM,  // deferred early warning
00160             // The following values must be greater than the preceding ones, to
00161             // ensure that in ordered processing they are processed afterwards.
00162             AT_LOGIN_ALARM      = 0x10,  // additional repeat-at-login trigger
00163             DISPLAYING_ALARM    = 0x20,  // copy of the alarm currently being displayed
00164             // The following values are for internal KAEvent use only
00165             AUDIO_ALARM         = 0x30,  // sound to play when displaying the alarm
00166             PRE_ACTION_ALARM    = 0x40,  // command to execute before displaying the alarm
00167             POST_ACTION_ALARM   = 0x50   // command to execute after the alarm window is closed
00168         };
00169         enum SubType
00170         {
00171             INVALID__ALARM                = INVALID_ALARM,
00172             MAIN__ALARM                   = MAIN_ALARM,
00173             // The following values may be used in combination as a bimask 0x0E
00174             REMINDER__ALARM               = REMINDER_ALARM,
00175             TIMED_DEFERRAL_FLAG           = 0x08,  // deferral has a time; if clear, it is date-only
00176             DEFERRED_DATE__ALARM          = DEFERRED_ALARM,  // deferred alarm - date-only
00177             DEFERRED_TIME__ALARM          = DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
00178             DEFERRED_REMINDER_DATE__ALARM = REMINDER_ALARM | DEFERRED_ALARM,  // deferred early warning (date-only)
00179             DEFERRED_REMINDER_TIME__ALARM = REMINDER_ALARM | DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,  // deferred early warning (date/time)
00180             // The following values must be greater than the preceding ones, to
00181             // ensure that in ordered processing they are processed afterwards.
00182             AT_LOGIN__ALARM               = AT_LOGIN_ALARM,
00183             DISPLAYING__ALARM             = DISPLAYING_ALARM,
00184             // The following values are for internal KAEvent use only
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 TQString&     eventID() const              { return mEventID; }
00198         DateTime           dateTime(bool withRepeats = false) const
00199                                                         { return (withRepeats && mNextRepeat && mRepeatInterval)
00200                                                             ? mNextMainDateTime.addSecs(mNextRepeat * mRepeatInterval * 60) : mNextMainDateTime; }
00201         TQDate              date() const                 { return mNextMainDateTime.date(); }
00202         TQTime              time() const                 { return mNextMainDateTime.time(); }
00203         TQString            audioFile() const            { return (mActionType == T_AUDIO) && !mBeep ? mText : TQString(); }
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 TQDateTime& 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;             // alarm type
00223         bool               mRecurs;           // there is a recurrence rule for the alarm
00224         bool               mDeferred;         // whether the alarm is an extra deferred/deferred-reminder alarm
00225 
00226     friend class KAEvent;
00227 };
00228 
00229 
00231 class KAEvent : public KAAlarmEventBase
00232 {
00233     public:
00234         enum            // flags for use in DCOP calls, etc.
00235         {
00236 #ifdef OLD_DCOP
00237             // *** DON'T CHANGE THESE VALUES ***
00238             // because they are part of KAlarm's external DCOP interface.
00239             // (But it's alright to add new values.)
00240             LATE_CANCEL     = 0x01,    // cancel alarm if not triggered within a minute of its scheduled time
00241 #endif
00242             BEEP            = 0x02,    // sound audible beep when alarm is displayed
00243             REPEAT_AT_LOGIN = 0x04,    // repeat alarm at every login
00244             ANY_TIME        = 0x08,    // only a date is specified for the alarm, not a time
00245             CONFIRM_ACK     = 0x10,    // closing the alarm message window requires confirmation prompt
00246             EMAIL_BCC       = 0x20,    // blind copy the email to the user
00247             DEFAULT_FONT    = 0x40,    // use default alarm message font
00248             REPEAT_SOUND    = 0x80,    // repeat sound file while alarm is displayed
00249             DISABLED        = 0x100,   // alarm is currently disabled
00250             AUTO_CLOSE      = 0x200,   // auto-close alarm window after late-cancel period
00251             SCRIPT          = 0x400,   // command is a script, not a shell command line
00252             EXEC_IN_XTERM   = 0x800,   // execute command in terminal window
00253             SPEAK           = 0x1000,  // speak the message when the alarm is displayed
00254                 COPY_KORGANIZER = 0x2000,  // KOrganizer should hold a copy of the event
00255 #ifdef OLD_DCOP
00256             // The following are read-only internal values, and may be changed
00257 #else
00258             // The following are read-only internal values
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   // mask for all read-only internal values
00267         };
00269         enum Status
00270         {
00271             ACTIVE,      // the event is currently active
00272             EXPIRED,     // the event has expired
00273             DISPLAYING,  // the event is currently being displayed
00274             TEMPLATE,    // the event is an alarm template
00275             KORGANIZER   // the event is a copy of a KAlarm event, held by 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     // what type of occurrence is due
00285         {
00286             NO_OCCURRENCE               = 0,      // no occurrence is due
00287             FIRST_OR_ONLY_OCCURRENCE    = 0x01,   // the first occurrence (takes precedence over LAST_RECURRENCE)
00288             RECURRENCE_DATE             = 0x02,   // a recurrence with only a date, not a time
00289             RECURRENCE_DATE_TIME        = 0x03,   // a recurrence with a date and time
00290             LAST_RECURRENCE             = 0x04,   // the last recurrence
00291             OCCURRENCE_REPEAT = 0x10,    // (bimask for a repetition of an occurrence)
00292             FIRST_OR_ONLY_OCCURRENCE_REPEAT = OCCURRENCE_REPEAT | FIRST_OR_ONLY_OCCURRENCE,     // a repetition of the first occurrence
00293             RECURRENCE_DATE_REPEAT      = OCCURRENCE_REPEAT | RECURRENCE_DATE,      // a repetition of a date-only recurrence
00294             RECURRENCE_DATE_TIME_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE_TIME, // a repetition of a date/time recurrence
00295             LAST_RECURRENCE_REPEAT      = OCCURRENCE_REPEAT | LAST_RECURRENCE       // a repetition of the last recurrence
00296         };
00297         enum OccurOption     // options for nextOccurrence()
00298         {
00299             IGNORE_REPETITION,    // check for recurrences only, ignore repetitions
00300             RETURN_REPETITION,    // return repetition if it's the next occurrence
00301             ALLOW_FOR_REPETITION  // check for repetition being the next occurrence, but return recurrence
00302         };
00303         enum DeferLimitType    // what type of occurrence currently limits a deferral
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 TQDateTime& dt, const TQString& message, const TQColor& bg, const TQColor& fg, const TQFont& 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 TQDateTime&, const TQString& message, const TQColor& bg, const TQColor& fg, const TQFont&, Action, int lateCancel, int flags);
00321         void               setEmail(uint from, const EmailAddressList&, const TQString& subject, const TQStringList& attachments);
00322         void               setAudioFile(const TQString& filename, float volume, float fadeVolume, int fadeSeconds);
00323         void               setTemplate(const TQString& name, int afterTime = -1)  { mTemplateName = name;  mTemplateAfterTime = afterTime;  mUpdated = true; }
00324         void               setActions(const TQString& pre, const TQString& post)   { mPreAction = pre;  mPostAction = post;  mUpdated = true; }
00325         OccurType          setNextOccurrence(const TQDateTime& preDateTime);
00326         void               setFirstRecurrence();
00327         void               setEventID(const TQString& id)                     { mEventID = id;  mUpdated = true; }
00328         void               setDate(const TQDate& d)                           { mNextMainDateTime.set(d);  mUpdated = true; }
00329         void               setTime(const TQDateTime& dt)                      { mNextMainDateTime.set(dt);  mUpdated = true; }
00330         void               setSaveDateTime(const TQDateTime& 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 TQString& 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 TQDateTime&);
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;    // convert to new Event
00352         bool               isTemplate() const             { return !mTemplateName.isEmpty(); }
00353         const TQString&     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 TQString&     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         TQDate              mainDate() const               { return mNextMainDateTime.date(); }
00372         TQTime              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 TQString&     messageFileOrCommand() const   { return mText; }
00384         TQString            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 TQString&     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 TQString&     preAction() const              { return mPreAction; }
00394         const TQString&     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;    // recurrence period in units of the recurrence period type (minutes, days, etc)
00399         int                longestRecurrenceInterval() const    { return mRecurrence ? mRecurrence->longestInterval() : 0; }
00400         TQString            recurrenceText(bool brief = false) const;
00401         TQString            repetitionText(bool brief = false) const;
00402         bool               occursAfter(const TQDateTime& preDateTime, bool includeRepetitions) const;
00403         OccurType          nextOccurrence(const TQDateTime& preDateTime, DateTime& result, OccurOption = IGNORE_REPETITION) const;
00404         OccurType          previousOccurrence(const TQDateTime& 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 TQString& uid);
00414         static TQString     uid(const TQString& id, Status);
00415         static KAEvent     findTemplateName(AlarmCalendar&, const TQString& name);
00416 
00417         struct MonthPos
00418         {
00419             MonthPos() : days(7) { }
00420             int        weeknum;     // week in month, or < 0 to count from end of month
00421             TQBitArray  days;        // days in week
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 TQDateTime& end);
00427         bool               setRecurDaily(int freq, const TQBitArray& days, int count, const TQDate& end);
00428         bool               setRecurWeekly(int freq, const TQBitArray& days, int count, const TQDate& end);
00429         bool               setRecurMonthlyByDate(int freq, const TQValueList<int>& days, int count, const TQDate& end);
00430         bool               setRecurMonthlyByPos(int freq, const TQValueList<MonthPos>& pos, int count, const TQDate& end);
00431         bool               setRecurAnnualByDate(int freq, const TQValueList<int>& months, int day, KARecurrence::Feb29Type, int count, const TQDate& end);
00432         bool               setRecurAnnualByPos(int freq, const TQValueList<MonthPos>& pos, const TQValueList<int>& months, int count, const TQDate& end);
00433 //      static TQValueList<MonthPos> convRecurPos(const TQValueList<KCal::RecurrenceRule::WDayPos>&);
00434 #ifdef NDEBUG
00435         void               dumpDebug() const  { }
00436 #else
00437         void               dumpDebug() const;
00438 #endif
00439         static int         calVersion();
00440         static TQString     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,   // there was a deferred alarm, but it has been cancelled
00448             NO_DEFERRAL = 0,        // there is no deferred alarm
00449             NORMAL_DEFERRAL,        // the main alarm, a recurrence or a repeat is deferred
00450             REMINDER_DEFERRAL       // a reminder alarm is deferred
00451         };
00452 
00453         void               copy(const KAEvent&);
00454         bool               setRecur(KCal::RecurrenceRule::PeriodType, int freq, int count, const TQDateTime& end, KARecurrence::Feb29Type = KARecurrence::FEB29_FEB29);
00455         void               clearRecur();
00456         KARecurrence::Type checkRecur() const;
00457         void               checkRepetition() const;
00458         OccurType          nextRecurrence(const TQDateTime& preDateTime, DateTime& result) const;
00459         OccurType          previousRecurrence(const TQDateTime& afterDateTime, DateTime& result) const;
00460         static bool        convertRepetition(KCal::Event*);
00461         KCal::Alarm*       initKCalAlarm(KCal::Event&, const DateTime&, const TQStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM) const;
00462         KCal::Alarm*       initKCalAlarm(KCal::Event&, int startOffsetSecs, const TQStringList& 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         TQString            mTemplateName;     // alarm template's name, or null if normal event
00471         TQString            mAudioFile;        // ATTACH: audio file to play
00472         TQString            mPreAction;        // command to execute before alarm is displayed
00473         TQString            mPostAction;       // command to execute after alarm window is closed
00474         DateTime           mStartDateTime;    // DTSTART and DTEND: start and end time for event
00475         TQDateTime          mSaveDateTime;     // CREATED: date event was created, or saved in expired calendar
00476         TQDateTime          mAtLoginDateTime;  // repeat-at-login time
00477         DateTime           mDeferralTime;     // extra time to trigger alarm (if alarm or reminder deferred)
00478         DateTime           mDisplayingTime;   // date/time shown in the alarm currently being displayed
00479         int                mDisplayingFlags;  // type of alarm which is currently being displayed
00480         int                mReminderMinutes;  // how long in advance reminder is to be, or 0 if none
00481         int                mArchiveReminderMinutes;  // original reminder period if now expired, or 0 if none
00482         int                mDeferDefaultMinutes; // default number of minutes for deferral dialogue, or 0 to select time control
00483         int                mRevision;         // SEQUENCE: revision number of the original alarm, or 0
00484         KARecurrence*      mRecurrence;       // RECUR: recurrence specification, or 0 if none
00485         int                mAlarmCount;       // number of alarms: count of !mMainExpired, mRepeatAtLogin, mDeferral, mReminderMinutes, mDisplaying
00486         DeferType          mDeferral;         // whether the alarm is an extra deferred/deferred-reminder alarm
00487         unsigned long      mKMailSerialNumber;// if email text, message's KMail serial number
00488         int                mTemplateAfterTime;// time not specified: use n minutes after default time, or -1 (applies to templates only)
00489         TQString            mLogFile;          // alarm output is to be logged to this URL
00490         bool               mCommandXterm;     // command alarm is to be executed in a terminal window
00491         bool               mCopyToKOrganizer; // KOrganizer should hold a copy of the event
00492         bool               mReminderOnceOnly; // the reminder is output only for the first recurrence
00493         bool               mMainExpired;      // main alarm has expired (in which case a deferral alarm will exist)
00494         bool               mArchiveRepeatAtLogin; // if now expired, original event was repeat-at-login
00495         bool               mArchive;          // event has triggered in the past, so archive it when closed
00496         bool               mEnabled;          // false if event is disabled
00497         mutable bool       mUpdated;          // event has been updated but not written to calendar file
00498 };
00499 
00500 #endif // KALARMEVENT_H