summaryrefslogtreecommitdiff
authorchristophe <christophe>2004-07-30 09:50:15 (UTC)
committer christophe <christophe>2004-07-30 09:50:15 (UTC)
commitb099a3dd18571fcbd5b1211f18ac111ec39f9ce8 (patch) (unidiff)
tree2b63e0043a5d535690fa3017f0489ba41bc797af
parent52b1ae9281920cf5a40fe543112d8b00e7699ef6 (diff)
downloadopie-b099a3dd18571fcbd5b1211f18ac111ec39f9ce8.zip
opie-b099a3dd18571fcbd5b1211f18ac111ec39f9ce8.tar.gz
opie-b099a3dd18571fcbd5b1211f18ac111ec39f9ce8.tar.bz2
ev is not required.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimevent.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 739cb6f..c656c3d 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -262,767 +262,767 @@ void 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
493bool OPimEvent::loadFromStream( QDataStream& ) 493bool OPimEvent::loadFromStream( QDataStream& )
494{ 494{
495 return true; 495 return true;
496} 496}
497 497
498 498
499bool OPimEvent::saveToStream( QDataStream& ) const 499bool OPimEvent::saveToStream( QDataStream& ) const
500{ 500{
501 return true; 501 return true;
502} 502}
503 503
504 504
505void OPimEvent::changeOrModify() 505void OPimEvent::changeOrModify()
506{ 506{
507 if ( data->count != 1 ) 507 if ( data->count != 1 )
508 { 508 {
509 data->deref(); 509 data->deref();
510 Data* d2 = new Data; 510 Data* d2 = new Data;
511 d2->description = data->description; 511 d2->description = data->description;
512 d2->location = data->location; 512 d2->location = data->location;
513 513
514 if ( data->manager ) 514 if ( data->manager )
515 d2->manager = new OPimNotifyManager( *data->manager ); 515 d2->manager = new OPimNotifyManager( *data->manager );
516 516
517 if ( data->recur ) 517 if ( data->recur )
518 d2->recur = new OPimRecurrence( *data->recur ); 518 d2->recur = new OPimRecurrence( *data->recur );
519 519
520 d2->note = data->note; 520 d2->note = data->note;
521 d2->created = data->created; 521 d2->created = data->created;
522 d2->start = data->start; 522 d2->start = data->start;
523 d2->end = data->end; 523 d2->end = data->end;
524 d2->isAllDay = data->isAllDay; 524 d2->isAllDay = data->isAllDay;
525 d2->timezone = data->timezone; 525 d2->timezone = data->timezone;
526 d2->parent = data->parent; 526 d2->parent = data->parent;
527 527
528 if ( data->child ) 528 if ( data->child )
529 { 529 {
530 d2->child = new QArray<int>( *data->child ); 530 d2->child = new QArray<int>( *data->child );
531 d2->child->detach(); 531 d2->child->detach();
532 } 532 }
533 533
534 data = d2; 534 data = d2;
535 } 535 }
536} 536}
537 537
538 538
539void OPimEvent::deref() 539void OPimEvent::deref()
540{ 540{
541 if ( data->deref() ) 541 if ( data->deref() )
542 { 542 {
543 delete data; 543 delete data;
544 data = 0; 544 data = 0;
545 } 545 }
546} 546}
547// Exporting Event data to map. Using the same 547// Exporting Event data to map. Using the same
548// encoding as ODateBookAccessBackend_xml does.. 548// encoding as ODateBookAccessBackend_xml does..
549// Thus, we could remove the stuff there and use this 549// Thus, we could remove the stuff there and use this
550// for it and for all other places.. 550// for it and for all other places..
551// Encoding should happen at one place, only ! (eilers) 551// Encoding should happen at one place, only ! (eilers)
552QMap<int, QString> OPimEvent::toMap() const 552QMap<int, QString> OPimEvent::toMap() const
553{ 553{
554 QMap<int, QString> retMap; 554 QMap<int, QString> retMap;
555 555
556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
561 if ( notifiers().alarms().count() ){ 561 if ( notifiers().alarms().count() ){
562 // Currently we just support one alarm.. (eilers) 562 // Currently we just support one alarm.. (eilers)
563 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 563 OPimAlarm alarm = notifiers().alarms() [ 0 ];
564 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 564 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
565 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 565 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
566 } 566 }
567 567
568 /* either use UTC timeZone or current() if there is was a timezone set */ 568 /* either use UTC timeZone or current() if there is was a timezone set */
569 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() ); 569 OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
570 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime()))); 570 retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
571 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() ))); 571 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
572 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 572 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
573 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 573 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
574 if ( parent() ) 574 if ( parent() )
575 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 575 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
576 if ( children().count() ) 576 if ( children().count() )
577 { 577 {
578 QArray<int> childr = children(); 578 QArray<int> childr = children();
579 QString buf; 579 QString buf;
580 for ( uint i = 0; i < childr.count(); i++ ) 580 for ( uint i = 0; i < childr.count(); i++ )
581 { 581 {
582 if ( i != 0 ) buf += " "; 582 if ( i != 0 ) buf += " ";
583 buf += QString::number( childr[ i ] ); 583 buf += QString::number( childr[ i ] );
584 } 584 }
585 retMap.insert( OPimEvent::FRecChildren, buf ); 585 retMap.insert( OPimEvent::FRecChildren, buf );
586 } 586 }
587 587
588 // Add recurrence stuff 588 // Add recurrence stuff
589 if ( hasRecurrence() ) 589 if ( hasRecurrence() )
590 { 590 {
591 OPimRecurrence recur = recurrence(); 591 OPimRecurrence recur = recurrence();
592 QMap<int, QString> recFields = recur.toMap(); 592 QMap<int, QString> recFields = recur.toMap();
593 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 593 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
594 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); 594 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
595 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); 595 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
596 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); 596 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
597 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); 597 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
598 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); 598 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
599 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); 599 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
600 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); 600 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
601 } 601 }
602 else 602 else
603 { 603 {
604 OPimRecurrence recur = recurrence(); 604 OPimRecurrence recur = recurrence();
605 QMap<int, QString> recFields = recur.toMap(); 605 QMap<int, QString> recFields = recur.toMap();
606 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 606 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
607 } 607 }
608 608
609 return retMap; 609 return retMap;
610} 610}
611 611
612 612
613void OPimEvent::fromMap( const QMap<int, QString>& map ) 613void OPimEvent::fromMap( const QMap<int, QString>& map )
614{ 614{
615 615
616 // We just want to set the UID if it is really stored. 616 // We just want to set the UID if it is really stored.
617 if ( !map[ OPimEvent::FUid ].isEmpty() ) 617 if ( !map[ OPimEvent::FUid ].isEmpty() )
618 setUid( map[ OPimEvent::FUid ].toInt() ); 618 setUid( map[ OPimEvent::FUid ].toInt() );
619 619
620 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); 620 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
621 setDescription( map[ OPimEvent::FDescription ] ); 621 setDescription( map[ OPimEvent::FDescription ] );
622 setLocation( map[ OPimEvent::FLocation ] ); 622 setLocation( map[ OPimEvent::FLocation ] );
623 623
624 if ( map[ OPimEvent::FType ] == "AllDay" ) 624 if ( map[ OPimEvent::FType ] == "AllDay" )
625 setAllDay( true ); 625 setAllDay( true );
626 else 626 else
627 setAllDay( false ); 627 setAllDay( false );
628 628
629 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) 629 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
630 { 630 {
631 setTimeZone( map[ OPimEvent::FTimeZone ] ); 631 setTimeZone( map[ OPimEvent::FTimeZone ] );
632 } 632 }
633 633
634 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); 634 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
635 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); 635 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
636 636
637 /* AllDay is always in UTC */ 637 /* AllDay is always in UTC */
638 if ( isAllDay() ) 638 if ( isAllDay() )
639 { 639 {
640 OPimTimeZone utc = OPimTimeZone::utc(); 640 OPimTimeZone utc = OPimTimeZone::utc();
641 setStartDateTime(utc.toDateTime( start ) ); 641 setStartDateTime(utc.toDateTime( start ) );
642 setEndDateTime ( utc.toDateTime( end ) ); 642 setEndDateTime ( utc.toDateTime( end ) );
643 } 643 }
644 else { 644 else {
645 /* to current date time */ 645 /* to current date time */
646 OPimTimeZone to_zone( ev.timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() ); 646 OPimTimeZone to_zone( timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() );
647 647
648 ev.setStartDateTime(to_zone.toDateTime( start)); 648 setStartDateTime(to_zone.toDateTime( start));
649 ev.setEndDateTime (to_zone.toDateTime( end)); 649 setEndDateTime (to_zone.toDateTime( end));
650 } 650 }
651 651
652 int alarmTime = -1; 652 int alarmTime = -1;
653 if ( !map[ OPimEvent::FAlarm ].isEmpty() ) 653 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
654 alarmTime = map[ OPimEvent::FAlarm ].toInt(); 654 alarmTime = map[ OPimEvent::FAlarm ].toInt();
655 655
656 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 656 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
657 if ( ( alarmTime != -1 ) ) 657 if ( ( alarmTime != -1 ) )
658 { 658 {
659 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); 659 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
660 OPimAlarm al( sound , dt ); 660 OPimAlarm al( sound , dt );
661 notifiers().add( al ); 661 notifiers().add( al );
662 } 662 }
663 663
664 664
665 if ( !map[ OPimEvent::FNote ].isEmpty() ) 665 if ( !map[ OPimEvent::FNote ].isEmpty() )
666 setNote( map[ OPimEvent::FNote ] ); 666 setNote( map[ OPimEvent::FNote ] );
667 667
668 if ( !map[ OPimEvent::FRecParent ].isEmpty() ) 668 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
669 setParent( map[ OPimEvent::FRecParent ].toInt() ); 669 setParent( map[ OPimEvent::FRecParent ].toInt() );
670 670
671 if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) 671 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
672 { 672 {
673 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); 673 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
674 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 674 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
675 { 675 {
676 addChild( ( *it ).toInt() ); 676 addChild( ( *it ).toInt() );
677 } 677 }
678 } 678 }
679 679
680 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. 680 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
681 if ( !map[ OPimEvent::FRType ].isEmpty() ) 681 if ( !map[ OPimEvent::FRType ].isEmpty() )
682 { 682 {
683 QMap<int, QString> recFields; 683 QMap<int, QString> recFields;
684 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); 684 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
685 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); 685 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
686 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); 686 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
687 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); 687 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
688 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); 688 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
689 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); 689 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
690 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); 690 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
691 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); 691 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
692 OPimRecurrence recur( recFields ); 692 OPimRecurrence recur( recFields );
693 setRecurrence( recur ); 693 setRecurrence( recur );
694 } 694 }
695 695
696} 696}
697 697
698 698
699int OPimEvent::parent() const 699int OPimEvent::parent() const
700{ 700{
701 return data->parent; 701 return data->parent;
702} 702}
703 703
704 704
705void OPimEvent::setParent( int uid ) 705void OPimEvent::setParent( int uid )
706{ 706{
707 changeOrModify(); 707 changeOrModify();
708 data->parent = uid; 708 data->parent = uid;
709} 709}
710 710
711 711
712QArray<int> OPimEvent::children() const 712QArray<int> OPimEvent::children() const
713{ 713{
714 if ( !data->child ) return QArray<int>(); 714 if ( !data->child ) return QArray<int>();
715 else 715 else
716 return data->child->copy(); 716 return data->child->copy();
717} 717}
718 718
719 719
720void OPimEvent::setChildren( const QArray<int>& arr ) 720void OPimEvent::setChildren( const QArray<int>& arr )
721{ 721{
722 changeOrModify(); 722 changeOrModify();
723 if ( data->child ) delete data->child; 723 if ( data->child ) delete data->child;
724 724
725 data->child = new QArray<int>( arr ); 725 data->child = new QArray<int>( arr );
726 data->child->detach(); 726 data->child->detach();
727} 727}
728 728
729 729
730void OPimEvent::addChild( int uid ) 730void OPimEvent::addChild( int uid )
731{ 731{
732 changeOrModify(); 732 changeOrModify();
733 if ( !data->child ) 733 if ( !data->child )
734 { 734 {
735 data->child = new QArray<int>( 1 ); 735 data->child = new QArray<int>( 1 );
736 ( *data->child ) [ 0 ] = uid; 736 ( *data->child ) [ 0 ] = uid;
737 } 737 }
738 else 738 else
739 { 739 {
740 int count = data->child->count(); 740 int count = data->child->count();
741 data->child->resize( count + 1 ); 741 data->child->resize( count + 1 );
742 ( *data->child ) [ count ] = uid; 742 ( *data->child ) [ count ] = uid;
743 } 743 }
744} 744}
745 745
746 746
747void OPimEvent::removeChild( int uid ) 747void OPimEvent::removeChild( int uid )
748{ 748{
749 if ( !data->child || !data->child->contains( uid ) ) return ; 749 if ( !data->child || !data->child->contains( uid ) ) return ;
750 changeOrModify(); 750 changeOrModify();
751 QArray<int> newAr( data->child->count() - 1 ); 751 QArray<int> newAr( data->child->count() - 1 );
752 int j = 0; 752 int j = 0;
753 uint count = data->child->count(); 753 uint count = data->child->count();
754 for ( uint i = 0; i < count; i++ ) 754 for ( uint i = 0; i < count; i++ )
755 { 755 {
756 if ( ( *data->child ) [ i ] != uid ) 756 if ( ( *data->child ) [ i ] != uid )
757 { 757 {
758 newAr[ j ] = ( *data->child ) [ i ]; 758 newAr[ j ] = ( *data->child ) [ i ];
759 j++; 759 j++;
760 } 760 }
761 } 761 }
762 ( *data->child ) = newAr; 762 ( *data->child ) = newAr;
763} 763}
764 764
765 765
766struct OEffectiveEvent::Data : public QShared 766struct OEffectiveEvent::Data : public QShared
767{ 767{
768 Data() : QShared() 768 Data() : QShared()
769 {} 769 {}
770 OPimEvent event; 770 OPimEvent event;
771 QDate date; 771 QDate date;
772 QTime start, end; 772 QTime start, end;
773 QDate startDate, endDate; 773 QDate startDate, endDate;
774bool dates : 1; 774bool dates : 1;
775}; 775};
776 776
777 777
778OEffectiveEvent::OEffectiveEvent() 778OEffectiveEvent::OEffectiveEvent()
779{ 779{
780 data = new Data; 780 data = new Data;
781 data->date = QDate::currentDate(); 781 data->date = QDate::currentDate();
782 data->start = data->end = QTime::currentTime(); 782 data->start = data->end = QTime::currentTime();
783 data->dates = false; 783 data->dates = false;
784} 784}
785 785
786 786
787OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate, 787OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate,
788 Position pos ) 788 Position pos )
789{ 789{
790 data = new Data; 790 data = new Data;
791 data->event = ev; 791 data->event = ev;
792 data->date = startDate; 792 data->date = startDate;
793 if ( pos & Start ) 793 if ( pos & Start )
794 data->start = ev.startDateTime().time(); 794 data->start = ev.startDateTime().time();
795 else 795 else
796 data->start = QTime( 0, 0, 0 ); 796 data->start = QTime( 0, 0, 0 );
797 797
798 if ( pos & End ) 798 if ( pos & End )
799 data->end = ev.endDateTime().time(); 799 data->end = ev.endDateTime().time();
800 else 800 else
801 data->end = QTime( 23, 59, 59 ); 801 data->end = QTime( 23, 59, 59 );
802 802
803 data->dates = false; 803 data->dates = false;
804} 804}
805 805
806 806
807OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) 807OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev )
808{ 808{
809 data = ev.data; 809 data = ev.data;
810 data->ref(); 810 data->ref();
811} 811}
812 812
813 813
814OEffectiveEvent::~OEffectiveEvent() 814OEffectiveEvent::~OEffectiveEvent()
815{ 815{
816 if ( data->deref() ) 816 if ( data->deref() )
817 { 817 {
818 delete data; 818 delete data;
819 data = 0; 819 data = 0;
820 } 820 }
821} 821}
822 822
823 823
824OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) 824OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev )
825{ 825{
826 if ( *this == ev ) return * this; 826 if ( *this == ev ) return * this;
827 827
828 ev.data->ref(); 828 ev.data->ref();
829 deref(); 829 deref();
830 data = ev.data; 830 data = ev.data;
831 831
832 return *this; 832 return *this;
833} 833}
834 834
835 835
836void OEffectiveEvent::setStartTime( const QTime& ti ) 836void OEffectiveEvent::setStartTime( const QTime& ti )
837{ 837{
838 changeOrModify(); 838 changeOrModify();
839 data->start = ti; 839 data->start = ti;
840} 840}
841 841
842 842
843void OEffectiveEvent::setEndTime( const QTime& en ) 843void OEffectiveEvent::setEndTime( const QTime& en )
844{ 844{
845 changeOrModify(); 845 changeOrModify();
846 data->end = en; 846 data->end = en;
847} 847}
848 848
849 849
850void OEffectiveEvent::setEvent( const OPimEvent& ev ) 850void OEffectiveEvent::setEvent( const OPimEvent& ev )
851{ 851{
852 changeOrModify(); 852 changeOrModify();
853 data->event = ev; 853 data->event = ev;
854} 854}
855 855
856 856
857void OEffectiveEvent::setDate( const QDate& da ) 857void OEffectiveEvent::setDate( const QDate& da )
858{ 858{
859 changeOrModify(); 859 changeOrModify();
860 data->date = da; 860 data->date = da;
861} 861}
862 862
863 863
864void OEffectiveEvent::setEffectiveDates( const QDate& from, 864void OEffectiveEvent::setEffectiveDates( const QDate& from,
865 const QDate& to ) 865 const QDate& to )
866{ 866{
867 if ( !from.isValid() ) 867 if ( !from.isValid() )
868 { 868 {
869 data->dates = false; 869 data->dates = false;
870 return ; 870 return ;
871 } 871 }
872 872
873 data->startDate = from; 873 data->startDate = from;
874 data->endDate = to; 874 data->endDate = to;
875} 875}
876 876
877 877
878QString OEffectiveEvent::description() const 878QString OEffectiveEvent::description() const
879{ 879{
880 return data->event.description(); 880 return data->event.description();
881} 881}
882 882
883 883
884QString OEffectiveEvent::location() const 884QString OEffectiveEvent::location() const
885{ 885{
886 return data->event.location(); 886 return data->event.location();
887} 887}
888 888
889 889
890QString OEffectiveEvent::note() const 890QString OEffectiveEvent::note() const
891{ 891{
892 return data->event.note(); 892 return data->event.note();
893} 893}
894 894
895 895
896OPimEvent OEffectiveEvent::event() const 896OPimEvent OEffectiveEvent::event() const
897{ 897{
898 return data->event; 898 return data->event;
899} 899}
900 900
901 901
902QTime OEffectiveEvent::startTime() const 902QTime OEffectiveEvent::startTime() const
903{ 903{
904 return data->start; 904 return data->start;
905} 905}
906 906
907 907
908QTime OEffectiveEvent::endTime() const 908QTime OEffectiveEvent::endTime() const
909{ 909{
910 return data->end; 910 return data->end;
911} 911}
912 912
913 913
914QDate OEffectiveEvent::date() const 914QDate OEffectiveEvent::date() const
915{ 915{
916 return data->date; 916 return data->date;
917} 917}
918 918
919 919
920int OEffectiveEvent::length() const 920int OEffectiveEvent::length() const
921{ 921{
922 return ( data->end.hour() * 60 - data->start.hour() * 60 ) 922 return ( data->end.hour() * 60 - data->start.hour() * 60 )
923 + QABS( data->start.minute() - data->end.minute() ); 923 + QABS( data->start.minute() - data->end.minute() );
924} 924}
925 925
926 926
927int OEffectiveEvent::size() const 927int OEffectiveEvent::size() const
928{ 928{
929 return ( data->end.hour() - data->start.hour() ) * 3600 929 return ( data->end.hour() - data->start.hour() ) * 3600
930 + ( data->end.minute() - data->start.minute() * 60 930 + ( data->end.minute() - data->start.minute() * 60
931 + data->end.second() - data->start.second() ); 931 + data->end.second() - data->start.second() );
932} 932}
933 933
934 934
935QDate OEffectiveEvent::startDate() const 935QDate OEffectiveEvent::startDate() const
936{ 936{
937 if ( data->dates ) 937 if ( data->dates )
938 return data->startDate; 938 return data->startDate;
939 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 939 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
940 return data->date; 940 return data->date;
941 else 941 else
942 return data->event.startDateTime().date(); 942 return data->event.startDateTime().date();
943} 943}
944 944
945 945
946QDate OEffectiveEvent::endDate() const 946QDate OEffectiveEvent::endDate() const
947{ 947{
948 if ( data->dates ) 948 if ( data->dates )
949 return data->endDate; 949 return data->endDate;
950 else if ( data->event.hasRecurrence() ) 950 else if ( data->event.hasRecurrence() )
951 return data->date; 951 return data->date;
952 else 952 else
953 return data->event.endDateTime().date(); 953 return data->event.endDateTime().date();
954} 954}
955 955
956 956
957void OEffectiveEvent::deref() 957void OEffectiveEvent::deref()
958{ 958{
959 if ( data->deref() ) 959 if ( data->deref() )
960 { 960 {
961 delete data; 961 delete data;
962 data = 0; 962 data = 0;
963 } 963 }
964} 964}
965 965
966 966
967void OEffectiveEvent::changeOrModify() 967void OEffectiveEvent::changeOrModify()
968{ 968{
969 if ( data->count != 1 ) 969 if ( data->count != 1 )
970 { 970 {
971 data->deref(); 971 data->deref();
972 Data* d2 = new Data; 972 Data* d2 = new Data;
973 d2->event = data->event; 973 d2->event = data->event;
974 d2->date = data->date; 974 d2->date = data->date;
975 d2->start = data->start; 975 d2->start = data->start;
976 d2->end = data->end; 976 d2->end = data->end;
977 d2->startDate = data->startDate; 977 d2->startDate = data->startDate;
978 d2->endDate = data->endDate; 978 d2->endDate = data->endDate;
979 d2->dates = data->dates; 979 d2->dates = data->dates;
980 data = d2; 980 data = d2;
981 } 981 }
982} 982}
983 983
984 984
985bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const 985bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const
986{ 986{
987 if ( data->date < e.date() ) 987 if ( data->date < e.date() )
988 return TRUE; 988 return TRUE;
989 if ( data->date == e.date() ) 989 if ( data->date == e.date() )
990 return ( startTime() < e.startTime() ); 990 return ( startTime() < e.startTime() );
991 else 991 else
992 return FALSE; 992 return FALSE;
993} 993}
994 994
995 995
996bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const 996bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const
997{ 997{
998 return ( data->date <= e.date() ); 998 return ( data->date <= e.date() );
999} 999}
1000 1000
1001 1001
1002bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const 1002bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const
1003{ 1003{
1004 return ( date() == e.date() 1004 return ( date() == e.date()
1005 && startTime() == e.startTime() 1005 && startTime() == e.startTime()
1006 && endTime() == e.endTime() 1006 && endTime() == e.endTime()
1007 && event() == e.event() ); 1007 && event() == e.event() );
1008} 1008}
1009 1009
1010 1010
1011bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const 1011bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const
1012{ 1012{
1013 return !( *this == e ); 1013 return !( *this == e );
1014} 1014}
1015 1015
1016 1016
1017bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const 1017bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const
1018{ 1018{
1019 return !( *this <= e ); 1019 return !( *this <= e );
1020} 1020}
1021 1021
1022 1022
1023bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const 1023bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const
1024{ 1024{
1025 return !( *this < e ); 1025 return !( *this < e );
1026} 1026}
1027 1027
1028} 1028}