[go: up one dir, main page]

Menu

[r3]: / calendar / src / Event.h  Maximize  Restore  History

Download this file

325 lines (285 with data), 10.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/***************************************************************************
* 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