296 // Make sure we're focused on an entry. |
296 // Make sure we're focused on an entry. |
297 if (iController.context().instanceId().mEntryLocalUid) { |
297 if (iController.context().instanceId().mEntryLocalUid) { |
298 // Fetch the entry |
298 // Fetch the entry |
299 AgendaEntry entry = iController.Services().agendaInterface()->fetchById( |
299 AgendaEntry entry = iController.Services().agendaInterface()->fetchById( |
300 iController.context().instanceId().mEntryLocalUid); |
300 iController.context().instanceId().mEntryLocalUid); |
301 |
301 // Check if the entry is a To-Do |
302 // Check if the entry is a To-Do |
302 if (AgendaEntry::TypeTodo == entry.type()) { |
303 if (AgendaEntry::TypeTodo == entry.type()) { |
303 showDeleteQuery(EDeleteToDo); |
304 if(!entry.isNull()) { |
304 } else { |
305 showDeleteQuery(entry.type() == AgendaEntry::TypeTodo ? |
305 // Show the repeat entry delete query for repeating entries except Anniversary |
306 EDeleteToDo : |
306 // Even though the anniversary is repeating |
307 EDeleteEntry ); |
307 // all the instances will be deleted |
|
308 if ((entry.isRepeating() || !entry.recurrenceId().isNull()) |
|
309 && (AgendaEntry::TypeAnniversary != entry.type())) { |
|
310 // Show a confirmation note whether the user |
|
311 // wants to delete the single instance or all of them |
|
312 showRepeatingEntryDeleteQuery(); |
|
313 } else { |
|
314 // If the entry is not a repeating entry, |
|
315 // delete it directly |
|
316 // Save the entry for later reference in the slot |
|
317 showDeleteQuery(EDeleteEntry); |
|
318 } |
308 } |
319 } |
309 } |
|
310 else { |
|
311 if (entry.isRepeating() || !entry.recurrenceId().isNull()) { |
|
312 // Show a confirmation note whether the user |
|
313 // wants to delete the single instance or all of them |
|
314 showRepeatingEntryDeleteQuery(); |
|
315 } else { |
|
316 // If the entry is not a repeating entry, |
|
317 // delete it directly |
|
318 // Save the entry for later reference in the slot |
|
319 showDeleteQuery(entry.type() == AgendaEntry::TypeTodo ? |
|
320 EDeleteToDo : |
|
321 EDeleteEntry ); |
|
322 } |
|
323 } |
|
324 } |
320 } |
325 TRACE_EXIT_POINT; |
321 TRACE_EXIT_POINT; |
326 } |
322 } |
327 |
323 |
328 // ---------------------------------------------------------------------------- |
324 // ---------------------------------------------------------------------------- |
378 mDatePicker->setMinimumDate(CalenDateUtils::minTime().date()); |
377 mDatePicker->setMinimumDate(CalenDateUtils::minTime().date()); |
379 mDatePicker->setMaximumDate(currentDate); |
378 mDatePicker->setMaximumDate(currentDate); |
380 mDatePicker->setDate(currentDate); |
379 mDatePicker->setDate(currentDate); |
381 |
380 |
382 popUp->setContentWidget(mDatePicker); |
381 popUp->setContentWidget(mDatePicker); |
383 |
382 mDeleteAction = new HbAction( |
384 popUp->addAction(new HbAction(hbTrId("txt_calendar_button_dialog_delete"))); |
383 hbTrId("txt_calendar_button_dialog_delete"), popUp); |
385 popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"),popUp)); |
384 popUp->addAction(mDeleteAction); |
|
385 mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"),popUp); |
|
386 popUp->addAction(mCancelAction); |
386 // Show the popup |
387 // Show the popup |
387 popUp->open(this, SLOT(handleDateQuery(HbAction*))); |
388 popUp->open(this, SLOT(handleDateQuery(HbAction*))); |
388 } |
389 } |
389 |
390 |
390 // ---------------------------------------------------------------------------- |
391 // ---------------------------------------------------------------------------- |
393 // (other items were commented in a header). |
394 // (other items were commented in a header). |
394 // ---------------------------------------------------------------------------- |
395 // ---------------------------------------------------------------------------- |
395 // |
396 // |
396 void CalenDeleteUi::handleDateQuery(HbAction* action) |
397 void CalenDeleteUi::handleDateQuery(HbAction* action) |
397 { |
398 { |
398 if(action->text() == hbTrId("txt_calendar_button_dialog_delete")) { |
399 if(action == mDeleteAction) { |
399 getSelectedDateAndDelete(); |
400 // User selected the date before which all the entries has to be deleted |
|
401 QDate selectedDate(mDatePicker->date()); |
|
402 // Check if the date is within the range. |
|
403 if(selectedDate.isValid()) { |
|
404 QTime time(0,0,0,0); |
|
405 QDateTime dateTime; |
|
406 dateTime.setDate(selectedDate); |
|
407 dateTime.setTime(time); |
|
408 // Do delete only if inputted day is after beginning of range |
|
409 if(dateTime > AgendaUtil::minTime()) { |
|
410 // Two pass delete: |
|
411 // 1. pass |
|
412 // To prevent destroying entries starting and ending midnight |
|
413 // subtract one second and do delete on that range. |
|
414 dateTime = dateTime.addSecs(-1); |
|
415 dateTime = ( dateTime > AgendaUtil::minTime()? |
|
416 dateTime : AgendaUtil::minTime()); |
|
417 |
|
418 HandleDeleteMultipleEventsL( AgendaUtil::minTime(), |
|
419 dateTime, 1); |
|
420 }else { |
|
421 iController.BroadcastNotification(ECalenNotifyDeleteFailed); |
|
422 } |
|
423 } |
400 }else { |
424 }else { |
|
425 // User pressed cancel |
401 handleDeleteCancel(); |
426 handleDeleteCancel(); |
402 } |
427 } |
|
428 // Reset the member variables |
|
429 mDeleteAction = NULL; |
|
430 mCancelAction = NULL; |
403 } |
431 } |
404 // ---------------------------------------------------------------------------- |
432 // ---------------------------------------------------------------------------- |
405 // CalenDeleteUi::showRepeatingEntryDeleteQuery |
433 // CalenDeleteUi::showRepeatingEntryDeleteQuery |
406 // Launches the popup for deleting the repeating entry |
434 // Launches the popup for deleting the repeating entry |
407 // (other items were commented in a header). |
435 // (other items were commented in a header). |
455 void CalenDeleteUi::handleDeleteCancel() |
483 void CalenDeleteUi::handleDeleteCancel() |
456 { |
484 { |
457 iController.BroadcastNotification(ECalenNotifyDeleteFailed); |
485 iController.BroadcastNotification(ECalenNotifyDeleteFailed); |
458 } |
486 } |
459 |
487 |
460 // ---------------------------------------------------------------------------- |
|
461 // CalenDeleteUi::getSelectedDateAndDelete |
|
462 // Deletes the entries before the selected date |
|
463 // (other items were commented in a header). |
|
464 // ---------------------------------------------------------------------------- |
|
465 // |
|
466 void CalenDeleteUi::getSelectedDateAndDelete() |
|
467 { |
|
468 QDate selectedDate(mDatePicker->date()); |
|
469 |
|
470 // Check if the date is within the range. |
|
471 if(selectedDate.isValid()) { |
|
472 QTime time(0,0,0,0); |
|
473 QDateTime dateTime; |
|
474 dateTime.setDate(selectedDate); |
|
475 dateTime.setTime(time); |
|
476 // Do delete only if inputted day is after beginning of range |
|
477 if(dateTime > AgendaUtil::minTime()) { |
|
478 // Two pass delete: |
|
479 // 1. pass |
|
480 // To prevent destroying entries starting and ending midnight |
|
481 // subtract one second and do delete on that range. |
|
482 dateTime = dateTime.addSecs(-1); |
|
483 dateTime = ( dateTime > AgendaUtil::minTime()? dateTime : AgendaUtil::minTime()); |
|
484 |
|
485 HandleDeleteMultipleEventsL( AgendaUtil::minTime(), dateTime,1 ); |
|
486 }else { |
|
487 iController.BroadcastNotification(ECalenNotifyDeleteFailed); |
|
488 } |
|
489 } |
|
490 } |
|
491 |
|
492 void CalenDeleteUi::handleRepeatedEntryDelete(int index) |
488 void CalenDeleteUi::handleRepeatedEntryDelete(int index) |
493 { |
489 { |
494 // Fetch the entry |
490 // Fetch the entry |
495 // Find all possible instances |
491 // Find all possible instances |
496 AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL( |
492 AgendaEntry instance = CalenActionUiUtils::findPossibleInstanceL( |
497 iController.context().instanceId(), |
493 iController.context().instanceId(), |
498 iController.Services().agendaInterface()); |
494 iController.Services().agendaInterface()); |
499 |
495 |
500 if (!instance.isNull()) { |
496 if (!instance.isNull()) { |
501 connect(iController.Services().agendaInterface(), SIGNAL(entryDeleted(ulong)), |
497 connect(iController.Services().agendaInterface(), |
502 this, SLOT(entryDeleted(ulong))); |
498 SIGNAL(entryDeleted(ulong)), |
503 switch(index) { |
499 this, SLOT(entryDeleted(ulong))); |
504 case 0: |
500 switch(index) { |
505 // User wants to delete only this occurence |
501 case 0: |
506 iController.Services().agendaInterface()->deleteRepeatedEntry(instance, AgendaUtil::ThisOnly); |
502 // User wants to delete only this occurence |
507 break; |
503 iController.Services().agendaInterface()->deleteRepeatedEntry( |
508 case 1: |
504 instance, AgendaUtil::ThisOnly); |
509 // User wants to delete all the occurences |
505 break; |
510 iController.Services().agendaInterface()->deleteRepeatedEntry(instance, AgendaUtil::ThisAndAll); |
506 case 1: |
511 break; |
507 // User wants to delete all the occurences |
512 } |
508 iController.Services().agendaInterface()->deleteRepeatedEntry( |
513 } |
509 instance, AgendaUtil::ThisAndAll); |
|
510 break; |
|
511 } |
|
512 } |
514 } |
513 } |
515 |
514 |
516 // ---------------------------------------------------------------------------- |
515 // ---------------------------------------------------------------------------- |
517 // CalenDeleteUi::showDeleteQuery |
516 // CalenDeleteUi::showDeleteQuery |
518 // Launches the popup for deleting the instance/instances |
517 // Launches the popup for deleting the instance/instances |
562 QList<QAction*> list = popup->actions(); |
560 QList<QAction*> list = popup->actions(); |
563 for(int i=0; i < list.count(); i++) |
561 for(int i=0; i < list.count(); i++) |
564 { |
562 { |
565 popup->removeAction(list[i]); |
563 popup->removeAction(list[i]); |
566 } |
564 } |
567 popup->addAction(new HbAction(hbTrId("txt_calendar_button_delete"), popup)); |
565 mDeleteAction = new HbAction( |
568 popup->addAction(new HbAction( |
566 hbTrId("txt_calendar_button_dialog_delete"), popup); |
569 hbTrId("txt_calendar_button_cancel"), popup)); |
567 popup->addAction(mDeleteAction); |
|
568 mCancelAction = new HbAction(hbTrId("txt_calendar_button_cancel"), popup); |
|
569 popup->addAction(mCancelAction); |
570 popup->open(this, SLOT(handleDeletion(HbAction*))); |
570 popup->open(this, SLOT(handleDeletion(HbAction*))); |
571 } |
571 } |
572 |
572 |
573 // ---------------------------------------------------------------------------- |
573 // ---------------------------------------------------------------------------- |
574 // CalenDeleteUi::handleDeletion |
574 // CalenDeleteUi::handleDeletion |
578 // |
578 // |
579 void CalenDeleteUi::handleDeletion(HbAction* action) |
579 void CalenDeleteUi::handleDeletion(HbAction* action) |
580 { |
580 { |
581 TCalenNotification notification = ECalenNotifyDeleteFailed; |
581 TCalenNotification notification = ECalenNotifyDeleteFailed; |
582 |
582 |
583 if(action->text() == hbTrId("txt_calendar_button_delete")) { |
583 if(action == mDeleteAction) { |
584 |
584 |
585 switch (mDeleteCommand) { |
585 switch (mDeleteCommand) { |
586 |
586 |
587 case ECalenDeleteCurrentEntry: |
587 case ECalenDeleteCurrentEntry: |
588 { |
588 { |
589 // Get the entry |
589 // Get the entry id |
590 AgendaEntry entry = |
590 ulong id = iController.context().instanceId().mEntryLocalUid; |
591 iController.Services().agendaInterface()->fetchById( |
591 connect(iController.Services().agendaInterface(), |
592 iController.context().instanceId().mEntryLocalUid); |
592 SIGNAL(entryDeleted(ulong)), |
|
593 this, SLOT(entryDeleted(ulong))); |
593 // Delete the entry if the delete button is been pressed |
594 // Delete the entry if the delete button is been pressed |
594 iController.Services().agendaInterface()->deleteEntry(entry.id()); |
595 iController.Services().agendaInterface()->deleteEntry(id); |
595 notification = ECalenNotifyEntryDeleted; |
|
596 } |
596 } |
597 break; |
597 break; |
598 |
598 |
599 case ECalenDeleteSeries: |
599 case ECalenDeleteSeries: |
600 case ECalenDeleteCurrentOccurrence: |
600 case ECalenDeleteCurrentOccurrence: |
601 { |
601 { |
602 AgendaEntry instance = |
602 AgendaEntry instance = |
603 CalenActionUiUtils::findPossibleInstanceL( |
603 CalenActionUiUtils::findPossibleInstanceL( |
604 iController.context().instanceId(), |
604 iController.context().instanceId(), |
605 iController.Services().agendaInterface() ); |
605 iController.Services().agendaInterface() ); |
606 QDateTime recId = instance.recurrenceId().toUTC(); |
606 if(!instance.isNull()) { |
607 const bool child = recId.isNull(); |
607 QDateTime recId = instance.recurrenceId().toUTC(); |
608 |
608 const bool child = recId.isNull(); |
609 if( !child || mRecurrenceRange == AgendaUtil::ThisOnly |
609 connect(iController.Services().agendaInterface(), |
610 || mRecurrenceRange == AgendaUtil::ThisAndAll) { |
610 SIGNAL(entryDeleted(ulong)), |
611 iController.Services().agendaInterface()->deleteRepeatedEntry( |
611 this, SLOT(entryDeleted(ulong))); |
612 instance, mRecurrenceRange ); |
612 if( !child || mRecurrenceRange == AgendaUtil::ThisOnly |
|
613 || mRecurrenceRange == AgendaUtil::ThisAndAll) { |
|
614 iController.Services().agendaInterface()->deleteRepeatedEntry( |
|
615 instance, mRecurrenceRange ); |
|
616 } |
613 } |
617 } |
614 notification = ECalenNotifyEntryDeleted; |
|
615 } |
618 } |
616 break; |
619 break; |
617 |
620 |
618 case ECalenDeleteAllEntries: |
621 case ECalenDeleteAllEntries: |
619 { |
622 { |
620 HandleDeleteMultipleEventsL( AgendaUtil::minTime(), |
623 HandleDeleteMultipleEventsL( AgendaUtil::minTime(), |
621 AgendaUtil::maxTime(),1 ); |
624 AgendaUtil::maxTime(),1 ); |
622 notification = ECalenNotifyEntryDeleted; |
|
623 } |
625 } |
624 break; |
626 break; |
625 |
627 |
626 default: |
628 default: |
627 break; |
629 break; |
630 } |
632 } |
631 // If the user presses cancel button the notification will be |
633 // If the user presses cancel button the notification will be |
632 // ECalenNotifyDeleteFailed as default. |
634 // ECalenNotifyDeleteFailed as default. |
633 // Notify the status |
635 // Notify the status |
634 iController.BroadcastNotification(notification); |
636 iController.BroadcastNotification(notification); |
|
637 |
|
638 // Reset the member variables |
|
639 mDeleteAction = NULL; |
|
640 mCancelAction = NULL; |
635 } |
641 } |
636 |
642 |
637 void CalenDeleteUi::entryDeleted(ulong id) |
643 void CalenDeleteUi::entryDeleted(ulong id) |
638 { |
644 { |
639 if (iController.context().instanceId().mEntryLocalUid == id) { |
645 if (iController.context().instanceId().mEntryLocalUid == id) { |
752 // Checking that if entry ends at midnight, is quite clumsy, but here goes: |
759 // Checking that if entry ends at midnight, is quite clumsy, but here goes: |
753 // EndsAtStartOfDay takes only CCalInstance, but here we mimic EndsAtStartOfDay |
760 // EndsAtStartOfDay takes only CCalInstance, but here we mimic EndsAtStartOfDay |
754 // for CCalEntry type. |
761 // for CCalEntry type. |
755 |
762 |
756 // First check that if _instance_ ends at midnight, but starts earlier |
763 // First check that if _instance_ ends at midnight, but starts earlier |
757 if( CalenAgendaUtils::endsAtStartOfDayL( entry, aMidnight ) ) |
764 if( CalenAgendaUtils::endsAtStartOfDay( entry, aMidnight ) ) |
758 { |
765 { |
759 // Second, check that _entry's_ endtime is exactly the midnight |
766 // Second, check that _entry's_ endtime is exactly the midnight |
760 // This prevents us from destroying repeating entries, that has one |
767 // This prevents us from destroying repeating entries, that has one |
761 // instance falling on given midnight. |
768 // instance falling on given midnight. |
762 if( entry.endTime() == aMidnight ) |
769 if( entry.endTime() == aMidnight ) |
829 // For later reference in handleDeletion() |
836 // For later reference in handleDeletion() |
830 mRecurrenceRange = aRepeatType; |
837 mRecurrenceRange = aRepeatType; |
831 |
838 |
832 if( !aHasRepeatType && ( child || repeating ) && |
839 if( !aHasRepeatType && ( child || repeating ) && |
833 ( aInstance.type() != AgendaEntry::TypeAnniversary ) ) { |
840 ( aInstance.type() != AgendaEntry::TypeAnniversary ) ) { |
834 //doDelete = CalenActionUiUtils::ShowRepeatTypeQueryL( aRepeatType, |
841 showRepeatingEntryDeleteQuery(); |
835 // CalenActionUiUtils::EDelete ); |
|
836 } |
842 } |
837 else |
843 else |
838 { |
844 { |
839 showDeleteQuery(aInstance.type() == AgendaEntry::TypeTodo ? |
845 showDeleteQuery(aInstance.type() == AgendaEntry::TypeTodo ? |
840 EDeleteToDo : |
846 EDeleteToDo : |