summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index d6ead37..547d02b 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -434,1543 +434,1541 @@ void CalendarView::init()
434 SLOT( processTodoListSelection( Incidence * ) ) ); 434 SLOT( processTodoListSelection( Incidence * ) ) );
435 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 435 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
436 436
437 // kdDebug() << "CalendarView::CalendarView() done" << endl; 437 // kdDebug() << "CalendarView::CalendarView() done" << endl;
438 438
439 mDateFrame = new QVBox(0,0,WType_Popup); 439 mDateFrame = new QVBox(0,0,WType_Popup);
440 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 440 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
441 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 441 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
442 mDateFrame->setLineWidth(3); 442 mDateFrame->setLineWidth(3);
443 mDateFrame->hide(); 443 mDateFrame->hide();
444 mDateFrame->setCaption( i18n( "Pick a date to display")); 444 mDateFrame->setCaption( i18n( "Pick a date to display"));
445 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 445 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
446 446
447 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 447 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
448 448
449 mEventEditor = mDialogManager->getEventEditor(); 449 mEventEditor = mDialogManager->getEventEditor();
450 mTodoEditor = mDialogManager->getTodoEditor(); 450 mTodoEditor = mDialogManager->getTodoEditor();
451 451
452 mFlagEditDescription = false; 452 mFlagEditDescription = false;
453 453
454 mSuspendTimer = new QTimer( this ); 454 mSuspendTimer = new QTimer( this );
455 mAlarmTimer = new QTimer( this ); 455 mAlarmTimer = new QTimer( this );
456 mRecheckAlarmTimer = new QTimer( this ); 456 mRecheckAlarmTimer = new QTimer( this );
457 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 457 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
458 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 458 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
459 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 459 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
460 mAlarmDialog = new AlarmDialog( this ); 460 mAlarmDialog = new AlarmDialog( this );
461 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 461 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
462 mAlarmDialog->setServerNotification( false ); 462 mAlarmDialog->setServerNotification( false );
463 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 463 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
464} 464}
465 465
466 466
467CalendarView::~CalendarView() 467CalendarView::~CalendarView()
468{ 468{
469 // kdDebug() << "~CalendarView()" << endl; 469 // kdDebug() << "~CalendarView()" << endl;
470 //qDebug("CalendarView::~CalendarView() "); 470 //qDebug("CalendarView::~CalendarView() ");
471 delete mDialogManager; 471 delete mDialogManager;
472 delete mViewManager; 472 delete mViewManager;
473 delete mStorage; 473 delete mStorage;
474 delete mDateFrame ; 474 delete mDateFrame ;
475 delete beamDialog; 475 delete beamDialog;
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 locCh = ( local->lastModified() > mLastCalendarSync ); 732 locCh = ( local->lastModified() > mLastCalendarSync );
733 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); 733 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
734 if ( !remCh && ! locCh ) { 734 if ( !remCh && ! locCh ) {
735 //qDebug("both not changed "); 735 //qDebug("both not changed ");
736 lastSync = local->lastModified().addDays(1); 736 lastSync = local->lastModified().addDays(1);
737 } else { 737 } else {
738 if ( locCh ) { 738 if ( locCh ) {
739 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); 739 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() );
740 lastSync = local->lastModified().addDays( -1 ); 740 lastSync = local->lastModified().addDays( -1 );
741 if ( !remCh ) 741 if ( !remCh )
742 remote->setLastModified( lastSync.addDays( -1 ) ); 742 remote->setLastModified( lastSync.addDays( -1 ) );
743 } else { 743 } else {
744 //qDebug(" not loc changed "); 744 //qDebug(" not loc changed ");
745 lastSync = local->lastModified().addDays( 1 ); 745 lastSync = local->lastModified().addDays( 1 );
746 if ( remCh ) 746 if ( remCh )
747 remote->setLastModified( lastSync.addDays( 1 ) ); 747 remote->setLastModified( lastSync.addDays( 1 ) );
748 748
749 } 749 }
750 } 750 }
751 full = true; 751 full = true;
752 if ( mode < SYNC_PREF_ASK ) 752 if ( mode < SYNC_PREF_ASK )
753 mode = SYNC_PREF_ASK; 753 mode = SYNC_PREF_ASK;
754 } else { 754 } else {
755 if ( local->lastModified() == remote->lastModified() ) 755 if ( local->lastModified() == remote->lastModified() )
756 if ( local->revision() == remote->revision() ) 756 if ( local->revision() == remote->revision() )
757 return 0; 757 return 0;
758 758
759 } 759 }
760 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 760 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
761 761
762 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 762 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
763 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 763 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
764 //full = true; //debug only 764 //full = true; //debug only
765 if ( full ) { 765 if ( full ) {
766 bool equ = false; 766 bool equ = false;
767 if ( local->type() == "Event" ) { 767 if ( local->type() == "Event" ) {
768 equ = (*((Event*) local) == *((Event*) remote)); 768 equ = (*((Event*) local) == *((Event*) remote));
769 } 769 }
770 else if ( local->type() =="Todo" ) 770 else if ( local->type() =="Todo" )
771 equ = (*((Todo*) local) == (*(Todo*) remote)); 771 equ = (*((Todo*) local) == (*(Todo*) remote));
772 else if ( local->type() =="Journal" ) 772 else if ( local->type() =="Journal" )
773 equ = (*((Journal*) local) == *((Journal*) remote)); 773 equ = (*((Journal*) local) == *((Journal*) remote));
774 if ( equ ) { 774 if ( equ ) {
775 //qDebug("equal "); 775 //qDebug("equal ");
776 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 776 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
777 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 777 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
778 } 778 }
779 if ( mode < SYNC_PREF_FORCE_LOCAL ) 779 if ( mode < SYNC_PREF_FORCE_LOCAL )
780 return 0; 780 return 0;
781 781
782 }//else //debug only 782 }//else //debug only
783 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 783 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
784 } 784 }
785 int result; 785 int result;
786 bool localIsNew; 786 bool localIsNew;
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remote->lastModified() ) 792 if ( lastSync > remote->lastModified() )
793 return 1; 793 return 1;
794 if ( lastSync > local->lastModified() ) 794 if ( lastSync > local->lastModified() )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remote->lastModified() ) 799 if ( lastSync > remote->lastModified() )
800 return 1; 800 return 1;
801 if ( lastSync > local->lastModified() ) 801 if ( lastSync > local->lastModified() )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( local->lastModified() > remote->lastModified() ) 806 if ( local->lastModified() > remote->lastModified() )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
813 if ( lastSync > remote->lastModified() ) 813 if ( lastSync > remote->lastModified() )
814 return 1; 814 return 1;
815 if ( lastSync > local->lastModified() ) 815 if ( lastSync > local->lastModified() )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
818 localIsNew = local->lastModified() > remote->lastModified(); 818 localIsNew = local->lastModified() > remote->lastModified();
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872// probaly useless 872// probaly useless
873void CalendarView::setupExternSyncProfiles() 873void CalendarView::setupExternSyncProfiles()
874{ 874{
875 Event* lse; 875 Event* lse;
876 mExternLastSyncEvent.clear(); 876 mExternLastSyncEvent.clear();
877 int i; 877 int i;
878 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 878 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
879 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 879 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
880 if ( lse ) 880 if ( lse )
881 mExternLastSyncEvent.append( lse ); 881 mExternLastSyncEvent.append( lse );
882 else 882 else
883 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 883 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
884 } 884 }
885 885
886} 886}
887// we check, if the to delete event has a id for a profile 887// we check, if the to delete event has a id for a profile
888// if yes, we set this id in the profile to delete 888// if yes, we set this id in the profile to delete
889void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 889void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
890{ 890{
891 if ( lastSync.count() == 0 ) { 891 if ( lastSync.count() == 0 ) {
892 //qDebug(" lastSync.count() == 0"); 892 //qDebug(" lastSync.count() == 0");
893 return; 893 return;
894 } 894 }
895 if ( toDelete->type() == "Journal" ) 895 if ( toDelete->type() == "Journal" )
896 return; 896 return;
897 897
898 Event* eve = lastSync.first(); 898 Event* eve = lastSync.first();
899 899
900 while ( eve ) { 900 while ( eve ) {
901 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 901 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
902 if ( !id.isEmpty() ) { 902 if ( !id.isEmpty() ) {
903 QString des = eve->description(); 903 QString des = eve->description();
904 QString pref = "e"; 904 QString pref = "e";
905 if ( toDelete->type() == "Todo" ) 905 if ( toDelete->type() == "Todo" )
906 pref = "t"; 906 pref = "t";
907 des += pref+ id + ","; 907 des += pref+ id + ",";
908 eve->setReadOnly( false ); 908 eve->setReadOnly( false );
909 eve->setDescription( des ); 909 eve->setDescription( des );
910 //qDebug("setdes %s ", des.latin1()); 910 //qDebug("setdes %s ", des.latin1());
911 eve->setReadOnly( true ); 911 eve->setReadOnly( true );
912 } 912 }
913 eve = lastSync.next(); 913 eve = lastSync.next();
914 } 914 }
915 915
916} 916}
917void CalendarView::checkExternalId( Incidence * inc ) 917void CalendarView::checkExternalId( Incidence * inc )
918{ 918{
919 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 919 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
920 checkExternSyncEvent( lastSync, inc ); 920 checkExternSyncEvent( lastSync, inc );
921 921
922} 922}
923bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 923bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
924{ 924{
925 bool syncOK = true; 925 bool syncOK = true;
926 int addedEvent = 0; 926 int addedEvent = 0;
927 int addedEventR = 0; 927 int addedEventR = 0;
928 int deletedEventR = 0; 928 int deletedEventR = 0;
929 int deletedEventL = 0; 929 int deletedEventL = 0;
930 int changedLocal = 0; 930 int changedLocal = 0;
931 int changedRemote = 0; 931 int changedRemote = 0;
932 //QPtrList<Event> el = local->rawEvents(); 932 //QPtrList<Event> el = local->rawEvents();
933 Event* eventR; 933 Event* eventR;
934 QString uid; 934 QString uid;
935 int take; 935 int take;
936 Event* eventL; 936 Event* eventL;
937 Event* eventRSync; 937 Event* eventRSync;
938 Event* eventLSync; 938 Event* eventLSync;
939 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 939 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
940 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 940 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
941 bool fullDateRange = false; 941 bool fullDateRange = false;
942 mLastCalendarSync = QDateTime::currentDateTime(); 942 mLastCalendarSync = QDateTime::currentDateTime();
943 QDateTime modifiedCalendar = mLastCalendarSync;; 943 QDateTime modifiedCalendar = mLastCalendarSync;;
944 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 944 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
945 if ( eventR ) { 945 if ( eventR ) {
946 eventRSync = (Event*) eventR->clone(); 946 eventRSync = (Event*) eventR->clone();
947 remote->deleteEvent(eventR ); 947 remote->deleteEvent(eventR );
948 948
949 } else { 949 } else {
950 fullDateRange = true; 950 fullDateRange = true;
951 eventRSync = new Event(); 951 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
957 } 957 }
958 eventLSync = getLastSyncEvent(); 958 eventLSync = getLastSyncEvent();
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 960 fullDateRange = true;
961 961
962 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 964
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 967 fullDateRange = true;
968 } 968 }
969 } 969 }
970 if ( fullDateRange ) 970 if ( fullDateRange )
971 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 971 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
972 else 972 else
973 mLastCalendarSync = eventLSync->dtStart(); 973 mLastCalendarSync = eventLSync->dtStart();
974 // for resyncing if own file has changed 974 // for resyncing if own file has changed
975 if ( mCurrentSyncDevice == "deleteaftersync" ) { 975 if ( mCurrentSyncDevice == "deleteaftersync" ) {
976 mLastCalendarSync = loadedFileVersion; 976 mLastCalendarSync = loadedFileVersion;
977 qDebug("setting mLastCalendarSync "); 977 qDebug("setting mLastCalendarSync ");
978 } 978 }
979 //qDebug("*************************** "); 979 //qDebug("*************************** ");
980 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 980 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
981 QPtrList<Incidence> er = remote->rawIncidences(); 981 QPtrList<Incidence> er = remote->rawIncidences();
982 Incidence* inR = er.first(); 982 Incidence* inR = er.first();
983 Incidence* inL; 983 Incidence* inL;
984 QProgressBar bar( er.count(),0 ); 984 QProgressBar bar( er.count(),0 );
985 bar.setCaption (i18n("Syncing - close to abort!") ); 985 bar.setCaption (i18n("Syncing - close to abort!") );
986 986
987 int w = 300; 987 int w = 300;
988 if ( QApplication::desktop()->width() < 320 ) 988 if ( QApplication::desktop()->width() < 320 )
989 w = 220; 989 w = 220;
990 int h = bar.sizeHint().height() ; 990 int h = bar.sizeHint().height() ;
991 int dw = QApplication::desktop()->width(); 991 int dw = QApplication::desktop()->width();
992 int dh = QApplication::desktop()->height(); 992 int dh = QApplication::desktop()->height();
993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
994 bar.show(); 994 bar.show();
995 int modulo = (er.count()/10)+1; 995 int modulo = (er.count()/10)+1;
996 int incCounter = 0; 996 int incCounter = 0;
997 while ( inR ) { 997 while ( inR ) {
998 if ( ! bar.isVisible() ) 998 if ( ! bar.isVisible() )
999 return false; 999 return false;
1000 if ( incCounter % modulo == 0 ) 1000 if ( incCounter % modulo == 0 )
1001 bar.setProgress( incCounter ); 1001 bar.setProgress( incCounter );
1002 ++incCounter; 1002 ++incCounter;
1003 uid = inR->uid(); 1003 uid = inR->uid();
1004 bool skipIncidence = false; 1004 bool skipIncidence = false;
1005 if ( uid.left(15) == QString("last-syncEvent-") ) 1005 if ( uid.left(15) == QString("last-syncEvent-") )
1006 skipIncidence = true; 1006 skipIncidence = true;
1007 1007
1008 qApp->processEvents(); 1008 qApp->processEvents();
1009 if ( !skipIncidence ) { 1009 if ( !skipIncidence ) {
1010 inL = local->incidence( uid ); 1010 inL = local->incidence( uid );
1011 if ( inL ) { // maybe conflict - same uid in both calendars 1011 if ( inL ) { // maybe conflict - same uid in both calendars
1012 int maxrev = inL->revision(); 1012 int maxrev = inL->revision();
1013 if ( maxrev < inR->revision() ) 1013 if ( maxrev < inR->revision() )
1014 maxrev = inR->revision(); 1014 maxrev = inR->revision();
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1017 if ( take == 3 )
1018 return false; 1018 return false;
1019 if ( take == 1 ) {// take local 1019 if ( take == 1 ) {// take local
1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1021 remote->deleteIncidence( inR ); 1021 remote->deleteIncidence( inR );
1022 if ( inL->revision() < maxrev ) 1022 if ( inL->revision() < maxrev )
1023 inL->setRevision( maxrev ); 1023 inL->setRevision( maxrev );
1024 remote->addIncidence( inL->clone() ); 1024 remote->addIncidence( inL->clone() );
1025 ++changedRemote; 1025 ++changedRemote;
1026 } else { 1026 } else {
1027 if ( inR->revision() < maxrev ) 1027 if ( inR->revision() < maxrev )
1028 inR->setRevision( maxrev ); 1028 inR->setRevision( maxrev );
1029 local->deleteIncidence( inL ); 1029 local->deleteIncidence( inL );
1030 local->addIncidence( inR->clone() ); 1030 local->addIncidence( inR->clone() );
1031 ++changedLocal; 1031 ++changedLocal;
1032 } 1032 }
1033 } 1033 }
1034 } else { // no conflict 1034 } else { // no conflict
1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1036 QString des = eventLSync->description(); 1036 QString des = eventLSync->description();
1037 QString pref = "e"; 1037 QString pref = "e";
1038 if ( inR->type() == "Todo" ) 1038 if ( inR->type() == "Todo" )
1039 pref = "t"; 1039 pref = "t";
1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1042 //remote->deleteIncidence( inR ); 1042 //remote->deleteIncidence( inR );
1043 ++deletedEventR; 1043 ++deletedEventR;
1044 } else { 1044 } else {
1045 inR->setLastModified( modifiedCalendar ); 1045 inR->setLastModified( modifiedCalendar );
1046 local->addIncidence( inR->clone() ); 1046 local->addIncidence( inR->clone() );
1047 ++addedEvent; 1047 ++addedEvent;
1048 } 1048 }
1049 } else { 1049 } else {
1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1051 inR->setLastModified( modifiedCalendar ); 1051 inR->setLastModified( modifiedCalendar );
1052 local->addIncidence( inR->clone() ); 1052 local->addIncidence( inR->clone() );
1053 ++addedEvent; 1053 ++addedEvent;
1054 } else { 1054 } else {
1055 checkExternSyncEvent(eventRSyncSharp, inR); 1055 checkExternSyncEvent(eventRSyncSharp, inR);
1056 remote->deleteIncidence( inR ); 1056 remote->deleteIncidence( inR );
1057 ++deletedEventR; 1057 ++deletedEventR;
1058 } 1058 }
1059 } 1059 }
1060 } 1060 }
1061 } 1061 }
1062 inR = er.next(); 1062 inR = er.next();
1063 } 1063 }
1064 QPtrList<Incidence> el = local->rawIncidences(); 1064 QPtrList<Incidence> el = local->rawIncidences();
1065 inL = el.first(); 1065 inL = el.first();
1066 modulo = (el.count()/10)+1; 1066 modulo = (el.count()/10)+1;
1067 bar.setCaption (i18n("Add / remove events") ); 1067 bar.setCaption (i18n("Add / remove events") );
1068 bar.setTotalSteps ( el.count() ) ; 1068 bar.setTotalSteps ( el.count() ) ;
1069 bar.show(); 1069 bar.show();
1070 incCounter = 0; 1070 incCounter = 0;
1071 1071
1072 while ( inL ) { 1072 while ( inL ) {
1073 1073
1074 qApp->processEvents(); 1074 qApp->processEvents();
1075 if ( ! bar.isVisible() ) 1075 if ( ! bar.isVisible() )
1076 return false; 1076 return false;
1077 if ( incCounter % modulo == 0 ) 1077 if ( incCounter % modulo == 0 )
1078 bar.setProgress( incCounter ); 1078 bar.setProgress( incCounter );
1079 ++incCounter; 1079 ++incCounter;
1080 uid = inL->uid(); 1080 uid = inL->uid();
1081 bool skipIncidence = false; 1081 bool skipIncidence = false;
1082 if ( uid.left(15) == QString("last-syncEvent-") ) 1082 if ( uid.left(15) == QString("last-syncEvent-") )
1083 skipIncidence = true; 1083 skipIncidence = true;
1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1085 skipIncidence = true; 1085 skipIncidence = true;
1086 if ( !skipIncidence ) { 1086 if ( !skipIncidence ) {
1087 inR = remote->incidence( uid ); 1087 inR = remote->incidence( uid );
1088 if ( ! inR ) { 1088 if ( ! inR ) {
1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1091 local->deleteIncidence( inL ); 1091 local->deleteIncidence( inL );
1092 ++deletedEventL; 1092 ++deletedEventL;
1093 } else { 1093 } else {
1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1095 inL->removeID(mCurrentSyncDevice ); 1095 inL->removeID(mCurrentSyncDevice );
1096 ++addedEventR; 1096 ++addedEventR;
1097 inL->setLastModified( modifiedCalendar ); 1097 inL->setLastModified( modifiedCalendar );
1098 remote->addIncidence( inL->clone() ); 1098 remote->addIncidence( inL->clone() );
1099 } 1099 }
1100 } 1100 }
1101 } else { 1101 } else {
1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1103 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1104 local->deleteIncidence( inL );
1105 ++deletedEventL; 1105 ++deletedEventL;
1106 } else { 1106 } else {
1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1108 ++addedEventR; 1108 ++addedEventR;
1109 inL->setLastModified( modifiedCalendar ); 1109 inL->setLastModified( modifiedCalendar );
1110 remote->addIncidence( inL->clone() ); 1110 remote->addIncidence( inL->clone() );
1111 } 1111 }
1112 } 1112 }
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
1116 inL = el.next(); 1116 inL = el.next();
1117 } 1117 }
1118 1118
1119 bar.hide(); 1119 bar.hide();
1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1121 eventLSync->setReadOnly( false ); 1121 eventLSync->setReadOnly( false );
1122 eventLSync->setDtStart( mLastCalendarSync ); 1122 eventLSync->setDtStart( mLastCalendarSync );
1123 eventRSync->setDtStart( mLastCalendarSync ); 1123 eventRSync->setDtStart( mLastCalendarSync );
1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1128 eventLSync->setReadOnly( true ); 1128 eventLSync->setReadOnly( true );
1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1130 remote->addEvent( eventRSync ); 1130 remote->addEvent( eventRSync );
1131 QString mes; 1131 QString mes;
1132 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 ); 1132 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 );
1133 if ( KOPrefs::instance()->mShowSyncSummary ) { 1133 if ( KOPrefs::instance()->mShowSyncSummary ) {
1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1135 } 1135 }
1136 qDebug( mes ); 1136 qDebug( mes );
1137 mCalendar->checkAlarmForIncidence( 0, true ); 1137 mCalendar->checkAlarmForIncidence( 0, true );
1138 return syncOK; 1138 return syncOK;
1139} 1139}
1140 1140
1141void CalendarView::setSyncDevice( QString s ) 1141void CalendarView::setSyncDevice( QString s )
1142{ 1142{
1143 mCurrentSyncDevice= s; 1143 mCurrentSyncDevice= s;
1144} 1144}
1145void CalendarView::setSyncName( QString s ) 1145void CalendarView::setSyncName( QString s )
1146{ 1146{
1147 mCurrentSyncName= s; 1147 mCurrentSyncName= s;
1148} 1148}
1149bool CalendarView::syncCalendar(QString filename, int mode) 1149bool CalendarView::syncCalendar(QString filename, int mode)
1150{ 1150{
1151 mGlobalSyncMode = SYNC_MODE_NORMAL; 1151 mGlobalSyncMode = SYNC_MODE_NORMAL;
1152 CalendarLocal* calendar = new CalendarLocal(); 1152 CalendarLocal* calendar = new CalendarLocal();
1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1154 FileStorage* storage = new FileStorage( calendar ); 1154 FileStorage* storage = new FileStorage( calendar );
1155 bool syncOK = false; 1155 bool syncOK = false;
1156 storage->setFileName( filename ); 1156 storage->setFileName( filename );
1157 // qDebug("loading ... "); 1157 // qDebug("loading ... ");
1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1159 getEventViewerDialog()->setSyncMode( true ); 1159 getEventViewerDialog()->setSyncMode( true );
1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1161 getEventViewerDialog()->setSyncMode( false ); 1161 getEventViewerDialog()->setSyncMode( false );
1162 if ( syncOK ) { 1162 if ( syncOK ) {
1163 if ( KOPrefs::instance()->mWriteBackFile ) 1163 if ( KOPrefs::instance()->mWriteBackFile )
1164 { 1164 {
1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1166 storage->save(); 1166 storage->save();
1167 } 1167 }
1168 } 1168 }
1169 setModified( true ); 1169 setModified( true );
1170 } 1170 }
1171 delete storage; 1171 delete storage;
1172 delete calendar; 1172 delete calendar;
1173 if ( syncOK ) 1173 if ( syncOK )
1174 updateView(); 1174 updateView();
1175 return syncOK; 1175 return syncOK;
1176} 1176}
1177void CalendarView::syncPhone() 1177void CalendarView::syncPhone()
1178{ 1178{
1179 syncExternal( 1 ); 1179 syncExternal( 1 );
1180} 1180}
1181void CalendarView::syncExternal( int mode ) 1181void CalendarView::syncExternal( int mode )
1182{ 1182{
1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1184 //mCurrentSyncDevice = "sharp-DTM"; 1184 //mCurrentSyncDevice = "sharp-DTM";
1185 if ( KOPrefs::instance()->mAskForPreferences ) 1185 if ( KOPrefs::instance()->mAskForPreferences )
1186 edit_sync_options(); 1186 edit_sync_options();
1187 qApp->processEvents(); 1187 qApp->processEvents();
1188 CalendarLocal* calendar = new CalendarLocal(); 1188 CalendarLocal* calendar = new CalendarLocal();
1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1190 bool syncOK = false; 1190 bool syncOK = false;
1191 bool loadSuccess = false; 1191 bool loadSuccess = false;
1192 PhoneFormat* phoneFormat = 0; 1192 PhoneFormat* phoneFormat = 0;
1193#ifndef DESKTOP_VERSION 1193#ifndef DESKTOP_VERSION
1194 SharpFormat* sharpFormat = 0; 1194 SharpFormat* sharpFormat = 0;
1195 if ( mode == 0 ) { // sharp 1195 if ( mode == 0 ) { // sharp
1196 sharpFormat = new SharpFormat () ; 1196 sharpFormat = new SharpFormat () ;
1197 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1197 loadSuccess = sharpFormat->load( calendar, mCalendar );
1198 1198
1199 } else 1199 } else
1200#endif 1200#endif
1201 if ( mode == 1 ) { // phone 1201 if ( mode == 1 ) { // phone
1202 phoneFormat = new PhoneFormat (); 1202 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1203 loadSuccess = phoneFormat->load( calendar,
1204 mCalendar,
1205 mCurrentSyncDevice,
1206 KOPrefs::instance()->mPhoneDevice, 1203 KOPrefs::instance()->mPhoneDevice,
1207 KOPrefs::instance()->mPhoneConnection, 1204 KOPrefs::instance()->mPhoneConnection,
1208 KOPrefs::instance()->mPhoneModel); 1205 KOPrefs::instance()->mPhoneModel);
1206 loadSuccess = phoneFormat->load( calendar,mCalendar);
1209 1207
1210 } else 1208 } else
1211 return; 1209 return;
1212 if ( loadSuccess ) { 1210 if ( loadSuccess ) {
1213 getEventViewerDialog()->setSyncMode( true ); 1211 getEventViewerDialog()->setSyncMode( true );
1214 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1212 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1215 getEventViewerDialog()->setSyncMode( false ); 1213 getEventViewerDialog()->setSyncMode( false );
1216 qApp->processEvents(); 1214 qApp->processEvents();
1217 if ( syncOK ) { 1215 if ( syncOK ) {
1218 if ( KOPrefs::instance()->mWriteBackFile ) 1216 if ( KOPrefs::instance()->mWriteBackFile )
1219 { 1217 {
1220 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1218 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1221 Incidence* inc = iL.first(); 1219 Incidence* inc = iL.first();
1222 /* obsolete 1220 /* obsolete
1223 while ( inc ) { 1221 while ( inc ) {
1224 inc->setZaurusStat( inc->revision () ); 1222 inc->setZaurusStat( inc->revision () );
1225 inc = iL.next(); 1223 inc = iL.next();
1226 } 1224 }
1227 */ 1225 */
1228#ifndef DESKTOP_VERSION 1226#ifndef DESKTOP_VERSION
1229 if ( sharpFormat ) 1227 if ( sharpFormat )
1230 sharpFormat->save(calendar); 1228 sharpFormat->save(calendar);
1231#endif 1229#endif
1232 if ( phoneFormat ) 1230 if ( phoneFormat )
1233 phoneFormat->save(calendar); 1231 phoneFormat->save(calendar);
1234 iL = calendar->rawIncidences(); 1232 iL = calendar->rawIncidences();
1235 inc = iL.first(); 1233 inc = iL.first();
1236 Incidence* loc; 1234 Incidence* loc;
1237 while ( inc ) { 1235 while ( inc ) {
1238 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1236 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1239 loc = mCalendar->incidence(inc->uid() ); 1237 loc = mCalendar->incidence(inc->uid() );
1240 if ( loc ) { 1238 if ( loc ) {
1241 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1239 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1242 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1240 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1243 } 1241 }
1244 } 1242 }
1245 inc = iL.next(); 1243 inc = iL.next();
1246 } 1244 }
1247 Incidence* lse = getLastSyncEvent(); 1245 Incidence* lse = getLastSyncEvent();
1248 if ( lse ) { 1246 if ( lse ) {
1249 lse->setReadOnly( false ); 1247 lse->setReadOnly( false );
1250 lse->setDescription( "" ); 1248 lse->setDescription( "" );
1251 lse->setReadOnly( true ); 1249 lse->setReadOnly( true );
1252 } 1250 }
1253 } 1251 }
1254 } 1252 }
1255 setModified( true ); 1253 setModified( true );
1256 } else { 1254 } else {
1257 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1255 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1258 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1256 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1259 question, i18n("Ok")) ; 1257 question, i18n("Ok")) ;
1260 1258
1261 } 1259 }
1262 delete calendar; 1260 delete calendar;
1263 updateView(); 1261 updateView();
1264 return ;//syncOK; 1262 return ;//syncOK;
1265 1263
1266} 1264}
1267void CalendarView::syncSharp() 1265void CalendarView::syncSharp()
1268{ 1266{
1269 syncExternal( 0 ); 1267 syncExternal( 0 );
1270 1268
1271} 1269}
1272 1270
1273 1271
1274#include <kabc/stdaddressbook.h> 1272#include <kabc/stdaddressbook.h>
1275bool CalendarView::importBday() 1273bool CalendarView::importBday()
1276{ 1274{
1277 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1275 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1278 KABC::AddressBook::Iterator it; 1276 KABC::AddressBook::Iterator it;
1279 int count = 0; 1277 int count = 0;
1280 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1278 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1281 ++count; 1279 ++count;
1282 } 1280 }
1283 QProgressBar bar(count,0 ); 1281 QProgressBar bar(count,0 );
1284 int w = 300; 1282 int w = 300;
1285 if ( QApplication::desktop()->width() < 320 ) 1283 if ( QApplication::desktop()->width() < 320 )
1286 w = 220; 1284 w = 220;
1287 int h = bar.sizeHint().height() ; 1285 int h = bar.sizeHint().height() ;
1288 int dw = QApplication::desktop()->width(); 1286 int dw = QApplication::desktop()->width();
1289 int dh = QApplication::desktop()->height(); 1287 int dh = QApplication::desktop()->height();
1290 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1288 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1291 bar.show(); 1289 bar.show();
1292 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1290 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1293 qApp->processEvents(); 1291 qApp->processEvents();
1294 count = 0; 1292 count = 0;
1295 int addCount = 0; 1293 int addCount = 0;
1296 KCal::Attendee* a = 0; 1294 KCal::Attendee* a = 0;
1297 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1295 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1298 if ( ! bar.isVisible() ) 1296 if ( ! bar.isVisible() )
1299 return false; 1297 return false;
1300 bar.setProgress( count++ ); 1298 bar.setProgress( count++ );
1301 qApp->processEvents(); 1299 qApp->processEvents();
1302 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1300 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1303 if ( (*it).birthday().date().isValid() ){ 1301 if ( (*it).birthday().date().isValid() ){
1304 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1302 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1305 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1303 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1306 ++addCount; 1304 ++addCount;
1307 } 1305 }
1308 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1306 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1309 if ( anni.isValid() ){ 1307 if ( anni.isValid() ){
1310 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1308 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1311 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1309 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1312 ++addCount; 1310 ++addCount;
1313 } 1311 }
1314 } 1312 }
1315 updateView(); 1313 updateView();
1316 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1314 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1317 return true; 1315 return true;
1318} 1316}
1319 1317
1320bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1318bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1321{ 1319{
1322 //qDebug("addAnni "); 1320 //qDebug("addAnni ");
1323 Event * ev = new Event(); 1321 Event * ev = new Event();
1324 if ( a ) { 1322 if ( a ) {
1325 ev->addAttendee( a ); 1323 ev->addAttendee( a );
1326 } 1324 }
1327 QString kind; 1325 QString kind;
1328 if ( birthday ) 1326 if ( birthday )
1329 kind = i18n( "Birthday" ); 1327 kind = i18n( "Birthday" );
1330 else 1328 else
1331 kind = i18n( "Anniversary" ); 1329 kind = i18n( "Anniversary" );
1332 ev->setSummary( name + " - " + kind ); 1330 ev->setSummary( name + " - " + kind );
1333 ev->setOrganizer( "nobody@nowhere" ); 1331 ev->setOrganizer( "nobody@nowhere" );
1334 ev->setCategories( kind ); 1332 ev->setCategories( kind );
1335 ev->setDtStart( QDateTime(date) ); 1333 ev->setDtStart( QDateTime(date) );
1336 ev->setDtEnd( QDateTime(date) ); 1334 ev->setDtEnd( QDateTime(date) );
1337 ev->setFloats( true ); 1335 ev->setFloats( true );
1338 Recurrence * rec = ev->recurrence(); 1336 Recurrence * rec = ev->recurrence();
1339 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1337 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1340 rec->addYearlyNum( date.month() ); 1338 rec->addYearlyNum( date.month() );
1341 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1339 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1342 delete ev; 1340 delete ev;
1343 return false; 1341 return false;
1344 } 1342 }
1345 return true; 1343 return true;
1346 1344
1347} 1345}
1348bool CalendarView::importQtopia( const QString &categories, 1346bool CalendarView::importQtopia( const QString &categories,
1349 const QString &datebook, 1347 const QString &datebook,
1350 const QString &todolist ) 1348 const QString &todolist )
1351{ 1349{
1352 1350
1353 QtopiaFormat qtopiaFormat; 1351 QtopiaFormat qtopiaFormat;
1354 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1352 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1355 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1353 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1356 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1354 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1357 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1355 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1358 1356
1359 updateView(); 1357 updateView();
1360 return true; 1358 return true;
1361 1359
1362#if 0 1360#if 0
1363 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1361 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1364 mCurrentSyncDevice = "qtopia-XML"; 1362 mCurrentSyncDevice = "qtopia-XML";
1365 if ( KOPrefs::instance()->mAskForPreferences ) 1363 if ( KOPrefs::instance()->mAskForPreferences )
1366 edit_sync_options(); 1364 edit_sync_options();
1367 qApp->processEvents(); 1365 qApp->processEvents();
1368 CalendarLocal* calendar = new CalendarLocal(); 1366 CalendarLocal* calendar = new CalendarLocal();
1369 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1367 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1370 bool syncOK = false; 1368 bool syncOK = false;
1371 QtopiaFormat qtopiaFormat; 1369 QtopiaFormat qtopiaFormat;
1372 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1370 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1373 bool loadOk = true; 1371 bool loadOk = true;
1374 if ( !categories.isEmpty() ) 1372 if ( !categories.isEmpty() )
1375 loadOk = qtopiaFormat.load( calendar, categories ); 1373 loadOk = qtopiaFormat.load( calendar, categories );
1376 if ( loadOk && !datebook.isEmpty() ) 1374 if ( loadOk && !datebook.isEmpty() )
1377 loadOk = qtopiaFormat.load( calendar, datebook ); 1375 loadOk = qtopiaFormat.load( calendar, datebook );
1378 if ( loadOk && !todolist.isEmpty() ) 1376 if ( loadOk && !todolist.isEmpty() )
1379 loadOk = qtopiaFormat.load( calendar, todolist ); 1377 loadOk = qtopiaFormat.load( calendar, todolist );
1380 1378
1381 if ( loadOk ) { 1379 if ( loadOk ) {
1382 getEventViewerDialog()->setSyncMode( true ); 1380 getEventViewerDialog()->setSyncMode( true );
1383 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1381 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1384 getEventViewerDialog()->setSyncMode( false ); 1382 getEventViewerDialog()->setSyncMode( false );
1385 qApp->processEvents(); 1383 qApp->processEvents();
1386 if ( syncOK ) { 1384 if ( syncOK ) {
1387 if ( KOPrefs::instance()->mWriteBackFile ) 1385 if ( KOPrefs::instance()->mWriteBackFile )
1388 { 1386 {
1389 // write back XML file 1387 // write back XML file
1390 1388
1391 } 1389 }
1392 setModified( true ); 1390 setModified( true );
1393 } 1391 }
1394 } else { 1392 } else {
1395 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1393 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1396 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1394 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1397 question, i18n("Ok")) ; 1395 question, i18n("Ok")) ;
1398 } 1396 }
1399 delete calendar; 1397 delete calendar;
1400 updateView(); 1398 updateView();
1401 return syncOK; 1399 return syncOK;
1402 1400
1403 1401
1404#endif 1402#endif
1405 1403
1406} 1404}
1407 1405
1408void CalendarView::setSyncEventsReadOnly() 1406void CalendarView::setSyncEventsReadOnly()
1409{ 1407{
1410 Event * ev; 1408 Event * ev;
1411 QPtrList<Event> eL = mCalendar->rawEvents(); 1409 QPtrList<Event> eL = mCalendar->rawEvents();
1412 ev = eL.first(); 1410 ev = eL.first();
1413 while ( ev ) { 1411 while ( ev ) {
1414 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1412 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1415 ev->setReadOnly( true ); 1413 ev->setReadOnly( true );
1416 ev = eL.next(); 1414 ev = eL.next();
1417 } 1415 }
1418} 1416}
1419bool CalendarView::openCalendar(QString filename, bool merge) 1417bool CalendarView::openCalendar(QString filename, bool merge)
1420{ 1418{
1421 1419
1422 if (filename.isEmpty()) { 1420 if (filename.isEmpty()) {
1423 return false; 1421 return false;
1424 } 1422 }
1425 1423
1426 if (!QFile::exists(filename)) { 1424 if (!QFile::exists(filename)) {
1427 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1425 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1428 return false; 1426 return false;
1429 } 1427 }
1430 1428
1431 globalFlagBlockAgenda = 1; 1429 globalFlagBlockAgenda = 1;
1432 if (!merge) mCalendar->close(); 1430 if (!merge) mCalendar->close();
1433 1431
1434 mStorage->setFileName( filename ); 1432 mStorage->setFileName( filename );
1435 1433
1436 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { 1434 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) {
1437 if ( merge ) ;//setModified( true ); 1435 if ( merge ) ;//setModified( true );
1438 else { 1436 else {
1439 //setModified( true ); 1437 //setModified( true );
1440 mViewManager->setDocumentId( filename ); 1438 mViewManager->setDocumentId( filename );
1441 mDialogManager->setDocumentId( filename ); 1439 mDialogManager->setDocumentId( filename );
1442 mTodoList->setDocumentId( filename ); 1440 mTodoList->setDocumentId( filename );
1443 } 1441 }
1444 globalFlagBlockAgenda = 2; 1442 globalFlagBlockAgenda = 2;
1445 // if ( getLastSyncEvent() ) 1443 // if ( getLastSyncEvent() )
1446 // getLastSyncEvent()->setReadOnly( true ); 1444 // getLastSyncEvent()->setReadOnly( true );
1447 mCalendar->reInitAlarmSettings(); 1445 mCalendar->reInitAlarmSettings();
1448 setSyncEventsReadOnly(); 1446 setSyncEventsReadOnly();
1449 updateUnmanagedViews(); 1447 updateUnmanagedViews();
1450 updateView(); 1448 updateView();
1451 if ( filename != MainWindow::defaultFileName() ) 1449 if ( filename != MainWindow::defaultFileName() )
1452 saveCalendar( MainWindow::defaultFileName() ); 1450 saveCalendar( MainWindow::defaultFileName() );
1453 loadedFileVersion = QDateTime::currentDateTime(); 1451 loadedFileVersion = QDateTime::currentDateTime();
1454 return true; 1452 return true;
1455 } else { 1453 } else {
1456 // while failing to load, the calendar object could 1454 // while failing to load, the calendar object could
1457 // have become partially populated. Clear it out. 1455 // have become partially populated. Clear it out.
1458 if ( !merge ) mCalendar->close(); 1456 if ( !merge ) mCalendar->close();
1459 1457
1460 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1458 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1461 1459
1462 globalFlagBlockAgenda = 2; 1460 globalFlagBlockAgenda = 2;
1463 updateView(); 1461 updateView();
1464 } 1462 }
1465 return false; 1463 return false;
1466} 1464}
1467void CalendarView::setLoadedFileVersion(QDateTime dt) 1465void CalendarView::setLoadedFileVersion(QDateTime dt)
1468{ 1466{
1469 loadedFileVersion = dt; 1467 loadedFileVersion = dt;
1470} 1468}
1471bool CalendarView::checkFileChanged(QString fn) 1469bool CalendarView::checkFileChanged(QString fn)
1472{ 1470{
1473 QFileInfo finf ( fn ); 1471 QFileInfo finf ( fn );
1474 if ( !finf.exists() ) 1472 if ( !finf.exists() )
1475 return true; 1473 return true;
1476 QDateTime dt = finf.lastModified (); 1474 QDateTime dt = finf.lastModified ();
1477 if ( dt <= loadedFileVersion ) 1475 if ( dt <= loadedFileVersion )
1478 return false; 1476 return false;
1479 return true; 1477 return true;
1480 1478
1481} 1479}
1482bool CalendarView::checkFileVersion(QString fn) 1480bool CalendarView::checkFileVersion(QString fn)
1483{ 1481{
1484 QFileInfo finf ( fn ); 1482 QFileInfo finf ( fn );
1485 if ( !finf.exists() ) 1483 if ( !finf.exists() )
1486 return true; 1484 return true;
1487 QDateTime dt = finf.lastModified (); 1485 QDateTime dt = finf.lastModified ();
1488 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1486 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1489 //qDebug("file on disk version %s",dt.toString().latin1()); 1487 //qDebug("file on disk version %s",dt.toString().latin1());
1490 if ( dt <= loadedFileVersion ) 1488 if ( dt <= loadedFileVersion )
1491 return true; 1489 return true;
1492 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , 1490 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) ,
1493 i18n("KO/Pi Warning"),i18n("Overwrite"), 1491 i18n("KO/Pi Warning"),i18n("Overwrite"),
1494 i18n("Sync+save")); 1492 i18n("Sync+save"));
1495 1493
1496 if ( km == KMessageBox::Cancel ) 1494 if ( km == KMessageBox::Cancel )
1497 return false; 1495 return false;
1498 if ( km == KMessageBox::Yes ) 1496 if ( km == KMessageBox::Yes )
1499 return true; 1497 return true;
1500 1498
1501 setSyncDevice("deleteaftersync" ); 1499 setSyncDevice("deleteaftersync" );
1502 KOPrefs::instance()->mAskForPreferences = true; 1500 KOPrefs::instance()->mAskForPreferences = true;
1503 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1501 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1504 KOPrefs::instance()->mWriteBackFile = false; 1502 KOPrefs::instance()->mWriteBackFile = false;
1505 KOPrefs::instance()->mWriteBackExistingOnly = false; 1503 KOPrefs::instance()->mWriteBackExistingOnly = false;
1506 KOPrefs::instance()->mShowSyncSummary = false; 1504 KOPrefs::instance()->mShowSyncSummary = false;
1507 syncCalendar( fn, 3 ); 1505 syncCalendar( fn, 3 );
1508 Event * e = getLastSyncEvent(); 1506 Event * e = getLastSyncEvent();
1509 mCalendar->deleteEvent ( e ); 1507 mCalendar->deleteEvent ( e );
1510 updateView(); 1508 updateView();
1511 return true; 1509 return true;
1512} 1510}
1513 1511
1514bool CalendarView::saveCalendar( QString filename ) 1512bool CalendarView::saveCalendar( QString filename )
1515{ 1513{
1516 1514
1517 // Store back all unsaved data into calendar object 1515 // Store back all unsaved data into calendar object
1518 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1516 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1519 if ( mViewManager->currentView() ) 1517 if ( mViewManager->currentView() )
1520 mViewManager->currentView()->flushView(); 1518 mViewManager->currentView()->flushView();
1521 1519
1522 //mStorage->setFileName( filename ); 1520 //mStorage->setFileName( filename );
1523 1521
1524 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1522 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1525 mStorage->setFileName( filename ); 1523 mStorage->setFileName( filename );
1526 bool success; 1524 bool success;
1527 success = mStorage->save(); 1525 success = mStorage->save();
1528 if ( !success ) { 1526 if ( !success ) {
1529 return false; 1527 return false;
1530 } 1528 }
1531 1529
1532 return true; 1530 return true;
1533} 1531}
1534 1532
1535void CalendarView::closeCalendar() 1533void CalendarView::closeCalendar()
1536{ 1534{
1537 1535
1538 // child windows no longer valid 1536 // child windows no longer valid
1539 emit closingDown(); 1537 emit closingDown();
1540 1538
1541 mCalendar->close(); 1539 mCalendar->close();
1542 setModified(false); 1540 setModified(false);
1543 updateView(); 1541 updateView();
1544} 1542}
1545 1543
1546void CalendarView::archiveCalendar() 1544void CalendarView::archiveCalendar()
1547{ 1545{
1548 mDialogManager->showArchiveDialog(); 1546 mDialogManager->showArchiveDialog();
1549} 1547}
1550 1548
1551 1549
1552void CalendarView::readSettings() 1550void CalendarView::readSettings()
1553{ 1551{
1554 1552
1555 1553
1556 // mViewManager->showAgendaView(); 1554 // mViewManager->showAgendaView();
1557 QString str; 1555 QString str;
1558 //qDebug("CalendarView::readSettings() "); 1556 //qDebug("CalendarView::readSettings() ");
1559 // read settings from the KConfig, supplying reasonable 1557 // read settings from the KConfig, supplying reasonable
1560 // defaults where none are to be found 1558 // defaults where none are to be found
1561 KConfig *config = KOGlobals::config(); 1559 KConfig *config = KOGlobals::config();
1562#ifndef KORG_NOSPLITTER 1560#ifndef KORG_NOSPLITTER
1563 config->setGroup("KOrganizer Geometry"); 1561 config->setGroup("KOrganizer Geometry");
1564 1562
1565 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1563 QValueList<int> sizes = config->readIntListEntry("Separator1");
1566 if (sizes.count() != 2) { 1564 if (sizes.count() != 2) {
1567 sizes << mDateNavigator->minimumSizeHint().width(); 1565 sizes << mDateNavigator->minimumSizeHint().width();
1568 sizes << 300; 1566 sizes << 300;
1569 } 1567 }
1570 mPanner->setSizes(sizes); 1568 mPanner->setSizes(sizes);
1571 1569
1572 sizes = config->readIntListEntry("Separator2"); 1570 sizes = config->readIntListEntry("Separator2");
1573 if ( ( mResourceView && sizes.count() == 4 ) || 1571 if ( ( mResourceView && sizes.count() == 4 ) ||
1574 ( !mResourceView && sizes.count() == 3 ) ) { 1572 ( !mResourceView && sizes.count() == 3 ) ) {
1575 mLeftSplitter->setSizes(sizes); 1573 mLeftSplitter->setSizes(sizes);
1576 } 1574 }
1577#endif 1575#endif
1578 globalFlagBlockAgenda = 1; 1576 globalFlagBlockAgenda = 1;
1579 mViewManager->showAgendaView(); 1577 mViewManager->showAgendaView();
1580 //mViewManager->readSettings( config ); 1578 //mViewManager->readSettings( config );
1581 mTodoList->restoreLayout(config,QString("Todo Layout")); 1579 mTodoList->restoreLayout(config,QString("Todo Layout"));
1582 readFilterSettings(config); 1580 readFilterSettings(config);
1583 config->setGroup( "Views" ); 1581 config->setGroup( "Views" );
1584 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1582 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1585 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1583 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1586 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1584 else if ( dateCount == 7 ) mNavigator->selectWeek();
1587 else mNavigator->selectDates( dateCount ); 1585 else mNavigator->selectDates( dateCount );
1588 // mViewManager->readSettings( config ); 1586 // mViewManager->readSettings( config );
1589 updateConfig(); 1587 updateConfig();
1590 globalFlagBlockAgenda = 2; 1588 globalFlagBlockAgenda = 2;
1591 mViewManager->readSettings( config ); 1589 mViewManager->readSettings( config );
1592#ifdef DESKTOP_VERSION 1590#ifdef DESKTOP_VERSION
1593 config->setGroup("WidgetLayout"); 1591 config->setGroup("WidgetLayout");
1594 QStringList list; 1592 QStringList list;
1595 list = config->readListEntry("MainLayout"); 1593 list = config->readListEntry("MainLayout");
1596 int x,y,w,h; 1594 int x,y,w,h;
1597 if ( ! list.isEmpty() ) { 1595 if ( ! list.isEmpty() ) {
1598 x = list[0].toInt(); 1596 x = list[0].toInt();
1599 y = list[1].toInt(); 1597 y = list[1].toInt();
1600 w = list[2].toInt(); 1598 w = list[2].toInt();
1601 h = list[3].toInt(); 1599 h = list[3].toInt();
1602 topLevelWidget()->setGeometry(x,y,w,h); 1600 topLevelWidget()->setGeometry(x,y,w,h);
1603 1601
1604 } else { 1602 } else {
1605 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1603 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1606 } 1604 }
1607 list = config->readListEntry("EditEventLayout"); 1605 list = config->readListEntry("EditEventLayout");
1608 if ( ! list.isEmpty() ) { 1606 if ( ! list.isEmpty() ) {
1609 x = list[0].toInt(); 1607 x = list[0].toInt();
1610 y = list[1].toInt(); 1608 y = list[1].toInt();
1611 w = list[2].toInt(); 1609 w = list[2].toInt();
1612 h = list[3].toInt(); 1610 h = list[3].toInt();
1613 mEventEditor->setGeometry(x,y,w,h); 1611 mEventEditor->setGeometry(x,y,w,h);
1614 1612
1615 } 1613 }
1616 list = config->readListEntry("EditTodoLayout"); 1614 list = config->readListEntry("EditTodoLayout");
1617 if ( ! list.isEmpty() ) { 1615 if ( ! list.isEmpty() ) {
1618 x = list[0].toInt(); 1616 x = list[0].toInt();
1619 y = list[1].toInt(); 1617 y = list[1].toInt();
1620 w = list[2].toInt(); 1618 w = list[2].toInt();
1621 h = list[3].toInt(); 1619 h = list[3].toInt();
1622 mTodoEditor->setGeometry(x,y,w,h); 1620 mTodoEditor->setGeometry(x,y,w,h);
1623 1621
1624 } 1622 }
1625 list = config->readListEntry("ViewerLayout"); 1623 list = config->readListEntry("ViewerLayout");
1626 if ( ! list.isEmpty() ) { 1624 if ( ! list.isEmpty() ) {
1627 x = list[0].toInt(); 1625 x = list[0].toInt();
1628 y = list[1].toInt(); 1626 y = list[1].toInt();
1629 w = list[2].toInt(); 1627 w = list[2].toInt();
1630 h = list[3].toInt(); 1628 h = list[3].toInt();
1631 getEventViewerDialog()->setGeometry(x,y,w,h); 1629 getEventViewerDialog()->setGeometry(x,y,w,h);
1632 } 1630 }
1633#endif 1631#endif
1634 1632
1635} 1633}
1636 1634
1637 1635
1638void CalendarView::writeSettings() 1636void CalendarView::writeSettings()
1639{ 1637{
1640 // kdDebug() << "CalendarView::writeSettings" << endl; 1638 // kdDebug() << "CalendarView::writeSettings" << endl;
1641 1639
1642 KConfig *config = KOGlobals::config(); 1640 KConfig *config = KOGlobals::config();
1643 1641
1644#ifndef KORG_NOSPLITTER 1642#ifndef KORG_NOSPLITTER
1645 config->setGroup("KOrganizer Geometry"); 1643 config->setGroup("KOrganizer Geometry");
1646 1644
1647 QValueList<int> list = mPanner->sizes(); 1645 QValueList<int> list = mPanner->sizes();
1648 config->writeEntry("Separator1",list); 1646 config->writeEntry("Separator1",list);
1649 1647
1650 list = mLeftSplitter->sizes(); 1648 list = mLeftSplitter->sizes();
1651 config->writeEntry("Separator2",list); 1649 config->writeEntry("Separator2",list);
1652#endif 1650#endif
1653 1651
1654 mViewManager->writeSettings( config ); 1652 mViewManager->writeSettings( config );
1655 mTodoList->saveLayout(config,QString("Todo Layout")); 1653 mTodoList->saveLayout(config,QString("Todo Layout"));
1656 mDialogManager->writeSettings( config ); 1654 mDialogManager->writeSettings( config );
1657 //KOPrefs::instance()->usrWriteConfig(); 1655 //KOPrefs::instance()->usrWriteConfig();
1658 KOPrefs::instance()->writeConfig(); 1656 KOPrefs::instance()->writeConfig();
1659 1657
1660 writeFilterSettings(config); 1658 writeFilterSettings(config);
1661 1659
1662 config->setGroup( "Views" ); 1660 config->setGroup( "Views" );
1663 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1661 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1664 1662
1665#ifdef DESKTOP_VERSION 1663#ifdef DESKTOP_VERSION
1666 config->setGroup("WidgetLayout"); 1664 config->setGroup("WidgetLayout");
1667 QStringList list ;//= config->readListEntry("MainLayout"); 1665 QStringList list ;//= config->readListEntry("MainLayout");
1668 int x,y,w,h; 1666 int x,y,w,h;
1669 QWidget* wid; 1667 QWidget* wid;
1670 wid = topLevelWidget(); 1668 wid = topLevelWidget();
1671 x = wid->geometry().x(); 1669 x = wid->geometry().x();
1672 y = wid->geometry().y(); 1670 y = wid->geometry().y();
1673 w = wid->width(); 1671 w = wid->width();
1674 h = wid->height(); 1672 h = wid->height();
1675 list.clear(); 1673 list.clear();
1676 list << QString::number( x ); 1674 list << QString::number( x );
1677 list << QString::number( y ); 1675 list << QString::number( y );
1678 list << QString::number( w ); 1676 list << QString::number( w );
1679 list << QString::number( h ); 1677 list << QString::number( h );
1680 config->writeEntry("MainLayout",list ); 1678 config->writeEntry("MainLayout",list );
1681 1679
1682 wid = mEventEditor; 1680 wid = mEventEditor;
1683 x = wid->geometry().x(); 1681 x = wid->geometry().x();
1684 y = wid->geometry().y(); 1682 y = wid->geometry().y();
1685 w = wid->width(); 1683 w = wid->width();
1686 h = wid->height(); 1684 h = wid->height();
1687 list.clear(); 1685 list.clear();
1688 list << QString::number( x ); 1686 list << QString::number( x );
1689 list << QString::number( y ); 1687 list << QString::number( y );
1690 list << QString::number( w ); 1688 list << QString::number( w );
1691 list << QString::number( h ); 1689 list << QString::number( h );
1692 config->writeEntry("EditEventLayout",list ); 1690 config->writeEntry("EditEventLayout",list );
1693 1691
1694 wid = mTodoEditor; 1692 wid = mTodoEditor;
1695 x = wid->geometry().x(); 1693 x = wid->geometry().x();
1696 y = wid->geometry().y(); 1694 y = wid->geometry().y();
1697 w = wid->width(); 1695 w = wid->width();
1698 h = wid->height(); 1696 h = wid->height();
1699 list.clear(); 1697 list.clear();
1700 list << QString::number( x ); 1698 list << QString::number( x );
1701 list << QString::number( y ); 1699 list << QString::number( y );
1702 list << QString::number( w ); 1700 list << QString::number( w );
1703 list << QString::number( h ); 1701 list << QString::number( h );
1704 config->writeEntry("EditTodoLayout",list ); 1702 config->writeEntry("EditTodoLayout",list );
1705 wid = getEventViewerDialog(); 1703 wid = getEventViewerDialog();
1706 x = wid->geometry().x(); 1704 x = wid->geometry().x();
1707 y = wid->geometry().y(); 1705 y = wid->geometry().y();
1708 w = wid->width(); 1706 w = wid->width();
1709 h = wid->height(); 1707 h = wid->height();
1710 list.clear(); 1708 list.clear();
1711 list << QString::number( x ); 1709 list << QString::number( x );
1712 list << QString::number( y ); 1710 list << QString::number( y );
1713 list << QString::number( w ); 1711 list << QString::number( w );
1714 list << QString::number( h ); 1712 list << QString::number( h );
1715 config->writeEntry("ViewerLayout",list ); 1713 config->writeEntry("ViewerLayout",list );
1716 wid = mDialogManager->getSearchDialog(); 1714 wid = mDialogManager->getSearchDialog();
1717 if ( wid ) { 1715 if ( wid ) {
1718 x = wid->geometry().x(); 1716 x = wid->geometry().x();
1719 y = wid->geometry().y(); 1717 y = wid->geometry().y();
1720 w = wid->width(); 1718 w = wid->width();
1721 h = wid->height(); 1719 h = wid->height();
1722 list.clear(); 1720 list.clear();
1723 list << QString::number( x ); 1721 list << QString::number( x );
1724 list << QString::number( y ); 1722 list << QString::number( y );
1725 list << QString::number( w ); 1723 list << QString::number( w );
1726 list << QString::number( h ); 1724 list << QString::number( h );
1727 config->writeEntry("SearchLayout",list ); 1725 config->writeEntry("SearchLayout",list );
1728 } 1726 }
1729#endif 1727#endif
1730 1728
1731 1729
1732 config->sync(); 1730 config->sync();
1733} 1731}
1734 1732
1735void CalendarView::readFilterSettings(KConfig *config) 1733void CalendarView::readFilterSettings(KConfig *config)
1736{ 1734{
1737 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1735 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1738 1736
1739 mFilters.clear(); 1737 mFilters.clear();
1740 1738
1741 config->setGroup("General"); 1739 config->setGroup("General");
1742 QStringList filterList = config->readListEntry("CalendarFilters"); 1740 QStringList filterList = config->readListEntry("CalendarFilters");
1743 1741
1744 QStringList::ConstIterator it = filterList.begin(); 1742 QStringList::ConstIterator it = filterList.begin();
1745 QStringList::ConstIterator end = filterList.end(); 1743 QStringList::ConstIterator end = filterList.end();
1746 while(it != end) { 1744 while(it != end) {
1747 // kdDebug() << " filter: " << (*it) << endl; 1745 // kdDebug() << " filter: " << (*it) << endl;
1748 1746
1749 CalFilter *filter; 1747 CalFilter *filter;
1750 filter = new CalFilter(*it); 1748 filter = new CalFilter(*it);
1751 config->setGroup("Filter_" + (*it)); 1749 config->setGroup("Filter_" + (*it));
1752 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1750 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1753 filter->setCriteria(config->readNumEntry("Criteria",0)); 1751 filter->setCriteria(config->readNumEntry("Criteria",0));
1754 filter->setCategoryList(config->readListEntry("CategoryList")); 1752 filter->setCategoryList(config->readListEntry("CategoryList"));
1755 mFilters.append(filter); 1753 mFilters.append(filter);
1756 1754
1757 ++it; 1755 ++it;
1758 } 1756 }
1759 1757
1760 if (mFilters.count() == 0) { 1758 if (mFilters.count() == 0) {
1761 CalFilter *filter = new CalFilter(i18n("Default")); 1759 CalFilter *filter = new CalFilter(i18n("Default"));
1762 mFilters.append(filter); 1760 mFilters.append(filter);
1763 } 1761 }
1764 mFilterView->updateFilters(); 1762 mFilterView->updateFilters();
1765 config->setGroup("FilterView"); 1763 config->setGroup("FilterView");
1766 1764
1767 mFilterView->blockSignals(true); 1765 mFilterView->blockSignals(true);
1768 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1766 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1769 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1767 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1770 mFilterView->blockSignals(false); 1768 mFilterView->blockSignals(false);
1771 // We do it manually to avoid it being done twice by the above calls 1769 // We do it manually to avoid it being done twice by the above calls
1772 updateFilter(); 1770 updateFilter();
1773} 1771}
1774 1772
1775void CalendarView::writeFilterSettings(KConfig *config) 1773void CalendarView::writeFilterSettings(KConfig *config)
1776{ 1774{
1777 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1775 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1778 1776
1779 QStringList filterList; 1777 QStringList filterList;
1780 1778
1781 CalFilter *filter = mFilters.first(); 1779 CalFilter *filter = mFilters.first();
1782 while(filter) { 1780 while(filter) {
1783 // kdDebug() << " fn: " << filter->name() << endl; 1781 // kdDebug() << " fn: " << filter->name() << endl;
1784 filterList << filter->name(); 1782 filterList << filter->name();
1785 config->setGroup("Filter_" + filter->name()); 1783 config->setGroup("Filter_" + filter->name());
1786 config->writeEntry("Criteria",filter->criteria()); 1784 config->writeEntry("Criteria",filter->criteria());
1787 config->writeEntry("CategoryList",filter->categoryList()); 1785 config->writeEntry("CategoryList",filter->categoryList());
1788 filter = mFilters.next(); 1786 filter = mFilters.next();
1789 } 1787 }
1790 config->setGroup("General"); 1788 config->setGroup("General");
1791 config->writeEntry("CalendarFilters",filterList); 1789 config->writeEntry("CalendarFilters",filterList);
1792 1790
1793 config->setGroup("FilterView"); 1791 config->setGroup("FilterView");
1794 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1792 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1795 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1793 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1796} 1794}
1797 1795
1798 1796
1799void CalendarView::goToday() 1797void CalendarView::goToday()
1800{ 1798{
1801 mNavigator->selectToday(); 1799 mNavigator->selectToday();
1802} 1800}
1803 1801
1804void CalendarView::goNext() 1802void CalendarView::goNext()
1805{ 1803{
1806 mNavigator->selectNext(); 1804 mNavigator->selectNext();
1807} 1805}
1808 1806
1809void CalendarView::goPrevious() 1807void CalendarView::goPrevious()
1810{ 1808{
1811 mNavigator->selectPrevious(); 1809 mNavigator->selectPrevious();
1812} 1810}
1813void CalendarView::goNextMonth() 1811void CalendarView::goNextMonth()
1814{ 1812{
1815 mNavigator->selectNextMonth(); 1813 mNavigator->selectNextMonth();
1816} 1814}
1817 1815
1818void CalendarView::goPreviousMonth() 1816void CalendarView::goPreviousMonth()
1819{ 1817{
1820 mNavigator->selectPreviousMonth(); 1818 mNavigator->selectPreviousMonth();
1821} 1819}
1822void CalendarView::writeLocale() 1820void CalendarView::writeLocale()
1823{ 1821{
1824 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 1822 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1825 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 1823 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1826 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 1824 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1827 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 1825 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1828 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 1826 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1829 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 1827 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1830 dummy = KOPrefs::instance()->mUserDateFormatShort; 1828 dummy = KOPrefs::instance()->mUserDateFormatShort;
1831 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 1829 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
1832 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 1830 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
1833 KOPrefs::instance()->mDaylightsavingStart, 1831 KOPrefs::instance()->mDaylightsavingStart,
1834 KOPrefs::instance()->mDaylightsavingEnd ); 1832 KOPrefs::instance()->mDaylightsavingEnd );
1835 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 1833 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
1836} 1834}
1837void CalendarView::updateConfig() 1835void CalendarView::updateConfig()
1838{ 1836{
1839 writeLocale(); 1837 writeLocale();
1840 if ( KOPrefs::instance()->mUseAppColors ) 1838 if ( KOPrefs::instance()->mUseAppColors )
1841 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 1839 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
1842 emit configChanged(); 1840 emit configChanged();
1843 mTodoList->updateConfig(); 1841 mTodoList->updateConfig();
1844 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 1842 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
1845 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1843 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1846 // To make the "fill window" configurations work 1844 // To make the "fill window" configurations work
1847 //mViewManager->raiseCurrentView(); 1845 //mViewManager->raiseCurrentView();
1848} 1846}
1849 1847
1850 1848
1851void CalendarView::eventChanged(Event *event) 1849void CalendarView::eventChanged(Event *event)
1852{ 1850{
1853 changeEventDisplay(event,KOGlobals::EVENTEDITED); 1851 changeEventDisplay(event,KOGlobals::EVENTEDITED);
1854 //updateUnmanagedViews(); 1852 //updateUnmanagedViews();
1855} 1853}
1856 1854
1857void CalendarView::eventAdded(Event *event) 1855void CalendarView::eventAdded(Event *event)
1858{ 1856{
1859 changeEventDisplay(event,KOGlobals::EVENTADDED); 1857 changeEventDisplay(event,KOGlobals::EVENTADDED);
1860} 1858}
1861 1859
1862void CalendarView::eventToBeDeleted(Event *) 1860void CalendarView::eventToBeDeleted(Event *)
1863{ 1861{
1864 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 1862 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
1865} 1863}
1866 1864
1867void CalendarView::eventDeleted() 1865void CalendarView::eventDeleted()
1868{ 1866{
1869 changeEventDisplay(0,KOGlobals::EVENTDELETED); 1867 changeEventDisplay(0,KOGlobals::EVENTDELETED);
1870} 1868}
1871void CalendarView::changeTodoDisplay(Todo *which, int action) 1869void CalendarView::changeTodoDisplay(Todo *which, int action)
1872{ 1870{
1873 changeIncidenceDisplay((Incidence *)which, action); 1871 changeIncidenceDisplay((Incidence *)which, action);
1874} 1872}
1875 1873
1876void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 1874void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
1877{ 1875{
1878 updateUnmanagedViews(); 1876 updateUnmanagedViews();
1879 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 1877 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
1880 if ( action == KOGlobals::EVENTDELETED ) { //delete 1878 if ( action == KOGlobals::EVENTDELETED ) { //delete
1881 mCalendar->checkAlarmForIncidence( 0, true ); 1879 mCalendar->checkAlarmForIncidence( 0, true );
1882 if ( mEventViewerDialog ) 1880 if ( mEventViewerDialog )
1883 mEventViewerDialog->hide(); 1881 mEventViewerDialog->hide();
1884 } 1882 }
1885 else 1883 else
1886 mCalendar->checkAlarmForIncidence( which , false ); 1884 mCalendar->checkAlarmForIncidence( which , false );
1887} 1885}
1888 1886
1889// most of the changeEventDisplays() right now just call the view's 1887// most of the changeEventDisplays() right now just call the view's
1890// total update mode, but they SHOULD be recoded to be more refresh-efficient. 1888// total update mode, but they SHOULD be recoded to be more refresh-efficient.
1891void CalendarView::changeEventDisplay(Event *which, int action) 1889void CalendarView::changeEventDisplay(Event *which, int action)
1892{ 1890{
1893 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 1891 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
1894 changeIncidenceDisplay((Incidence *)which, action); 1892 changeIncidenceDisplay((Incidence *)which, action);
1895 mDateNavigator->updateView(); 1893 mDateNavigator->updateView();
1896 //mDialogManager->updateSearchDialog(); 1894 //mDialogManager->updateSearchDialog();
1897 1895
1898 if (which) { 1896 if (which) {
1899 // If there is an event view visible update the display 1897 // If there is an event view visible update the display
1900 mViewManager->currentView()->changeEventDisplay(which,action); 1898 mViewManager->currentView()->changeEventDisplay(which,action);
1901 // TODO: check, if update needed 1899 // TODO: check, if update needed
1902 // if (which->getTodoStatus()) { 1900 // if (which->getTodoStatus()) {
1903 mTodoList->updateView(); 1901 mTodoList->updateView();
1904 // } 1902 // }
1905 } else { 1903 } else {
1906 mViewManager->currentView()->updateView(); 1904 mViewManager->currentView()->updateView();
1907 } 1905 }
1908} 1906}
1909 1907
1910 1908
1911void CalendarView::updateTodoViews() 1909void CalendarView::updateTodoViews()
1912{ 1910{
1913 1911
1914 mTodoList->updateView(); 1912 mTodoList->updateView();
1915 mViewManager->currentView()->updateView(); 1913 mViewManager->currentView()->updateView();
1916 1914
1917} 1915}
1918 1916
1919 1917
1920void CalendarView::updateView(const QDate &start, const QDate &end) 1918void CalendarView::updateView(const QDate &start, const QDate &end)
1921{ 1919{
1922 mTodoList->updateView(); 1920 mTodoList->updateView();
1923 mViewManager->updateView(start, end); 1921 mViewManager->updateView(start, end);
1924 //mDateNavigator->updateView(); 1922 //mDateNavigator->updateView();
1925} 1923}
1926 1924
1927void CalendarView::updateView() 1925void CalendarView::updateView()
1928{ 1926{
1929 DateList tmpList = mNavigator->selectedDates(); 1927 DateList tmpList = mNavigator->selectedDates();
1930 1928
1931 // We assume that the navigator only selects consecutive days. 1929 // We assume that the navigator only selects consecutive days.
1932 updateView( tmpList.first(), tmpList.last() ); 1930 updateView( tmpList.first(), tmpList.last() );
1933} 1931}
1934 1932
1935void CalendarView::updateUnmanagedViews() 1933void CalendarView::updateUnmanagedViews()
1936{ 1934{
1937 mDateNavigator->updateDayMatrix(); 1935 mDateNavigator->updateDayMatrix();
1938} 1936}
1939 1937
1940int CalendarView::msgItemDelete() 1938int CalendarView::msgItemDelete()
1941{ 1939{
1942 return KMessageBox::warningContinueCancel(this, 1940 return KMessageBox::warningContinueCancel(this,
1943 i18n("This item will be\npermanently deleted."), 1941 i18n("This item will be\npermanently deleted."),
1944 i18n("KO/Pi Confirmation"),i18n("Delete")); 1942 i18n("KO/Pi Confirmation"),i18n("Delete"));
1945} 1943}
1946 1944
1947 1945
1948void CalendarView::edit_cut() 1946void CalendarView::edit_cut()
1949{ 1947{
1950 Event *anEvent=0; 1948 Event *anEvent=0;
1951 1949
1952 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1950 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1953 1951
1954 if (mViewManager->currentView()->isEventView()) { 1952 if (mViewManager->currentView()->isEventView()) {
1955 if ( incidence && incidence->type() == "Event" ) { 1953 if ( incidence && incidence->type() == "Event" ) {
1956 anEvent = static_cast<Event *>(incidence); 1954 anEvent = static_cast<Event *>(incidence);
1957 } 1955 }
1958 } 1956 }
1959 1957
1960 if (!anEvent) { 1958 if (!anEvent) {
1961 KNotifyClient::beep(); 1959 KNotifyClient::beep();
1962 return; 1960 return;
1963 } 1961 }
1964 DndFactory factory( mCalendar ); 1962 DndFactory factory( mCalendar );
1965 factory.cutEvent(anEvent); 1963 factory.cutEvent(anEvent);
1966 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 1964 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
1967} 1965}
1968 1966
1969void CalendarView::edit_copy() 1967void CalendarView::edit_copy()
1970{ 1968{
1971 Event *anEvent=0; 1969 Event *anEvent=0;
1972 1970
1973 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1971 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1974 1972
1975 if (mViewManager->currentView()->isEventView()) { 1973 if (mViewManager->currentView()->isEventView()) {
1976 if ( incidence && incidence->type() == "Event" ) { 1974 if ( incidence && incidence->type() == "Event" ) {