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
@@ -51,77 +51,75 @@ class PhoneParser : public QObject
51public: 51public:
52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { 52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
53 ; 53 ;
54 } 54 }
55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) 55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
56 { 56 {
57 57
58 int id = ToDo->Location; 58 int id = ToDo->Location;
59 Todo *todo; 59 Todo *todo;
60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); 60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
61 if (todo ) 61 if (todo )
62 todo = (Todo *)todo->clone(); 62 todo = (Todo *)todo->clone();
63 else 63 else
64 todo = new Todo; 64 todo = new Todo;
65 todo->setID( mProfileName,QString::number( id ) ); 65 todo->setID( mProfileName,QString::number( id ) );
66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
67 int priority; 67 int priority;
68 switch (ToDo->Priority) { 68 switch (ToDo->Priority) {
69 case GSM_Priority_Low : priority = 1; break; 69 case GSM_Priority_Low : priority = 1; break;
70 case GSM_Priority_Medium : priority = 3; break; 70 case GSM_Priority_Medium : priority = 3; break;
71 case GSM_Priority_High : priority = 5; break; 71 case GSM_Priority_High : priority = 5; break;
72 default :priority = 3 ;break; 72 default :priority = 3 ;break;
73 } 73 }
74 todo->setPriority( priority ); 74 todo->setPriority( priority );
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;
104 alarmDt = fromGSM ( dtp ); 102 alarmDt = fromGSM ( dtp );
105 break; 103 break;
106 case TODO_SILENT_ALARM_DATETIME: 104 case TODO_SILENT_ALARM_DATETIME:
107 dtp = &ToDo->Entries[j].Date ; 105 dtp = &ToDo->Entries[j].Date ;
108 alarm = true; 106 alarm = true;
109 alarmDt = fromGSM ( dtp ); 107 alarmDt = fromGSM ( dtp );
110 break; 108 break;
111 case TODO_TEXT: 109 case TODO_TEXT:
112 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); 110 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
113 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); 111 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
114 break; 112 break;
115 case TODO_PRIVATE: 113 case TODO_PRIVATE:
116 if ( ToDo->Entries[j].Number == 1 ) 114 if ( ToDo->Entries[j].Number == 1 )
117 todo->setSecrecy( Incidence::SecrecyPrivate ); 115 todo->setSecrecy( Incidence::SecrecyPrivate );
118 else 116 else
119 todo->setSecrecy( Incidence::SecrecyPublic ); 117 todo->setSecrecy( Incidence::SecrecyPublic );
120 break; 118 break;
121 case TODO_CATEGORY: 119 case TODO_CATEGORY:
122 Category.Location = ToDo->Entries[j].Number; 120 Category.Location = ToDo->Entries[j].Number;
123 Category.Type = Category_ToDo; 121 Category.Type = Category_ToDo;
124 error=Phone->GetCategory(s, &Category); 122 error=Phone->GetCategory(s, &Category);
125 if (error == ERR_NONE) { 123 if (error == ERR_NONE) {
126 QStringList cat = todo->categories(); 124 QStringList cat = todo->categories();
127 QString nCat = QString ( (const char*)Category.Name ); 125 QString nCat = QString ( (const char*)Category.Name );
@@ -153,76 +151,66 @@ public:
153 case TODO_PHONE: 151 case TODO_PHONE:
154#if 0 152#if 0
155 // not supported 153 // not supported
156 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 154 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
157#endif 155#endif
158 break; 156 break;
159 } 157 }
160 } 158 }
161 QString alarmString = "na"; 159 QString alarmString = "na";
162 if ( alarm ) { 160 if ( alarm ) {
163 Alarm *alarm; 161 Alarm *alarm;
164 if ( todo->alarms().count() > 0 ) 162 if ( todo->alarms().count() > 0 )
165 alarm = todo->alarms().first(); 163 alarm = todo->alarms().first();
166 else { 164 else {
167 alarm = new Alarm( todo ); 165 alarm = new Alarm( todo );
168 todo->addAlarm( alarm ); 166 todo->addAlarm( alarm );
169 } 167 }
170 alarm->setType( Alarm::Audio ); 168 alarm->setType( Alarm::Audio );
171 alarm->setEnabled( true ); 169 alarm->setEnabled( true );
172 int alarmOffset = alarmDt.secsTo( todo->dtStart() ); 170 int alarmOffset = alarmDt.secsTo( todo->dtStart() );
173 alarm->setStartOffset( -alarmOffset ); 171 alarm->setStartOffset( -alarmOffset );
174 alarmString = QString::number( alarmOffset ); 172 alarmString = QString::number( alarmOffset );
175 } else { 173 } else {
176 Alarm *alarm; 174 Alarm *alarm;
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 {
205 193
206 int id = Note->Location; 194 int id = Note->Location;
207 Event *event; 195 Event *event;
208 event = existingCalendar->event( mProfileName ,QString::number( id ) ); 196 event = existingCalendar->event( mProfileName ,QString::number( id ) );
209 if ( event ) 197 if ( event )
210 event = (Event*)event->clone(); 198 event = (Event*)event->clone();
211 else 199 else
212 event = new Event; 200 event = new Event;
213 event->setID( mProfileName,QString::number( id ) ); 201 event->setID( mProfileName,QString::number( id ) );
214 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 202 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
215 203
216 204
217 int i = 0; 205 int i = 0;
218 bool repeating = false; 206 bool repeating = false;
219 int repeat_dayofweek = -1; 207 int repeat_dayofweek = -1;
220 int repeat_day = -1; 208 int repeat_day = -1;
221 int repeat_weekofmonth = -1; 209 int repeat_weekofmonth = -1;
222 int repeat_month = -1; 210 int repeat_month = -1;
223 int repeat_frequency = -1; 211 int repeat_frequency = -1;
224 int rec_type = -1; 212 int rec_type = -1;
225 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 213 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
226 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 214 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
227 GSM_DateTime* dtp; 215 GSM_DateTime* dtp;
228 bool alarm = false; 216 bool alarm = false;
@@ -431,128 +419,117 @@ public:
431 } else if ( rtype == 1 ) { 419 } else if ( rtype == 1 ) {
432 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 420 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
433 else r->setWeekly( freq, weekDays, -1 ); 421 else r->setWeekly( freq, weekDays, -1 );
434 } else if ( rtype == 3 ) { 422 } else if ( rtype == 3 ) {
435 if ( hasEndDate ) 423 if ( hasEndDate )
436 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 424 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
437 else 425 else
438 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 426 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
439 r->addMonthlyDay( startDate.day() ); 427 r->addMonthlyDay( startDate.day() );
440 } else if ( rtype == 2 ) { 428 } else if ( rtype == 2 ) {
441 if ( hasEndDate ) 429 if ( hasEndDate )
442 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 430 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
443 else 431 else
444 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 432 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
445 QBitArray days( 7 ); 433 QBitArray days( 7 );
446 days.fill( false ); 434 days.fill( false );
447 days.setBit( dayOfWeek - 1 ); 435 days.setBit( dayOfWeek - 1 );
448 r->addMonthlyPos( pos, days ); 436 r->addMonthlyPos( pos, days );
449 } else if ( rtype == 4 ) { 437 } else if ( rtype == 4 ) {
450 if ( hasEndDate ) 438 if ( hasEndDate )
451 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 439 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
452 else 440 else
453 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 441 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
454 r->addYearlyNum( startDate.month() ); 442 r->addYearlyNum( startDate.month() );
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
508 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { 485 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) {
509 QDateTime dt; 486 QDateTime dt;
510 int y,m,t,h,min,sec; 487 int y,m,t,h,min,sec;
511 y = dtp->Year; 488 y = dtp->Year;
512 m = dtp->Month; 489 m = dtp->Month;
513 t = dtp->Day; 490 t = dtp->Day;
514 h = dtp->Hour; 491 h = dtp->Hour;
515 min = dtp->Minute; 492 min = dtp->Minute;
516 sec = dtp->Second; 493 sec = dtp->Second;
517 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 494 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
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
535 dt = dti; 512 dt = dti;
536 if(dt.date().isValid()){ 513 if(dt.date().isValid()){
537 const QDate& date = dt.date(); 514 const QDate& date = dt.date();
538 datestr.sprintf("%04d%02d%02d", 515 datestr.sprintf("%04d%02d%02d",
539 date.year(), date.month(), date.day()); 516 date.year(), date.month(), date.day());
540 } 517 }
541 if(dt.time().isValid()){ 518 if(dt.time().isValid()){
542 const QTime& time = dt.time(); 519 const QTime& time = dt.time();
543 timestr.sprintf("T%02d%02d%02d", 520 timestr.sprintf("T%02d%02d%02d",
544 time.hour(), time.minute(), time.second()); 521 time.hour(), time.minute(), time.second());
545 } 522 }
546 return datestr + timestr; 523 return datestr + timestr;
547 } 524 }
548 QDate datefromGSM ( GSM_DateTime*dtp ) { 525 QDate datefromGSM ( GSM_DateTime*dtp ) {
549 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 526 return QDate ( dtp->Year, dtp->Month, dtp->Day );
550 } 527 }
551 QString getCategory( GSM_CalendarEntry*Note) 528 QString getCategory( GSM_CalendarEntry*Note)
552 { 529 {
553 QString CATEGORY; 530 QString CATEGORY;
554 switch (Note->Type) { 531 switch (Note->Type) {
555 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 532 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
556 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 533 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
557 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 534 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
558 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 535 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
@@ -600,64 +577,195 @@ PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection,
600 mConnection = connection; 577 mConnection = connection;
601 mModel = model; 578 mModel = model;
602} 579}
603 580
604PhoneFormat::~PhoneFormat() 581PhoneFormat::~PhoneFormat()
605{ 582{
606} 583}
607int PhoneFormat::initDevice(GSM_StateMachine *s) 584int PhoneFormat::initDevice(GSM_StateMachine *s)
608{ 585{
609 GSM_ReadConfig(NULL, &s->Config[0], 0); 586 GSM_ReadConfig(NULL, &s->Config[0], 0);
610 s->ConfigNum = 1; 587 s->ConfigNum = 1;
611 GSM_Config *cfg = &s->Config[0]; 588 GSM_Config *cfg = &s->Config[0];
612 if ( ! mConnection.isEmpty() ) { 589 if ( ! mConnection.isEmpty() ) {
613 cfg->Connection = strdup(mConnection.latin1()); 590 cfg->Connection = strdup(mConnection.latin1());
614 cfg->DefaultConnection = false; 591 cfg->DefaultConnection = false;
615 qDebug("Connection set %s ", cfg->Connection ); 592 qDebug("Connection set %s ", cfg->Connection );
616 593
617 } 594 }
618 if ( ! mDevice.isEmpty() ) { 595 if ( ! mDevice.isEmpty() ) {
619 cfg->Device = strdup(mDevice.latin1()); 596 cfg->Device = strdup(mDevice.latin1());
620 cfg->DefaultDevice = false; 597 cfg->DefaultDevice = false;
621 qDebug("Device set %s ", cfg->Device); 598 qDebug("Device set %s ", cfg->Device);
622 599
623 } 600 }
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];
640 if ( ! s.isEmpty() ){ 748 if ( ! s.isEmpty() ){
641 j = s.length(); 749 j = s.length();
642 for ( k = 0; k < j; ++k ) { 750 for ( k = 0; k < j; ++k ) {
643 int mul = k +1; 751 int mul = k +1;
644 add = s[k].unicode (); 752 add = s[k].unicode ();
645 if ( k < 16 ) 753 if ( k < 16 )
646 mul = mul * mul; 754 mul = mul * mul;
647 add = add * mul *i*i*i; 755 add = add * mul *i*i*i;
648 cSum += add; 756 cSum += add;
649 } 757 }
650 } 758 }
651 } 759 }
652 return cSum; 760 return cSum;
653 761
654} 762}
655//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 763//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
656#include <stdlib.h> 764#include <stdlib.h>
657#define DEBUGMODE false 765#define DEBUGMODE false
658bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 766bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
659{ 767{
660 GSM_StateMachines; 768 GSM_StateMachines;
661 qDebug(" load "); 769 qDebug(" load ");
662 s.opened = false; 770 s.opened = false;
663 s.msg = NULL; 771 s.msg = NULL;
@@ -769,166 +877,188 @@ void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
769 list.append( QString() ); 877 list.append( QString() );
770 878
771 if ( todo->isCompleted() ) { 879 if ( todo->isCompleted() ) {
772 list.append( dtToString( todo->completed()) ); 880 list.append( dtToString( todo->completed()) );
773 list.append( "0" ); // yes 0 == completed 881 list.append( "0" ); // yes 0 == completed
774 } else { 882 } else {
775 list.append( dtToString( todo->completed()) ); 883 list.append( dtToString( todo->completed()) );
776 list.append( "1" ); 884 list.append( "1" );
777 } 885 }
778 list.append( QString::number( todo->priority() )); 886 list.append( QString::number( todo->priority() ));
779 if( ! todo->summary().isEmpty() ) 887 if( ! todo->summary().isEmpty() )
780 list.append( todo->summary() ); 888 list.append( todo->summary() );
781 else 889 else
782 list.append( "" ); 890 list.append( "" );
783 if (! todo->description().isEmpty() ) 891 if (! todo->description().isEmpty() )
784 list.append( todo->description() ); 892 list.append( todo->description() );
785 else 893 else
786 list.append( "" ); 894 list.append( "" );
787 for(QStringList::Iterator it=list.begin(); 895 for(QStringList::Iterator it=list.begin();
788 it!=list.end(); ++it){ 896 it!=list.end(); ++it){
789 QString& s = (*it); 897 QString& s = (*it);
790 s.replace(QRegExp("\""), "\"\""); 898 s.replace(QRegExp("\""), "\"\"");
791 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 899 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
792 s.prepend('\"'); 900 s.prepend('\"');
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 );
809 int w = status.sizeHint().width()+20 ; 928 int w = status.sizeHint().width()+20 ;
810 if ( w < 200 ) w = 200; 929 if ( w < 200 ) w = 200;
811 int h = status.sizeHint().height()+20 ; 930 int h = status.sizeHint().height()+20 ;
812 int dw = QApplication::desktop()->width(); 931 int dw = QApplication::desktop()->width();
813 int dh = QApplication::desktop()->height(); 932 int dh = QApplication::desktop()->height();
814 status.setCaption(i18n("Writing DTM Data") ); 933 status.setCaption(i18n("Writing DTM Data") );
815 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 934 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
816 status.show(); 935 status.show();
817 status.raise(); 936 status.raise();
818 qApp->processEvents(); 937 qApp->processEvents();
819 938
820 int error=initDevice(&s); 939 int error=initDevice(&s);
821 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 940 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
822 if ( error != ERR_NONE ) 941 if ( error != ERR_NONE )
823 return false; 942 return false;
824 GSM_Phone_Functions*Phone; 943 GSM_Phone_Functions*Phone;
825 GSM_CalendarEntryNote; 944 GSM_CalendarEntryNote;
826 bool start = true; 945 bool start = true;
827 Phone=s.Phone.Functions; 946 Phone=s.Phone.Functions;
828 bool gshutdown = false; 947 bool gshutdown = false;
829 QPtrList<Event> er = calendar->rawEvents(); 948 QPtrList<Event> er = calendar->rawEvents();
830 Event* ev = er.first(); 949 Event* ev = er.first();
831 QString message = i18n("Processing event # "); 950 QString message = i18n("Processing event # ");
832 int procCount = 0; 951 int procCount = 0;
833 while ( ev ) { 952 while ( ev ) {
834 //qDebug("i %d ", ++i); 953 //qDebug("i %d ", ++i);
835 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one 954 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
836 955
837 status.setText ( message + QString::number ( ++procCount ) ); 956 status.setText ( message + QString::number ( ++procCount ) );
838 qApp->processEvents(); 957 qApp->processEvents();
839 event2GSM( ev, &Note ); 958 event2GSM( ev, &Note );
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
872 message = i18n("Processing todo # "); 996 message = i18n("Processing todo # ");
873 procCount = 0; 997 procCount = 0;
874 while ( to ) { 998 while ( to ) {
875 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 999 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
876 status.setText ( message + QString::number ( ++procCount ) ); 1000 status.setText ( message + QString::number ( ++procCount ) );
877 qApp->processEvents(); 1001 qApp->processEvents();
878 todo2GSM( to, &ToDoEntry ); 1002 todo2GSM( to, &ToDoEntry );
879 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 1003 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
880 error=Phone->DeleteToDo(&s,&ToDoEntry); 1004 error=Phone->DeleteToDo(&s,&ToDoEntry);
881 } 1005 }
882 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 1006 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
883 ; 1007 ;
884 } 1008 }
885 else { // change existing 1009 else { // change existing
886 error=Phone->AddToDo(&s,&ToDoEntry); 1010 error=Phone->AddToDo(&s,&ToDoEntry);
887 } 1011 }
888 } 1012 }
889 to = tl.next(); 1013 to = tl.next();
890 } 1014 }
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{
911 QString datestr; 1041 QString datestr;
912 QString timestr; 1042 QString timestr;
913 int offset = KGlobal::locale()->localTimeOffset( dti ); 1043 int offset = KGlobal::locale()->localTimeOffset( dti );
914 QDateTime dt; 1044 QDateTime dt;
915 if (useTZ) 1045 if (useTZ)
916 dt = dti.addSecs ( -(offset*60)); 1046 dt = dti.addSecs ( -(offset*60));
917 else 1047 else
918 dt = dti; 1048 dt = dti;
919 if(dt.date().isValid()){ 1049 if(dt.date().isValid()){
920 const QDate& date = dt.date(); 1050 const QDate& date = dt.date();
921 datestr.sprintf("%04d%02d%02d", 1051 datestr.sprintf("%04d%02d%02d",
922 date.year(), date.month(), date.day()); 1052 date.year(), date.month(), date.day());
923 } 1053 }
924 if(dt.time().isValid()){ 1054 if(dt.time().isValid()){
925 const QTime& time = dt.time(); 1055 const QTime& time = dt.time();
926 timestr.sprintf("T%02d%02d%02d", 1056 timestr.sprintf("T%02d%02d%02d",
927 time.hour(), time.minute(), time.second()); 1057 time.hour(), time.minute(), time.second());
928 } 1058 }
929 return datestr + timestr; 1059 return datestr + timestr;
930} 1060}
931QString PhoneFormat::getEventString( Event* event ) 1061QString PhoneFormat::getEventString( Event* event )
932{ 1062{
933#if 0 1063#if 0
934 QStringList list; 1064 QStringList list;
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 1472880..7b7dd04 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -18,46 +18,48 @@
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21#ifndef PHONEFORMAT_H 21#ifndef PHONEFORMAT_H
22#define PHONEFORMAT_H 22#define PHONEFORMAT_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25 25
26#include "scheduler.h" 26#include "scheduler.h"
27 27
28#include "calformat.h" 28#include "calformat.h"
29extern "C" { 29extern "C" {
30#include "../gammu/emb/common/gammu.h" 30#include "../gammu/emb/common/gammu.h"
31} 31}
32namespace KCal { 32namespace KCal {
33 33
34/** 34/**
35 This class implements the calendar format used by Phone. 35 This class implements the calendar format used by Phone.
36*/ 36*/
37 class Event; 37 class Event;
38 class Todo; 38 class Todo;
39class PhoneFormat : public QObject { 39class PhoneFormat : public QObject {
40 public: 40 public:
41 /** Create new iCalendar format. */ 41 /** Create new iCalendar format. */
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