summaryrefslogtreecommitdiff
path: root/core/pim/todo/todotable.cpp
Unidiff
Diffstat (limited to 'core/pim/todo/todotable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp68
1 files changed, 64 insertions, 4 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 2bb95a2..3cd0c0e 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -14,13 +14,14 @@
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20/* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de)
21 */
21#include "todotable.h" 22#include "todotable.h"
22 23
23#include <opie/tododb.h> 24#include <opie/tododb.h>
24#include <qpe/categoryselect.h> 25#include <qpe/categoryselect.h>
25#include <qpe/xmlreader.h> 26#include <qpe/xmlreader.h>
26 27
@@ -35,12 +36,14 @@
35#include <qcursor.h> 36#include <qcursor.h>
36#include <qregexp.h> 37#include <qregexp.h>
37 38
38#include <errno.h> 39#include <errno.h>
39#include <stdlib.h> 40#include <stdlib.h>
40 41
42#include <stdio.h>
43
41 44
42 45
43static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); 46static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
44 47
45static QString journalFileName(); 48static QString journalFileName();
46 49
@@ -161,30 +164,43 @@ QString ComboItem::text() const
161 164
162 165
163TodoTable::TodoTable( QWidget *parent, const char *name ) 166TodoTable::TodoTable( QWidget *parent, const char *name )
164// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR 167// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR
165// : QTable( 0, 3, parent, name, TRUE ), 168// : QTable( 0, 3, parent, name, TRUE ),
166// #else 169// #else
167 : QTable( 0, 3, parent, name ), 170 : QTable( 0, 4, parent, name ),
168// #endif 171// #endif
169 showComp( true ), 172 showComp( true ),
170 enablePainting( true ), 173 enablePainting( true ),
171 mCat( 0 ), 174 mCat( 0 ),
172 currFindRow( -2 ) 175 currFindRow( -2 ),
176 showDeadl( true)
173{ 177{
174 mCat.load( categoryFileName() ); 178 mCat.load( categoryFileName() );
175 setSorting( TRUE ); 179 setSorting( TRUE );
176 setSelectionMode( NoSelection ); 180 setSelectionMode( NoSelection );
177 setColumnStretchable( 2, TRUE ); 181 setColumnStretchable( 2, TRUE );
178 setColumnWidth( 0, 20 ); 182 setColumnWidth( 0, 20 );
179 setColumnWidth( 1, 35 ); 183 setColumnWidth( 1, 35 );
184
180 setLeftMargin( 0 ); 185 setLeftMargin( 0 );
181 verticalHeader()->hide(); 186 verticalHeader()->hide();
182 horizontalHeader()->setLabel( 0, tr( "C." ) ); 187 horizontalHeader()->setLabel( 0, tr( "C." ) );
183 horizontalHeader()->setLabel( 1, tr( "Prior." ) ); 188 horizontalHeader()->setLabel( 1, tr( "Prior." ) );
184 horizontalHeader()->setLabel( 2, tr( "Description" ) ); 189 horizontalHeader()->setLabel( 2, tr( "Description" ) );
190
191 setColumnStretchable( 3, FALSE );
192 setColumnWidth( 3, 20 );
193 horizontalHeader()->setLabel( 3, tr( "Deadline" ) );
194
195 if (showDeadl){
196 showColumn (3);
197 }else{
198 hideColumn (3);
199 }
200
185 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 201 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
186 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); 202 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) );
187 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), 203 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ),
188 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); 204 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) );
189 connect( this, SIGNAL( valueChanged( int, int ) ), 205 connect( this, SIGNAL( valueChanged( int, int ) ),
190 this, SLOT( slotCheckPriority( int, int ) ) ); 206 this, SLOT( slotCheckPriority( int, int ) ) );
@@ -231,12 +247,17 @@ void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
231 break; 247 break;
232 case 2: 248 case 2:
233 // may as well edit it... 249 // may as well edit it...
234 menuTimer->stop(); 250 menuTimer->stop();
235// emit signalEdit(); 251// emit signalEdit();
236 break; 252 break;
253 case 3: /* added 20.01.2k2 by se */
254 // may as well edit it...
255 menuTimer->stop();
256 emit signalEdit();
257 break;
237 } 258 }
238} 259}
239 260
240void TodoTable::slotPressed( int row, int col, int, const QPoint &pos ) 261void TodoTable::slotPressed( int row, int col, int, const QPoint &pos )
241{ 262{
242 if ( col == 2 && cellGeometry( row, col ).contains(pos) ) 263 if ( col == 2 && cellGeometry( row, col ).contains(pos) )
@@ -262,12 +283,14 @@ void TodoTable::internalAddEntries( QList<ToDoEvent> &list )
262 insertIntoTable( it, row++ ); 283 insertIntoTable( it, row++ );
263} 284}
264 285
265 286
266ToDoEvent TodoTable::currentEntry() const 287ToDoEvent TodoTable::currentEntry() const
267{ 288{
289 printf ("in currentEntry\n");
290
268 QTableItem *i = item( currentRow(), 0 ); 291 QTableItem *i = item( currentRow(), 0 );
269 if ( !i || rowHeight( currentRow() ) <= 0 ) 292 if ( !i || rowHeight( currentRow() ) <= 0 )
270 return ToDoEvent(); 293 return ToDoEvent();
271 ToDoEvent *todo = todoList[(CheckItem*)i]; 294 ToDoEvent *todo = todoList[(CheckItem*)i];
272 todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); 295 todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() );
273 todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); 296 todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() );
@@ -351,12 +374,21 @@ void TodoTable::updateVisible()
351{ 374{
352 if ( !isUpdatesEnabled() ) 375 if ( !isUpdatesEnabled() )
353 return; 376 return;
354 377
355// qDebug("--> updateVisible!"); 378// qDebug("--> updateVisible!");
356 379
380 /* added 20.01.2k2 by se */
381 if (showDeadl){
382 showColumn (3);
383 adjustColumn(3);
384 }else{
385 hideColumn (3);
386 adjustColumn(2);
387 }
388
357 int visible = 0; 389 int visible = 0;
358 int id = mCat.id( "Todo List", showCat ); 390 int id = mCat.id( "Todo List", showCat );
359 for ( int row = 0; row < numRows(); row++ ) { 391 for ( int row = 0; row < numRows(); row++ ) {
360 CheckItem *ci = (CheckItem *)item( row, 0 ); 392 CheckItem *ci = (CheckItem *)item( row, 0 );
361 ToDoEvent *t = todoList[ci]; 393 ToDoEvent *t = todoList[ci];
362 QArray<int> vlCats = t->categories(); 394 QArray<int> vlCats = t->categories();
@@ -452,13 +484,13 @@ void TodoTable::slotCheckPriority(int row, int col )
452 ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); 484 ComboItem* i = static_cast<ComboItem*>( item( row, col ) );
453 emit signalPriorityChanged( i->text().toInt() ); 485 emit signalPriorityChanged( i->text().toInt() );
454 } 486 }
455} 487}
456 488
457 489
458void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action, int row ) 490void TodoTable::updateJournal( const ToDoEvent &/*todo*/, journal_action action, int row )
459{ 491{
460 QFile f( journalFileName() ); 492 QFile f( journalFileName() );
461 if ( !f.open(IO_WriteOnly|IO_Append) ) 493 if ( !f.open(IO_WriteOnly|IO_Append) )
462 return; 494 return;
463 QString buf; 495 QString buf;
464 QCString str; 496 QCString str;
@@ -505,22 +537,50 @@ void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
505 for ( it = todoList.begin(); it != todoList.end(); ++it ) { 537 for ( it = todoList.begin(); it != todoList.end(); ++it ) {
506 if ( *(*it) == todo ) { 538 if ( *(*it) == todo ) {
507 row = it.key()->row(); 539 row = it.key()->row();
508 it.key()->setChecked( todo.isCompleted() ); 540 it.key()->setChecked( todo.isCompleted() );
509 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 541 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
510 item( row, 2 )->setText( strTodo ); 542 item( row, 2 )->setText( strTodo );
543
544 /* added 20.01.2k2 by se */
545 if (showDeadl){
546 if (todo.hasDate()){
547 QDate *today = new QDate (QDate::currentDate());
548 if (today){
549 item (row, 3)->setText (tr ("%1").arg(today->daysTo(todo.date())));
550 delete (today);
551 }
552 }else{
553 item (row, 3)->setText ("n.d.");
554 }
555 }
556
511 *(*it) = todo; 557 *(*it) = todo;
512 } 558 }
513 } 559 }
514 } else { 560 } else {
515 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; 561 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))];
516 todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); 562 todoList.remove( static_cast<CheckItem*>(item(row, 0)) );
517 delete t; 563 delete t;
518 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() ); 564 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() );
519 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 565 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
520 item( row, 2 )->setText( strTodo ); 566 item( row, 2 )->setText( strTodo );
567
568 /* added 20.01.2k2 by se */
569 if (showDeadl){
570 if (todo.hasDate()){
571 QDate *today = new QDate (QDate::currentDate());
572 if (today){
573 item (row, 3)->setText (tr ("%1").arg(today->daysTo(todo.date())));
574 delete (today);
575 }
576 }else{
577 item (row, 3)->setText ("n.d.");
578 }
579 }
580
521 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); 581 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) );
522 } 582 }
523} 583}
524 584
525void TodoTable::journalFreeRemoveEntry( int row ) 585void TodoTable::journalFreeRemoveEntry( int row )
526{ 586{