summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp23
-rw-r--r--core/pim/todo/todotable.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 96cd860..d0bc61c 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -1,905 +1,928 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
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/* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de) 20/* Show Deadline was added by Stefan Eilers (se, eilers.stefan@epost.de)
21 */ 21 */
22#include "todotable.h" 22#include "todotable.h"
23 23
24#include <opie/tododb.h> 24#include <opie/tododb.h>
25#include <opie/xmltree.h> 25#include <opie/xmltree.h>
26 26
27#include <qpe/categoryselect.h> 27#include <qpe/categoryselect.h>
28#include <qpe/xmlreader.h> 28#include <qpe/xmlreader.h>
29 29
30#include <qasciidict.h> 30#include <qasciidict.h>
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qtextcodec.h> 34#include <qtextcodec.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qdatetime.h> 36#include <qdatetime.h>
37#include <qtextstream.h> 37#include <qtextstream.h>
38 38
39#include <qcursor.h> 39#include <qcursor.h>
40#include <qregexp.h> 40#include <qregexp.h>
41 41
42#include <errno.h> 42#include <errno.h>
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45#include <stdio.h> 45#include <stdio.h>
46#include <iostream> 46#include <iostream>
47 47
48namespace { 48namespace {
49 49
50 static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ); 50 static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category );
51 static QString journalFileName(); 51 static QString journalFileName();
52 static ToDoEvent xmlToEvent( XMLElement *ev ); 52 static ToDoEvent xmlToEvent( XMLElement *ev );
53} 53}
54CheckItem::CheckItem( QTable *t, const QString &key ) 54CheckItem::CheckItem( QTable *t, const QString &key )
55 : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key ) 55 : QTableItem( t, Never, "" ), checked( FALSE ), sortKey( key )
56{ 56{
57} 57}
58 58
59QString CheckItem::key() const 59QString CheckItem::key() const
60{ 60{
61 return sortKey; 61 return sortKey;
62} 62}
63 63
64void CheckItem::setChecked( bool b ) 64void CheckItem::setChecked( bool b )
65{ 65{
66 checked = b; 66 checked = b;
67 table()->updateCell( row(), col() ); 67 table()->updateCell( row(), col() );
68} 68}
69 69
70void CheckItem::toggle() 70void CheckItem::toggle()
71{ 71{
72 TodoTable *parent = static_cast<TodoTable*>(table()); 72 TodoTable *parent = static_cast<TodoTable*>(table());
73 ToDoEvent newTodo = parent->currentEntry(); 73 ToDoEvent newTodo = parent->currentEntry();
74 checked = !checked; 74 checked = !checked;
75 newTodo.setCompleted( checked ); 75 newTodo.setCompleted( checked );
76 table()->updateCell( row(), col() ); 76 table()->updateCell( row(), col() );
77 parent->replaceCurrentEntry( newTodo, true ); 77 parent->replaceCurrentEntry( newTodo, true );
78} 78}
79 79
80bool CheckItem::isChecked() const 80bool CheckItem::isChecked() const
81{ 81{
82 return checked; 82 return checked;
83} 83}
84 84
85static const int BoxSize = 10; 85static const int BoxSize = 10;
86 86
87void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, 87void CheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr,
88 bool ) 88 bool )
89{ 89{
90 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 90 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
91 91
92 int marg = ( cr.width() - BoxSize ) / 2; 92 int marg = ( cr.width() - BoxSize ) / 2;
93 int x = 0; 93 int x = 0;
94 int y = ( cr.height() - BoxSize ) / 2; 94 int y = ( cr.height() - BoxSize ) / 2;
95 p->setPen( QPen( cg.text() ) ); 95 p->setPen( QPen( cg.text() ) );
96 p->drawRect( x + marg, y, BoxSize, BoxSize ); 96 p->drawRect( x + marg, y, BoxSize, BoxSize );
97 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 97 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
98 p->setPen( darkGreen ); 98 p->setPen( darkGreen );
99 x += 1; 99 x += 1;
100 y += 1; 100 y += 1;
101 if ( checked ) { 101 if ( checked ) {
102 QPointArray a( 7*2 ); 102 QPointArray a( 7*2 );
103 int i, xx, yy; 103 int i, xx, yy;
104 xx = x+1+marg; 104 xx = x+1+marg;
105 yy = y+2; 105 yy = y+2;
106 for ( i=0; i<3; i++ ) { 106 for ( i=0; i<3; i++ ) {
107 a.setPoint( 2*i, xx, yy ); 107 a.setPoint( 2*i, xx, yy );
108 a.setPoint( 2*i+1, xx, yy+2 ); 108 a.setPoint( 2*i+1, xx, yy+2 );
109 xx++; yy++; 109 xx++; yy++;
110 } 110 }
111 yy -= 2; 111 yy -= 2;
112 for ( i=3; i<7; i++ ) { 112 for ( i=3; i<7; i++ ) {
113 a.setPoint( 2*i, xx, yy ); 113 a.setPoint( 2*i, xx, yy );
114 a.setPoint( 2*i+1, xx, yy+2 ); 114 a.setPoint( 2*i+1, xx, yy+2 );
115 xx++; yy--; 115 xx++; yy--;
116 } 116 }
117 p->drawLineSegments( a ); 117 p->drawLineSegments( a );
118 } 118 }
119} 119}
120 120
121 121
122ComboItem::ComboItem( QTable *t, EditType et ) 122ComboItem::ComboItem( QTable *t, EditType et )
123 : QTableItem( t, et, "3" ), cb( 0 ) 123 : QTableItem( t, et, "3" ), cb( 0 )
124{ 124{
125 setReplaceable( FALSE ); 125 setReplaceable( FALSE );
126} 126}
127 127
128QWidget *ComboItem::createEditor() const 128QWidget *ComboItem::createEditor() const
129{ 129{
130 QString txt = text(); 130 QString txt = text();
131 ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() ); 131 ( (ComboItem*)this )->cb = new QComboBox( table()->viewport() );
132 cb->insertItem( "1" ); 132 cb->insertItem( "1" );
133 cb->insertItem( "2" ); 133 cb->insertItem( "2" );
134 cb->insertItem( "3" ); 134 cb->insertItem( "3" );
135 cb->insertItem( "4" ); 135 cb->insertItem( "4" );
136 cb->insertItem( "5" ); 136 cb->insertItem( "5" );
137 cb->setCurrentItem( txt.toInt() - 1 ); 137 cb->setCurrentItem( txt.toInt() - 1 );
138 return cb; 138 return cb;
139} 139}
140 140
141void ComboItem::setContentFromEditor( QWidget *w ) 141void ComboItem::setContentFromEditor( QWidget *w )
142{ 142{
143 TodoTable *parent = static_cast<TodoTable*>(table()); 143 TodoTable *parent = static_cast<TodoTable*>(table());
144 ToDoEvent newTodo = parent->currentEntry(); 144 ToDoEvent newTodo = parent->currentEntry();
145 145
146 if ( w->inherits( "QComboBox" ) ) 146 if ( w->inherits( "QComboBox" ) )
147 setText( ( (QComboBox*)w )->currentText() ); 147 setText( ( (QComboBox*)w )->currentText() );
148 else 148 else
149 QTableItem::setContentFromEditor( w ); 149 QTableItem::setContentFromEditor( w );
150 newTodo.setPriority( text().toInt() ); 150 newTodo.setPriority( text().toInt() );
151 parent->replaceCurrentEntry( newTodo, true ); 151 parent->replaceCurrentEntry( newTodo, true );
152} 152}
153 153
154void ComboItem::setText( const QString &s ) 154void ComboItem::setText( const QString &s )
155{ 155{
156 if ( cb ) 156 if ( cb )
157 cb->setCurrentItem( s.toInt() - 1 ); 157 cb->setCurrentItem( s.toInt() - 1 );
158 QTableItem::setText( s ); 158 QTableItem::setText( s );
159} 159}
160 160
161QString ComboItem::text() const 161QString ComboItem::text() const
162{ 162{
163 if ( cb ) 163 if ( cb )
164 return cb->currentText(); 164 return cb->currentText();
165 return QTableItem::text(); 165 return QTableItem::text();
166} 166}
167DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev ) 167DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev )
168 : QTableItem(t, Never, QString::null ) 168 : QTableItem(t, Never, QString::null )
169{ 169{
170 setToDoEvent( ev ); 170 setToDoEvent( ev );
171} 171}
172QString DueTextItem::key() const 172QString DueTextItem::key() const
173{ 173{
174 QString key; 174 QString key;
175 if( m_hasDate ){ 175 if( m_hasDate ){
176 if(m_off == 0 ){ 176 if(m_off == 0 ){
177 key.append("b"); 177 key.append("b");
178 }else if( m_off > 0 ){ 178 }else if( m_off > 0 ){
179 key.append("c"); 179 key.append("c");
180 }else if( m_off < 0 ){ 180 }else if( m_off < 0 ){
181 key.append("a"); 181 key.append("a");
182 } 182 }
183 key.append(QString::number(m_off ) ); 183 key.append(QString::number(m_off ) );
184 }else{ 184 }else{
185 key.append("d"); 185 key.append("d");
186 } 186 }
187 return key; 187 return key;
188} 188}
189void DueTextItem::setToDoEvent( const ToDoEvent *ev ) 189void DueTextItem::setToDoEvent( const ToDoEvent *ev )
190{ 190{
191 m_hasDate = ev->hasDate(); 191 m_hasDate = ev->hasDate();
192 m_completed = ev->isCompleted(); 192 m_completed = ev->isCompleted();
193 if( ev->hasDate() ){ 193 if( ev->hasDate() ){
194 QDate today = QDate::currentDate(); 194 QDate today = QDate::currentDate();
195 m_off = today.daysTo(ev->date() ); 195 m_off = today.daysTo(ev->date() );
196 //qWarning("DueText m_off=%d", m_off );
196 setText( QString::number(m_off) + " day(s) " ); 197 setText( QString::number(m_off) + " day(s) " );
197 }else{ 198 }else{
198 setText("n.d." ); 199 setText("n.d." );
199 m_off = 0; 200 m_off = 0;
200 } 201 }
202 //qWarning("m_off=%d", m_off );
201} 203}
202void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) 204void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected )
203{ 205{
206 //qWarning ("paint m_off=%d", m_off );
204 QColorGroup cg2(cg); 207 QColorGroup cg2(cg);
205 QColor text = cg.text(); 208 QColor text = cg.text();
206 if( m_hasDate && !m_completed ){ 209 if( m_hasDate && !m_completed ){
207 if( m_off < 0 ){ 210 if( m_off < 0 ){
208 cg2.setColor(QColorGroup::Text, QColor(red ) ); 211 cg2.setColor(QColorGroup::Text, QColor(red ) );
209 }else if( m_off == 0 ){ 212 }else if( m_off == 0 ){
210 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined 213 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined
211 }else if( m_off > 0){ 214 }else if( m_off > 0){
212 cg2.setColor(QColorGroup::Text, QColor(green ) ); 215 cg2.setColor(QColorGroup::Text, QColor(green ) );
213 } 216 }
214 } 217 }
215 QTableItem::paint(p, cg2, cr, selected ); 218 QTableItem::paint(p, cg2, cr, selected );
216 cg2.setColor(QColorGroup::Text, text ); 219 cg2.setColor(QColorGroup::Text, text );
217} 220}
218TodoTable::TodoTable( QWidget *parent, const char *name ) 221TodoTable::TodoTable( QWidget *parent, const char *name )
219// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR 222// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR
220// : QTable( 0, 3, parent, name, TRUE ), 223// : QTable( 0, 3, parent, name, TRUE ),
221// #else 224// #else
222 : QTable( 0, 4, parent, name ), 225 : QTable( 0, 4, parent, name ),
223// #endif 226// #endif
224 showComp( true ), 227 showComp( true ),
225 enablePainting( true ), 228 enablePainting( true ),
226 mCat( 0 ), 229 mCat( 0 ),
227 currFindRow( -2 ), 230 currFindRow( -2 ),
228 showDeadl( true) 231 showDeadl( true)
229{ 232{
230 mCat.load( categoryFileName() ); 233 mCat.load( categoryFileName() );
231 setSorting( TRUE ); 234 setSorting( TRUE );
232 setSelectionMode( NoSelection ); 235 setSelectionMode( NoSelection );
233 setColumnStretchable( 2, TRUE ); 236 setColumnStretchable( 2, TRUE );
234 setColumnWidth( 0, 20 ); 237 setColumnWidth( 0, 20 );
235 setColumnWidth( 1, 35 ); 238 setColumnWidth( 1, 35 );
236 239
237 setLeftMargin( 0 ); 240 setLeftMargin( 0 );
238 verticalHeader()->hide(); 241 verticalHeader()->hide();
239 horizontalHeader()->setLabel( 0, tr( "C." ) ); 242 horizontalHeader()->setLabel( 0, tr( "C." ) );
240 horizontalHeader()->setLabel( 1, tr( "Prior." ) ); 243 horizontalHeader()->setLabel( 1, tr( "Prior." ) );
241 horizontalHeader()->setLabel( 2, tr( "Description" ) ); 244 horizontalHeader()->setLabel( 2, tr( "Description" ) );
242 245
243 setColumnStretchable( 3, FALSE ); 246 setColumnStretchable( 3, FALSE );
244 setColumnWidth( 3, 20 ); 247 setColumnWidth( 3, 20 );
245 horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); 248 horizontalHeader()->setLabel( 3, tr( "Deadline" ) );
246 249
247 if (showDeadl){ 250 if (showDeadl){
248 showColumn (3); 251 showColumn (3);
249 }else{ 252 }else{
250 hideColumn (3); 253 hideColumn (3);
251 } 254 }
252 255
253 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 256 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
254 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); 257 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) );
255 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), 258 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ),
256 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); 259 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) );
257 connect( this, SIGNAL( valueChanged( int, int ) ), 260 connect( this, SIGNAL( valueChanged( int, int ) ),
258 this, SLOT( slotCheckPriority( int, int ) ) ); 261 this, SLOT( slotCheckPriority( int, int ) ) );
259 connect( this, SIGNAL( currentChanged( int, int ) ), 262 connect( this, SIGNAL( currentChanged( int, int ) ),
260 this, SLOT( slotCurrentChanged( int, int ) ) ); 263 this, SLOT( slotCurrentChanged( int, int ) ) );
261 264
262 menuTimer = new QTimer( this ); 265 menuTimer = new QTimer( this );
263 connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); 266 connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) );
267
268 mDayTimer = new QTimer( this );
269 connect( mDayTimer, SIGNAL(timeout()), this, SLOT(slotCheckDay() ) );
270 mDay = QDate::currentDate();
264} 271}
265 272
266void TodoTable::addEntry( const ToDoEvent &todo ) 273void TodoTable::addEntry( const ToDoEvent &todo )
267{ 274{
268 int row = numRows(); 275 int row = numRows();
269 setNumRows( row + 1 ); 276 setNumRows( row + 1 );
270 updateJournal( todo, ACTION_ADD ); 277 updateJournal( todo, ACTION_ADD );
271 insertIntoTable( new ToDoEvent(todo), row ); 278 insertIntoTable( new ToDoEvent(todo), row );
272 setCurrentCell(row, currentColumn()); 279 setCurrentCell(row, currentColumn());
273 updateVisible(); 280 updateVisible();
274} 281}
275 282
276void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) 283void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
277{ 284{
278 if ( !cellGeometry( row, col ).contains(pos) ) 285 if ( !cellGeometry( row, col ).contains(pos) )
279 return; 286 return;
280 // let's switch on the column number... 287 // let's switch on the column number...
281 switch ( col ) 288 switch ( col )
282 { 289 {
283 case 0: { 290 case 0: {
284 CheckItem *i = static_cast<CheckItem*>(item( row, col )); 291 CheckItem *i = static_cast<CheckItem*>(item( row, col ));
285 if ( i ) { 292 if ( i ) {
286 int x = pos.x() - columnPos( col ); 293 int x = pos.x() - columnPos( col );
287 int y = pos.y() - rowPos( row ); 294 int y = pos.y() - rowPos( row );
288 int w = columnWidth( col ); 295 int w = columnWidth( col );
289 int h = rowHeight( row ); 296 int h = rowHeight( row );
290 if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && 297 if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize &&
291 y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { 298 y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) {
292 i->toggle(); 299 i->toggle();
293 } 300 }
294 emit signalDoneChanged( i->isChecked() ); 301 emit signalDoneChanged( i->isChecked() );
295 } 302 }
296 } 303 }
297 break; 304 break;
298 case 1: 305 case 1:
299 break; 306 break;
300 case 2: 307 case 2:
301 // may as well edit it... 308 // may as well edit it...
302 // menuTimer->stop(); 309 // menuTimer->stop();
303// emit signalEdit(); 310// emit signalEdit();
304 // fall through 311 // fall through
305 case 3: 312 case 3:
306 // may as well edit it... 313 // may as well edit it...
307 menuTimer->stop(); 314 menuTimer->stop();
308 // emit signalEdit(); 315 // emit signalEdit();
309 break; 316 break;
310 } 317 }
311} 318}
312 319
313void TodoTable::slotPressed( int row, int col, int, const QPoint &pos ) 320void TodoTable::slotPressed( int row, int col, int, const QPoint &pos )
314{ 321{
315 if ( col == 2 && cellGeometry( row, col ).contains(pos) ) 322 if ( col == 2 && cellGeometry( row, col ).contains(pos) )
316 menuTimer->start( 750, TRUE ); 323 menuTimer->start( 750, TRUE );
317} 324}
318 325
319void TodoTable::slotShowMenu() 326void TodoTable::slotShowMenu()
320{ 327{
321 emit signalShowMenu( QCursor::pos() ); 328 emit signalShowMenu( QCursor::pos() );
322} 329}
323 330
324void TodoTable::slotCurrentChanged( int, int ) 331void TodoTable::slotCurrentChanged( int, int )
325{ 332{
326 menuTimer->stop(); 333 menuTimer->stop();
327} 334}
328 335
329void TodoTable::internalAddEntries( QList<ToDoEvent> &list ) 336void TodoTable::internalAddEntries( QList<ToDoEvent> &list )
330{ 337{
331 setNumRows( list.count() ); 338 setNumRows( list.count() );
332 int row = 0; 339 int row = 0;
333 ToDoEvent *it; 340 ToDoEvent *it;
334 for ( it = list.first(); it; it = list.next() ) 341 for ( it = list.first(); it; it = list.next() )
335 insertIntoTable( it, row++ ); 342 insertIntoTable( it, row++ );
336} 343}
337 344
338 345
339ToDoEvent TodoTable::currentEntry() const 346ToDoEvent TodoTable::currentEntry() const
340{ 347{
341 printf ("in currentEntry\n"); 348 printf ("in currentEntry\n");
342 349
343 QTableItem *i = item( currentRow(), 0 ); 350 QTableItem *i = item( currentRow(), 0 );
344 if ( !i || rowHeight( currentRow() ) <= 0 ) 351 if ( !i || rowHeight( currentRow() ) <= 0 )
345 return ToDoEvent(); 352 return ToDoEvent();
346 ToDoEvent *todo = todoList[(CheckItem*)i]; 353 ToDoEvent *todo = todoList[(CheckItem*)i];
347 todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() ); 354 todo->setCompleted( ( (CheckItem*)item( currentRow(), 0 ) )->isChecked() );
348 todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() ); 355 todo->setPriority( ( (ComboItem*)item( currentRow(), 1 ) )->text().toInt() );
349 return *todo; 356 return *todo;
350} 357}
351 358
352void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem ) 359void TodoTable::replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem )
353{ 360{
354 int row = currentRow(); 361 int row = currentRow();
355 updateJournal( todo, ACTION_REPLACE); 362 updateJournal( todo, ACTION_REPLACE);
356 363
357 if ( !fromTableItem ) { 364 if ( !fromTableItem ) {
358 journalFreeReplaceEntry( todo, row ); 365 journalFreeReplaceEntry( todo, row );
359 updateVisible(); 366 updateVisible();
360 } 367 }
361} 368}
362 369
363void TodoTable::removeCurrentEntry() 370void TodoTable::removeCurrentEntry()
364{ 371{
365 ToDoEvent *oldTodo; 372 ToDoEvent *oldTodo;
366 int row = currentRow(); 373 int row = currentRow();
367 CheckItem *chk; 374 CheckItem *chk;
368 375
369 chk = static_cast<CheckItem*>(item(row, 0 )); 376 chk = static_cast<CheckItem*>(item(row, 0 ));
370 if ( !chk ) 377 if ( !chk )
371 return; 378 return;
372 oldTodo = todoList[chk]; 379 oldTodo = todoList[chk];
373 todoList.remove( chk ); 380 todoList.remove( chk );
374 oldTodo->setCompleted( chk->isChecked() ); 381 oldTodo->setCompleted( chk->isChecked() );
375 oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() ); 382 oldTodo->setPriority( static_cast<ComboItem*>(item(row, 1))->text().toInt() );
376 realignTable( row ); 383 realignTable( row );
377 updateVisible(); 384 updateVisible();
378 updateJournal( *oldTodo, ACTION_REMOVE); 385 updateJournal( *oldTodo, ACTION_REMOVE);
379 delete oldTodo; 386 delete oldTodo;
380} 387}
381 388
382 389
383bool TodoTable::save( const QString &fn ) 390bool TodoTable::save( const QString &fn )
384{ 391{
385 QString strNewFile = fn + ".new"; 392 QString strNewFile = fn + ".new";
386 QFile::remove( strNewFile ); // just to be sure 393 QFile::remove( strNewFile ); // just to be sure
387 ToDoDB todoDB( strNewFile ); 394 ToDoDB todoDB( strNewFile );
388 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); 395 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
389 it != todoList.end(); ++it ) { 396 it != todoList.end(); ++it ) {
390 if ( !item( it.key()->row(), 0 ) ) 397 if ( !item( it.key()->row(), 0 ) )
391 continue; 398 continue;
392 ToDoEvent *todo = *it; 399 ToDoEvent *todo = *it;
393 // sync item with table 400 // sync item with table
394 todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); 401 todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() );
395 todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); 402 todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() );
396 todoDB.addEvent( *todo ); 403 todoDB.addEvent( *todo );
397 } 404 }
398 if(!todoDB.save() ){ 405 if(!todoDB.save() ){
399 QFile::remove( strNewFile ); 406 QFile::remove( strNewFile );
400 return false; 407 return false;
401 }; 408 };
402 // now do the rename 409 // now do the rename
403 if ( ::rename( strNewFile, fn ) < 0 ) 410 if ( ::rename( strNewFile, fn ) < 0 )
404 qWarning( "problem renaming file %s to %s errno %d", 411 qWarning( "problem renaming file %s to %s errno %d",
405 strNewFile.latin1(), fn.latin1(), errno ); 412 strNewFile.latin1(), fn.latin1(), errno );
406 413
407 // remove the journal 414 // remove the journal
408 QFile::remove( journalFileName() ); 415 QFile::remove( journalFileName() );
409 return true; 416 return true;
410} 417}
411 418
412void TodoTable::load( const QString &fn ) 419void TodoTable::load( const QString &fn )
413{ 420{
414 if ( QFile::exists(journalFileName()) ) { 421 if ( QFile::exists(journalFileName()) ) {
415 applyJournal(); 422 applyJournal();
416 QFile::remove(journalFileName() ); 423 QFile::remove(journalFileName() );
417 } 424 }
418 loadFile( fn ); 425 loadFile( fn );
419// QTable::sortColumn(2,TRUE,TRUE); 426// QTable::sortColumn(2,TRUE,TRUE);
420// QTable::sortColumn(1,TRUE,TRUE); 427// QTable::sortColumn(1,TRUE,TRUE);
421 QTable::sortColumn(0,TRUE,TRUE); 428 QTable::sortColumn(0,TRUE,TRUE);
422 setCurrentCell( 0, 2 ); 429 setCurrentCell( 0, 2 );
423 setSorting(true ); 430 setSorting(true );
431 mDayTimer->start( 60 * 1000 ); // gone in 60 seconds?
424} 432}
425void TodoTable::updateVisible() 433void TodoTable::updateVisible()
426{ 434{
427 if ( !isUpdatesEnabled() ) 435 if ( !isUpdatesEnabled() )
428 return; 436 return;
429 437
430 if (showDeadl){ 438 if (showDeadl){
431 showColumn (3); 439 showColumn (3);
432 adjustColumn(3); 440 adjustColumn(3);
433 }else{ 441 }else{
434 hideColumn (3); 442 hideColumn (3);
435 adjustColumn(2); 443 adjustColumn(2);
436 } 444 }
437 445
438 int visible = 0; 446 int visible = 0;
439 int id = mCat.id( "Todo List", showCat ); 447 int id = mCat.id( "Todo List", showCat );
440 for ( int row = 0; row < numRows(); row++ ) { 448 for ( int row = 0; row < numRows(); row++ ) {
441 CheckItem *ci = (CheckItem *)item( row, 0 ); 449 CheckItem *ci = (CheckItem *)item( row, 0 );
442 ToDoEvent *t = todoList[ci]; 450 ToDoEvent *t = todoList[ci];
443 QArray<int> vlCats = t->categories(); 451 QArray<int> vlCats = t->categories();
444 bool hide = false; 452 bool hide = false;
445 if ( !showComp && ci->isChecked() ) 453 if ( !showComp && ci->isChecked() )
446 hide = true; 454 hide = true;
447 if ( !showCat.isEmpty() ) { 455 if ( !showCat.isEmpty() ) {
448 if ( showCat == tr( "Unfiled" ) ) { 456 if ( showCat == tr( "Unfiled" ) ) {
449 if ( vlCats.count() > 0 ) 457 if ( vlCats.count() > 0 )
450 hide = true; 458 hide = true;
451 } else { 459 } else {
452 // do some comparing, we have to reverse our idea here... which idea? - zecke 460 // do some comparing, we have to reverse our idea here... which idea? - zecke
453 if ( !hide ) { 461 if ( !hide ) {
454 hide = true; 462 hide = true;
455 for ( uint it = 0; it < vlCats.count(); ++it ) { 463 for ( uint it = 0; it < vlCats.count(); ++it ) {
456 if ( vlCats[it] == id ) { 464 if ( vlCats[it] == id ) {
457 hide = false; 465 hide = false;
458 break; 466 break;
459 } 467 }
460 } 468 }
461 } 469 }
462 } 470 }
463 } 471 }
464 if ( hide ) { 472 if ( hide ) {
465 if ( currentRow() == row ) 473 if ( currentRow() == row )
466 setCurrentCell( -1, 0 ); 474 setCurrentCell( -1, 0 );
467 if ( rowHeight( row ) > 0 ) 475 if ( rowHeight( row ) > 0 )
468 hideRow( row ); 476 hideRow( row );
469 } else { 477 } else {
470 if ( rowHeight( row ) == 0 ) { 478 if ( rowHeight( row ) == 0 ) {
471 showRow( row ); 479 showRow( row );
472 adjustRow( row ); 480 adjustRow( row );
473 } 481 }
474 visible++; 482 visible++;
475 } 483 }
476 } 484 }
477 if ( !visible ) 485 if ( !visible )
478 setCurrentCell( -1, 0 ); 486 setCurrentCell( -1, 0 );
479} 487}
480 488
481void TodoTable::viewportPaintEvent( QPaintEvent *pe ) 489void TodoTable::viewportPaintEvent( QPaintEvent *pe )
482{ 490{
483 if ( enablePainting ) 491 if ( enablePainting )
484 QTable::viewportPaintEvent( pe ); 492 QTable::viewportPaintEvent( pe );
485} 493}
486 494
487void TodoTable::setPaintingEnabled( bool e ) 495void TodoTable::setPaintingEnabled( bool e )
488{ 496{
489 if ( e != enablePainting ) { 497 if ( e != enablePainting ) {
490 if ( !enablePainting ) { 498 if ( !enablePainting ) {
491 enablePainting = true; 499 enablePainting = true;
492 rowHeightChanged( 0 ); 500 rowHeightChanged( 0 );
493 viewport()->update(); 501 viewport()->update();
494 } else { 502 } else {
495 enablePainting = false; 503 enablePainting = false;
496 } 504 }
497 } 505 }
498} 506}
499 507
500void TodoTable::clear() 508void TodoTable::clear()
501{ 509{
502 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); 510 for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin();
503 it != todoList.end(); ++it ) { 511 it != todoList.end(); ++it ) {
504 ToDoEvent *todo = it.data(); 512 ToDoEvent *todo = it.data();
505 updateJournal( *todo, ACTION_REMOVE ); 513 updateJournal( *todo, ACTION_REMOVE );
506 delete todo; 514 delete todo;
507 } 515 }
508 todoList.clear(); 516 todoList.clear();
509 for ( int r = 0; r < numRows(); ++r ) { 517 for ( int r = 0; r < numRows(); ++r ) {
510 for ( int c = 0; c < numCols(); ++c ) { 518 for ( int c = 0; c < numCols(); ++c ) {
511 if ( cellWidget( r, c ) ) 519 if ( cellWidget( r, c ) )
512 clearCellWidget( r, c ); 520 clearCellWidget( r, c );
513 clearCell( r, c ); 521 clearCell( r, c );
514 } 522 }
515 } 523 }
516 setNumRows( 0 ); 524 setNumRows( 0 );
517} 525}
518 526
519void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ ) 527void TodoTable::sortColumn( int col, bool ascending, bool /*wholeRows*/ )
520{ 528{
521 // The default for wholeRows is false, however 529 // The default for wholeRows is false, however
522 // for this todo table we want to exchange complete 530 // for this todo table we want to exchange complete
523 // rows when sorting. Also, we always want ascending, since 531 // rows when sorting. Also, we always want ascending, since
524 // the values have a logical order. 532 // the values have a logical order.
525 QTable::sortColumn( col, ascending, TRUE ); 533 QTable::sortColumn( col, ascending, TRUE );
526 updateVisible(); 534 updateVisible();
527} 535}
528 536
529void TodoTable::slotCheckPriority(int row, int col ) 537void TodoTable::slotCheckPriority(int row, int col )
530{ 538{
531 // kludgey work around to make forward along the updated priority... 539 // kludgey work around to make forward along the updated priority...
532 if ( col == 1 ) { 540 if ( col == 1 ) {
533 // let everyone know!! 541 // let everyone know!!
534 ComboItem* i = static_cast<ComboItem*>( item( row, col ) ); 542 ComboItem* i = static_cast<ComboItem*>( item( row, col ) );
535 emit signalPriorityChanged( i->text().toInt() ); 543 emit signalPriorityChanged( i->text().toInt() );
536 } 544 }
537} 545}
538 546
539 547
540void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action ) 548void TodoTable::updateJournal( const ToDoEvent &todo, journal_action action )
541{ 549{
542 QFile f( journalFileName() ); 550 QFile f( journalFileName() );
543 if ( !f.open(IO_WriteOnly|IO_Append) ) 551 if ( !f.open(IO_WriteOnly|IO_Append) )
544 return; 552 return;
545 QString buf; 553 QString buf;
546 QCString str; 554 QCString str;
547 buf = "<Task"; 555 buf = "<Task";
548 // todo.save( buf ); 556 // todo.save( buf );
549 buf += " Action=\"" + QString::number( int(action) ) + "\""; 557 buf += " Action=\"" + QString::number( int(action) ) + "\"";
550 buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id 558 buf += " Uid=\"" + QString::number( todo.uid() ) + "\""; // better write the id
551 buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\""; 559 buf += " Completed=\""+ QString::number((int)todo.isCompleted() ) + "\"";
552 buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\""; 560 buf += " HasDate=\""+ QString::number((int)todo.hasDate() ) +"\"";
553 buf += " Priority=\"" + QString::number( todo.priority() ) + "\""; 561 buf += " Priority=\"" + QString::number( todo.priority() ) + "\"";
554 QArray<int> arrat = todo.categories(); 562 QArray<int> arrat = todo.categories();
555 QString attr; 563 QString attr;
556 for(uint i=0; i < arrat.count(); i++ ){ 564 for(uint i=0; i < arrat.count(); i++ ){
557 attr.append(QString::number(arrat[i])+";" ); 565 attr.append(QString::number(arrat[i])+";" );
558 } 566 }
559 if(!attr.isEmpty() ) // remove the last ; 567 if(!attr.isEmpty() ) // remove the last ;
560 attr.remove(attr.length()-1, 1 ); 568 attr.remove(attr.length()-1, 1 );
561 buf += " Categories=\"" + attr + "\""; 569 buf += " Categories=\"" + attr + "\"";
562 buf += " Description=\"" + todo.description() + "\""; 570 buf += " Description=\"" + todo.description() + "\"";
563 if(todo.hasDate() ) { 571 if(todo.hasDate() ) {
564 buf += " DateYear=\""+QString::number( todo.date().year() ) + "\""; 572 buf += " DateYear=\""+QString::number( todo.date().year() ) + "\"";
565 buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\""; 573 buf += " DateMonth=\"" + QString::number( todo.date().month() ) + "\"";
566 buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\""; 574 buf += " DateDay=\"" + QString::number( todo.date().day() ) + "\"";
567 } 575 }
568 buf += "/>\n"; 576 buf += "/>\n";
569 str = buf.utf8(); 577 str = buf.utf8();
570 f.writeBlock( str.data(), str.length() ); 578 f.writeBlock( str.data(), str.length() );
571 f.close(); 579 f.close();
572} 580}
573 581
574void TodoTable::rowHeightChanged( int row ) 582void TodoTable::rowHeightChanged( int row )
575{ 583{
576 if ( enablePainting ) 584 if ( enablePainting )
577 QTable::rowHeightChanged( row ); 585 QTable::rowHeightChanged( row );
578} 586}
579 587
580void TodoTable::loadFile( const QString &/*we use the standard*/ ) 588void TodoTable::loadFile( const QString &/*we use the standard*/ )
581{ 589{
582 590
583 QList<ToDoEvent> list; 591 QList<ToDoEvent> list;
584 ToDoDB todoDB; 592 ToDoDB todoDB;
585 QValueList<ToDoEvent> vaList = todoDB.rawToDos(); 593 QValueList<ToDoEvent> vaList = todoDB.rawToDos();
586 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){ 594 for(QValueList<ToDoEvent>::ConstIterator it = vaList.begin(); it != vaList.end(); ++it ){
587 list.append( new ToDoEvent( (*it) ) ); 595 list.append( new ToDoEvent( (*it) ) );
588 } 596 }
589 vaList.clear(); 597 vaList.clear();
590 // qDebug("parsing done=%d", t.elapsed() ); 598 // qDebug("parsing done=%d", t.elapsed() );
591 if ( list.count() > 0 ) { 599 if ( list.count() > 0 ) {
592 internalAddEntries( list ); 600 internalAddEntries( list );
593 list.clear(); 601 list.clear();
594 } 602 }
595// qDebug("loading done: t=%d", t.elapsed() ); 603// qDebug("loading done: t=%d", t.elapsed() );
596} 604}
597 605
598void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row ) 606void TodoTable::journalFreeReplaceEntry( const ToDoEvent &todo, int row )
599{ 607{
600 QString strTodo; 608 QString strTodo;
601 strTodo = todo.description().left(40).simplifyWhiteSpace(); 609 strTodo = todo.description().left(40).simplifyWhiteSpace();
602 if ( row == -1 ) { 610 if ( row == -1 ) {
603 QMapIterator<CheckItem*, ToDoEvent *> it; 611 QMapIterator<CheckItem*, ToDoEvent *> it;
604 for ( it = todoList.begin(); it != todoList.end(); ++it ) { 612 for ( it = todoList.begin(); it != todoList.end(); ++it ) {
605 if ( *(*it) == todo ) { 613 if ( *(*it) == todo ) {
606 row = it.key()->row(); 614 row = it.key()->row();
607 it.key()->setChecked( todo.isCompleted() ); 615 it.key()->setChecked( todo.isCompleted() );
608 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 616 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
609 item( row, 2 )->setText( strTodo ); 617 item( row, 2 )->setText( strTodo );
610 618
611 if (showDeadl){ 619 if (showDeadl){
612 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); 620 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo );
613 } 621 }
614 622
615 *(*it) = todo; 623 *(*it) = todo;
616 } 624 }
617 } 625 }
618 } else { 626 } else {
619 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))]; 627 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(row, 0))];
620 todoList.remove( static_cast<CheckItem*>(item(row, 0)) ); 628 todoList.remove( static_cast<CheckItem*>(item(row, 0)) );
621 delete t; 629 delete t;
622 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() ); 630 static_cast<CheckItem*>(item(row, 0))->setChecked( todo.isCompleted() );
623 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) ); 631 static_cast<ComboItem*>(item(row, 1))->setText( QString::number(todo.priority()) );
624 item( row, 2 )->setText( strTodo ); 632 item( row, 2 )->setText( strTodo );
625 633
626 if (showDeadl){ 634 if (showDeadl){
627 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo ); 635 static_cast<DueTextItem*>(item(row,3))->setToDoEvent(&todo );
628 } 636 }
629 637
630 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) ); 638 todoList.insert( static_cast<CheckItem*>(item(row,0)), new ToDoEvent(todo) );
631 } 639 }
632} 640}
633 641
634void TodoTable::journalFreeRemoveEntry( int row ) 642void TodoTable::journalFreeRemoveEntry( int row )
635{ 643{
636 CheckItem *chk; 644 CheckItem *chk;
637 chk = static_cast<CheckItem*>(item(row, 0 )); 645 chk = static_cast<CheckItem*>(item(row, 0 ));
638 if ( !chk ) 646 if ( !chk )
639 return; 647 return;
640 todoList.remove( chk ); 648 todoList.remove( chk );
641 649
642 realignTable( row ); 650 realignTable( row );
643} 651}
644 652
645void TodoTable::keyPressEvent( QKeyEvent *e ) 653void TodoTable::keyPressEvent( QKeyEvent *e )
646{ 654{
647 if ( e->key() == Key_Space || e->key() == Key_Return ) { 655 if ( e->key() == Key_Space || e->key() == Key_Return ) {
648 switch ( currentColumn() ) { 656 switch ( currentColumn() ) {
649 case 0: { 657 case 0: {
650 CheckItem *i = static_cast<CheckItem*>(item(currentRow(), 658 CheckItem *i = static_cast<CheckItem*>(item(currentRow(),
651 currentColumn())); 659 currentColumn()));
652 if ( i ) 660 if ( i )
653 i->toggle(); 661 i->toggle();
654 break; 662 break;
655 } 663 }
656 case 1: 664 case 1:
657 break; 665 break;
658 case 2: 666 case 2:
659 emit signalEdit(); 667 emit signalEdit();
660 default: 668 default:
661 break; 669 break;
662 } 670 }
663 } else { 671 } else {
664 QTable::keyPressEvent( e ); 672 QTable::keyPressEvent( e );
665 } 673 }
666} 674}
667 675
668QStringList TodoTable::categories() 676QStringList TodoTable::categories()
669{ 677{
670 // This is called seldom, so calling a load in here 678 // This is called seldom, so calling a load in here
671 // should be fine. 679 // should be fine.
672 mCat.load( categoryFileName() ); 680 mCat.load( categoryFileName() );
673 QStringList categoryList = mCat.labels( "Todo List" ); 681 QStringList categoryList = mCat.labels( "Todo List" );
674 return categoryList; 682 return categoryList;
675} 683}
676 684
677void TodoTable::slotDoFind( const QString &findString, bool caseSensitive, 685void TodoTable::slotDoFind( const QString &findString, bool caseSensitive,
678 bool backwards, int category ) 686 bool backwards, int category )
679{ 687{
680 // we have to iterate through the table, this gives the illusion that 688 // we have to iterate through the table, this gives the illusion that
681 // sorting is actually being used. 689 // sorting is actually being used.
682 if ( currFindRow < -1 ) 690 if ( currFindRow < -1 )
683 currFindRow = currentRow() - 1; 691 currFindRow = currentRow() - 1;
684 clearSelection( TRUE ); 692 clearSelection( TRUE );
685 int rows, 693 int rows,
686 row; 694 row;
687 CheckItem *chk; 695 CheckItem *chk;
688 QRegExp r( findString ); 696 QRegExp r( findString );
689 697
690 r.setCaseSensitive( caseSensitive ); 698 r.setCaseSensitive( caseSensitive );
691 rows = numRows(); 699 rows = numRows();
692 static bool wrapAround = true; 700 static bool wrapAround = true;
693 701
694 if ( !backwards ) { 702 if ( !backwards ) {
695 for ( row = currFindRow + 1; row < rows; row++ ) { 703 for ( row = currFindRow + 1; row < rows; row++ ) {
696 chk = static_cast<CheckItem*>( item(row, 0) ); 704 chk = static_cast<CheckItem*>( item(row, 0) );
697 if ( taskCompare(*(todoList[chk]), r, category) ) 705 if ( taskCompare(*(todoList[chk]), r, category) )
698 break; 706 break;
699 } 707 }
700 } else { 708 } else {
701 for ( row = currFindRow - 1; row > -1; row-- ) { 709 for ( row = currFindRow - 1; row > -1; row-- ) {
702 chk = static_cast<CheckItem*>( item(row, 0) ); 710 chk = static_cast<CheckItem*>( item(row, 0) );
703 if ( taskCompare(*(todoList[chk]), r, category) ) 711 if ( taskCompare(*(todoList[chk]), r, category) )
704 break; 712 break;
705 } 713 }
706 } 714 }
707 if ( row >= rows || row < 0 ) { 715 if ( row >= rows || row < 0 ) {
708 if ( row < 0 ) 716 if ( row < 0 )
709 currFindRow = rows; 717 currFindRow = rows;
710 else 718 else
711 currFindRow = -1; 719 currFindRow = -1;
712 if ( wrapAround ) 720 if ( wrapAround )
713 emit signalWrapAround(); 721 emit signalWrapAround();
714 else 722 else
715 emit signalNotFound(); 723 emit signalNotFound();
716 wrapAround = !wrapAround; 724 wrapAround = !wrapAround;
717 } else { 725 } else {
718 currFindRow = row; 726 currFindRow = row;
719 QTableSelection foundSelection; 727 QTableSelection foundSelection;
720 foundSelection.init( currFindRow, 0 ); 728 foundSelection.init( currFindRow, 0 );
721 foundSelection.expandTo( currFindRow, numCols() - 1 ); 729 foundSelection.expandTo( currFindRow, numCols() - 1 );
722 addSelection( foundSelection ); 730 addSelection( foundSelection );
723 setCurrentCell( currFindRow, numCols() - 1 ); 731 setCurrentCell( currFindRow, numCols() - 1 );
724 // we should always be able to wrap around and find this again, 732 // we should always be able to wrap around and find this again,
725 // so don't give confusing not found message... 733 // so don't give confusing not found message...
726 wrapAround = true; 734 wrapAround = true;
727 } 735 }
728} 736}
729 737
730int TodoTable::showCategoryId() const 738int TodoTable::showCategoryId() const
731{ 739{
732 int id; 740 int id;
733 id = -1; 741 id = -1;
734 // if allcategories are selected, you get unfiled... 742 // if allcategories are selected, you get unfiled...
735 if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) ) 743 if ( showCat != tr( "Unfiled" ) && showCat != tr( "All" ) )
736 id = mCat.id( "Todo List", showCat ); 744 id = mCat.id( "Todo List", showCat );
737 return id; 745 return id;
738} 746}
739void TodoTable::applyJournal() 747void TodoTable::applyJournal()
740{ 748{
741 // we need to hack 749 // we need to hack
742 QFile file( journalFileName() ); 750 QFile file( journalFileName() );
743 if( file.open(IO_ReadOnly ) ) { 751 if( file.open(IO_ReadOnly ) ) {
744 QByteArray ar = file.readAll(); 752 QByteArray ar = file.readAll();
745 file.close(); 753 file.close();
746 QFile file2( journalFileName() + "_new" ); 754 QFile file2( journalFileName() + "_new" );
747 if( file2.open(IO_WriteOnly ) ){ 755 if( file2.open(IO_WriteOnly ) ){
748 QTextStream str(&file2 ); 756 QTextStream str(&file2 );
749 str << QString::fromLatin1("<Tasks>") << endl; 757 str << QString::fromLatin1("<Tasks>") << endl;
750 str << ar.data(); 758 str << ar.data();
751 str << QString::fromLatin1("</Tasks>") << endl; 759 str << QString::fromLatin1("</Tasks>") << endl;
752 file2.close(); 760 file2.close();
753 } 761 }
754 XMLElement *root = XMLElement::load(journalFileName()+ "_new"); 762 XMLElement *root = XMLElement::load(journalFileName()+ "_new");
755 XMLElement *el = root->firstChild(); 763 XMLElement *el = root->firstChild();
756 el = el->firstChild(); 764 el = el->firstChild();
757 ToDoDB tododb; // allready loaded ;) 765 ToDoDB tododb; // allready loaded ;)
758 bool ok; 766 bool ok;
759 int action; 767 int action;
760 QString dummy; 768 QString dummy;
761 while( el ){ 769 while( el ){
762 dummy = el->attribute("Action" ); 770 dummy = el->attribute("Action" );
763 action = dummy.toInt(&ok ); 771 action = dummy.toInt(&ok );
764 ToDoEvent ev = xmlToEvent( el ); 772 ToDoEvent ev = xmlToEvent( el );
765 if(ok ){ 773 if(ok ){
766 switch( action){ 774 switch( action){
767 case ACTION_ADD: 775 case ACTION_ADD:
768 tododb.addEvent(ev ); 776 tododb.addEvent(ev );
769 break; 777 break;
770 case ACTION_REMOVE: 778 case ACTION_REMOVE:
771 tododb.removeEvent( ev ); 779 tododb.removeEvent( ev );
772 break; 780 break;
773 case ACTION_REPLACE: 781 case ACTION_REPLACE:
774 tododb.replaceEvent( ev ); 782 tododb.replaceEvent( ev );
775 break; 783 break;
776 } 784 }
777 } 785 }
778 el = el->nextChild(); 786 el = el->nextChild();
779 } 787 }
780 QFile::remove(journalFileName()+ "_new" ); 788 QFile::remove(journalFileName()+ "_new" );
781 tododb.save(); 789 tododb.save();
782 } 790 }
783} 791}
792void TodoTable::slotCheckDay()
793{
794 QDate date = QDate::currentDate();
795 if( mDay.daysTo(date )!= 0 ){
796 setPaintingEnabled( FALSE );
797 for(int i=0; i < numRows(); i++ ){
798 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(i, 0))];
799 static_cast<DueTextItem*>(item(i, 3) )->setToDoEvent( t );
800
801 }
802 setPaintingEnabled( TRUE );
803 mDay = date;
804 }
805 mDayTimer->start( 60 * 1000 ); // 60 seconds
806}
784// check Action and decide 807// check Action and decide
785/* 808/*
786void TodoTable::doApply(XMLElement *el ) 809void TodoTable::doApply(XMLElement *el )
787{ 810{
788 QString dummy; 811 QString dummy;
789 bool ok; 812 bool ok;
790 int action; 813 int action;
791 dummy = el->attribute("Action" ); 814 dummy = el->attribute("Action" );
792 action = dummy.toInt(&ok ); 815 action = dummy.toInt(&ok );
793 ToDoEvent ev = xmlToEvent( el ); 816 ToDoEvent ev = xmlToEvent( el );
794 if( ok ){ 817 if( ok ){
795 switch( action ){ 818 switch( action ){
796 case ACTION_ADD: 819 case ACTION_ADD:
797 addEntry( ev ); 820 addEntry( ev );
798 break; 821 break;
799 case ACTION_REMOVE:{ // find an entry with the same uid and remove it then 822 case ACTION_REMOVE:{ // find an entry with the same uid and remove it then
800 break; 823 break;
801 } 824 }
802 case ACTION_REPLACE: 825 case ACTION_REPLACE:
803 break; 826 break;
804 } 827 }
805 } 828 }
806} 829}
807*/ 830*/
808namespace { 831namespace {
809static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) 832static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category )
810{ 833{
811 bool returnMe; 834 bool returnMe;
812 QArray<int> cats; 835 QArray<int> cats;
813 cats = task.categories(); 836 cats = task.categories();
814 837
815 returnMe = false; 838 returnMe = false;
816 if ( (category == -1 && cats.count() == 0) || category == -2 ) 839 if ( (category == -1 && cats.count() == 0) || category == -2 )
817 returnMe = task.match( r ); 840 returnMe = task.match( r );
818 else { 841 else {
819 int i; 842 int i;
820 for ( i = 0; i < int(cats.count()); i++ ) { 843 for ( i = 0; i < int(cats.count()); i++ ) {
821 if ( cats[i] == category ) { 844 if ( cats[i] == category ) {
822 returnMe = task.match( r ); 845 returnMe = task.match( r );
823 break; 846 break;
824 } 847 }
825 } 848 }
826 } 849 }
827 return returnMe; 850 return returnMe;
828} 851}
829 852
830static QString journalFileName() 853static QString journalFileName()
831{ 854{
832 QString str; 855 QString str;
833 str = getenv( "HOME" ); 856 str = getenv( "HOME" );
834 str += "/.opie_todojournal"; 857 str += "/.opie_todojournal";
835 return str; 858 return str;
836} 859}
837static ToDoEvent xmlToEvent( XMLElement *element ) 860static ToDoEvent xmlToEvent( XMLElement *element )
838{ 861{
839 QString dummy; 862 QString dummy;
840 ToDoEvent event; 863 ToDoEvent event;
841 bool ok; 864 bool ok;
842 int dumInt; 865 int dumInt;
843 // completed 866 // completed
844 dummy = element->attribute("Completed" ); 867 dummy = element->attribute("Completed" );
845 dumInt = dummy.toInt(&ok ); 868 dumInt = dummy.toInt(&ok );
846 if(ok ) event.setCompleted( dumInt == 0 ? false : true ); 869 if(ok ) event.setCompleted( dumInt == 0 ? false : true );
847 // hasDate 870 // hasDate
848 dummy = element->attribute("HasDate" ); 871 dummy = element->attribute("HasDate" );
849 dumInt = dummy.toInt(&ok ); 872 dumInt = dummy.toInt(&ok );
850 if(ok ) event.setHasDate( dumInt == 0 ? false: true ); 873 if(ok ) event.setHasDate( dumInt == 0 ? false: true );
851 // set the date 874 // set the date
852 bool hasDa = dumInt; 875 bool hasDa = dumInt;
853 if ( hasDa ) { //parse the date 876 if ( hasDa ) { //parse the date
854 int year, day, month = 0; 877 int year, day, month = 0;
855 year = day = month; 878 year = day = month;
856 // year 879 // year
857 dummy = element->attribute("DateYear" ); 880 dummy = element->attribute("DateYear" );
858 dumInt = dummy.toInt(&ok ); 881 dumInt = dummy.toInt(&ok );
859 if( ok ) year = dumInt; 882 if( ok ) year = dumInt;
860 // month 883 // month
861 dummy = element->attribute("DateMonth" ); 884 dummy = element->attribute("DateMonth" );
862 dumInt = dummy.toInt(&ok ); 885 dumInt = dummy.toInt(&ok );
863 if(ok ) month = dumInt; 886 if(ok ) month = dumInt;
864 dummy = element->attribute("DateDay" ); 887 dummy = element->attribute("DateDay" );
865 dumInt = dummy.toInt(&ok ); 888 dumInt = dummy.toInt(&ok );
866 if(ok ) day = dumInt; 889 if(ok ) day = dumInt;
867 // set the date 890 // set the date
868 QDate date( year, month, day ); 891 QDate date( year, month, day );
869 event.setDate( date); 892 event.setDate( date);
870 } 893 }
871 dummy = element->attribute("Priority" ); 894 dummy = element->attribute("Priority" );
872 dumInt = dummy.toInt(&ok ); 895 dumInt = dummy.toInt(&ok );
873 if(!ok ) dumInt = ToDoEvent::NORMAL; 896 if(!ok ) dumInt = ToDoEvent::NORMAL;
874 event.setPriority( dumInt ); 897 event.setPriority( dumInt );
875 //description 898 //description
876 dummy = element->attribute("Description" ); 899 dummy = element->attribute("Description" );
877 event.setDescription( dummy ); 900 event.setDescription( dummy );
878 // category 901 // category
879 dummy = element->attribute("Categories" ); 902 dummy = element->attribute("Categories" );
880 QStringList ids = QStringList::split(";", dummy ); 903 QStringList ids = QStringList::split(";", dummy );
881 event.setCategories( ids ); 904 event.setCategories( ids );
882 905
883 //uid 906 //uid
884 dummy = element->attribute("Uid" ); 907 dummy = element->attribute("Uid" );
885 dumInt = dummy.toInt(&ok ); 908 dumInt = dummy.toInt(&ok );
886 if(ok ) event.setUid( dumInt ); 909 if(ok ) event.setUid( dumInt );
887 return event; 910 return event;
888} 911}
889 912
890} 913}
891// int TodoTable::rowHeight( int ) const 914// int TodoTable::rowHeight( int ) const
892// { 915// {
893// return 18; 916// return 18;
894// } 917// }
895 918
896// int TodoTable::rowPos( int row ) const 919// int TodoTable::rowPos( int row ) const
897// { 920// {
898// return 18*row; 921// return 18*row;
899// } 922// }
900 923
901// int TodoTable::rowAt( int pos ) const 924// int TodoTable::rowAt( int pos ) const
902// { 925// {
903// return QMIN( pos/18, numRows()-1 ); 926// return QMIN( pos/18, numRows()-1 );
904// } 927// }
905 928
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h
index 6e371e8..458e07a 100644
--- a/core/pim/todo/todotable.h
+++ b/core/pim/todo/todotable.h
@@ -1,237 +1,240 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
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
21#ifndef TODOTABLE_H 21#ifndef TODOTABLE_H
22#define TODOTABLE_H 22#define TODOTABLE_H
23 23
24#include <qpe/categories.h> 24#include <qpe/categories.h>
25#include <qpe/stringutil.h> 25#include <qpe/stringutil.h>
26//#include <qpe/task.h> 26//#include <qpe/task.h>
27#include <opie/todoevent.h> 27#include <opie/todoevent.h>
28 28
29#include <qtable.h> 29#include <qtable.h>
30#include <qmap.h> 30#include <qmap.h>
31#include <qguardedptr.h> 31#include <qguardedptr.h>
32 32
33class Node; 33class Node;
34class QComboBox; 34class QComboBox;
35class QTimer; 35class QTimer;
36 36
37class CheckItem : public QTableItem 37class CheckItem : public QTableItem
38{ 38{
39public: 39public:
40 CheckItem( QTable *t, const QString &sortkey ); 40 CheckItem( QTable *t, const QString &sortkey );
41 41
42 void setChecked( bool b ); 42 void setChecked( bool b );
43 void toggle(); 43 void toggle();
44 bool isChecked() const; 44 bool isChecked() const;
45 void setKey( const QString &key ) { sortKey = key; } 45 void setKey( const QString &key ) { sortKey = key; }
46 QString key() const; 46 QString key() const;
47 47
48 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); 48 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected );
49 49
50private: 50private:
51 bool checked; 51 bool checked;
52 QString sortKey; 52 QString sortKey;
53}; 53};
54 54
55class ComboItem : public QTableItem 55class ComboItem : public QTableItem
56{ 56{
57public: 57public:
58 ComboItem( QTable *t, EditType et ); 58 ComboItem( QTable *t, EditType et );
59 QWidget *createEditor() const; 59 QWidget *createEditor() const;
60 void setContentFromEditor( QWidget *w ); 60 void setContentFromEditor( QWidget *w );
61 void setText( const QString &s ); 61 void setText( const QString &s );
62 int alignment() const { return Qt::AlignCenter; } 62 int alignment() const { return Qt::AlignCenter; }
63 63
64 QString text() const; 64 QString text() const;
65 65
66private: 66private:
67 QGuardedPtr<QComboBox> cb; 67 QGuardedPtr<QComboBox> cb;
68 68
69}; 69};
70 70
71class TodoTextItem : public QTableItem 71class TodoTextItem : public QTableItem
72{ 72{
73public: 73public:
74 TodoTextItem( QTable *t, const QString & str ) 74 TodoTextItem( QTable *t, const QString & str )
75 :QTableItem( t, QTableItem::Never, str ) {} 75 :QTableItem( t, QTableItem::Never, str ) {}
76 76
77 QString key () const { return Qtopia::buildSortKey( text() ); } 77 QString key () const { return Qtopia::buildSortKey( text() ); }
78}; 78};
79 79
80class DueTextItem : public QTableItem 80class DueTextItem : public QTableItem
81{ 81{
82 public: 82 public:
83 DueTextItem( QTable *t, ToDoEvent *ev ); 83 DueTextItem( QTable *t, ToDoEvent *ev );
84 QString key() const; 84 QString key() const;
85 void setToDoEvent( const ToDoEvent *ev ); 85 void setToDoEvent( const ToDoEvent *ev );
86 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); 86 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected );
87 private: 87 private:
88 int m_off; 88 int m_off;
89 bool m_hasDate:1; 89 bool m_hasDate:1;
90 bool m_completed:1; 90 bool m_completed:1;
91 91
92}; 92};
93 93
94 94
95enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE }; 95enum journal_action { ACTION_ADD=0, ACTION_REMOVE, ACTION_REPLACE };
96 96
97class XMLElement; 97class XMLElement;
98class TodoTable : public QTable 98class TodoTable : public QTable
99{ 99{
100 Q_OBJECT 100 Q_OBJECT
101 101
102public: 102public:
103 TodoTable( QWidget *parent = 0, const char * name = 0 ); 103 TodoTable( QWidget *parent = 0, const char * name = 0 );
104 void addEntry( const ToDoEvent &todo ); 104 void addEntry( const ToDoEvent &todo );
105 void clearFindRow() { currFindRow = -2; } 105 void clearFindRow() { currFindRow = -2; }
106 106
107 ToDoEvent currentEntry() const; 107 ToDoEvent currentEntry() const;
108 void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false ); 108 void replaceCurrentEntry( const ToDoEvent &todo, bool fromTableItem = false );
109 109
110 QStringList categories(); 110 QStringList categories();
111 111
112 void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); } 112 void setShowCompleted( bool sc ) { showComp = sc; updateVisible(); }
113 bool showCompleted() const { return showComp; } 113 bool showCompleted() const { return showComp; }
114 114
115 void setShowDeadline (bool sd) {showDeadl = sd; updateVisible();} 115 void setShowDeadline (bool sd) {showDeadl = sd; updateVisible();}
116 bool showDeadline() const { return showDeadl;} 116 bool showDeadline() const { return showDeadl;}
117 117
118 void setShowCategory( const QString &c ) { showCat = c; updateVisible(); } 118 void setShowCategory( const QString &c ) { showCat = c; updateVisible(); }
119 const QString &showCategory() const { return showCat; } 119 const QString &showCategory() const { return showCat; }
120 int showCategoryId() const; 120 int showCategoryId() const;
121 121
122 bool save( const QString &fn ); 122 bool save( const QString &fn );
123 void load( const QString &fn ); 123 void load( const QString &fn );
124 void applyJournal( ); 124 void applyJournal( );
125 void clear(); 125 void clear();
126 void removeCurrentEntry(); 126 void removeCurrentEntry();
127 void removeAllEntries() { clear(); }; 127 void removeAllEntries() { clear(); };
128 //void removeAllEntriesInCategory(const QString &category ); 128 //void removeAllEntriesInCategory(const QString &category );
129 129
130 void setPaintingEnabled( bool e ); 130 void setPaintingEnabled( bool e );
131 131
132 virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); 132 virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ );
133 133
134// int rowHeight( int ) const; 134// int rowHeight( int ) const;
135// int rowPos( int row ) const; 135// int rowPos( int row ) const;
136// virtual int rowAt( int pos ) const; 136// virtual int rowAt( int pos ) const;
137 137
138signals: 138signals:
139 void signalEdit(); 139 void signalEdit();
140 void signalDoneChanged( bool b ); 140 void signalDoneChanged( bool b );
141 void signalPriorityChanged( int i ); 141 void signalPriorityChanged( int i );
142 void signalShowMenu( const QPoint & ); 142 void signalShowMenu( const QPoint & );
143 void signalNotFound(); 143 void signalNotFound();
144 void signalWrapAround(); 144 void signalWrapAround();
145 145
146protected: 146protected:
147 void keyPressEvent( QKeyEvent *e ); 147 void keyPressEvent( QKeyEvent *e );
148 148
149private: 149private:
150 void updateVisible(); 150 void updateVisible();
151 void viewportPaintEvent( QPaintEvent * ); 151 void viewportPaintEvent( QPaintEvent * );
152 void internalAddEntries( QList<ToDoEvent> &list); 152 void internalAddEntries( QList<ToDoEvent> &list);
153 inline void insertIntoTable( ToDoEvent *todo, int row ); 153 inline void insertIntoTable( ToDoEvent *todo, int row );
154 void updateJournal( const ToDoEvent &todo, journal_action action); 154 void updateJournal( const ToDoEvent &todo, journal_action action);
155 void mergeJournal(); 155 void mergeJournal();
156 void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); 156 void journalFreeReplaceEntry( const ToDoEvent &todo, int row );
157 void journalFreeRemoveEntry( int row ); 157 void journalFreeRemoveEntry( int row );
158 inline void realignTable( int row ); 158 inline void realignTable( int row );
159 void loadFile( const QString &strFile); 159 void loadFile( const QString &strFile);
160 160
161private slots: 161private slots:
162 void slotClicked( int row, int col, int button, const QPoint &pos ); 162 void slotClicked( int row, int col, int button, const QPoint &pos );
163 void slotPressed( int row, int col, int button, const QPoint &pos ); 163 void slotPressed( int row, int col, int button, const QPoint &pos );
164 void slotCheckPriority(int row, int col ); 164 void slotCheckPriority(int row, int col );
165 void slotCurrentChanged(int row, int col ); 165 void slotCurrentChanged(int row, int col );
166 void slotDoFind( const QString &findString, bool caseSensetive, 166 void slotDoFind( const QString &findString, bool caseSensetive,
167 bool backwards, int category ); 167 bool backwards, int category );
168 void slotShowMenu(); 168 void slotShowMenu();
169 void rowHeightChanged( int row ); 169 void rowHeightChanged( int row );
170 void slotCheckDay(); // check the day
170 171
171private: 172private:
172 friend class TodoWindow; 173 friend class TodoWindow;
173 174
174 QMap<CheckItem*, ToDoEvent *> todoList; 175 QMap<CheckItem*, ToDoEvent *> todoList;
175 QStringList categoryList; 176 QStringList categoryList;
176 bool showComp; 177 bool showComp;
177 QString showCat; 178 QString showCat;
178 QTimer *menuTimer; 179 QTimer *menuTimer;
180 QDate mDay;
181 QTimer *mDayTimer; // see if the day changed
179 bool enablePainting; 182 bool enablePainting;
180 Categories mCat; 183 Categories mCat;
181 int currFindRow; 184 int currFindRow;
182 bool showDeadl:1; 185 bool showDeadl:1;
183}; 186};
184 187
185 188
186inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) 189inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row )
187{ 190{
188 QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') 191 QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A')
189 + todo->priority() ) 192 + todo->priority() )
190 + Qtopia::buildSortKey( todo->description() ); 193 + Qtopia::buildSortKey( todo->description() );
191 CheckItem *chk = new CheckItem( this, sortKey ); 194 CheckItem *chk = new CheckItem( this, sortKey );
192 chk->setChecked( todo->isCompleted() ); 195 chk->setChecked( todo->isCompleted() );
193 ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); 196 ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent );
194 cmb->setText( QString::number( todo->priority() ) ); 197 cmb->setText( QString::number( todo->priority() ) );
195 QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); 198 QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() );
196 ti->setReplaceable( false ); 199 ti->setReplaceable( false );
197 200
198 DueTextItem *due = new DueTextItem(this, todo ); 201 DueTextItem *due = new DueTextItem(this, todo );
199 setItem( row, 3, due); 202 setItem( row, 3, due);
200 203
201 setItem( row, 0, chk ); 204 setItem( row, 0, chk );
202 setItem( row, 1, cmb ); 205 setItem( row, 1, cmb );
203 setItem( row, 2, ti ); 206 setItem( row, 2, ti );
204 207
205 208
206 todoList.insert( chk, todo ); 209 todoList.insert( chk, todo );
207} 210}
208 211
209inline void TodoTable::realignTable( int row ) 212inline void TodoTable::realignTable( int row )
210{ 213{
211 QTableItem *ti1, 214 QTableItem *ti1,
212 *ti2, 215 *ti2,
213 *ti3, 216 *ti3,
214 *ti4; 217 *ti4;
215 int totalRows = numRows(); 218 int totalRows = numRows();
216 for ( int curr = row; curr < totalRows - 1; curr++ ) { 219 for ( int curr = row; curr < totalRows - 1; curr++ ) {
217 // this is bad, we must take the item out and then 220 // this is bad, we must take the item out and then
218 // set it. In the end, it behaves no worse (time wise) 221 // set it. In the end, it behaves no worse (time wise)
219 // then the old way of saving the entries to file, clearing 222 // then the old way of saving the entries to file, clearing
220 // the table re-reading in the file and resetting the table 223 // the table re-reading in the file and resetting the table
221 ti1 = item( curr + 1, 0 ); 224 ti1 = item( curr + 1, 0 );
222 ti2 = item( curr + 1, 1 ); 225 ti2 = item( curr + 1, 1 );
223 ti3 = item( curr + 1, 2 ); 226 ti3 = item( curr + 1, 2 );
224 ti4 = item( curr + 1, 3 ); 227 ti4 = item( curr + 1, 3 );
225 takeItem( ti1 ); 228 takeItem( ti1 );
226 takeItem( ti2 ); 229 takeItem( ti2 );
227 takeItem( ti3 ); 230 takeItem( ti3 );
228 takeItem( ti4 ); 231 takeItem( ti4 );
229 setItem( curr, 0, ti1 ); 232 setItem( curr, 0, ti1 );
230 setItem( curr, 1, ti2 ); 233 setItem( curr, 1, ti2 );
231 setItem( curr, 2, ti3 ); 234 setItem( curr, 2, ti3 );
232 setItem( curr, 3, ti4 ); 235 setItem( curr, 3, ti4 );
233 } 236 }
234 setNumRows( totalRows - 1 ); 237 setNumRows( totalRows - 1 );
235} 238}
236 239
237#endif 240#endif