-rw-r--r-- | libkcal/calendarlocal.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 52c298b..5c889c3 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -109,384 +109,385 @@ bool CalendarLocal::addAnniversaryNoDup( Event *event ) | |||
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | if ( mUndoIncidence ) delete mUndoIncidence; | 155 | if ( mUndoIncidence ) delete mUndoIncidence; |
156 | mUndoIncidence = event->clone(); | 156 | mUndoIncidence = event->clone(); |
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | if ( mUndoIncidence ) delete mUndoIncidence; | 204 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | removeRelations( todo ); | 205 | removeRelations( todo ); |
206 | mUndoIncidence = todo->clone(); | 206 | mUndoIncidence = todo->clone(); |
207 | 207 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 208 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 209 | setModified( true ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 213 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 214 | { |
215 | return mTodoList; | 215 | return mTodoList; |
216 | } | 216 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 218 | { |
219 | Todo *todo; | 219 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 221 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 222 | } |
223 | 223 | ||
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 226 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 227 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 228 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 229 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 230 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 231 | inc->removeID( syncProfile ); |
232 | } | 232 | } |
233 | if ( syncProfile.isEmpty() ) { | 233 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 234 | QPtrList<Event> el; |
235 | Event *todo; | 235 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 238 | el.append( todo ); |
239 | } | 239 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 240 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 241 | deleteIncidence ( todo ); |
242 | } | 242 | } |
243 | } else { | 243 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 244 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | if ( lse ) | 245 | if ( lse ) |
246 | deleteIncidence ( lse ); | 246 | deleteIncidence ( lse ); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
250 | { | 250 | { |
251 | QPtrList<Event> el; | 251 | QPtrList<Event> el; |
252 | Event *todo; | 252 | Event *todo; |
253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
255 | if ( todo->summary().left(3) == "E: " ) | 255 | if ( todo->summary().left(3) == "E: " ) |
256 | el.append( todo ); | 256 | el.append( todo ); |
257 | } | 257 | } |
258 | 258 | ||
259 | return el; | 259 | return el; |
260 | 260 | ||
261 | } | 261 | } |
262 | Event *CalendarLocal::event( QString syncProf, QString id ) | 262 | Event *CalendarLocal::event( QString syncProf, QString id ) |
263 | { | 263 | { |
264 | Event *todo; | 264 | Event *todo; |
265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
266 | if ( todo->getID( syncProf ) == id ) return todo; | 266 | if ( todo->getID( syncProf ) == id ) return todo; |
267 | } | 267 | } |
268 | 268 | ||
269 | return 0; | 269 | return 0; |
270 | } | 270 | } |
271 | Todo *CalendarLocal::todo( const QString &uid ) | 271 | Todo *CalendarLocal::todo( const QString &uid ) |
272 | { | 272 | { |
273 | Todo *todo; | 273 | Todo *todo; |
274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
275 | if ( todo->uid() == uid ) return todo; | 275 | if ( todo->uid() == uid ) return todo; |
276 | } | 276 | } |
277 | 277 | ||
278 | return 0; | 278 | return 0; |
279 | } | 279 | } |
280 | QString CalendarLocal::nextSummary() const | 280 | QString CalendarLocal::nextSummary() const |
281 | { | 281 | { |
282 | return mNextSummary; | 282 | return mNextSummary; |
283 | } | 283 | } |
284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
285 | { | 285 | { |
286 | return mNextAlarmEventDateTime; | 286 | return mNextAlarmEventDateTime; |
287 | } | 287 | } |
288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
289 | { | 289 | { |
290 | //mNextAlarmIncidence | 290 | //mNextAlarmIncidence |
291 | //mNextAlarmDateTime | 291 | //mNextAlarmDateTime |
292 | //return mNextSummary; | 292 | //return mNextSummary; |
293 | //return mNextAlarmEventDateTime; | 293 | //return mNextAlarmEventDateTime; |
294 | bool newNextAlarm = false; | 294 | bool newNextAlarm = false; |
295 | bool computeNextAlarm = false; | 295 | bool computeNextAlarm = false; |
296 | bool ok; | 296 | bool ok; |
297 | int offset; | 297 | int offset; |
298 | QDateTime nextA; | 298 | QDateTime nextA; |
299 | // QString nextSum; | 299 | // QString nextSum; |
300 | //QDateTime nextEvent; | 300 | //QDateTime nextEvent; |
301 | mNextAlarmEventDateTime = QDateTime(); | ||
301 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 302 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
302 | computeNextAlarm = true; | 303 | computeNextAlarm = true; |
303 | } else { | 304 | } else { |
304 | if ( ! deleted ) { | 305 | if ( ! deleted ) { |
305 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 306 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
306 | if ( ok ) { | 307 | if ( ok ) { |
307 | if ( nextA < mNextAlarmDateTime ) { | 308 | if ( nextA < mNextAlarmDateTime ) { |
308 | deRegisterAlarm(); | 309 | deRegisterAlarm(); |
309 | mNextAlarmDateTime = nextA; | 310 | mNextAlarmDateTime = nextA; |
310 | mNextSummary = incidence->summary(); | 311 | mNextSummary = incidence->summary(); |
311 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 312 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
312 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 313 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
313 | newNextAlarm = true; | 314 | newNextAlarm = true; |
314 | mNextAlarmIncidence = incidence; | 315 | mNextAlarmIncidence = incidence; |
315 | } else { | 316 | } else { |
316 | if ( incidence == mNextAlarmIncidence ) { | 317 | if ( incidence == mNextAlarmIncidence ) { |
317 | computeNextAlarm = true; | 318 | computeNextAlarm = true; |
318 | } | 319 | } |
319 | } | 320 | } |
320 | } else { | 321 | } else { |
321 | if ( mNextAlarmIncidence == incidence ) { | 322 | if ( mNextAlarmIncidence == incidence ) { |
322 | computeNextAlarm = true; | 323 | computeNextAlarm = true; |
323 | } | 324 | } |
324 | } | 325 | } |
325 | } else { // deleted | 326 | } else { // deleted |
326 | if ( incidence == mNextAlarmIncidence ) { | 327 | if ( incidence == mNextAlarmIncidence ) { |
327 | computeNextAlarm = true; | 328 | computeNextAlarm = true; |
328 | } | 329 | } |
329 | } | 330 | } |
330 | } | 331 | } |
331 | if ( computeNextAlarm ) { | 332 | if ( computeNextAlarm ) { |
332 | deRegisterAlarm(); | 333 | deRegisterAlarm(); |
333 | nextA = nextAlarm( 1000 ); | 334 | nextA = nextAlarm( 1000 ); |
334 | if (! mNextAlarmIncidence ) { | 335 | if (! mNextAlarmIncidence ) { |
335 | return; | 336 | return; |
336 | } | 337 | } |
337 | newNextAlarm = true; | 338 | newNextAlarm = true; |
338 | } | 339 | } |
339 | if ( newNextAlarm ) | 340 | if ( newNextAlarm ) |
340 | registerAlarm(); | 341 | registerAlarm(); |
341 | } | 342 | } |
342 | QString CalendarLocal:: getAlarmNotification() | 343 | QString CalendarLocal:: getAlarmNotification() |
343 | { | 344 | { |
344 | QString ret; | 345 | QString ret; |
345 | // this should not happen | 346 | // this should not happen |
346 | if (! mNextAlarmIncidence ) | 347 | if (! mNextAlarmIncidence ) |
347 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 348 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
348 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 349 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
349 | if ( alarm->type() == Alarm::Procedure ) { | 350 | if ( alarm->type() == Alarm::Procedure ) { |
350 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 351 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
351 | } else { | 352 | } else { |
352 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 353 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
353 | } | 354 | } |
354 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 355 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
355 | if ( mNextSummary.length() > 25 ) | 356 | if ( mNextSummary.length() > 25 ) |
356 | ret += "\n" + mNextSummary.mid(25, 25 ); | 357 | ret += "\n" + mNextSummary.mid(25, 25 ); |
357 | ret+= "\n"+mNextAlarmEventDateTimeString; | 358 | ret+= "\n"+mNextAlarmEventDateTimeString; |
358 | return ret; | 359 | return ret; |
359 | } | 360 | } |
360 | void CalendarLocal::registerAlarm() | 361 | void CalendarLocal::registerAlarm() |
361 | { | 362 | { |
362 | mLastAlarmNotificationString = getAlarmNotification(); | 363 | mLastAlarmNotificationString = getAlarmNotification(); |
363 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 364 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
364 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 365 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
365 | // #ifndef DESKTOP_VERSION | 366 | // #ifndef DESKTOP_VERSION |
366 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 367 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
367 | // #endif | 368 | // #endif |
368 | } | 369 | } |
369 | void CalendarLocal::deRegisterAlarm() | 370 | void CalendarLocal::deRegisterAlarm() |
370 | { | 371 | { |
371 | if ( mLastAlarmNotificationString.isNull() ) | 372 | if ( mLastAlarmNotificationString.isNull() ) |
372 | return; | 373 | return; |
373 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 374 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
374 | 375 | ||
375 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 376 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
376 | // #ifndef DESKTOP_VERSION | 377 | // #ifndef DESKTOP_VERSION |
377 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 378 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
378 | // #endif | 379 | // #endif |
379 | } | 380 | } |
380 | 381 | ||
381 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 382 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
382 | { | 383 | { |
383 | QPtrList<Todo> todos; | 384 | QPtrList<Todo> todos; |
384 | 385 | ||
385 | Todo *todo; | 386 | Todo *todo; |
386 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 387 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
387 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 388 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
388 | todos.append( todo ); | 389 | todos.append( todo ); |
389 | } | 390 | } |
390 | } | 391 | } |
391 | 392 | ||
392 | filter()->apply( &todos ); | 393 | filter()->apply( &todos ); |
393 | return todos; | 394 | return todos; |
394 | } | 395 | } |
395 | void CalendarLocal::reInitAlarmSettings() | 396 | void CalendarLocal::reInitAlarmSettings() |
396 | { | 397 | { |
397 | if ( !mNextAlarmIncidence ) { | 398 | if ( !mNextAlarmIncidence ) { |
398 | nextAlarm( 1000 ); | 399 | nextAlarm( 1000 ); |
399 | } | 400 | } |
400 | deRegisterAlarm(); | 401 | deRegisterAlarm(); |
401 | mNextAlarmIncidence = 0; | 402 | mNextAlarmIncidence = 0; |
402 | checkAlarmForIncidence( 0, false ); | 403 | checkAlarmForIncidence( 0, false ); |
403 | 404 | ||
404 | } | 405 | } |
405 | 406 | ||
406 | 407 | ||
407 | 408 | ||
408 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 409 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
409 | { | 410 | { |
410 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 411 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
411 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 412 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
412 | QDateTime next; | 413 | QDateTime next; |
413 | Event *e; | 414 | Event *e; |
414 | bool ok; | 415 | bool ok; |
415 | bool found = false; | 416 | bool found = false; |
416 | int offset; | 417 | int offset; |
417 | mNextAlarmIncidence = 0; | 418 | mNextAlarmIncidence = 0; |
418 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 419 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
419 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 420 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
420 | if ( ok ) { | 421 | if ( ok ) { |
421 | if ( next < nextA ) { | 422 | if ( next < nextA ) { |
422 | nextA = next; | 423 | nextA = next; |
423 | found = true; | 424 | found = true; |
424 | mNextSummary = e->summary(); | 425 | mNextSummary = e->summary(); |
425 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 426 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
426 | mNextAlarmIncidence = (Incidence *) e; | 427 | mNextAlarmIncidence = (Incidence *) e; |
427 | } | 428 | } |
428 | } | 429 | } |
429 | } | 430 | } |
430 | Todo *t; | 431 | Todo *t; |
431 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 432 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
432 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 433 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
433 | if ( ok ) { | 434 | if ( ok ) { |
434 | if ( next < nextA ) { | 435 | if ( next < nextA ) { |
435 | nextA = next; | 436 | nextA = next; |
436 | found = true; | 437 | found = true; |
437 | mNextSummary = t->summary(); | 438 | mNextSummary = t->summary(); |
438 | mNextAlarmEventDateTime = next.addSecs(offset ); | 439 | mNextAlarmEventDateTime = next.addSecs(offset ); |
439 | mNextAlarmIncidence = (Incidence *) t; | 440 | mNextAlarmIncidence = (Incidence *) t; |
440 | } | 441 | } |
441 | } | 442 | } |
442 | } | 443 | } |
443 | if ( mNextAlarmIncidence ) { | 444 | if ( mNextAlarmIncidence ) { |
444 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 445 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
445 | mNextAlarmDateTime = nextA; | 446 | mNextAlarmDateTime = nextA; |
446 | } | 447 | } |
447 | return nextA; | 448 | return nextA; |
448 | } | 449 | } |
449 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 450 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
450 | { | 451 | { |
451 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 452 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
452 | } | 453 | } |
453 | 454 | ||
454 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 455 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
455 | { | 456 | { |
456 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 457 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
457 | << to.toString() << ")\n"; | 458 | << to.toString() << ")\n"; |
458 | 459 | ||
459 | Alarm::List alarms; | 460 | Alarm::List alarms; |
460 | 461 | ||
461 | Event *e; | 462 | Event *e; |
462 | 463 | ||
463 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 464 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
464 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 465 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
465 | else appendAlarms( alarms, e, from, to ); | 466 | else appendAlarms( alarms, e, from, to ); |
466 | } | 467 | } |
467 | 468 | ||
468 | Todo *t; | 469 | Todo *t; |
469 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 470 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
470 | appendAlarms( alarms, t, from, to ); | 471 | appendAlarms( alarms, t, from, to ); |
471 | } | 472 | } |
472 | 473 | ||
473 | return alarms; | 474 | return alarms; |
474 | } | 475 | } |
475 | 476 | ||
476 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 477 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
477 | const QDateTime &from, const QDateTime &to ) | 478 | const QDateTime &from, const QDateTime &to ) |
478 | { | 479 | { |
479 | QPtrList<Alarm> alarmList = incidence->alarms(); | 480 | QPtrList<Alarm> alarmList = incidence->alarms(); |
480 | Alarm *alarm; | 481 | Alarm *alarm; |
481 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 482 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
482 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 483 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
483 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 484 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
484 | if ( alarm->enabled() ) { | 485 | if ( alarm->enabled() ) { |
485 | if ( alarm->time() >= from && alarm->time() <= to ) { | 486 | if ( alarm->time() >= from && alarm->time() <= to ) { |
486 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 487 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
487 | << "': " << alarm->time().toString() << endl; | 488 | << "': " << alarm->time().toString() << endl; |
488 | alarms.append( alarm ); | 489 | alarms.append( alarm ); |
489 | } | 490 | } |
490 | } | 491 | } |
491 | } | 492 | } |
492 | } | 493 | } |