author | zecke <zecke> | 2002-03-21 00:26:39 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-21 00:26:39 (UTC) |
commit | 8bfe366ce8667addc539f11fc560250c306340ae (patch) (unidiff) | |
tree | 4b890a47d86621d3e1f0aacde2485457862f02c8 /core/pim/todo/todotable.cpp | |
parent | e8f15a98c611b0c6030e8210672b249b42107526 (diff) | |
download | opie-8bfe366ce8667addc539f11fc560250c306340ae.zip opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.gz opie-8bfe366ce8667addc539f11fc560250c306340ae.tar.bz2 |
Move todolist to tododb
Please test todolist
-rw-r--r-- | core/pim/todo/todotable.cpp | 274 |
1 files changed, 44 insertions, 230 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 77d3389..2bb95a2 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp | |||
@@ -22,2 +22,3 @@ | |||
22 | 22 | ||
23 | #include <opie/tododb.h> | ||
23 | #include <qpe/categoryselect.h> | 24 | #include <qpe/categoryselect.h> |
@@ -41,3 +42,3 @@ | |||
41 | 42 | ||
42 | static bool taskCompare( const Task &task, const QRegExp &r, int category ); | 43 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); |
43 | 44 | ||
@@ -64,3 +65,3 @@ void CheckItem::toggle() | |||
64 | TodoTable *parent = static_cast<TodoTable*>(table()); | 65 | TodoTable *parent = static_cast<TodoTable*>(table()); |
65 | Task newTodo = parent->currentEntry(); | 66 | ToDoEvent newTodo = parent->currentEntry(); |
66 | checked = !checked; | 67 | checked = !checked; |
@@ -135,3 +136,3 @@ void ComboItem::setContentFromEditor( QWidget *w ) | |||
135 | TodoTable *parent = static_cast<TodoTable*>(table()); | 136 | TodoTable *parent = static_cast<TodoTable*>(table()); |
136 | Task newTodo = parent->currentEntry(); | 137 | ToDoEvent newTodo = parent->currentEntry(); |
137 | 138 | ||
@@ -196,3 +197,3 @@ TodoTable::TodoTable( QWidget *parent, const char *name ) | |||
196 | 197 | ||
197 | void TodoTable::addEntry( const Task &todo ) | 198 | void TodoTable::addEntry( const ToDoEvent &todo ) |
198 | { | 199 | { |
@@ -201,3 +202,3 @@ void TodoTable::addEntry( const Task &todo ) | |||
201 | updateJournal( todo, ACTION_ADD ); | 202 | updateJournal( todo, ACTION_ADD ); |
202 | insertIntoTable( new Task(todo), row ); | 203 | insertIntoTable( new ToDoEvent(todo), row ); |
203 | setCurrentCell(row, currentColumn()); | 204 | setCurrentCell(row, currentColumn()); |
@@ -254,3 +255,3 @@ void TodoTable::slotCurrentChanged( int, int ) | |||
254 | 255 | ||
255 | void TodoTable::internalAddEntries( QList<Task> &list ) | 256 | void TodoTable::internalAddEntries( QList<ToDoEvent> &list ) |
256 | { | 257 | { |
@@ -258,3 +259,3 @@ void TodoTable::internalAddEntries( QList<Task> &list ) | |||
258 | int row = 0; | 259 | int row = 0; |
259 | Task *it; | 260 | ToDoEvent *it; |
260 | for ( it = list.first(); it; it = list.next() ) | 261 | for ( it = list.first(); it; it = list.next() ) |
@@ -264,3 +265,3 @@ void TodoTable::internalAddEntries( QList<Task> &list ) | |||
264 | 265 | ||
265 | Task TodoTable::currentEntry() const | 266 | ToDoEvent TodoTable::currentEntry() const |
266 | { | 267 | { |
@@ -268,4 +269,4 @@ Task TodoTable::currentEntry() const | |||
268 | if ( !i || rowHeight( currentRow() ) <= 0 ) | 269 | if ( !i || rowHeight( currentRow() ) <= 0 ) |
269 | return Task(); | 270 | return ToDoEvent(); |
270 | Task *todo = todoList[(CheckItem*)i]; | 271 | ToDoEvent *todo = todoList[(CheckItem*)i]; |
271 | todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); | 272 | todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); |
@@ -275,3 +276,3 @@ Task TodoTable::currentEntry() const | |||
275 | 276 | ||
276 | void TodoTable::replaceCurrentEntry( const Task &todo, bool fromTableItem ) | 277 | void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) |
277 | { | 278 | { |
@@ -288,3 +289,3 @@ void TodoTable::removeCurrentEntry() | |||
288 | { | 289 | { |
289 | Task *oldTodo; | 290 | ToDoEvent *oldTodo; |
290 | int row = currentRow(); | 291 | int row = currentRow(); |
@@ -309,11 +310,5 @@ bool TodoTable::save( const QString &fn ) | |||
309 | QString strNewFile = fn + ".new"; | 310 | QString strNewFile = fn + ".new"; |
310 | QFile f( strNewFile ); | 311 | QFile::remove( strNewFile ); // just to be sure |
311 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 312 | ToDoDB todoDB( strNewFile ); |
312 | return false; | 313 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
313 | |||
314 | QString buf("<!DOCTYPE Tasks>\n<Tasks>\n"); | ||
315 | QCString str; | ||
316 | int total_written; | ||
317 | |||
318 | for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin(); | ||
319 | it != todoList.end(); ++it ) { | 314 | it != todoList.end(); ++it ) { |
@@ -321,3 +316,3 @@ bool TodoTable::save( const QString &fn ) | |||
321 | continue; | 316 | continue; |
322 | Task *todo = *it; | 317 | ToDoEvent *todo = *it; |
323 | // sync item with table | 318 | // sync item with table |
@@ -325,25 +320,8 @@ bool TodoTable::save( const QString &fn ) | |||
325 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); | 320 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); |
326 | buf += "<Task"; | 321 | todoDB.addEvent( *todo ); |
327 | todo->save( buf ); | ||
328 | buf += " />\n"; | ||
329 | str = buf.utf8(); | ||
330 | total_written = f.writeBlock( str.data(), str.length() ); | ||
331 | if ( total_written != int(str.length()) ) { | ||
332 | f.close(); | ||
333 | QFile::remove( strNewFile ); | ||
334 | return false; | ||
335 | } | ||
336 | buf = ""; | ||
337 | } | ||
338 | |||
339 | buf += "</Tasks>\n"; | ||
340 | str = buf.utf8(); | ||
341 | total_written = f.writeBlock( str.data(), str.length() ); | ||
342 | if ( total_written != int(str.length()) ) { | ||
343 | f.close(); | ||
344 | QFile::remove( strNewFile ); | ||
345 | return false; | ||
346 | } | 322 | } |
347 | f.close(); | 323 | if(!todoDB.save() ){ |
348 | 324 | QFile::remove( strNewFile ); | |
325 | return false; | ||
326 | }; | ||
349 | // now do the rename | 327 | // now do the rename |
@@ -382,3 +360,3 @@ void TodoTable::updateVisible() | |||
382 | CheckItem *ci = (CheckItem *)item( row, 0 ); | 360 | CheckItem *ci = (CheckItem *)item( row, 0 ); |
383 | Task *t = todoList[ci]; | 361 | ToDoEvent *t = todoList[ci]; |
384 | QArray<int> vlCats = t->categories(); | 362 | QArray<int> vlCats = t->categories(); |
@@ -442,5 +420,5 @@ void TodoTable::clear() | |||
442 | { | 420 | { |
443 | for ( QMap<CheckItem*, Task *>::Iterator it = todoList.begin(); | 421 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
444 | it != todoList.end(); ++it ) { | 422 | it != todoList.end(); ++it ) { |
445 | Task *todo = *it; | 423 | ToDoEvent *todo = *it; |
446 | delete todo; | 424 | delete todo; |
@@ -479,3 +457,3 @@ void TodoTable::slotCheckPriority(int row, int col ) | |||
479 | 457 | ||
480 | void TodoTable::updateJournal( const Task &todo, journal_action action, int row ) | 458 | void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) |
481 | { | 459 | { |
@@ -487,3 +465,3 @@ void TodoTable::updateJournal( const Task &todo, journal_action action, int row | |||
487 | buf = "<Task"; | 465 | buf = "<Task"; |
488 | todo.save( buf ); | 466 | // todo.save( buf ); |
489 | buf += " Action=\"" + QString::number( int(action) ) + "\""; | 467 | buf += " Action=\"" + QString::number( int(action) ) + "\""; |
@@ -504,179 +482,15 @@ void TodoTable::loadFile( const QString &strFile, bool fromJournal ) | |||
504 | { | 482 | { |
505 | QFile f( strFile ); | ||
506 | if ( !f.open(IO_ReadOnly) ) | ||
507 | return; | ||
508 | |||
509 | int action, row; | ||
510 | action = 0; row = 0; | ||
511 | |||
512 | enum Attribute { | ||
513 | FCompleted = 0, | ||
514 | FHasDate, | ||
515 | FPriority, | ||
516 | FCategories, | ||
517 | FDescription, | ||
518 | FDateYear, | ||
519 | FDateMonth, | ||
520 | FDateDay, | ||
521 | FUid, | ||
522 | FAction, | ||
523 | FRow | ||
524 | }; | ||
525 | |||
526 | QAsciiDict<int> dict( 31 ); | ||
527 | QList<Task> list; | ||
528 | dict.setAutoDelete( TRUE ); | ||
529 | dict.insert( "Completed", new int(FCompleted) ); | ||
530 | dict.insert( "HasDate", new int(FHasDate) ); | ||
531 | dict.insert( "Priority", new int(FPriority) ); | ||
532 | dict.insert( "Categories", new int(FCategories) ); | ||
533 | dict.insert( "Description", new int(FDescription) ); | ||
534 | dict.insert( "DateYear", new int(FDateYear) ); | ||
535 | dict.insert( "DateMonth", new int(FDateMonth) ); | ||
536 | dict.insert( "DateDay", new int(FDateDay) ); | ||
537 | dict.insert( "Uid", new int(FUid) ); | ||
538 | dict.insert( "Action", new int(FAction) ); | ||
539 | dict.insert( "Row", new int(FRow) ); | ||
540 | |||
541 | QByteArray ba = f.readAll(); | ||
542 | f.close(); | ||
543 | char* dt = ba.data(); | ||
544 | int len = ba.size(); | ||
545 | bool hasDueDate = FALSE; | ||
546 | |||
547 | action = ACTION_ADD; | ||
548 | int i = 0; | ||
549 | char *point; | ||
550 | while ( ( point = strstr( dt+i, "<Task " ) ) != NULL ) { | ||
551 | // new Task | ||
552 | i = point - dt; | ||
553 | Task *todo = new Task; | ||
554 | int dtY = 0, dtM = 0, dtD = 0; | ||
555 | |||
556 | i += 5; | ||
557 | |||
558 | while( 1 ) { | ||
559 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | ||
560 | ++i; | ||
561 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | ||
562 | break; | ||
563 | // we have another attribute, read it. | ||
564 | int j = i; | ||
565 | while ( j < len && dt[j] != '=' ) | ||
566 | ++j; | ||
567 | char *attr = dt+i; | ||
568 | dt[j] = '\0'; | ||
569 | i = ++j; // skip = | ||
570 | while ( i < len && dt[i] != '"' ) | ||
571 | ++i; | ||
572 | j = ++i; | ||
573 | bool haveUtf = FALSE; | ||
574 | bool haveEnt = FALSE; | ||
575 | while ( j < len && dt[j] != '"' ) { | ||
576 | if ( ((unsigned char)dt[j]) > 0x7f ) | ||
577 | haveUtf = TRUE; | ||
578 | if ( dt[j] == '&' ) | ||
579 | haveEnt = TRUE; | ||
580 | ++j; | ||
581 | } | ||
582 | if ( i == j ) { | ||
583 | // empty value | ||
584 | i = j + 1; | ||
585 | continue; | ||
586 | } | ||
587 | QCString value( dt+i, j-i+1 ); | ||
588 | i = j + 1; | ||
589 | int *lookup = dict[ attr ]; | ||
590 | if ( !lookup ) { | ||
591 | todo->setCustomField(attr, value); | ||
592 | continue; | ||
593 | } | ||
594 | switch( *lookup ) { | ||
595 | case FCompleted: | ||
596 | todo->setCompleted( value.toInt() ); | ||
597 | break; | ||
598 | case FHasDate: | ||
599 | // leave... | ||
600 | hasDueDate = value.toInt(); | ||
601 | break; | ||
602 | case FPriority: | ||
603 | todo->setPriority( value.toInt() ); | ||
604 | break; | ||
605 | case FCategories: { | ||
606 | //QString str = Qtopia::plainString( value ); | ||
607 | todo->setCategories( Qtopia::Record::idsFromString( value ) ); | ||
608 | break; | ||
609 | } | ||
610 | case FDescription: | ||
611 | { | ||
612 | QString str = (haveUtf ? QString::fromUtf8( value ) | ||
613 | : QString::fromLatin1( value ) ); | ||
614 | if ( haveEnt ) | ||
615 | str = Qtopia::plainString( str ); | ||
616 | todo->setDescription( str ); | ||
617 | break; | ||
618 | } | ||
619 | case FDateYear: | ||
620 | dtY = value.toInt(); | ||
621 | break; | ||
622 | case FDateMonth: | ||
623 | dtM = value.toInt(); | ||
624 | break; | ||
625 | case FDateDay: | ||
626 | dtD = value.toInt(); | ||
627 | break; | ||
628 | case FUid: | ||
629 | todo->setUid( value.toInt() ); | ||
630 | break; | ||
631 | case FAction: | ||
632 | action = value.toInt(); | ||
633 | break; | ||
634 | case FRow: | ||
635 | row = value.toInt(); | ||
636 | break; | ||
637 | default: | ||
638 | qDebug( "huh??? missing enum? -- attr.: %s", attr ); | ||
639 | break; | ||
640 | } | ||
641 | } | ||
642 | |||
643 | if ( dtY != 0 && dtM != 0 && dtD != 0 ) | ||
644 | todo->setDueDate( QDate( dtY, dtM, dtD), hasDueDate ); | ||
645 | else | ||
646 | todo->setHasDueDate( hasDueDate ); | ||
647 | |||
648 | // if ( categoryList.find( todo.category() ) == categoryList.end() ) | ||
649 | // categoryList.append( todo.category() ); | ||
650 | |||
651 | 483 | ||
652 | // sadly we can't delay adding of items from the journal to get | 484 | QList<ToDoEvent> list; |
653 | // the proper effect, but then, the journal should _never_ be | 485 | ToDoDB todoDB; |
654 | // that huge | 486 | QValueList<ToDoEvent> vaList = todoDB.rawToDos(); |
655 | 487 | for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ | |
656 | switch( action ) { | 488 | list.append( new ToDoEvent( (*it) ) ); |
657 | case ACTION_ADD: | 489 | } |
658 | if ( fromJournal ) { | 490 | vaList.clear(); |
659 | int myrows = numRows(); | 491 | // qDebug("parsing done=%d", t.elapsed() ); |
660 | setNumRows( myrows + 1 ); | 492 | if ( list.count() > 0 ) { |
661 | insertIntoTable( todo, myrows ); | 493 | internalAddEntries( list ); |
662 | delete todo; | 494 | list.clear(); |
663 | } else | 495 | } |
664 | list.append( todo ); | ||
665 | break; | ||
666 | case ACTION_REMOVE: | ||
667 | journalFreeRemoveEntry( row ); | ||
668 | break; | ||
669 | case ACTION_REPLACE: | ||
670 | journalFreeReplaceEntry( *todo, row ); | ||
671 | delete todo; | ||
672 | break; | ||
673 | default: | ||
674 | break; | ||
675 | } | ||
676 | } | ||
677 | // qDebug("parsing done=%d", t.elapsed() ); | ||
678 | if ( list.count() > 0 ) { | ||
679 | internalAddEntries( list ); | ||
680 | list.clear(); | ||
681 | } | ||
682 | // qDebug("loading done: t=%d", t.elapsed() ); | 496 | // qDebug("loading done: t=%d", t.elapsed() ); |
@@ -684,3 +498,3 @@ void TodoTable::loadFile( const QString &strFile, bool fromJournal ) | |||
684 | 498 | ||
685 | void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | 499 | void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row ) |
686 | { | 500 | { |
@@ -689,3 +503,3 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | |||
689 | if ( row == -1 ) { | 503 | if ( row == -1 ) { |
690 | QMapIterator<CheckItem*, Task *> it; | 504 | QMapIterator<CheckItem*, ToDoEvent *> it; |
691 | for ( it = todoList.begin(); it != todoList.end(); ++it ) { | 505 | for ( it = todoList.begin(); it != todoList.end(); ++it ) { |
@@ -700,3 +514,3 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | |||
700 | } else { | 514 | } else { |
701 | Task *t = todoList[static_cast<CheckItem*>(item(row, 0))]; | 515 | ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; |
702 | todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); | 516 | todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); |
@@ -706,3 +520,3 @@ void TodoTable::journalFreeReplaceEntry( const Task &todo, int row ) | |||
706 | item( row, 2 )->setText( strTodo ); | 520 | item( row, 2 )->setText( strTodo ); |
707 | todoList.insert( static_cast<CheckItem*>(item(row,0)), new Task(todo) ); | 521 | todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); |
708 | } | 522 | } |
@@ -816,3 +630,3 @@ int TodoTable::showCategoryId() const | |||
816 | 630 | ||
817 | static bool taskCompare( const Task &task, const QRegExp &r, int category ) | 631 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) |
818 | { | 632 | { |