summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index 7dcf156..db2058b 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -427,605 +427,610 @@ void DateBook::editEvent( const Event &e )
427#if defined(Q_WS_QWS) || defined(_WS_QWS_) 427#if defined(Q_WS_QWS) || defined(_WS_QWS_)
428 editDlg.showMaximized(); 428 editDlg.showMaximized();
429#endif 429#endif
430 while (editDlg.exec() ) { 430 while (editDlg.exec() ) {
431 Event newEv = entry->event(); 431 Event newEv = entry->event();
432 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 432 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
433 break; 433 break;
434 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 434 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
435 QString error = checkEvent(newEv); 435 QString error = checkEvent(newEv);
436 if (!error.isNull()) { 436 if (!error.isNull()) {
437 if (QMessageBox::warning(this, "error box", 437 if (QMessageBox::warning(this, "error box",
438 error, "Fix it", "Continue", 438 error, "Fix it", "Continue",
439 0, 0, 1) == 0) 439 0, 0, 1) == 0)
440 continue; 440 continue;
441 } 441 }
442 db->editEvent(e, newEv); 442 db->editEvent(e, newEv);
443 emit newEvent(); 443 emit newEvent();
444 break; 444 break;
445 } 445 }
446} 446}
447 447
448void DateBook::removeEvent( const Event &e ) 448void DateBook::removeEvent( const Event &e )
449{ 449{
450 if (syncing) { 450 if (syncing) {
451 QMessageBox::warning( this, tr("Calendar"), 451 QMessageBox::warning( this, tr("Calendar"),
452 tr( "Can not edit data, currently syncing") ); 452 tr( "Can not edit data, currently syncing") );
453 return; 453 return;
454 } 454 }
455 455
456 QString strName = e.description(); 456 QString strName = e.description();
457 457
458 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 458 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
459 return; 459 return;
460 460
461 db->removeEvent( e ); 461 db->removeEvent( e );
462 if ( views->visibleWidget() == dayView && dayView ) 462 if ( views->visibleWidget() == dayView && dayView )
463 dayView->redraw(); 463 dayView->redraw();
464} 464}
465 465
466void DateBook::addEvent( const Event &e ) 466void DateBook::addEvent( const Event &e )
467{ 467{
468 QDate d = e.start().date(); 468 QDate d = e.start().date();
469 initDay(); 469 initDay();
470 dayView->setDate( d ); 470 dayView->setDate( d );
471} 471}
472 472
473void DateBook::showDay( int year, int month, int day ) 473void DateBook::showDay( int year, int month, int day )
474{ 474{
475 QDate d(year, month, day); 475 QDate d(year, month, day);
476 view(DAY,d); 476 view(DAY,d);
477} 477}
478 478
479void DateBook::initDay() 479void DateBook::initDay()
480{ 480{
481 if ( !dayView ) { 481 if ( !dayView ) {
482 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 482 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
483 views->addWidget( dayView, DAY ); 483 views->addWidget( dayView, DAY );
484 dayView->setStartViewTime( startTime ); 484 dayView->setStartViewTime( startTime );
485 dayView->setJumpToCurTime( bJumpToCurTime ); 485 dayView->setJumpToCurTime( bJumpToCurTime );
486 dayView->setRowStyle( rowStyle ); 486 dayView->setRowStyle( rowStyle );
487 connect( this, SIGNAL( newEvent() ), 487 connect( this, SIGNAL( newEvent() ),
488 dayView, SLOT( redraw() ) ); 488 dayView, SLOT( redraw() ) );
489 connect( dayView, SIGNAL( newEvent() ), 489 connect( dayView, SIGNAL( newEvent() ),
490 this, SLOT( fileNew() ) ); 490 this, SLOT( fileNew() ) );
491 connect( dayView, SIGNAL( removeEvent( const Event & ) ), 491 connect( dayView, SIGNAL( removeEvent( const Event & ) ),
492 this, SLOT( removeEvent( const Event & ) ) ); 492 this, SLOT( removeEvent( const Event & ) ) );
493 connect( dayView, SIGNAL( editEvent( const Event & ) ), 493 connect( dayView, SIGNAL( editEvent( const Event & ) ),
494 this, SLOT( editEvent( const Event & ) ) ); 494 this, SLOT( editEvent( const Event & ) ) );
495 connect( dayView, SIGNAL( beamEvent( const Event & ) ), 495 connect( dayView, SIGNAL( beamEvent( const Event & ) ),
496 this, SLOT( beamEvent( const Event & ) ) ); 496 this, SLOT( beamEvent( const Event & ) ) );
497 connect( dayView, SIGNAL(sigNewEvent(const QString &)), 497 connect( dayView, SIGNAL(sigNewEvent(const QString &)),
498 this, SLOT(slotNewEventFromKey(const QString &)) ); 498 this, SLOT(slotNewEventFromKey(const QString &)) );
499 } 499 }
500} 500}
501 501
502void DateBook::initWeek() 502void DateBook::initWeek()
503{ 503{
504 if ( !weekView ) { 504 if ( !weekView ) {
505 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 505 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
506 weekView->setStartViewTime( startTime ); 506 weekView->setStartViewTime( startTime );
507 views->addWidget( weekView, WEEK ); 507 views->addWidget( weekView, WEEK );
508 connect( weekView, SIGNAL( showDate( int, int, int ) ), 508 connect( weekView, SIGNAL( showDate( int, int, int ) ),
509 this, SLOT( showDay( int, int, int ) ) ); 509 this, SLOT( showDay( int, int, int ) ) );
510 connect( this, SIGNAL( newEvent() ), 510 connect( this, SIGNAL( newEvent() ),
511 weekView, SLOT( redraw() ) ); 511 weekView, SLOT( redraw() ) );
512 } 512 }
513 //But also get it right: the year that we display can be different 513 //But also get it right: the year that we display can be different
514 //from the year of the current date. So, first find the year 514 //from the year of the current date. So, first find the year
515 //number of the current week. 515 //number of the current week.
516 516
517 int yearNumber, totWeeks; 517 int yearNumber, totWeeks;
518 calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); 518 calcWeek( currentDate(), totWeeks, yearNumber, onMonday );
519 519
520 QDate d = QDate( yearNumber, 12, 31 ); 520 QDate d = QDate( yearNumber, 12, 31 );
521 calcWeek( d, totWeeks, yearNumber, onMonday ); 521 calcWeek( d, totWeeks, yearNumber, onMonday );
522 522
523 while ( totWeeks == 1 ) { 523 while ( totWeeks == 1 ) {
524 d = d.addDays( -1 ); 524 d = d.addDays( -1 );
525 calcWeek( d, totWeeks, yearNumber, onMonday ); 525 calcWeek( d, totWeeks, yearNumber, onMonday );
526 } 526 }
527 if ( totWeeks != weekView->totalWeeks() ) 527 if ( totWeeks != weekView->totalWeeks() )
528 weekView->setTotalWeeks( totWeeks ); 528 weekView->setTotalWeeks( totWeeks );
529} 529}
530void DateBook::initWeekLst() { 530void DateBook::initWeekLst() {
531 if ( !weekLstView ) { 531 if ( !weekLstView ) {
532 weekLstView = new DateBookWeekLst( ampm, onMonday, db, 532 weekLstView = new DateBookWeekLst( ampm, onMonday, db,
533 views, "weeklst view" ); 533 views, "weeklst view" );
534 views->addWidget( weekLstView, WEEKLST ); 534 views->addWidget( weekLstView, WEEKLST );
535 535
536 //weekLstView->setStartViewTime( startTime ); 536 //weekLstView->setStartViewTime( startTime );
537 connect( weekLstView, SIGNAL( showDate( int, int, int ) ), 537 connect( weekLstView, SIGNAL( showDate( int, int, int ) ),
538 this, SLOT( showDay( int, int, int ) ) ); 538 this, SLOT( showDay( int, int, int ) ) );
539 connect( weekLstView, SIGNAL( addEvent( const QDateTime &, 539 connect( weekLstView, SIGNAL( addEvent( const QDateTime &,
540 const QDateTime &, 540 const QDateTime &,
541 const QString & ) ), 541 const QString & ) ),
542 this, SLOT( slotNewEntry( const QDateTime &, 542 this, SLOT( slotNewEntry( const QDateTime &,
543 const QDateTime &, 543 const QDateTime &,
544 const QString & ) ) ); 544 const QString & ) ) );
545 connect( this, SIGNAL( newEvent() ), 545 connect( this, SIGNAL( newEvent() ),
546 weekLstView, SLOT( redraw() ) ); 546 weekLstView, SLOT( redraw() ) );
547 connect( weekLstView, SIGNAL( editEvent( const Event & ) ), 547 connect( weekLstView, SIGNAL( editEvent( const Event & ) ),
548 this, SLOT( editEvent( const Event & ) ) ); 548 this, SLOT( editEvent( const Event & ) ) );
549 } 549 }
550} 550}
551 551
552 552
553void DateBook::initMonth() 553void DateBook::initMonth()
554{ 554{
555 if ( !monthView ) { 555 if ( !monthView ) {
556 monthView = new DateBookMonth( views, "month view", FALSE, db ); 556 monthView = new DateBookMonth( views, "month view", FALSE, db );
557 views->addWidget( monthView, MONTH ); 557 views->addWidget( monthView, MONTH );
558 connect( monthView, SIGNAL( dateClicked( int, int, int ) ), 558 connect( monthView, SIGNAL( dateClicked( int, int, int ) ),
559 this, SLOT( showDay( int, int, int ) ) ); 559 this, SLOT( showDay( int, int, int ) ) );
560 connect( this, SIGNAL( newEvent() ), 560 connect( this, SIGNAL( newEvent() ),
561 monthView, SLOT( redraw() ) ); 561 monthView, SLOT( redraw() ) );
562 qApp->processEvents(); 562 qApp->processEvents();
563 } 563 }
564} 564}
565 565
566void DateBook::loadSettings() 566void DateBook::loadSettings()
567{ 567{
568 { 568 {
569 Config config( "qpe" ); 569 Config config( "qpe" );
570 config.setGroup("Time"); 570 config.setGroup("Time");
571 ampm = config.readBoolEntry( "AMPM", TRUE ); 571 ampm = config.readBoolEntry( "AMPM", TRUE );
572 onMonday = config.readBoolEntry( "MONDAY" ); 572 onMonday = config.readBoolEntry( "MONDAY" );
573 } 573 }
574 574
575 { 575 {
576 Config config("DateBook"); 576 Config config("DateBook");
577 config.setGroup("Main"); 577 config.setGroup("Main");
578 startTime = config.readNumEntry("startviewtime", 8); 578 startTime = config.readNumEntry("startviewtime", 8);
579 aPreset = config.readBoolEntry("alarmpreset"); 579 aPreset = config.readBoolEntry("alarmpreset");
580 presetTime = config.readNumEntry("presettime"); 580 presetTime = config.readNumEntry("presettime");
581 bJumpToCurTime = config.readBoolEntry("jumptocurtime"); 581 bJumpToCurTime = config.readBoolEntry("jumptocurtime");
582 rowStyle = config.readNumEntry("rowstyle"); 582 rowStyle = config.readNumEntry("rowstyle");
583 } 583 }
584} 584}
585 585
586void DateBook::saveSettings() 586void DateBook::saveSettings()
587{ 587{
588 Config config( "qpe" ); 588 Config config( "qpe" );
589 Config configDB( "DateBook" ); 589 Config configDB( "DateBook" );
590 configDB.setGroup( "Main" ); 590 configDB.setGroup( "Main" );
591 configDB.writeEntry("startviewtime",startTime); 591 configDB.writeEntry("startviewtime",startTime);
592 configDB.writeEntry("alarmpreset",aPreset); 592 configDB.writeEntry("alarmpreset",aPreset);
593 configDB.writeEntry("presettime",presetTime); 593 configDB.writeEntry("presettime",presetTime);
594 configDB.writeEntry("jumptocurtime", bJumpToCurTime); 594 configDB.writeEntry("jumptocurtime", bJumpToCurTime);
595 configDB.writeEntry("rowstyle", rowStyle); 595 configDB.writeEntry("rowstyle", rowStyle);
596} 596}
597 597
598void DateBook::newDefaultView(QAction *a) { 598void DateBook::newDefaultView(QAction *a) {
599 int val=DAY; 599 int val=DAY;
600 if (a->text() == "Day") val=DAY; 600 if (a->text() == "Day") val=DAY;
601 if (a->text() == "Week") val=WEEK; 601 if (a->text() == "Week") val=WEEK;
602 if (a->text() == "WeekLst") val=WEEKLST; 602 if (a->text() == "WeekLst") val=WEEKLST;
603 if (a->text() == "Month") val=MONTH; 603 if (a->text() == "Month") val=MONTH;
604 604
605 Config configDB( "DateBook" ); 605 Config configDB( "DateBook" );
606 configDB.setGroup( "Main" ); 606 configDB.setGroup( "Main" );
607 configDB.writeEntry("defaultview",val); 607 configDB.writeEntry("defaultview",val);
608} 608}
609 609
610void DateBook::appMessage(const QCString& msg, const QByteArray& data) 610void DateBook::appMessage(const QCString& msg, const QByteArray& data)
611{ 611{
612 bool needShow = FALSE; 612 bool needShow = FALSE;
613 if ( msg == "alarm(QDateTime,int)" ) { 613 if ( msg == "alarm(QDateTime,int)" ) {
614 QDataStream ds(data,IO_ReadOnly); 614 QDataStream ds(data,IO_ReadOnly);
615 QDateTime when; int warn; 615 QDateTime when; int warn;
616 ds >> when >> warn; 616 ds >> when >> warn;
617 617
618 // check to make it's okay to continue, 618 // check to make it's okay to continue,
619 // this is the case that the time was set ahead, and 619 // this is the case that the time was set ahead, and
620 // we are forced given a stale alarm... 620 // we are forced given a stale alarm...
621 QDateTime current = QDateTime::currentDateTime(); 621 QDateTime current = QDateTime::currentDateTime();
622 if ( current.time().hour() != when.time().hour() 622 if ( current.time().hour() != when.time().hour()
623 && current.time().minute() != when.time().minute() ) 623 && current.time().minute() != when.time().minute() )
624 return; 624 return;
625 625
626 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); 626 QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60));
627 if ( list.count() > 0 ) { 627 if ( list.count() > 0 ) {
628 QString msg; 628 QString msg;
629 bool bSound = FALSE; 629 bool bSound = FALSE;
630 int stopTimer = 0; 630 int stopTimer = 0;
631 bool found = FALSE; 631 bool found = FALSE;
632 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); 632 for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin();
633 it!=list.end(); ++it ) { 633 it!=list.end(); ++it ) {
634 if ( (*it).event().hasAlarm() ) { 634 if ( (*it).event().hasAlarm() ) {
635 found = TRUE; 635 found = TRUE;
636 msg += "<CENTER><B>" + (*it).description() + "</B>" 636 msg += "<CENTER><B>" + (*it).description() + "</B>"
637 + "<BR>" + (*it).location() + "<BR>" 637 + "<BR>" + (*it).location() + "<BR>"
638 + TimeString::dateString((*it).event().start(),ampm) 638 + TimeString::dateString((*it).event().start(),ampm)
639 + (warn 639 + (warn
640 ? tr(" (in " + QString::number(warn) 640 ? tr(" (in " + QString::number(warn)
641 + tr(" minutes)")) 641 + tr(" minutes)"))
642 : QString("")) 642 : QString(""))
643 + "<BR>" 643 + "<BR>"
644 + (*it).notes() + "</CENTER>"; 644 + (*it).notes() + "</CENTER>";
645 if ( (*it).event().alarmSound() != Event::Silent ) { 645 if ( (*it).event().alarmSound() != Event::Silent ) {
646 bSound = TRUE; 646 bSound = TRUE;
647 } 647 }
648 } 648 }
649 } 649 }
650 if ( found ) { 650 if ( found ) {
651 if ( bSound ) { 651 if ( bSound ) {
652 Sound::soundAlarm(); 652 Sound::soundAlarm();
653 alarmCounter = 0; 653 alarmCounter = 0;
654 stopTimer = startTimer( 5000 ); 654 stopTimer = startTimer( 5000 );
655 } 655 }
656 656
657 QDialog dlg( this, 0, TRUE ); 657 QDialog dlg( this, 0, TRUE );
658 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 658 QVBoxLayout *vb = new QVBoxLayout( &dlg );
659 QScrollView *view = new QScrollView( &dlg, "scrollView"); 659 QScrollView *view = new QScrollView( &dlg, "scrollView");
660 view->setResizePolicy( QScrollView::AutoOneFit ); 660 view->setResizePolicy( QScrollView::AutoOneFit );
661 vb->addWidget( view ); 661 vb->addWidget( view );
662 QLabel *lblMsg = new QLabel( msg, &dlg ); 662 QLabel *lblMsg = new QLabel( msg, &dlg );
663 view->addChild( lblMsg ); 663 view->addChild( lblMsg );
664 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 664 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
665 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 665 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
666 vb->addWidget( cmdOk ); 666 vb->addWidget( cmdOk );
667 667
668#if defined(Q_WS_QWS) || defined(_WS_QWS_) 668#if defined(Q_WS_QWS) || defined(_WS_QWS_)
669 dlg.showMaximized(); 669 dlg.showMaximized();
670#endif 670#endif
671 needShow = dlg.exec(); 671 needShow = dlg.exec();
672 672
673 if ( bSound ) 673 if ( bSound )
674 killTimer( stopTimer ); 674 killTimer( stopTimer );
675 } 675 }
676 } 676 }
677 } else if ( msg == "nextView()" ) { 677 } else if ( msg == "nextView()" ) {
678 if ( !qApp-> activeWindow ( )) { 678 if ( !qApp-> activeWindow ( )) {
679 needShow = TRUE; 679 needShow = TRUE;
680 } 680 }
681 else { 681 else {
682 QWidget* cur = views->visibleWidget(); 682 QWidget* cur = views->visibleWidget();
683 if ( cur ) { 683 if ( cur ) {
684 if ( cur == dayView ) 684 if ( cur == dayView )
685 viewWeek(); 685 viewWeek();
686 else if ( cur == weekView ) 686 else if ( cur == weekView )
687 viewWeekLst(); 687 viewWeekLst();
688 else if ( cur == weekLstView ) 688 else if ( cur == weekLstView )
689 viewMonth(); 689 viewMonth();
690 else if ( cur == monthView ) 690 else if ( cur == monthView )
691 viewDay(); 691 viewDay();
692 needShow = TRUE; 692 needShow = TRUE;
693 } 693 }
694 } 694 }
695 } 695 }
696 if ( needShow ) { 696 if ( needShow ) {
697#if defined(Q_WS_QWS) || defined(_WS_QWS_) 697#if defined(Q_WS_QWS) || defined(_WS_QWS_)
698 showMaximized(); 698 showMaximized();
699#else 699#else
700 show(); 700 show();
701#endif 701#endif
702 raise(); 702 raise();
703 QPEApplication::setKeepRunning(); 703 QPEApplication::setKeepRunning();
704 setActiveWindow(); 704 setActiveWindow();
705 } 705 }
706} 706}
707 707
708void DateBook::reload() 708void DateBook::reload()
709{ 709{
710 db->reload(); 710 db->reload();
711 if ( dayAction->isOn() ) 711 if ( dayAction->isOn() )
712 viewDay(); 712 viewDay();
713 else if ( weekAction->isOn() ) 713 else if ( weekAction->isOn() )
714 viewWeek(); 714 viewWeek();
715 else if ( monthAction->isOn() ) 715 else if ( monthAction->isOn() )
716 viewMonth(); 716 viewMonth();
717 syncing = FALSE; 717 syncing = FALSE;
718} 718}
719 719
720void DateBook::flush() 720void DateBook::flush()
721{ 721{
722 syncing = TRUE; 722 syncing = TRUE;
723 db->save(); 723 db->save();
724} 724}
725 725
726void DateBook::timerEvent( QTimerEvent *e ) 726void DateBook::timerEvent( QTimerEvent *e )
727{ 727{
728 if ( alarmCounter < 10 ) { 728 if ( alarmCounter < 10 ) {
729 alarmCounter++; 729 alarmCounter++;
730 Sound::soundAlarm(); 730 Sound::soundAlarm();
731 } 731 }
732 else 732 else
733 killTimer( e->timerId() ); 733 killTimer( e->timerId() );
734} 734}
735 735
736void DateBook::changeClock( bool newClock ) 736void DateBook::changeClock( bool newClock )
737{ 737{
738 ampm = newClock; 738 ampm = newClock;
739 // repaint the affected objects... 739 // repaint the affected objects...
740 if (dayView) dayView->redraw(); 740 if (dayView) dayView->redraw();
741 if (weekView) weekView->redraw(); 741 if (weekView) weekView->redraw();
742 if (weekLstView) weekLstView->redraw(); 742 if (weekLstView) weekLstView->redraw();
743} 743}
744 744
745void DateBook::changeWeek( bool m ) 745void DateBook::changeWeek( bool m )
746{ 746{
747 /* no need to redraw, each widget catches. Do need to 747 /* no need to redraw, each widget catches. Do need to
748 store though for widgets we haven't made yet */ 748 store though for widgets we haven't made yet */
749 onMonday = m; 749 onMonday = m;
750} 750}
751 751
752void DateBook::slotToday() 752void DateBook::slotToday()
753{ 753{
754 // we need to view today using default view 754 // we need to view today using default view
755 viewDefault(QDate::currentDate()); 755 viewDefault(QDate::currentDate());
756} 756}
757 757
758void DateBook::closeEvent( QCloseEvent *e ) 758void DateBook::closeEvent( QCloseEvent *e )
759{ 759{
760 if(syncing) { 760 if(syncing) {
761 /* no need to save, did that at flush */ 761 /* no need to save, did that at flush */
762 e->accept(); 762 e->accept();
763 return; 763 return;
764 } 764 }
765 765
766 // save settings will generate it's own error messages, no 766 // save settings will generate it's own error messages, no
767 // need to do checking ourselves. 767 // need to do checking ourselves.
768 saveSettings(); 768 saveSettings();
769 if ( db->save() ) 769 if ( db->save() )
770 e->accept(); 770 e->accept();
771 else { 771 else {
772 if ( QMessageBox::critical( this, tr( "Out of space" ), 772 if ( QMessageBox::critical( this, tr( "Out of space" ),
773 tr("Calendar was unable to save\n" 773 tr("Calendar was unable to save\n"
774 "your changes.\n" 774 "your changes.\n"
775 "Free up some space and try again.\n" 775 "Free up some space and try again.\n"
776 "\nQuit anyway?"), 776 "\nQuit anyway?"),
777 QMessageBox::Yes|QMessageBox::Escape, 777 QMessageBox::Yes|QMessageBox::Escape,
778 QMessageBox::No|QMessageBox::Default ) 778 QMessageBox::No|QMessageBox::Default )
779 != QMessageBox::No ) 779 != QMessageBox::No )
780 e->accept(); 780 e->accept();
781 else 781 else
782 e->ignore(); 782 e->ignore();
783 } 783 }
784} 784}
785 785
786// Entering directly from the "keyboard" 786// Entering directly from the "keyboard"
787void DateBook::slotNewEventFromKey( const QString &str ) 787void DateBook::slotNewEventFromKey( const QString &str )
788{ 788{
789 if (syncing) { 789 if (syncing) {
790 QMessageBox::warning( this, tr("Calendar"), 790 QMessageBox::warning( this, tr("Calendar"),
791 tr( "Can not edit data, currently syncing") ); 791 tr( "Can not edit data, currently syncing") );
792 return; 792 return;
793 } 793 }
794 794
795 // We get to here from a key pressed in the Day View 795 // We get to here from a key pressed in the Day View
796 // So we can assume some things. We want the string 796 // So we can assume some things. We want the string
797 // passed in to be part of the description. 797 // passed in to be part of the description.
798 QDateTime start, end; 798 QDateTime start, end;
799 if ( views->visibleWidget() == dayView ) { 799 if ( views->visibleWidget() == dayView ) {
800 dayView->selectedDates( start, end ); 800 dayView->selectedDates( start, end );
801 } else if ( views->visibleWidget() == monthView ) { 801 } else if ( views->visibleWidget() == monthView ) {
802 QDate d = monthView->selectedDate(); 802 QDate d = monthView->selectedDate();
803 start = end = d; 803 start = end = d;
804 start.setTime( QTime( 10, 0 ) ); 804 start.setTime( QTime( 10, 0 ) );
805 end.setTime( QTime( 12, 0 ) ); 805 end.setTime( QTime( 12, 0 ) );
806 } else if ( views->visibleWidget() == weekView ) { 806 } else if ( views->visibleWidget() == weekView ) {
807 QDate d = weekView->date(); 807 QDate d = weekView->date();
808 start = end = d; 808 start = end = d;
809 start.setTime( QTime( 10, 0 ) ); 809 start.setTime( QTime( 10, 0 ) );
810 end.setTime( QTime( 12, 0 ) ); 810 end.setTime( QTime( 12, 0 ) );
811 } 811 } else if ( views->visibleWidget() == weekLstView ) {
812 QDate d = weekLstView->date();
813 start = end = d;
814 start.setTime( QTime( 10, 0 ) );
815 end.setTime( QTime( 12, 0 ) );
816 }
812 slotNewEntry(start, end, str); 817 slotNewEntry(start, end, str);
813} 818}
814void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) { 819void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str) {
815 // argh! This really needs to be encapsulated in a class 820 // argh! This really needs to be encapsulated in a class
816 // or function. 821 // or function.
817 QDialog newDlg( this, 0, TRUE ); 822 QDialog newDlg( this, 0, TRUE );
818 newDlg.setCaption( DateEntryBase::tr("New Event") ); 823 newDlg.setCaption( DateEntryBase::tr("New Event") );
819 DateEntry *e; 824 DateEntry *e;
820 QVBoxLayout *vb = new QVBoxLayout( &newDlg ); 825 QVBoxLayout *vb = new QVBoxLayout( &newDlg );
821 QScrollView *sv = new QScrollView( &newDlg ); 826 QScrollView *sv = new QScrollView( &newDlg );
822 sv->setResizePolicy( QScrollView::AutoOneFit ); 827 sv->setResizePolicy( QScrollView::AutoOneFit );
823 sv->setFrameStyle( QFrame::NoFrame ); 828 sv->setFrameStyle( QFrame::NoFrame );
824 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 829 sv->setHScrollBarMode( QScrollView::AlwaysOff );
825 vb->addWidget( sv ); 830 vb->addWidget( sv );
826 831
827 Event ev; 832 Event ev;
828 ev.setDescription( str ); 833 ev.setDescription( str );
829 // When the new gui comes in, change this... 834 // When the new gui comes in, change this...
830 ev.setLocation( tr("(Unknown)") ); 835 ev.setLocation( tr("(Unknown)") );
831 ev.setStart( start ); 836 ev.setStart( start );
832 ev.setEnd( end ); 837 ev.setEnd( end );
833 838
834 e = new DateEntry( onMonday, ev, ampm, &newDlg ); 839 e = new DateEntry( onMonday, ev, ampm, &newDlg );
835 e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); 840 e->setAlarmEnabled( aPreset, presetTime, Event::Loud );
836 sv->addChild( e ); 841 sv->addChild( e );
837#if defined(Q_WS_QWS) || defined(_WS_QWS_) 842#if defined(Q_WS_QWS) || defined(_WS_QWS_)
838 newDlg.showMaximized(); 843 newDlg.showMaximized();
839#endif 844#endif
840 while (newDlg.exec()) { 845 while (newDlg.exec()) {
841 ev = e->event(); 846 ev = e->event();
842 ev.assignUid(); 847 ev.assignUid();
843 QString error = checkEvent( ev ); 848 QString error = checkEvent( ev );
844 if ( !error.isNull() ) { 849 if ( !error.isNull() ) {
845 if ( QMessageBox::warning( this, tr("Error!"), 850 if ( QMessageBox::warning( this, tr("Error!"),
846 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) 851 error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 )
847 continue; 852 continue;
848 } 853 }
849 db->addEvent( ev ); 854 db->addEvent( ev );
850 emit newEvent(); 855 emit newEvent();
851 break; 856 break;
852 } 857 }
853} 858}
854 859
855void DateBook::setDocument( const QString &filename ) 860void DateBook::setDocument( const QString &filename )
856{ 861{
857 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 862 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
858 863
859 QValueList<Event> tl = Event::readVCalendar( filename ); 864 QValueList<Event> tl = Event::readVCalendar( filename );
860 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 865 for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
861 db->addEvent( *it ); 866 db->addEvent( *it );
862 } 867 }
863} 868}
864 869
865static const char * beamfile = "/tmp/obex/event.vcs"; 870static const char * beamfile = "/tmp/obex/event.vcs";
866 871
867void DateBook::beamEvent( const Event &e ) 872void DateBook::beamEvent( const Event &e )
868{ 873{
869 qDebug("trying to beamn"); 874 qDebug("trying to beamn");
870 unlink( beamfile ); // delete if exists 875 unlink( beamfile ); // delete if exists
871 mkdir("/tmp/obex/", 0755); 876 mkdir("/tmp/obex/", 0755);
872 Event::writeVCalendar( beamfile, e ); 877 Event::writeVCalendar( beamfile, e );
873 Ir *ir = new Ir( this ); 878 Ir *ir = new Ir( this );
874 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 879 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
875 QString description = e.description(); 880 QString description = e.description();
876 ir->send( beamfile, description, "text/x-vCalendar" ); 881 ir->send( beamfile, description, "text/x-vCalendar" );
877} 882}
878 883
879void DateBook::beamDone( Ir *ir ) 884void DateBook::beamDone( Ir *ir )
880{ 885{
881 delete ir; 886 delete ir;
882 unlink( beamfile ); 887 unlink( beamfile );
883} 888}
884 889
885void DateBook::slotFind() 890void DateBook::slotFind()
886{ 891{
887 // move it to the day view... 892 // move it to the day view...
888 viewDay(); 893 viewDay();
889 FindDialog frmFind( "Calendar", this ); 894 FindDialog frmFind( "Calendar", this );
890 frmFind.setUseDate( true ); 895 frmFind.setUseDate( true );
891 frmFind.setDate( currentDate() ); 896 frmFind.setDate( currentDate() );
892 QObject::connect( &frmFind, 897 QObject::connect( &frmFind,
893 SIGNAL(signalFindClicked(const QString&, const QDate&, 898 SIGNAL(signalFindClicked(const QString&, const QDate&,
894 bool, bool, int)), 899 bool, bool, int)),
895 this, 900 this,
896 SLOT(slotDoFind(const QString&, const QDate&, 901 SLOT(slotDoFind(const QString&, const QDate&,
897 bool, bool, int)) ); 902 bool, bool, int)) );
898 QObject::connect( this, 903 QObject::connect( this,
899 SIGNAL(signalNotFound()), 904 SIGNAL(signalNotFound()),
900 &frmFind, 905 &frmFind,
901 SLOT(slotNotFound()) ); 906 SLOT(slotNotFound()) );
902 QObject::connect( this, 907 QObject::connect( this,
903 SIGNAL(signalWrapAround()), 908 SIGNAL(signalWrapAround()),
904 &frmFind, 909 &frmFind,
905 SLOT(slotWrapAround()) ); 910 SLOT(slotWrapAround()) );
906 frmFind.exec(); 911 frmFind.exec();
907 inSearch = false; 912 inSearch = false;
908} 913}
909 914
910bool catComp( QArray<int> cats, int category ) 915bool catComp( QArray<int> cats, int category )
911{ 916{
912 bool returnMe; 917 bool returnMe;
913 int i, 918 int i,
914 count; 919 count;
915 920
916 count = int(cats.count()); 921 count = int(cats.count());
917 returnMe = false; 922 returnMe = false;
918 if ( (category == -1 && count == 0) || category == -2 ) 923 if ( (category == -1 && count == 0) || category == -2 )
919 returnMe = true; 924 returnMe = true;
920 else { 925 else {
921 for ( i = 0; i < count; i++ ) { 926 for ( i = 0; i < count; i++ ) {
922 if ( category == cats[i] ) { 927 if ( category == cats[i] ) {
923 returnMe = true; 928 returnMe = true;
924 break; 929 break;
925 } 930 }
926 } 931 }
927 } 932 }
928 return returnMe; 933 return returnMe;
929} 934}
930 935
931 936
932void DateBook::slotDoFind( const QString& txt, const QDate &dt, 937void DateBook::slotDoFind( const QString& txt, const QDate &dt,
933 bool caseSensitive, bool /*backwards*/, 938 bool caseSensitive, bool /*backwards*/,
934 int category ) 939 int category )
935{ 940{
936 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), 941 QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ),
937 next; 942 next;
938 943
939 QRegExp r( txt ); 944 QRegExp r( txt );
940 r.setCaseSensitive( caseSensitive ); 945 r.setCaseSensitive( caseSensitive );
941 946
942 947
943 static Event rev, 948 static Event rev,
944 nonrev; 949 nonrev;
945 if ( !inSearch ) { 950 if ( !inSearch ) {
946 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 951 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
947 nonrev.setStart( rev.start() ); 952 nonrev.setStart( rev.start() );
948 inSearch = true; 953 inSearch = true;
949 } 954 }
950 static QDate searchDate = dt; 955 static QDate searchDate = dt;
951 static bool wrapAround = true; 956 static bool wrapAround = true;
952 bool candidtate; 957 bool candidtate;
953 candidtate = false; 958 candidtate = false;
954 959
955 QValueList<Event> repeats = db->getRawRepeats(); 960 QValueList<Event> repeats = db->getRawRepeats();
956 961
957 // find the candidate for the first repeat that matches... 962 // find the candidate for the first repeat that matches...
958 QValueListConstIterator<Event> it; 963 QValueListConstIterator<Event> it;
959 QDate start = dt; 964 QDate start = dt;
960 for ( it = repeats.begin(); it != repeats.end(); ++it ) { 965 for ( it = repeats.begin(); it != repeats.end(); ++it ) {
961 if ( catComp( (*it).categories(), category ) ) { 966 if ( catComp( (*it).categories(), category ) ) {
962 while ( nextOccurance( *it, start, next ) ) { 967 while ( nextOccurance( *it, start, next ) ) {
963 if ( next < dtEnd ) { 968 if ( next < dtEnd ) {
964 if ( (*it).match( r ) && !(next <= rev.start()) ) { 969 if ( (*it).match( r ) && !(next <= rev.start()) ) {
965 rev = *it; 970 rev = *it;
966 dtEnd = next; 971 dtEnd = next;
967 rev.setStart( next ); 972 rev.setStart( next );
968 candidtate = true; 973 candidtate = true;
969 wrapAround = true; 974 wrapAround = true;
970 start = dt; 975 start = dt;
971 break; 976 break;
972 } else 977 } else
973 start = next.date().addDays( 1 ); 978 start = next.date().addDays( 1 );
974 } 979 }
975 } 980 }
976 } 981 }
977 } 982 }
978 983
979 // now the for first non repeat... 984 // now the for first non repeat...
980 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); 985 QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() );
981 qHeapSort( nonRepeats.begin(), nonRepeats.end() ); 986 qHeapSort( nonRepeats.begin(), nonRepeats.end() );
982 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { 987 for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) {
983 if ( catComp( (*it).categories(), category ) ) { 988 if ( catComp( (*it).categories(), category ) ) {
984 if ( (*it).start() < dtEnd ) { 989 if ( (*it).start() < dtEnd ) {
985 if ( (*it).match( r ) && !(*it <= nonrev) ) { 990 if ( (*it).match( r ) && !(*it <= nonrev) ) {
986 nonrev = *it; 991 nonrev = *it;
987 dtEnd = nonrev.start(); 992 dtEnd = nonrev.start();
988 candidtate = true; 993 candidtate = true;
989 wrapAround = true; 994 wrapAround = true;
990 break; 995 break;
991 } 996 }
992 } 997 }
993 } 998 }
994 } 999 }
995 if ( candidtate ) { 1000 if ( candidtate ) {
996 dayView->setStartViewTime( dtEnd.time().hour() ); 1001 dayView->setStartViewTime( dtEnd.time().hour() );
997 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), 1002 dayView->setDate( dtEnd.date().year(), dtEnd.date().month(),
998 dtEnd.date().day() ); 1003 dtEnd.date().day() );
999 } else { 1004 } else {
1000 if ( wrapAround ) { 1005 if ( wrapAround ) {
1001 emit signalWrapAround(); 1006 emit signalWrapAround();
1002 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); 1007 rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) );
1003 nonrev.setStart( rev.start() ); 1008 nonrev.setStart( rev.start() );
1004 } else 1009 } else
1005 emit signalNotFound(); 1010 emit signalNotFound();
1006 wrapAround = !wrapAround; 1011 wrapAround = !wrapAround;
1007 } 1012 }
1008} 1013}
1009 1014
1010Event DateBookDBHack::eventByUID(int uid) { 1015Event DateBookDBHack::eventByUID(int uid) {
1011 1016
1012 // FIXME: Dirty Hacks to get hold of the private event lists 1017 // FIXME: Dirty Hacks to get hold of the private event lists
1013 QDate start; 1018 QDate start;
1014 QDate end=start.addDays(-1); 1019 QDate end=start.addDays(-1);
1015 QValueList<Event> myEventList=getNonRepeatingEvents(start,end); 1020 QValueList<Event> myEventList=getNonRepeatingEvents(start,end);
1016 QValueList<Event> myRepeatEvents=getRawRepeats(); 1021 QValueList<Event> myRepeatEvents=getRawRepeats();
1017 1022
1018 QValueList<Event>::ConstIterator it; 1023 QValueList<Event>::ConstIterator it;
1019 1024
1020 for (it = myEventList.begin(); it != myEventList.end(); it++) { 1025 for (it = myEventList.begin(); it != myEventList.end(); it++) {
1021 if ((*it).uid() == uid) return *it; 1026 if ((*it).uid() == uid) return *it;
1022 } 1027 }
1023 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { 1028 for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) {
1024 if ((*it).uid() == uid) return *it; 1029 if ((*it).uid() == uid) return *it;
1025 } 1030 }
1026 1031
1027 qDebug("Event not found: uid=%d\n", uid); 1032 qDebug("Event not found: uid=%d\n", uid);
1028 Event ev; 1033 Event ev;
1029 return ev; // return at least 1034 return ev; // return at least
1030} 1035}
1031 1036