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