summaryrefslogtreecommitdiffabout
path: root/libkcal/phoneformat.cpp
authorzautrix <zautrix>2004-08-09 16:25:52 (UTC)
committer zautrix <zautrix>2004-08-09 16:25:52 (UTC)
commitecdcad49975976ff877ff506fae3b14934c01898 (patch) (unidiff)
tree55d79a2b7d90c4c7ce097063449946f2b2504d6a /libkcal/phoneformat.cpp
parentad99dd380750834b3ccc4dd6fdcdd446ca5ba7ee (diff)
downloadkdepimpi-ecdcad49975976ff877ff506fae3b14934c01898.zip
kdepimpi-ecdcad49975976ff877ff506fae3b14934c01898.tar.gz
kdepimpi-ecdcad49975976ff877ff506fae3b14934c01898.tar.bz2
more phone sync
Diffstat (limited to 'libkcal/phoneformat.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp194
1 files changed, 162 insertions, 32 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index b8fed47..e43a507 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -82,3 +82,2 @@ public:
82 int error; 82 int error;
83 QString completedString = "no";
84 for (j=0;j<ToDo->EntriesNum;j++) { 83 for (j=0;j<ToDo->EntriesNum;j++) {
@@ -94,3 +93,2 @@ public:
94 todo->setCompleted( true ); 93 todo->setCompleted( true );
95 completedString = "yes";
96 } 94 }
@@ -184,14 +182,4 @@ public:
184 // csum ***************************************** 182 // csum *****************************************
185 QStringList attList;
186 uint cSum; 183 uint cSum;
187 if ( todo->hasDueDate() ) 184 cSum = PhoneFormat::getCsumTodo( todo );
188 attList << dtToString ( todo->dtDue() );
189 attList << QString::number( id );
190 attList << todo->summary();
191 attList << completedString;
192 attList << QString::number( todo->priority() );
193 attList << alarmString;
194 attList << todo->categoriesStr();
195 attList << todo->secrecyStr();
196 cSum = PhoneFormat::getCsum(attList );
197 todo->setCsum( mProfileName, QString::number( cSum )); 185 todo->setCsum( mProfileName, QString::number( cSum ));
@@ -462,3 +450,2 @@ public:
462 event->setCategories( categoryList ); 450 event->setCategories( categoryList );
463 QString alarmString = "na";
464 // strange 0 semms to mean: alarm enabled 451 // strange 0 semms to mean: alarm enabled
@@ -476,3 +463,2 @@ public:
476 alarm->setStartOffset( -alarmOffset ); 463 alarm->setStartOffset( -alarmOffset );
477 alarmString = QString::number( alarmOffset );
478 } else { 464 } else {
@@ -487,14 +473,5 @@ public:
487 // csum ***************************************** 473 // csum *****************************************
488 QStringList attList; 474
489 uint cSum; 475 uint cSum;
490 attList << dtToString ( event->dtStart() ); 476 cSum = PhoneFormat::getCsumEvent( event );
491 attList << dtToString ( event->dtEnd() );
492 attList << QString::number( id );
493 attList << event->summary();
494 attList << event->location();
495 attList << alarmString;
496 attList << recurString;
497 attList << event->categoriesStr();
498 attList << event->secrecyStr();
499 cSum = PhoneFormat::getCsum(attList );
500 event->setCsum( mProfileName, QString::number( cSum )); 477 event->setCsum( mProfileName, QString::number( cSum ));
@@ -525,3 +502,3 @@ public:
525 502
526 QString dtToString( const QDateTime& dti, bool useTZ = false ) 503 static QString dtToString( const QDateTime& dti, bool useTZ = false )
527 { 504 {
@@ -631,2 +608,133 @@ int PhoneFormat::initDevice(GSM_StateMachine *s)
631} 608}
609ulong PhoneFormat::getCsumTodo( Todo* todo )
610{
611 QStringList attList;
612 if ( todo->hasDueDate() )
613 attList << PhoneParser::dtToString ( todo->dtDue() );
614 attList << todo->summary();
615 QString completedString = "no";
616 if ( todo->isCompleted() )
617 completedString = "yes";
618 attList << completedString;
619 attList << QString::number( todo->priority() );
620 QString alarmString = "na";
621 Alarm *alarm;
622 if ( todo->alarms().count() > 0 ) {
623 alarm = todo->alarms().first();
624 if ( alarm->enabled() ) {
625 alarmString = QString::number(alarm->startOffset().asSeconds() );
626 }
627 }
628 attList << alarmString;
629 attList << todo->categoriesStr();
630 attList << todo->secrecyStr();
631 return PhoneFormat::getCsum(attList );
632
633}
634ulong PhoneFormat::getCsumEvent( Event* event )
635{
636 QStringList attList;
637 attList << PhoneParser::dtToString ( event->dtStart() );
638 attList << PhoneParser::dtToString ( event->dtEnd() );
639 attList << event->summary();
640 attList << event->location();
641 QString alarmString = "na";
642 Alarm *alarm;
643 if ( event->alarms().count() > 0 ) {
644 alarm = event->alarms().first();
645 if ( alarm->enabled() ) {
646 alarmString = QString::number( alarm->startOffset().asSeconds() );
647 }
648 }
649 attList << alarmString;
650 Recurrence* rec = event->recurrence();
651 QStringList list;
652 bool writeEndDate = false;
653 switch ( rec->doesRecur() )
654 {
655 case Recurrence::rDaily: // 0
656 list.append( "0" );
657 list.append( QString::number( rec->frequency() ));//12
658 list.append( "0" );
659 list.append( "0" );
660 writeEndDate = true;
661 break;
662 case Recurrence::rWeekly:// 1
663 list.append( "1" );
664 list.append( QString::number( rec->frequency()) );//12
665 list.append( "0" );
666 {
667 int days = 0;
668 QBitArray weekDays = rec->days();
669 int i;
670 for( i = 1; i <= 7; ++i ) {
671 if ( weekDays[i-1] ) {
672 days += 1 << (i-1);
673 }
674 }
675 list.append( QString::number( days ) );
676 }
677 //pending weekdays
678 writeEndDate = true;
679
680 break;
681 case Recurrence::rMonthlyPos:// 2
682 list.append( "2" );
683 list.append( QString::number( rec->frequency()) );//12
684
685 writeEndDate = true;
686 {
687 int count = 1;
688 QPtrList<Recurrence::rMonthPos> rmp;
689 rmp = rec->monthPositions();
690 if ( rmp.first()->negative )
691 count = 5 - rmp.first()->rPos - 1;
692 else
693 count = rmp.first()->rPos - 1;
694 list.append( QString::number( count ) );
695
696 }
697
698 list.append( "0" );
699 break;
700 case Recurrence::rMonthlyDay:// 3
701 list.append( "3" );
702 list.append( QString::number( rec->frequency()) );//12
703 list.append( "0" );
704 list.append( "0" );
705 writeEndDate = true;
706 break;
707 case Recurrence::rYearlyMonth://4
708 list.append( "4" );
709 list.append( QString::number( rec->frequency()) );//12
710 list.append( "0" );
711 list.append( "0" );
712 writeEndDate = true;
713 break;
714
715 default:
716 list.append( "255" );
717 list.append( QString() );
718 list.append( "0" );
719 list.append( QString() );
720 list.append( "0" );
721 list.append( "20991231T000000" );
722 break;
723 }
724 if ( writeEndDate ) {
725
726 if ( rec->endDate().isValid() ) { // 15 + 16
727 list.append( "1" );
728 list.append( PhoneParser::dtToString( rec->endDate()) );
729 } else {
730 list.append( "0" );
731 list.append( "20991231T000000" );
732 }
733
734 }
735 attList << list.join("");
736 attList << event->categoriesStr();
737 attList << event->secrecyStr();
738 return PhoneFormat::getCsum(attList );
739}
632ulong PhoneFormat::getCsum( const QStringList & attList) 740ulong PhoneFormat::getCsum( const QStringList & attList)
@@ -800,2 +908,13 @@ void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
800} 908}
909void PhoneFormat::afterSave( Incidence* inc)
910{
911 uint csum;
912 if ( inc->type() == "Event")
913 csum = PhoneFormat::getCsumEvent( (Event*) inc );
914 else
915 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
916 inc->setCsum( mProfileName, QString::number( csum ));
917 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
918
919}
801bool PhoneFormat::save( Calendar *calendar) 920bool PhoneFormat::save( Calendar *calendar)
@@ -847,3 +966,3 @@ bool PhoneFormat::save( Calendar *calendar)
847 else { // change existing 966 else { // change existing
848 error = Phone->AddCalendar(&s, &Note); 967 error = Phone->SetCalendar(&s, &Note);
849 } 968 }
@@ -859,6 +978,11 @@ bool PhoneFormat::save( Calendar *calendar)
859 qApp->processEvents(); 978 qApp->processEvents();
860 int newID ;//= pending 979 //int newID ;//= pending
861 ev->setID(mProfileName, QString::number( newID )); 980 //ev->setID(mProfileName, QString::number( newID ));
862 event2GSM( ev, &Note ); 981 event2GSM( ev, &Note );
982 Note.Location = 0;
863 error = Phone->AddCalendar(&s, &Note); 983 error = Phone->AddCalendar(&s, &Note);
984 ev->setID( mProfileName, QString::number( Note.Location ) );
985 afterSave( ev );
986 } else {
987 afterSave( ev ); // setting temp sync stat for changed items
864 } 988 }
@@ -898,6 +1022,12 @@ bool PhoneFormat::save( Calendar *calendar)
898 qApp->processEvents(); 1022 qApp->processEvents();
899 int newID ;//= pending 1023 //int newID ;//= pending
900 to->setID(mProfileName, QString::number( newID )); 1024 //to->setID(mProfileName, QString::number( newID ));
901 todo2GSM( to, &ToDoEntry ); 1025 todo2GSM( to, &ToDoEntry );
1026 ToDoEntry.Location = 0;
902 error=Phone->AddToDo(&s,&ToDoEntry); 1027 error=Phone->AddToDo(&s,&ToDoEntry);
1028 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1029 afterSave( to );
1030 qDebug("New Todo. Location %d ",ToDoEntry.Location );
1031 } else {
1032 afterSave( to );
903 } 1033 }