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