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