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-2006 by David Jarvie <software@astrojar.org.uk>
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 <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 Recurrence;
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 // Base class containing data common to KAAlarm and KAEvent
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         QString            emailFromKMail() const      { return mEmailFromKMail; }
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() : 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;          // UID: KCal::Event unique ID
00103         QString            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         QColor             mBgColour;         // background colour of alarm message
00106         QColor             mFgColour;         // foreground colour of alarm message, or invalid for default
00107         QFont              mFont;             // font of alarm message (ignored if mDefaultFont true)
00108         QString            mEmailFromKMail;   // KMail identity for email 'From' field, or empty
00109         EmailAddressList   mEmailAddresses;   // ATTENDEE: addresses to send email to
00110         QString            mEmailSubject;     // SUMMARY: subject line of email
00111         QStringList        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;      // simple repetition count (excluding the first time)
00117         int                mRepeatInterval;   // simple repetition interval (minutes)
00118         int                mLateCancel;       // how many minutes late will cancel the alarm, or 0 for no cancellation
00119         bool               mAutoClose;        // whether to close the alarm window after the late-cancel period
00120         bool               mCommandScript;    // the command text is a script, not a shell command line
00121         bool               mBeep;             // whether to beep when the alarm is displayed
00122         bool               mSpeak;            // whether to speak the message when the alarm is displayed
00123         bool               mRepeatSound;      // whether to repeat the sound file while the alarm is displayed
00124         bool               mRepeatAtLogin;    // whether to repeat the alarm at every login
00125         bool               mDisplaying;       // whether the alarm is currently being displayed
00126         bool               mEmailBcc;         // blind copy the email to the user
00127         bool               mConfirmAck;       // alarm acknowledgement requires confirmation by user
00128         bool               mDefaultFont;      // use default message font, not mFont
00129 
00130     friend class AlarmData;
00131 };
00132 
00133 
00134 // KAAlarm corresponds to a single KCal::Alarm instance.
00135 // A KAEvent may contain multiple KAAlarm's.
00136 class KAAlarm : public KAAlarmEventBase
00137 {
00138     public:
00139         // Define the basic KAAlaem action types
00140         enum Action
00141         {
00142             MESSAGE = T_MESSAGE,   // KCal::Alarm::Display type: display a text message
00143             FILE    = T_FILE,      // KCal::Alarm::Display type: display a file (URL given by the alarm text)
00144             COMMAND = T_COMMAND,   // KCal::Alarm::Procedure type: execute a shell command
00145             EMAIL   = T_EMAIL,     // KCal::Alarm::Email type: send an email
00146             AUDIO   = T_AUDIO      // KCal::Alarm::Audio type: play a sound file
00147         };
00148         // Define the KAAlarm types.
00149         // KAAlarm's of different types may be contained in a KAEvent,
00150         // each defining a different component of the overall alarm.
00151         enum Type
00152         {
00153             INVALID_ALARM       = 0,     // not an alarm
00154             MAIN_ALARM          = 1,     // THE real alarm. Must be the first in the enumeration.
00155             // The following values may be used in combination as a bitmask 0x0E
00156             REMINDER_ALARM      = 0x02,  // reminder in advance of main alarm
00157             DEFERRED_ALARM      = 0x04,  // deferred alarm
00158             DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM,  // deferred early warning
00159             // The following values must be greater than the preceding ones, to
00160             // ensure that in ordered processing they are processed afterwards.
00161             AT_LOGIN_ALARM      = 0x10,  // additional repeat-at-login trigger
00162             DISPLAYING_ALARM    = 0x20,  // copy of the alarm currently being displayed
00163             // The following values are for internal KAEvent use only
00164             AUDIO_ALARM         = 0x30,  // sound to play when displaying the alarm
00165             PRE_ACTION_ALARM    = 0x40,  // command to execute before displaying the alarm
00166             POST_ACTION_ALARM   = 0x50   // command to execute after the alarm window is closed
00167         };
00168         enum SubType
00169         {
00170             INVALID__ALARM                = INVALID_ALARM,
00171             MAIN__ALARM                   = MAIN_ALARM,
00172             // The following values may be used in combination as a bitmask 0x0E
00173             REMINDER__ALARM               = REMINDER_ALARM,
00174             TIMED_DEFERRAL_FLAG           = 0x08,  // deferral has a time; if clear, it is date-only
00175             DEFERRED_DATE__ALARM          = DEFERRED_ALARM,  // deferred alarm - date-only
00176             DEFERRED_TIME__ALARM          = DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,
00177             DEFERRED_REMINDER_DATE__ALARM = REMINDER_ALARM | DEFERRED_ALARM,  // deferred early warning (date-only)
00178             DEFERRED_REMINDER_TIME__ALARM = REMINDER_ALARM | DEFERRED_ALARM | TIMED_DEFERRAL_FLAG,  // deferred early warning (date/time)
00179             // The following values must be greater than the preceding ones, to
00180             // ensure that in ordered processing they are processed afterwards.
00181             AT_LOGIN__ALARM               = AT_LOGIN_ALARM,
00182             DISPLAYING__ALARM             = DISPLAYING_ALARM,
00183             // The following values are for internal KAEvent use only
00184             AUDIO__ALARM                  = AUDIO_ALARM,
00185             PRE_ACTION__ALARM             = PRE_ACTION_ALARM,
00186             POST_ACTION__ALARM            = POST_ACTION_ALARM
00187         };
00188 
00189         KAAlarm()          : mType(INVALID__ALARM), mDeferred(false) { }
00190         KAAlarm(const KAAlarm&);
00191         ~KAAlarm()  { }
00192         Action             action() const               { return (Action)mActionType; }
00193         bool               valid() const                { return mType != INVALID__ALARM; }
00194         Type               type() const                 { return static_cast<Type>(mType & ~TIMED_DEFERRAL_FLAG); }
00195         SubType            subType() const              { return mType; }
00196         const QString&     eventID() const              { return mEventID; }
00197         const DateTime&    dateTime() const             { return mNextMainDateTime; }
00198         QDate              date() const                 { return mNextMainDateTime.date(); }
00199         QTime              time() const                 { return mNextMainDateTime.time(); }
00200         QString            audioFile() const            { return (mActionType == T_AUDIO) && !mBeep ? mText : QString::null; }
00201         float              soundVolume() const          { return (mActionType == T_AUDIO) && !mBeep && !mText.isEmpty() ? mSoundVolume : -1; }
00202         float              fadeVolume() const           { return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeSeconds && !mBeep && !mText.isEmpty() ? mFadeVolume : -1; }
00203         int                fadeSeconds() const          { return (mActionType == T_AUDIO) && mSoundVolume >= 0 && mFadeVolume >= 0 && !mBeep && !mText.isEmpty() ? mFadeSeconds : 0; }
00204         bool               repeatSound() const          { return (mActionType == T_AUDIO) && mRepeatSound && !mBeep && !mText.isEmpty(); }
00205         bool               reminder() const             { return mType == REMINDER__ALARM; }
00206         bool               deferred() const             { return mDeferred; }
00207         void               setTime(const DateTime& dt)  { mNextMainDateTime = dt; }
00208         void               setTime(const QDateTime& dt) { mNextMainDateTime = dt; }
00209         int                flags() const;
00210 #ifdef NDEBUG
00211         void               dumpDebug() const  { }
00212         static const char* debugType(Type)   { return ""; }
00213 #else
00214         void               dumpDebug() const;
00215         static const char* debugType(Type);
00216 #endif
00217 
00218     private:
00219         SubType            mType;             // alarm type
00220         bool               mRecurs;           // there is a recurrence rule for the alarm
00221         bool               mDeferred;         // whether the alarm is an extra deferred/deferred-reminder alarm
00222 
00223     friend class KAEvent;
00224 };
00225 
00226 
00228 class KAEvent : public KAAlarmEventBase
00229 {
00230     public:
00231         enum            // flags for use in DCOP calls, etc.
00232         {
00233 #ifdef OLD_DCOP
00234             // *** DON'T CHANGE THESE VALUES ***
00235             // because they are part of KAlarm's external DCOP interface.
00236             // (But it's alright to add new values.)
00237             LATE_CANCEL     = 0x01,    // cancel alarm if not triggered within a minute of its scheduled time
00238 #endif
00239             BEEP            = 0x02,    // sound audible beep when alarm is displayed
00240             REPEAT_AT_LOGIN = 0x04,    // repeat alarm at every login
00241             ANY_TIME        = 0x08,    // only a date is specified for the alarm, not a time
00242             CONFIRM_ACK     = 0x10,    // closing the alarm message window requires confirmation prompt
00243             EMAIL_BCC       = 0x20,    // blind copy the email to the user
00244             DEFAULT_FONT    = 0x40,    // use default alarm message font
00245             REPEAT_SOUND    = 0x80,    // repeat sound file while alarm is displayed
00246             DISABLED        = 0x100,   // alarm is currently disabled
00247             AUTO_CLOSE      = 0x200,   // auto-close alarm window after late-cancel period
00248             SCRIPT          = 0x400,   // command is a script, not a shell command line
00249             EXEC_IN_XTERM   = 0x800,   // execute command in terminal window
00250             SPEAK           = 0x1000,  // speak the message when the alarm is displayed
00251                 COPY_KORGANIZER = 0x2000,  // KOrganizer should hold a copy of the event
00252 #ifdef OLD_DCOP
00253             // The following are read-only internal values, and may be changed
00254 #else
00255             // The following are read-only internal values
00256 #endif
00257             REMINDER        = 0x10000,
00258             DEFERRAL        = 0x20000,
00259             TIMED_FLAG      = 0x40000,
00260             DATE_DEFERRAL   = DEFERRAL,
00261             TIME_DEFERRAL   = DEFERRAL | TIMED_FLAG,
00262             DISPLAYING_     = 0x80000,
00263             READ_ONLY_FLAGS = 0xF0000   // mask for all read-only internal values
00264         };
00266         enum Status
00267         {
00268             ACTIVE,      // the event is currently active
00269             EXPIRED,     // the event has expired
00270             DISPLAYING,  // the event is currently being displayed
00271             TEMPLATE,    // the event is an alarm template
00272             KORGANIZER   // the event is a copy of a KAlarm event, held by KOrganizer
00273         };
00274         enum Action
00275         {
00276             MESSAGE = T_MESSAGE,
00277             FILE    = T_FILE,
00278             COMMAND = T_COMMAND,
00279             EMAIL   = T_EMAIL
00280         };
00281         enum OccurType     // what type of occurrence is due
00282         {
00283             NO_OCCURRENCE               = 0,      // no occurrence is due
00284             FIRST_OR_ONLY_OCCURRENCE    = 0x01,   // the first occurrence (takes precedence over LAST_RECURRENCE)
00285             RECURRENCE_DATE             = 0x02,   // a recurrence with only a date, not a time
00286             RECURRENCE_DATE_TIME        = 0x03,   // a recurrence with a date and time
00287             LAST_RECURRENCE             = 0x04,   // the last recurrence
00288             OCCURRENCE_REPEAT = 0x10,    // (bitmask for a repetition of an occurrence)
00289             FIRST_OR_ONLY_OCCURRENCE_REPEAT = OCCURRENCE_REPEAT | FIRST_OR_ONLY_OCCURRENCE,     // a repetition of the first occurrence
00290             RECURRENCE_DATE_REPEAT      = OCCURRENCE_REPEAT | RECURRENCE_DATE,      // a repetition of a date-only recurrence
00291             RECURRENCE_DATE_TIME_REPEAT = OCCURRENCE_REPEAT | RECURRENCE_DATE_TIME, // a repetition of a date/time recurrence
00292             LAST_RECURRENCE_REPEAT      = OCCURRENCE_REPEAT | LAST_RECURRENCE       // a repetition of the last recurrence
00293         };
00294         enum OccurOption     // options for nextOccurrence()
00295         {
00296             IGNORE_REPETITION,    // check for recurrences only, ignore repetitions
00297             RETURN_REPETITION,    // return repetition if it's the next occurrence
00298             ALLOW_FOR_REPETITION  // check for repetition being the next occurrence, but return recurrence
00299         };
00300         enum DeferLimitType    // what type of occurrence currently limits a deferral
00301         {
00302             LIMIT_NONE,
00303             LIMIT_MAIN,
00304             LIMIT_RECURRENCE,
00305             LIMIT_REPETITION,
00306             LIMIT_REMINDER
00307         };
00308 
00309         KAEvent()          : mRevision(0), mRecurrence(0), mAlarmCount(0) { }
00310         KAEvent(const QDateTime& dt, const QString& message, const QColor& bg, const QColor& fg, const QFont& f, Action action, int lateCancel, int flags)
00311                                                 : mRecurrence(0) { set(dt, message, bg, fg, f, action, lateCancel, flags); }
00312         explicit KAEvent(const KCal::Event& e)  : mRecurrence(0) { set(e); }
00313         KAEvent(const KAEvent& e)               : KAAlarmEventBase(e), mRecurrence(0) { copy(e); }
00314         ~KAEvent()         { delete mRecurrence; }
00315         KAEvent&           operator=(const KAEvent& e)       { if (&e != this) copy(e);  return *this; }
00316         void               set(const KCal::Event&);
00317         void               set(const QDate& d, const QString& message, const QColor& bg, const QColor& fg, const QFont& f, Action action, int lateCancel, int flags)
00318                                     { set(d, message, bg, fg, f, action, lateCancel, flags | ANY_TIME); }
00319         void               set(const QDateTime&, const QString& message, const QColor& bg, const QColor& fg, const QFont&, Action, int lateCancel, int flags);
00320         void               setMessage(const QDate& d, const QString& message, const QColor& bg, const QColor& fg, const QFont& f, int lateCancel, int flags)
00321                                     { set(d, message, bg, fg, f, MESSAGE, lateCancel, flags | ANY_TIME); }
00322         void               setMessage(const QDateTime& dt, const QString& message, const QColor& bg, const QColor& fg, const QFont& f, int lateCancel, int flags)
00323                                     { set(dt, message, bg, fg, f, MESSAGE, lateCancel, flags); }
00324         void               setFileName(const QDate& d, const QString& filename, const QColor& bg, const QColor& fg, const QFont& f, int lateCancel, int flags)
00325                                     { set(d, filename, bg, fg, f, FILE, lateCancel, flags | ANY_TIME); }
00326         void               setFileName(const QDateTime& dt, const QString& filename, const QColor& bg, const QColor& fg, const QFont& f, int lateCancel, int flags)
00327                                     { set(dt, filename, bg, fg, f, FILE, lateCancel, flags); }
00328         void               setCommand(const QDate&, const QString& command, int lateCancel, int flags, const QString& logfile = QString::null);
00329         void               setCommand(const QDateTime&, const QString& command, int lateCancel, int flags, const QString& logfile = QString::null);
00330         void               setEmail(const QDate&, const QString& from, const EmailAddressList&, const QString& subject,
00331                                     const QString& message, const QStringList& attachments, int lateCancel, int flags);
00332         void               setEmail(const QDateTime&, const QString& from, const EmailAddressList&, const QString& subject,
00333                                     const QString& message, const QStringList& attachments, int lateCancel, int flags);
00334         void               setEmail(const QString& from, const EmailAddressList&, const QString& subject, const QStringList& attachments);
00335         void               setAudioFile(const QString& filename, float volume, float fadeVolume, int fadeSeconds);
00336         void               setTemplate(const QString& name, int afterTime = -1)  { mTemplateName = name;  mTemplateAfterTime = afterTime;  mUpdated = true; }
00337         void               setActions(const QString& pre, const QString& post)   { mPreAction = pre;  mPostAction = post;  mUpdated = true; }
00338         OccurType          setNextOccurrence(const QDateTime& preDateTime, bool includeRepetitions = false);
00339         void               setFirstRecurrence();
00340         void               setEventID(const QString& id)                     { mEventID = id;  mUpdated = true; }
00341         void               adjustStartDate(const QDate&);
00342         void               setDate(const QDate& d)                           { mNextMainDateTime.set(d);  mUpdated = true; }
00343         void               setTime(const QDateTime& dt)                      { mNextMainDateTime.set(dt);  mUpdated = true; }
00344         void               setSaveDateTime(const QDateTime& dt)              { mSaveDateTime = dt;  mUpdated = true; }
00345         void               setLateCancel(int lc)                             { mLateCancel = lc;  mUpdated = true; }
00346         void               setAutoClose(bool ac)                             { mAutoClose = ac;  mUpdated = true; }
00347         void               setRepeatAtLogin(bool rl)                         { mRepeatAtLogin = rl;  mUpdated = true; }
00348         void               set(int flags);
00349         void               setUid(Status s)                                  { mEventID = uid(mEventID, s);  mUpdated = true; }
00350         void               setKMailSerialNumber(unsigned long n)             { mKMailSerialNumber = n; }
00351         void               setLogFile(const QString& logfile);
00352         void               setReminder(int minutes, bool onceOnly);
00353         bool               defer(const DateTime&, bool reminder, bool adjustRecurrence = false);
00354         void               cancelDefer();
00355         void               cancelCancelledDeferral();
00356         void               setDeferDefaultMinutes(int minutes)               { mDeferDefaultMinutes = minutes;  mUpdated = true; }
00357         bool               setDisplaying(const KAEvent&, KAAlarm::Type, const QDateTime&);
00358         void               reinstateFromDisplaying(const KAEvent& dispEvent);
00359         void               setArchive()                                      { mArchive = true;  mUpdated = true; }
00360         void               setEnabled(bool enable)                           { mEnabled = enable;  mUpdated = true; }
00361         void               setUpdated()                                      { mUpdated = true; }
00362         void               clearUpdated() const                              { mUpdated = false; }
00363         void               removeExpiredAlarm(KAAlarm::Type);
00364         void               incrementRevision()                               { ++mRevision;  mUpdated = true; }
00365 
00366         KCal::Event*       event() const;    // convert to new Event
00367         bool               isTemplate() const             { return !mTemplateName.isEmpty(); }
00368         const QString&     templateName() const           { return mTemplateName; }
00369         bool               usingDefaultTime() const       { return mTemplateAfterTime == 0; }
00370         int                templateAfterTime() const      { return mTemplateAfterTime; }
00371         KAAlarm            alarm(KAAlarm::Type) const;
00372         KAAlarm            firstAlarm() const;
00373         KAAlarm            nextAlarm(const KAAlarm& al) const  { return nextAlarm(al.type()); }
00374         KAAlarm            nextAlarm(KAAlarm::Type) const;
00375         KAAlarm            convertDisplayingAlarm() const;
00376         bool               updateKCalEvent(KCal::Event&, bool checkUid = true, bool original = false, bool cancelCancelledDefer = false) const;
00377         Action             action() const                 { return (Action)mActionType; }
00378         bool               displayAction() const          { return mActionType == T_MESSAGE || mActionType == T_FILE; }
00379         const QString&     id() const                     { return mEventID; }
00380         bool               valid() const                  { return mAlarmCount  &&  (mAlarmCount != 1 || !mRepeatAtLogin); }
00381         int                alarmCount() const             { return mAlarmCount; }
00382         const DateTime&    startDateTime() const          { return mStartDateTime; }
00383         const DateTime&    mainDateTime() const           { return mNextMainDateTime; }
00384         QDate              mainDate() const               { return mNextMainDateTime.date(); }
00385         QTime              mainTime() const               { return mNextMainDateTime.time(); }
00386         DateTime           mainEndRepeatTime() const      { return mRepeatCount ? mNextMainDateTime.addSecs(mRepeatCount * mRepeatInterval * 60) : mNextMainDateTime; }
00387         int                reminder() const               { return mReminderMinutes; }
00388         bool               reminderOnceOnly() const       { return mReminderOnceOnly; }
00389         bool               reminderDeferral() const       { return mDeferral == REMINDER_DEFERRAL; }
00390         int                reminderArchived() const       { return mArchiveReminderMinutes; }
00391         DateTime           deferDateTime() const          { return mDeferralTime; }
00392         DateTime           deferralLimit(DeferLimitType* = 0) const;
00393         int                deferDefaultMinutes() const    { return mDeferDefaultMinutes; }
00394         DateTime           nextDateTime(bool includeReminders = true) const;
00395         const QString&     messageFileOrCommand() const   { return mText; }
00396         QString            logFile() const                { return mLogFile; }
00397         bool               commandXterm() const           { return mCommandXterm; }
00398         unsigned long      kmailSerialNumber() const      { return mKMailSerialNumber; }
00399         bool               copyToKOrganizer() const       { return mCopyToKOrganizer; }
00400         const QString&     audioFile() const              { return mAudioFile; }
00401         float              soundVolume() const            { return !mAudioFile.isEmpty() ? mSoundVolume : -1; }
00402         float              fadeVolume() const             { return !mAudioFile.isEmpty() && mSoundVolume >= 0 && mFadeSeconds ? mFadeVolume : -1; }
00403         int                fadeSeconds() const            { return !mAudioFile.isEmpty() && mSoundVolume >= 0 && mFadeVolume >= 0 ? mFadeSeconds : 0; }
00404         bool               repeatSound() const            { return mRepeatSound  &&  !mAudioFile.isEmpty(); }
00405         const QString&     preAction() const              { return mPreAction; }
00406         const QString&     postAction() const             { return mPostAction; }
00407         bool               recurs() const                 { return checkRecur() != KARecurrence::NO_RECUR; }
00408         KARecurrence::Type recurType() const              { return checkRecur(); }
00409         KARecurrence*      recurrence() const             { return mRecurrence; }
00410         int                recurInterval() const;    // recurrence period in units of the recurrence period type (minutes, days, etc)
00411         int                longestRecurrenceInterval() const    { return mRecurrence ? mRecurrence->longestInterval() : 0; }
00412         QString            recurrenceText(bool brief = false) const;
00413         QString            repetitionText(bool brief = false) const;
00414         int                remainingRecurrences() const   { return mRemainingRecurrences; }
00415         bool               occursAfter(const QDateTime& preDateTime, bool includeRepetitions) const;
00416         OccurType          nextOccurrence(const QDateTime& preDateTime, DateTime& result, OccurOption = IGNORE_REPETITION) const;
00417         OccurType          previousOccurrence(const QDateTime& afterDateTime, DateTime& result, bool includeRepetitions = false) const;
00418         int                flags() const;
00419         bool               deferred() const               { return mDeferral > 0; }
00420         bool               toBeArchived() const           { return mArchive; }
00421         bool               enabled() const                { return mEnabled; }
00422         bool               updated() const                { return mUpdated; }
00423         bool               mainExpired() const            { return mMainExpired; }
00424         bool               expired() const                { return mDisplaying && mMainExpired  ||  uidStatus(mEventID) == EXPIRED; }
00425         Status             uidStatus() const              { return uidStatus(mEventID); }
00426         static Status      uidStatus(const QString& uid);
00427         static QString     uid(const QString& id, Status);
00428         static KAEvent     findTemplateName(AlarmCalendar&, const QString& name);
00429 
00430         struct MonthPos
00431         {
00432             MonthPos() : days(7) { }
00433             int        weeknum;     // week in month, or < 0 to count from end of month
00434             QBitArray  days;        // days in week
00435         };
00436         bool               setRepetition(int interval, int count);
00437         void               setNoRecur()                   { clearRecur(); }
00438         void               setRecurrence(const KARecurrence&);
00439         bool               setRecurMinutely(int freq, int count, const QDateTime& end);
00440         bool               setRecurDaily(int freq, const QBitArray& days, int count, const QDate& end);
00441         bool               setRecurWeekly(int freq, const QBitArray& days, int count, const QDate& end);
00442         bool               setRecurMonthlyByDate(int freq, const QValueList<int>& days, int count, const QDate& end);
00443         bool               setRecurMonthlyByPos(int freq, const QValueList<MonthPos>& pos, int count, const QDate& end);
00444         bool               setRecurAnnualByDate(int freq, const QValueList<int>& months, int day, KARecurrence::Feb29Type, int count, const QDate& end);
00445         bool               setRecurAnnualByPos(int freq, const QValueList<MonthPos>& pos, const QValueList<int>& months, int count, const QDate& end);
00446 //      static QValueList<MonthPos> convRecurPos(const QValueList<KCal::RecurrenceRule::WDayPos>&);
00447 #ifdef NDEBUG
00448         void               dumpDebug() const  { }
00449 #else
00450         void               dumpDebug() const;
00451 #endif
00452         static int         calVersion();
00453         static QString     calVersionString();
00454         static bool        adjustStartOfDay(const KCal::Event::List&);
00455         static void        convertKCalEvents(KCal::Calendar&, int version, bool adjustSummerTime);
00456 
00457     private:
00458         enum DeferType {
00459             CANCEL_DEFERRAL = -1,   // there was a deferred alarm, but it has been cancelled
00460             NO_DEFERRAL = 0,        // there is no deferred alarm
00461             NORMAL_DEFERRAL,        // the main alarm, a recurrence or a repeat is deferred
00462             REMINDER_DEFERRAL       // a reminder alarm is deferred
00463         };
00464 
00465         void               copy(const KAEvent&);
00466         bool               setRecur(KCal::RecurrenceRule::PeriodType, int freq, int count, const QDateTime& end, KARecurrence::Feb29Type = KARecurrence::FEB29_FEB29);
00467         void               clearRecur();
00468         KARecurrence::Type checkRecur() const;
00469         OccurType          nextRecurrence(const QDateTime& preDateTime, DateTime& result, int& remainingCount) const;
00470         OccurType          previousRecurrence(const QDateTime& afterDateTime, DateTime& result) const;
00471         KCal::Alarm*       initKcalAlarm(KCal::Event&, const DateTime&, const QStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM) const;
00472         KCal::Alarm*       initKcalAlarm(KCal::Event&, int startOffsetSecs, const QStringList& types, KAAlarm::Type = KAAlarm::INVALID_ALARM) const;
00473         static void        readAlarms(const KCal::Event&, void* alarmMap);
00474         static void        readAlarm(const KCal::Alarm&, AlarmData&);
00475         inline void        set_deferral(DeferType);
00476         inline void        set_reminder(int minutes);
00477         inline void        set_archiveReminder();
00478 
00479         QString            mTemplateName;     // alarm template's name, or null if normal event
00480         QString            mAudioFile;        // ATTACH: audio file to play
00481         QString            mPreAction;        // command to execute before alarm is displayed
00482         QString            mPostAction;       // command to execute after alarm window is closed
00483         DateTime           mStartDateTime;    // DTSTART and DTEND: start and end time for event
00484         QDateTime          mSaveDateTime;     // CREATED: date event was created, or saved in expired calendar
00485         QDateTime          mAtLoginDateTime;  // repeat-at-login time
00486         DateTime           mDeferralTime;     // extra time to trigger alarm (if alarm or reminder deferred)
00487         DateTime           mDisplayingTime;   // date/time shown in the alarm currently being displayed
00488         int                mDisplayingFlags;  // type of alarm which is currently being displayed
00489         int                mReminderMinutes;  // how long in advance reminder is to be, or 0 if none
00490         int                mArchiveReminderMinutes;  // original reminder period if now expired, or 0 if none
00491         int                mDeferDefaultMinutes; // default number of minutes for deferral dialogue, or 0 to select time control
00492         int                mRevision;         // SEQUENCE: revision number of the original alarm, or 0
00493         KARecurrence*      mRecurrence;       // RECUR: recurrence specification, or 0 if none
00494         int                mRemainingRecurrences; // remaining number of alarm recurrences including initial time, -1 to repeat indefinitely
00495         int                mAlarmCount;       // number of alarms: count of !mMainExpired, mRepeatAtLogin, mDeferral, mReminderMinutes, mDisplaying
00496         DeferType          mDeferral;         // whether the alarm is an extra deferred/deferred-reminder alarm
00497         unsigned long      mKMailSerialNumber;// if email text, message's KMail serial number
00498         int                mTemplateAfterTime;// time not specified: use n minutes after default time, or -1 (applies to templates only)
00499         QString            mLogFile;          // alarm output is to be logged to this URL
00500         bool               mCommandXterm;     // command alarm is to be executed in a terminal window
00501         bool               mCopyToKOrganizer; // KOrganizer should hold a copy of the event
00502         bool               mReminderOnceOnly; // the reminder is output only for the first recurrence
00503         bool               mMainExpired;      // main alarm has expired (in which case a deferral alarm will exist)
00504         bool               mArchiveRepeatAtLogin; // if now expired, original event was repeat-at-login
00505         bool               mArchive;          // event has triggered in the past, so archive it when closed
00506         bool               mEnabled;          // false if event is disabled
00507         mutable bool       mUpdated;          // event has been updated but not written to calendar file
00508 };
00509 
00510 #endif // KALARMEVENT_H
KDE Home | KDE Accessibility Home | Description of Access Keys