summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimevent.cpp263
-rw-r--r--libopie2/opiepim/core/opimevent.h65
2 files changed, 0 insertions, 328 deletions
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 1b553d8..cc84426 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -16,1032 +16,769 @@
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimevent.h" 30#include "opimevent.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecurrence.h> 33#include <opie2/opimrecurrence.h>
34#include <opie2/opimresolver.h> 34#include <opie2/opimresolver.h>
35#include <opie2/opimnotifymanager.h> 35#include <opie2/opimnotifymanager.h>
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37 37
38#include <qpe/categories.h> 38#include <qpe/categories.h>
39#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
40 40
41/* QT */ 41/* QT */
42 42
43namespace Opie 43namespace Opie
44{ 44{
45 45
46int OCalendarHelper::week( const QDate& date ) 46int OCalendarHelper::week( const QDate& date )
47{ 47{
48 // Calculates the week this date is in within that 48 // Calculates the week this date is in within that
49 // month. Equals the "row" is is in in the month view 49 // month. Equals the "row" is is in in the month view
50 int week = 1; 50 int week = 1;
51 QDate tmp( date.year(), date.month(), 1 ); 51 QDate tmp( date.year(), date.month(), 1 );
52 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 52 if ( date.dayOfWeek() < tmp.dayOfWeek() )
53 ++week; 53 ++week;
54 54
55 week += ( date.day() - 1 ) / 7; 55 week += ( date.day() - 1 ) / 7;
56 56
57 return week; 57 return week;
58} 58}
59 59
60 60
61int OCalendarHelper::ocurrence( const QDate& date ) 61int OCalendarHelper::ocurrence( const QDate& date )
62{ 62{
63 // calculates the number of occurrances of this day of the 63 // calculates the number of occurrances of this day of the
64 // week till the given date (e.g 3rd Wednesday of the month) 64 // week till the given date (e.g 3rd Wednesday of the month)
65 return ( date.day() - 1 ) / 7 + 1; 65 return ( date.day() - 1 ) / 7 + 1;
66} 66}
67 67
68 68
69int OCalendarHelper::dayOfWeek( char day ) 69int OCalendarHelper::dayOfWeek( char day )
70{ 70{
71 int dayOfWeek = 1; 71 int dayOfWeek = 1;
72 char i = OPimRecurrence::MON; 72 char i = OPimRecurrence::MON;
73 while ( !( i & day ) && i <= static_cast<char>(OPimRecurrence::SUN) ) 73 while ( !( i & day ) && i <= static_cast<char>(OPimRecurrence::SUN) )
74 { 74 {
75 i <<= 1; 75 i <<= 1;
76 ++dayOfWeek; 76 ++dayOfWeek;
77 } 77 }
78 return dayOfWeek; 78 return dayOfWeek;
79} 79}
80 80
81 81
82int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) 82int OCalendarHelper::monthDiff( const QDate& first, const QDate& second )
83{ 83{
84 return ( second.year() - first.year() ) * 12 + 84 return ( second.year() - first.year() ) * 12 +
85 second.month() - first.month(); 85 second.month() - first.month();
86} 86}
87 87
88 88
89struct OPimEvent::Data : public QShared 89struct OPimEvent::Data : public QShared
90{ 90{
91 Data() : QShared() 91 Data() : QShared()
92 { 92 {
93 child = 0; 93 child = 0;
94 recur = 0; 94 recur = 0;
95 manager = 0; 95 manager = 0;
96 isAllDay = false; 96 isAllDay = false;
97 parent = 0; 97 parent = 0;
98 } 98 }
99 ~Data() 99 ~Data()
100 { 100 {
101 delete manager; 101 delete manager;
102 delete recur; 102 delete recur;
103 } 103 }
104 QString description; 104 QString description;
105 QString location; 105 QString location;
106 OPimNotifyManager* manager; 106 OPimNotifyManager* manager;
107 OPimRecurrence* recur; 107 OPimRecurrence* recur;
108 QString note; 108 QString note;
109 QDateTime created; 109 QDateTime created;
110 QDateTime start; 110 QDateTime start;
111 QDateTime end; 111 QDateTime end;
112bool isAllDay : 1; 112bool isAllDay : 1;
113 QString timezone; 113 QString timezone;
114 QArray<int>* child; 114 QArray<int>* child;
115 int parent; 115 int parent;
116}; 116};
117 117
118 118
119OPimEvent::OPimEvent( int uid ) 119OPimEvent::OPimEvent( int uid )
120 : OPimRecord( uid ) 120 : OPimRecord( uid )
121{ 121{
122 data = new Data; 122 data = new Data;
123} 123}
124 124
125 125
126OPimEvent::OPimEvent( const OPimEvent& ev ) 126OPimEvent::OPimEvent( const OPimEvent& ev )
127 : OPimRecord( ev ), data( ev.data ) 127 : OPimRecord( ev ), data( ev.data )
128{ 128{
129 data->ref(); 129 data->ref();
130} 130}
131 131
132 132
133OPimEvent::OPimEvent( const QMap<int, QString> map ) 133OPimEvent::OPimEvent( const QMap<int, QString> map )
134 : OPimRecord( 0 ) 134 : OPimRecord( 0 )
135{ 135{
136 data = new Data; 136 data = new Data;
137 137
138 fromMap( map ); 138 fromMap( map );
139} 139}
140 140
141 141
142OPimEvent::~OPimEvent() 142OPimEvent::~OPimEvent()
143{ 143{
144 if ( data->deref() ) 144 if ( data->deref() )
145 { 145 {
146 delete data; 146 delete data;
147 data = 0; 147 data = 0;
148 } 148 }
149} 149}
150 150
151 151
152OPimEvent& OPimEvent::operator=( const OPimEvent& ev ) 152OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
153{ 153{
154 if ( this == &ev ) return * this; 154 if ( this == &ev ) return * this;
155 155
156 OPimRecord::operator=( ev ); 156 OPimRecord::operator=( ev );
157 ev.data->ref(); 157 ev.data->ref();
158 deref(); 158 deref();
159 data = ev.data; 159 data = ev.data;
160 160
161 161
162 return *this; 162 return *this;
163} 163}
164 164
165 165
166QString OPimEvent::description() const 166QString OPimEvent::description() const
167{ 167{
168 return data->description; 168 return data->description;
169} 169}
170 170
171 171
172void OPimEvent::setDescription( const QString& description ) 172void OPimEvent::setDescription( const QString& description )
173{ 173{
174 changeOrModify(); 174 changeOrModify();
175 data->description = description; 175 data->description = description;
176} 176}
177 177
178 178
179void OPimEvent::setLocation( const QString& loc ) 179void OPimEvent::setLocation( const QString& loc )
180{ 180{
181 changeOrModify(); 181 changeOrModify();
182 data->location = loc; 182 data->location = loc;
183} 183}
184 184
185 185
186QString OPimEvent::location() const 186QString OPimEvent::location() const
187{ 187{
188 return data->location; 188 return data->location;
189} 189}
190 190
191 191
192OPimNotifyManager &OPimEvent::notifiers() const 192OPimNotifyManager &OPimEvent::notifiers() const
193{ 193{
194 // I hope we can skip the changeOrModify here 194 // I hope we can skip the changeOrModify here
195 // the notifier should take care of it 195 // the notifier should take care of it
196 // and OPimNotify is shared too 196 // and OPimNotify is shared too
197 if ( !data->manager ) 197 if ( !data->manager )
198 data->manager = new OPimNotifyManager; 198 data->manager = new OPimNotifyManager;
199 199
200 return *data->manager; 200 return *data->manager;
201} 201}
202 202
203 203
204bool OPimEvent::hasNotifiers() const 204bool OPimEvent::hasNotifiers() const
205{ 205{
206 if ( !data->manager ) 206 if ( !data->manager )
207 return false; 207 return false;
208 if ( data->manager->reminders().isEmpty() && 208 if ( data->manager->reminders().isEmpty() &&
209 data->manager->alarms().isEmpty() ) 209 data->manager->alarms().isEmpty() )
210 return false; 210 return false;
211 211
212 return true; 212 return true;
213} 213}
214 214
215 215
216OPimRecurrence OPimEvent::recurrence() const 216OPimRecurrence OPimEvent::recurrence() const
217{ 217{
218 if ( !data->recur ) 218 if ( !data->recur )
219 data->recur = new OPimRecurrence; 219 data->recur = new OPimRecurrence;
220 220
221 return *data->recur; 221 return *data->recur;
222} 222}
223 223
224 224
225void OPimEvent::setRecurrence( const OPimRecurrence& rec ) 225void OPimEvent::setRecurrence( const OPimRecurrence& rec )
226{ 226{
227 changeOrModify(); 227 changeOrModify();
228 if ( data->recur ) 228 if ( data->recur )
229 ( *data->recur ) = rec; 229 ( *data->recur ) = rec;
230 else 230 else
231 data->recur = new OPimRecurrence( rec ); 231 data->recur = new OPimRecurrence( rec );
232} 232}
233 233
234 234
235bool OPimEvent::hasRecurrence() const 235bool OPimEvent::hasRecurrence() const
236{ 236{
237 if ( !data->recur ) return false; 237 if ( !data->recur ) return false;
238 return data->recur->doesRecur(); 238 return data->recur->doesRecur();
239} 239}
240 240
241 241
242QString OPimEvent::note() const 242QString OPimEvent::note() const
243{ 243{
244 return data->note; 244 return data->note;
245} 245}
246 246
247 247
248void OPimEvent::setNote( const QString& note ) 248void OPimEvent::setNote( const QString& note )
249{ 249{
250 changeOrModify(); 250 changeOrModify();
251 data->note = note; 251 data->note = note;
252} 252}
253 253
254 254
255QDateTime OPimEvent::createdDateTime() const 255QDateTime OPimEvent::createdDateTime() const
256{ 256{
257 return data->created; 257 return data->created;
258} 258}
259 259
260 260
261void OPimEvent::setCreatedDateTime( const QDateTime& time ) 261void OPimEvent::setCreatedDateTime( const QDateTime& time )
262{ 262{
263 changeOrModify(); 263 changeOrModify();
264 data->created = time; 264 data->created = time;
265} 265}
266 266
267 267
268QDateTime OPimEvent::startDateTime() const 268QDateTime OPimEvent::startDateTime() const
269{ 269{
270 if ( data->isAllDay ) 270 if ( data->isAllDay )
271 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) ); 271 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
272 return data->start; 272 return data->start;
273} 273}
274 274
275 275
276QDateTime OPimEvent::startDateTimeInZone() const 276QDateTime OPimEvent::startDateTimeInZone() const
277{ 277{
278 /* if no timezone, or all day event or if the current and this timeZone match... */ 278 /* if no timezone, or all day event or if the current and this timeZone match... */
279 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime(); 279 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime();
280 280
281 OPimTimeZone zone( data->timezone ); 281 OPimTimeZone zone( data->timezone );
282 return zone.toDateTime( data->start, OPimTimeZone::current() ); 282 return zone.toDateTime( data->start, OPimTimeZone::current() );
283} 283}
284 284
285 285
286void OPimEvent::setStartDateTime( const QDateTime& dt ) 286void OPimEvent::setStartDateTime( const QDateTime& dt )
287{ 287{
288 changeOrModify(); 288 changeOrModify();
289 data->start = dt; 289 data->start = dt;
290} 290}
291 291
292 292
293QDateTime OPimEvent::endDateTime() const 293QDateTime OPimEvent::endDateTime() const
294{ 294{
295 /* 295 /*
296 * if all Day event the end time needs 296 * if all Day event the end time needs
297 * to be on the same day as the start 297 * to be on the same day as the start
298 */ 298 */
299 if ( data->isAllDay ) { 299 if ( data->isAllDay ) {
300 QDate end = data->end.isValid() ? data->end.date() : data->start.date() ; 300 QDate end = data->end.isValid() ? data->end.date() : data->start.date() ;
301 return QDateTime( end, QTime( 23, 59, 59 ) ); 301 return QDateTime( end, QTime( 23, 59, 59 ) );
302 } 302 }
303 return data->end; 303 return data->end;
304} 304}
305 305
306 306
307QDateTime OPimEvent::endDateTimeInZone() const 307QDateTime OPimEvent::endDateTimeInZone() const
308{ 308{
309 /* if no timezone, or all day event or if the current and this timeZone match... */ 309 /* if no timezone, or all day event or if the current and this timeZone match... */
310 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime(); 310 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime();
311 311
312 OPimTimeZone zone( data->timezone ); 312 OPimTimeZone zone( data->timezone );
313 return zone.toDateTime( data->end, OPimTimeZone::current() ); 313 return zone.toDateTime( data->end, OPimTimeZone::current() );
314} 314}
315 315
316 316
317void OPimEvent::setEndDateTime( const QDateTime& dt ) 317void OPimEvent::setEndDateTime( const QDateTime& dt )
318{ 318{
319 changeOrModify(); 319 changeOrModify();
320 data->end = dt; 320 data->end = dt;
321} 321}
322 322
323 323
324bool OPimEvent::isMultipleDay() const 324bool OPimEvent::isMultipleDay() const
325{ 325{
326 return data->end.date().day() - data->start.date().day(); 326 return data->end.date().day() - data->start.date().day();
327} 327}
328 328
329 329
330bool OPimEvent::isAllDay() const 330bool OPimEvent::isAllDay() const
331{ 331{
332 return data->isAllDay; 332 return data->isAllDay;
333} 333}
334 334
335 335
336void OPimEvent::setAllDay( bool allDay ) 336void OPimEvent::setAllDay( bool allDay )
337{ 337{
338 changeOrModify(); 338 changeOrModify();
339 data->isAllDay = allDay; 339 data->isAllDay = allDay;
340} 340}
341 341
342 342
343void OPimEvent::setTimeZone( const QString& tz ) 343void OPimEvent::setTimeZone( const QString& tz )
344{ 344{
345 changeOrModify(); 345 changeOrModify();
346 data->timezone = tz; 346 data->timezone = tz;
347} 347}
348 348
349 349
350QString OPimEvent::timeZone() const 350QString OPimEvent::timeZone() const
351{ 351{
352 if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" ); 352 if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" );
353 return data->timezone; 353 return data->timezone;
354} 354}
355 355
356 356
357bool OPimEvent::match( const QRegExp& re ) const 357bool OPimEvent::match( const QRegExp& re ) const
358{ 358{
359 if ( re.match( data->description ) != -1 ) 359 if ( re.match( data->description ) != -1 )
360 { 360 {
361 setLastHitField( Qtopia::DatebookDescription ); 361 setLastHitField( Qtopia::DatebookDescription );
362 return true; 362 return true;
363 } 363 }
364 if ( re.match( data->note ) != -1 ) 364 if ( re.match( data->note ) != -1 )
365 { 365 {
366 setLastHitField( Qtopia::Note ); 366 setLastHitField( Qtopia::Note );
367 return true; 367 return true;
368 } 368 }
369 if ( re.match( data->location ) != -1 ) 369 if ( re.match( data->location ) != -1 )
370 { 370 {
371 setLastHitField( Qtopia::Location ); 371 setLastHitField( Qtopia::Location );
372 return true; 372 return true;
373 } 373 }
374 if ( re.match( data->start.toString() ) != -1 ) 374 if ( re.match( data->start.toString() ) != -1 )
375 { 375 {
376 setLastHitField( Qtopia::StartDateTime ); 376 setLastHitField( Qtopia::StartDateTime );
377 return true; 377 return true;
378 } 378 }
379 if ( re.match( data->end.toString() ) != -1 ) 379 if ( re.match( data->end.toString() ) != -1 )
380 { 380 {
381 setLastHitField( Qtopia::EndDateTime ); 381 setLastHitField( Qtopia::EndDateTime );
382 return true; 382 return true;
383 } 383 }
384 return false; 384 return false;
385} 385}
386 386
387 387
388QString OPimEvent::toRichText() const 388QString OPimEvent::toRichText() const
389{ 389{
390 QString text, value; 390 QString text, value;
391 391
392 // description 392 // description
393 text += "<b><h3><img src=\"datebook/DateBook\">"; 393 text += "<b><h3><img src=\"datebook/DateBook\">";
394 if ( !description().isEmpty() ) 394 if ( !description().isEmpty() )
395 { 395 {
396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" ); 396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
397 } 397 }
398 text += "</h3></b><br><hr><br>"; 398 text += "</h3></b><br><hr><br>";
399 399
400 // location 400 // location
401 if ( !( value = location() ).isEmpty() ) 401 if ( !( value = location() ).isEmpty() )
402 { 402 {
403 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 403 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
404 text += Qtopia::escapeString( value ) + "<br>"; 404 text += Qtopia::escapeString( value ) + "<br>";
405 } 405 }
406 406
407 // all day event 407 // all day event
408 if ( isAllDay() ) 408 if ( isAllDay() )
409 { 409 {
410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
411 } 411 }
412 // multiple day event 412 // multiple day event
413 else if ( isMultipleDay () ) 413 else if ( isMultipleDay () )
414 { 414 {
415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
416 } 416 }
417 // start & end times 417 // start & end times
418 else 418 else
419 { 419 {
420 // start time 420 // start time
421 if ( startDateTime().isValid() ) 421 if ( startDateTime().isValid() )
422 { 422 {
423 text += "<b>" + QObject::tr( "Start:" ) + "</b> "; 423 text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
424 text += Qtopia::escapeString( startDateTime().toString() ). 424 text += Qtopia::escapeString( startDateTime().toString() ).
425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
426 } 426 }
427 427
428 // end time 428 // end time
429 if ( endDateTime().isValid() ) 429 if ( endDateTime().isValid() )
430 { 430 {
431 text += "<b>" + QObject::tr( "End:" ) + "</b> "; 431 text += "<b>" + QObject::tr( "End:" ) + "</b> ";
432 text += Qtopia::escapeString( endDateTime().toString() ). 432 text += Qtopia::escapeString( endDateTime().toString() ).
433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
434 } 434 }
435 } 435 }
436 436
437 // categories 437 // categories
438 if ( categoryNames( "Calendar" ).count() ) 438 if ( categoryNames( "Calendar" ).count() )
439 { 439 {
440 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 440 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
441 text += categoryNames( "Calendar" ).join( ", " ); 441 text += categoryNames( "Calendar" ).join( ", " );
442 text += "<br>"; 442 text += "<br>";
443 } 443 }
444 444
445 //notes 445 //notes
446 if ( !note().isEmpty() ) 446 if ( !note().isEmpty() )
447 { 447 {
448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>"; 448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
449 text += note(); 449 text += note();
450 // text += Qtopia::escapeString(note() ). 450 // text += Qtopia::escapeString(note() ).
451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
452 } 452 }
453 return text; 453 return text;
454} 454}
455 455
456 456
457QString OPimEvent::toShortText() const 457QString OPimEvent::toShortText() const
458{ 458{
459 QString text; 459 QString text;
460 text += QString::number( startDateTime().date().day() ); 460 text += QString::number( startDateTime().date().day() );
461 text += "."; 461 text += ".";
462 text += QString::number( startDateTime().date().month() ); 462 text += QString::number( startDateTime().date().month() );
463 text += "."; 463 text += ".";
464 text += QString::number( startDateTime().date().year() ); 464 text += QString::number( startDateTime().date().year() );
465 text += " "; 465 text += " ";
466 text += QString::number( startDateTime().time().hour() ); 466 text += QString::number( startDateTime().time().hour() );
467 text += ":"; 467 text += ":";
468 text += QString::number( startDateTime().time().minute() ); 468 text += QString::number( startDateTime().time().minute() );
469 text += " - "; 469 text += " - ";
470 text += description(); 470 text += description();
471 return text; 471 return text;
472} 472}
473 473
474 474
475QString OPimEvent::type() const 475QString OPimEvent::type() const
476{ 476{
477 return QString::fromLatin1( "OPimEvent" ); 477 return QString::fromLatin1( "OPimEvent" );
478} 478}
479 479
480 480
481QString OPimEvent::recordField( int /*id */ ) const 481QString OPimEvent::recordField( int /*id */ ) const
482{ 482{
483 return QString::null; 483 return QString::null;
484} 484}
485 485
486 486
487int OPimEvent::rtti() const 487int OPimEvent::rtti() const
488{ 488{
489 return OPimResolver::DateBook; 489 return OPimResolver::DateBook;
490} 490}
491 491
492/** 492/**
493 * \brief Cast safely to OPimEvent from OPimRecord 493 * \brief Cast safely to OPimEvent from OPimRecord
494 * 494 *
495 * Safely cast from OPimRecord to OPimEvent. If the 495 * Safely cast from OPimRecord to OPimEvent. If the
496 * OPimRecord is not of type OPimEvent Null will be 496 * OPimRecord is not of type OPimEvent Null will be
497 * returned. 497 * returned.
498 * 498 *
499 * @param rec The OPimRecord to be casted to OPimEvent 499 * @param rec The OPimRecord to be casted to OPimEvent
500 * 500 *
501 * @see OPimTodo::safeCast 501 * @see OPimTodo::safeCast
502 * @return OPimEvent or Null Pointer 502 * @return OPimEvent or Null Pointer
503 */ 503 */
504OPimEvent* OPimEvent::safeCast( const OPimRecord* rec) { 504OPimEvent* OPimEvent::safeCast( const OPimRecord* rec) {
505 return ( rec && rec->rtti() == OPimResolver::DateBook ) ? 505 return ( rec && rec->rtti() == OPimResolver::DateBook ) ?
506 static_cast<OPimEvent*>( const_cast<OPimRecord*>(rec) ) : 506 static_cast<OPimEvent*>( const_cast<OPimRecord*>(rec) ) :
507 0l; 507 0l;
508} 508}
509 509
510 510
511 511
512bool OPimEvent::loadFromStream( QDataStream& ) 512bool OPimEvent::loadFromStream( QDataStream& )
513{ 513{
514 return true; 514 return true;
515} 515}
516 516
517 517
518bool OPimEvent::saveToStream( QDataStream& ) const 518bool OPimEvent::saveToStream( QDataStream& ) const
519{ 519{
520 return true; 520 return true;
521} 521}
522 522
523 523
524void OPimEvent::changeOrModify() 524void OPimEvent::changeOrModify()
525{ 525{
526 if ( data->count != 1 ) 526 if ( data->count != 1 )
527 { 527 {
528 data->deref(); 528 data->deref();
529 Data* d2 = new Data; 529 Data* d2 = new Data;
530 d2->description = data->description; 530 d2->description = data->description;
531 d2->location = data->location; 531 d2->location = data->location;
532 532
533 if ( data->manager ) 533 if ( data->manager )
534 d2->manager = new OPimNotifyManager( *data->manager ); 534 d2->manager = new OPimNotifyManager( *data->manager );
535 535
536 if ( data->recur ) 536 if ( data->recur )
537 d2->recur = new OPimRecurrence( *data->recur ); 537 d2->recur = new OPimRecurrence( *data->recur );
538 538
539 d2->note = data->note; 539 d2->note = data->note;
540 d2->created = data->created; 540 d2->created = data->created;
541 d2->start = data->start; 541 d2->start = data->start;
542 d2->end = data->end; 542 d2->end = data->end;
543 d2->isAllDay = data->isAllDay; 543 d2->isAllDay = data->isAllDay;
544 d2->timezone = data->timezone; 544 d2->timezone = data->timezone;
545 d2->parent = data->parent; 545 d2->parent = data->parent;
546 546
547 if ( data->child ) 547 if ( data->child )
548 { 548 {
549 d2->child = new QArray<int>( *data->child ); 549 d2->child = new QArray<int>( *data->child );
550 d2->child->detach(); 550 d2->child->detach();
551 } 551 }
552 552
553 data = d2; 553 data = d2;
554 } 554 }
555} 555}
556 556
557 557
558void OPimEvent::deref() 558void OPimEvent::deref()
559{ 559{
560 if ( data->deref() ) 560 if ( data->deref() )
561 { 561 {
562 delete data; 562 delete data;
563 data = 0; 563 data = 0;
564 } 564 }
565} 565}
566// Exporting Event data to map. Using the same 566// Exporting Event data to map. Using the same
567// encoding as ODateBookAccessBackend_xml does.. 567// encoding as ODateBookAccessBackend_xml does..
568// Thus, we could remove the stuff there and use this 568// Thus, we could remove the stuff there and use this
569// for it and for all other places.. 569// for it and for all other places..
570// Encoding should happen at one place, only ! (eilers) 570// Encoding should happen at one place, only ! (eilers)
571QMap<int, QString> OPimEvent::toMap() const 571QMap<int, QString> OPimEvent::toMap() const
572{ 572{
573 QMap<int, QString> retMap; 573 QMap<int, QString> retMap;
574 574
575 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 575 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
576 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 576 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
577 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 577 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
578 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 578 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
579 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 579 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
580 if ( notifiers().alarms().count() ){ 580 if ( notifiers().alarms().count() ){
581 // Currently we just support one alarm.. (eilers) 581 // Currently we just support one alarm.. (eilers)
582 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 582 OPimAlarm alarm = notifiers().alarms() [ 0 ];
583 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 583 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
584 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 584 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
585 } 585 }
586 586
587 /* either use UTC timeZone or current() if there is was a timezone set */ 587 /* either use UTC timeZone or current() if there is was a timezone set */
588 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); 588 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
589 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime()))); 589 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
590 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() ))); 590 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
591 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 591 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
592 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 592 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
593 if ( parent() ) 593 if ( parent() )
594 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 594 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
595 if ( children().count() ) 595 if ( children().count() )
596 { 596 {
597 QArray<int> childr = children(); 597 QArray<int> childr = children();
598 QString buf; 598 QString buf;
599 for ( uint i = 0; i < childr.count(); i++ ) 599 for ( uint i = 0; i < childr.count(); i++ )
600 { 600 {
601 if ( i != 0 ) buf += " "; 601 if ( i != 0 ) buf += " ";
602 buf += QString::number( childr[ i ] ); 602 buf += QString::number( childr[ i ] );
603 } 603 }
604 retMap.insert( OPimEvent::FRecChildren, buf ); 604 retMap.insert( OPimEvent::FRecChildren, buf );
605 } 605 }
606 606
607 // Add recurrence stuff 607 // Add recurrence stuff
608 if ( hasRecurrence() ) 608 if ( hasRecurrence() )
609 { 609 {
610 OPimRecurrence recur = recurrence(); 610 OPimRecurrence recur = recurrence();
611 QMap<int, QString> recFields = recur.toMap(); 611 QMap<int, QString> recFields = recur.toMap();
612 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 612 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
613 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); 613 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
614 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); 614 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
615 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); 615 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
616 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); 616 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
617 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); 617 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
618 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); 618 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
619 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); 619 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
620 } 620 }
621 else 621 else
622 { 622 {
623 OPimRecurrence recur = recurrence(); 623 OPimRecurrence recur = recurrence();
624 QMap<int, QString> recFields = recur.toMap(); 624 QMap<int, QString> recFields = recur.toMap();
625 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 625 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
626 } 626 }
627 627
628 return retMap; 628 return retMap;
629} 629}
630 630
631 631
632void OPimEvent::fromMap( const QMap<int, QString>& map ) 632void OPimEvent::fromMap( const QMap<int, QString>& map )
633{ 633{
634 634
635 // We just want to set the UID if it is really stored. 635 // We just want to set the UID if it is really stored.
636 if ( !map[ OPimEvent::FUid ].isEmpty() ) 636 if ( !map[ OPimEvent::FUid ].isEmpty() )
637 setUid( map[ OPimEvent::FUid ].toInt() ); 637 setUid( map[ OPimEvent::FUid ].toInt() );
638 638
639 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); 639 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
640 setDescription( map[ OPimEvent::FDescription ] ); 640 setDescription( map[ OPimEvent::FDescription ] );
641 setLocation( map[ OPimEvent::FLocation ] ); 641 setLocation( map[ OPimEvent::FLocation ] );
642 642
643 if ( map[ OPimEvent::FType ] == "AllDay" ) 643 if ( map[ OPimEvent::FType ] == "AllDay" )
644 setAllDay( true ); 644 setAllDay( true );
645 else 645 else
646 setAllDay( false ); 646 setAllDay( false );
647 647
648 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) 648 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
649 { 649 {
650 setTimeZone( map[ OPimEvent::FTimeZone ] ); 650 setTimeZone( map[ OPimEvent::FTimeZone ] );
651 } 651 }
652 652
653 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); 653 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
654 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); 654 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
655 655
656 /* AllDay is always in UTC */ 656 /* AllDay is always in UTC */
657 if ( isAllDay() ) 657 if ( isAllDay() )
658 { 658 {
659 OPimTimeZone utc = OPimTimeZone::utc(); 659 OPimTimeZone utc = OPimTimeZone::utc();
660 setStartDateTime(utc.toDateTime( start ) ); 660 setStartDateTime(utc.toDateTime( start ) );
661 setEndDateTime ( utc.toDateTime( end ) ); 661 setEndDateTime ( utc.toDateTime( end ) );
662 } 662 }
663 else { 663 else {
664 /* to current date time */ 664 /* to current date time */
665 OPimTimeZone to_zone( timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() ); 665 OPimTimeZone to_zone( timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() );
666 666
667 setStartDateTime(to_zone.toDateTime( start)); 667 setStartDateTime(to_zone.toDateTime( start));
668 setEndDateTime (to_zone.toDateTime( end)); 668 setEndDateTime (to_zone.toDateTime( end));
669 } 669 }
670 670
671 int alarmTime = -1; 671 int alarmTime = -1;
672 if ( !map[ OPimEvent::FAlarm ].isEmpty() ) 672 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
673 alarmTime = map[ OPimEvent::FAlarm ].toInt(); 673 alarmTime = map[ OPimEvent::FAlarm ].toInt();
674 674
675 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 675 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
676 if ( ( alarmTime != -1 ) ) 676 if ( ( alarmTime != -1 ) )
677 { 677 {
678 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); 678 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
679 OPimAlarm al( sound , dt ); 679 OPimAlarm al( sound , dt );
680 notifiers().add( al ); 680 notifiers().add( al );
681 } 681 }
682 682
683 683
684 if ( !map[ OPimEvent::FNote ].isEmpty() ) 684 if ( !map[ OPimEvent::FNote ].isEmpty() )
685 setNote( map[ OPimEvent::FNote ] ); 685 setNote( map[ OPimEvent::FNote ] );
686 686
687 if ( !map[ OPimEvent::FRecParent ].isEmpty() ) 687 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
688 setParent( map[ OPimEvent::FRecParent ].toInt() ); 688 setParent( map[ OPimEvent::FRecParent ].toInt() );
689 689
690 if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) 690 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
691 { 691 {
692 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); 692 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
693 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 693 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
694 { 694 {
695 addChild( ( *it ).toInt() ); 695 addChild( ( *it ).toInt() );
696 } 696 }
697 } 697 }
698 698
699 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. 699 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
700 if ( !map[ OPimEvent::FRType ].isEmpty() ) 700 if ( !map[ OPimEvent::FRType ].isEmpty() )
701 { 701 {
702 QMap<int, QString> recFields; 702 QMap<int, QString> recFields;
703 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); 703 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
704 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); 704 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
705 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); 705 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
706 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); 706 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
707 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); 707 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
708 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); 708 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
709 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); 709 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
710 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); 710 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
711 OPimRecurrence recur( recFields ); 711 OPimRecurrence recur( recFields );
712 setRecurrence( recur ); 712 setRecurrence( recur );
713 } 713 }
714 714
715} 715}
716 716
717 717
718int OPimEvent::parent() const 718int OPimEvent::parent() const
719{ 719{
720 return data->parent; 720 return data->parent;
721} 721}
722 722
723 723
724void OPimEvent::setParent( int uid ) 724void OPimEvent::setParent( int uid )
725{ 725{
726 changeOrModify(); 726 changeOrModify();
727 data->parent = uid; 727 data->parent = uid;
728} 728}
729 729
730 730
731QArray<int> OPimEvent::children() const 731QArray<int> OPimEvent::children() const
732{ 732{
733 if ( !data->child ) return QArray<int>(); 733 if ( !data->child ) return QArray<int>();
734 else 734 else
735 return data->child->copy(); 735 return data->child->copy();
736} 736}
737 737
738 738
739void OPimEvent::setChildren( const QArray<int>& arr ) 739void OPimEvent::setChildren( const QArray<int>& arr )
740{ 740{
741 changeOrModify(); 741 changeOrModify();
742 if ( data->child ) delete data->child; 742 if ( data->child ) delete data->child;
743 743
744 data->child = new QArray<int>( arr ); 744 data->child = new QArray<int>( arr );
745 data->child->detach(); 745 data->child->detach();
746} 746}
747 747
748 748
749void OPimEvent::addChild( int uid ) 749void OPimEvent::addChild( int uid )
750{ 750{
751 changeOrModify(); 751 changeOrModify();
752 if ( !data->child ) 752 if ( !data->child )
753 { 753 {
754 data->child = new QArray<int>( 1 ); 754 data->child = new QArray<int>( 1 );
755 ( *data->child ) [ 0 ] = uid; 755 ( *data->child ) [ 0 ] = uid;
756 } 756 }
757 else 757 else
758 { 758 {
759 int count = data->child->count(); 759 int count = data->child->count();
760 data->child->resize( count + 1 ); 760 data->child->resize( count + 1 );
761 ( *data->child ) [ count ] = uid; 761 ( *data->child ) [ count ] = uid;
762 } 762 }
763} 763}
764 764
765 765
766void OPimEvent::removeChild( int uid ) 766void OPimEvent::removeChild( int uid )
767{ 767{
768 if ( !data->child || !data->child->contains( uid ) ) return ; 768 if ( !data->child || !data->child->contains( uid ) ) return ;
769 changeOrModify(); 769 changeOrModify();
770 QArray<int> newAr( data->child->count() - 1 ); 770 QArray<int> newAr( data->child->count() - 1 );
771 int j = 0; 771 int j = 0;
772 uint count = data->child->count(); 772 uint count = data->child->count();
773 for ( uint i = 0; i < count; i++ ) 773 for ( uint i = 0; i < count; i++ )
774 { 774 {
775 if ( ( *data->child ) [ i ] != uid ) 775 if ( ( *data->child ) [ i ] != uid )
776 { 776 {
777 newAr[ j ] = ( *data->child ) [ i ]; 777 newAr[ j ] = ( *data->child ) [ i ];
778 j++; 778 j++;
779 } 779 }
780 } 780 }
781 ( *data->child ) = newAr; 781 ( *data->child ) = newAr;
782} 782}
783 783
784
785struct OEffectiveEvent::Data : public QShared
786{
787 Data() : QShared()
788 {}
789 OPimEvent event;
790 QDate date;
791 QTime start, end;
792 QDate startDate, endDate;
793bool dates : 1;
794};
795
796
797OEffectiveEvent::OEffectiveEvent()
798{
799 data = new Data;
800 data->date = QDate::currentDate();
801 data->start = data->end = QTime::currentTime();
802 data->dates = false;
803}
804
805
806OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate,
807 Position pos )
808{
809 data = new Data;
810 data->event = ev;
811 data->date = startDate;
812 if ( pos & Start )
813 data->start = ev.startDateTime().time();
814 else
815 data->start = QTime( 0, 0, 0 );
816
817 if ( pos & End )
818 data->end = ev.endDateTime().time();
819 else
820 data->end = QTime( 23, 59, 59 );
821
822 data->dates = false;
823}
824
825
826OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev )
827{
828 data = ev.data;
829 data->ref();
830}
831
832
833OEffectiveEvent::~OEffectiveEvent()
834{
835 if ( data->deref() )
836 {
837 delete data;
838 data = 0;
839 }
840}
841
842
843OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev )
844{
845 if ( *this == ev ) return * this;
846
847 ev.data->ref();
848 deref();
849 data = ev.data;
850
851 return *this;
852}
853
854
855void OEffectiveEvent::setStartTime( const QTime& ti )
856{
857 changeOrModify();
858 data->start = ti;
859}
860
861
862void OEffectiveEvent::setEndTime( const QTime& en )
863{
864 changeOrModify();
865 data->end = en;
866}
867
868
869void OEffectiveEvent::setEvent( const OPimEvent& ev )
870{
871 changeOrModify();
872 data->event = ev;
873}
874
875
876void OEffectiveEvent::setDate( const QDate& da )
877{
878 changeOrModify();
879 data->date = da;
880}
881
882
883void OEffectiveEvent::setEffectiveDates( const QDate& from,
884 const QDate& to )
885{
886 if ( !from.isValid() )
887 {
888 data->dates = false;
889 return ;
890 }
891
892 data->startDate = from;
893 data->endDate = to;
894}
895
896
897QString OEffectiveEvent::description() const
898{
899 return data->event.description();
900}
901
902
903QString OEffectiveEvent::location() const
904{
905 return data->event.location();
906}
907
908
909QString OEffectiveEvent::note() const
910{
911 return data->event.note();
912}
913
914
915OPimEvent OEffectiveEvent::event() const
916{
917 return data->event;
918}
919
920
921QTime OEffectiveEvent::startTime() const
922{
923 return data->start;
924}
925
926
927QTime OEffectiveEvent::endTime() const
928{
929 return data->end;
930}
931
932
933QDate OEffectiveEvent::date() const
934{
935 return data->date;
936}
937
938
939int OEffectiveEvent::length() const
940{
941 return ( data->end.hour() * 60 - data->start.hour() * 60 )
942 + QABS( data->start.minute() - data->end.minute() );
943}
944
945
946int OEffectiveEvent::size() const
947{
948 return ( data->end.hour() - data->start.hour() ) * 3600
949 + ( data->end.minute() - data->start.minute() * 60
950 + data->end.second() - data->start.second() );
951}
952
953
954QDate OEffectiveEvent::startDate() const
955{
956 if ( data->dates )
957 return data->startDate;
958 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
959 return data->date;
960 else
961 return data->event.startDateTime().date();
962}
963
964
965QDate OEffectiveEvent::endDate() const
966{
967 if ( data->dates )
968 return data->endDate;
969 else if ( data->event.hasRecurrence() )
970 return data->date;
971 else
972 return data->event.endDateTime().date();
973}
974
975
976void OEffectiveEvent::deref()
977{
978 if ( data->deref() )
979 {
980 delete data;
981 data = 0;
982 }
983}
984
985
986void OEffectiveEvent::changeOrModify()
987{
988 if ( data->count != 1 )
989 {
990 data->deref();
991 Data* d2 = new Data;
992 d2->event = data->event;
993 d2->date = data->date;
994 d2->start = data->start;
995 d2->end = data->end;
996 d2->startDate = data->startDate;
997 d2->endDate = data->endDate;
998 d2->dates = data->dates;
999 data = d2;
1000 }
1001}
1002
1003
1004bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const
1005{
1006 if ( data->date < e.date() )
1007 return TRUE;
1008 if ( data->date == e.date() )
1009 return ( startTime() < e.startTime() );
1010 else
1011 return FALSE;
1012}
1013
1014
1015bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const
1016{
1017 return ( data->date <= e.date() );
1018}
1019
1020
1021bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const
1022{
1023 return ( date() == e.date()
1024 && startTime() == e.startTime()
1025 && endTime() == e.endTime()
1026 && event() == e.event() );
1027}
1028
1029
1030bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const
1031{
1032 return !( *this == e );
1033}
1034
1035
1036bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const
1037{
1038 return !( *this <= e );
1039}
1040
1041
1042bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const
1043{
1044 return !( *this < e );
1045}
1046
1047} 784}
diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h
index 32f648f..1d12530 100644
--- a/libopie2/opiepim/core/opimevent.h
+++ b/libopie2/opiepim/core/opimevent.h
@@ -1,289 +1,224 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de> 3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29// CONTAINS GPLed code of TT 29// CONTAINS GPLed code of TT
30 30
31#ifndef OEVENT_H 31#ifndef OEVENT_H
32#define OEVENT_H 32#define OEVENT_H
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/opimtimezone.h> 35#include <opie2/opimtimezone.h>
36#include <opie2/opimrecord.h> 36#include <opie2/opimrecord.h>
37#include <qpe/recordfields.h> 37#include <qpe/recordfields.h>
38#include <qpe/palmtopuidgen.h> 38#include <qpe/palmtopuidgen.h>
39 39
40/* QT */ 40/* QT */
41#include <qstring.h> 41#include <qstring.h>
42#include <qdatetime.h> 42#include <qdatetime.h>
43#include <qvaluelist.h> 43#include <qvaluelist.h>
44 44
45namespace Opie 45namespace Opie
46{ 46{
47struct OCalendarHelper 47struct OCalendarHelper
48{ 48{
49 /** calculate the week number of the date */ 49 /** calculate the week number of the date */
50 static int week( const QDate& ); 50 static int week( const QDate& );
51 /** calculate the occurence of week days since the start of the month */ 51 /** calculate the occurence of week days since the start of the month */
52 static int ocurrence( const QDate& ); 52 static int ocurrence( const QDate& );
53 53
54 // returns the dayOfWeek for the *first* day it finds (ignores 54 // returns the dayOfWeek for the *first* day it finds (ignores
55 // any further days!). Returns 1 (Monday) if there isn't any day found 55 // any further days!). Returns 1 (Monday) if there isn't any day found
56 static int dayOfWeek( char day ); 56 static int dayOfWeek( char day );
57 57
58 /** returns the diff of month */ 58 /** returns the diff of month */
59 static int monthDiff( const QDate& first, const QDate& second ); 59 static int monthDiff( const QDate& first, const QDate& second );
60 60
61}; 61};
62 62
63class OPimNotifyManager; 63class OPimNotifyManager;
64class OPimRecurrence; 64class OPimRecurrence;
65 65
66/** 66/**
67 * This is the container for all Events. It encapsules all 67 * This is the container for all Events. It encapsules all
68 * available information for a single Event 68 * available information for a single Event
69 * @short container for events. 69 * @short container for events.
70 */ 70 */
71class OPimEvent : public OPimRecord 71class OPimEvent : public OPimRecord
72{ 72{
73 public: 73 public:
74 typedef QValueList<OPimEvent> ValueList; 74 typedef QValueList<OPimEvent> ValueList;
75 /** 75 /**
76 * RecordFields contain possible attributes 76 * RecordFields contain possible attributes
77 * used in the Results of toMap().. 77 * used in the Results of toMap()..
78 */ 78 */
79 enum RecordFields { 79 enum RecordFields {
80 FUid = Qtopia::UID_ID, 80 FUid = Qtopia::UID_ID,
81 FCategories = Qtopia::CATEGORY_ID, 81 FCategories = Qtopia::CATEGORY_ID,
82 FDescription /* = 0 Why this ? (eilers) */, 82 FDescription /* = 0 Why this ? (eilers) */,
83 FLocation, 83 FLocation,
84 FType, 84 FType,
85 FAlarm, 85 FAlarm,
86 FSound, 86 FSound,
87 FRType, 87 FRType,
88 FRWeekdays, 88 FRWeekdays,
89 FRPosition, 89 FRPosition,
90 FRFreq, 90 FRFreq,
91 FRHasEndDate, 91 FRHasEndDate,
92 FREndDate, 92 FREndDate,
93 FRCreated, 93 FRCreated,
94 FRExceptions, 94 FRExceptions,
95 FStart, 95 FStart,
96 FEnd, 96 FEnd,
97 FNote, 97 FNote,
98 FTimeZone, 98 FTimeZone,
99 FRecParent, 99 FRecParent,
100 FRecChildren, 100 FRecChildren,
101 }; 101 };
102 102
103 /** 103 /**
104 * Start with an Empty OPimEvent. UID == 0 means that it is empty 104 * Start with an Empty OPimEvent. UID == 0 means that it is empty
105 */ 105 */
106 OPimEvent( int uid = 0 ); 106 OPimEvent( int uid = 0 );
107 107
108 /** 108 /**
109 * copy c'tor 109 * copy c'tor
110 */ 110 */
111 OPimEvent( const OPimEvent& ); 111 OPimEvent( const OPimEvent& );
112 112
113 /** 113 /**
114 * Create OPimEvent, initialized by map 114 * Create OPimEvent, initialized by map
115 * @see enum RecordFields 115 * @see enum RecordFields
116 */ 116 */
117 OPimEvent( const QMap<int, QString> map ); 117 OPimEvent( const QMap<int, QString> map );
118 ~OPimEvent(); 118 ~OPimEvent();
119 OPimEvent &operator=( const OPimEvent& ); 119 OPimEvent &operator=( const OPimEvent& );
120 120
121 //@{ 121 //@{
122 QString description() const; 122 QString description() const;
123 void setDescription( const QString& description ); 123 void setDescription( const QString& description );
124 124
125 QString location() const; 125 QString location() const;
126 void setLocation( const QString& loc ); 126 void setLocation( const QString& loc );
127 //@} 127 //@}
128 128
129 //@{ 129 //@{
130 bool hasNotifiers() const; 130 bool hasNotifiers() const;
131 OPimNotifyManager &notifiers() const; 131 OPimNotifyManager &notifiers() const;
132 //@} 132 //@}
133 133
134 //@{ 134 //@{
135 OPimRecurrence recurrence() const; 135 OPimRecurrence recurrence() const;
136 void setRecurrence( const OPimRecurrence& ); 136 void setRecurrence( const OPimRecurrence& );
137 bool hasRecurrence() const; 137 bool hasRecurrence() const;
138 //@} 138 //@}
139 139
140 //@{ 140 //@{
141 QString note() const; 141 QString note() const;
142 void setNote( const QString& note ); 142 void setNote( const QString& note );
143 //@} 143 //@}
144 144
145 145
146 QDateTime createdDateTime() const; 146 QDateTime createdDateTime() const;
147 void setCreatedDateTime( const QDateTime& dt ); 147 void setCreatedDateTime( const QDateTime& dt );
148 148
149 /** set the date to dt. dt is the QDateTime in localtime */ 149 /** set the date to dt. dt is the QDateTime in localtime */
150 void setStartDateTime( const QDateTime& ); 150 void setStartDateTime( const QDateTime& );
151 /** returns the datetime in the local timeZone */ 151 /** returns the datetime in the local timeZone */
152 QDateTime startDateTime() const; 152 QDateTime startDateTime() const;
153 153
154 /** returns the start datetime in the current zone */ 154 /** returns the start datetime in the current zone */
155 QDateTime startDateTimeInZone() const; 155 QDateTime startDateTimeInZone() const;
156 156
157 /** in current timezone */ 157 /** in current timezone */
158 void setEndDateTime( const QDateTime& ); 158 void setEndDateTime( const QDateTime& );
159 /** in current timezone */ 159 /** in current timezone */
160 QDateTime endDateTime() const; 160 QDateTime endDateTime() const;
161 QDateTime endDateTimeInZone() const; 161 QDateTime endDateTimeInZone() const;
162 162
163 bool isMultipleDay() const; 163 bool isMultipleDay() const;
164 bool isAllDay() const; 164 bool isAllDay() const;
165 void setAllDay( bool isAllDay ); 165 void setAllDay( bool isAllDay );
166 166
167 /* pin this event to a timezone! FIXME */ 167 /* pin this event to a timezone! FIXME */
168 void setTimeZone( const QString& timeZone ); 168 void setTimeZone( const QString& timeZone );
169 QString timeZone() const; 169 QString timeZone() const;
170 170
171 171
172 //@{ 172 //@{
173 /** For exception to recurrence here is a list of children... */ 173 /** For exception to recurrence here is a list of children... */
174 QArray<int> children() const; 174 QArray<int> children() const;
175 void setChildren( const QArray<int>& ); 175 void setChildren( const QArray<int>& );
176 void addChild( int uid ); 176 void addChild( int uid );
177 void removeChild( int uid ); 177 void removeChild( int uid );
178 //@} 178 //@}
179 179
180 /** return the parent OPimEvent */ 180 /** return the parent OPimEvent */
181 int parent() const; 181 int parent() const;
182 void setParent( int uid ); 182 void setParent( int uid );
183 183
184 184
185 /* needed reimp */ 185 /* needed reimp */
186 //@{ Reimplementations 186 //@{ Reimplementations
187 virtual bool match( const QRegExp& ) const; 187 virtual bool match( const QRegExp& ) const;
188 QString toRichText() const; 188 QString toRichText() const;
189 QString toShortText() const; 189 QString toShortText() const;
190 QString type() const; 190 QString type() const;
191 191
192 QMap<int, QString> toMap() const; 192 QMap<int, QString> toMap() const;
193 void fromMap( const QMap<int, QString>& map ); 193 void fromMap( const QMap<int, QString>& map );
194 QString recordField( int ) const; 194 QString recordField( int ) const;
195 195
196 bool loadFromStream( QDataStream& ); 196 bool loadFromStream( QDataStream& );
197 bool saveToStream( QDataStream& ) const; 197 bool saveToStream( QDataStream& ) const;
198 //@} 198 //@}
199 199
200 //@{ 200 //@{
201 int rtti() const; 201 int rtti() const;
202 static OPimEvent* safeCast( const OPimRecord* ); 202 static OPimEvent* safeCast( const OPimRecord* );
203 //@} 203 //@}
204 204
205 /* bool operator==( const OPimEvent& ); 205 /* bool operator==( const OPimEvent& );
206 bool operator!=( const OPimEvent& ); 206 bool operator!=( const OPimEvent& );
207 bool operator<( const OPimEvent& ); 207 bool operator<( const OPimEvent& );
208 bool operator<=( const OPimEvent& ); 208 bool operator<=( const OPimEvent& );
209 bool operator>( const OPimEvent& ); 209 bool operator>( const OPimEvent& );
210 bool operator>=(const OPimEvent& ); 210 bool operator>=(const OPimEvent& );
211 */ 211 */
212 212
213 private: 213 private:
214 inline void changeOrModify(); 214 inline void changeOrModify();
215 void deref(); 215 void deref();
216 struct Data; 216 struct Data;
217 Data* data; 217 Data* data;
218 class Private; 218 class Private;
219 Private* priv; 219 Private* priv;
220 220
221}; 221};
222
223/**
224 * AN Event can span through multiple days. We split up a multiday eve
225 */
226class OEffectiveEvent
227{
228
229 public:
230 typedef QValueList<OEffectiveEvent> ValueList;
231 enum Position { MidWay, Start, End, StartEnd };
232 // If we calculate the effective event of a multi-day event
233 // we have to figure out whether we are at the first day,
234 // at the end, or anywhere else ("middle"). This is important
235 // for the start/end times (00:00/23:59)
236 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
237 // day event
238 // Start: start time -> 23:59
239 // End: 00:00 -> end time
240 // Start | End == StartEnd: for single-day events (default)
241 // here we draw start time -> end time
242 OEffectiveEvent();
243 OEffectiveEvent( const OPimEvent& event, const QDate& startDate, Position pos = StartEnd );
244 OEffectiveEvent( const OEffectiveEvent& );
245 OEffectiveEvent &operator=( const OEffectiveEvent& );
246 ~OEffectiveEvent();
247
248 void setStartTime( const QTime& );
249 void setEndTime( const QTime& );
250 void setEvent( const OPimEvent& );
251 void setDate( const QDate& );
252
253 void setEffectiveDates( const QDate& from, const QDate& to );
254
255 QString description() const;
256 QString location() const;
257 QString note() const;
258 OPimEvent event() const;
259 QTime startTime() const;
260 QTime endTime() const;
261 QDate date() const;
262
263 /* return the length in hours */
264 int length() const;
265 int size() const;
266
267 QDate startDate() const;
268 QDate endDate() const;
269
270 bool operator<( const OEffectiveEvent &e ) const;
271 bool operator<=( const OEffectiveEvent &e ) const;
272 bool operator==( const OEffectiveEvent &e ) const;
273 bool operator!=( const OEffectiveEvent &e ) const;
274 bool operator>( const OEffectiveEvent &e ) const;
275 bool operator>= ( const OEffectiveEvent &e ) const;
276
277 private:
278 void deref();
279 inline void changeOrModify();
280 class Private;
281 Private* priv;
282 struct Data;
283 Data* data;
284
285};
286
287} 222}
288 223
289#endif 224#endif