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