calendarui/caleneditor/src/caleneditorreminderfield.cpp
changeset 68 a5a1242fd2e8
parent 58 ef813d54df51
child 77 b0711afde476
equal deleted inserted replaced
58:ef813d54df51 68:a5a1242fd2e8
    88 	 Set the reminder choices.
    88 	 Set the reminder choices.
    89  */
    89  */
    90 void CalenEditorReminderField::setReminderChoices()
    90 void CalenEditorReminderField::setReminderChoices()
    91 {
    91 {
    92 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_ENTRY );
    92 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_ENTRY );
       
    93 	
       
    94 	// Disconnect the slot and connect it back again at end to avoid unnecessary
       
    95 	// calls to handleReminderIndexChanged slot. Or else the slot gets called 
       
    96 	// when we add all of items to the repeat combobox.
       
    97 	mEditorForm->removeConnection(mReminderItem,
       
    98 							SIGNAL(currentIndexChanged(int)), this,
       
    99 							SLOT(handleReminderIndexChanged(int)));
    93 	// Create the reminder choices
   100 	// Create the reminder choices
    94 	QStringList reminderChoices;
   101 	QStringList reminderChoices;
    95 	reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off")
   102 	reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off")
    96 				<< hbTrId("txt_calendar_setlabel_reminder_val_at_the_start")
   103 				<< hbTrId("txt_calendar_setlabel_reminder_val_at_the_start")
    97 				<< hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo")
   104 				<< hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo")
    98 				<< hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo")
   105 				<< hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo")
    99 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_hour_before");
   106 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_hour_before");
   100 
   107 
   101 	mReminderItem->setContentWidgetData("items", reminderChoices);
   108 	mReminderItem->setContentWidgetData("items", reminderChoices);
   102 	mReminderItem->setContentWidgetData("objectName", "remainderItem");
       
   103 
       
   104 	// Build the hash map for the reminder.
       
   105 	mReminderHash[0] = -1; // OFF.
       
   106 	mReminderHash[1] = 0;
       
   107 	mReminderHash[2] = 15;
       
   108 	mReminderHash[3] = 30;
       
   109 	mReminderHash[4] = 60;
       
   110 	mReminderItem->setEnabled(true);
   109 	mReminderItem->setEnabled(true);
       
   110 	
       
   111 	mEditorForm->addConnection(mReminderItem,
       
   112 							SIGNAL(currentIndexChanged(int)), this,
       
   113 							SLOT(handleReminderIndexChanged(int)));
   111 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_EXIT );
   114 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_EXIT );
   112 }
   115 }
   113 
   116 
   114 /*!
   117 /*!
   115 	 Adds reminder item to the model
   118 	 Adds reminder item to the model
   132 	mCalenEditorModel->removeItem(modelIndex());
   135 	mCalenEditorModel->removeItem(modelIndex());
   133 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMOVEITEMFROMMODEL_EXIT );
   136 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMOVEITEMFROMMODEL_EXIT );
   134 }
   137 }
   135 
   138 
   136 /*!
   139 /*!
       
   140 	 Set the current reminder index with the value which was saved 
       
   141 	 before, if it is valid or else default the value to 15MinsBefore
       
   142 	 or AtTheStart whichever is appropriate
       
   143  */
       
   144 void CalenEditorReminderField::setSavedMeetingReminderIndex()
       
   145 {
       
   146 	// Get the reminder offset value.
       
   147 	int reminderOffset =
       
   148 	mCalenEditor->editedEntry()->alarm().timeOffset();
       
   149 	// Get the index value for the reminder combo box from the hash 
       
   150 	// table. 2nd argument is defaultKey if the hash contains no item mapped to value
       
   151 	//TODO: Need to confirm the default reminder to set if none of the choices are met like in case of synch from outlook.
       
   152 	int index = mReminderHash.key(reminderOffset, Reminder15MinsBefore); 
       
   153 	
       
   154 	if (index < reminderItemsCount())
       
   155 		setCurrentIndex(index);
       
   156 	else if (reminderItemsCount() == (ReminderAtStart + 1)) //+1 because enum starts from 0.
       
   157 		setCurrentIndex(ReminderAtStart); 
       
   158 	else
       
   159 		setCurrentIndex(Reminder15MinsBefore);
       
   160 }
       
   161 
       
   162 /*!
   137 	 Populates reminder item with available choices to the user
   163 	 Populates reminder item with available choices to the user
   138 	 \param newEntry bool value to indicate if its a new entry
   164 	 \param newEntry bool value to indicate if its a new entry
   139  */
   165  */
   140 void CalenEditorReminderField::populateReminderItem(bool newEntry)
   166 void CalenEditorReminderField::populateReminderItem(bool newEntry)
   141 {
   167 {
   142 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_ENTRY );
   168 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_ENTRY );
   143 	AgendaAlarm reminder;
   169 	AgendaAlarm reminder;
   144 	bool pastEvent =  false;
   170 	bool pastEvent =  false;
   145 	
   171 	bool repeatingEntry = false;
       
   172 	bool sameDay = false;
       
   173 	
       
   174 	mReminderItem->setContentWidgetData("objectName", "remainderItem");
       
   175 	// Build the hash map for the reminder.
       
   176 	mReminderHash[ReminderOff] = -1; // OFF.
       
   177 	mReminderHash[ReminderAtStart] = 0;
       
   178 	mReminderHash[Reminder15MinsBefore] = 15;
       
   179 	mReminderHash[Reminder30MinsBefore] = 30;
       
   180 	mReminderHash[Reminder1HourBefore] = 60;
       
   181 	    
   146 	// Set reference date to start date or repeat until date accordingly to 
   182 	// Set reference date to start date or repeat until date accordingly to 
   147 	// decide whether its a past event or not.
   183 	// decide whether its a past event or not.
   148 	QDate referenceDate;
   184 	QDate referenceDate;
   149 	if (!mCalenEditor->editedEntry()->isRepeating() || 
   185 	if (!mCalenEditor->editedEntry()->isRepeating() || 
   150 					(mCalenEditor->isEditRangeThisOnly())) {
   186 					(mCalenEditor->isEditRangeThisOnly())) {
   151 		referenceDate = mCalenEditor->editedEntry()->startTime().date();
   187 		referenceDate = mCalenEditor->editedEntry()->startTime().date();
   152 	} else {
   188 	} else {
   153 		referenceDate = mCalenEditor->editedEntry()->repeatRule().until().date();
   189 		referenceDate = mCalenEditor->editedEntry()->repeatRule().until().date();
       
   190 		repeatingEntry = true;
   154 	}
   191 	}
   155 	
   192 	
   156 	if ((referenceDate < QDate::currentDate()) || 
   193 	if ((referenceDate < QDate::currentDate()) || 
   157 					(referenceDate == QDate::currentDate()
   194 					(referenceDate == QDate::currentDate()
   158 					&& (mCalenEditor->editedEntry()->startTime().time() < 
   195 					&& (mCalenEditor->editedEntry()->startTime().time() < 
   161 	}
   198 	}
   162 	
   199 	
   163 	if (mCalenEditor->isAllDayEvent()) {
   200 	if (mCalenEditor->isAllDayEvent()) {
   164 		updateReminderChoicesForAllDay(referenceDate);
   201 		updateReminderChoicesForAllDay(referenceDate);
   165 	} else {
   202 	} else {
       
   203 		if((referenceDate == QDate::currentDate())
       
   204 					&& !pastEvent) {
       
   205 			UpdateReminderChoicesForSameDay(mCalenEditor->editedEntry()->startTime().time());
       
   206 			sameDay = true;
       
   207 		}
       
   208 		else {
   166 		setReminderChoices();
   209 		setReminderChoices();
       
   210 		}
   167 	}
   211 	}
   168 	// Set the default reminder value to 15 minutes 
   212 	// Set the default reminder value to 15 minutes 
   169 	if (newEntry) {
   213 	if (newEntry) {
   170 		if (!pastEvent) {
   214 		if (!pastEvent) {
   171 			mReminderItem->setContentWidgetData("currentIndex", 2);
   215 			int defaultIndex = Reminder15MinsBefore;
       
   216 			if (reminderItemsCount() == (ReminderAtStart + 1))  //If 15MinsBefore option is not available
       
   217 				defaultIndex = ReminderAtStart;
       
   218 		
       
   219 			setCurrentIndex(defaultIndex);
   172 			// Save the reminder alarm for the entry
   220 			// Save the reminder alarm for the entry
   173 			reminder.setTimeOffset(mReminderHash.value(2));
   221 			reminder.setTimeOffset(mReminderHash.value(defaultIndex));
   174 			reminder.setAlarmSoundName(QString(" "));
   222 			reminder.setAlarmSoundName(QString(" "));
   175 			// Set the reminder to the entry as well as original entry.
   223 			// Set the reminder to the entry as well as original entry.
   176 			mCalenEditor->editedEntry()->setAlarm(reminder);
   224 			mCalenEditor->editedEntry()->setAlarm(reminder);
   177 			mCalenEditor->originalEntry()->setAlarm(reminder);
   225 			mCalenEditor->originalEntry()->setAlarm(reminder);
   178 		} else {
   226 		} else {
   179 			mReminderItem->setContentWidgetData("currentIndex", 0);
   227 			setReminderOff();
   180 			mReminderItem->setEnabled(false);
       
   181 		}
   228 		}
   182 	} else {
   229 	} else {
       
   230         int offsetInMins = mCalenEditor->editedEntry()->alarm().timeOffset();
   183 		// If the alarm is not null,
   231 		// If the alarm is not null,
   184 		// Check if all day event or not and then set the choices accordingly.
   232 		// Check if all day event or not and then set the choices accordingly.
   185 		if (mCalenEditor->editedEntry()->alarm().isNull()) {
   233 		if (mCalenEditor->editedEntry()->alarm().isNull()) {
   186 			// Alarm is set off
   234 			// Alarm is set off
   187 			mReminderItem->setContentWidgetData("currentIndex", ReminderOff);
   235 			setCurrentIndex(ReminderOff);
   188 			if(mReminderTimeAdded) {
   236 			if(mReminderTimeAdded) {
   189 				removeReminderTimeField();
   237 				removeReminderTimeField();
   190 			}
   238 			}
   191 		} else if (!mCalenEditor->isAllDayEvent()) {
   239 		} else if (!mCalenEditor->isAllDayEvent()) {
   192 			// Get the reminder offset value.
   240 			QTime currentTime = QTime::currentTime();
   193 			int reminderOffset =
   241 
   194 			        mCalenEditor->editedEntry()->alarm().timeOffset();
   242 			//TODO: Still need confirmation for proper behaviour when entry is edited after alarm has expired.
   195 			// Get the index value for the reminder combo box from the hash 
   243 			if (!repeatingEntry && sameDay && (currentTime.addSecs(offsetInMins * 60) >= mCalenEditor->editedEntry()->startTime().time())) {
   196 			// table.
   244 				setCurrentIndex(ReminderOff); //Alarm has expired already, so making it off.
   197 			int index = mReminderHash.key(reminderOffset);
   245 				//The slot for index 0 is not called, since after UpdateReminderChoicesForSameDay()
   198 			mReminderItem->setContentWidgetData("currentIndex", index);
   246 				//index is 0 itself and there is no change. So explicitly calling it here.
       
   247 				handleReminderIndexChanged(0); 
       
   248 			}
       
   249 			else {
       
   250 				setSavedMeetingReminderIndex();
       
   251 			}
   199 		} else {
   252 		} else {
   200 			// Insert reminder time field and display entry's reminder time.
   253 			// Insert reminder time field and display entry's reminder time.
   201 			// If past then disable the field.
   254 			// If past then disable the field.
   202 			if (!mReminderTimeAdded) {
   255 			if (!mReminderTimeAdded) {
   203 				insertReminderTimeField();
   256 				insertReminderTimeField();
   204 			}
   257 			}
   205 			if (pastEvent && mReminderTimeAdded) {
   258 			if (pastEvent && mReminderTimeAdded) {
   206 				mCustomReminderTimeItem->setEnabled(false);
   259 				mCustomReminderTimeItem->setEnabled(false);
   207 			}
   260 			}
   208 			QStringList reminderChoicesForAllDay;
   261 			// Get the appropriate reminder index depending on the value of time offset.
   209 			reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off") 
   262 			int index = getReminderIndexBasedOnEntryAlarm();
   210 					<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   263 			mReminderItem->setContentWidgetData("currentIndex", index);
   211 					<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before")
       
   212 					<< hbTrId("txt_calendar_setlabel_reminder_val_2_days_before");
       
   213 			mReminderItem->setContentWidgetData(QString("items"),
       
   214 			                                    reminderChoicesForAllDay);
       
   215 			QTime referenceTime(0, 0, 0);
       
   216 			// Set the appropriate reminder depending on the value of time offset.
       
   217 			reminder = mCalenEditor->editedEntry()->alarm();
       
   218 			int offsetInMins = reminder.timeOffset();
       
   219 			if (offsetInMins < 0 || offsetInMins == 0) {
       
   220 				mReminderItem->setContentWidgetData("currentIndex", ReminderOnEventDay);
       
   221 				mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins
       
   222 						* 60));
       
   223 			} else if (offsetInMins < numberOfMinutesInADay) {
       
   224 				mReminderItem->setContentWidgetData("currentIndex", ReminderOneDayBefore);
       
   225 				mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins
       
   226 						* 60));
       
   227 			} else {
       
   228 				mReminderItem->setContentWidgetData("currentIndex", ReminderTwoDaysBefore);
       
   229 				offsetInMins %= (24 * 60);
       
   230 				mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins
       
   231 						* 60));
       
   232 			}
       
   233 			setDisplayTime();
   264 			setDisplayTime();
   234 		}
   265 		}
   235 		if (pastEvent) {
   266 		if (pastEvent) {
   236 			mReminderItem->setEnabled(false);
   267 			mReminderItem->setEnabled(false);
   237 		}
   268 		}
   241 							SLOT(handleReminderIndexChanged(int)));
   272 							SLOT(handleReminderIndexChanged(int)));
   242 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_EXIT );
   273 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_EXIT );
   243 }
   274 }
   244 
   275 
   245 /*!
   276 /*!
   246 	Triggerd from tapping on reminder item.
   277 	Triggered from tapping on reminder item.
   247 	Handles the reminder time change and updates the same in the event.
   278 	Handles the reminder time change and updates the same in the event.
   248 	\param index The new index chosen in the reminder list.
   279 	\param index The new index chosen in the reminder list.
   249  */
   280  */
   250 void CalenEditorReminderField::handleReminderIndexChanged(int index)
   281 void CalenEditorReminderField::handleReminderIndexChanged(int index)
   251 {
   282 {
   267 			// value to the entry.
   298 			// value to the entry.
   268 			reminder.setTimeOffset(mReminderHash.value(index));
   299 			reminder.setTimeOffset(mReminderHash.value(index));
   269 			reminder.setAlarmSoundName(QString(" "));
   300 			reminder.setAlarmSoundName(QString(" "));
   270 		}
   301 		}
   271 	} else {
   302 	} else {
   272 		QDateTime reminderDateTimeForAllDay; 
   303 		QDateTime reminderDateTimeForAllDay;
   273 		QDateTime
   304 		QDateTime
   274 		        startDateTimeForAllDay(
   305 		        startDateTimeForAllDay(
   275 		                               mCalenEditor->editedEntry()->startTime().date(),
   306 		                               mCalenEditor->editedEntry()->startTime().date(),
   276 		                               QTime(0, 0, 0));
   307 		                               QTime(0, 0, 0));
   277 		if (mReminderItem->contentWidgetData("currentIndex") == ReminderOff) {
   308 		if (mReminderItem->contentWidgetData("currentIndex") == ReminderOff) {
   283 				offset = 1;
   314 				offset = 1;
   284 			} else if (mReminderItem->contentWidgetData("currentIndex") == ReminderTwoDaysBefore) {
   315 			} else if (mReminderItem->contentWidgetData("currentIndex") == ReminderTwoDaysBefore) {
   285 				offset = 2;
   316 				offset = 2;
   286 			}
   317 			}
   287 			if(!mReminderTimeAdded) {
   318 			if(!mReminderTimeAdded) {
   288 				insertReminderTimeField()
   319 				insertReminderTimeField();
   289 ;			}
   320 			}
   290 			// If on same day as that of the event then check if time has been 
   321 			// If on same day as that of the event then check if time has been 
   291 			// changed , if changed retain that else set default time.
   322 			// changed , if changed retain that else set default time.
   292 			if (offset == 0) {
   323 			if (offset == 0) {
   293 				if(mReminderTimeForAllDay == QTime(18, 0, 0, 0)) {
   324 				if(mReminderTimeForAllDay == QTime(18, 0, 0, 0)) {
   294 					mReminderTimeForAllDay.setHMS(8, 0, 0);
   325 					mReminderTimeForAllDay.setHMS(8, 0, 0);
   295 					setDisplayTime();
       
   296 				}
   326 				}
       
   327 			}else {
       
   328 				// For the reminder options other than ReminderOnEventDay
       
   329 				// reset the default values since the time set for one option 
       
   330 				// may not be valid for the other option
       
   331 				mReminderTimeForAllDay.setHMS(18, 0, 0, 0);
   297 			}
   332 			}
       
   333 			setDisplayTime();
   298 			reminderDateTimeForAllDay.setDate(
   334 			reminderDateTimeForAllDay.setDate(
   299 					mCalenEditor->editedEntry()->startTime().date().addDays(
   335 					mCalenEditor->editedEntry()->startTime().date().addDays(
   300 																	-offset));
   336 																	-offset));
   301 			reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay);
   337 			reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay);
   302 			int seconds =
   338 			int seconds =
   368 	}
   404 	}
   369 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETDEFAULTALARMFORALLDAY_EXIT );
   405 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETDEFAULTALARMFORALLDAY_EXIT );
   370 }
   406 }
   371 
   407 
   372 /*!
   408 /*!
       
   409 	 Update the reminder choices when the meeting is on same day, 
       
   410 	 based on the time available from current time to start time of the event.
       
   411  */
       
   412 void CalenEditorReminderField::UpdateReminderChoicesForSameDay(QTime startTime)
       
   413 {
       
   414 	QTime currentTime = QTime::currentTime();
       
   415 	int offset = currentTime.secsTo(startTime);
       
   416 
       
   417 	// Disconnect the slot and connect it back again at end to avoid unnecessary
       
   418 	// calls to handleReminderIndexChanged slot. Or else the slot gets called 
       
   419 	// when we add all of items to the repeat combobox.
       
   420 	mEditorForm->removeConnection(mReminderItem,
       
   421 							SIGNAL(currentIndexChanged(int)), this,
       
   422 							SLOT(handleReminderIndexChanged(int)));
       
   423 
       
   424 	//The event start time is within 15mins from current time of today,
       
   425 	//then we cannot have alarms "15 mins before", "30mins before" and "1 hour before"
       
   426 	if (offset <= SecsIn15Mins)
       
   427 	{
       
   428 		QStringList reminderChoices;
       
   429 		//First to clear all items, we just set items with empty list.
       
   430 		mReminderItem->setContentWidgetData("items", reminderChoices); 
       
   431 		reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off")
       
   432 				<< hbTrId("txt_calendar_setlabel_reminder_val_at_the_start");
       
   433 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   434 	}
       
   435 	//The event start time is within half and hour from current time of today
       
   436 	//then we cannot have alarms "30mins before" and "1 hour before"
       
   437 	else if (offset <= SecsIn30Mins)
       
   438 	{
       
   439 		QStringList reminderChoices;
       
   440 		//First to clear all items, we just set items with empty list.
       
   441 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   442 		reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off")
       
   443 				<< hbTrId("txt_calendar_setlabel_reminder_val_at_the_start")
       
   444 				<< hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo");
       
   445 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   446 	}
       
   447 	//The event start time is within an hour of the current time of today,
       
   448 	//then cannot have alarm "1 hour before".
       
   449 	else if (offset <= SecsInOneHour)
       
   450 	{
       
   451 		QStringList reminderChoices;
       
   452 		//First to clear all items, we just set items with empty list.
       
   453 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   454 		reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off")
       
   455 				<< hbTrId("txt_calendar_setlabel_reminder_val_at_the_start")
       
   456 				<< hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo")
       
   457 				<< hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo");
       
   458 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   459 	}
       
   460 	// The event start time is more than one hour from current time 
       
   461 	// then we can have all choices for alarm.
       
   462 	else
       
   463 	{
       
   464 		QStringList reminderChoices;
       
   465 		//First to clear all items, we just set items with empty list.
       
   466 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   467 		reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off")
       
   468 				<< hbTrId("txt_calendar_setlabel_reminder_val_at_the_start")
       
   469 				<< hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo")
       
   470 				<< hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo")
       
   471 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_hour_before");
       
   472 		mReminderItem->setContentWidgetData("items", reminderChoices);
       
   473 	}
       
   474 	mReminderItem->setEnabled(true);
       
   475 	mEditorForm->addConnection(mReminderItem,
       
   476 							SIGNAL(currentIndexChanged(int)), this,
       
   477 							SLOT(handleReminderIndexChanged(int)));
       
   478 }
       
   479 
       
   480 /*!
   373 	 Updates the reminder choices for an all day event.
   481 	 Updates the reminder choices for an all day event.
   374 	 \param referenceDate to indicate past or not.
   482 	 \param referenceDate to indicate past or not.
   375  */
   483  */
   376 void CalenEditorReminderField::updateReminderChoicesForAllDay(QDate referenceDate)
   484 void CalenEditorReminderField::updateReminderChoicesForAllDay(QDate referenceDate)
   377 {
   485 {
   378 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_ENTRY );
   486 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_ENTRY );
   379 	if (!mReminderTimeAdded){
   487 	if (!mReminderTimeAdded){
   380 		insertReminderTimeField();
   488 		insertReminderTimeField();
   381 	}
   489 	}
       
   490 	// This functions rearranges the reminder options based on the date and time
       
   491 	// To avoid the unecessary call to handleReminderIndexChanged 
       
   492 	// the connection is removed.
       
   493 	mEditorForm->removeConnection(mReminderItem,
       
   494 								SIGNAL(currentIndexChanged(int)), this,
       
   495 								SLOT(handleReminderIndexChanged(int)));
       
   496 	
       
   497 	// Since the combox box is not updated as per the current datetime
       
   498 	// there can be a conflict between the previousIndex set on the combobox
       
   499 	// and the actual index. This comes while populating an existing entry.
       
   500 	// So the index has to be taken from the entry alarm 
       
   501 	
       
   502 	AgendaAlarm actualAlarm = mCalenEditor->editedEntry()->alarm();
       
   503 	// Get the actual alarm index from the entry alarm which is been set
       
   504 	int actualIndex = getReminderIndexBasedOnEntryAlarm();
       
   505 	int offsetInMins = actualAlarm.timeOffset();
       
   506 
       
   507 	// Calculate the alarm time
       
   508 	QDateTime alarmDateTime;
       
   509 	alarmDateTime.setDate(referenceDate);
       
   510 	alarmDateTime.setTime(mCalenEditor->editedEntry()->startTime().time());
       
   511 	QTime checkTime = alarmDateTime.time().addSecs(-(offsetInMins * 60));
       
   512 	alarmDateTime.setTime(checkTime);
       
   513 	
       
   514 	// The combox is updated based on the reference date which is beed passed.
       
   515 	// And the reminder time has to be set acoordingly
   382 	QStringList reminderChoicesForAllDay;
   516 	QStringList reminderChoicesForAllDay;
   383 	QDate tomorrow = QDate::currentDate().addDays(1);
   517 	QDate tomorrow = QDate::currentDate().addDays(1);
   384 	QDate theDayAfterTomorrow = QDate::currentDate().addDays(2);
   518 	QDate theDayAfterTomorrow = QDate::currentDate().addDays(2);
   385 	
   519 
   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.
   520 	// If the event is on a past date the default alarm will be off.
   413 	if (referenceDate < QDate::currentDate() || 
   521 	if (referenceDate < QDate::currentDate() || 
   414 			referenceDate == QDate::currentDate()) {
   522 			referenceDate == QDate::currentDate()) {
   415 		// Set reminder off for past event.
   523 		// Set reminder off for past event.
   416 		reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off");
   524 		reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off");
   417 		mReminderItem->setContentWidgetData(QString("items"), 
   525 		mReminderItem->setContentWidgetData(QString("items"), 
   418 													reminderChoicesForAllDay);
   526 		                                    reminderChoicesForAllDay);
   419 		mReminderItem->setEnabled(false);		
   527 		mReminderItem->setEnabled(false);		
   420 		// Remove the reminder field if it was added
   528 		// Remove the reminder field if it was added
   421 		if(mReminderTimeAdded) {
   529 		if(mReminderTimeAdded) {
   422 			removeReminderTimeField();
   530 			removeReminderTimeField();
   423 		}
   531 		}
   424 	} else if (theDayAfterTomorrow < referenceDate || 
   532 	} else if (theDayAfterTomorrow < referenceDate) {
   425 			theDayAfterTomorrow == referenceDate) {
       
   426 		// If the event is on a future date which is two days after the current date
   533 		// 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
   534 		// The options are off, on event day, 1 day before and 2 days before
   428 		reminderChoicesForAllDay 
   535 		reminderChoicesForAllDay 
       
   536 			<< hbTrId("txt_calendar_setlabel_reminder_val_off")
       
   537 			<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
       
   538 			<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before")
       
   539 			<< hbTrId("txt_calendar_setlabel_reminder_val_2_days_before");
       
   540 		mReminderItem->setEnabled(true);
       
   541 		mCustomReminderTimeItem->setEnabled(true);
       
   542 		mReminderItem->setContentWidgetData(QString("items"), 
       
   543 		                                    reminderChoicesForAllDay);
       
   544 	} else if (theDayAfterTomorrow == referenceDate) {
       
   545 		// If the event is on a future date which is two days after the current date
       
   546 		// If the current time is before 6.00 pm (default for 2 days before)
       
   547 		// The options are off, on event day, 1 day before and 2 days before
       
   548 		if (QTime::currentTime() < QTime(18, 0, 0, 0)) {
       
   549 			reminderChoicesForAllDay 
   429 				<< hbTrId("txt_calendar_setlabel_reminder_val_off")
   550 				<< hbTrId("txt_calendar_setlabel_reminder_val_off")
   430 				<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   551 				<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   431 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before")
   552 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before")
   432 				<< hbTrId("txt_calendar_setlabel_reminder_val_2_days_before");
   553 				<< hbTrId("txt_calendar_setlabel_reminder_val_2_days_before");
       
   554 		}else {
       
   555 			// If the event is on a future date which is two days after the current date
       
   556 			// the current time is after 6.00 pm (default for 2 days before)
       
   557 			// If its after the default time don't show the 2 days before option
       
   558 			reminderChoicesForAllDay 
       
   559 				<< hbTrId("txt_calendar_setlabel_reminder_val_off")
       
   560 				<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
       
   561 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before");
       
   562 		}
   433 		mReminderItem->setEnabled(true);
   563 		mReminderItem->setEnabled(true);
   434 		mCustomReminderTimeItem->setEnabled(true);
   564 		mCustomReminderTimeItem->setEnabled(true);
   435 		mReminderItem->setContentWidgetData(QString("items"), 
   565 		mReminderItem->setContentWidgetData(QString("items"), 
   436 													reminderChoicesForAllDay);
   566 		                                    reminderChoicesForAllDay);
   437 	} else if (QTime::currentTime() < QTime(18, 0, 0, 0)) {
   567 	}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
   568 		// 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.
   569 		// and current time is before 6.00 pm.
   440 		// The options are off, on event day and 1 day before
   570 		// The options are off, on event day and 1 day before
   441 		reminderChoicesForAllDay 
   571 		reminderChoicesForAllDay 
   442 				<< hbTrId("txt_calendar_setlabel_reminder_val_off")
   572 			<< hbTrId("txt_calendar_setlabel_reminder_val_off")
   443 				<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   573 			<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day")
   444 				<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before");
   574 			<< hbTrId("txt_calendar_setlabel_reminder_val_1_day_before");
   445 		mReminderItem->setEnabled(true);
   575 		mReminderItem->setEnabled(true);
   446 		mCustomReminderTimeItem->setEnabled(true);
   576 		mCustomReminderTimeItem->setEnabled(true);
   447 		mReminderItem->setContentWidgetData(QString("items"), 
   577 		mReminderItem->setContentWidgetData(QString("items"), 
   448 		                                    reminderChoicesForAllDay);
   578 		                                    reminderChoicesForAllDay);
   449 	}else {
   579 	}else {
   450 		// If the event is on a future date which is one day after the current date
   580 		// 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.
   581 		// and current time is after 6.00 pm.
   452 		// The options are off and on event day
   582 		// The options are off and on event day
   453 		reminderChoicesForAllDay 
   583 		reminderChoicesForAllDay 
   454 				<< hbTrId("txt_calendar_setlabel_reminder_val_off")
   584 			<< hbTrId("txt_calendar_setlabel_reminder_val_off")
   455 				<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day");
   585 			<< hbTrId("txt_calendar_setlabel_reminder_val_on_event_day");
   456 		mReminderItem->setEnabled(true);
   586 		mReminderItem->setEnabled(true);
   457 		mCustomReminderTimeItem->setEnabled(true);
   587 		mCustomReminderTimeItem->setEnabled(true);
   458 		mReminderItem->setContentWidgetData(QString("items"), 
   588 		mReminderItem->setContentWidgetData(QString("items"), 
   459 		                                    reminderChoicesForAllDay);
   589 		                                    reminderChoicesForAllDay);
   460 	}
   590 	}
   461 	// Set the proper index based on the validity of the previous index
   591 	// Get the count of the reminder options after the rearrangement 
       
   592 	// based on the date and time 
   462 	int count = reminderItemsCount();
   593 	int count = reminderItemsCount();
   463 	// By default, in case of reminder updation, its been agreed to set 
   594 	// Set the reminder index
   464 	// ReminderOneDayBefore even though ReminderTwoDaysBefore holds good
   595 	
   465 	// If the ReminderOneDayBefore option is available set it or 
   596 	if (count <= actualIndex || 
   466 	// else set it to ReminderOff
   597 			alarmDateTime < QDateTime::currentDateTime() || 
   467 	if(count > ReminderOneDayBefore) {
   598 			actualIndex == ReminderOff) {
   468 		// Don't make the reminder off since
   599 		// This will be executed when the actual index is not 
   469 		// the valid reminder options are there in the combobox
   600 		// available in the combobox or the alarm time is already passed
   470 		// So check for ReminderOff is needed
   601 		// or the actual alarm is off
   471 		if (update && 
   602 		// So set it as off
   472 			(previousIndex == ReminderOff || previousIndex >= ReminderOneDayBefore)) {
   603 		mReminderItem->setContentWidgetData("currentIndex", ReminderOff);
   473 			// If the index has to be updated check the previous index value
   604 		actualAlarm = AgendaAlarm();
   474 			// And set the default reminder as 1 day before.
   605 		mCalenEditor->editedEntry()->setAlarm(actualAlarm);
   475 			mReminderItem->setContentWidgetData("currentIndex", 
   606 		removeReminderTimeField();
   476 														ReminderOneDayBefore);
   607 	}else {
   477 		}else {
   608 		// Set the actual reminder index
   478 			// Set the previous index since the alarm is valid
   609 		mReminderItem->setContentWidgetData("currentIndex", actualIndex);
   479 			mReminderItem->setContentWidgetData("currentIndex", previousIndex);
   610 		if( actualIndex != ReminderOff) {
   480 			// Set the previous alarm also as the value will be changed to default value
   611 			if(!mReminderTimeAdded) {
   481 			// when the current index is been changed
   612 				insertReminderTimeField();
   482 			mCalenEditor->editedEntry()->setAlarm(previousAlarm);
   613 			}
       
   614 			mCalenEditor->editedEntry()->setAlarm(actualAlarm);
   483 			// Get the alarm time from the offset
   615 			// Get the alarm time from the offset
   484 			QTime alarmTime = refDateTime.time();
   616 			QTime alarmTime = alarmDateTime.time();
   485 			// Set the alarm time and display it on the button
   617 			// Set the alarm time and display it on the button
   486 			mReminderTimeForAllDay.setHMS(
   618 			mReminderTimeForAllDay.setHMS(
   487 					alarmTime.hour(),alarmTime.minute(),alarmTime.second());
   619 					alarmTime.hour(),alarmTime.minute(),alarmTime.second());
   488 			setDisplayTime();
   620 			setDisplayTime();
   489 		}
   621 		}else {
   490 	}else {
   622 			actualAlarm = AgendaAlarm();
   491 		// Enters this condition if the previous index set is not valid or
   623 			removeReminderTimeField();
   492 		// the index is ReminderOff
   624 		}
   493 		mReminderItem->setContentWidgetData("currentIndex", ReminderOff);
   625 	}
   494 	}
   626 	// Connect the slot for the index change
   495 	
   627 	mEditorForm->addConnection(mReminderItem,
       
   628 								SIGNAL(currentIndexChanged(int)), this,
       
   629 								SLOT(handleReminderIndexChanged(int)));
       
   630 
   496 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_EXIT );
   631 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_EXIT );
       
   632 }
       
   633 
       
   634 /*!
       
   635 	 Gets the reminder index for all day events based on the alarm
       
   636 	 which is saved for the entry
       
   637  */
       
   638 int CalenEditorReminderField::getReminderIndexBasedOnEntryAlarm()
       
   639 {
       
   640 	// Get the appropriate reminder index depending on the value of time offset.
       
   641 	AgendaAlarm actualAlarm = mCalenEditor->editedEntry()->alarm();
       
   642 	QTime referenceTime(0, 0, 0);
       
   643 	int index = ReminderOff;
       
   644 	int offsetInMins = actualAlarm.timeOffset();
       
   645 	if(offsetInMins == -1) {
       
   646 		index = ReminderOff;
       
   647 	}else if (offsetInMins < 0 || offsetInMins == 0) {
       
   648 		index = ReminderOnEventDay;
       
   649 		mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins
       
   650 				* 60));
       
   651 	} else if (offsetInMins <= numberOfMinutesInADay) {
       
   652 		index = ReminderOneDayBefore;
       
   653 		mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins
       
   654 				* 60));
       
   655 	} else {
       
   656 		index = ReminderTwoDaysBefore;
       
   657 		offsetInMins %= (24 * 60);
       
   658 		mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins
       
   659 				* 60));
       
   660 	}
       
   661 	return index;
   497 }
   662 }
   498 
   663 
   499 /*!
   664 /*!
   500 	 Insert the reminder time field for an all day event.
   665 	 Insert the reminder time field for an all day event.
   501  */
   666  */
   547  */
   712  */
   548 void CalenEditorReminderField::removeReminderTimeField()
   713 void CalenEditorReminderField::removeReminderTimeField()
   549 {
   714 {
   550 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMOVEREMINDERTIMEFIELD_ENTRY );
   715 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMOVEREMINDERTIMEFIELD_ENTRY );
   551 	mReminderTimeAdded = false;
   716 	mReminderTimeAdded = false;
       
   717 	mEditorForm->removeConnection(mCustomReminderTimeItem, SIGNAL(clicked()),
       
   718 		                           this, SLOT(launchReminderTimePicker()));
   552 	if (mCustomReminderTimeItem) {
   719 	if (mCustomReminderTimeItem) {
   553 		QModelIndex reminderIndex =
   720 		QModelIndex reminderIndex =
   554 				mCalenEditorModel->indexFromItem(mCustomReminderTimeItem);
   721 				mCalenEditorModel->indexFromItem(mCustomReminderTimeItem);
   555 		mCalenEditorModel->removeItem(
   722 		mCalenEditorModel->removeItem(
   556 				mCalenEditorModel->index(
   723 				mCalenEditorModel->index(
   574 	popUp->setHeadingWidget( new HbLabel(
   741 	popUp->setHeadingWidget( new HbLabel(
   575 				hbTrId("Reminder Time")));
   742 				hbTrId("Reminder Time")));
   576 	
   743 	
   577 	HbExtendedLocale locale = HbExtendedLocale::system();
   744 	HbExtendedLocale locale = HbExtendedLocale::system();
   578 	mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay);
   745 	mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay);
       
   746 	// Set the display format
   579 	if(locale.timeStyle() == HbExtendedLocale::Time12) {
   747 	if(locale.timeStyle() == HbExtendedLocale::Time12) {
   580 		mTimePicker->setDisplayFormat("hh:mm ap");	
   748 		mTimePicker->setDisplayFormat("hh:mm ap");	
   581 	}else {
   749 	}else {
   582 		mTimePicker->setDisplayFormat("hh:mm");
   750 		mTimePicker->setDisplayFormat("hh:mm");
       
   751 	}
       
   752 	
       
   753 	// Check if the entry is repeating based on the repeatuntil item
       
   754 	if(!mCalenEditor->isRepeatUntilItemAdded()) {
       
   755 		int index = currentReminderIndex();
       
   756 		QDate checkDate = mCalenEditor->editedEntry()->startTime().date();
       
   757 		// Restrict the time picker to show the valid time 
       
   758 		// depending on the reminder options
       
   759 		// Take an offset of 5 mins
       
   760 		QTime minTime = QTime::currentTime().addSecs(5 * 60);
       
   761 		if(index == ReminderTwoDaysBefore &&  checkDate.addDays(-2) == QDate::currentDate()) {
       
   762 				mTimePicker->setMinimumTime(minTime);
       
   763 		}else if(index == ReminderOneDayBefore && checkDate.addDays(-1) == QDate::currentDate()) {
       
   764 				mTimePicker->setMinimumTime(minTime);
       
   765 		}else if(index == ReminderOnEventDay && checkDate == QDate::currentDate()) {
       
   766 				mTimePicker->setMinimumTime(minTime);
       
   767 		}
   583 	}
   768 	}
   584 	mTimePicker->setTime(mReminderTimeForAllDay);
   769 	mTimePicker->setTime(mReminderTimeForAllDay);
   585 	popUp->setContentWidget(mTimePicker);
   770 	popUp->setContentWidget(mTimePicker);
   586 	
   771 	
   587 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp);
   772 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp);
   601 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_ENTRY );
   786 	OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_ENTRY );
   602 	mReminderTimeForAllDay = mTimePicker->time();
   787 	mReminderTimeForAllDay = mTimePicker->time();
   603 	if (mReminderTimeForAllDay.isValid()) {
   788 	if (mReminderTimeForAllDay.isValid()) {
   604 		// Change the time displayed to that selected by the user.
   789 		// Change the time displayed to that selected by the user.
   605 		setDisplayTime();
   790 		setDisplayTime();
   606 		handleReminderIndexChanged(currentReminderIndex());
   791 		int offset = 0;
       
   792 		if (currentReminderIndex() == ReminderOneDayBefore) {
       
   793 			offset = 1;
       
   794 		} else if (currentReminderIndex() == ReminderTwoDaysBefore) {
       
   795 			offset = 2;
       
   796 		}
       
   797 		QDateTime startDateTimeForAllDay(
       
   798 			mCalenEditor->editedEntry()->startTime().date(), QTime(0, 0, 0));
       
   799 		QDateTime reminderDateTimeForAllDay; 
       
   800 		reminderDateTimeForAllDay.setDate(
       
   801 				mCalenEditor->editedEntry()->startTime().date().addDays(
       
   802 						-offset));
       
   803 		reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay);
       
   804 		int seconds =
       
   805 				reminderDateTimeForAllDay.secsTo(startDateTimeForAllDay);
       
   806 		int timeOffset = seconds / 60;
       
   807 		mCustomReminderTimeItem->setEnabled(true);
       
   808 		AgendaAlarm reminder;
       
   809 		reminder.setTimeOffset(timeOffset);
       
   810 		reminder.setAlarmSoundName(QString(" "));
       
   811 		// Set the reminder to the entry.
       
   812 		mCalenEditor->editedEntry()->setAlarm(reminder);
   607 	}	
   813 	}	
   608 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_EXIT );
   814 	OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_EXIT );
   609 }
   815 }
   610 
   816 
   611 /*!
   817 /*!