summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 4ada2d8..7bf756a 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,362 +1,363 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::Todo(): QObject(), Incidence()
35{ 35{
36// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
37 37
38 mHasDueDate = false; 38 mHasDueDate = false;
39 setHasStartDate( false ); 39 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 41 mHasCompletedDate = false;
42 mPercentComplete = 0; 42 mPercentComplete = 0;
43 mRunning = false; 43 mRunning = false;
44 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
45} 45}
46 46
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
48{ 48{
49 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
50 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
51 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
52 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
53 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
54 mRunning = false; 54 mRunning = false;
55 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
56} 56}
57 57
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 mRunSaveTimer->stop(); 69 if ( mRunSaveTimer )
70 mRunSaveTimer->stop();
70 saveRunningInfoToFile( s ); 71 saveRunningInfoToFile( s );
71} 72}
72void Todo::stopRunning() 73void Todo::stopRunning()
73{ 74{
74 if ( !mRunning ) 75 if ( !mRunning )
75 return; 76 return;
76 if ( mRunSaveTimer ) 77 if ( mRunSaveTimer )
77 mRunSaveTimer->stop(); 78 mRunSaveTimer->stop();
78 mRunning = false; 79 mRunning = false;
79} 80}
80void Todo::setRunning( bool run ) 81void Todo::setRunning( bool run )
81{ 82{
82 if ( run == mRunning ) 83 if ( run == mRunning )
83 return; 84 return;
84 //qDebug("Todo::setRunning %d ", run); 85 //qDebug("Todo::setRunning %d ", run);
85 if ( !mRunSaveTimer ) { 86 if ( !mRunSaveTimer ) {
86 mRunSaveTimer = new QTimer ( this ); 87 mRunSaveTimer = new QTimer ( this );
87 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 88 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
88 } 89 }
89 mRunning = run; 90 mRunning = run;
90 if ( mRunning ) { 91 if ( mRunning ) {
91 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 92 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
92 mRunStart = QDateTime::currentDateTime(); 93 mRunStart = QDateTime::currentDateTime();
93 } else { 94 } else {
94 mRunSaveTimer->stop(); 95 mRunSaveTimer->stop();
95 saveRunningInfoToFile(); 96 saveRunningInfoToFile();
96 } 97 }
97} 98}
98void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 99void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
99{ 100{
100 if ( !mRunning) return; 101 if ( !mRunning) return;
101 mRunning = false; 102 mRunning = false;
102 mRunStart = start; 103 mRunStart = start;
103 mRunEnd = end; 104 mRunEnd = end;
104 saveRunningInfoToFile( comment ); 105 saveRunningInfoToFile( comment );
105} 106}
106void Todo::saveRunningInfoToFile() 107void Todo::saveRunningInfoToFile()
107{ 108{
108 mRunEnd = QDateTime::currentDateTime(); 109 mRunEnd = QDateTime::currentDateTime();
109 saveRunningInfoToFile( QString::null ); 110 saveRunningInfoToFile( QString::null );
110} 111}
111void Todo::saveRunningInfoToFile( QString comment ) 112void Todo::saveRunningInfoToFile( QString comment )
112{ 113{
113 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 114 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
114 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 115 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
115 qDebug("Running time < 15 seconds. Skipped. "); 116 qDebug("Running time < 15 seconds. Skipped. ");
116 return; 117 return;
117 } 118 }
118 QString dir = KGlobalSettings::timeTrackerDir(); 119 QString dir = KGlobalSettings::timeTrackerDir();
119 //qDebug("%s ", dir.latin1()); 120 //qDebug("%s ", dir.latin1());
120 QString file = "%1%2%3-%4%5%6-"; 121 QString file = "%1%2%3-%4%5%6-";
121 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 ); 122 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 );
122 file.replace ( QRegExp (" "), "0" ); 123 file.replace ( QRegExp (" "), "0" );
123 file += uid(); 124 file += uid();
124 //qDebug("File %s ",file.latin1() ); 125 //qDebug("File %s ",file.latin1() );
125 CalendarLocal cal; 126 CalendarLocal cal;
126 cal.setLocalTime(); 127 cal.setLocalTime();
127 Todo * to = (Todo*) clone(); 128 Todo * to = (Todo*) clone();
128 to->setFloats( false ); 129 to->setFloats( false );
129 to->setDtStart( mRunStart ); 130 to->setDtStart( mRunStart );
130 to->setHasStartDate( true ); 131 to->setHasStartDate( true );
131 to->setDtDue( mRunEnd ); 132 to->setDtDue( mRunEnd );
132 to->setHasDueDate( true ); 133 to->setHasDueDate( true );
133 to->setUid( file ); 134 to->setUid( file );
134 if ( !comment.isEmpty() ) { 135 if ( !comment.isEmpty() ) {
135 QString des = to->description(); 136 QString des = to->description();
136 if ( des.isEmpty () ) 137 if ( des.isEmpty () )
137 to->setDescription( "TT-Note: " + comment ); 138 to->setDescription( "TT-Note: " + comment );
138 else 139 else
139 to->setDescription( "TT-Note: " + comment +"\n" + des ); 140 to->setDescription( "TT-Note: " + comment +"\n" + des );
140 } 141 }
141 cal.addIncidence( to ); 142 cal.addIncidence( to );
142 ICalFormat format; 143 ICalFormat format( false );
143 file = dir +"/" +file +".ics"; 144 file = dir +"/" +file +".ics";
144 format.save( &cal, file ); 145 format.save( &cal, file );
145 saveParents(); 146 saveParents();
146 147
147} 148}
148void Todo::saveParents() 149void Todo::saveParents()
149{ 150{
150 if (!relatedTo() ) 151 if (!relatedTo() )
151 return; 152 return;
152 Incidence * inc = relatedTo(); 153 Incidence * inc = relatedTo();
153 if ( inc->typeID() != todoID ) 154 if ( inc->typeID() != todoID )
154 return; 155 return;
155 Todo* to = (Todo*)inc; 156 Todo* to = (Todo*)inc;
156 bool saveTodo = false; 157 bool saveTodo = false;
157 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 158 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
158 QFileInfo fi ( file ); 159 QFileInfo fi ( file );
159 if ( fi.exists() ) { 160 if ( fi.exists() ) {
160 if ( fi.lastModified () < to->lastModified ()) 161 if ( fi.lastModified () < to->lastModified ())
161 saveTodo = true; 162 saveTodo = true;
162 } else { 163 } else {
163 saveTodo = true; 164 saveTodo = true;
164 } 165 }
165 if ( saveTodo ) { 166 if ( saveTodo ) {
166 CalendarLocal cal; 167 CalendarLocal cal;
167 cal.setLocalTime(); 168 cal.setLocalTime();
168 Todo * par = (Todo *) to->clone(); 169 Todo * par = (Todo *) to->clone();
169 cal.addIncidence( par ); 170 cal.addIncidence( par );
170 ICalFormat format; 171 ICalFormat format( false );
171 format.save( &cal, file ); 172 format.save( &cal, file );
172 } 173 }
173 to->saveParents(); 174 to->saveParents();
174} 175}
175 176
176int Todo::runTime() 177int Todo::runTime()
177{ 178{
178 if ( !mRunning ) 179 if ( !mRunning )
179 return 0; 180 return 0;
180 return mRunStart.secsTo( QDateTime::currentDateTime() ); 181 return mRunStart.secsTo( QDateTime::currentDateTime() );
181} 182}
182bool Todo::hasRunningSub() 183bool Todo::hasRunningSub()
183{ 184{
184 if ( mRunning ) 185 if ( mRunning )
185 return true; 186 return true;
186 Incidence *aTodo; 187 Incidence *aTodo;
187 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 188 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
188 if ( ((Todo*)aTodo)->hasRunningSub() ) 189 if ( ((Todo*)aTodo)->hasRunningSub() )
189 return true; 190 return true;
190 } 191 }
191 return false; 192 return false;
192} 193}
193Incidence *Todo::clone() 194Incidence *Todo::clone()
194{ 195{
195 return new Todo(*this); 196 return new Todo(*this);
196} 197}
197 198
198bool Todo::contains ( Todo* from ) 199bool Todo::contains ( Todo* from )
199{ 200{
200 201
201 if ( !from->summary().isEmpty() ) 202 if ( !from->summary().isEmpty() )
202 if ( !summary().startsWith( from->summary() )) 203 if ( !summary().startsWith( from->summary() ))
203 return false; 204 return false;
204 if ( from->hasStartDate() ) { 205 if ( from->hasStartDate() ) {
205 if ( !hasStartDate() ) 206 if ( !hasStartDate() )
206 return false; 207 return false;
207 if ( from->dtStart() != dtStart()) 208 if ( from->dtStart() != dtStart())
208 return false; 209 return false;
209 } 210 }
210 if ( from->hasDueDate() ){ 211 if ( from->hasDueDate() ){
211 if ( !hasDueDate() ) 212 if ( !hasDueDate() )
212 return false; 213 return false;
213 if ( from->dtDue() != dtDue()) 214 if ( from->dtDue() != dtDue())
214 return false; 215 return false;
215 } 216 }
216 if ( !from->location().isEmpty() ) 217 if ( !from->location().isEmpty() )
217 if ( !location().startsWith( from->location() ) ) 218 if ( !location().startsWith( from->location() ) )
218 return false; 219 return false;
219 if ( !from->description().isEmpty() ) 220 if ( !from->description().isEmpty() )
220 if ( !description().startsWith( from->description() )) 221 if ( !description().startsWith( from->description() ))
221 return false; 222 return false;
222 if ( from->alarms().count() ) { 223 if ( from->alarms().count() ) {
223 Alarm *a = from->alarms().first(); 224 Alarm *a = from->alarms().first();
224 if ( a->enabled() ){ 225 if ( a->enabled() ){
225 if ( !alarms().count() ) 226 if ( !alarms().count() )
226 return false; 227 return false;
227 Alarm *b = alarms().first(); 228 Alarm *b = alarms().first();
228 if( ! b->enabled() ) 229 if( ! b->enabled() )
229 return false; 230 return false;
230 if ( ! (a->offset() == b->offset() )) 231 if ( ! (a->offset() == b->offset() ))
231 return false; 232 return false;
232 } 233 }
233 } 234 }
234 235
235 QStringList cat = categories(); 236 QStringList cat = categories();
236 QStringList catFrom = from->categories(); 237 QStringList catFrom = from->categories();
237 QString nCat; 238 QString nCat;
238 unsigned int iii; 239 unsigned int iii;
239 for ( iii = 0; iii < catFrom.count();++iii ) { 240 for ( iii = 0; iii < catFrom.count();++iii ) {
240 nCat = catFrom[iii]; 241 nCat = catFrom[iii];
241 if ( !nCat.isEmpty() ) 242 if ( !nCat.isEmpty() )
242 if ( !cat.contains( nCat )) { 243 if ( !cat.contains( nCat )) {
243 return false; 244 return false;
244 } 245 }
245 } 246 }
246 if ( from->isCompleted() ) { 247 if ( from->isCompleted() ) {
247 if ( !isCompleted() ) 248 if ( !isCompleted() )
248 return false; 249 return false;
249 } 250 }
250 if( priority() != from->priority() ) 251 if( priority() != from->priority() )
251 return false; 252 return false;
252 253
253 254
254 return true; 255 return true;
255 256
256} 257}
257bool KCal::operator==( const Todo& t1, const Todo& t2 ) 258bool KCal::operator==( const Todo& t1, const Todo& t2 )
258{ 259{
259 260
260 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 261 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
261 if ( ! ret ) 262 if ( ! ret )
262 return false; 263 return false;
263 if ( t1.hasDueDate() == t2.hasDueDate() ) { 264 if ( t1.hasDueDate() == t2.hasDueDate() ) {
264 if ( t1.hasDueDate() ) { 265 if ( t1.hasDueDate() ) {
265 if ( t1.doesFloat() == t2.doesFloat() ) { 266 if ( t1.doesFloat() == t2.doesFloat() ) {
266 if ( t1.doesFloat() ) { 267 if ( t1.doesFloat() ) {
267 if ( t1.dtDue().date() != t2.dtDue().date() ) 268 if ( t1.dtDue().date() != t2.dtDue().date() )
268 return false; 269 return false;
269 } else 270 } else
270 if ( t1.dtDue() != t2.dtDue() ) 271 if ( t1.dtDue() != t2.dtDue() )
271 return false; 272 return false;
272 } else 273 } else
273 return false;// float != 274 return false;// float !=
274 } 275 }
275 276
276 } else 277 } else
277 return false; 278 return false;
278 if ( t1.percentComplete() != t2.percentComplete() ) 279 if ( t1.percentComplete() != t2.percentComplete() )
279 return false; 280 return false;
280 if ( t1.isCompleted() ) { 281 if ( t1.isCompleted() ) {
281 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 282 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
282 if ( t1.hasCompletedDate() ) { 283 if ( t1.hasCompletedDate() ) {
283 if ( t1.completed() != t2.completed() ) 284 if ( t1.completed() != t2.completed() )
284 return false; 285 return false;
285 } 286 }
286 287
287 } else 288 } else
288 return false; 289 return false;
289 } 290 }
290 return true; 291 return true;
291 292
292} 293}
293 294
294void Todo::setDtDue(const QDateTime &dtDue) 295void Todo::setDtDue(const QDateTime &dtDue)
295{ 296{
296 //int diffsecs = mDtDue.secsTo(dtDue); 297 //int diffsecs = mDtDue.secsTo(dtDue);
297 298
298 /*if (mReadOnly) return; 299 /*if (mReadOnly) return;
299 const QPtrList<Alarm>& alarms = alarms(); 300 const QPtrList<Alarm>& alarms = alarms();
300 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 301 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
301 if (alarm->enabled()) { 302 if (alarm->enabled()) {
302 alarm->setTime(alarm->time().addSecs(diffsecs)); 303 alarm->setTime(alarm->time().addSecs(diffsecs));
303 } 304 }
304 }*/ 305 }*/
305 mDtDue = getEvenTime(dtDue); 306 mDtDue = getEvenTime(dtDue);
306 307
307 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 308 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
308 309
309 /*const QPtrList<Alarm>& alarms = alarms(); 310 /*const QPtrList<Alarm>& alarms = alarms();
310 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 311 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
311 alarm->setAlarmStart(mDtDue);*/ 312 alarm->setAlarmStart(mDtDue);*/
312 updated(); 313 updated();
313} 314}
314 315
315QDateTime Todo::dtDue() const 316QDateTime Todo::dtDue() const
316{ 317{
317 return mDtDue; 318 return mDtDue;
318} 319}
319 320
320QString Todo::dtDueTimeStr() const 321QString Todo::dtDueTimeStr() const
321{ 322{
322 return KGlobal::locale()->formatTime(mDtDue.time()); 323 return KGlobal::locale()->formatTime(mDtDue.time());
323} 324}
324 325
325QString Todo::dtDueDateStr(bool shortfmt) const 326QString Todo::dtDueDateStr(bool shortfmt) const
326{ 327{
327 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 328 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
328} 329}
329 330
330QString Todo::dtDueStr(bool shortfmt) const 331QString Todo::dtDueStr(bool shortfmt) const
331{ 332{
332 if ( doesFloat() ) 333 if ( doesFloat() )
333 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 334 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
334 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 335 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
335} 336}
336// retval 0 : no found 337// retval 0 : no found
337// 1 : due for date found 338// 1 : due for date found
338// 2 : overdue for date found 339// 2 : overdue for date found
339int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 340int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
340{ 341{
341 int retval = 0; 342 int retval = 0;
342 if ( isCompleted() ) 343 if ( isCompleted() )
343 return 0; 344 return 0;
344 if ( hasDueDate() ) { 345 if ( hasDueDate() ) {
345 if ( dtDue().date() < date ) 346 if ( dtDue().date() < date )
346 return 2; 347 return 2;
347 // we do not return, because we may find an overdue sub todo 348 // we do not return, because we may find an overdue sub todo
348 if ( dtDue().date() == date ) 349 if ( dtDue().date() == date )
349 retval = 1; 350 retval = 1;
350 } 351 }
351 if ( checkSubtodos ) { 352 if ( checkSubtodos ) {
352 Incidence *aTodo; 353 Incidence *aTodo;
353 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 354 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
354 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 355 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
355 if ( ret == 2 ) 356 if ( ret == 2 )
356 return 2; 357 return 2;
357 if ( ret == 1) 358 if ( ret == 1)
358 retval = 1; 359 retval = 1;
359 } 360 }
360 } 361 }
361 return retval; 362 return retval;
362} 363}