summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index f7e38a7..d7431c7 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,573 +1,577 @@
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
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::Todo(): QObject(), Incidence()
35{ 35{
36// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
37 37
38 mHasDueDate = false; 38 mHasDueDate = false;
39 setHasStartDate( false ); 39 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 41 mHasCompletedDate = false;
42 mPercentComplete = 0; 42 mPercentComplete = 0;
43 mRunning = false; 43 mRunning = false;
44 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
45} 45}
46 46
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
48{ 48{
49 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
50 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
51 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
52 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
53 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
54 mRunning = false; 54 mRunning = false;
55 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
56} 56}
57 57
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 mRunSaveTimer->stop(); 69 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 70 saveRunningInfoToFile( s );
71} 71}
72void Todo::setRunning( bool run ) 72void Todo::setRunning( bool run )
73{ 73{
74 if ( run == mRunning ) 74 if ( run == mRunning )
75 return; 75 return;
76 //qDebug("Todo::setRunning %d ", run); 76 //qDebug("Todo::setRunning %d ", run);
77 if ( !mRunSaveTimer ) { 77 if ( !mRunSaveTimer ) {
78 mRunSaveTimer = new QTimer ( this ); 78 mRunSaveTimer = new QTimer ( this );
79 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 79 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
80 } 80 }
81 mRunning = run; 81 mRunning = run;
82 if ( mRunning ) { 82 if ( mRunning ) {
83 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 83 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
84 mRunStart = QDateTime::currentDateTime(); 84 mRunStart = QDateTime::currentDateTime();
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 to->setDescription( comment ); 115 QString des = to->description();
116 if ( des.isEmpty () )
117 to->setDescription( "TT-Note: " + comment );
118 else
119 to->setDescription( "TT-Note: " + comment +"\n" + des );
116 } 120 }
117 cal.addIncidence( to ); 121 cal.addIncidence( to );
118 ICalFormat format; 122 ICalFormat format;
119 file = dir +"/" +file +".ics"; 123 file = dir +"/" +file +".ics";
120 format.save( &cal, file ); 124 format.save( &cal, file );
121 saveParents(); 125 saveParents();
122 126
123} 127}
124void Todo::saveParents() 128void Todo::saveParents()
125{ 129{
126 if (!relatedTo() ) 130 if (!relatedTo() )
127 return; 131 return;
128 Incidence * inc = relatedTo(); 132 Incidence * inc = relatedTo();
129 if ( inc->type() != "Todo" ) 133 if ( inc->type() != "Todo" )
130 return; 134 return;
131 Todo* to = (Todo*)inc; 135 Todo* to = (Todo*)inc;
132 bool saveTodo = false; 136 bool saveTodo = false;
133 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 137 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
134 QFileInfo fi ( file ); 138 QFileInfo fi ( file );
135 if ( fi.exists() ) { 139 if ( fi.exists() ) {
136 if ( fi.lastModified () < to->lastModified ()) 140 if ( fi.lastModified () < to->lastModified ())
137 saveTodo = true; 141 saveTodo = true;
138 } else { 142 } else {
139 saveTodo = true; 143 saveTodo = true;
140 } 144 }
141 if ( saveTodo ) { 145 if ( saveTodo ) {
142 CalendarLocal cal; 146 CalendarLocal cal;
143 cal.setLocalTime(); 147 cal.setLocalTime();
144 Todo * par = (Todo *) to->clone(); 148 Todo * par = (Todo *) to->clone();
145 cal.addIncidence( par ); 149 cal.addIncidence( par );
146 ICalFormat format; 150 ICalFormat format;
147 format.save( &cal, file ); 151 format.save( &cal, file );
148 } 152 }
149 to->saveParents(); 153 to->saveParents();
150} 154}
151 155
152int Todo::runTime() 156int Todo::runTime()
153{ 157{
154 if ( !mRunning ) 158 if ( !mRunning )
155 return 0; 159 return 0;
156 return mRunStart.secsTo( QDateTime::currentDateTime() ); 160 return mRunStart.secsTo( QDateTime::currentDateTime() );
157} 161}
158bool Todo::hasRunningSub() 162bool Todo::hasRunningSub()
159{ 163{
160 if ( mRunning ) 164 if ( mRunning )
161 return true; 165 return true;
162 Incidence *aTodo; 166 Incidence *aTodo;
163 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 167 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
164 if ( ((Todo*)aTodo)->hasRunningSub() ) 168 if ( ((Todo*)aTodo)->hasRunningSub() )
165 return true; 169 return true;
166 } 170 }
167 return false; 171 return false;
168} 172}
169Incidence *Todo::clone() 173Incidence *Todo::clone()
170{ 174{
171 return new Todo(*this); 175 return new Todo(*this);
172} 176}
173 177
174bool Todo::contains ( Todo* from ) 178bool Todo::contains ( Todo* from )
175{ 179{
176 180
177 if ( !from->summary().isEmpty() ) 181 if ( !from->summary().isEmpty() )
178 if ( !summary().startsWith( from->summary() )) 182 if ( !summary().startsWith( from->summary() ))
179 return false; 183 return false;
180 if ( from->hasStartDate() ) { 184 if ( from->hasStartDate() ) {
181 if ( !hasStartDate() ) 185 if ( !hasStartDate() )
182 return false; 186 return false;
183 if ( from->dtStart() != dtStart()) 187 if ( from->dtStart() != dtStart())
184 return false; 188 return false;
185 } 189 }
186 if ( from->hasDueDate() ){ 190 if ( from->hasDueDate() ){
187 if ( !hasDueDate() ) 191 if ( !hasDueDate() )
188 return false; 192 return false;
189 if ( from->dtDue() != dtDue()) 193 if ( from->dtDue() != dtDue())
190 return false; 194 return false;
191 } 195 }
192 if ( !from->location().isEmpty() ) 196 if ( !from->location().isEmpty() )
193 if ( !location().startsWith( from->location() ) ) 197 if ( !location().startsWith( from->location() ) )
194 return false; 198 return false;
195 if ( !from->description().isEmpty() ) 199 if ( !from->description().isEmpty() )
196 if ( !description().startsWith( from->description() )) 200 if ( !description().startsWith( from->description() ))
197 return false; 201 return false;
198 if ( from->alarms().count() ) { 202 if ( from->alarms().count() ) {
199 Alarm *a = from->alarms().first(); 203 Alarm *a = from->alarms().first();
200 if ( a->enabled() ){ 204 if ( a->enabled() ){
201 if ( !alarms().count() ) 205 if ( !alarms().count() )
202 return false; 206 return false;
203 Alarm *b = alarms().first(); 207 Alarm *b = alarms().first();
204 if( ! b->enabled() ) 208 if( ! b->enabled() )
205 return false; 209 return false;
206 if ( ! (a->offset() == b->offset() )) 210 if ( ! (a->offset() == b->offset() ))
207 return false; 211 return false;
208 } 212 }
209 } 213 }
210 214
211 QStringList cat = categories(); 215 QStringList cat = categories();
212 QStringList catFrom = from->categories(); 216 QStringList catFrom = from->categories();
213 QString nCat; 217 QString nCat;
214 unsigned int iii; 218 unsigned int iii;
215 for ( iii = 0; iii < catFrom.count();++iii ) { 219 for ( iii = 0; iii < catFrom.count();++iii ) {
216 nCat = catFrom[iii]; 220 nCat = catFrom[iii];
217 if ( !nCat.isEmpty() ) 221 if ( !nCat.isEmpty() )
218 if ( !cat.contains( nCat )) { 222 if ( !cat.contains( nCat )) {
219 return false; 223 return false;
220 } 224 }
221 } 225 }
222 if ( from->isCompleted() ) { 226 if ( from->isCompleted() ) {
223 if ( !isCompleted() ) 227 if ( !isCompleted() )
224 return false; 228 return false;
225 } 229 }
226 if( priority() != from->priority() ) 230 if( priority() != from->priority() )
227 return false; 231 return false;
228 232
229 233
230 return true; 234 return true;
231 235
232} 236}
233bool KCal::operator==( const Todo& t1, const Todo& t2 ) 237bool KCal::operator==( const Todo& t1, const Todo& t2 )
234{ 238{
235 239
236 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 240 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
237 if ( ! ret ) 241 if ( ! ret )
238 return false; 242 return false;
239 if ( t1.hasDueDate() == t2.hasDueDate() ) { 243 if ( t1.hasDueDate() == t2.hasDueDate() ) {
240 if ( t1.hasDueDate() ) { 244 if ( t1.hasDueDate() ) {
241 if ( t1.doesFloat() == t2.doesFloat() ) { 245 if ( t1.doesFloat() == t2.doesFloat() ) {
242 if ( t1.doesFloat() ) { 246 if ( t1.doesFloat() ) {
243 if ( t1.dtDue().date() != t2.dtDue().date() ) 247 if ( t1.dtDue().date() != t2.dtDue().date() )
244 return false; 248 return false;
245 } else 249 } else
246 if ( t1.dtDue() != t2.dtDue() ) 250 if ( t1.dtDue() != t2.dtDue() )
247 return false; 251 return false;
248 } else 252 } else
249 return false;// float != 253 return false;// float !=
250 } 254 }
251 255
252 } else 256 } else
253 return false; 257 return false;
254 if ( t1.percentComplete() != t2.percentComplete() ) 258 if ( t1.percentComplete() != t2.percentComplete() )
255 return false; 259 return false;
256 if ( t1.isCompleted() ) { 260 if ( t1.isCompleted() ) {
257 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 261 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
258 if ( t1.hasCompletedDate() ) { 262 if ( t1.hasCompletedDate() ) {
259 if ( t1.completed() != t2.completed() ) 263 if ( t1.completed() != t2.completed() )
260 return false; 264 return false;
261 } 265 }
262 266
263 } else 267 } else
264 return false; 268 return false;
265 } 269 }
266 return true; 270 return true;
267 271
268} 272}
269 273
270void Todo::setDtDue(const QDateTime &dtDue) 274void Todo::setDtDue(const QDateTime &dtDue)
271{ 275{
272 //int diffsecs = mDtDue.secsTo(dtDue); 276 //int diffsecs = mDtDue.secsTo(dtDue);
273 277
274 /*if (mReadOnly) return; 278 /*if (mReadOnly) return;
275 const QPtrList<Alarm>& alarms = alarms(); 279 const QPtrList<Alarm>& alarms = alarms();
276 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 280 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
277 if (alarm->enabled()) { 281 if (alarm->enabled()) {
278 alarm->setTime(alarm->time().addSecs(diffsecs)); 282 alarm->setTime(alarm->time().addSecs(diffsecs));
279 } 283 }
280 }*/ 284 }*/
281 mDtDue = getEvenTime(dtDue); 285 mDtDue = getEvenTime(dtDue);
282 286
283 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 287 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
284 288
285 /*const QPtrList<Alarm>& alarms = alarms(); 289 /*const QPtrList<Alarm>& alarms = alarms();
286 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 290 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
287 alarm->setAlarmStart(mDtDue);*/ 291 alarm->setAlarmStart(mDtDue);*/
288 updated(); 292 updated();
289} 293}
290 294
291QDateTime Todo::dtDue() const 295QDateTime Todo::dtDue() const
292{ 296{
293 return mDtDue; 297 return mDtDue;
294} 298}
295 299
296QString Todo::dtDueTimeStr() const 300QString Todo::dtDueTimeStr() const
297{ 301{
298 return KGlobal::locale()->formatTime(mDtDue.time()); 302 return KGlobal::locale()->formatTime(mDtDue.time());
299} 303}
300 304
301QString Todo::dtDueDateStr(bool shortfmt) const 305QString Todo::dtDueDateStr(bool shortfmt) const
302{ 306{
303 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 307 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
304} 308}
305 309
306QString Todo::dtDueStr(bool shortfmt) const 310QString Todo::dtDueStr(bool shortfmt) const
307{ 311{
308 if ( doesFloat() ) 312 if ( doesFloat() )
309 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 313 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
310 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 314 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
311} 315}
312// retval 0 : no found 316// retval 0 : no found
313// 1 : due for date found 317// 1 : due for date found
314// 2 : overdue for date found 318// 2 : overdue for date found
315int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 319int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
316{ 320{
317 int retval = 0; 321 int retval = 0;
318 if ( isCompleted() ) 322 if ( isCompleted() )
319 return 0; 323 return 0;
320 if ( hasDueDate() ) { 324 if ( hasDueDate() ) {
321 if ( dtDue().date() < date ) 325 if ( dtDue().date() < date )
322 return 2; 326 return 2;
323 // we do not return, because we may find an overdue sub todo 327 // we do not return, because we may find an overdue sub todo
324 if ( dtDue().date() == date ) 328 if ( dtDue().date() == date )
325 retval = 1; 329 retval = 1;
326 } 330 }
327 if ( checkSubtodos ) { 331 if ( checkSubtodos ) {
328 Incidence *aTodo; 332 Incidence *aTodo;
329 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 333 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
330 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 334 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
331 if ( ret == 2 ) 335 if ( ret == 2 )
332 return 2; 336 return 2;
333 if ( ret == 1) 337 if ( ret == 1)
334 retval = 1; 338 retval = 1;
335 } 339 }
336 } 340 }
337 return retval; 341 return retval;
338} 342}
339int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 343int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
340{ 344{
341 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 345 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
342} 346}
343bool Todo::hasDueDate() const 347bool Todo::hasDueDate() const
344{ 348{
345 return mHasDueDate; 349 return mHasDueDate;
346} 350}
347 351
348void Todo::setHasDueDate(bool f) 352void Todo::setHasDueDate(bool f)
349{ 353{
350 if (mReadOnly) return; 354 if (mReadOnly) return;
351 mHasDueDate = f; 355 mHasDueDate = f;
352 updated(); 356 updated();
353} 357}
354 358
355 359
356#if 0 360#if 0
357void Todo::setStatus(const QString &statStr) 361void Todo::setStatus(const QString &statStr)
358{ 362{
359 if (mReadOnly) return; 363 if (mReadOnly) return;
360 QString ss(statStr.upper()); 364 QString ss(statStr.upper());
361 365
362 if (ss == "X-ACTION") 366 if (ss == "X-ACTION")
363 mStatus = NEEDS_ACTION; 367 mStatus = NEEDS_ACTION;
364 else if (ss == "NEEDS ACTION") 368 else if (ss == "NEEDS ACTION")
365 mStatus = NEEDS_ACTION; 369 mStatus = NEEDS_ACTION;
366 else if (ss == "ACCEPTED") 370 else if (ss == "ACCEPTED")
367 mStatus = ACCEPTED; 371 mStatus = ACCEPTED;
368 else if (ss == "SENT") 372 else if (ss == "SENT")
369 mStatus = SENT; 373 mStatus = SENT;
370 else if (ss == "TENTATIVE") 374 else if (ss == "TENTATIVE")
371 mStatus = TENTATIVE; 375 mStatus = TENTATIVE;
372 else if (ss == "CONFIRMED") 376 else if (ss == "CONFIRMED")
373 mStatus = CONFIRMED; 377 mStatus = CONFIRMED;
374 else if (ss == "DECLINED") 378 else if (ss == "DECLINED")
375 mStatus = DECLINED; 379 mStatus = DECLINED;
376 else if (ss == "COMPLETED") 380 else if (ss == "COMPLETED")
377 mStatus = COMPLETED; 381 mStatus = COMPLETED;
378 else if (ss == "DELEGATED") 382 else if (ss == "DELEGATED")
379 mStatus = DELEGATED; 383 mStatus = DELEGATED;
380 384
381 updated(); 385 updated();
382} 386}
383 387
384void Todo::setStatus(int status) 388void Todo::setStatus(int status)
385{ 389{
386 if (mReadOnly) return; 390 if (mReadOnly) return;
387 mStatus = status; 391 mStatus = status;
388 updated(); 392 updated();
389} 393}
390 394
391int Todo::status() const 395int Todo::status() const
392{ 396{
393 return mStatus; 397 return mStatus;
394} 398}
395 399
396QString Todo::statusStr() const 400QString Todo::statusStr() const
397{ 401{
398 switch(mStatus) { 402 switch(mStatus) {
399 case NEEDS_ACTION: 403 case NEEDS_ACTION:
400 return QString("NEEDS ACTION"); 404 return QString("NEEDS ACTION");
401 break; 405 break;
402 case ACCEPTED: 406 case ACCEPTED:
403 return QString("ACCEPTED"); 407 return QString("ACCEPTED");
404 break; 408 break;
405 case SENT: 409 case SENT:
406 return QString("SENT"); 410 return QString("SENT");
407 break; 411 break;
408 case TENTATIVE: 412 case TENTATIVE:
409 return QString("TENTATIVE"); 413 return QString("TENTATIVE");
410 break; 414 break;
411 case CONFIRMED: 415 case CONFIRMED:
412 return QString("CONFIRMED"); 416 return QString("CONFIRMED");
413 break; 417 break;
414 case DECLINED: 418 case DECLINED:
415 return QString("DECLINED"); 419 return QString("DECLINED");
416 break; 420 break;
417 case COMPLETED: 421 case COMPLETED:
418 return QString("COMPLETED"); 422 return QString("COMPLETED");
419 break; 423 break;
420 case DELEGATED: 424 case DELEGATED:
421 return QString("DELEGATED"); 425 return QString("DELEGATED");
422 break; 426 break;
423 } 427 }
424 return QString(""); 428 return QString("");
425} 429}
426#endif 430#endif
427 431
428bool Todo::isCompleted() const 432bool Todo::isCompleted() const
429{ 433{
430 if (mPercentComplete == 100) { 434 if (mPercentComplete == 100) {
431 return true; 435 return true;
432 } 436 }
433 else return false; 437 else return false;
434} 438}
435 439
436void Todo::setCompleted(bool completed) 440void Todo::setCompleted(bool completed)
437{ 441{
438 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 442 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
439 if ( !setRecurDates() ) 443 if ( !setRecurDates() )
440 completed = false; 444 completed = false;
441 } 445 }
442 if (completed) mPercentComplete = 100; 446 if (completed) mPercentComplete = 100;
443 else { 447 else {
444 mPercentComplete = 0; 448 mPercentComplete = 0;
445 mHasCompletedDate = false; 449 mHasCompletedDate = false;
446 } 450 }
447 updated(); 451 updated();
448} 452}
449 453
450QDateTime Todo::completed() const 454QDateTime Todo::completed() const
451{ 455{
452 return mCompleted; 456 return mCompleted;
453} 457}
454 458
455QString Todo::completedStr( bool shortF ) const 459QString Todo::completedStr( bool shortF ) const
456{ 460{
457 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 461 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
458} 462}
459 463
460void Todo::setCompleted(const QDateTime &completed) 464void Todo::setCompleted(const QDateTime &completed)
461{ 465{
462 //qDebug("Todo::setCompleted "); 466 //qDebug("Todo::setCompleted ");
463 if ( mHasCompletedDate ) { 467 if ( mHasCompletedDate ) {
464 // qDebug("has completed data - return "); 468 // qDebug("has completed data - return ");
465 return; 469 return;
466 } 470 }
467 mHasCompletedDate = true; 471 mHasCompletedDate = true;
468 mPercentComplete = 100; 472 mPercentComplete = 100;
469 mCompleted = getEvenTime(completed); 473 mCompleted = getEvenTime(completed);
470 updated(); 474 updated();
471} 475}
472 476
473bool Todo::hasCompletedDate() const 477bool Todo::hasCompletedDate() const
474{ 478{
475 return mHasCompletedDate; 479 return mHasCompletedDate;
476} 480}
477 481
478int Todo::percentComplete() const 482int Todo::percentComplete() const
479{ 483{
480 return mPercentComplete; 484 return mPercentComplete;
481} 485}
482bool Todo::setRecurDates() 486bool Todo::setRecurDates()
483{ 487{
484 if ( !mHasRecurrenceID ) 488 if ( !mHasRecurrenceID )
485 return true; 489 return true;
486 int secs = mDtStart.secsTo( dtDue() ); 490 int secs = mDtStart.secsTo( dtDue() );
487 bool ok; 491 bool ok;
488 qDebug("T:setRecurDates() "); 492 qDebug("T:setRecurDates() ");
489 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 493 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
490 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 494 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
491 if ( ok ) { 495 if ( ok ) {
492 mRecurrenceID = next; 496 mRecurrenceID = next;
493 mDtStart = next; 497 mDtStart = next;
494 setDtDue( next.addSecs( secs ) ); 498 setDtDue( next.addSecs( secs ) );
495 if ( QDateTime::currentDateTime() > next) 499 if ( QDateTime::currentDateTime() > next)
496 return false; 500 return false;
497 } else { 501 } else {
498 setHasRecurrenceID( false ); 502 setHasRecurrenceID( false );
499 recurrence()->unsetRecurs(); 503 recurrence()->unsetRecurs();
500 } 504 }
501 return true; 505 return true;
502} 506}
503void Todo::setPercentComplete(int v) 507void Todo::setPercentComplete(int v)
504{ 508{
505 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 509 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
506 if ( !setRecurDates() ) 510 if ( !setRecurDates() )
507 v = 0; 511 v = 0;
508 } 512 }
509 mPercentComplete = v; 513 mPercentComplete = v;
510 if ( v != 100 ) 514 if ( v != 100 )
511 mHasCompletedDate = false; 515 mHasCompletedDate = false;
512 updated(); 516 updated();
513} 517}
514QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 518QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
515{ 519{
516 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 520 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
517 *ok = false; 521 *ok = false;
518 return QDateTime (); 522 return QDateTime ();
519 } 523 }
520 QDateTime incidenceStart; 524 QDateTime incidenceStart;
521 incidenceStart = dtDue(); 525 incidenceStart = dtDue();
522 bool enabled = false; 526 bool enabled = false;
523 Alarm* alarm; 527 Alarm* alarm;
524 int off = 0; 528 int off = 0;
525 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
526 // if ( QDateTime::currentDateTime() > incidenceStart ){ 530 // if ( QDateTime::currentDateTime() > incidenceStart ){
527// *ok = false; 531// *ok = false;
528// return incidenceStart; 532// return incidenceStart;
529// } 533// }
530 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
531 if (alarm->enabled()) { 535 if (alarm->enabled()) {
532 if ( alarm->hasTime () ) { 536 if ( alarm->hasTime () ) {
533 if ( alarm->time() < alarmStart ) { 537 if ( alarm->time() < alarmStart ) {
534 alarmStart = alarm->time(); 538 alarmStart = alarm->time();
535 enabled = true; 539 enabled = true;
536 off = alarmStart.secsTo( incidenceStart ); 540 off = alarmStart.secsTo( incidenceStart );
537 } 541 }
538 542
539 } else { 543 } else {
540 int secs = alarm->startOffset().asSeconds(); 544 int secs = alarm->startOffset().asSeconds();
541 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 545 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
542 alarmStart = incidenceStart.addSecs( secs ); 546 alarmStart = incidenceStart.addSecs( secs );
543 enabled = true; 547 enabled = true;
544 off = -secs; 548 off = -secs;
545 } 549 }
546 } 550 }
547 } 551 }
548 } 552 }
549 if ( enabled ) { 553 if ( enabled ) {
550 if ( alarmStart > QDateTime::currentDateTime() ) { 554 if ( alarmStart > QDateTime::currentDateTime() ) {
551 *ok = true; 555 *ok = true;
552 * offset = off; 556 * offset = off;
553 return alarmStart; 557 return alarmStart;
554 } 558 }
555 } 559 }
556 *ok = false; 560 *ok = false;
557 return QDateTime (); 561 return QDateTime ();
558 562
559} 563}
560 564
561void Todo::checkSetCompletedFalse() 565void Todo::checkSetCompletedFalse()
562{ 566{
563 if ( !hasRecurrenceID() ) { 567 if ( !hasRecurrenceID() ) {
564 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
565 } 569 }
566 // qDebug("Todo::checkSetCompletedFalse()"); 570 // qDebug("Todo::checkSetCompletedFalse()");
567 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 571 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
568 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { 572 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) {
569 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 573 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
570 setCompleted( false ); 574 setCompleted( false );
571 qDebug("Todo::checkSetCompletedFalse "); 575 qDebug("Todo::checkSetCompletedFalse ");
572 } 576 }
573} 577}