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
@@ -1,674 +1,681 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
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 ) {
289 nCat = catFrom[iii]; 296 nCat = catFrom[iii];
290 if ( !nCat.isEmpty() ) 297 if ( !nCat.isEmpty() )
291 if ( !cat.contains( nCat )) { 298 if ( !cat.contains( nCat )) {
292 return false; 299 return false;
293 } 300 }
294 } 301 }
295 if ( from->isCompleted() ) { 302 if ( from->isCompleted() ) {
296 if ( !isCompleted() ) 303 if ( !isCompleted() )
297 return false; 304 return false;
298 } 305 }
299 if( priority() != from->priority() ) 306 if( priority() != from->priority() )
300 return false; 307 return false;
301 308
302 309
303 return true; 310 return true;
304 311
305} 312}
306bool KCal::operator==( const Todo& t1, const Todo& t2 ) 313bool KCal::operator==( const Todo& t1, const Todo& t2 )
307{ 314{
308 315
309 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 316 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
310 if ( ! ret ) 317 if ( ! ret )
311 return false; 318 return false;
312 if ( t1.hasDueDate() == t2.hasDueDate() ) { 319 if ( t1.hasDueDate() == t2.hasDueDate() ) {
313 if ( t1.hasDueDate() ) { 320 if ( t1.hasDueDate() ) {
314 if ( t1.doesFloat() == t2.doesFloat() ) { 321 if ( t1.doesFloat() == t2.doesFloat() ) {
315 if ( t1.doesFloat() ) { 322 if ( t1.doesFloat() ) {
316 if ( t1.dtDue().date() != t2.dtDue().date() ) 323 if ( t1.dtDue().date() != t2.dtDue().date() )
317 return false; 324 return false;
318 } else 325 } else
319 if ( t1.dtDue() != t2.dtDue() ) 326 if ( t1.dtDue() != t2.dtDue() )
320 return false; 327 return false;
321 } else 328 } else
322 return false;// float != 329 return false;// float !=
323 } 330 }
324 331
325 } else 332 } else
326 return false; 333 return false;
327 if ( t1.percentComplete() != t2.percentComplete() ) 334 if ( t1.percentComplete() != t2.percentComplete() )
328 return false; 335 return false;
329 if ( t1.isCompleted() ) { 336 if ( t1.isCompleted() ) {
330 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 337 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
331 if ( t1.hasCompletedDate() ) { 338 if ( t1.hasCompletedDate() ) {
332 if ( t1.completed() != t2.completed() ) 339 if ( t1.completed() != t2.completed() )
333 return false; 340 return false;
334 } 341 }
335 342
336 } else 343 } else
337 return false; 344 return false;
338 } 345 }
339 return true; 346 return true;
340 347
341} 348}
342 349
343void Todo::setDtDue(const QDateTime &dtDue) 350void Todo::setDtDue(const QDateTime &dtDue)
344{ 351{
345 //int diffsecs = mDtDue.secsTo(dtDue); 352 //int diffsecs = mDtDue.secsTo(dtDue);
346 353
347 /*if (mReadOnly) return; 354 /*if (mReadOnly) return;
348 const QPtrList<Alarm>& alarms = alarms(); 355 const QPtrList<Alarm>& alarms = alarms();
349 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 356 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
350 if (alarm->enabled()) { 357 if (alarm->enabled()) {
351 alarm->setTime(alarm->time().addSecs(diffsecs)); 358 alarm->setTime(alarm->time().addSecs(diffsecs));
352 } 359 }
353 }*/ 360 }*/
354 mDtDue = getEvenTime(dtDue); 361 mDtDue = getEvenTime(dtDue);
355 362
356 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 363 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
357 364
358 /*const QPtrList<Alarm>& alarms = alarms(); 365 /*const QPtrList<Alarm>& alarms = alarms();
359 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 366 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
360 alarm->setAlarmStart(mDtDue);*/ 367 alarm->setAlarmStart(mDtDue);*/
361 updated(); 368 updated();
362} 369}
363 370
364QDateTime Todo::dtDue() const 371QDateTime Todo::dtDue() const
365{ 372{
366 return mDtDue; 373 return mDtDue;
367} 374}
368 375
369QString Todo::dtDueTimeStr() const 376QString Todo::dtDueTimeStr() const
370{ 377{
371 return KGlobal::locale()->formatTime(mDtDue.time()); 378 return KGlobal::locale()->formatTime(mDtDue.time());
372} 379}
373 380
374QString Todo::dtDueDateStr(bool shortfmt) const 381QString Todo::dtDueDateStr(bool shortfmt) const
375{ 382{
376 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 383 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
377} 384}
378 385
379QString Todo::dtDueStr(bool shortfmt) const 386QString Todo::dtDueStr(bool shortfmt) const
380{ 387{
381 if ( doesFloat() ) 388 if ( doesFloat() )
382 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 389 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
383 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 390 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
384} 391}
385// retval 0 : no found 392// retval 0 : no found
386// 1 : due for date found 393// 1 : due for date found
387// 2 : overdue for date found 394// 2 : overdue for date found
388int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 395int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
389{ 396{
390 int retval = 0; 397 int retval = 0;
391 if ( isCompleted() ) 398 if ( isCompleted() )
392 return 0; 399 return 0;
393 if ( hasDueDate() ) { 400 if ( hasDueDate() ) {
394 if ( dtDue().date() < date ) 401 if ( dtDue().date() < date )
395 return 2; 402 return 2;
396 // we do not return, because we may find an overdue sub todo 403 // we do not return, because we may find an overdue sub todo
397 if ( dtDue().date() == date ) 404 if ( dtDue().date() == date )
398 retval = 1; 405 retval = 1;
399 } 406 }
400 if ( checkSubtodos ) { 407 if ( checkSubtodos ) {
401 Incidence *aTodo; 408 Incidence *aTodo;
402 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 409 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
403 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 410 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
404 if ( ret == 2 ) 411 if ( ret == 2 )
405 return 2; 412 return 2;
406 if ( ret == 1) 413 if ( ret == 1)
407 retval = 1; 414 retval = 1;
408 } 415 }
409 } 416 }
410 return retval; 417 return retval;
411} 418}
412int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 419int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
413{ 420{
414 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 421 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
415} 422}
416bool Todo::hasDueDate() const 423bool Todo::hasDueDate() const
417{ 424{
418 return mHasDueDate; 425 return mHasDueDate;
419} 426}
420 427
421void Todo::setHasDueDate(bool f) 428void Todo::setHasDueDate(bool f)
422{ 429{
423 if (mReadOnly) return; 430 if (mReadOnly) return;
424 mHasDueDate = f; 431 mHasDueDate = f;
425 updated(); 432 updated();
426} 433}
427 434
428 435
429#if 0 436#if 0
430void Todo::setStatus(const QString &statStr) 437void Todo::setStatus(const QString &statStr)
431{ 438{
432 if (mReadOnly) return; 439 if (mReadOnly) return;
433 QString ss(statStr.upper()); 440 QString ss(statStr.upper());
434 441
435 if (ss == "X-ACTION") 442 if (ss == "X-ACTION")
436 mStatus = NEEDS_ACTION; 443 mStatus = NEEDS_ACTION;
437 else if (ss == "NEEDS ACTION") 444 else if (ss == "NEEDS ACTION")
438 mStatus = NEEDS_ACTION; 445 mStatus = NEEDS_ACTION;
439 else if (ss == "ACCEPTED") 446 else if (ss == "ACCEPTED")
440 mStatus = ACCEPTED; 447 mStatus = ACCEPTED;
441 else if (ss == "SENT") 448 else if (ss == "SENT")
442 mStatus = SENT; 449 mStatus = SENT;
443 else if (ss == "TENTATIVE") 450 else if (ss == "TENTATIVE")
444 mStatus = TENTATIVE; 451 mStatus = TENTATIVE;
445 else if (ss == "CONFIRMED") 452 else if (ss == "CONFIRMED")
446 mStatus = CONFIRMED; 453 mStatus = CONFIRMED;
447 else if (ss == "DECLINED") 454 else if (ss == "DECLINED")
448 mStatus = DECLINED; 455 mStatus = DECLINED;
449 else if (ss == "COMPLETED") 456 else if (ss == "COMPLETED")
450 mStatus = COMPLETED; 457 mStatus = COMPLETED;
451 else if (ss == "DELEGATED") 458 else if (ss == "DELEGATED")
452 mStatus = DELEGATED; 459 mStatus = DELEGATED;
453 460
454 updated(); 461 updated();
455} 462}
456 463
457void Todo::setStatus(int status) 464void Todo::setStatus(int status)
458{ 465{
459 if (mReadOnly) return; 466 if (mReadOnly) return;
460 mStatus = status; 467 mStatus = status;
461 updated(); 468 updated();
462} 469}
463 470
464int Todo::status() const 471int Todo::status() const
465{ 472{
466 return mStatus; 473 return mStatus;
467} 474}
468 475
469QString Todo::statusStr() const 476QString Todo::statusStr() const
470{ 477{
471 switch(mStatus) { 478 switch(mStatus) {
472 case NEEDS_ACTION: 479 case NEEDS_ACTION:
473 return QString("NEEDS ACTION"); 480 return QString("NEEDS ACTION");
474 break; 481 break;
475 case ACCEPTED: 482 case ACCEPTED:
476 return QString("ACCEPTED"); 483 return QString("ACCEPTED");
477 break; 484 break;
478 case SENT: 485 case SENT:
479 return QString("SENT"); 486 return QString("SENT");
480 break; 487 break;
481 case TENTATIVE: 488 case TENTATIVE:
482 return QString("TENTATIVE"); 489 return QString("TENTATIVE");
483 break; 490 break;
484 case CONFIRMED: 491 case CONFIRMED:
485 return QString("CONFIRMED"); 492 return QString("CONFIRMED");
486 break; 493 break;
487 case DECLINED: 494 case DECLINED:
488 return QString("DECLINED"); 495 return QString("DECLINED");
489 break; 496 break;
490 case COMPLETED: 497 case COMPLETED:
491 return QString("COMPLETED"); 498 return QString("COMPLETED");
492 break; 499 break;
493 case DELEGATED: 500 case DELEGATED:
494 return QString("DELEGATED"); 501 return QString("DELEGATED");
495 break; 502 break;
496 } 503 }
497 return QString(""); 504 return QString("");
498} 505}
499#endif 506#endif
500 507
501bool Todo::isCompleted() const 508bool Todo::isCompleted() const
502{ 509{
503 if (mPercentComplete == 100) { 510 if (mPercentComplete == 100) {
504 return true; 511 return true;
505 } 512 }
506 else return false; 513 else return false;
507} 514}
508 515
509void Todo::setCompleted(bool completed) 516void Todo::setCompleted(bool completed)
510{ 517{
511 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 518 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
512 if ( !setRecurDates() ) 519 if ( !setRecurDates() )
513 completed = false; 520 completed = false;
514 } 521 }
515 if (completed) mPercentComplete = 100; 522 if (completed) mPercentComplete = 100;
516 else { 523 else {
517 mPercentComplete = 0; 524 mPercentComplete = 0;
518 mHasCompletedDate = false; 525 mHasCompletedDate = false;
519 } 526 }
520 updated(); 527 updated();
521} 528}
522 529
523QDateTime Todo::completed() const 530QDateTime Todo::completed() const
524{ 531{
525 return mCompleted; 532 return mCompleted;
526} 533}
527 534
528QString Todo::completedStr( bool shortF ) const 535QString Todo::completedStr( bool shortF ) const
529{ 536{
530 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 537 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
531} 538}
532 539
533void Todo::setCompleted(const QDateTime &completed) 540void Todo::setCompleted(const QDateTime &completed)
534{ 541{
535 //qDebug("Todo::setCompleted "); 542 //qDebug("Todo::setCompleted ");
536 if ( mHasCompletedDate ) { 543 if ( mHasCompletedDate ) {
537 // qDebug("has completed data - return "); 544 // qDebug("has completed data - return ");
538 return; 545 return;
539 } 546 }
540 mHasCompletedDate = true; 547 mHasCompletedDate = true;
541 mPercentComplete = 100; 548 mPercentComplete = 100;
542 mCompleted = getEvenTime(completed); 549 mCompleted = getEvenTime(completed);
543 updated(); 550 updated();
544} 551}
545 552
546bool Todo::hasCompletedDate() const 553bool Todo::hasCompletedDate() const
547{ 554{
548 return mHasCompletedDate; 555 return mHasCompletedDate;
549} 556}
550 557
551int Todo::percentComplete() const 558int Todo::percentComplete() const
552{ 559{
553 return mPercentComplete; 560 return mPercentComplete;
554} 561}
555bool Todo::setRecurDates() 562bool Todo::setRecurDates()
556{ 563{
557 if ( !mHasRecurrenceID ) 564 if ( !mHasRecurrenceID )
558 return true; 565 return true;
559 int secs = mDtStart.secsTo( dtDue() ); 566 int secs = mDtStart.secsTo( dtDue() );
560 bool ok; 567 bool ok;
561 qDebug("T:setRecurDates() "); 568 qDebug("T:setRecurDates() ");
562 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 569 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
563 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 570 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
564 if ( ok ) { 571 if ( ok ) {
565 mRecurrenceID = next; 572 mRecurrenceID = next;
566 mDtStart = next; 573 mDtStart = next;
567 setDtDue( next.addSecs( secs ) ); 574 setDtDue( next.addSecs( secs ) );
568 if ( QDateTime::currentDateTime() > next) 575 if ( QDateTime::currentDateTime() > next)
569 return false; 576 return false;
570 } else { 577 } else {
571 setHasRecurrenceID( false ); 578 setHasRecurrenceID( false );
572 recurrence()->unsetRecurs(); 579 recurrence()->unsetRecurs();
573 } 580 }
574 return true; 581 return true;
575} 582}
576void Todo::setPercentComplete(int v) 583void Todo::setPercentComplete(int v)
577{ 584{
578 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 585 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
579 if ( !setRecurDates() ) 586 if ( !setRecurDates() )
580 v = 0; 587 v = 0;
581 } 588 }
582 mPercentComplete = v; 589 mPercentComplete = v;
583 if ( v != 100 ) 590 if ( v != 100 )
584 mHasCompletedDate = false; 591 mHasCompletedDate = false;
585 updated(); 592 updated();
586} 593}
587QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 594QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
588{ 595{
589 *ok = false; 596 *ok = false;
590 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { 597 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) {
591 return QDateTime (); 598 return QDateTime ();
592 } 599 }
593 // if the recurring todo is set to complete and requested time < start time of todo 600 // if the recurring todo is set to complete and requested time < start time of todo
594 // we want to get the alarm. 601 // we want to get the alarm.
595 bool iscompleted = isCompleted(); 602 bool iscompleted = isCompleted();
596 if ( iscompleted && doesRecur() ) { 603 if ( iscompleted && doesRecur() ) {
597 Todo * to = (Todo*) this; 604 Todo * to = (Todo*) this;
598 to->checkSetCompletedFalse(); 605 to->checkSetCompletedFalse();
599 iscompleted = isCompleted(); 606 iscompleted = isCompleted();
600 if ( hasStartDate() && start_dt < dtStart() ){ 607 if ( hasStartDate() && start_dt < dtStart() ){
601 iscompleted = false; 608 iscompleted = false;
602 } 609 }
603 } 610 }
604 if ( iscompleted ) { 611 if ( iscompleted ) {
605 return QDateTime (); 612 return QDateTime ();
606 } 613 }
607 QDateTime incidenceStart; 614 QDateTime incidenceStart;
608 incidenceStart = dtDue(); 615 incidenceStart = dtDue();
609 bool enabled = false; 616 bool enabled = false;
610 Alarm* alarm; 617 Alarm* alarm;
611 int off = 0; 618 int off = 0;
612 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 619 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
613 // if ( QDateTime::currentDateTime() > incidenceStart ){ 620 // if ( QDateTime::currentDateTime() > incidenceStart ){
614// *ok = false; 621// *ok = false;
615// return incidenceStart; 622// return incidenceStart;
616// } 623// }
617 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 624 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
618 if (alarm->enabled()) { 625 if (alarm->enabled()) {
619 if ( alarm->hasTime () ) { 626 if ( alarm->hasTime () ) {
620 if ( alarm->time() < alarmStart ) { 627 if ( alarm->time() < alarmStart ) {
621 alarmStart = alarm->time(); 628 alarmStart = alarm->time();
622 enabled = true; 629 enabled = true;
623 off = alarmStart.secsTo( incidenceStart ); 630 off = alarmStart.secsTo( incidenceStart );
624 } 631 }
625 632
626 } else { 633 } else {
627 int secs = alarm->startOffset().asSeconds(); 634 int secs = alarm->startOffset().asSeconds();
628 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 635 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
629 alarmStart = incidenceStart.addSecs( secs ); 636 alarmStart = incidenceStart.addSecs( secs );
630 enabled = true; 637 enabled = true;
631 off = -secs; 638 off = -secs;
632 } 639 }
633 } 640 }
634 } 641 }
635 } 642 }
636 if ( enabled ) { 643 if ( enabled ) {
637 if ( alarmStart > start_dt ) { 644 if ( alarmStart > start_dt ) {
638 *ok = true; 645 *ok = true;
639 * offset = off; 646 * offset = off;
640 return alarmStart; 647 return alarmStart;
641 } 648 }
642 } 649 }
643 *ok = false; 650 *ok = false;
644 return QDateTime (); 651 return QDateTime ();
645 652
646} 653}
647 654
648void Todo::checkSetCompletedFalse() 655void Todo::checkSetCompletedFalse()
649{ 656{
650 if ( !mHasRecurrenceID ) { 657 if ( !mHasRecurrenceID ) {
651 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 658 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
652 return; 659 return;
653 } 660 }
654 // qDebug("Todo::checkSetCompletedFalse()"); 661 // qDebug("Todo::checkSetCompletedFalse()");
655 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 662 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
656 if ( mPercentComplete == 100 ) { 663 if ( mPercentComplete == 100 ) {
657 QDateTime dt = QDateTime::currentDateTime(); 664 QDateTime dt = QDateTime::currentDateTime();
658 if ( dt > mDtStart && dt > mRecurrenceID ) { 665 if ( dt > mDtStart && dt > mRecurrenceID ) {
659 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 666 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
660 setCompleted( false ); 667 setCompleted( false );
661 qDebug("Todo::checkSetCompletedFalse "); 668 qDebug("Todo::checkSetCompletedFalse ");
662 } 669 }
663 } 670 }
664} 671}
665QString Todo::durationText() 672QString Todo::durationText()
666{ 673{
667 if ( mHasDueDate && hasStartDate() ) { 674 if ( mHasDueDate && hasStartDate() ) {
668 int sec = dtStart().secsTo( dtDue() ); 675 int sec = dtStart().secsTo( dtDue() );
669 if ( doesFloat() ) 676 if ( doesFloat() )
670 sec += 86400; 677 sec += 86400;
671 return durationText4Time( sec ); 678 return durationText4Time( sec );
672 } 679 }
673 return "---"; 680 return "---";
674} 681}