-rw-r--r-- | core/pim/todo/mainwindow.cpp | 120 |
1 files changed, 102 insertions, 18 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 5119ae0..6725951 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -62,24 +62,25 @@ | |||
62 | #include "textviewshow.h" | 62 | #include "textviewshow.h" |
63 | #include "todoeditor.h" | 63 | #include "todoeditor.h" |
64 | #include "mainwindow.h" | 64 | #include "mainwindow.h" |
65 | 65 | ||
66 | 66 | ||
67 | using namespace Todo; | 67 | using namespace Todo; |
68 | 68 | ||
69 | MainWindow::MainWindow( QWidget* parent, | 69 | MainWindow::MainWindow( QWidget* parent, |
70 | const char* name ) | 70 | const char* name ) |
71 | : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) | 71 | : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) |
72 | { | 72 | { |
73 | m_syncing = false; | 73 | m_syncing = false; |
74 | m_showing = false; | ||
74 | m_counter = 0; | 75 | m_counter = 0; |
75 | m_tempManager = new TemplateManager(); | 76 | m_tempManager = new TemplateManager(); |
76 | m_tempManager->load(); | 77 | m_tempManager->load(); |
77 | 78 | ||
78 | initUI(); | 79 | initUI(); |
79 | initConfig(); | 80 | initConfig(); |
80 | initViews(); | 81 | initViews(); |
81 | initActions(); | 82 | initActions(); |
82 | initEditor(); | 83 | initEditor(); |
83 | initShow(); | 84 | initShow(); |
84 | initTemplate(); | 85 | initTemplate(); |
85 | 86 | ||
@@ -152,32 +153,35 @@ void MainWindow::initActions() { | |||
152 | m_duplicateAction = a; | 153 | m_duplicateAction = a; |
153 | 154 | ||
154 | m_edit->insertSeparator(); | 155 | m_edit->insertSeparator(); |
155 | 156 | ||
156 | if ( Ir::supported() ) { | 157 | if ( Ir::supported() ) { |
157 | a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); | 158 | a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); |
158 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | 159 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); |
159 | a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) ); | 160 | a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) ); |
160 | a->addTo( m_edit ); | 161 | a->addTo( m_edit ); |
161 | a->addTo( m_tool ); | 162 | a->addTo( m_tool ); |
162 | } | 163 | } |
163 | 164 | ||
165 | #if 0 | ||
164 | // Options menu | 166 | // Options menu |
165 | a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), | 167 | a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), |
166 | QString::null, 0, this, 0 ); | 168 | QString::null, 0, this, 0 ); |
167 | connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); | 169 | connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); |
168 | a->addTo( m_options ); | 170 | a->addTo( m_options ); |
169 | m_findAction = a; | 171 | m_findAction = a; |
170 | 172 | ||
173 | |||
171 | m_options->insertSeparator(); | 174 | m_options->insertSeparator(); |
175 | #endif | ||
172 | 176 | ||
173 | m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), | 177 | m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), |
174 | 0, this, 0, TRUE ); | 178 | 0, this, 0, TRUE ); |
175 | m_completedAction->addTo( m_options ); | 179 | m_completedAction->addTo( m_options ); |
176 | m_completedAction->setOn( showCompleted() ); | 180 | m_completedAction->setOn( showCompleted() ); |
177 | connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) ); | 181 | connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) ); |
178 | 182 | ||
179 | a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), | 183 | a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), |
180 | 0, this, 0, TRUE ); | 184 | 0, this, 0, TRUE ); |
181 | a->addTo( m_options ); | 185 | a->addTo( m_options ); |
182 | a->setOn( showOverDue() ); | 186 | a->setOn( showOverDue() ); |
183 | connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); | 187 | connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); |
@@ -343,24 +347,25 @@ Editor* MainWindow::currentEditor() { | |||
343 | return m_curEdit; | 347 | return m_curEdit; |
344 | } | 348 | } |
345 | TodoShow* MainWindow::currentShow() { | 349 | TodoShow* MainWindow::currentShow() { |
346 | return m_curShow; | 350 | return m_curShow; |
347 | } | 351 | } |
348 | void MainWindow::slotReload() { | 352 | void MainWindow::slotReload() { |
349 | m_todoMgr.reload(); | 353 | m_todoMgr.reload(); |
350 | currentView()->updateView( ); | 354 | currentView()->updateView( ); |
351 | raiseCurrentView(); | 355 | raiseCurrentView(); |
352 | } | 356 | } |
353 | void MainWindow::closeEvent( QCloseEvent* e ) { | 357 | void MainWindow::closeEvent( QCloseEvent* e ) { |
354 | if (m_stack->visibleWidget() == currentShow()->widget() ) { | 358 | if (m_stack->visibleWidget() == currentShow()->widget() ) { |
359 | m_showing = false; | ||
355 | raiseCurrentView(); | 360 | raiseCurrentView(); |
356 | e->ignore(); | 361 | e->ignore(); |
357 | return; | 362 | return; |
358 | } | 363 | } |
359 | /* | 364 | /* |
360 | * we should have flushed and now we're still saving | 365 | * we should have flushed and now we're still saving |
361 | * so there is no need to flush | 366 | * so there is no need to flush |
362 | */ | 367 | */ |
363 | if (m_syncing ) { | 368 | if (m_syncing ) { |
364 | e->accept(); | 369 | e->accept(); |
365 | return; | 370 | return; |
366 | } | 371 | } |
@@ -400,102 +405,120 @@ void MainWindow::closeEvent( QCloseEvent* e ) { | |||
400 | } | 405 | } |
401 | void MainWindow::populateTemplates() { | 406 | void MainWindow::populateTemplates() { |
402 | m_template->clear(); | 407 | m_template->clear(); |
403 | QStringList list = templateManager()->templates(); | 408 | QStringList list = templateManager()->templates(); |
404 | QStringList::Iterator it; | 409 | QStringList::Iterator it; |
405 | for ( it = list.begin(); it != list.end(); ++it ) { | 410 | for ( it = list.begin(); it != list.end(); ++it ) { |
406 | m_template->insertItem( (*it) ); | 411 | m_template->insertItem( (*it) ); |
407 | } | 412 | } |
408 | } | 413 | } |
409 | /* | 414 | /* |
410 | * slotNewFromTemplate | 415 | * slotNewFromTemplate |
411 | * We use the edit widget to do | 416 | * We use the edit widget to do |
412 | * the config but we setUid(-1) | 417 | * the config but we setUid(1) |
413 | * to get a new uid | 418 | * to get a new uid |
414 | */ | 419 | */ |
415 | /* | 420 | /* |
416 | * first we get the name of the template | 421 | * first we get the name of the template |
417 | * then we will use the TemplateManager | 422 | * then we will use the TemplateManager |
418 | */ | 423 | */ |
419 | void MainWindow::slotNewFromTemplate( int id ) { | 424 | void MainWindow::slotNewFromTemplate( int id ) { |
420 | QString name = m_template->text( id ); | 425 | QString name = m_template->text( id ); |
421 | 426 | ||
422 | OTodo event = templateManager()->templateEvent( name ); | 427 | OTodo event = templateManager()->templateEvent( name ); |
423 | event = currentEditor()->edit(this, | 428 | event = currentEditor()->edit(this, |
424 | event ); | 429 | event ); |
425 | 430 | ||
426 | if ( currentEditor()->accepted() ) { | 431 | if ( currentEditor()->accepted() ) { |
427 | /* assign new todo */ | 432 | /* assign new todo */ |
428 | event.setUid( -1 ); | 433 | event.setUid( 1 ); |
429 | currentView()->addEvent( event ); | 434 | handleAlarms( OTodo(), event ); |
430 | m_todoMgr.add( event ); | 435 | m_todoMgr.add( event ); |
436 | currentView()->addEvent( event ); | ||
431 | 437 | ||
432 | populateCategories(); | 438 | populateCategories(); |
433 | } | 439 | } |
440 | raiseCurrentView(); | ||
434 | } | 441 | } |
435 | void MainWindow::slotNew() { | 442 | void MainWindow::slotNew() { |
436 | create(); | 443 | create(); |
437 | } | 444 | } |
438 | void MainWindow::slotDuplicate() { | 445 | void MainWindow::slotDuplicate() { |
439 | if(m_syncing) { | 446 | if(m_syncing) { |
440 | QMessageBox::warning(this, QWidget::tr("Todo"), | 447 | QMessageBox::warning(this, QWidget::tr("Todo"), |
441 | QWidget::tr("Can not edit data, currently syncing")); | 448 | QWidget::tr("Data can not be edited, currently syncing")); |
442 | return; | 449 | return; |
443 | } | 450 | } |
444 | OTodo ev = m_todoMgr.event( currentView()->current() ); | 451 | OTodo ev = m_todoMgr.event( currentView()->current() ); |
445 | /* let's generate a new uid */ | 452 | /* let's generate a new uid */ |
446 | ev.setUid(-1); | 453 | ev.setUid(1); |
447 | m_todoMgr.add( ev ); | 454 | m_todoMgr.add( ev ); |
448 | 455 | ||
449 | currentView()->addEvent( ev ); | 456 | currentView()->addEvent( ev ); |
450 | raiseCurrentView(); | 457 | raiseCurrentView(); |
451 | } | 458 | } |
452 | void MainWindow::slotDelete() { | 459 | void MainWindow::slotDelete() { |
453 | if (!currentView()->current() ) | 460 | if (!currentView()->current() ) |
454 | return; | 461 | return; |
455 | 462 | ||
456 | if(m_syncing) { | 463 | if(m_syncing) { |
457 | QMessageBox::warning(this, QWidget::tr("Todo"), | 464 | QMessageBox::warning(this, QWidget::tr("Todo"), |
458 | QWidget::tr("Can not edit data, currently syncing")); | 465 | QWidget::tr("Data can not be edited, currently syncing")); |
459 | return; | 466 | return; |
460 | } | 467 | } |
461 | QString strName = currentView()->currentRepresentation(); | 468 | QString strName = currentView()->currentRepresentation(); |
462 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) | 469 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) |
463 | return; | 470 | return; |
464 | 471 | ||
465 | handleAlarms( OTodo(), m_todoMgr.event( currentView()->current() ) ); | 472 | handleAlarms( m_todoMgr.event( currentView()->current() ), OTodo() ); |
466 | m_todoMgr.remove( currentView()->current() ); | 473 | m_todoMgr.remove( currentView()->current() ); |
467 | currentView()->removeEvent( currentView()->current() ); | 474 | currentView()->removeEvent( currentView()->current() ); |
468 | raiseCurrentView(); | 475 | raiseCurrentView(); |
469 | } | 476 | } |
477 | void MainWindow::slotDelete(int uid ) { | ||
478 | if( uid == 0 ) return; | ||
479 | if(m_syncing) { | ||
480 | QMessageBox::warning(this, QWidget::tr("Todo"), | ||
481 | QWidget::tr("Data can not be edited, currently syncing")); | ||
482 | return; | ||
483 | } | ||
484 | OTodo to = m_todoMgr.event(uid); | ||
485 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) | ||
486 | return; | ||
487 | |||
488 | handleAlarms(to, OTodo() ); | ||
489 | m_todoMgr.remove( to.uid() ); | ||
490 | currentView()->removeEvent( to.uid() ); | ||
491 | raiseCurrentView(); | ||
492 | } | ||
470 | void MainWindow::slotDeleteAll() { | 493 | void MainWindow::slotDeleteAll() { |
471 | if(m_syncing) { | 494 | if(m_syncing) { |
472 | QMessageBox::warning(this, QWidget::tr("Todo"), | 495 | QMessageBox::warning(this, QWidget::tr("Todo"), |
473 | QWidget::tr("Can not edit data, currently syncing")); | 496 | QWidget::tr("Data can not be edited, currently syncing")); |
474 | return; | 497 | return; |
475 | } | 498 | } |
476 | 499 | ||
477 | 500 | ||
478 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) | 501 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) |
479 | return; | 502 | return; |
480 | 503 | ||
481 | m_todoMgr.removeAll(); | 504 | m_todoMgr.removeAll(); |
482 | currentView()->clear(); | 505 | currentView()->clear(); |
483 | 506 | ||
484 | raiseCurrentView(); | 507 | raiseCurrentView(); |
485 | } | 508 | } |
486 | void MainWindow::slotDeleteCompleted() { | 509 | void MainWindow::slotDeleteCompleted() { |
487 | if(m_syncing) { | 510 | if(m_syncing) { |
488 | QMessageBox::warning(this, QWidget::tr("Todo"), | 511 | QMessageBox::warning(this, QWidget::tr("Todo"), |
489 | QWidget::tr("Can not edit data, currently syncing")); | 512 | QWidget::tr("Data can not be edited, currently syncing")); |
490 | return; | 513 | return; |
491 | } | 514 | } |
492 | 515 | ||
493 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) | 516 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) |
494 | return; | 517 | return; |
495 | 518 | ||
496 | 519 | ||
497 | m_todoMgr.removeCompleted(); | 520 | m_todoMgr.removeCompleted(); |
498 | currentView()->updateView( ); | 521 | currentView()->updateView( ); |
499 | } | 522 | } |
500 | void MainWindow::slotFind() { | 523 | void MainWindow::slotFind() { |
501 | 524 | ||
@@ -557,40 +580,44 @@ void MainWindow::setDocument( const QString& fi) { | |||
557 | } | 580 | } |
558 | 581 | ||
559 | static const char *beamfile = "/tmp/opie-todo.vcs"; | 582 | static const char *beamfile = "/tmp/opie-todo.vcs"; |
560 | void MainWindow::slotBeam() { | 583 | void MainWindow::slotBeam() { |
561 | beam( currentView()->current() ); | 584 | beam( currentView()->current() ); |
562 | } | 585 | } |
563 | void MainWindow::beamDone( Ir* ir) { | 586 | void MainWindow::beamDone( Ir* ir) { |
564 | delete ir; | 587 | delete ir; |
565 | ::unlink( beamfile ); | 588 | ::unlink( beamfile ); |
566 | } | 589 | } |
567 | void MainWindow::receiveFile( const QString& filename ) { | 590 | void MainWindow::receiveFile( const QString& filename ) { |
568 | OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); | 591 | OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); |
592 | |||
569 | OTodoAccess acc( cal ); | 593 | OTodoAccess acc( cal ); |
570 | acc.load(); | 594 | acc.load(); |
571 | OTodoAccess::List list = acc.allRecords(); | 595 | OTodoAccess::List list = acc.allRecords(); |
572 | 596 | ||
597 | if (list.count()){ | ||
598 | |||
573 | QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); | 599 | QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); |
574 | 600 | ||
575 | if ( QMessageBox::information(this, QWidget::tr("New Tasks"), | 601 | if ( QMessageBox::information(this, QWidget::tr("New Tasks"), |
576 | message, QMessageBox::Ok, | 602 | message, QMessageBox::Ok, |
577 | QMessageBox::Cancel ) == QMessageBox::Ok ) { | 603 | QMessageBox::Cancel ) == QMessageBox::Ok ) { |
578 | OTodoAccess::List::Iterator it; | 604 | OTodoAccess::List::Iterator it; |
579 | for ( it = list.begin(); it != list.end(); ++it ) | 605 | for ( it = list.begin(); it != list.end(); ++it ) |
580 | m_todoMgr.add( (*it) ); | 606 | m_todoMgr.add( (*it) ); |
581 | 607 | ||
582 | currentView()->updateView(); | 608 | currentView()->updateView(); |
583 | } | 609 | } |
584 | } | 610 | } |
611 | } | ||
585 | 612 | ||
586 | void MainWindow::slotFlush() { | 613 | void MainWindow::slotFlush() { |
587 | m_syncing = FALSE; | 614 | m_syncing = FALSE; |
588 | m_todoMgr.save(); | 615 | m_todoMgr.save(); |
589 | } | 616 | } |
590 | void MainWindow::slotShowDetails() { | 617 | void MainWindow::slotShowDetails() { |
591 | slotShow( currentView()->current() ); | 618 | slotShow( currentView()->current() ); |
592 | } | 619 | } |
593 | /* | 620 | /* |
594 | * populate the Categories | 621 | * populate the Categories |
595 | * Menu | 622 | * Menu |
596 | */ | 623 | */ |
@@ -625,51 +652,68 @@ bool MainWindow::showQuickTask()const { | |||
625 | return m_quicktask; | 652 | return m_quicktask; |
626 | } | 653 | } |
627 | QString MainWindow::currentCategory()const { | 654 | QString MainWindow::currentCategory()const { |
628 | return m_curCat; | 655 | return m_curCat; |
629 | } | 656 | } |
630 | int MainWindow::currentCatId() { | 657 | int MainWindow::currentCatId() { |
631 | return m_todoMgr.catId( m_curCat ); | 658 | return m_todoMgr.catId( m_curCat ); |
632 | } | 659 | } |
633 | ViewBase* MainWindow::currentView() { | 660 | ViewBase* MainWindow::currentView() { |
634 | return m_curView; | 661 | return m_curView; |
635 | } | 662 | } |
636 | void MainWindow::raiseCurrentView() { | 663 | void MainWindow::raiseCurrentView() { |
664 | // due QPE/Application/todolist show(int) | ||
665 | // we might not have the populateCategories slot called once | ||
666 | // we would show the otodo but then imediately switch to the currentView | ||
667 | // if we're initially showing we shouldn't raise the table | ||
668 | // in returnFromView we fix up m_showing | ||
669 | if (m_showing ) return; | ||
670 | |||
637 | m_stack->raiseWidget( m_curView->widget() ); | 671 | m_stack->raiseWidget( m_curView->widget() ); |
638 | } | 672 | } |
639 | void MainWindow::slotShowDue(bool ov) { | 673 | void MainWindow::slotShowDue(bool ov) { |
640 | m_overdue = ov; | 674 | m_overdue = ov; |
641 | currentView()->showOverDue( ov ); | 675 | currentView()->showOverDue( ov ); |
642 | raiseCurrentView(); | 676 | raiseCurrentView(); |
643 | } | 677 | } |
644 | void MainWindow::slotShow( int uid ) { | 678 | void MainWindow::slotShow( int uid ) { |
679 | if ( uid == 0 ) return; | ||
645 | qWarning("slotShow"); | 680 | qWarning("slotShow"); |
646 | currentShow()->slotShow( event( uid ) ); | 681 | currentShow()->slotShow( event( uid ) ); |
647 | m_stack->raiseWidget( currentShow()->widget() ); | 682 | m_stack->raiseWidget( currentShow()->widget() ); |
648 | } | 683 | } |
684 | void MainWindow::slotShowNext() { | ||
685 | int l = currentView()->next(); | ||
686 | if (l!=0) | ||
687 | slotShow(l); | ||
688 | } | ||
689 | void MainWindow::slotShowPrev() { | ||
690 | int l = currentView()->prev(); | ||
691 | if (l!=0) | ||
692 | slotShow(l); | ||
693 | } | ||
649 | void MainWindow::slotEdit( int uid ) { | 694 | void MainWindow::slotEdit( int uid ) { |
650 | if (uid == 1 ) return; | 695 | if (uid == 0 ) return; |
651 | if(m_syncing) { | 696 | if(m_syncing) { |
652 | QMessageBox::warning(this, QWidget::tr("Todo"), | 697 | QMessageBox::warning(this, QWidget::tr("Todo"), |
653 | QWidget::tr("Can not edit data, currently syncing")); | 698 | QWidget::tr("Data can't be edited, currently syncing")); |
654 | return; | 699 | return; |
655 | } | 700 | } |
656 | 701 | ||
657 | OTodo old_todo = m_todoMgr.event( uid ); | 702 | OTodo old_todo = m_todoMgr.event( uid ); |
658 | 703 | ||
659 | OTodo todo = currentEditor()->edit(this, old_todo ); | 704 | OTodo todo = currentEditor()->edit(this, old_todo ); |
660 | 705 | ||
661 | /* if completed */ | 706 | /* if completed */ |
662 | if ( currentEditor()->accepted() ) { | 707 | if ( currentEditor()->accepted() ) { |
663 | qWarning("Replacing now" ); | ||
664 | handleAlarms( old_todo, todo ); | 708 | handleAlarms( old_todo, todo ); |
665 | m_todoMgr.update( todo.uid(), todo ); | 709 | m_todoMgr.update( todo.uid(), todo ); |
666 | currentView()->replaceEvent( todo ); | 710 | currentView()->replaceEvent( todo ); |
667 | /* a Category might have changed */ | 711 | /* a Category might have changed */ |
668 | populateCategories(); | 712 | populateCategories(); |
669 | } | 713 | } |
670 | 714 | ||
671 | raiseCurrentView(); | 715 | raiseCurrentView(); |
672 | } | 716 | } |
673 | /* | 717 | /* |
674 | void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { | 718 | void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { |
675 | m_todoMgr.update( uid, ev ); | 719 | m_todoMgr.update( uid, ev ); |
@@ -709,78 +753,106 @@ void MainWindow::slotComplete( int uid ) { | |||
709 | } | 753 | } |
710 | void MainWindow::slotComplete( const OTodo& todo ) { | 754 | void MainWindow::slotComplete( const OTodo& todo ) { |
711 | OTodo to = todo; | 755 | OTodo to = todo; |
712 | to.setCompleted( !to.isCompleted() ); | 756 | to.setCompleted( !to.isCompleted() ); |
713 | to.setCompletedDate( QDate::currentDate() ); | 757 | to.setCompletedDate( QDate::currentDate() ); |
714 | 758 | ||
715 | /* | 759 | /* |
716 | * if the item does recur | 760 | * if the item does recur |
717 | * we need to spin it off | 761 | * we need to spin it off |
718 | * and update the items duedate to the next | 762 | * and update the items duedate to the next |
719 | * possible recurrance of this item... | 763 | * possible recurrance of this item... |
720 | * the spinned off one will loose the | 764 | * the spinned off one will loose the |
765 | * recurrence. | ||
766 | * We calculate the difference between the old due date and the | ||
767 | * new one and add this diff to start, completed and alarm dates | ||
768 | * -zecke | ||
721 | */ | 769 | */ |
722 | if ( to.hasRecurrence() && to.isCompleted() ) { | 770 | if ( to.hasRecurrence() && to.isCompleted() ) { |
723 | OTodo to2( to ); | 771 | OTodo to2( to ); |
724 | 772 | ||
725 | /* the spinned off one won't recur anymore */ | 773 | /* the spinned off one won't recur anymore */ |
726 | to.setRecurrence( ORecur() ); | 774 | to.setRecurrence( ORecur() ); |
727 | 775 | ||
728 | ORecur rec = to2.recurrence(); | 776 | ORecur rec = to2.recurrence(); |
729 | rec.setStart( to.dueDate() ); | 777 | rec.setStart( to.dueDate() ); |
730 | to2.setRecurrence( rec ); | 778 | to2.setRecurrence( rec ); |
731 | /* | 779 | /* |
732 | * if there is a next occurence | 780 | * if there is a next occurence |
733 | * from the duedate of the last recurrance | 781 | * from the duedate of the last recurrance |
734 | */ | 782 | */ |
735 | QDate date; | 783 | QDate date; |
736 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { | 784 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { |
785 | int dayDiff = to.dueDate().daysTo( date ); | ||
786 | qWarning("day diff is %d", dayDiff ); | ||
737 | QDate inval; | 787 | QDate inval; |
738 | /* generate a new uid for the old record */ | 788 | /* generate a new uid for the old record */ |
739 | to.setUid( 1 ); | 789 | to.setUid( 1 ); |
740 | 790 | ||
741 | /* add the old one cause it has a new UID here cause it was spin off */ | 791 | /* add the old one cause it has a new UID here cause it was spin off */ |
742 | m_todoMgr.add( to ); | 792 | m_todoMgr.add( to ); |
743 | 793 | ||
744 | /* | 794 | /* |
745 | * update the due date | 795 | * update the due date |
746 | * start date | 796 | * start date |
747 | * and complete date | 797 | * and complete date |
748 | */ | 798 | */ |
749 | to2.setDueDate( date ); | 799 | to2.setDueDate( date ); |
750 | to2.setStartDate( inval ); | 800 | rec.setStart( date ); |
801 | to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week | ||
802 | |||
803 | /* move start date */ | ||
804 | if (to2.hasStartDate() ) | ||
805 | to2.setStartDate( to2.startDate().addDays( dayDiff ) ); | ||
806 | |||
807 | /* now the alarms */ | ||
808 | if (to2.hasNotifiers() ) { | ||
809 | OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); | ||
810 | OPimNotifyManager::Alarms als; | ||
811 | |||
812 | /* for every alarm move the day */ | ||
813 | for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { | ||
814 | OPimAlarm al = (*it); | ||
815 | al.setDateTime( al.dateTime().addDays( dayDiff ) ); | ||
816 | als.append( al ); | ||
817 | } | ||
818 | to2.notifiers().setAlarms( als ); | ||
819 | handleAlarms( OTodo(), todo ); | ||
820 | } | ||
751 | to2.setCompletedDate( inval ); | 821 | to2.setCompletedDate( inval ); |
752 | to2.setCompleted( false ); | 822 | to2.setCompleted( false ); |
823 | |||
753 | updateTodo( to2 ); | 824 | updateTodo( to2 ); |
754 | }else | 825 | }else |
755 | updateTodo( to ); | 826 | updateTodo( to ); |
756 | }else | 827 | }else |
757 | updateTodo( to ); | 828 | updateTodo( to ); |
758 | 829 | ||
759 | currentView()->updateView(); | 830 | currentView()->updateView(); |
760 | raiseCurrentView(); | 831 | raiseCurrentView(); |
761 | } | 832 | } |
762 | void MainWindow::flush() { | 833 | void MainWindow::flush() { |
763 | slotFlush(); | 834 | slotFlush(); |
764 | } | 835 | } |
765 | void MainWindow::reload() { | 836 | void MainWindow::reload() { |
766 | slotReload(); | 837 | slotReload(); |
767 | } | 838 | } |
768 | int MainWindow::create() { | 839 | int MainWindow::create() { |
769 | int uid = 0; | 840 | int uid = 0; |
770 | if(m_syncing) { | 841 | if(m_syncing) { |
771 | QMessageBox::warning(this, QWidget::tr("Todo"), | 842 | QMessageBox::warning(this, QWidget::tr("Todo"), |
772 | QWidget::tr("Can not edit data, currently syncing")); | 843 | QWidget::tr("Data can not be edited, currently syncing")); |
773 | return uid; | 844 | return uid; |
774 | } | 845 | } |
846 | m_todoMgr.load(); | ||
775 | 847 | ||
776 | 848 | ||
777 | OTodo todo = currentEditor()->newTodo( currentCatId(), | 849 | OTodo todo = currentEditor()->newTodo( currentCatId(), |
778 | this ); | 850 | this ); |
779 | 851 | ||
780 | if ( currentEditor()->accepted() ) { | 852 | if ( currentEditor()->accepted() ) { |
781 | //todo.assignUid(); | 853 | //todo.assignUid(); |
782 | uid = todo.uid(); | 854 | uid = todo.uid(); |
783 | handleAlarms( OTodo(), todo ); | 855 | handleAlarms( OTodo(), todo ); |
784 | m_todoMgr.add( todo ); | 856 | m_todoMgr.add( todo ); |
785 | currentView()->addEvent( todo ); | 857 | currentView()->addEvent( todo ); |
786 | 858 | ||
@@ -795,57 +867,68 @@ int MainWindow::create() { | |||
795 | return uid; | 867 | return uid; |
796 | } | 868 | } |
797 | /* delete it silently... */ | 869 | /* delete it silently... */ |
798 | bool MainWindow::remove( int uid ) { | 870 | bool MainWindow::remove( int uid ) { |
799 | if (m_syncing) return false; | 871 | if (m_syncing) return false; |
800 | 872 | ||
801 | /* argh need to get the whole OEvent... to disable alarms -zecke */ | 873 | /* argh need to get the whole OEvent... to disable alarms -zecke */ |
802 | handleAlarms( OTodo(), m_todoMgr.event( uid ) ); | 874 | handleAlarms( OTodo(), m_todoMgr.event( uid ) ); |
803 | 875 | ||
804 | return m_todoMgr.remove( uid ); | 876 | return m_todoMgr.remove( uid ); |
805 | } | 877 | } |
806 | void MainWindow::beam( int uid) { | 878 | void MainWindow::beam( int uid) { |
879 | if( uid == 0 ) return; | ||
880 | |||
807 | ::unlink( beamfile ); | 881 | ::unlink( beamfile ); |
882 | m_todoMgr.load(); | ||
883 | |||
808 | OTodo todo = event( uid ); | 884 | OTodo todo = event( uid ); |
809 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); | 885 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); |
810 | OTodoAccess acc( cal ); | 886 | OTodoAccess acc( cal ); |
811 | acc.load(); | 887 | acc.load(); |
812 | acc.add( todo ); | 888 | acc.add( todo ); |
813 | acc.save(); | 889 | acc.save(); |
814 | Ir* ir = new Ir(this ); | 890 | Ir* ir = new Ir(this ); |
815 | connect(ir, SIGNAL(done(Ir*) ), | 891 | connect(ir, SIGNAL(done(Ir*) ), |
816 | this, SLOT(beamDone(Ir*) ) ); | 892 | this, SLOT(beamDone(Ir*) ) ); |
817 | ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); | 893 | ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); |
818 | } | 894 | } |
819 | void MainWindow::show( int uid ) { | 895 | void MainWindow::show( int uid ) { |
896 | m_todoMgr.load(); // might not be loaded yet | ||
897 | m_showing = true; | ||
820 | slotShow( uid ); | 898 | slotShow( uid ); |
899 | raise(); | ||
900 | QPEApplication::setKeepRunning(); | ||
821 | } | 901 | } |
822 | void MainWindow::edit( int uid ) { | 902 | void MainWindow::edit( int uid ) { |
903 | m_todoMgr.load(); | ||
823 | slotEdit( uid ); | 904 | slotEdit( uid ); |
824 | } | 905 | } |
825 | void MainWindow::add( const OPimRecord& rec) { | 906 | void MainWindow::add( const OPimRecord& rec) { |
826 | if ( rec.rtti() != OTodo::rtti() ) return; | 907 | if ( rec.rtti() != OTodo::rtti() ) return; |
908 | m_todoMgr.load(); // might not be loaded | ||
827 | 909 | ||
828 | const OTodo& todo = static_cast<const OTodo&>(rec); | 910 | const OTodo& todo = static_cast<const OTodo&>(rec); |
829 | 911 | ||
830 | m_todoMgr.add(todo ); | 912 | m_todoMgr.add(todo ); |
831 | currentView()->addEvent( todo ); | 913 | currentView()->addEvent( todo ); |
832 | 914 | ||
833 | 915 | ||
834 | // I'm afraid we must call this every time now, otherwise | 916 | // I'm afraid we must call this every time now, otherwise |
835 | // spend expensive time comparing all these strings... | 917 | // spend expensive time comparing all these strings... |
836 | // but only call if we changed something -zecke | 918 | // but only call if we changed something -zecke |
837 | populateCategories(); | 919 | populateCategories(); |
838 | } | 920 | } |
839 | void MainWindow::slotReturnFromView() { | 921 | void MainWindow::slotReturnFromView() { |
922 | m_showing = false; | ||
840 | raiseCurrentView(); | 923 | raiseCurrentView(); |
841 | } | 924 | } |
842 | 925 | ||
843 | namespace { | 926 | namespace { |
844 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, | 927 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, |
845 | const OPimNotifyManager::Alarms& newAls ) { | 928 | const OPimNotifyManager::Alarms& newAls ) { |
846 | OPimNotifyManager::Alarms nonMatching; | 929 | OPimNotifyManager::Alarms nonMatching; |
847 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); | 930 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); |
848 | OPimNotifyManager::Alarms::ConstIterator newIt; | 931 | OPimNotifyManager::Alarms::ConstIterator newIt; |
849 | for ( ; oldIt != oldAls.end(); ++oldIt ) { | 932 | for ( ; oldIt != oldAls.end(); ++oldIt ) { |
850 | bool found = false; | 933 | bool found = false; |
851 | QDateTime oldDt = (*oldIt).dateTime(); | 934 | QDateTime oldDt = (*oldIt).dateTime(); |
@@ -923,30 +1006,31 @@ void MainWindow::doAlarm( const QDateTime& dt, int uid ) { | |||
923 | } | 1006 | } |
924 | if (loud) | 1007 | if (loud) |
925 | startAlarm(); | 1008 | startAlarm(); |
926 | 1009 | ||
927 | QDialog dlg(this, 0, TRUE ); | 1010 | QDialog dlg(this, 0, TRUE ); |
928 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); | 1011 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); |
929 | QTextView* view = new QTextView( &dlg ); | 1012 | QTextView* view = new QTextView( &dlg ); |
930 | lay->addWidget( view ); | 1013 | lay->addWidget( view ); |
931 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); | 1014 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); |
932 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); | 1015 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); |
933 | lay->addWidget( btnOk ); | 1016 | lay->addWidget( btnOk ); |
934 | 1017 | ||
935 | QString text = tr("<h1>Alarm at %0</h1><br>").arg( TimeString::dateString( dt ) ); | 1018 | QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); |
936 | text += todo.toRichText(); | 1019 | text += todo.toRichText(); |
937 | view->setText( text ); | 1020 | view->setText( text ); |
938 | 1021 | ||
939 | dlg.showMaximized(); | 1022 | dlg.showMaximized(); |
940 | bool needToStay = dlg.exec(); | 1023 | bool needToStay = dlg.exec(); |
941 | 1024 | ||
942 | if (loud) | 1025 | if (loud) |
943 | killAlarm(); | 1026 | killAlarm(); |
944 | 1027 | ||
945 | if (needToStay) { | 1028 | if (needToStay) { |
946 | showMaximized(); | 1029 | // showMaximized(); |
947 | raise(); | 1030 | // raise(); |
948 | QPEApplication::setKeepRunning(); | 1031 | QPEApplication::setKeepRunning(); |
949 | setActiveWindow(); | 1032 | // setActiveWindow(); |
950 | } | 1033 | } |
951 | 1034 | ||
952 | } | 1035 | } |
1036 | |||