summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-14 03:13:52 (UTC)
committer zautrix <zautrix>2004-09-14 03:13:52 (UTC)
commitf1f43030eefa765950cb501aece6cc71fb4e9859 (patch) (unidiff)
treed7396ac13ab052ee38e2e8e139854cc88a289a43
parent5060b0737c0c279859cac3bcfb73d2ac21c6a79e (diff)
downloadkdepimpi-f1f43030eefa765950cb501aece6cc71fb4e9859.zip
kdepimpi-f1f43030eefa765950cb501aece6cc71fb4e9859.tar.gz
kdepimpi-f1f43030eefa765950cb501aece6cc71fb4e9859.tar.bz2
More fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp9
-rw-r--r--libkcal/sharpformat.cpp18
2 files changed, 21 insertions, 6 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 5a6d615..369c7a0 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -476,899 +476,898 @@ CalendarView::~CalendarView()
476 //kdDebug() << "~CalendarView() done" << endl; 476 //kdDebug() << "~CalendarView() done" << endl;
477} 477}
478void CalendarView::timerAlarm() 478void CalendarView::timerAlarm()
479{ 479{
480 //qDebug("CalendarView::timerAlarm() "); 480 //qDebug("CalendarView::timerAlarm() ");
481 computeAlarm(mAlarmNotification ); 481 computeAlarm(mAlarmNotification );
482} 482}
483 483
484void CalendarView::suspendAlarm() 484void CalendarView::suspendAlarm()
485{ 485{
486 //qDebug(" CalendarView::suspendAlarm() "); 486 //qDebug(" CalendarView::suspendAlarm() ");
487 computeAlarm(mSuspendAlarmNotification ); 487 computeAlarm(mSuspendAlarmNotification );
488 488
489} 489}
490 490
491void CalendarView::startAlarm( QString mess , QString filename) 491void CalendarView::startAlarm( QString mess , QString filename)
492{ 492{
493 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 493 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
494 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 494 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
495 495
496} 496}
497 497
498void CalendarView::checkNextTimerAlarm() 498void CalendarView::checkNextTimerAlarm()
499{ 499{
500 mCalendar->checkAlarmForIncidence( 0, true ); 500 mCalendar->checkAlarmForIncidence( 0, true );
501} 501}
502 502
503void CalendarView::computeAlarm( QString msg ) 503void CalendarView::computeAlarm( QString msg )
504{ 504{
505 505
506 QString mess = msg; 506 QString mess = msg;
507 QString mAlarmMessage = mess.mid( 9 ); 507 QString mAlarmMessage = mess.mid( 9 );
508 QString filename = MainWindow::resourcePath(); 508 QString filename = MainWindow::resourcePath();
509 filename += "koalarm.wav"; 509 filename += "koalarm.wav";
510 QString tempfilename; 510 QString tempfilename;
511 if ( mess.left( 13 ) == "suspend_alarm") { 511 if ( mess.left( 13 ) == "suspend_alarm") {
512 bool error = false; 512 bool error = false;
513 int len = mess.mid( 13 ).find("+++"); 513 int len = mess.mid( 13 ).find("+++");
514 if ( len < 2 ) 514 if ( len < 2 )
515 error = true; 515 error = true;
516 else { 516 else {
517 tempfilename = mess.mid( 13, len ); 517 tempfilename = mess.mid( 13, len );
518 if ( !QFile::exists( tempfilename ) ) 518 if ( !QFile::exists( tempfilename ) )
519 error = true; 519 error = true;
520 } 520 }
521 if ( ! error ) { 521 if ( ! error ) {
522 filename = tempfilename; 522 filename = tempfilename;
523 } 523 }
524 mAlarmMessage = mess.mid( 13+len+3 ); 524 mAlarmMessage = mess.mid( 13+len+3 );
525 //qDebug("suspend file %s ",tempfilename.latin1() ); 525 //qDebug("suspend file %s ",tempfilename.latin1() );
526 startAlarm( mAlarmMessage, filename); 526 startAlarm( mAlarmMessage, filename);
527 return; 527 return;
528 } 528 }
529 if ( mess.left( 11 ) == "timer_alarm") { 529 if ( mess.left( 11 ) == "timer_alarm") {
530 //mTimerTime = 0; 530 //mTimerTime = 0;
531 startAlarm( mess.mid( 11 ), filename ); 531 startAlarm( mess.mid( 11 ), filename );
532 return; 532 return;
533 } 533 }
534 if ( mess.left( 10 ) == "proc_alarm") { 534 if ( mess.left( 10 ) == "proc_alarm") {
535 bool error = false; 535 bool error = false;
536 int len = mess.mid( 10 ).find("+++"); 536 int len = mess.mid( 10 ).find("+++");
537 if ( len < 2 ) 537 if ( len < 2 )
538 error = true; 538 error = true;
539 else { 539 else {
540 tempfilename = mess.mid( 10, len ); 540 tempfilename = mess.mid( 10, len );
541 if ( !QFile::exists( tempfilename ) ) 541 if ( !QFile::exists( tempfilename ) )
542 error = true; 542 error = true;
543 } 543 }
544 if ( error ) { 544 if ( error ) {
545 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 545 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
546 mAlarmMessage += mess.mid( 10+len+3+9 ); 546 mAlarmMessage += mess.mid( 10+len+3+9 );
547 } else { 547 } else {
548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
549 //qDebug("-----system command %s ",tempfilename.latin1() ); 549 //qDebug("-----system command %s ",tempfilename.latin1() );
550#ifndef _WIN32_ 550#ifndef _WIN32_
551 if ( vfork () == 0 ) { 551 if ( vfork () == 0 ) {
552 execl ( tempfilename.latin1(), 0 ); 552 execl ( tempfilename.latin1(), 0 );
553 return; 553 return;
554 } 554 }
555#else 555#else
556 QProcess* p = new QProcess(); 556 QProcess* p = new QProcess();
557 p->addArgument( tempfilename.latin1() ); 557 p->addArgument( tempfilename.latin1() );
558 p->start(); 558 p->start();
559 return; 559 return;
560#endif 560#endif
561 561
562 return; 562 return;
563 } 563 }
564 564
565 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 565 //qDebug("+++++++system command %s ",tempfilename.latin1() );
566 } 566 }
567 if ( mess.left( 11 ) == "audio_alarm") { 567 if ( mess.left( 11 ) == "audio_alarm") {
568 bool error = false; 568 bool error = false;
569 int len = mess.mid( 11 ).find("+++"); 569 int len = mess.mid( 11 ).find("+++");
570 if ( len < 2 ) 570 if ( len < 2 )
571 error = true; 571 error = true;
572 else { 572 else {
573 tempfilename = mess.mid( 11, len ); 573 tempfilename = mess.mid( 11, len );
574 if ( !QFile::exists( tempfilename ) ) 574 if ( !QFile::exists( tempfilename ) )
575 error = true; 575 error = true;
576 } 576 }
577 if ( ! error ) { 577 if ( ! error ) {
578 filename = tempfilename; 578 filename = tempfilename;
579 } 579 }
580 mAlarmMessage = mess.mid( 11+len+3+9 ); 580 mAlarmMessage = mess.mid( 11+len+3+9 );
581 //qDebug("audio file command %s ",tempfilename.latin1() ); 581 //qDebug("audio file command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 9 ) == "cal_alarm") { 583 if ( mess.left( 9 ) == "cal_alarm") {
584 mAlarmMessage = mess.mid( 9 ) ; 584 mAlarmMessage = mess.mid( 9 ) ;
585 } 585 }
586 586
587 startAlarm( mAlarmMessage, filename ); 587 startAlarm( mAlarmMessage, filename );
588 588
589 589
590} 590}
591 591
592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
593{ 593{
594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
595 595
596 mSuspendAlarmNotification = noti; 596 mSuspendAlarmNotification = noti;
597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
599 mSuspendTimer->start( ms , true ); 599 mSuspendTimer->start( ms , true );
600 600
601} 601}
602 602
603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
604{ 604{
605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
607#ifndef DESKTOP_VERSION 607#ifndef DESKTOP_VERSION
608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
609#endif 609#endif
610 return; 610 return;
611 } 611 }
612 int maxSec; 612 int maxSec;
613 //maxSec = 5; //testing only 613 //maxSec = 5; //testing only
614 maxSec = 86400+3600; // one day+1hour 614 maxSec = 86400+3600; // one day+1hour
615 mAlarmNotification = noti; 615 mAlarmNotification = noti;
616 int sec = QDateTime::currentDateTime().secsTo( qdt ); 616 int sec = QDateTime::currentDateTime().secsTo( qdt );
617 if ( sec > maxSec ) { 617 if ( sec > maxSec ) {
618 mRecheckAlarmTimer->start( maxSec * 1000 ); 618 mRecheckAlarmTimer->start( maxSec * 1000 );
619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
620 return; 620 return;
621 } else { 621 } else {
622 mRecheckAlarmTimer->stop(); 622 mRecheckAlarmTimer->stop();
623 } 623 }
624 //qDebug("Alarm timer started with secs: %d ", sec); 624 //qDebug("Alarm timer started with secs: %d ", sec);
625 mAlarmTimer->start( sec *1000 , true ); 625 mAlarmTimer->start( sec *1000 , true );
626 626
627} 627}
628// called by mRecheckAlarmTimer to get next alarm 628// called by mRecheckAlarmTimer to get next alarm
629// we need this, because a QTimer has only a max range of 25 days 629// we need this, because a QTimer has only a max range of 25 days
630void CalendarView::recheckTimerAlarm() 630void CalendarView::recheckTimerAlarm()
631{ 631{
632 mAlarmTimer->stop(); 632 mAlarmTimer->stop();
633 mRecheckAlarmTimer->stop(); 633 mRecheckAlarmTimer->stop();
634 mCalendar->checkAlarmForIncidence( 0, true ); 634 mCalendar->checkAlarmForIncidence( 0, true );
635} 635}
636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
637{ 637{
638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
640#ifndef DESKTOP_VERSION 640#ifndef DESKTOP_VERSION
641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
642#endif 642#endif
643 return; 643 return;
644 } 644 }
645 mAlarmTimer->stop(); 645 mAlarmTimer->stop();
646} 646}
647void CalendarView::selectWeekNum ( int num ) 647void CalendarView::selectWeekNum ( int num )
648{ 648{
649 dateNavigator()->selectWeek( num ); 649 dateNavigator()->selectWeek( num );
650 mViewManager->showWeekView(); 650 mViewManager->showWeekView();
651} 651}
652KOViewManager *CalendarView::viewManager() 652KOViewManager *CalendarView::viewManager()
653{ 653{
654 return mViewManager; 654 return mViewManager;
655} 655}
656 656
657KODialogManager *CalendarView::dialogManager() 657KODialogManager *CalendarView::dialogManager()
658{ 658{
659 return mDialogManager; 659 return mDialogManager;
660} 660}
661 661
662QDate CalendarView::startDate() 662QDate CalendarView::startDate()
663{ 663{
664 DateList dates = mNavigator->selectedDates(); 664 DateList dates = mNavigator->selectedDates();
665 665
666 return dates.first(); 666 return dates.first();
667} 667}
668 668
669QDate CalendarView::endDate() 669QDate CalendarView::endDate()
670{ 670{
671 DateList dates = mNavigator->selectedDates(); 671 DateList dates = mNavigator->selectedDates();
672 672
673 return dates.last(); 673 return dates.last();
674} 674}
675 675
676 676
677void CalendarView::createPrinter() 677void CalendarView::createPrinter()
678{ 678{
679#ifndef KORG_NOPRINTER 679#ifndef KORG_NOPRINTER
680 if (!mCalPrinter) { 680 if (!mCalPrinter) {
681 mCalPrinter = new CalPrinter(this, mCalendar); 681 mCalPrinter = new CalPrinter(this, mCalendar);
682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
683 } 683 }
684#endif 684#endif
685} 685}
686 686
687void CalendarView::confSync() 687void CalendarView::confSync()
688{ 688{
689 static KSyncPrefsDialog* sp = 0; 689 static KSyncPrefsDialog* sp = 0;
690 if ( ! sp ) { 690 if ( ! sp ) {
691 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 691 sp = new KSyncPrefsDialog( this, "syncprefs", true );
692 } 692 }
693 sp->usrReadConfig(); 693 sp->usrReadConfig();
694#ifndef DESKTOP_VERSION 694#ifndef DESKTOP_VERSION
695 sp->showMaximized(); 695 sp->showMaximized();
696#else 696#else
697 sp->show(); 697 sp->show();
698#endif 698#endif
699 sp->exec(); 699 sp->exec();
700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
702} 702}
703 703
704 704
705//KOPrefs::instance()->mWriteBackFile 705//KOPrefs::instance()->mWriteBackFile
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
730 bool remCh, locCh; 730 bool remCh, locCh;
731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
732 if ( remCh ) 732 //if ( remCh )
733 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 733 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
734 locCh = ( local->lastModified() > mLastCalendarSync ); 734 locCh = ( local->lastModified() > mLastCalendarSync );
735 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
736 if ( !remCh && ! locCh ) { 735 if ( !remCh && ! locCh ) {
737 //qDebug("both not changed "); 736 //qDebug("both not changed ");
738 lastSync = local->lastModified().addDays(1); 737 lastSync = local->lastModified().addDays(1);
739 } else { 738 } else {
740 if ( locCh ) { 739 if ( locCh ) {
741 // qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); 740 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
742 lastSync = local->lastModified().addDays( -1 ); 741 lastSync = local->lastModified().addDays( -1 );
743 if ( !remCh ) 742 if ( !remCh )
744 remote->setLastModified( lastSync.addDays( -1 ) ); 743 remote->setLastModified( lastSync.addDays( -1 ) );
745 } else { 744 } else {
746 //qDebug(" not loc changed "); 745 //qDebug(" not loc changed ");
747 lastSync = local->lastModified().addDays( 1 ); 746 lastSync = local->lastModified().addDays( 1 );
748 if ( remCh ) 747 if ( remCh )
749 remote->setLastModified( lastSync.addDays( 1 ) ); 748 remote->setLastModified( lastSync.addDays( 1 ) );
750 749
751 } 750 }
752 } 751 }
753 full = true; 752 full = true;
754 if ( mode < SYNC_PREF_ASK ) 753 if ( mode < SYNC_PREF_ASK )
755 mode = SYNC_PREF_ASK; 754 mode = SYNC_PREF_ASK;
756 } else { 755 } else {
757 if ( local->lastModified() == remote->lastModified() ) 756 if ( local->lastModified() == remote->lastModified() )
758 if ( local->revision() == remote->revision() ) 757 if ( local->revision() == remote->revision() )
759 return 0; 758 return 0;
760 759
761 } 760 }
762 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 761 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
763 762
764 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 763 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
765 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 764 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
766 //full = true; //debug only 765 //full = true; //debug only
767 if ( full ) { 766 if ( full ) {
768 bool equ = false; 767 bool equ = false;
769 if ( local->type() == "Event" ) { 768 if ( local->type() == "Event" ) {
770 equ = (*((Event*) local) == *((Event*) remote)); 769 equ = (*((Event*) local) == *((Event*) remote));
771 } 770 }
772 else if ( local->type() =="Todo" ) 771 else if ( local->type() =="Todo" )
773 equ = (*((Todo*) local) == (*(Todo*) remote)); 772 equ = (*((Todo*) local) == (*(Todo*) remote));
774 else if ( local->type() =="Journal" ) 773 else if ( local->type() =="Journal" )
775 equ = (*((Journal*) local) == *((Journal*) remote)); 774 equ = (*((Journal*) local) == *((Journal*) remote));
776 if ( equ ) { 775 if ( equ ) {
777 //qDebug("equal "); 776 //qDebug("equal ");
778 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 777 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
779 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 778 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
780 } 779 }
781 if ( mode < SYNC_PREF_FORCE_LOCAL ) 780 if ( mode < SYNC_PREF_FORCE_LOCAL )
782 return 0; 781 return 0;
783 782
784 }//else //debug only 783 }//else //debug only
785 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 784 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
786 } 785 }
787 int result; 786 int result;
788 bool localIsNew; 787 bool localIsNew;
789 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 788 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
790 789
791 if ( full && mode < SYNC_PREF_NEWEST ) 790 if ( full && mode < SYNC_PREF_NEWEST )
792 mode = SYNC_PREF_ASK; 791 mode = SYNC_PREF_ASK;
793 792
794 switch( mode ) { 793 switch( mode ) {
795 case SYNC_PREF_LOCAL: 794 case SYNC_PREF_LOCAL:
796 if ( lastSync > remote->lastModified() ) 795 if ( lastSync > remote->lastModified() )
797 return 1; 796 return 1;
798 if ( lastSync > local->lastModified() ) 797 if ( lastSync > local->lastModified() )
799 return 2; 798 return 2;
800 return 1; 799 return 1;
801 break; 800 break;
802 case SYNC_PREF_REMOTE: 801 case SYNC_PREF_REMOTE:
803 if ( lastSync > remote->lastModified() ) 802 if ( lastSync > remote->lastModified() )
804 return 1; 803 return 1;
805 if ( lastSync > local->lastModified() ) 804 if ( lastSync > local->lastModified() )
806 return 2; 805 return 2;
807 return 2; 806 return 2;
808 break; 807 break;
809 case SYNC_PREF_NEWEST: 808 case SYNC_PREF_NEWEST:
810 if ( local->lastModified() > remote->lastModified() ) 809 if ( local->lastModified() > remote->lastModified() )
811 return 1; 810 return 1;
812 else 811 else
813 return 2; 812 return 2;
814 break; 813 break;
815 case SYNC_PREF_ASK: 814 case SYNC_PREF_ASK:
816 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 815 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
817 if ( lastSync > remote->lastModified() ) 816 if ( lastSync > remote->lastModified() )
818 return 1; 817 return 1;
819 if ( lastSync > local->lastModified() ) 818 if ( lastSync > local->lastModified() )
820 return 2; 819 return 2;
821 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 820 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
822 localIsNew = local->lastModified() >= remote->lastModified(); 821 localIsNew = local->lastModified() >= remote->lastModified();
823 if ( localIsNew ) 822 if ( localIsNew )
824 getEventViewerDialog()->setColorMode( 1 ); 823 getEventViewerDialog()->setColorMode( 1 );
825 else 824 else
826 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
827 getEventViewerDialog()->setIncidence(local); 826 getEventViewerDialog()->setIncidence(local);
828 if ( localIsNew ) 827 if ( localIsNew )
829 getEventViewerDialog()->setColorMode( 2 ); 828 getEventViewerDialog()->setColorMode( 2 );
830 else 829 else
831 getEventViewerDialog()->setColorMode( 1 ); 830 getEventViewerDialog()->setColorMode( 1 );
832 getEventViewerDialog()->addIncidence(remote); 831 getEventViewerDialog()->addIncidence(remote);
833 getEventViewerDialog()->setColorMode( 0 ); 832 getEventViewerDialog()->setColorMode( 0 );
834 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 833 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
835 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 834 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
836 getEventViewerDialog()->showMe(); 835 getEventViewerDialog()->showMe();
837 result = getEventViewerDialog()->executeS( localIsNew ); 836 result = getEventViewerDialog()->executeS( localIsNew );
838 return result; 837 return result;
839 838
840 break; 839 break;
841 case SYNC_PREF_FORCE_LOCAL: 840 case SYNC_PREF_FORCE_LOCAL:
842 return 1; 841 return 1;
843 break; 842 break;
844 case SYNC_PREF_FORCE_REMOTE: 843 case SYNC_PREF_FORCE_REMOTE:
845 return 2; 844 return 2;
846 break; 845 break;
847 846
848 default: 847 default:
849 // SYNC_PREF_TAKE_BOTH not implemented 848 // SYNC_PREF_TAKE_BOTH not implemented
850 break; 849 break;
851 } 850 }
852 return 0; 851 return 0;
853} 852}
854Event* CalendarView::getLastSyncEvent() 853Event* CalendarView::getLastSyncEvent()
855{ 854{
856 Event* lse; 855 Event* lse;
857 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 856 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
858 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
859 if (!lse) { 858 if (!lse) {
860 lse = new Event(); 859 lse = new Event();
861 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 860 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
862 QString sum = ""; 861 QString sum = "";
863 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 862 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
864 sum = "E: "; 863 sum = "E: ";
865 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 864 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
866 lse->setDtStart( mLastCalendarSync ); 865 lse->setDtStart( mLastCalendarSync );
867 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 866 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
868 lse->setCategories( i18n("SyncEvent") ); 867 lse->setCategories( i18n("SyncEvent") );
869 lse->setReadOnly( true ); 868 lse->setReadOnly( true );
870 mCalendar->addEvent( lse ); 869 mCalendar->addEvent( lse );
871 } 870 }
872 871
873 return lse; 872 return lse;
874 873
875} 874}
876// probaly useless 875// probaly useless
877void CalendarView::setupExternSyncProfiles() 876void CalendarView::setupExternSyncProfiles()
878{ 877{
879 Event* lse; 878 Event* lse;
880 mExternLastSyncEvent.clear(); 879 mExternLastSyncEvent.clear();
881 int i; 880 int i;
882 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 881 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
883 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 882 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
884 if ( lse ) 883 if ( lse )
885 mExternLastSyncEvent.append( lse ); 884 mExternLastSyncEvent.append( lse );
886 else 885 else
887 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 886 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
888 } 887 }
889 888
890} 889}
891// we check, if the to delete event has a id for a profile 890// we check, if the to delete event has a id for a profile
892// if yes, we set this id in the profile to delete 891// if yes, we set this id in the profile to delete
893void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 892void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
894{ 893{
895 if ( lastSync.count() == 0 ) { 894 if ( lastSync.count() == 0 ) {
896 //qDebug(" lastSync.count() == 0"); 895 //qDebug(" lastSync.count() == 0");
897 return; 896 return;
898 } 897 }
899 if ( toDelete->type() == "Journal" ) 898 if ( toDelete->type() == "Journal" )
900 return; 899 return;
901 900
902 Event* eve = lastSync.first(); 901 Event* eve = lastSync.first();
903 902
904 while ( eve ) { 903 while ( eve ) {
905 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 904 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
906 if ( !id.isEmpty() ) { 905 if ( !id.isEmpty() ) {
907 QString des = eve->description(); 906 QString des = eve->description();
908 QString pref = "e"; 907 QString pref = "e";
909 if ( toDelete->type() == "Todo" ) 908 if ( toDelete->type() == "Todo" )
910 pref = "t"; 909 pref = "t";
911 des += pref+ id + ","; 910 des += pref+ id + ",";
912 eve->setReadOnly( false ); 911 eve->setReadOnly( false );
913 eve->setDescription( des ); 912 eve->setDescription( des );
914 //qDebug("setdes %s ", des.latin1()); 913 //qDebug("setdes %s ", des.latin1());
915 eve->setReadOnly( true ); 914 eve->setReadOnly( true );
916 } 915 }
917 eve = lastSync.next(); 916 eve = lastSync.next();
918 } 917 }
919 918
920} 919}
921void CalendarView::checkExternalId( Incidence * inc ) 920void CalendarView::checkExternalId( Incidence * inc )
922{ 921{
923 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 922 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
924 checkExternSyncEvent( lastSync, inc ); 923 checkExternSyncEvent( lastSync, inc );
925 924
926} 925}
927bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 926bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
928{ 927{
929 bool syncOK = true; 928 bool syncOK = true;
930 int addedEvent = 0; 929 int addedEvent = 0;
931 int addedEventR = 0; 930 int addedEventR = 0;
932 int deletedEventR = 0; 931 int deletedEventR = 0;
933 int deletedEventL = 0; 932 int deletedEventL = 0;
934 int changedLocal = 0; 933 int changedLocal = 0;
935 int changedRemote = 0; 934 int changedRemote = 0;
936 //QPtrList<Event> el = local->rawEvents(); 935 //QPtrList<Event> el = local->rawEvents();
937 Event* eventR; 936 Event* eventR;
938 QString uid; 937 QString uid;
939 int take; 938 int take;
940 Event* eventL; 939 Event* eventL;
941 Event* eventRSync; 940 Event* eventRSync;
942 Event* eventLSync; 941 Event* eventLSync;
943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 942 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 943 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
945 bool fullDateRange = false; 944 bool fullDateRange = false;
946 local->resetTempSyncStat(); 945 local->resetTempSyncStat();
947 mLastCalendarSync = QDateTime::currentDateTime(); 946 mLastCalendarSync = QDateTime::currentDateTime();
948 QDateTime modifiedCalendar = mLastCalendarSync;; 947 QDateTime modifiedCalendar = mLastCalendarSync;;
949 eventLSync = getLastSyncEvent(); 948 eventLSync = getLastSyncEvent();
950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 949 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
951 if ( eventR ) { 950 if ( eventR ) {
952 eventRSync = (Event*) eventR->clone(); 951 eventRSync = (Event*) eventR->clone();
953 remote->deleteEvent(eventR ); 952 remote->deleteEvent(eventR );
954 953
955 } else { 954 } else {
956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 955 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
957 eventRSync = (Event*)eventLSync->clone(); 956 eventRSync = (Event*)eventLSync->clone();
958 } else { 957 } else {
959 fullDateRange = true; 958 fullDateRange = true;
960 eventRSync = new Event(); 959 eventRSync = new Event();
961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 960 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 961 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
963 eventRSync->setDtStart( mLastCalendarSync ); 962 eventRSync->setDtStart( mLastCalendarSync );
964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 963 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
965 eventRSync->setCategories( i18n("SyncEvent") ); 964 eventRSync->setCategories( i18n("SyncEvent") );
966 } 965 }
967 } 966 }
968 if ( eventLSync->dtStart() == mLastCalendarSync ) 967 if ( eventLSync->dtStart() == mLastCalendarSync )
969 fullDateRange = true; 968 fullDateRange = true;
970 969
971 if ( ! fullDateRange ) { 970 if ( ! fullDateRange ) {
972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 971 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
973 972
974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 973 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 974 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
976 fullDateRange = true; 975 fullDateRange = true;
977 } 976 }
978 } 977 }
979 if ( fullDateRange ) 978 if ( fullDateRange )
980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 979 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
981 else 980 else
982 mLastCalendarSync = eventLSync->dtStart(); 981 mLastCalendarSync = eventLSync->dtStart();
983 // for resyncing if own file has changed 982 // for resyncing if own file has changed
984 if ( mCurrentSyncDevice == "deleteaftersync" ) { 983 if ( mCurrentSyncDevice == "deleteaftersync" ) {
985 mLastCalendarSync = loadedFileVersion; 984 mLastCalendarSync = loadedFileVersion;
986 qDebug("setting mLastCalendarSync "); 985 qDebug("setting mLastCalendarSync ");
987 } 986 }
988 //qDebug("*************************** "); 987 //qDebug("*************************** ");
989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 988 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
990 QPtrList<Incidence> er = remote->rawIncidences(); 989 QPtrList<Incidence> er = remote->rawIncidences();
991 Incidence* inR = er.first(); 990 Incidence* inR = er.first();
992 Incidence* inL; 991 Incidence* inL;
993 QProgressBar bar( er.count(),0 ); 992 QProgressBar bar( er.count(),0 );
994 bar.setCaption (i18n("Syncing - close to abort!") ); 993 bar.setCaption (i18n("Syncing - close to abort!") );
995 994
996 int w = 300; 995 int w = 300;
997 if ( QApplication::desktop()->width() < 320 ) 996 if ( QApplication::desktop()->width() < 320 )
998 w = 220; 997 w = 220;
999 int h = bar.sizeHint().height() ; 998 int h = bar.sizeHint().height() ;
1000 int dw = QApplication::desktop()->width(); 999 int dw = QApplication::desktop()->width();
1001 int dh = QApplication::desktop()->height(); 1000 int dh = QApplication::desktop()->height();
1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1001 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1003 bar.show(); 1002 bar.show();
1004 int modulo = (er.count()/10)+1; 1003 int modulo = (er.count()/10)+1;
1005 int incCounter = 0; 1004 int incCounter = 0;
1006 while ( inR ) { 1005 while ( inR ) {
1007 if ( ! bar.isVisible() ) 1006 if ( ! bar.isVisible() )
1008 return false; 1007 return false;
1009 if ( incCounter % modulo == 0 ) 1008 if ( incCounter % modulo == 0 )
1010 bar.setProgress( incCounter ); 1009 bar.setProgress( incCounter );
1011 ++incCounter; 1010 ++incCounter;
1012 uid = inR->uid(); 1011 uid = inR->uid();
1013 bool skipIncidence = false; 1012 bool skipIncidence = false;
1014 if ( uid.left(15) == QString("last-syncEvent-") ) 1013 if ( uid.left(15) == QString("last-syncEvent-") )
1015 skipIncidence = true; 1014 skipIncidence = true;
1016 QString idS; 1015 QString idS;
1017 qApp->processEvents(); 1016 qApp->processEvents();
1018 if ( !skipIncidence ) { 1017 if ( !skipIncidence ) {
1019 inL = local->incidence( uid ); 1018 inL = local->incidence( uid );
1020 if ( inL ) { // maybe conflict - same uid in both calendars 1019 if ( inL ) { // maybe conflict - same uid in both calendars
1021 int maxrev = inL->revision(); 1020 int maxrev = inL->revision();
1022 if ( maxrev < inR->revision() ) 1021 if ( maxrev < inR->revision() )
1023 maxrev = inR->revision(); 1022 maxrev = inR->revision();
1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1023 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1025 //qDebug("take %d %s ", take, inL->summary().latin1()); 1024 //qDebug("take %d %s ", take, inL->summary().latin1());
1026 if ( take == 3 ) 1025 if ( take == 3 )
1027 return false; 1026 return false;
1028 if ( take == 1 ) {// take local 1027 if ( take == 1 ) {// take local
1029 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1028 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1030 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1031 else 1030 else
1032 idS = inR->IDStr(); 1031 idS = inR->IDStr();
1033 remote->deleteIncidence( inR ); 1032 remote->deleteIncidence( inR );
1034 if ( inL->revision() < maxrev ) 1033 if ( inL->revision() < maxrev )
1035 inL->setRevision( maxrev ); 1034 inL->setRevision( maxrev );
1036 inR = inL->clone(); 1035 inR = inL->clone();
1037 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1036 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1038 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1037 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1039 inR->setIDStr( idS ); 1038 inR->setIDStr( idS );
1040 remote->addIncidence( inR ); 1039 remote->addIncidence( inR );
1041 ++changedRemote; 1040 ++changedRemote;
1042 } else { 1041 } else {
1043 if ( inR->revision() < maxrev ) 1042 if ( inR->revision() < maxrev )
1044 inR->setRevision( maxrev ); 1043 inR->setRevision( maxrev );
1045 idS = inL->IDStr(); 1044 idS = inL->IDStr();
1046 local->deleteIncidence( inL ); 1045 local->deleteIncidence( inL );
1047 inL = inR->clone(); 1046 inL = inR->clone();
1048 inL->setIDStr( idS ); 1047 inL->setIDStr( idS );
1049 local->addIncidence( inL ); 1048 local->addIncidence( inL );
1050 ++changedLocal; 1049 ++changedLocal;
1051 } 1050 }
1052 } 1051 }
1053 } else { // no conflict 1052 } else { // no conflict
1054 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1053 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1055 QString des = eventLSync->description(); 1054 QString des = eventLSync->description();
1056 QString pref = "e"; 1055 QString pref = "e";
1057 if ( inR->type() == "Todo" ) 1056 if ( inR->type() == "Todo" )
1058 pref = "t"; 1057 pref = "t";
1059 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1058 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1060 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1059 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1061 //remote->deleteIncidence( inR ); 1060 //remote->deleteIncidence( inR );
1062 ++deletedEventR; 1061 ++deletedEventR;
1063 } else { 1062 } else {
1064 inR->setLastModified( modifiedCalendar ); 1063 inR->setLastModified( modifiedCalendar );
1065 inL = inR->clone(); 1064 inL = inR->clone();
1066 local->addIncidence( inL ); 1065 local->addIncidence( inL );
1067 ++addedEvent; 1066 ++addedEvent;
1068 } 1067 }
1069 } else { 1068 } else {
1070 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1071 inR->setLastModified( modifiedCalendar ); 1070 inR->setLastModified( modifiedCalendar );
1072 local->addIncidence( inR->clone() ); 1071 local->addIncidence( inR->clone() );
1073 ++addedEvent; 1072 ++addedEvent;
1074 } else { 1073 } else {
1075 checkExternSyncEvent(eventRSyncSharp, inR); 1074 checkExternSyncEvent(eventRSyncSharp, inR);
1076 remote->deleteIncidence( inR ); 1075 remote->deleteIncidence( inR );
1077 ++deletedEventR; 1076 ++deletedEventR;
1078 } 1077 }
1079 } 1078 }
1080 } 1079 }
1081 } 1080 }
1082 inR = er.next(); 1081 inR = er.next();
1083 } 1082 }
1084 QPtrList<Incidence> el = local->rawIncidences(); 1083 QPtrList<Incidence> el = local->rawIncidences();
1085 inL = el.first(); 1084 inL = el.first();
1086 modulo = (el.count()/10)+1; 1085 modulo = (el.count()/10)+1;
1087 bar.setCaption (i18n("Add / remove events") ); 1086 bar.setCaption (i18n("Add / remove events") );
1088 bar.setTotalSteps ( el.count() ) ; 1087 bar.setTotalSteps ( el.count() ) ;
1089 bar.show(); 1088 bar.show();
1090 incCounter = 0; 1089 incCounter = 0;
1091 1090
1092 while ( inL ) { 1091 while ( inL ) {
1093 1092
1094 qApp->processEvents(); 1093 qApp->processEvents();
1095 if ( ! bar.isVisible() ) 1094 if ( ! bar.isVisible() )
1096 return false; 1095 return false;
1097 if ( incCounter % modulo == 0 ) 1096 if ( incCounter % modulo == 0 )
1098 bar.setProgress( incCounter ); 1097 bar.setProgress( incCounter );
1099 ++incCounter; 1098 ++incCounter;
1100 uid = inL->uid(); 1099 uid = inL->uid();
1101 bool skipIncidence = false; 1100 bool skipIncidence = false;
1102 if ( uid.left(15) == QString("last-syncEvent-") ) 1101 if ( uid.left(15) == QString("last-syncEvent-") )
1103 skipIncidence = true; 1102 skipIncidence = true;
1104 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1103 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1105 skipIncidence = true; 1104 skipIncidence = true;
1106 if ( !skipIncidence ) { 1105 if ( !skipIncidence ) {
1107 inR = remote->incidence( uid ); 1106 inR = remote->incidence( uid );
1108 if ( ! inR ) { 1107 if ( ! inR ) {
1109 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1108 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1110 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1109 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1111 checkExternSyncEvent(eventLSyncSharp, inL); 1110 checkExternSyncEvent(eventLSyncSharp, inL);
1112 local->deleteIncidence( inL ); 1111 local->deleteIncidence( inL );
1113 ++deletedEventL; 1112 ++deletedEventL;
1114 } else { 1113 } else {
1115 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1114 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1116 inL->removeID(mCurrentSyncDevice ); 1115 inL->removeID(mCurrentSyncDevice );
1117 ++addedEventR; 1116 ++addedEventR;
1118 qDebug("remote added Incidence %s ", inL->summary().latin1()); 1117 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1119 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1120 inR = inL->clone(); 1119 inR = inL->clone();
1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1120 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1122 remote->addIncidence( inR ); 1121 remote->addIncidence( inR );
1123 } 1122 }
1124 } 1123 }
1125 } else { 1124 } else {
1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1125 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1127 checkExternSyncEvent(eventLSyncSharp, inL); 1126 checkExternSyncEvent(eventLSyncSharp, inL);
1128 local->deleteIncidence( inL ); 1127 local->deleteIncidence( inL );
1129 ++deletedEventL; 1128 ++deletedEventL;
1130 } else { 1129 } else {
1131 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1130 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1132 ++addedEventR; 1131 ++addedEventR;
1133 inL->setLastModified( modifiedCalendar ); 1132 inL->setLastModified( modifiedCalendar );
1134 remote->addIncidence( inL->clone() ); 1133 remote->addIncidence( inL->clone() );
1135 } 1134 }
1136 } 1135 }
1137 } 1136 }
1138 } 1137 }
1139 } 1138 }
1140 inL = el.next(); 1139 inL = el.next();
1141 } 1140 }
1142 int delFut = 0; 1141 int delFut = 0;
1143 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1142 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1144 er = remote->rawIncidences(); 1143 er = remote->rawIncidences();
1145 inR = er.first(); 1144 inR = er.first();
1146 QDateTime dt; 1145 QDateTime dt;
1147 QDateTime cur = QDateTime::currentDateTime(); 1146 QDateTime cur = QDateTime::currentDateTime();
1148 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); 1147 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
1149 while ( inR ) { 1148 while ( inR ) {
1150 if ( inR->type() == "Todo" ) { 1149 if ( inR->type() == "Todo" ) {
1151 Todo * t = (Todo*)inR; 1150 Todo * t = (Todo*)inR;
1152 if ( t->hasDueDate() ) 1151 if ( t->hasDueDate() )
1153 dt = t->dtDue(); 1152 dt = t->dtDue();
1154 else 1153 else
1155 dt = cur.addSecs( 62 ); 1154 dt = cur.addSecs( 62 );
1156 } 1155 }
1157 else if (inR->type() == "Event" ) { 1156 else if (inR->type() == "Event" ) {
1158 bool ok; 1157 bool ok;
1159 dt = inR->getNextOccurence( cur, &ok ); 1158 dt = inR->getNextOccurence( cur, &ok );
1160 if ( !ok ) 1159 if ( !ok )
1161 dt = cur.addSecs( -62 ); 1160 dt = cur.addSecs( -62 );
1162 } 1161 }
1163 else 1162 else
1164 dt = inR->dtStart(); 1163 dt = inR->dtStart();
1165 if ( dt < cur || dt > end ) { 1164 if ( dt < cur || dt > end ) {
1166 remote->deleteIncidence( inR ); 1165 remote->deleteIncidence( inR );
1167 ++delFut; 1166 ++delFut;
1168 } 1167 }
1169 inR = er.next(); 1168 inR = er.next();
1170 } 1169 }
1171 } 1170 }
1172 bar.hide(); 1171 bar.hide();
1173 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1172 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1174 eventLSync->setReadOnly( false ); 1173 eventLSync->setReadOnly( false );
1175 eventLSync->setDtStart( mLastCalendarSync ); 1174 eventLSync->setDtStart( mLastCalendarSync );
1176 eventRSync->setDtStart( mLastCalendarSync ); 1175 eventRSync->setDtStart( mLastCalendarSync );
1177 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1176 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1178 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1177 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1179 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1178 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1180 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1179 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1181 eventLSync->setReadOnly( true ); 1180 eventLSync->setReadOnly( true );
1182 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1181 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1183 remote->addEvent( eventRSync ); 1182 remote->addEvent( eventRSync );
1184 QString mes; 1183 QString mes;
1185 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 ); 1184 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 );
1186 QString delmess; 1185 QString delmess;
1187 if ( delFut ) { 1186 if ( delFut ) {
1188 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 1187 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1189 mes += delmess; 1188 mes += delmess;
1190 } 1189 }
1191 if ( KOPrefs::instance()->mShowSyncSummary ) { 1190 if ( KOPrefs::instance()->mShowSyncSummary ) {
1192 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1191 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1193 } 1192 }
1194 qDebug( mes ); 1193 qDebug( mes );
1195 mCalendar->checkAlarmForIncidence( 0, true ); 1194 mCalendar->checkAlarmForIncidence( 0, true );
1196 return syncOK; 1195 return syncOK;
1197} 1196}
1198 1197
1199void CalendarView::setSyncDevice( QString s ) 1198void CalendarView::setSyncDevice( QString s )
1200{ 1199{
1201 mCurrentSyncDevice= s; 1200 mCurrentSyncDevice= s;
1202} 1201}
1203void CalendarView::setSyncName( QString s ) 1202void CalendarView::setSyncName( QString s )
1204{ 1203{
1205 mCurrentSyncName= s; 1204 mCurrentSyncName= s;
1206} 1205}
1207bool CalendarView::syncCalendar(QString filename, int mode) 1206bool CalendarView::syncCalendar(QString filename, int mode)
1208{ 1207{
1209 mGlobalSyncMode = SYNC_MODE_NORMAL; 1208 mGlobalSyncMode = SYNC_MODE_NORMAL;
1210 CalendarLocal* calendar = new CalendarLocal(); 1209 CalendarLocal* calendar = new CalendarLocal();
1211 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1210 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1212 FileStorage* storage = new FileStorage( calendar ); 1211 FileStorage* storage = new FileStorage( calendar );
1213 bool syncOK = false; 1212 bool syncOK = false;
1214 storage->setFileName( filename ); 1213 storage->setFileName( filename );
1215 // qDebug("loading ... "); 1214 // qDebug("loading ... ");
1216 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1215 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1217 getEventViewerDialog()->setSyncMode( true ); 1216 getEventViewerDialog()->setSyncMode( true );
1218 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1217 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1219 getEventViewerDialog()->setSyncMode( false ); 1218 getEventViewerDialog()->setSyncMode( false );
1220 if ( syncOK ) { 1219 if ( syncOK ) {
1221 if ( KOPrefs::instance()->mWriteBackFile ) 1220 if ( KOPrefs::instance()->mWriteBackFile )
1222 { 1221 {
1223 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1222 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1224 storage->save(); 1223 storage->save();
1225 } 1224 }
1226 } 1225 }
1227 setModified( true ); 1226 setModified( true );
1228 } 1227 }
1229 delete storage; 1228 delete storage;
1230 delete calendar; 1229 delete calendar;
1231 if ( syncOK ) 1230 if ( syncOK )
1232 updateView(); 1231 updateView();
1233 return syncOK; 1232 return syncOK;
1234} 1233}
1235void CalendarView::syncPhone() 1234void CalendarView::syncPhone()
1236{ 1235{
1237 syncExternal( 1 ); 1236 syncExternal( 1 );
1238} 1237}
1239void CalendarView::syncExternal( int mode ) 1238void CalendarView::syncExternal( int mode )
1240{ 1239{
1241 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1240 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1242 //mCurrentSyncDevice = "sharp-DTM"; 1241 //mCurrentSyncDevice = "sharp-DTM";
1243 if ( KOPrefs::instance()->mAskForPreferences ) 1242 if ( KOPrefs::instance()->mAskForPreferences )
1244 edit_sync_options(); 1243 edit_sync_options();
1245 qApp->processEvents(); 1244 qApp->processEvents();
1246 CalendarLocal* calendar = new CalendarLocal(); 1245 CalendarLocal* calendar = new CalendarLocal();
1247 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1246 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1248 bool syncOK = false; 1247 bool syncOK = false;
1249 bool loadSuccess = false; 1248 bool loadSuccess = false;
1250 PhoneFormat* phoneFormat = 0; 1249 PhoneFormat* phoneFormat = 0;
1251#ifndef DESKTOP_VERSION 1250#ifndef DESKTOP_VERSION
1252 SharpFormat* sharpFormat = 0; 1251 SharpFormat* sharpFormat = 0;
1253 if ( mode == 0 ) { // sharp 1252 if ( mode == 0 ) { // sharp
1254 sharpFormat = new SharpFormat () ; 1253 sharpFormat = new SharpFormat () ;
1255 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1254 loadSuccess = sharpFormat->load( calendar, mCalendar );
1256 1255
1257 } else 1256 } else
1258#endif 1257#endif
1259 if ( mode == 1 ) { // phone 1258 if ( mode == 1 ) { // phone
1260 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1259 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1261 KOPrefs::instance()->mPhoneDevice, 1260 KOPrefs::instance()->mPhoneDevice,
1262 KOPrefs::instance()->mPhoneConnection, 1261 KOPrefs::instance()->mPhoneConnection,
1263 KOPrefs::instance()->mPhoneModel); 1262 KOPrefs::instance()->mPhoneModel);
1264 loadSuccess = phoneFormat->load( calendar,mCalendar); 1263 loadSuccess = phoneFormat->load( calendar,mCalendar);
1265 1264
1266 } else 1265 } else
1267 return; 1266 return;
1268 if ( loadSuccess ) { 1267 if ( loadSuccess ) {
1269 getEventViewerDialog()->setSyncMode( true ); 1268 getEventViewerDialog()->setSyncMode( true );
1270 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1269 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1271 getEventViewerDialog()->setSyncMode( false ); 1270 getEventViewerDialog()->setSyncMode( false );
1272 qApp->processEvents(); 1271 qApp->processEvents();
1273 if ( syncOK ) { 1272 if ( syncOK ) {
1274 if ( KOPrefs::instance()->mWriteBackFile ) 1273 if ( KOPrefs::instance()->mWriteBackFile )
1275 { 1274 {
1276 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1275 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1277 Incidence* inc = iL.first(); 1276 Incidence* inc = iL.first();
1278 if ( phoneFormat ) { 1277 if ( phoneFormat ) {
1279 while ( inc ) { 1278 while ( inc ) {
1280 inc->removeID(mCurrentSyncDevice); 1279 inc->removeID(mCurrentSyncDevice);
1281 inc = iL.next(); 1280 inc = iL.next();
1282 } 1281 }
1283 } 1282 }
1284#ifndef DESKTOP_VERSION 1283#ifndef DESKTOP_VERSION
1285 if ( sharpFormat ) 1284 if ( sharpFormat )
1286 sharpFormat->save(calendar); 1285 sharpFormat->save(calendar);
1287#endif 1286#endif
1288 if ( phoneFormat ) 1287 if ( phoneFormat )
1289 phoneFormat->save(calendar); 1288 phoneFormat->save(calendar);
1290 iL = calendar->rawIncidences(); 1289 iL = calendar->rawIncidences();
1291 inc = iL.first(); 1290 inc = iL.first();
1292 Incidence* loc; 1291 Incidence* loc;
1293 while ( inc ) { 1292 while ( inc ) {
1294 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1293 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1295 loc = mCalendar->incidence(inc->uid() ); 1294 loc = mCalendar->incidence(inc->uid() );
1296 if ( loc ) { 1295 if ( loc ) {
1297 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1296 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1298 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1297 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1299 } 1298 }
1300 } 1299 }
1301 inc = iL.next(); 1300 inc = iL.next();
1302 } 1301 }
1303 Incidence* lse = getLastSyncEvent(); 1302 Incidence* lse = getLastSyncEvent();
1304 if ( lse ) { 1303 if ( lse ) {
1305 lse->setReadOnly( false ); 1304 lse->setReadOnly( false );
1306 lse->setDescription( "" ); 1305 lse->setDescription( "" );
1307 lse->setReadOnly( true ); 1306 lse->setReadOnly( true );
1308 } 1307 }
1309 } 1308 }
1310 } 1309 }
1311 setModified( true ); 1310 setModified( true );
1312 } else { 1311 } else {
1313 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1312 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1314 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1313 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1315 question, i18n("Ok")) ; 1314 question, i18n("Ok")) ;
1316 1315
1317 } 1316 }
1318 delete calendar; 1317 delete calendar;
1319 updateView(); 1318 updateView();
1320 return ;//syncOK; 1319 return ;//syncOK;
1321 1320
1322} 1321}
1323void CalendarView::syncSharp() 1322void CalendarView::syncSharp()
1324{ 1323{
1325 syncExternal( 0 ); 1324 syncExternal( 0 );
1326 1325
1327} 1326}
1328 1327
1329 1328
1330#include <kabc/stdaddressbook.h> 1329#include <kabc/stdaddressbook.h>
1331bool CalendarView::importBday() 1330bool CalendarView::importBday()
1332{ 1331{
1333 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1332 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1334 KABC::AddressBook::Iterator it; 1333 KABC::AddressBook::Iterator it;
1335 int count = 0; 1334 int count = 0;
1336 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1335 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1337 ++count; 1336 ++count;
1338 } 1337 }
1339 QProgressBar bar(count,0 ); 1338 QProgressBar bar(count,0 );
1340 int w = 300; 1339 int w = 300;
1341 if ( QApplication::desktop()->width() < 320 ) 1340 if ( QApplication::desktop()->width() < 320 )
1342 w = 220; 1341 w = 220;
1343 int h = bar.sizeHint().height() ; 1342 int h = bar.sizeHint().height() ;
1344 int dw = QApplication::desktop()->width(); 1343 int dw = QApplication::desktop()->width();
1345 int dh = QApplication::desktop()->height(); 1344 int dh = QApplication::desktop()->height();
1346 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1345 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1347 bar.show(); 1346 bar.show();
1348 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1347 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1349 qApp->processEvents(); 1348 qApp->processEvents();
1350 count = 0; 1349 count = 0;
1351 int addCount = 0; 1350 int addCount = 0;
1352 KCal::Attendee* a = 0; 1351 KCal::Attendee* a = 0;
1353 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1352 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1354 if ( ! bar.isVisible() ) 1353 if ( ! bar.isVisible() )
1355 return false; 1354 return false;
1356 bar.setProgress( count++ ); 1355 bar.setProgress( count++ );
1357 qApp->processEvents(); 1356 qApp->processEvents();
1358 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1357 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1359 if ( (*it).birthday().date().isValid() ){ 1358 if ( (*it).birthday().date().isValid() ){
1360 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1359 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1361 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1360 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1362 ++addCount; 1361 ++addCount;
1363 } 1362 }
1364 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1363 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1365 if ( anni.isValid() ){ 1364 if ( anni.isValid() ){
1366 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1365 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1367 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1366 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1368 ++addCount; 1367 ++addCount;
1369 } 1368 }
1370 } 1369 }
1371 updateView(); 1370 updateView();
1372 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1371 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1373 return true; 1372 return true;
1374} 1373}
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index a53b3f8..e7fc670 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -228,564 +228,580 @@ class SharpParser : public QObject
228 228
229 229
230 230
231 QString hasDateStr = attList[3]; // due 231 QString hasDateStr = attList[3]; // due
232 if ( !hasDateStr.isEmpty() ) { 232 if ( !hasDateStr.isEmpty() ) {
233 if ( hasDateStr.right(6) == "000000" ) { 233 if ( hasDateStr.right(6) == "000000" ) {
234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
235 todo->setFloats( true ); 235 todo->setFloats( true );
236 } 236 }
237 else { 237 else {
238 todo->setDtDue( fromString( hasDateStr ) ); 238 todo->setDtDue( fromString( hasDateStr ) );
239 todo->setFloats( false ); 239 todo->setFloats( false );
240 } 240 }
241 241
242 todo->setHasDueDate( true ); 242 todo->setHasDueDate( true );
243 } 243 }
244 hasDateStr = attList[2];//start 244 hasDateStr = attList[2];//start
245 if ( !hasDateStr.isEmpty() ) { 245 if ( !hasDateStr.isEmpty() ) {
246 246
247 todo->setDtStart( fromString( hasDateStr ) ); 247 todo->setDtStart( fromString( hasDateStr ) );
248 todo->setHasStartDate( true); 248 todo->setHasStartDate( true);
249 } else 249 } else
250 todo->setHasStartDate( false ); 250 todo->setHasStartDate( false );
251 hasDateStr = attList[4];//completed 251 hasDateStr = attList[4];//completed
252 if ( !hasDateStr.isEmpty() ) { 252 if ( !hasDateStr.isEmpty() ) {
253 todo->setCompleted(fromString( hasDateStr ) ); 253 todo->setCompleted(fromString( hasDateStr ) );
254 } 254 }
255 QString completedStr = attList[5]; 255 QString completedStr = attList[5];
256 if ( completedStr == "0" ) 256 if ( completedStr == "0" )
257 todo->setCompleted( true ); 257 todo->setCompleted( true );
258 else 258 else
259 todo->setCompleted( false ); 259 todo->setCompleted( false );
260 mCalendar->addTodo( todo ); 260 mCalendar->addTodo( todo );
261 261
262 } else if ( qName == "Category" ) { 262 } else if ( qName == "Category" ) {
263 /* 263 /*
264 QString id = attributes.value( "id" ); 264 QString id = attributes.value( "id" );
265 QString name = attributes.value( "name" ); 265 QString name = attributes.value( "name" );
266 setCategory( id, name ); 266 setCategory( id, name );
267 */ 267 */
268 } 268 }
269 //qDebug("end "); 269 //qDebug("end ");
270 return true; 270 return true;
271 } 271 }
272 272
273 273
274 void setCategoriesList ( QStringList * c ) 274 void setCategoriesList ( QStringList * c )
275 { 275 {
276 oldCategories = c; 276 oldCategories = c;
277 } 277 }
278 278
279 QDateTime fromString ( QString s, bool useTz = true ) { 279 QDateTime fromString ( QString s, bool useTz = true ) {
280 QDateTime dt; 280 QDateTime dt;
281 int y,m,t,h,min,sec; 281 int y,m,t,h,min,sec;
282 y = s.mid(0,4).toInt(); 282 y = s.mid(0,4).toInt();
283 m = s.mid(4,2).toInt(); 283 m = s.mid(4,2).toInt();
284 t = s.mid(6,2).toInt(); 284 t = s.mid(6,2).toInt();
285 h = s.mid(9,2).toInt(); 285 h = s.mid(9,2).toInt();
286 min = s.mid(11,2).toInt(); 286 min = s.mid(11,2).toInt();
287 sec = s.mid(13,2).toInt(); 287 sec = s.mid(13,2).toInt();
288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
289 int offset = KGlobal::locale()->localTimeOffset( dt ); 289 int offset = KGlobal::locale()->localTimeOffset( dt );
290 if ( useTz ) 290 if ( useTz )
291 dt = dt.addSecs ( offset*60); 291 dt = dt.addSecs ( offset*60);
292 return dt; 292 return dt;
293 293
294 } 294 }
295 protected: 295 protected:
296 QDateTime toDateTime( const QString &value ) 296 QDateTime toDateTime( const QString &value )
297 { 297 {
298 QDateTime dt; 298 QDateTime dt;
299 dt.setTime_t( value.toUInt() ); 299 dt.setTime_t( value.toUInt() );
300 300
301 return dt; 301 return dt;
302 } 302 }
303 303
304 QStringList lookupCategories( const QString &categoryList ) 304 QStringList lookupCategories( const QString &categoryList )
305 { 305 {
306 QStringList categoryIds = QStringList::split( ";", categoryList ); 306 QStringList categoryIds = QStringList::split( ";", categoryList );
307 QStringList categories; 307 QStringList categories;
308 QStringList::ConstIterator it; 308 QStringList::ConstIterator it;
309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
310 QString cate = category( *it ); 310 QString cate = category( *it );
311 if ( oldCategories ) { 311 if ( oldCategories ) {
312 if ( ! oldCategories->contains( cate ) ) 312 if ( ! oldCategories->contains( cate ) )
313 oldCategories->append( cate ); 313 oldCategories->append( cate );
314 } 314 }
315 categories.append(cate ); 315 categories.append(cate );
316 } 316 }
317 return categories; 317 return categories;
318 } 318 }
319 319
320 private: 320 private:
321 Calendar *mCalendar; 321 Calendar *mCalendar;
322 QStringList * oldCategories; 322 QStringList * oldCategories;
323 static QString category( const QString &id ) 323 static QString category( const QString &id )
324 { 324 {
325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
326 if ( it == mCategoriesMap.end() ) return id; 326 if ( it == mCategoriesMap.end() ) return id;
327 else return *it; 327 else return *it;
328 } 328 }
329 329
330 static void setCategory( const QString &id, const QString &name ) 330 static void setCategory( const QString &id, const QString &name )
331 { 331 {
332 mCategoriesMap.insert( id, name ); 332 mCategoriesMap.insert( id, name );
333 } 333 }
334 334
335 static QMap<QString,QString> mCategoriesMap; 335 static QMap<QString,QString> mCategoriesMap;
336}; 336};
337 337
338QMap<QString,QString> SharpParser::mCategoriesMap; 338QMap<QString,QString> SharpParser::mCategoriesMap;
339 339
340SharpFormat::SharpFormat() 340SharpFormat::SharpFormat()
341{ 341{
342 mCategories = 0; 342 mCategories = 0;
343} 343}
344 344
345SharpFormat::~SharpFormat() 345SharpFormat::~SharpFormat()
346{ 346{
347} 347}
348ulong SharpFormat::getCsum( const QStringList & attList) 348ulong SharpFormat::getCsum( const QStringList & attList)
349{ 349{
350 int max = attList.count() -1; 350 int max = attList.count() -1;
351 ulong cSum = 0; 351 ulong cSum = 0;
352 int j,k,i; 352 int j,k,i;
353 int add; 353 int add;
354 for ( i = 1; i < max ; ++i ) { 354 for ( i = 1; i < max ; ++i ) {
355 QString s = attList[i]; 355 QString s = attList[i];
356 if ( ! s.isEmpty() ){ 356 if ( ! s.isEmpty() ){
357 j = s.length(); 357 j = s.length();
358 for ( k = 0; k < j; ++k ) { 358 for ( k = 0; k < j; ++k ) {
359 int mul = k +1; 359 int mul = k +1;
360 add = s[k].unicode (); 360 add = s[k].unicode ();
361 if ( k < 16 ) 361 if ( k < 16 )
362 mul = mul * mul; 362 mul = mul * mul;
363 add = add * mul *i*i*i; 363 add = add * mul *i*i*i;
364 cSum += add; 364 cSum += add;
365 } 365 }
366 } 366 }
367 } 367 }
368 return cSum; 368 return cSum;
369 369
370} 370}
371#include <stdlib.h> 371#include <stdlib.h>
372#define DEBUGMODE false 372#define DEBUGMODE false
373//#define DEBUGMODE true 373//#define DEBUGMODE true
374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
375{ 375{
376 376
377 377
378 bool debug = DEBUGMODE; 378 bool debug = DEBUGMODE;
379 QString text; 379 QString text;
380 QString codec = "utf8"; 380 QString codec = "utf8";
381 QLabel status ( i18n("Reading events ..."), 0 ); 381 QLabel status ( i18n("Reading events ..."), 0 );
382 382
383 int w = status.sizeHint().width()+20 ; 383 int w = status.sizeHint().width()+20 ;
384 if ( w < 200 ) w = 200; 384 if ( w < 200 ) w = 200;
385 int h = status.sizeHint().height()+20 ; 385 int h = status.sizeHint().height()+20 ;
386 int dw = QApplication::desktop()->width(); 386 int dw = QApplication::desktop()->width();
387 int dh = QApplication::desktop()->height(); 387 int dh = QApplication::desktop()->height();
388 status.setCaption(i18n("Reading DTM Data") ); 388 status.setCaption(i18n("Reading DTM Data") );
389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
390 status.show(); 390 status.show();
391 status.raise(); 391 status.raise();
392 qApp->processEvents(); 392 qApp->processEvents();
393 QString fileName; 393 QString fileName;
394 if ( ! debug ) { 394 if ( ! debug ) {
395 fileName = "/tmp/kopitempout"; 395 fileName = "/tmp/kopitempout";
396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
397 system ( command.latin1() ); 397 system ( command.latin1() );
398 } else { 398 } else {
399 fileName = "/tmp/events.txt"; 399 fileName = "/tmp/events.txt";
400 400
401 } 401 }
402 QFile file( fileName ); 402 QFile file( fileName );
403 if (!file.open( IO_ReadOnly ) ) { 403 if (!file.open( IO_ReadOnly ) ) {
404 return false; 404 return false;
405 405
406 } 406 }
407 QTextStream ts( &file ); 407 QTextStream ts( &file );
408 ts.setCodec( QTextCodec::codecForName("utf8") ); 408 ts.setCodec( QTextCodec::codecForName("utf8") );
409 text = ts.read(); 409 text = ts.read();
410 file.close(); 410 file.close();
411 status.setText( i18n("Processing events ...") ); 411 status.setText( i18n("Processing events ...") );
412 status.raise(); 412 status.raise();
413 qApp->processEvents(); 413 qApp->processEvents();
414 fromString2Cal( calendar, existngCal, text, "Event" ); 414 fromString2Cal( calendar, existngCal, text, "Event" );
415 status.setText( i18n("Reading todos ...") ); 415 status.setText( i18n("Reading todos ...") );
416 qApp->processEvents(); 416 qApp->processEvents();
417 if ( ! debug ) { 417 if ( ! debug ) {
418 fileName = "/tmp/kopitempout"; 418 fileName = "/tmp/kopitempout";
419 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 419 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
420 system ( command.latin1() ); 420 system ( command.latin1() );
421 } else { 421 } else {
422 fileName = "/tmp/todo.txt"; 422 fileName = "/tmp/todo.txt";
423 } 423 }
424 file.setName( fileName ); 424 file.setName( fileName );
425 if (!file.open( IO_ReadOnly ) ) { 425 if (!file.open( IO_ReadOnly ) ) {
426 return false; 426 return false;
427 427
428 } 428 }
429 ts.setDevice( &file ); 429 ts.setDevice( &file );
430 text = ts.read(); 430 text = ts.read();
431 file.close(); 431 file.close();
432 432
433 status.setText( i18n("Processing todos ...") ); 433 status.setText( i18n("Processing todos ...") );
434 status.raise(); 434 status.raise();
435 qApp->processEvents(); 435 qApp->processEvents();
436 fromString2Cal( calendar, existngCal, text, "Todo" ); 436 fromString2Cal( calendar, existngCal, text, "Todo" );
437 return true; 437 return true;
438} 438}
439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
440{ 440{
441 int retval = -1; 441 int retval = -1;
442 QStringList templist; 442 QStringList templist;
443 QString tempString; 443 QString tempString;
444 int start = 0; 444 int start = 0;
445 int len = answer.length(); 445 int len = answer.length();
446 int end = answer.find ("\n",start)+1; 446 int end = answer.find ("\n",start)+1;
447 bool ok = true; 447 bool ok = true;
448 start = end; 448 start = end;
449 int ccc = 0; 449 int ccc = 0;
450 while ( start > 0 ) { 450 while ( start > 0 ) {
451 templist.clear(); 451 templist.clear();
452 ok = true; 452 ok = true;
453 int loopCount = 0; 453 int loopCount = 0;
454 while ( ok ) { 454 while ( ok ) {
455 ++loopCount; 455 ++loopCount;
456 if ( loopCount > 25 ) { 456 if ( loopCount > 25 ) {
457 qDebug("KO: Error in while loop"); 457 qDebug("KO: Error in while loop");
458 ok = false; 458 ok = false;
459 start = 0; 459 start = 0;
460 break; 460 break;
461 } 461 }
462 if ( ok ) 462 if ( ok )
463 tempString = getPart( answer, ok, start ); 463 tempString = getPart( answer, ok, start );
464 if ( start >= len || start == 0 ) { 464 if ( start >= len || start == 0 ) {
465 start = 0; 465 start = 0;
466 ok = false; 466 ok = false;
467 } 467 }
468 if ( tempString.right(1) =="\n" ) 468 if ( tempString.right(1) =="\n" )
469 tempString = tempString.left( tempString.length()-1); 469 tempString = tempString.left( tempString.length()-1);
470 470
471 templist.append( tempString ); 471 templist.append( tempString );
472 } 472 }
473 ++ccc; 473 ++ccc;
474 if ( ccc == 2 && loopCount < 25 ) { 474 if ( ccc == 2 && loopCount < 25 ) {
475 start = 0; 475 start = 0;
476 bool ok; 476 bool ok;
477 int newnum = templist[0].toInt( &ok ); 477 int newnum = templist[0].toInt( &ok );
478 if ( ok && newnum > 0) { 478 if ( ok && newnum > 0) {
479 retval = newnum; 479 retval = newnum;
480 inc->setID( "Sharp_DTM",templist[0] ); 480 inc->setID( "Sharp_DTM",templist[0] );
481 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 481 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
482 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 482 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
483 } 483 }
484 if ( ok && newnum == -1 ) {
485 qDebug("Error writing back %s ", inc->summary().latin1());
486 }
484 } 487 }
485 } 488 }
486 //qDebug("getNumFromRecord returning : %d ", retval); 489 //qDebug("getNumFromRecord returning : %d ", retval);
487 return retval; 490 return retval;
488} 491}
489bool SharpFormat::save( Calendar *calendar) 492bool SharpFormat::save( Calendar *calendar)
490{ 493{
491 494
492 QLabel status ( i18n("Processing/adding events ..."), 0 ); 495 QLabel status ( i18n("Processing/adding events ..."), 0 );
493 int w = status.sizeHint().width()+20 ; 496 int w = status.sizeHint().width()+20 ;
494 if ( w < 200 ) w = 200; 497 if ( w < 200 ) w = 200;
495 int h = status.sizeHint().height()+20 ; 498 int h = status.sizeHint().height()+20 ;
496 int dw = QApplication::desktop()->width(); 499 int dw = QApplication::desktop()->width();
497 int dh = QApplication::desktop()->height(); 500 int dh = QApplication::desktop()->height();
498 status.setCaption(i18n("Writing DTM Data") ); 501 status.setCaption(i18n("Writing DTM Data") );
499 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 502 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
500 status.show(); 503 status.show();
501 status.raise(); 504 status.raise();
502 qApp->processEvents(); 505 qApp->processEvents();
503 bool debug = DEBUGMODE; 506 bool debug = DEBUGMODE;
504 QString codec = "utf8"; 507 QString codec = "utf8";
505 QString answer; 508 QString answer;
506 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 509 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
507 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 510 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
508 QString command; 511 QString command;
509 QPtrList<Event> er = calendar->rawEvents(); 512 QPtrList<Event> er = calendar->rawEvents();
510 Event* ev = er.first(); 513 Event* ev = er.first();
511 QString fileName = "/tmp/kopitempout"; 514 QString fileName = "/tmp/kopitempout";
512 int i = 0; 515 int i = 0;
513 QString changeString = ePrefix; 516 QString changeString = ePrefix;
514 QString deleteString = ePrefix; 517 QString deleteString = ePrefix;
515 bool deleteEnt = false; 518 bool deleteEnt = false;
516 bool changeEnt = false; 519 bool changeEnt = false;
517 QString message = i18n("Processing event # "); 520 QString message = i18n("Processing event # ");
518 int procCount = 0; 521 int procCount = 0;
519 while ( ev ) { 522 while ( ev ) {
520 //qDebug("i %d ", ++i); 523 //qDebug("i %d ", ++i);
521 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 524 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
522 status.setText ( message + QString::number ( ++procCount ) ); 525 status.setText ( message + QString::number ( ++procCount ) );
523 qApp->processEvents(); 526 qApp->processEvents();
524 QString eString = getEventString( ev ); 527 QString eString = getEventString( ev );
525 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 528 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
526 // deleting empty strings does not work. 529 // deleting empty strings does not work.
527 // we write first and x and then delete the record with the x 530 // we write first and x and then delete the record with the x
528 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 531 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
529 changeString += eString + "\n"; 532 changeString += eString + "\n";
530 deleteString += eString + "\n"; 533 deleteString += eString + "\n";
531 deleteEnt = true; 534 deleteEnt = true;
532 changeEnt = true; 535 changeEnt = true;
533 } 536 }
534 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 537 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
535 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 538 QString fileNameIn = "/tmp/kopitempin";
539 QFile fileIn( fileNameIn );
540 if (!fileIn.open( IO_WriteOnly ) ) {
541 return false;
542 }
543 QTextStream tsIn( &fileIn );
544 tsIn.setCodec( QTextCodec::codecForName("utf8") );
545 tsIn << ePrefix << eString ;
546 fileIn.close();
547 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
548 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName;
549 qDebug("command ++++++++ ");
550 qDebug("%s ",command.latin1());
551 qDebug("command -------- ");
536 system ( command.utf8() ); 552 system ( command.utf8() );
537 QFile file( fileName ); 553 QFile file( fileName );
538 if (!file.open( IO_ReadOnly ) ) { 554 if (!file.open( IO_ReadOnly ) ) {
539 return false; 555 return false;
540 556
541 } 557 }
542 QTextStream ts( &file ); 558 QTextStream ts( &file );
543 ts.setCodec( QTextCodec::codecForName("utf8") ); 559 ts.setCodec( QTextCodec::codecForName("utf8") );
544 answer = ts.read(); 560 answer = ts.read();
545 file.close(); 561 file.close();
546 //qDebug("answer \n%s ", answer.latin1()); 562 //qDebug("answer \n%s ", answer.latin1());
547 getNumFromRecord( answer, ev ) ; 563 getNumFromRecord( answer, ev ) ;
548 564
549 } 565 }
550 else { // change existing 566 else { // change existing
551 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 567 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
552 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 568 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
553 changeString += eString + "\n"; 569 changeString += eString + "\n";
554 changeEnt = true; 570 changeEnt = true;
555 571
556 } 572 }
557 } 573 }
558 ev = er.next(); 574 ev = er.next();
559 } 575 }
560 status.setText ( i18n("Changing events ...") ); 576 status.setText ( i18n("Changing events ...") );
561 qApp->processEvents(); 577 qApp->processEvents();
562 //qDebug("changing... "); 578 //qDebug("changing... ");
563 if ( changeEnt ) { 579 if ( changeEnt ) {
564 QFile file( fileName ); 580 QFile file( fileName );
565 if (!file.open( IO_WriteOnly ) ) { 581 if (!file.open( IO_WriteOnly ) ) {
566 return false; 582 return false;
567 583
568 } 584 }
569 QTextStream ts( &file ); 585 QTextStream ts( &file );
570 ts.setCodec( QTextCodec::codecForName("utf8") ); 586 ts.setCodec( QTextCodec::codecForName("utf8") );
571 ts << changeString ; 587 ts << changeString ;
572 file.close(); 588 file.close();
573 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 589 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
574 system ( command.latin1() ); 590 system ( command.latin1() );
575 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 591 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
576 592
577 } 593 }
578 status.setText ( i18n("Deleting events ...") ); 594 status.setText ( i18n("Deleting events ...") );
579 qApp->processEvents(); 595 qApp->processEvents();
580 //qDebug("deleting... "); 596 //qDebug("deleting... ");
581 if ( deleteEnt ) { 597 if ( deleteEnt ) {
582 QFile file( fileName ); 598 QFile file( fileName );
583 if (!file.open( IO_WriteOnly ) ) { 599 if (!file.open( IO_WriteOnly ) ) {
584 return false; 600 return false;
585 601
586 } 602 }
587 QTextStream ts( &file ); 603 QTextStream ts( &file );
588 ts.setCodec( QTextCodec::codecForName("utf8") ); 604 ts.setCodec( QTextCodec::codecForName("utf8") );
589 ts << deleteString; 605 ts << deleteString;
590 file.close(); 606 file.close();
591 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 607 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
592 system ( command.latin1() ); 608 system ( command.latin1() );
593 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 609 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
594 } 610 }
595 611
596 612
597 changeString = tPrefix; 613 changeString = tPrefix;
598 deleteString = tPrefix; 614 deleteString = tPrefix;
599 status.setText ( i18n("Processing todos ...") ); 615 status.setText ( i18n("Processing todos ...") );
600 qApp->processEvents(); 616 qApp->processEvents();
601 QPtrList<Todo> tl = calendar->rawTodos(); 617 QPtrList<Todo> tl = calendar->rawTodos();
602 Todo* to = tl.first(); 618 Todo* to = tl.first();
603 i = 0; 619 i = 0;
604 message = i18n("Processing todo # "); 620 message = i18n("Processing todo # ");
605 procCount = 0; 621 procCount = 0;
606 while ( to ) { 622 while ( to ) {
607 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 623 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
608 status.setText ( message + QString::number ( ++procCount ) ); 624 status.setText ( message + QString::number ( ++procCount ) );
609 qApp->processEvents(); 625 qApp->processEvents();
610 QString eString = getTodoString( to ); 626 QString eString = getTodoString( to );
611 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 627 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
612 // deleting empty strings does not work. 628 // deleting empty strings does not work.
613 // we write first and x and then delete the record with the x 629 // we write first and x and then delete the record with the x
614 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 630 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
615 changeString += eString + "\n"; 631 changeString += eString + "\n";
616 deleteString += eString + "\n"; 632 deleteString += eString + "\n";
617 deleteEnt = true; 633 deleteEnt = true;
618 changeEnt = true; 634 changeEnt = true;
619 } 635 }
620 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 636 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
621 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 637 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
622 system ( command.utf8() ); 638 system ( command.utf8() );
623 QFile file( fileName ); 639 QFile file( fileName );
624 if (!file.open( IO_ReadOnly ) ) { 640 if (!file.open( IO_ReadOnly ) ) {
625 return false; 641 return false;
626 642
627 } 643 }
628 QTextStream ts( &file ); 644 QTextStream ts( &file );
629 ts.setCodec( QTextCodec::codecForName("utf8") ); 645 ts.setCodec( QTextCodec::codecForName("utf8") );
630 answer = ts.read(); 646 answer = ts.read();
631 file.close(); 647 file.close();
632 //qDebug("answer \n%s ", answer.latin1()); 648 //qDebug("answer \n%s ", answer.latin1());
633 getNumFromRecord( answer, to ) ; 649 getNumFromRecord( answer, to ) ;
634 650
635 } 651 }
636 else { // change existing 652 else { // change existing
637 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 653 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
638 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 654 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
639 changeString += eString + "\n"; 655 changeString += eString + "\n";
640 changeEnt = true; 656 changeEnt = true;
641 657
642 } 658 }
643 } 659 }
644 660
645 to = tl.next(); 661 to = tl.next();
646 } 662 }
647 status.setText ( i18n("Changing todos ...") ); 663 status.setText ( i18n("Changing todos ...") );
648 qApp->processEvents(); 664 qApp->processEvents();
649 //qDebug("changing... "); 665 //qDebug("changing... ");
650 if ( changeEnt ) { 666 if ( changeEnt ) {
651 QFile file( fileName ); 667 QFile file( fileName );
652 if (!file.open( IO_WriteOnly ) ) { 668 if (!file.open( IO_WriteOnly ) ) {
653 return false; 669 return false;
654 670
655 } 671 }
656 QTextStream ts( &file ); 672 QTextStream ts( &file );
657 ts.setCodec( QTextCodec::codecForName("utf8") ); 673 ts.setCodec( QTextCodec::codecForName("utf8") );
658 ts << changeString ; 674 ts << changeString ;
659 file.close(); 675 file.close();
660 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 676 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
661 system ( command.latin1() ); 677 system ( command.latin1() );
662 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 678 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
663 679
664 } 680 }
665 status.setText ( i18n("Deleting todos ...") ); 681 status.setText ( i18n("Deleting todos ...") );
666 qApp->processEvents(); 682 qApp->processEvents();
667 //qDebug("deleting... "); 683 //qDebug("deleting... ");
668 if ( deleteEnt ) { 684 if ( deleteEnt ) {
669 QFile file( fileName ); 685 QFile file( fileName );
670 if (!file.open( IO_WriteOnly ) ) { 686 if (!file.open( IO_WriteOnly ) ) {
671 return false; 687 return false;
672 688
673 } 689 }
674 QTextStream ts( &file ); 690 QTextStream ts( &file );
675 ts.setCodec( QTextCodec::codecForName("utf8") ); 691 ts.setCodec( QTextCodec::codecForName("utf8") );
676 ts << deleteString; 692 ts << deleteString;
677 file.close(); 693 file.close();
678 command = "db2file todo -d -c " + codec+ " < "+ fileName; 694 command = "db2file todo -d -c " + codec+ " < "+ fileName;
679 system ( command.latin1() ); 695 system ( command.latin1() );
680 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 696 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
681 } 697 }
682 698
683 return true; 699 return true;
684} 700}
685QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 701QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
686{ 702{
687 QString datestr; 703 QString datestr;
688 QString timestr; 704 QString timestr;
689 int offset = KGlobal::locale()->localTimeOffset( dti ); 705 int offset = KGlobal::locale()->localTimeOffset( dti );
690 QDateTime dt; 706 QDateTime dt;
691 if (useTZ) 707 if (useTZ)
692 dt = dti.addSecs ( -(offset*60)); 708 dt = dti.addSecs ( -(offset*60));
693 else 709 else
694 dt = dti; 710 dt = dti;
695 if(dt.date().isValid()){ 711 if(dt.date().isValid()){
696 const QDate& date = dt.date(); 712 const QDate& date = dt.date();
697 datestr.sprintf("%04d%02d%02d", 713 datestr.sprintf("%04d%02d%02d",
698 date.year(), date.month(), date.day()); 714 date.year(), date.month(), date.day());
699 } 715 }
700 if(dt.time().isValid()){ 716 if(dt.time().isValid()){
701 const QTime& time = dt.time(); 717 const QTime& time = dt.time();
702 timestr.sprintf("T%02d%02d%02d", 718 timestr.sprintf("T%02d%02d%02d",
703 time.hour(), time.minute(), time.second()); 719 time.hour(), time.minute(), time.second());
704 } 720 }
705 return datestr + timestr; 721 return datestr + timestr;
706} 722}
707QString SharpFormat::getEventString( Event* event ) 723QString SharpFormat::getEventString( Event* event )
708{ 724{
709 QStringList list; 725 QStringList list;
710 list.append( event->getID("Sharp_DTM") ); 726 list.append( event->getID("Sharp_DTM") );
711 list.append( event->categories().join(",") ); 727 list.append( event->categories().join(",") );
712 if ( !event->summary().isEmpty() ) 728 if ( !event->summary().isEmpty() )
713 list.append( event->summary() ); 729 list.append( event->summary() );
714 else 730 else
715 list.append("" ); 731 list.append("" );
716 if ( !event->location().isEmpty() ) 732 if ( !event->location().isEmpty() )
717 list.append( event->location() ); 733 list.append( event->location() );
718 else 734 else
719 list.append("" ); 735 list.append("" );
720 if ( !event->description().isEmpty() ) 736 if ( !event->description().isEmpty() )
721 list.append( event->description() ); 737 list.append( event->description() );
722 else 738 else
723 list.append( "" ); 739 list.append( "" );
724 if ( event->doesFloat () ) { 740 if ( event->doesFloat () ) {
725 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 741 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
726 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 742 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
727 list.append( "1" ); 743 list.append( "1" );
728 744
729 } 745 }
730 else { 746 else {
731 list.append( dtToString( event->dtStart()) ); 747 list.append( dtToString( event->dtStart()) );
732 list.append( dtToString( event->dtEnd()) ); //6 748 list.append( dtToString( event->dtEnd()) ); //6
733 list.append( "0" ); 749 list.append( "0" );
734 } 750 }
735 bool noAlarm = true; 751 bool noAlarm = true;
736 if ( event->alarms().count() > 0 ) { 752 if ( event->alarms().count() > 0 ) {
737 Alarm * al = event->alarms().first(); 753 Alarm * al = event->alarms().first();
738 if ( al->enabled() ) { 754 if ( al->enabled() ) {
739 noAlarm = false; 755 noAlarm = false;
740 list.append( "0" ); // yes, 0 == alarm 756 list.append( "0" ); // yes, 0 == alarm
741 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 757 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
742 if ( al->type() == Alarm::Audio ) 758 if ( al->type() == Alarm::Audio )
743 list.append( "1" ); // type audio 759 list.append( "1" ); // type audio
744 else 760 else
745 list.append( "0" ); // type silent 761 list.append( "0" ); // type silent
746 } 762 }
747 } 763 }
748 if ( noAlarm ) { 764 if ( noAlarm ) {
749 list.append( "1" ); // yes, 1 == no alarm 765 list.append( "1" ); // yes, 1 == no alarm
750 list.append( "0" ); // no alarm offset 766 list.append( "0" ); // no alarm offset
751 list.append( "1" ); // type 767 list.append( "1" ); // type
752 } 768 }
753 // next is: 11 769 // next is: 11
754 // next is: 11-16 are recurrence 770 // next is: 11-16 are recurrence
755 Recurrence* rec = event->recurrence(); 771 Recurrence* rec = event->recurrence();
756 772
757 bool writeEndDate = false; 773 bool writeEndDate = false;
758 switch ( rec->doesRecur() ) 774 switch ( rec->doesRecur() )
759 { 775 {
760 case Recurrence::rDaily: // 0 776 case Recurrence::rDaily: // 0
761 list.append( "0" ); 777 list.append( "0" );
762 list.append( QString::number( rec->frequency() ));//12 778 list.append( QString::number( rec->frequency() ));//12
763 list.append( "0" ); 779 list.append( "0" );
764 list.append( "0" ); 780 list.append( "0" );
765 writeEndDate = true; 781 writeEndDate = true;
766 break; 782 break;
767 case Recurrence::rWeekly:// 1 783 case Recurrence::rWeekly:// 1
768 list.append( "1" ); 784 list.append( "1" );
769 list.append( QString::number( rec->frequency()) );//12 785 list.append( QString::number( rec->frequency()) );//12
770 list.append( "0" ); 786 list.append( "0" );
771 { 787 {
772 int days = 0; 788 int days = 0;
773 QBitArray weekDays = rec->days(); 789 QBitArray weekDays = rec->days();
774 int i; 790 int i;
775 for( i = 1; i <= 7; ++i ) { 791 for( i = 1; i <= 7; ++i ) {
776 if ( weekDays[i-1] ) { 792 if ( weekDays[i-1] ) {
777 days += 1 << (i-1); 793 days += 1 << (i-1);
778 } 794 }
779 } 795 }
780 list.append( QString::number( days ) ); 796 list.append( QString::number( days ) );
781 } 797 }
782 //pending weekdays 798 //pending weekdays
783 writeEndDate = true; 799 writeEndDate = true;
784 800
785 break; 801 break;
786 case Recurrence::rMonthlyPos:// 2 802 case Recurrence::rMonthlyPos:// 2
787 list.append( "2" ); 803 list.append( "2" );
788 list.append( QString::number( rec->frequency()) );//12 804 list.append( QString::number( rec->frequency()) );//12
789 805
790 writeEndDate = true; 806 writeEndDate = true;
791 { 807 {