diff -r 579cc610882e -r ef813d54df51 calendarui/caleneditor/src/caleneditorreminderfield.cpp --- a/calendarui/caleneditor/src/caleneditorreminderfield.cpp Tue Jul 06 14:14:56 2010 +0300 +++ b/calendarui/caleneditor/src/caleneditorreminderfield.cpp Wed Aug 18 09:47:38 2010 +0300 @@ -31,7 +31,13 @@ #include // User Includes +#include "calenagendautils.h" #include "caleneditorreminderfield.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "caleneditorreminderfieldTraces.h" +#endif + #define numberOfMinutesInADay 1440 /*! @@ -52,9 +58,10 @@ mCalenEditor(calenEditor), mEditorForm(form), mCalenEditorModel(model), - mCustomReminderTimeItem(NULL), + mCustomReminderTimeItem(0), mReminderTimeAdded(false) { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_ENTRY ); mReminderItem = new HbDataFormModelItem(); mReminderItem->setType(HbDataFormModelItem::ComboBoxItem); mReminderItem->setData(HbDataFormModelItem::LabelRole, @@ -62,6 +69,7 @@ // Add it to the model mCalenEditorModel->appendDataFormItem(mReminderItem, mCalenEditorModel->invisibleRootItem()); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_EXIT ); } /*! @@ -69,9 +77,11 @@ */ CalenEditorReminderField::~CalenEditorReminderField() { + OstTraceFunctionEntry0( DUP1_CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_ENTRY ); if(mReminderHash.count()) { mReminderHash.clear(); } + OstTraceFunctionExit0( DUP1_CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_EXIT ); } /*! @@ -79,6 +89,7 @@ */ void CalenEditorReminderField::setReminderChoices() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_ENTRY ); // Create the reminder choices QStringList reminderChoices; reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off") @@ -87,7 +98,8 @@ << hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo") << hbTrId("txt_calendar_setlabel_reminder_val_1_hour_before"); - mReminderItem->setContentWidgetData(QString("items"), reminderChoices); + mReminderItem->setContentWidgetData("items", reminderChoices); + mReminderItem->setContentWidgetData("objectName", "remainderItem"); // Build the hash map for the reminder. mReminderHash[0] = -1; // OFF. @@ -96,6 +108,7 @@ mReminderHash[3] = 30; mReminderHash[4] = 60; mReminderItem->setEnabled(true); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_EXIT ); } /*! @@ -103,9 +116,11 @@ */ void CalenEditorReminderField::addItemToModel() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_ADDITEMTOMODEL_ENTRY ); // Add reminder to the model mCalenEditorModel->appendDataFormItem( mReminderItem, mCalenEditorModel->invisibleRootItem()); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_ADDITEMTOMODEL_EXIT ); } /*! @@ -113,7 +128,9 @@ */ void CalenEditorReminderField::removeItemFromModel() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMOVEITEMFROMMODEL_ENTRY ); mCalenEditorModel->removeItem(modelIndex()); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMOVEITEMFROMMODEL_EXIT ); } /*! @@ -122,6 +139,7 @@ */ void CalenEditorReminderField::populateReminderItem(bool newEntry) { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_ENTRY ); AgendaAlarm reminder; bool pastEvent = false; @@ -166,12 +184,11 @@ // Check if all day event or not and then set the choices accordingly. if (mCalenEditor->editedEntry()->alarm().isNull()) { // Alarm is set off - mReminderItem->setContentWidgetData("currentIndex", 0); + mReminderItem->setContentWidgetData("currentIndex", ReminderOff); if(mReminderTimeAdded) { removeReminderTimeField(); } - } else if (mCalenEditor->editedEntry()->type() - != AgendaEntry::TypeEvent) { + } else if (!mCalenEditor->isAllDayEvent()) { // Get the reminder offset value. int reminderOffset = mCalenEditor->editedEntry()->alarm().timeOffset(); @@ -184,9 +201,9 @@ // If past then disable the field. if (!mReminderTimeAdded) { insertReminderTimeField(); - if (pastEvent) { - mCustomReminderTimeItem->setEnabled(false); - } + } + if (pastEvent && mReminderTimeAdded) { + mCustomReminderTimeItem->setEnabled(false); } QStringList reminderChoicesForAllDay; reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off") @@ -200,15 +217,15 @@ reminder = mCalenEditor->editedEntry()->alarm(); int offsetInMins = reminder.timeOffset(); if (offsetInMins < 0 || offsetInMins == 0) { - mReminderItem->setContentWidgetData("currentIndex", 1); + mReminderItem->setContentWidgetData("currentIndex", ReminderOnEventDay); mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins * 60)); } else if (offsetInMins < numberOfMinutesInADay) { - mReminderItem->setContentWidgetData("currentIndex", 2); + mReminderItem->setContentWidgetData("currentIndex", ReminderOneDayBefore); mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins * 60)); } else { - mReminderItem->setContentWidgetData("currentIndex", 3); + mReminderItem->setContentWidgetData("currentIndex", ReminderTwoDaysBefore); offsetInMins %= (24 * 60); mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins * 60)); @@ -222,6 +239,7 @@ mEditorForm->addConnection(mReminderItem, SIGNAL(currentIndexChanged(int)), this, SLOT(handleReminderIndexChanged(int))); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_EXIT ); } /*! @@ -231,6 +249,7 @@ */ void CalenEditorReminderField::handleReminderIndexChanged(int index) { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_HANDLEREMINDERINDEXCHANGED_ENTRY ); AgendaAlarm reminder; if (!mCalenEditor->editedEntry()->alarm().isNull()) { reminder = mCalenEditor->editedEntry()->alarm(); @@ -255,14 +274,14 @@ startDateTimeForAllDay( mCalenEditor->editedEntry()->startTime().date(), QTime(0, 0, 0)); - if (mReminderItem->contentWidgetData("currentIndex") == 0) { + if (mReminderItem->contentWidgetData("currentIndex") == ReminderOff) { reminder = AgendaAlarm(); - mCustomReminderTimeItem->setEnabled(false); + removeReminderTimeField(); } else { int offset = 0; - if (mReminderItem->contentWidgetData("currentIndex") == 2) { + if (mReminderItem->contentWidgetData("currentIndex") == ReminderOneDayBefore) { offset = 1; - } else if (mReminderItem->contentWidgetData("currentIndex") == 3) { + } else if (mReminderItem->contentWidgetData("currentIndex") == ReminderTwoDaysBefore) { offset = 2; } if(!mReminderTimeAdded) { @@ -282,17 +301,18 @@ reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay); int seconds = reminderDateTimeForAllDay.secsTo(startDateTimeForAllDay); - int timeOffest = seconds / 60; + int timeOffset = seconds / 60; mCustomReminderTimeItem->setEnabled(true); - reminder.setTimeOffset(timeOffest); + reminder.setTimeOffset(timeOffset); reminder.setAlarmSoundName(QString(" ")); } } // Set the reminder to the entry. mCalenEditor->editedEntry()->setAlarm(reminder); if(!mCalenEditor->isNewEntry()) { - mCalenEditor->addDiscardAction(); + mCalenEditor->addDiscardAction(); } + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_HANDLEREMINDERINDEXCHANGED_EXIT ); } /*! @@ -301,6 +321,7 @@ */ QModelIndex CalenEditorReminderField::modelIndex() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_MODELINDEX_ENTRY ); return mCalenEditorModel->indexFromItem(mReminderItem); } @@ -309,11 +330,13 @@ */ void CalenEditorReminderField::setReminderOff() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDEROFF_ENTRY ); // Create the remindar choices QStringList reminderChoices; reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off"); mReminderItem->setContentWidgetData(QString("items"), reminderChoices); mReminderItem->setEnabled(false); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDEROFF_EXIT ); } /*! @@ -321,12 +344,13 @@ */ void CalenEditorReminderField::setDefaultAlarmForAllDay() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETDEFAULTALARMFORALLDAY_ENTRY ); // Set default alarm if its a new entry. if (mCalenEditor->isNewEntry()) { AgendaAlarm reminder; QDate defaultDate (mCalenEditor->editedEntry()->startTime().date().addDays(-1)); - // Set default time. + // Set default time as 6pm of the previous day. mReminderTimeForAllDay.setHMS(18, 0, 0, 0); setDisplayTime(); QDateTime startDateTimeForAllDay( @@ -342,6 +366,7 @@ mCalenEditor->editedEntry()->setAlarm(reminder); mCalenEditor->originalEntry()->setAlarm(reminder); } + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETDEFAULTALARMFORALLDAY_EXIT ); } /*! @@ -350,6 +375,7 @@ */ void CalenEditorReminderField::updateReminderChoicesForAllDay(QDate referenceDate) { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_ENTRY ); if (!mReminderTimeAdded){ insertReminderTimeField(); } @@ -357,16 +383,48 @@ QDate tomorrow = QDate::currentDate().addDays(1); QDate theDayAfterTomorrow = QDate::currentDate().addDays(2); + // Get the previous index to retain if the alarm is valid + QVariant countVariant = mReminderItem->contentWidgetData("currentIndex"); + int previousIndex = countVariant.toInt(); + AgendaAlarm previousAlarm = mCalenEditor->editedEntry()->alarm(); + + // Update the reminder choices only if the alarm set is not valid + // Get the alarm offset to check for the validity + int offset = mCalenEditor->editedEntry()->alarm().timeOffset(); + bool update = true; + + // Calculate the alarm time + QDateTime refDateTime; + refDateTime.setDate(referenceDate); + refDateTime.setTime(mCalenEditor->editedEntry()->startTime().time()); + QTime checkTime = refDateTime.time().addSecs(-(offset * 60)); + refDateTime.setTime(checkTime); + // Check for valid alarm offset + if(offset >= 0) { + // If the alarm which was already set is valid, + // then dont update the reminder choices + if ((refDateTime > QDateTime::currentDateTime()) || + (refDateTime.date() == QDate::currentDate() && ( + refDateTime.time() > QTime::currentTime()))) { + update = false; + } + } + // If the event is on a past date the default alarm will be off. if (referenceDate < QDate::currentDate() || referenceDate == QDate::currentDate()) { // Set reminder off for past event. reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off"); mReminderItem->setContentWidgetData(QString("items"), reminderChoicesForAllDay); - mReminderItem->setEnabled(false); - removeReminderTimeField(); + mReminderItem->setEnabled(false); + // Remove the reminder field if it was added + if(mReminderTimeAdded) { + removeReminderTimeField(); + } } else if (theDayAfterTomorrow < referenceDate || theDayAfterTomorrow == referenceDate) { + // If the event is on a future date which is two days after the current date + // The options are off, on event day, 1 day before and 2 days before reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off") << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") @@ -374,18 +432,68 @@ << hbTrId("txt_calendar_setlabel_reminder_val_2_days_before"); mReminderItem->setEnabled(true); mCustomReminderTimeItem->setEnabled(true); - } else { + mReminderItem->setContentWidgetData(QString("items"), + reminderChoicesForAllDay); + } else if (QTime::currentTime() < QTime(18, 0, 0, 0)) { + // If the event is on a future date which is one day after the current date + // and current time is before 6.00 pm. + // The options are off, on event day and 1 day before reminderChoicesForAllDay - << hbTrId("txt_calendar_setlabel_reminder_val_off") - << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") - << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before"); + << hbTrId("txt_calendar_setlabel_reminder_val_off") + << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") + << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before"); + mReminderItem->setEnabled(true); + mCustomReminderTimeItem->setEnabled(true); + mReminderItem->setContentWidgetData(QString("items"), + reminderChoicesForAllDay); + }else { + // If the event is on a future date which is one day after the current date + // and current time is after 6.00 pm. + // The options are off and on event day + reminderChoicesForAllDay + << hbTrId("txt_calendar_setlabel_reminder_val_off") + << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day"); mReminderItem->setEnabled(true); mCustomReminderTimeItem->setEnabled(true); + mReminderItem->setContentWidgetData(QString("items"), + reminderChoicesForAllDay); } - if (mReminderItem->isEnabled()) { - mReminderItem->setContentWidgetData(QString("items"), - reminderChoicesForAllDay); + // Set the proper index based on the validity of the previous index + int count = reminderItemsCount(); + // By default, in case of reminder updation, its been agreed to set + // ReminderOneDayBefore even though ReminderTwoDaysBefore holds good + // If the ReminderOneDayBefore option is available set it or + // else set it to ReminderOff + if(count > ReminderOneDayBefore) { + // Don't make the reminder off since + // the valid reminder options are there in the combobox + // So check for ReminderOff is needed + if (update && + (previousIndex == ReminderOff || previousIndex >= ReminderOneDayBefore)) { + // If the index has to be updated check the previous index value + // And set the default reminder as 1 day before. + mReminderItem->setContentWidgetData("currentIndex", + ReminderOneDayBefore); + }else { + // Set the previous index since the alarm is valid + mReminderItem->setContentWidgetData("currentIndex", previousIndex); + // Set the previous alarm also as the value will be changed to default value + // when the current index is been changed + mCalenEditor->editedEntry()->setAlarm(previousAlarm); + // Get the alarm time from the offset + QTime alarmTime = refDateTime.time(); + // Set the alarm time and display it on the button + mReminderTimeForAllDay.setHMS( + alarmTime.hour(),alarmTime.minute(),alarmTime.second()); + setDisplayTime(); + } + }else { + // Enters this condition if the previous index set is not valid or + // the index is ReminderOff + mReminderItem->setContentWidgetData("currentIndex", ReminderOff); } + + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_EXIT ); } /*! @@ -393,6 +501,7 @@ */ void CalenEditorReminderField::insertReminderTimeField() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_INSERTREMINDERTIMEFIELD_ENTRY ); HbDataFormModelItem::DataItemType itemType = static_cast (ReminderTimeOffset); @@ -416,6 +525,7 @@ this, SLOT(launchReminderTimePicker())); setDisplayTime(); mReminderTimeAdded = true; + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_INSERTREMINDERTIMEFIELD_EXIT ); } /*! @@ -423,11 +533,13 @@ */ void CalenEditorReminderField::setDisplayTime() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETDISPLAYTIME_ENTRY ); HbExtendedLocale locale = HbExtendedLocale::system(); QString timeString = locale.format( mReminderTimeForAllDay, r_qtn_time_usual_with_zero); mCustomReminderTimeItem->setContentWidgetData("text", timeString); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETDISPLAYTIME_EXIT ); } /*! @@ -435,6 +547,7 @@ */ void CalenEditorReminderField::removeReminderTimeField() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMOVEREMINDERTIMEFIELD_ENTRY ); mReminderTimeAdded = false; if (mCustomReminderTimeItem) { QModelIndex reminderIndex = @@ -442,8 +555,9 @@ mCalenEditorModel->removeItem( mCalenEditorModel->index( reminderIndex.row(), 0)); - mCustomReminderTimeItem = NULL; + mCustomReminderTimeItem = 0; } + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMOVEREMINDERTIMEFIELD_EXIT ); } /*! @@ -451,21 +565,32 @@ */ void CalenEditorReminderField::launchReminderTimePicker() { - mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay); - mTimePicker->setTime(mReminderTimeForAllDay); + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_ENTRY ); + HbDialog *popUp = new HbDialog(); popUp->setDismissPolicy(HbDialog::NoDismiss); popUp->setTimeout(HbDialog::NoTimeout); - popUp->setContentWidget(mTimePicker); + popUp->setAttribute( Qt::WA_DeleteOnClose, true ); popUp->setHeadingWidget( new HbLabel( - hbTrId("Reminder Time"))); - HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok")); + hbTrId("Reminder Time"))); + + HbExtendedLocale locale = HbExtendedLocale::system(); + mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay); + if(locale.timeStyle() == HbExtendedLocale::Time12) { + mTimePicker->setDisplayFormat("hh:mm ap"); + }else { + mTimePicker->setDisplayFormat("hh:mm"); + } + mTimePicker->setTime(mReminderTimeForAllDay); + popUp->setContentWidget(mTimePicker); + + HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp); popUp->addAction(okAction); connect(okAction, SIGNAL(triggered()), this, SLOT(setReminderTimeForAllDay())); - connect(okAction, SIGNAL(triggered()), popUp, SLOT(close())); popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popUp)); popUp->open(); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_EXIT ); } /*! @@ -473,12 +598,14 @@ */ void CalenEditorReminderField::setReminderTimeForAllDay() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_ENTRY ); mReminderTimeForAllDay = mTimePicker->time(); if (mReminderTimeForAllDay.isValid()) { // Change the time displayed to that selected by the user. setDisplayTime(); handleReminderIndexChanged(currentReminderIndex()); } + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_EXIT ); } /*! @@ -486,6 +613,7 @@ */ bool CalenEditorReminderField::isReminderFieldEnabled() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_ISREMINDERFIELDENABLED_ENTRY ); return mReminderItem->isEnabled(); } @@ -494,9 +622,11 @@ */ int CalenEditorReminderField::reminderItemsCount() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMINDERITEMSCOUNT_ENTRY ); QVariant strings = mReminderItem->contentWidgetData("items"); QStringList stringList(strings.toStringList()); int count = stringList.count(); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMINDERITEMSCOUNT_EXIT ); return count; } @@ -505,8 +635,10 @@ */ int CalenEditorReminderField::currentReminderIndex() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_CURRENTREMINDERINDEX_ENTRY ); QVariant countVariant = mReminderItem->contentWidgetData("currentIndex"); int index = countVariant.toInt(); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_CURRENTREMINDERINDEX_EXIT ); return index; } @@ -516,7 +648,9 @@ */ void CalenEditorReminderField::setCurrentIndex(int index) { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETCURRENTINDEX_ENTRY ); mReminderItem->setContentWidgetData("currentIndex", index); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETCURRENTINDEX_EXIT ); } /*! @@ -524,9 +658,11 @@ */ void CalenEditorReminderField::disableReminderTimeField() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_DISABLEREMINDERTIMEFIELD_ENTRY ); if (mReminderTimeAdded) { mCustomReminderTimeItem->setEnabled(false); } + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_DISABLEREMINDERTIMEFIELD_EXIT ); } /*! @@ -534,6 +670,8 @@ */ bool CalenEditorReminderField::isReminderTimeForAllDayAdded() { + OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_ISREMINDERTIMEFORALLDAYADDED_ENTRY ); + OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_ISREMINDERTIMEFORALLDAYADDED_EXIT ); return mReminderTimeAdded; }