summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-04-09 20:21:58 (UTC)
committer zautrix <zautrix>2005-04-09 20:21:58 (UTC)
commit9e43ebbe5867b2da957bb17c35bd357715424cba (patch) (unidiff)
treeb506ba029b50fc46a33d35a39e6f1c768c995f22 /libkcal
parent2c39ac46121e8796e780a5321ab777f08792e5ba (diff)
downloadkdepimpi-9e43ebbe5867b2da957bb17c35bd357715424cba.zip
kdepimpi-9e43ebbe5867b2da957bb17c35bd357715424cba.tar.gz
kdepimpi-9e43ebbe5867b2da957bb17c35bd357715424cba.tar.bz2
todo tt
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp44
-rw-r--r--libkcal/todo.h16
2 files changed, 58 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index a496404..7dee4cd 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,437 +1,481 @@
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 <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "todo.h" 25#include "todo.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Todo::Todo(): Incidence() 29Todo::Todo(): Incidence()
30{ 30{
31// mStatus = TENTATIVE; 31// mStatus = TENTATIVE;
32 32
33 mHasDueDate = false; 33 mHasDueDate = false;
34 setHasStartDate( false ); 34 setHasStartDate( false );
35 mCompleted = getEvenTime(QDateTime::currentDateTime()); 35 mCompleted = getEvenTime(QDateTime::currentDateTime());
36 mHasCompletedDate = false; 36 mHasCompletedDate = false;
37 mPercentComplete = 0; 37 mPercentComplete = 0;
38 mRunning = false;
39 mRunSaveTimer = 0;
38} 40}
39 41
40Todo::Todo(const Todo &t) : Incidence(t) 42Todo::Todo(const Todo &t) : Incidence(t)
41{ 43{
42 mDtDue = t.mDtDue; 44 mDtDue = t.mDtDue;
43 mHasDueDate = t.mHasDueDate; 45 mHasDueDate = t.mHasDueDate;
44 mCompleted = t.mCompleted; 46 mCompleted = t.mCompleted;
45 mHasCompletedDate = t.mHasCompletedDate; 47 mHasCompletedDate = t.mHasCompletedDate;
46 mPercentComplete = t.mPercentComplete; 48 mPercentComplete = t.mPercentComplete;
49 mRunning = false;
50 mRunSaveTimer = 0;
47} 51}
48 52
49Todo::~Todo() 53Todo::~Todo()
50{ 54{
55 setRunning( false );
56}
57
58void Todo::setRunning( bool run )
59{
60 if ( run == mRunning )
61 return;
62 if ( !mRunSaveTimer ) {
63 mRunSaveTimer = new QTimer ( this );
64 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
65 }
66 mRunning = run;
67 if ( mRunning ) {
68 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
69 mRunStart = QDateTime::currentDateTime();
70 } else {
71 mRunSaveTimer->stop();
72 saveRunningInfoToFile();
73 }
74}
51 75
76void Todo::saveRunningInfoToFile()
77{
78 qDebug("Todo::saveRunningInfoToFile() ");
52} 79}
53 80
81int Todo::runTime()
82{
83 if ( !mRunning )
84 return 0;
85 return mRunStart.secsTo( QDateTime::currentDateTime() );
86}
87bool Todo::hasRunningSub()
88{
89 if ( mRunning )
90 return true;
91 Incidence *aTodo;
92 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
93 if ( ((Todo*)aTodo)->hasRunningSub() )
94 return true;
95 }
96 return false;
97}
54Incidence *Todo::clone() 98Incidence *Todo::clone()
55{ 99{
56 return new Todo(*this); 100 return new Todo(*this);
57} 101}
58 102
59bool Todo::contains ( Todo* from ) 103bool Todo::contains ( Todo* from )
60{ 104{
61 105
62 if ( !from->summary().isEmpty() ) 106 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 107 if ( !summary().startsWith( from->summary() ))
64 return false; 108 return false;
65 if ( from->hasStartDate() ) { 109 if ( from->hasStartDate() ) {
66 if ( !hasStartDate() ) 110 if ( !hasStartDate() )
67 return false; 111 return false;
68 if ( from->dtStart() != dtStart()) 112 if ( from->dtStart() != dtStart())
69 return false; 113 return false;
70 } 114 }
71 if ( from->hasDueDate() ){ 115 if ( from->hasDueDate() ){
72 if ( !hasDueDate() ) 116 if ( !hasDueDate() )
73 return false; 117 return false;
74 if ( from->dtDue() != dtDue()) 118 if ( from->dtDue() != dtDue())
75 return false; 119 return false;
76 } 120 }
77 if ( !from->location().isEmpty() ) 121 if ( !from->location().isEmpty() )
78 if ( !location().startsWith( from->location() ) ) 122 if ( !location().startsWith( from->location() ) )
79 return false; 123 return false;
80 if ( !from->description().isEmpty() ) 124 if ( !from->description().isEmpty() )
81 if ( !description().startsWith( from->description() )) 125 if ( !description().startsWith( from->description() ))
82 return false; 126 return false;
83 if ( from->alarms().count() ) { 127 if ( from->alarms().count() ) {
84 Alarm *a = from->alarms().first(); 128 Alarm *a = from->alarms().first();
85 if ( a->enabled() ){ 129 if ( a->enabled() ){
86 if ( !alarms().count() ) 130 if ( !alarms().count() )
87 return false; 131 return false;
88 Alarm *b = alarms().first(); 132 Alarm *b = alarms().first();
89 if( ! b->enabled() ) 133 if( ! b->enabled() )
90 return false; 134 return false;
91 if ( ! (a->offset() == b->offset() )) 135 if ( ! (a->offset() == b->offset() ))
92 return false; 136 return false;
93 } 137 }
94 } 138 }
95 139
96 QStringList cat = categories(); 140 QStringList cat = categories();
97 QStringList catFrom = from->categories(); 141 QStringList catFrom = from->categories();
98 QString nCat; 142 QString nCat;
99 unsigned int iii; 143 unsigned int iii;
100 for ( iii = 0; iii < catFrom.count();++iii ) { 144 for ( iii = 0; iii < catFrom.count();++iii ) {
101 nCat = catFrom[iii]; 145 nCat = catFrom[iii];
102 if ( !nCat.isEmpty() ) 146 if ( !nCat.isEmpty() )
103 if ( !cat.contains( nCat )) { 147 if ( !cat.contains( nCat )) {
104 return false; 148 return false;
105 } 149 }
106 } 150 }
107 if ( from->isCompleted() ) { 151 if ( from->isCompleted() ) {
108 if ( !isCompleted() ) 152 if ( !isCompleted() )
109 return false; 153 return false;
110 } 154 }
111 if( priority() != from->priority() ) 155 if( priority() != from->priority() )
112 return false; 156 return false;
113 157
114 158
115 return true; 159 return true;
116 160
117} 161}
118bool KCal::operator==( const Todo& t1, const Todo& t2 ) 162bool KCal::operator==( const Todo& t1, const Todo& t2 )
119{ 163{
120 164
121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 165 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
122 if ( ! ret ) 166 if ( ! ret )
123 return false; 167 return false;
124 if ( t1.hasDueDate() == t2.hasDueDate() ) { 168 if ( t1.hasDueDate() == t2.hasDueDate() ) {
125 if ( t1.hasDueDate() ) { 169 if ( t1.hasDueDate() ) {
126 if ( t1.doesFloat() == t2.doesFloat() ) { 170 if ( t1.doesFloat() == t2.doesFloat() ) {
127 if ( t1.doesFloat() ) { 171 if ( t1.doesFloat() ) {
128 if ( t1.dtDue().date() != t2.dtDue().date() ) 172 if ( t1.dtDue().date() != t2.dtDue().date() )
129 return false; 173 return false;
130 } else 174 } else
131 if ( t1.dtDue() != t2.dtDue() ) 175 if ( t1.dtDue() != t2.dtDue() )
132 return false; 176 return false;
133 } else 177 } else
134 return false;// float != 178 return false;// float !=
135 } 179 }
136 180
137 } else 181 } else
138 return false; 182 return false;
139 if ( t1.percentComplete() != t2.percentComplete() ) 183 if ( t1.percentComplete() != t2.percentComplete() )
140 return false; 184 return false;
141 if ( t1.isCompleted() ) { 185 if ( t1.isCompleted() ) {
142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 186 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
143 if ( t1.hasCompletedDate() ) { 187 if ( t1.hasCompletedDate() ) {
144 if ( t1.completed() != t2.completed() ) 188 if ( t1.completed() != t2.completed() )
145 return false; 189 return false;
146 } 190 }
147 191
148 } else 192 } else
149 return false; 193 return false;
150 } 194 }
151 return true; 195 return true;
152 196
153} 197}
154 198
155void Todo::setDtDue(const QDateTime &dtDue) 199void Todo::setDtDue(const QDateTime &dtDue)
156{ 200{
157 //int diffsecs = mDtDue.secsTo(dtDue); 201 //int diffsecs = mDtDue.secsTo(dtDue);
158 202
159 /*if (mReadOnly) return; 203 /*if (mReadOnly) return;
160 const QPtrList<Alarm>& alarms = alarms(); 204 const QPtrList<Alarm>& alarms = alarms();
161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 205 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
162 if (alarm->enabled()) { 206 if (alarm->enabled()) {
163 alarm->setTime(alarm->time().addSecs(diffsecs)); 207 alarm->setTime(alarm->time().addSecs(diffsecs));
164 } 208 }
165 }*/ 209 }*/
166 mDtDue = getEvenTime(dtDue); 210 mDtDue = getEvenTime(dtDue);
167 211
168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 212 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
169 213
170 /*const QPtrList<Alarm>& alarms = alarms(); 214 /*const QPtrList<Alarm>& alarms = alarms();
171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 215 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
172 alarm->setAlarmStart(mDtDue);*/ 216 alarm->setAlarmStart(mDtDue);*/
173 217
174 updated(); 218 updated();
175} 219}
176 220
177QDateTime Todo::dtDue() const 221QDateTime Todo::dtDue() const
178{ 222{
179 return mDtDue; 223 return mDtDue;
180} 224}
181 225
182QString Todo::dtDueTimeStr() const 226QString Todo::dtDueTimeStr() const
183{ 227{
184 return KGlobal::locale()->formatTime(mDtDue.time()); 228 return KGlobal::locale()->formatTime(mDtDue.time());
185} 229}
186 230
187QString Todo::dtDueDateStr(bool shortfmt) const 231QString Todo::dtDueDateStr(bool shortfmt) const
188{ 232{
189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 233 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
190} 234}
191 235
192QString Todo::dtDueStr(bool shortfmt) const 236QString Todo::dtDueStr(bool shortfmt) const
193{ 237{
194 if ( doesFloat() ) 238 if ( doesFloat() )
195 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 239 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
196 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 240 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
197} 241}
198// retval 0 : no found 242// retval 0 : no found
199// 1 : due for date found 243// 1 : due for date found
200// 2 : overdue for date found 244// 2 : overdue for date found
201int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 245int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
202{ 246{
203 int retval = 0; 247 int retval = 0;
204 if ( isCompleted() ) 248 if ( isCompleted() )
205 return 0; 249 return 0;
206 if ( hasDueDate() ) { 250 if ( hasDueDate() ) {
207 if ( dtDue().date() < date ) 251 if ( dtDue().date() < date )
208 return 2; 252 return 2;
209 // we do not return, because we may find an overdue sub todo 253 // we do not return, because we may find an overdue sub todo
210 if ( dtDue().date() == date ) 254 if ( dtDue().date() == date )
211 retval = 1; 255 retval = 1;
212 } 256 }
213 if ( checkSubtodos ) { 257 if ( checkSubtodos ) {
214 Incidence *aTodo; 258 Incidence *aTodo;
215 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 259 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
216 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 260 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
217 if ( ret == 2 ) 261 if ( ret == 2 )
218 return 2; 262 return 2;
219 if ( ret == 1) 263 if ( ret == 1)
220 retval = 1; 264 retval = 1;
221 } 265 }
222 } 266 }
223 return retval; 267 return retval;
224} 268}
225int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 269int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
226{ 270{
227 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 271 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
228} 272}
229bool Todo::hasDueDate() const 273bool Todo::hasDueDate() const
230{ 274{
231 return mHasDueDate; 275 return mHasDueDate;
232} 276}
233 277
234void Todo::setHasDueDate(bool f) 278void Todo::setHasDueDate(bool f)
235{ 279{
236 if (mReadOnly) return; 280 if (mReadOnly) return;
237 mHasDueDate = f; 281 mHasDueDate = f;
238 updated(); 282 updated();
239} 283}
240 284
241 285
242#if 0 286#if 0
243void Todo::setStatus(const QString &statStr) 287void Todo::setStatus(const QString &statStr)
244{ 288{
245 if (mReadOnly) return; 289 if (mReadOnly) return;
246 QString ss(statStr.upper()); 290 QString ss(statStr.upper());
247 291
248 if (ss == "X-ACTION") 292 if (ss == "X-ACTION")
249 mStatus = NEEDS_ACTION; 293 mStatus = NEEDS_ACTION;
250 else if (ss == "NEEDS ACTION") 294 else if (ss == "NEEDS ACTION")
251 mStatus = NEEDS_ACTION; 295 mStatus = NEEDS_ACTION;
252 else if (ss == "ACCEPTED") 296 else if (ss == "ACCEPTED")
253 mStatus = ACCEPTED; 297 mStatus = ACCEPTED;
254 else if (ss == "SENT") 298 else if (ss == "SENT")
255 mStatus = SENT; 299 mStatus = SENT;
256 else if (ss == "TENTATIVE") 300 else if (ss == "TENTATIVE")
257 mStatus = TENTATIVE; 301 mStatus = TENTATIVE;
258 else if (ss == "CONFIRMED") 302 else if (ss == "CONFIRMED")
259 mStatus = CONFIRMED; 303 mStatus = CONFIRMED;
260 else if (ss == "DECLINED") 304 else if (ss == "DECLINED")
261 mStatus = DECLINED; 305 mStatus = DECLINED;
262 else if (ss == "COMPLETED") 306 else if (ss == "COMPLETED")
263 mStatus = COMPLETED; 307 mStatus = COMPLETED;
264 else if (ss == "DELEGATED") 308 else if (ss == "DELEGATED")
265 mStatus = DELEGATED; 309 mStatus = DELEGATED;
266 310
267 updated(); 311 updated();
268} 312}
269 313
270void Todo::setStatus(int status) 314void Todo::setStatus(int status)
271{ 315{
272 if (mReadOnly) return; 316 if (mReadOnly) return;
273 mStatus = status; 317 mStatus = status;
274 updated(); 318 updated();
275} 319}
276 320
277int Todo::status() const 321int Todo::status() const
278{ 322{
279 return mStatus; 323 return mStatus;
280} 324}
281 325
282QString Todo::statusStr() const 326QString Todo::statusStr() const
283{ 327{
284 switch(mStatus) { 328 switch(mStatus) {
285 case NEEDS_ACTION: 329 case NEEDS_ACTION:
286 return QString("NEEDS ACTION"); 330 return QString("NEEDS ACTION");
287 break; 331 break;
288 case ACCEPTED: 332 case ACCEPTED:
289 return QString("ACCEPTED"); 333 return QString("ACCEPTED");
290 break; 334 break;
291 case SENT: 335 case SENT:
292 return QString("SENT"); 336 return QString("SENT");
293 break; 337 break;
294 case TENTATIVE: 338 case TENTATIVE:
295 return QString("TENTATIVE"); 339 return QString("TENTATIVE");
296 break; 340 break;
297 case CONFIRMED: 341 case CONFIRMED:
298 return QString("CONFIRMED"); 342 return QString("CONFIRMED");
299 break; 343 break;
300 case DECLINED: 344 case DECLINED:
301 return QString("DECLINED"); 345 return QString("DECLINED");
302 break; 346 break;
303 case COMPLETED: 347 case COMPLETED:
304 return QString("COMPLETED"); 348 return QString("COMPLETED");
305 break; 349 break;
306 case DELEGATED: 350 case DELEGATED:
307 return QString("DELEGATED"); 351 return QString("DELEGATED");
308 break; 352 break;
309 } 353 }
310 return QString(""); 354 return QString("");
311} 355}
312#endif 356#endif
313 357
314bool Todo::isCompleted() const 358bool Todo::isCompleted() const
315{ 359{
316 if (mPercentComplete == 100) { 360 if (mPercentComplete == 100) {
317 return true; 361 return true;
318 } 362 }
319 else return false; 363 else return false;
320} 364}
321 365
322void Todo::setCompleted(bool completed) 366void Todo::setCompleted(bool completed)
323{ 367{
324 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 368 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
325 if ( !setRecurDates() ) 369 if ( !setRecurDates() )
326 completed = false; 370 completed = false;
327 } 371 }
328 if (completed) mPercentComplete = 100; 372 if (completed) mPercentComplete = 100;
329 else { 373 else {
330 mPercentComplete = 0; 374 mPercentComplete = 0;
331 mHasCompletedDate = false; 375 mHasCompletedDate = false;
332 } 376 }
333 updated(); 377 updated();
334} 378}
335 379
336QDateTime Todo::completed() const 380QDateTime Todo::completed() const
337{ 381{
338 return mCompleted; 382 return mCompleted;
339} 383}
340 384
341QString Todo::completedStr( bool shortF ) const 385QString Todo::completedStr( bool shortF ) const
342{ 386{
343 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 387 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
344} 388}
345 389
346void Todo::setCompleted(const QDateTime &completed) 390void Todo::setCompleted(const QDateTime &completed)
347{ 391{
348 //qDebug("Todo::setCompleted "); 392 //qDebug("Todo::setCompleted ");
349 if ( mHasCompletedDate ) { 393 if ( mHasCompletedDate ) {
350 // qDebug("has completed data - return "); 394 // qDebug("has completed data - return ");
351 return; 395 return;
352 } 396 }
353 mHasCompletedDate = true; 397 mHasCompletedDate = true;
354 mPercentComplete = 100; 398 mPercentComplete = 100;
355 mCompleted = getEvenTime(completed); 399 mCompleted = getEvenTime(completed);
356 updated(); 400 updated();
357} 401}
358 402
359bool Todo::hasCompletedDate() const 403bool Todo::hasCompletedDate() const
360{ 404{
361 return mHasCompletedDate; 405 return mHasCompletedDate;
362} 406}
363 407
364int Todo::percentComplete() const 408int Todo::percentComplete() const
365{ 409{
366 return mPercentComplete; 410 return mPercentComplete;
367} 411}
368bool Todo::setRecurDates() 412bool Todo::setRecurDates()
369{ 413{
370 if ( !mHasRecurrenceID ) 414 if ( !mHasRecurrenceID )
371 return true; 415 return true;
372 int secs = mDtStart.secsTo( dtDue() ); 416 int secs = mDtStart.secsTo( dtDue() );
373 bool ok; 417 bool ok;
374 qDebug("T:setRecurDates() "); 418 qDebug("T:setRecurDates() ");
375 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 419 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
376 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 420 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
377 if ( ok ) { 421 if ( ok ) {
378 mRecurrenceID = next; 422 mRecurrenceID = next;
379 mDtStart = next; 423 mDtStart = next;
380 setDtDue( next.addSecs( secs ) ); 424 setDtDue( next.addSecs( secs ) );
381 if ( QDateTime::currentDateTime() > next) 425 if ( QDateTime::currentDateTime() > next)
382 return false; 426 return false;
383 } else { 427 } else {
384 setHasRecurrenceID( false ); 428 setHasRecurrenceID( false );
385 recurrence()->unsetRecurs(); 429 recurrence()->unsetRecurs();
386 } 430 }
387 return true; 431 return true;
388} 432}
389void Todo::setPercentComplete(int v) 433void Todo::setPercentComplete(int v)
390{ 434{
391 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 435 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
392 if ( !setRecurDates() ) 436 if ( !setRecurDates() )
393 v = 0; 437 v = 0;
394 } 438 }
395 mPercentComplete = v; 439 mPercentComplete = v;
396 if ( v != 100 ) 440 if ( v != 100 )
397 mHasCompletedDate = false; 441 mHasCompletedDate = false;
398 updated(); 442 updated();
399} 443}
400QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 444QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
401{ 445{
402 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 446 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
403 *ok = false; 447 *ok = false;
404 return QDateTime (); 448 return QDateTime ();
405 } 449 }
406 QDateTime incidenceStart; 450 QDateTime incidenceStart;
407 incidenceStart = dtDue(); 451 incidenceStart = dtDue();
408 bool enabled = false; 452 bool enabled = false;
409 Alarm* alarm; 453 Alarm* alarm;
410 int off = 0; 454 int off = 0;
411 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 455 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
412 // if ( QDateTime::currentDateTime() > incidenceStart ){ 456 // if ( QDateTime::currentDateTime() > incidenceStart ){
413// *ok = false; 457// *ok = false;
414// return incidenceStart; 458// return incidenceStart;
415// } 459// }
416 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 460 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
417 if (alarm->enabled()) { 461 if (alarm->enabled()) {
418 if ( alarm->hasTime () ) { 462 if ( alarm->hasTime () ) {
419 if ( alarm->time() < alarmStart ) { 463 if ( alarm->time() < alarmStart ) {
420 alarmStart = alarm->time(); 464 alarmStart = alarm->time();
421 enabled = true; 465 enabled = true;
422 off = alarmStart.secsTo( incidenceStart ); 466 off = alarmStart.secsTo( incidenceStart );
423 } 467 }
424 468
425 } else { 469 } else {
426 int secs = alarm->startOffset().asSeconds(); 470 int secs = alarm->startOffset().asSeconds();
427 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 471 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
428 alarmStart = incidenceStart.addSecs( secs ); 472 alarmStart = incidenceStart.addSecs( secs );
429 enabled = true; 473 enabled = true;
430 off = -secs; 474 off = -secs;
431 } 475 }
432 } 476 }
433 } 477 }
434 } 478 }
435 if ( enabled ) { 479 if ( enabled ) {
436 if ( alarmStart > QDateTime::currentDateTime() ) { 480 if ( alarmStart > QDateTime::currentDateTime() ) {
437 *ok = true; 481 *ok = true;
diff --git a/libkcal/todo.h b/libkcal/todo.h
index a22d4b7..fe43357 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -1,136 +1,148 @@
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#ifndef TODO_H 20#ifndef TODO_H
21#define TODO_H 21#define TODO_H
22// 22//
23// Todo component, representing a VTODO object 23// Todo component, representing a VTODO object
24// 24//
25 25
26#include "incidence.h" 26#include "incidence.h"
27 27
28#include <qtimer.h>
29
28namespace KCal { 30namespace KCal {
29 31
30/** 32/**
31 This class provides a Todo in the sense of RFC2445. 33 This class provides a Todo in the sense of RFC2445.
32*/ 34*/
33class Todo : public Incidence 35 class Todo : public QObject,public Incidence
34{ 36{
37 Q_OBJECT
35 public: 38 public:
36 Todo(); 39 Todo();
37 Todo(const Todo &); 40 Todo(const Todo &);
38 ~Todo(); 41 ~Todo();
39 typedef ListBase<Todo> List; 42 typedef ListBase<Todo> List;
40 QCString type() const { return "Todo"; } 43 QCString type() const { return "Todo"; }
41 44
42 /** Return an exact copy of this todo. */ 45 /** Return an exact copy of this todo. */
43 Incidence *clone(); 46 Incidence *clone();
44 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; 47 QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const;
45 48
46 /** for setting the todo's due date/time with a QDateTime. */ 49 /** for setting the todo's due date/time with a QDateTime. */
47 void setDtDue(const QDateTime &dtDue); 50 void setDtDue(const QDateTime &dtDue);
48 /** returns an event's Due date/time as a QDateTime. */ 51 /** returns an event's Due date/time as a QDateTime. */
49 QDateTime dtDue() const; 52 QDateTime dtDue() const;
50 /** returns an event's due time as a string formatted according to the 53 /** returns an event's due time as a string formatted according to the
51 users locale settings */ 54 users locale settings */
52 QString dtDueTimeStr() const; 55 QString dtDueTimeStr() const;
53 /** returns an event's due date as a string formatted according to the 56 /** returns an event's due date as a string formatted according to the
54 users locale settings */ 57 users locale settings */
55 QString dtDueDateStr(bool shortfmt=true) const; 58 QString dtDueDateStr(bool shortfmt=true) const;
56 /** returns an event's due date and time as a string formatted according 59 /** returns an event's due date and time as a string formatted according
57 to the users locale settings */ 60 to the users locale settings */
58 QString dtDueStr(bool shortfmt=true) const; 61 QString dtDueStr(bool shortfmt=true) const;
59 62
60 /** returns TRUE or FALSE depending on whether the todo has a due date */ 63 /** returns TRUE or FALSE depending on whether the todo has a due date */
61 bool hasDueDate() const; 64 bool hasDueDate() const;
62 /** sets the event's hasDueDate value. */ 65 /** sets the event's hasDueDate value. */
63 void setHasDueDate(bool f); 66 void setHasDueDate(bool f);
64 67
65 /* 68 /*
66 Looks for a subtodo (including itself ) which is not complete and is 69 Looks for a subtodo (including itself ) which is not complete and is
67 - overdue, or 70 - overdue, or
68 - due today. 71 - due today.
69 It returns 0 for nothing found, 72 It returns 0 for nothing found,
70 1 for found a todo which is due today and no overdue found 73 1 for found a todo which is due today and no overdue found
71 2 for found a overdue todo 74 2 for found a overdue todo
72 */ 75 */
73 int hasDueSubTodo( bool checkSubtodos = true ); 76 int hasDueSubTodo( bool checkSubtodos = true );
74 /* same as above, but a specific date can be specified*/ 77 /* same as above, but a specific date can be specified*/
75 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); 78 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos );
76 79
77 80
78 /** sets the event's status to the string specified. The string 81 /** sets the event's status to the string specified. The string
79 * must be a recognized value for the status field, i.e. a string 82 * must be a recognized value for the status field, i.e. a string
80 * equivalent of the possible status enumerations previously described. */ 83 * equivalent of the possible status enumerations previously described. */
81// void setStatus(const QString &statStr); 84// void setStatus(const QString &statStr);
82 /** sets the event's status to the value specified. See the enumeration 85 /** sets the event's status to the value specified. See the enumeration
83 * above for possible values. */ 86 * above for possible values. */
84// void setStatus(int); 87// void setStatus(int);
85 /** return the event's status. */ 88 /** return the event's status. */
86// int status() const; 89// int status() const;
87 /** return the event's status in string format. */ 90 /** return the event's status in string format. */
88// QString statusStr() const; 91// QString statusStr() const;
89 92
90 /** return, if this todo is completed */ 93 /** return, if this todo is completed */
91 bool isCompleted() const; 94 bool isCompleted() const;
92 /** set completed state of this todo */ 95 /** set completed state of this todo */
93 void setCompleted(bool); 96 void setCompleted(bool);
94 97
95 /** 98 /**
96 Return how many percent of the task are completed. Returns a value 99 Return how many percent of the task are completed. Returns a value
97 between 0 and 100. 100 between 0 and 100.
98 */ 101 */
99 int percentComplete() const; 102 int percentComplete() const;
100 /** 103 /**
101 Set how many percent of the task are completed. Valid values are in the 104 Set how many percent of the task are completed. Valid values are in the
102 range from 0 to 100. 105 range from 0 to 100.
103 */ 106 */
104 void setPercentComplete(int); 107 void setPercentComplete(int);
105 108
106 /** return date and time when todo was completed */ 109 /** return date and time when todo was completed */
107 QDateTime completed() const; 110 QDateTime completed() const;
108 QString completedStr(bool shortF = true) const; 111 QString completedStr(bool shortF = true) const;
109 /** set date and time of completion */ 112 /** set date and time of completion */
110 void setCompleted(const QDateTime &completed); 113 void setCompleted(const QDateTime &completed);
111 114
112 /** Return true, if todo has a date associated with completion */ 115 /** Return true, if todo has a date associated with completion */
113 bool hasCompletedDate() const; 116 bool hasCompletedDate() const;
114 bool contains ( Todo*); 117 bool contains ( Todo*);
115 void checkSetCompletedFalse(); 118 void checkSetCompletedFalse();
116 bool setRecurDates(); 119 bool setRecurDates();
117 120 bool isRunning() {return mRunning;}
121 bool hasRunningSub();
122 void setRunning( bool );
123 int runTime();
124 QDateTime runStart () const { return mRunStart;}
125 public slots:
126 void saveRunningInfoToFile();
118 private: 127 private:
128 bool mRunning;
129 QTimer * mRunSaveTimer;
130 QDateTime mRunStart;
119 bool accept(Visitor &v) { return v.visit(this); } 131 bool accept(Visitor &v) { return v.visit(this); }
120 132
121 QDateTime mDtDue; // due date of todo 133 QDateTime mDtDue; // due date of todo
122 134
123 bool mHasDueDate; // if todo has associated due date 135 bool mHasDueDate; // if todo has associated due date
124 136
125// int mStatus; // confirmed/delegated/tentative/etc 137// int mStatus; // confirmed/delegated/tentative/etc
126 138
127 QDateTime mCompleted; 139 QDateTime mCompleted;
128 bool mHasCompletedDate; 140 bool mHasCompletedDate;
129 141
130 int mPercentComplete; 142 int mPercentComplete;
131}; 143};
132 144
133 bool operator==( const Todo&, const Todo& ); 145 bool operator==( const Todo&, const Todo& );
134} 146}
135 147
136#endif 148#endif