author | zecke <zecke> | 2002-04-15 20:55:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-15 20:55:49 (UTC) |
commit | 943f0de13f6b017e67d0289c7273ddbf496a2cff (patch) (side-by-side diff) | |
tree | ed28fa2c3632ce672b31edff10ecf08356d35f64 /core/pim/todo/todotable.cpp | |
parent | e010d922ac415558e5efd35e69e39e45908b5501 (diff) | |
download | opie-943f0de13f6b017e67d0289c7273ddbf496a2cff.zip opie-943f0de13f6b017e67d0289c7273ddbf496a2cff.tar.gz opie-943f0de13f6b017e67d0289c7273ddbf496a2cff.tar.bz2 |
journal is in place again
-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 @@ -343,48 +343,48 @@ ToDoEvent TodoTable::currentEntry() const QTableItem *i = item( currentRow(), 0 ); if ( !i || rowHeight( currentRow() ) <= 0 ) return ToDoEvent(); ToDoEvent *todo = todoList[(CheckItem*)i]; todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); 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(); } } void TodoTable::removeCurrentEntry() { ToDoEvent *oldTodo; int row = currentRow(); CheckItem *chk; chk = static_cast<CheckItem*>(item(row, 0 )); if ( !chk ) return; 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 ) { QString strNewFile = fn + ".new"; QFile::remove( strNewFile ); // just to be sure ToDoDB todoDB( strNewFile ); for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); it != todoList.end(); ++it ) { if ( !item( it.key()->row(), 0 ) ) @@ -402,29 +402,29 @@ bool TodoTable::save( const QString &fn ) // now do the rename if ( ::rename( strNewFile, fn ) < 0 ) qWarning( "problem renaming file %s to %s errno %d", strNewFile.latin1(), fn.latin1(), errno ); // remove the journal 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 ); } void TodoTable::updateVisible() { if ( !isUpdatesEnabled() ) return; if (showDeadl){ @@ -492,26 +492,26 @@ void TodoTable::setPaintingEnabled( bool e ) rowHeightChanged( 0 ); viewport()->update(); } else { enablePainting = false; } } } 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 ) ) clearCellWidget( r, c ); clearCell( r, c ); } } setNumRows( 0 ); } @@ -528,25 +528,25 @@ void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) void TodoTable::slotCheckPriority(int row, int col ) { // kludgey work around to make forward along the updated priority... if ( col == 1 ) { // let everyone know!! 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; buf = "<Task"; // todo.save( buf ); buf += " Action=\"" + QString::number( int(action) ) + "\""; buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\""; buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\""; @@ -568,25 +568,25 @@ void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int buf += "/>\n"; str = buf.utf8(); f.writeBlock( str.data(), str.length() ); f.close(); } 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 ){ list.append( new ToDoEvent( (*it) ) ); } vaList.clear(); // qDebug("parsing done=%d", t.elapsed() ); if ( list.count() > 0 ) { internalAddEntries( list ); @@ -745,54 +745,75 @@ void TodoTable::applyJournal() file.close(); QFile file2( journalFileName() + "_new" ); if( file2.open(IO_WriteOnly ) ){ QTextStream str(&file2 ); str << QString::fromLatin1("<Tasks>") << endl; str << ar.data(); 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" ); action = dummy.toInt(&ok ); ToDoEvent ev = xmlToEvent( el ); if( ok ){ switch( action ){ case ACTION_ADD: addEntry( ev ); break; case ACTION_REMOVE:{ // find an entry with the same uid and remove it then break; } case ACTION_REPLACE: break; } } } +*/ namespace { static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) { bool returnMe; QArray<int> cats; cats = task.categories(); returnMe = false; if ( (category == -1 && cats.count() == 0) || category == -2 ) returnMe = task.match( r ); else { int i; @@ -854,25 +875,24 @@ static ToDoEvent xmlToEvent( XMLElement *element ) //description dummy = element->attribute("Description" ); event.setDescription( dummy ); // category dummy = element->attribute("Categories" ); QStringList ids = QStringList::split(";", dummy ); event.setCategories( ids ); //uid dummy = element->attribute("Uid" ); dumInt = dummy.toInt(&ok ); if(ok ) event.setUid( dumInt ); - return event; } } // int TodoTable::rowHeight( int ) const // { // return 18; // } // int TodoTable::rowPos( int row ) const // { // return 18*row; |