summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 38ba2c7..c97a61e 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -85,97 +85,97 @@ void Todo::setRunning( bool run )
85 } else { 85 } else {
86 mRunSaveTimer->stop(); 86 mRunSaveTimer->stop();
87 saveRunningInfoToFile(); 87 saveRunningInfoToFile();
88 } 88 }
89} 89}
90 90
91void Todo::saveRunningInfoToFile( QString comment ) 91void Todo::saveRunningInfoToFile( QString comment )
92{ 92{
93 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 93 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
94 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { 94 if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) {
95 qDebug("Running time < 30 seconds. Skipped. "); 95 qDebug("Running time < 30 seconds. Skipped. ");
96 return; 96 return;
97 } 97 }
98 QString dir = KGlobalSettings::timeTrackerDir(); 98 QString dir = KGlobalSettings::timeTrackerDir();
99 //qDebug("%s ", dir.latin1()); 99 //qDebug("%s ", dir.latin1());
100 QString file = "%1%2%3-%4%5%6-"; 100 QString file = "%1%2%3-%4%5%6-";
101 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); 101 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
102 file.replace ( QRegExp (" "), "0" ); 102 file.replace ( QRegExp (" "), "0" );
103 file += uid(); 103 file += uid();
104 //qDebug("File %s ",file.latin1() ); 104 //qDebug("File %s ",file.latin1() );
105 CalendarLocal cal; 105 CalendarLocal cal;
106 cal.setLocalTime(); 106 cal.setLocalTime();
107 Todo * to = (Todo*) clone(); 107 Todo * to = (Todo*) clone();
108 to->setFloats( false ); 108 to->setFloats( false );
109 to->setDtStart( mRunStart ); 109 to->setDtStart( mRunStart );
110 to->setHasStartDate( true ); 110 to->setHasStartDate( true );
111 to->setDtDue( QDateTime::currentDateTime() ); 111 to->setDtDue( QDateTime::currentDateTime() );
112 to->setHasDueDate( true ); 112 to->setHasDueDate( true );
113 to->setUid( file ); 113 to->setUid( file );
114 if ( !comment.isEmpty() ) { 114 if ( !comment.isEmpty() ) {
115 QString des = to->description(); 115 QString des = to->description();
116 if ( des.isEmpty () ) 116 if ( des.isEmpty () )
117 to->setDescription( "TT-Note: " + comment ); 117 to->setDescription( "TT-Note: " + comment );
118 else 118 else
119 to->setDescription( "TT-Note: " + comment +"\n" + des ); 119 to->setDescription( "TT-Note: " + comment +"\n" + des );
120 } 120 }
121 cal.addIncidence( to ); 121 cal.addIncidence( to );
122 ICalFormat format; 122 ICalFormat format;
123 file = dir +"/" +file +".ics"; 123 file = dir +"/" +file +".ics";
124 format.save( &cal, file ); 124 format.save( &cal, file );
125 saveParents(); 125 saveParents();
126 126
127} 127}
128void Todo::saveParents() 128void Todo::saveParents()
129{ 129{
130 if (!relatedTo() ) 130 if (!relatedTo() )
131 return; 131 return;
132 Incidence * inc = relatedTo(); 132 Incidence * inc = relatedTo();
133 if ( inc->type() != "Todo" ) 133 if ( inc->typeID() != todoID )
134 return; 134 return;
135 Todo* to = (Todo*)inc; 135 Todo* to = (Todo*)inc;
136 bool saveTodo = false; 136 bool saveTodo = false;
137 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 137 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
138 QFileInfo fi ( file ); 138 QFileInfo fi ( file );
139 if ( fi.exists() ) { 139 if ( fi.exists() ) {
140 if ( fi.lastModified () < to->lastModified ()) 140 if ( fi.lastModified () < to->lastModified ())
141 saveTodo = true; 141 saveTodo = true;
142 } else { 142 } else {
143 saveTodo = true; 143 saveTodo = true;
144 } 144 }
145 if ( saveTodo ) { 145 if ( saveTodo ) {
146 CalendarLocal cal; 146 CalendarLocal cal;
147 cal.setLocalTime(); 147 cal.setLocalTime();
148 Todo * par = (Todo *) to->clone(); 148 Todo * par = (Todo *) to->clone();
149 cal.addIncidence( par ); 149 cal.addIncidence( par );
150 ICalFormat format; 150 ICalFormat format;
151 format.save( &cal, file ); 151 format.save( &cal, file );
152 } 152 }
153 to->saveParents(); 153 to->saveParents();
154} 154}
155 155
156int Todo::runTime() 156int Todo::runTime()
157{ 157{
158 if ( !mRunning ) 158 if ( !mRunning )
159 return 0; 159 return 0;
160 return mRunStart.secsTo( QDateTime::currentDateTime() ); 160 return mRunStart.secsTo( QDateTime::currentDateTime() );
161} 161}
162bool Todo::hasRunningSub() 162bool Todo::hasRunningSub()
163{ 163{
164 if ( mRunning ) 164 if ( mRunning )
165 return true; 165 return true;
166 Incidence *aTodo; 166 Incidence *aTodo;
167 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 167 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
168 if ( ((Todo*)aTodo)->hasRunningSub() ) 168 if ( ((Todo*)aTodo)->hasRunningSub() )
169 return true; 169 return true;
170 } 170 }
171 return false; 171 return false;
172} 172}
173Incidence *Todo::clone() 173Incidence *Todo::clone()
174{ 174{
175 return new Todo(*this); 175 return new Todo(*this);
176} 176}
177 177
178bool Todo::contains ( Todo* from ) 178bool Todo::contains ( Todo* from )
179{ 179{
180 180
181 if ( !from->summary().isEmpty() ) 181 if ( !from->summary().isEmpty() )
@@ -519,62 +519,63 @@ QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_d
519{ 519{
520 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 520 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
521 *ok = false; 521 *ok = false;
522 return QDateTime (); 522 return QDateTime ();
523 } 523 }
524 QDateTime incidenceStart; 524 QDateTime incidenceStart;
525 incidenceStart = dtDue(); 525 incidenceStart = dtDue();
526 bool enabled = false; 526 bool enabled = false;
527 Alarm* alarm; 527 Alarm* alarm;
528 int off = 0; 528 int off = 0;
529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
530 // if ( QDateTime::currentDateTime() > incidenceStart ){ 530 // if ( QDateTime::currentDateTime() > incidenceStart ){
531// *ok = false; 531// *ok = false;
532// return incidenceStart; 532// return incidenceStart;
533// } 533// }
534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
535 if (alarm->enabled()) { 535 if (alarm->enabled()) {
536 if ( alarm->hasTime () ) { 536 if ( alarm->hasTime () ) {
537 if ( alarm->time() < alarmStart ) { 537 if ( alarm->time() < alarmStart ) {
538 alarmStart = alarm->time(); 538 alarmStart = alarm->time();
539 enabled = true; 539 enabled = true;
540 off = alarmStart.secsTo( incidenceStart ); 540 off = alarmStart.secsTo( incidenceStart );
541 } 541 }
542 542
543 } else { 543 } else {
544 int secs = alarm->startOffset().asSeconds(); 544 int secs = alarm->startOffset().asSeconds();
545 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 545 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
546 alarmStart = incidenceStart.addSecs( secs ); 546 alarmStart = incidenceStart.addSecs( secs );
547 enabled = true; 547 enabled = true;
548 off = -secs; 548 off = -secs;
549 } 549 }
550 } 550 }
551 } 551 }
552 } 552 }
553 if ( enabled ) { 553 if ( enabled ) {
554 if ( alarmStart > start_dt ) { 554 if ( alarmStart > start_dt ) {
555 *ok = true; 555 *ok = true;
556 * offset = off; 556 * offset = off;
557 return alarmStart; 557 return alarmStart;
558 } 558 }
559 } 559 }
560 *ok = false; 560 *ok = false;
561 return QDateTime (); 561 return QDateTime ();
562 562
563} 563}
564 564
565void Todo::checkSetCompletedFalse() 565void Todo::checkSetCompletedFalse()
566{ 566{
567 if ( !hasRecurrenceID() ) { 567 if ( !mHasRecurrenceID ) {
568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
569 return;
569 } 570 }
570 // qDebug("Todo::checkSetCompletedFalse()"); 571 // qDebug("Todo::checkSetCompletedFalse()");
571 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 572 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
572 if ( mPercentComplete == 100 ) { 573 if ( mPercentComplete == 100 ) {
573 QDateTime dt = QDateTime::currentDateTime(); 574 QDateTime dt = QDateTime::currentDateTime();
574 if ( dt > mDtStart && dt > mRecurrenceID ) { 575 if ( dt > mDtStart && dt > mRecurrenceID ) {
575 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 576 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
576 setCompleted( false ); 577 setCompleted( false );
577 qDebug("Todo::checkSetCompletedFalse "); 578 qDebug("Todo::checkSetCompletedFalse ");
578 } 579 }
579 } 580 }
580} 581}