summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/todo.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 70a7711..29f725f 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -110,133 +110,133 @@ void Todo::setRunning( bool run )
110} 110}
111void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 111void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
112{ 112{
113 if ( !mRunning) return; 113 if ( !mRunning) return;
114 mRunning = false; 114 mRunning = false;
115 mRunStart = start; 115 mRunStart = start;
116 mRunEnd = end; 116 mRunEnd = end;
117 saveRunningInfoToFile( comment ); 117 saveRunningInfoToFile( comment );
118} 118}
119void Todo::restartSaveTimer( int secs ) 119void Todo::restartSaveTimer( int secs )
120{ 120{
121 mRunSaveTimer->start( secs * 1000 ); 121 mRunSaveTimer->start( secs * 1000 );
122 mRunLastSave = QDateTime::currentDateTime(); 122 mRunLastSave = QDateTime::currentDateTime();
123 mCurrentTimerDelay = secs; 123 mCurrentTimerDelay = secs;
124} 124}
125void Todo::timerSlotSaveRunningInfoToFile() 125void Todo::timerSlotSaveRunningInfoToFile()
126{ 126{
127 mRunEnd = QDateTime::currentDateTime(); 127 mRunEnd = QDateTime::currentDateTime();
128 int secsTo = mRunLastSave.secsTo( mRunEnd ); 128 int secsTo = mRunLastSave.secsTo( mRunEnd );
129 //if( secsTo == 8 ) ++secsTo; 129 //if( secsTo == 8 ) ++secsTo;
130 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); 130 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay );
131 if ( secsTo > mCurrentTimerDelay ) { 131 if ( secsTo > mCurrentTimerDelay ) {
132 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); 132 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS );
133 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 133 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
134 return; 134 return;
135 } 135 }
136 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); 136 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time());
137 if ( msecs < 0 ) { 137 if ( msecs < 0 ) {
138 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 138 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
139 return; 139 return;
140 } 140 }
141 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); 141 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
142 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { 142 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) {
143 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); 143 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
144 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 144 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
145 return; 145 return;
146 } 146 }
147 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); 147 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
148 saveRunningInfoToFile( QString::null ); 148 saveRunningInfoToFile( QString::null );
149} 149}
150void Todo::saveRunningInfoToFile() 150void Todo::saveRunningInfoToFile()
151{ 151{
152 mRunEnd = QDateTime::currentDateTime(); 152 mRunEnd = QDateTime::currentDateTime();
153 saveRunningInfoToFile( QString::null ); 153 saveRunningInfoToFile( QString::null );
154} 154}
155void Todo::saveRunningInfoToFile( QString comment ) 155void Todo::saveRunningInfoToFile( QString comment )
156{ 156{
157#ifndef DESKTOP_VERSION 157#ifndef DESKTOP_VERSION
158 QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable ); 158 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
159#endif 159#endif
160 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 160 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
161 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 161 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
162 qDebug("Running time < 15 seconds. Skipped. "); 162 qDebug("Running time < 15 seconds. Skipped. ");
163 return; 163 return;
164 } 164 }
165 QString dir = KGlobalSettings::timeTrackerDir(); 165 QString dir = KGlobalSettings::timeTrackerDir();
166 //qDebug("%s ", dir.latin1()); 166 //qDebug("%s ", dir.latin1());
167 QString file = "%1%2%3-%4%5%6-"; 167 QString file = "%1%2%3-%4%5%6-";
168 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 ); 168 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 );
169 file.replace ( QRegExp (" "), "0" ); 169 file.replace ( QRegExp (" "), "0" );
170 file += uid(); 170 file += uid();
171 //qDebug("File %s ",file.latin1() ); 171 //qDebug("File %s ",file.latin1() );
172 CalendarLocal cal; 172 CalendarLocal cal;
173 cal.setLocalTime(); 173 cal.setLocalTime();
174 Todo * to = (Todo*) clone(); 174 Todo * to = (Todo*) clone();
175 to->setFloats( false ); 175 to->setFloats( false );
176 to->setDtStart( mRunStart ); 176 to->setDtStart( mRunStart );
177 to->setHasStartDate( true ); 177 to->setHasStartDate( true );
178 to->setDtDue( mRunEnd ); 178 to->setDtDue( mRunEnd );
179 to->setHasDueDate( true ); 179 to->setHasDueDate( true );
180 to->setUid( file ); 180 to->setUid( file );
181 if ( !comment.isEmpty() ) { 181 if ( !comment.isEmpty() ) {
182 QString des = to->description(); 182 QString des = to->description();
183 if ( des.isEmpty () ) 183 if ( des.isEmpty () )
184 to->setDescription( "TT-Note: " + comment ); 184 to->setDescription( "TT-Note: " + comment );
185 else 185 else
186 to->setDescription( "TT-Note: " + comment +"\n" + des ); 186 to->setDescription( "TT-Note: " + comment +"\n" + des );
187 } 187 }
188 cal.addIncidence( to ); 188 cal.addIncidence( to );
189 ICalFormat format( false ); 189 ICalFormat format( false );
190 file = dir +"/" +file +".ics"; 190 file = dir +"/" +file +".ics";
191 format.save( &cal, file ); 191 format.save( &cal, file );
192 saveParents(); 192 saveParents();
193#ifndef DESKTOP_VERSION 193#ifndef DESKTOP_VERSION
194 QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable ); 194 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
195#endif 195#endif
196} 196}
197void Todo::saveParents() 197void Todo::saveParents()
198{ 198{
199 if (!relatedTo() ) 199 if (!relatedTo() )
200 return; 200 return;
201 Incidence * inc = relatedTo(); 201 Incidence * inc = relatedTo();
202 if ( inc->typeID() != todoID ) 202 if ( inc->typeID() != todoID )
203 return; 203 return;
204 Todo* to = (Todo*)inc; 204 Todo* to = (Todo*)inc;
205 bool saveTodo = false; 205 bool saveTodo = false;
206 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 206 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
207 QFileInfo fi ( file ); 207 QFileInfo fi ( file );
208 if ( fi.exists() ) { 208 if ( fi.exists() ) {
209 if ( fi.lastModified () < to->lastModified ()) 209 if ( fi.lastModified () < to->lastModified ())
210 saveTodo = true; 210 saveTodo = true;
211 } else { 211 } else {
212 saveTodo = true; 212 saveTodo = true;
213 } 213 }
214 if ( saveTodo ) { 214 if ( saveTodo ) {
215 CalendarLocal cal; 215 CalendarLocal cal;
216 cal.setLocalTime(); 216 cal.setLocalTime();
217 Todo * par = (Todo *) to->clone(); 217 Todo * par = (Todo *) to->clone();
218 cal.addIncidence( par ); 218 cal.addIncidence( par );
219 ICalFormat format( false ); 219 ICalFormat format( false );
220 format.save( &cal, file ); 220 format.save( &cal, file );
221 } 221 }
222 to->saveParents(); 222 to->saveParents();
223} 223}
224 224
225int Todo::runTime() 225int Todo::runTime()
226{ 226{
227 if ( !mRunning ) 227 if ( !mRunning )
228 return 0; 228 return 0;
229 return mRunStart.secsTo( QDateTime::currentDateTime() ); 229 return mRunStart.secsTo( QDateTime::currentDateTime() );
230} 230}
231bool Todo::hasRunningSub() 231bool Todo::hasRunningSub()
232{ 232{
233 if ( mRunning ) 233 if ( mRunning )
234 return true; 234 return true;
235 Incidence *aTodo; 235 Incidence *aTodo;
236 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 236 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
237 if ( ((Todo*)aTodo)->hasRunningSub() ) 237 if ( ((Todo*)aTodo)->hasRunningSub() )
238 return true; 238 return true;
239 } 239 }
240 return false; 240 return false;
241} 241}
242Incidence *Todo::clone() 242Incidence *Todo::clone()