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