calendarui/caleneditor/src/caleneditorrepeatfield.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 // System Includes
    20 // System Includes
       
    21 #include <QDate>
    21 #include <hbdataformmodelitem.h>
    22 #include <hbdataformmodelitem.h>
    22 #include <hbdataformviewitem.h>
    23 #include <hbdataformviewitem.h>
    23 #include <hbdataformmodel.h>
    24 #include <hbdataformmodel.h>
    24 #include <hbdataform.h>
    25 #include <hbdataform.h>
    25 #include <hbcombobox.h>
    26 #include <hbcombobox.h>
    29 #include <agendautil.h>
    30 #include <agendautil.h>
    30 
    31 
    31 // User Included
    32 // User Included
    32 #include "caleneditorrepeatfield.h"
    33 #include "caleneditorrepeatfield.h"
    33 #include "caleneditorcustomitem.h"
    34 #include "caleneditorcustomitem.h"
       
    35 
       
    36 // Constants
       
    37 const int userRole = Qt::UserRole + 100;
    34 
    38 
    35 /*!
    39 /*!
    36 	\class CalenEditorRepeatField
    40 	\class CalenEditorRepeatField
    37  */
    41  */
    38 /*!
    42 /*!
    68 
    72 
    69 		// Create the repeat choices
    73 		// Create the repeat choices
    70 		QStringList repeatChoices;
    74 		QStringList repeatChoices;
    71 		repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
    75 		repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
    72 		        << hbTrId("txt_calendar_setlabel_repeat_val_daily")
    76 		        << hbTrId("txt_calendar_setlabel_repeat_val_daily")
    73 		        // TODO : add text ID for workdays
    77 		        << hbTrId("txt_calendar_setlabel_repeat_val_workdays")
    74 		        << hbTrId("Workdays")
       
    75 		        << hbTrId("txt_calendar_setlabel_repeat_val_weekly")
    78 		        << hbTrId("txt_calendar_setlabel_repeat_val_weekly")
    76 		        << hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
    79 		        << hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
    77 		        << hbTrId("txt_calendar_setlabel_repeat_val_monthly")
    80 		        << hbTrId("txt_calendar_setlabel_repeat_val_monthly")
    78 		        << hbTrId("txt_calendar_setlabel_repeat_val_yearly");
    81 		        << hbTrId("txt_calendar_setlabel_repeat_val_yearly");
    79 
    82 
   123 			= qobject_cast<HbComboBox *> (item->dataItemContentWidget());
   126 			= qobject_cast<HbComboBox *> (item->dataItemContentWidget());
   124 
   127 
   125 	// Set the user roles for the combobox items so that we depend on these
   128 	// Set the user roles for the combobox items so that we depend on these
   126 	// roles to identify the correct repeat type when repeat choices are 
   129 	// roles to identify the correct repeat type when repeat choices are 
   127 	// dynamically removed or added
   130 	// dynamically removed or added
   128 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, Qt::UserRole+100);
   131 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, userRole);
   129 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, Qt::UserRole+100);
   132 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, userRole);
   130 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   133 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   131 								 RepeatWorkdays, Qt::UserRole+100);
   134 								 RepeatWorkdays, userRole);
   132 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly, Qt::UserRole+100);
   135 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly, userRole);
   133 	mRepeatComboBox->setItemData(RepeatBiWeekly, 
   136 	mRepeatComboBox->setItemData(RepeatBiWeekly, 
   134 								 RepeatBiWeekly, Qt::UserRole+100);
   137 								 RepeatBiWeekly, userRole);
   135 	mRepeatComboBox->setItemData(RepeatMonthly, 
   138 	mRepeatComboBox->setItemData(RepeatMonthly, 
   136 								 RepeatMonthly, Qt::UserRole+100);
   139 								 RepeatMonthly, userRole);
   137 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, Qt::UserRole+100);
   140 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, userRole);
   138 	
   141 	
   139 	if (mCalenEditor->editedEntry()->isRepeating()) {
   142 	if (mCalenEditor->editedEntry()->isRepeating()) {
   140 		switch (mCalenEditor->editedEntry()->repeatRule().type()) {
   143 		switch (mCalenEditor->editedEntry()->repeatRule().type()) {
   141 			case AgendaRepeatRule::DailyRule: {
   144 			case AgendaRepeatRule::DailyRule: {
   142 				mRepeatComboBox->setCurrentIndex(1);
   145 				mRepeatComboBox->setCurrentIndex(1);
   176 		// Set the Original entry value also.
   179 		// Set the Original entry value also.
   177 		mCalenEditor->originalEntry()->setRepeatRule(
   180 		mCalenEditor->originalEntry()->setRepeatRule(
   178 									  AgendaRepeatRule(
   181 									  AgendaRepeatRule(
   179 									  AgendaRepeatRule::InvalidRule));
   182 									  AgendaRepeatRule::InvalidRule));
   180 	}
   183 	}
   181 	connect(mRepeatComboBox, SIGNAL(currentIndexChanged(int)), this,
       
   182 			SLOT(handleRepeatIndexChanged(int)));
       
   183 	
   184 	
   184 	// Update the repeat choices depending upon the duration
   185 	// Update the repeat choices depending upon the duration
   185 	updateRepeatChoices();
   186 	updateRepeatChoices();
       
   187 	connect(mRepeatComboBox, SIGNAL(currentIndexChanged(int)), this,
       
   188 				SLOT(handleRepeatIndexChanged(int)));
   186 }
   189 }
   187 
   190 
   188 /*!
   191 /*!
   189 	Triggerd from tapping on reminder item.
   192 	Triggerd from tapping on reminder item.
   190 	Handles the reminder time change and updates the same in the event.
   193 	Handles the reminder time change and updates the same in the event.
   194 {
   197 {
   195 	mIsBiWeekly = false;
   198 	mIsBiWeekly = false;
   196 	mIsWorkdays = false;
   199 	mIsWorkdays = false;
   197 
   200 
   198 	HbExtendedLocale locale = HbExtendedLocale::system();
   201 	HbExtendedLocale locale = HbExtendedLocale::system();
   199 	// Get the user role w ehave set for this index
   202 	// Get the user role we have set for this index
   200 	QVariant userRole = mRepeatComboBox->itemData(index, Qt::UserRole + 100);
   203 	QVariant role = mRepeatComboBox->itemData(index, userRole);
   201 	int value = userRole.toInt();
   204 	int value = role.toInt();
   202 	switch (value) {
   205 	switch (value) {
   203 		case 1: {
   206 		case 1: {
   204 			if (!mRepeatUntilItemAdded) {
   207 			if (!mRepeatUntilItemAdded) {
   205 				insertRepeatUntilItem();
   208 				insertRepeatUntilItem();
   206 			}
   209 			}
   293 				mCustomRepeatUntilItem = NULL;
   296 				mCustomRepeatUntilItem = NULL;
   294 			}
   297 			}
   295 		}
   298 		}
   296 		break;
   299 		break;
   297 	}
   300 	}
   298 	mCalenEditor->addDiscardAction();
   301 	if(!mCalenEditor->isNewEntry()) {
       
   302 		mCalenEditor->addDiscardAction();
       
   303 	}
       
   304 	mCalenEditor->updateReminderChoices();
   299 }
   305 }
   300 
   306 
   301 /*!
   307 /*!
   302 	 Returns model index of the repeat item
   308 	 Returns model index of the repeat item
   303 	 \return Model index of the repeat item
   309 	 \return Model index of the repeat item
   312  */
   318  */
   313 void CalenEditorRepeatField::insertRepeatUntilItem()
   319 void CalenEditorRepeatField::insertRepeatUntilItem()
   314 {
   320 {
   315 	HbDataFormModelItem::DataItemType itemType =
   321 	HbDataFormModelItem::DataItemType itemType =
   316 	        static_cast<HbDataFormModelItem::DataItemType> (RepeatUntilOffset);
   322 	        static_cast<HbDataFormModelItem::DataItemType> (RepeatUntilOffset);
   317 
   323 	
   318 	QModelIndex repeatIndex = mCalenEditorModel->indexFromItem(mRepeatItem);
   324 	int index = CalenEditorPrivate::RepeatUntilItem;
       
   325 	if (!mCalenEditor->isReminderTimeForAllDayAdded()) {
       
   326 		index -= 1;
       
   327 	}
   319 	mCustomRepeatUntilItem = mCalenEditorModel->insertDataFormItem(
   328 	mCustomRepeatUntilItem = mCalenEditorModel->insertDataFormItem(
   320 										CalenEditorPrivate::RepeatUntilItem,
   329 										index,
   321 										itemType,
   330 										itemType,
   322 										QString(
   331 										QString(
   323 										hbTrId(
   332 										hbTrId(
   324 										"txt_calendar_setlabel_repeat_until")),
   333 										"txt_calendar_setlabel_repeat_until")),
   325 										mCalenEditorModel->invisibleRootItem());
   334 										mCalenEditorModel->invisibleRootItem());
   349 /*!
   358 /*!
   350 	Launches the date picker by tapping on the repaet until pushbutton
   359 	Launches the date picker by tapping on the repaet until pushbutton
   351  */
   360  */
   352 void CalenEditorRepeatField::launchRepeatUntilDatePicker()
   361 void CalenEditorRepeatField::launchRepeatUntilDatePicker()
   353 {
   362 {
       
   363 	HbDialog *popUp = new HbDialog();
       
   364 	popUp->setDismissPolicy(HbDialog::NoDismiss);
       
   365 	popUp->setTimeout(HbDialog::NoTimeout);
       
   366 	popUp->setHeadingWidget( new HbLabel(
       
   367 									hbTrId("txt_calendar_title_repeat_until")));
       
   368 	popUp->setAttribute( Qt::WA_DeleteOnClose, true );
       
   369 	
   354 	if (mDatePicker) {
   370 	if (mDatePicker) {
   355 		mDatePicker = NULL;
   371 		mDatePicker = NULL;
   356 	}
   372 	}
   357 	if (mRepeatRuleType == AgendaRepeatRule::DailyRule) {
   373 	if (mRepeatRuleType == AgendaRepeatRule::DailyRule) {
   358 		QDate minDate = mCalenEditor->editedEntry()->endTime().date().addDays(1);
   374 		QDate minDate = mCalenEditor->editedEntry()->endTime().date().addDays(1);
   359 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate);
   375 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp);
   360 		mDatePicker->setMinimumDate(minDate);
   376 		mDatePicker->setMinimumDate(minDate);
   361 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   377 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   362 		mDatePicker->setDate(mRepeatUntilDate);
   378 		mDatePicker->setDate(mRepeatUntilDate);
   363 	} else if (mRepeatRuleType == AgendaRepeatRule::WeeklyRule) {
   379 	} else if (mRepeatRuleType == AgendaRepeatRule::WeeklyRule) {
   364 		QDate minDate;
   380 		QDate minDate;
   365 		if (!mIsBiWeekly || mIsWorkdays) {
   381 		if (!mIsBiWeekly || mIsWorkdays) {
   366 			minDate = mCalenEditor->editedEntry()->endTime().date().addDays(7);
   382 			minDate = mCalenEditor->editedEntry()->endTime().date().addDays(7);
   367 		} else {
   383 		} else {
   368 			minDate = mCalenEditor->editedEntry()->endTime().date().addDays(14);
   384 			minDate = mCalenEditor->editedEntry()->endTime().date().addDays(14);
   369 		}
   385 		}
   370 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate);
   386 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp);
   371 		mDatePicker->setMinimumDate(minDate);
   387 		mDatePicker->setMinimumDate(minDate);
   372 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   388 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   373 		mDatePicker->setDate(mRepeatUntilDate);
   389 		mDatePicker->setDate(mRepeatUntilDate);
   374 	} else if (mRepeatRuleType == AgendaRepeatRule::MonthlyRule) {
   390 	} else if (mRepeatRuleType == AgendaRepeatRule::MonthlyRule) {
   375 		QDate minDate = mCalenEditor->editedEntry()->endTime().date().addMonths(1);
   391 		QDate minDate = mCalenEditor->editedEntry()->endTime().date().addMonths(1);
   376 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate);
   392 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp);
   377 		mDatePicker->setMinimumDate(minDate);
   393 		mDatePicker->setMinimumDate(minDate);
   378 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   394 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   379 		mDatePicker->setDate(mRepeatUntilDate);
   395 		mDatePicker->setDate(mRepeatUntilDate);
   380 	} else if (mRepeatRuleType == AgendaRepeatRule::YearlyRule) {
   396 	} else if (mRepeatRuleType == AgendaRepeatRule::YearlyRule) {
   381 		QDate minDate = mCalenEditor->editedEntry()->endTime().date().addYears(1);
   397 		QDate minDate = mCalenEditor->editedEntry()->endTime().date().addYears(1);
   382 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate);
   398 		mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp);
   383 		mDatePicker->setMinimumDate(minDate);
   399 		mDatePicker->setMinimumDate(minDate);
   384 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   400 		mDatePicker->setMaximumDate(QDate(31, 12, 2100));
   385 		mDatePicker->setDate(mRepeatUntilDate);
   401 		mDatePicker->setDate(mRepeatUntilDate);
   386 	}
   402 	}
   387 	HbDialog popUp;
   403 	popUp->setContentWidget(mDatePicker);
   388 	popUp.setDismissPolicy(HbDialog::NoDismiss);
   404 	
   389 	popUp.setTimeout(HbDialog::NoTimeout);
       
   390 	popUp.setContentWidget(mDatePicker);
       
   391 	popUp.setHeadingWidget( new HbLabel(
       
   392 								hbTrId("txt_calendar_title_repeat_until")));
       
   393 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   405 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   394 	popUp.setPrimaryAction(okAction);
   406 	popUp->addAction(okAction);
   395 	connect(okAction, SIGNAL(triggered()), this, SLOT(setRepeatUntilDate()));
   407 	connect(okAction, SIGNAL(triggered()), this, SLOT(setRepeatUntilDate()));
   396 	connect(okAction, SIGNAL(triggered()), &popUp, SLOT(close()));
   408 	popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popUp));
   397 	popUp.setSecondaryAction(new HbAction(hbTrId("txt_common_button_cancel"),
   409 	popUp->open();
   398 								&popUp));
       
   399 	popUp.exec();
       
   400 }
   410 }
   401 
   411 
   402 /*!
   412 /*!
   403 	Sets the repeat until date on the repeat until item
   413 	Sets the repeat until date on the repeat until item
   404  */
   414  */
   409 		HbExtendedLocale locale = HbExtendedLocale::system();
   419 		HbExtendedLocale locale = HbExtendedLocale::system();
   410 		QString dateString = locale.format(mRepeatUntilDate,
   420 		QString dateString = locale.format(mRepeatUntilDate,
   411 									r_qtn_date_usual_with_zero);
   421 									r_qtn_date_usual_with_zero);
   412 		mCustomRepeatUntilItem->setContentWidgetData("text", dateString);
   422 		mCustomRepeatUntilItem->setContentWidgetData("text", dateString);
   413 	}
   423 	}
       
   424 	mCalenEditor->updateReminderChoices();
       
   425 }
       
   426 
       
   427 /*!
       
   428 	Returns the repeatuntildate displayed.
       
   429  */
       
   430 QDate CalenEditorRepeatField::repeatUntilDate()
       
   431 {
       
   432 	return mRepeatUntilDate;
   414 }
   433 }
   415 
   434 
   416 /*!
   435 /*!
   417 	Updates the repeat choices depending on the meeting duration
   436 	Updates the repeat choices depending on the meeting duration
   418 */
   437 */
   419 void CalenEditorRepeatField::updateRepeatChoices()
   438 void CalenEditorRepeatField::updateRepeatChoices()
   420 {
   439 {
       
   440     if (!mRepeatComboBox) {
       
   441         return;
       
   442     }
   421 	// Clear all the choices and add it again. If we dont do it 
   443 	// Clear all the choices and add it again. If we dont do it 
   422 	// as user would have changed the end times many times and we would have
   444 	// as user would have changed the end times many times and we would have
   423 	// deleted repeat options depending upon that
   445 	// deleted repeat options depending upon that
   424 	// Get the current choice
   446 	// Get the current choice
   425 	int choice = mRepeatComboBox->currentIndex();
   447 	int choice = mRepeatComboBox->currentIndex();
   426 	int previousCount = mRepeatComboBox->count();
   448 	int previousCount = mRepeatComboBox->count();
   427 	mRepeatComboBox->clear();
   449 	mRepeatComboBox->clear();
   428 	QStringList repeatChoices;
   450 	QStringList repeatChoices;
   429 	repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
   451 	repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once")
   430 			<< hbTrId("txt_calendar_setlabel_repeat_val_daily")
   452 			<< hbTrId("txt_calendar_setlabel_repeat_val_daily")
   431 			// TODO : add text ID for workdays
   453 			<< hbTrId("txt_calendar_setlabel_repeat_val_workdays")
   432 			<< hbTrId("Workdays")
       
   433 			<< hbTrId("txt_calendar_setlabel_repeat_val_weekly")
   454 			<< hbTrId("txt_calendar_setlabel_repeat_val_weekly")
   434 			<< hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
   455 			<< hbTrId("txt_calendar_setlabel_repeat_val_fortnightly")
   435 			<< hbTrId("txt_calendar_setlabel_repeat_val_monthly")
   456 			<< hbTrId("txt_calendar_setlabel_repeat_val_monthly")
   436 			<< hbTrId("txt_calendar_setlabel_repeat_val_yearly");
   457 			<< hbTrId("txt_calendar_setlabel_repeat_val_yearly");
   437 	mRepeatComboBox->addItems(repeatChoices);
   458 	mRepeatComboBox->addItems(repeatChoices);
   438 	// Set the user roles for the combobox items so that we depend on these
   459 	// Set the user roles for the combobox items so that we depend on these
   439 	// roles to identify the correct repeat type when repeat choices are 
   460 	// roles to identify the correct repeat type when repeat choices are 
   440 	// dynamically removed or added
   461 	// dynamically removed or added
   441 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, Qt::UserRole + 100);
   462 	mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, userRole);
   442 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, 
   463 	mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, 
   443 								 Qt::UserRole + 100);
   464 	                             userRole);
   444 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   465 	mRepeatComboBox->setItemData(RepeatWorkdays, 
   445 								 RepeatWorkdays, Qt::UserRole+100);
   466 								 RepeatWorkdays, userRole);
   446 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly,
   467 	mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly,
   447 								 Qt::UserRole + 100);
   468 	                             userRole);
   448 	mRepeatComboBox->setItemData(RepeatBiWeekly, RepeatBiWeekly,
   469 	mRepeatComboBox->setItemData(RepeatBiWeekly, RepeatBiWeekly,
   449 								 Qt::UserRole + 100);
   470 	                             userRole);
   450 	mRepeatComboBox->setItemData(RepeatMonthly, RepeatMonthly,
   471 	mRepeatComboBox->setItemData(RepeatMonthly, RepeatMonthly,
   451 								 Qt::UserRole + 100);
   472 	                             userRole);
   452 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, 
   473 	mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, 
   453 								 Qt::UserRole + 100);
   474 	                             userRole);
   454 
   475 
   455 	int totalCount = mRepeatComboBox->count();
   476 	int totalCount = mRepeatComboBox->count();
   456 
   477 
   457 	if (previousCount < totalCount && choice > 0) {
   478 	if (previousCount < totalCount && choice > 0) {
   458 		choice += (totalCount - previousCount);
   479 		choice += (totalCount - previousCount);
   524 	if (choice >= count) {
   545 	if (choice >= count) {
   525 		choice = count - 1;
   546 		choice = count - 1;
   526 	}
   547 	}
   527 	// Set the previous user's choice
   548 	// Set the previous user's choice
   528 	mRepeatComboBox->setCurrentIndex(choice);
   549 	mRepeatComboBox->setCurrentIndex(choice);
   529 	handleRepeatIndexChanged(choice);
       
   530 }
   550 }
   531 
   551 
   532 /*!
   552 /*!
   533 	Save RepeatRule to the edited entry
   553 	Save RepeatRule to the edited entry
   534  */
   554  */