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