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