summaryrefslogtreecommitdiff
authorzecke <zecke>2002-04-28 08:46:50 (UTC)
committer zecke <zecke>2002-04-28 08:46:50 (UTC)
commitee6fdf8783f7a2fa91792e2f0ce0f8350f8cac0d (patch) (unidiff)
treebdd4764fc90df1214a728eef6aacc3c2b3bb2ebb
parentf68f837aec3d6ddd24c2281cadc02bda5d8678e1 (diff)
downloadopie-ee6fdf8783f7a2fa91792e2f0ce0f8350f8cac0d.zip
opie-ee6fdf8783f7a2fa91792e2f0ce0f8350f8cac0d.tar.gz
opie-ee6fdf8783f7a2fa91792e2f0ce0f8350f8cac0d.tar.bz2
Patch from Stefan Eilers to raise the Tablewidget when searching and finding ;)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/mainwindow.cpp2
-rw-r--r--core/pim/todo/todotable.cpp7
2 files changed, 6 insertions, 3 deletions
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp
index d3f4cb4..a28fc3e 100644
--- a/core/pim/todo/mainwindow.cpp
+++ b/core/pim/todo/mainwindow.cpp
@@ -331,291 +331,293 @@ void TodoWindow::slotDelete()
331 table->removeCurrentEntry(); 331 table->removeCurrentEntry();
332 table->setPaintingEnabled( true ); 332 table->setPaintingEnabled( true );
333 333
334 if ( table->numRows() == 0 ) { 334 if ( table->numRows() == 0 ) {
335 currentEntryChanged( -1, 0 ); 335 currentEntryChanged( -1, 0 );
336 findAction->setEnabled( FALSE ); 336 findAction->setEnabled( FALSE );
337 } 337 }
338 mStack->raiseWidget(1); 338 mStack->raiseWidget(1);
339} 339}
340void TodoWindow::slotDeleteAll() 340void TodoWindow::slotDeleteAll()
341{ 341{
342 if(syncing) { 342 if(syncing) {
343 QMessageBox::warning(this, tr("Todo"), 343 QMessageBox::warning(this, tr("Todo"),
344 tr("Can not edit data, currently syncing")); 344 tr("Can not edit data, currently syncing"));
345 return; 345 return;
346 } 346 }
347 347
348 //QString strName = table->text( table->currentRow(), 2 ).left( 30 ); 348 //QString strName = table->text( table->currentRow(), 2 ).left( 30 );
349 349
350 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("Delete all tasks?") ) ) 350 if ( !QPEMessageBox::confirmDelete( this, tr( "Todo" ), tr("Delete all tasks?") ) )
351 return; 351 return;
352 352
353 353
354 354
355 table->setPaintingEnabled( false ); 355 table->setPaintingEnabled( false );
356 table->removeAllEntries(); 356 table->removeAllEntries();
357 table->setPaintingEnabled( true ); 357 table->setPaintingEnabled( true );
358 358
359 if ( table->numRows() == 0 ) { 359 if ( table->numRows() == 0 ) {
360 currentEntryChanged( -1, 0 ); 360 currentEntryChanged( -1, 0 );
361 findAction->setEnabled( FALSE ); 361 findAction->setEnabled( FALSE );
362 } 362 }
363 mStack->raiseWidget(1 ); 363 mStack->raiseWidget(1 );
364} 364}
365 365
366void TodoWindow::slotEdit() 366void TodoWindow::slotEdit()
367{ 367{
368 if(syncing) { 368 if(syncing) {
369 QMessageBox::warning(this, tr("Todo"), 369 QMessageBox::warning(this, tr("Todo"),
370 tr("Can not edit data, currently syncing")); 370 tr("Can not edit data, currently syncing"));
371 return; 371 return;
372 } 372 }
373 373
374 ToDoEvent todo = table->currentEntry(); 374 ToDoEvent todo = table->currentEntry();
375 375
376 NewTaskDialog e( todo, this, 0, TRUE ); 376 NewTaskDialog e( todo, this, 0, TRUE );
377 e.setCaption( tr( "Edit Task" ) ); 377 e.setCaption( tr( "Edit Task" ) );
378 378
379#if defined(Q_WS_QWS) || defined(_WS_QWS_) 379#if defined(Q_WS_QWS) || defined(_WS_QWS_)
380 e.showMaximized(); 380 e.showMaximized();
381#endif 381#endif
382 int ret = e.exec(); 382 int ret = e.exec();
383 383
384 if ( ret == QDialog::Accepted ) { 384 if ( ret == QDialog::Accepted ) {
385 table->setPaintingEnabled( false ); 385 table->setPaintingEnabled( false );
386 todo = e.todoEntry(); 386 todo = e.todoEntry();
387 table->replaceCurrentEntry( todo ); 387 table->replaceCurrentEntry( todo );
388 table->setPaintingEnabled( true ); 388 table->setPaintingEnabled( true );
389 } 389 }
390 populateCategories(); 390 populateCategories();
391 mStack->raiseWidget( 1 ); 391 mStack->raiseWidget( 1 );
392} 392}
393void TodoWindow::slotDuplicate() 393void TodoWindow::slotDuplicate()
394{ 394{
395 if(syncing) { 395 if(syncing) {
396 QMessageBox::warning(this, tr("Todo"), 396 QMessageBox::warning(this, tr("Todo"),
397 tr("Can not edit data, currently syncing")); 397 tr("Can not edit data, currently syncing"));
398 return; 398 return;
399 } 399 }
400 ToDoEvent ev = table->currentEntry(); 400 ToDoEvent ev = table->currentEntry();
401 ToDoEvent ev2 = ToDoEvent( ev ); // what about the uid 401 ToDoEvent ev2 = ToDoEvent( ev ); // what about the uid
402 int uid; 402 int uid;
403 { // uid 403 { // uid
404 Qtopia::UidGen *uidgen = new Qtopia::UidGen(); 404 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
405 uid = uidgen->generate(); 405 uid = uidgen->generate();
406 delete uidgen; 406 delete uidgen;
407 } 407 }
408 ev2.setUid( uid ); 408 ev2.setUid( uid );
409 table->setPaintingEnabled( false ); 409 table->setPaintingEnabled( false );
410 table->addEntry( ev2 ); 410 table->addEntry( ev2 );
411 table->setPaintingEnabled( true ); 411 table->setPaintingEnabled( true );
412 412
413 mStack->raiseWidget( 1 ); 413 mStack->raiseWidget( 1 );
414} 414}
415void TodoWindow::slotShowPopup( const QPoint &p ) 415void TodoWindow::slotShowPopup( const QPoint &p )
416{ 416{
417 contextMenu->popup( p ); 417 contextMenu->popup( p );
418} 418}
419 419
420void TodoWindow::showCompleted( bool s ) 420void TodoWindow::showCompleted( bool s )
421{ 421{
422 if ( !table->isUpdatesEnabled() ) 422 if ( !table->isUpdatesEnabled() )
423 return; 423 return;
424 table->setPaintingEnabled( false ); 424 table->setPaintingEnabled( false );
425 table->setShowCompleted( s ); 425 table->setShowCompleted( s );
426 table->setPaintingEnabled( true ); 426 table->setPaintingEnabled( true );
427 mStack->raiseWidget( 1 );
427} 428}
428 429
429void TodoWindow::currentEntryChanged( int r, int ) 430void TodoWindow::currentEntryChanged( int r, int )
430{ 431{
431 if ( r != -1 && table->rowHeight( r ) > 0 ) { 432 if ( r != -1 && table->rowHeight( r ) > 0 ) {
432 editAction->setEnabled( TRUE ); 433 editAction->setEnabled( TRUE );
433 deleteAction->setEnabled( TRUE ); 434 deleteAction->setEnabled( TRUE );
434 duplicateAction->setEnabled( TRUE ); 435 duplicateAction->setEnabled( TRUE );
435 deleteAllAction->setEnabled( TRUE ); 436 deleteAllAction->setEnabled( TRUE );
436 } else { 437 } else {
437 editAction->setEnabled( FALSE ); 438 editAction->setEnabled( FALSE );
438 deleteAction->setEnabled( FALSE ); 439 deleteAction->setEnabled( FALSE );
439 duplicateAction->setEnabled( FALSE ); 440 duplicateAction->setEnabled( FALSE );
440 deleteAllAction->setEnabled( FALSE ); 441 deleteAllAction->setEnabled( FALSE );
441 } 442 }
442} 443}
443 444
444void TodoWindow::setCategory( int c ) 445void TodoWindow::setCategory( int c )
445{ 446{
446 if ( c <= 0 ) return; 447 if ( c <= 0 ) return;
447 if ( !table->isUpdatesEnabled() ) 448 if ( !table->isUpdatesEnabled() )
448 return; 449 return;
449 table->setPaintingEnabled( false ); 450 table->setPaintingEnabled( false );
450 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 451 for ( unsigned int i = 1; i < catMenu->count(); i++ )
451 catMenu->setItemChecked( i, c == (int)i ); 452 catMenu->setItemChecked( i, c == (int)i );
452 if ( c == 1 ) { 453 if ( c == 1 ) {
453 table->setShowCategory( QString::null ); 454 table->setShowCategory( QString::null );
454 setCaption( tr("Todo") + " - " + tr( "All Categories" ) ); 455 setCaption( tr("Todo") + " - " + tr( "All Categories" ) );
455 } else if ( c == (int)catMenu->count() - 1 ) { 456 } else if ( c == (int)catMenu->count() - 1 ) {
456 table->setShowCategory( tr( "Unfiled" ) ); 457 table->setShowCategory( tr( "Unfiled" ) );
457 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) ); 458 setCaption( tr("Todo") + " - " + tr( "Unfiled" ) );
458 } else { 459 } else {
459 QString cat = table->categories()[c - 2]; 460 QString cat = table->categories()[c - 2];
460 table->setShowCategory( cat ); 461 table->setShowCategory( cat );
461 setCaption( tr("Todo") + " - " + cat ); 462 setCaption( tr("Todo") + " - " + cat );
462 } 463 }
463 table->setPaintingEnabled( true ); 464 table->setPaintingEnabled( true );
464 465
465 mStack->raiseWidget( 1 ); 466 mStack->raiseWidget( 1 );
466} 467}
467 468
468void TodoWindow::populateCategories() 469void TodoWindow::populateCategories()
469{ 470{
470 catMenu->clear(); 471 catMenu->clear();
471 int id, rememberId; 472 int id, rememberId;
472 id = 1; 473 id = 1;
473 rememberId = 0; 474 rememberId = 0;
474 catMenu->insertItem( tr( "All Categories" ), id++ ); 475 catMenu->insertItem( tr( "All Categories" ), id++ );
475 catMenu->insertSeparator(); 476 catMenu->insertSeparator();
476 QStringList categories = table->categories(); 477 QStringList categories = table->categories();
477 categories.append( tr( "Unfiled" ) ); 478 categories.append( tr( "Unfiled" ) );
478 for ( QStringList::Iterator it = categories.begin(); 479 for ( QStringList::Iterator it = categories.begin();
479 it != categories.end(); ++it ) { 480 it != categories.end(); ++it ) {
480 catMenu->insertItem( *it, id ); 481 catMenu->insertItem( *it, id );
481 if ( *it == table->showCategory() ) 482 if ( *it == table->showCategory() )
482 rememberId = id; 483 rememberId = id;
483 ++id; 484 ++id;
484 } 485 }
485 if ( table->showCategory().isEmpty() ) 486 if ( table->showCategory().isEmpty() )
486 setCategory( 1 ); 487 setCategory( 1 );
487 else 488 else
488 setCategory( rememberId ); 489 setCategory( rememberId );
489} 490}
490 491
491void TodoWindow::reload() 492void TodoWindow::reload()
492{ 493{
493 table->clear(); 494 table->clear();
494 table->load( todolistXMLFilename() ); 495 table->load( todolistXMLFilename() );
495 syncing = FALSE; 496 syncing = FALSE;
496} 497}
497 498
498void TodoWindow::flush() 499void TodoWindow::flush()
499{ 500{
500 syncing = TRUE; 501 syncing = TRUE;
501 table->save( todolistXMLFilename() ); 502 table->save( todolistXMLFilename() );
502} 503}
503 504
504void TodoWindow::closeEvent( QCloseEvent *e ) 505void TodoWindow::closeEvent( QCloseEvent *e )
505{ 506{
506 if( mStack->visibleWidget() != table ){ 507 if( mStack->visibleWidget() != table ){
507 mStack->raiseWidget( 1 ); 508 mStack->raiseWidget( 1 );
508 e->ignore(); 509 e->ignore();
509 return; 510 return;
510 } 511 }
511 if(syncing) { 512 if(syncing) {
512 /* no need to save if in the middle of syncing */ 513 /* no need to save if in the middle of syncing */
513 e->accept(); 514 e->accept();
514 return; 515 return;
515 } 516 }
516 517
517 if ( table->save( todolistXMLFilename() ) ) { 518 if ( table->save( todolistXMLFilename() ) ) {
518 e->accept(); 519 e->accept();
519 // repeat for categories... 520 // repeat for categories...
520 // if writing configs fail, it will emit an 521 // if writing configs fail, it will emit an
521 // error, but I feel that it is "ok" for us to exit 522 // error, but I feel that it is "ok" for us to exit
522 // espically since we aren't told if the write succeeded... 523 // espically since we aren't told if the write succeeded...
523 Config config( "todo" ); 524 Config config( "todo" );
524 config.setGroup( "View" ); 525 config.setGroup( "View" );
525 config.writeEntry( "ShowComplete", table->showCompleted() ); 526 config.writeEntry( "ShowComplete", table->showCompleted() );
526 config.writeEntry( "Category", table->showCategory() ); 527 config.writeEntry( "Category", table->showCategory() );
527 /* added 20.01.2k2 by se */ 528 /* added 20.01.2k2 by se */
528 config.writeEntry( "ShowDeadLine", table->showDeadline()); 529 config.writeEntry( "ShowDeadLine", table->showDeadline());
529 } else { 530 } else {
530 if ( QMessageBox::critical( this, tr("Out of space"), 531 if ( QMessageBox::critical( this, tr("Out of space"),
531 tr("Todo was unable\n" 532 tr("Todo was unable\n"
532 "to save your changes.\n" 533 "to save your changes.\n"
533 "Free up some space\n" 534 "Free up some space\n"
534 "and try again.\n" 535 "and try again.\n"
535 "\nQuit Anyway?"), 536 "\nQuit Anyway?"),
536 QMessageBox::Yes|QMessageBox::Escape, 537 QMessageBox::Yes|QMessageBox::Escape,
537 QMessageBox::No|QMessageBox::Default) 538 QMessageBox::No|QMessageBox::Default)
538 != QMessageBox::No ) 539 != QMessageBox::No )
539 e->accept(); 540 e->accept();
540 else 541 else
541 e->ignore(); 542 e->ignore();
542 } 543 }
543} 544}
544 545
545void TodoWindow::slotFind() 546void TodoWindow::slotFind()
546{ 547{
547 // put everything back to view all for searching... 548 // put everything back to view all for searching...
549 mStack->raiseWidget( 1 );
548 if ( !catMenu->isItemChecked( 0 ) ) 550 if ( !catMenu->isItemChecked( 0 ) )
549 setCategory( 0 ); 551 setCategory( 0 );
550 552
551 FindDialog dlg( "Todo List", this ); 553 FindDialog dlg( "Todo List", this );
552 QObject::connect( &dlg, 554 QObject::connect( &dlg,
553 SIGNAL(signalFindClicked(const QString &, 555 SIGNAL(signalFindClicked(const QString &,
554 bool, bool, int)), 556 bool, bool, int)),
555 table, 557 table,
556 SLOT(slotDoFind(const QString&, bool, bool, int)) ); 558 SLOT(slotDoFind(const QString&, bool, bool, int)) );
557 QObject::connect( table, SIGNAL(signalNotFound()), &dlg, 559 QObject::connect( table, SIGNAL(signalNotFound()), &dlg,
558 SLOT(slotNotFound()) ); 560 SLOT(slotNotFound()) );
559 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg, 561 QObject::connect( table, SIGNAL(signalWrapAround()), &dlg,
560 SLOT(slotWrapAround()) ); 562 SLOT(slotWrapAround()) );
561 dlg.exec(); 563 dlg.exec();
562 if ( table->numSelections() ) 564 if ( table->numSelections() )
563 table->clearSelection(); 565 table->clearSelection();
564 table->clearFindRow(); 566 table->clearFindRow();
565} 567}
566 568
567 569
568void TodoWindow::setDocument( const QString &filename ) 570void TodoWindow::setDocument( const QString &filename )
569{ 571{
570 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; 572 if ( filename.find(".vcs") != int(filename.length()) - 4 ) return;
571 573
572 ToDoDB todoDB(filename, new ToDoVCalResource() ); 574 ToDoDB todoDB(filename, new ToDoVCalResource() );
573 QValueList<ToDoEvent> tl = todoDB.rawToDos(); 575 QValueList<ToDoEvent> tl = todoDB.rawToDos();
574 for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) { 576 for( QValueList<ToDoEvent>::Iterator it = tl.begin(); it != tl.end(); ++it ) {
575 table->addEntry( *it ); 577 table->addEntry( *it );
576 } 578 }
577} 579}
578 580
579static const char * beamfile = "/tmp/obex/todo.vcs"; 581static const char * beamfile = "/tmp/obex/todo.vcs";
580 582
581void TodoWindow::slotBeam() 583void TodoWindow::slotBeam()
582{ 584{
583 unlink( beamfile ); // delete if exists 585 unlink( beamfile ); // delete if exists
584 ToDoEvent c = table->currentEntry(); 586 ToDoEvent c = table->currentEntry();
585 mkdir("/tmp/obex/", 0755); 587 mkdir("/tmp/obex/", 0755);
586 ToDoDB todoDB( beamfile, new ToDoVCalResource() ); 588 ToDoDB todoDB( beamfile, new ToDoVCalResource() );
587 todoDB.addEvent( c ); 589 todoDB.addEvent( c );
588 todoDB.save(); 590 todoDB.save();
589 Ir *ir = new Ir( this ); 591 Ir *ir = new Ir( this );
590 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 592 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
591 QString description = c.description(); 593 QString description = c.description();
592 ir->send( beamfile, description, "text/x-vCalendar" ); 594 ir->send( beamfile, description, "text/x-vCalendar" );
593} 595}
594 596
595void TodoWindow::beamDone( Ir *ir ) 597void TodoWindow::beamDone( Ir *ir )
596{ 598{
597 delete ir; 599 delete ir;
598 unlink( beamfile ); 600 unlink( beamfile );
599} 601}
600 602
601void TodoWindow::showDeadline( bool s ) 603void TodoWindow::showDeadline( bool s )
602{ 604{
603 table->setPaintingEnabled( false ); 605 table->setPaintingEnabled( false );
604 table->setShowDeadline( s ); 606 table->setShowDeadline( s );
605 table->setPaintingEnabled( true ); 607 table->setPaintingEnabled( true );
606} 608}
607void TodoWindow::slotShowDetails() 609void TodoWindow::slotShowDetails()
608{ 610{
609 ToDoEvent event = table->currentEntry(); 611 ToDoEvent event = table->currentEntry();
610 slotShowDetails( event ); 612 slotShowDetails( event );
611} 613}
612void TodoWindow::slotShowDetails( const ToDoEvent &event ) 614void TodoWindow::slotShowDetails( const ToDoEvent &event )
613{ 615{
614 if( mView == 0l ){ 616 if( mView == 0l ){
615 mView = new TodoLabel(mStack); 617 mView = new TodoLabel(mStack);
616 mStack->addWidget( mView, 2 ); 618 mStack->addWidget( mView, 2 );
617 } 619 }
618 mView->init( event ); 620 mView->init( event );
619 mView->sync(); 621 mView->sync();
620 mStack->raiseWidget( 2); 622 mStack->raiseWidget( 2);
621} 623}
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 753c036..dc60cc4 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -505,236 +505,237 @@ void TodoTable::setPaintingEnabled( bool e )
505 enablePainting = true; 505 enablePainting = true;
506 rowHeightChanged( 0 ); 506 rowHeightChanged( 0 );
507 viewport()->update(); 507 viewport()->update();
508 } else { 508 } else {
509 enablePainting = false; 509 enablePainting = false;
510 } 510 }
511 } 511 }
512} 512}
513 513
514void TodoTable::clear() 514void TodoTable::clear()
515{ 515{
516 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); 516 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
517 it != todoList.end(); ++it ) { 517 it != todoList.end(); ++it ) {
518 ToDoEvent *todo = it.data(); 518 ToDoEvent *todo = it.data();
519 updateJournal( *todo, ACTION_REMOVE ); 519 updateJournal( *todo, ACTION_REMOVE );
520 delete todo; 520 delete todo;
521 } 521 }
522 todoList.clear(); 522 todoList.clear();
523 for ( int r = 0; r < numRows(); ++r ) { 523 for ( int r = 0; r < numRows(); ++r ) {
524 for ( int c = 0; c < numCols(); ++c ) { 524 for ( int c = 0; c < numCols(); ++c ) {
525 if ( cellWidget( r, c ) ) 525 if ( cellWidget( r, c ) )
526 clearCellWidget( r, c ); 526 clearCellWidget( r, c );
527 clearCell( r, c ); 527 clearCell( r, c );
528 } 528 }
529 } 529 }
530 setNumRows( 0 ); 530 setNumRows( 0 );
531} 531}
532 532
533void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) 533void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ )
534{ 534{
535 // The default for wholeRows is false, however 535 // The default for wholeRows is false, however
536 // for this todo table we want to exchange complete 536 // for this todo table we want to exchange complete
537 // rows when sorting. Also, we always want ascending, since 537 // rows when sorting. Also, we always want ascending, since
538 // the values have a logical order. 538 // the values have a logical order.
539 QTable::sortColumn( col, ascending, TRUE ); 539 QTable::sortColumn( col, ascending, TRUE );
540 updateVisible(); 540 updateVisible();
541} 541}
542 542
543void TodoTable::slotCheckPriority(int row, int col ) 543void TodoTable::slotCheckPriority(int row, int col )
544{ 544{
545 // kludgey work around to make forward along the updated priority... 545 // kludgey work around to make forward along the updated priority...
546 if ( col == 1 ) { 546 if ( col == 1 ) {
547 // let everyone know!! 547 // let everyone know!!
548 ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); 548 ComboItem* i = static_cast<ComboItem*>( item( row, col ) );
549 emit signalPriorityChanged( i->text().toInt() ); 549 emit signalPriorityChanged( i->text().toInt() );
550 } 550 }
551} 551}
552 552
553 553
554void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action ) 554void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action )
555{ 555{
556 QFile f( journalFileName() ); 556 QFile f( journalFileName() );
557 if ( !f.open(IO_WriteOnly|IO_Append) ) 557 if ( !f.open(IO_WriteOnly|IO_Append) )
558 return; 558 return;
559 QString buf; 559 QString buf;
560 QCString str; 560 QCString str;
561 buf = "<Task"; 561 buf = "<Task";
562 // todo.save( buf ); 562 // todo.save( buf );
563 buf += " Action=\"" + QString::number( int(action) ) + "\""; 563 buf += " Action=\"" + QString::number( int(action) ) + "\"";
564 buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id 564 buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id
565 buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\""; 565 buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\"";
566 buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\""; 566 buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\"";
567 buf += " Priority=\"" + QString::number( todo.priority() ) + "\""; 567 buf += " Priority=\"" + QString::number( todo.priority() ) + "\"";
568 QArray<int> arrat = todo.categories(); 568 QArray<int> arrat = todo.categories();
569 QString attr; 569 QString attr;
570 for(uint i=0; i < arrat.count(); i++ ){ 570 for(uint i=0; i < arrat.count(); i++ ){
571 attr.append(QString::number(arrat[i])+";" ); 571 attr.append(QString::number(arrat[i])+";" );
572 } 572 }
573 if(!attr.isEmpty() ) // remove the last ; 573 if(!attr.isEmpty() ) // remove the last ;
574 attr.remove(attr.length()-1, 1 ); 574 attr.remove(attr.length()-1, 1 );
575 buf += " Categories=\"" + attr + "\""; 575 buf += " Categories=\"" + attr + "\"";
576 buf += " Description=\"" + todo.description() + "\""; 576 buf += " Description=\"" + todo.description() + "\"";
577 if(todo.hasDate() ) { 577 if(todo.hasDate() ) {
578 buf += " DateYear=\""+QString::number( todo.date().year() ) + "\""; 578 buf += " DateYear=\""+QString::number( todo.date().year() ) + "\"";
579 buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\""; 579 buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\"";
580 buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\""; 580 buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\"";
581 } 581 }
582 buf += "/>\n"; 582 buf += "/>\n";
583 str = buf.utf8(); 583 str = buf.utf8();
584 f.writeBlock( str.data(), str.length() ); 584 f.writeBlock( str.data(), str.length() );
585 f.close(); 585 f.close();
586} 586}
587 587
588void TodoTable::rowHeightChanged( int row ) 588void TodoTable::rowHeightChanged( int row )
589{ 589{
590 if ( enablePainting ) 590 if ( enablePainting )
591 QTable::rowHeightChanged( row ); 591 QTable::rowHeightChanged( row );
592} 592}
593 593
594void TodoTable::loadFile( const QString &/*we use the standard*/ ) 594void TodoTable::loadFile( const QString &/*we use the standard*/ )
595{ 595{
596 596
597 QList<ToDoEvent> list; 597 QList<ToDoEvent> list;
598 ToDoDB todoDB; 598 ToDoDB todoDB;
599 QValueList<ToDoEvent> vaList = todoDB.rawToDos(); 599 QValueList<ToDoEvent> vaList = todoDB.rawToDos();
600 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ 600 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){
601 list.append( new ToDoEvent( (*it) ) ); 601 ToDoEvent *event = new ToDoEvent( (*it) );
602 list.append( event );
602 } 603 }
603 vaList.clear(); 604 vaList.clear();
604 // qDebug("parsing done=%d", t.elapsed() ); 605 // qDebug("parsing done=%d", t.elapsed() );
605 if ( list.count() > 0 ) { 606 if ( list.count() > 0 ) {
606 internalAddEntries( list ); 607 internalAddEntries( list );
607 list.clear(); 608 list.clear();
608 } 609 }
609// qDebug("loading done: t=%d", t.elapsed() ); 610// qDebug("loading done: t=%d", t.elapsed() );
610} 611}
611 612
612void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row ) 613void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
613{ 614{
614 QString strTodo; 615 QString strTodo;
615 strTodo = todo.description().left(40).simplifyWhiteSpace(); 616 strTodo = todo.description().left(40).simplifyWhiteSpace();
616 if ( row == -1 ) { 617 if ( row == -1 ) {
617 QMapIterator<CheckItem*, ToDoEvent *> it; 618 QMapIterator<CheckItem*, ToDoEvent *> it;
618 for ( it = todoList.begin(); it != todoList.end(); ++it ) { 619 for ( it = todoList.begin(); it != todoList.end(); ++it ) {
619 if ( *(*it) == todo ) { 620 if ( *(*it) == todo ) {
620 row = it.key()->row(); 621 row = it.key()->row();
621 it.key()->setChecked( todo.isCompleted() ); 622 it.key()->setChecked( todo.isCompleted() );
622 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 623 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
623 item( row, 2 )->setText( strTodo ); 624 item( row, 2 )->setText( strTodo );
624 625
625 if (showDeadl){ 626 if (showDeadl){
626 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); 627 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo );
627 } 628 }
628 629
629 *(*it) = todo; 630 *(*it) = todo;
630 } 631 }
631 } 632 }
632 } else { 633 } else {
633 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; 634 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))];
634 todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); 635 todoList.remove( static_cast<CheckItem*>(item(row, 0)) );
635 delete t; 636 delete t;
636 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() ); 637 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() );
637 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 638 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
638 item( row, 2 )->setText( strTodo ); 639 item( row, 2 )->setText( strTodo );
639 640
640 if (showDeadl){ 641 if (showDeadl){
641 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); 642 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo );
642 } 643 }
643 644 ToDoEvent *ev = new ToDoEvent( todo );
644 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); 645 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(ev) );
645 } 646 }
646} 647}
647 648
648void TodoTable::journalFreeRemoveEntry( int row ) 649void TodoTable::journalFreeRemoveEntry( int row )
649{ 650{
650 CheckItem *chk; 651 CheckItem *chk;
651 chk = static_cast<CheckItem*>(item(row, 0 )); 652 chk = static_cast<CheckItem*>(item(row, 0 ));
652 if ( !chk ) 653 if ( !chk )
653 return; 654 return;
654 todoList.remove( chk ); 655 todoList.remove( chk );
655 656
656 realignTable( row ); 657 realignTable( row );
657} 658}
658 659
659void TodoTable::keyPressEvent( QKeyEvent *e ) 660void TodoTable::keyPressEvent( QKeyEvent *e )
660{ 661{
661 if ( e->key() == Key_Space || e->key() == Key_Return ) { 662 if ( e->key() == Key_Space || e->key() == Key_Return ) {
662 switch ( currentColumn() ) { 663 switch ( currentColumn() ) {
663 case 0: { 664 case 0: {
664 CheckItem *i = static_cast<CheckItem*>(item(currentRow(), 665 CheckItem *i = static_cast<CheckItem*>(item(currentRow(),
665 currentColumn())); 666 currentColumn()));
666 if ( i ) 667 if ( i )
667 i->toggle(); 668 i->toggle();
668 break; 669 break;
669 } 670 }
670 case 1: 671 case 1:
671 break; 672 break;
672 case 2: 673 case 2:
673 emit signalEdit(); 674 emit signalEdit();
674 default: 675 default:
675 break; 676 break;
676 } 677 }
677 } else { 678 } else {
678 QTable::keyPressEvent( e ); 679 QTable::keyPressEvent( e );
679 } 680 }
680} 681}
681 682
682QStringList TodoTable::categories() 683QStringList TodoTable::categories()
683{ 684{
684 // This is called seldom, so calling a load in here 685 // This is called seldom, so calling a load in here
685 // should be fine. 686 // should be fine.
686 mCat.load( categoryFileName() ); 687 mCat.load( categoryFileName() );
687 QStringList categoryList = mCat.labels( "Todo List" ); 688 QStringList categoryList = mCat.labels( "Todo List" );
688 return categoryList; 689 return categoryList;
689} 690}
690 691
691void TodoTable::slotDoFind( const QString &findString, bool caseSensitive, 692void TodoTable::slotDoFind( const QString &findString, bool caseSensitive,
692 bool backwards, int category ) 693 bool backwards, int category )
693{ 694{
694 // we have to iterate through the table, this gives the illusion that 695 // we have to iterate through the table, this gives the illusion that
695 // sorting is actually being used. 696 // sorting is actually being used.
696 if ( currFindRow < -1 ) 697 if ( currFindRow < -1 )
697 currFindRow = currentRow() - 1; 698 currFindRow = currentRow() - 1;
698 clearSelection( TRUE ); 699 clearSelection( TRUE );
699 int rows, 700 int rows,
700 row; 701 row;
701 CheckItem *chk; 702 CheckItem *chk;
702 QRegExp r( findString ); 703 QRegExp r( findString );
703 704
704 r.setCaseSensitive( caseSensitive ); 705 r.setCaseSensitive( caseSensitive );
705 rows = numRows(); 706 rows = numRows();
706 static bool wrapAround = true; 707 static bool wrapAround = true;
707 708
708 if ( !backwards ) { 709 if ( !backwards ) {
709 for ( row = currFindRow + 1; row < rows; row++ ) { 710 for ( row = currFindRow + 1; row < rows; row++ ) {
710 chk = static_cast<CheckItem*>( item(row, 0) ); 711 chk = static_cast<CheckItem*>( item(row, 0) );
711 if ( taskCompare(*(todoList[chk]), r, category) ) 712 if ( taskCompare(*(todoList[chk]), r, category) )
712 break; 713 break;
713 } 714 }
714 } else { 715 } else {
715 for ( row = currFindRow - 1; row > -1; row-- ) { 716 for ( row = currFindRow - 1; row > -1; row-- ) {
716 chk = static_cast<CheckItem*>( item(row, 0) ); 717 chk = static_cast<CheckItem*>( item(row, 0) );
717 if ( taskCompare(*(todoList[chk]), r, category) ) 718 if ( taskCompare(*(todoList[chk]), r, category) )
718 break; 719 break;
719 } 720 }
720 } 721 }
721 if ( row >= rows || row < 0 ) { 722 if ( row >= rows || row < 0 ) {
722 if ( row < 0 ) 723 if ( row < 0 )
723 currFindRow = rows; 724 currFindRow = rows;
724 else 725 else
725 currFindRow = -1; 726 currFindRow = -1;
726 if ( wrapAround ) 727 if ( wrapAround )
727 emit signalWrapAround(); 728 emit signalWrapAround();
728 else 729 else
729 emit signalNotFound(); 730 emit signalNotFound();
730 wrapAround = !wrapAround; 731 wrapAround = !wrapAround;
731 } else { 732 } else {
732 currFindRow = row; 733 currFindRow = row;
733 QTableSelection foundSelection; 734 QTableSelection foundSelection;
734 foundSelection.init( currFindRow, 0 ); 735 foundSelection.init( currFindRow, 0 );
735 foundSelection.expandTo( currFindRow, numCols() - 1 ); 736 foundSelection.expandTo( currFindRow, numCols() - 1 );
736 addSelection( foundSelection ); 737 addSelection( foundSelection );
737 setCurrentCell( currFindRow, numCols() - 1 ); 738 setCurrentCell( currFindRow, numCols() - 1 );
738 // we should always be able to wrap around and find this again, 739 // we should always be able to wrap around and find this again,
739 // so don't give confusing not found message... 740 // so don't give confusing not found message...
740 wrapAround = true; 741 wrapAround = true;