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