-rw-r--r-- | libkcal/todo.cpp | 36 | ||||
-rw-r--r-- | libkcal/todo.h | 1 |
2 files changed, 34 insertions, 3 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 90e7eb9..b89abce 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,491 +1,521 @@ | |||
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 | 27 | ||
27 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
28 | #include "icalformat.h" | 29 | #include "icalformat.h" |
29 | #include "todo.h" | 30 | #include "todo.h" |
30 | 31 | ||
31 | using namespace KCal; | 32 | using namespace KCal; |
32 | 33 | ||
33 | Todo::Todo(): Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
34 | { | 35 | { |
35 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
36 | 37 | ||
37 | mHasDueDate = false; | 38 | mHasDueDate = false; |
38 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
39 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
40 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
41 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
42 | mRunning = false; | 43 | mRunning = false; |
43 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
44 | } | 45 | } |
45 | 46 | ||
46 | Todo::Todo(const Todo &t) : Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
47 | { | 48 | { |
48 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
49 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
50 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
51 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
52 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
53 | mRunning = false; | 54 | mRunning = false; |
54 | mRunSaveTimer = 0; | 55 | mRunSaveTimer = 0; |
55 | } | 56 | } |
56 | 57 | ||
57 | Todo::~Todo() | 58 | Todo::~Todo() |
58 | { | 59 | { |
59 | setRunning( false ); | 60 | setRunning( false ); |
60 | //qDebug("Todo::~Todo() "); | 61 | //qDebug("Todo::~Todo() "); |
61 | } | 62 | } |
62 | 63 | ||
63 | void Todo::setRunning( bool run ) | 64 | void Todo::setRunning( bool run ) |
64 | { | 65 | { |
65 | if ( run == mRunning ) | 66 | if ( run == mRunning ) |
66 | return; | 67 | return; |
67 | if ( !mRunSaveTimer ) { | 68 | if ( !mRunSaveTimer ) { |
68 | mRunSaveTimer = new QTimer ( this ); | 69 | mRunSaveTimer = new QTimer ( this ); |
69 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 70 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
70 | } | 71 | } |
71 | mRunning = run; | 72 | mRunning = run; |
72 | if ( mRunning ) { | 73 | if ( mRunning ) { |
73 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 74 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
74 | mRunStart = QDateTime::currentDateTime(); | 75 | mRunStart = QDateTime::currentDateTime(); |
75 | } else { | 76 | } else { |
76 | mRunSaveTimer->stop(); | 77 | mRunSaveTimer->stop(); |
77 | saveRunningInfoToFile(); | 78 | saveRunningInfoToFile(); |
78 | } | 79 | } |
79 | } | 80 | } |
80 | 81 | ||
81 | void Todo::saveRunningInfoToFile() | 82 | void Todo::saveRunningInfoToFile() |
82 | { | 83 | { |
83 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 84 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
84 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) | 85 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
86 | qDebug("Running time < 30 seconds. Skipped. "); | ||
85 | return; | 87 | return; |
88 | } | ||
86 | QString dir = KGlobalSettings::timeTrackerDir(); | 89 | QString dir = KGlobalSettings::timeTrackerDir(); |
87 | //qDebug("%s ", dir.latin1()); | 90 | //qDebug("%s ", dir.latin1()); |
88 | QString file = "%1%2%3-%4%5%6-"; | 91 | QString file = "%1%2%3-%4%5%6-"; |
89 | 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 ); | 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 ); |
90 | file.replace ( QRegExp (" "), "0" ); | 93 | file.replace ( QRegExp (" "), "0" ); |
91 | file += uid(); | 94 | file += uid(); |
92 | //qDebug("File %s ",file.latin1() ); | 95 | //qDebug("File %s ",file.latin1() ); |
93 | CalendarLocal cal; | 96 | CalendarLocal cal; |
94 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 97 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
95 | Todo * to = (Todo*) clone(); | 98 | Todo * to = (Todo*) clone(); |
96 | to->setFloats( false ); | 99 | to->setFloats( false ); |
97 | to->setDtStart( mRunStart ); | 100 | to->setDtStart( mRunStart ); |
98 | to->setHasStartDate( true ); | 101 | to->setHasStartDate( true ); |
99 | to->setDtDue( QDateTime::currentDateTime() ); | 102 | to->setDtDue( QDateTime::currentDateTime() ); |
100 | to->setHasDueDate( true ); | 103 | to->setHasDueDate( true ); |
101 | to->setUid( file ); | 104 | to->setUid( file ); |
102 | cal.addIncidence( to ); | 105 | cal.addIncidence( to ); |
103 | ICalFormat format; | 106 | ICalFormat format; |
104 | file = dir +"/" +file +".ics"; | 107 | file = dir +"/" +file +".ics"; |
105 | format.save( &cal, file ); | 108 | format.save( &cal, file ); |
109 | saveParents(); | ||
106 | 110 | ||
107 | } | 111 | } |
112 | void Todo::saveParents() | ||
113 | { | ||
114 | if (!relatedTo() ) | ||
115 | return; | ||
116 | Incidence * inc = relatedTo(); | ||
117 | if ( inc->type() != "Todo" ) | ||
118 | return; | ||
119 | Todo* to = (Todo*)inc; | ||
120 | bool saveTodo = false; | ||
121 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | ||
122 | QFileInfo fi ( file ); | ||
123 | if ( fi.exists() ) { | ||
124 | if ( fi.lastModified () < to->lastModified ()) | ||
125 | saveTodo = true; | ||
126 | } else { | ||
127 | saveTodo = true; | ||
128 | } | ||
129 | if ( saveTodo ) { | ||
130 | CalendarLocal cal; | ||
131 | cal.setTimeZoneId( " 00:00 Europe/London(UTC)" ); | ||
132 | Todo * par = (Todo *) to->clone(); | ||
133 | cal.addIncidence( par ); | ||
134 | ICalFormat format; | ||
135 | format.save( &cal, file ); | ||
136 | } | ||
137 | } | ||
108 | 138 | ||
109 | int Todo::runTime() | 139 | int Todo::runTime() |
110 | { | 140 | { |
111 | if ( !mRunning ) | 141 | if ( !mRunning ) |
112 | return 0; | 142 | return 0; |
113 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 143 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
114 | } | 144 | } |
115 | bool Todo::hasRunningSub() | 145 | bool Todo::hasRunningSub() |
116 | { | 146 | { |
117 | if ( mRunning ) | 147 | if ( mRunning ) |
118 | return true; | 148 | return true; |
119 | Incidence *aTodo; | 149 | Incidence *aTodo; |
120 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 150 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
121 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 151 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
122 | return true; | 152 | return true; |
123 | } | 153 | } |
124 | return false; | 154 | return false; |
125 | } | 155 | } |
126 | Incidence *Todo::clone() | 156 | Incidence *Todo::clone() |
127 | { | 157 | { |
128 | return new Todo(*this); | 158 | return new Todo(*this); |
129 | } | 159 | } |
130 | 160 | ||
131 | bool Todo::contains ( Todo* from ) | 161 | bool Todo::contains ( Todo* from ) |
132 | { | 162 | { |
133 | 163 | ||
134 | if ( !from->summary().isEmpty() ) | 164 | if ( !from->summary().isEmpty() ) |
135 | if ( !summary().startsWith( from->summary() )) | 165 | if ( !summary().startsWith( from->summary() )) |
136 | return false; | 166 | return false; |
137 | if ( from->hasStartDate() ) { | 167 | if ( from->hasStartDate() ) { |
138 | if ( !hasStartDate() ) | 168 | if ( !hasStartDate() ) |
139 | return false; | 169 | return false; |
140 | if ( from->dtStart() != dtStart()) | 170 | if ( from->dtStart() != dtStart()) |
141 | return false; | 171 | return false; |
142 | } | 172 | } |
143 | if ( from->hasDueDate() ){ | 173 | if ( from->hasDueDate() ){ |
144 | if ( !hasDueDate() ) | 174 | if ( !hasDueDate() ) |
145 | return false; | 175 | return false; |
146 | if ( from->dtDue() != dtDue()) | 176 | if ( from->dtDue() != dtDue()) |
147 | return false; | 177 | return false; |
148 | } | 178 | } |
149 | if ( !from->location().isEmpty() ) | 179 | if ( !from->location().isEmpty() ) |
150 | if ( !location().startsWith( from->location() ) ) | 180 | if ( !location().startsWith( from->location() ) ) |
151 | return false; | 181 | return false; |
152 | if ( !from->description().isEmpty() ) | 182 | if ( !from->description().isEmpty() ) |
153 | if ( !description().startsWith( from->description() )) | 183 | if ( !description().startsWith( from->description() )) |
154 | return false; | 184 | return false; |
155 | if ( from->alarms().count() ) { | 185 | if ( from->alarms().count() ) { |
156 | Alarm *a = from->alarms().first(); | 186 | Alarm *a = from->alarms().first(); |
157 | if ( a->enabled() ){ | 187 | if ( a->enabled() ){ |
158 | if ( !alarms().count() ) | 188 | if ( !alarms().count() ) |
159 | return false; | 189 | return false; |
160 | Alarm *b = alarms().first(); | 190 | Alarm *b = alarms().first(); |
161 | if( ! b->enabled() ) | 191 | if( ! b->enabled() ) |
162 | return false; | 192 | return false; |
163 | if ( ! (a->offset() == b->offset() )) | 193 | if ( ! (a->offset() == b->offset() )) |
164 | return false; | 194 | return false; |
165 | } | 195 | } |
166 | } | 196 | } |
167 | 197 | ||
168 | QStringList cat = categories(); | 198 | QStringList cat = categories(); |
169 | QStringList catFrom = from->categories(); | 199 | QStringList catFrom = from->categories(); |
170 | QString nCat; | 200 | QString nCat; |
171 | unsigned int iii; | 201 | unsigned int iii; |
172 | for ( iii = 0; iii < catFrom.count();++iii ) { | 202 | for ( iii = 0; iii < catFrom.count();++iii ) { |
173 | nCat = catFrom[iii]; | 203 | nCat = catFrom[iii]; |
174 | if ( !nCat.isEmpty() ) | 204 | if ( !nCat.isEmpty() ) |
175 | if ( !cat.contains( nCat )) { | 205 | if ( !cat.contains( nCat )) { |
176 | return false; | 206 | return false; |
177 | } | 207 | } |
178 | } | 208 | } |
179 | if ( from->isCompleted() ) { | 209 | if ( from->isCompleted() ) { |
180 | if ( !isCompleted() ) | 210 | if ( !isCompleted() ) |
181 | return false; | 211 | return false; |
182 | } | 212 | } |
183 | if( priority() != from->priority() ) | 213 | if( priority() != from->priority() ) |
184 | return false; | 214 | return false; |
185 | 215 | ||
186 | 216 | ||
187 | return true; | 217 | return true; |
188 | 218 | ||
189 | } | 219 | } |
190 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 220 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
191 | { | 221 | { |
192 | 222 | ||
193 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 223 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
194 | if ( ! ret ) | 224 | if ( ! ret ) |
195 | return false; | 225 | return false; |
196 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 226 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
197 | if ( t1.hasDueDate() ) { | 227 | if ( t1.hasDueDate() ) { |
198 | if ( t1.doesFloat() == t2.doesFloat() ) { | 228 | if ( t1.doesFloat() == t2.doesFloat() ) { |
199 | if ( t1.doesFloat() ) { | 229 | if ( t1.doesFloat() ) { |
200 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 230 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
201 | return false; | 231 | return false; |
202 | } else | 232 | } else |
203 | if ( t1.dtDue() != t2.dtDue() ) | 233 | if ( t1.dtDue() != t2.dtDue() ) |
204 | return false; | 234 | return false; |
205 | } else | 235 | } else |
206 | return false;// float != | 236 | return false;// float != |
207 | } | 237 | } |
208 | 238 | ||
209 | } else | 239 | } else |
210 | return false; | 240 | return false; |
211 | if ( t1.percentComplete() != t2.percentComplete() ) | 241 | if ( t1.percentComplete() != t2.percentComplete() ) |
212 | return false; | 242 | return false; |
213 | if ( t1.isCompleted() ) { | 243 | if ( t1.isCompleted() ) { |
214 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 244 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
215 | if ( t1.hasCompletedDate() ) { | 245 | if ( t1.hasCompletedDate() ) { |
216 | if ( t1.completed() != t2.completed() ) | 246 | if ( t1.completed() != t2.completed() ) |
217 | return false; | 247 | return false; |
218 | } | 248 | } |
219 | 249 | ||
220 | } else | 250 | } else |
221 | return false; | 251 | return false; |
222 | } | 252 | } |
223 | return true; | 253 | return true; |
224 | 254 | ||
225 | } | 255 | } |
226 | 256 | ||
227 | void Todo::setDtDue(const QDateTime &dtDue) | 257 | void Todo::setDtDue(const QDateTime &dtDue) |
228 | { | 258 | { |
229 | //int diffsecs = mDtDue.secsTo(dtDue); | 259 | //int diffsecs = mDtDue.secsTo(dtDue); |
230 | 260 | ||
231 | /*if (mReadOnly) return; | 261 | /*if (mReadOnly) return; |
232 | const QPtrList<Alarm>& alarms = alarms(); | 262 | const QPtrList<Alarm>& alarms = alarms(); |
233 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 263 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
234 | if (alarm->enabled()) { | 264 | if (alarm->enabled()) { |
235 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 265 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
236 | } | 266 | } |
237 | }*/ | 267 | }*/ |
238 | mDtDue = getEvenTime(dtDue); | 268 | mDtDue = getEvenTime(dtDue); |
239 | 269 | ||
240 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 270 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
241 | 271 | ||
242 | /*const QPtrList<Alarm>& alarms = alarms(); | 272 | /*const QPtrList<Alarm>& alarms = alarms(); |
243 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 273 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
244 | alarm->setAlarmStart(mDtDue);*/ | 274 | alarm->setAlarmStart(mDtDue);*/ |
245 | updated(); | 275 | updated(); |
246 | } | 276 | } |
247 | 277 | ||
248 | QDateTime Todo::dtDue() const | 278 | QDateTime Todo::dtDue() const |
249 | { | 279 | { |
250 | return mDtDue; | 280 | return mDtDue; |
251 | } | 281 | } |
252 | 282 | ||
253 | QString Todo::dtDueTimeStr() const | 283 | QString Todo::dtDueTimeStr() const |
254 | { | 284 | { |
255 | return KGlobal::locale()->formatTime(mDtDue.time()); | 285 | return KGlobal::locale()->formatTime(mDtDue.time()); |
256 | } | 286 | } |
257 | 287 | ||
258 | QString Todo::dtDueDateStr(bool shortfmt) const | 288 | QString Todo::dtDueDateStr(bool shortfmt) const |
259 | { | 289 | { |
260 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 290 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
261 | } | 291 | } |
262 | 292 | ||
263 | QString Todo::dtDueStr(bool shortfmt) const | 293 | QString Todo::dtDueStr(bool shortfmt) const |
264 | { | 294 | { |
265 | if ( doesFloat() ) | 295 | if ( doesFloat() ) |
266 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 296 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
267 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 297 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
268 | } | 298 | } |
269 | // retval 0 : no found | 299 | // retval 0 : no found |
270 | // 1 : due for date found | 300 | // 1 : due for date found |
271 | // 2 : overdue for date found | 301 | // 2 : overdue for date found |
272 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 302 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
273 | { | 303 | { |
274 | int retval = 0; | 304 | int retval = 0; |
275 | if ( isCompleted() ) | 305 | if ( isCompleted() ) |
276 | return 0; | 306 | return 0; |
277 | if ( hasDueDate() ) { | 307 | if ( hasDueDate() ) { |
278 | if ( dtDue().date() < date ) | 308 | if ( dtDue().date() < date ) |
279 | return 2; | 309 | return 2; |
280 | // we do not return, because we may find an overdue sub todo | 310 | // we do not return, because we may find an overdue sub todo |
281 | if ( dtDue().date() == date ) | 311 | if ( dtDue().date() == date ) |
282 | retval = 1; | 312 | retval = 1; |
283 | } | 313 | } |
284 | if ( checkSubtodos ) { | 314 | if ( checkSubtodos ) { |
285 | Incidence *aTodo; | 315 | Incidence *aTodo; |
286 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 316 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
287 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 317 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
288 | if ( ret == 2 ) | 318 | if ( ret == 2 ) |
289 | return 2; | 319 | return 2; |
290 | if ( ret == 1) | 320 | if ( ret == 1) |
291 | retval = 1; | 321 | retval = 1; |
292 | } | 322 | } |
293 | } | 323 | } |
294 | return retval; | 324 | return retval; |
295 | } | 325 | } |
296 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 326 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
297 | { | 327 | { |
298 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 328 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
299 | } | 329 | } |
300 | bool Todo::hasDueDate() const | 330 | bool Todo::hasDueDate() const |
301 | { | 331 | { |
302 | return mHasDueDate; | 332 | return mHasDueDate; |
303 | } | 333 | } |
304 | 334 | ||
305 | void Todo::setHasDueDate(bool f) | 335 | void Todo::setHasDueDate(bool f) |
306 | { | 336 | { |
307 | if (mReadOnly) return; | 337 | if (mReadOnly) return; |
308 | mHasDueDate = f; | 338 | mHasDueDate = f; |
309 | updated(); | 339 | updated(); |
310 | } | 340 | } |
311 | 341 | ||
312 | 342 | ||
313 | #if 0 | 343 | #if 0 |
314 | void Todo::setStatus(const QString &statStr) | 344 | void Todo::setStatus(const QString &statStr) |
315 | { | 345 | { |
316 | if (mReadOnly) return; | 346 | if (mReadOnly) return; |
317 | QString ss(statStr.upper()); | 347 | QString ss(statStr.upper()); |
318 | 348 | ||
319 | if (ss == "X-ACTION") | 349 | if (ss == "X-ACTION") |
320 | mStatus = NEEDS_ACTION; | 350 | mStatus = NEEDS_ACTION; |
321 | else if (ss == "NEEDS ACTION") | 351 | else if (ss == "NEEDS ACTION") |
322 | mStatus = NEEDS_ACTION; | 352 | mStatus = NEEDS_ACTION; |
323 | else if (ss == "ACCEPTED") | 353 | else if (ss == "ACCEPTED") |
324 | mStatus = ACCEPTED; | 354 | mStatus = ACCEPTED; |
325 | else if (ss == "SENT") | 355 | else if (ss == "SENT") |
326 | mStatus = SENT; | 356 | mStatus = SENT; |
327 | else if (ss == "TENTATIVE") | 357 | else if (ss == "TENTATIVE") |
328 | mStatus = TENTATIVE; | 358 | mStatus = TENTATIVE; |
329 | else if (ss == "CONFIRMED") | 359 | else if (ss == "CONFIRMED") |
330 | mStatus = CONFIRMED; | 360 | mStatus = CONFIRMED; |
331 | else if (ss == "DECLINED") | 361 | else if (ss == "DECLINED") |
332 | mStatus = DECLINED; | 362 | mStatus = DECLINED; |
333 | else if (ss == "COMPLETED") | 363 | else if (ss == "COMPLETED") |
334 | mStatus = COMPLETED; | 364 | mStatus = COMPLETED; |
335 | else if (ss == "DELEGATED") | 365 | else if (ss == "DELEGATED") |
336 | mStatus = DELEGATED; | 366 | mStatus = DELEGATED; |
337 | 367 | ||
338 | updated(); | 368 | updated(); |
339 | } | 369 | } |
340 | 370 | ||
341 | void Todo::setStatus(int status) | 371 | void Todo::setStatus(int status) |
342 | { | 372 | { |
343 | if (mReadOnly) return; | 373 | if (mReadOnly) return; |
344 | mStatus = status; | 374 | mStatus = status; |
345 | updated(); | 375 | updated(); |
346 | } | 376 | } |
347 | 377 | ||
348 | int Todo::status() const | 378 | int Todo::status() const |
349 | { | 379 | { |
350 | return mStatus; | 380 | return mStatus; |
351 | } | 381 | } |
352 | 382 | ||
353 | QString Todo::statusStr() const | 383 | QString Todo::statusStr() const |
354 | { | 384 | { |
355 | switch(mStatus) { | 385 | switch(mStatus) { |
356 | case NEEDS_ACTION: | 386 | case NEEDS_ACTION: |
357 | return QString("NEEDS ACTION"); | 387 | return QString("NEEDS ACTION"); |
358 | break; | 388 | break; |
359 | case ACCEPTED: | 389 | case ACCEPTED: |
360 | return QString("ACCEPTED"); | 390 | return QString("ACCEPTED"); |
361 | break; | 391 | break; |
362 | case SENT: | 392 | case SENT: |
363 | return QString("SENT"); | 393 | return QString("SENT"); |
364 | break; | 394 | break; |
365 | case TENTATIVE: | 395 | case TENTATIVE: |
366 | return QString("TENTATIVE"); | 396 | return QString("TENTATIVE"); |
367 | break; | 397 | break; |
368 | case CONFIRMED: | 398 | case CONFIRMED: |
369 | return QString("CONFIRMED"); | 399 | return QString("CONFIRMED"); |
370 | break; | 400 | break; |
371 | case DECLINED: | 401 | case DECLINED: |
372 | return QString("DECLINED"); | 402 | return QString("DECLINED"); |
373 | break; | 403 | break; |
374 | case COMPLETED: | 404 | case COMPLETED: |
375 | return QString("COMPLETED"); | 405 | return QString("COMPLETED"); |
376 | break; | 406 | break; |
377 | case DELEGATED: | 407 | case DELEGATED: |
378 | return QString("DELEGATED"); | 408 | return QString("DELEGATED"); |
379 | break; | 409 | break; |
380 | } | 410 | } |
381 | return QString(""); | 411 | return QString(""); |
382 | } | 412 | } |
383 | #endif | 413 | #endif |
384 | 414 | ||
385 | bool Todo::isCompleted() const | 415 | bool Todo::isCompleted() const |
386 | { | 416 | { |
387 | if (mPercentComplete == 100) { | 417 | if (mPercentComplete == 100) { |
388 | return true; | 418 | return true; |
389 | } | 419 | } |
390 | else return false; | 420 | else return false; |
391 | } | 421 | } |
392 | 422 | ||
393 | void Todo::setCompleted(bool completed) | 423 | void Todo::setCompleted(bool completed) |
394 | { | 424 | { |
395 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 425 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
396 | if ( !setRecurDates() ) | 426 | if ( !setRecurDates() ) |
397 | completed = false; | 427 | completed = false; |
398 | } | 428 | } |
399 | if (completed) mPercentComplete = 100; | 429 | if (completed) mPercentComplete = 100; |
400 | else { | 430 | else { |
401 | mPercentComplete = 0; | 431 | mPercentComplete = 0; |
402 | mHasCompletedDate = false; | 432 | mHasCompletedDate = false; |
403 | } | 433 | } |
404 | updated(); | 434 | updated(); |
405 | } | 435 | } |
406 | 436 | ||
407 | QDateTime Todo::completed() const | 437 | QDateTime Todo::completed() const |
408 | { | 438 | { |
409 | return mCompleted; | 439 | return mCompleted; |
410 | } | 440 | } |
411 | 441 | ||
412 | QString Todo::completedStr( bool shortF ) const | 442 | QString Todo::completedStr( bool shortF ) const |
413 | { | 443 | { |
414 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 444 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
415 | } | 445 | } |
416 | 446 | ||
417 | void Todo::setCompleted(const QDateTime &completed) | 447 | void Todo::setCompleted(const QDateTime &completed) |
418 | { | 448 | { |
419 | //qDebug("Todo::setCompleted "); | 449 | //qDebug("Todo::setCompleted "); |
420 | if ( mHasCompletedDate ) { | 450 | if ( mHasCompletedDate ) { |
421 | // qDebug("has completed data - return "); | 451 | // qDebug("has completed data - return "); |
422 | return; | 452 | return; |
423 | } | 453 | } |
424 | mHasCompletedDate = true; | 454 | mHasCompletedDate = true; |
425 | mPercentComplete = 100; | 455 | mPercentComplete = 100; |
426 | mCompleted = getEvenTime(completed); | 456 | mCompleted = getEvenTime(completed); |
427 | updated(); | 457 | updated(); |
428 | } | 458 | } |
429 | 459 | ||
430 | bool Todo::hasCompletedDate() const | 460 | bool Todo::hasCompletedDate() const |
431 | { | 461 | { |
432 | return mHasCompletedDate; | 462 | return mHasCompletedDate; |
433 | } | 463 | } |
434 | 464 | ||
435 | int Todo::percentComplete() const | 465 | int Todo::percentComplete() const |
436 | { | 466 | { |
437 | return mPercentComplete; | 467 | return mPercentComplete; |
438 | } | 468 | } |
439 | bool Todo::setRecurDates() | 469 | bool Todo::setRecurDates() |
440 | { | 470 | { |
441 | if ( !mHasRecurrenceID ) | 471 | if ( !mHasRecurrenceID ) |
442 | return true; | 472 | return true; |
443 | int secs = mDtStart.secsTo( dtDue() ); | 473 | int secs = mDtStart.secsTo( dtDue() ); |
444 | bool ok; | 474 | bool ok; |
445 | qDebug("T:setRecurDates() "); | 475 | qDebug("T:setRecurDates() "); |
446 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 476 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
447 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 477 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
448 | if ( ok ) { | 478 | if ( ok ) { |
449 | mRecurrenceID = next; | 479 | mRecurrenceID = next; |
450 | mDtStart = next; | 480 | mDtStart = next; |
451 | setDtDue( next.addSecs( secs ) ); | 481 | setDtDue( next.addSecs( secs ) ); |
452 | if ( QDateTime::currentDateTime() > next) | 482 | if ( QDateTime::currentDateTime() > next) |
453 | return false; | 483 | return false; |
454 | } else { | 484 | } else { |
455 | setHasRecurrenceID( false ); | 485 | setHasRecurrenceID( false ); |
456 | recurrence()->unsetRecurs(); | 486 | recurrence()->unsetRecurs(); |
457 | } | 487 | } |
458 | return true; | 488 | return true; |
459 | } | 489 | } |
460 | void Todo::setPercentComplete(int v) | 490 | void Todo::setPercentComplete(int v) |
461 | { | 491 | { |
462 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 492 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
463 | if ( !setRecurDates() ) | 493 | if ( !setRecurDates() ) |
464 | v = 0; | 494 | v = 0; |
465 | } | 495 | } |
466 | mPercentComplete = v; | 496 | mPercentComplete = v; |
467 | if ( v != 100 ) | 497 | if ( v != 100 ) |
468 | mHasCompletedDate = false; | 498 | mHasCompletedDate = false; |
469 | updated(); | 499 | updated(); |
470 | } | 500 | } |
471 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const | 501 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const |
472 | { | 502 | { |
473 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { | 503 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { |
474 | *ok = false; | 504 | *ok = false; |
475 | return QDateTime (); | 505 | return QDateTime (); |
476 | } | 506 | } |
477 | QDateTime incidenceStart; | 507 | QDateTime incidenceStart; |
478 | incidenceStart = dtDue(); | 508 | incidenceStart = dtDue(); |
479 | bool enabled = false; | 509 | bool enabled = false; |
480 | Alarm* alarm; | 510 | Alarm* alarm; |
481 | int off = 0; | 511 | int off = 0; |
482 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 512 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
483 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 513 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
484 | // *ok = false; | 514 | // *ok = false; |
485 | // return incidenceStart; | 515 | // return incidenceStart; |
486 | // } | 516 | // } |
487 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 517 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
488 | if (alarm->enabled()) { | 518 | if (alarm->enabled()) { |
489 | if ( alarm->hasTime () ) { | 519 | if ( alarm->hasTime () ) { |
490 | if ( alarm->time() < alarmStart ) { | 520 | if ( alarm->time() < alarmStart ) { |
491 | alarmStart = alarm->time(); | 521 | alarmStart = alarm->time(); |
diff --git a/libkcal/todo.h b/libkcal/todo.h index fe43357..ec1ffda 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -1,148 +1,149 @@ | |||
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 | #ifndef TODO_H | 20 | #ifndef TODO_H |
21 | #define TODO_H | 21 | #define TODO_H |
22 | // | 22 | // |
23 | // Todo component, representing a VTODO object | 23 | // Todo component, representing a VTODO object |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "incidence.h" | 26 | #include "incidence.h" |
27 | 27 | ||
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | 29 | ||
30 | namespace KCal { | 30 | namespace KCal { |
31 | 31 | ||
32 | /** | 32 | /** |
33 | This class provides a Todo in the sense of RFC2445. | 33 | This class provides a Todo in the sense of RFC2445. |
34 | */ | 34 | */ |
35 | class Todo : public QObject,public Incidence | 35 | class Todo : public QObject,public Incidence |
36 | { | 36 | { |
37 | Q_OBJECT | 37 | Q_OBJECT |
38 | public: | 38 | public: |
39 | Todo(); | 39 | Todo(); |
40 | Todo(const Todo &); | 40 | Todo(const Todo &); |
41 | ~Todo(); | 41 | ~Todo(); |
42 | typedef ListBase<Todo> List; | 42 | typedef ListBase<Todo> List; |
43 | QCString type() const { return "Todo"; } | 43 | QCString type() const { return "Todo"; } |
44 | 44 | ||
45 | /** Return an exact copy of this todo. */ | 45 | /** Return an exact copy of this todo. */ |
46 | Incidence *clone(); | 46 | Incidence *clone(); |
47 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; | 47 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const; |
48 | 48 | ||
49 | /** for setting the todo's due date/time with a QDateTime. */ | 49 | /** for setting the todo's due date/time with a QDateTime. */ |
50 | void setDtDue(const QDateTime &dtDue); | 50 | void setDtDue(const QDateTime &dtDue); |
51 | /** returns an event's Due date/time as a QDateTime. */ | 51 | /** returns an event's Due date/time as a QDateTime. */ |
52 | QDateTime dtDue() const; | 52 | QDateTime dtDue() const; |
53 | /** returns an event's due time as a string formatted according to the | 53 | /** returns an event's due time as a string formatted according to the |
54 | users locale settings */ | 54 | users locale settings */ |
55 | QString dtDueTimeStr() const; | 55 | QString dtDueTimeStr() const; |
56 | /** returns an event's due date as a string formatted according to the | 56 | /** returns an event's due date as a string formatted according to the |
57 | users locale settings */ | 57 | users locale settings */ |
58 | QString dtDueDateStr(bool shortfmt=true) const; | 58 | QString dtDueDateStr(bool shortfmt=true) const; |
59 | /** returns an event's due date and time as a string formatted according | 59 | /** returns an event's due date and time as a string formatted according |
60 | to the users locale settings */ | 60 | to the users locale settings */ |
61 | QString dtDueStr(bool shortfmt=true) const; | 61 | QString dtDueStr(bool shortfmt=true) const; |
62 | 62 | ||
63 | /** returns TRUE or FALSE depending on whether the todo has a due date */ | 63 | /** returns TRUE or FALSE depending on whether the todo has a due date */ |
64 | bool hasDueDate() const; | 64 | bool hasDueDate() const; |
65 | /** sets the event's hasDueDate value. */ | 65 | /** sets the event's hasDueDate value. */ |
66 | void setHasDueDate(bool f); | 66 | void setHasDueDate(bool f); |
67 | 67 | ||
68 | /* | 68 | /* |
69 | Looks for a subtodo (including itself ) which is not complete and is | 69 | Looks for a subtodo (including itself ) which is not complete and is |
70 | - overdue, or | 70 | - overdue, or |
71 | - due today. | 71 | - due today. |
72 | It returns 0 for nothing found, | 72 | It returns 0 for nothing found, |
73 | 1 for found a todo which is due today and no overdue found | 73 | 1 for found a todo which is due today and no overdue found |
74 | 2 for found a overdue todo | 74 | 2 for found a overdue todo |
75 | */ | 75 | */ |
76 | int hasDueSubTodo( bool checkSubtodos = true ); | 76 | int hasDueSubTodo( bool checkSubtodos = true ); |
77 | /* same as above, but a specific date can be specified*/ | 77 | /* same as above, but a specific date can be specified*/ |
78 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); | 78 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); |
79 | 79 | ||
80 | 80 | ||
81 | /** sets the event's status to the string specified. The string | 81 | /** sets the event's status to the string specified. The string |
82 | * must be a recognized value for the status field, i.e. a string | 82 | * must be a recognized value for the status field, i.e. a string |
83 | * equivalent of the possible status enumerations previously described. */ | 83 | * equivalent of the possible status enumerations previously described. */ |
84 | // void setStatus(const QString &statStr); | 84 | // void setStatus(const QString &statStr); |
85 | /** sets the event's status to the value specified. See the enumeration | 85 | /** sets the event's status to the value specified. See the enumeration |
86 | * above for possible values. */ | 86 | * above for possible values. */ |
87 | // void setStatus(int); | 87 | // void setStatus(int); |
88 | /** return the event's status. */ | 88 | /** return the event's status. */ |
89 | // int status() const; | 89 | // int status() const; |
90 | /** return the event's status in string format. */ | 90 | /** return the event's status in string format. */ |
91 | // QString statusStr() const; | 91 | // QString statusStr() const; |
92 | 92 | ||
93 | /** return, if this todo is completed */ | 93 | /** return, if this todo is completed */ |
94 | bool isCompleted() const; | 94 | bool isCompleted() const; |
95 | /** set completed state of this todo */ | 95 | /** set completed state of this todo */ |
96 | void setCompleted(bool); | 96 | void setCompleted(bool); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | Return how many percent of the task are completed. Returns a value | 99 | Return how many percent of the task are completed. Returns a value |
100 | between 0 and 100. | 100 | between 0 and 100. |
101 | */ | 101 | */ |
102 | int percentComplete() const; | 102 | int percentComplete() const; |
103 | /** | 103 | /** |
104 | Set how many percent of the task are completed. Valid values are in the | 104 | Set how many percent of the task are completed. Valid values are in the |
105 | range from 0 to 100. | 105 | range from 0 to 100. |
106 | */ | 106 | */ |
107 | void setPercentComplete(int); | 107 | void setPercentComplete(int); |
108 | 108 | ||
109 | /** return date and time when todo was completed */ | 109 | /** return date and time when todo was completed */ |
110 | QDateTime completed() const; | 110 | QDateTime completed() const; |
111 | QString completedStr(bool shortF = true) const; | 111 | QString completedStr(bool shortF = true) const; |
112 | /** set date and time of completion */ | 112 | /** set date and time of completion */ |
113 | void setCompleted(const QDateTime &completed); | 113 | void setCompleted(const QDateTime &completed); |
114 | 114 | ||
115 | /** Return true, if todo has a date associated with completion */ | 115 | /** Return true, if todo has a date associated with completion */ |
116 | bool hasCompletedDate() const; | 116 | bool hasCompletedDate() const; |
117 | bool contains ( Todo*); | 117 | bool contains ( Todo*); |
118 | void checkSetCompletedFalse(); | 118 | void checkSetCompletedFalse(); |
119 | bool setRecurDates(); | 119 | bool setRecurDates(); |
120 | bool isRunning() {return mRunning;} | 120 | bool isRunning() {return mRunning;} |
121 | bool hasRunningSub(); | 121 | bool hasRunningSub(); |
122 | void setRunning( bool ); | 122 | void setRunning( bool ); |
123 | int runTime(); | 123 | int runTime(); |
124 | QDateTime runStart () const { return mRunStart;} | 124 | QDateTime runStart () const { return mRunStart;} |
125 | public slots: | 125 | public slots: |
126 | void saveRunningInfoToFile(); | 126 | void saveRunningInfoToFile(); |
127 | void saveParents(); | ||
127 | private: | 128 | private: |
128 | bool mRunning; | 129 | bool mRunning; |
129 | QTimer * mRunSaveTimer; | 130 | QTimer * mRunSaveTimer; |
130 | QDateTime mRunStart; | 131 | QDateTime mRunStart; |
131 | bool accept(Visitor &v) { return v.visit(this); } | 132 | bool accept(Visitor &v) { return v.visit(this); } |
132 | 133 | ||
133 | QDateTime mDtDue; // due date of todo | 134 | QDateTime mDtDue; // due date of todo |
134 | 135 | ||
135 | bool mHasDueDate; // if todo has associated due date | 136 | bool mHasDueDate; // if todo has associated due date |
136 | 137 | ||
137 | // int mStatus; // confirmed/delegated/tentative/etc | 138 | // int mStatus; // confirmed/delegated/tentative/etc |
138 | 139 | ||
139 | QDateTime mCompleted; | 140 | QDateTime mCompleted; |
140 | bool mHasCompletedDate; | 141 | bool mHasCompletedDate; |
141 | 142 | ||
142 | int mPercentComplete; | 143 | int mPercentComplete; |
143 | }; | 144 | }; |
144 | 145 | ||
145 | bool operator==( const Todo&, const Todo& ); | 146 | bool operator==( const Todo&, const Todo& ); |
146 | } | 147 | } |
147 | 148 | ||
148 | #endif | 149 | #endif |