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