summaryrefslogtreecommitdiff
authorzecke <zecke>2002-04-18 20:43:35 (UTC)
committer zecke <zecke>2002-04-18 20:43:35 (UTC)
commit877e3d4899013687a0a16caefadabf86703bcf27 (patch) (unidiff)
treeb8df1964ea9ea4dc1a1cbb9cab8a2ff84560a11f
parent56c20411484700350362b5041e3c9db030084caf (diff)
downloadopie-877e3d4899013687a0a16caefadabf86703bcf27.zip
opie-877e3d4899013687a0a16caefadabf86703bcf27.tar.gz
opie-877e3d4899013687a0a16caefadabf86703bcf27.tar.bz2
on day change the deadline gets changed
I use QDate and a Timer for that. Does anyone know a better way?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/todotable.cpp23
-rw-r--r--core/pim/todo/todotable.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/core/pim/todo/todotable.cpp b/core/pim/todo/todotable.cpp
index 96cd860..d0bc61c 100644
--- a/core/pim/todo/todotable.cpp
+++ b/core/pim/todo/todotable.cpp
@@ -172,56 +172,59 @@ DueTextItem::DueTextItem( QTable *t, ToDoEvent *ev )
172QString DueTextItem::key() const 172QString DueTextItem::key() const
173{ 173{
174 QString key; 174 QString key;
175 if( m_hasDate ){ 175 if( m_hasDate ){
176 if(m_off == 0 ){ 176 if(m_off == 0 ){
177 key.append("b"); 177 key.append("b");
178 }else if( m_off > 0 ){ 178 }else if( m_off > 0 ){
179 key.append("c"); 179 key.append("c");
180 }else if( m_off < 0 ){ 180 }else if( m_off < 0 ){
181 key.append("a"); 181 key.append("a");
182 } 182 }
183 key.append(QString::number(m_off ) ); 183 key.append(QString::number(m_off ) );
184 }else{ 184 }else{
185 key.append("d"); 185 key.append("d");
186 } 186 }
187 return key; 187 return key;
188} 188}
189void DueTextItem::setToDoEvent( const ToDoEvent *ev ) 189void DueTextItem::setToDoEvent( const ToDoEvent *ev )
190{ 190{
191 m_hasDate = ev->hasDate(); 191 m_hasDate = ev->hasDate();
192 m_completed = ev->isCompleted(); 192 m_completed = ev->isCompleted();
193 if( ev->hasDate() ){ 193 if( ev->hasDate() ){
194 QDate today = QDate::currentDate(); 194 QDate today = QDate::currentDate();
195 m_off = today.daysTo(ev->date() ); 195 m_off = today.daysTo(ev->date() );
196 //qWarning("DueText m_off=%d", m_off );
196 setText( QString::number(m_off) + " day(s) " ); 197 setText( QString::number(m_off) + " day(s) " );
197 }else{ 198 }else{
198 setText("n.d." ); 199 setText("n.d." );
199 m_off = 0; 200 m_off = 0;
200 } 201 }
202 //qWarning("m_off=%d", m_off );
201} 203}
202void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) 204void DueTextItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected )
203{ 205{
206 //qWarning ("paint m_off=%d", m_off );
204 QColorGroup cg2(cg); 207 QColorGroup cg2(cg);
205 QColor text = cg.text(); 208 QColor text = cg.text();
206 if( m_hasDate && !m_completed ){ 209 if( m_hasDate && !m_completed ){
207 if( m_off < 0 ){ 210 if( m_off < 0 ){
208 cg2.setColor(QColorGroup::Text, QColor(red ) ); 211 cg2.setColor(QColorGroup::Text, QColor(red ) );
209 }else if( m_off == 0 ){ 212 }else if( m_off == 0 ){
210 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined 213 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined
211 }else if( m_off > 0){ 214 }else if( m_off > 0){
212 cg2.setColor(QColorGroup::Text, QColor(green ) ); 215 cg2.setColor(QColorGroup::Text, QColor(green ) );
213 } 216 }
214 } 217 }
215 QTableItem::paint(p, cg2, cr, selected ); 218 QTableItem::paint(p, cg2, cr, selected );
216 cg2.setColor(QColorGroup::Text, text ); 219 cg2.setColor(QColorGroup::Text, text );
217} 220}
218TodoTable::TodoTable( QWidget *parent, const char *name ) 221TodoTable::TodoTable( QWidget *parent, const char *name )
219// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR 222// #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR
220// : QTable( 0, 3, parent, name, TRUE ), 223// : QTable( 0, 3, parent, name, TRUE ),
221// #else 224// #else
222 : QTable( 0, 4, parent, name ), 225 : QTable( 0, 4, parent, name ),
223// #endif 226// #endif
224 showComp( true ), 227 showComp( true ),
225 enablePainting( true ), 228 enablePainting( true ),
226 mCat( 0 ), 229 mCat( 0 ),
227 currFindRow( -2 ), 230 currFindRow( -2 ),
@@ -240,48 +243,52 @@ TodoTable::TodoTable( QWidget *parent, const char *name )
240 horizontalHeader()->setLabel( 1, tr( "Prior." ) ); 243 horizontalHeader()->setLabel( 1, tr( "Prior." ) );
241 horizontalHeader()->setLabel( 2, tr( "Description" ) ); 244 horizontalHeader()->setLabel( 2, tr( "Description" ) );
242 245
243 setColumnStretchable( 3, FALSE ); 246 setColumnStretchable( 3, FALSE );
244 setColumnWidth( 3, 20 ); 247 setColumnWidth( 3, 20 );
245 horizontalHeader()->setLabel( 3, tr( "Deadline" ) ); 248 horizontalHeader()->setLabel( 3, tr( "Deadline" ) );
246 249
247 if (showDeadl){ 250 if (showDeadl){
248 showColumn (3); 251 showColumn (3);
249 }else{ 252 }else{
250 hideColumn (3); 253 hideColumn (3);
251 } 254 }
252 255
253 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 256 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
254 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) ); 257 this, SLOT( slotClicked( int, int, int, const QPoint & ) ) );
255 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ), 258 connect( this, SIGNAL( pressed( int, int, int, const QPoint & ) ),
256 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) ); 259 this, SLOT( slotPressed( int, int, int, const QPoint & ) ) );
257 connect( this, SIGNAL( valueChanged( int, int ) ), 260 connect( this, SIGNAL( valueChanged( int, int ) ),
258 this, SLOT( slotCheckPriority( int, int ) ) ); 261 this, SLOT( slotCheckPriority( int, int ) ) );
259 connect( this, SIGNAL( currentChanged( int, int ) ), 262 connect( this, SIGNAL( currentChanged( int, int ) ),
260 this, SLOT( slotCurrentChanged( int, int ) ) ); 263 this, SLOT( slotCurrentChanged( int, int ) ) );
261 264
262 menuTimer = new QTimer( this ); 265 menuTimer = new QTimer( this );
263 connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) ); 266 connect( menuTimer, SIGNAL(timeout()), this, SLOT(slotShowMenu()) );
267
268 mDayTimer = new QTimer( this );
269 connect( mDayTimer, SIGNAL(timeout()), this, SLOT(slotCheckDay() ) );
270 mDay = QDate::currentDate();
264} 271}
265 272
266void TodoTable::addEntry( const ToDoEvent &todo ) 273void TodoTable::addEntry( const ToDoEvent &todo )
267{ 274{
268 int row = numRows(); 275 int row = numRows();
269 setNumRows( row + 1 ); 276 setNumRows( row + 1 );
270 updateJournal( todo, ACTION_ADD ); 277 updateJournal( todo, ACTION_ADD );
271 insertIntoTable( new ToDoEvent(todo), row ); 278 insertIntoTable( new ToDoEvent(todo), row );
272 setCurrentCell(row, currentColumn()); 279 setCurrentCell(row, currentColumn());
273 updateVisible(); 280 updateVisible();
274} 281}
275 282
276void TodoTable::slotClicked( int row, int col, int, const QPoint &pos ) 283void TodoTable::slotClicked( int row, int col, int, const QPoint &pos )
277{ 284{
278 if ( !cellGeometry( row, col ).contains(pos) ) 285 if ( !cellGeometry( row, col ).contains(pos) )
279 return; 286 return;
280 // let's switch on the column number... 287 // let's switch on the column number...
281 switch ( col ) 288 switch ( col )
282 { 289 {
283 case 0: { 290 case 0: {
284 CheckItem *i = static_cast<CheckItem*>(item( row, col )); 291 CheckItem *i = static_cast<CheckItem*>(item( row, col ));
285 if ( i ) { 292 if ( i ) {
286 int x = pos.x() - columnPos( col ); 293 int x = pos.x() - columnPos( col );
287 int y = pos.y() - rowPos( row ); 294 int y = pos.y() - rowPos( row );
@@ -400,48 +407,49 @@ bool TodoTable::save( const QString &fn )
400 return false; 407 return false;
401 }; 408 };
402 // now do the rename 409 // now do the rename
403 if ( ::rename( strNewFile, fn ) < 0 ) 410 if ( ::rename( strNewFile, fn ) < 0 )
404 qWarning( "problem renaming file %s to %s errno %d", 411 qWarning( "problem renaming file %s to %s errno %d",
405 strNewFile.latin1(), fn.latin1(), errno ); 412 strNewFile.latin1(), fn.latin1(), errno );
406 413
407 // remove the journal 414 // remove the journal
408 QFile::remove( journalFileName() ); 415 QFile::remove( journalFileName() );
409 return true; 416 return true;
410} 417}
411 418
412void TodoTable::load( const QString &fn ) 419void TodoTable::load( const QString &fn )
413{ 420{
414 if ( QFile::exists(journalFileName()) ) { 421 if ( QFile::exists(journalFileName()) ) {
415 applyJournal(); 422 applyJournal();
416 QFile::remove(journalFileName() ); 423 QFile::remove(journalFileName() );
417 } 424 }
418 loadFile( fn ); 425 loadFile( fn );
419// QTable::sortColumn(2,TRUE,TRUE); 426// QTable::sortColumn(2,TRUE,TRUE);
420// QTable::sortColumn(1,TRUE,TRUE); 427// QTable::sortColumn(1,TRUE,TRUE);
421 QTable::sortColumn(0,TRUE,TRUE); 428 QTable::sortColumn(0,TRUE,TRUE);
422 setCurrentCell( 0, 2 ); 429 setCurrentCell( 0, 2 );
423 setSorting(true ); 430 setSorting(true );
431 mDayTimer->start( 60 * 1000 ); // gone in 60 seconds?
424} 432}
425void TodoTable::updateVisible() 433void TodoTable::updateVisible()
426{ 434{
427 if ( !isUpdatesEnabled() ) 435 if ( !isUpdatesEnabled() )
428 return; 436 return;
429 437
430 if (showDeadl){ 438 if (showDeadl){
431 showColumn (3); 439 showColumn (3);
432 adjustColumn(3); 440 adjustColumn(3);
433 }else{ 441 }else{
434 hideColumn (3); 442 hideColumn (3);
435 adjustColumn(2); 443 adjustColumn(2);
436 } 444 }
437 445
438 int visible = 0; 446 int visible = 0;
439 int id = mCat.id( "Todo List", showCat ); 447 int id = mCat.id( "Todo List", showCat );
440 for ( int row = 0; row < numRows(); row++ ) { 448 for ( int row = 0; row < numRows(); row++ ) {
441 CheckItem *ci = (CheckItem *)item( row, 0 ); 449 CheckItem *ci = (CheckItem *)item( row, 0 );
442 ToDoEvent *t = todoList[ci]; 450 ToDoEvent *t = todoList[ci];
443 QArray<int> vlCats = t->categories(); 451 QArray<int> vlCats = t->categories();
444 bool hide = false; 452 bool hide = false;
445 if ( !showComp && ci->isChecked() ) 453 if ( !showComp && ci->isChecked() )
446 hide = true; 454 hide = true;
447 if ( !showCat.isEmpty() ) { 455 if ( !showCat.isEmpty() ) {
@@ -760,48 +768,63 @@ void TodoTable::applyJournal()
760 QString dummy; 768 QString dummy;
761 while( el ){ 769 while( el ){
762 dummy = el->attribute("Action" ); 770 dummy = el->attribute("Action" );
763 action = dummy.toInt(&ok ); 771 action = dummy.toInt(&ok );
764 ToDoEvent ev = xmlToEvent( el ); 772 ToDoEvent ev = xmlToEvent( el );
765 if(ok ){ 773 if(ok ){
766 switch( action){ 774 switch( action){
767 case ACTION_ADD: 775 case ACTION_ADD:
768 tododb.addEvent(ev ); 776 tododb.addEvent(ev );
769 break; 777 break;
770 case ACTION_REMOVE: 778 case ACTION_REMOVE:
771 tododb.removeEvent( ev ); 779 tododb.removeEvent( ev );
772 break; 780 break;
773 case ACTION_REPLACE: 781 case ACTION_REPLACE:
774 tododb.replaceEvent( ev ); 782 tododb.replaceEvent( ev );
775 break; 783 break;
776 } 784 }
777 } 785 }
778 el = el->nextChild(); 786 el = el->nextChild();
779 } 787 }
780 QFile::remove(journalFileName()+ "_new" ); 788 QFile::remove(journalFileName()+ "_new" );
781 tododb.save(); 789 tododb.save();
782 } 790 }
783} 791}
792void TodoTable::slotCheckDay()
793{
794 QDate date = QDate::currentDate();
795 if( mDay.daysTo(date )!= 0 ){
796 setPaintingEnabled( FALSE );
797 for(int i=0; i < numRows(); i++ ){
798 ToDoEvent *t = todoList[static_cast<CheckItem*>(item(i, 0))];
799 static_cast<DueTextItem*>(item(i, 3) )->setToDoEvent( t );
800
801 }
802 setPaintingEnabled( TRUE );
803 mDay = date;
804 }
805 mDayTimer->start( 60 * 1000 ); // 60 seconds
806}
784// check Action and decide 807// check Action and decide
785/* 808/*
786void TodoTable::doApply(XMLElement *el ) 809void TodoTable::doApply(XMLElement *el )
787{ 810{
788 QString dummy; 811 QString dummy;
789 bool ok; 812 bool ok;
790 int action; 813 int action;
791 dummy = el->attribute("Action" ); 814 dummy = el->attribute("Action" );
792 action = dummy.toInt(&ok ); 815 action = dummy.toInt(&ok );
793 ToDoEvent ev = xmlToEvent( el ); 816 ToDoEvent ev = xmlToEvent( el );
794 if( ok ){ 817 if( ok ){
795 switch( action ){ 818 switch( action ){
796 case ACTION_ADD: 819 case ACTION_ADD:
797 addEntry( ev ); 820 addEntry( ev );
798 break; 821 break;
799 case ACTION_REMOVE:{ // find an entry with the same uid and remove it then 822 case ACTION_REMOVE:{ // find an entry with the same uid and remove it then
800 break; 823 break;
801 } 824 }
802 case ACTION_REPLACE: 825 case ACTION_REPLACE:
803 break; 826 break;
804 } 827 }
805 } 828 }
806} 829}
807*/ 830*/
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
@@ -146,57 +146,60 @@ signals:
146protected: 146protected:
147 void keyPressEvent( QKeyEvent *e ); 147 void keyPressEvent( QKeyEvent *e );
148 148
149private: 149private:
150 void updateVisible(); 150 void updateVisible();
151 void viewportPaintEvent( QPaintEvent * ); 151 void viewportPaintEvent( QPaintEvent * );
152 void internalAddEntries( QList<ToDoEvent> &list); 152 void internalAddEntries( QList<ToDoEvent> &list);
153 inline void insertIntoTable( ToDoEvent *todo, int row ); 153 inline void insertIntoTable( ToDoEvent *todo, int row );
154 void updateJournal( const ToDoEvent &todo, journal_action action); 154 void updateJournal( const ToDoEvent &todo, journal_action action);
155 void mergeJournal(); 155 void mergeJournal();
156 void journalFreeReplaceEntry( const ToDoEvent &todo, int row ); 156 void journalFreeReplaceEntry( const ToDoEvent &todo, int row );
157 void journalFreeRemoveEntry( int row ); 157 void journalFreeRemoveEntry( int row );
158 inline void realignTable( int row ); 158 inline void realignTable( int row );
159 void loadFile( const QString &strFile); 159 void loadFile( const QString &strFile);
160 160
161private slots: 161private slots:
162 void slotClicked( int row, int col, int button, const QPoint &pos ); 162 void slotClicked( int row, int col, int button, const QPoint &pos );
163 void slotPressed( int row, int col, int button, const QPoint &pos ); 163 void slotPressed( int row, int col, int button, const QPoint &pos );
164 void slotCheckPriority(int row, int col ); 164 void slotCheckPriority(int row, int col );
165 void slotCurrentChanged(int row, int col ); 165 void slotCurrentChanged(int row, int col );
166 void slotDoFind( const QString &findString, bool caseSensetive, 166 void slotDoFind( const QString &findString, bool caseSensetive,
167 bool backwards, int category ); 167 bool backwards, int category );
168 void slotShowMenu(); 168 void slotShowMenu();
169 void rowHeightChanged( int row ); 169 void rowHeightChanged( int row );
170 void slotCheckDay(); // check the day
170 171
171private: 172private:
172 friend class TodoWindow; 173 friend class TodoWindow;
173 174
174 QMap<CheckItem*, ToDoEvent *> todoList; 175 QMap<CheckItem*, ToDoEvent *> todoList;
175 QStringList categoryList; 176 QStringList categoryList;
176 bool showComp; 177 bool showComp;
177 QString showCat; 178 QString showCat;
178 QTimer *menuTimer; 179 QTimer *menuTimer;
180 QDate mDay;
181 QTimer *mDayTimer; // see if the day changed
179 bool enablePainting; 182 bool enablePainting;
180 Categories mCat; 183 Categories mCat;
181 int currFindRow; 184 int currFindRow;
182 bool showDeadl:1; 185 bool showDeadl:1;
183}; 186};
184 187
185 188
186inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row ) 189inline void TodoTable::insertIntoTable( ToDoEvent *todo, int row )
187{ 190{
188 QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A') 191 QString sortKey = (char) ((todo->isCompleted() ? 'a' : 'A')
189 + todo->priority() ) 192 + todo->priority() )
190 + Qtopia::buildSortKey( todo->description() ); 193 + Qtopia::buildSortKey( todo->description() );
191 CheckItem *chk = new CheckItem( this, sortKey ); 194 CheckItem *chk = new CheckItem( this, sortKey );
192 chk->setChecked( todo->isCompleted() ); 195 chk->setChecked( todo->isCompleted() );
193 ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent ); 196 ComboItem *cmb = new ComboItem( this, QTableItem::WhenCurrent );
194 cmb->setText( QString::number( todo->priority() ) ); 197 cmb->setText( QString::number( todo->priority() ) );
195 QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() ); 198 QTableItem *ti = new TodoTextItem( this, todo->description().left(40).simplifyWhiteSpace() );
196 ti->setReplaceable( false ); 199 ti->setReplaceable( false );
197 200
198 DueTextItem *due = new DueTextItem(this, todo ); 201 DueTextItem *due = new DueTextItem(this, todo );
199 setItem( row, 3, due); 202 setItem( row, 3, due);
200 203
201 setItem( row, 0, chk ); 204 setItem( row, 0, chk );
202 setItem( row, 1, cmb ); 205 setItem( row, 1, cmb );