summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebook.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/datebook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebook.cpp50
1 files changed, 40 insertions, 10 deletions
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp
index b7e89b0..10a9b59 100644
--- a/core/pim/datebook/datebook.cpp
+++ b/core/pim/datebook/datebook.cpp
@@ -207,49 +207,53 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f )
207 * from view() 207 * from view()
208 */ 208 */
209 if( needEvilHack ){ 209 if( needEvilHack ){
210 QTimer::singleShot( 500, this, SLOT(viewWeek()) ); 210 QTimer::singleShot( 500, this, SLOT(viewWeek()) );
211 } 211 }
212} 212}
213 213
214void DateBook::receive( const QCString &msg, const QByteArray &data ) 214void DateBook::receive( const QCString &msg, const QByteArray &data )
215{ 215{
216 QDataStream stream( data, IO_ReadOnly ); 216 QDataStream stream( data, IO_ReadOnly );
217 if ( msg == "timeChange(QString)" ) { 217 if ( msg == "timeChange(QString)" ) {
218 // update active view! 218 // update active view!
219 if ( dayAction->isOn() ) 219 if ( dayAction->isOn() )
220 viewDay(); 220 viewDay();
221 else if ( weekAction->isOn() ) 221 else if ( weekAction->isOn() )
222 viewWeek(); 222 viewWeek();
223 else if ( monthAction->isOn() ) 223 else if ( monthAction->isOn() )
224 viewMonth(); 224 viewMonth();
225 } 225 }
226 else if (msg == "editEvent(int)") { 226 else if (msg == "editEvent(int)") {
227 int uid; 227 int uid;
228 stream >> uid; 228 stream >> uid;
229 Event e=db->eventByUID(uid); 229 Event e=db->eventByUID(uid);
230 editEvent(e); 230 editEvent(e);
231 } 231 }else if (msg == "viewDefault(QDate)"){
232 QDate day;
233 stream >> day;
234 viewDefault(day);
235 }
232} 236}
233 237
234DateBook::~DateBook() 238DateBook::~DateBook()
235{ 239{
236} 240}
237 241
238void DateBook::slotSettings() 242void DateBook::slotSettings()
239{ 243{
240 DateBookSettings frmSettings( ampm, this ); 244 DateBookSettings frmSettings( ampm, this );
241 frmSettings.setStartTime( startTime ); 245 frmSettings.setStartTime( startTime );
242 frmSettings.setAlarmPreset( aPreset, presetTime ); 246 frmSettings.setAlarmPreset( aPreset, presetTime );
243 frmSettings.setJumpToCurTime( bJumpToCurTime ); 247 frmSettings.setJumpToCurTime( bJumpToCurTime );
244 frmSettings.setRowStyle( rowStyle ); 248 frmSettings.setRowStyle( rowStyle );
245 frmSettings.comboDefaultView->setCurrentItem(defaultView-1); 249 frmSettings.comboDefaultView->setCurrentItem(defaultView-1);
246 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); 250 frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig);
247 251
248 bool found=false; 252 bool found=false;
249 for (int i=0; i<(frmSettings.comboLocation->count()); i++) { 253 for (int i=0; i<(frmSettings.comboLocation->count()); i++) {
250 if ( frmSettings.comboLocation->text(i) == defaultLocation ) { 254 if ( frmSettings.comboLocation->text(i) == defaultLocation ) {
251 frmSettings.comboLocation->setCurrentItem(i); 255 frmSettings.comboLocation->setCurrentItem(i);
252 found=true; 256 found=true;
253 break; 257 break;
254 } 258 }
255 } 259 }
@@ -415,133 +419,143 @@ void DateBook::duplicateEvent( const Event &e )
415 419
416 Event dupevent(e);// Make a duplicate. 420 Event dupevent(e);// Make a duplicate.
417 421
418 // workaround added for text input. 422 // workaround added for text input.
419 QDialog editDlg( this, 0, TRUE ); 423 QDialog editDlg( this, 0, TRUE );
420 DateEntry *entry; 424 DateEntry *entry;
421 editDlg.setCaption( tr("Duplicate Event") ); 425 editDlg.setCaption( tr("Duplicate Event") );
422 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 426 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
423 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 427 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
424 sv->setResizePolicy( QScrollView::AutoOneFit ); 428 sv->setResizePolicy( QScrollView::AutoOneFit );
425 // KLUDGE!!! 429 // KLUDGE!!!
426 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 430 sv->setHScrollBarMode( QScrollView::AlwaysOff );
427 vb->addWidget( sv ); 431 vb->addWidget( sv );
428 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); 432 entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" );
429 entry->timezone->setEnabled( FALSE ); 433 entry->timezone->setEnabled( FALSE );
430 sv->addChild( entry ); 434 sv->addChild( entry );
431 435
432#if defined(Q_WS_QWS) || defined(_WS_QWS_) 436#if defined(Q_WS_QWS) || defined(_WS_QWS_)
433 editDlg.showMaximized(); 437 editDlg.showMaximized();
434#endif 438#endif
435 while (editDlg.exec() ) { 439 while (editDlg.exec() ) {
436 Event newEv = entry->event(); 440 Event newEv = entry->event();
437 QString error = checkEvent(newEv); 441 QString error = checkEvent(newEv);
438 if (!error.isNull()) { 442 if (!error.isNull()) {
439 if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) 443 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0)
440 continue; 444 continue;
441 } 445 }
446 /*
447 * The problem:
448 * DateBookDB does remove repeating events not by uid but by the time
449 * the recurrence was created
450 * so we need to update that time as well
451 */
452 Event::RepeatPattern rp = newEv.repeatPattern();
453 rp.createTime = ::time( NULL );
454 newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern...
455
442 db->addEvent(newEv); 456 db->addEvent(newEv);
443 emit newEvent(); 457 emit newEvent();
444 break; 458 break;
445 } 459 }
446} 460}
447 461
448void DateBook::editEvent( const Event &e ) 462void DateBook::editEvent( const Event &e )
449{ 463{
450 if (syncing) { 464 if (syncing) {
451 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 465 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
452 return; 466 return;
453 } 467 }
454 468
455 // workaround added for text input. 469 // workaround added for text input.
456 QDialog editDlg( this, 0, TRUE ); 470 QDialog editDlg( this, 0, TRUE );
457 DateEntry *entry; 471 DateEntry *entry;
458 editDlg.setCaption( tr("Edit Event") ); 472 editDlg.setCaption( tr("Edit Event") );
459 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 473 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
460 QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); 474 QScrollView *sv = new QScrollView( &editDlg, "scrollview" );
461 sv->setResizePolicy( QScrollView::AutoOneFit ); 475 sv->setResizePolicy( QScrollView::AutoOneFit );
462 // KLUDGE!!! 476 // KLUDGE!!!
463 sv->setHScrollBarMode( QScrollView::AlwaysOff ); 477 sv->setHScrollBarMode( QScrollView::AlwaysOff );
464 vb->addWidget( sv ); 478 vb->addWidget( sv );
465 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); 479 entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" );
466 entry->timezone->setEnabled( FALSE ); 480 entry->timezone->setEnabled( FALSE );
467 sv->addChild( entry ); 481 sv->addChild( entry );
468 482
469#if defined(Q_WS_QWS) || defined(_WS_QWS_) 483#if defined(Q_WS_QWS) || defined(_WS_QWS_)
470 editDlg.showMaximized(); 484 editDlg.showMaximized();
471#endif 485#endif
472 while (editDlg.exec() ) { 486 while (editDlg.exec() ) {
473 Event newEv = entry->event(); 487 Event newEv = entry->event();
474 if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) 488 if(newEv.description().isEmpty() && newEv.notes().isEmpty() )
475 break; 489 break;
476 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid 490 newEv.setUid(e.uid()); // FIXME: Hack not to clear uid
477 QString error = checkEvent(newEv); 491 QString error = checkEvent(newEv);
478 if (!error.isNull()) { 492 if (!error.isNull()) {
479 if (QMessageBox::warning(this, "error box", error, "Fix it", "Continue", 0, 0, 1) == 0) continue; 493 if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue;
480 } 494 }
481 db->editEvent(e, newEv); 495 db->editEvent(e, newEv);
482 emit newEvent(); 496 emit newEvent();
483 break; 497 break;
484 } 498 }
485} 499}
486 500
487void DateBook::removeEvent( const Event &e ) 501void DateBook::removeEvent( const Event &e )
488{ 502{
489 if (syncing) { 503 if (syncing) {
490 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); 504 QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") );
491 return; 505 return;
492 } 506 }
493 507
494 QString strName = e.description(); 508 QString strName = e.description();
495 509
496 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) 510 if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) )
497 return; 511 return;
498 512
499 db->removeEvent( e ); 513 db->removeEvent( e );
500 if ( views->visibleWidget() == dayView && dayView ) 514 if ( views->visibleWidget() == dayView && dayView )
501 dayView->redraw(); 515 dayView->redraw();
502} 516}
503 517
504void DateBook::addEvent( const Event &e ) 518void DateBook::addEvent( const Event &e )
505{ 519{
506 QDate d = e.start().date(); 520 QDate d = e.start().date();
507 initDay(); 521 initDay();
508 dayView->setDate( d ); 522 dayView->setDate( d );
509} 523}
510 524
511void DateBook::showDay( int year, int month, int day ) 525void DateBook::showDay( int year, int month, int day )
512{ 526{
513 QDate d(year, month, day); 527 QDate d(year, month, day);
514 view(DAY,d); 528 view(DAY,d);
515} 529}
516 530
517void DateBook::initDay() 531void DateBook::initDay()
518{ 532{
519 if ( !dayView ) { 533 if ( !dayView ) {
520 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); 534 dayView = new DateBookDay( ampm, onMonday, db, views, "day view" );
521 views->addWidget( dayView, DAY ); 535 views->addWidget( dayView, DAY );
536 dayView->setJumpToCurTime( bJumpToCurTime );
522 dayView->setStartViewTime( startTime ); 537 dayView->setStartViewTime( startTime );
523 dayView->setJumpToCurTime( bJumpToCurTime );
524 dayView->setRowStyle( rowStyle ); 538 dayView->setRowStyle( rowStyle );
525 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); 539 connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) );
526 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); 540 connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) );
527 connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); 541 connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) );
528 connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); 542 connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) );
529 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); 543 connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) );
530 connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) ); 544 connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) );
531 connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) ); 545 connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) );
532 } 546 }
533} 547}
534 548
535void DateBook::initWeek() 549void DateBook::initWeek()
536{ 550{
537 if ( !weekView ) { 551 if ( !weekView ) {
538 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); 552 weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" );
539 weekView->setStartViewTime( startTime ); 553 weekView->setStartViewTime( startTime );
540 views->addWidget( weekView, WEEK ); 554 views->addWidget( weekView, WEEK );
541 connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); 555 connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) );
542 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); 556 connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) );
543 } 557 }
544 558
545 //But also get it right: the year that we display can be different 559 //But also get it right: the year that we display can be different
546 //from the year of the current date. So, first find the year 560 //from the year of the current date. So, first find the year
547 //number of the current week. 561 //number of the current week.
@@ -676,74 +690,90 @@ void DateBook::appMessage(const QCString& msg, const QByteArray& data)
676 alarmCounter = 0; 690 alarmCounter = 0;
677 stopTimer = startTimer( 5000 ); 691 stopTimer = startTimer( 5000 );
678 } 692 }
679 QDialog dlg( this, 0, TRUE ); 693 QDialog dlg( this, 0, TRUE );
680 QVBoxLayout *vb = new QVBoxLayout( &dlg ); 694 QVBoxLayout *vb = new QVBoxLayout( &dlg );
681 QScrollView *view = new QScrollView( &dlg, "scrollView"); 695 QScrollView *view = new QScrollView( &dlg, "scrollView");
682 view->setResizePolicy( QScrollView::AutoOneFit ); 696 view->setResizePolicy( QScrollView::AutoOneFit );
683 vb->addWidget( view ); 697 vb->addWidget( view );
684 QLabel *lblMsg = new QLabel( msg, &dlg ); 698 QLabel *lblMsg = new QLabel( msg, &dlg );
685 view->addChild( lblMsg ); 699 view->addChild( lblMsg );
686 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); 700 QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg );
687 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); 701 connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) );
688 vb->addWidget( cmdOk ); 702 vb->addWidget( cmdOk );
689 703
690#if defined(Q_WS_QWS) || defined(_WS_QWS_) 704#if defined(Q_WS_QWS) || defined(_WS_QWS_)
691 dlg.showMaximized(); 705 dlg.showMaximized();
692#endif 706#endif
693 needShow = dlg.exec(); 707 needShow = dlg.exec();
694 708
695 if ( bSound ) 709 if ( bSound )
696 killTimer( stopTimer ); 710 killTimer( stopTimer );
697 } 711 }
698 } 712 }
699 } else if ( msg == "nextView()" ) { 713 } else if ( msg == "nextView()" ) {
714 needShow = true;
700 if ( !qApp-> activeWindow ( )) { 715 if ( !qApp-> activeWindow ( )) {
701 needShow = TRUE; 716 needShow = TRUE;
702 } else { 717 } else {
703 QWidget* cur = views->visibleWidget(); 718 QWidget* cur = views->visibleWidget();
704 if ( cur ) { 719 if ( cur ) {
705 if ( cur == dayView ) 720 if ( cur == dayView )
706 viewWeek(); 721 viewWeek();
707 else if ( cur == weekView ) 722 else if ( cur == weekView )
708 viewWeekLst(); 723 viewWeekLst();
709 else if ( cur == weekLstView ) 724 else if ( cur == weekLstView )
710 viewMonth(); 725 viewMonth();
711 else if ( cur == monthView ) 726 else if ( cur == monthView )
712 viewDay(); 727 viewDay();
713 needShow = TRUE; 728 needShow = TRUE;
714 } 729 }
715 } 730 }
716 } 731 } else if (msg == "editEvent(int)") {
732 /* simple copy from receive */
733 QDataStream stream(data,IO_ReadOnly);
734 int uid;
735 stream >> uid;
736 Event e=db->eventByUID(uid);
737 editEvent(e);
738 } else if (msg == "viewDefault(QDate)"){
739 /* simple copy from receive */
740 QDataStream stream(data,IO_ReadOnly);
741 QDate day;
742 stream >> day;
743 viewDefault(day);
744 needShow = true;
745 }
746
717 if ( needShow ) { 747 if ( needShow ) {
718#if defined(Q_WS_QWS) || defined(_WS_QWS_) 748#if defined(Q_WS_QWS) || defined(_WS_QWS_)
719 showMaximized(); 749 // showMaximized();
720#else 750#else
721 show(); 751 // show();
722#endif 752#endif
723 raise(); 753 // raise();
724 QPEApplication::setKeepRunning(); 754 QPEApplication::setKeepRunning();
725 setActiveWindow(); 755 // setActiveWindow();
726 } 756 }
727} 757}
728 758
729void DateBook::reload() 759void DateBook::reload()
730{ 760{
731 db->reload(); 761 db->reload();
732 if ( dayAction->isOn() ) viewDay(); 762 if ( dayAction->isOn() ) viewDay();
733 else if ( weekAction->isOn() ) viewWeek(); 763 else if ( weekAction->isOn() ) viewWeek();
734 else if ( monthAction->isOn() ) viewMonth(); 764 else if ( monthAction->isOn() ) viewMonth();
735 syncing = FALSE; 765 syncing = FALSE;
736} 766}
737 767
738void DateBook::flush() 768void DateBook::flush()
739{ 769{
740 syncing = TRUE; 770 syncing = TRUE;
741 db->save(); 771 db->save();
742} 772}
743 773
744void DateBook::timerEvent( QTimerEvent *e ) 774void DateBook::timerEvent( QTimerEvent *e )
745{ 775{
746 if ( alarmCounter < 10 ) { 776 if ( alarmCounter < 10 ) {
747 alarmCounter++; 777 alarmCounter++;
748 Sound::soundAlarm(); 778 Sound::soundAlarm();
749 } else { 779 } else {
@@ -896,49 +926,49 @@ void DateBook::setDocument( const QString &filename )
896static const char * beamfile = "/tmp/obex/event.vcs"; 926static const char * beamfile = "/tmp/obex/event.vcs";
897 927
898void DateBook::beamEvent( const Event &e ) 928void DateBook::beamEvent( const Event &e )
899{ 929{
900 qDebug("trying to beamn"); 930 qDebug("trying to beamn");
901 unlink( beamfile ); // delete if exists 931 unlink( beamfile ); // delete if exists
902 mkdir("/tmp/obex/", 0755); 932 mkdir("/tmp/obex/", 0755);
903 Event::writeVCalendar( beamfile, e ); 933 Event::writeVCalendar( beamfile, e );
904 Ir *ir = new Ir( this ); 934 Ir *ir = new Ir( this );
905 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 935 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
906 QString description = e.description(); 936 QString description = e.description();
907 ir->send( beamfile, description, "text/x-vCalendar" ); 937 ir->send( beamfile, description, "text/x-vCalendar" );
908} 938}
909 939
910void DateBook::beamDone( Ir *ir ) 940void DateBook::beamDone( Ir *ir )
911{ 941{
912 delete ir; 942 delete ir;
913 unlink( beamfile ); 943 unlink( beamfile );
914} 944}
915 945
916void DateBook::slotFind() 946void DateBook::slotFind()
917{ 947{
918 // move it to the day view... 948 // move it to the day view...
919 viewDay(); 949 viewDay();
920 FindDialog frmFind( "Calendar", this ); 950 FindDialog frmFind( "Calendar", this ); // no tr needed
921 frmFind.setUseDate( true ); 951 frmFind.setUseDate( true );
922 frmFind.setDate( currentDate() ); 952 frmFind.setDate( currentDate() );
923 QObject::connect( &frmFind, 953 QObject::connect( &frmFind,
924 SIGNAL(signalFindClicked(const QString&, const QDate&, 954 SIGNAL(signalFindClicked(const QString&, const QDate&,
925 bool, bool, int)), 955 bool, bool, int)),
926 this, 956 this,
927 SLOT(slotDoFind(const QString&, const QDate&, 957 SLOT(slotDoFind(const QString&, const QDate&,
928 bool, bool, int)) ); 958 bool, bool, int)) );
929 QObject::connect( this, 959 QObject::connect( this,
930 SIGNAL(signalNotFound()), 960 SIGNAL(signalNotFound()),
931 &frmFind, 961 &frmFind,
932 SLOT(slotNotFound()) ); 962 SLOT(slotNotFound()) );
933 QObject::connect( this, 963 QObject::connect( this,
934 SIGNAL(signalWrapAround()), 964 SIGNAL(signalWrapAround()),
935 &frmFind, 965 &frmFind,
936 SLOT(slotWrapAround()) ); 966 SLOT(slotWrapAround()) );
937 frmFind.move(0,0); 967 frmFind.move(0,0);
938 frmFind.exec(); 968 frmFind.exec();
939 inSearch = false; 969 inSearch = false;
940} 970}
941 971
942bool catComp( QArray<int> cats, int category ) 972bool catComp( QArray<int> cats, int category )
943{ 973{
944 bool returnMe; 974 bool returnMe;