summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 29f725f..2201814 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -86,48 +86,49 @@ void Todo::stopRunning()
86 if ( !mRunning ) 86 if ( !mRunning )
87 return; 87 return;
88 if ( mRunSaveTimer ) 88 if ( mRunSaveTimer )
89 mRunSaveTimer->stop(); 89 mRunSaveTimer->stop();
90 mRunning = false; 90 mRunning = false;
91} 91}
92void Todo::setRunning( bool run ) 92void Todo::setRunning( bool run )
93{ 93{
94 if ( run == mRunning ) 94 if ( run == mRunning )
95 return; 95 return;
96 //qDebug("Todo::setRunning %d ", run); 96 //qDebug("Todo::setRunning %d ", run);
97 if ( !mRunSaveTimer ) { 97 if ( !mRunSaveTimer ) {
98 mRunSaveTimer = new QTimer ( this ); 98 mRunSaveTimer = new QTimer ( this );
99 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); 99 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) );
100 } 100 }
101 mRunning = run; 101 mRunning = run;
102 mRunLastSave = QDateTime::currentDateTime(); 102 mRunLastSave = QDateTime::currentDateTime();
103 if ( mRunning ) { 103 if ( mRunning ) {
104 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); 104 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
105 mRunStart = QDateTime::currentDateTime(); 105 mRunStart = QDateTime::currentDateTime();
106 } else { 106 } else {
107 mRunSaveTimer->stop(); 107 mRunSaveTimer->stop();
108 saveRunningInfoToFile(); 108 saveRunningInfoToFile();
109 } 109 }
110 mLastSavedFileName = "";
110} 111}
111void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 112void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
112{ 113{
113 if ( !mRunning) return; 114 if ( !mRunning) return;
114 mRunning = false; 115 mRunning = false;
115 mRunStart = start; 116 mRunStart = start;
116 mRunEnd = end; 117 mRunEnd = end;
117 saveRunningInfoToFile( comment ); 118 saveRunningInfoToFile( comment );
118} 119}
119void Todo::restartSaveTimer( int secs ) 120void Todo::restartSaveTimer( int secs )
120{ 121{
121 mRunSaveTimer->start( secs * 1000 ); 122 mRunSaveTimer->start( secs * 1000 );
122 mRunLastSave = QDateTime::currentDateTime(); 123 mRunLastSave = QDateTime::currentDateTime();
123 mCurrentTimerDelay = secs; 124 mCurrentTimerDelay = secs;
124} 125}
125void Todo::timerSlotSaveRunningInfoToFile() 126void Todo::timerSlotSaveRunningInfoToFile()
126{ 127{
127 mRunEnd = QDateTime::currentDateTime(); 128 mRunEnd = QDateTime::currentDateTime();
128 int secsTo = mRunLastSave.secsTo( mRunEnd ); 129 int secsTo = mRunLastSave.secsTo( mRunEnd );
129 //if( secsTo == 8 ) ++secsTo; 130 //if( secsTo == 8 ) ++secsTo;
130 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); 131 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay );
131 if ( secsTo > mCurrentTimerDelay ) { 132 if ( secsTo > mCurrentTimerDelay ) {
132 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); 133 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS );
133 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 134 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
@@ -169,48 +170,54 @@ void Todo::saveRunningInfoToFile( QString comment )
169 file.replace ( QRegExp (" "), "0" ); 170 file.replace ( QRegExp (" "), "0" );
170 file += uid(); 171 file += uid();
171 //qDebug("File %s ",file.latin1() ); 172 //qDebug("File %s ",file.latin1() );
172 CalendarLocal cal; 173 CalendarLocal cal;
173 cal.setLocalTime(); 174 cal.setLocalTime();
174 Todo * to = (Todo*) clone(); 175 Todo * to = (Todo*) clone();
175 to->setFloats( false ); 176 to->setFloats( false );
176 to->setDtStart( mRunStart ); 177 to->setDtStart( mRunStart );
177 to->setHasStartDate( true ); 178 to->setHasStartDate( true );
178 to->setDtDue( mRunEnd ); 179 to->setDtDue( mRunEnd );
179 to->setHasDueDate( true ); 180 to->setHasDueDate( true );
180 to->setUid( file ); 181 to->setUid( file );
181 if ( !comment.isEmpty() ) { 182 if ( !comment.isEmpty() ) {
182 QString des = to->description(); 183 QString des = to->description();
183 if ( des.isEmpty () ) 184 if ( des.isEmpty () )
184 to->setDescription( "TT-Note: " + comment ); 185 to->setDescription( "TT-Note: " + comment );
185 else 186 else
186 to->setDescription( "TT-Note: " + comment +"\n" + des ); 187 to->setDescription( "TT-Note: " + comment +"\n" + des );
187 } 188 }
188 cal.addIncidence( to ); 189 cal.addIncidence( to );
189 ICalFormat format( false ); 190 ICalFormat format( false );
190 file = dir +"/" +file +".ics"; 191 file = dir +"/" +file +".ics";
191 format.save( &cal, file ); 192 format.save( &cal, file );
192 saveParents(); 193 saveParents();
194 if ( !mLastSavedFileName.isEmpty() ) {
195 if ( mLastSavedFileName != file ) {
196 QFile::remove( mLastSavedFileName );
197 }
198 }
199 mLastSavedFileName = file;
193#ifndef DESKTOP_VERSION 200#ifndef DESKTOP_VERSION
194 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable ); 201 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
195#endif 202#endif
196} 203}
197void Todo::saveParents() 204void Todo::saveParents()
198{ 205{
199 if (!relatedTo() ) 206 if (!relatedTo() )
200 return; 207 return;
201 Incidence * inc = relatedTo(); 208 Incidence * inc = relatedTo();
202 if ( inc->typeID() != todoID ) 209 if ( inc->typeID() != todoID )
203 return; 210 return;
204 Todo* to = (Todo*)inc; 211 Todo* to = (Todo*)inc;
205 bool saveTodo = false; 212 bool saveTodo = false;
206 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 213 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
207 QFileInfo fi ( file ); 214 QFileInfo fi ( file );
208 if ( fi.exists() ) { 215 if ( fi.exists() ) {
209 if ( fi.lastModified () < to->lastModified ()) 216 if ( fi.lastModified () < to->lastModified ())
210 saveTodo = true; 217 saveTodo = true;
211 } else { 218 } else {
212 saveTodo = true; 219 saveTodo = true;
213 } 220 }
214 if ( saveTodo ) { 221 if ( saveTodo ) {
215 CalendarLocal cal; 222 CalendarLocal cal;
216 cal.setLocalTime(); 223 cal.setLocalTime();