215 QTime referenceTime(0, 0, 0); |
215 QTime referenceTime(0, 0, 0); |
216 // Set the appropriate reminder depending on the value of time offset. |
216 // Set the appropriate reminder depending on the value of time offset. |
217 reminder = mCalenEditor->editedEntry()->alarm(); |
217 reminder = mCalenEditor->editedEntry()->alarm(); |
218 int offsetInMins = reminder.timeOffset(); |
218 int offsetInMins = reminder.timeOffset(); |
219 if (offsetInMins < 0 || offsetInMins == 0) { |
219 if (offsetInMins < 0 || offsetInMins == 0) { |
220 mReminderItem->setContentWidgetData("currentIndex", 1); |
220 mReminderItem->setContentWidgetData("currentIndex", ReminderOnEventDay); |
221 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
221 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
222 * 60)); |
222 * 60)); |
223 } else if (offsetInMins < numberOfMinutesInADay) { |
223 } else if (offsetInMins < numberOfMinutesInADay) { |
224 mReminderItem->setContentWidgetData("currentIndex", 2); |
224 mReminderItem->setContentWidgetData("currentIndex", ReminderOneDayBefore); |
225 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
225 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
226 * 60)); |
226 * 60)); |
227 } else { |
227 } else { |
228 mReminderItem->setContentWidgetData("currentIndex", 3); |
228 mReminderItem->setContentWidgetData("currentIndex", ReminderTwoDaysBefore); |
229 offsetInMins %= (24 * 60); |
229 offsetInMins %= (24 * 60); |
230 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
230 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
231 * 60)); |
231 * 60)); |
232 } |
232 } |
233 setDisplayTime(); |
233 setDisplayTime(); |
381 } |
381 } |
382 QStringList reminderChoicesForAllDay; |
382 QStringList reminderChoicesForAllDay; |
383 QDate tomorrow = QDate::currentDate().addDays(1); |
383 QDate tomorrow = QDate::currentDate().addDays(1); |
384 QDate theDayAfterTomorrow = QDate::currentDate().addDays(2); |
384 QDate theDayAfterTomorrow = QDate::currentDate().addDays(2); |
385 |
385 |
|
386 // Get the previous index to retain if the alarm is valid |
|
387 QVariant countVariant = mReminderItem->contentWidgetData("currentIndex"); |
|
388 int previousIndex = countVariant.toInt(); |
|
389 AgendaAlarm previousAlarm = mCalenEditor->editedEntry()->alarm(); |
|
390 |
|
391 // Update the reminder choices only if the alarm set is not valid |
|
392 // Get the alarm offset to check for the validity |
|
393 int offset = mCalenEditor->editedEntry()->alarm().timeOffset(); |
|
394 bool update = true; |
|
395 |
|
396 // Calculate the alarm time |
|
397 QDateTime refDateTime; |
|
398 refDateTime.setDate(referenceDate); |
|
399 refDateTime.setTime(mCalenEditor->editedEntry()->startTime().time()); |
|
400 QTime checkTime = refDateTime.time().addSecs(-(offset * 60)); |
|
401 refDateTime.setTime(checkTime); |
|
402 // Check for valid alarm offset |
|
403 if(offset >= 0) { |
|
404 // If the alarm which was already set is valid, |
|
405 // then dont update the reminder choices |
|
406 if ((refDateTime > QDateTime::currentDateTime()) || |
|
407 (refDateTime.date() == QDate::currentDate() && ( |
|
408 refDateTime.time() > QTime::currentTime()))) { |
|
409 update = false; |
|
410 } |
|
411 } |
|
412 // If the event is on a past date the default alarm will be off. |
386 if (referenceDate < QDate::currentDate() || |
413 if (referenceDate < QDate::currentDate() || |
387 referenceDate == QDate::currentDate()) { |
414 referenceDate == QDate::currentDate()) { |
388 // Set reminder off for past event. |
415 // Set reminder off for past event. |
389 reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off"); |
416 reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off"); |
390 mReminderItem->setContentWidgetData(QString("items"), |
417 mReminderItem->setContentWidgetData(QString("items"), |
391 reminderChoicesForAllDay); |
418 reminderChoicesForAllDay); |
392 mReminderItem->setEnabled(false); |
419 mReminderItem->setEnabled(false); |
393 removeReminderTimeField(); |
420 // Remove the reminder field if it was added |
|
421 if(mReminderTimeAdded) { |
|
422 removeReminderTimeField(); |
|
423 } |
394 } else if (theDayAfterTomorrow < referenceDate || |
424 } else if (theDayAfterTomorrow < referenceDate || |
395 theDayAfterTomorrow == referenceDate) { |
425 theDayAfterTomorrow == referenceDate) { |
|
426 // If the event is on a future date which is two days after the current date |
|
427 // The options are off, on event day, 1 day before and 2 days before |
396 reminderChoicesForAllDay |
428 reminderChoicesForAllDay |
397 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
429 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
398 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
430 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
399 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before") |
431 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before") |
400 << hbTrId("txt_calendar_setlabel_reminder_val_2_days_before"); |
432 << hbTrId("txt_calendar_setlabel_reminder_val_2_days_before"); |
401 mReminderItem->setEnabled(true); |
433 mReminderItem->setEnabled(true); |
402 mCustomReminderTimeItem->setEnabled(true); |
434 mCustomReminderTimeItem->setEnabled(true); |
403 } else { |
435 mReminderItem->setContentWidgetData(QString("items"), |
|
436 reminderChoicesForAllDay); |
|
437 } else if (QTime::currentTime() < QTime(18, 0, 0, 0)) { |
|
438 // If the event is on a future date which is one day after the current date |
|
439 // and current time is before 6.00 pm. |
|
440 // The options are off, on event day and 1 day before |
404 reminderChoicesForAllDay |
441 reminderChoicesForAllDay |
405 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
442 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
406 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
443 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
407 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before"); |
444 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before"); |
408 mReminderItem->setEnabled(true); |
445 mReminderItem->setEnabled(true); |
409 mCustomReminderTimeItem->setEnabled(true); |
446 mCustomReminderTimeItem->setEnabled(true); |
410 } |
|
411 if (mReminderItem->isEnabled()) { |
|
412 mReminderItem->setContentWidgetData(QString("items"), |
447 mReminderItem->setContentWidgetData(QString("items"), |
413 reminderChoicesForAllDay); |
448 reminderChoicesForAllDay); |
414 } |
449 }else { |
|
450 // If the event is on a future date which is one day after the current date |
|
451 // and current time is after 6.00 pm. |
|
452 // The options are off and on event day |
|
453 reminderChoicesForAllDay |
|
454 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
455 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day"); |
|
456 mReminderItem->setEnabled(true); |
|
457 mCustomReminderTimeItem->setEnabled(true); |
|
458 mReminderItem->setContentWidgetData(QString("items"), |
|
459 reminderChoicesForAllDay); |
|
460 } |
|
461 // Set the proper index based on the validity of the previous index |
|
462 int count = reminderItemsCount(); |
|
463 // By default, in case of reminder updation, its been agreed to set |
|
464 // ReminderOneDayBefore even though ReminderTwoDaysBefore holds good |
|
465 // If the ReminderOneDayBefore option is available set it or |
|
466 // else set it to ReminderOff |
|
467 if(count > ReminderOneDayBefore) { |
|
468 // Don't make the reminder off since |
|
469 // the valid reminder options are there in the combobox |
|
470 // So check for ReminderOff is needed |
|
471 if (update && |
|
472 (previousIndex == ReminderOff || previousIndex >= ReminderOneDayBefore)) { |
|
473 // If the index has to be updated check the previous index value |
|
474 // And set the default reminder as 1 day before. |
|
475 mReminderItem->setContentWidgetData("currentIndex", |
|
476 ReminderOneDayBefore); |
|
477 }else { |
|
478 // Set the previous index since the alarm is valid |
|
479 mReminderItem->setContentWidgetData("currentIndex", previousIndex); |
|
480 // Set the previous alarm also as the value will be changed to default value |
|
481 // when the current index is been changed |
|
482 mCalenEditor->editedEntry()->setAlarm(previousAlarm); |
|
483 // Get the alarm time from the offset |
|
484 QTime alarmTime = refDateTime.time(); |
|
485 // Set the alarm time and display it on the button |
|
486 mReminderTimeForAllDay.setHMS( |
|
487 alarmTime.hour(),alarmTime.minute(),alarmTime.second()); |
|
488 setDisplayTime(); |
|
489 } |
|
490 }else { |
|
491 // Enters this condition if the previous index set is not valid or |
|
492 // the index is ReminderOff |
|
493 mReminderItem->setContentWidgetData("currentIndex", ReminderOff); |
|
494 } |
|
495 |
415 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_EXIT ); |
496 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_EXIT ); |
416 } |
497 } |
417 |
498 |
418 /*! |
499 /*! |
419 Insert the reminder time field for an all day event. |
500 Insert the reminder time field for an all day event. |
483 Launches time picker to select time. |
564 Launches time picker to select time. |
484 */ |
565 */ |
485 void CalenEditorReminderField::launchReminderTimePicker() |
566 void CalenEditorReminderField::launchReminderTimePicker() |
486 { |
567 { |
487 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_ENTRY ); |
568 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_ENTRY ); |
488 mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay); |
569 |
489 mTimePicker->setTime(mReminderTimeForAllDay); |
|
490 HbDialog *popUp = new HbDialog(); |
570 HbDialog *popUp = new HbDialog(); |
491 popUp->setDismissPolicy(HbDialog::NoDismiss); |
571 popUp->setDismissPolicy(HbDialog::NoDismiss); |
492 popUp->setTimeout(HbDialog::NoTimeout); |
572 popUp->setTimeout(HbDialog::NoTimeout); |
|
573 popUp->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
574 popUp->setHeadingWidget( new HbLabel( |
|
575 hbTrId("Reminder Time"))); |
|
576 |
|
577 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
578 mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay); |
|
579 if(locale.timeStyle() == HbExtendedLocale::Time12) { |
|
580 mTimePicker->setDisplayFormat("hh:mm ap"); |
|
581 }else { |
|
582 mTimePicker->setDisplayFormat("hh:mm"); |
|
583 } |
|
584 mTimePicker->setTime(mReminderTimeForAllDay); |
493 popUp->setContentWidget(mTimePicker); |
585 popUp->setContentWidget(mTimePicker); |
494 popUp->setHeadingWidget( new HbLabel( |
586 |
495 hbTrId("Reminder Time"))); |
587 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp); |
496 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok")); |
|
497 popUp->addAction(okAction); |
588 popUp->addAction(okAction); |
498 connect(okAction, SIGNAL(triggered()), this, SLOT(setReminderTimeForAllDay())); |
589 connect(okAction, SIGNAL(triggered()), this, SLOT(setReminderTimeForAllDay())); |
499 connect(okAction, SIGNAL(triggered()), popUp, SLOT(close())); |
|
500 popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), |
590 popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), |
501 popUp)); |
591 popUp)); |
502 popUp->open(); |
592 popUp->open(); |
503 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_EXIT ); |
593 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_EXIT ); |
504 } |
594 } |