summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-07 11:30:06 (UTC)
committer zautrix <zautrix>2004-08-07 11:30:06 (UTC)
commit835cc1b2c671bf2ab228362cf4ea2e4a04a1d5e5 (patch) (unidiff)
tree816191299c688a7de051703af11d0ba4f8c8247f
parent55ad0e5d505055016a0e5032bcc8f9355dfff210 (diff)
downloadkdepimpi-835cc1b2c671bf2ab228362cf4ea2e4a04a1d5e5.zip
kdepimpi-835cc1b2c671bf2ab228362cf4ea2e4a04a1d5e5.tar.gz
kdepimpi-835cc1b2c671bf2ab228362cf4ea2e4a04a1d5e5.tar.bz2
More sync stuff converted
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp20
-rw-r--r--libkcal/incidencebase.cpp96
-rw-r--r--libkcal/incidencebase.h13
-rw-r--r--libkcal/sharpformat.cpp20
4 files changed, 45 insertions, 104 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index fab4540..5150455 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -474,994 +474,994 @@ CalendarView::~CalendarView()
474 delete beamDialog; 474 delete beamDialog;
475 //kdDebug() << "~CalendarView() done" << endl; 475 //kdDebug() << "~CalendarView() done" << endl;
476} 476}
477void CalendarView::timerAlarm() 477void CalendarView::timerAlarm()
478{ 478{
479 //qDebug("CalendarView::timerAlarm() "); 479 //qDebug("CalendarView::timerAlarm() ");
480 computeAlarm(mAlarmNotification ); 480 computeAlarm(mAlarmNotification );
481} 481}
482 482
483void CalendarView::suspendAlarm() 483void CalendarView::suspendAlarm()
484{ 484{
485 //qDebug(" CalendarView::suspendAlarm() "); 485 //qDebug(" CalendarView::suspendAlarm() ");
486 computeAlarm(mSuspendAlarmNotification ); 486 computeAlarm(mSuspendAlarmNotification );
487 487
488} 488}
489 489
490void CalendarView::startAlarm( QString mess , QString filename) 490void CalendarView::startAlarm( QString mess , QString filename)
491{ 491{
492 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 492 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
493 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 493 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
494 494
495} 495}
496 496
497void CalendarView::checkNextTimerAlarm() 497void CalendarView::checkNextTimerAlarm()
498{ 498{
499 mCalendar->checkAlarmForIncidence( 0, true ); 499 mCalendar->checkAlarmForIncidence( 0, true );
500} 500}
501 501
502void CalendarView::computeAlarm( QString msg ) 502void CalendarView::computeAlarm( QString msg )
503{ 503{
504 504
505 QString mess = msg; 505 QString mess = msg;
506 QString mAlarmMessage = mess.mid( 9 ); 506 QString mAlarmMessage = mess.mid( 9 );
507 QString filename = MainWindow::resourcePath(); 507 QString filename = MainWindow::resourcePath();
508 filename += "koalarm.wav"; 508 filename += "koalarm.wav";
509 QString tempfilename; 509 QString tempfilename;
510 if ( mess.left( 13 ) == "suspend_alarm") { 510 if ( mess.left( 13 ) == "suspend_alarm") {
511 bool error = false; 511 bool error = false;
512 int len = mess.mid( 13 ).find("+++"); 512 int len = mess.mid( 13 ).find("+++");
513 if ( len < 2 ) 513 if ( len < 2 )
514 error = true; 514 error = true;
515 else { 515 else {
516 tempfilename = mess.mid( 13, len ); 516 tempfilename = mess.mid( 13, len );
517 if ( !QFile::exists( tempfilename ) ) 517 if ( !QFile::exists( tempfilename ) )
518 error = true; 518 error = true;
519 } 519 }
520 if ( ! error ) { 520 if ( ! error ) {
521 filename = tempfilename; 521 filename = tempfilename;
522 } 522 }
523 mAlarmMessage = mess.mid( 13+len+3 ); 523 mAlarmMessage = mess.mid( 13+len+3 );
524 //qDebug("suspend file %s ",tempfilename.latin1() ); 524 //qDebug("suspend file %s ",tempfilename.latin1() );
525 startAlarm( mAlarmMessage, filename); 525 startAlarm( mAlarmMessage, filename);
526 return; 526 return;
527 } 527 }
528 if ( mess.left( 11 ) == "timer_alarm") { 528 if ( mess.left( 11 ) == "timer_alarm") {
529 //mTimerTime = 0; 529 //mTimerTime = 0;
530 startAlarm( mess.mid( 11 ), filename ); 530 startAlarm( mess.mid( 11 ), filename );
531 return; 531 return;
532 } 532 }
533 if ( mess.left( 10 ) == "proc_alarm") { 533 if ( mess.left( 10 ) == "proc_alarm") {
534 bool error = false; 534 bool error = false;
535 int len = mess.mid( 10 ).find("+++"); 535 int len = mess.mid( 10 ).find("+++");
536 if ( len < 2 ) 536 if ( len < 2 )
537 error = true; 537 error = true;
538 else { 538 else {
539 tempfilename = mess.mid( 10, len ); 539 tempfilename = mess.mid( 10, len );
540 if ( !QFile::exists( tempfilename ) ) 540 if ( !QFile::exists( tempfilename ) )
541 error = true; 541 error = true;
542 } 542 }
543 if ( error ) { 543 if ( error ) {
544 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 544 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
545 mAlarmMessage += mess.mid( 10+len+3+9 ); 545 mAlarmMessage += mess.mid( 10+len+3+9 );
546 } else { 546 } else {
547 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 547 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
548 //qDebug("-----system command %s ",tempfilename.latin1() ); 548 //qDebug("-----system command %s ",tempfilename.latin1() );
549#ifndef _WIN32_ 549#ifndef _WIN32_
550 if ( vfork () == 0 ) { 550 if ( vfork () == 0 ) {
551 execl ( tempfilename.latin1(), 0 ); 551 execl ( tempfilename.latin1(), 0 );
552 return; 552 return;
553 } 553 }
554#else 554#else
555 QProcess* p = new QProcess(); 555 QProcess* p = new QProcess();
556 p->addArgument( tempfilename.latin1() ); 556 p->addArgument( tempfilename.latin1() );
557 p->start(); 557 p->start();
558 return; 558 return;
559#endif 559#endif
560 560
561 return; 561 return;
562 } 562 }
563 563
564 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 564 //qDebug("+++++++system command %s ",tempfilename.latin1() );
565 } 565 }
566 if ( mess.left( 11 ) == "audio_alarm") { 566 if ( mess.left( 11 ) == "audio_alarm") {
567 bool error = false; 567 bool error = false;
568 int len = mess.mid( 11 ).find("+++"); 568 int len = mess.mid( 11 ).find("+++");
569 if ( len < 2 ) 569 if ( len < 2 )
570 error = true; 570 error = true;
571 else { 571 else {
572 tempfilename = mess.mid( 11, len ); 572 tempfilename = mess.mid( 11, len );
573 if ( !QFile::exists( tempfilename ) ) 573 if ( !QFile::exists( tempfilename ) )
574 error = true; 574 error = true;
575 } 575 }
576 if ( ! error ) { 576 if ( ! error ) {
577 filename = tempfilename; 577 filename = tempfilename;
578 } 578 }
579 mAlarmMessage = mess.mid( 11+len+3+9 ); 579 mAlarmMessage = mess.mid( 11+len+3+9 );
580 //qDebug("audio file command %s ",tempfilename.latin1() ); 580 //qDebug("audio file command %s ",tempfilename.latin1() );
581 } 581 }
582 if ( mess.left( 9 ) == "cal_alarm") { 582 if ( mess.left( 9 ) == "cal_alarm") {
583 mAlarmMessage = mess.mid( 9 ) ; 583 mAlarmMessage = mess.mid( 9 ) ;
584 } 584 }
585 585
586 startAlarm( mAlarmMessage, filename ); 586 startAlarm( mAlarmMessage, filename );
587 587
588 588
589} 589}
590 590
591void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 591void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
592{ 592{
593 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 593 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
594 594
595 mSuspendAlarmNotification = noti; 595 mSuspendAlarmNotification = noti;
596 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 596 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
597 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 597 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
598 mSuspendTimer->start( ms , true ); 598 mSuspendTimer->start( ms , true );
599 599
600} 600}
601 601
602void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 602void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
603{ 603{
604 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 604 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
605 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 605 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
606#ifndef DESKTOP_VERSION 606#ifndef DESKTOP_VERSION
607 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 607 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
608#endif 608#endif
609 return; 609 return;
610 } 610 }
611 int maxSec; 611 int maxSec;
612 //maxSec = 5; //testing only 612 //maxSec = 5; //testing only
613 maxSec = 86400+3600; // one day+1hour 613 maxSec = 86400+3600; // one day+1hour
614 mAlarmNotification = noti; 614 mAlarmNotification = noti;
615 int sec = QDateTime::currentDateTime().secsTo( qdt ); 615 int sec = QDateTime::currentDateTime().secsTo( qdt );
616 if ( sec > maxSec ) { 616 if ( sec > maxSec ) {
617 mRecheckAlarmTimer->start( maxSec * 1000 ); 617 mRecheckAlarmTimer->start( maxSec * 1000 );
618 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 618 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
619 return; 619 return;
620 } else { 620 } else {
621 mRecheckAlarmTimer->stop(); 621 mRecheckAlarmTimer->stop();
622 } 622 }
623 //qDebug("Alarm timer started with secs: %d ", sec); 623 //qDebug("Alarm timer started with secs: %d ", sec);
624 mAlarmTimer->start( sec *1000 , true ); 624 mAlarmTimer->start( sec *1000 , true );
625 625
626} 626}
627// called by mRecheckAlarmTimer to get next alarm 627// called by mRecheckAlarmTimer to get next alarm
628// we need this, because a QTimer has only a max range of 25 days 628// we need this, because a QTimer has only a max range of 25 days
629void CalendarView::recheckTimerAlarm() 629void CalendarView::recheckTimerAlarm()
630{ 630{
631 mAlarmTimer->stop(); 631 mAlarmTimer->stop();
632 mRecheckAlarmTimer->stop(); 632 mRecheckAlarmTimer->stop();
633 mCalendar->checkAlarmForIncidence( 0, true ); 633 mCalendar->checkAlarmForIncidence( 0, true );
634} 634}
635void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 635void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
636{ 636{
637 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 637 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
638 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 638 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
639#ifndef DESKTOP_VERSION 639#ifndef DESKTOP_VERSION
640 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 640 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
641#endif 641#endif
642 return; 642 return;
643 } 643 }
644 mAlarmTimer->stop(); 644 mAlarmTimer->stop();
645} 645}
646void CalendarView::selectWeekNum ( int num ) 646void CalendarView::selectWeekNum ( int num )
647{ 647{
648 dateNavigator()->selectWeek( num ); 648 dateNavigator()->selectWeek( num );
649 mViewManager->showWeekView(); 649 mViewManager->showWeekView();
650} 650}
651KOViewManager *CalendarView::viewManager() 651KOViewManager *CalendarView::viewManager()
652{ 652{
653 return mViewManager; 653 return mViewManager;
654} 654}
655 655
656KODialogManager *CalendarView::dialogManager() 656KODialogManager *CalendarView::dialogManager()
657{ 657{
658 return mDialogManager; 658 return mDialogManager;
659} 659}
660 660
661QDate CalendarView::startDate() 661QDate CalendarView::startDate()
662{ 662{
663 DateList dates = mNavigator->selectedDates(); 663 DateList dates = mNavigator->selectedDates();
664 664
665 return dates.first(); 665 return dates.first();
666} 666}
667 667
668QDate CalendarView::endDate() 668QDate CalendarView::endDate()
669{ 669{
670 DateList dates = mNavigator->selectedDates(); 670 DateList dates = mNavigator->selectedDates();
671 671
672 return dates.last(); 672 return dates.last();
673} 673}
674 674
675 675
676void CalendarView::createPrinter() 676void CalendarView::createPrinter()
677{ 677{
678#ifndef KORG_NOPRINTER 678#ifndef KORG_NOPRINTER
679 if (!mCalPrinter) { 679 if (!mCalPrinter) {
680 mCalPrinter = new CalPrinter(this, mCalendar); 680 mCalPrinter = new CalPrinter(this, mCalendar);
681 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 681 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
682 } 682 }
683#endif 683#endif
684} 684}
685 685
686void CalendarView::confSync() 686void CalendarView::confSync()
687{ 687{
688 static KSyncPrefsDialog* sp = 0; 688 static KSyncPrefsDialog* sp = 0;
689 if ( ! sp ) { 689 if ( ! sp ) {
690 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 690 sp = new KSyncPrefsDialog( this, "syncprefs", true );
691 } 691 }
692 sp->usrReadConfig(); 692 sp->usrReadConfig();
693#ifndef DESKTOP_VERSION 693#ifndef DESKTOP_VERSION
694 sp->showMaximized(); 694 sp->showMaximized();
695#else 695#else
696 sp->show(); 696 sp->show();
697#endif 697#endif
698 sp->exec(); 698 sp->exec();
699 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 699 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
700 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 700 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 //void setZaurusId(int id); 717 //void setZaurusId(int id);
718 // int zaurusId() const; 718 // int zaurusId() const;
719 // void setZaurusUid(int id); 719 // void setZaurusUid(int id);
720 // int zaurusUid() const; 720 // int zaurusUid() const;
721 // void setZaurusStat(int id); 721 // void setZaurusStat(int id);
722 // int zaurusStat() const; 722 // int zaurusStat() const;
723 // 0 equal 723 // 0 equal
724 // 1 take local 724 // 1 take local
725 // 2 take remote 725 // 2 take remote
726 // 3 cancel 726 // 3 cancel
727 QDateTime lastSync = mLastCalendarSync; 727 QDateTime lastSync = mLastCalendarSync;
728 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 728 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
729 bool remCh, locCh; 729 bool remCh, locCh;
730 remCh = ( remote->zaurusUid() != local->zaurusUid() ); 730 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
731 locCh = ( local->lastModified() > mLastCalendarSync ); 731 locCh = ( local->lastModified() > mLastCalendarSync );
732 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); 732 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
733 if ( !remCh && ! locCh ) { 733 if ( !remCh && ! locCh ) {
734 //qDebug("both not changed "); 734 //qDebug("both not changed ");
735 lastSync = local->lastModified().addDays(1); 735 lastSync = local->lastModified().addDays(1);
736 } else { 736 } else {
737 if ( locCh ) { 737 if ( locCh ) {
738 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); 738 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() );
739 lastSync = local->lastModified().addDays( -1 ); 739 lastSync = local->lastModified().addDays( -1 );
740 if ( !remCh ) 740 if ( !remCh )
741 remote->setLastModified( lastSync.addDays( -1 ) ); 741 remote->setLastModified( lastSync.addDays( -1 ) );
742 } else { 742 } else {
743 //qDebug(" not loc changed "); 743 //qDebug(" not loc changed ");
744 lastSync = local->lastModified().addDays( 1 ); 744 lastSync = local->lastModified().addDays( 1 );
745 if ( remCh ) 745 if ( remCh )
746 remote->setLastModified( lastSync.addDays( 1 ) ); 746 remote->setLastModified( lastSync.addDays( 1 ) );
747 747
748 } 748 }
749 } 749 }
750 full = true; 750 full = true;
751 if ( mode < SYNC_PREF_ASK ) 751 if ( mode < SYNC_PREF_ASK )
752 mode = SYNC_PREF_ASK; 752 mode = SYNC_PREF_ASK;
753 } else { 753 } else {
754 if ( local->lastModified() == remote->lastModified() ) 754 if ( local->lastModified() == remote->lastModified() )
755 if ( local->revision() == remote->revision() ) 755 if ( local->revision() == remote->revision() )
756 return 0; 756 return 0;
757 757
758 } 758 }
759 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 759 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
760 760
761 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 761 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
762 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 762 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
763 //full = true; //debug only 763 //full = true; //debug only
764 if ( full ) { 764 if ( full ) {
765 bool equ = false; 765 bool equ = false;
766 if ( local->type() == "Event" ) { 766 if ( local->type() == "Event" ) {
767 equ = (*((Event*) local) == *((Event*) remote)); 767 equ = (*((Event*) local) == *((Event*) remote));
768 } 768 }
769 else if ( local->type() =="Todo" ) 769 else if ( local->type() =="Todo" )
770 equ = (*((Todo*) local) == (*(Todo*) remote)); 770 equ = (*((Todo*) local) == (*(Todo*) remote));
771 else if ( local->type() =="Journal" ) 771 else if ( local->type() =="Journal" )
772 equ = (*((Journal*) local) == *((Journal*) remote)); 772 equ = (*((Journal*) local) == *((Journal*) remote));
773 if ( equ ) { 773 if ( equ ) {
774 //qDebug("equal "); 774 //qDebug("equal ");
775 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 775 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
776 local->setZaurusUid( remote->zaurusUid() ); 776 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
777 } 777 }
778 if ( mode < SYNC_PREF_FORCE_LOCAL ) 778 if ( mode < SYNC_PREF_FORCE_LOCAL )
779 return 0; 779 return 0;
780 780
781 }//else //debug only 781 }//else //debug only
782 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 782 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
783 } 783 }
784 int result; 784 int result;
785 bool localIsNew; 785 bool localIsNew;
786 if ( full && mode < SYNC_PREF_NEWEST ) 786 if ( full && mode < SYNC_PREF_NEWEST )
787 mode = SYNC_PREF_ASK; 787 mode = SYNC_PREF_ASK;
788 788
789 switch( mode ) { 789 switch( mode ) {
790 case SYNC_PREF_LOCAL: 790 case SYNC_PREF_LOCAL:
791 if ( lastSync > remote->lastModified() ) 791 if ( lastSync > remote->lastModified() )
792 return 1; 792 return 1;
793 if ( lastSync > local->lastModified() ) 793 if ( lastSync > local->lastModified() )
794 return 2; 794 return 2;
795 return 1; 795 return 1;
796 break; 796 break;
797 case SYNC_PREF_REMOTE: 797 case SYNC_PREF_REMOTE:
798 if ( lastSync > remote->lastModified() ) 798 if ( lastSync > remote->lastModified() )
799 return 1; 799 return 1;
800 if ( lastSync > local->lastModified() ) 800 if ( lastSync > local->lastModified() )
801 return 2; 801 return 2;
802 return 2; 802 return 2;
803 break; 803 break;
804 case SYNC_PREF_NEWEST: 804 case SYNC_PREF_NEWEST:
805 if ( local->lastModified() > remote->lastModified() ) 805 if ( local->lastModified() > remote->lastModified() )
806 return 1; 806 return 1;
807 else 807 else
808 return 2; 808 return 2;
809 break; 809 break;
810 case SYNC_PREF_ASK: 810 case SYNC_PREF_ASK:
811 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 811 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
812 if ( lastSync > remote->lastModified() ) 812 if ( lastSync > remote->lastModified() )
813 return 1; 813 return 1;
814 if ( lastSync > local->lastModified() ) 814 if ( lastSync > local->lastModified() )
815 return 2; 815 return 2;
816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
817 localIsNew = local->lastModified() > remote->lastModified(); 817 localIsNew = local->lastModified() > remote->lastModified();
818 if ( localIsNew ) 818 if ( localIsNew )
819 getEventViewerDialog()->setColorMode( 1 ); 819 getEventViewerDialog()->setColorMode( 1 );
820 else 820 else
821 getEventViewerDialog()->setColorMode( 2 ); 821 getEventViewerDialog()->setColorMode( 2 );
822 getEventViewerDialog()->setIncidence(local); 822 getEventViewerDialog()->setIncidence(local);
823 if ( localIsNew ) 823 if ( localIsNew )
824 getEventViewerDialog()->setColorMode( 2 ); 824 getEventViewerDialog()->setColorMode( 2 );
825 else 825 else
826 getEventViewerDialog()->setColorMode( 1 ); 826 getEventViewerDialog()->setColorMode( 1 );
827 getEventViewerDialog()->addIncidence(remote); 827 getEventViewerDialog()->addIncidence(remote);
828 getEventViewerDialog()->setColorMode( 0 ); 828 getEventViewerDialog()->setColorMode( 0 );
829 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 829 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
830 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 830 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
831 getEventViewerDialog()->showMe(); 831 getEventViewerDialog()->showMe();
832 result = getEventViewerDialog()->executeS( localIsNew ); 832 result = getEventViewerDialog()->executeS( localIsNew );
833 return result; 833 return result;
834 834
835 break; 835 break;
836 case SYNC_PREF_FORCE_LOCAL: 836 case SYNC_PREF_FORCE_LOCAL:
837 return 1; 837 return 1;
838 break; 838 break;
839 case SYNC_PREF_FORCE_REMOTE: 839 case SYNC_PREF_FORCE_REMOTE:
840 return 2; 840 return 2;
841 break; 841 break;
842 842
843 default: 843 default:
844 // SYNC_PREF_TAKE_BOTH not implemented 844 // SYNC_PREF_TAKE_BOTH not implemented
845 break; 845 break;
846 } 846 }
847 return 0; 847 return 0;
848} 848}
849Event* CalendarView::getLastSyncEvent() 849Event* CalendarView::getLastSyncEvent()
850{ 850{
851 Event* lse; 851 Event* lse;
852 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 852 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
853 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 853 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
854 if (!lse) { 854 if (!lse) {
855 lse = new Event(); 855 lse = new Event();
856 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 856 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
857 QString sum = ""; 857 QString sum = "";
858 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 858 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
859 sum = "E: "; 859 sum = "E: ";
860 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 860 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
861 lse->setDtStart( mLastCalendarSync ); 861 lse->setDtStart( mLastCalendarSync );
862 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 862 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
863 lse->setCategories( i18n("SyncEvent") ); 863 lse->setCategories( i18n("SyncEvent") );
864 lse->setReadOnly( true ); 864 lse->setReadOnly( true );
865 mCalendar->addEvent( lse ); 865 mCalendar->addEvent( lse );
866 } 866 }
867 867
868 return lse; 868 return lse;
869 869
870} 870}
871// probaly useless 871// probaly useless
872void CalendarView::setupExternSyncProfiles() 872void CalendarView::setupExternSyncProfiles()
873{ 873{
874 Event* lse; 874 Event* lse;
875 mExternLastSyncEvent.clear(); 875 mExternLastSyncEvent.clear();
876 int i; 876 int i;
877 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 877 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
878 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 878 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
879 if ( lse ) 879 if ( lse )
880 mExternLastSyncEvent.append( lse ); 880 mExternLastSyncEvent.append( lse );
881 else 881 else
882 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 882 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
883 } 883 }
884 884
885} 885}
886// we check, if the to delete event has a id for a profile 886// we check, if the to delete event has a id for a profile
887// if yes, we set this id in the profile to delete 887// if yes, we set this id in the profile to delete
888void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 888void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
889{ 889{
890 if ( ! lastSync.count() == 0 ) 890 if ( ! lastSync.count() == 0 )
891 return; 891 return;
892 if ( toDelete->type() == "Journal" ) 892 if ( toDelete->type() == "Journal" )
893 return; 893 return;
894 894
895 Event* eve = lastSync.first(); 895 Event* eve = lastSync.first();
896 896
897 while ( eve ) { 897 while ( eve ) {
898 int id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 898 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
899 if ( id >= 0 ) { 899 if ( !id.isEmpty() ) {
900 QString des = eve->description(); 900 QString des = eve->description();
901 QString pref = "e"; 901 QString pref = "e";
902 if ( toDelete->type() == "Todo" ) 902 if ( toDelete->type() == "Todo" )
903 pref = "t"; 903 pref = "t";
904 des += pref+ QString::number ( id ) + ","; 904 des += pref+ id + ",";
905 eve->setReadOnly( false ); 905 eve->setReadOnly( false );
906 eve->setDescription( des ); 906 eve->setDescription( des );
907 eve->setReadOnly( true ); 907 eve->setReadOnly( true );
908 } 908 }
909 eve = lastSync.next(); 909 eve = lastSync.next();
910 } 910 }
911 911
912} 912}
913void CalendarView::checkExternalId( Incidence * inc ) 913void CalendarView::checkExternalId( Incidence * inc )
914{ 914{
915 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 915 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
916 checkExternSyncEvent( lastSync, inc ); 916 checkExternSyncEvent( lastSync, inc );
917 917
918} 918}
919bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 919bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
920{ 920{
921 bool syncOK = true; 921 bool syncOK = true;
922 int addedEvent = 0; 922 int addedEvent = 0;
923 int addedEventR = 0; 923 int addedEventR = 0;
924 int deletedEventR = 0; 924 int deletedEventR = 0;
925 int deletedEventL = 0; 925 int deletedEventL = 0;
926 int changedLocal = 0; 926 int changedLocal = 0;
927 int changedRemote = 0; 927 int changedRemote = 0;
928 //QPtrList<Event> el = local->rawEvents(); 928 //QPtrList<Event> el = local->rawEvents();
929 Event* eventR; 929 Event* eventR;
930 QString uid; 930 QString uid;
931 int take; 931 int take;
932 Event* eventL; 932 Event* eventL;
933 Event* eventRSync; 933 Event* eventRSync;
934 Event* eventLSync; 934 Event* eventLSync;
935 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 935 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
936 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 936 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
937 bool fullDateRange = false; 937 bool fullDateRange = false;
938 mLastCalendarSync = QDateTime::currentDateTime(); 938 mLastCalendarSync = QDateTime::currentDateTime();
939 QDateTime modifiedCalendar = mLastCalendarSync;; 939 QDateTime modifiedCalendar = mLastCalendarSync;;
940 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 940 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
941 if ( eventR ) { 941 if ( eventR ) {
942 eventRSync = (Event*) eventR->clone(); 942 eventRSync = (Event*) eventR->clone();
943 remote->deleteEvent(eventR ); 943 remote->deleteEvent(eventR );
944 944
945 } else { 945 } else {
946 fullDateRange = true; 946 fullDateRange = true;
947 eventRSync = new Event(); 947 eventRSync = new Event();
948 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 948 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
949 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 949 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
950 eventRSync->setDtStart( mLastCalendarSync ); 950 eventRSync->setDtStart( mLastCalendarSync );
951 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 951 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
952 eventRSync->setCategories( i18n("SyncEvent") ); 952 eventRSync->setCategories( i18n("SyncEvent") );
953 } 953 }
954 eventLSync = getLastSyncEvent(); 954 eventLSync = getLastSyncEvent();
955 if ( eventLSync->dtStart() == mLastCalendarSync ) 955 if ( eventLSync->dtStart() == mLastCalendarSync )
956 fullDateRange = true; 956 fullDateRange = true;
957 957
958 if ( ! fullDateRange ) { 958 if ( ! fullDateRange ) {
959 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 959 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
960 960
961 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 961 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
962 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 962 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
963 fullDateRange = true; 963 fullDateRange = true;
964 } 964 }
965 } 965 }
966 if ( fullDateRange ) 966 if ( fullDateRange )
967 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 967 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
968 else 968 else
969 mLastCalendarSync = eventLSync->dtStart(); 969 mLastCalendarSync = eventLSync->dtStart();
970 // for resyncing if own file has changed 970 // for resyncing if own file has changed
971 if ( mCurrentSyncDevice == "deleteaftersync" ) { 971 if ( mCurrentSyncDevice == "deleteaftersync" ) {
972 mLastCalendarSync = loadedFileVersion; 972 mLastCalendarSync = loadedFileVersion;
973 qDebug("setting mLastCalendarSync "); 973 qDebug("setting mLastCalendarSync ");
974 } 974 }
975 //qDebug("*************************** "); 975 //qDebug("*************************** ");
976 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 976 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
977 QPtrList<Incidence> er = remote->rawIncidences(); 977 QPtrList<Incidence> er = remote->rawIncidences();
978 Incidence* inR = er.first(); 978 Incidence* inR = er.first();
979 Incidence* inL; 979 Incidence* inL;
980 QProgressBar bar( er.count(),0 ); 980 QProgressBar bar( er.count(),0 );
981 bar.setCaption (i18n("Syncing - close to abort!") ); 981 bar.setCaption (i18n("Syncing - close to abort!") );
982 982
983 int w = 300; 983 int w = 300;
984 if ( QApplication::desktop()->width() < 320 ) 984 if ( QApplication::desktop()->width() < 320 )
985 w = 220; 985 w = 220;
986 int h = bar.sizeHint().height() ; 986 int h = bar.sizeHint().height() ;
987 int dw = QApplication::desktop()->width(); 987 int dw = QApplication::desktop()->width();
988 int dh = QApplication::desktop()->height(); 988 int dh = QApplication::desktop()->height();
989 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 989 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
990 bar.show(); 990 bar.show();
991 int modulo = (er.count()/10)+1; 991 int modulo = (er.count()/10)+1;
992 int incCounter = 0; 992 int incCounter = 0;
993 while ( inR ) { 993 while ( inR ) {
994 if ( ! bar.isVisible() ) 994 if ( ! bar.isVisible() )
995 return false; 995 return false;
996 if ( incCounter % modulo == 0 ) 996 if ( incCounter % modulo == 0 )
997 bar.setProgress( incCounter ); 997 bar.setProgress( incCounter );
998 ++incCounter; 998 ++incCounter;
999 uid = inR->uid(); 999 uid = inR->uid();
1000 bool skipIncidence = false; 1000 bool skipIncidence = false;
1001 if ( uid.left(15) == QString("last-syncEvent-") ) 1001 if ( uid.left(15) == QString("last-syncEvent-") )
1002 skipIncidence = true; 1002 skipIncidence = true;
1003 1003
1004 qApp->processEvents(); 1004 qApp->processEvents();
1005 if ( !skipIncidence ) { 1005 if ( !skipIncidence ) {
1006 inL = local->incidence( uid ); 1006 inL = local->incidence( uid );
1007 if ( inL ) { // maybe conflict - same uid in both calendars 1007 if ( inL ) { // maybe conflict - same uid in both calendars
1008 int maxrev = inL->revision(); 1008 int maxrev = inL->revision();
1009 if ( maxrev < inR->revision() ) 1009 if ( maxrev < inR->revision() )
1010 maxrev = inR->revision(); 1010 maxrev = inR->revision();
1011 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1011 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1012 //qDebug("take %d %s ", take, inL->summary().latin1()); 1012 //qDebug("take %d %s ", take, inL->summary().latin1());
1013 if ( take == 3 ) 1013 if ( take == 3 )
1014 return false; 1014 return false;
1015 if ( take == 1 ) {// take local 1015 if ( take == 1 ) {// take local
1016 inL->setZaurusUid( inR->zaurusUid() ); 1016 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1017 remote->deleteIncidence( inR ); 1017 remote->deleteIncidence( inR );
1018 if ( inL->revision() < maxrev ) 1018 if ( inL->revision() < maxrev )
1019 inL->setRevision( maxrev ); 1019 inL->setRevision( maxrev );
1020 remote->addIncidence( inL->clone() ); 1020 remote->addIncidence( inL->clone() );
1021 ++changedRemote; 1021 ++changedRemote;
1022 } else { 1022 } else {
1023 if ( inR->revision() < maxrev ) 1023 if ( inR->revision() < maxrev )
1024 inR->setRevision( maxrev ); 1024 inR->setRevision( maxrev );
1025 local->deleteIncidence( inL ); 1025 local->deleteIncidence( inL );
1026 local->addIncidence( inR->clone() ); 1026 local->addIncidence( inR->clone() );
1027 ++changedLocal; 1027 ++changedLocal;
1028 } 1028 }
1029 } 1029 }
1030 } else { // no conflict 1030 } else { // no conflict
1031 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1031 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1032 QString des = eventLSync->description(); 1032 QString des = eventLSync->description();
1033 QString pref = "e"; 1033 QString pref = "e";
1034 if ( inR->type() == "Todo" ) 1034 if ( inR->type() == "Todo" )
1035 pref = "t"; 1035 pref = "t";
1036 if ( des.find(pref+QString::number( inR->getID(mCurrentSyncDevice) ) +"," ) >= 0 && mode != 5) { // delete it 1036 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1037 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1037 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1038 //remote->deleteIncidence( inR ); 1038 //remote->deleteIncidence( inR );
1039 ++deletedEventR; 1039 ++deletedEventR;
1040 } else { 1040 } else {
1041 inR->setLastModified( modifiedCalendar ); 1041 inR->setLastModified( modifiedCalendar );
1042 local->addIncidence( inR->clone() ); 1042 local->addIncidence( inR->clone() );
1043 ++addedEvent; 1043 ++addedEvent;
1044 } 1044 }
1045 } else { 1045 } else {
1046 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1046 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1047 inR->setLastModified( modifiedCalendar ); 1047 inR->setLastModified( modifiedCalendar );
1048 local->addIncidence( inR->clone() ); 1048 local->addIncidence( inR->clone() );
1049 ++addedEvent; 1049 ++addedEvent;
1050 } else { 1050 } else {
1051 checkExternSyncEvent(eventRSyncSharp, inR); 1051 checkExternSyncEvent(eventRSyncSharp, inR);
1052 remote->deleteIncidence( inR ); 1052 remote->deleteIncidence( inR );
1053 ++deletedEventR; 1053 ++deletedEventR;
1054 } 1054 }
1055 } 1055 }
1056 } 1056 }
1057 } 1057 }
1058 inR = er.next(); 1058 inR = er.next();
1059 } 1059 }
1060 QPtrList<Incidence> el = local->rawIncidences(); 1060 QPtrList<Incidence> el = local->rawIncidences();
1061 inL = el.first(); 1061 inL = el.first();
1062 modulo = (el.count()/10)+1; 1062 modulo = (el.count()/10)+1;
1063 bar.setCaption (i18n("Add / remove events") ); 1063 bar.setCaption (i18n("Add / remove events") );
1064 bar.setTotalSteps ( el.count() ) ; 1064 bar.setTotalSteps ( el.count() ) ;
1065 bar.show(); 1065 bar.show();
1066 incCounter = 0; 1066 incCounter = 0;
1067 1067
1068 while ( inL ) { 1068 while ( inL ) {
1069 1069
1070 qApp->processEvents(); 1070 qApp->processEvents();
1071 if ( ! bar.isVisible() ) 1071 if ( ! bar.isVisible() )
1072 return false; 1072 return false;
1073 if ( incCounter % modulo == 0 ) 1073 if ( incCounter % modulo == 0 )
1074 bar.setProgress( incCounter ); 1074 bar.setProgress( incCounter );
1075 ++incCounter; 1075 ++incCounter;
1076 uid = inL->uid(); 1076 uid = inL->uid();
1077 bool skipIncidence = false; 1077 bool skipIncidence = false;
1078 if ( uid.left(15) == QString("last-syncEvent-") ) 1078 if ( uid.left(15) == QString("last-syncEvent-") )
1079 skipIncidence = true; 1079 skipIncidence = true;
1080 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1080 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1081 skipIncidence = true; 1081 skipIncidence = true;
1082 if ( !skipIncidence ) { 1082 if ( !skipIncidence ) {
1083 inR = remote->incidence( uid ); 1083 inR = remote->incidence( uid );
1084 if ( ! inR ) { 1084 if ( ! inR ) {
1085 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1085 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1086 if ( inL->getID(mCurrentSyncDevice) >= 0 && mode != 4 ) { 1086 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1087 local->deleteIncidence( inL ); 1087 local->deleteIncidence( inL );
1088 ++deletedEventL; 1088 ++deletedEventL;
1089 } else { 1089 } else {
1090 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1090 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1091 inL->setID(mCurrentSyncDevice, -1 ); 1091 inL->removeID(mCurrentSyncDevice );
1092 ++addedEventR; 1092 ++addedEventR;
1093 inL->setLastModified( modifiedCalendar ); 1093 inL->setLastModified( modifiedCalendar );
1094 remote->addIncidence( inL->clone() ); 1094 remote->addIncidence( inL->clone() );
1095 } 1095 }
1096 } 1096 }
1097 } else { 1097 } else {
1098 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1098 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1099 checkExternSyncEvent(eventLSyncSharp, inL); 1099 checkExternSyncEvent(eventLSyncSharp, inL);
1100 local->deleteIncidence( inL ); 1100 local->deleteIncidence( inL );
1101 ++deletedEventL; 1101 ++deletedEventL;
1102 } else { 1102 } else {
1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1104 ++addedEventR; 1104 ++addedEventR;
1105 inL->setLastModified( modifiedCalendar ); 1105 inL->setLastModified( modifiedCalendar );
1106 remote->addIncidence( inL->clone() ); 1106 remote->addIncidence( inL->clone() );
1107 } 1107 }
1108 } 1108 }
1109 } 1109 }
1110 } 1110 }
1111 } 1111 }
1112 inL = el.next(); 1112 inL = el.next();
1113 } 1113 }
1114 1114
1115 bar.hide(); 1115 bar.hide();
1116 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1116 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1117 eventLSync->setReadOnly( false ); 1117 eventLSync->setReadOnly( false );
1118 eventLSync->setDtStart( mLastCalendarSync ); 1118 eventLSync->setDtStart( mLastCalendarSync );
1119 eventRSync->setDtStart( mLastCalendarSync ); 1119 eventRSync->setDtStart( mLastCalendarSync );
1120 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1120 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1121 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1121 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1122 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1122 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1123 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1123 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1124 eventLSync->setReadOnly( true ); 1124 eventLSync->setReadOnly( true );
1125 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1125 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1126 remote->addEvent( eventRSync ); 1126 remote->addEvent( eventRSync );
1127 QString mes; 1127 QString mes;
1128 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1128 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1129 if ( KOPrefs::instance()->mShowSyncSummary ) { 1129 if ( KOPrefs::instance()->mShowSyncSummary ) {
1130 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1130 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1131 } 1131 }
1132 qDebug( mes ); 1132 qDebug( mes );
1133 mCalendar->checkAlarmForIncidence( 0, true ); 1133 mCalendar->checkAlarmForIncidence( 0, true );
1134 return syncOK; 1134 return syncOK;
1135} 1135}
1136 1136
1137void CalendarView::setSyncDevice( QString s ) 1137void CalendarView::setSyncDevice( QString s )
1138{ 1138{
1139 mCurrentSyncDevice= s; 1139 mCurrentSyncDevice= s;
1140} 1140}
1141void CalendarView::setSyncName( QString s ) 1141void CalendarView::setSyncName( QString s )
1142{ 1142{
1143 mCurrentSyncName= s; 1143 mCurrentSyncName= s;
1144} 1144}
1145bool CalendarView::syncCalendar(QString filename, int mode) 1145bool CalendarView::syncCalendar(QString filename, int mode)
1146{ 1146{
1147 mGlobalSyncMode = SYNC_MODE_NORMAL; 1147 mGlobalSyncMode = SYNC_MODE_NORMAL;
1148 CalendarLocal* calendar = new CalendarLocal(); 1148 CalendarLocal* calendar = new CalendarLocal();
1149 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1149 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1150 FileStorage* storage = new FileStorage( calendar ); 1150 FileStorage* storage = new FileStorage( calendar );
1151 bool syncOK = false; 1151 bool syncOK = false;
1152 storage->setFileName( filename ); 1152 storage->setFileName( filename );
1153 // qDebug("loading ... "); 1153 // qDebug("loading ... ");
1154 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1154 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1155 getEventViewerDialog()->setSyncMode( true ); 1155 getEventViewerDialog()->setSyncMode( true );
1156 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1156 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1157 getEventViewerDialog()->setSyncMode( false ); 1157 getEventViewerDialog()->setSyncMode( false );
1158 if ( syncOK ) { 1158 if ( syncOK ) {
1159 if ( KOPrefs::instance()->mWriteBackFile ) 1159 if ( KOPrefs::instance()->mWriteBackFile )
1160 { 1160 {
1161 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1161 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1162 storage->save(); 1162 storage->save();
1163 } 1163 }
1164 } 1164 }
1165 setModified( true ); 1165 setModified( true );
1166 } 1166 }
1167 delete storage; 1167 delete storage;
1168 delete calendar; 1168 delete calendar;
1169 if ( syncOK ) 1169 if ( syncOK )
1170 updateView(); 1170 updateView();
1171 return syncOK; 1171 return syncOK;
1172} 1172}
1173void CalendarView::syncSharp() 1173void CalendarView::syncSharp()
1174{ 1174{
1175#ifndef DESKTOP_VERSION 1175#ifndef DESKTOP_VERSION
1176 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1176 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1177 //mCurrentSyncDevice = "sharp-DTM"; 1177 //mCurrentSyncDevice = "sharp-DTM";
1178 if ( KOPrefs::instance()->mAskForPreferences ) 1178 if ( KOPrefs::instance()->mAskForPreferences )
1179 edit_sync_options(); 1179 edit_sync_options();
1180 qApp->processEvents(); 1180 qApp->processEvents();
1181 CalendarLocal* calendar = new CalendarLocal(); 1181 CalendarLocal* calendar = new CalendarLocal();
1182 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1182 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1183 bool syncOK = false; 1183 bool syncOK = false;
1184 SharpFormat sharpFormat; 1184 SharpFormat sharpFormat;
1185 if ( sharpFormat.load( calendar, mCalendar ) ) { 1185 if ( sharpFormat.load( calendar, mCalendar ) ) {
1186 getEventViewerDialog()->setSyncMode( true ); 1186 getEventViewerDialog()->setSyncMode( true );
1187 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1187 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1188 getEventViewerDialog()->setSyncMode( false ); 1188 getEventViewerDialog()->setSyncMode( false );
1189 qApp->processEvents(); 1189 qApp->processEvents();
1190 if ( syncOK ) { 1190 if ( syncOK ) {
1191 if ( KOPrefs::instance()->mWriteBackFile ) 1191 if ( KOPrefs::instance()->mWriteBackFile )
1192 { 1192 {
1193 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1193 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1194 Incidence* inc = iL.first(); 1194 Incidence* inc = iL.first();
1195 /* obsolete 1195 /* obsolete
1196 while ( inc ) { 1196 while ( inc ) {
1197 inc->setZaurusStat( inc->revision () ); 1197 inc->setZaurusStat( inc->revision () );
1198 inc = iL.next(); 1198 inc = iL.next();
1199 } 1199 }
1200 */ 1200 */
1201 // pending: clean last sync event description 1201 // pending: clean last sync event description
1202 sharpFormat.save(calendar); 1202 sharpFormat.save(calendar);
1203 iL = calendar->rawIncidences(); 1203 iL = calendar->rawIncidences();
1204 inc = iL.first(); 1204 inc = iL.first();
1205 Incidence* loc; 1205 Incidence* loc;
1206 while ( inc ) { 1206 while ( inc ) {
1207 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1207 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1208 loc = mCalendar->incidence(inc->uid() ); 1208 loc = mCalendar->incidence(inc->uid() );
1209 if ( loc ) { 1209 if ( loc ) {
1210 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1210 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1211 loc->setZaurusUid( inc->zaurusUid() ); 1211 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1212 } 1212 }
1213 } 1213 }
1214 inc = iL.next(); 1214 inc = iL.next();
1215 } 1215 }
1216 Incidence* lse = getLastSyncEvent(); 1216 Incidence* lse = getLastSyncEvent();
1217 if ( lse ) { 1217 if ( lse ) {
1218 lse->setReadOnly( false ); 1218 lse->setReadOnly( false );
1219 lse->setDescription( "" ); 1219 lse->setDescription( "" );
1220 lse->setReadOnly( true ); 1220 lse->setReadOnly( true );
1221 } 1221 }
1222 } 1222 }
1223 } 1223 }
1224 setModified( true ); 1224 setModified( true );
1225 } else { 1225 } else {
1226 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1226 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1227 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1227 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1228 question, i18n("Ok")) ; 1228 question, i18n("Ok")) ;
1229 1229
1230 } 1230 }
1231 delete calendar; 1231 delete calendar;
1232 updateView(); 1232 updateView();
1233 return ;//syncOK; 1233 return ;//syncOK;
1234#endif 1234#endif
1235} 1235}
1236 1236
1237 1237
1238#include <kabc/stdaddressbook.h> 1238#include <kabc/stdaddressbook.h>
1239bool CalendarView::importBday() 1239bool CalendarView::importBday()
1240{ 1240{
1241 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1241 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1242 KABC::AddressBook::Iterator it; 1242 KABC::AddressBook::Iterator it;
1243 int count = 0; 1243 int count = 0;
1244 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1244 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1245 ++count; 1245 ++count;
1246 } 1246 }
1247 QProgressBar bar(count,0 ); 1247 QProgressBar bar(count,0 );
1248 int w = 300; 1248 int w = 300;
1249 if ( QApplication::desktop()->width() < 320 ) 1249 if ( QApplication::desktop()->width() < 320 )
1250 w = 220; 1250 w = 220;
1251 int h = bar.sizeHint().height() ; 1251 int h = bar.sizeHint().height() ;
1252 int dw = QApplication::desktop()->width(); 1252 int dw = QApplication::desktop()->width();
1253 int dh = QApplication::desktop()->height(); 1253 int dh = QApplication::desktop()->height();
1254 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1254 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1255 bar.show(); 1255 bar.show();
1256 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1256 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1257 qApp->processEvents(); 1257 qApp->processEvents();
1258 count = 0; 1258 count = 0;
1259 int addCount = 0; 1259 int addCount = 0;
1260 KCal::Attendee* a = 0; 1260 KCal::Attendee* a = 0;
1261 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1261 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1262 if ( ! bar.isVisible() ) 1262 if ( ! bar.isVisible() )
1263 return false; 1263 return false;
1264 bar.setProgress( count++ ); 1264 bar.setProgress( count++ );
1265 qApp->processEvents(); 1265 qApp->processEvents();
1266 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1266 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1267 if ( (*it).birthday().date().isValid() ){ 1267 if ( (*it).birthday().date().isValid() ){
1268 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1268 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1269 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1269 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1270 ++addCount; 1270 ++addCount;
1271 } 1271 }
1272 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1272 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1273 if ( anni.isValid() ){ 1273 if ( anni.isValid() ){
1274 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1274 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1275 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1275 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1276 ++addCount; 1276 ++addCount;
1277 } 1277 }
1278 } 1278 }
1279 updateView(); 1279 updateView();
1280 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1280 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1281 return true; 1281 return true;
1282} 1282}
1283 1283
1284bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1284bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1285{ 1285{
1286 //qDebug("addAnni "); 1286 //qDebug("addAnni ");
1287 Event * ev = new Event(); 1287 Event * ev = new Event();
1288 if ( a ) { 1288 if ( a ) {
1289 ev->addAttendee( a ); 1289 ev->addAttendee( a );
1290 } 1290 }
1291 QString kind; 1291 QString kind;
1292 if ( birthday ) 1292 if ( birthday )
1293 kind = i18n( "Birthday" ); 1293 kind = i18n( "Birthday" );
1294 else 1294 else
1295 kind = i18n( "Anniversary" ); 1295 kind = i18n( "Anniversary" );
1296 ev->setSummary( name + " - " + kind ); 1296 ev->setSummary( name + " - " + kind );
1297 ev->setOrganizer( "nobody@nowhere" ); 1297 ev->setOrganizer( "nobody@nowhere" );
1298 ev->setCategories( kind ); 1298 ev->setCategories( kind );
1299 ev->setDtStart( QDateTime(date) ); 1299 ev->setDtStart( QDateTime(date) );
1300 ev->setDtEnd( QDateTime(date) ); 1300 ev->setDtEnd( QDateTime(date) );
1301 ev->setFloats( true ); 1301 ev->setFloats( true );
1302 Recurrence * rec = ev->recurrence(); 1302 Recurrence * rec = ev->recurrence();
1303 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1303 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1304 rec->addYearlyNum( date.month() ); 1304 rec->addYearlyNum( date.month() );
1305 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1305 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1306 delete ev; 1306 delete ev;
1307 return false; 1307 return false;
1308 } 1308 }
1309 return true; 1309 return true;
1310 1310
1311} 1311}
1312bool CalendarView::importQtopia( const QString &categories, 1312bool CalendarView::importQtopia( const QString &categories,
1313 const QString &datebook, 1313 const QString &datebook,
1314 const QString &todolist ) 1314 const QString &todolist )
1315{ 1315{
1316 1316
1317 QtopiaFormat qtopiaFormat; 1317 QtopiaFormat qtopiaFormat;
1318 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1318 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1319 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1319 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1320 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1320 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1321 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1321 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1322 1322
1323 updateView(); 1323 updateView();
1324 return true; 1324 return true;
1325 1325
1326#if 0 1326#if 0
1327 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1327 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1328 mCurrentSyncDevice = "qtopia-XML"; 1328 mCurrentSyncDevice = "qtopia-XML";
1329 if ( KOPrefs::instance()->mAskForPreferences ) 1329 if ( KOPrefs::instance()->mAskForPreferences )
1330 edit_sync_options(); 1330 edit_sync_options();
1331 qApp->processEvents(); 1331 qApp->processEvents();
1332 CalendarLocal* calendar = new CalendarLocal(); 1332 CalendarLocal* calendar = new CalendarLocal();
1333 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1333 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1334 bool syncOK = false; 1334 bool syncOK = false;
1335 QtopiaFormat qtopiaFormat; 1335 QtopiaFormat qtopiaFormat;
1336 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1336 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1337 bool loadOk = true; 1337 bool loadOk = true;
1338 if ( !categories.isEmpty() ) 1338 if ( !categories.isEmpty() )
1339 loadOk = qtopiaFormat.load( calendar, categories ); 1339 loadOk = qtopiaFormat.load( calendar, categories );
1340 if ( loadOk && !datebook.isEmpty() ) 1340 if ( loadOk && !datebook.isEmpty() )
1341 loadOk = qtopiaFormat.load( calendar, datebook ); 1341 loadOk = qtopiaFormat.load( calendar, datebook );
1342 if ( loadOk && !todolist.isEmpty() ) 1342 if ( loadOk && !todolist.isEmpty() )
1343 loadOk = qtopiaFormat.load( calendar, todolist ); 1343 loadOk = qtopiaFormat.load( calendar, todolist );
1344 1344
1345 if ( loadOk ) { 1345 if ( loadOk ) {
1346 getEventViewerDialog()->setSyncMode( true ); 1346 getEventViewerDialog()->setSyncMode( true );
1347 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1347 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1348 getEventViewerDialog()->setSyncMode( false ); 1348 getEventViewerDialog()->setSyncMode( false );
1349 qApp->processEvents(); 1349 qApp->processEvents();
1350 if ( syncOK ) { 1350 if ( syncOK ) {
1351 if ( KOPrefs::instance()->mWriteBackFile ) 1351 if ( KOPrefs::instance()->mWriteBackFile )
1352 { 1352 {
1353 // write back XML file 1353 // write back XML file
1354 1354
1355 } 1355 }
1356 setModified( true ); 1356 setModified( true );
1357 } 1357 }
1358 } else { 1358 } else {
1359 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1359 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1360 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1360 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1361 question, i18n("Ok")) ; 1361 question, i18n("Ok")) ;
1362 } 1362 }
1363 delete calendar; 1363 delete calendar;
1364 updateView(); 1364 updateView();
1365 return syncOK; 1365 return syncOK;
1366 1366
1367 1367
1368#endif 1368#endif
1369 1369
1370} 1370}
1371 1371
1372void CalendarView::setSyncEventsReadOnly() 1372void CalendarView::setSyncEventsReadOnly()
1373{ 1373{
1374 Event * ev; 1374 Event * ev;
1375 QPtrList<Event> eL = mCalendar->rawEvents(); 1375 QPtrList<Event> eL = mCalendar->rawEvents();
1376 ev = eL.first(); 1376 ev = eL.first();
1377 while ( ev ) { 1377 while ( ev ) {
1378 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1378 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1379 ev->setReadOnly( true ); 1379 ev->setReadOnly( true );
1380 ev = eL.next(); 1380 ev = eL.next();
1381 } 1381 }
1382} 1382}
1383bool CalendarView::openCalendar(QString filename, bool merge) 1383bool CalendarView::openCalendar(QString filename, bool merge)
1384{ 1384{
1385 1385
1386 if (filename.isEmpty()) { 1386 if (filename.isEmpty()) {
1387 return false; 1387 return false;
1388 } 1388 }
1389 1389
1390 if (!QFile::exists(filename)) { 1390 if (!QFile::exists(filename)) {
1391 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1391 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1392 return false; 1392 return false;
1393 } 1393 }
1394 1394
1395 globalFlagBlockAgenda = 1; 1395 globalFlagBlockAgenda = 1;
1396 if (!merge) mCalendar->close(); 1396 if (!merge) mCalendar->close();
1397 1397
1398 mStorage->setFileName( filename ); 1398 mStorage->setFileName( filename );
1399 1399
1400 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { 1400 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) {
1401 if ( merge ) ;//setModified( true ); 1401 if ( merge ) ;//setModified( true );
1402 else { 1402 else {
1403 //setModified( true ); 1403 //setModified( true );
1404 mViewManager->setDocumentId( filename ); 1404 mViewManager->setDocumentId( filename );
1405 mDialogManager->setDocumentId( filename ); 1405 mDialogManager->setDocumentId( filename );
1406 mTodoList->setDocumentId( filename ); 1406 mTodoList->setDocumentId( filename );
1407 } 1407 }
1408 globalFlagBlockAgenda = 2; 1408 globalFlagBlockAgenda = 2;
1409 // if ( getLastSyncEvent() ) 1409 // if ( getLastSyncEvent() )
1410 // getLastSyncEvent()->setReadOnly( true ); 1410 // getLastSyncEvent()->setReadOnly( true );
1411 mCalendar->reInitAlarmSettings(); 1411 mCalendar->reInitAlarmSettings();
1412 setSyncEventsReadOnly(); 1412 setSyncEventsReadOnly();
1413 updateUnmanagedViews(); 1413 updateUnmanagedViews();
1414 updateView(); 1414 updateView();
1415 if ( filename != MainWindow::defaultFileName() ) 1415 if ( filename != MainWindow::defaultFileName() )
1416 saveCalendar( MainWindow::defaultFileName() ); 1416 saveCalendar( MainWindow::defaultFileName() );
1417 loadedFileVersion = QDateTime::currentDateTime(); 1417 loadedFileVersion = QDateTime::currentDateTime();
1418 return true; 1418 return true;
1419 } else { 1419 } else {
1420 // while failing to load, the calendar object could 1420 // while failing to load, the calendar object could
1421 // have become partially populated. Clear it out. 1421 // have become partially populated. Clear it out.
1422 if ( !merge ) mCalendar->close(); 1422 if ( !merge ) mCalendar->close();
1423 1423
1424 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1424 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1425 1425
1426 globalFlagBlockAgenda = 2; 1426 globalFlagBlockAgenda = 2;
1427 updateView(); 1427 updateView();
1428 } 1428 }
1429 return false; 1429 return false;
1430} 1430}
1431void CalendarView::setLoadedFileVersion(QDateTime dt) 1431void CalendarView::setLoadedFileVersion(QDateTime dt)
1432{ 1432{
1433 loadedFileVersion = dt; 1433 loadedFileVersion = dt;
1434} 1434}
1435bool CalendarView::checkFileChanged(QString fn) 1435bool CalendarView::checkFileChanged(QString fn)
1436{ 1436{
1437 QFileInfo finf ( fn ); 1437 QFileInfo finf ( fn );
1438 if ( !finf.exists() ) 1438 if ( !finf.exists() )
1439 return true; 1439 return true;
1440 QDateTime dt = finf.lastModified (); 1440 QDateTime dt = finf.lastModified ();
1441 if ( dt <= loadedFileVersion ) 1441 if ( dt <= loadedFileVersion )
1442 return false; 1442 return false;
1443 return true; 1443 return true;
1444 1444
1445} 1445}
1446bool CalendarView::checkFileVersion(QString fn) 1446bool CalendarView::checkFileVersion(QString fn)
1447{ 1447{
1448 QFileInfo finf ( fn ); 1448 QFileInfo finf ( fn );
1449 if ( !finf.exists() ) 1449 if ( !finf.exists() )
1450 return true; 1450 return true;
1451 QDateTime dt = finf.lastModified (); 1451 QDateTime dt = finf.lastModified ();
1452 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1452 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1453 //qDebug("file on disk version %s",dt.toString().latin1()); 1453 //qDebug("file on disk version %s",dt.toString().latin1());
1454 if ( dt <= loadedFileVersion ) 1454 if ( dt <= loadedFileVersion )
1455 return true; 1455 return true;
1456 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , 1456 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) ,
1457 i18n("KO/Pi Warning"),i18n("Overwrite"), 1457 i18n("KO/Pi Warning"),i18n("Overwrite"),
1458 i18n("Sync+save")); 1458 i18n("Sync+save"));
1459 1459
1460 if ( km == KMessageBox::Cancel ) 1460 if ( km == KMessageBox::Cancel )
1461 return false; 1461 return false;
1462 if ( km == KMessageBox::Yes ) 1462 if ( km == KMessageBox::Yes )
1463 return true; 1463 return true;
1464 1464
1465 setSyncDevice("deleteaftersync" ); 1465 setSyncDevice("deleteaftersync" );
1466 KOPrefs::instance()->mAskForPreferences = true; 1466 KOPrefs::instance()->mAskForPreferences = true;
1467 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1467 KOPrefs::instance()->mSyncAlgoPrefs = 3;
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 5d8785b..15c4fa8 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,462 +1,406 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h>
24 25
25#include "calformat.h" 26#include "calformat.h"
26 27
27#include "incidencebase.h" 28#include "incidencebase.h"
28 29
29using namespace KCal; 30using namespace KCal;
30 31
31IncidenceBase::IncidenceBase() : 32IncidenceBase::IncidenceBase() :
32 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 33 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
33 mPilotId(0), mSyncStatus(SYNCMOD) 34 mPilotId(0), mSyncStatus(SYNCMOD)
34{ 35{
35 setUid(CalFormat::createUniqueId()); 36 setUid(CalFormat::createUniqueId());
36 mOrganizer = ""; 37 mOrganizer = "";
37 mFloats = false; 38 mFloats = false;
38 mDuration = 0; 39 mDuration = 0;
39 mHasDuration = false; 40 mHasDuration = false;
40 mPilotId = 0; 41 mPilotId = 0;
41 mZaurusUid = 0;
42 mExternalId = ":"; 42 mExternalId = ":";
43 mTempSyncStat = 0; 43 mTempSyncStat = 0;
44 mSyncStatus = 0; 44 mSyncStatus = 0;
45 mAttendees.setAutoDelete( true ); 45 mAttendees.setAutoDelete( true );
46} 46}
47 47
48IncidenceBase::IncidenceBase(const IncidenceBase &i) : 48IncidenceBase::IncidenceBase(const IncidenceBase &i) :
49 CustomProperties( i ) 49 CustomProperties( i )
50{ 50{
51 mReadOnly = i.mReadOnly; 51 mReadOnly = i.mReadOnly;
52 mDtStart = i.mDtStart; 52 mDtStart = i.mDtStart;
53 mDuration = i.mDuration; 53 mDuration = i.mDuration;
54 mHasDuration = i.mHasDuration; 54 mHasDuration = i.mHasDuration;
55 mOrganizer = i.mOrganizer; 55 mOrganizer = i.mOrganizer;
56 mUid = i.mUid; 56 mUid = i.mUid;
57 QPtrList<Attendee> attendees = i.attendees(); 57 QPtrList<Attendee> attendees = i.attendees();
58 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 58 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
59 mAttendees.append( new Attendee( *a ) ); 59 mAttendees.append( new Attendee( *a ) );
60 } 60 }
61 mFloats = i.mFloats; 61 mFloats = i.mFloats;
62 mLastModified = i.mLastModified; 62 mLastModified = i.mLastModified;
63 mPilotId = i.mPilotId; 63 mPilotId = i.mPilotId;
64 mZaurusUid = i.mZaurusUid;
65 mTempSyncStat = i.mTempSyncStat; 64 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 65 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 66 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 67 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 68 // of the original object.
70 mObservers.clear(); 69 mObservers.clear();
71 70
72 mAttendees.setAutoDelete( true ); 71 mAttendees.setAutoDelete( true );
73} 72}
74 73
75IncidenceBase::~IncidenceBase() 74IncidenceBase::~IncidenceBase()
76{ 75{
77} 76}
78 77
79 78
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 79bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 80{
82 // do not compare mSyncStatus and mExternalId 81 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 82 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 83 return false; // no need to check further
85 } 84 }
86 if ( i1.attendees().count() > 0 ) { 85 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 86 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 87 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 88 if ( !( (*a1) == (*a2)) )
90 { 89 {
91 //qDebug("Attendee not equal "); 90 //qDebug("Attendee not equal ");
92 return false; 91 return false;
93 } 92 }
94 a1 = i1.attendees().next(); 93 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 94 a2 = i2.attendees().next();
96 } 95 }
97 } 96 }
98 //if ( i1.dtStart() != i2.dtStart() ) 97 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 98 // return false;
100#if 0 99#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 100 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 101 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 102 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 103 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 104 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 105 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 106
108#endif 107#endif
109 return ( i1.organizer() == i2.organizer() && 108 return ( i1.organizer() == i2.organizer() &&
110 // i1.uid() == i2.uid() && 109 // i1.uid() == i2.uid() &&
111 // Don't compare lastModified, otherwise the operator is not 110 // Don't compare lastModified, otherwise the operator is not
112 // of much use. We are not comparing for identity, after all. 111 // of much use. We are not comparing for identity, after all.
113 i1.doesFloat() == i2.doesFloat() && 112 i1.doesFloat() == i2.doesFloat() &&
114 i1.duration() == i2.duration() && 113 i1.duration() == i2.duration() &&
115 i1.hasDuration() == i2.hasDuration() && 114 i1.hasDuration() == i2.hasDuration() &&
116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 115 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
117 // no need to compare mObserver 116 // no need to compare mObserver
118} 117}
119 118
120 119
121QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 120QDateTime IncidenceBase::getEvenTime( QDateTime dt )
122{ 121{
123 QTime t = dt.time(); 122 QTime t = dt.time();
124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 123 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
125 return dt; 124 return dt;
126} 125}
127 126
128 127
129void IncidenceBase::setUid(const QString &uid) 128void IncidenceBase::setUid(const QString &uid)
130{ 129{
131 mUid = uid; 130 mUid = uid;
132 updated(); 131 updated();
133} 132}
134 133
135QString IncidenceBase::uid() const 134QString IncidenceBase::uid() const
136{ 135{
137 return mUid; 136 return mUid;
138} 137}
139 138
140void IncidenceBase::setLastModified(const QDateTime &lm) 139void IncidenceBase::setLastModified(const QDateTime &lm)
141{ 140{
142 // DON'T! updated() because we call this from 141 // DON'T! updated() because we call this from
143 // Calendar::updateEvent(). 142 // Calendar::updateEvent().
144 mLastModified = getEvenTime(lm); 143 mLastModified = getEvenTime(lm);
145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 144 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
146} 145}
147 146
148QDateTime IncidenceBase::lastModified() const 147QDateTime IncidenceBase::lastModified() const
149{ 148{
150 return mLastModified; 149 return mLastModified;
151} 150}
152 151
153void IncidenceBase::setOrganizer(const QString &o) 152void IncidenceBase::setOrganizer(const QString &o)
154{ 153{
155 // we don't check for readonly here, because it is 154 // we don't check for readonly here, because it is
156 // possible that by setting the organizer we are changing 155 // possible that by setting the organizer we are changing
157 // the event's readonly status... 156 // the event's readonly status...
158 mOrganizer = o; 157 mOrganizer = o;
159 if (mOrganizer.left(7).upper() == "MAILTO:") 158 if (mOrganizer.left(7).upper() == "MAILTO:")
160 mOrganizer = mOrganizer.remove(0,7); 159 mOrganizer = mOrganizer.remove(0,7);
161 160
162 updated(); 161 updated();
163} 162}
164 163
165QString IncidenceBase::organizer() const 164QString IncidenceBase::organizer() const
166{ 165{
167 return mOrganizer; 166 return mOrganizer;
168} 167}
169 168
170void IncidenceBase::setReadOnly( bool readOnly ) 169void IncidenceBase::setReadOnly( bool readOnly )
171{ 170{
172 mReadOnly = readOnly; 171 mReadOnly = readOnly;
173} 172}
174 173
175void IncidenceBase::setDtStart(const QDateTime &dtStart) 174void IncidenceBase::setDtStart(const QDateTime &dtStart)
176{ 175{
177// if (mReadOnly) return; 176// if (mReadOnly) return;
178 mDtStart = getEvenTime(dtStart); 177 mDtStart = getEvenTime(dtStart);
179 updated(); 178 updated();
180} 179}
181 180
182QDateTime IncidenceBase::dtStart() const 181QDateTime IncidenceBase::dtStart() const
183{ 182{
184 return mDtStart; 183 return mDtStart;
185} 184}
186 185
187QString IncidenceBase::dtStartTimeStr() const 186QString IncidenceBase::dtStartTimeStr() const
188{ 187{
189 return KGlobal::locale()->formatTime(dtStart().time()); 188 return KGlobal::locale()->formatTime(dtStart().time());
190} 189}
191 190
192QString IncidenceBase::dtStartDateStr(bool shortfmt) const 191QString IncidenceBase::dtStartDateStr(bool shortfmt) const
193{ 192{
194 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 193 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
195} 194}
196 195
197QString IncidenceBase::dtStartStr(bool shortfmt) const 196QString IncidenceBase::dtStartStr(bool shortfmt) const
198{ 197{
199 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 198 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
200} 199}
201 200
202 201
203bool IncidenceBase::doesFloat() const 202bool IncidenceBase::doesFloat() const
204{ 203{
205 return mFloats; 204 return mFloats;
206} 205}
207 206
208void IncidenceBase::setFloats(bool f) 207void IncidenceBase::setFloats(bool f)
209{ 208{
210 if (mReadOnly) return; 209 if (mReadOnly) return;
211 mFloats = f; 210 mFloats = f;
212 updated(); 211 updated();
213} 212}
214 213
215 214
216void IncidenceBase::addAttendee(Attendee *a, bool doupdate) 215void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
217{ 216{
218 if (mReadOnly) return; 217 if (mReadOnly) return;
219 if (a->name().left(7).upper() == "MAILTO:") 218 if (a->name().left(7).upper() == "MAILTO:")
220 a->setName(a->name().remove(0,7)); 219 a->setName(a->name().remove(0,7));
221 220
222 mAttendees.append(a); 221 mAttendees.append(a);
223 if (doupdate) updated(); 222 if (doupdate) updated();
224} 223}
225 224
226#if 0 225#if 0
227void IncidenceBase::removeAttendee(Attendee *a) 226void IncidenceBase::removeAttendee(Attendee *a)
228{ 227{
229 if (mReadOnly) return; 228 if (mReadOnly) return;
230 mAttendees.removeRef(a); 229 mAttendees.removeRef(a);
231 updated(); 230 updated();
232} 231}
233 232
234void IncidenceBase::removeAttendee(const char *n) 233void IncidenceBase::removeAttendee(const char *n)
235{ 234{
236 Attendee *a; 235 Attendee *a;
237 236
238 if (mReadOnly) return; 237 if (mReadOnly) return;
239 for (a = mAttendees.first(); a; a = mAttendees.next()) 238 for (a = mAttendees.first(); a; a = mAttendees.next())
240 if (a->getName() == n) { 239 if (a->getName() == n) {
241 mAttendees.remove(); 240 mAttendees.remove();
242 break; 241 break;
243 } 242 }
244} 243}
245#endif 244#endif
246 245
247void IncidenceBase::clearAttendees() 246void IncidenceBase::clearAttendees()
248{ 247{
249 if (mReadOnly) return; 248 if (mReadOnly) return;
250 mAttendees.clear(); 249 mAttendees.clear();
251} 250}
252 251
253#if 0 252#if 0
254Attendee *IncidenceBase::getAttendee(const char *n) const 253Attendee *IncidenceBase::getAttendee(const char *n) const
255{ 254{
256 QPtrListIterator<Attendee> qli(mAttendees); 255 QPtrListIterator<Attendee> qli(mAttendees);
257 256
258 qli.toFirst(); 257 qli.toFirst();
259 while (qli) { 258 while (qli) {
260 if (qli.current()->getName() == n) 259 if (qli.current()->getName() == n)
261 return qli.current(); 260 return qli.current();
262 ++qli; 261 ++qli;
263 } 262 }
264 return 0L; 263 return 0L;
265} 264}
266#endif 265#endif
267 266
268Attendee *IncidenceBase::attendeeByMail(const QString &email) 267Attendee *IncidenceBase::attendeeByMail(const QString &email)
269{ 268{
270 QPtrListIterator<Attendee> qli(mAttendees); 269 QPtrListIterator<Attendee> qli(mAttendees);
271 270
272 qli.toFirst(); 271 qli.toFirst();
273 while (qli) { 272 while (qli) {
274 if (qli.current()->email() == email) 273 if (qli.current()->email() == email)
275 return qli.current(); 274 return qli.current();
276 ++qli; 275 ++qli;
277 } 276 }
278 return 0L; 277 return 0L;
279} 278}
280 279
281Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 280Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
282{ 281{
283 QPtrListIterator<Attendee> qli(mAttendees); 282 QPtrListIterator<Attendee> qli(mAttendees);
284 283
285 QStringList mails = emails; 284 QStringList mails = emails;
286 if (!email.isEmpty()) { 285 if (!email.isEmpty()) {
287 mails.append(email); 286 mails.append(email);
288 } 287 }
289 qli.toFirst(); 288 qli.toFirst();
290 while (qli) { 289 while (qli) {
291 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 290 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
292 if (qli.current()->email() == *it) 291 if (qli.current()->email() == *it)
293 return qli.current(); 292 return qli.current();
294 } 293 }
295 294
296 ++qli; 295 ++qli;
297 } 296 }
298 return 0L; 297 return 0L;
299} 298}
300 299
301void IncidenceBase::setDuration(int seconds) 300void IncidenceBase::setDuration(int seconds)
302{ 301{
303 mDuration = seconds; 302 mDuration = seconds;
304 setHasDuration(true); 303 setHasDuration(true);
305} 304}
306 305
307int IncidenceBase::duration() const 306int IncidenceBase::duration() const
308{ 307{
309 return mDuration; 308 return mDuration;
310} 309}
311 310
312void IncidenceBase::setHasDuration(bool b) 311void IncidenceBase::setHasDuration(bool b)
313{ 312{
314 mHasDuration = b; 313 mHasDuration = b;
315} 314}
316 315
317bool IncidenceBase::hasDuration() const 316bool IncidenceBase::hasDuration() const
318{ 317{
319 return mHasDuration; 318 return mHasDuration;
320} 319}
321 320
322void IncidenceBase::setSyncStatus(int stat) 321void IncidenceBase::setSyncStatus(int stat)
323{ 322{
324 if (mReadOnly) return; 323 if (mReadOnly) return;
325 mSyncStatus = stat; 324 mSyncStatus = stat;
326} 325}
327 326
328int IncidenceBase::syncStatus() const 327int IncidenceBase::syncStatus() const
329{ 328{
330 return mSyncStatus; 329 return mSyncStatus;
331} 330}
332 331
333void IncidenceBase::setPilotId( int id ) 332void IncidenceBase::setPilotId( int id )
334{ 333{
335 if (mReadOnly) return; 334 if (mReadOnly) return;
336 mPilotId = id; 335 mPilotId = id;
337} 336}
338 337
339int IncidenceBase::pilotId() const 338int IncidenceBase::pilotId() const
340{ 339{
341 return mPilotId; 340 return mPilotId;
342} 341}
343 342
344int IncidenceBase::zaurusUid() const
345{
346 return mZaurusUid;
347}
348void IncidenceBase::setZaurusUid( int id )
349{
350 if (mReadOnly) return;
351 mZaurusUid = id;
352}
353
354int IncidenceBase::tempSyncStat() const 343int IncidenceBase::tempSyncStat() const
355{ 344{
356 return mTempSyncStat; 345 return mTempSyncStat;
357} 346}
358void IncidenceBase::setTempSyncStat( int id ) 347void IncidenceBase::setTempSyncStat( int id )
359{ 348{
360 if (mReadOnly) return; 349 if (mReadOnly) return;
361 mTempSyncStat = id; 350 mTempSyncStat = id;
362} 351}
363 352
364void IncidenceBase::setID( const QString & prof , int id ) 353void IncidenceBase::removeID(const QString &prof)
365{ 354{
366 int num = mExternalId.find( ":"+prof+";" ); 355 mExternalId = KIdManager::removeId ( mExternalId, prof);
367 if ( num >= 0 ) { 356
368 int len = prof.length()+2; 357}
369 int end = mExternalId.find( ";", num+len ); 358void IncidenceBase::setID( const QString & prof , const QString & id )
370 if ( end > 0 ) { 359{
371 mExternalId = mExternalId.left( num+len ) +QString::number( id)+mExternalId.mid( end ); 360 mExternalId = KIdManager::setId ( mExternalId, prof, id );
372 } else 361}
373 qDebug("Error in IncidenceBase::setID "); 362QString IncidenceBase::getID( const QString & prof)
374 } else { 363{
375 mExternalId += prof+";"+QString::number( id) +";0:"; 364 return KIdManager::getId ( mExternalId, prof );
376 }
377 qDebug("setID*%s*%d*%s* ", prof.latin1(), id,mExternalId.latin1() );
378}
379int IncidenceBase::getID( const QString & prof)
380{
381 int ret = -1;
382 int num = mExternalId.find(":"+ prof+";" );
383 if ( num >= 0 ) {
384 int len = prof.length()+2;
385 int end = mExternalId.find( ";", num+len );
386 if ( end > 0 ) {
387 bool ok;
388 ret = mExternalId.mid ( num + len,end-len-num).toInt( &ok );
389 if (!ok)
390 ret = -1;
391 }
392 }
393 qDebug("getID*%s*%d*%s* ", prof.latin1(), ret,mExternalId.latin1() );
394 return ret;
395} 365}
396 366
397// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 367// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
398// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 368// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
399void IncidenceBase::setCsum( const QString & prof , int id ) 369void IncidenceBase::setCsum( const QString & prof , const QString & id )
400{ 370{
401 int num = mExternalId.find( ":"+prof+";"); 371 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
402 if ( num >= 0 ) { 372}
403 int len = prof.length()+2; 373QString IncidenceBase::getCsum( const QString & prof)
404 num = mExternalId.find( ";", num+len ); 374{
405 int end = mExternalId.find( ":", num+1 ); 375 return KIdManager::getCsum ( mExternalId, prof );
406 if ( end > 0 ) {
407 mExternalId = mExternalId.left( num ) +QString::number(id)+mExternalId.mid( end );
408 } else
409 qDebug("Error in IncidenceBase::setCsum ");
410 } else {
411 mExternalId += prof+";-1;"+QString::number( id) +":";
412 }
413 qDebug("setCsum*%s*%d*%s* ", prof.latin1(), id,mExternalId.latin1() );
414}
415int IncidenceBase::getCsum( const QString & prof)
416{
417 int ret = -1;
418 int num = mExternalId.find( ":"+prof+";" );
419 if ( num >= 0 ) {
420 int len = prof.length()+2;
421 num = mExternalId.find( ";", num+len );
422 int end = mExternalId.find( ":", num+1 );
423 if ( end > 0 ) {
424 bool ok;
425 ret = mExternalId.mid ( num ,end-num).toInt( &ok );
426 if (!ok)
427 ret = -1;
428 }
429 }
430 qDebug("getCsum*%s*%d*%s* ", prof.latin1(), ret,mExternalId.latin1() );
431 return ret;
432} 376}
433 377
434void IncidenceBase::setIDStr( const QString & s ) 378void IncidenceBase::setIDStr( const QString & s )
435{ 379{
436 if (mReadOnly) return; 380 if (mReadOnly) return;
437 mExternalId = s; 381 mExternalId = s;
438} 382}
439 383
440QString IncidenceBase::IDStr() const 384QString IncidenceBase::IDStr() const
441{ 385{
442 return mExternalId ; 386 return mExternalId ;
443} 387}
444void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 388void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
445{ 389{
446 if( !mObservers.contains(observer) ) mObservers.append( observer ); 390 if( !mObservers.contains(observer) ) mObservers.append( observer );
447} 391}
448 392
449void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 393void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
450{ 394{
451 mObservers.remove( observer ); 395 mObservers.remove( observer );
452} 396}
453 397
454void IncidenceBase::updated() 398void IncidenceBase::updated()
455{ 399{
456 QPtrListIterator<Observer> it(mObservers); 400 QPtrListIterator<Observer> it(mObservers);
457 while( it.current() ) { 401 while( it.current() ) {
458 Observer *o = it.current(); 402 Observer *o = it.current();
459 ++it; 403 ++it;
460 o->incidenceUpdated( this ); 404 o->incidenceUpdated( this );
461 } 405 }
462} 406}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index e2950d3..e02d03a 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,175 +1,172 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 37
38/** 38/**
39 This class provides the base class common to all calendar components. 39 This class provides the base class common to all calendar components.
40*/ 40*/
41class IncidenceBase : public CustomProperties 41class IncidenceBase : public CustomProperties
42{ 42{
43 public: 43 public:
44 class Observer { 44 class Observer {
45 public: 45 public:
46 virtual void incidenceUpdated( IncidenceBase * ) = 0; 46 virtual void incidenceUpdated( IncidenceBase * ) = 0;
47 }; 47 };
48 48
49 IncidenceBase(); 49 IncidenceBase();
50 IncidenceBase(const IncidenceBase &); 50 IncidenceBase(const IncidenceBase &);
51 virtual ~IncidenceBase(); 51 virtual ~IncidenceBase();
52 52
53 virtual QCString type() const = 0; 53 virtual QCString type() const = 0;
54 54
55 /** Set the unique id for the event */ 55 /** Set the unique id for the event */
56 void setUid(const QString &); 56 void setUid(const QString &);
57 /** Return the unique id for the event */ 57 /** Return the unique id for the event */
58 QString uid() const; 58 QString uid() const;
59 59
60 /** Sets the time the incidence was last modified. */ 60 /** Sets the time the incidence was last modified. */
61 void setLastModified(const QDateTime &lm); 61 void setLastModified(const QDateTime &lm);
62 /** Return the time the incidence was last modified. */ 62 /** Return the time the incidence was last modified. */
63 QDateTime lastModified() const; 63 QDateTime lastModified() const;
64 64
65 /** sets the organizer for the event */ 65 /** sets the organizer for the event */
66 void setOrganizer(const QString &o); 66 void setOrganizer(const QString &o);
67 QString organizer() const; 67 QString organizer() const;
68 68
69 /** Set readonly status. */ 69 /** Set readonly status. */
70 virtual void setReadOnly( bool ); 70 virtual void setReadOnly( bool );
71 /** Return if the object is read-only. */ 71 /** Return if the object is read-only. */
72 bool isReadOnly() const { return mReadOnly; } 72 bool isReadOnly() const { return mReadOnly; }
73 73
74 /** for setting the event's starting date/time with a QDateTime. */ 74 /** for setting the event's starting date/time with a QDateTime. */
75 virtual void setDtStart(const QDateTime &dtStart); 75 virtual void setDtStart(const QDateTime &dtStart);
76 /** returns an event's starting date/time as a QDateTime. */ 76 /** returns an event's starting date/time as a QDateTime. */
77 QDateTime dtStart() const; 77 QDateTime dtStart() const;
78 /** returns an event's starting time as a string formatted according to the 78 /** returns an event's starting time as a string formatted according to the
79 users locale settings */ 79 users locale settings */
80 QString dtStartTimeStr() const; 80 QString dtStartTimeStr() const;
81 /** returns an event's starting date as a string formatted according to the 81 /** returns an event's starting date as a string formatted according to the
82 users locale settings */ 82 users locale settings */
83 QString dtStartDateStr(bool shortfmt=true) const; 83 QString dtStartDateStr(bool shortfmt=true) const;
84 /** returns an event's starting date and time as a string formatted according 84 /** returns an event's starting date and time as a string formatted according
85 to the users locale settings */ 85 to the users locale settings */
86 QString dtStartStr(bool shortfmt=true) const; 86 QString dtStartStr(bool shortfmt=true) const;
87 87
88 virtual void setDuration(int seconds); 88 virtual void setDuration(int seconds);
89 int duration() const; 89 int duration() const;
90 void setHasDuration(bool); 90 void setHasDuration(bool);
91 bool hasDuration() const; 91 bool hasDuration() const;
92 92
93 /** Return true or false depending on whether the incidence "floats," 93 /** Return true or false depending on whether the incidence "floats,"
94 * i.e. has a date but no time attached to it. */ 94 * i.e. has a date but no time attached to it. */
95 bool doesFloat() const; 95 bool doesFloat() const;
96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
97 void setFloats(bool f); 97 void setFloats(bool f);
98 98
99 /** 99 /**
100 Add Attendee to this incidence. IncidenceBase takes ownership of the 100 Add Attendee to this incidence. IncidenceBase takes ownership of the
101 Attendee object. 101 Attendee object.
102 */ 102 */
103 void addAttendee(Attendee *a, bool doupdate=true ); 103 void addAttendee(Attendee *a, bool doupdate=true );
104// void removeAttendee(Attendee *a); 104// void removeAttendee(Attendee *a);
105// void removeAttendee(const char *n); 105// void removeAttendee(const char *n);
106 /** Remove all Attendees. */ 106 /** Remove all Attendees. */
107 void clearAttendees(); 107 void clearAttendees();
108 /** Return list of attendees. */ 108 /** Return list of attendees. */
109 QPtrList<Attendee> attendees() const { return mAttendees; }; 109 QPtrList<Attendee> attendees() const { return mAttendees; };
110 /** Return number of attendees. */ 110 /** Return number of attendees. */
111 int attendeeCount() const { return mAttendees.count(); }; 111 int attendeeCount() const { return mAttendees.count(); };
112 /** Return the Attendee with this email */ 112 /** Return the Attendee with this email */
113 Attendee* attendeeByMail(const QString &); 113 Attendee* attendeeByMail(const QString &);
114 /** Return first Attendee with one of this emails */ 114 /** Return first Attendee with one of this emails */
115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
116 116
117 /** pilot syncronization states */ 117 /** pilot syncronization states */
118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
119 /** Set synchronisation satus. */ 119 /** Set synchronisation satus. */
120 void setSyncStatus(int stat); 120 void setSyncStatus(int stat);
121 /** Return synchronisation status. */ 121 /** Return synchronisation status. */
122 int syncStatus() const; 122 int syncStatus() const;
123 123
124 /** Set Pilot Id. */ 124 /** Set Pilot Id. */
125 void setPilotId(int id); 125 void setPilotId(int id);
126 /** Return Pilot Id. */ 126 /** Return Pilot Id. */
127 int pilotId() const; 127 int pilotId() const;
128 128
129 void setZaurusUid(int id);
130 int zaurusUid() const;
131 void setTempSyncStat(int id); 129 void setTempSyncStat(int id);
132 int tempSyncStat() const; 130 int tempSyncStat() const;
133 void setIDStr( const QString & ); 131 void setIDStr( const QString & );
134 QString IDStr() const; 132 QString IDStr() const;
135 void setID( const QString &, int ); 133 void setID( const QString &, const QString & );
136 int getID( const QString & ); 134 QString getID( const QString & );
137 void setCsum( const QString &, int ); 135 void setCsum( const QString &, const QString & );
138 int getCsum( const QString & ); 136 QString getCsum( const QString & );
139 137 void removeID(const QString &);
140 138
141 void registerObserver( Observer * ); 139 void registerObserver( Observer * );
142 void unRegisterObserver( Observer * ); 140 void unRegisterObserver( Observer * );
143 void updated(); 141 void updated();
144 142
145 protected: 143 protected:
146 bool mReadOnly; 144 bool mReadOnly;
147 QDateTime getEvenTime( QDateTime ); 145 QDateTime getEvenTime( QDateTime );
148 146
149 private: 147 private:
150 // base components 148 // base components
151 QDateTime mDtStart; 149 QDateTime mDtStart;
152 QString mOrganizer; 150 QString mOrganizer;
153 QString mUid; 151 QString mUid;
154 QDateTime mLastModified; 152 QDateTime mLastModified;
155 QPtrList<Attendee> mAttendees; 153 QPtrList<Attendee> mAttendees;
156 154
157 bool mFloats; 155 bool mFloats;
158 156
159 int mDuration; 157 int mDuration;
160 bool mHasDuration; 158 bool mHasDuration;
161 QString mExternalId; 159 QString mExternalId;
162 int mZaurusUid;
163 int mTempSyncStat; 160 int mTempSyncStat;
164 161
165 // PILOT SYNCHRONIZATION STUFF 162 // PILOT SYNCHRONIZATION STUFF
166 int mPilotId; // unique id for pilot sync 163 int mPilotId; // unique id for pilot sync
167 int mSyncStatus; // status (for sync) 164 int mSyncStatus; // status (for sync)
168 165
169 QPtrList<Observer> mObservers; 166 QPtrList<Observer> mObservers;
170}; 167};
171 168
172bool operator==( const IncidenceBase&, const IncidenceBase& ); 169bool operator==( const IncidenceBase&, const IncidenceBase& );
173} 170}
174 171
175#endif 172#endif
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 605a54d..e8934bf 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,1008 +1,1008 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "sharpformat.h" 44#include "sharpformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY 49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY
50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
51 51
52//ARSD silentalarm = 0 52//ARSD silentalarm = 0
53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly 53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly
54// 12 RFRQ 54// 12 RFRQ
55// 13 RPOS pos = 4. monday in month 55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun 56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end 57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt 58// 16 REDT rec end dt
59//ALSD 59//ALSD
60//ALED 60//ALED
61//MDAY 61//MDAY
62 62
63class SharpParser : public QObject 63class SharpParser : public QObject
64{ 64{
65 public: 65 public:
66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) { 66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
67 oldCategories = 0; 67 oldCategories = 0;
68 } 68 }
69 69
70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
71 { 71 {
72 int i = 1; 72 int i = 1;
73 bool skip = true; 73 bool skip = true;
74 int max = attList.count() -2; 74 int max = attList.count() -2;
75 while ( i < max ) { 75 while ( i < max ) {
76 if ( !attList[i].isEmpty() ) { 76 if ( !attList[i].isEmpty() ) {
77 skip = false; 77 skip = false;
78 break; 78 break;
79 } 79 }
80 ++i ; 80 ++i ;
81 } 81 }
82 if ( skip ) 82 if ( skip )
83 return false; 83 return false;
84 ulong cSum = SharpFormat::getCsum(attList ); 84 ulong cSum = SharpFormat::getCsum(attList );
85 85
86 if ( qName == "Event" ) { 86 if ( qName == "Event" ) {
87 Event *event; 87 Event *event;
88 event = existingCalendar->event( "Sharp_DTM",attList[0].toInt() ); 88 event = existingCalendar->event( "Sharp_DTM",attList[0].toInt() );
89 if ( event ) 89 if ( event )
90 event = (Event*)event->clone(); 90 event = (Event*)event->clone();
91 else 91 else
92 event = new Event; 92 event = new Event;
93 event->setID("Sharp_DTM", attList[0].toInt() ); 93 event->setID("Sharp_DTM", attList[0] );
94 event->setZaurusUid( cSum ); 94 event->setCsum( "Sharp_DTM", QString::number( cSum ));
95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
96 96
97 event->setSummary( attList[2] ); 97 event->setSummary( attList[2] );
98 event->setLocation( attList[3] ); 98 event->setLocation( attList[3] );
99 event->setDescription( attList[4] ); 99 event->setDescription( attList[4] );
100 if ( attList[7] == "1" ) { 100 if ( attList[7] == "1" ) {
101 event->setDtStart( QDateTime(fromString( attList[17]+"000000", false ).date(),QTime(0,0,0 ) )); 101 event->setDtStart( QDateTime(fromString( attList[17]+"000000", false ).date(),QTime(0,0,0 ) ));
102 event->setDtEnd( QDateTime(fromString( attList[18]+"000000", false ).date(),QTime(0,0,0 ))); 102 event->setDtEnd( QDateTime(fromString( attList[18]+"000000", false ).date(),QTime(0,0,0 )));
103 event->setFloats( true ); 103 event->setFloats( true );
104 } else { 104 } else {
105 event->setFloats( false ); 105 event->setFloats( false );
106 event->setDtStart( fromString( attList[5] ) ); 106 event->setDtStart( fromString( attList[5] ) );
107 event->setDtEnd( fromString( attList[6] )); 107 event->setDtEnd( fromString( attList[6] ));
108 } 108 }
109 109
110 QString rtype = attList[11]; 110 QString rtype = attList[11];
111 if ( rtype != "255" ) { 111 if ( rtype != "255" ) {
112 // qDebug("recurs "); 112 // qDebug("recurs ");
113 QDate startDate = event->dtStart().date(); 113 QDate startDate = event->dtStart().date();
114 114
115 QString freqStr = attList[12]; 115 QString freqStr = attList[12];
116 int freq = freqStr.toInt(); 116 int freq = freqStr.toInt();
117 117
118 QString hasEndDateStr = attList[15] ; 118 QString hasEndDateStr = attList[15] ;
119 bool hasEndDate = hasEndDateStr == "1"; 119 bool hasEndDate = hasEndDateStr == "1";
120 120
121 QString endDateStr = attList[16]; 121 QString endDateStr = attList[16];
122 QDate endDate = fromString( endDateStr ).date(); 122 QDate endDate = fromString( endDateStr ).date();
123 123
124 QString weekDaysStr = attList[14]; 124 QString weekDaysStr = attList[14];
125 uint weekDaysNum = weekDaysStr.toInt(); 125 uint weekDaysNum = weekDaysStr.toInt();
126 126
127 QBitArray weekDays( 7 ); 127 QBitArray weekDays( 7 );
128 int i; 128 int i;
129 int bb = 1; 129 int bb = 1;
130 for( i = 1; i <= 7; ++i ) { 130 for( i = 1; i <= 7; ++i ) {
131 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 131 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
132 bb = 2 << (i-1); 132 bb = 2 << (i-1);
133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
134 } 134 }
135 // qDebug("next "); 135 // qDebug("next ");
136 QString posStr = attList[13]; 136 QString posStr = attList[13];
137 int pos = posStr.toInt(); 137 int pos = posStr.toInt();
138 Recurrence *r = event->recurrence(); 138 Recurrence *r = event->recurrence();
139 139
140 if ( rtype == "0" ) { 140 if ( rtype == "0" ) {
141 if ( hasEndDate ) r->setDaily( freq, endDate ); 141 if ( hasEndDate ) r->setDaily( freq, endDate );
142 else r->setDaily( freq, -1 ); 142 else r->setDaily( freq, -1 );
143 } else if ( rtype == "1" ) { 143 } else if ( rtype == "1" ) {
144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
145 else r->setWeekly( freq, weekDays, -1 ); 145 else r->setWeekly( freq, weekDays, -1 );
146 } else if ( rtype == "3" ) { 146 } else if ( rtype == "3" ) {
147 if ( hasEndDate ) 147 if ( hasEndDate )
148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
149 else 149 else
150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
151 r->addMonthlyDay( startDate.day() ); 151 r->addMonthlyDay( startDate.day() );
152 } else if ( rtype == "2" ) { 152 } else if ( rtype == "2" ) {
153 if ( hasEndDate ) 153 if ( hasEndDate )
154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
155 else 155 else
156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
157 QBitArray days( 7 ); 157 QBitArray days( 7 );
158 days.fill( false ); 158 days.fill( false );
159 days.setBit( startDate.dayOfWeek() - 1 ); 159 days.setBit( startDate.dayOfWeek() - 1 );
160 r->addMonthlyPos( pos, days ); 160 r->addMonthlyPos( pos, days );
161 } else if ( rtype == "4" ) { 161 } else if ( rtype == "4" ) {
162 if ( hasEndDate ) 162 if ( hasEndDate )
163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
164 else 164 else
165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
166 r->addYearlyNum( startDate.month() ); 166 r->addYearlyNum( startDate.month() );
167 } 167 }
168 } 168 }
169 169
170 QString categoryList = attList[1] ; 170 QString categoryList = attList[1] ;
171 event->setCategories( lookupCategories( categoryList ) ); 171 event->setCategories( lookupCategories( categoryList ) );
172 172
173 // strange 0 semms to mean: alarm enabled 173 // strange 0 semms to mean: alarm enabled
174 if ( attList[8] == "0" ) { 174 if ( attList[8] == "0" ) {
175 Alarm *alarm; 175 Alarm *alarm;
176 if ( event->alarms().count() > 0 ) 176 if ( event->alarms().count() > 0 )
177 alarm = event->alarms().first(); 177 alarm = event->alarms().first();
178 else { 178 else {
179 alarm = new Alarm( event ); 179 alarm = new Alarm( event );
180 event->addAlarm( alarm ); 180 event->addAlarm( alarm );
181 } 181 }
182 alarm->setType( Alarm::Audio ); 182 alarm->setType( Alarm::Audio );
183 alarm->setEnabled( true ); 183 alarm->setEnabled( true );
184 int alarmOffset = attList[9].toInt(); 184 int alarmOffset = attList[9].toInt();
185 alarm->setStartOffset( alarmOffset * -60 ); 185 alarm->setStartOffset( alarmOffset * -60 );
186 } 186 }
187 187
188 mCalendar->addEvent( event); 188 mCalendar->addEvent( event);
189 } else if ( qName == "Todo" ) { 189 } else if ( qName == "Todo" ) {
190 Todo *todo; 190 Todo *todo;
191 191
192 todo = existingCalendar->todo( "Sharp_DTM", attList[0].toInt() ); 192 todo = existingCalendar->todo( "Sharp_DTM", attList[0].toInt() );
193 if (todo ) 193 if (todo )
194 todo = (Todo*)todo->clone(); 194 todo = (Todo*)todo->clone();
195 else 195 else
196 todo = new Todo; 196 todo = new Todo;
197 197
198//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 198//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
199// 0 1 2 3 4 5 6 7 8 199// 0 1 2 3 4 5 6 7 8
200//1,,,,,1,4,Loch zumachen,"" 200//1,,,,,1,4,Loch zumachen,""
201//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 201//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
202//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 202//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
203 203
204 todo->setID( "Sharp_DTM", attList[0].toInt() ); 204 todo->setID( "Sharp_DTM", attList[0]);
205 todo->setZaurusUid( cSum ); 205 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
206 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 206 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
207 207
208 todo->setSummary( attList[7] ); 208 todo->setSummary( attList[7] );
209 todo->setDescription( attList[8]); 209 todo->setDescription( attList[8]);
210 210
211 int priority = attList[6].toInt(); 211 int priority = attList[6].toInt();
212 if ( priority == 0 ) priority = 3; 212 if ( priority == 0 ) priority = 3;
213 todo->setPriority( priority ); 213 todo->setPriority( priority );
214 214
215 QString categoryList = attList[1]; 215 QString categoryList = attList[1];
216 todo->setCategories( lookupCategories( categoryList ) ); 216 todo->setCategories( lookupCategories( categoryList ) );
217 217
218 218
219 219
220 QString hasDateStr = attList[3]; // due 220 QString hasDateStr = attList[3]; // due
221 if ( !hasDateStr.isEmpty() ) { 221 if ( !hasDateStr.isEmpty() ) {
222 if ( hasDateStr.right(6) == "000000" ) { 222 if ( hasDateStr.right(6) == "000000" ) {
223 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 223 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
224 todo->setFloats( true ); 224 todo->setFloats( true );
225 } 225 }
226 else { 226 else {
227 todo->setDtDue( fromString( hasDateStr ) ); 227 todo->setDtDue( fromString( hasDateStr ) );
228 todo->setFloats( false ); 228 todo->setFloats( false );
229 } 229 }
230 230
231 todo->setHasDueDate( true ); 231 todo->setHasDueDate( true );
232 } 232 }
233 hasDateStr = attList[2];//start 233 hasDateStr = attList[2];//start
234 if ( !hasDateStr.isEmpty() ) { 234 if ( !hasDateStr.isEmpty() ) {
235 235
236 todo->setDtStart( fromString( hasDateStr ) ); 236 todo->setDtStart( fromString( hasDateStr ) );
237 todo->setHasStartDate( true); 237 todo->setHasStartDate( true);
238 } else 238 } else
239 todo->setHasStartDate( false ); 239 todo->setHasStartDate( false );
240 hasDateStr = attList[4];//completed 240 hasDateStr = attList[4];//completed
241 if ( !hasDateStr.isEmpty() ) { 241 if ( !hasDateStr.isEmpty() ) {
242 todo->setCompleted(fromString( hasDateStr ) ); 242 todo->setCompleted(fromString( hasDateStr ) );
243 } 243 }
244 QString completedStr = attList[5]; 244 QString completedStr = attList[5];
245 if ( completedStr == "0" ) 245 if ( completedStr == "0" )
246 todo->setCompleted( true ); 246 todo->setCompleted( true );
247 else 247 else
248 todo->setCompleted( false ); 248 todo->setCompleted( false );
249 mCalendar->addTodo( todo ); 249 mCalendar->addTodo( todo );
250 250
251 } else if ( qName == "Category" ) { 251 } else if ( qName == "Category" ) {
252 /* 252 /*
253 QString id = attributes.value( "id" ); 253 QString id = attributes.value( "id" );
254 QString name = attributes.value( "name" ); 254 QString name = attributes.value( "name" );
255 setCategory( id, name ); 255 setCategory( id, name );
256 */ 256 */
257 } 257 }
258 //qDebug("end "); 258 //qDebug("end ");
259 return true; 259 return true;
260 } 260 }
261 261
262 262
263 void setCategoriesList ( QStringList * c ) 263 void setCategoriesList ( QStringList * c )
264 { 264 {
265 oldCategories = c; 265 oldCategories = c;
266 } 266 }
267 267
268 QDateTime fromString ( QString s, bool useTz = true ) { 268 QDateTime fromString ( QString s, bool useTz = true ) {
269 QDateTime dt; 269 QDateTime dt;
270 int y,m,t,h,min,sec; 270 int y,m,t,h,min,sec;
271 y = s.mid(0,4).toInt(); 271 y = s.mid(0,4).toInt();
272 m = s.mid(4,2).toInt(); 272 m = s.mid(4,2).toInt();
273 t = s.mid(6,2).toInt(); 273 t = s.mid(6,2).toInt();
274 h = s.mid(9,2).toInt(); 274 h = s.mid(9,2).toInt();
275 min = s.mid(11,2).toInt(); 275 min = s.mid(11,2).toInt();
276 sec = s.mid(13,2).toInt(); 276 sec = s.mid(13,2).toInt();
277 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 277 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
278 int offset = KGlobal::locale()->localTimeOffset( dt ); 278 int offset = KGlobal::locale()->localTimeOffset( dt );
279 if ( useTz ) 279 if ( useTz )
280 dt = dt.addSecs ( offset*60); 280 dt = dt.addSecs ( offset*60);
281 return dt; 281 return dt;
282 282
283 } 283 }
284 protected: 284 protected:
285 QDateTime toDateTime( const QString &value ) 285 QDateTime toDateTime( const QString &value )
286 { 286 {
287 QDateTime dt; 287 QDateTime dt;
288 dt.setTime_t( value.toUInt() ); 288 dt.setTime_t( value.toUInt() );
289 289
290 return dt; 290 return dt;
291 } 291 }
292 292
293 QStringList lookupCategories( const QString &categoryList ) 293 QStringList lookupCategories( const QString &categoryList )
294 { 294 {
295 QStringList categoryIds = QStringList::split( ";", categoryList ); 295 QStringList categoryIds = QStringList::split( ";", categoryList );
296 QStringList categories; 296 QStringList categories;
297 QStringList::ConstIterator it; 297 QStringList::ConstIterator it;
298 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 298 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
299 QString cate = category( *it ); 299 QString cate = category( *it );
300 if ( oldCategories ) { 300 if ( oldCategories ) {
301 if ( ! oldCategories->contains( cate ) ) 301 if ( ! oldCategories->contains( cate ) )
302 oldCategories->append( cate ); 302 oldCategories->append( cate );
303 } 303 }
304 categories.append(cate ); 304 categories.append(cate );
305 } 305 }
306 return categories; 306 return categories;
307 } 307 }
308 308
309 private: 309 private:
310 Calendar *mCalendar; 310 Calendar *mCalendar;
311 QStringList * oldCategories; 311 QStringList * oldCategories;
312 static QString category( const QString &id ) 312 static QString category( const QString &id )
313 { 313 {
314 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 314 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
315 if ( it == mCategoriesMap.end() ) return id; 315 if ( it == mCategoriesMap.end() ) return id;
316 else return *it; 316 else return *it;
317 } 317 }
318 318
319 static void setCategory( const QString &id, const QString &name ) 319 static void setCategory( const QString &id, const QString &name )
320 { 320 {
321 mCategoriesMap.insert( id, name ); 321 mCategoriesMap.insert( id, name );
322 } 322 }
323 323
324 static QMap<QString,QString> mCategoriesMap; 324 static QMap<QString,QString> mCategoriesMap;
325}; 325};
326 326
327QMap<QString,QString> SharpParser::mCategoriesMap; 327QMap<QString,QString> SharpParser::mCategoriesMap;
328 328
329SharpFormat::SharpFormat() 329SharpFormat::SharpFormat()
330{ 330{
331 mCategories = 0; 331 mCategories = 0;
332} 332}
333 333
334SharpFormat::~SharpFormat() 334SharpFormat::~SharpFormat()
335{ 335{
336} 336}
337ulong SharpFormat::getCsum( const QStringList & attList) 337ulong SharpFormat::getCsum( const QStringList & attList)
338{ 338{
339 int max = attList.count() -1; 339 int max = attList.count() -1;
340 ulong cSum = 0; 340 ulong cSum = 0;
341 int j,k,i; 341 int j,k,i;
342 int add; 342 int add;
343 for ( i = 1; i < max ; ++i ) { 343 for ( i = 1; i < max ; ++i ) {
344 QString s = attList[i]; 344 QString s = attList[i];
345 if ( ! s.isEmpty() ){ 345 if ( ! s.isEmpty() ){
346 j = s.length(); 346 j = s.length();
347 for ( k = 0; k < j; ++k ) { 347 for ( k = 0; k < j; ++k ) {
348 int mul = k +1; 348 int mul = k +1;
349 add = s[k].unicode (); 349 add = s[k].unicode ();
350 if ( k < 16 ) 350 if ( k < 16 )
351 mul = mul * mul; 351 mul = mul * mul;
352 add = add * mul *i*i*i; 352 add = add * mul *i*i*i;
353 cSum += add; 353 cSum += add;
354 } 354 }
355 } 355 }
356 } 356 }
357 return cSum; 357 return cSum;
358 358
359} 359}
360#include <stdlib.h> 360#include <stdlib.h>
361#define DEBUGMODE false 361#define DEBUGMODE false
362bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 362bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
363{ 363{
364 364
365 365
366 bool debug = DEBUGMODE; 366 bool debug = DEBUGMODE;
367 //debug = true; 367 //debug = true;
368 QString text; 368 QString text;
369 QString codec = "utf8"; 369 QString codec = "utf8";
370 QLabel status ( i18n("Reading events ..."), 0 ); 370 QLabel status ( i18n("Reading events ..."), 0 );
371 371
372 int w = status.sizeHint().width()+20 ; 372 int w = status.sizeHint().width()+20 ;
373 if ( w < 200 ) w = 200; 373 if ( w < 200 ) w = 200;
374 int h = status.sizeHint().height()+20 ; 374 int h = status.sizeHint().height()+20 ;
375 int dw = QApplication::desktop()->width(); 375 int dw = QApplication::desktop()->width();
376 int dh = QApplication::desktop()->height(); 376 int dh = QApplication::desktop()->height();
377 status.setCaption(i18n("Reading DTM Data") ); 377 status.setCaption(i18n("Reading DTM Data") );
378 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 378 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
379 status.show(); 379 status.show();
380 status.raise(); 380 status.raise();
381 qApp->processEvents(); 381 qApp->processEvents();
382 QString fileName; 382 QString fileName;
383 if ( ! debug ) { 383 if ( ! debug ) {
384 fileName = "/tmp/kopitempout"; 384 fileName = "/tmp/kopitempout";
385 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 385 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
386 system ( command.latin1() ); 386 system ( command.latin1() );
387 } else { 387 } else {
388 fileName = "/tmp/events.txt"; 388 fileName = "/tmp/events.txt";
389 389
390 } 390 }
391 QFile file( fileName ); 391 QFile file( fileName );
392 if (!file.open( IO_ReadOnly ) ) { 392 if (!file.open( IO_ReadOnly ) ) {
393 return false; 393 return false;
394 394
395 } 395 }
396 QTextStream ts( &file ); 396 QTextStream ts( &file );
397 ts.setCodec( QTextCodec::codecForName("utf8") ); 397 ts.setCodec( QTextCodec::codecForName("utf8") );
398 text = ts.read(); 398 text = ts.read();
399 file.close(); 399 file.close();
400 status.setText( i18n("Processing events ...") ); 400 status.setText( i18n("Processing events ...") );
401 status.raise(); 401 status.raise();
402 qApp->processEvents(); 402 qApp->processEvents();
403 fromString2Cal( calendar, existngCal, text, "Event" ); 403 fromString2Cal( calendar, existngCal, text, "Event" );
404 status.setText( i18n("Reading todos ...") ); 404 status.setText( i18n("Reading todos ...") );
405 qApp->processEvents(); 405 qApp->processEvents();
406 if ( ! debug ) { 406 if ( ! debug ) {
407 fileName = "/tmp/kopitempout"; 407 fileName = "/tmp/kopitempout";
408 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 408 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
409 system ( command.latin1() ); 409 system ( command.latin1() );
410 } else { 410 } else {
411 fileName = "/tmp/todo.txt"; 411 fileName = "/tmp/todo.txt";
412 } 412 }
413 file.setName( fileName ); 413 file.setName( fileName );
414 if (!file.open( IO_ReadOnly ) ) { 414 if (!file.open( IO_ReadOnly ) ) {
415 return false; 415 return false;
416 416
417 } 417 }
418 ts.setDevice( &file ); 418 ts.setDevice( &file );
419 text = ts.read(); 419 text = ts.read();
420 file.close(); 420 file.close();
421 421
422 status.setText( i18n("Processing todos ...") ); 422 status.setText( i18n("Processing todos ...") );
423 status.raise(); 423 status.raise();
424 qApp->processEvents(); 424 qApp->processEvents();
425 fromString2Cal( calendar, existngCal, text, "Todo" ); 425 fromString2Cal( calendar, existngCal, text, "Todo" );
426 return true; 426 return true;
427} 427}
428int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 428int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
429{ 429{
430 int retval = -1; 430 int retval = -1;
431 QStringList templist; 431 QStringList templist;
432 QString tempString; 432 QString tempString;
433 int start = 0; 433 int start = 0;
434 int len = answer.length(); 434 int len = answer.length();
435 int end = answer.find ("\n",start)+1; 435 int end = answer.find ("\n",start)+1;
436 bool ok = true; 436 bool ok = true;
437 start = end; 437 start = end;
438 int ccc = 0; 438 int ccc = 0;
439 while ( start > 0 ) { 439 while ( start > 0 ) {
440 templist.clear(); 440 templist.clear();
441 ok = true; 441 ok = true;
442 int loopCount = 0; 442 int loopCount = 0;
443 while ( ok ) { 443 while ( ok ) {
444 ++loopCount; 444 ++loopCount;
445 if ( loopCount > 25 ) { 445 if ( loopCount > 25 ) {
446 qDebug("KO: Error in while loop"); 446 qDebug("KO: Error in while loop");
447 ok = false; 447 ok = false;
448 start = 0; 448 start = 0;
449 break; 449 break;
450 } 450 }
451 if ( ok ) 451 if ( ok )
452 tempString = getPart( answer, ok, start ); 452 tempString = getPart( answer, ok, start );
453 if ( start >= len || start == 0 ) { 453 if ( start >= len || start == 0 ) {
454 start = 0; 454 start = 0;
455 ok = false; 455 ok = false;
456 } 456 }
457 if ( tempString.right(1) =="\n" ) 457 if ( tempString.right(1) =="\n" )
458 tempString = tempString.left( tempString.length()-1); 458 tempString = tempString.left( tempString.length()-1);
459 459
460 templist.append( tempString ); 460 templist.append( tempString );
461 } 461 }
462 ++ccc; 462 ++ccc;
463 if ( ccc == 2 && loopCount < 25 ) { 463 if ( ccc == 2 && loopCount < 25 ) {
464 start = 0; 464 start = 0;
465 bool ok; 465 bool ok;
466 int newnum = templist[0].toInt( &ok ); 466 int newnum = templist[0].toInt( &ok );
467 if ( ok && newnum > 0) { 467 if ( ok && newnum > 0) {
468 retval = newnum; 468 retval = newnum;
469 inc->setID( "Sharp_DTM",newnum ); 469 inc->setID( "Sharp_DTM",templist[0] );
470 inc->setZaurusUid( getCsum( templist ) ); 470 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
471 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 471 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
472 } 472 }
473 } 473 }
474 } 474 }
475 //qDebug("getNumFromRecord returning : %d ", retval); 475 //qDebug("getNumFromRecord returning : %d ", retval);
476 return retval; 476 return retval;
477} 477}
478bool SharpFormat::save( Calendar *calendar) 478bool SharpFormat::save( Calendar *calendar)
479{ 479{
480 480
481 QLabel status ( i18n("Processing/adding events ..."), 0 ); 481 QLabel status ( i18n("Processing/adding events ..."), 0 );
482 int w = status.sizeHint().width()+20 ; 482 int w = status.sizeHint().width()+20 ;
483 if ( w < 200 ) w = 200; 483 if ( w < 200 ) w = 200;
484 int h = status.sizeHint().height()+20 ; 484 int h = status.sizeHint().height()+20 ;
485 int dw = QApplication::desktop()->width(); 485 int dw = QApplication::desktop()->width();
486 int dh = QApplication::desktop()->height(); 486 int dh = QApplication::desktop()->height();
487 status.setCaption(i18n("Writing DTM Data") ); 487 status.setCaption(i18n("Writing DTM Data") );
488 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 488 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
489 status.show(); 489 status.show();
490 status.raise(); 490 status.raise();
491 qApp->processEvents(); 491 qApp->processEvents();
492 bool debug = DEBUGMODE; 492 bool debug = DEBUGMODE;
493 QString codec = "utf8"; 493 QString codec = "utf8";
494 QString answer; 494 QString answer;
495 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 495 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
496 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 496 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
497 QString command; 497 QString command;
498 QPtrList<Event> er = calendar->rawEvents(); 498 QPtrList<Event> er = calendar->rawEvents();
499 Event* ev = er.first(); 499 Event* ev = er.first();
500 QString fileName = "/tmp/kopitempout"; 500 QString fileName = "/tmp/kopitempout";
501 int i = 0; 501 int i = 0;
502 QString changeString = ePrefix; 502 QString changeString = ePrefix;
503 QString deleteString = ePrefix; 503 QString deleteString = ePrefix;
504 bool deleteEnt = false; 504 bool deleteEnt = false;
505 bool changeEnt = false; 505 bool changeEnt = false;
506 QString message = i18n("Processing event # "); 506 QString message = i18n("Processing event # ");
507 int procCount = 0; 507 int procCount = 0;
508 while ( ev ) { 508 while ( ev ) {
509 //qDebug("i %d ", ++i); 509 //qDebug("i %d ", ++i);
510 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 510 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
511 status.setText ( message + QString::number ( ++procCount ) ); 511 status.setText ( message + QString::number ( ++procCount ) );
512 qApp->processEvents(); 512 qApp->processEvents();
513 QString eString = getEventString( ev ); 513 QString eString = getEventString( ev );
514 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 514 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
515 // deleting empty strings does not work. 515 // deleting empty strings does not work.
516 // we write first and x and then delete the record with the x 516 // we write first and x and then delete the record with the x
517 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 517 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
518 changeString += eString + "\n"; 518 changeString += eString + "\n";
519 deleteString += eString + "\n"; 519 deleteString += eString + "\n";
520 deleteEnt = true; 520 deleteEnt = true;
521 changeEnt = true; 521 changeEnt = true;
522 } 522 }
523 else if ( ev->getID("Sharp_DTM") == -1 ) { // add new 523 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
524 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 524 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
525 system ( command.utf8() ); 525 system ( command.utf8() );
526 QFile file( fileName ); 526 QFile file( fileName );
527 if (!file.open( IO_ReadOnly ) ) { 527 if (!file.open( IO_ReadOnly ) ) {
528 return false; 528 return false;
529 529
530 } 530 }
531 QTextStream ts( &file ); 531 QTextStream ts( &file );
532 ts.setCodec( QTextCodec::codecForName("utf8") ); 532 ts.setCodec( QTextCodec::codecForName("utf8") );
533 answer = ts.read(); 533 answer = ts.read();
534 file.close(); 534 file.close();
535 //qDebug("answer \n%s ", answer.latin1()); 535 //qDebug("answer \n%s ", answer.latin1());
536 getNumFromRecord( answer, ev ) ; 536 getNumFromRecord( answer, ev ) ;
537 537
538 } 538 }
539 else { // change existing 539 else { // change existing
540 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 540 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
541 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 541 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
542 changeString += eString + "\n"; 542 changeString += eString + "\n";
543 changeEnt = true; 543 changeEnt = true;
544 544
545 } 545 }
546 } 546 }
547 ev = er.next(); 547 ev = er.next();
548 } 548 }
549 status.setText ( i18n("Changing events ...") ); 549 status.setText ( i18n("Changing events ...") );
550 qApp->processEvents(); 550 qApp->processEvents();
551 //qDebug("changing... "); 551 //qDebug("changing... ");
552 if ( changeEnt ) { 552 if ( changeEnt ) {
553 QFile file( fileName ); 553 QFile file( fileName );
554 if (!file.open( IO_WriteOnly ) ) { 554 if (!file.open( IO_WriteOnly ) ) {
555 return false; 555 return false;
556 556
557 } 557 }
558 QTextStream ts( &file ); 558 QTextStream ts( &file );
559 ts.setCodec( QTextCodec::codecForName("utf8") ); 559 ts.setCodec( QTextCodec::codecForName("utf8") );
560 ts << changeString ; 560 ts << changeString ;
561 file.close(); 561 file.close();
562 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 562 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
563 system ( command.latin1() ); 563 system ( command.latin1() );
564 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 564 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
565 565
566 } 566 }
567 status.setText ( i18n("Deleting events ...") ); 567 status.setText ( i18n("Deleting events ...") );
568 qApp->processEvents(); 568 qApp->processEvents();
569 //qDebug("deleting... "); 569 //qDebug("deleting... ");
570 if ( deleteEnt ) { 570 if ( deleteEnt ) {
571 QFile file( fileName ); 571 QFile file( fileName );
572 if (!file.open( IO_WriteOnly ) ) { 572 if (!file.open( IO_WriteOnly ) ) {
573 return false; 573 return false;
574 574
575 } 575 }
576 QTextStream ts( &file ); 576 QTextStream ts( &file );
577 ts.setCodec( QTextCodec::codecForName("utf8") ); 577 ts.setCodec( QTextCodec::codecForName("utf8") );
578 ts << deleteString; 578 ts << deleteString;
579 file.close(); 579 file.close();
580 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 580 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
581 system ( command.latin1() ); 581 system ( command.latin1() );
582 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 582 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
583 } 583 }
584 584
585 585
586 changeString = tPrefix; 586 changeString = tPrefix;
587 deleteString = tPrefix; 587 deleteString = tPrefix;
588 status.setText ( i18n("Processing todos ...") ); 588 status.setText ( i18n("Processing todos ...") );
589 qApp->processEvents(); 589 qApp->processEvents();
590 QPtrList<Todo> tl = calendar->rawTodos(); 590 QPtrList<Todo> tl = calendar->rawTodos();
591 Todo* to = tl.first(); 591 Todo* to = tl.first();
592 i = 0; 592 i = 0;
593 message = i18n("Processing todo # "); 593 message = i18n("Processing todo # ");
594 procCount = 0; 594 procCount = 0;
595 while ( to ) { 595 while ( to ) {
596 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 596 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
597 status.setText ( message + QString::number ( ++procCount ) ); 597 status.setText ( message + QString::number ( ++procCount ) );
598 qApp->processEvents(); 598 qApp->processEvents();
599 QString eString = getTodoString( to ); 599 QString eString = getTodoString( to );
600 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 600 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
601 // deleting empty strings does not work. 601 // deleting empty strings does not work.
602 // we write first and x and then delete the record with the x 602 // we write first and x and then delete the record with the x
603 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 603 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
604 changeString += eString + "\n"; 604 changeString += eString + "\n";
605 deleteString += eString + "\n"; 605 deleteString += eString + "\n";
606 deleteEnt = true; 606 deleteEnt = true;
607 changeEnt = true; 607 changeEnt = true;
608 } 608 }
609 else if ( to->getID("Sharp_DTM") == -1 ) { // add new 609 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
610 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 610 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
611 system ( command.utf8() ); 611 system ( command.utf8() );
612 QFile file( fileName ); 612 QFile file( fileName );
613 if (!file.open( IO_ReadOnly ) ) { 613 if (!file.open( IO_ReadOnly ) ) {
614 return false; 614 return false;
615 615
616 } 616 }
617 QTextStream ts( &file ); 617 QTextStream ts( &file );
618 ts.setCodec( QTextCodec::codecForName("utf8") ); 618 ts.setCodec( QTextCodec::codecForName("utf8") );
619 answer = ts.read(); 619 answer = ts.read();
620 file.close(); 620 file.close();
621 //qDebug("answer \n%s ", answer.latin1()); 621 //qDebug("answer \n%s ", answer.latin1());
622 getNumFromRecord( answer, to ) ; 622 getNumFromRecord( answer, to ) ;
623 623
624 } 624 }
625 else { // change existing 625 else { // change existing
626 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 626 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
627 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 627 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
628 changeString += eString + "\n"; 628 changeString += eString + "\n";
629 changeEnt = true; 629 changeEnt = true;
630 630
631 } 631 }
632 } 632 }
633 633
634 to = tl.next(); 634 to = tl.next();
635 } 635 }
636 status.setText ( i18n("Changing todos ...") ); 636 status.setText ( i18n("Changing todos ...") );
637 qApp->processEvents(); 637 qApp->processEvents();
638 //qDebug("changing... "); 638 //qDebug("changing... ");
639 if ( changeEnt ) { 639 if ( changeEnt ) {
640 QFile file( fileName ); 640 QFile file( fileName );
641 if (!file.open( IO_WriteOnly ) ) { 641 if (!file.open( IO_WriteOnly ) ) {
642 return false; 642 return false;
643 643
644 } 644 }
645 QTextStream ts( &file ); 645 QTextStream ts( &file );
646 ts.setCodec( QTextCodec::codecForName("utf8") ); 646 ts.setCodec( QTextCodec::codecForName("utf8") );
647 ts << changeString ; 647 ts << changeString ;
648 file.close(); 648 file.close();
649 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 649 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
650 system ( command.latin1() ); 650 system ( command.latin1() );
651 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 651 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
652 652
653 } 653 }
654 status.setText ( i18n("Deleting todos ...") ); 654 status.setText ( i18n("Deleting todos ...") );
655 qApp->processEvents(); 655 qApp->processEvents();
656 //qDebug("deleting... "); 656 //qDebug("deleting... ");
657 if ( deleteEnt ) { 657 if ( deleteEnt ) {
658 QFile file( fileName ); 658 QFile file( fileName );
659 if (!file.open( IO_WriteOnly ) ) { 659 if (!file.open( IO_WriteOnly ) ) {
660 return false; 660 return false;
661 661
662 } 662 }
663 QTextStream ts( &file ); 663 QTextStream ts( &file );
664 ts.setCodec( QTextCodec::codecForName("utf8") ); 664 ts.setCodec( QTextCodec::codecForName("utf8") );
665 ts << deleteString; 665 ts << deleteString;
666 file.close(); 666 file.close();
667 command = "db2file todo -d -c " + codec+ " < "+ fileName; 667 command = "db2file todo -d -c " + codec+ " < "+ fileName;
668 system ( command.latin1() ); 668 system ( command.latin1() );
669 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 669 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
670 } 670 }
671 671
672 return true; 672 return true;
673} 673}
674QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 674QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
675{ 675{
676 QString datestr; 676 QString datestr;
677 QString timestr; 677 QString timestr;
678 int offset = KGlobal::locale()->localTimeOffset( dti ); 678 int offset = KGlobal::locale()->localTimeOffset( dti );
679 QDateTime dt; 679 QDateTime dt;
680 if (useTZ) 680 if (useTZ)
681 dt = dti.addSecs ( -(offset*60)); 681 dt = dti.addSecs ( -(offset*60));
682 else 682 else
683 dt = dti; 683 dt = dti;
684 if(dt.date().isValid()){ 684 if(dt.date().isValid()){
685 const QDate& date = dt.date(); 685 const QDate& date = dt.date();
686 datestr.sprintf("%04d%02d%02d", 686 datestr.sprintf("%04d%02d%02d",
687 date.year(), date.month(), date.day()); 687 date.year(), date.month(), date.day());
688 } 688 }
689 if(dt.time().isValid()){ 689 if(dt.time().isValid()){
690 const QTime& time = dt.time(); 690 const QTime& time = dt.time();
691 timestr.sprintf("T%02d%02d%02d", 691 timestr.sprintf("T%02d%02d%02d",
692 time.hour(), time.minute(), time.second()); 692 time.hour(), time.minute(), time.second());
693 } 693 }
694 return datestr + timestr; 694 return datestr + timestr;
695} 695}
696QString SharpFormat::getEventString( Event* event ) 696QString SharpFormat::getEventString( Event* event )
697{ 697{
698 QStringList list; 698 QStringList list;
699 list.append( QString::number(event->getID("Sharp_DTM") ) ); 699 list.append( event->getID("Sharp_DTM") );
700 list.append( event->categories().join(",") ); 700 list.append( event->categories().join(",") );
701 if ( !event->summary().isEmpty() ) 701 if ( !event->summary().isEmpty() )
702 list.append( event->summary() ); 702 list.append( event->summary() );
703 else 703 else
704 list.append("" ); 704 list.append("" );
705 if ( !event->location().isEmpty() ) 705 if ( !event->location().isEmpty() )
706 list.append( event->location() ); 706 list.append( event->location() );
707 else 707 else
708 list.append("" ); 708 list.append("" );
709 if ( !event->description().isEmpty() ) 709 if ( !event->description().isEmpty() )
710 list.append( event->description() ); 710 list.append( event->description() );
711 else 711 else
712 list.append( "" ); 712 list.append( "" );
713 if ( event->doesFloat () ) { 713 if ( event->doesFloat () ) {
714 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 714 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
715 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 715 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
716 list.append( "1" ); 716 list.append( "1" );
717 717
718 } 718 }
719 else { 719 else {
720 list.append( dtToString( event->dtStart()) ); 720 list.append( dtToString( event->dtStart()) );
721 list.append( dtToString( event->dtEnd()) ); //6 721 list.append( dtToString( event->dtEnd()) ); //6
722 list.append( "0" ); 722 list.append( "0" );
723 } 723 }
724 bool noAlarm = true; 724 bool noAlarm = true;
725 if ( event->alarms().count() > 0 ) { 725 if ( event->alarms().count() > 0 ) {
726 Alarm * al = event->alarms().first(); 726 Alarm * al = event->alarms().first();
727 if ( al->enabled() ) { 727 if ( al->enabled() ) {
728 noAlarm = false; 728 noAlarm = false;
729 list.append( "0" ); // yes, 0 == alarm 729 list.append( "0" ); // yes, 0 == alarm
730 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 730 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
731 if ( al->type() == Alarm::Audio ) 731 if ( al->type() == Alarm::Audio )
732 list.append( "1" ); // type audio 732 list.append( "1" ); // type audio
733 else 733 else
734 list.append( "0" ); // type silent 734 list.append( "0" ); // type silent
735 } 735 }
736 } 736 }
737 if ( noAlarm ) { 737 if ( noAlarm ) {
738 list.append( "1" ); // yes, 1 == no alarm 738 list.append( "1" ); // yes, 1 == no alarm
739 list.append( "0" ); // no alarm offset 739 list.append( "0" ); // no alarm offset
740 list.append( "1" ); // type 740 list.append( "1" ); // type
741 } 741 }
742 // next is: 11 742 // next is: 11
743 // next is: 11-16 are recurrence 743 // next is: 11-16 are recurrence
744 Recurrence* rec = event->recurrence(); 744 Recurrence* rec = event->recurrence();
745 745
746 bool writeEndDate = false; 746 bool writeEndDate = false;
747 switch ( rec->doesRecur() ) 747 switch ( rec->doesRecur() )
748 { 748 {
749 case Recurrence::rDaily: // 0 749 case Recurrence::rDaily: // 0
750 list.append( "0" ); 750 list.append( "0" );
751 list.append( QString::number( rec->frequency() ));//12 751 list.append( QString::number( rec->frequency() ));//12
752 list.append( "0" ); 752 list.append( "0" );
753 list.append( "0" ); 753 list.append( "0" );
754 writeEndDate = true; 754 writeEndDate = true;
755 break; 755 break;
756 case Recurrence::rWeekly:// 1 756 case Recurrence::rWeekly:// 1
757 list.append( "1" ); 757 list.append( "1" );
758 list.append( QString::number( rec->frequency()) );//12 758 list.append( QString::number( rec->frequency()) );//12
759 list.append( "0" ); 759 list.append( "0" );
760 { 760 {
761 int days = 0; 761 int days = 0;
762 QBitArray weekDays = rec->days(); 762 QBitArray weekDays = rec->days();
763 int i; 763 int i;
764 for( i = 1; i <= 7; ++i ) { 764 for( i = 1; i <= 7; ++i ) {
765 if ( weekDays[i-1] ) { 765 if ( weekDays[i-1] ) {
766 days += 1 << (i-1); 766 days += 1 << (i-1);
767 } 767 }
768 } 768 }
769 list.append( QString::number( days ) ); 769 list.append( QString::number( days ) );
770 } 770 }
771 //pending weekdays 771 //pending weekdays
772 writeEndDate = true; 772 writeEndDate = true;
773 773
774 break; 774 break;
775 case Recurrence::rMonthlyPos:// 2 775 case Recurrence::rMonthlyPos:// 2
776 list.append( "2" ); 776 list.append( "2" );
777 list.append( QString::number( rec->frequency()) );//12 777 list.append( QString::number( rec->frequency()) );//12
778 778
779 writeEndDate = true; 779 writeEndDate = true;
780 { 780 {
781 int count = 1; 781 int count = 1;
782 QPtrList<Recurrence::rMonthPos> rmp; 782 QPtrList<Recurrence::rMonthPos> rmp;
783 rmp = rec->monthPositions(); 783 rmp = rec->monthPositions();
784 if ( rmp.first()->negative ) 784 if ( rmp.first()->negative )
785 count = 5 - rmp.first()->rPos - 1; 785 count = 5 - rmp.first()->rPos - 1;
786 else 786 else
787 count = rmp.first()->rPos - 1; 787 count = rmp.first()->rPos - 1;
788 list.append( QString::number( count ) ); 788 list.append( QString::number( count ) );
789 789
790 } 790 }
791 791
792 list.append( "0" ); 792 list.append( "0" );
793 break; 793 break;
794 case Recurrence::rMonthlyDay:// 3 794 case Recurrence::rMonthlyDay:// 3
795 list.append( "3" ); 795 list.append( "3" );
796 list.append( QString::number( rec->frequency()) );//12 796 list.append( QString::number( rec->frequency()) );//12
797 list.append( "0" ); 797 list.append( "0" );
798 list.append( "0" ); 798 list.append( "0" );
799 writeEndDate = true; 799 writeEndDate = true;
800 break; 800 break;
801 case Recurrence::rYearlyMonth://4 801 case Recurrence::rYearlyMonth://4
802 list.append( "4" ); 802 list.append( "4" );
803 list.append( QString::number( rec->frequency()) );//12 803 list.append( QString::number( rec->frequency()) );//12
804 list.append( "0" ); 804 list.append( "0" );
805 list.append( "0" ); 805 list.append( "0" );
806 writeEndDate = true; 806 writeEndDate = true;
807 break; 807 break;
808 808
809 default: 809 default:
810 list.append( "255" ); 810 list.append( "255" );
811 list.append( QString() ); 811 list.append( QString() );
812 list.append( "0" ); 812 list.append( "0" );
813 list.append( QString() ); 813 list.append( QString() );
814 list.append( "0" ); 814 list.append( "0" );
815 list.append( "20991231T000000" ); 815 list.append( "20991231T000000" );
816 break; 816 break;
817 } 817 }
818 if ( writeEndDate ) { 818 if ( writeEndDate ) {
819 819
820 if ( rec->endDate().isValid() ) { // 15 + 16 820 if ( rec->endDate().isValid() ) { // 15 + 16
821 list.append( "1" ); 821 list.append( "1" );
822 list.append( dtToString( rec->endDate()) ); 822 list.append( dtToString( rec->endDate()) );
823 } else { 823 } else {
824 list.append( "0" ); 824 list.append( "0" );
825 list.append( "20991231T000000" ); 825 list.append( "20991231T000000" );
826 } 826 }
827 827
828 } 828 }
829 if ( event->doesFloat () ) { 829 if ( event->doesFloat () ) {
830 list.append( dtToString( event->dtStart(), false ).left( 8 )); 830 list.append( dtToString( event->dtStart(), false ).left( 8 ));
831 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 831 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
832 832
833 } 833 }
834 else { 834 else {
835 list.append( QString() ); 835 list.append( QString() );
836 list.append( QString() ); 836 list.append( QString() );
837 837
838 } 838 }
839 if (event->dtStart().date() == event->dtEnd().date() ) 839 if (event->dtStart().date() == event->dtEnd().date() )
840 list.append( "0" ); 840 list.append( "0" );
841 else 841 else
842 list.append( "1" ); 842 list.append( "1" );
843 843
844 844
845 for(QStringList::Iterator it=list.begin(); 845 for(QStringList::Iterator it=list.begin();
846 it!=list.end(); ++it){ 846 it!=list.end(); ++it){
847 QString& s = (*it); 847 QString& s = (*it);
848 s.replace(QRegExp("\""), "\"\""); 848 s.replace(QRegExp("\""), "\"\"");
849 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 849 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
850 s.prepend('\"'); 850 s.prepend('\"');
851 s.append('\"'); 851 s.append('\"');
852 } else if(s.isEmpty() && !s.isNull()){ 852 } else if(s.isEmpty() && !s.isNull()){
853 s = "\"\""; 853 s = "\"\"";
854 } 854 }
855 } 855 }
856 return list.join(","); 856 return list.join(",");
857 857
858 858
859} 859}
860QString SharpFormat::getTodoString( Todo* todo ) 860QString SharpFormat::getTodoString( Todo* todo )
861{ 861{
862 QStringList list; 862 QStringList list;
863 list.append( QString::number( todo->getID("Sharp_DTM") ) ); 863 list.append( todo->getID("Sharp_DTM") );
864 list.append( todo->categories().join(",") ); 864 list.append( todo->categories().join(",") );
865 865
866 if ( todo->hasStartDate() ) { 866 if ( todo->hasStartDate() ) {
867 list.append( dtToString( todo->dtStart()) ); 867 list.append( dtToString( todo->dtStart()) );
868 } else 868 } else
869 list.append( QString() ); 869 list.append( QString() );
870 870
871 if ( todo->hasDueDate() ) { 871 if ( todo->hasDueDate() ) {
872 QTime tim; 872 QTime tim;
873 if ( todo->doesFloat()) { 873 if ( todo->doesFloat()) {
874 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 874 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
875 } else { 875 } else {
876 list.append( dtToString(todo->dtDue() ) ); 876 list.append( dtToString(todo->dtDue() ) );
877 } 877 }
878 } else 878 } else
879 list.append( QString() ); 879 list.append( QString() );
880 880
881 if ( todo->isCompleted() ) { 881 if ( todo->isCompleted() ) {
882 list.append( dtToString( todo->completed()) ); 882 list.append( dtToString( todo->completed()) );
883 list.append( "0" ); // yes 0 == completed 883 list.append( "0" ); // yes 0 == completed
884 } else { 884 } else {
885 list.append( dtToString( todo->completed()) ); 885 list.append( dtToString( todo->completed()) );
886 list.append( "1" ); 886 list.append( "1" );
887 } 887 }
888 list.append( QString::number( todo->priority() )); 888 list.append( QString::number( todo->priority() ));
889 if( ! todo->summary().isEmpty() ) 889 if( ! todo->summary().isEmpty() )
890 list.append( todo->summary() ); 890 list.append( todo->summary() );
891 else 891 else
892 list.append( "" ); 892 list.append( "" );
893 if (! todo->description().isEmpty() ) 893 if (! todo->description().isEmpty() )
894 list.append( todo->description() ); 894 list.append( todo->description() );
895 else 895 else
896 list.append( "" ); 896 list.append( "" );
897 for(QStringList::Iterator it=list.begin(); 897 for(QStringList::Iterator it=list.begin();
898 it!=list.end(); ++it){ 898 it!=list.end(); ++it){
899 QString& s = (*it); 899 QString& s = (*it);
900 s.replace(QRegExp("\""), "\"\""); 900 s.replace(QRegExp("\""), "\"\"");
901 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 901 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
902 s.prepend('\"'); 902 s.prepend('\"');
903 s.append('\"'); 903 s.append('\"');
904 } else if(s.isEmpty() && !s.isNull()){ 904 } else if(s.isEmpty() && !s.isNull()){
905 s = "\"\""; 905 s = "\"\"";
906 } 906 }
907 } 907 }
908 return list.join(","); 908 return list.join(",");
909} 909}
910QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) 910QString SharpFormat::getPart( const QString & text, bool &ok, int &start )
911{ 911{
912 //qDebug("start %d ", start); 912 //qDebug("start %d ", start);
913 913
914 QString retval =""; 914 QString retval ="";
915 if ( text.at(start) == '"' ) { 915 if ( text.at(start) == '"' ) {
916 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { 916 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) {
917 start = start +2; 917 start = start +2;
918 if ( text.mid( start,1) == "," ) { 918 if ( text.mid( start,1) == "," ) {
919 start += 1; 919 start += 1;
920 } 920 }
921 retval = ""; 921 retval = "";
922 if ( text.mid( start,1) == "\n" ) { 922 if ( text.mid( start,1) == "\n" ) {
923 start += 1; 923 start += 1;
924 ok = false; 924 ok = false;
925 } 925 }
926 return retval; 926 return retval;
927 } 927 }
928 int hk = start+1; 928 int hk = start+1;
929 hk = text.find ('"',hk); 929 hk = text.find ('"',hk);
930 while ( text.at(hk+1) == '"' ) 930 while ( text.at(hk+1) == '"' )
931 hk = text.find ('"',hk+2); 931 hk = text.find ('"',hk+2);
932 retval = text.mid( start+1, hk-start-1); 932 retval = text.mid( start+1, hk-start-1);
933 start = hk+1; 933 start = hk+1;
934 retval.replace( QRegExp("\"\""), "\""); 934 retval.replace( QRegExp("\"\""), "\"");
935 if ( text.mid( start,1) == "," ) { 935 if ( text.mid( start,1) == "," ) {
936 start += 1; 936 start += 1;
937 } 937 }
938 if ( text.mid( start,1) == "\n" ) { 938 if ( text.mid( start,1) == "\n" ) {
939 start += 1; 939 start += 1;
940 ok = false; 940 ok = false;
941 } 941 }
942 //qDebug("retval***%s*** ",retval.latin1() ); 942 //qDebug("retval***%s*** ",retval.latin1() );
943 return retval; 943 return retval;
944 944
945 } else { 945 } else {
946 int nl = text.find ("\n",start); 946 int nl = text.find ("\n",start);
947 int kom = text.find (',',start); 947 int kom = text.find (',',start);
948 if ( kom < nl ) { 948 if ( kom < nl ) {
949 // qDebug("kom < nl %d ", kom); 949 // qDebug("kom < nl %d ", kom);
950 retval = text.mid(start, kom-start); 950 retval = text.mid(start, kom-start);
951 start = kom+1; 951 start = kom+1;
952 return retval; 952 return retval;
953 } else { 953 } else {
954 if ( nl == kom ) { 954 if ( nl == kom ) {
955 // qDebug(" nl == kom "); 955 // qDebug(" nl == kom ");
956 start = 0; 956 start = 0;
957 ok = false; 957 ok = false;
958 return "0"; 958 return "0";
959 } 959 }
960 // qDebug(" nl < kom ", nl); 960 // qDebug(" nl < kom ", nl);
961 retval = text.mid( start, nl-start); 961 retval = text.mid( start, nl-start);
962 ok = false; 962 ok = false;
963 start = nl+1; 963 start = nl+1;
964 return retval; 964 return retval;
965 } 965 }
966 } 966 }
967} 967}
968bool SharpFormat::fromString( Calendar *calendar, const QString & text) 968bool SharpFormat::fromString( Calendar *calendar, const QString & text)
969{ 969{
970 return false; 970 return false;
971} 971}
972bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) 972bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type)
973{ 973{
974 // qDebug("test %s ", text.latin1()); 974 // qDebug("test %s ", text.latin1());
975 QStringList templist; 975 QStringList templist;
976 QString tempString; 976 QString tempString;
977 int start = 0; 977 int start = 0;
978 int len = text.length(); 978 int len = text.length();
979 int end = text.find ("\n",start)+1; 979 int end = text.find ("\n",start)+1;
980 bool ok = true; 980 bool ok = true;
981 start = end; 981 start = end;
982 SharpParser handler( calendar ); 982 SharpParser handler( calendar );
983 handler.setCategoriesList( mCategories ); 983 handler.setCategoriesList( mCategories );
984 while ( start > 0 ) { 984 while ( start > 0 ) {
985 templist.clear(); 985 templist.clear();
986 ok = true; 986 ok = true;
987 while ( ok ) { 987 while ( ok ) {
988 tempString = getPart( text, ok, start ); 988 tempString = getPart( text, ok, start );
989 if ( start >= len || start == 0 ) { 989 if ( start >= len || start == 0 ) {
990 start = 0; 990 start = 0;
991 ok = false; 991 ok = false;
992 } 992 }
993 if ( tempString.right(1) =="\n" ) 993 if ( tempString.right(1) =="\n" )
994 tempString = tempString.left( tempString.length()-1); 994 tempString = tempString.left( tempString.length()-1);
995 //if ( ok ) 995 //if ( ok )
996 templist.append( tempString ); 996 templist.append( tempString );
997 //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); 997 //qDebug("%d ---%s---", templist.count(),tempString.latin1() );
998 } 998 }
999 handler.startElement( existingCalendar, templist, type ); 999 handler.startElement( existingCalendar, templist, type );
1000 } 1000 }
1001 1001
1002 return false; 1002 return false;
1003} 1003}
1004 1004
1005QString SharpFormat::toString( Calendar * ) 1005QString SharpFormat::toString( Calendar * )
1006{ 1006{
1007 return QString::null; 1007 return QString::null;
1008} 1008}