-rw-r--r-- | core/pim/todo/todotable.cpp | 23 | ||||
-rw-r--r-- | core/pim/todo/todotable.h | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp index 96cd860..d0bc61c 100644 --- a/core/pim/todo/todotable.cpp +++ b/core/pim/todo/todotable.cpp | |||
@@ -148,164 +148,171 @@ void ComboItem::setContentFromEditor( QWidget *w ) | |||
148 | else | 148 | else |
149 | QTableItem::setContentFromEditor( w ); | 149 | QTableItem::setContentFromEditor( w ); |
150 | newTodo.setPriority( text().toInt() ); | 150 | newTodo.setPriority( text().toInt() ); |
151 | parent->replaceCurrentEntry( newTodo, true ); | 151 | parent->replaceCurrentEntry( newTodo, true ); |
152 | } | 152 | } |
153 | 153 | ||
154 | void ComboItem::setText( const QString &s ) | 154 | void ComboItem::setText( const QString &s ) |
155 | { | 155 | { |
156 | if ( cb ) | 156 | if ( cb ) |
157 | cb->setCurrentItem( s.toInt() - 1 ); | 157 | cb->setCurrentItem( s.toInt() - 1 ); |
158 | QTableItem::setText( s ); | 158 | QTableItem::setText( s ); |
159 | } | 159 | } |
160 | 160 | ||
161 | QString ComboItem::text() const | 161 | QString ComboItem::text() const |
162 | { | 162 | { |
163 | if ( cb ) | 163 | if ( cb ) |
164 | return cb->currentText(); | 164 | return cb->currentText(); |
165 | return QTableItem::text(); | 165 | return QTableItem::text(); |
166 | } | 166 | } |
167 | DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev ) | 167 | DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev ) |
168 | : QTableItem(t, Never, QString::null ) | 168 | : QTableItem(t, Never, QString::null ) |
169 | { | 169 | { |
170 | setToDoEvent( ev ); | 170 | setToDoEvent( ev ); |
171 | } | 171 | } |
172 | QString DueTextItem::key() const | 172 | QString DueTextItem::key() const |
173 | { | 173 | { |
174 | QString key; | 174 | QString key; |
175 | if( m_hasDate ){ | 175 | if( m_hasDate ){ |
176 | if(m_off == 0 ){ | 176 | if(m_off == 0 ){ |
177 | key.append("b"); | 177 | key.append("b"); |
178 | }else if( m_off > 0 ){ | 178 | }else if( m_off > 0 ){ |
179 | key.append("c"); | 179 | key.append("c"); |
180 | }else if( m_off < 0 ){ | 180 | }else if( m_off < 0 ){ |
181 | key.append("a"); | 181 | key.append("a"); |
182 | } | 182 | } |
183 | key.append(QString::number(m_off ) ); | 183 | key.append(QString::number(m_off ) ); |
184 | }else{ | 184 | }else{ |
185 | key.append("d"); | 185 | key.append("d"); |
186 | } | 186 | } |
187 | return key; | 187 | return key; |
188 | } | 188 | } |
189 | void DueTextItem::setToDoEvent( const ToDoEvent *ev ) | 189 | void DueTextItem::setToDoEvent( const ToDoEvent *ev ) |
190 | { | 190 | { |
191 | m_hasDate = ev->hasDate(); | 191 | m_hasDate = ev->hasDate(); |
192 | m_completed = ev->isCompleted(); | 192 | m_completed = ev->isCompleted(); |
193 | if( ev->hasDate() ){ | 193 | if( ev->hasDate() ){ |
194 | QDate today = QDate::currentDate(); | 194 | QDate today = QDate::currentDate(); |
195 | m_off = today.daysTo(ev->date() ); | 195 | m_off = today.daysTo(ev->date() ); |
196 | //qWarning("DueText m_off=%d", m_off ); | ||
196 | setText( QString::number(m_off) + " day(s) " ); | 197 | setText( QString::number(m_off) + " day(s) " ); |
197 | }else{ | 198 | }else{ |
198 | setText("n.d." ); | 199 | setText("n.d." ); |
199 | m_off = 0; | 200 | m_off = 0; |
200 | } | 201 | } |
202 | //qWarning("m_off=%d", m_off ); | ||
201 | } | 203 | } |
202 | void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) | 204 | void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) |
203 | { | 205 | { |
206 | //qWarning ("paint m_off=%d", m_off ); | ||
204 | QColorGroup cg2(cg); | 207 | QColorGroup cg2(cg); |
205 | QColor text = cg.text(); | 208 | QColor text = cg.text(); |
206 | if( m_hasDate && !m_completed ){ | 209 | if( m_hasDate && !m_completed ){ |
207 | if( m_off < 0 ){ | 210 | if( m_off < 0 ){ |
208 | cg2.setColor(QColorGroup::Text, QColor(red ) ); | 211 | cg2.setColor(QColorGroup::Text, QColor(red ) ); |
209 | }else if( m_off == 0 ){ | 212 | }else if( m_off == 0 ){ |
210 | cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined | 213 | cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined |
211 | }else if( m_off > 0){ | 214 | }else if( m_off > 0){ |
212 | cg2.setColor(QColorGroup::Text, QColor(green ) ); | 215 | cg2.setColor(QColorGroup::Text, QColor(green ) ); |
213 | } | 216 | } |
214 | } | 217 | } |
215 | QTableItem::paint(p, cg2, cr, selected ); | 218 | QTableItem::paint(p, cg2, cr, selected ); |
216 | cg2.setColor(QColorGroup::Text, text ); | 219 | cg2.setColor(QColorGroup::Text, text ); |
217 | } | 220 | } |
218 | TodoTable::TodoTable( QWidget *parent, const char *name ) | 221 | TodoTable::TodoTable( QWidget *parent, const char *name ) |
219 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR | 222 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR |
220 | // : QTable( 0, 3, parent, name, TRUE ), | 223 | // : QTable( 0, 3, parent, name, TRUE ), |
221 | // #else | 224 | // #else |
222 | : QTable( 0, 4, parent, name ), | 225 | : QTable( 0, 4, parent, name ), |
223 | // #endif | 226 | // #endif |
224 | showComp( true ), | 227 | showComp( true ), |
225 | enablePainting( true ), | 228 | enablePainting( true ), |
226 | mCat( 0 ), | 229 | mCat( 0 ), |
227 | currFindRow( -2 ), | 230 | currFindRow( -2 ), |
228 | showDeadl( true) | 231 | showDeadl( true) |
229 | { | 232 | { |
230 | mCat.load( categoryFileName() ); | 233 | mCat.load( categoryFileName() ); |
231 | setSorting( TRUE ); | 234 | setSorting( TRUE ); |
232 | setSelectionMode( NoSelection ); | 235 | setSelectionMode( NoSelection ); |
233 | setColumnStretchable( 2, TRUE ); | 236 | setColumnStretchable( 2, TRUE ); |
234 | setColumnWidth( 0, 20 ); | 237 | setColumnWidth( 0, 20 ); |
235 | setColumnWidth( 1, 35 ); | 238 | setColumnWidth( 1, 35 ); |
236 | 239 | ||
237 | setLeftMargin( 0 ); | 240 | setLeftMargin( 0 ); |
238 | verticalHeader()->hide(); | 241 | verticalHeader()->hide(); |
239 | horizontalHeader()->setLabel( 0, tr( "C." ) ); | 242 | horizontalHeader()->setLabel( 0, tr( "C." ) ); |
240 | horizontalHeader()->setLabel( 1, tr( "Prior." ) ); | 243 | horizontalHeader()->setLabel( 1, tr( "Prior." ) ); |
241 | horizontalHeader()->setLabel( 2, tr( "Description" ) ); | 244 | horizontalHeader()->setLabel( 2, tr( "Description" ) ); |
242 | 245 | ||
243 | setColumnStretchable( 3, FALSE ); | 246 | setColumnStretchable( 3, FALSE ); |
244 | setColumnWidth( 3, 20 ); | 247 | setColumnWidth( 3, 20 ); |
245 | horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); | 248 | horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); |
246 | 249 | ||
247 | if (showDeadl){ | 250 | if (showDeadl){ |
248 | showColumn (3); | 251 | showColumn (3); |
249 | }else{ | 252 | }else{ |
250 | hideColumn (3); | 253 | hideColumn (3); |
251 | } | 254 | } |
252 | 255 | ||
253 | connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), | 256 | connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), |
254 | this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); | 257 | this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); |
255 | connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), | 258 | connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), |
256 | this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); | 259 | this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); |
257 | connect( this, SIGNAL( valueChanged( int, int ) ), | 260 | connect( this, SIGNAL( valueChanged( int, int ) ), |
258 | this, SLOT( slotCheckPriority( int, int ) ) ); | 261 | this, SLOT( slotCheckPriority( int, int ) ) ); |
259 | connect( this, SIGNAL( currentChanged( int, int ) ), | 262 | connect( this, SIGNAL( currentChanged( int, int ) ), |
260 | this, SLOT( slotCurrentChanged( int, int ) ) ); | 263 | this, SLOT( slotCurrentChanged( int, int ) ) ); |
261 | 264 | ||
262 | menuTimer = new QTimer( this ); | 265 | menuTimer = new QTimer( this ); |
263 | connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); | 266 | connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); |
267 | |||
268 | mDayTimer = new QTimer( this ); | ||
269 | connect( mDayTimer, SIGNAL(timeout()), this, SLOT(slotCheckDay() ) ); | ||
270 | mDay = QDate::currentDate(); | ||
264 | } | 271 | } |
265 | 272 | ||
266 | void TodoTable::addEntry( const ToDoEvent &todo ) | 273 | void TodoTable::addEntry( const ToDoEvent &todo ) |
267 | { | 274 | { |
268 | int row = numRows(); | 275 | int row = numRows(); |
269 | setNumRows( row + 1 ); | 276 | setNumRows( row + 1 ); |
270 | updateJournal( todo, ACTION_ADD ); | 277 | updateJournal( todo, ACTION_ADD ); |
271 | insertIntoTable( new ToDoEvent(todo), row ); | 278 | insertIntoTable( new ToDoEvent(todo), row ); |
272 | setCurrentCell(row, currentColumn()); | 279 | setCurrentCell(row, currentColumn()); |
273 | updateVisible(); | 280 | updateVisible(); |
274 | } | 281 | } |
275 | 282 | ||
276 | void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) | 283 | void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) |
277 | { | 284 | { |
278 | if ( !cellGeometry( row, col ).contains(pos) ) | 285 | if ( !cellGeometry( row, col ).contains(pos) ) |
279 | return; | 286 | return; |
280 | // let's switch on the column number... | 287 | // let's switch on the column number... |
281 | switch ( col ) | 288 | switch ( col ) |
282 | { | 289 | { |
283 | case 0: { | 290 | case 0: { |
284 | CheckItem *i = static_cast<CheckItem*>(item( row, col )); | 291 | CheckItem *i = static_cast<CheckItem*>(item( row, col )); |
285 | if ( i ) { | 292 | if ( i ) { |
286 | int x = pos.x() - columnPos( col ); | 293 | int x = pos.x() - columnPos( col ); |
287 | int y = pos.y() - rowPos( row ); | 294 | int y = pos.y() - rowPos( row ); |
288 | int w = columnWidth( col ); | 295 | int w = columnWidth( col ); |
289 | int h = rowHeight( row ); | 296 | int h = rowHeight( row ); |
290 | if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && | 297 | if ( i && x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize && |
291 | y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { | 298 | y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) { |
292 | i->toggle(); | 299 | i->toggle(); |
293 | } | 300 | } |
294 | emit signalDoneChanged( i->isChecked() ); | 301 | emit signalDoneChanged( i->isChecked() ); |
295 | } | 302 | } |
296 | } | 303 | } |
297 | break; | 304 | break; |
298 | case 1: | 305 | case 1: |
299 | break; | 306 | break; |
300 | case 2: | 307 | case 2: |
301 | // may as well edit it... | 308 | // may as well edit it... |
302 | // menuTimer->stop(); | 309 | // menuTimer->stop(); |
303 | // emit signalEdit(); | 310 | // emit signalEdit(); |
304 | // fall through | 311 | // fall through |
305 | case 3: | 312 | case 3: |
306 | // may as well edit it... | 313 | // may as well edit it... |
307 | menuTimer->stop(); | 314 | menuTimer->stop(); |
308 | // emit signalEdit(); | 315 | // emit signalEdit(); |
309 | break; | 316 | break; |
310 | } | 317 | } |
311 | } | 318 | } |
@@ -376,96 +383,97 @@ void TodoTable::removeCurrentEntry() | |||
376 | realignTable( row ); | 383 | realignTable( row ); |
377 | updateVisible(); | 384 | updateVisible(); |
378 | updateJournal( *oldTodo, ACTION_REMOVE); | 385 | updateJournal( *oldTodo, ACTION_REMOVE); |
379 | delete oldTodo; | 386 | delete oldTodo; |
380 | } | 387 | } |
381 | 388 | ||
382 | 389 | ||
383 | bool TodoTable::save( const QString &fn ) | 390 | bool TodoTable::save( const QString &fn ) |
384 | { | 391 | { |
385 | QString strNewFile = fn + ".new"; | 392 | QString strNewFile = fn + ".new"; |
386 | QFile::remove( strNewFile ); // just to be sure | 393 | QFile::remove( strNewFile ); // just to be sure |
387 | ToDoDB todoDB( strNewFile ); | 394 | ToDoDB todoDB( strNewFile ); |
388 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); | 395 | for ( QMap<CheckItem*, ToDoEvent *>::Iterator it = todoList.begin(); |
389 | it != todoList.end(); ++it ) { | 396 | it != todoList.end(); ++it ) { |
390 | if ( !item( it.key()->row(), 0 ) ) | 397 | if ( !item( it.key()->row(), 0 ) ) |
391 | continue; | 398 | continue; |
392 | ToDoEvent *todo = *it; | 399 | ToDoEvent *todo = *it; |
393 | // sync item with table | 400 | // sync item with table |
394 | todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); | 401 | todo->setCompleted( ((CheckItem*)item(it.key()->row(), 0))->isChecked() ); |
395 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); | 402 | todo->setPriority( ((ComboItem*)item( it.key()->row(), 1))->text().toInt() ); |
396 | todoDB.addEvent( *todo ); | 403 | todoDB.addEvent( *todo ); |
397 | } | 404 | } |
398 | if(!todoDB.save() ){ | 405 | if(!todoDB.save() ){ |
399 | QFile::remove( strNewFile ); | 406 | QFile::remove( strNewFile ); |
400 | return false; | 407 | return false; |
401 | }; | 408 | }; |
402 | // now do the rename | 409 | // now do the rename |
403 | if ( ::rename( strNewFile, fn ) < 0 ) | 410 | if ( ::rename( strNewFile, fn ) < 0 ) |
404 | qWarning( "problem renaming file %s to %s errno %d", | 411 | qWarning( "problem renaming file %s to %s errno %d", |
405 | strNewFile.latin1(), fn.latin1(), errno ); | 412 | strNewFile.latin1(), fn.latin1(), errno ); |
406 | 413 | ||
407 | // remove the journal | 414 | // remove the journal |
408 | QFile::remove( journalFileName() ); | 415 | QFile::remove( journalFileName() ); |
409 | return true; | 416 | return true; |
410 | } | 417 | } |
411 | 418 | ||
412 | void TodoTable::load( const QString &fn ) | 419 | void TodoTable::load( const QString &fn ) |
413 | { | 420 | { |
414 | if ( QFile::exists(journalFileName()) ) { | 421 | if ( QFile::exists(journalFileName()) ) { |
415 | applyJournal(); | 422 | applyJournal(); |
416 | QFile::remove(journalFileName() ); | 423 | QFile::remove(journalFileName() ); |
417 | } | 424 | } |
418 | loadFile( fn ); | 425 | loadFile( fn ); |
419 | // QTable::sortColumn(2,TRUE,TRUE); | 426 | // QTable::sortColumn(2,TRUE,TRUE); |
420 | // QTable::sortColumn(1,TRUE,TRUE); | 427 | // QTable::sortColumn(1,TRUE,TRUE); |
421 | QTable::sortColumn(0,TRUE,TRUE); | 428 | QTable::sortColumn(0,TRUE,TRUE); |
422 | setCurrentCell( 0, 2 ); | 429 | setCurrentCell( 0, 2 ); |
423 | setSorting(true ); | 430 | setSorting(true ); |
431 | mDayTimer->start( 60 * 1000 ); // gone in 60 seconds? | ||
424 | } | 432 | } |
425 | void TodoTable::updateVisible() | 433 | void TodoTable::updateVisible() |
426 | { | 434 | { |
427 | if ( !isUpdatesEnabled() ) | 435 | if ( !isUpdatesEnabled() ) |
428 | return; | 436 | return; |
429 | 437 | ||
430 | if (showDeadl){ | 438 | if (showDeadl){ |
431 | showColumn (3); | 439 | showColumn (3); |
432 | adjustColumn(3); | 440 | adjustColumn(3); |
433 | }else{ | 441 | }else{ |
434 | hideColumn (3); | 442 | hideColumn (3); |
435 | adjustColumn(2); | 443 | adjustColumn(2); |
436 | } | 444 | } |
437 | 445 | ||
438 | int visible = 0; | 446 | int visible = 0; |
439 | int id = mCat.id( "Todo List", showCat ); | 447 | int id = mCat.id( "Todo List", showCat ); |
440 | for ( int row = 0; row < numRows(); row++ ) { | 448 | for ( int row = 0; row < numRows(); row++ ) { |
441 | CheckItem *ci = (CheckItem *)item( row, 0 ); | 449 | CheckItem *ci = (CheckItem *)item( row, 0 ); |
442 | ToDoEvent *t = todoList[ci]; | 450 | ToDoEvent *t = todoList[ci]; |
443 | QArray<int> vlCats = t->categories(); | 451 | QArray<int> vlCats = t->categories(); |
444 | bool hide = false; | 452 | bool hide = false; |
445 | if ( !showComp && ci->isChecked() ) | 453 | if ( !showComp && ci->isChecked() ) |
446 | hide = true; | 454 | hide = true; |
447 | if ( !showCat.isEmpty() ) { | 455 | if ( !showCat.isEmpty() ) { |
448 | if ( showCat == tr( "Unfiled" ) ) { | 456 | if ( showCat == tr( "Unfiled" ) ) { |
449 | if ( vlCats.count() > 0 ) | 457 | if ( vlCats.count() > 0 ) |
450 | hide = true; | 458 | hide = true; |
451 | } else { | 459 | } else { |
452 | // do some comparing, we have to reverse our idea here... which idea? - zecke | 460 | // do some comparing, we have to reverse our idea here... which idea? - zecke |
453 | if ( !hide ) { | 461 | if ( !hide ) { |
454 | hide = true; | 462 | hide = true; |
455 | for ( uint it = 0; it < vlCats.count(); ++it ) { | 463 | for ( uint it = 0; it < vlCats.count(); ++it ) { |
456 | if ( vlCats[it] == id ) { | 464 | if ( vlCats[it] == id ) { |
457 | hide = false; | 465 | hide = false; |
458 | break; | 466 | break; |
459 | } | 467 | } |
460 | } | 468 | } |
461 | } | 469 | } |
462 | } | 470 | } |
463 | } | 471 | } |
464 | if ( hide ) { | 472 | if ( hide ) { |
465 | if ( currentRow() == row ) | 473 | if ( currentRow() == row ) |
466 | setCurrentCell( -1, 0 ); | 474 | setCurrentCell( -1, 0 ); |
467 | if ( rowHeight( row ) > 0 ) | 475 | if ( rowHeight( row ) > 0 ) |
468 | hideRow( row ); | 476 | hideRow( row ); |
469 | } else { | 477 | } else { |
470 | if ( rowHeight( row ) == 0 ) { | 478 | if ( rowHeight( row ) == 0 ) { |
471 | showRow( row ); | 479 | showRow( row ); |
@@ -736,96 +744,111 @@ int TodoTable::showCategoryId() const | |||
736 | id = mCat.id( "Todo List", showCat ); | 744 | id = mCat.id( "Todo List", showCat ); |
737 | return id; | 745 | return id; |
738 | } | 746 | } |
739 | void TodoTable::applyJournal() | 747 | void TodoTable::applyJournal() |
740 | { | 748 | { |
741 | // we need to hack | 749 | // we need to hack |
742 | QFile file( journalFileName() ); | 750 | QFile file( journalFileName() ); |
743 | if( file.open(IO_ReadOnly ) ) { | 751 | if( file.open(IO_ReadOnly ) ) { |
744 | QByteArray ar = file.readAll(); | 752 | QByteArray ar = file.readAll(); |
745 | file.close(); | 753 | file.close(); |
746 | QFile file2( journalFileName() + "_new" ); | 754 | QFile file2( journalFileName() + "_new" ); |
747 | if( file2.open(IO_WriteOnly ) ){ | 755 | if( file2.open(IO_WriteOnly ) ){ |
748 | QTextStream str(&file2 ); | 756 | QTextStream str(&file2 ); |
749 | str << QString::fromLatin1("<Tasks>") << endl; | 757 | str << QString::fromLatin1("<Tasks>") << endl; |
750 | str << ar.data(); | 758 | str << ar.data(); |
751 | str << QString::fromLatin1("</Tasks>") << endl; | 759 | str << QString::fromLatin1("</Tasks>") << endl; |
752 | file2.close(); | 760 | file2.close(); |
753 | } | 761 | } |
754 | XMLElement *root = XMLElement::load(journalFileName()+ "_new"); | 762 | XMLElement *root = XMLElement::load(journalFileName()+ "_new"); |
755 | XMLElement *el = root->firstChild(); | 763 | XMLElement *el = root->firstChild(); |
756 | el = el->firstChild(); | 764 | el = el->firstChild(); |
757 | ToDoDB tododb; // allready loaded ;) | 765 | ToDoDB tododb; // allready loaded ;) |
758 | bool ok; | 766 | bool ok; |
759 | int action; | 767 | int action; |
760 | QString dummy; | 768 | QString dummy; |
761 | while( el ){ | 769 | while( el ){ |
762 | dummy = el->attribute("Action" ); | 770 | dummy = el->attribute("Action" ); |
763 | action = dummy.toInt(&ok ); | 771 | action = dummy.toInt(&ok ); |
764 | ToDoEvent ev = xmlToEvent( el ); | 772 | ToDoEvent ev = xmlToEvent( el ); |
765 | if(ok ){ | 773 | if(ok ){ |
766 | switch( action){ | 774 | switch( action){ |
767 | case ACTION_ADD: | 775 | case ACTION_ADD: |
768 | tododb.addEvent(ev ); | 776 | tododb.addEvent(ev ); |
769 | break; | 777 | break; |
770 | case ACTION_REMOVE: | 778 | case ACTION_REMOVE: |
771 | tododb.removeEvent( ev ); | 779 | tododb.removeEvent( ev ); |
772 | break; | 780 | break; |
773 | case ACTION_REPLACE: | 781 | case ACTION_REPLACE: |
774 | tododb.replaceEvent( ev ); | 782 | tododb.replaceEvent( ev ); |
775 | break; | 783 | break; |
776 | } | 784 | } |
777 | } | 785 | } |
778 | el = el->nextChild(); | 786 | el = el->nextChild(); |
779 | } | 787 | } |
780 | QFile::remove(journalFileName()+ "_new" ); | 788 | QFile::remove(journalFileName()+ "_new" ); |
781 | tododb.save(); | 789 | tododb.save(); |
782 | } | 790 | } |
783 | } | 791 | } |
792 | void TodoTable::slotCheckDay() | ||
793 | { | ||
794 | QDate date = QDate::currentDate(); | ||
795 | if( mDay.daysTo(date )!= 0 ){ | ||
796 | setPaintingEnabled( FALSE ); | ||
797 | for(int i=0; i < numRows(); i++ ){ | ||
798 | ToDoEvent *t = todoList[static_cast<CheckItem*>(item(i, 0))]; | ||
799 | static_cast<DueTextItem*>(item(i, 3) )->setToDoEvent( t ); | ||
800 | |||
801 | } | ||
802 | setPaintingEnabled( TRUE ); | ||
803 | mDay = date; | ||
804 | } | ||
805 | mDayTimer->start( 60 * 1000 ); // 60 seconds | ||
806 | } | ||
784 | // check Action and decide | 807 | // check Action and decide |
785 | /* | 808 | /* |
786 | void TodoTable::doApply(XMLElement *el ) | 809 | void TodoTable::doApply(XMLElement *el ) |
787 | { | 810 | { |
788 | QString dummy; | 811 | QString dummy; |
789 | bool ok; | 812 | bool ok; |
790 | int action; | 813 | int action; |
791 | dummy = el->attribute("Action" ); | 814 | dummy = el->attribute("Action" ); |
792 | action = dummy.toInt(&ok ); | 815 | action = dummy.toInt(&ok ); |
793 | ToDoEvent ev = xmlToEvent( el ); | 816 | ToDoEvent ev = xmlToEvent( el ); |
794 | if( ok ){ | 817 | if( ok ){ |
795 | switch( action ){ | 818 | switch( action ){ |
796 | case ACTION_ADD: | 819 | case ACTION_ADD: |
797 | addEntry( ev ); | 820 | addEntry( ev ); |
798 | break; | 821 | break; |
799 | case ACTION_REMOVE:{ // find an entry with the same uid and remove it then | 822 | case ACTION_REMOVE:{ // find an entry with the same uid and remove it then |
800 | break; | 823 | break; |
801 | } | 824 | } |
802 | case ACTION_REPLACE: | 825 | case ACTION_REPLACE: |
803 | break; | 826 | break; |
804 | } | 827 | } |
805 | } | 828 | } |
806 | } | 829 | } |
807 | */ | 830 | */ |
808 | namespace { | 831 | namespace { |
809 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) | 832 | static bool taskCompare( const ToDoEvent &task, const QRegExp &r, int category ) |
810 | { | 833 | { |
811 | bool returnMe; | 834 | bool returnMe; |
812 | QArray<int> cats; | 835 | QArray<int> cats; |
813 | cats = task.categories(); | 836 | cats = task.categories(); |
814 | 837 | ||
815 | returnMe = false; | 838 | returnMe = false; |
816 | if ( (category == -1 && cats.count() == 0) || category == -2 ) | 839 | if ( (category == -1 && cats.count() == 0) || category == -2 ) |
817 | returnMe = task.match( r ); | 840 | returnMe = task.match( r ); |
818 | else { | 841 | else { |
819 | int i; | 842 | int i; |
820 | for ( i = 0; i < int(cats.count()); i++ ) { | 843 | for ( i = 0; i < int(cats.count()); i++ ) { |
821 | if ( cats[i] == category ) { | 844 | if ( cats[i] == category ) { |
822 | returnMe = task.match( r ); | 845 | returnMe = task.match( r ); |
823 | break; | 846 | break; |
824 | } | 847 | } |
825 | } | 848 | } |
826 | } | 849 | } |
827 | return returnMe; | 850 | return returnMe; |
828 | } | 851 | } |
829 | 852 | ||
830 | static QString journalFileName() | 853 | static QString journalFileName() |
831 | { | 854 | { |
diff --git a/core/pim/todo/todotable.h b/core/pim/todo/todotable.h index 6e371e8..458e07a 100644 --- a/core/pim/todo/todotable.h +++ b/core/pim/todo/todotable.h | |||
@@ -122,105 +122,108 @@ public: | |||
122 | bool save( const QString &fn ); | 122 | bool save( const QString &fn ); |
123 | void load( const QString &fn ); | 123 | void load( const QString &fn ); |
124 | void applyJournal( ); | 124 | void applyJournal( ); |
125 | void clear(); | 125 | void clear(); |
126 | void removeCurrentEntry(); | 126 | void removeCurrentEntry(); |
127 | void removeAllEntries() { clear(); }; | 127 | void removeAllEntries() { clear(); }; |
128 | //void removeAllEntriesInCategory(const QString &category ); | 128 | //void removeAllEntriesInCategory(const QString &category ); |
129 | 129 | ||
130 | void setPaintingEnabled( bool e ); | 130 | void setPaintingEnabled( bool e ); |
131 | 131 | ||
132 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); | 132 | virtual void sortColumn( int col, bool ascending, bool /*wholeRows*/ ); |
133 | 133 | ||
134 | // int rowHeight( int ) const; | 134 | // int rowHeight( int ) const; |
135 | // int rowPos( int row ) const; | 135 | // int rowPos( int row ) const; |
136 | // virtual int rowAt( int pos ) const; | 136 | // virtual int rowAt( int pos ) const; |
137 | 137 | ||
138 | signals: | 138 | signals: |
139 | void signalEdit(); | 139 | void signalEdit(); |
140 | void signalDoneChanged( bool b ); | 140 | void signalDoneChanged( bool b ); |
141 | void signalPriorityChanged( int i ); | 141 | void signalPriorityChanged( int i ); |
142 | void signalShowMenu( const QPoint & ); | 142 | void signalShowMenu( const QPoint & ); |
143 | void signalNotFound(); | 143 | void signalNotFound(); |
144 | void signalWrapAround(); | 144 | void signalWrapAround(); |
145 | 145 | ||
146 | protected: | 146 | protected: |
147 | void keyPressEvent( QKeyEvent *e ); | 147 | void keyPressEvent( QKeyEvent *e ); |
148 | 148 | ||
149 | private: | 149 | private: |
150 | void updateVisible(); | 150 | void updateVisible(); |
151 | void viewportPaintEvent( QPaintEvent * ); | 151 | void viewportPaintEvent( QPaintEvent * ); |
152 | void internalAddEntries( QList<ToDoEvent> &list); | 152 | void internalAddEntries( QList<ToDoEvent> &list); |
153 | inline void insertIntoTable( ToDoEvent *todo, int row ); | 153 | inline void insertIntoTable( ToDoEvent *todo, int row ); |
154 | void updateJournal( const ToDoEvent &todo, journal_action action); | 154 | void updateJournal( const ToDoEvent &todo, journal_action action); |
155 | void mergeJournal(); | 155 | void mergeJournal(); |
156 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); | 156 | void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); |
157 | void journalFreeRemoveEntry( int row ); | 157 | void journalFreeRemoveEntry( int row ); |
158 | inline void realignTable( int row ); | 158 | inline void realignTable( int row ); |
159 | void loadFile( const QString &strFile); | 159 | void loadFile( const QString &strFile); |
160 | 160 | ||
161 | private slots: | 161 | private slots: |
162 | void slotClicked( int row, int col, int button, const QPoint &pos ); | 162 | void slotClicked( int row, int col, int button, const QPoint &pos ); |
163 | void slotPressed( int row, int col, int button, const QPoint &pos ); | 163 | void slotPressed( int row, int col, int button, const QPoint &pos ); |
164 | void slotCheckPriority(int row, int col ); | 164 | void slotCheckPriority(int row, int col ); |
165 | void slotCurrentChanged(int row, int col ); | 165 | void slotCurrentChanged(int row, int col ); |
166 | void slotDoFind( const QString &findString, bool caseSensetive, | 166 | void slotDoFind( const QString &findString, bool caseSensetive, |
167 | bool backwards, int category ); | 167 | bool backwards, int category ); |
168 | void slotShowMenu(); | 168 | void slotShowMenu(); |
169 | void rowHeightChanged( int row ); | 169 | void rowHeightChanged( int row ); |
170 | void slotCheckDay(); // check the day | ||
170 | 171 | ||
171 | private: | 172 | private: |
172 | friend class TodoWindow; | 173 | friend class TodoWindow; |
173 | 174 | ||
174 | QMap<CheckItem*, ToDoEvent *> todoList; | 175 | QMap<CheckItem*, ToDoEvent *> todoList; |
175 | QStringList categoryList; | 176 | QStringList categoryList; |
176 | bool showComp; | 177 | bool showComp; |
177 | QString showCat; | 178 | QString showCat; |
178 | QTimer *menuTimer; | 179 | QTimer *menuTimer; |
180 | QDate mDay; | ||
181 | QTimer *mDayTimer; // see if the day changed | ||
179 | bool enablePainting; | 182 | bool enablePainting; |
180 | Categories mCat; | 183 | Categories mCat; |
181 | int currFindRow; | 184 | int currFindRow; |
182 | bool showDeadl:1; | 185 | bool showDeadl:1; |
183 | }; | 186 | }; |
184 | 187 | ||
185 | 188 | ||
186 | inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) | 189 | inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) |
187 | { | 190 | { |
188 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') | 191 | QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') |
189 | + todo->priority() ) | 192 | + todo->priority() ) |
190 | + Qtopia::buildSortKey( todo->description() ); | 193 | + Qtopia::buildSortKey( todo->description() ); |
191 | CheckItem *chk = new CheckItem( this, sortKey ); | 194 | CheckItem *chk = new CheckItem( this, sortKey ); |
192 | chk->setChecked( todo->isCompleted() ); | 195 | chk->setChecked( todo->isCompleted() ); |
193 | ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); | 196 | ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); |
194 | cmb->setText( QString::number( todo->priority() ) ); | 197 | cmb->setText( QString::number( todo->priority() ) ); |
195 | QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); | 198 | QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); |
196 | ti->setReplaceable( false ); | 199 | ti->setReplaceable( false ); |
197 | 200 | ||
198 | DueTextItem *due = new DueTextItem(this, todo ); | 201 | DueTextItem *due = new DueTextItem(this, todo ); |
199 | setItem( row, 3, due); | 202 | setItem( row, 3, due); |
200 | 203 | ||
201 | setItem( row, 0, chk ); | 204 | setItem( row, 0, chk ); |
202 | setItem( row, 1, cmb ); | 205 | setItem( row, 1, cmb ); |
203 | setItem( row, 2, ti ); | 206 | setItem( row, 2, ti ); |
204 | 207 | ||
205 | 208 | ||
206 | todoList.insert( chk, todo ); | 209 | todoList.insert( chk, todo ); |
207 | } | 210 | } |
208 | 211 | ||
209 | inline void TodoTable::realignTable( int row ) | 212 | inline void TodoTable::realignTable( int row ) |
210 | { | 213 | { |
211 | QTableItem *ti1, | 214 | QTableItem *ti1, |
212 | *ti2, | 215 | *ti2, |
213 | *ti3, | 216 | *ti3, |
214 | *ti4; | 217 | *ti4; |
215 | int totalRows = numRows(); | 218 | int totalRows = numRows(); |
216 | for ( int curr = row; curr < totalRows - 1; curr++ ) { | 219 | for ( int curr = row; curr < totalRows - 1; curr++ ) { |
217 | // this is bad, we must take the item out and then | 220 | // this is bad, we must take the item out and then |
218 | // set it. In the end, it behaves no worse (time wise) | 221 | // set it. In the end, it behaves no worse (time wise) |
219 | // then the old way of saving the entries to file, clearing | 222 | // then the old way of saving the entries to file, clearing |
220 | // the table re-reading in the file and resetting the table | 223 | // the table re-reading in the file and resetting the table |
221 | ti1 = item( curr + 1, 0 ); | 224 | ti1 = item( curr + 1, 0 ); |
222 | ti2 = item( curr + 1, 1 ); | 225 | ti2 = item( curr + 1, 1 ); |
223 | ti3 = item( curr + 1, 2 ); | 226 | ti3 = item( curr + 1, 2 ); |
224 | ti4 = item( curr + 1, 3 ); | 227 | ti4 = item( curr + 1, 3 ); |
225 | takeItem( ti1 ); | 228 | takeItem( ti1 ); |
226 | takeItem( ti2 ); | 229 | takeItem( ti2 ); |