summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp194
-rw-r--r--libkcal/phoneformat.h4
2 files changed, 165 insertions, 33 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index b8fed47..e43a507 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -80,7 +80,6 @@ public:
80 QDateTime alarmDt; 80 QDateTime alarmDt;
81 GSM_Category Category; 81 GSM_Category Category;
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++) {
85 84
86 //qDebug(" for todo %d",ToDo->Location ); 85 //qDebug(" for todo %d",ToDo->Location );
@@ -92,7 +91,6 @@ public:
92 case TODO_COMPLETED: 91 case TODO_COMPLETED:
93 if ( ToDo->Entries[j].Number == 1 ) { 92 if ( ToDo->Entries[j].Number == 1 ) {
94 todo->setCompleted( true ); 93 todo->setCompleted( true );
95 completedString = "yes";
96 } 94 }
97 else { 95 else {
98 todo->setCompleted( false ); 96 todo->setCompleted( false );
@@ -182,18 +180,8 @@ public:
182 } 180 }
183 } 181 }
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 ));
198 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 186 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
199 mCalendar->addTodo( todo); 187 mCalendar->addTodo( todo);
@@ -460,7 +448,6 @@ public:
460 QStringList categoryList; 448 QStringList categoryList;
461 categoryList << getCategory( Note ); 449 categoryList << getCategory( Note );
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
465 if ( alarm ) { 452 if ( alarm ) {
466 Alarm *alarm; 453 Alarm *alarm;
@@ -474,7 +461,6 @@ public:
474 alarm->setEnabled( true ); 461 alarm->setEnabled( true );
475 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 462 int alarmOffset = alarmDt.secsTo( event->dtStart() );
476 alarm->setStartOffset( -alarmOffset ); 463 alarm->setStartOffset( -alarmOffset );
477 alarmString = QString::number( alarmOffset );
478 } else { 464 } else {
479 Alarm *alarm; 465 Alarm *alarm;
480 if ( event->alarms().count() > 0 ) { 466 if ( event->alarms().count() > 0 ) {
@@ -485,18 +471,9 @@ public:
485 } 471 }
486 } 472 }
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 ));
501 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 478 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
502 mCalendar->addEvent( event); 479 mCalendar->addEvent( event);
@@ -523,7 +500,7 @@ public:
523 500
524 } 501 }
525 502
526 QString dtToString( const QDateTime& dti, bool useTZ = false ) 503 static QString dtToString( const QDateTime& dti, bool useTZ = false )
527 { 504 {
528 QString datestr; 505 QString datestr;
529 QString timestr; 506 QString timestr;
@@ -629,6 +606,137 @@ int PhoneFormat::initDevice(GSM_StateMachine *s)
629 int error=GSM_InitConnection(s,3); 606 int error=GSM_InitConnection(s,3);
630 return error; 607 return error;
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)
633{ 741{
634 int max = attList.count() -1; 742 int max = attList.count() -1;
@@ -798,6 +906,17 @@ void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
798 return list.join(","); 906 return list.join(",");
799#endif 907#endif
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)
802{ 921{
803 GSM_StateMachines; 922 GSM_StateMachines;
@@ -845,7 +964,7 @@ bool PhoneFormat::save( Calendar *calendar)
845 964
846 } 965 }
847 else { // change existing 966 else { // change existing
848 error = Phone->AddCalendar(&s, &Note); 967 error = Phone->SetCalendar(&s, &Note);
849 } 968 }
850 } 969 }
851 ev = er.next(); 970 ev = er.next();
@@ -857,10 +976,15 @@ bool PhoneFormat::save( Calendar *calendar)
857 if ( ev->getID(mProfileName).isEmpty() ) { 976 if ( ev->getID(mProfileName).isEmpty() ) {
858 status.setText ( message + QString::number ( ++procCount ) ); 977 status.setText ( message + QString::number ( ++procCount ) );
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 }
865 } 989 }
866 ev = er.next(); 990 ev = er.next();
@@ -896,10 +1020,16 @@ bool PhoneFormat::save( Calendar *calendar)
896 if ( to->getID(mProfileName).isEmpty() ) { 1020 if ( to->getID(mProfileName).isEmpty() ) {
897 status.setText ( message + QString::number ( ++procCount ) ); 1021 status.setText ( message + QString::number ( ++procCount ) );
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 }
904 } 1034 }
905 to = tl.next(); 1035 to = tl.next();
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 1472880..7b7dd04 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -47,7 +47,8 @@ class PhoneFormat : public QObject {
47 bool fromString( Calendar *, const QString & ); 47 bool fromString( Calendar *, const QString & );
48 QString toString( Calendar * ); 48 QString toString( Calendar * );
49 static ulong getCsum( const QStringList & ); 49 static ulong getCsum( const QStringList & );
50 50 static ulong getCsumTodo( Todo* to );
51 static ulong getCsumEvent( Event* ev );
51 private: 52 private:
52 void event2GSM( Event* ev, GSM_CalendarEntry*Note ); 53 void event2GSM( Event* ev, GSM_CalendarEntry*Note );
53 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo ); 54 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
@@ -56,6 +57,7 @@ class PhoneFormat : public QObject {
56 QString getTodoString( Todo* ); 57 QString getTodoString( Todo* );
57 QString dtToGSM( const QDateTime& dt, bool useTZ = true ); 58 QString dtToGSM( const QDateTime& dt, bool useTZ = true );
58 QString mProfileName, mDevice, mConnection, mModel; 59 QString mProfileName, mDevice, mConnection, mModel;
60 void afterSave( Incidence* );
59}; 61};
60 62
61} 63}