summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore 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
@@ -75,29 +75,27 @@ public:
75 GSM_Phone_Functions*Phone; 75 GSM_Phone_Functions*Phone;
76 Phone=s->Phone.Functions; 76 Phone=s->Phone.Functions;
77 int j; 77 int j;
78 GSM_DateTime* dtp; 78 GSM_DateTime* dtp;
79 bool alarm = false; 79 bool alarm = false;
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 );
87 switch (ToDo->Entries[j].EntryType) { 86 switch (ToDo->Entries[j].EntryType) {
88 case TODO_END_DATETIME: 87 case TODO_END_DATETIME:
89 dtp = &ToDo->Entries[j].Date ; 88 dtp = &ToDo->Entries[j].Date ;
90 todo->setDtDue (fromGSM ( dtp )); 89 todo->setDtDue (fromGSM ( dtp ));
91 break; 90 break;
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 );
99 } 97 }
100 break; 98 break;
101 case TODO_ALARM_DATETIME: 99 case TODO_ALARM_DATETIME:
102 dtp = &ToDo->Entries[j].Date ; 100 dtp = &ToDo->Entries[j].Date ;
103 alarm = true; 101 alarm = true;
@@ -177,28 +175,18 @@ public:
177 if ( todo->alarms().count() > 0 ) { 175 if ( todo->alarms().count() > 0 ) {
178 alarm = todo->alarms().first(); 176 alarm = todo->alarms().first();
179 alarm->setType( Alarm::Audio ); 177 alarm->setType( Alarm::Audio );
180 alarm->setStartOffset( -60*15 ); 178 alarm->setStartOffset( -60*15 );
181 alarm->setEnabled( false ); 179 alarm->setEnabled( false );
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);
200 188
201 return true; 189 return true;
202 } 190 }
203 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) 191 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note)
204 { 192 {
@@ -455,53 +443,42 @@ public:
455 } 443 }
456 } else { 444 } else {
457 event->recurrence()->unsetRecurs(); 445 event->recurrence()->unsetRecurs();
458 } 446 }
459 447
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;
467 if ( event->alarms().count() > 0 ) 454 if ( event->alarms().count() > 0 )
468 alarm = event->alarms().first(); 455 alarm = event->alarms().first();
469 else { 456 else {
470 alarm = new Alarm( event ); 457 alarm = new Alarm( event );
471 event->addAlarm( alarm ); 458 event->addAlarm( alarm );
472 } 459 }
473 alarm->setType( Alarm::Audio ); 460 alarm->setType( Alarm::Audio );
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 ) {
481 alarm = event->alarms().first(); 467 alarm = event->alarms().first();
482 alarm->setType( Alarm::Audio ); 468 alarm->setType( Alarm::Audio );
483 alarm->setStartOffset( -60*15 ); 469 alarm->setStartOffset( -60*15 );
484 alarm->setEnabled( false ); 470 alarm->setEnabled( false );
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);
503 480
504 return true; 481 return true;
505 } 482 }
506 483
507 484
@@ -518,17 +495,17 @@ public:
518 // dtp->Timezone: offset in hours 495 // dtp->Timezone: offset in hours
519 int offset = KGlobal::locale()->localTimeOffset( dt ); 496 int offset = KGlobal::locale()->localTimeOffset( dt );
520 if ( useTz ) 497 if ( useTz )
521 dt = dt.addSecs ( offset*60); 498 dt = dt.addSecs ( offset*60);
522 return dt; 499 return dt;
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;
530 int offset = KGlobal::locale()->localTimeOffset( dti ); 507 int offset = KGlobal::locale()->localTimeOffset( dti );
531 QDateTime dt; 508 QDateTime dt;
532 if (useTZ) 509 if (useTZ)
533 dt = dti.addSecs ( -(offset*60)); 510 dt = dti.addSecs ( -(offset*60));
534 else 511 else
@@ -624,16 +601,147 @@ int PhoneFormat::initDevice(GSM_StateMachine *s)
624 if ( ! mModel.isEmpty() ) { 601 if ( ! mModel.isEmpty() ) {
625 strcpy(cfg->Model,mModel.latin1() ); 602 strcpy(cfg->Model,mModel.latin1() );
626 cfg->DefaultModel = false; 603 cfg->DefaultModel = false;
627 qDebug("Model set %s ",cfg->Model ); 604 qDebug("Model set %s ",cfg->Model );
628 } 605 }
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;
635 ulong cSum = 0; 743 ulong cSum = 0;
636 int j,k,i; 744 int j,k,i;
637 int add; 745 int add;
638 for ( i = 1; i < max ; ++i ) { 746 for ( i = 1; i < max ; ++i ) {
639 QString s = attList[i]; 747 QString s = attList[i];
@@ -793,16 +901,27 @@ void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
793 s.append('\"'); 901 s.append('\"');
794 } else if(s.isEmpty() && !s.isNull()){ 902 } else if(s.isEmpty() && !s.isNull()){
795 s = "\"\""; 903 s = "\"\"";
796 } 904 }
797 } 905 }
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;
804 qDebug(" save "); 923 qDebug(" save ");
805 s.opened = false; 924 s.opened = false;
806 s.msg = NULL; 925 s.msg = NULL;
807 s.ConfigNum = 0; 926 s.ConfigNum = 0;
808 QLabel status ( i18n("Writing data. Opening device ..."), 0 ); 927 QLabel status ( i18n("Writing data. Opening device ..."), 0 );
@@ -840,32 +959,37 @@ bool PhoneFormat::save( Calendar *calendar)
840 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 959 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
841 error = Phone->DeleteCalendar(&s, &Note); 960 error = Phone->DeleteCalendar(&s, &Note);
842 } 961 }
843 else if ( ev->getID(mProfileName).isEmpty() ) { // add new 962 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
844 // we have to do this later after deleting 963 // we have to do this later after deleting
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();
852 } 971 }
853 ev = er.first(); 972 ev = er.first();
854 // pending get empty slots 973 // pending get empty slots
855 while ( ev ) { 974 while ( ev ) {
856 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 975 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
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();
867 } 991 }
868 GSM_ToDoEntry ToDoEntry; 992 GSM_ToDoEntry ToDoEntry;
869 QPtrList<Todo> tl = calendar->rawTodos(); 993 QPtrList<Todo> tl = calendar->rawTodos();
870 Todo* to = tl.first(); 994 Todo* to = tl.first();
871 995
@@ -891,20 +1015,26 @@ bool PhoneFormat::save( Calendar *calendar)
891 1015
892 // pending get empty slots 1016 // pending get empty slots
893 to = tl.first(); 1017 to = tl.first();
894 while ( to ) { 1018 while ( to ) {
895 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1019 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
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();
906 } 1036 }
907 return true; 1037 return true;
908} 1038}
909QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) 1039QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
910{ 1040{
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 1472880..7b7dd04 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -42,22 +42,24 @@ class PhoneFormat : public QObject {
42 PhoneFormat(QString profileName, QString device,QString connection, QString model); 42 PhoneFormat(QString profileName, QString device,QString connection, QString model);
43 virtual ~PhoneFormat(); 43 virtual ~PhoneFormat();
44 44
45 bool load( Calendar * ,Calendar * ); 45 bool load( Calendar * ,Calendar * );
46 bool save( Calendar * ); 46 bool save( Calendar * );
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 );
54 int initDevice(GSM_StateMachine *s); 55 int initDevice(GSM_StateMachine *s);
55 QString getEventString( Event* ); 56 QString getEventString( Event* );
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}
62 64
63#endif 65#endif