summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
authorzautrix <zautrix>2005-09-28 00:42:41 (UTC)
committer zautrix <zautrix>2005-09-28 00:42:41 (UTC)
commit4fb9beb1ec26f37a18f98af9d3b6b59acf8c56d2 (patch) (unidiff)
treecbfbb81858c5ec08ba16e45b511ddbab539af864 /libkcal/todo.cpp
parente6112c5497b334d6dc38108b37963c5e803413d3 (diff)
downloadkdepimpi-4fb9beb1ec26f37a18f98af9d3b6b59acf8c56d2.zip
kdepimpi-4fb9beb1ec26f37a18f98af9d3b6b59acf8c56d2.tar.gz
kdepimpi-4fb9beb1ec26f37a18f98af9d3b6b59acf8c56d2.tar.bz2
save tt fix
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
@@ -14,275 +14,282 @@
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32#ifndef DESKTOP_VERSION 32#ifndef DESKTOP_VERSION
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#endif 34#endif
35 35
36#define SAVETIMER_TIMEOUT_SECONDS 300 36#define SAVETIMER_TIMEOUT_SECONDS 300
37//#define SAVETIMER_TIMEOUT_SECONDS 8 37//#define SAVETIMER_TIMEOUT_SECONDS 8
38#define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 38#define SAVETIMER_TIMEOUT_RETRY_SECONDS 5
39 39
40using namespace KCal; 40using namespace KCal;
41 41
42Todo::Todo(): QObject(), Incidence() 42Todo::Todo(): QObject(), Incidence()
43{ 43{
44// mStatus = TENTATIVE; 44// mStatus = TENTATIVE;
45 45
46 mHasDueDate = false; 46 mHasDueDate = false;
47 setHasStartDate( false ); 47 setHasStartDate( false );
48 mCompleted = getEvenTime(QDateTime::currentDateTime()); 48 mCompleted = getEvenTime(QDateTime::currentDateTime());
49 mHasCompletedDate = false; 49 mHasCompletedDate = false;
50 mPercentComplete = 0; 50 mPercentComplete = 0;
51 mRunning = false; 51 mRunning = false;
52 mRunSaveTimer = 0; 52 mRunSaveTimer = 0;
53 setFloats( true ); 53 setFloats( true );
54 mCurrentTimerDelay = 0; 54 mCurrentTimerDelay = 0;
55} 55}
56 56
57Todo::Todo(const Todo &t) : QObject(),Incidence(t) 57Todo::Todo(const Todo &t) : QObject(),Incidence(t)
58{ 58{
59 mDtDue = t.mDtDue; 59 mDtDue = t.mDtDue;
60 mHasDueDate = t.mHasDueDate; 60 mHasDueDate = t.mHasDueDate;
61 mCompleted = t.mCompleted; 61 mCompleted = t.mCompleted;
62 mHasCompletedDate = t.mHasCompletedDate; 62 mHasCompletedDate = t.mHasCompletedDate;
63 mPercentComplete = t.mPercentComplete; 63 mPercentComplete = t.mPercentComplete;
64 mRunning = false; 64 mRunning = false;
65 mRunSaveTimer = 0; 65 mRunSaveTimer = 0;
66 mCurrentTimerDelay = 0; 66 mCurrentTimerDelay = 0;
67} 67}
68 68
69Todo::~Todo() 69Todo::~Todo()
70{ 70{
71 setRunning( false ); 71 setRunning( false );
72 //qDebug("Todo::~Todo() "); 72 //qDebug("Todo::~Todo() ");
73} 73}
74 74
75void Todo::setRunningFalse( QString s ) 75void Todo::setRunningFalse( QString s )
76{ 76{
77 if ( ! mRunning ) 77 if ( ! mRunning )
78 return; 78 return;
79 mRunning = false; 79 mRunning = false;
80 if ( mRunSaveTimer ) 80 if ( mRunSaveTimer )
81 mRunSaveTimer->stop(); 81 mRunSaveTimer->stop();
82 saveRunningInfoToFile( s ); 82 saveRunningInfoToFile( s );
83} 83}
84void Todo::stopRunning() 84void Todo::stopRunning()
85{ 85{
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 );
134 return; 135 return;
135 } 136 }
136 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); 137 int msecs = mRunLastSave.time().msecsTo( mRunEnd.time());
137 if ( msecs < 0 ) { 138 if ( msecs < 0 ) {
138 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 139 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
139 return; 140 return;
140 } 141 }
141 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); 142 // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
142 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { 143 if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) {
143 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); 144 qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
144 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); 145 restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
145 return; 146 return;
146 } 147 }
147 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); 148 restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
148 saveRunningInfoToFile( QString::null ); 149 saveRunningInfoToFile( QString::null );
149} 150}
150void Todo::saveRunningInfoToFile() 151void Todo::saveRunningInfoToFile()
151{ 152{
152 mRunEnd = QDateTime::currentDateTime(); 153 mRunEnd = QDateTime::currentDateTime();
153 saveRunningInfoToFile( QString::null ); 154 saveRunningInfoToFile( QString::null );
154} 155}
155void Todo::saveRunningInfoToFile( QString comment ) 156void Todo::saveRunningInfoToFile( QString comment )
156{ 157{
157#ifndef DESKTOP_VERSION 158#ifndef DESKTOP_VERSION
158 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable ); 159 //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
159#endif 160#endif
160 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 161 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
161 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 162 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
162 qDebug("Running time < 15 seconds. Skipped. "); 163 qDebug("Running time < 15 seconds. Skipped. ");
163 return; 164 return;
164 } 165 }
165 QString dir = KGlobalSettings::timeTrackerDir(); 166 QString dir = KGlobalSettings::timeTrackerDir();
166 //qDebug("%s ", dir.latin1()); 167 //qDebug("%s ", dir.latin1());
167 QString file = "%1%2%3-%4%5%6-"; 168 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 ); 169 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" ); 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();
217 Todo * par = (Todo *) to->clone(); 224 Todo * par = (Todo *) to->clone();
218 cal.addIncidence( par ); 225 cal.addIncidence( par );
219 ICalFormat format( false ); 226 ICalFormat format( false );
220 format.save( &cal, file ); 227 format.save( &cal, file );
221 } 228 }
222 to->saveParents(); 229 to->saveParents();
223} 230}
224 231
225int Todo::runTime() 232int Todo::runTime()
226{ 233{
227 if ( !mRunning ) 234 if ( !mRunning )
228 return 0; 235 return 0;
229 return mRunStart.secsTo( QDateTime::currentDateTime() ); 236 return mRunStart.secsTo( QDateTime::currentDateTime() );
230} 237}
231bool Todo::hasRunningSub() 238bool Todo::hasRunningSub()
232{ 239{
233 if ( mRunning ) 240 if ( mRunning )
234 return true; 241 return true;
235 Incidence *aTodo; 242 Incidence *aTodo;
236 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 243 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
237 if ( ((Todo*)aTodo)->hasRunningSub() ) 244 if ( ((Todo*)aTodo)->hasRunningSub() )
238 return true; 245 return true;
239 } 246 }
240 return false; 247 return false;
241} 248}
242Incidence *Todo::clone() 249Incidence *Todo::clone()
243{ 250{
244 return new Todo(*this); 251 return new Todo(*this);
245} 252}
246 253
247bool Todo::contains ( Todo* from ) 254bool Todo::contains ( Todo* from )
248{ 255{
249 256
250 if ( !from->summary().isEmpty() ) 257 if ( !from->summary().isEmpty() )
251 if ( !summary().startsWith( from->summary() )) 258 if ( !summary().startsWith( from->summary() ))
252 return false; 259 return false;
253 if ( from->hasStartDate() ) { 260 if ( from->hasStartDate() ) {
254 if ( !hasStartDate() ) 261 if ( !hasStartDate() )
255 return false; 262 return false;
256 if ( from->dtStart() != dtStart()) 263 if ( from->dtStart() != dtStart())
257 return false; 264 return false;
258 } 265 }
259 if ( from->hasDueDate() ){ 266 if ( from->hasDueDate() ){
260 if ( !hasDueDate() ) 267 if ( !hasDueDate() )
261 return false; 268 return false;
262 if ( from->dtDue() != dtDue()) 269 if ( from->dtDue() != dtDue())
263 return false; 270 return false;
264 } 271 }
265 if ( !from->location().isEmpty() ) 272 if ( !from->location().isEmpty() )
266 if ( !location().startsWith( from->location() ) ) 273 if ( !location().startsWith( from->location() ) )
267 return false; 274 return false;
268 if ( !from->description().isEmpty() ) 275 if ( !from->description().isEmpty() )
269 if ( !description().startsWith( from->description() )) 276 if ( !description().startsWith( from->description() ))
270 return false; 277 return false;
271 if ( from->alarms().count() ) { 278 if ( from->alarms().count() ) {
272 Alarm *a = from->alarms().first(); 279 Alarm *a = from->alarms().first();
273 if ( a->enabled() ){ 280 if ( a->enabled() ){
274 if ( !alarms().count() ) 281 if ( !alarms().count() )
275 return false; 282 return false;
276 Alarm *b = alarms().first(); 283 Alarm *b = alarms().first();
277 if( ! b->enabled() ) 284 if( ! b->enabled() )
278 return false; 285 return false;
279 if ( ! (a->offset() == b->offset() )) 286 if ( ! (a->offset() == b->offset() ))
280 return false; 287 return false;
281 } 288 }
282 } 289 }
283 290
284 QStringList cat = categories(); 291 QStringList cat = categories();
285 QStringList catFrom = from->categories(); 292 QStringList catFrom = from->categories();
286 QString nCat; 293 QString nCat;
287 unsigned int iii; 294 unsigned int iii;
288 for ( iii = 0; iii < catFrom.count();++iii ) { 295 for ( iii = 0; iii < catFrom.count();++iii ) {