summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimevent.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimevent.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimevent.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 8bf8b25..9d46651 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -546,27 +546,30 @@ void OPimEvent::deref()
546// Thus, we could remove the stuff there and use this 546// Thus, we could remove the stuff there and use this
547// for it and for all other places.. 547// for it and for all other places..
548// Encoding should happen at one place, only ! (eilers) 548// Encoding should happen at one place, only ! (eilers)
549QMap<int, QString> OPimEvent::toMap() const 549QMap<int, QString> OPimEvent::toMap() const
550{ 550{
551 QMap<int, QString> retMap; 551 QMap<int, QString> retMap;
552 552
553 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 553 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
554 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 554 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
555 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 555 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
556 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 556 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
557 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 557 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
558 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 558 if ( notifiers().alarms().count() ){
559 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 559 // Currently we just support one alarm.. (eilers)
560 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 560 OPimAlarm alarm = notifiers().alarms() [ 0 ];
561 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
562 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
563 }
561 564
562 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); 565 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
563 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); 566 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) );
564 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); 567 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) );
565 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 568 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
566 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 569 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
567 if ( parent() ) 570 if ( parent() )
568 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 571 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
569 if ( children().count() ) 572 if ( children().count() )
570 { 573 {
571 QArray<int> childr = children(); 574 QArray<int> childr = children();
572 QString buf; 575 QString buf;
@@ -610,35 +613,24 @@ void OPimEvent::fromMap( const QMap<int, QString>& map )
610 if ( !map[ OPimEvent::FUid ].isEmpty() ) 613 if ( !map[ OPimEvent::FUid ].isEmpty() )
611 setUid( map[ OPimEvent::FUid ].toInt() ); 614 setUid( map[ OPimEvent::FUid ].toInt() );
612 615
613 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); 616 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
614 setDescription( map[ OPimEvent::FDescription ] ); 617 setDescription( map[ OPimEvent::FDescription ] );
615 setLocation( map[ OPimEvent::FLocation ] ); 618 setLocation( map[ OPimEvent::FLocation ] );
616 619
617 if ( map[ OPimEvent::FType ] == "AllDay" ) 620 if ( map[ OPimEvent::FType ] == "AllDay" )
618 setAllDay( true ); 621 setAllDay( true );
619 else 622 else
620 setAllDay( false ); 623 setAllDay( false );
621 624
622 int alarmTime = -1;
623 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
624 alarmTime = map[ OPimEvent::FAlarm ].toInt();
625
626 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
627 if ( ( alarmTime != -1 ) )
628 {
629 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
630 OPimAlarm al( sound , dt );
631 notifiers().add( al );
632 }
633 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) 625 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
634 { 626 {
635 setTimeZone( map[ OPimEvent::FTimeZone ] ); 627 setTimeZone( map[ OPimEvent::FTimeZone ] );
636 } 628 }
637 629
638 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); 630 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
639 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); 631 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
640 632
641 /* AllDay is always in UTC */ 633 /* AllDay is always in UTC */
642 if ( isAllDay() ) 634 if ( isAllDay() )
643 { 635 {
644 OPimTimeZone utc = OPimTimeZone::utc(); 636 OPimTimeZone utc = OPimTimeZone::utc();
@@ -650,24 +642,40 @@ void OPimEvent::fromMap( const QMap<int, QString>& map )
650 { 642 {
651 /* to current date time */ 643 /* to current date time */
652 // qWarning(" Start is %d", start ); 644 // qWarning(" Start is %d", start );
653 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); 645 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
654 QDateTime date = zone.toDateTime( start ); 646 QDateTime date = zone.toDateTime( start );
655 qWarning( " Start is %s", date.toString().latin1() ); 647 qWarning( " Start is %s", date.toString().latin1() );
656 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); 648 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
657 649
658 date = zone.toDateTime( end ); 650 date = zone.toDateTime( end );
659 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); 651 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
660 } 652 }
661 653
654 int alarmTime = -1;
655 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
656 alarmTime = map[ OPimEvent::FAlarm ].toInt();
657
658 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
659 if ( ( alarmTime != -1 ) )
660 {
661 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
662 OPimAlarm al( sound , dt );
663 notifiers().add( al );
664 }
665
666
667 if ( !map[ OPimEvent::FNote ].isEmpty() )
668 setNote( map[ OPimEvent::FNote ] );
669
662 if ( !map[ OPimEvent::FRecParent ].isEmpty() ) 670 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
663 setParent( map[ OPimEvent::FRecParent ].toInt() ); 671 setParent( map[ OPimEvent::FRecParent ].toInt() );
664 672
665 if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) 673 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
666 { 674 {
667 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); 675 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
668 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 676 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
669 { 677 {
670 addChild( ( *it ).toInt() ); 678 addChild( ( *it ).toInt() );
671 } 679 }
672 } 680 }
673 681