summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-04-10 09:27:53 (UTC)
committer zautrix <zautrix>2005-04-10 09:27:53 (UTC)
commiteda44f28d633f852caebd21a1e375f3e8e91a5cb (patch) (unidiff)
treec7b380b9c742420c6d84b61700f05b72cd6b1d75
parent79b12b680f6a0653bcff84c8ef83b23803246b7d (diff)
downloadkdepimpi-eda44f28d633f852caebd21a1e375f3e8e91a5cb.zip
kdepimpi-eda44f28d633f852caebd21a1e375f3e8e91a5cb.tar.gz
kdepimpi-eda44f28d633f852caebd21a1e375f3e8e91a5cb.tar.bz2
fixxx
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 7906046..19a7ffd 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,370 +1,371 @@
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 26
27#include "calendarlocal.h" 27#include "calendarlocal.h"
28#include "icalformat.h" 28#include "icalformat.h"
29#include "todo.h" 29#include "todo.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33Todo::Todo(): Incidence() 33Todo::Todo(): Incidence()
34{ 34{
35// mStatus = TENTATIVE; 35// mStatus = TENTATIVE;
36 36
37 mHasDueDate = false; 37 mHasDueDate = false;
38 setHasStartDate( false ); 38 setHasStartDate( false );
39 mCompleted = getEvenTime(QDateTime::currentDateTime()); 39 mCompleted = getEvenTime(QDateTime::currentDateTime());
40 mHasCompletedDate = false; 40 mHasCompletedDate = false;
41 mPercentComplete = 0; 41 mPercentComplete = 0;
42 mRunning = false; 42 mRunning = false;
43 mRunSaveTimer = 0; 43 mRunSaveTimer = 0;
44} 44}
45 45
46Todo::Todo(const Todo &t) : Incidence(t) 46Todo::Todo(const Todo &t) : Incidence(t)
47{ 47{
48 mDtDue = t.mDtDue; 48 mDtDue = t.mDtDue;
49 mHasDueDate = t.mHasDueDate; 49 mHasDueDate = t.mHasDueDate;
50 mCompleted = t.mCompleted; 50 mCompleted = t.mCompleted;
51 mHasCompletedDate = t.mHasCompletedDate; 51 mHasCompletedDate = t.mHasCompletedDate;
52 mPercentComplete = t.mPercentComplete; 52 mPercentComplete = t.mPercentComplete;
53 mRunning = false; 53 mRunning = false;
54 mRunSaveTimer = 0; 54 mRunSaveTimer = 0;
55} 55}
56 56
57Todo::~Todo() 57Todo::~Todo()
58{ 58{
59 setRunning( false ); 59 setRunning( false );
60 qDebug("Todo::~Todo() "); 60 //qDebug("Todo::~Todo() ");
61} 61}
62 62
63void Todo::setRunning( bool run ) 63void Todo::setRunning( bool run )
64{ 64{
65 if ( run == mRunning ) 65 if ( run == mRunning )
66 return; 66 return;
67 if ( !mRunSaveTimer ) { 67 if ( !mRunSaveTimer ) {
68 mRunSaveTimer = new QTimer ( this ); 68 mRunSaveTimer = new QTimer ( this );
69 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 69 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
70 } 70 }
71 mRunning = run; 71 mRunning = run;
72 if ( mRunning ) { 72 if ( mRunning ) {
73 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 73 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
74 mRunStart = QDateTime::currentDateTime(); 74 mRunStart = QDateTime::currentDateTime();
75 } else { 75 } else {
76 mRunSaveTimer->stop(); 76 mRunSaveTimer->stop();
77 saveRunningInfoToFile(); 77 saveRunningInfoToFile();
78 } 78 }
79} 79}
80 80
81void Todo::saveRunningInfoToFile() 81void Todo::saveRunningInfoToFile()
82{ 82{
83 qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 83 qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
84 84
85 QString dir = KGlobalSettings::timeTrackerDir(); 85 QString dir = KGlobalSettings::timeTrackerDir();
86 qDebug("%s ", dir.latin1()); 86 qDebug("%s ", dir.latin1());
87 QString file = "%1%2%3-%4%5%6-%7%8%9-"; 87 QString file = "%1%2%3-%4%5%6-";
88 int runtime = mRunStart.secsTo( QDateTime::currentDateTime() ); 88 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 );
89 runtime = (runtime / 60) +1;
90 int h = runtime / 60;
91 int m = runtime % 60;
92 int d = h / 24;
93 h = h % 24;
94 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 ).arg( d,3 ).arg( h,2 ).arg( m,2 );
95 file.replace ( QRegExp (" "), "0" ); 89 file.replace ( QRegExp (" "), "0" );
96 file = dir +"/" +file + uid()+".ics"; 90 file += uid();
97 qDebug("File %s ",file.latin1() ); 91 qDebug("File %s ",file.latin1() );
98 CalendarLocal cal; 92 CalendarLocal cal;
99 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); 93 cal.setTimeZoneId( " 00:00 Europe/London(UTC)" );
100 cal.addIncidence( clone() ); 94 Todo * to = (Todo*) clone();
95 to->setFloats( false );
96 to->setDtStart( mRunStart );
97 to->setHasStartDate( true );
98 to->setDtDue( QDateTime::currentDateTime() );
99 to->setHasDueDate( true );
100 to->setUid( file );
101 cal.addIncidence( to );
101 ICalFormat format; 102 ICalFormat format;
103 file = dir +"/" +file +".ics";
102 format.save( &cal, file ); 104 format.save( &cal, file );
103 105
104} 106}
105 107
106int Todo::runTime() 108int Todo::runTime()
107{ 109{
108 if ( !mRunning ) 110 if ( !mRunning )
109 return 0; 111 return 0;
110 return mRunStart.secsTo( QDateTime::currentDateTime() ); 112 return mRunStart.secsTo( QDateTime::currentDateTime() );
111} 113}
112bool Todo::hasRunningSub() 114bool Todo::hasRunningSub()
113{ 115{
114 if ( mRunning ) 116 if ( mRunning )
115 return true; 117 return true;
116 Incidence *aTodo; 118 Incidence *aTodo;
117 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 119 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
118 if ( ((Todo*)aTodo)->hasRunningSub() ) 120 if ( ((Todo*)aTodo)->hasRunningSub() )
119 return true; 121 return true;
120 } 122 }
121 return false; 123 return false;
122} 124}
123Incidence *Todo::clone() 125Incidence *Todo::clone()
124{ 126{
125 return new Todo(*this); 127 return new Todo(*this);
126} 128}
127 129
128bool Todo::contains ( Todo* from ) 130bool Todo::contains ( Todo* from )
129{ 131{
130 132
131 if ( !from->summary().isEmpty() ) 133 if ( !from->summary().isEmpty() )
132 if ( !summary().startsWith( from->summary() )) 134 if ( !summary().startsWith( from->summary() ))
133 return false; 135 return false;
134 if ( from->hasStartDate() ) { 136 if ( from->hasStartDate() ) {
135 if ( !hasStartDate() ) 137 if ( !hasStartDate() )
136 return false; 138 return false;
137 if ( from->dtStart() != dtStart()) 139 if ( from->dtStart() != dtStart())
138 return false; 140 return false;
139 } 141 }
140 if ( from->hasDueDate() ){ 142 if ( from->hasDueDate() ){
141 if ( !hasDueDate() ) 143 if ( !hasDueDate() )
142 return false; 144 return false;
143 if ( from->dtDue() != dtDue()) 145 if ( from->dtDue() != dtDue())
144 return false; 146 return false;
145 } 147 }
146 if ( !from->location().isEmpty() ) 148 if ( !from->location().isEmpty() )
147 if ( !location().startsWith( from->location() ) ) 149 if ( !location().startsWith( from->location() ) )
148 return false; 150 return false;
149 if ( !from->description().isEmpty() ) 151 if ( !from->description().isEmpty() )
150 if ( !description().startsWith( from->description() )) 152 if ( !description().startsWith( from->description() ))
151 return false; 153 return false;
152 if ( from->alarms().count() ) { 154 if ( from->alarms().count() ) {
153 Alarm *a = from->alarms().first(); 155 Alarm *a = from->alarms().first();
154 if ( a->enabled() ){ 156 if ( a->enabled() ){
155 if ( !alarms().count() ) 157 if ( !alarms().count() )
156 return false; 158 return false;
157 Alarm *b = alarms().first(); 159 Alarm *b = alarms().first();
158 if( ! b->enabled() ) 160 if( ! b->enabled() )
159 return false; 161 return false;
160 if ( ! (a->offset() == b->offset() )) 162 if ( ! (a->offset() == b->offset() ))
161 return false; 163 return false;
162 } 164 }
163 } 165 }
164 166
165 QStringList cat = categories(); 167 QStringList cat = categories();
166 QStringList catFrom = from->categories(); 168 QStringList catFrom = from->categories();
167 QString nCat; 169 QString nCat;
168 unsigned int iii; 170 unsigned int iii;
169 for ( iii = 0; iii < catFrom.count();++iii ) { 171 for ( iii = 0; iii < catFrom.count();++iii ) {
170 nCat = catFrom[iii]; 172 nCat = catFrom[iii];
171 if ( !nCat.isEmpty() ) 173 if ( !nCat.isEmpty() )
172 if ( !cat.contains( nCat )) { 174 if ( !cat.contains( nCat )) {
173 return false; 175 return false;
174 } 176 }
175 } 177 }
176 if ( from->isCompleted() ) { 178 if ( from->isCompleted() ) {
177 if ( !isCompleted() ) 179 if ( !isCompleted() )
178 return false; 180 return false;
179 } 181 }
180 if( priority() != from->priority() ) 182 if( priority() != from->priority() )
181 return false; 183 return false;
182 184
183 185
184 return true; 186 return true;
185 187
186} 188}
187bool KCal::operator==( const Todo& t1, const Todo& t2 ) 189bool KCal::operator==( const Todo& t1, const Todo& t2 )
188{ 190{
189 191
190 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 192 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
191 if ( ! ret ) 193 if ( ! ret )
192 return false; 194 return false;
193 if ( t1.hasDueDate() == t2.hasDueDate() ) { 195 if ( t1.hasDueDate() == t2.hasDueDate() ) {
194 if ( t1.hasDueDate() ) { 196 if ( t1.hasDueDate() ) {
195 if ( t1.doesFloat() == t2.doesFloat() ) { 197 if ( t1.doesFloat() == t2.doesFloat() ) {
196 if ( t1.doesFloat() ) { 198 if ( t1.doesFloat() ) {
197 if ( t1.dtDue().date() != t2.dtDue().date() ) 199 if ( t1.dtDue().date() != t2.dtDue().date() )
198 return false; 200 return false;
199 } else 201 } else
200 if ( t1.dtDue() != t2.dtDue() ) 202 if ( t1.dtDue() != t2.dtDue() )
201 return false; 203 return false;
202 } else 204 } else
203 return false;// float != 205 return false;// float !=
204 } 206 }
205 207
206 } else 208 } else
207 return false; 209 return false;
208 if ( t1.percentComplete() != t2.percentComplete() ) 210 if ( t1.percentComplete() != t2.percentComplete() )
209 return false; 211 return false;
210 if ( t1.isCompleted() ) { 212 if ( t1.isCompleted() ) {
211 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 213 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
212 if ( t1.hasCompletedDate() ) { 214 if ( t1.hasCompletedDate() ) {
213 if ( t1.completed() != t2.completed() ) 215 if ( t1.completed() != t2.completed() )
214 return false; 216 return false;
215 } 217 }
216 218
217 } else 219 } else
218 return false; 220 return false;
219 } 221 }
220 return true; 222 return true;
221 223
222} 224}
223 225
224void Todo::setDtDue(const QDateTime &dtDue) 226void Todo::setDtDue(const QDateTime &dtDue)
225{ 227{
226 //int diffsecs = mDtDue.secsTo(dtDue); 228 //int diffsecs = mDtDue.secsTo(dtDue);
227 229
228 /*if (mReadOnly) return; 230 /*if (mReadOnly) return;
229 const QPtrList<Alarm>& alarms = alarms(); 231 const QPtrList<Alarm>& alarms = alarms();
230 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 232 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
231 if (alarm->enabled()) { 233 if (alarm->enabled()) {
232 alarm->setTime(alarm->time().addSecs(diffsecs)); 234 alarm->setTime(alarm->time().addSecs(diffsecs));
233 } 235 }
234 }*/ 236 }*/
235 mDtDue = getEvenTime(dtDue); 237 mDtDue = getEvenTime(dtDue);
236 238
237 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 239 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
238 240
239 /*const QPtrList<Alarm>& alarms = alarms(); 241 /*const QPtrList<Alarm>& alarms = alarms();
240 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 242 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
241 alarm->setAlarmStart(mDtDue);*/ 243 alarm->setAlarmStart(mDtDue);*/
242
243 updated(); 244 updated();
244} 245}
245 246
246QDateTime Todo::dtDue() const 247QDateTime Todo::dtDue() const
247{ 248{
248 return mDtDue; 249 return mDtDue;
249} 250}
250 251
251QString Todo::dtDueTimeStr() const 252QString Todo::dtDueTimeStr() const
252{ 253{
253 return KGlobal::locale()->formatTime(mDtDue.time()); 254 return KGlobal::locale()->formatTime(mDtDue.time());
254} 255}
255 256
256QString Todo::dtDueDateStr(bool shortfmt) const 257QString Todo::dtDueDateStr(bool shortfmt) const
257{ 258{
258 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 259 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
259} 260}
260 261
261QString Todo::dtDueStr(bool shortfmt) const 262QString Todo::dtDueStr(bool shortfmt) const
262{ 263{
263 if ( doesFloat() ) 264 if ( doesFloat() )
264 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 265 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
265 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 266 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
266} 267}
267// retval 0 : no found 268// retval 0 : no found
268// 1 : due for date found 269// 1 : due for date found
269// 2 : overdue for date found 270// 2 : overdue for date found
270int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 271int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
271{ 272{
272 int retval = 0; 273 int retval = 0;
273 if ( isCompleted() ) 274 if ( isCompleted() )
274 return 0; 275 return 0;
275 if ( hasDueDate() ) { 276 if ( hasDueDate() ) {
276 if ( dtDue().date() < date ) 277 if ( dtDue().date() < date )
277 return 2; 278 return 2;
278 // we do not return, because we may find an overdue sub todo 279 // we do not return, because we may find an overdue sub todo
279 if ( dtDue().date() == date ) 280 if ( dtDue().date() == date )
280 retval = 1; 281 retval = 1;
281 } 282 }
282 if ( checkSubtodos ) { 283 if ( checkSubtodos ) {
283 Incidence *aTodo; 284 Incidence *aTodo;
284 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 285 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
285 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 286 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
286 if ( ret == 2 ) 287 if ( ret == 2 )
287 return 2; 288 return 2;
288 if ( ret == 1) 289 if ( ret == 1)
289 retval = 1; 290 retval = 1;
290 } 291 }
291 } 292 }
292 return retval; 293 return retval;
293} 294}
294int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 295int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
295{ 296{
296 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 297 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
297} 298}
298bool Todo::hasDueDate() const 299bool Todo::hasDueDate() const
299{ 300{
300 return mHasDueDate; 301 return mHasDueDate;
301} 302}
302 303
303void Todo::setHasDueDate(bool f) 304void Todo::setHasDueDate(bool f)
304{ 305{
305 if (mReadOnly) return; 306 if (mReadOnly) return;
306 mHasDueDate = f; 307 mHasDueDate = f;
307 updated(); 308 updated();
308} 309}
309 310
310 311
311#if 0 312#if 0
312void Todo::setStatus(const QString &statStr) 313void Todo::setStatus(const QString &statStr)
313{ 314{
314 if (mReadOnly) return; 315 if (mReadOnly) return;
315 QString ss(statStr.upper()); 316 QString ss(statStr.upper());
316 317
317 if (ss == "X-ACTION") 318 if (ss == "X-ACTION")
318 mStatus = NEEDS_ACTION; 319 mStatus = NEEDS_ACTION;
319 else if (ss == "NEEDS ACTION") 320 else if (ss == "NEEDS ACTION")
320 mStatus = NEEDS_ACTION; 321 mStatus = NEEDS_ACTION;
321 else if (ss == "ACCEPTED") 322 else if (ss == "ACCEPTED")
322 mStatus = ACCEPTED; 323 mStatus = ACCEPTED;
323 else if (ss == "SENT") 324 else if (ss == "SENT")
324 mStatus = SENT; 325 mStatus = SENT;
325 else if (ss == "TENTATIVE") 326 else if (ss == "TENTATIVE")
326 mStatus = TENTATIVE; 327 mStatus = TENTATIVE;
327 else if (ss == "CONFIRMED") 328 else if (ss == "CONFIRMED")
328 mStatus = CONFIRMED; 329 mStatus = CONFIRMED;
329 else if (ss == "DECLINED") 330 else if (ss == "DECLINED")
330 mStatus = DECLINED; 331 mStatus = DECLINED;
331 else if (ss == "COMPLETED") 332 else if (ss == "COMPLETED")
332 mStatus = COMPLETED; 333 mStatus = COMPLETED;
333 else if (ss == "DELEGATED") 334 else if (ss == "DELEGATED")
334 mStatus = DELEGATED; 335 mStatus = DELEGATED;
335 336
336 updated(); 337 updated();
337} 338}
338 339
339void Todo::setStatus(int status) 340void Todo::setStatus(int status)
340{ 341{
341 if (mReadOnly) return; 342 if (mReadOnly) return;
342 mStatus = status; 343 mStatus = status;
343 updated(); 344 updated();
344} 345}
345 346
346int Todo::status() const 347int Todo::status() const
347{ 348{
348 return mStatus; 349 return mStatus;
349} 350}
350 351
351QString Todo::statusStr() const 352QString Todo::statusStr() const
352{ 353{
353 switch(mStatus) { 354 switch(mStatus) {
354 case NEEDS_ACTION: 355 case NEEDS_ACTION:
355 return QString("NEEDS ACTION"); 356 return QString("NEEDS ACTION");
356 break; 357 break;
357 case ACCEPTED: 358 case ACCEPTED:
358 return QString("ACCEPTED"); 359 return QString("ACCEPTED");
359 break; 360 break;
360 case SENT: 361 case SENT:
361 return QString("SENT"); 362 return QString("SENT");
362 break; 363 break;
363 case TENTATIVE: 364 case TENTATIVE:
364 return QString("TENTATIVE"); 365 return QString("TENTATIVE");
365 break; 366 break;
366 case CONFIRMED: 367 case CONFIRMED:
367 return QString("CONFIRMED"); 368 return QString("CONFIRMED");
368 break; 369 break;
369 case DECLINED: 370 case DECLINED:
370 return QString("DECLINED"); 371 return QString("DECLINED");