calendarui/caleneditor/src/caleneditorreminderfield.cpp
changeset 57 bb2d3e476f29
parent 55 2c54b51f39c4
child 63 a3cb48f6c889
equal deleted inserted replaced
55:2c54b51f39c4 57:bb2d3e476f29
    29 #include <hbdialog.h>
    29 #include <hbdialog.h>
    30 #include <hblabel.h>
    30 #include <hblabel.h>
    31 #include <hbaction.h>
    31 #include <hbaction.h>
    32 
    32 
    33 // User Includes
    33 // User Includes
       
    34 #include "calenagendautils.h"
    34 #include "caleneditorreminderfield.h"
    35 #include "caleneditorreminderfield.h"
    35 #include "OstTraceDefinitions.h"
    36 #include "OstTraceDefinitions.h"
    36 #ifdef OST_TRACE_COMPILER_IN_USE
    37 #ifdef OST_TRACE_COMPILER_IN_USE
    37 #include "caleneditorreminderfieldTraces.h"
    38 #include "caleneditorreminderfieldTraces.h"
    38 #endif
    39 #endif
   181 	} else {
   182 	} else {
   182 		// If the alarm is not null,
   183 		// If the alarm is not null,
   183 		// Check if all day event or not and then set the choices accordingly.
   184 		// Check if all day event or not and then set the choices accordingly.
   184 		if (mCalenEditor->editedEntry()->alarm().isNull()) {
   185 		if (mCalenEditor->editedEntry()->alarm().isNull()) {
   185 			// Alarm is set off
   186 			// Alarm is set off
   186 			mReminderItem->setContentWidgetData("currentIndex", 0);
   187 			mReminderItem->setContentWidgetData("currentIndex", ReminderOff);
   187 			if(mReminderTimeAdded) {
   188 			if(mReminderTimeAdded) {
   188 				removeReminderTimeField();
   189 				removeReminderTimeField();
   189 			}
   190 			}
   190 		} else if (mCalenEditor->editedEntry()->type()
   191 		} else if (!mCalenEditor->isAllDayEvent()) {
   191 		        != AgendaEntry::TypeEvent) {
       
   192 			// Get the reminder offset value.
   192 			// Get the reminder offset value.
   193 			int reminderOffset =
   193 			int reminderOffset =
   194 			        mCalenEditor->editedEntry()->alarm().timeOffset();
   194 			        mCalenEditor->editedEntry()->alarm().timeOffset();
   195 			// Get the index value for the reminder combo box from the hash 
   195 			// Get the index value for the reminder combo box from the hash 
   196 			// table.
   196 			// table.
   199 		} else {
   199 		} else {
   200 			// Insert reminder time field and display entry's reminder time.
   200 			// Insert reminder time field and display entry's reminder time.
   201 			// If past then disable the field.
   201 			// If past then disable the field.
   202 			if (!mReminderTimeAdded) {
   202 			if (!mReminderTimeAdded) {
   203 				insertReminderTimeField();
   203 				insertReminderTimeField();
   204 				if (pastEvent) {
   204 			}
   205 					mCustomReminderTimeItem->setEnabled(false);
   205 			if (pastEvent && mReminderTimeAdded) {
   206 				}
   206 				mCustomReminderTimeItem->setEnabled(false);
   207 			}
   207 			}
   208 			QStringList reminderChoicesForAllDay;
   208 			QStringList reminderChoicesForAllDay;
   209 			reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off") 
   209 			reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off") 
   210 					<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   210 					<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   211 					<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before")
   211 					<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before")
   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();
   272 		QDateTime reminderDateTimeForAllDay; 
   272 		QDateTime reminderDateTimeForAllDay; 
   273 		QDateTime
   273 		QDateTime
   274 		        startDateTimeForAllDay(
   274 		        startDateTimeForAllDay(
   275 		                               mCalenEditor->editedEntry()->startTime().date(),
   275 		                               mCalenEditor->editedEntry()->startTime().date(),
   276 		                               QTime(0, 0, 0));
   276 		                               QTime(0, 0, 0));
   277 		if (mReminderItem->contentWidgetData("currentIndex") == 0) {
   277 		if (mReminderItem->contentWidgetData("currentIndex") == ReminderOff) {
   278 			reminder = AgendaAlarm();
   278 			reminder = AgendaAlarm();
   279 			mCustomReminderTimeItem->setEnabled(false);
   279 			removeReminderTimeField();
   280 		} else {
   280 		} else {
   281 			int offset = 0;
   281 			int offset = 0;
   282 			if (mReminderItem->contentWidgetData("currentIndex") == 2) {
   282 			if (mReminderItem->contentWidgetData("currentIndex") == ReminderOneDayBefore) {
   283 				offset = 1;
   283 				offset = 1;
   284 			} else if (mReminderItem->contentWidgetData("currentIndex") == 3) {
   284 			} else if (mReminderItem->contentWidgetData("currentIndex") == ReminderTwoDaysBefore) {
   285 				offset = 2;
   285 				offset = 2;
   286 			}
   286 			}
   287 			if(!mReminderTimeAdded) {
   287 			if(!mReminderTimeAdded) {
   288 				insertReminderTimeField()
   288 				insertReminderTimeField()
   289 ;			}
   289 ;			}
   299 					mCalenEditor->editedEntry()->startTime().date().addDays(
   299 					mCalenEditor->editedEntry()->startTime().date().addDays(
   300 																	-offset));
   300 																	-offset));
   301 			reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay);
   301 			reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay);
   302 			int seconds =
   302 			int seconds =
   303 					reminderDateTimeForAllDay.secsTo(startDateTimeForAllDay);
   303 					reminderDateTimeForAllDay.secsTo(startDateTimeForAllDay);
   304 			int timeOffest = seconds / 60;
   304 			int timeOffset = seconds / 60;
   305 			mCustomReminderTimeItem->setEnabled(true);
   305 			mCustomReminderTimeItem->setEnabled(true);
   306 			reminder.setTimeOffset(timeOffest);
   306 			reminder.setTimeOffset(timeOffset);
   307 			reminder.setAlarmSoundName(QString(" "));
   307 			reminder.setAlarmSoundName(QString(" "));
   308 		}
   308 		}
   309 	}
   309 	}
   310 	// Set the reminder to the entry.
   310 	// Set the reminder to the entry.
   311 	mCalenEditor->editedEntry()->setAlarm(reminder);
   311 	mCalenEditor->editedEntry()->setAlarm(reminder);
   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 }