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