-rw-r--r-- | korganizer/calendarview.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index a9de65a..7c8316f 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -462,1537 +462,1538 @@ void CalendarView::init() | |||
462 | //US listen for arriving address resultsets | 462 | //US listen for arriving address resultsets |
463 | connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), | 463 | connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), |
464 | this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); | 464 | this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); |
465 | #endif | 465 | #endif |
466 | 466 | ||
467 | } | 467 | } |
468 | 468 | ||
469 | 469 | ||
470 | CalendarView::~CalendarView() | 470 | CalendarView::~CalendarView() |
471 | { | 471 | { |
472 | // kdDebug() << "~CalendarView()" << endl; | 472 | // kdDebug() << "~CalendarView()" << endl; |
473 | //qDebug("CalendarView::~CalendarView() "); | 473 | //qDebug("CalendarView::~CalendarView() "); |
474 | delete mDialogManager; | 474 | delete mDialogManager; |
475 | delete mViewManager; | 475 | delete mViewManager; |
476 | delete mStorage; | 476 | delete mStorage; |
477 | delete mDateFrame ; | 477 | delete mDateFrame ; |
478 | delete beamDialog; | 478 | delete beamDialog; |
479 | //kdDebug() << "~CalendarView() done" << endl; | 479 | //kdDebug() << "~CalendarView() done" << endl; |
480 | } | 480 | } |
481 | 481 | ||
482 | void CalendarView::showDay( QDate d ) | 482 | void CalendarView::showDay( QDate d ) |
483 | { | 483 | { |
484 | dateNavigator()->blockSignals( true ); | 484 | dateNavigator()->blockSignals( true ); |
485 | dateNavigator()->selectDate( d ); | 485 | dateNavigator()->selectDate( d ); |
486 | dateNavigator()->blockSignals( false ); | 486 | dateNavigator()->blockSignals( false ); |
487 | mViewManager->showDayView(); | 487 | mViewManager->showDayView(); |
488 | //dateNavigator()->selectDate( d ); | 488 | //dateNavigator()->selectDate( d ); |
489 | } | 489 | } |
490 | void CalendarView::timerAlarm() | 490 | void CalendarView::timerAlarm() |
491 | { | 491 | { |
492 | //qDebug("CalendarView::timerAlarm() "); | 492 | //qDebug("CalendarView::timerAlarm() "); |
493 | computeAlarm(mAlarmNotification ); | 493 | computeAlarm(mAlarmNotification ); |
494 | } | 494 | } |
495 | 495 | ||
496 | void CalendarView::suspendAlarm() | 496 | void CalendarView::suspendAlarm() |
497 | { | 497 | { |
498 | //qDebug(" CalendarView::suspendAlarm() "); | 498 | //qDebug(" CalendarView::suspendAlarm() "); |
499 | computeAlarm(mSuspendAlarmNotification ); | 499 | computeAlarm(mSuspendAlarmNotification ); |
500 | 500 | ||
501 | } | 501 | } |
502 | 502 | ||
503 | void CalendarView::startAlarm( QString mess , QString filename) | 503 | void CalendarView::startAlarm( QString mess , QString filename) |
504 | { | 504 | { |
505 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 505 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
506 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); | 506 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); |
507 | 507 | ||
508 | } | 508 | } |
509 | 509 | ||
510 | void CalendarView::checkNextTimerAlarm() | 510 | void CalendarView::checkNextTimerAlarm() |
511 | { | 511 | { |
512 | mCalendar->checkAlarmForIncidence( 0, true ); | 512 | mCalendar->checkAlarmForIncidence( 0, true ); |
513 | } | 513 | } |
514 | 514 | ||
515 | void CalendarView::computeAlarm( QString msg ) | 515 | void CalendarView::computeAlarm( QString msg ) |
516 | { | 516 | { |
517 | 517 | ||
518 | QString mess = msg; | 518 | QString mess = msg; |
519 | QString mAlarmMessage = mess.mid( 9 ); | 519 | QString mAlarmMessage = mess.mid( 9 ); |
520 | QString filename = MainWindow::resourcePath(); | 520 | QString filename = MainWindow::resourcePath(); |
521 | filename += "koalarm.wav"; | 521 | filename += "koalarm.wav"; |
522 | QString tempfilename; | 522 | QString tempfilename; |
523 | if ( mess.left( 13 ) == "suspend_alarm") { | 523 | if ( mess.left( 13 ) == "suspend_alarm") { |
524 | bool error = false; | 524 | bool error = false; |
525 | int len = mess.mid( 13 ).find("+++"); | 525 | int len = mess.mid( 13 ).find("+++"); |
526 | if ( len < 2 ) | 526 | if ( len < 2 ) |
527 | error = true; | 527 | error = true; |
528 | else { | 528 | else { |
529 | tempfilename = mess.mid( 13, len ); | 529 | tempfilename = mess.mid( 13, len ); |
530 | if ( !QFile::exists( tempfilename ) ) | 530 | if ( !QFile::exists( tempfilename ) ) |
531 | error = true; | 531 | error = true; |
532 | } | 532 | } |
533 | if ( ! error ) { | 533 | if ( ! error ) { |
534 | filename = tempfilename; | 534 | filename = tempfilename; |
535 | } | 535 | } |
536 | mAlarmMessage = mess.mid( 13+len+3 ); | 536 | mAlarmMessage = mess.mid( 13+len+3 ); |
537 | //qDebug("suspend file %s ",tempfilename.latin1() ); | 537 | //qDebug("suspend file %s ",tempfilename.latin1() ); |
538 | startAlarm( mAlarmMessage, filename); | 538 | startAlarm( mAlarmMessage, filename); |
539 | return; | 539 | return; |
540 | } | 540 | } |
541 | if ( mess.left( 11 ) == "timer_alarm") { | 541 | if ( mess.left( 11 ) == "timer_alarm") { |
542 | //mTimerTime = 0; | 542 | //mTimerTime = 0; |
543 | startAlarm( mess.mid( 11 ), filename ); | 543 | startAlarm( mess.mid( 11 ), filename ); |
544 | return; | 544 | return; |
545 | } | 545 | } |
546 | if ( mess.left( 10 ) == "proc_alarm") { | 546 | if ( mess.left( 10 ) == "proc_alarm") { |
547 | bool error = false; | 547 | bool error = false; |
548 | int len = mess.mid( 10 ).find("+++"); | 548 | int len = mess.mid( 10 ).find("+++"); |
549 | if ( len < 2 ) | 549 | if ( len < 2 ) |
550 | error = true; | 550 | error = true; |
551 | else { | 551 | else { |
552 | tempfilename = mess.mid( 10, len ); | 552 | tempfilename = mess.mid( 10, len ); |
553 | if ( !QFile::exists( tempfilename ) ) | 553 | if ( !QFile::exists( tempfilename ) ) |
554 | error = true; | 554 | error = true; |
555 | } | 555 | } |
556 | if ( error ) { | 556 | if ( error ) { |
557 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; | 557 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; |
558 | mAlarmMessage += mess.mid( 10+len+3+9 ); | 558 | mAlarmMessage += mess.mid( 10+len+3+9 ); |
559 | } else { | 559 | } else { |
560 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); | 560 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); |
561 | //qDebug("-----system command %s ",tempfilename.latin1() ); | 561 | //qDebug("-----system command %s ",tempfilename.latin1() ); |
562 | #ifndef _WIN32_ | 562 | #ifndef _WIN32_ |
563 | if ( vfork () == 0 ) { | 563 | if ( vfork () == 0 ) { |
564 | execl ( tempfilename.latin1(), 0 ); | 564 | execl ( tempfilename.latin1(), 0 ); |
565 | return; | 565 | return; |
566 | } | 566 | } |
567 | #else | 567 | #else |
568 | QProcess* p = new QProcess(); | 568 | QProcess* p = new QProcess(); |
569 | p->addArgument( tempfilename.latin1() ); | 569 | p->addArgument( tempfilename.latin1() ); |
570 | p->start(); | 570 | p->start(); |
571 | return; | 571 | return; |
572 | #endif | 572 | #endif |
573 | 573 | ||
574 | return; | 574 | return; |
575 | } | 575 | } |
576 | 576 | ||
577 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 577 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
578 | } | 578 | } |
579 | if ( mess.left( 11 ) == "audio_alarm") { | 579 | if ( mess.left( 11 ) == "audio_alarm") { |
580 | bool error = false; | 580 | bool error = false; |
581 | int len = mess.mid( 11 ).find("+++"); | 581 | int len = mess.mid( 11 ).find("+++"); |
582 | if ( len < 2 ) | 582 | if ( len < 2 ) |
583 | error = true; | 583 | error = true; |
584 | else { | 584 | else { |
585 | tempfilename = mess.mid( 11, len ); | 585 | tempfilename = mess.mid( 11, len ); |
586 | if ( !QFile::exists( tempfilename ) ) | 586 | if ( !QFile::exists( tempfilename ) ) |
587 | error = true; | 587 | error = true; |
588 | } | 588 | } |
589 | if ( ! error ) { | 589 | if ( ! error ) { |
590 | filename = tempfilename; | 590 | filename = tempfilename; |
591 | } | 591 | } |
592 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 592 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
593 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 593 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
594 | } | 594 | } |
595 | if ( mess.left( 9 ) == "cal_alarm") { | 595 | if ( mess.left( 9 ) == "cal_alarm") { |
596 | mAlarmMessage = mess.mid( 9 ) ; | 596 | mAlarmMessage = mess.mid( 9 ) ; |
597 | } | 597 | } |
598 | 598 | ||
599 | startAlarm( mAlarmMessage, filename ); | 599 | startAlarm( mAlarmMessage, filename ); |
600 | 600 | ||
601 | 601 | ||
602 | } | 602 | } |
603 | 603 | ||
604 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 604 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
605 | { | 605 | { |
606 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 606 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
607 | 607 | ||
608 | mSuspendAlarmNotification = noti; | 608 | mSuspendAlarmNotification = noti; |
609 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 609 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
610 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 610 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
611 | mSuspendTimer->start( ms , true ); | 611 | mSuspendTimer->start( ms , true ); |
612 | 612 | ||
613 | } | 613 | } |
614 | 614 | ||
615 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 615 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
616 | { | 616 | { |
617 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 617 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
618 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 618 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
619 | #ifndef DESKTOP_VERSION | 619 | #ifndef DESKTOP_VERSION |
620 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); | 620 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); |
621 | #endif | 621 | #endif |
622 | return; | 622 | return; |
623 | } | 623 | } |
624 | int maxSec; | 624 | int maxSec; |
625 | //maxSec = 5; //testing only | 625 | //maxSec = 5; //testing only |
626 | maxSec = 86400+3600; // one day+1hour | 626 | maxSec = 86400+3600; // one day+1hour |
627 | mAlarmNotification = noti; | 627 | mAlarmNotification = noti; |
628 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 628 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
629 | if ( sec > maxSec ) { | 629 | if ( sec > maxSec ) { |
630 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 630 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
631 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 631 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
632 | return; | 632 | return; |
633 | } else { | 633 | } else { |
634 | mRecheckAlarmTimer->stop(); | 634 | mRecheckAlarmTimer->stop(); |
635 | } | 635 | } |
636 | //qDebug("Alarm timer started with secs: %d ", sec); | 636 | //qDebug("Alarm timer started with secs: %d ", sec); |
637 | mAlarmTimer->start( sec *1000 , true ); | 637 | mAlarmTimer->start( sec *1000 , true ); |
638 | 638 | ||
639 | } | 639 | } |
640 | // called by mRecheckAlarmTimer to get next alarm | 640 | // called by mRecheckAlarmTimer to get next alarm |
641 | // we need this, because a QTimer has only a max range of 25 days | 641 | // we need this, because a QTimer has only a max range of 25 days |
642 | void CalendarView::recheckTimerAlarm() | 642 | void CalendarView::recheckTimerAlarm() |
643 | { | 643 | { |
644 | mAlarmTimer->stop(); | 644 | mAlarmTimer->stop(); |
645 | mRecheckAlarmTimer->stop(); | 645 | mRecheckAlarmTimer->stop(); |
646 | mCalendar->checkAlarmForIncidence( 0, true ); | 646 | mCalendar->checkAlarmForIncidence( 0, true ); |
647 | } | 647 | } |
648 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 648 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
649 | { | 649 | { |
650 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 650 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
651 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 651 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
652 | #ifndef DESKTOP_VERSION | 652 | #ifndef DESKTOP_VERSION |
653 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); | 653 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); |
654 | #endif | 654 | #endif |
655 | return; | 655 | return; |
656 | } | 656 | } |
657 | mAlarmTimer->stop(); | 657 | mAlarmTimer->stop(); |
658 | } | 658 | } |
659 | void CalendarView::selectWeekNum ( int num ) | 659 | void CalendarView::selectWeekNum ( int num ) |
660 | { | 660 | { |
661 | dateNavigator()->blockSignals( true ); | 661 | dateNavigator()->blockSignals( true ); |
662 | dateNavigator()->selectWeek( num ); | 662 | dateNavigator()->selectWeek( num ); |
663 | dateNavigator()->blockSignals( false ); | 663 | dateNavigator()->blockSignals( false ); |
664 | mViewManager->showWeekView(); | 664 | mViewManager->showWeekView(); |
665 | } | 665 | } |
666 | KOViewManager *CalendarView::viewManager() | 666 | KOViewManager *CalendarView::viewManager() |
667 | { | 667 | { |
668 | return mViewManager; | 668 | return mViewManager; |
669 | } | 669 | } |
670 | 670 | ||
671 | KODialogManager *CalendarView::dialogManager() | 671 | KODialogManager *CalendarView::dialogManager() |
672 | { | 672 | { |
673 | return mDialogManager; | 673 | return mDialogManager; |
674 | } | 674 | } |
675 | 675 | ||
676 | QDate CalendarView::startDate() | 676 | QDate CalendarView::startDate() |
677 | { | 677 | { |
678 | DateList dates = mNavigator->selectedDates(); | 678 | DateList dates = mNavigator->selectedDates(); |
679 | 679 | ||
680 | return dates.first(); | 680 | return dates.first(); |
681 | } | 681 | } |
682 | 682 | ||
683 | QDate CalendarView::endDate() | 683 | QDate CalendarView::endDate() |
684 | { | 684 | { |
685 | DateList dates = mNavigator->selectedDates(); | 685 | DateList dates = mNavigator->selectedDates(); |
686 | 686 | ||
687 | return dates.last(); | 687 | return dates.last(); |
688 | } | 688 | } |
689 | 689 | ||
690 | 690 | ||
691 | void CalendarView::createPrinter() | 691 | void CalendarView::createPrinter() |
692 | { | 692 | { |
693 | #ifndef KORG_NOPRINTER | 693 | #ifndef KORG_NOPRINTER |
694 | if (!mCalPrinter) { | 694 | if (!mCalPrinter) { |
695 | mCalPrinter = new CalPrinter(this, mCalendar); | 695 | mCalPrinter = new CalPrinter(this, mCalendar); |
696 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 696 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
697 | } | 697 | } |
698 | #endif | 698 | #endif |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | //KOPrefs::instance()->mWriteBackFile | 702 | //KOPrefs::instance()->mWriteBackFile |
703 | //KOPrefs::instance()->mWriteBackExistingOnly | 703 | //KOPrefs::instance()->mWriteBackExistingOnly |
704 | 704 | ||
705 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 705 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
706 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 706 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
707 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 707 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
708 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 708 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
709 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 709 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
710 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 710 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
711 | 711 | ||
712 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 712 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
713 | { | 713 | { |
714 | 714 | ||
715 | // 0 equal | 715 | // 0 equal |
716 | // 1 take local | 716 | // 1 take local |
717 | // 2 take remote | 717 | // 2 take remote |
718 | // 3 cancel | 718 | // 3 cancel |
719 | QDateTime lastSync = mLastCalendarSync; | 719 | QDateTime lastSync = mLastCalendarSync; |
720 | QDateTime localMod = local->lastModified(); | 720 | QDateTime localMod = local->lastModified(); |
721 | QDateTime remoteMod = remote->lastModified(); | 721 | QDateTime remoteMod = remote->lastModified(); |
722 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 722 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
723 | bool remCh, locCh; | 723 | bool remCh, locCh; |
724 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 724 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
725 | //if ( remCh ) | 725 | //if ( remCh ) |
726 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 726 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
727 | locCh = ( localMod > mLastCalendarSync ); | 727 | locCh = ( localMod > mLastCalendarSync ); |
728 | if ( !remCh && ! locCh ) { | 728 | if ( !remCh && ! locCh ) { |
729 | //qDebug("both not changed "); | 729 | //qDebug("both not changed "); |
730 | lastSync = localMod.addDays(1); | 730 | lastSync = localMod.addDays(1); |
731 | if ( mode <= SYNC_PREF_ASK ) | 731 | if ( mode <= SYNC_PREF_ASK ) |
732 | return 0; | 732 | return 0; |
733 | } else { | 733 | } else { |
734 | if ( locCh ) { | 734 | if ( locCh ) { |
735 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); | 735 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); |
736 | lastSync = localMod.addDays( -1 ); | 736 | lastSync = localMod.addDays( -1 ); |
737 | if ( !remCh ) | 737 | if ( !remCh ) |
738 | remoteMod = ( lastSync.addDays( -1 ) ); | 738 | remoteMod = ( lastSync.addDays( -1 ) ); |
739 | } else { | 739 | } else { |
740 | //qDebug(" not loc changed "); | 740 | //qDebug(" not loc changed "); |
741 | lastSync = localMod.addDays( 1 ); | 741 | lastSync = localMod.addDays( 1 ); |
742 | if ( remCh ) | 742 | if ( remCh ) |
743 | remoteMod =( lastSync.addDays( 1 ) ); | 743 | remoteMod =( lastSync.addDays( 1 ) ); |
744 | 744 | ||
745 | } | 745 | } |
746 | } | 746 | } |
747 | full = true; | 747 | full = true; |
748 | if ( mode < SYNC_PREF_ASK ) | 748 | if ( mode < SYNC_PREF_ASK ) |
749 | mode = SYNC_PREF_ASK; | 749 | mode = SYNC_PREF_ASK; |
750 | } else { | 750 | } else { |
751 | if ( localMod == remoteMod ) | 751 | if ( localMod == remoteMod ) |
752 | // if ( local->revision() == remote->revision() ) | 752 | // if ( local->revision() == remote->revision() ) |
753 | return 0; | 753 | return 0; |
754 | 754 | ||
755 | } | 755 | } |
756 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 756 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
757 | 757 | ||
758 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); | 758 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); |
759 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); | 759 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); |
760 | //full = true; //debug only | 760 | //full = true; //debug only |
761 | if ( full ) { | 761 | if ( full ) { |
762 | bool equ = false; | 762 | bool equ = false; |
763 | if ( local->type() == "Event" ) { | 763 | if ( local->type() == "Event" ) { |
764 | equ = (*((Event*) local) == *((Event*) remote)); | 764 | equ = (*((Event*) local) == *((Event*) remote)); |
765 | } | 765 | } |
766 | else if ( local->type() =="Todo" ) | 766 | else if ( local->type() =="Todo" ) |
767 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 767 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
768 | else if ( local->type() =="Journal" ) | 768 | else if ( local->type() =="Journal" ) |
769 | equ = (*((Journal*) local) == *((Journal*) remote)); | 769 | equ = (*((Journal*) local) == *((Journal*) remote)); |
770 | if ( equ ) { | 770 | if ( equ ) { |
771 | //qDebug("equal "); | 771 | //qDebug("equal "); |
772 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 772 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
773 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 773 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
774 | } | 774 | } |
775 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 775 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
776 | return 0; | 776 | return 0; |
777 | 777 | ||
778 | }//else //debug only | 778 | }//else //debug only |
779 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 779 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
780 | } | 780 | } |
781 | int result; | 781 | int result; |
782 | bool localIsNew; | 782 | bool localIsNew; |
783 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); | 783 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); |
784 | 784 | ||
785 | if ( full && mode < SYNC_PREF_NEWEST ) | 785 | if ( full && mode < SYNC_PREF_NEWEST ) |
786 | mode = SYNC_PREF_ASK; | 786 | mode = SYNC_PREF_ASK; |
787 | 787 | ||
788 | switch( mode ) { | 788 | switch( mode ) { |
789 | case SYNC_PREF_LOCAL: | 789 | case SYNC_PREF_LOCAL: |
790 | if ( lastSync > remoteMod ) | 790 | if ( lastSync > remoteMod ) |
791 | return 1; | 791 | return 1; |
792 | if ( lastSync > localMod ) | 792 | if ( lastSync > localMod ) |
793 | return 2; | 793 | return 2; |
794 | return 1; | 794 | return 1; |
795 | break; | 795 | break; |
796 | case SYNC_PREF_REMOTE: | 796 | case SYNC_PREF_REMOTE: |
797 | if ( lastSync > remoteMod ) | 797 | if ( lastSync > remoteMod ) |
798 | return 1; | 798 | return 1; |
799 | if ( lastSync > localMod ) | 799 | if ( lastSync > localMod ) |
800 | return 2; | 800 | return 2; |
801 | return 2; | 801 | return 2; |
802 | break; | 802 | break; |
803 | case SYNC_PREF_NEWEST: | 803 | case SYNC_PREF_NEWEST: |
804 | if ( localMod > remoteMod ) | 804 | if ( localMod > remoteMod ) |
805 | return 1; | 805 | return 1; |
806 | else | 806 | else |
807 | return 2; | 807 | return 2; |
808 | break; | 808 | break; |
809 | case SYNC_PREF_ASK: | 809 | case SYNC_PREF_ASK: |
810 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 810 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
811 | if ( lastSync > remoteMod ) | 811 | if ( lastSync > remoteMod ) |
812 | return 1; | 812 | return 1; |
813 | if ( lastSync > localMod ) | 813 | if ( lastSync > localMod ) |
814 | return 2; | 814 | return 2; |
815 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 815 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
816 | localIsNew = localMod >= remoteMod; | 816 | localIsNew = localMod >= remoteMod; |
817 | if ( localIsNew ) | 817 | if ( localIsNew ) |
818 | getEventViewerDialog()->setColorMode( 1 ); | 818 | getEventViewerDialog()->setColorMode( 1 ); |
819 | else | 819 | else |
820 | getEventViewerDialog()->setColorMode( 2 ); | 820 | getEventViewerDialog()->setColorMode( 2 ); |
821 | getEventViewerDialog()->setIncidence(local); | 821 | getEventViewerDialog()->setIncidence(local); |
822 | if ( localIsNew ) | 822 | if ( localIsNew ) |
823 | getEventViewerDialog()->setColorMode( 2 ); | 823 | getEventViewerDialog()->setColorMode( 2 ); |
824 | else | 824 | else |
825 | getEventViewerDialog()->setColorMode( 1 ); | 825 | getEventViewerDialog()->setColorMode( 1 ); |
826 | getEventViewerDialog()->addIncidence(remote); | 826 | getEventViewerDialog()->addIncidence(remote); |
827 | getEventViewerDialog()->setColorMode( 0 ); | 827 | getEventViewerDialog()->setColorMode( 0 ); |
828 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 828 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
829 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 829 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
830 | getEventViewerDialog()->showMe(); | 830 | getEventViewerDialog()->showMe(); |
831 | result = getEventViewerDialog()->executeS( localIsNew ); | 831 | result = getEventViewerDialog()->executeS( localIsNew ); |
832 | return result; | 832 | return result; |
833 | 833 | ||
834 | break; | 834 | break; |
835 | case SYNC_PREF_FORCE_LOCAL: | 835 | case SYNC_PREF_FORCE_LOCAL: |
836 | return 1; | 836 | return 1; |
837 | break; | 837 | break; |
838 | case SYNC_PREF_FORCE_REMOTE: | 838 | case SYNC_PREF_FORCE_REMOTE: |
839 | return 2; | 839 | return 2; |
840 | break; | 840 | break; |
841 | 841 | ||
842 | default: | 842 | default: |
843 | // SYNC_PREF_TAKE_BOTH not implemented | 843 | // SYNC_PREF_TAKE_BOTH not implemented |
844 | break; | 844 | break; |
845 | } | 845 | } |
846 | return 0; | 846 | return 0; |
847 | } | 847 | } |
848 | Event* CalendarView::getLastSyncEvent() | 848 | Event* CalendarView::getLastSyncEvent() |
849 | { | 849 | { |
850 | Event* lse; | 850 | Event* lse; |
851 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 851 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
852 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 852 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
853 | if (!lse) { | 853 | if (!lse) { |
854 | lse = new Event(); | 854 | lse = new Event(); |
855 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 855 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
856 | QString sum = ""; | 856 | QString sum = ""; |
857 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 857 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
858 | sum = "E: "; | 858 | sum = "E: "; |
859 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 859 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
860 | lse->setDtStart( mLastCalendarSync ); | 860 | lse->setDtStart( mLastCalendarSync ); |
861 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 861 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
862 | lse->setCategories( i18n("SyncEvent") ); | 862 | lse->setCategories( i18n("SyncEvent") ); |
863 | lse->setReadOnly( true ); | 863 | lse->setReadOnly( true ); |
864 | mCalendar->addEvent( lse ); | 864 | mCalendar->addEvent( lse ); |
865 | } | 865 | } |
866 | 866 | ||
867 | return lse; | 867 | return lse; |
868 | 868 | ||
869 | } | 869 | } |
870 | 870 | ||
871 | // we check, if the to delete event has a id for a profile | 871 | // we check, if the to delete event has a id for a profile |
872 | // if yes, we set this id in the profile to delete | 872 | // if yes, we set this id in the profile to delete |
873 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 873 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
874 | { | 874 | { |
875 | if ( lastSync.count() == 0 ) { | 875 | if ( lastSync.count() == 0 ) { |
876 | //qDebug(" lastSync.count() == 0"); | 876 | //qDebug(" lastSync.count() == 0"); |
877 | return; | 877 | return; |
878 | } | 878 | } |
879 | if ( toDelete->type() == "Journal" ) | 879 | if ( toDelete->type() == "Journal" ) |
880 | return; | 880 | return; |
881 | 881 | ||
882 | Event* eve = lastSync.first(); | 882 | Event* eve = lastSync.first(); |
883 | 883 | ||
884 | while ( eve ) { | 884 | while ( eve ) { |
885 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 885 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
886 | if ( !id.isEmpty() ) { | 886 | if ( !id.isEmpty() ) { |
887 | QString des = eve->description(); | 887 | QString des = eve->description(); |
888 | QString pref = "e"; | 888 | QString pref = "e"; |
889 | if ( toDelete->type() == "Todo" ) | 889 | if ( toDelete->type() == "Todo" ) |
890 | pref = "t"; | 890 | pref = "t"; |
891 | des += pref+ id + ","; | 891 | des += pref+ id + ","; |
892 | eve->setReadOnly( false ); | 892 | eve->setReadOnly( false ); |
893 | eve->setDescription( des ); | 893 | eve->setDescription( des ); |
894 | //qDebug("setdes %s ", des.latin1()); | 894 | //qDebug("setdes %s ", des.latin1()); |
895 | eve->setReadOnly( true ); | 895 | eve->setReadOnly( true ); |
896 | } | 896 | } |
897 | eve = lastSync.next(); | 897 | eve = lastSync.next(); |
898 | } | 898 | } |
899 | 899 | ||
900 | } | 900 | } |
901 | void CalendarView::checkExternalId( Incidence * inc ) | 901 | void CalendarView::checkExternalId( Incidence * inc ) |
902 | { | 902 | { |
903 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 903 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
904 | checkExternSyncEvent( lastSync, inc ); | 904 | checkExternSyncEvent( lastSync, inc ); |
905 | 905 | ||
906 | } | 906 | } |
907 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 907 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
908 | { | 908 | { |
909 | bool syncOK = true; | 909 | bool syncOK = true; |
910 | int addedEvent = 0; | 910 | int addedEvent = 0; |
911 | int addedEventR = 0; | 911 | int addedEventR = 0; |
912 | int deletedEventR = 0; | 912 | int deletedEventR = 0; |
913 | int deletedEventL = 0; | 913 | int deletedEventL = 0; |
914 | int changedLocal = 0; | 914 | int changedLocal = 0; |
915 | int changedRemote = 0; | 915 | int changedRemote = 0; |
916 | int filteredIN = 0; | 916 | int filteredIN = 0; |
917 | int filteredOUT = 0; | 917 | int filteredOUT = 0; |
918 | //QPtrList<Event> el = local->rawEvents(); | 918 | //QPtrList<Event> el = local->rawEvents(); |
919 | Event* eventR; | 919 | Event* eventR; |
920 | QString uid; | 920 | QString uid; |
921 | int take; | 921 | int take; |
922 | Event* eventL; | 922 | Event* eventL; |
923 | Event* eventRSync; | 923 | Event* eventRSync; |
924 | Event* eventLSync; | 924 | Event* eventLSync; |
925 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 925 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
926 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 926 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
927 | bool fullDateRange = false; | 927 | bool fullDateRange = false; |
928 | local->resetTempSyncStat(); | 928 | local->resetTempSyncStat(); |
929 | mLastCalendarSync = QDateTime::currentDateTime(); | 929 | mLastCalendarSync = QDateTime::currentDateTime(); |
930 | if ( mSyncManager->syncWithDesktop() ) { | 930 | if ( mSyncManager->syncWithDesktop() ) { |
931 | remote->resetPilotStat(1); | 931 | remote->resetPilotStat(1); |
932 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 932 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
933 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; | 933 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; |
934 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); | 934 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); |
935 | } else { | 935 | } else { |
936 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 936 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
937 | } | 937 | } |
938 | } | 938 | } |
939 | QDateTime modifiedCalendar = mLastCalendarSync; | 939 | QDateTime modifiedCalendar = mLastCalendarSync; |
940 | eventLSync = getLastSyncEvent(); | 940 | eventLSync = getLastSyncEvent(); |
941 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 941 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
942 | if ( eventR ) { | 942 | if ( eventR ) { |
943 | eventRSync = (Event*) eventR->clone(); | 943 | eventRSync = (Event*) eventR->clone(); |
944 | remote->deleteEvent(eventR ); | 944 | remote->deleteEvent(eventR ); |
945 | 945 | ||
946 | } else { | 946 | } else { |
947 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { | 947 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { |
948 | eventRSync = (Event*)eventLSync->clone(); | 948 | eventRSync = (Event*)eventLSync->clone(); |
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 | } | 958 | } |
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 ( mSyncManager->syncWithDesktop() ) { | 970 | if ( mSyncManager->syncWithDesktop() ) { |
971 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); | 971 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); |
972 | } | 972 | } |
973 | if ( fullDateRange ) | 973 | if ( fullDateRange ) |
974 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 974 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
975 | else | 975 | else |
976 | mLastCalendarSync = eventLSync->dtStart(); | 976 | mLastCalendarSync = eventLSync->dtStart(); |
977 | // for resyncing if own file has changed | 977 | // for resyncing if own file has changed |
978 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 978 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
979 | mLastCalendarSync = loadedFileVersion; | 979 | mLastCalendarSync = loadedFileVersion; |
980 | //qDebug("setting mLastCalendarSync "); | 980 | //qDebug("setting mLastCalendarSync "); |
981 | } | 981 | } |
982 | //qDebug("*************************** "); | 982 | //qDebug("*************************** "); |
983 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 983 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
984 | QPtrList<Incidence> er = remote->rawIncidences(); | 984 | QPtrList<Incidence> er = remote->rawIncidences(); |
985 | Incidence* inR = er.first(); | 985 | Incidence* inR = er.first(); |
986 | Incidence* inL; | 986 | Incidence* inL; |
987 | QProgressBar bar( er.count(),0 ); | 987 | QProgressBar bar( er.count(),0 ); |
988 | bar.setCaption (i18n("Syncing - close to abort!") ); | 988 | bar.setCaption (i18n("Syncing - close to abort!") ); |
989 | 989 | ||
990 | // ************** setting up filter ************* | 990 | // ************** setting up filter ************* |
991 | CalFilter *filterIN = 0; | 991 | CalFilter *filterIN = 0; |
992 | CalFilter *filterOUT = 0; | 992 | CalFilter *filterOUT = 0; |
993 | CalFilter *filter = mFilters.first(); | 993 | CalFilter *filter = mFilters.first(); |
994 | while(filter) { | 994 | while(filter) { |
995 | if ( filter->name() == mSyncManager->mFilterInCal ) | 995 | if ( filter->name() == mSyncManager->mFilterInCal ) |
996 | filterIN = filter; | 996 | filterIN = filter; |
997 | if ( filter->name() == mSyncManager->mFilterOutCal ) | 997 | if ( filter->name() == mSyncManager->mFilterOutCal ) |
998 | filterOUT = filter; | 998 | filterOUT = filter; |
999 | filter = mFilters.next(); | 999 | filter = mFilters.next(); |
1000 | } | 1000 | } |
1001 | int w = 300; | 1001 | int w = 300; |
1002 | if ( QApplication::desktop()->width() < 320 ) | 1002 | if ( QApplication::desktop()->width() < 320 ) |
1003 | w = 220; | 1003 | w = 220; |
1004 | int h = bar.sizeHint().height() ; | 1004 | int h = bar.sizeHint().height() ; |
1005 | int dw = QApplication::desktop()->width(); | 1005 | int dw = QApplication::desktop()->width(); |
1006 | int dh = QApplication::desktop()->height(); | 1006 | int dh = QApplication::desktop()->height(); |
1007 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1007 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1008 | bar.show(); | 1008 | bar.show(); |
1009 | int modulo = (er.count()/10)+1; | 1009 | int modulo = (er.count()/10)+1; |
1010 | int incCounter = 0; | 1010 | int incCounter = 0; |
1011 | while ( inR ) { | 1011 | while ( inR ) { |
1012 | if ( ! bar.isVisible() ) | 1012 | if ( ! bar.isVisible() ) |
1013 | return false; | 1013 | return false; |
1014 | if ( incCounter % modulo == 0 ) | 1014 | if ( incCounter % modulo == 0 ) |
1015 | bar.setProgress( incCounter ); | 1015 | bar.setProgress( incCounter ); |
1016 | ++incCounter; | 1016 | ++incCounter; |
1017 | uid = inR->uid(); | 1017 | uid = inR->uid(); |
1018 | bool skipIncidence = false; | 1018 | bool skipIncidence = false; |
1019 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1019 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1020 | skipIncidence = true; | 1020 | skipIncidence = true; |
1021 | QString idS; | 1021 | QString idS; |
1022 | qApp->processEvents(); | 1022 | qApp->processEvents(); |
1023 | if ( !skipIncidence ) { | 1023 | if ( !skipIncidence ) { |
1024 | inL = local->incidence( uid ); | 1024 | inL = local->incidence( uid ); |
1025 | if ( inL ) { // maybe conflict - same uid in both calendars | 1025 | if ( inL ) { // maybe conflict - same uid in both calendars |
1026 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1026 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1027 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1027 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1028 | if ( take == 3 ) | 1028 | if ( take == 3 ) |
1029 | return false; | 1029 | return false; |
1030 | if ( take == 1 ) {// take local ********************** | 1030 | if ( take == 1 ) {// take local ********************** |
1031 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1031 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1032 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1032 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1033 | else | 1033 | else |
1034 | idS = inR->IDStr(); | 1034 | idS = inR->IDStr(); |
1035 | remote->deleteIncidence( inR ); | 1035 | remote->deleteIncidence( inR ); |
1036 | inR = inL->clone(); | 1036 | inR = inL->clone(); |
1037 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1037 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1038 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1038 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1039 | inR->setIDStr( idS ); | 1039 | inR->setIDStr( idS ); |
1040 | remote->addIncidence( inR ); | 1040 | remote->addIncidence( inR ); |
1041 | if ( mSyncManager->syncWithDesktop() ) | 1041 | if ( mSyncManager->syncWithDesktop() ) |
1042 | inR->setPilotId( 2 ); | 1042 | inR->setPilotId( 2 ); |
1043 | ++changedRemote; | 1043 | ++changedRemote; |
1044 | } else {// take remote ********************** | 1044 | } else {// take remote ********************** |
1045 | idS = inL->IDStr(); | 1045 | idS = inL->IDStr(); |
1046 | int pid = inL->pilotId(); | 1046 | int pid = inL->pilotId(); |
1047 | local->deleteIncidence( inL ); | 1047 | local->deleteIncidence( inL ); |
1048 | inL = inR->clone(); | 1048 | inL = inR->clone(); |
1049 | if ( mSyncManager->syncWithDesktop() ) | 1049 | if ( mSyncManager->syncWithDesktop() ) |
1050 | inL->setPilotId( pid ); | 1050 | inL->setPilotId( pid ); |
1051 | inL->setIDStr( idS ); | 1051 | inL->setIDStr( idS ); |
1052 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1052 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1053 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1053 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1054 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1054 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1055 | } | 1055 | } |
1056 | local->addIncidence( inL ); | 1056 | local->addIncidence( inL ); |
1057 | ++changedLocal; | 1057 | ++changedLocal; |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | } else { // no conflict ********** add or delete remote | 1060 | } else { // no conflict ********** add or delete remote |
1061 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1061 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1062 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1062 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1063 | QString des = eventLSync->description(); | 1063 | QString des = eventLSync->description(); |
1064 | QString pref = "e"; | 1064 | QString pref = "e"; |
1065 | if ( inR->type() == "Todo" ) | 1065 | if ( inR->type() == "Todo" ) |
1066 | pref = "t"; | 1066 | pref = "t"; |
1067 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1067 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1068 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1068 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1069 | //remote->deleteIncidence( inR ); | 1069 | //remote->deleteIncidence( inR ); |
1070 | ++deletedEventR; | 1070 | ++deletedEventR; |
1071 | } else { | 1071 | } else { |
1072 | inR->setLastModified( modifiedCalendar ); | 1072 | inR->setLastModified( modifiedCalendar ); |
1073 | inL = inR->clone(); | 1073 | inL = inR->clone(); |
1074 | inL->setIDStr( ":" ); | 1074 | inL->setIDStr( ":" ); |
1075 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1075 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1076 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1076 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1077 | local->addIncidence( inL ); | 1077 | local->addIncidence( inL ); |
1078 | ++addedEvent; | 1078 | ++addedEvent; |
1079 | 1079 | ||
1080 | } | 1080 | } |
1081 | } else { | 1081 | } else { |
1082 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1082 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1083 | inR->setLastModified( modifiedCalendar ); | 1083 | inR->setLastModified( modifiedCalendar ); |
1084 | inL = inR->clone(); | 1084 | inL = inR->clone(); |
1085 | inL->setIDStr( ":" ); | 1085 | inL->setIDStr( ":" ); |
1086 | local->addIncidence( inL ); | 1086 | local->addIncidence( inL ); |
1087 | ++addedEvent; | 1087 | ++addedEvent; |
1088 | 1088 | ||
1089 | } else { | 1089 | } else { |
1090 | checkExternSyncEvent(eventRSyncSharp, inR); | 1090 | checkExternSyncEvent(eventRSyncSharp, inR); |
1091 | remote->deleteIncidence( inR ); | 1091 | remote->deleteIncidence( inR ); |
1092 | ++deletedEventR; | 1092 | ++deletedEventR; |
1093 | } | 1093 | } |
1094 | } | 1094 | } |
1095 | } else { | 1095 | } else { |
1096 | ++filteredIN; | 1096 | ++filteredIN; |
1097 | } | 1097 | } |
1098 | } | 1098 | } |
1099 | } | 1099 | } |
1100 | inR = er.next(); | 1100 | inR = er.next(); |
1101 | } | 1101 | } |
1102 | QPtrList<Incidence> el = local->rawIncidences(); | 1102 | QPtrList<Incidence> el = local->rawIncidences(); |
1103 | inL = el.first(); | 1103 | inL = el.first(); |
1104 | modulo = (el.count()/10)+1; | 1104 | modulo = (el.count()/10)+1; |
1105 | bar.setCaption (i18n("Add / remove events") ); | 1105 | bar.setCaption (i18n("Add / remove events") ); |
1106 | bar.setTotalSteps ( el.count() ) ; | 1106 | bar.setTotalSteps ( el.count() ) ; |
1107 | bar.show(); | 1107 | bar.show(); |
1108 | incCounter = 0; | 1108 | incCounter = 0; |
1109 | 1109 | ||
1110 | while ( inL ) { | 1110 | while ( inL ) { |
1111 | 1111 | ||
1112 | qApp->processEvents(); | 1112 | qApp->processEvents(); |
1113 | if ( ! bar.isVisible() ) | 1113 | if ( ! bar.isVisible() ) |
1114 | return false; | 1114 | return false; |
1115 | if ( incCounter % modulo == 0 ) | 1115 | if ( incCounter % modulo == 0 ) |
1116 | bar.setProgress( incCounter ); | 1116 | bar.setProgress( incCounter ); |
1117 | ++incCounter; | 1117 | ++incCounter; |
1118 | uid = inL->uid(); | 1118 | uid = inL->uid(); |
1119 | bool skipIncidence = false; | 1119 | bool skipIncidence = false; |
1120 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1120 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1121 | skipIncidence = true; | 1121 | skipIncidence = true; |
1122 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1122 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1123 | skipIncidence = true; | 1123 | skipIncidence = true; |
1124 | if ( !skipIncidence ) { | 1124 | if ( !skipIncidence ) { |
1125 | inR = remote->incidence( uid ); | 1125 | inR = remote->incidence( uid ); |
1126 | if ( ! inR ) { | 1126 | if ( ! inR ) { |
1127 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ | 1127 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ |
1128 | // no conflict ********** add or delete local | 1128 | // no conflict ********** add or delete local |
1129 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1129 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1130 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1130 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1131 | checkExternSyncEvent(eventLSyncSharp, inL); | 1131 | checkExternSyncEvent(eventLSyncSharp, inL); |
1132 | local->deleteIncidence( inL ); | 1132 | local->deleteIncidence( inL ); |
1133 | ++deletedEventL; | 1133 | ++deletedEventL; |
1134 | } else { | 1134 | } else { |
1135 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1135 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1136 | inL->removeID(mCurrentSyncDevice ); | 1136 | inL->removeID(mCurrentSyncDevice ); |
1137 | ++addedEventR; | 1137 | ++addedEventR; |
1138 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1138 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1139 | inL->setLastModified( modifiedCalendar ); | 1139 | inL->setLastModified( modifiedCalendar ); |
1140 | inR = inL->clone(); | 1140 | inR = inL->clone(); |
1141 | inR->setIDStr( ":" ); | 1141 | inR->setIDStr( ":" ); |
1142 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1142 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1143 | remote->addIncidence( inR ); | 1143 | remote->addIncidence( inR ); |
1144 | } | 1144 | } |
1145 | } | 1145 | } |
1146 | } else { | 1146 | } else { |
1147 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1147 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1148 | checkExternSyncEvent(eventLSyncSharp, inL); | 1148 | checkExternSyncEvent(eventLSyncSharp, inL); |
1149 | local->deleteIncidence( inL ); | 1149 | local->deleteIncidence( inL ); |
1150 | ++deletedEventL; | 1150 | ++deletedEventL; |
1151 | } else { | 1151 | } else { |
1152 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1152 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1153 | ++addedEventR; | 1153 | ++addedEventR; |
1154 | inL->setLastModified( modifiedCalendar ); | 1154 | inL->setLastModified( modifiedCalendar ); |
1155 | inR = inL->clone(); | 1155 | inR = inL->clone(); |
1156 | inR->setIDStr( ":" ); | 1156 | inR->setIDStr( ":" ); |
1157 | remote->addIncidence( inR ); | 1157 | remote->addIncidence( inR ); |
1158 | } | 1158 | } |
1159 | } | 1159 | } |
1160 | } | 1160 | } |
1161 | } else { | 1161 | } else { |
1162 | ++filteredOUT; | 1162 | ++filteredOUT; |
1163 | } | 1163 | } |
1164 | } | 1164 | } |
1165 | } | 1165 | } |
1166 | inL = el.next(); | 1166 | inL = el.next(); |
1167 | } | 1167 | } |
1168 | int delFut = 0; | 1168 | int delFut = 0; |
1169 | int remRem = 0; | 1169 | int remRem = 0; |
1170 | if ( mSyncManager->mWriteBackInFuture ) { | 1170 | if ( mSyncManager->mWriteBackInFuture ) { |
1171 | er = remote->rawIncidences(); | 1171 | er = remote->rawIncidences(); |
1172 | remRem = er.count(); | 1172 | remRem = er.count(); |
1173 | inR = er.first(); | 1173 | inR = er.first(); |
1174 | QDateTime dt; | 1174 | QDateTime dt; |
1175 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); | 1175 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); |
1176 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); | 1176 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); |
1177 | while ( inR ) { | 1177 | while ( inR ) { |
1178 | if ( inR->type() == "Todo" ) { | 1178 | if ( inR->type() == "Todo" ) { |
1179 | Todo * t = (Todo*)inR; | 1179 | Todo * t = (Todo*)inR; |
1180 | if ( t->hasDueDate() ) | 1180 | if ( t->hasDueDate() ) |
1181 | dt = t->dtDue(); | 1181 | dt = t->dtDue(); |
1182 | else | 1182 | else |
1183 | dt = cur.addSecs( 62 ); | 1183 | dt = cur.addSecs( 62 ); |
1184 | } | 1184 | } |
1185 | else if (inR->type() == "Event" ) { | 1185 | else if (inR->type() == "Event" ) { |
1186 | bool ok; | 1186 | bool ok; |
1187 | dt = inR->getNextOccurence( cur, &ok ); | 1187 | dt = inR->getNextOccurence( cur, &ok ); |
1188 | if ( !ok ) | 1188 | if ( !ok ) |
1189 | dt = cur.addSecs( -62 ); | 1189 | dt = cur.addSecs( -62 ); |
1190 | } | 1190 | } |
1191 | else | 1191 | else |
1192 | dt = inR->dtStart(); | 1192 | dt = inR->dtStart(); |
1193 | if ( dt < cur || dt > end ) { | 1193 | if ( dt < cur || dt > end ) { |
1194 | remote->deleteIncidence( inR ); | 1194 | remote->deleteIncidence( inR ); |
1195 | ++delFut; | 1195 | ++delFut; |
1196 | } | 1196 | } |
1197 | inR = er.next(); | 1197 | inR = er.next(); |
1198 | } | 1198 | } |
1199 | } | 1199 | } |
1200 | bar.hide(); | 1200 | bar.hide(); |
1201 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1201 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1202 | eventLSync->setReadOnly( false ); | 1202 | eventLSync->setReadOnly( false ); |
1203 | eventLSync->setDtStart( mLastCalendarSync ); | 1203 | eventLSync->setDtStart( mLastCalendarSync ); |
1204 | eventRSync->setDtStart( mLastCalendarSync ); | 1204 | eventRSync->setDtStart( mLastCalendarSync ); |
1205 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1205 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1206 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1206 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1207 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1207 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1208 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1208 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1209 | eventLSync->setReadOnly( true ); | 1209 | eventLSync->setReadOnly( true ); |
1210 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); | 1210 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); |
1211 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... | 1211 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... |
1212 | remote->addEvent( eventRSync ); | 1212 | remote->addEvent( eventRSync ); |
1213 | else | 1213 | else |
1214 | delete eventRSync; | 1214 | delete eventRSync; |
1215 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); | 1215 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); |
1216 | QString mes; | 1216 | QString mes; |
1217 | 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); | 1217 | 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); |
1218 | QString delmess; | 1218 | QString delmess; |
1219 | if ( delFut ) { | 1219 | if ( delFut ) { |
1220 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); | 1220 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); |
1221 | mes += delmess; | 1221 | mes += delmess; |
1222 | } | 1222 | } |
1223 | mes = i18n("Local calendar changed!\n") +mes; | 1223 | mes = i18n("Local calendar changed!\n") +mes; |
1224 | mCalendar->checkAlarmForIncidence( 0, true ); | 1224 | mCalendar->checkAlarmForIncidence( 0, true ); |
1225 | qDebug( mes ); | 1225 | qDebug( mes ); |
1226 | if ( mSyncManager->mShowSyncSummary ) { | 1226 | if ( mSyncManager->mShowSyncSummary ) { |
1227 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 1227 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
1228 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { | 1228 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { |
1229 | qDebug("KO: WB cancelled "); | 1229 | qDebug("KO: WB cancelled "); |
1230 | return false; | 1230 | mSyncManager->mWriteBackFile = false; |
1231 | return syncOK; | ||
1231 | } | 1232 | } |
1232 | } | 1233 | } |
1233 | return syncOK; | 1234 | return syncOK; |
1234 | } | 1235 | } |
1235 | 1236 | ||
1236 | void CalendarView::setSyncDevice( QString s ) | 1237 | void CalendarView::setSyncDevice( QString s ) |
1237 | { | 1238 | { |
1238 | mCurrentSyncDevice= s; | 1239 | mCurrentSyncDevice= s; |
1239 | } | 1240 | } |
1240 | void CalendarView::setSyncName( QString s ) | 1241 | void CalendarView::setSyncName( QString s ) |
1241 | { | 1242 | { |
1242 | mCurrentSyncName= s; | 1243 | mCurrentSyncName= s; |
1243 | } | 1244 | } |
1244 | bool CalendarView::syncCalendar(QString filename, int mode) | 1245 | bool CalendarView::syncCalendar(QString filename, int mode) |
1245 | { | 1246 | { |
1246 | //qDebug("syncCalendar %s ", filename.latin1()); | 1247 | //qDebug("syncCalendar %s ", filename.latin1()); |
1247 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1248 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1248 | CalendarLocal* calendar = new CalendarLocal(); | 1249 | CalendarLocal* calendar = new CalendarLocal(); |
1249 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1250 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1250 | FileStorage* storage = new FileStorage( calendar ); | 1251 | FileStorage* storage = new FileStorage( calendar ); |
1251 | bool syncOK = false; | 1252 | bool syncOK = false; |
1252 | storage->setFileName( filename ); | 1253 | storage->setFileName( filename ); |
1253 | // qDebug("loading ... "); | 1254 | // qDebug("loading ... "); |
1254 | if ( storage->load() ) { | 1255 | if ( storage->load() ) { |
1255 | getEventViewerDialog()->setSyncMode( true ); | 1256 | getEventViewerDialog()->setSyncMode( true ); |
1256 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1257 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1257 | getEventViewerDialog()->setSyncMode( false ); | 1258 | getEventViewerDialog()->setSyncMode( false ); |
1258 | if ( syncOK ) { | 1259 | if ( syncOK ) { |
1259 | if ( mSyncManager->mWriteBackFile ) | 1260 | if ( mSyncManager->mWriteBackFile ) |
1260 | { | 1261 | { |
1261 | storage->setSaveFormat( new ICalFormat() ); | 1262 | storage->setSaveFormat( new ICalFormat() ); |
1262 | storage->save(); | 1263 | storage->save(); |
1263 | } | 1264 | } |
1264 | } | 1265 | } |
1265 | setModified( true ); | 1266 | setModified( true ); |
1266 | } | 1267 | } |
1267 | delete storage; | 1268 | delete storage; |
1268 | delete calendar; | 1269 | delete calendar; |
1269 | if ( syncOK ) | 1270 | if ( syncOK ) |
1270 | updateView(); | 1271 | updateView(); |
1271 | return syncOK; | 1272 | return syncOK; |
1272 | } | 1273 | } |
1273 | 1274 | ||
1274 | void CalendarView::syncExternal( int mode ) | 1275 | void CalendarView::syncExternal( int mode ) |
1275 | { | 1276 | { |
1276 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1277 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1277 | 1278 | ||
1278 | qApp->processEvents(); | 1279 | qApp->processEvents(); |
1279 | CalendarLocal* calendar = new CalendarLocal(); | 1280 | CalendarLocal* calendar = new CalendarLocal(); |
1280 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1281 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1281 | bool syncOK = false; | 1282 | bool syncOK = false; |
1282 | bool loadSuccess = false; | 1283 | bool loadSuccess = false; |
1283 | PhoneFormat* phoneFormat = 0; | 1284 | PhoneFormat* phoneFormat = 0; |
1284 | emit tempDisableBR(true); | 1285 | emit tempDisableBR(true); |
1285 | #ifndef DESKTOP_VERSION | 1286 | #ifndef DESKTOP_VERSION |
1286 | SharpFormat* sharpFormat = 0; | 1287 | SharpFormat* sharpFormat = 0; |
1287 | if ( mode == 0 ) { // sharp | 1288 | if ( mode == 0 ) { // sharp |
1288 | sharpFormat = new SharpFormat () ; | 1289 | sharpFormat = new SharpFormat () ; |
1289 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1290 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1290 | 1291 | ||
1291 | } else | 1292 | } else |
1292 | #endif | 1293 | #endif |
1293 | if ( mode == 1 ) { // phone | 1294 | if ( mode == 1 ) { // phone |
1294 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1295 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1295 | mSyncManager->mPhoneDevice, | 1296 | mSyncManager->mPhoneDevice, |
1296 | mSyncManager->mPhoneConnection, | 1297 | mSyncManager->mPhoneConnection, |
1297 | mSyncManager->mPhoneModel); | 1298 | mSyncManager->mPhoneModel); |
1298 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1299 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1299 | 1300 | ||
1300 | } else { | 1301 | } else { |
1301 | emit tempDisableBR(false); | 1302 | emit tempDisableBR(false); |
1302 | return; | 1303 | return; |
1303 | } | 1304 | } |
1304 | if ( loadSuccess ) { | 1305 | if ( loadSuccess ) { |
1305 | getEventViewerDialog()->setSyncMode( true ); | 1306 | getEventViewerDialog()->setSyncMode( true ); |
1306 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1307 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1307 | getEventViewerDialog()->setSyncMode( false ); | 1308 | getEventViewerDialog()->setSyncMode( false ); |
1308 | qApp->processEvents(); | 1309 | qApp->processEvents(); |
1309 | if ( syncOK ) { | 1310 | if ( syncOK ) { |
1310 | if ( mSyncManager->mWriteBackFile ) | 1311 | if ( mSyncManager->mWriteBackFile ) |
1311 | { | 1312 | { |
1312 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1313 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1313 | Incidence* inc = iL.first(); | 1314 | Incidence* inc = iL.first(); |
1314 | if ( phoneFormat ) { | 1315 | if ( phoneFormat ) { |
1315 | while ( inc ) { | 1316 | while ( inc ) { |
1316 | inc->removeID(mCurrentSyncDevice); | 1317 | inc->removeID(mCurrentSyncDevice); |
1317 | inc = iL.next(); | 1318 | inc = iL.next(); |
1318 | } | 1319 | } |
1319 | } | 1320 | } |
1320 | #ifndef DESKTOP_VERSION | 1321 | #ifndef DESKTOP_VERSION |
1321 | if ( sharpFormat ) | 1322 | if ( sharpFormat ) |
1322 | sharpFormat->save(calendar); | 1323 | sharpFormat->save(calendar); |
1323 | #endif | 1324 | #endif |
1324 | if ( phoneFormat ) | 1325 | if ( phoneFormat ) |
1325 | phoneFormat->save(calendar); | 1326 | phoneFormat->save(calendar); |
1326 | iL = calendar->rawIncidences(); | 1327 | iL = calendar->rawIncidences(); |
1327 | inc = iL.first(); | 1328 | inc = iL.first(); |
1328 | Incidence* loc; | 1329 | Incidence* loc; |
1329 | while ( inc ) { | 1330 | while ( inc ) { |
1330 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1331 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1331 | loc = mCalendar->incidence(inc->uid() ); | 1332 | loc = mCalendar->incidence(inc->uid() ); |
1332 | if ( loc ) { | 1333 | if ( loc ) { |
1333 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1334 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1334 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1335 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1335 | } | 1336 | } |
1336 | } | 1337 | } |
1337 | inc = iL.next(); | 1338 | inc = iL.next(); |
1338 | } | 1339 | } |
1339 | Incidence* lse = getLastSyncEvent(); | 1340 | Incidence* lse = getLastSyncEvent(); |
1340 | if ( lse ) { | 1341 | if ( lse ) { |
1341 | lse->setReadOnly( false ); | 1342 | lse->setReadOnly( false ); |
1342 | lse->setDescription( "" ); | 1343 | lse->setDescription( "" ); |
1343 | lse->setReadOnly( true ); | 1344 | lse->setReadOnly( true ); |
1344 | } | 1345 | } |
1345 | } | 1346 | } |
1346 | } else { | 1347 | } else { |
1347 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 1348 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
1348 | } | 1349 | } |
1349 | setModified( true ); | 1350 | setModified( true ); |
1350 | } else { | 1351 | } else { |
1351 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1352 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1352 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1353 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1353 | question, i18n("Ok")) ; | 1354 | question, i18n("Ok")) ; |
1354 | 1355 | ||
1355 | } | 1356 | } |
1356 | delete calendar; | 1357 | delete calendar; |
1357 | updateView(); | 1358 | updateView(); |
1358 | emit tempDisableBR(false); | 1359 | emit tempDisableBR(false); |
1359 | return ;//syncOK; | 1360 | return ;//syncOK; |
1360 | 1361 | ||
1361 | } | 1362 | } |
1362 | 1363 | ||
1363 | bool CalendarView::importBday() | 1364 | bool CalendarView::importBday() |
1364 | { | 1365 | { |
1365 | #ifndef KORG_NOKABC | 1366 | #ifndef KORG_NOKABC |
1366 | 1367 | ||
1367 | #ifdef DESKTOP_VERSION | 1368 | #ifdef DESKTOP_VERSION |
1368 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1369 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1369 | KABC::AddressBook::Iterator it; | 1370 | KABC::AddressBook::Iterator it; |
1370 | int count = 0; | 1371 | int count = 0; |
1371 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1372 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1372 | ++count; | 1373 | ++count; |
1373 | } | 1374 | } |
1374 | QProgressBar bar(count,0 ); | 1375 | QProgressBar bar(count,0 ); |
1375 | int w = 300; | 1376 | int w = 300; |
1376 | if ( QApplication::desktop()->width() < 320 ) | 1377 | if ( QApplication::desktop()->width() < 320 ) |
1377 | w = 220; | 1378 | w = 220; |
1378 | int h = bar.sizeHint().height() ; | 1379 | int h = bar.sizeHint().height() ; |
1379 | int dw = QApplication::desktop()->width(); | 1380 | int dw = QApplication::desktop()->width(); |
1380 | int dh = QApplication::desktop()->height(); | 1381 | int dh = QApplication::desktop()->height(); |
1381 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1382 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1382 | bar.show(); | 1383 | bar.show(); |
1383 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1384 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1384 | qApp->processEvents(); | 1385 | qApp->processEvents(); |
1385 | count = 0; | 1386 | count = 0; |
1386 | int addCount = 0; | 1387 | int addCount = 0; |
1387 | KCal::Attendee* a = 0; | 1388 | KCal::Attendee* a = 0; |
1388 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1389 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1389 | if ( ! bar.isVisible() ) | 1390 | if ( ! bar.isVisible() ) |
1390 | return false; | 1391 | return false; |
1391 | bar.setProgress( count++ ); | 1392 | bar.setProgress( count++ ); |
1392 | qApp->processEvents(); | 1393 | qApp->processEvents(); |
1393 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1394 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1394 | if ( (*it).birthday().date().isValid() ){ | 1395 | if ( (*it).birthday().date().isValid() ){ |
1395 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1396 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1396 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1397 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1397 | ++addCount; | 1398 | ++addCount; |
1398 | } | 1399 | } |
1399 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1400 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1400 | if ( anni.isValid() ){ | 1401 | if ( anni.isValid() ){ |
1401 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1402 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1402 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1403 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1403 | ++addCount; | 1404 | ++addCount; |
1404 | } | 1405 | } |
1405 | } | 1406 | } |
1406 | updateView(); | 1407 | updateView(); |
1407 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1408 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1408 | #else //DESKTOP_VERSION | 1409 | #else //DESKTOP_VERSION |
1409 | 1410 | ||
1410 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); | 1411 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); |
1411 | // the result should now arrive through method insertBirthdays | 1412 | // the result should now arrive through method insertBirthdays |
1412 | 1413 | ||
1413 | #endif //DESKTOP_VERSION | 1414 | #endif //DESKTOP_VERSION |
1414 | 1415 | ||
1415 | #endif //KORG_NOKABC | 1416 | #endif //KORG_NOKABC |
1416 | 1417 | ||
1417 | 1418 | ||
1418 | return true; | 1419 | return true; |
1419 | } | 1420 | } |
1420 | 1421 | ||
1421 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI | 1422 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI |
1422 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, | 1423 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, |
1423 | const QStringList& anniversaryList, const QStringList& realNameList, | 1424 | const QStringList& anniversaryList, const QStringList& realNameList, |
1424 | const QStringList& emailList, const QStringList& assembledNameList, | 1425 | const QStringList& emailList, const QStringList& assembledNameList, |
1425 | const QStringList& uidList) | 1426 | const QStringList& uidList) |
1426 | { | 1427 | { |
1427 | //qDebug("KO::CalendarView::insertBirthdays"); | 1428 | //qDebug("KO::CalendarView::insertBirthdays"); |
1428 | if (uid == this->name()) | 1429 | if (uid == this->name()) |
1429 | { | 1430 | { |
1430 | int count = birthdayList.count(); | 1431 | int count = birthdayList.count(); |
1431 | int addCount = 0; | 1432 | int addCount = 0; |
1432 | KCal::Attendee* a = 0; | 1433 | KCal::Attendee* a = 0; |
1433 | 1434 | ||
1434 | //qDebug("CalView 1 %i", count); | 1435 | //qDebug("CalView 1 %i", count); |
1435 | 1436 | ||
1436 | QProgressBar bar(count,0 ); | 1437 | QProgressBar bar(count,0 ); |
1437 | int w = 300; | 1438 | int w = 300; |
1438 | if ( QApplication::desktop()->width() < 320 ) | 1439 | if ( QApplication::desktop()->width() < 320 ) |
1439 | w = 220; | 1440 | w = 220; |
1440 | int h = bar.sizeHint().height() ; | 1441 | int h = bar.sizeHint().height() ; |
1441 | int dw = QApplication::desktop()->width(); | 1442 | int dw = QApplication::desktop()->width(); |
1442 | int dh = QApplication::desktop()->height(); | 1443 | int dh = QApplication::desktop()->height(); |
1443 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1444 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1444 | bar.show(); | 1445 | bar.show(); |
1445 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); | 1446 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); |
1446 | qApp->processEvents(); | 1447 | qApp->processEvents(); |
1447 | 1448 | ||
1448 | QDate birthday; | 1449 | QDate birthday; |
1449 | QDate anniversary; | 1450 | QDate anniversary; |
1450 | QString realName; | 1451 | QString realName; |
1451 | QString email; | 1452 | QString email; |
1452 | QString assembledName; | 1453 | QString assembledName; |
1453 | QString uid; | 1454 | QString uid; |
1454 | bool ok = true; | 1455 | bool ok = true; |
1455 | for ( int i = 0; i < count; i++) | 1456 | for ( int i = 0; i < count; i++) |
1456 | { | 1457 | { |
1457 | if ( ! bar.isVisible() ) | 1458 | if ( ! bar.isVisible() ) |
1458 | return; | 1459 | return; |
1459 | bar.setProgress( i ); | 1460 | bar.setProgress( i ); |
1460 | qApp->processEvents(); | 1461 | qApp->processEvents(); |
1461 | 1462 | ||
1462 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); | 1463 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); |
1463 | if (!ok) { | 1464 | if (!ok) { |
1464 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); | 1465 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); |
1465 | } | 1466 | } |
1466 | 1467 | ||
1467 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); | 1468 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); |
1468 | if (!ok) { | 1469 | if (!ok) { |
1469 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); | 1470 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); |
1470 | } | 1471 | } |
1471 | realName = realNameList[i]; | 1472 | realName = realNameList[i]; |
1472 | email = emailList[i]; | 1473 | email = emailList[i]; |
1473 | assembledName = assembledNameList[i]; | 1474 | assembledName = assembledNameList[i]; |
1474 | uid = uidList[i]; | 1475 | uid = uidList[i]; |
1475 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); | 1476 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); |
1476 | 1477 | ||
1477 | if ( birthday.isValid() ){ | 1478 | if ( birthday.isValid() ){ |
1478 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1479 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1479 | KCal::Attendee::ReqParticipant,uid) ; | 1480 | KCal::Attendee::ReqParticipant,uid) ; |
1480 | if ( addAnniversary( birthday, assembledName, a, true ) ) | 1481 | if ( addAnniversary( birthday, assembledName, a, true ) ) |
1481 | ++addCount; | 1482 | ++addCount; |
1482 | } | 1483 | } |
1483 | 1484 | ||
1484 | if ( anniversary.isValid() ){ | 1485 | if ( anniversary.isValid() ){ |
1485 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1486 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1486 | KCal::Attendee::ReqParticipant,uid) ; | 1487 | KCal::Attendee::ReqParticipant,uid) ; |
1487 | if ( addAnniversary( anniversary, assembledName, a, false ) ) | 1488 | if ( addAnniversary( anniversary, assembledName, a, false ) ) |
1488 | ++addCount; | 1489 | ++addCount; |
1489 | } | 1490 | } |
1490 | } | 1491 | } |
1491 | 1492 | ||
1492 | updateView(); | 1493 | updateView(); |
1493 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1494 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1494 | 1495 | ||
1495 | } | 1496 | } |
1496 | 1497 | ||
1497 | } | 1498 | } |
1498 | 1499 | ||
1499 | 1500 | ||
1500 | 1501 | ||
1501 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1502 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1502 | { | 1503 | { |
1503 | //qDebug("addAnni "); | 1504 | //qDebug("addAnni "); |
1504 | Event * ev = new Event(); | 1505 | Event * ev = new Event(); |
1505 | ev->setOrganizer(KOPrefs::instance()->email()); | 1506 | ev->setOrganizer(KOPrefs::instance()->email()); |
1506 | if ( a ) { | 1507 | if ( a ) { |
1507 | ev->addAttendee( a ); | 1508 | ev->addAttendee( a ); |
1508 | } | 1509 | } |
1509 | QString kind; | 1510 | QString kind; |
1510 | if ( birthday ) { | 1511 | if ( birthday ) { |
1511 | kind = i18n( "Birthday" ); | 1512 | kind = i18n( "Birthday" ); |
1512 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); | 1513 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); |
1513 | } | 1514 | } |
1514 | else { | 1515 | else { |
1515 | kind = i18n( "Anniversary" ); | 1516 | kind = i18n( "Anniversary" ); |
1516 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); | 1517 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); |
1517 | } | 1518 | } |
1518 | ev->setCategories( kind ); | 1519 | ev->setCategories( kind ); |
1519 | ev->setDtStart( QDateTime(date) ); | 1520 | ev->setDtStart( QDateTime(date) ); |
1520 | ev->setDtEnd( QDateTime(date) ); | 1521 | ev->setDtEnd( QDateTime(date) ); |
1521 | ev->setFloats( true ); | 1522 | ev->setFloats( true ); |
1522 | Recurrence * rec = ev->recurrence(); | 1523 | Recurrence * rec = ev->recurrence(); |
1523 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1524 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1524 | rec->addYearlyNum( date.month() ); | 1525 | rec->addYearlyNum( date.month() ); |
1525 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1526 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1526 | delete ev; | 1527 | delete ev; |
1527 | return false; | 1528 | return false; |
1528 | } | 1529 | } |
1529 | return true; | 1530 | return true; |
1530 | 1531 | ||
1531 | } | 1532 | } |
1532 | bool CalendarView::importQtopia( const QString &categories, | 1533 | bool CalendarView::importQtopia( const QString &categories, |
1533 | const QString &datebook, | 1534 | const QString &datebook, |
1534 | const QString &todolist ) | 1535 | const QString &todolist ) |
1535 | { | 1536 | { |
1536 | 1537 | ||
1537 | QtopiaFormat qtopiaFormat; | 1538 | QtopiaFormat qtopiaFormat; |
1538 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1539 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1539 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1540 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1540 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1541 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1541 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1542 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1542 | 1543 | ||
1543 | updateView(); | 1544 | updateView(); |
1544 | return true; | 1545 | return true; |
1545 | 1546 | ||
1546 | #if 0 | 1547 | #if 0 |
1547 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1548 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1548 | mCurrentSyncDevice = "qtopia-XML"; | 1549 | mCurrentSyncDevice = "qtopia-XML"; |
1549 | if ( mSyncManager->mAskForPreferences ) | 1550 | if ( mSyncManager->mAskForPreferences ) |
1550 | edit_sync_options(); | 1551 | edit_sync_options(); |
1551 | qApp->processEvents(); | 1552 | qApp->processEvents(); |
1552 | CalendarLocal* calendar = new CalendarLocal(); | 1553 | CalendarLocal* calendar = new CalendarLocal(); |
1553 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1554 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1554 | bool syncOK = false; | 1555 | bool syncOK = false; |
1555 | QtopiaFormat qtopiaFormat; | 1556 | QtopiaFormat qtopiaFormat; |
1556 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1557 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1557 | bool loadOk = true; | 1558 | bool loadOk = true; |
1558 | if ( !categories.isEmpty() ) | 1559 | if ( !categories.isEmpty() ) |
1559 | loadOk = qtopiaFormat.load( calendar, categories ); | 1560 | loadOk = qtopiaFormat.load( calendar, categories ); |
1560 | if ( loadOk && !datebook.isEmpty() ) | 1561 | if ( loadOk && !datebook.isEmpty() ) |
1561 | loadOk = qtopiaFormat.load( calendar, datebook ); | 1562 | loadOk = qtopiaFormat.load( calendar, datebook ); |
1562 | if ( loadOk && !todolist.isEmpty() ) | 1563 | if ( loadOk && !todolist.isEmpty() ) |
1563 | loadOk = qtopiaFormat.load( calendar, todolist ); | 1564 | loadOk = qtopiaFormat.load( calendar, todolist ); |
1564 | 1565 | ||
1565 | if ( loadOk ) { | 1566 | if ( loadOk ) { |
1566 | getEventViewerDialog()->setSyncMode( true ); | 1567 | getEventViewerDialog()->setSyncMode( true ); |
1567 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1568 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1568 | getEventViewerDialog()->setSyncMode( false ); | 1569 | getEventViewerDialog()->setSyncMode( false ); |
1569 | qApp->processEvents(); | 1570 | qApp->processEvents(); |
1570 | if ( syncOK ) { | 1571 | if ( syncOK ) { |
1571 | if ( mSyncManager->mWriteBackFile ) | 1572 | if ( mSyncManager->mWriteBackFile ) |
1572 | { | 1573 | { |
1573 | // write back XML file | 1574 | // write back XML file |
1574 | 1575 | ||
1575 | } | 1576 | } |
1576 | setModified( true ); | 1577 | setModified( true ); |
1577 | } | 1578 | } |
1578 | } else { | 1579 | } else { |
1579 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1580 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1580 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1581 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1581 | question, i18n("Ok")) ; | 1582 | question, i18n("Ok")) ; |
1582 | } | 1583 | } |
1583 | delete calendar; | 1584 | delete calendar; |
1584 | updateView(); | 1585 | updateView(); |
1585 | return syncOK; | 1586 | return syncOK; |
1586 | 1587 | ||
1587 | 1588 | ||
1588 | #endif | 1589 | #endif |
1589 | 1590 | ||
1590 | } | 1591 | } |
1591 | 1592 | ||
1592 | void CalendarView::setSyncEventsReadOnly() | 1593 | void CalendarView::setSyncEventsReadOnly() |
1593 | { | 1594 | { |
1594 | Event * ev; | 1595 | Event * ev; |
1595 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1596 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1596 | ev = eL.first(); | 1597 | ev = eL.first(); |
1597 | while ( ev ) { | 1598 | while ( ev ) { |
1598 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1599 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1599 | ev->setReadOnly( true ); | 1600 | ev->setReadOnly( true ); |
1600 | ev = eL.next(); | 1601 | ev = eL.next(); |
1601 | } | 1602 | } |
1602 | } | 1603 | } |
1603 | bool CalendarView::openCalendar(QString filename, bool merge) | 1604 | bool CalendarView::openCalendar(QString filename, bool merge) |
1604 | { | 1605 | { |
1605 | 1606 | ||
1606 | if (filename.isEmpty()) { | 1607 | if (filename.isEmpty()) { |
1607 | return false; | 1608 | return false; |
1608 | } | 1609 | } |
1609 | 1610 | ||
1610 | if (!QFile::exists(filename)) { | 1611 | if (!QFile::exists(filename)) { |
1611 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1612 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1612 | return false; | 1613 | return false; |
1613 | } | 1614 | } |
1614 | 1615 | ||
1615 | globalFlagBlockAgenda = 1; | 1616 | globalFlagBlockAgenda = 1; |
1616 | if (!merge) mCalendar->close(); | 1617 | if (!merge) mCalendar->close(); |
1617 | 1618 | ||
1618 | mStorage->setFileName( filename ); | 1619 | mStorage->setFileName( filename ); |
1619 | 1620 | ||
1620 | if ( mStorage->load() ) { | 1621 | if ( mStorage->load() ) { |
1621 | if ( merge ) ;//setModified( true ); | 1622 | if ( merge ) ;//setModified( true ); |
1622 | else { | 1623 | else { |
1623 | //setModified( true ); | 1624 | //setModified( true ); |
1624 | mViewManager->setDocumentId( filename ); | 1625 | mViewManager->setDocumentId( filename ); |
1625 | mDialogManager->setDocumentId( filename ); | 1626 | mDialogManager->setDocumentId( filename ); |
1626 | mTodoList->setDocumentId( filename ); | 1627 | mTodoList->setDocumentId( filename ); |
1627 | } | 1628 | } |
1628 | globalFlagBlockAgenda = 2; | 1629 | globalFlagBlockAgenda = 2; |
1629 | // if ( getLastSyncEvent() ) | 1630 | // if ( getLastSyncEvent() ) |
1630 | // getLastSyncEvent()->setReadOnly( true ); | 1631 | // getLastSyncEvent()->setReadOnly( true ); |
1631 | mCalendar->reInitAlarmSettings(); | 1632 | mCalendar->reInitAlarmSettings(); |
1632 | setSyncEventsReadOnly(); | 1633 | setSyncEventsReadOnly(); |
1633 | updateUnmanagedViews(); | 1634 | updateUnmanagedViews(); |
1634 | updateView(); | 1635 | updateView(); |
1635 | if ( filename != MainWindow::defaultFileName() ) { | 1636 | if ( filename != MainWindow::defaultFileName() ) { |
1636 | saveCalendar( MainWindow::defaultFileName() ); | 1637 | saveCalendar( MainWindow::defaultFileName() ); |
1637 | } else { | 1638 | } else { |
1638 | QFileInfo finf ( MainWindow::defaultFileName()); | 1639 | QFileInfo finf ( MainWindow::defaultFileName()); |
1639 | if ( finf.exists() ) { | 1640 | if ( finf.exists() ) { |
1640 | setLoadedFileVersion( finf.lastModified () ); | 1641 | setLoadedFileVersion( finf.lastModified () ); |
1641 | } | 1642 | } |
1642 | } | 1643 | } |
1643 | return true; | 1644 | return true; |
1644 | } else { | 1645 | } else { |
1645 | // while failing to load, the calendar object could | 1646 | // while failing to load, the calendar object could |
1646 | // have become partially populated. Clear it out. | 1647 | // have become partially populated. Clear it out. |
1647 | if ( !merge ) { | 1648 | if ( !merge ) { |
1648 | mCalendar->close(); | 1649 | mCalendar->close(); |
1649 | mViewManager->setDocumentId( filename ); | 1650 | mViewManager->setDocumentId( filename ); |
1650 | mDialogManager->setDocumentId( filename ); | 1651 | mDialogManager->setDocumentId( filename ); |
1651 | mTodoList->setDocumentId( filename ); | 1652 | mTodoList->setDocumentId( filename ); |
1652 | } | 1653 | } |
1653 | 1654 | ||
1654 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 1655 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
1655 | 1656 | ||
1656 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 1657 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
1657 | globalFlagBlockAgenda = 2; | 1658 | globalFlagBlockAgenda = 2; |
1658 | mCalendar->reInitAlarmSettings(); | 1659 | mCalendar->reInitAlarmSettings(); |
1659 | setSyncEventsReadOnly(); | 1660 | setSyncEventsReadOnly(); |
1660 | updateUnmanagedViews(); | 1661 | updateUnmanagedViews(); |
1661 | updateView(); | 1662 | updateView(); |
1662 | } | 1663 | } |
1663 | return false; | 1664 | return false; |
1664 | } | 1665 | } |
1665 | void CalendarView::showOpenError() | 1666 | void CalendarView::showOpenError() |
1666 | { | 1667 | { |
1667 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 1668 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
1668 | } | 1669 | } |
1669 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1670 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1670 | { | 1671 | { |
1671 | loadedFileVersion = dt; | 1672 | loadedFileVersion = dt; |
1672 | } | 1673 | } |
1673 | bool CalendarView::checkFileChanged(QString fn) | 1674 | bool CalendarView::checkFileChanged(QString fn) |
1674 | { | 1675 | { |
1675 | QFileInfo finf ( fn ); | 1676 | QFileInfo finf ( fn ); |
1676 | if ( !finf.exists() ) | 1677 | if ( !finf.exists() ) |
1677 | return true; | 1678 | return true; |
1678 | QDateTime dt = finf.lastModified (); | 1679 | QDateTime dt = finf.lastModified (); |
1679 | if ( dt <= loadedFileVersion ) | 1680 | if ( dt <= loadedFileVersion ) |
1680 | return false; | 1681 | return false; |
1681 | return true; | 1682 | return true; |
1682 | 1683 | ||
1683 | } | 1684 | } |
1684 | void CalendarView::watchSavedFile() | 1685 | void CalendarView::watchSavedFile() |
1685 | { | 1686 | { |
1686 | QFileInfo finf ( MainWindow::defaultFileName()); | 1687 | QFileInfo finf ( MainWindow::defaultFileName()); |
1687 | if ( !finf.exists() ) | 1688 | if ( !finf.exists() ) |
1688 | return; | 1689 | return; |
1689 | QDateTime dt = finf.lastModified (); | 1690 | QDateTime dt = finf.lastModified (); |
1690 | if ( dt < loadedFileVersion ) { | 1691 | if ( dt < loadedFileVersion ) { |
1691 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 1692 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
1692 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 1693 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
1693 | return; | 1694 | return; |
1694 | } | 1695 | } |
1695 | loadedFileVersion = dt; | 1696 | loadedFileVersion = dt; |
1696 | } | 1697 | } |
1697 | 1698 | ||
1698 | bool CalendarView::checkFileVersion(QString fn) | 1699 | bool CalendarView::checkFileVersion(QString fn) |
1699 | { | 1700 | { |
1700 | QFileInfo finf ( fn ); | 1701 | QFileInfo finf ( fn ); |
1701 | if ( !finf.exists() ) | 1702 | if ( !finf.exists() ) |
1702 | return true; | 1703 | return true; |
1703 | QDateTime dt = finf.lastModified (); | 1704 | QDateTime dt = finf.lastModified (); |
1704 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 1705 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); |
1705 | //qDebug("file on disk version %s",dt.toString().latin1()); | 1706 | //qDebug("file on disk version %s",dt.toString().latin1()); |
1706 | if ( dt <= loadedFileVersion ) | 1707 | if ( dt <= loadedFileVersion ) |
1707 | return true; | 1708 | return true; |
1708 | 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, true)) , | 1709 | 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, true)) , |
1709 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 1710 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
1710 | i18n("Sync+save")); | 1711 | i18n("Sync+save")); |
1711 | 1712 | ||
1712 | if ( km == KMessageBox::Cancel ) | 1713 | if ( km == KMessageBox::Cancel ) |
1713 | return false; | 1714 | return false; |
1714 | if ( km == KMessageBox::Yes ) | 1715 | if ( km == KMessageBox::Yes ) |
1715 | return true; | 1716 | return true; |
1716 | 1717 | ||
1717 | setSyncDevice("deleteaftersync" ); | 1718 | setSyncDevice("deleteaftersync" ); |
1718 | mSyncManager->mAskForPreferences = true; | 1719 | mSyncManager->mAskForPreferences = true; |
1719 | mSyncManager->mSyncAlgoPrefs = 3; | 1720 | mSyncManager->mSyncAlgoPrefs = 3; |
1720 | mSyncManager->mWriteBackFile = false; | 1721 | mSyncManager->mWriteBackFile = false; |
1721 | mSyncManager->mWriteBackExistingOnly = false; | 1722 | mSyncManager->mWriteBackExistingOnly = false; |
1722 | mSyncManager->mShowSyncSummary = false; | 1723 | mSyncManager->mShowSyncSummary = false; |
1723 | syncCalendar( fn, 3 ); | 1724 | syncCalendar( fn, 3 ); |
1724 | Event * e = getLastSyncEvent(); | 1725 | Event * e = getLastSyncEvent(); |
1725 | mCalendar->deleteEvent ( e ); | 1726 | mCalendar->deleteEvent ( e ); |
1726 | updateView(); | 1727 | updateView(); |
1727 | return true; | 1728 | return true; |
1728 | } | 1729 | } |
1729 | 1730 | ||
1730 | bool CalendarView::saveCalendar( QString filename ) | 1731 | bool CalendarView::saveCalendar( QString filename ) |
1731 | { | 1732 | { |
1732 | 1733 | ||
1733 | // Store back all unsaved data into calendar object | 1734 | // Store back all unsaved data into calendar object |
1734 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 1735 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
1735 | if ( mViewManager->currentView() ) | 1736 | if ( mViewManager->currentView() ) |
1736 | mViewManager->currentView()->flushView(); | 1737 | mViewManager->currentView()->flushView(); |
1737 | 1738 | ||
1738 | 1739 | ||
1739 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); | 1740 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); |
1740 | mStorage->setSaveFormat( new ICalFormat() ); | 1741 | mStorage->setSaveFormat( new ICalFormat() ); |
1741 | mStorage->setFileName( filename ); | 1742 | mStorage->setFileName( filename ); |
1742 | bool success; | 1743 | bool success; |
1743 | success = mStorage->save(); | 1744 | success = mStorage->save(); |
1744 | if ( !success ) { | 1745 | if ( !success ) { |
1745 | return false; | 1746 | return false; |
1746 | } | 1747 | } |
1747 | if ( filename == MainWindow::defaultFileName() ) { | 1748 | if ( filename == MainWindow::defaultFileName() ) { |
1748 | setLoadedFileVersion( lfv ); | 1749 | setLoadedFileVersion( lfv ); |
1749 | watchSavedFile(); | 1750 | watchSavedFile(); |
1750 | } | 1751 | } |
1751 | return true; | 1752 | return true; |
1752 | } | 1753 | } |
1753 | 1754 | ||
1754 | void CalendarView::closeCalendar() | 1755 | void CalendarView::closeCalendar() |
1755 | { | 1756 | { |
1756 | 1757 | ||
1757 | // child windows no longer valid | 1758 | // child windows no longer valid |
1758 | emit closingDown(); | 1759 | emit closingDown(); |
1759 | 1760 | ||
1760 | mCalendar->close(); | 1761 | mCalendar->close(); |
1761 | setModified(false); | 1762 | setModified(false); |
1762 | updateView(); | 1763 | updateView(); |
1763 | } | 1764 | } |
1764 | 1765 | ||
1765 | void CalendarView::archiveCalendar() | 1766 | void CalendarView::archiveCalendar() |
1766 | { | 1767 | { |
1767 | mDialogManager->showArchiveDialog(); | 1768 | mDialogManager->showArchiveDialog(); |
1768 | } | 1769 | } |
1769 | 1770 | ||
1770 | 1771 | ||
1771 | void CalendarView::readSettings() | 1772 | void CalendarView::readSettings() |
1772 | { | 1773 | { |
1773 | 1774 | ||
1774 | 1775 | ||
1775 | // mViewManager->showAgendaView(); | 1776 | // mViewManager->showAgendaView(); |
1776 | QString str; | 1777 | QString str; |
1777 | //qDebug("CalendarView::readSettings() "); | 1778 | //qDebug("CalendarView::readSettings() "); |
1778 | // read settings from the KConfig, supplying reasonable | 1779 | // read settings from the KConfig, supplying reasonable |
1779 | // defaults where none are to be found | 1780 | // defaults where none are to be found |
1780 | KConfig *config = KOGlobals::config(); | 1781 | KConfig *config = KOGlobals::config(); |
1781 | #ifndef KORG_NOSPLITTER | 1782 | #ifndef KORG_NOSPLITTER |
1782 | config->setGroup("KOrganizer Geometry"); | 1783 | config->setGroup("KOrganizer Geometry"); |
1783 | 1784 | ||
1784 | QValueList<int> sizes = config->readIntListEntry("Separator1"); | 1785 | QValueList<int> sizes = config->readIntListEntry("Separator1"); |
1785 | if (sizes.count() != 2) { | 1786 | if (sizes.count() != 2) { |
1786 | sizes << mDateNavigator->minimumSizeHint().width(); | 1787 | sizes << mDateNavigator->minimumSizeHint().width(); |
1787 | sizes << 300; | 1788 | sizes << 300; |
1788 | } | 1789 | } |
1789 | mPanner->setSizes(sizes); | 1790 | mPanner->setSizes(sizes); |
1790 | 1791 | ||
1791 | sizes = config->readIntListEntry("Separator2"); | 1792 | sizes = config->readIntListEntry("Separator2"); |
1792 | if ( ( mResourceView && sizes.count() == 4 ) || | 1793 | if ( ( mResourceView && sizes.count() == 4 ) || |
1793 | ( !mResourceView && sizes.count() == 3 ) ) { | 1794 | ( !mResourceView && sizes.count() == 3 ) ) { |
1794 | mLeftSplitter->setSizes(sizes); | 1795 | mLeftSplitter->setSizes(sizes); |
1795 | } | 1796 | } |
1796 | #endif | 1797 | #endif |
1797 | globalFlagBlockAgenda = 1; | 1798 | globalFlagBlockAgenda = 1; |
1798 | mViewManager->showAgendaView(); | 1799 | mViewManager->showAgendaView(); |
1799 | //mViewManager->readSettings( config ); | 1800 | //mViewManager->readSettings( config ); |
1800 | mTodoList->restoreLayout(config,QString("Todo Layout")); | 1801 | mTodoList->restoreLayout(config,QString("Todo Layout")); |
1801 | readFilterSettings(config); | 1802 | readFilterSettings(config); |
1802 | config->setGroup( "Views" ); | 1803 | config->setGroup( "Views" ); |
1803 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); | 1804 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); |
1804 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); | 1805 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); |
1805 | else if ( dateCount == 7 ) mNavigator->selectWeek(); | 1806 | else if ( dateCount == 7 ) mNavigator->selectWeek(); |
1806 | else mNavigator->selectDates( dateCount ); | 1807 | else mNavigator->selectDates( dateCount ); |
1807 | // mViewManager->readSettings( config ); | 1808 | // mViewManager->readSettings( config ); |
1808 | updateConfig(); | 1809 | updateConfig(); |
1809 | globalFlagBlockAgenda = 2; | 1810 | globalFlagBlockAgenda = 2; |
1810 | mViewManager->readSettings( config ); | 1811 | mViewManager->readSettings( config ); |
1811 | #ifdef DESKTOP_VERSION | 1812 | #ifdef DESKTOP_VERSION |
1812 | config->setGroup("WidgetLayout"); | 1813 | config->setGroup("WidgetLayout"); |
1813 | QStringList list; | 1814 | QStringList list; |
1814 | list = config->readListEntry("MainLayout"); | 1815 | list = config->readListEntry("MainLayout"); |
1815 | int x,y,w,h; | 1816 | int x,y,w,h; |
1816 | if ( ! list.isEmpty() ) { | 1817 | if ( ! list.isEmpty() ) { |
1817 | x = list[0].toInt(); | 1818 | x = list[0].toInt(); |
1818 | y = list[1].toInt(); | 1819 | y = list[1].toInt(); |
1819 | w = list[2].toInt(); | 1820 | w = list[2].toInt(); |
1820 | h = list[3].toInt(); | 1821 | h = list[3].toInt(); |
1821 | topLevelWidget()->setGeometry(x,y,w,h); | 1822 | topLevelWidget()->setGeometry(x,y,w,h); |
1822 | 1823 | ||
1823 | } else { | 1824 | } else { |
1824 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); | 1825 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); |
1825 | } | 1826 | } |
1826 | list = config->readListEntry("EditEventLayout"); | 1827 | list = config->readListEntry("EditEventLayout"); |
1827 | if ( ! list.isEmpty() ) { | 1828 | if ( ! list.isEmpty() ) { |
1828 | x = list[0].toInt(); | 1829 | x = list[0].toInt(); |
1829 | y = list[1].toInt(); | 1830 | y = list[1].toInt(); |
1830 | w = list[2].toInt(); | 1831 | w = list[2].toInt(); |
1831 | h = list[3].toInt(); | 1832 | h = list[3].toInt(); |
1832 | mEventEditor->setGeometry(x,y,w,h); | 1833 | mEventEditor->setGeometry(x,y,w,h); |
1833 | 1834 | ||
1834 | } | 1835 | } |
1835 | list = config->readListEntry("EditTodoLayout"); | 1836 | list = config->readListEntry("EditTodoLayout"); |
1836 | if ( ! list.isEmpty() ) { | 1837 | if ( ! list.isEmpty() ) { |
1837 | x = list[0].toInt(); | 1838 | x = list[0].toInt(); |
1838 | y = list[1].toInt(); | 1839 | y = list[1].toInt(); |
1839 | w = list[2].toInt(); | 1840 | w = list[2].toInt(); |
1840 | h = list[3].toInt(); | 1841 | h = list[3].toInt(); |
1841 | mTodoEditor->setGeometry(x,y,w,h); | 1842 | mTodoEditor->setGeometry(x,y,w,h); |
1842 | 1843 | ||
1843 | } | 1844 | } |
1844 | list = config->readListEntry("ViewerLayout"); | 1845 | list = config->readListEntry("ViewerLayout"); |
1845 | if ( ! list.isEmpty() ) { | 1846 | if ( ! list.isEmpty() ) { |
1846 | x = list[0].toInt(); | 1847 | x = list[0].toInt(); |
1847 | y = list[1].toInt(); | 1848 | y = list[1].toInt(); |
1848 | w = list[2].toInt(); | 1849 | w = list[2].toInt(); |
1849 | h = list[3].toInt(); | 1850 | h = list[3].toInt(); |
1850 | getEventViewerDialog()->setGeometry(x,y,w,h); | 1851 | getEventViewerDialog()->setGeometry(x,y,w,h); |
1851 | } | 1852 | } |
1852 | #endif | 1853 | #endif |
1853 | 1854 | ||
1854 | } | 1855 | } |
1855 | 1856 | ||
1856 | 1857 | ||
1857 | void CalendarView::writeSettings() | 1858 | void CalendarView::writeSettings() |
1858 | { | 1859 | { |
1859 | // kdDebug() << "CalendarView::writeSettings" << endl; | 1860 | // kdDebug() << "CalendarView::writeSettings" << endl; |
1860 | 1861 | ||
1861 | KConfig *config = KOGlobals::config(); | 1862 | KConfig *config = KOGlobals::config(); |
1862 | 1863 | ||
1863 | #ifndef KORG_NOSPLITTER | 1864 | #ifndef KORG_NOSPLITTER |
1864 | config->setGroup("KOrganizer Geometry"); | 1865 | config->setGroup("KOrganizer Geometry"); |
1865 | 1866 | ||
1866 | QValueList<int> list = mPanner->sizes(); | 1867 | QValueList<int> list = mPanner->sizes(); |
1867 | config->writeEntry("Separator1",list); | 1868 | config->writeEntry("Separator1",list); |
1868 | 1869 | ||
1869 | list = mLeftSplitter->sizes(); | 1870 | list = mLeftSplitter->sizes(); |
1870 | config->writeEntry("Separator2",list); | 1871 | config->writeEntry("Separator2",list); |
1871 | #endif | 1872 | #endif |
1872 | 1873 | ||
1873 | mViewManager->writeSettings( config ); | 1874 | mViewManager->writeSettings( config ); |
1874 | mTodoList->saveLayout(config,QString("Todo Layout")); | 1875 | mTodoList->saveLayout(config,QString("Todo Layout")); |
1875 | mDialogManager->writeSettings( config ); | 1876 | mDialogManager->writeSettings( config ); |
1876 | //KOPrefs::instance()->usrWriteConfig(); | 1877 | //KOPrefs::instance()->usrWriteConfig(); |
1877 | KOPrefs::instance()->writeConfig(); | 1878 | KOPrefs::instance()->writeConfig(); |
1878 | 1879 | ||
1879 | writeFilterSettings(config); | 1880 | writeFilterSettings(config); |
1880 | 1881 | ||
1881 | config->setGroup( "Views" ); | 1882 | config->setGroup( "Views" ); |
1882 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); | 1883 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); |
1883 | 1884 | ||
1884 | #ifdef DESKTOP_VERSION | 1885 | #ifdef DESKTOP_VERSION |
1885 | config->setGroup("WidgetLayout"); | 1886 | config->setGroup("WidgetLayout"); |
1886 | QStringList list ;//= config->readListEntry("MainLayout"); | 1887 | QStringList list ;//= config->readListEntry("MainLayout"); |
1887 | int x,y,w,h; | 1888 | int x,y,w,h; |
1888 | QWidget* wid; | 1889 | QWidget* wid; |
1889 | wid = topLevelWidget(); | 1890 | wid = topLevelWidget(); |
1890 | x = wid->geometry().x(); | 1891 | x = wid->geometry().x(); |
1891 | y = wid->geometry().y(); | 1892 | y = wid->geometry().y(); |
1892 | w = wid->width(); | 1893 | w = wid->width(); |
1893 | h = wid->height(); | 1894 | h = wid->height(); |
1894 | list.clear(); | 1895 | list.clear(); |
1895 | list << QString::number( x ); | 1896 | list << QString::number( x ); |
1896 | list << QString::number( y ); | 1897 | list << QString::number( y ); |
1897 | list << QString::number( w ); | 1898 | list << QString::number( w ); |
1898 | list << QString::number( h ); | 1899 | list << QString::number( h ); |
1899 | config->writeEntry("MainLayout",list ); | 1900 | config->writeEntry("MainLayout",list ); |
1900 | 1901 | ||
1901 | wid = mEventEditor; | 1902 | wid = mEventEditor; |
1902 | x = wid->geometry().x(); | 1903 | x = wid->geometry().x(); |
1903 | y = wid->geometry().y(); | 1904 | y = wid->geometry().y(); |
1904 | w = wid->width(); | 1905 | w = wid->width(); |
1905 | h = wid->height(); | 1906 | h = wid->height(); |
1906 | list.clear(); | 1907 | list.clear(); |
1907 | list << QString::number( x ); | 1908 | list << QString::number( x ); |
1908 | list << QString::number( y ); | 1909 | list << QString::number( y ); |
1909 | list << QString::number( w ); | 1910 | list << QString::number( w ); |
1910 | list << QString::number( h ); | 1911 | list << QString::number( h ); |
1911 | config->writeEntry("EditEventLayout",list ); | 1912 | config->writeEntry("EditEventLayout",list ); |
1912 | 1913 | ||
1913 | wid = mTodoEditor; | 1914 | wid = mTodoEditor; |
1914 | x = wid->geometry().x(); | 1915 | x = wid->geometry().x(); |
1915 | y = wid->geometry().y(); | 1916 | y = wid->geometry().y(); |
1916 | w = wid->width(); | 1917 | w = wid->width(); |
1917 | h = wid->height(); | 1918 | h = wid->height(); |
1918 | list.clear(); | 1919 | list.clear(); |
1919 | list << QString::number( x ); | 1920 | list << QString::number( x ); |
1920 | list << QString::number( y ); | 1921 | list << QString::number( y ); |
1921 | list << QString::number( w ); | 1922 | list << QString::number( w ); |
1922 | list << QString::number( h ); | 1923 | list << QString::number( h ); |
1923 | config->writeEntry("EditTodoLayout",list ); | 1924 | config->writeEntry("EditTodoLayout",list ); |
1924 | wid = getEventViewerDialog(); | 1925 | wid = getEventViewerDialog(); |
1925 | x = wid->geometry().x(); | 1926 | x = wid->geometry().x(); |
1926 | y = wid->geometry().y(); | 1927 | y = wid->geometry().y(); |
1927 | w = wid->width(); | 1928 | w = wid->width(); |
1928 | h = wid->height(); | 1929 | h = wid->height(); |
1929 | list.clear(); | 1930 | list.clear(); |
1930 | list << QString::number( x ); | 1931 | list << QString::number( x ); |
1931 | list << QString::number( y ); | 1932 | list << QString::number( y ); |
1932 | list << QString::number( w ); | 1933 | list << QString::number( w ); |
1933 | list << QString::number( h ); | 1934 | list << QString::number( h ); |
1934 | config->writeEntry("ViewerLayout",list ); | 1935 | config->writeEntry("ViewerLayout",list ); |
1935 | wid = mDialogManager->getSearchDialog(); | 1936 | wid = mDialogManager->getSearchDialog(); |
1936 | if ( wid ) { | 1937 | if ( wid ) { |
1937 | x = wid->geometry().x(); | 1938 | x = wid->geometry().x(); |
1938 | y = wid->geometry().y(); | 1939 | y = wid->geometry().y(); |
1939 | w = wid->width(); | 1940 | w = wid->width(); |
1940 | h = wid->height(); | 1941 | h = wid->height(); |
1941 | list.clear(); | 1942 | list.clear(); |
1942 | list << QString::number( x ); | 1943 | list << QString::number( x ); |
1943 | list << QString::number( y ); | 1944 | list << QString::number( y ); |
1944 | list << QString::number( w ); | 1945 | list << QString::number( w ); |
1945 | list << QString::number( h ); | 1946 | list << QString::number( h ); |
1946 | config->writeEntry("SearchLayout",list ); | 1947 | config->writeEntry("SearchLayout",list ); |
1947 | } | 1948 | } |
1948 | #endif | 1949 | #endif |
1949 | 1950 | ||
1950 | 1951 | ||
1951 | config->sync(); | 1952 | config->sync(); |
1952 | } | 1953 | } |
1953 | 1954 | ||
1954 | void CalendarView::readFilterSettings(KConfig *config) | 1955 | void CalendarView::readFilterSettings(KConfig *config) |
1955 | { | 1956 | { |
1956 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; | 1957 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; |
1957 | 1958 | ||
1958 | mFilters.clear(); | 1959 | mFilters.clear(); |
1959 | 1960 | ||
1960 | config->setGroup("General"); | 1961 | config->setGroup("General"); |
1961 | QStringList filterList = config->readListEntry("CalendarFilters"); | 1962 | QStringList filterList = config->readListEntry("CalendarFilters"); |
1962 | 1963 | ||
1963 | QStringList::ConstIterator it = filterList.begin(); | 1964 | QStringList::ConstIterator it = filterList.begin(); |
1964 | QStringList::ConstIterator end = filterList.end(); | 1965 | QStringList::ConstIterator end = filterList.end(); |
1965 | while(it != end) { | 1966 | while(it != end) { |
1966 | // kdDebug() << " filter: " << (*it) << endl; | 1967 | // kdDebug() << " filter: " << (*it) << endl; |
1967 | 1968 | ||
1968 | CalFilter *filter; | 1969 | CalFilter *filter; |
1969 | filter = new CalFilter(*it); | 1970 | filter = new CalFilter(*it); |
1970 | config->setGroup("Filter_" + (*it)); | 1971 | config->setGroup("Filter_" + (*it)); |
1971 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); | 1972 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); |
1972 | filter->setCriteria(config->readNumEntry("Criteria",0)); | 1973 | filter->setCriteria(config->readNumEntry("Criteria",0)); |
1973 | filter->setCategoryList(config->readListEntry("CategoryList")); | 1974 | filter->setCategoryList(config->readListEntry("CategoryList")); |
1974 | mFilters.append(filter); | 1975 | mFilters.append(filter); |
1975 | 1976 | ||
1976 | ++it; | 1977 | ++it; |
1977 | } | 1978 | } |
1978 | 1979 | ||
1979 | if (mFilters.count() == 0) { | 1980 | if (mFilters.count() == 0) { |
1980 | CalFilter *filter = new CalFilter(i18n("Default")); | 1981 | CalFilter *filter = new CalFilter(i18n("Default")); |
1981 | mFilters.append(filter); | 1982 | mFilters.append(filter); |
1982 | } | 1983 | } |
1983 | mFilterView->updateFilters(); | 1984 | mFilterView->updateFilters(); |
1984 | config->setGroup("FilterView"); | 1985 | config->setGroup("FilterView"); |
1985 | 1986 | ||
1986 | mFilterView->blockSignals(true); | 1987 | mFilterView->blockSignals(true); |
1987 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); | 1988 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); |
1988 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); | 1989 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); |
1989 | mFilterView->blockSignals(false); | 1990 | mFilterView->blockSignals(false); |
1990 | // We do it manually to avoid it being done twice by the above calls | 1991 | // We do it manually to avoid it being done twice by the above calls |
1991 | updateFilter(); | 1992 | updateFilter(); |
1992 | } | 1993 | } |
1993 | 1994 | ||
1994 | void CalendarView::writeFilterSettings(KConfig *config) | 1995 | void CalendarView::writeFilterSettings(KConfig *config) |
1995 | { | 1996 | { |
1996 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; | 1997 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; |
1997 | 1998 | ||
1998 | QStringList filterList; | 1999 | QStringList filterList; |