summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/event.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/library/backend/event.cpp b/library/backend/event.cpp
index eb238a4..0003fe9 100644
--- a/library/backend/event.cpp
+++ b/library/backend/event.cpp
@@ -1,1357 +1,1357 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "event.h" 21#include "event.h"
22#include "qfiledirect_p.h" 22#include "qfiledirect_p.h"
23#include <qtopia/timeconversion.h> 23#include <qtopia/timeconversion.h>
24#include <qtopia/stringutil.h> 24#include <qtopia/stringutil.h>
25#include <qtopia/private/recordfields.h> 25#include <qtopia/private/recordfields.h>
26#include <qbuffer.h> 26#include <qbuffer.h>
27#include <time.h> 27#include <time.h>
28#include "vobject_p.h" 28#include "vobject_p.h"
29 29
30#include <stdio.h> 30#include <stdio.h>
31 31
32using namespace Qtopia; 32using namespace Qtopia;
33 33
34static void write( QString& buf, const Event::RepeatPattern &r ) 34static void write( QString& buf, const Event::RepeatPattern &r )
35{ 35{
36 buf += " rtype=\""; 36 buf += " rtype=\"";
37 switch ( r.type ) { 37 switch ( r.type ) {
38 case Event::Daily: 38 case Event::Daily:
39 buf += "Daily"; 39 buf += "Daily";
40 break; 40 break;
41 case Event::Weekly: 41 case Event::Weekly:
42 buf += "Weekly"; 42 buf += "Weekly";
43 break; 43 break;
44 case Event::MonthlyDay: 44 case Event::MonthlyDay:
45 buf += "MonthlyDay"; 45 buf += "MonthlyDay";
46 break; 46 break;
47 case Event::MonthlyDate: 47 case Event::MonthlyDate:
48 buf += "MonthlyDate"; 48 buf += "MonthlyDate";
49 break; 49 break;
50 case Event::Yearly: 50 case Event::Yearly:
51 buf += "Yearly"; 51 buf += "Yearly";
52 break; 52 break;
53 default: 53 default:
54 buf += "NoRepeat"; 54 buf += "NoRepeat";
55 break; 55 break;
56 } 56 }
57 buf += "\""; 57 buf += "\"";
58 if ( r.days > 0 ) 58 if ( r.days > 0 )
59 buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\""; 59 buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\"";
60 if ( r.position != 0 ) 60 if ( r.position != 0 )
61 buf += " rposition=\"" + QString::number( r.position ) + "\""; 61 buf += " rposition=\"" + QString::number( r.position ) + "\"";
62 62
63 buf += " rfreq=\"" + QString::number( r.frequency ) + "\""; 63 buf += " rfreq=\"" + QString::number( r.frequency ) + "\"";
64 buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\""; 64 buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\"";
65 if ( r.hasEndDate ) 65 if ( r.hasEndDate )
66 buf += " enddt=\"" 66 buf += " enddt=\""
67 + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) ) 67 + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) )
68 + "\""; 68 + "\"";
69 buf += " created=\"" + QString::number( r.createTime ) + "\""; 69 buf += " created=\"" + QString::number( r.createTime ) + "\"";
70} 70}
71 71
72Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia ); 72Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia );
73 73
74/*! 74/*!
75 \class Event event.h 75 \class Event event.h
76 \brief The Event class holds the data of a calendar event. 76 \brief The Event class holds the data of a calendar event.
77 77
78 This data includes descriptive data of the event and schedualing information. 78 This data includes descriptive data of the event and schedualing information.
79 79
80 \ingroup qtopiaemb 80 \ingroup qtopiaemb
81 \ingroup qtopiadesktop 81 \ingroup qtopiadesktop
82*/ 82*/
83 83
84/*! 84/*!
85 \class Event::RepeatPattern 85 \class Event::RepeatPattern
86 \class The Event::RepeatPattern class is internal. 86 \class The Event::RepeatPattern class is internal.
87 \internal 87 \internal
88*/ 88*/
89 89
90/*! 90/*!
91 \enum Event::Days 91 \enum Event::Days
92 \internal 92 \internal
93*/ 93*/
94 94
95/*! 95/*!
96 \enum Event::Type 96 \enum Event::Type
97 \internal 97 \internal
98*/ 98*/
99 99
100/*! 100/*!
101 \enum Event::SoundTypeChoice 101 \enum Event::SoundTypeChoice
102 102
103 This enum type defines what kind of sound is made when an alarm occurs 103 This enum type defines what kind of sound is made when an alarm occurs
104 for an event. The currently defined types are: 104 for an event. The currently defined types are:
105 105
106 <ul> 106 <ul>
107 <li>\c Silent - No sound is produced. 107 <li>\c Silent - No sound is produced.
108 <li>\c Loud - A loud sound is produced. 108 <li>\c Loud - A loud sound is produced.
109 </ul> 109 </ul>
110*/ 110*/
111 111
112/*! 112/*!
113 \fn bool Event::operator<( const Event & ) const 113 \fn bool Event::operator<( const Event & ) const
114 \internal 114 \internal
115*/ 115*/
116 116
117/*! 117/*!
118 \fn bool Event::operator<=( const Event & ) const 118 \fn bool Event::operator<=( const Event & ) const
119 \internal 119 \internal
120*/ 120*/
121 121
122/*! 122/*!
123 \fn bool Event::operator!=( const Event & ) const 123 \fn bool Event::operator!=( const Event & ) const
124 \internal 124 \internal
125*/ 125*/
126 126
127/*! 127/*!
128 \fn bool Event::operator>( const Event & ) const 128 \fn bool Event::operator>( const Event & ) const
129 \internal 129 \internal
130*/ 130*/
131 131
132/*! 132/*!
133 \fn bool Event::operator>=( const Event & ) const 133 \fn bool Event::operator>=( const Event & ) const
134 \internal 134 \internal
135*/ 135*/
136 136
137/*! 137/*!
138 \enum Event::RepeatType 138 \enum Event::RepeatType
139 139
140 This enum defines how a event will repeat, if at all. 140 This enum defines how a event will repeat, if at all.
141 141
142 <ul> 142 <ul>
143 <li>\c NoRepeat - Event does not repeat. 143 <li>\c NoRepeat - Event does not repeat.
144 <li>\c Daily - Event occurs every n days. 144 <li>\c Daily - Event occurs every n days.
145 <li>\c Weekly - Event occurs every n weeks. 145 <li>\c Weekly - Event occurs every n weeks.
146 <li>\c MonthlyDay - Event occurs every n months. Event will always occur in 146 <li>\c MonthlyDay - Event occurs every n months. Event will always occur in
147 the same week and same day of week as the first event. 147 the same week and same day of week as the first event.
148 <li>\c MonthlyDate - Event occurs every n months. Event will always occur 148 <li>\c MonthlyDate - Event occurs every n months. Event will always occur
149 on the same day of the month as the first event. 149 on the same day of the month as the first event.
150 <li>\c Yearly - Event occurs every n years. 150 <li>\c Yearly - Event occurs every n years.
151 </ul> 151 </ul>
152*/ 152*/
153 153
154/*! 154/*!
155 \fn bool Event::isAllDay() const 155 \fn bool Event::isAllDay() const
156 156
157 Returns TRUE if the event is an all day event. Otherwise returns FALSE. 157 Returns TRUE if the event is an all day event. Otherwise returns FALSE.
158*/ 158*/
159 159
160/*! 160/*!
161 \fn void Event::setAllDay(bool allday) 161 \fn void Event::setAllDay(bool allday)
162 162
163 If \a allday is TRUE, will set the event to be an all day event. 163 If \a allday is TRUE, will set the event to be an all day event.
164 Otherwise sets the event to not be an all day event. 164 Otherwise sets the event to not be an all day event.
165 165
166 \warning This function may affect the start and end times of the event. 166 \warning This function may affect the start and end times of the event.
167*/ 167*/
168 168
169/*! 169/*!
170 \fn QDateTime Event::start() const 170 \fn QDateTime Event::start() const
171 171
172 Returns the start date and time of the first occurance of the event. 172 Returns the start date and time of the first occurance of the event.
173*/ 173*/
174 174
175/*! 175/*!
176 \fn QDateTime Event::end() const 176 \fn QDateTime Event::end() const
177 177
178 Returns the end date and time of the first occurance of the event. 178 Returns the end date and time of the first occurance of the event.
179*/ 179*/
180 180
181/*! 181/*!
182 \fn time_t Event::startTime() const 182 \fn time_t Event::startTime() const
183 \internal 183 \internal
184*/ 184*/
185 185
186/*! 186/*!
187 \fn time_t Event::endTime() const 187 \fn time_t Event::endTime() const
188 \internal 188 \internal
189*/ 189*/
190 190
191/*! 191/*!
192 \fn void Event::setAlarm(int delay, SoundTypeChoice s) 192 \fn void Event::setAlarm(int delay, SoundTypeChoice s)
193 193
194 Sets the alarm delay of the event to \a delay and the sound type of the 194 Sets the alarm delay of the event to \a delay and the sound type of the
195 alarm to \a s. 195 alarm to \a s.
196*/ 196*/
197 197
198/*! 198/*!
199 \fn void Event::clearAlarm() 199 \fn void Event::clearAlarm()
200 200
201 Clears the alarm for the event. 201 Clears the alarm for the event.
202*/ 202*/
203 203
204/*! 204/*!
205 \fn int Event::alarmDelay() const 205 \fn int Event::alarmDelay() const
206 206
207 Returns the delay in minutes between the alarm for an event and the 207 Returns the delay in minutes between the alarm for an event and the
208 start of the event. 208 start of the event.
209*/ 209*/
210 210
211/*! 211/*!
212 \fn Event::RepeatType Event::repeatType() const 212 \fn Event::RepeatType Event::repeatType() const
213 213
214 Returns the repeat pattern type for the event. 214 Returns the repeat pattern type for the event.
215 215
216 \sa frequency() 216 \sa frequency()
217*/ 217*/
218 218
219/*! 219/*!
220 \fn int Event::weekOffset() const 220 \fn int Event::weekOffset() const
221 221
222 Returns the number of weeks from the start of the month that this event 222 Returns the number of weeks from the start of the month that this event
223 occurs. 223 occurs.
224*/ 224*/
225 225
226/*! 226/*!
227 \fn QDate Event::repeatTill() const 227 \fn QDate Event::repeatTill() const
228 228
229 Returns the date that the event will continue to repeat until. If the event 229 Returns the date that the event will continue to repeat until. If the event
230 repeats forever the value returned is undefined. 230 repeats forever the value returned is undefined.
231 231
232 \sa repeatForever() 232 \sa repeatForever()
233*/ 233*/
234 234
235/*! 235/*!
236 \fn bool Event::repeatForever() const 236 \fn bool Event::repeatForever() const
237 237
238 Returns FALSE if there is a date set for the event to continue until. 238 Returns FALSE if there is a date set for the event to continue until.
239 Otherwise returns TRUE. 239 Otherwise returns TRUE.
240*/ 240*/
241 241
242/*! 242/*!
243 \fn bool Event::doRepeat() const 243 \fn bool Event::doRepeat() const
244 \internal 244 \internal
245*/ 245*/
246 246
247/*! 247/*!
248 \fn bool Event::repeatOnWeekDay(int day) const 248 \fn bool Event::repeatOnWeekDay(int day) const
249 249
250 Returns TRUE if the event has a RepeatType of Weekly and is set to occur on 250 Returns TRUE if the event has a RepeatType of Weekly and is set to occur on
251 \a day each week. Otherwise returns FALSE. 251 \a day each week. Otherwise returns FALSE.
252 252
253 \sa QDate::dayName() 253 \sa QDate::dayName()
254*/ 254*/
255 255
256/*! 256/*!
257 \fn void Event::setRepeatOnWeekDay(int day, bool enable) 257 \fn void Event::setRepeatOnWeekDay(int day, bool enable)
258 258
259 If \a enable is TRUE then sets the event to occur on \a day each week. 259 If \a enable is TRUE then sets the event to occur on \a day each week.
260 Otherwise sets the event not to occur on \a day. 260 Otherwise sets the event not to occur on \a day.
261 261
262 \warning this function is only relavent for a event with RepeatType of 262 \warning this function is only relavent for a event with RepeatType of
263 Weekly. 263 Weekly.
264 264
265 \sa QDate::dayName() 265 \sa QDate::dayName()
266*/ 266*/
267 267
268/*! 268/*!
269 \fn int Event::frequency() const 269 \fn int Event::frequency() const
270 270
271 Returns how often the event repeats. 271 Returns how often the event repeats.
272 272
273 \sa repeatType() 273 \sa repeatType()
274*/ 274*/
275 275
276/*! 276/*!
277 \fn void Event::setRepeatType(RepeatType t) 277 \fn void Event::setRepeatType(RepeatType t)
278 278
279 Sets the repeat pattern type of the event to \a t. 279 Sets the repeat pattern type of the event to \a t.
280 280
281 \sa setFrequency() 281 \sa setFrequency()
282*/ 282*/
283 283
284/*! 284/*!
285 \fn void Event::setFrequency(int n) 285 \fn void Event::setFrequency(int n)
286 286
287 Sets how often the event occurs with in its repeat pattern. 287 Sets how often the event occurs with in its repeat pattern.
288 288
289 \sa setRepeatType() 289 \sa setRepeatType()
290*/ 290*/
291 291
292/*! 292/*!
293 \fn void Event::setRepeatTill(const QDate &d) 293 \fn void Event::setRepeatTill(const QDate &d)
294 294
295 Sets the event to repeat until \a d. 295 Sets the event to repeat until \a d.
296*/ 296*/
297 297
298/*! 298/*!
299 \fn void Event::setRepeatForever(bool enable) 299 \fn void Event::setRepeatForever(bool enable)
300 300
301 If \a enable is TRUE, sets the event to repeat forever. Otherwise 301 If \a enable is TRUE, sets the event to repeat forever. Otherwise
302 sets the event to stop repeating at some date. 302 sets the event to stop repeating at some date.
303 303
304 \warning This function may affect the specific date the event will repeat 304 \warning This function may affect the specific date the event will repeat
305 till. 305 till.
306*/ 306*/
307 307
308/*! 308/*!
309 \fn bool Event::match(const QRegExp &r) const 309 \fn bool Event::match(const QRegExp &r) const
310 310
311 Returns TRUE if the event matches the regular expression \a r. 311 Returns TRUE if the event matches the regular expression \a r.
312 Otherwise returns FALSE. 312 Otherwise returns FALSE.
313*/ 313*/
314 314
315/*! 315/*!
316 \fn char Event::day(int) 316 \fn char Event::day(int)
317 \internal 317 \internal
318*/ 318*/
319 319
320/*! 320/*!
321 Creates a new, empty event. 321 Creates a new, empty event.
322*/ 322*/
323Event::Event() : Record() 323Event::Event() : Record()
324{ 324{
325 startUTC = endUTC = time( 0 ); 325 startUTC = endUTC = time( 0 );
326 typ = Normal; 326 typ = Normal;
327 hAlarm = FALSE; 327 hAlarm = FALSE;
328 hRepeat = FALSE; 328 hRepeat = FALSE;
329 aMinutes = 0; 329 aMinutes = 0;
330 aSound = Silent; 330 aSound = Silent;
331 pattern.type = NoRepeat; 331 pattern.type = NoRepeat;
332 pattern.frequency = -1; 332 pattern.frequency = -1;
333} 333}
334 334
335/*! 335/*!
336 \internal 336 \internal
337*/ 337*/
338Event::Event( const QMap<int, QString> &map ) 338Event::Event( const QMap<int, QString> &map )
339{ 339{
340 setDescription( map[DatebookDescription] ); 340 setDescription( map[DatebookDescription] );
341 setLocation( map[Location] ); 341 setLocation( map[Location] );
342 setCategories( idsFromString( map[DatebookCategory] ) ); 342 setCategories( idsFromString( map[DatebookCategory] ) );
343 setTimeZone( map[TimeZone] ); 343 setTimeZone( map[TimeZone] );
344 setNotes( map[Note] ); 344 setNotes( map[Note] );
345 setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) ); 345 setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) );
346 setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) ); 346 setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) );
347 setType( (Event::Type) map[DatebookType].toInt() ); 347 setType( (Event::Type) map[DatebookType].toInt() );
348 setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() ); 348 setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() );
349 Event::RepeatPattern p; 349 Event::RepeatPattern p;
350 p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt(); 350 p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt();
351 p.frequency = map[ RepeatPatternFrequency ].toInt(); 351 p.frequency = map[ RepeatPatternFrequency ].toInt();
352 p.position = map[ RepeatPatternPosition ].toInt(); 352 p.position = map[ RepeatPatternPosition ].toInt();
353 p.days = map[ RepeatPatternDays ].toInt(); 353 p.days = map[ RepeatPatternDays ].toInt();
354 p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt(); 354 p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt();
355 p.endDateUTC = map[ RepeatPatternEndDate ].toUInt(); 355 p.endDateUTC = map[ RepeatPatternEndDate ].toUInt();
356 setRepeat( p ); 356 setRepeat( p );
357 357
358 setUid( map[ DatebookUid ].toInt() ); 358 setUid( map[ DatebookUid ].toInt() );
359} 359}
360 360
361/*! 361/*!
362 Destroys an event. 362 Destroys an event.
363*/ 363*/
364Event::~Event() 364Event::~Event()
365{ 365{
366} 366}
367 367
368/*! 368/*!
369 \internal 369 \internal
370*/ 370*/
371int Event::week( const QDate& date ) 371int Event::week( const QDate& date )
372{ 372{
373 // Calculates the week this date is in within that 373 // Calculates the week this date is in within that
374 // month. Equals the "row" is is in in the month view 374 // month. Equals the "row" is is in in the month view
375 int week = 1; 375 int week = 1;
376 QDate tmp( date.year(), date.month(), 1 ); 376 QDate tmp( date.year(), date.month(), 1 );
377 377
378 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 378 if ( date.dayOfWeek() < tmp.dayOfWeek() )
379 ++week; 379 ++week;
380 380
381 week += ( date.day() - 1 ) / 7; 381 week += ( date.day() - 1 ) / 7;
382 return week; 382 return week;
383} 383}
384 384
385/*! 385/*!
386 \internal 386 \internal
387*/ 387*/
388int Event::occurrence( const QDate& date ) 388int Event::occurrence( const QDate& date )
389{ 389{
390 // calculates the number of occurrances of this day of the 390 // calculates the number of occurrances of this day of the
391 // week till the given date (e.g 3rd Wednesday of the month) 391 // week till the given date (e.g 3rd Wednesday of the month)
392 return ( date.day() - 1 ) / 7 + 1; 392 return ( date.day() - 1 ) / 7 + 1;
393} 393}
394 394
395/*! 395/*!
396 \internal 396 \internal
397*/ 397*/
398int Event::dayOfWeek( char day ) 398int Event::dayOfWeek( char day )
399{ 399{
400 int dayOfWeek = 1; 400 int dayOfWeek = 1;
401 char i = Event::MON; 401 char i = Event::MON;
402 while ( !( i & day ) && i <= Event::SUN ) { 402 while ( !( i & day ) && i <= Event::SUN ) {
403 i <<= 1; 403 i <<= 1;
404 ++dayOfWeek; 404 ++dayOfWeek;
405 } 405 }
406 return dayOfWeek; 406 return dayOfWeek;
407} 407}
408 408
409/*! 409/*!
410 \internal 410 \internal
411*/ 411*/
412int Event::monthDiff( const QDate& first, const QDate& second ) 412int Event::monthDiff( const QDate& first, const QDate& second )
413{ 413{
414 return ( second.year() - first.year() ) * 12 + 414 return ( second.year() - first.year() ) * 12 +
415 second.month() - first.month(); 415 second.month() - first.month();
416} 416}
417 417
418/*! 418/*!
419 \internal 419 \internal
420*/ 420*/
421QMap<int, QString> Event::toMap() const 421QMap<int, QString> Event::toMap() const
422{ 422{
423 QMap<int, QString> m; 423 QMap<int, QString> m;
424 424
425 if ( !description().isEmpty() ) 425 if ( !description().isEmpty() )
426 m.insert( DatebookDescription, description() ); 426 m.insert( DatebookDescription, description() );
427 if ( !location().isEmpty() ) 427 if ( !location().isEmpty() )
428 m.insert ( Location, location() ); 428 m.insert ( Location, location() );
429 if ( categories().count() ) 429 if ( categories().count() )
430 m.insert ( DatebookCategory, idsToString( categories() ) ); 430 m.insert ( DatebookCategory, idsToString( categories() ) );
431 if ( !timeZone().isEmpty() ) 431 if ( !timeZone().isEmpty() )
432 m.insert ( TimeZone, timeZone() ); 432 m.insert ( TimeZone, timeZone() );
433 if ( !notes().isEmpty() ) 433 if ( !notes().isEmpty() )
434 m.insert ( Note, notes() ); 434 m.insert ( Note, notes() );
435 435
436 m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) ); 436 m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) );
437 m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) ); 437 m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) );
438 m.insert ( DatebookType, QString::number( (int)type() ) ); 438 m.insert ( DatebookType, QString::number( (int)type() ) );
439 m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) ); 439 m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) );
440 m.insert ( SoundType, QString::number( (int)alarmSound() ) ); 440 m.insert ( SoundType, QString::number( (int)alarmSound() ) );
441 m.insert ( AlarmTime, QString::number( alarmTime() ) ); 441 m.insert ( AlarmTime, QString::number( alarmTime() ) );
442 m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) ); 442 m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) );
443 m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) ); 443 m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) );
444 m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) ); 444 m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) );
445 m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) ); 445 m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) );
446 m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) ); 446 m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) );
447 m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) ); 447 m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) );
448 448
449 m.insert( DatebookUid, QString::number( uid()) ); 449 m.insert( DatebookUid, QString::number( uid()) );
450 450
451 return m; 451 return m;
452} 452}
453 453
454/*! 454/*!
455 \internal 455 \internal
456*/ 456*/
457void Event::setRepeat( const RepeatPattern &p ) 457void Event::setRepeat( const RepeatPattern &p )
458{ 458{
459 setRepeat( p.type != NoRepeat, p ); 459 setRepeat( p.type != NoRepeat, p );
460} 460}
461 461
462/*! 462/*!
463 Sets the description of the event to \a s. 463 Sets the description of the event to \a s.
464*/ 464*/
465void Event::setDescription( const QString &s ) 465void Event::setDescription( const QString &s )
466{ 466{
467 descript = s; 467 descript = s;
468} 468}
469 469
470/*! 470/*!
471 Sets the location of the event to \a s. 471 Sets the location of the event to \a s.
472*/ 472*/
473void Event::setLocation( const QString &s ) 473void Event::setLocation( const QString &s )
474{ 474{
475 locat = s; 475 locat = s;
476} 476}
477 477
478// void Event::setCategory( const QString &s ) 478// void Event::setCategory( const QString &s )
479// { 479// {
480// categ = s; 480// categ = s;
481// } 481// }
482 482
483/*! 483/*!
484 \internal 484 \internal
485*/ 485*/
486void Event::setType( Type t ) 486void Event::setType( Type t )
487{ 487{
488 typ = t; 488 typ = t;
489} 489}
490 490
491/*! 491/*!
492 Sets the start date and time of the first or only occurance of this event 492 Sets the start date and time of the first or only occurance of this event
493 to the date and time \a d. \a d should be in local time. 493 to the date and time \a d. \a d should be in local time.
494*/ 494*/
495void Event::setStart( const QDateTime &d ) 495void Event::setStart( const QDateTime &d )
496{ 496{
497 startUTC = TimeConversion::toUTC( d ); 497 startUTC = TimeConversion::toUTC( d );
498} 498}
499 499
500/*! 500/*!
501 \internal 501 \internal
502*/ 502*/
503void Event::setStart( time_t time ) 503void Event::setStart( time_t time )
504{ 504{
505 startUTC = time; 505 startUTC = time;
506} 506}
507 507
508/*! 508/*!
509 Sets the end date and time of the first or only occurance of this event 509 Sets the end date and time of the first or only occurance of this event
510 to the date and time \a d. \a d should be in local time. 510 to the date and time \a d. \a d should be in local time.
511*/ 511*/
512void Event::setEnd( const QDateTime &d ) 512void Event::setEnd( const QDateTime &d )
513{ 513{
514 endUTC = TimeConversion::toUTC( d ); 514 endUTC = TimeConversion::toUTC( d );
515} 515}
516 516
517/*! 517/*!
518 \internal 518 \internal
519*/ 519*/
520void Event::setEnd( time_t time ) 520void Event::setEnd( time_t time )
521{ 521{
522 endUTC = time; 522 endUTC = time;
523} 523}
524 524
525/*! 525/*!
526 \internal 526 \internal
527*/ 527*/
528void Event::setTimeZone( const QString &z ) 528void Event::setTimeZone( const QString &z )
529{ 529{
530 tz = z; 530 tz = z;
531} 531}
532 532
533/*! 533/*!
534 \internal 534 \internal
535*/ 535*/
536void Event::setAlarm( bool b, int minutes, SoundTypeChoice s ) 536void Event::setAlarm( bool b, int minutes, SoundTypeChoice s )
537{ 537{
538 hAlarm = b; 538 hAlarm = b;
539 aMinutes = minutes; 539 aMinutes = minutes;
540 aSound = s; 540 aSound = s;
541} 541}
542 542
543/*! 543/*!
544 \internal 544 \internal
545*/ 545*/
546void Event::setRepeat( bool b, const RepeatPattern &p ) 546void Event::setRepeat( bool b, const RepeatPattern &p )
547{ 547{
548 hRepeat = b; 548 hRepeat = b;
549 pattern = p; 549 pattern = p;
550} 550}
551 551
552/*! 552/*!
553 Sets the notes for the event to \a n. 553 Sets the notes for the event to \a n.
554*/ 554*/
555void Event::setNotes( const QString &n ) 555void Event::setNotes( const QString &n )
556{ 556{
557 note = n; 557 note = n;
558} 558}
559 559
560/*! 560/*!
561 Returns the description of the event. 561 Returns the description of the event.
562*/ 562*/
563const QString &Event::description() const 563const QString &Event::description() const
564{ 564{
565 return descript; 565 return descript;
566} 566}
567 567
568/*! 568/*!
569 Returns the location of the event. 569 Returns the location of the event.
570*/ 570*/
571const QString &Event::location() const 571const QString &Event::location() const
572{ 572{
573 return locat; 573 return locat;
574} 574}
575 575
576// QString Event::category() const 576// QString Event::category() const
577// { 577// {
578// return categ; 578// return categ;
579// } 579// }
580 580
581/*! 581/*!
582 \internal 582 \internal
583*/ 583*/
584Event::Type Event::type() const 584Event::Type Event::type() const
585{ 585{
586 return typ; 586 return typ;
587} 587}
588/* 588/*
589QDateTime Event::start() const { 589QDateTime Event::start() const {
590 return start( TRUE ); 590 return start( TRUE );
591} 591}
592*/ 592*/
593/*! 593/*!
594 \internal 594 \internal
595*/ 595*/
596QDateTime Event::start( bool actual ) const 596QDateTime Event::start( bool actual ) const
597{ 597{
598 QDateTime dt = (startUTC > 0) ? TimeConversion::fromUTC( startUTC ) : QDateTime::currentDateTime(); 598 QDateTime dt = TimeConversion::fromUTC( startUTC );
599 599
600 if ( actual && typ == AllDay ) { 600 if ( actual && typ == AllDay ) {
601 QTime t = dt.time(); 601 QTime t = dt.time();
602 t.setHMS( 0, 0, 0 ); 602 t.setHMS( 0, 0, 0 );
603 dt.setTime( t ); 603 dt.setTime( t );
604 } 604 }
605 return dt; 605 return dt;
606} 606}
607/* 607/*
608QDateTime Event::end() const { 608QDateTime Event::end() const {
609 return end( TRUE ); 609 return end( TRUE );
610} 610}
611*/ 611*/
612/*! 612/*!
613 \internal 613 \internal
614*/ 614*/
615QDateTime Event::end( bool actual ) const 615QDateTime Event::end( bool actual ) const
616{ 616{
617 QDateTime dt = (endUTC > 0) ? TimeConversion::fromUTC( endUTC ) : QDateTime::currentDateTime(); 617 QDateTime dt = TimeConversion::fromUTC( endUTC );
618 618
619 if ( actual && typ == AllDay ) { 619 if ( actual && typ == AllDay ) {
620 QTime t = dt.time(); 620 QTime t = dt.time();
621 t.setHMS( 23, 59, 59 ); 621 t.setHMS( 23, 59, 59 );
622 dt.setTime( t ); 622 dt.setTime( t );
623 } 623 }
624 return dt; 624 return dt;
625} 625}
626 626
627/*! 627/*!
628 \internal 628 \internal
629*/ 629*/
630const QString &Event::timeZone() const 630const QString &Event::timeZone() const
631{ 631{
632 return tz; 632 return tz;
633} 633}
634 634
635/*! 635/*!
636 \internal 636 \internal
637*/ 637*/
638bool Event::hasAlarm() const 638bool Event::hasAlarm() const
639{ 639{
640 return hAlarm; 640 return hAlarm;
641} 641}
642 642
643/*! 643/*!
644 \internal 644 \internal
645*/ 645*/
646int Event::alarmTime() const 646int Event::alarmTime() const
647{ 647{
648 return aMinutes; 648 return aMinutes;
649} 649}
650 650
651/*! 651/*!
652 Returns the sound type for the alarm of this event. 652 Returns the sound type for the alarm of this event.
653*/ 653*/
654Event::SoundTypeChoice Event::alarmSound() const 654Event::SoundTypeChoice Event::alarmSound() const
655{ 655{
656 return aSound; 656 return aSound;
657} 657}
658 658
659/*! 659/*!
660 \internal 660 \internal
661*/ 661*/
662bool Event::hasRepeat() const 662bool Event::hasRepeat() const
663{ 663{
664 return doRepeat(); 664 return doRepeat();
665} 665}
666 666
667/*! 667/*!
668 \internal 668 \internal
669*/ 669*/
670const Event::RepeatPattern &Event::repeatPattern() const 670const Event::RepeatPattern &Event::repeatPattern() const
671{ 671{
672 return pattern; 672 return pattern;
673} 673}
674 674
675/*! 675/*!
676 \internal 676 \internal
677*/ 677*/
678Event::RepeatPattern &Event::repeatPattern() 678Event::RepeatPattern &Event::repeatPattern()
679{ 679{
680 return pattern; 680 return pattern;
681} 681}
682 682
683/*! 683/*!
684 Returns the notes for the event. 684 Returns the notes for the event.
685*/ 685*/
686const QString &Event::notes() const 686const QString &Event::notes() const
687{ 687{
688 return note; 688 return note;
689} 689}
690 690
691/*! 691/*!
692 \internal 692 \internal
693*/ 693*/
694bool Event::operator==( const Event &e ) const 694bool Event::operator==( const Event &e ) const
695{ 695{
696 if ( uid() && e.uid() == uid() ) 696 if ( uid() && e.uid() == uid() )
697 return TRUE; 697 return TRUE;
698 return ( e.descript == descript && 698 return ( e.descript == descript &&
699 e.locat == locat && 699 e.locat == locat &&
700 e.categ == categ && 700 e.categ == categ &&
701 e.typ == typ && 701 e.typ == typ &&
702 e.startUTC == startUTC && 702 e.startUTC == startUTC &&
703 e.endUTC == endUTC && 703 e.endUTC == endUTC &&
704 e.tz == tz && 704 e.tz == tz &&
705 e.hAlarm == hAlarm && 705 e.hAlarm == hAlarm &&
706 e.aMinutes == aMinutes && 706 e.aMinutes == aMinutes &&
707 e.aSound == aSound && 707 e.aSound == aSound &&
708 e.hRepeat == hRepeat && 708 e.hRepeat == hRepeat &&
709 e.pattern == pattern && 709 e.pattern == pattern &&
710 e.note == note ); 710 e.note == note );
711} 711}
712 712
713/*! 713/*!
714 \internal 714 \internal
715 Appends the contact information to \a buf. 715 Appends the contact information to \a buf.
716*/ 716*/
717void Event::save( QString& buf ) 717void Event::save( QString& buf )
718{ 718{
719 buf += " description=\"" + Qtopia::escapeString(descript) + "\""; 719 buf += " description=\"" + Qtopia::escapeString(descript) + "\"";
720 if ( !locat.isEmpty() ) 720 if ( !locat.isEmpty() )
721 buf += " location=\"" + Qtopia::escapeString(locat) + "\""; 721 buf += " location=\"" + Qtopia::escapeString(locat) + "\"";
722 // save the categoies differently.... 722 // save the categoies differently....
723 QString strCats = idsToString( categories() ); 723 QString strCats = idsToString( categories() );
724 buf += " categories=\"" + Qtopia::escapeString(strCats) + "\""; 724 buf += " categories=\"" + Qtopia::escapeString(strCats) + "\"";
725 buf += " uid=\"" + QString::number( uid() ) + "\""; 725 buf += " uid=\"" + QString::number( uid() ) + "\"";
726 if ( (Type)typ != Normal ) 726 if ( (Type)typ != Normal )
727 buf += " type=\"AllDay\""; 727 buf += " type=\"AllDay\"";
728 if ( hAlarm ) { 728 if ( hAlarm ) {
729 buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\""; 729 buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\"";
730 if ( aSound == Event::Loud ) 730 if ( aSound == Event::Loud )
731 buf += "loud"; 731 buf += "loud";
732 else 732 else
733 buf += "silent"; 733 buf += "silent";
734 buf += "\""; 734 buf += "\"";
735 } 735 }
736 if ( hRepeat ) 736 if ( hRepeat )
737 write( buf, pattern ); 737 write( buf, pattern );
738 738
739 buf += " start=\"" 739 buf += " start=\""
740 + QString::number( startUTC ) 740 + QString::number( startUTC )
741 + "\""; 741 + "\"";
742 742
743 buf += " end=\"" 743 buf += " end=\""
744 + QString::number( endUTC ) 744 + QString::number( endUTC )
745 + "\""; 745 + "\"";
746 746
747 if ( !note.isEmpty() ) 747 if ( !note.isEmpty() )
748 buf += " note=\"" + Qtopia::escapeString( note ) + "\""; 748 buf += " note=\"" + Qtopia::escapeString( note ) + "\"";
749 buf += customToXml(); 749 buf += customToXml();
750} 750}
751 751
752/*! 752/*!
753 \internal 753 \internal
754*/ 754*/
755bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const 755bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const
756{ 756{
757 // *sigh* 757 // *sigh*
758 return ( type == right.type 758 return ( type == right.type
759 && frequency == right.frequency 759 && frequency == right.frequency
760 && position == right.position 760 && position == right.position
761 && days == right.days 761 && days == right.days
762 && hasEndDate == right.hasEndDate 762 && hasEndDate == right.hasEndDate
763 && endDateUTC == right.endDateUTC 763 && endDateUTC == right.endDateUTC
764 && createTime == right.createTime ); 764 && createTime == right.createTime );
765} 765}
766 766
767/*! 767/*!
768 \class EffectiveEvent 768 \class EffectiveEvent
769 \brief The EffectiveEvent class the data for a single occurance of an event. 769 \brief The EffectiveEvent class the data for a single occurance of an event.
770 770
771 This class describes the event for a single occurance of it. For example if 771 This class describes the event for a single occurance of it. For example if
772 an Event occurs every week, the effective event might represent the third 772 an Event occurs every week, the effective event might represent the third
773 occurance of this Event. 773 occurance of this Event.
774 774
775 \ingroup qtopiaemb 775 \ingroup qtopiaemb
776 \ingroup qtopiadesktop 776 \ingroup qtopiadesktop
777 \warning This class will be phased out in Qtopia 3.x 777 \warning This class will be phased out in Qtopia 3.x
778*/ 778*/
779 779
780/*! 780/*!
781 \enum EffectiveEvent::Position 781 \enum EffectiveEvent::Position
782 \internal 782 \internal
783*/ 783*/
784 784
785/*! 785/*!
786 \fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &) 786 \fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &)
787 \internal 787 \internal
788*/ 788*/
789 789
790class EffectiveEventPrivate 790class EffectiveEventPrivate
791{ 791{
792public: 792public:
793 //currently the existence of the d pointer means multi-day repeating, 793 //currently the existence of the d pointer means multi-day repeating,
794 //msut be changed if we use the d pointer for anything else. 794 //msut be changed if we use the d pointer for anything else.
795 QDate startDate; 795 QDate startDate;
796 QDate endDate; 796 QDate endDate;
797}; 797};
798 798
799/*! 799/*!
800 \internal 800 \internal
801*/ 801*/
802EffectiveEvent::EffectiveEvent() 802EffectiveEvent::EffectiveEvent()
803{ 803{
804 mDate = QDate::currentDate(); 804 mDate = QDate::currentDate();
805 mStart = mEnd = QTime::currentTime(); 805 mStart = mEnd = QTime::currentTime();
806 d = 0; 806 d = 0;
807} 807}
808 808
809/*! 809/*!
810 \internal 810 \internal
811*/ 811*/
812EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos ) 812EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos )
813{ 813{
814 mEvent = e; 814 mEvent = e;
815 mDate = date; 815 mDate = date;
816 if ( pos & Start ) 816 if ( pos & Start )
817 mStart = e.start( TRUE ).time(); 817 mStart = e.start( TRUE ).time();
818 else 818 else
819 mStart = QTime( 0, 0, 0 ); 819 mStart = QTime( 0, 0, 0 );
820 820
821 if ( pos & End ) 821 if ( pos & End )
822 mEnd = e.end( TRUE ).time(); 822 mEnd = e.end( TRUE ).time();
823 else 823 else
824 mEnd = QTime( 23, 59, 59 ); 824 mEnd = QTime( 23, 59, 59 );
825 d = 0; 825 d = 0;
826} 826}
827 827
828/*! 828/*!
829 \internal 829 \internal
830*/ 830*/
831EffectiveEvent::~EffectiveEvent() 831EffectiveEvent::~EffectiveEvent()
832{ 832{
833 delete d; 833 delete d;
834} 834}
835 835
836/*! 836/*!
837 \internal 837 \internal
838*/ 838*/
839EffectiveEvent::EffectiveEvent( const EffectiveEvent &e ) 839EffectiveEvent::EffectiveEvent( const EffectiveEvent &e )
840{ 840{
841 d = 0; 841 d = 0;
842 *this = e; 842 *this = e;
843} 843}
844 844
845EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e ) 845EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e )
846{ 846{
847 if ( &e == this ) 847 if ( &e == this )
848 return *this; 848 return *this;
849 delete d; 849 delete d;
850 if ( e.d ) { 850 if ( e.d ) {
851 d = new EffectiveEventPrivate; 851 d = new EffectiveEventPrivate;
852 d->startDate = e.d->startDate; 852 d->startDate = e.d->startDate;
853 d->endDate = e.d->endDate; 853 d->endDate = e.d->endDate;
854 } else { 854 } else {
855 d = 0; 855 d = 0;
856 } 856 }
857 mEvent = e.mEvent; 857 mEvent = e.mEvent;
858 mDate = e.mDate; 858 mDate = e.mDate;
859 mStart = e.mStart; 859 mStart = e.mStart;
860 mEnd = e.mEnd; 860 mEnd = e.mEnd;
861 861
862 return *this; 862 return *this;
863 863
864} 864}
865 865
866// QString EffectiveEvent::category() const 866// QString EffectiveEvent::category() const
867// { 867// {
868// return mEvent.category(); 868// return mEvent.category();
869// } 869// }
870 870
871/*! 871/*!
872 Returns the description of the event for this effective event. 872 Returns the description of the event for this effective event.
873*/ 873*/
874const QString &EffectiveEvent::description( ) const 874const QString &EffectiveEvent::description( ) const
875{ 875{
876 return mEvent.description(); 876 return mEvent.description();
877} 877}
878 878
879/*! 879/*!
880\internal 880\internal
881*/ 881*/
882const QString &EffectiveEvent::location( ) const 882const QString &EffectiveEvent::location( ) const
883{ 883{
884 return mEvent.location(); 884 return mEvent.location();
885} 885}
886 886
887/*! 887/*!
888\internal 888\internal
889*/ 889*/
890const QString &EffectiveEvent::notes() const 890const QString &EffectiveEvent::notes() const
891{ 891{
892 return mEvent.notes(); 892 return mEvent.notes();
893} 893}
894 894
895/*! 895/*!
896 Returns the event associated with this effective event. 896 Returns the event associated with this effective event.
897*/ 897*/
898const Event &EffectiveEvent::event() const 898const Event &EffectiveEvent::event() const
899{ 899{
900 return mEvent; 900 return mEvent;
901} 901}
902 902
903/*! 903/*!
904 \internal 904 \internal
905*/ 905*/
906const QTime &EffectiveEvent::end() const 906const QTime &EffectiveEvent::end() const
907{ 907{
908 return mEnd; 908 return mEnd;
909} 909}
910 910
911/*! 911/*!
912 \internal 912 \internal
913*/ 913*/
914const QTime &EffectiveEvent::start() const 914const QTime &EffectiveEvent::start() const
915{ 915{
916 return mStart; 916 return mStart;
917} 917}
918 918
919/*! 919/*!
920 Returns the date the effective event occurs on. 920 Returns the date the effective event occurs on.
921*/ 921*/
922const QDate &EffectiveEvent::date() const 922const QDate &EffectiveEvent::date() const
923{ 923{
924 return mDate; 924 return mDate;
925} 925}
926 926
927/*! 927/*!
928 \internal 928 \internal
929*/ 929*/
930int EffectiveEvent::length() const 930int EffectiveEvent::length() const
931{ 931{
932 return (mEnd.hour() * 60 - mStart.hour() * 60) 932 return (mEnd.hour() * 60 - mStart.hour() * 60)
933 + QABS(mStart.minute() - mEnd.minute() ); 933 + QABS(mStart.minute() - mEnd.minute() );
934} 934}
935 935
936/*! 936/*!
937 \internal 937 \internal
938*/ 938*/
939void EffectiveEvent::setDate( const QDate &dt ) 939void EffectiveEvent::setDate( const QDate &dt )
940{ 940{
941 mDate = dt; 941 mDate = dt;
942} 942}
943 943
944/*! 944/*!
945 \internal 945 \internal
946*/ 946*/
947void EffectiveEvent::setStart( const QTime &start ) 947void EffectiveEvent::setStart( const QTime &start )
948{ 948{
949 mStart = start; 949 mStart = start;
950} 950}
951 951
952/*! 952/*!
953 \internal 953 \internal
954*/ 954*/
955void EffectiveEvent::setEnd( const QTime &end ) 955void EffectiveEvent::setEnd( const QTime &end )
956{ 956{
957 mEnd = end; 957 mEnd = end;
958} 958}
959 959
960/*! 960/*!
961 \internal 961 \internal
962*/ 962*/
963void EffectiveEvent::setEvent( Event e ) 963void EffectiveEvent::setEvent( Event e )
964{ 964{
965 mEvent = e; 965 mEvent = e;
966} 966}
967 967
968/*! 968/*!
969 \internal 969 \internal
970*/ 970*/
971bool EffectiveEvent::operator<( const EffectiveEvent &e ) const 971bool EffectiveEvent::operator<( const EffectiveEvent &e ) const
972{ 972{
973 if ( mDate < e.date() ) 973 if ( mDate < e.date() )
974 return TRUE; 974 return TRUE;
975 if ( mDate == e.date() ) 975 if ( mDate == e.date() )
976 return ( mStart < e.start() ); 976 return ( mStart < e.start() );
977 else 977 else
978 return FALSE; 978 return FALSE;
979} 979}
980 980
981/*! 981/*!
982 \internal 982 \internal
983*/ 983*/
984bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const 984bool EffectiveEvent::operator<=( const EffectiveEvent &e ) const
985{ 985{
986 return (mDate <= e.date() ); 986 return (mDate <= e.date() );
987} 987}
988 988
989/*! 989/*!
990 \internal 990 \internal
991*/ 991*/
992bool EffectiveEvent::operator==( const EffectiveEvent &e ) const 992bool EffectiveEvent::operator==( const EffectiveEvent &e ) const
993{ 993{
994 return ( mDate == e.date() 994 return ( mDate == e.date()
995 && mStart == e.start() 995 && mStart == e.start()
996 && mEnd == e.end() 996 && mEnd == e.end()
997 && mEvent == e.event() ); 997 && mEvent == e.event() );
998} 998}
999 999
1000/*! 1000/*!
1001 \internal 1001 \internal
1002*/ 1002*/
1003bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const 1003bool EffectiveEvent::operator!=( const EffectiveEvent &e ) const
1004{ 1004{
1005 return !(*this == e); 1005 return !(*this == e);
1006} 1006}
1007 1007
1008/*! 1008/*!
1009 \internal 1009 \internal
1010*/ 1010*/
1011bool EffectiveEvent::operator>( const EffectiveEvent &e ) const 1011bool EffectiveEvent::operator>( const EffectiveEvent &e ) const
1012{ 1012{
1013 return !(*this <= e ); 1013 return !(*this <= e );
1014} 1014}
1015 1015
1016/*! 1016/*!
1017 \internal 1017 \internal
1018*/ 1018*/
1019bool EffectiveEvent::operator>=(const EffectiveEvent &e) const 1019bool EffectiveEvent::operator>=(const EffectiveEvent &e) const
1020{ 1020{
1021 return !(*this < e); 1021 return !(*this < e);
1022} 1022}
1023 1023
1024/*! 1024/*!
1025 \internal 1025 \internal
1026*/ 1026*/
1027void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to ) 1027void EffectiveEvent::setEffectiveDates( const QDate &from, const QDate &to )
1028{ 1028{
1029 if ( !from.isValid() ) { 1029 if ( !from.isValid() ) {
1030 delete d; 1030 delete d;
1031 d = 0; 1031 d = 0;
1032 return; 1032 return;
1033 } 1033 }
1034 if ( !d ) 1034 if ( !d )
1035 d = new EffectiveEventPrivate; 1035 d = new EffectiveEventPrivate;
1036 d->startDate = from; 1036 d->startDate = from;
1037 d->endDate = to; 1037 d->endDate = to;
1038} 1038}
1039 1039
1040/*! 1040/*!
1041 \internal 1041 \internal
1042*/ 1042*/
1043QDate EffectiveEvent::startDate() const 1043QDate EffectiveEvent::startDate() const
1044{ 1044{
1045 if ( d ) 1045 if ( d )
1046 return d->startDate; 1046 return d->startDate;
1047 else if ( mEvent.hasRepeat() ) 1047 else if ( mEvent.hasRepeat() )
1048 return mDate; // single day, since multi-day should have a d pointer 1048 return mDate; // single day, since multi-day should have a d pointer
1049 else 1049 else
1050 return mEvent.start().date(); 1050 return mEvent.start().date();
1051} 1051}
1052 1052
1053/*! 1053/*!
1054 \internal 1054 \internal
1055*/ 1055*/
1056QDate EffectiveEvent::endDate() const 1056QDate EffectiveEvent::endDate() const
1057{ 1057{
1058 if ( d ) 1058 if ( d )
1059 return d->endDate; 1059 return d->endDate;
1060 else if ( mEvent.hasRepeat() ) 1060 else if ( mEvent.hasRepeat() )
1061 return mDate; // single day, since multi-day should have a d pointer 1061 return mDate; // single day, since multi-day should have a d pointer
1062 else 1062 else
1063 return mEvent.end().date(); 1063 return mEvent.end().date();
1064} 1064}
1065 1065
1066/*! 1066/*!
1067 \internal 1067 \internal
1068*/ 1068*/
1069int EffectiveEvent::size() const 1069int EffectiveEvent::size() const
1070{ 1070{
1071 return ( mEnd.hour() - mStart.hour() ) * 3600 1071 return ( mEnd.hour() - mStart.hour() ) * 3600
1072 + (mEnd.minute() - mStart.minute() * 60 1072 + (mEnd.minute() - mStart.minute() * 60
1073 + mEnd.second() - mStart.second() ); 1073 + mEnd.second() - mStart.second() );
1074} 1074}
1075 1075
1076 1076
1077// vcal conversion code 1077// vcal conversion code
1078static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1078static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1079{ 1079{
1080 VObject *ret = 0; 1080 VObject *ret = 0;
1081 if ( o && !value.isEmpty() ) 1081 if ( o && !value.isEmpty() )
1082 ret = addPropValue( o, prop, value.latin1() ); 1082 ret = addPropValue( o, prop, value.latin1() );
1083 return ret; 1083 return ret;
1084} 1084}
1085 1085
1086static inline VObject *safeAddProp( VObject *o, const char *prop) 1086static inline VObject *safeAddProp( VObject *o, const char *prop)
1087{ 1087{
1088 VObject *ret = 0; 1088 VObject *ret = 0;
1089 if ( o ) 1089 if ( o )
1090 ret = addProp( o, prop ); 1090 ret = addProp( o, prop );
1091 return ret; 1091 return ret;
1092} 1092}
1093 1093
1094/* 1094/*
1095 * Until we support vCal/iCal right 1095 * Until we support vCal/iCal right
1096 * we will make DTSTART and other things 1096 * we will make DTSTART and other things
1097 * be floating in the sense of 1097 * be floating in the sense of
1098 * RFC 2445 1098 * RFC 2445
1099 */ 1099 */
1100namespace { 1100namespace {
1101/* 1101/*
1102 * Convert QDateTime to iso8601 but take 1102 * Convert QDateTime to iso8601 but take
1103 * local time and do not use the Z at the end 1103 * local time and do not use the Z at the end
1104 * 1104 *
1105 */ 1105 */
1106 QCString toISOLocal( const QDateTime& dt ) { 1106 QCString toISOLocal( const QDateTime& dt ) {
1107 QCString str; 1107 QCString str;
1108 /* 1108 /*
1109 * year month day T Hour Minute Second 1109 * year month day T Hour Minute Second
1110 * 4 2 2 2 2 2 digits 1110 * 4 2 2 2 2 2 digits
1111 */ 1111 */
1112 str.sprintf("%04d%02d%02dT%02d%02d%02d", 1112 str.sprintf("%04d%02d%02dT%02d%02d%02d",
1113 dt.date().year(), 1113 dt.date().year(),
1114 dt.date().month(), 1114 dt.date().month(),
1115 dt.date().day(), 1115 dt.date().day(),
1116 dt.time().hour(), 1116 dt.time().hour(),
1117 dt.time().minute(), 1117 dt.time().minute(),
1118 dt.time().second() ); 1118 dt.time().second() );
1119 1119
1120 qWarning("Str ist %s", str.data() ); 1120 qWarning("Str ist %s", str.data() );
1121 1121
1122 return str; 1122 return str;
1123 } 1123 }
1124 1124
1125 1125
1126}; 1126};
1127 1127
1128static VObject *createVObject( const Event &e ) 1128static VObject *createVObject( const Event &e )
1129{ 1129{
1130 VObject *vcal = newVObject( VCCalProp ); 1130 VObject *vcal = newVObject( VCCalProp );
1131 safeAddPropValue( vcal, VCVersionProp, "1.0" ); 1131 safeAddPropValue( vcal, VCVersionProp, "1.0" );
1132 VObject *event = safeAddProp( vcal, VCEventProp ); 1132 VObject *event = safeAddProp( vcal, VCEventProp );
1133 1133
1134 safeAddPropValue( event, VCDTstartProp, toISOLocal( e.start() ) ); 1134 safeAddPropValue( event, VCDTstartProp, toISOLocal( e.start() ) );
1135 safeAddPropValue( event, VCDTendProp, toISOLocal( e.end() ) ); 1135 safeAddPropValue( event, VCDTendProp, toISOLocal( e.end() ) );
1136 safeAddPropValue( event, "X-Qtopia-NOTES", e.description() ); 1136 safeAddPropValue( event, "X-Qtopia-NOTES", e.description() );
1137 safeAddPropValue( event, VCDescriptionProp, e.description() ); 1137 safeAddPropValue( event, VCDescriptionProp, e.description() );
1138 safeAddPropValue( event, VCLocationProp, e.location() ); 1138 safeAddPropValue( event, VCLocationProp, e.location() );
1139 1139
1140 if ( e.hasAlarm() ) { 1140 if ( e.hasAlarm() ) {
1141 VObject *alarm = safeAddProp( event, VCAAlarmProp ); 1141 VObject *alarm = safeAddProp( event, VCAAlarmProp );
1142 QDateTime dt = e.start(); 1142 QDateTime dt = e.start();
1143 dt = dt.addSecs( -e.alarmTime()*60 ); 1143 dt = dt.addSecs( -e.alarmTime()*60 );
1144 safeAddPropValue( alarm, VCRunTimeProp, toISOLocal( dt ) ); 1144 safeAddPropValue( alarm, VCRunTimeProp, toISOLocal( dt ) );
1145 safeAddPropValue( alarm, VCAudioContentProp, 1145 safeAddPropValue( alarm, VCAudioContentProp,
1146 (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) ); 1146 (e.alarmSound() == Event::Silent ? "silent" : "alarm" ) );
1147 } 1147 }
1148 1148
1149 safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() ); 1149 safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone() );
1150 1150
1151 if ( e.type() == Event::AllDay ) 1151 if ( e.type() == Event::AllDay )
1152 safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() ); 1152 safeAddPropValue( event, "X-Qtopia-AllDay", e.timeZone() );
1153 1153
1154 // ### repeat missing 1154 // ### repeat missing
1155 1155
1156 // ### categories missing 1156 // ### categories missing
1157 1157
1158 return vcal; 1158 return vcal;
1159} 1159}
1160 1160
1161 1161
1162static Event parseVObject( VObject *obj ) 1162static Event parseVObject( VObject *obj )
1163{ 1163{
1164 Event e; 1164 Event e;
1165 1165
1166 bool haveAlarm = FALSE; 1166 bool haveAlarm = FALSE;
1167 bool haveStart = FALSE; 1167 bool haveStart = FALSE;
1168 bool haveEnd = FALSE; 1168 bool haveEnd = FALSE;
1169 QDateTime alarmTime; 1169 QDateTime alarmTime;
1170 Event::SoundTypeChoice soundType = Event::Silent; 1170 Event::SoundTypeChoice soundType = Event::Silent;
1171 1171
1172 VObjectIterator it; 1172 VObjectIterator it;
1173 initPropIterator( &it, obj ); 1173 initPropIterator( &it, obj );
1174 while( moreIteration( &it ) ) { 1174 while( moreIteration( &it ) ) {
1175 VObject *o = nextVObject( &it ); 1175 VObject *o = nextVObject( &it );
1176 QCString name = vObjectName( o ); 1176 QCString name = vObjectName( o );
1177 QCString value = vObjectStringZValue( o ); 1177 QCString value = vObjectStringZValue( o );
1178 if ( name == VCDTstartProp ) { 1178 if ( name == VCDTstartProp ) {
1179 e.setStart( TimeConversion::fromISO8601( value ) ); 1179 e.setStart( TimeConversion::fromISO8601( value ) );
1180 haveStart = TRUE; 1180 haveStart = TRUE;
1181 } 1181 }
1182 else if ( name == VCDTendProp ) { 1182 else if ( name == VCDTendProp ) {
1183 e.setEnd( TimeConversion::fromISO8601( value ) ); 1183 e.setEnd( TimeConversion::fromISO8601( value ) );
1184 haveEnd = TRUE; 1184 haveEnd = TRUE;
1185 } 1185 }
1186 else if ( name == "X-Qtopia-NOTES" ) { 1186 else if ( name == "X-Qtopia-NOTES" ) {
1187 e.setNotes( value ); 1187 e.setNotes( value );
1188 } 1188 }
1189 else if ( name == VCDescriptionProp ) { 1189 else if ( name == VCDescriptionProp ) {
1190 e.setDescription( value ); 1190 e.setDescription( value );
1191 } 1191 }
1192 else if ( name == VCLocationProp ) { 1192 else if ( name == VCLocationProp ) {
1193 e.setLocation( value ); 1193 e.setLocation( value );
1194 } 1194 }
1195 else if ( name == VCAudioContentProp ) { 1195 else if ( name == VCAudioContentProp ) {
1196 haveAlarm = TRUE; 1196 haveAlarm = TRUE;
1197 VObjectIterator nit; 1197 VObjectIterator nit;
1198 initPropIterator( &nit, o ); 1198 initPropIterator( &nit, o );
1199 while( moreIteration( &nit ) ) { 1199 while( moreIteration( &nit ) ) {
1200 VObject *o = nextVObject( &nit ); 1200 VObject *o = nextVObject( &nit );
1201 QCString name = vObjectName( o ); 1201 QCString name = vObjectName( o );
1202 QCString value = vObjectStringZValue( o ); 1202 QCString value = vObjectStringZValue( o );
1203 if ( name == VCRunTimeProp ) 1203 if ( name == VCRunTimeProp )
1204 alarmTime = TimeConversion::fromISO8601( value ); 1204 alarmTime = TimeConversion::fromISO8601( value );
1205 else if ( name == VCAudioContentProp ) { 1205 else if ( name == VCAudioContentProp ) {
1206 if ( value == "silent" ) 1206 if ( value == "silent" )
1207 soundType = Event::Silent; 1207 soundType = Event::Silent;
1208 else 1208 else
1209 soundType = Event::Loud; 1209 soundType = Event::Loud;
1210 } 1210 }
1211 } 1211 }
1212 } 1212 }
1213 else if ( name == "X-Qtopia-TIMEZONE") { 1213 else if ( name == "X-Qtopia-TIMEZONE") {
1214 e.setTimeZone( value ); 1214 e.setTimeZone( value );
1215 } 1215 }
1216 else if ( name == "X-Qtopia-AllDay" ) { 1216 else if ( name == "X-Qtopia-AllDay" ) {
1217 e.setType( Event::AllDay ); 1217 e.setType( Event::AllDay );
1218 } 1218 }
1219#if 0 1219#if 0
1220 else { 1220 else {
1221 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1221 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1222 VObjectIterator nit; 1222 VObjectIterator nit;
1223 initPropIterator( &nit, o ); 1223 initPropIterator( &nit, o );
1224 while( moreIteration( &nit ) ) { 1224 while( moreIteration( &nit ) ) {
1225 VObject *o = nextVObject( &nit ); 1225 VObject *o = nextVObject( &nit );
1226 QCString name = vObjectName( o ); 1226 QCString name = vObjectName( o );
1227 QString value = vObjectStringZValue( o ); 1227 QString value = vObjectStringZValue( o );
1228 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1228 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1229 } 1229 }
1230 } 1230 }
1231#endif 1231#endif
1232 } 1232 }
1233 1233
1234 if ( !haveStart && !haveEnd ) 1234 if ( !haveStart && !haveEnd )
1235 e.setStart( QDateTime::currentDateTime() ); 1235 e.setStart( QDateTime::currentDateTime() );
1236 1236
1237 if ( !haveEnd ) { 1237 if ( !haveEnd ) {
1238 e.setType( Event::AllDay ); 1238 e.setType( Event::AllDay );
1239 e.setEnd( e.start() ); 1239 e.setEnd( e.start() );
1240 } 1240 }
1241 1241
1242 if ( haveAlarm ) { 1242 if ( haveAlarm ) {
1243 int minutes = alarmTime.secsTo( e.start() ) / 60; 1243 int minutes = alarmTime.secsTo( e.start() ) / 60;
1244 e.setAlarm( TRUE, minutes, soundType ); 1244 e.setAlarm( TRUE, minutes, soundType );
1245 } 1245 }
1246 return e; 1246 return e;
1247} 1247}
1248 1248
1249 1249
1250/*! 1250/*!
1251 Writes the list of \a events as a set of VCards to the file \a filename. 1251 Writes the list of \a events as a set of VCards to the file \a filename.
1252*/ 1252*/
1253void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events) 1253void Event::writeVCalendar( const QString &filename, const QValueList<Event> &events)
1254{ 1254{
1255 1255
1256 QFileDirect f( filename.utf8().data() ); 1256 QFileDirect f( filename.utf8().data() );
1257 1257
1258 if ( !f.open( IO_WriteOnly ) ) { 1258 if ( !f.open( IO_WriteOnly ) ) {
1259 1259
1260 qWarning("Unable to open vcard write"); 1260 qWarning("Unable to open vcard write");
1261 1261
1262 return; 1262 return;
1263 1263
1264 } 1264 }
1265 1265
1266 1266
1267 QValueList<Event>::ConstIterator it; 1267 QValueList<Event>::ConstIterator it;
1268 for( it = events.begin(); it != events.end(); ++it ) { 1268 for( it = events.begin(); it != events.end(); ++it ) {
1269 VObject *obj = createVObject( *it ); 1269 VObject *obj = createVObject( *it );
1270 writeVObject( f.directHandle() , obj ); 1270 writeVObject( f.directHandle() , obj );
1271 cleanVObject( obj ); 1271 cleanVObject( obj );
1272 } 1272 }
1273 1273
1274 1274
1275 cleanStrTbl(); 1275 cleanStrTbl();
1276} 1276}
1277 1277
1278/*! 1278/*!
1279 Writes \a event as a VCard to the file \a filename. 1279 Writes \a event as a VCard to the file \a filename.
1280*/ 1280*/
1281void Event::writeVCalendar( const QString &filename, const Event &event) 1281void Event::writeVCalendar( const QString &filename, const Event &event)
1282{ 1282{
1283 1283
1284 QFileDirect f( filename.utf8().data() ); 1284 QFileDirect f( filename.utf8().data() );
1285 1285
1286 if ( !f.open( IO_WriteOnly ) ) { 1286 if ( !f.open( IO_WriteOnly ) ) {
1287 1287
1288 qWarning("Unable to open vcard write"); 1288 qWarning("Unable to open vcard write");
1289 1289
1290 return; 1290 return;
1291 1291
1292 } 1292 }
1293 1293
1294 1294
1295 VObject *obj = createVObject( event ); 1295 VObject *obj = createVObject( event );
1296 writeVObject( f.directHandle() , obj ); 1296 writeVObject( f.directHandle() , obj );
1297 cleanVObject( obj ); 1297 cleanVObject( obj );
1298 1298
1299 cleanStrTbl(); 1299 cleanStrTbl();
1300} 1300}
1301 1301
1302/*! 1302/*!
1303 Returns the set of events read as VCards from the file \a filename. 1303 Returns the set of events read as VCards from the file \a filename.
1304*/ 1304*/
1305QValueList<Event> Event::readVCalendar( const QString &filename ) 1305QValueList<Event> Event::readVCalendar( const QString &filename )
1306{ 1306{
1307 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1307 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1308 1308
1309 QValueList<Event> events; 1309 QValueList<Event> events;
1310 1310
1311 while ( obj ) { 1311 while ( obj ) {
1312 QCString name = vObjectName( obj ); 1312 QCString name = vObjectName( obj );
1313 if ( name == VCCalProp ) { 1313 if ( name == VCCalProp ) {
1314 VObjectIterator nit; 1314 VObjectIterator nit;
1315 initPropIterator( &nit, obj ); 1315 initPropIterator( &nit, obj );
1316 while( moreIteration( &nit ) ) { 1316 while( moreIteration( &nit ) ) {
1317 VObject *o = nextVObject( &nit ); 1317 VObject *o = nextVObject( &nit );
1318 QCString name = vObjectName( o ); 1318 QCString name = vObjectName( o );
1319 if ( name == VCEventProp ) 1319 if ( name == VCEventProp )
1320 events.append( parseVObject( o ) ); 1320 events.append( parseVObject( o ) );
1321 } 1321 }
1322 } else if ( name == VCEventProp ) { 1322 } else if ( name == VCEventProp ) {
1323 // shouldn't happen, but just to be sure 1323 // shouldn't happen, but just to be sure
1324 events.append( parseVObject( obj ) ); 1324 events.append( parseVObject( obj ) );
1325 } 1325 }
1326 VObject *t = obj; 1326 VObject *t = obj;
1327 obj = nextVObjectInList(obj); 1327 obj = nextVObjectInList(obj);
1328 cleanVObject( t ); 1328 cleanVObject( t );
1329 } 1329 }
1330 1330
1331 return events; 1331 return events;
1332} 1332}
1333 1333
1334bool Event::match( const QRegExp &r ) const 1334bool Event::match( const QRegExp &r ) const
1335{ 1335{
1336 bool returnMe; 1336 bool returnMe;
1337 returnMe = false; 1337 returnMe = false;
1338 1338
1339 if ( descript.find( r ) > -1 ) 1339 if ( descript.find( r ) > -1 )
1340 returnMe = true; 1340 returnMe = true;
1341 else if ( locat.find( r ) > -1 ) 1341 else if ( locat.find( r ) > -1 )
1342 returnMe = true; 1342 returnMe = true;
1343 else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 ) 1343 else if ( TimeConversion::fromUTC( startUTC ).toString().find( r ) > -1 )
1344 returnMe = true; 1344 returnMe = true;
1345 else if ( TimeConversion::fromUTC( endUTC ).toString().find( r ) > -1 ) 1345 else if ( TimeConversion::fromUTC( endUTC ).toString().find( r ) > -1 )
1346 returnMe = true; 1346 returnMe = true;
1347 else if ( tz.find( r ) > -1 ) 1347 else if ( tz.find( r ) > -1 )
1348 returnMe = true; 1348 returnMe = true;
1349 else if ( note.find( r ) > -1 ) 1349 else if ( note.find( r ) > -1 )
1350 returnMe = true; 1350 returnMe = true;
1351 else if ( doRepeat() ) { 1351 else if ( doRepeat() ) {
1352 if ( pattern.hasEndDate ) 1352 if ( pattern.hasEndDate )
1353 if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 ) 1353 if ( TimeConversion::fromUTC( pattern.endDateUTC ).toString().find(r) > -1 )
1354 returnMe = true; 1354 returnMe = true;
1355 } 1355 }
1356 return returnMe; 1356 return returnMe;
1357} 1357}