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