-rw-r--r-- | core/pim/todo/todotable.cpp | 48 |
1 files changed, 34 insertions, 14 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 return *todo; } void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) { int row = currentRow(); - updateJournal( todo, ACTION_REPLACE, row ); + updateJournal( todo, ACTION_REPLACE); if ( !fromTableItem ) { journalFreeReplaceEntry( todo, row ); updateVisible(); } } @@ -372,13 +372,13 @@ void TodoTable::removeCurrentEntry() oldTodo = todoList[chk]; todoList.remove( chk ); oldTodo->setCompleted( chk->isChecked() ); oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); realignTable( row ); updateVisible(); - updateJournal( *oldTodo, ACTION_REMOVE, row ); + updateJournal( *oldTodo, ACTION_REMOVE); delete oldTodo; } bool TodoTable::save( const QString &fn ) { @@ -408,17 +408,17 @@ bool TodoTable::save( const QString &fn ) QFile::remove( journalFileName() ); return true; } void TodoTable::load( const QString &fn ) { - loadFile( fn, false ); - if ( QFile::exists(journalFileName()) ) { - applyJournal( ); - save( fn ); - } + if ( QFile::exists(journalFileName()) ) { + applyJournal(); + QFile::remove(journalFileName() ); + } + loadFile( fn ); // QTable::sortColumn(2,TRUE,TRUE); // QTable::sortColumn(1,TRUE,TRUE); QTable::sortColumn(0,TRUE,TRUE); setCurrentCell( 0, 2 ); setSorting(true ); } @@ -498,14 +498,14 @@ void TodoTable::setPaintingEnabled( bool e ) } void TodoTable::clear() { for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); it != todoList.end(); ++it ) { - ToDoEvent *todo = *it; - updateJournal( todo, ACTION_REMOVE, 0 ); + ToDoEvent *todo = it.data(); + updateJournal( *todo, ACTION_REMOVE ); delete todo; } todoList.clear(); for ( int r = 0; r < numRows(); ++r ) { for ( int c = 0; c < numCols(); ++c ) { if ( cellWidget( r, c ) ) @@ -534,13 +534,13 @@ void TodoTable::slotCheckPriority(int row, int col ) ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); emit signalPriorityChanged( i->text().toInt() ); } } -void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) +void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action ) { QFile f( journalFileName() ); if ( !f.open(IO_WriteOnly|IO_Append) ) return; QString buf; QCString str; @@ -574,13 +574,13 @@ void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int void TodoTable::rowHeightChanged( int row ) { if ( enablePainting ) QTable::rowHeightChanged( row ); } -void TodoTable::loadFile( const QString &strFile, bool fromJournal ) +void TodoTable::loadFile( const QString &/*we use the standard*/ ) { QList<ToDoEvent> list; ToDoDB todoDB; QValueList<ToDoEvent> vaList = todoDB.rawToDos(); for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ @@ -751,21 +751,41 @@ void TodoTable::applyJournal() str << QString::fromLatin1("</Tasks>") << endl; file2.close(); } XMLElement *root = XMLElement::load(journalFileName()+ "_new"); XMLElement *el = root->firstChild(); el = el->firstChild(); + ToDoDB tododb; // allready loaded ;) + bool ok; + int action; + QString dummy; while( el ){ - qWarning("journal: %s %s", el->attribute("Uid" ).latin1(), el->tagName().latin1() ); - doApply( el ); + dummy = el->attribute("Action" ); + action = dummy.toInt(&ok ); + ToDoEvent ev = xmlToEvent( el ); + if(ok ){ + switch( action){ + case ACTION_ADD: + tododb.addEvent(ev ); + break; + case ACTION_REMOVE: + tododb.removeEvent( ev ); + break; + case ACTION_REPLACE: + tododb.replaceEvent( ev ); + break; + } + } el = el->nextChild(); } QFile::remove(journalFileName()+ "_new" ); + tododb.save(); } } // check Action and decide +/* void TodoTable::doApply(XMLElement *el ) { QString dummy; bool ok; int action; dummy = el->attribute("Action" ); @@ -781,12 +801,13 @@ void TodoTable::doApply(XMLElement *el ) } case ACTION_REPLACE: break; } } } +*/ namespace { static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) { bool returnMe; QArray<int> cats; cats = task.categories(); @@ -860,13 +881,12 @@ static ToDoEvent xmlToEvent( XMLElement *element ) event.setCategories( ids ); //uid dummy = element->attribute("Uid" ); dumInt = dummy.toInt(&ok ); if(ok ) event.setUid( dumInt ); - return event; } } // int TodoTable::rowHeight( int ) const // { |