summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-08-20 04:28:28 (UTC)
committer zautrix <zautrix>2004-08-20 04:28:28 (UTC)
commit93decd4185adc7197008e8397cf753a5ab674d99 (patch) (unidiff)
tree0d701d0a687c22cfe2894121f8540d60a5fbe7a9 /libkcal
parentf7a401f03c18ef96eb40dc5540b31cd10880e845 (diff)
downloadkdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.zip
kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.tar.gz
kdepimpi-93decd4185adc7197008e8397cf753a5ab674d99.tar.bz2
Bugfixes for syncing
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp336
-rw-r--r--libkcal/sharpformat.cpp2
-rw-r--r--libkcal/vcalformat.cpp71
3 files changed, 323 insertions, 86 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 6bbc0a3..6276498 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -390,193 +390,193 @@ public:
390 */ 390 */
391 int dayOfWeek = startDate.dayOfWeek(); 391 int dayOfWeek = startDate.dayOfWeek();
392 if ( repeat_weekofmonth >= 0 ) { 392 if ( repeat_weekofmonth >= 0 ) {
393 rtype = 2; // ************************ 2 MonthlyPos 393 rtype = 2; // ************************ 2 MonthlyPos
394 pos = repeat_weekofmonth; 394 pos = repeat_weekofmonth;
395 if ( repeat_dayofweek >= 0 ) 395 if ( repeat_dayofweek >= 0 )
396 dayOfWeek = repeat_dayofweek; 396 dayOfWeek = repeat_dayofweek;
397 if (repeat_month > 0) { 397 if (repeat_month > 0) {
398 if ( repeat_month != event->dtStart().date().month() ) { 398 if ( repeat_month != event->dtStart().date().month() ) {
399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); 399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() );
400 event->setDtStart(QDateTime ( date , event->dtStart().time()) ); 400 event->setDtStart(QDateTime ( date , event->dtStart().time()) );
401 } 401 }
402 if ( freq == 1 ) 402 if ( freq == 1 )
403 freq = 12; 403 freq = 12;
404 } 404 }
405 } else if ( repeat_dayofweek >= 0 ) { 405 } else if ( repeat_dayofweek >= 0 ) {
406 rtype = 1;// ************************ 1 Weekly 406 rtype = 1;// ************************ 1 Weekly
407 } else if ( repeat_day >= 0 ) { 407 } else if ( repeat_day >= 0 ) {
408 if ( repeat_month > 0) { 408 if ( repeat_month > 0) {
409 rtype = 4; 409 rtype = 4;
410 } else { 410 } else {
411 rtype = 3; 411 rtype = 3;
412 } 412 }
413 } else { 413 } else {
414 rtype = 0 ; 414 rtype = 0 ;
415 } 415 }
416 416
417 if ( rtype == 0 ) { 417 if ( rtype == 0 ) {
418 if ( hasEndDate ) r->setDaily( freq, endDate ); 418 if ( hasEndDate ) r->setDaily( freq, endDate );
419 else r->setDaily( freq, -1 ); 419 else r->setDaily( freq, -1 );
420 } else if ( rtype == 1 ) { 420 } else if ( rtype == 1 ) {
421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
422 else r->setWeekly( freq, weekDays, -1 ); 422 else r->setWeekly( freq, weekDays, -1 );
423 } else if ( rtype == 3 ) { 423 } else if ( rtype == 3 ) {
424 if ( hasEndDate ) 424 if ( hasEndDate )
425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
426 else 426 else
427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
428 r->addMonthlyDay( startDate.day() ); 428 r->addMonthlyDay( startDate.day() );
429 } else if ( rtype == 2 ) { 429 } else if ( rtype == 2 ) {
430 if ( hasEndDate ) 430 if ( hasEndDate )
431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
432 else 432 else
433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
434 QBitArray days( 7 ); 434 QBitArray days( 7 );
435 days.fill( false ); 435 days.fill( false );
436 days.setBit( dayOfWeek - 1 ); 436 days.setBit( dayOfWeek - 1 );
437 r->addMonthlyPos( pos, days ); 437 r->addMonthlyPos( pos, days );
438 } else if ( rtype == 4 ) { 438 } else if ( rtype == 4 ) {
439 if ( hasEndDate ) 439 if ( hasEndDate )
440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
441 else 441 else
442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
443 r->addYearlyNum( startDate.month() ); 443 r->addYearlyNum( startDate.month() );
444 } 444 }
445 } else { 445 } else {
446 event->recurrence()->unsetRecurs(); 446 event->recurrence()->unsetRecurs();
447 } 447 }
448 448
449 QStringList categoryList; 449 QStringList categoryList;
450 categoryList << getCategory( Note ); 450 categoryList << getCategory( Note );
451 event->setCategories( categoryList ); 451 event->setCategories( categoryList );
452 // strange 0 semms to mean: alarm enabled 452 // strange 0 semms to mean: alarm enabled
453 if ( alarm ) { 453 if ( alarm ) {
454 Alarm *alarm; 454 Alarm *alarm;
455 if ( event->alarms().count() > 0 ) 455 if ( event->alarms().count() > 0 )
456 alarm = event->alarms().first(); 456 alarm = event->alarms().first();
457 else { 457 else {
458 alarm = new Alarm( event ); 458 alarm = new Alarm( event );
459 event->addAlarm( alarm ); 459 event->addAlarm( alarm );
460 } 460 }
461 alarm->setType( Alarm::Audio ); 461 alarm->setType( Alarm::Audio );
462 alarm->setEnabled( true ); 462 alarm->setEnabled( true );
463 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 463 int alarmOffset = alarmDt.secsTo( event->dtStart() );
464 alarm->setStartOffset( -alarmOffset ); 464 alarm->setStartOffset( -alarmOffset );
465 } else { 465 } else {
466 Alarm *alarm; 466 Alarm *alarm;
467 if ( event->alarms().count() > 0 ) { 467 if ( event->alarms().count() > 0 ) {
468 alarm = event->alarms().first(); 468 alarm = event->alarms().first();
469 alarm->setType( Alarm::Audio ); 469 alarm->setType( Alarm::Audio );
470 alarm->setStartOffset( -60*15 ); 470 alarm->setStartOffset( -60*15 );
471 alarm->setEnabled( false ); 471 alarm->setEnabled( false );
472 } 472 }
473 } 473 }
474 // csum ***************************************** 474 // csum *****************************************
475 475
476 uint cSum; 476 uint cSum;
477 cSum = PhoneFormat::getCsumEvent( event ); 477 cSum = PhoneFormat::getCsumEvent( event );
478 event->setCsum( mProfileName, QString::number( cSum )); 478 event->setCsum( mProfileName, QString::number( cSum ));
479 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 479 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
480 mCalendar->addEvent( event); 480 mCalendar->addEvent( event);
481 481
482 return true; 482 return true;
483 } 483 }
484 484
485 485
486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { 486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = false ) {
487 QDateTime dt; 487 QDateTime dt;
488 int y,m,t,h,min,sec; 488 int y,m,t,h,min,sec;
489 y = dtp->Year; 489 y = dtp->Year;
490 m = dtp->Month; 490 m = dtp->Month;
491 t = dtp->Day; 491 t = dtp->Day;
492 h = dtp->Hour; 492 h = dtp->Hour;
493 min = dtp->Minute; 493 min = dtp->Minute;
494 sec = dtp->Second; 494 sec = dtp->Second;
495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
496 // dtp->Timezone: offset in hours 496 // dtp->Timezone: offset in hours
497 int offset = KGlobal::locale()->localTimeOffset( dt ); 497 int offset = KGlobal::locale()->localTimeOffset( dt );
498 if ( useTz ) 498 if ( useTz )
499 dt = dt.addSecs ( offset*60); 499 dt = dt.addSecs ( offset*60);
500 return dt; 500 return dt;
501 501
502 } 502 }
503 503
504 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 504 static QString dtToString( const QDateTime& dti, bool useTZ = false )
505 { 505 {
506 QString datestr; 506 QString datestr;
507 QString timestr; 507 QString timestr;
508 int offset = KGlobal::locale()->localTimeOffset( dti ); 508 int offset = KGlobal::locale()->localTimeOffset( dti );
509 QDateTime dt; 509 QDateTime dt;
510 if (useTZ) 510 if (useTZ)
511 dt = dti.addSecs ( -(offset*60)); 511 dt = dti.addSecs ( -(offset*60));
512 else 512 else
513 dt = dti; 513 dt = dti;
514 if(dt.date().isValid()){ 514 if(dt.date().isValid()){
515 const QDate& date = dt.date(); 515 const QDate& date = dt.date();
516 datestr.sprintf("%04d%02d%02d", 516 datestr.sprintf("%04d%02d%02d",
517 date.year(), date.month(), date.day()); 517 date.year(), date.month(), date.day());
518 } 518 }
519 if(dt.time().isValid()){ 519 if(dt.time().isValid()){
520 const QTime& time = dt.time(); 520 const QTime& time = dt.time();
521 timestr.sprintf("T%02d%02d%02d", 521 timestr.sprintf("T%02d%02d%02d",
522 time.hour(), time.minute(), time.second()); 522 time.hour(), time.minute(), time.second());
523 } 523 }
524 return datestr + timestr; 524 return datestr + timestr;
525 } 525 }
526 QDate datefromGSM ( GSM_DateTime*dtp ) { 526 QDate datefromGSM ( GSM_DateTime*dtp ) {
527 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 527 return QDate ( dtp->Year, dtp->Month, dtp->Day );
528 } 528 }
529 QString getCategory( GSM_CalendarEntry*Note) 529 QString getCategory( GSM_CalendarEntry*Note)
530 { 530 {
531 QString CATEGORY; 531 QString CATEGORY;
532 switch (Note->Type) { 532 switch (Note->Type) {
533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
561 default : CATEGORY = QString(""); 561 default : CATEGORY = QString("");
562 } 562 }
563 563
564 return CATEGORY; 564 return CATEGORY;
565 } 565 }
566 566
567protected: 567protected:
568private: 568private:
569 Calendar *mCalendar; 569 Calendar *mCalendar;
570 QString mProfileName ; 570 QString mProfileName ;
571}; 571};
572 572
573 573
574PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 574PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
575{ 575{
576 mProfileName = profileName; 576 mProfileName = profileName;
577 mDevice = device; 577 mDevice = device;
578 mConnection = connection; 578 mConnection = connection;
579 mModel = model; 579 mModel = model;
580} 580}
581 581
582PhoneFormat::~PhoneFormat() 582PhoneFormat::~PhoneFormat()
@@ -689,583 +689,815 @@ ulong PhoneFormat::getCsumEvent( Event* event )
689 QPtrList<Recurrence::rMonthPos> rmp; 689 QPtrList<Recurrence::rMonthPos> rmp;
690 rmp = rec->monthPositions(); 690 rmp = rec->monthPositions();
691 if ( rmp.first()->negative ) 691 if ( rmp.first()->negative )
692 count = 5 - rmp.first()->rPos - 1; 692 count = 5 - rmp.first()->rPos - 1;
693 else 693 else
694 count = rmp.first()->rPos - 1; 694 count = rmp.first()->rPos - 1;
695 list.append( QString::number( count ) ); 695 list.append( QString::number( count ) );
696 696
697 } 697 }
698 698
699 list.append( "0" ); 699 list.append( "0" );
700 break; 700 break;
701 case Recurrence::rMonthlyDay:// 3 701 case Recurrence::rMonthlyDay:// 3
702 list.append( "3" ); 702 list.append( "3" );
703 list.append( QString::number( rec->frequency()) );//12 703 list.append( QString::number( rec->frequency()) );//12
704 list.append( "0" ); 704 list.append( "0" );
705 list.append( "0" ); 705 list.append( "0" );
706 writeEndDate = true; 706 writeEndDate = true;
707 break; 707 break;
708 case Recurrence::rYearlyMonth://4 708 case Recurrence::rYearlyMonth://4
709 list.append( "4" ); 709 list.append( "4" );
710 list.append( QString::number( rec->frequency()) );//12 710 list.append( QString::number( rec->frequency()) );//12
711 list.append( "0" ); 711 list.append( "0" );
712 list.append( "0" ); 712 list.append( "0" );
713 writeEndDate = true; 713 writeEndDate = true;
714 break; 714 break;
715 715
716 default: 716 default:
717 list.append( "255" ); 717 list.append( "255" );
718 list.append( QString() ); 718 list.append( QString() );
719 list.append( "0" ); 719 list.append( "0" );
720 list.append( QString() ); 720 list.append( QString() );
721 list.append( "0" ); 721 list.append( "0" );
722 list.append( "20991231T000000" ); 722 list.append( "20991231T000000" );
723 break; 723 break;
724 } 724 }
725 if ( writeEndDate ) { 725 if ( writeEndDate ) {
726 726
727 if ( rec->endDate().isValid() ) { // 15 + 16 727 if ( rec->endDate().isValid() ) { // 15 + 16
728 list.append( "1" ); 728 list.append( "1" );
729 list.append( PhoneParser::dtToString( rec->endDate()) ); 729 list.append( PhoneParser::dtToString( rec->endDate()) );
730 } else { 730 } else {
731 list.append( "0" ); 731 list.append( "0" );
732 list.append( "20991231T000000" ); 732 list.append( "20991231T000000" );
733 } 733 }
734 734
735 } 735 }
736 attList << list.join(""); 736 attList << list.join("");
737 attList << event->categoriesStr(); 737 attList << event->categoriesStr();
738 attList << event->secrecyStr(); 738 attList << event->secrecyStr();
739 return PhoneFormat::getCsum(attList ); 739 return PhoneFormat::getCsum(attList );
740} 740}
741ulong PhoneFormat::getCsum( const QStringList & attList) 741ulong PhoneFormat::getCsum( const QStringList & attList)
742{ 742{
743 int max = attList.count() -1; 743 int max = attList.count() -1;
744 ulong cSum = 0; 744 ulong cSum = 0;
745 int j,k,i; 745 int j,k,i;
746 int add; 746 int add;
747 for ( i = 1; i < max ; ++i ) { 747 for ( i = 1; i < max ; ++i ) {
748 QString s = attList[i]; 748 QString s = attList[i];
749 if ( ! s.isEmpty() ){ 749 if ( ! s.isEmpty() ){
750 j = s.length(); 750 j = s.length();
751 for ( k = 0; k < j; ++k ) { 751 for ( k = 0; k < j; ++k ) {
752 int mul = k +1; 752 int mul = k +1;
753 add = s[k].unicode (); 753 add = s[k].unicode ();
754 if ( k < 16 ) 754 if ( k < 16 )
755 mul = mul * mul; 755 mul = mul * mul;
756 add = add * mul *i*i*i; 756 add = add * mul *i*i*i;
757 cSum += add; 757 cSum += add;
758 } 758 }
759 } 759 }
760 } 760 }
761 return cSum; 761 return cSum;
762 762
763} 763}
764//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 764//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
765#include <stdlib.h> 765#include <stdlib.h>
766#define DEBUGMODE false 766#define DEBUGMODE false
767bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 767bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
768{ 768{
769 GSM_StateMachines; 769 GSM_StateMachines;
770 qDebug(" load "); 770 qDebug(" load ");
771 s.opened = false; 771 s.opened = false;
772 s.msg = NULL; 772 s.msg = NULL;
773 s.ConfigNum = 0; 773 s.ConfigNum = 0;
774 QLabel status ( i18n("Opening device ..."), 0 ); 774 QLabel status ( i18n("Opening device ..."), 0 );
775 int w = status.sizeHint().width()+20 ; 775 int w = status.sizeHint().width()+20 ;
776 if ( w < 200 ) w = 230; 776 if ( w < 200 ) w = 230;
777 int h = status.sizeHint().height()+20 ; 777 int h = status.sizeHint().height()+20 ;
778 int dw = QApplication::desktop()->width(); 778 int dw = QApplication::desktop()->width();
779 int dh = QApplication::desktop()->height(); 779 int dh = QApplication::desktop()->height();
780 status.setCaption(i18n("Reading phone...") ); 780 status.setCaption(i18n("Reading phone...") );
781 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 781 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
782 status.show(); 782 status.show();
783 status.raise(); 783 status.raise();
784 qApp->processEvents(); 784 qApp->processEvents();
785#if 0
786 static char*cp;
787 static INI_Section *cfg = NULL;
788 cfg=GSM_FindGammuRC();
789 int i;
790 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
791 if (cfg!=NULL) {
792 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
793 if (cp) di.coding = cp;
794
795 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
796 if (s.Config[i].Localize) {
797 s.msg=INI_ReadFile(s.Config[i].Localize, true);
798 } else {
799#if !defined(WIN32) && defined(LOCALE_PATH)
800 locale = setlocale(LC_MESSAGES, NULL);
801 if (locale != NULL) {
802 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
803 LOCALE_PATH,
804 tolower(locale[0]),
805 tolower(locale[1]));
806 s.msg = INI_ReadFile(locale_file, true);
807 }
808#endif
809 }
810 }
811
812 /* Wanted user specific configuration? */
813
814 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
815
816 s.ConfigNum++;
817
818 /* We want to use only one file descriptor for global and state machine debug output */
819 s.Config[i].UseGlobalDebugFile = true;
820
821
822 785
823 /* We wanted to read just user specified configuration. */
824 {break;}
825 }
826
827#endif
828 int error=initDevice(&s); 786 int error=initDevice(&s);
829 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 787 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
830 if ( error != ERR_NONE ) 788 if ( error != ERR_NONE )
831 return false; 789 return false;
832 GSM_Phone_Functions*Phone; 790 GSM_Phone_Functions*Phone;
833 GSM_CalendarEntrynote; 791 GSM_CalendarEntrynote;
834 bool start = true; 792 bool start = true;
835 Phone=s.Phone.Functions; 793 Phone=s.Phone.Functions;
836 bool gshutdown = false; 794 bool gshutdown = false;
837 PhoneParser handler( calendar, mProfileName ); 795 PhoneParser handler( calendar, mProfileName );
838 int ccc = 0; 796 int ccc = 0;
839 QString message = i18n(" Reading event # "); 797 QString message = i18n(" Reading event # ");
840 int procCount = 0; 798 int procCount = 0;
841 qDebug("Debug: only 10 calender items are downloaded "); 799 qDebug("Debug: only 10 calender items are downloaded ");
842 while (!gshutdown && ccc++ < 10) { 800 while (!gshutdown && ccc++ < 10) {
843 status.setText ( message + QString::number ( ++procCount ) ); 801 status.setText ( message + QString::number ( ++procCount ) );
844 qApp->processEvents(); 802 qApp->processEvents();
845 qDebug("readEvent %d ", ccc); 803 qDebug("readEvent %d ", ccc);
846 error=Phone->GetNextCalendar(&s,&note,start); 804 error=Phone->GetNextCalendar(&s,&note,start);
847 if (error == ERR_EMPTY) break; 805 if (error == ERR_EMPTY) break;
848 start = false; 806 start = false;
849 handler.readEvent( existingCal, &note ); 807 handler.readEvent( existingCal, &note );
850 qDebug("Org loc %d ",note.Location); 808 qDebug("Org loc %d ",note.Location);
851 //note.Location = 0; 809 //note.Location = 0;
852 error=Phone->SetCalendar(&s,&note); 810 error=Phone->SetCalendar(&s,&note);
853 qDebug("new loc %d ",note.Location); 811 qDebug("new loc %d ",note.Location);
854 } 812 }
855 813
856 start = true; 814 start = true;
857 GSM_ToDoEntry ToDo; 815 GSM_ToDoEntry ToDo;
858 ccc = 0; 816 ccc = 0;
859 message = i18n(" Reading todo # "); 817 message = i18n(" Reading todo # ");
860 procCount = 0; 818 procCount = 0;
861 while (!gshutdown && ccc++ < 10) { 819 while (!gshutdown && ccc++ < 10) {
862 status.setText ( message + QString::number ( ++procCount ) ); 820 status.setText ( message + QString::number ( ++procCount ) );
863 qApp->processEvents(); 821 qApp->processEvents();
864 error = Phone->GetNextToDo(&s, &ToDo, start); 822 error = Phone->GetNextToDo(&s, &ToDo, start);
865 if (error == ERR_EMPTY) break; 823 if (error == ERR_EMPTY) break;
866 start = false; 824 start = false;
867 qDebug("ReadTodo %d ", ccc); 825 qDebug("ReadTodo %d ", ccc);
868 handler.readTodo( existingCal, &ToDo, &s); 826 handler.readTodo( existingCal, &ToDo, &s);
869 827
870 } 828 }
871 829
872 error=GSM_TerminateConnection(&s); 830 error=GSM_TerminateConnection(&s);
873 831
874 return true; 832 return true;
875} 833}
876#include <qcstring.h> 834#include <qcstring.h>
877void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) 835void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note )
878{ 836{
879 QString eText = vfconverter.eventToString( ev, cal ); 837 QString eText = vfconverter.eventToString( ev, cal );
880 int pos = 0; 838 int pos = 0;
881 GSM_ToDoEntry dummy; 839 GSM_ToDoEntry dummy;
882 qDebug( "Convert event"); 840 qDebug( "Convert event");
883 QByteArray ba; 841 QByteArray ba;
884 QDataStream s ( ba, IO_WriteOnly ); 842 QDataStream s ( ba, IO_WriteOnly );
885 s << eText.utf8(); 843 s << eText.utf8();
886 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); 844 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
887 qDebug( "Convert event done"); 845 qDebug( "Convert event done");
888 Note->Location = 0; 846 Note->Location = 0;
889 QString loc = ev->getID(mProfileName); 847 QString loc = ev->getID(mProfileName);
890 if ( !loc.isEmpty() ){ 848 if ( !loc.isEmpty() ){
891 Note->Location = loc.toInt(); 849 Note->Location = loc.toInt();
892 } 850 }
893 851
894} 852}
895void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) 853void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo )
896{ 854{
897 qDebug( "Convert todo1"); 855 qDebug( "Convert todo1");
898 QString tText = vfconverter.todoToString( todo, cal ); 856 QString tText = vfconverter.todoToString( todo, cal );
899 int pos = 0; 857 int pos = 0;
900 GSM_CalendarEntry dummy; 858 GSM_CalendarEntry dummy;
901 QByteArray ba; 859 QByteArray ba;
902 QDataStream s ( ba, IO_WriteOnly ); 860 QDataStream s ( ba, IO_WriteOnly );
903 s << tText.utf8(); 861 s << tText.utf8();
904 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); 862 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
905 qDebug( "Convert todo done "); 863 qDebug( "Convert todo done ");
906 gsmTodo->Location = 0; 864 gsmTodo->Location = 0;
907 QString loc = todo->getID(mProfileName); 865 QString loc = todo->getID(mProfileName);
908 if ( !loc.isEmpty() ){ 866 if ( !loc.isEmpty() ){
909 gsmTodo->Location = loc.toInt(); 867 gsmTodo->Location = loc.toInt();
910 } 868 }
911 869
912} 870}
913void PhoneFormat::afterSave( Incidence* inc) 871void PhoneFormat::afterSave( Incidence* inc)
914{ 872{
915 uint csum; 873 uint csum;
874 inc->removeID( mProfileName );
916 if ( inc->type() == "Event") 875 if ( inc->type() == "Event")
917 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 876 csum = PhoneFormat::getCsumEvent( (Event*) inc );
918 else 877 else
919 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 878 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
920 inc->setCsum( mProfileName, QString::number( csum )); 879 inc->setCsum( mProfileName, QString::number( csum ));
921 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 880 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
922 881
923} 882}
924bool PhoneFormat::save( Calendar *calendar) 883bool PhoneFormat::save( Calendar *calendar)
925{ 884{
926 return true; 885
927 GSM_StateMachines; 886 GSM_StateMachines;
928 qDebug(" save "); 887 qDebug(" save ");
929 s.opened = false; 888 s.opened = false;
930 s.msg = NULL; 889 s.msg = NULL;
931 s.ConfigNum = 0; 890 s.ConfigNum = 0;
932 QLabel status ( i18n(" Opening device ..."), 0 ); 891 QLabel status ( i18n(" Opening device ..."), 0 );
933 int w = status.sizeHint().width()+20 ; 892 int w = status.sizeHint().width()+20 ;
934 if ( w < 200 ) w = 230; 893 if ( w < 200 ) w = 230;
935 int h = status.sizeHint().height()+20 ; 894 int h = status.sizeHint().height()+20 ;
936 int dw = QApplication::desktop()->width(); 895 int dw = QApplication::desktop()->width();
937 int dh = QApplication::desktop()->height(); 896 int dh = QApplication::desktop()->height();
938 status.setCaption(i18n("Writing to phone...") ); 897 status.setCaption(i18n("Writing to phone...") );
939 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 898 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
940 status.show(); 899 status.show();
941 status.raise(); 900 status.raise();
942 qApp->processEvents(); 901 qApp->processEvents();
943 902
944 int error=initDevice(&s); 903 int error=initDevice(&s);
945 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 904 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
946 if ( error != ERR_NONE ) 905 if ( error != ERR_NONE )
947 return false; 906 return false;
948 GSM_Phone_Functions*Phone; 907 GSM_Phone_Functions*Phone;
949 GSM_CalendarEntryNote; 908 GSM_CalendarEntryNote;
950 bool start = true; 909 bool start = true;
951 Phone=s.Phone.Functions; 910 Phone=s.Phone.Functions;
952 bool gshutdown = false; 911 bool gshutdown = false;
953 QPtrList<Event> er = calendar->rawEvents(); 912 QPtrList<Event> er = calendar->rawEvents();
954 Event* ev = er.first(); 913 Event* ev = er.first();
955 QString message = i18n(" Processing event # "); 914 QString message = i18n(" Deleting event # ");
956 int procCount = 0; 915 int procCount = 0;
957 bool planB = true;// false; 916 int diffProc = 0;
917 bool setPossible = true;
918#ifdef _WIN32_
919 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
920#else
921 QString fileName = "/tmp/kdepimtemp.vcs";
922#endif
923 //algo 1 delete event
924 while ( ev ) {
925 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
926
927 status.setText ( message + QString::number ( ++procCount ) );
928 qApp->processEvents();
929 qDebug("del event1 %d ", procCount);
930 //event2GSM( calendar, ev, &Note );
931 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
932
933 QString loc = ev->getID(mProfileName);
934 if ( !loc.isEmpty() ){
935 Note.Location = loc.toInt();
936 } else {
937 qDebug("error: loc is empty ");
938 }
939 error = Phone->DeleteCalendar(&s, &Note);
940 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
941 qDebug(" e error delete1 planB %d ", error);
942 break;
943 }
944 }
945 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
946 // we have to do this later after deleting
947
948 }
949 else { // change existing
950
951 QString loc = ev->getID(mProfileName);
952 if ( !loc.isEmpty() ){
953 Note.Location = loc.toInt();
954 } else {
955 qDebug("error3: loc is empty ");
956 }
957 error = Phone->DeleteCalendar(&s, &Note);
958 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
959 qDebug(" e error delete2 planB %d ", error);
960 break;
961 }
962 ev->removeID( mProfileName );
963 }
964 }
965 ev = er.next();
966 }
967 //algo 1 delete todo
968 GSM_ToDoEntry ToDoEntry;
969 QPtrList<Todo> tl = calendar->rawTodos();
970 Todo* to = tl.first();
971 message = i18n(" Deleting todo # ");
972 procCount = 0;
973 while ( to ) {
974 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
975 qDebug("todo3 %d ", procCount);
976 status.setText ( message + QString::number ( ++procCount ) );
977 qApp->processEvents();
978 qDebug("todo5 %d ", procCount);
979 // todo2GSM( calendar, to, &ToDoEntry );
980 QString loc = to->getID(mProfileName);
981 if ( !loc.isEmpty() ){
982 ToDoEntry.Location = loc.toInt();
983 } else {
984 qDebug("error2: loc is empty ");
985 }
986 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
987 error=Phone->DeleteToDo(&s,&ToDoEntry);
988 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
989 qDebug("delete planB %d ", error);
990 }
991 }
992 else if ( to->getID(mProfileName).isEmpty() ) { // add new
993 ;
994 }
995 else { // change existing
996 error=Phone->DeleteToDo(&s,&ToDoEntry);
997 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
998 qDebug("set planB %d ", error);
999 }
1000 to->removeID( mProfileName );
1001 }
1002 }
1003 to = tl.next();
1004 }
1005 //algo 2 add event
1006 ev = er.first();
1007 QString filec;
1008 message = i18n(" Preparing event # ");
1009 procCount = 0;
1010 while ( ev ) {
1011 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1012 if ( ev->getID(mProfileName).isEmpty() ) {
1013 status.setText ( message + QString::number ( ++procCount ) );
1014 qApp->processEvents();
1015 filec += vfconverter.eventToString( ev, calendar )+ "\n";
1016 afterSave ( ev );
1017
1018 }
1019 }
1020 ev = er.next();
1021 }
1022 //algo 2 add todo
1023 to = tl.first();
1024 procCount = 0;
1025 message = i18n(" Preparing todo # ");
1026 while ( to ) {
1027 qDebug("todo2 %d ", procCount);
1028 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1029 qDebug("todo4 %d ", procCount);
1030 if ( to->getID(mProfileName).isEmpty() ) {
1031 status.setText ( message + QString::number ( ++procCount ) );
1032 qApp->processEvents();
1033 filec += vfconverter.todoToString( to, calendar )+ "\n";
1034 afterSave ( to );
1035 }
1036 }
1037 to = tl.next();
1038 }
1039 if ( filec.isEmpty() ) {
1040 qDebug("Nothing to write back.Finished. ");
1041 error=GSM_TerminateConnection(&s);
1042 return true;
1043 }
1044 //algo 3 saving file
1045 message = i18n(" Saving temp file ... ");
1046 status.setText ( message );
1047 qApp->processEvents();
1048 QFile file( fileName );
1049 if (!file.open( IO_WriteOnly ) ) {
1050 qDebug("error open file ");
1051 error=GSM_TerminateConnection(&s);
1052 return false;
1053 }
1054 QTextStream ts( &file );
1055 ts.setCodec( QTextCodec::codecForName("utf8") );
1056 ts << filec ;
1057 file.close();
1058
1059
1060 message = i18n(" Parsing temp file ... ");
1061 status.setText ( message );
1062 qApp->processEvents();
1063 GSM_Backup Backup;
1064 error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup);
1065 qDebug("Read file result %d ",error );
1066 //algo 4 writing event
1067 int max, i;
1068 procCount = 0;
1069 message = i18n(" Writing event # ");
1070 if (Backup.Calendar[0] != NULL) {
1071 max = 0;
1072 while (Backup.Calendar[max]!=NULL) max++;
1073 for (i=0;i<max;i++) {
1074 status.setText ( message + QString::number ( ++procCount ) );
1075 qApp->processEvents();
1076 Note = *Backup.Calendar[i];
1077 Note.Location = 0;
1078 error=Phone->AddCalendar(&s,&Note);
1079 qDebug("add event %d %d", error, Note.Location );
1080 }
1081 }
1082 //algo 4 writing todo
1083 procCount = 0;
1084 message = i18n(" Writing todo # ");
1085 if (Backup.ToDo[0] != NULL) {
1086 max = 0;
1087 while (Backup.ToDo[max]!=NULL) max++;
1088 for (i=0;i<max;i++) {
1089 status.setText ( message + QString::number ( ++procCount ) );
1090 qApp->processEvents();
1091 ToDoEntry = *Backup.ToDo[i];
1092 error = Phone->AddToDo(&s,&ToDoEntry);
1093 qDebug("add todo %d ", error);
1094 }
1095 }
1096 //algo 5 reread
1097 message = i18n(" Rereading all data ... ");
1098 status.setText ( message );
1099 qApp->processEvents();
1100 error=GSM_TerminateConnection(&s);
1101 CalendarLocal* calendarTemp = new CalendarLocal();
1102 calendarTemp->setTimeZoneId( calendar->timeZoneId());
1103 if ( ! load( calendarTemp,calendar) ){
1104 qDebug("error reloading calendar ");
1105 delete calendarTemp;
1106 return false;
1107 }
1108
1109
1110 //algo 6 compare event
1111 ev = er.first();
1112 message = i18n(" Comparing event # ");
1113 QPtrList<Event> er1 = calendarTemp->rawEvents();
1114 Event* ev1;
1115 procCount = 0;
1116 while ( ev ) {
1117 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) {
1118 qDebug("event new ID ");
1119 status.setText ( message + QString::number ( ++procCount ) );
1120 qApp->processEvents();
1121 QString cSum = ev->getCsum(mProfileName);
1122 ev1 = er1.first();
1123 while ( ev1 ) {
1124 if ( ev1->getCsum( mProfileName ) == cSum ) {
1125 er1.remove( ev1 );
1126 ev->setID(mProfileName, ev1->getID(mProfileName) );
1127 break;
1128 }
1129 ev1 = er1.next();
1130 }
1131 if ( ! ev1 ) {
1132 ev->removeID(mProfileName);
1133 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
1134 qDebug("Probably writing back of events not supported ");
1135 }
1136
1137 }
1138 ev = er.next();
1139 }
1140 //algo 6 compare todo
1141 to = tl.first();
1142 procCount = 0;
1143 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
1144 Todo* to1 ;
1145 message = i18n(" Comparing todo # ");
1146 while ( to ) {
1147 qDebug("todo2 %d ", procCount);
1148 if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) {
1149 status.setText ( message + QString::number ( ++procCount ) );
1150 qApp->processEvents();
1151 QString cSum = to->getCsum(mProfileName);
1152 Todo* to1 = tl1.first();
1153 while ( to1 ) {
1154 if ( to1->getCsum( mProfileName ) == cSum ) {
1155 tl1.remove( to1 );
1156 to->setID(mProfileName, to1->getID(mProfileName) );
1157 break;
1158 }
1159 to1 = tl1.next();
1160 }
1161 if ( ! to1 ) {
1162 to->removeID(mProfileName);
1163 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
1164 qDebug("Probably writing back of todos not supported ");
1165 }
1166 }
1167 to = tl.next();
1168 }
1169 delete calendarTemp;
1170 return true;
1171 // *******************************************************************
1172 // *******************************************************************
1173 // *******************************************************************
1174#if 0
958 while ( ev && ! planB) { 1175 while ( ev && ! planB) {
959 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one 1176 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
960 1177
961 status.setText ( message + QString::number ( ++procCount ) ); 1178 status.setText ( message + QString::number ( ++procCount ) );
962 qApp->processEvents(); 1179 qApp->processEvents();
963 qDebug("event1 %d ", procCount); 1180 qDebug("event1 %d ", procCount);
964 event2GSM( calendar, ev, &Note ); 1181 event2GSM( calendar, ev, &Note );
965 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 1182 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
966 error = Phone->DeleteCalendar(&s, &Note); 1183 error = Phone->DeleteCalendar(&s, &Note);
967 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1184 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
968 planB = true; 1185 planB = true;
969 qDebug(" e delete planB %d ", error); 1186 qDebug(" e delete1 planB %d ", error);
970 break; 1187 break;
971 } 1188 }
972 } 1189 }
973 else if ( ev->getID(mProfileName).isEmpty() ) { // add new 1190 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
974 // we have to do this later after deleting 1191 // we have to do this later after deleting
975 1192
976 } 1193 }
977 else { // change existing 1194 else { // change existing
978 error = Phone->SetCalendar(&s, &Note); 1195 if ( setPossible ) {
979 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1196 error = Phone->SetCalendar(&s, &Note);
980 planB = true; 1197 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
981 qDebug(" e change planB %d ", error); 1198 setPossible = false;
982 break; 1199 ++diffProc;
1200 qDebug("Set cal not supported %d ", error);
1201 break;
1202 }
1203 }
1204 if ( ! setPossible) {
1205 ++diffProc;
1206 error = Phone->DeleteCalendar(&s, &Note);
1207 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1208 planB = true;
1209 qDebug(" e delete2 planB %d ", error);
1210 break;
1211 }
1212 ev->removeID( mProfileName );
983 } 1213 }
984 qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); 1214 qDebug("Change Calendar. Location %d status: %d",Note.Location, error );
985 } 1215 }
986 } 1216 }
987 ev = er.next(); 1217 ev = er.next();
988 } 1218 }
989 ev = er.first(); 1219 ev = er.first();
990 // pending get empty slots 1220 // pending get empty slots
991 int loc = 0; 1221 int loc = 0;
1222 procCount -= diffProc;
992 while ( ev && ! planB) { 1223 while ( ev && ! planB) {
993 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1224 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
994 qDebug("event2 %d ", procCount); 1225 qDebug("event2 %d ", procCount);
995 if ( ev->getID(mProfileName).isEmpty() ) { 1226 if ( ev->getID(mProfileName).isEmpty() ) {
996 status.setText ( message + QString::number ( ++procCount ) ); 1227 status.setText ( message + QString::number ( ++procCount ) );
997 qApp->processEvents(); 1228 qApp->processEvents();
998 //int newID ;//= pending 1229 //int newID ;//= pending
999 //ev->setID(mProfileName, QString::number( newID )); 1230 //ev->setID(mProfileName, QString::number( newID ));
1000 event2GSM( calendar, ev, &Note ); 1231 event2GSM( calendar, ev, &Note );
1001 ++loc; 1232 ++loc;
1002 Note.Location = loc; 1233 Note.Location = loc;
1003 error = Phone->AddCalendar(&s, &Note); 1234 error = Phone->AddCalendar(&s, &Note);
1004 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1235 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1005 planB = true; 1236 planB = true;
1006 qDebug(" e add planB %d ", error); 1237 qDebug(" e add planB %d ", error);
1007 break; 1238 break;
1008 } 1239 }
1009 ev->setID( mProfileName, QString::number( Note.Location ) ); 1240 ev->setID( mProfileName, QString::number( Note.Location ) );
1010 qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); 1241 qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN);
1011 afterSave( ev ); 1242 afterSave( ev );
1012 } else { 1243 } else {
1013 afterSave( ev ); // setting temp sync stat for changed items 1244 afterSave( ev ); // setting temp sync stat for changed items
1014 } 1245 }
1015 } 1246 }
1016 ev = er.next(); 1247 ev = er.next();
1017 } 1248 }
1018 1249
1019 1250
1020 if ( planB ) { 1251 if ( planB ) {
1021 qDebug("delete all calendar..."); 1252 qDebug("delete all calendar...");
1022 status.setText ( i18n("Deleting all calendar...")); 1253 status.setText ( i18n("Deleting all calendar..."));
1023 qApp->processEvents(); 1254 qApp->processEvents();
1024 error=Phone->DeleteAllCalendar(&s); 1255 error=Phone->DeleteAllCalendar(&s);
1025 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1256 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1026 message = i18n(" Deleting event # "); 1257 message = i18n(" Deleting event # ");
1027 procCount = 0; 1258 procCount = 0;
1028 while (1) { 1259 while (1) {
1029 status.setText ( message + QString::number ( ++procCount ) ); 1260 status.setText ( message + QString::number ( ++procCount ) );
1030 qApp->processEvents(); 1261 qApp->processEvents();
1031 qDebug("deleting event ... %d", procCount); 1262 qDebug("deleting event ... %d", procCount);
1032 error = Phone->GetNextCalendar(&s,&Note,true); 1263 error = Phone->GetNextCalendar(&s,&Note,true);
1033 if (error != ERR_NONE) break; 1264 if (error != ERR_NONE) break;
1034 error = Phone->DeleteCalendar(&s,&Note); 1265 error = Phone->DeleteCalendar(&s,&Note);
1035 } 1266 }
1036 qDebug("deleting calendar ... finished"); 1267 qDebug("deleting calendar ... finished");
1037 } else { 1268 } else {
1038 status.setText ( i18n("All calendar deleted!")); 1269 status.setText ( i18n("All calendar deleted!"));
1039 qDebug("all cal deleted"); 1270 qDebug("all cal deleted");
1040 } 1271 }
1041 bool planC = false; 1272 bool planC = false;
1042 ev = er.first(); 1273 ev = er.first();
1043 procCount = 0; 1274 procCount = 0;
1044 message = i18n(" Writing event # "); 1275 message = i18n(" Writing event # ");
1045 while ( ev && ! planC) { 1276 while ( ev && ! planC) {
1046 status.setText ( message + QString::number ( ++procCount ) ); 1277 status.setText ( message + QString::number ( ++procCount ) );
1047 qApp->processEvents(); 1278 qApp->processEvents();
1048 event2GSM( calendar, ev, &Note ); 1279 event2GSM( calendar, ev, &Note );
1049 Note.Location = procCount; 1280 Note.Location = procCount;
1050 error=Phone->AddCalendar(&s,&Note); 1281 error=Phone->AddCalendar(&s,&Note);
1051 if (error != ERR_NONE ) { 1282 if (error != ERR_NONE ) {
1052 // we have currently no planC :-( 1283 // we have currently no planC :-(
1053 // planC = true; 1284 // planC = true;
1054 //qDebug("add planC %d ", error); 1285 //qDebug("add planC %d ", error);
1055 //break; 1286 //break;
1056 // we remove the ID such that this todo is not deleted after next sync 1287 // we remove the ID such that this todo is not deleted after next sync
1057 ev->removeID(mProfileName); 1288 ev->removeID(mProfileName);
1058 ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 1289 ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1059 qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); 1290 qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error);
1060 } else { 1291 } else {
1061 qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); 1292 qDebug("cal adding loc %d planB stat %d ", Note.Location ,error);
1062 ev->setID(mProfileName, QString::number( Note.Location )); 1293 ev->setID(mProfileName, QString::number( Note.Location ));
1063 afterSave( ev ); 1294 afterSave( ev );
1064 } 1295 }
1065 ev = er.next(); 1296 ev = er.next();
1066 } 1297 }
1067 if ( planC ) { 1298 if ( planC ) {
1068 qDebug("writing cal went wrong..."); 1299 qDebug("writing cal went wrong...");
1069 1300
1070 // we have currently no planC :-( 1301 // we have currently no planC :-(
1071 } 1302 }
1072 } 1303 }
1073 GSM_ToDoEntry ToDoEntry; 1304 GSM_ToDoEntry ToDoEntry;
1074 QPtrList<Todo> tl = calendar->rawTodos(); 1305 QPtrList<Todo> tl = calendar->rawTodos();
1075 Todo* to = tl.first(); 1306 Todo* to = tl.first();
1076 1307
1077 message = i18n(" Processing todo # "); 1308 message = i18n(" Processing todo # ");
1078 procCount = 0; 1309 procCount = 0;
1079 planB = false; 1310 planB = false;
1080 while ( to && ! planB ) { 1311 while ( to && ! planB ) {
1081 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 1312 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
1082 qDebug("todo3 %d ", procCount); 1313 qDebug("todo3 %d ", procCount);
1083 status.setText ( message + QString::number ( ++procCount ) ); 1314 status.setText ( message + QString::number ( ++procCount ) );
1084 qApp->processEvents(); 1315 qApp->processEvents();
1085 qDebug("todo5 %d ", procCount); 1316 qDebug("todo5 %d ", procCount);
1086 todo2GSM( calendar, to, &ToDoEntry ); 1317 todo2GSM( calendar, to, &ToDoEntry );
1087 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 1318 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
1088 error=Phone->DeleteToDo(&s,&ToDoEntry); 1319 error=Phone->DeleteToDo(&s,&ToDoEntry);
1089 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1320 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1090 planB = true; 1321 planB = true;
1091 qDebug("delete planB %d ", error); 1322 qDebug("delete planB %d ", error);
1092 } 1323 }
1093 } 1324 }
1094 else if ( to->getID(mProfileName).isEmpty() ) { // add new 1325 else if ( to->getID(mProfileName).isEmpty() ) { // add new
1095 ; 1326 ;
1096 } 1327 }
1097 else { // change existing 1328 else { // change existing
1098 error=Phone->SetToDo(&s,&ToDoEntry); 1329 error=Phone->SetToDo(&s,&ToDoEntry);
1099 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1330 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1100 planB = true; 1331 planB = true;
1101 qDebug("set planB %d ", error); 1332 qDebug("set planB %d ", error);
1102 } 1333 }
1103 qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); 1334 qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error );
1104 } 1335 }
1105 } 1336 }
1106 to = tl.next(); 1337 to = tl.next();
1107 } 1338 }
1108 1339
1109 // pending get empty slots 1340 // pending get empty slots
1110 to = tl.first(); 1341 to = tl.first();
1111 while ( to && ! planB ) { 1342 while ( to && ! planB ) {
1112 qDebug("todo2 %d ", procCount); 1343 qDebug("todo2 %d ", procCount);
1113 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1344 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1114 qDebug("todo4 %d ", procCount); 1345 qDebug("todo4 %d ", procCount);
1115 if ( to->getID(mProfileName).isEmpty() ) { 1346 if ( to->getID(mProfileName).isEmpty() ) {
1116 status.setText ( message + QString::number ( ++procCount ) ); 1347 status.setText ( message + QString::number ( ++procCount ) );
1117 qApp->processEvents(); 1348 qApp->processEvents();
1118 //int newID ;//= pending 1349 //int newID ;//= pending
1119 //to->setID(mProfileName, QString::number( newID )); 1350 //to->setID(mProfileName, QString::number( newID ));
1120 todo2GSM( calendar,to, &ToDoEntry ); 1351 todo2GSM( calendar,to, &ToDoEntry );
1121 ToDoEntry.Location = 0; 1352 ToDoEntry.Location = 0;
1122 error=Phone->AddToDo(&s,&ToDoEntry); 1353 error=Phone->AddToDo(&s,&ToDoEntry);
1123 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1354 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1124 planB = true; 1355 planB = true;
1125 qDebug("new planB %d ", error); 1356 qDebug("new planB %d ", error);
1126 } 1357 }
1127 to->setID(mProfileName, QString::number( ToDoEntry.Location )); 1358 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1128 afterSave( to ); 1359 afterSave( to );
1129 qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); 1360 qDebug("New Todo. Location %d %d",ToDoEntry.Location, error );
1130 } else { 1361 } else {
1131 afterSave( to ); 1362 afterSave( to );
1132 } 1363 }
1133 } 1364 }
1134 to = tl.next(); 1365 to = tl.next();
1135 } 1366 }
1136 if ( planB ) { 1367 if ( planB ) {
1137 qDebug("delete all ..."); 1368 qDebug("delete all ...");
1138 error=Phone->DeleteAllToDo(&s); 1369 error=Phone->DeleteAllToDo(&s);
1139 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1370 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1140 while (1) { 1371 while (1) {
1141 qDebug("deleting todo ..."); 1372 qDebug("deleting todo ...");
1142 error = Phone->GetNextToDo(&s,&ToDoEntry,true); 1373 error = Phone->GetNextToDo(&s,&ToDoEntry,true);
1143 if (error != ERR_NONE) break; 1374 if (error != ERR_NONE) break;
1144 error = Phone->DeleteToDo(&s,&ToDoEntry); 1375 error = Phone->DeleteToDo(&s,&ToDoEntry);
1145 } 1376 }
1146 qDebug("deleting todo ... finished"); 1377 qDebug("deleting todo ... finished");
1147 } else { 1378 } else {
1148 qDebug("all todo deleted"); 1379 qDebug("all todo deleted");
1149 } 1380 }
1150 bool planC = false; 1381 bool planC = false;
1151 to = tl.first(); 1382 to = tl.first();
1152 while ( to && ! planC ) { 1383 while ( to && ! planC ) {
1153 todo2GSM( calendar,to, &ToDoEntry ); 1384 todo2GSM( calendar,to, &ToDoEntry );
1154 ToDoEntry.Location = 0; 1385 ToDoEntry.Location = 0;
1155 error=Phone->AddToDo(&s,&ToDoEntry); 1386 error=Phone->AddToDo(&s,&ToDoEntry);
1156 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1387 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1157 // we have currently no planC :-( 1388 // we have currently no planC :-(
1158 // planC = true; 1389 // planC = true;
1159 //qDebug("add planC %d ", error); 1390 //qDebug("add planC %d ", error);
1160 //break; 1391 //break;
1161 // we remove the ID such that this todo is not deleted after next sync 1392 // we remove the ID such that this todo is not deleted after next sync
1162 to->removeID(mProfileName); 1393 to->removeID(mProfileName);
1163 to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 1394 to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1164 } else { 1395 } else {
1165 qDebug("adding %d planB %d ", ToDoEntry.Location ,error); 1396 qDebug("adding %d planB %d ", ToDoEntry.Location ,error);
1166 to->setID(mProfileName, QString::number( ToDoEntry.Location )); 1397 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1167 afterSave( to ); 1398 afterSave( to );
1168 } 1399 }
1169 to = tl.next(); 1400 to = tl.next();
1170 } 1401 }
1171 if ( planC ) { 1402 if ( planC ) {
1172 // we have currently no planC :-( 1403 // we have currently no planC :-(
1173 } 1404 }
1174 } 1405 }
1175 return true; 1406 return true;
1407#endif
1176} 1408}
1177QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) 1409QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
1178{ 1410{
1179 QString datestr; 1411 QString datestr;
1180 QString timestr; 1412 QString timestr;
1181 int offset = KGlobal::locale()->localTimeOffset( dti ); 1413 int offset = KGlobal::locale()->localTimeOffset( dti );
1182 QDateTime dt; 1414 QDateTime dt;
1183 if (useTZ) 1415 if (useTZ)
1184 dt = dti.addSecs ( -(offset*60)); 1416 dt = dti.addSecs ( -(offset*60));
1185 else 1417 else
1186 dt = dti; 1418 dt = dti;
1187 if(dt.date().isValid()){ 1419 if(dt.date().isValid()){
1188 const QDate& date = dt.date(); 1420 const QDate& date = dt.date();
1189 datestr.sprintf("%04d%02d%02d", 1421 datestr.sprintf("%04d%02d%02d",
1190 date.year(), date.month(), date.day()); 1422 date.year(), date.month(), date.day());
1191 } 1423 }
1192 if(dt.time().isValid()){ 1424 if(dt.time().isValid()){
1193 const QTime& time = dt.time(); 1425 const QTime& time = dt.time();
1194 timestr.sprintf("T%02d%02d%02d", 1426 timestr.sprintf("T%02d%02d%02d",
1195 time.hour(), time.minute(), time.second()); 1427 time.hour(), time.minute(), time.second());
1196 } 1428 }
1197 return datestr + timestr; 1429 return datestr + timestr;
1198} 1430}
1199QString PhoneFormat::getEventString( Event* event ) 1431QString PhoneFormat::getEventString( Event* event )
1200{ 1432{
1201#if 0 1433#if 0
1202 QStringList list; 1434 QStringList list;
1203 list.append( QString::number(event->zaurusId() ) ); 1435 list.append( QString::number(event->zaurusId() ) );
1204 list.append( event->categories().join(",") ); 1436 list.append( event->categories().join(",") );
1205 if ( !event->summary().isEmpty() ) 1437 if ( !event->summary().isEmpty() )
1206 list.append( event->summary() ); 1438 list.append( event->summary() );
1207 else 1439 else
1208 list.append("" ); 1440 list.append("" );
1209 if ( !event->location().isEmpty() ) 1441 if ( !event->location().isEmpty() )
1210 list.append( event->location() ); 1442 list.append( event->location() );
1211 else 1443 else
1212 list.append("" ); 1444 list.append("" );
1213 if ( !event->description().isEmpty() ) 1445 if ( !event->description().isEmpty() )
1214 list.append( event->description() ); 1446 list.append( event->description() );
1215 else 1447 else
1216 list.append( "" ); 1448 list.append( "" );
1217 if ( event->doesFloat () ) { 1449 if ( event->doesFloat () ) {
1218 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 1450 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
1219 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 1451 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
1220 list.append( "1" ); 1452 list.append( "1" );
1221 1453
1222 } 1454 }
1223 else { 1455 else {
1224 list.append( dtToString( event->dtStart()) ); 1456 list.append( dtToString( event->dtStart()) );
1225 list.append( dtToString( event->dtEnd()) ); //6 1457 list.append( dtToString( event->dtEnd()) ); //6
1226 list.append( "0" ); 1458 list.append( "0" );
1227 } 1459 }
1228 bool noAlarm = true; 1460 bool noAlarm = true;
1229 if ( event->alarms().count() > 0 ) { 1461 if ( event->alarms().count() > 0 ) {
1230 Alarm * al = event->alarms().first(); 1462 Alarm * al = event->alarms().first();
1231 if ( al->enabled() ) { 1463 if ( al->enabled() ) {
1232 noAlarm = false; 1464 noAlarm = false;
1233 list.append( "0" ); // yes, 0 == alarm 1465 list.append( "0" ); // yes, 0 == alarm
1234 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 1466 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
1235 if ( al->type() == Alarm::Audio ) 1467 if ( al->type() == Alarm::Audio )
1236 list.append( "1" ); // type audio 1468 list.append( "1" ); // type audio
1237 else 1469 else
1238 list.append( "0" ); // type silent 1470 list.append( "0" ); // type silent
1239 } 1471 }
1240 } 1472 }
1241 if ( noAlarm ) { 1473 if ( noAlarm ) {
1242 list.append( "1" ); // yes, 1 == no alarm 1474 list.append( "1" ); // yes, 1 == no alarm
1243 list.append( "0" ); // no alarm offset 1475 list.append( "0" ); // no alarm offset
1244 list.append( "1" ); // type 1476 list.append( "1" ); // type
1245 } 1477 }
1246 // next is: 11 1478 // next is: 11
1247 // next is: 11-16 are recurrence 1479 // next is: 11-16 are recurrence
1248 Recurrence* rec = event->recurrence(); 1480 Recurrence* rec = event->recurrence();
1249 1481
1250 bool writeEndDate = false; 1482 bool writeEndDate = false;
1251 switch ( rec->doesRecur() ) 1483 switch ( rec->doesRecur() )
1252 { 1484 {
1253 case Recurrence::rDaily: // 0 1485 case Recurrence::rDaily: // 0
1254 list.append( "0" ); 1486 list.append( "0" );
1255 list.append( QString::number( rec->frequency() ));//12 1487 list.append( QString::number( rec->frequency() ));//12
1256 list.append( "0" ); 1488 list.append( "0" );
1257 list.append( "0" ); 1489 list.append( "0" );
1258 writeEndDate = true; 1490 writeEndDate = true;
1259 break; 1491 break;
1260 case Recurrence::rWeekly:// 1 1492 case Recurrence::rWeekly:// 1
1261 list.append( "1" ); 1493 list.append( "1" );
1262 list.append( QString::number( rec->frequency()) );//12 1494 list.append( QString::number( rec->frequency()) );//12
1263 list.append( "0" ); 1495 list.append( "0" );
1264 { 1496 {
1265 int days = 0; 1497 int days = 0;
1266 QBitArray weekDays = rec->days(); 1498 QBitArray weekDays = rec->days();
1267 int i; 1499 int i;
1268 for( i = 1; i <= 7; ++i ) { 1500 for( i = 1; i <= 7; ++i ) {
1269 if ( weekDays[i-1] ) { 1501 if ( weekDays[i-1] ) {
1270 days += 1 << (i-1); 1502 days += 1 << (i-1);
1271 } 1503 }
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index defdb09..820d068 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -414,193 +414,193 @@ bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
414 status.setText( i18n("Reading todos ...") ); 414 status.setText( i18n("Reading todos ...") );
415 qApp->processEvents(); 415 qApp->processEvents();
416 if ( ! debug ) { 416 if ( ! debug ) {
417 fileName = "/tmp/kopitempout"; 417 fileName = "/tmp/kopitempout";
418 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 418 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
419 system ( command.latin1() ); 419 system ( command.latin1() );
420 } else { 420 } else {
421 fileName = "/tmp/todo.txt"; 421 fileName = "/tmp/todo.txt";
422 } 422 }
423 file.setName( fileName ); 423 file.setName( fileName );
424 if (!file.open( IO_ReadOnly ) ) { 424 if (!file.open( IO_ReadOnly ) ) {
425 return false; 425 return false;
426 426
427 } 427 }
428 ts.setDevice( &file ); 428 ts.setDevice( &file );
429 text = ts.read(); 429 text = ts.read();
430 file.close(); 430 file.close();
431 431
432 status.setText( i18n("Processing todos ...") ); 432 status.setText( i18n("Processing todos ...") );
433 status.raise(); 433 status.raise();
434 qApp->processEvents(); 434 qApp->processEvents();
435 fromString2Cal( calendar, existngCal, text, "Todo" ); 435 fromString2Cal( calendar, existngCal, text, "Todo" );
436 return true; 436 return true;
437} 437}
438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
439{ 439{
440 int retval = -1; 440 int retval = -1;
441 QStringList templist; 441 QStringList templist;
442 QString tempString; 442 QString tempString;
443 int start = 0; 443 int start = 0;
444 int len = answer.length(); 444 int len = answer.length();
445 int end = answer.find ("\n",start)+1; 445 int end = answer.find ("\n",start)+1;
446 bool ok = true; 446 bool ok = true;
447 start = end; 447 start = end;
448 int ccc = 0; 448 int ccc = 0;
449 while ( start > 0 ) { 449 while ( start > 0 ) {
450 templist.clear(); 450 templist.clear();
451 ok = true; 451 ok = true;
452 int loopCount = 0; 452 int loopCount = 0;
453 while ( ok ) { 453 while ( ok ) {
454 ++loopCount; 454 ++loopCount;
455 if ( loopCount > 25 ) { 455 if ( loopCount > 25 ) {
456 qDebug("KO: Error in while loop"); 456 qDebug("KO: Error in while loop");
457 ok = false; 457 ok = false;
458 start = 0; 458 start = 0;
459 break; 459 break;
460 } 460 }
461 if ( ok ) 461 if ( ok )
462 tempString = getPart( answer, ok, start ); 462 tempString = getPart( answer, ok, start );
463 if ( start >= len || start == 0 ) { 463 if ( start >= len || start == 0 ) {
464 start = 0; 464 start = 0;
465 ok = false; 465 ok = false;
466 } 466 }
467 if ( tempString.right(1) =="\n" ) 467 if ( tempString.right(1) =="\n" )
468 tempString = tempString.left( tempString.length()-1); 468 tempString = tempString.left( tempString.length()-1);
469 469
470 templist.append( tempString ); 470 templist.append( tempString );
471 } 471 }
472 ++ccc; 472 ++ccc;
473 if ( ccc == 2 && loopCount < 25 ) { 473 if ( ccc == 2 && loopCount < 25 ) {
474 start = 0; 474 start = 0;
475 bool ok; 475 bool ok;
476 int newnum = templist[0].toInt( &ok ); 476 int newnum = templist[0].toInt( &ok );
477 if ( ok && newnum > 0) { 477 if ( ok && newnum > 0) {
478 retval = newnum; 478 retval = newnum;
479 inc->setID( "Sharp_DTM",templist[0] ); 479 inc->setID( "Sharp_DTM",templist[0] );
480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
482 } 482 }
483 } 483 }
484 } 484 }
485 //qDebug("getNumFromRecord returning : %d ", retval); 485 //qDebug("getNumFromRecord returning : %d ", retval);
486 return retval; 486 return retval;
487} 487}
488bool SharpFormat::save( Calendar *calendar) 488bool SharpFormat::save( Calendar *calendar)
489{ 489{
490 490
491 QLabel status ( i18n("Processing/adding events ..."), 0 ); 491 QLabel status ( i18n("Processing/adding events ..."), 0 );
492 int w = status.sizeHint().width()+20 ; 492 int w = status.sizeHint().width()+20 ;
493 if ( w < 200 ) w = 200; 493 if ( w < 200 ) w = 200;
494 int h = status.sizeHint().height()+20 ; 494 int h = status.sizeHint().height()+20 ;
495 int dw = QApplication::desktop()->width(); 495 int dw = QApplication::desktop()->width();
496 int dh = QApplication::desktop()->height(); 496 int dh = QApplication::desktop()->height();
497 status.setCaption(i18n("Writing DTM Data") ); 497 status.setCaption(i18n("Writing DTM Data") );
498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
499 status.show(); 499 status.show();
500 status.raise(); 500 status.raise();
501 qApp->processEvents(); 501 qApp->processEvents();
502 bool debug = DEBUGMODE; 502 bool debug = DEBUGMODE;
503 QString codec = "utf8"; 503 QString codec = "utf8";
504 QString answer; 504 QString answer;
505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
507 QString command; 507 QString command;
508 QPtrList<Event> er = calendar->rawEvents(); 508 QPtrList<Event> er = calendar->rawEvents();
509 Event* ev = er.first(); 509 Event* ev = er.first();
510 QString fileName = "/tmp/kopitempout"; 510 QString fileName = "/tmp/kdepimtempfile";
511 int i = 0; 511 int i = 0;
512 QString changeString = ePrefix; 512 QString changeString = ePrefix;
513 QString deleteString = ePrefix; 513 QString deleteString = ePrefix;
514 bool deleteEnt = false; 514 bool deleteEnt = false;
515 bool changeEnt = false; 515 bool changeEnt = false;
516 QString message = i18n("Processing event # "); 516 QString message = i18n("Processing event # ");
517 int procCount = 0; 517 int procCount = 0;
518 while ( ev ) { 518 while ( ev ) {
519 //qDebug("i %d ", ++i); 519 //qDebug("i %d ", ++i);
520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
521 status.setText ( message + QString::number ( ++procCount ) ); 521 status.setText ( message + QString::number ( ++procCount ) );
522 qApp->processEvents(); 522 qApp->processEvents();
523 QString eString = getEventString( ev ); 523 QString eString = getEventString( ev );
524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
525 // deleting empty strings does not work. 525 // deleting empty strings does not work.
526 // we write first and x and then delete the record with the x 526 // we write first and x and then delete the record with the x
527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
528 changeString += eString + "\n"; 528 changeString += eString + "\n";
529 deleteString += eString + "\n"; 529 deleteString += eString + "\n";
530 deleteEnt = true; 530 deleteEnt = true;
531 changeEnt = true; 531 changeEnt = true;
532 } 532 }
533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
535 system ( command.utf8() ); 535 system ( command.utf8() );
536 QFile file( fileName ); 536 QFile file( fileName );
537 if (!file.open( IO_ReadOnly ) ) { 537 if (!file.open( IO_ReadOnly ) ) {
538 return false; 538 return false;
539 539
540 } 540 }
541 QTextStream ts( &file ); 541 QTextStream ts( &file );
542 ts.setCodec( QTextCodec::codecForName("utf8") ); 542 ts.setCodec( QTextCodec::codecForName("utf8") );
543 answer = ts.read(); 543 answer = ts.read();
544 file.close(); 544 file.close();
545 //qDebug("answer \n%s ", answer.latin1()); 545 //qDebug("answer \n%s ", answer.latin1());
546 getNumFromRecord( answer, ev ) ; 546 getNumFromRecord( answer, ev ) ;
547 547
548 } 548 }
549 else { // change existing 549 else { // change existing
550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
552 changeString += eString + "\n"; 552 changeString += eString + "\n";
553 changeEnt = true; 553 changeEnt = true;
554 554
555 } 555 }
556 } 556 }
557 ev = er.next(); 557 ev = er.next();
558 } 558 }
559 status.setText ( i18n("Changing events ...") ); 559 status.setText ( i18n("Changing events ...") );
560 qApp->processEvents(); 560 qApp->processEvents();
561 //qDebug("changing... "); 561 //qDebug("changing... ");
562 if ( changeEnt ) { 562 if ( changeEnt ) {
563 QFile file( fileName ); 563 QFile file( fileName );
564 if (!file.open( IO_WriteOnly ) ) { 564 if (!file.open( IO_WriteOnly ) ) {
565 return false; 565 return false;
566 566
567 } 567 }
568 QTextStream ts( &file ); 568 QTextStream ts( &file );
569 ts.setCodec( QTextCodec::codecForName("utf8") ); 569 ts.setCodec( QTextCodec::codecForName("utf8") );
570 ts << changeString ; 570 ts << changeString ;
571 file.close(); 571 file.close();
572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
573 system ( command.latin1() ); 573 system ( command.latin1() );
574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
575 575
576 } 576 }
577 status.setText ( i18n("Deleting events ...") ); 577 status.setText ( i18n("Deleting events ...") );
578 qApp->processEvents(); 578 qApp->processEvents();
579 //qDebug("deleting... "); 579 //qDebug("deleting... ");
580 if ( deleteEnt ) { 580 if ( deleteEnt ) {
581 QFile file( fileName ); 581 QFile file( fileName );
582 if (!file.open( IO_WriteOnly ) ) { 582 if (!file.open( IO_WriteOnly ) ) {
583 return false; 583 return false;
584 584
585 } 585 }
586 QTextStream ts( &file ); 586 QTextStream ts( &file );
587 ts.setCodec( QTextCodec::codecForName("utf8") ); 587 ts.setCodec( QTextCodec::codecForName("utf8") );
588 ts << deleteString; 588 ts << deleteString;
589 file.close(); 589 file.close();
590 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 590 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
591 system ( command.latin1() ); 591 system ( command.latin1() );
592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
593 } 593 }
594 594
595 595
596 changeString = tPrefix; 596 changeString = tPrefix;
597 deleteString = tPrefix; 597 deleteString = tPrefix;
598 status.setText ( i18n("Processing todos ...") ); 598 status.setText ( i18n("Processing todos ...") );
599 qApp->processEvents(); 599 qApp->processEvents();
600 QPtrList<Todo> tl = calendar->rawTodos(); 600 QPtrList<Todo> tl = calendar->rawTodos();
601 Todo* to = tl.first(); 601 Todo* to = tl.first();
602 i = 0; 602 i = 0;
603 message = i18n("Processing todo # "); 603 message = i18n("Processing todo # ");
604 procCount = 0; 604 procCount = 0;
605 while ( to ) { 605 while ( to ) {
606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 076cd3f..9307f12 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -254,208 +254,210 @@ VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
254 tmpStr = qDateTimeToISO(anEvent->lastModified()); 254 tmpStr = qDateTimeToISO(anEvent->lastModified());
255 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 255 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
256 256
257 // organizer stuff 257 // organizer stuff
258 tmpStr = "MAILTO:" + anEvent->organizer(); 258 tmpStr = "MAILTO:" + anEvent->organizer();
259 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 259 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
260 260
261 // attendees 261 // attendees
262 if (anEvent->attendeeCount() != 0) { 262 if (anEvent->attendeeCount() != 0) {
263 QPtrList<Attendee> al = anEvent->attendees(); 263 QPtrList<Attendee> al = anEvent->attendees();
264 QPtrListIterator<Attendee> ai(al); 264 QPtrListIterator<Attendee> ai(al);
265 Attendee *curAttendee; 265 Attendee *curAttendee;
266 266
267 for (; ai.current(); ++ai) { 267 for (; ai.current(); ++ai) {
268 curAttendee = ai.current(); 268 curAttendee = ai.current();
269 if (!curAttendee->email().isEmpty() && 269 if (!curAttendee->email().isEmpty() &&
270 !curAttendee->name().isEmpty()) 270 !curAttendee->name().isEmpty())
271 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 271 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
272 curAttendee->email() + ">"; 272 curAttendee->email() + ">";
273 else if (curAttendee->name().isEmpty()) 273 else if (curAttendee->name().isEmpty())
274 tmpStr = "MAILTO: " + curAttendee->email(); 274 tmpStr = "MAILTO: " + curAttendee->email();
275 else if (curAttendee->email().isEmpty()) 275 else if (curAttendee->email().isEmpty())
276 tmpStr = "MAILTO: " + curAttendee->name(); 276 tmpStr = "MAILTO: " + curAttendee->name();
277 else if (curAttendee->name().isEmpty() && 277 else if (curAttendee->name().isEmpty() &&
278 curAttendee->email().isEmpty()) 278 curAttendee->email().isEmpty())
279 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 279 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
280 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 280 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
281 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 281 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
282 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 282 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
283 } 283 }
284 } 284 }
285 285
286 // description BL: 286 // description BL:
287 if (!anEvent->description().isEmpty()) { 287 if (!anEvent->description().isEmpty()) {
288 VObject *d = addPropValue(vtodo, VCDescriptionProp, 288 VObject *d = addPropValue(vtodo, VCDescriptionProp,
289 anEvent->description().local8Bit()); 289 anEvent->description().local8Bit());
290 if (anEvent->description().find('\n') != -1) 290 if (anEvent->description().find('\n') != -1)
291 addProp(d, VCQuotedPrintableProp); 291 addProp(d, VCQuotedPrintableProp);
292 } 292 }
293 293
294 // summary 294 // summary
295 if (!anEvent->summary().isEmpty()) 295 if (!anEvent->summary().isEmpty())
296 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); 296 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
297 297
298 if (!anEvent->location().isEmpty()) 298 if (!anEvent->location().isEmpty())
299 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); 299 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
300 300
301 // completed 301 // completed
302 // status 302 // status
303 // backward compatibility, KOrganizer used to interpret only these two values 303 // backward compatibility, KOrganizer used to interpret only these two values
304 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : 304 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
305 "NEEDS_ACTION"); 305 "NEEDS_ACTION");
306 // completion date 306 // completion date
307 if (anEvent->hasCompletedDate()) { 307 if (anEvent->hasCompletedDate()) {
308 tmpStr = qDateTimeToISO(anEvent->completed()); 308 tmpStr = qDateTimeToISO(anEvent->completed());
309 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); 309 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
310 } 310 }
311 311
312 // priority 312 // priority
313 tmpStr.sprintf("%i",anEvent->priority()); 313 tmpStr.sprintf("%i",anEvent->priority());
314 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); 314 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
315 315
316 // related event 316 // related event
317 if (anEvent->relatedTo()) { 317 if (anEvent->relatedTo()) {
318 addPropValue(vtodo, VCRelatedToProp, 318 addPropValue(vtodo, VCRelatedToProp,
319 anEvent->relatedTo()->uid().local8Bit()); 319 anEvent->relatedTo()->uid().local8Bit());
320 } 320 }
321 321
322 // categories 322 // categories
323 tmpStrList = anEvent->categories(); 323 tmpStrList = anEvent->categories();
324 tmpStr = ""; 324 tmpStr = "";
325 QString catStr; 325 QString catStr;
326 for ( QStringList::Iterator it = tmpStrList.begin(); 326 for ( QStringList::Iterator it = tmpStrList.begin();
327 it != tmpStrList.end(); 327 it != tmpStrList.end();
328 ++it ) { 328 ++it ) {
329 catStr = *it; 329 catStr = *it;
330 if (catStr[0] == ' ') 330 if (catStr[0] == ' ')
331 tmpStr += catStr.mid(1); 331 tmpStr += catStr.mid(1);
332 else 332 else
333 tmpStr += catStr; 333 tmpStr += catStr;
334 // this must be a ';' character as the vCalendar specification requires! 334 // this must be a ';' character as the vCalendar specification requires!
335 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 335 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
336 // read in. 336 // read in.
337 tmpStr += ";"; 337 tmpStr += ";";
338 } 338 }
339 if (!tmpStr.isEmpty()) { 339 if (!tmpStr.isEmpty()) {
340 tmpStr.truncate(tmpStr.length()-1); 340 tmpStr.truncate(tmpStr.length()-1);
341 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); 341 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
342 } 342 }
343 343
344 // alarm stuff 344 // alarm stuff
345 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; 345 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
346 QPtrList<Alarm> alarms = anEvent->alarms(); 346 QPtrList<Alarm> alarms = anEvent->alarms();
347 Alarm* alarm; 347 Alarm* alarm;
348 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 348 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
349 if (alarm->enabled()) { 349 if (alarm->enabled()) {
350 VObject *a = addProp(vtodo, VCDAlarmProp); 350 VObject *a;
351 tmpStr = qDateTimeToISO(alarm->time()); 351 tmpStr = qDateTimeToISO(alarm->time());
352 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 352 if (alarm->type() == Alarm::Audio) {
353 addPropValue(a, VCRepeatCountProp, "1"); 353 a = addProp(vtodo, VCAAlarmProp);
354 addPropValue(a, VCDisplayStringProp, "beep!"); 354 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
355 if (alarm->type() == Alarm::Audio) { 355 addPropValue(a, VCRepeatCountProp, "1");
356 a = addProp(vtodo, VCAAlarmProp); 356 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
357 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 357 }
358 addPropValue(a, VCRepeatCountProp, "1"); 358 else if (alarm->type() == Alarm::Procedure) {
359 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 359 a = addProp(vtodo, VCPAlarmProp);
360 } 360 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
361 else if (alarm->type() == Alarm::Procedure) { 361 addPropValue(a, VCRepeatCountProp, "1");
362 a = addProp(vtodo, VCPAlarmProp); 362 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
363 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 363 } else {
364 addPropValue(a, VCRepeatCountProp, "1"); 364 a = addProp(vtodo, VCDAlarmProp);
365 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 365 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
366 addPropValue(a, VCRepeatCountProp, "1");
367 addPropValue(a, VCDisplayStringProp, "beep!");
366 } 368 }
367 } 369 }
368 } 370 }
369 371
370 if (anEvent->pilotId()) { 372 if (anEvent->pilotId()) {
371 // pilot sync stuff 373 // pilot sync stuff
372 tmpStr.sprintf("%i",anEvent->pilotId()); 374 tmpStr.sprintf("%i",anEvent->pilotId());
373 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); 375 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
374 tmpStr.sprintf("%i",anEvent->syncStatus()); 376 tmpStr.sprintf("%i",anEvent->syncStatus());
375 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); 377 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
376 } 378 }
377 379
378 return vtodo; 380 return vtodo;
379} 381}
380 382
381VObject* VCalFormat::eventToVEvent(const Event *anEvent) 383VObject* VCalFormat::eventToVEvent(const Event *anEvent)
382{ 384{
383 VObject *vevent; 385 VObject *vevent;
384 QString tmpStr; 386 QString tmpStr;
385 QStringList tmpStrList; 387 QStringList tmpStrList;
386 388
387 vevent = newVObject(VCEventProp); 389 vevent = newVObject(VCEventProp);
388 390
389 // start and end time 391 // start and end time
390 tmpStr = qDateTimeToISO(anEvent->dtStart(), 392 tmpStr = qDateTimeToISO(anEvent->dtStart(),
391 !anEvent->doesFloat()); 393 !anEvent->doesFloat());
392 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); 394 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
393 395
394 // events that have time associated but take up no time should 396 // events that have time associated but take up no time should
395 // not have both DTSTART and DTEND. 397 // not have both DTSTART and DTEND.
396 if (anEvent->dtStart() != anEvent->dtEnd()) { 398 if (anEvent->dtStart() != anEvent->dtEnd()) {
397 tmpStr = qDateTimeToISO(anEvent->dtEnd(), 399 tmpStr = qDateTimeToISO(anEvent->dtEnd(),
398 !anEvent->doesFloat()); 400 !anEvent->doesFloat());
399 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); 401 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
400 } 402 }
401 403
402 // creation date 404 // creation date
403 tmpStr = qDateTimeToISO(anEvent->created()); 405 tmpStr = qDateTimeToISO(anEvent->created());
404 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); 406 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
405 407
406 // unique id 408 // unique id
407 addPropValue(vevent, VCUniqueStringProp, 409 addPropValue(vevent, VCUniqueStringProp,
408 anEvent->uid().local8Bit()); 410 anEvent->uid().local8Bit());
409 411
410 // revision 412 // revision
411 tmpStr.sprintf("%i", anEvent->revision()); 413 tmpStr.sprintf("%i", anEvent->revision());
412 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); 414 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
413 415
414 // last modification date 416 // last modification date
415 tmpStr = qDateTimeToISO(anEvent->lastModified()); 417 tmpStr = qDateTimeToISO(anEvent->lastModified());
416 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); 418 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
417 419
418 // attendee and organizer stuff 420 // attendee and organizer stuff
419 tmpStr = "MAILTO:" + anEvent->organizer(); 421 tmpStr = "MAILTO:" + anEvent->organizer();
420 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); 422 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
421 423
422 if (anEvent->attendeeCount() != 0) { 424 if (anEvent->attendeeCount() != 0) {
423 QPtrList<Attendee> al = anEvent->attendees(); 425 QPtrList<Attendee> al = anEvent->attendees();
424 QPtrListIterator<Attendee> ai(al); 426 QPtrListIterator<Attendee> ai(al);
425 Attendee *curAttendee; 427 Attendee *curAttendee;
426 428
427 // TODO: Put this functionality into Attendee class 429 // TODO: Put this functionality into Attendee class
428 for (; ai.current(); ++ai) { 430 for (; ai.current(); ++ai) {
429 curAttendee = ai.current(); 431 curAttendee = ai.current();
430 if (!curAttendee->email().isEmpty() && 432 if (!curAttendee->email().isEmpty() &&
431 !curAttendee->name().isEmpty()) 433 !curAttendee->name().isEmpty())
432 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 434 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
433 curAttendee->email() + ">"; 435 curAttendee->email() + ">";
434 else if (curAttendee->name().isEmpty()) 436 else if (curAttendee->name().isEmpty())
435 tmpStr = "MAILTO: " + curAttendee->email(); 437 tmpStr = "MAILTO: " + curAttendee->email();
436 else if (curAttendee->email().isEmpty()) 438 else if (curAttendee->email().isEmpty())
437 tmpStr = "MAILTO: " + curAttendee->name(); 439 tmpStr = "MAILTO: " + curAttendee->name();
438 else if (curAttendee->name().isEmpty() && 440 else if (curAttendee->name().isEmpty() &&
439 curAttendee->email().isEmpty()) 441 curAttendee->email().isEmpty())
440 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 442 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
441 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); 443 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
442 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; 444 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");;
443 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 445 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
444 } 446 }
445 } 447 }
446 448
447 // recurrence rule stuff 449 // recurrence rule stuff
448 if (anEvent->recurrence()->doesRecur()) { 450 if (anEvent->recurrence()->doesRecur()) {
449 // some more variables 451 // some more variables
450 QPtrList<Recurrence::rMonthPos> tmpPositions; 452 QPtrList<Recurrence::rMonthPos> tmpPositions;
451 QPtrList<int> tmpDays; 453 QPtrList<int> tmpDays;
452 int *tmpDay; 454 int *tmpDay;
453 Recurrence::rMonthPos *tmpPos; 455 Recurrence::rMonthPos *tmpPos;
454 QString tmpStr2; 456 QString tmpStr2;
455 int i; 457 int i;
456 458
457 switch(anEvent->recurrence()->doesRecur()) { 459 switch(anEvent->recurrence()->doesRecur()) {
458 case Recurrence::rDaily: 460 case Recurrence::rDaily:
459 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); 461 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
460// if (anEvent->rDuration > 0) 462// if (anEvent->rDuration > 0)
461 //tmpStr += "#"; 463 //tmpStr += "#";
@@ -532,209 +534,212 @@ VObject* VCalFormat::eventToVEvent(const Event *anEvent)
532 tmpStr += "#0"; // defined as repeat forever 534 tmpStr += "#0"; // defined as repeat forever
533 } else { 535 } else {
534 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); 536 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE);
535 } 537 }
536 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); 538 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
537 539
538 } // event repeats 540 } // event repeats
539 541
540 // exceptions to recurrence 542 // exceptions to recurrence
541 DateList dateList = anEvent->exDates(); 543 DateList dateList = anEvent->exDates();
542 DateList::ConstIterator it; 544 DateList::ConstIterator it;
543 QString tmpStr2; 545 QString tmpStr2;
544 546
545 for (it = dateList.begin(); it != dateList.end(); ++it) { 547 for (it = dateList.begin(); it != dateList.end(); ++it) {
546 tmpStr = qDateToISO(*it) + ";"; 548 tmpStr = qDateToISO(*it) + ";";
547 tmpStr2 += tmpStr; 549 tmpStr2 += tmpStr;
548 } 550 }
549 if (!tmpStr2.isEmpty()) { 551 if (!tmpStr2.isEmpty()) {
550 tmpStr2.truncate(tmpStr2.length()-1); 552 tmpStr2.truncate(tmpStr2.length()-1);
551 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); 553 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit());
552 } 554 }
553 555
554 // description 556 // description
555 if (!anEvent->description().isEmpty()) { 557 if (!anEvent->description().isEmpty()) {
556 VObject *d = addPropValue(vevent, VCDescriptionProp, 558 VObject *d = addPropValue(vevent, VCDescriptionProp,
557 anEvent->description().local8Bit()); 559 anEvent->description().local8Bit());
558 if (anEvent->description().find('\n') != -1) 560 if (anEvent->description().find('\n') != -1)
559 addProp(d, VCQuotedPrintableProp); 561 addProp(d, VCQuotedPrintableProp);
560 } 562 }
561 563
562 // summary 564 // summary
563 if (!anEvent->summary().isEmpty()) 565 if (!anEvent->summary().isEmpty())
564 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); 566 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit());
565 567
566 if (!anEvent->location().isEmpty()) 568 if (!anEvent->location().isEmpty())
567 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); 569 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit());
568 570
569 // status 571 // status
570// TODO: define Event status 572// TODO: define Event status
571// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); 573// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit());
572 574
573 // secrecy 575 // secrecy
574 const char *text = 0; 576 const char *text = 0;
575 switch (anEvent->secrecy()) { 577 switch (anEvent->secrecy()) {
576 case Incidence::SecrecyPublic: 578 case Incidence::SecrecyPublic:
577 text = "PUBLIC"; 579 text = "PUBLIC";
578 break; 580 break;
579 case Incidence::SecrecyPrivate: 581 case Incidence::SecrecyPrivate:
580 text = "PRIVATE"; 582 text = "PRIVATE";
581 break; 583 break;
582 case Incidence::SecrecyConfidential: 584 case Incidence::SecrecyConfidential:
583 text = "CONFIDENTIAL"; 585 text = "CONFIDENTIAL";
584 break; 586 break;
585 } 587 }
586 if (text) { 588 if (text) {
587 addPropValue(vevent, VCClassProp, text); 589 addPropValue(vevent, VCClassProp, text);
588 } 590 }
589 591
590 // categories 592 // categories
591 tmpStrList = anEvent->categories(); 593 tmpStrList = anEvent->categories();
592 tmpStr = ""; 594 tmpStr = "";
593 QString catStr; 595 QString catStr;
594 for ( QStringList::Iterator it = tmpStrList.begin(); 596 for ( QStringList::Iterator it = tmpStrList.begin();
595 it != tmpStrList.end(); 597 it != tmpStrList.end();
596 ++it ) { 598 ++it ) {
597 catStr = *it; 599 catStr = *it;
598 if (catStr[0] == ' ') 600 if (catStr[0] == ' ')
599 tmpStr += catStr.mid(1); 601 tmpStr += catStr.mid(1);
600 else 602 else
601 tmpStr += catStr; 603 tmpStr += catStr;
602 // this must be a ';' character as the vCalendar specification requires! 604 // this must be a ';' character as the vCalendar specification requires!
603 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 605 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
604 // read in. 606 // read in.
605 tmpStr += ";"; 607 tmpStr += ";";
606 } 608 }
607 if (!tmpStr.isEmpty()) { 609 if (!tmpStr.isEmpty()) {
608 tmpStr.truncate(tmpStr.length()-1); 610 tmpStr.truncate(tmpStr.length()-1);
609 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); 611 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
610 } 612 }
611 613
612 // attachments 614 // attachments
613 // TODO: handle binary attachments! 615 // TODO: handle binary attachments!
614 QPtrList<Attachment> attachments = anEvent->attachments(); 616 QPtrList<Attachment> attachments = anEvent->attachments();
615 for ( Attachment *at = attachments.first(); at; at = attachments.next() ) 617 for ( Attachment *at = attachments.first(); at; at = attachments.next() )
616 addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); 618 addPropValue(vevent, VCAttachProp, at->uri().local8Bit());
617 619
618 // resources 620 // resources
619 tmpStrList = anEvent->resources(); 621 tmpStrList = anEvent->resources();
620 tmpStr = tmpStrList.join(";"); 622 tmpStr = tmpStrList.join(";");
621 if (!tmpStr.isEmpty()) 623 if (!tmpStr.isEmpty())
622 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); 624 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
623 625
624 // alarm stuff 626 // alarm stuff
625 QPtrList<Alarm> alarms = anEvent->alarms(); 627 QPtrList<Alarm> alarms = anEvent->alarms();
626 Alarm* alarm; 628 Alarm* alarm;
627 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 629 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
628 if (alarm->enabled()) { 630 if (alarm->enabled()) {
629 VObject *a = addProp(vevent, VCDAlarmProp); 631 VObject *a ;
630 tmpStr = qDateTimeToISO(alarm->time()); 632 tmpStr = qDateTimeToISO(alarm->time());
631 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 633 if (alarm->type() == Alarm::Audio) {
632 addPropValue(a, VCRepeatCountProp, "1"); 634 a = addProp(vevent, VCAAlarmProp);
633 addPropValue(a, VCDisplayStringProp, "beep!"); 635 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
634 if (alarm->type() == Alarm::Audio) { 636 addPropValue(a, VCRepeatCountProp, "1");
635 a = addProp(vevent, VCAAlarmProp); 637 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
636 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 638 }
637 addPropValue(a, VCRepeatCountProp, "1"); 639 if (alarm->type() == Alarm::Procedure) {
638 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 640 a = addProp(vevent, VCPAlarmProp);
639 } 641 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
640 if (alarm->type() == Alarm::Procedure) { 642 addPropValue(a, VCRepeatCountProp, "1");
641 a = addProp(vevent, VCPAlarmProp); 643 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
642 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 644 } else {
643 addPropValue(a, VCRepeatCountProp, "1"); 645 a = addProp(vevent, VCDAlarmProp);
644 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 646 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
647 addPropValue(a, VCRepeatCountProp, "1");
648 addPropValue(a, VCDisplayStringProp, "beep!");
649
645 } 650 }
646 } 651 }
647 } 652 }
648 653
649 // priority 654 // priority
650 tmpStr.sprintf("%i",anEvent->priority()); 655 tmpStr.sprintf("%i",anEvent->priority());
651 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); 656 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
652 657
653 // transparency 658 // transparency
654 tmpStr.sprintf("%i",anEvent->transparency()); 659 tmpStr.sprintf("%i",anEvent->transparency());
655 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); 660 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
656 661
657 // related event 662 // related event
658 if (anEvent->relatedTo()) { 663 if (anEvent->relatedTo()) {
659 addPropValue(vevent, VCRelatedToProp, 664 addPropValue(vevent, VCRelatedToProp,
660 anEvent->relatedTo()->uid().local8Bit()); 665 anEvent->relatedTo()->uid().local8Bit());
661 } 666 }
662 667
663 if (anEvent->pilotId()) { 668 if (anEvent->pilotId()) {
664 // pilot sync stuff 669 // pilot sync stuff
665 tmpStr.sprintf("%i",anEvent->pilotId()); 670 tmpStr.sprintf("%i",anEvent->pilotId());
666 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); 671 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit());
667 tmpStr.sprintf("%i",anEvent->syncStatus()); 672 tmpStr.sprintf("%i",anEvent->syncStatus());
668 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); 673 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit());
669 } 674 }
670 675
671 return vevent; 676 return vevent;
672} 677}
673 678
674Todo *VCalFormat::VTodoToEvent(VObject *vtodo) 679Todo *VCalFormat::VTodoToEvent(VObject *vtodo)
675{ 680{
676 VObject *vo; 681 VObject *vo;
677 VObjectIterator voi; 682 VObjectIterator voi;
678 char *s; 683 char *s;
679 684
680 Todo *anEvent = new Todo; 685 Todo *anEvent = new Todo;
681 686
682 // creation date 687 // creation date
683 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { 688 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
684 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 689 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
685 deleteStr(s); 690 deleteStr(s);
686 } 691 }
687 692
688 // unique id 693 // unique id
689 vo = isAPropertyOf(vtodo, VCUniqueStringProp); 694 vo = isAPropertyOf(vtodo, VCUniqueStringProp);
690 // while the UID property is preferred, it is not required. We'll use the 695 // while the UID property is preferred, it is not required. We'll use the
691 // default Event UID if none is given. 696 // default Event UID if none is given.
692 if (vo) { 697 if (vo) {
693 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 698 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
694 deleteStr(s); 699 deleteStr(s);
695 } 700 }
696 701
697 // last modification date 702 // last modification date
698 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { 703 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
699 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 704 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
700 deleteStr(s); 705 deleteStr(s);
701 } 706 }
702 else 707 else
703 anEvent->setLastModified(QDateTime(QDate::currentDate(), 708 anEvent->setLastModified(QDateTime(QDate::currentDate(),
704 QTime::currentTime())); 709 QTime::currentTime()));
705 710
706 // organizer 711 // organizer
707 // if our extension property for the event's ORGANIZER exists, add it. 712 // if our extension property for the event's ORGANIZER exists, add it.
708 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { 713 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
709 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 714 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
710 deleteStr(s); 715 deleteStr(s);
711 } else { 716 } else {
712 anEvent->setOrganizer(mCalendar->getEmail()); 717 anEvent->setOrganizer(mCalendar->getEmail());
713 } 718 }
714 719
715 // attendees. 720 // attendees.
716 initPropIterator(&voi, vtodo); 721 initPropIterator(&voi, vtodo);
717 while (moreIteration(&voi)) { 722 while (moreIteration(&voi)) {
718 vo = nextVObject(&voi); 723 vo = nextVObject(&voi);
719 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 724 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
720 Attendee *a; 725 Attendee *a;
721 VObject *vp; 726 VObject *vp;
722 s = fakeCString(vObjectUStringZValue(vo)); 727 s = fakeCString(vObjectUStringZValue(vo));
723 QString tmpStr = QString::fromLocal8Bit(s); 728 QString tmpStr = QString::fromLocal8Bit(s);
724 deleteStr(s); 729 deleteStr(s);
725 tmpStr = tmpStr.simplifyWhiteSpace(); 730 tmpStr = tmpStr.simplifyWhiteSpace();
726 int emailPos1, emailPos2; 731 int emailPos1, emailPos2;
727 if ((emailPos1 = tmpStr.find('<')) > 0) { 732 if ((emailPos1 = tmpStr.find('<')) > 0) {
728 // both email address and name 733 // both email address and name
729 emailPos2 = tmpStr.findRev('>'); 734 emailPos2 = tmpStr.findRev('>');
730 a = new Attendee(tmpStr.left(emailPos1 - 1), 735 a = new Attendee(tmpStr.left(emailPos1 - 1),
731 tmpStr.mid(emailPos1 + 1, 736 tmpStr.mid(emailPos1 + 1,
732 emailPos2 - (emailPos1 + 1))); 737 emailPos2 - (emailPos1 + 1)));
733 } else if (tmpStr.find('@') > 0) { 738 } else if (tmpStr.find('@') > 0) {
734 // just an email address 739 // just an email address
735 a = new Attendee(0, tmpStr); 740 a = new Attendee(0, tmpStr);
736 } else { 741 } else {
737 // just a name 742 // just a name
738 QString email = tmpStr.replace( QRegExp(" "), "." ); 743 QString email = tmpStr.replace( QRegExp(" "), "." );
739 a = new Attendee(tmpStr,email); 744 a = new Attendee(tmpStr,email);
740 } 745 }