summaryrefslogtreecommitdiff
path: root/core/pim/todo/todotable.cpp
Unidiff
Diffstat (limited to 'core/pim/todo/todotable.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 401d2c8..96cd860 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -349,13 +349,13 @@ ToDoEvent TodoTable::currentEntry() const
349 return *todo; 349 return *todo;
350} 350}
351 351
352void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) 352void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem )
353{ 353{
354 int row = currentRow(); 354 int row = currentRow();
355 updateJournal( todo, ACTION_REPLACE, row ); 355 updateJournal( todo, ACTION_REPLACE);
356 356
357 if ( !fromTableItem ) { 357 if ( !fromTableItem ) {
358 journalFreeReplaceEntry( todo, row ); 358 journalFreeReplaceEntry( todo, row );
359 updateVisible(); 359 updateVisible();
360 } 360 }
361} 361}
@@ -372,13 +372,13 @@ void TodoTable::removeCurrentEntry()
372 oldTodo = todoList[chk]; 372 oldTodo = todoList[chk];
373 todoList.remove( chk ); 373 todoList.remove( chk );
374 oldTodo->setCompleted( chk->isChecked() ); 374 oldTodo->setCompleted( chk->isChecked() );
375 oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); 375 oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() );
376 realignTable( row ); 376 realignTable( row );
377 updateVisible(); 377 updateVisible();
378 updateJournal( *oldTodo, ACTION_REMOVE, row ); 378 updateJournal( *oldTodo, ACTION_REMOVE);
379 delete oldTodo; 379 delete oldTodo;
380} 380}
381 381
382 382
383bool TodoTable::save( const QString &fn ) 383bool TodoTable::save( const QString &fn )
384{ 384{
@@ -408,17 +408,17 @@ bool TodoTable::save( const QString &fn )
408 QFile::remove( journalFileName() ); 408 QFile::remove( journalFileName() );
409 return true; 409 return true;
410} 410}
411 411
412void TodoTable::load( const QString &fn ) 412void TodoTable::load( const QString &fn )
413{ 413{
414 loadFile( fn, false );
415 if ( QFile::exists(journalFileName()) ) { 414 if ( QFile::exists(journalFileName()) ) {
416 applyJournal( ); 415 applyJournal( );
417 save( fn ); 416 QFile::remove(journalFileName() );
418 } 417 }
418 loadFile( fn );
419// QTable::sortColumn(2,TRUE,TRUE); 419// QTable::sortColumn(2,TRUE,TRUE);
420// QTable::sortColumn(1,TRUE,TRUE); 420// QTable::sortColumn(1,TRUE,TRUE);
421 QTable::sortColumn(0,TRUE,TRUE); 421 QTable::sortColumn(0,TRUE,TRUE);
422 setCurrentCell( 0, 2 ); 422 setCurrentCell( 0, 2 );
423 setSorting(true ); 423 setSorting(true );
424} 424}
@@ -498,14 +498,14 @@ void TodoTable::setPaintingEnabled( bool e )
498} 498}
499 499
500void TodoTable::clear() 500void TodoTable::clear()
501{ 501{
502 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); 502 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
503 it != todoList.end(); ++it ) { 503 it != todoList.end(); ++it ) {
504 ToDoEvent *todo = *it; 504 ToDoEvent *todo = it.data();
505 updateJournal( todo, ACTION_REMOVE, 0 ); 505 updateJournal( *todo, ACTION_REMOVE );
506 delete todo; 506 delete todo;
507 } 507 }
508 todoList.clear(); 508 todoList.clear();
509 for ( int r = 0; r < numRows(); ++r ) { 509 for ( int r = 0; r < numRows(); ++r ) {
510 for ( int c = 0; c < numCols(); ++c ) { 510 for ( int c = 0; c < numCols(); ++c ) {
511 if ( cellWidget( r, c ) ) 511 if ( cellWidget( r, c ) )
@@ -534,13 +534,13 @@ void TodoTable::slotCheckPriority(int row, int col )
534 ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); 534 ComboItem* i = static_cast<ComboItem*>( item( row, col ) );
535 emit signalPriorityChanged( i->text().toInt() ); 535 emit signalPriorityChanged( i->text().toInt() );
536 } 536 }
537} 537}
538 538
539 539
540void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) 540void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action )
541{ 541{
542 QFile f( journalFileName() ); 542 QFile f( journalFileName() );
543 if ( !f.open(IO_WriteOnly|IO_Append) ) 543 if ( !f.open(IO_WriteOnly|IO_Append) )
544 return; 544 return;
545 QString buf; 545 QString buf;
546 QCString str; 546 QCString str;
@@ -574,13 +574,13 @@ void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int
574void TodoTable::rowHeightChanged( int row ) 574void TodoTable::rowHeightChanged( int row )
575{ 575{
576 if ( enablePainting ) 576 if ( enablePainting )
577 QTable::rowHeightChanged( row ); 577 QTable::rowHeightChanged( row );
578} 578}
579 579
580void TodoTable::loadFile( const QString &strFile, bool fromJournal ) 580void TodoTable::loadFile( const QString &/*we use the standard*/ )
581{ 581{
582 582
583 QList<ToDoEvent> list; 583 QList<ToDoEvent> list;
584 ToDoDB todoDB; 584 ToDoDB todoDB;
585 QValueList<ToDoEvent> vaList = todoDB.rawToDos(); 585 QValueList<ToDoEvent> vaList = todoDB.rawToDos();
586 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ 586 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){
@@ -751,21 +751,41 @@ void TodoTable::applyJournal()
751 str << QString::fromLatin1("</Tasks>") << endl; 751 str << QString::fromLatin1("</Tasks>") << endl;
752 file2.close(); 752 file2.close();
753 } 753 }
754 XMLElement *root = XMLElement::load(journalFileName()+ "_new"); 754 XMLElement *root = XMLElement::load(journalFileName()+ "_new");
755 XMLElement *el = root->firstChild(); 755 XMLElement *el = root->firstChild();
756 el = el->firstChild(); 756 el = el->firstChild();
757 ToDoDB tododb; // allready loaded ;)
758 bool ok;
759 int action;
760 QString dummy;
757 while( el ){ 761 while( el ){
758 qWarning("journal: %s %s", el->attribute("Uid" ).latin1(), el->tagName().latin1() ); 762 dummy = el->attribute("Action" );
759 doApply( el ); 763 action = dummy.toInt(&ok );
764 ToDoEvent ev = xmlToEvent( el );
765 if(ok ){
766 switch( action){
767 case ACTION_ADD:
768 tododb.addEvent(ev );
769 break;
770 case ACTION_REMOVE:
771 tododb.removeEvent( ev );
772 break;
773 case ACTION_REPLACE:
774 tododb.replaceEvent( ev );
775 break;
776 }
777 }
760 el = el->nextChild(); 778 el = el->nextChild();
761 } 779 }
762 QFile::remove(journalFileName()+ "_new" ); 780 QFile::remove(journalFileName()+ "_new" );
781 tododb.save();
763 } 782 }
764} 783}
765// check Action and decide 784// check Action and decide
785/*
766void TodoTable::doApply(XMLElement *el ) 786void TodoTable::doApply(XMLElement *el )
767{ 787{
768 QString dummy; 788 QString dummy;
769 bool ok; 789 bool ok;
770 int action; 790 int action;
771 dummy = el->attribute("Action" ); 791 dummy = el->attribute("Action" );
@@ -781,12 +801,13 @@ void TodoTable::doApply(XMLElement *el )
781 } 801 }
782 case ACTION_REPLACE: 802 case ACTION_REPLACE:
783 break; 803 break;
784 } 804 }
785 } 805 }
786} 806}
807*/
787namespace { 808namespace {
788static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) 809static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
789{ 810{
790 bool returnMe; 811 bool returnMe;
791 QArray<int> cats; 812 QArray<int> cats;
792 cats = task.categories(); 813 cats = task.categories();
@@ -860,13 +881,12 @@ static ToDoEvent xmlToEvent( XMLElement *element )
860 event.setCategories( ids ); 881 event.setCategories( ids );
861 882
862 //uid 883 //uid
863 dummy = element->attribute("Uid" ); 884 dummy = element->attribute("Uid" );
864 dumInt = dummy.toInt(&ok ); 885 dumInt = dummy.toInt(&ok );
865 if(ok ) event.setUid( dumInt ); 886 if(ok ) event.setUid( dumInt );
866
867 return event; 887 return event;
868} 888}
869 889
870} 890}
871// int TodoTable::rowHeight( int ) const 891// int TodoTable::rowHeight( int ) const
872// { 892// {