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