/***************************************************************************
* Copyright (C) 2004 by Gerhard W. Gruber *
* sparhawk@gmx.at *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/***************************************************************************
*
* PROJECT: CalendarGlobals
* $Source: /cvsroot/desktoptools/calendar/src/Event.h,v $
* $Revision: 1.5 $
* $Date: 2004/11/05 15:24:57 $
* $Author: lightweave $
* $Name: $
*
* $Log: Event.h,v $
* Revision 1.5 2004/11/05 15:24:57 lightweave
* 1041233: Fixed a bug that caused events to be triggered at startup despite a later time being set.
*
* Revision 1.4 2004/10/05 21:44:58 lightweave
* Implemented changes for linux compatibillity
*
* Revision 1.3 2004/09/27 17:42:13 lightweave
* Split the inputeventdialog into two parts.
* Repeatevents are now configured seperately.
*
* Revision 1.2 2004/09/22 16:41:23 lightweave
* Finished implementation of the event class.
*
* Revision 1.1.1.1 2004/08/24 07:03:22 lightweave
* Initial release
*
***************************************************************************/
#ifndef EVENT_H
#define EVENT_H
#include <wx/datetime.h>
typedef unsigned long t_EventId;
class CEvent {
public:
typedef enum {
ET_REMINDER,
ET_LAST
} ET_EventType;
typedef enum {
ES_NEW, // Event is new
ES_PENDING, // Event is pending, waiting for triggering
ES_SHOWIT, // Event has to be shown.
ES_FINISHED, // Event has expired
ES_COUNT
} ES_EventState;
typedef enum {
RT_NO,
RT_EVERY,
RT_ON,
RT_COUNT
} RT_RepeatType;
typedef enum {
RL_LIMIT_NO,
RL_LIMIT_COUNT,
RL_LIMIT_UNTIL,
RL_COUNT
} RL_RepeatLimit;
typedef enum {
RD_MONDAY,
RD_TUEDAY,
RD_WEDNESDAY,
RD_THURSDAY,
RD_FRIDAY,
RD_SATURDAY,
RD_SUNDAY,
RD_COUNT
} RD_RepeatDay;
typedef enum {
DT_MINUTES,
DT_HOURS,
DT_DAYS,
DT_WEEKS,
DT_MONTHS,
DT_YEARS,
DT_COUNT
} DT_DateType;
typedef enum {
AM_VAL = 0,
PM_VAL = 1,
AMPM_COUNT
} AMPM_VAL;
typedef enum {
RO_ALL,
RO_1ST,
RO_2ND,
RO_3RD,
RO_4TH,
RO_LAST,
RO_COUNT
} RO_RepeatOn;
/**
* LS_LoadState specifies the state for parsing the loadstring
* into the CEvent class.
*/
typedef enum {
LS_EVENTTYPE,
LS_24,
LS_YEAR,
LS_MONTH,
LS_DAY,
LS_TIMED,
LS_HOUR,
LS_MINUTE,
LS_REPEATTYPE,
LS_REPEATEVERY,
LS_REPEATEVERYTYPE,
LS_REPEATON,
LS_REPEATONTYPE,
LS_REPEAT_LIMIT_TYPE,
LS_REPEAT_LIMIT_COUNT,
LS_REPEAT_LIMIT_YEAR,
LS_WARNING,
LS_WARNINGTYPE,
LS_EVENTSTATE,
LS_TITLELEN,
LS_TITLE,
LS_MESSAGELEN,
LS_MESSAGE,
LS_FINISHED, // string is empty
LS_CONT, // string is not empty
LS_LAST
} LS_LoadState;
public:
CEvent(void);
CEvent(CEvent const &Event);
virtual ~CEvent(void);
virtual void Init(void);
/**
* CreateInstance creates a new event of the given type. If a pointer
* to another event is given, it will be copied. If the type is not
* the same it will not be copied and NULL is returned.
*/
virtual CEvent *CreateInstance(CEvent *Source = NULL);
/**
* GetType() returns the type of the event.
*/
virtual int GetType(void);
/**
* IsDisplayable returns true if the event should show a messagebox
* if it is triggered, otherwise false.
*/
virtual bool IsDisplayable(void);
/**
* RestoreString will parse the string and fills the event structure.
* This string should have been created by SaveString() to restore
* the event. If the event is not of the type as the string indicates
* it will skip the string and proceed with the next eventstring.
*
* -1 will be returned if the parsing resulted in errors, otherwise
* the number of bytes are returned which have been sucessfully parsed.
* In derived classes the function should call the base function first
* and then can use the returned value to continue it's own parsing where
* the base function left off.
*/
virtual int RestoreString(wxString const &LoadString, int Offset = 0);
/**
* SaveString will create a string which is suitable to pass to
* LoadString in order to save the event for recreation at a
* later time.
* Derived classes should always prepend their own data at the end
* of the string after calling the base class for creating their
* part of the string.
*
* true will be returned if the string was successfully created.
*/
virtual bool SaveString(wxString &SaveString);
virtual CEvent &operator=(CEvent const &Source);
virtual void Copy(CEvent const &Source);
virtual bool operator==(CEvent const &s);
virtual bool operator<(CEvent const &s);
virtual bool operator>(CEvent const &s);
virtual bool operator<=(CEvent const &s);
virtual bool operator>=(CEvent const &s);
virtual int Compare(CEvent const &s);
/**
* CalcTrigger will calculate the triggerdate when the event has to
* be shown. With an simple event the trigger date is the same as the
* user sets the date. If a warning is activated, the event retains its
* date, but will be displayed as much earlier as is determined by the
* warning setting. If the current date is already in the past, then
* it is checked if the event is repeatable. In this case the new date
* is set according to the next repeatable interval and the warning
* is subtracted again. If the event is in the past and is not repeatable
* false will be returned.
* Note that, in case of a repeatable event with a warning, the date will
* always contain the real target date and only the trigger date is
* using the warning time. The trigger date will also be used if the user
* has the event displayed, but opted to keep the event and re-display it
* at a later time. This means that m_Date and m_Trigger can differ, while
* m_Trigger will always contain the date when the event is actually
* displayed to the user while m_Date always contains the user-selected date
* or a multiple thereof (in case of repeatable events).
*/
virtual bool CalcTrigger(void);
/**
* GetDate will return a string with the date representation for the given
* date structure.
*/
static wxString GetDate(wxDateTime const &);
/**
* GetTime will return a string with the time representation for the given
* date structure.
*/
static wxString GetTime(wxDateTime const &);
/**
* Trigger is to be called when an event has reached it's time. If it is
* a non-repeatable event it will simply stop, otherwise it calculates the
* next date and continues the event. If the event is a bill, and it has not
* been payed yet, then the event will be duplicated as a non-repeatable event
* (the original one continues) in order to keep track of it until it is payed.
* If the event had to be duplicated the pointer is returned in pNewEvent.
*/
virtual bool Trigger(CEvent *&pNewEvent);
/**
* Disable will disable the event. If it is a non-repeatable event this has no
* effect, but if it is a repeatable event it will be stopped an no longer repeated.
*/
virtual void Disable(void);
protected:
/**
* These are helperfunctions for parsing the string for a particular type while loading.
* It will return the respective datatype from the stream and advances
* the offset accordingly.
* false is returned if an error occurs and the value is undefined..
* Clean will clean the structure (if applicable) before it will start
* parsing. In case of GetNumber the value is always cleared. If the value
* is not cleared then only the appropriate fields are filled and the remainder
* is untouched. In case of GetString this means that the string is appended.
*
* Each of these functions will throw an int exception in case of an error.
*/
static long GetNumber(wxString const &LoadString, int &Offset);
static bool GetDate(wxString const &LoadString, wxDateTime &Date, int &Offset, bool Clean = true);
static bool GetTime(wxString const &LoadString, wxDateTime &Time, int &Offset, bool Clean = true);
static bool GetString(wxString const &LoadString, wxString &String, int &Offset, bool Clean = true);
static void PutNumber(wxString &SaveString, long Value);
static void PutDate(wxString &SaveString, wxDateTime &Date);
static void PutTime(wxString &SaveString, wxDateTime &Time);
static void PutString(wxString &SaveString, wxString &String);
public:
t_EventId m_EventId; // This is only used for internal purposes and will not be written to the savefile
ES_EventState m_EventState;
wxDateTime m_Date; // This is the actual date of the event which is shown in the display.
wxDateTime m_Trigger; // This is the calculated date when the event should be shown
wxString m_Title;
wxString m_Message;
RT_RepeatType m_RepeatType;
RO_RepeatOn m_RepeatOn;
RD_RepeatDay m_RepeatOnType;
int m_RepeatEvery;
DT_DateType m_RepeatEveryType;
int m_Warning;
DT_DateType m_WarningType;
bool m_Timed; // True if the event has a time associated
bool m_24h;
AMPM_VAL m_AMPM;
RL_RepeatLimit m_RepeatLimitType;
int m_RepeatLimitCount;
wxDateTime m_RepeatLimitDate;
// Now we have some variables which are needed for
// maintaining the grid
void *m_Renderer;
void *m_Editor;
};
WX_DEFINE_ARRAY(CEvent *, AEvent);
int EventCompare(CEvent **p1, CEvent **p2);
#endif