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