summaryrefslogtreecommitdiffabout
path: root/libkcal/event.cpp
Unidiff
Diffstat (limited to 'libkcal/event.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/event.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 0766fd9..fdf5657 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -225,192 +225,200 @@ bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime*
225 return false; 225 return false;
226 } 226 }
227 } 227 }
228 Event *nonRecur = 0; 228 Event *nonRecur = 0;
229 Event *recurEvent = 0; 229 Event *recurEvent = 0;
230 if ( ! doesRecur() ) { 230 if ( ! doesRecur() ) {
231 nonRecur = this; 231 nonRecur = this;
232 recurEvent = testEvent; 232 recurEvent = testEvent;
233 } 233 }
234 else if ( !testEvent->doesRecur() ) { 234 else if ( !testEvent->doesRecur() ) {
235 nonRecur = testEvent; 235 nonRecur = testEvent;
236 recurEvent = this; 236 recurEvent = this;
237 } 237 }
238 if ( nonRecur ) { 238 if ( nonRecur ) {
239 QDateTime enr; 239 QDateTime enr;
240 if ( nonRecur->doesFloat() ) 240 if ( nonRecur->doesFloat() )
241 enr = nonRecur->mDtEnd.addDays( 1 ); 241 enr = nonRecur->mDtEnd.addDays( 1 );
242 else 242 else
243 enr = nonRecur->mDtEnd; 243 enr = nonRecur->mDtEnd;
244 if ( enr < recurEvent->mDtStart ) 244 if ( enr < recurEvent->mDtStart )
245 return false; 245 return false;
246 if ( startDT && enr < *startDT ) 246 if ( startDT && enr < *startDT )
247 return false; 247 return false;
248 248
249 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); 249 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd );
250 if ( recurEvent->doesFloat() ) 250 if ( recurEvent->doesFloat() )
251 recDuration += 86400; 251 recDuration += 86400;
252 bool ok = false; 252 bool ok = false;
253 QDateTime recStart; 253 QDateTime recStart;
254 if ( startDT ) { 254 if ( startDT ) {
255 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 255 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
256 } 256 }
257 if ( recStart.isValid() ) { 257 if ( recStart.isValid() ) {
258 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); 258 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1());
259 recStart = recStart.addSecs( -300); 259 recStart = recStart.addSecs( -300);
260 } 260 }
261 else 261 else
262 recStart = recurEvent->mDtStart.addSecs( -300); 262 recStart = recurEvent->mDtStart.addSecs( -300);
263 ok = true; 263 ok = true;
264 264
265 while ( ok ) { 265 while ( ok ) {
266 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); 266 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok );
267 if ( ok ) { 267 if ( ok ) {
268 if ( recStart > enr ) 268 if ( recStart > enr )
269 return false; 269 return false;
270 QDateTime recEnd = recStart.addSecs( recDuration ); 270 QDateTime recEnd = recStart.addSecs( recDuration );
271 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { 271 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) {
272 if ( nonRecur->mDtStart < recStart ) 272 if ( nonRecur->mDtStart < recStart )
273 *overlapDT = recStart; 273 *overlapDT = recStart;
274 else 274 else
275 *overlapDT = nonRecur->mDtStart; 275 *overlapDT = nonRecur->mDtStart;
276 if ( startDT ) { 276 if ( startDT ) {
277 if ( *overlapDT >= *startDT ) 277 if ( *overlapDT >= *startDT )
278 return true; 278 return true;
279 } else 279 } else
280 return true; 280 return true;
281 } 281 }
282 } 282 }
283 } 283 }
284 return false; 284 return false;
285 } 285 }
286 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 286 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
287 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { 287 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) {
288 bool found = false; 288 bool found = false;
289 uint i; 289 uint i;
290 for ( i=0; i< recurrence()->days().size();++i ) { 290 for ( i=0; i< recurrence()->days().size();++i ) {
291 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); 291 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) );
292 } 292 }
293 if ( ! found ) { 293 if ( ! found ) {
294 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); 294 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1());
295 return false; 295 return false;
296 } 296 }
297 297
298 } 298 }
299 } 299 }
300 bool ok = true; 300 bool ok = true;
301 QDateTime incidenceStart;// = mDtStart; 301 QDateTime incidenceStart;// = mDtStart;
302 QDateTime testincidenceStart;// = testEvent->mDtStart; 302 QDateTime testincidenceStart;// = testEvent->mDtStart;
303 if ( startDT ) { 303 if ( startDT ) {
304 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 304 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
305 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 305 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
306 } 306 }
307 if ( !testincidenceStart.isValid() ) 307 if ( !testincidenceStart.isValid() )
308 testincidenceStart = testEvent->mDtStart; 308 testincidenceStart = testEvent->mDtStart;
309 if ( !incidenceStart.isValid() ) 309 if ( !incidenceStart.isValid() )
310 incidenceStart = mDtStart; 310 incidenceStart = mDtStart;
311 int duration = mDtStart.secsTo( mDtEnd ); 311 int duration = mDtStart.secsTo( mDtEnd );
312 if ( doesFloat() ) 312 if ( doesFloat() )
313 duration += 86400; 313 duration += 86400;
314 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); 314 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd );
315 if ( testEvent->doesFloat() ) 315 if ( testEvent->doesFloat() )
316 testduration += 86400; 316 testduration += 86400;
317 bool computeThis = false; 317 bool computeThis = false;
318 if ( incidenceStart < testincidenceStart ) 318 if ( incidenceStart < testincidenceStart )
319 computeThis = true; 319 computeThis = true;
320 if ( computeThis ) 320 if ( computeThis )
321 incidenceStart = incidenceStart.addSecs( -300 ); 321 incidenceStart = incidenceStart.addSecs( -300 );
322 else 322 else
323 testincidenceStart = testincidenceStart.addSecs( -300 ); 323 testincidenceStart = testincidenceStart.addSecs( -300 );
324 int count = 0; 324 int count = 0;
325 ok = true; 325 ok = true;
326 int countbreak = 2000; 326 int countbreak = 2000;
327 QDateTime stopSearch; 327 QDateTime stopSearch;
328 bool testStop = false; 328 bool testStop = false;
329 if ( startDT ) { 329 if ( startDT ) {
330 stopSearch = startDT->addDays( 365*3 ); 330 stopSearch = startDT->addDays( 365*3 );
331 testStop = true; 331 testStop = true;
332 } 332 }
333 while ( ok ) { 333 while ( ok ) {
334 ++count; 334 ++count;
335 if ( count > countbreak ) break; 335 if ( count > countbreak ) break;
336 if ( computeThis ) { 336 if ( computeThis ) {
337 if ( testStop ) 337 if ( testStop )
338 if ( testincidenceStart > stopSearch ) 338 if ( testincidenceStart > stopSearch )
339 break; 339 break;
340 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); 340 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok );
341 } 341 }
342 else { 342 else {
343 if ( testStop ) 343 if ( testStop )
344 if ( incidenceStart > stopSearch ) 344 if ( incidenceStart > stopSearch )
345 break; 345 break;
346 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); 346 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok );
347 } 347 }
348 if ( ok ) { 348 if ( ok ) {
349 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { 349 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) {
350 if ( incidenceStart < testincidenceStart ) 350 if ( incidenceStart < testincidenceStart )
351 *overlapDT = testincidenceStart; 351 *overlapDT = testincidenceStart;
352 else 352 else
353 *overlapDT = incidenceStart; 353 *overlapDT = incidenceStart;
354 if ( startDT ) { 354 if ( startDT ) {
355 if ( *overlapDT >= *startDT ) 355 if ( *overlapDT >= *startDT )
356 return true; 356 return true;
357 } else 357 } else
358 return true; 358 return true;
359 } 359 }
360 computeThis = ( incidenceStart < testincidenceStart ); 360 computeThis = ( incidenceStart < testincidenceStart );
361 } 361 }
362 362
363 } 363 }
364 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); 364 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() );
365 return false; 365 return false;
366} 366}
367QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 367QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
368{ 368{
369 *ok = false; 369 *ok = false;
370 if ( !alarmEnabled() ) 370 if ( !alarmEnabled() )
371 return QDateTime (); 371 return QDateTime ();
372 bool yes; 372 bool yes;
373 QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); 373 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
374 if ( ! yes || cancelled() ) { 374 if ( ! yes || cancelled() ) {
375 *ok = false; 375 *ok = false;
376 return QDateTime (); 376 return QDateTime ();
377 } 377 }
378 378
379 bool enabled = false; 379 bool enabled = false;
380 Alarm* alarm; 380 Alarm* alarm;
381 int off = 0; 381 int off = 0;
382 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 382 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
383 // if ( QDateTime::currentDateTime() > incidenceStart ){ 383 // if ( QDateTime::currentDateTime() > incidenceStart ){
384// *ok = false; 384// *ok = false;
385// return incidenceStart; 385// return incidenceStart;
386// } 386// }
387 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 387 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
388 if (alarm->enabled()) { 388 if (alarm->enabled()) {
389 if ( alarm->hasTime () ) { 389 if ( alarm->hasTime () ) {
390 if ( alarm->time() < alarmStart ) { 390 if ( alarm->time() < alarmStart ) {
391 alarmStart = alarm->time(); 391 alarmStart = alarm->time();
392 enabled = true; 392 enabled = true;
393 off = alarmStart.secsTo( incidenceStart ); 393 off = alarmStart.secsTo( incidenceStart );
394 } 394 }
395 395
396 } else { 396 } else {
397 int secs = alarm->startOffset().asSeconds(); 397 int secs = alarm->startOffset().asSeconds();
398 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 398 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
399 alarmStart = incidenceStart.addSecs( secs ); 399 alarmStart = incidenceStart.addSecs( secs );
400 enabled = true; 400 enabled = true;
401 off = -secs; 401 off = -secs;
402 } 402 }
403 } 403 }
404 } 404 }
405 } 405 }
406 if ( enabled ) { 406 if ( enabled ) {
407 if ( alarmStart > start_dt ) { 407 if ( alarmStart > start_dt ) {
408 *ok = true; 408 *ok = true;
409 * offset = off; 409 * offset = off;
410 return alarmStart; 410 return alarmStart;
411 } 411 }
412 } 412 }
413 *ok = false; 413 *ok = false;
414 return QDateTime (); 414 return QDateTime ();
415 415
416} 416}
417
418QString Event::durationText()
419{
420 int sec = mDtStart.secsTo( mDtEnd );
421 if ( doesFloat() )
422 sec += 86400;
423 return durationText4Time( sec );
424}