clock/clockui/clocksettingsview/src/settingscustomitem.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 49 5de72ea7a065
equal deleted inserted replaced
23:fd30d51f876b 26:a949c2543c15
    52 SettingsCustomItem::SettingsCustomItem(QGraphicsItem *parent)
    52 SettingsCustomItem::SettingsCustomItem(QGraphicsItem *parent)
    53 :HbDataFormViewItem(parent)
    53 :HbDataFormViewItem(parent)
    54 {
    54 {
    55 	// Construct the settignsutility.
    55 	// Construct the settignsutility.
    56 	mSettingsUtility = new SettingsUtility();
    56 	mSettingsUtility = new SettingsUtility();
       
    57 	// Construct the timezone client.
       
    58 	mTimezoneClient = TimezoneClient::getInstance();
    57 }
    59 }
    58 
    60 
    59 /*!
    61 /*!
    60 	Destructor.
    62 	Destructor.
    61  */
    63  */
    62 SettingsCustomItem::~SettingsCustomItem()
    64 SettingsCustomItem::~SettingsCustomItem()
    63 {
    65 {
    64 
    66 	if (!mTimezoneClient->isNull()) {
       
    67 		mTimezoneClient->deleteInstance();
       
    68 	}
    65 }
    69 }
    66 
    70 
    67 /*!
    71 /*!
    68 	\reimp
    72 	\reimp
    69 	Creates SettingsCustomItem.
    73 	Creates SettingsCustomItem.
    72 {
    76 {
    73 	return new SettingsCustomItem(*this);
    77 	return new SettingsCustomItem(*this);
    74 }
    78 }
    75 
    79 
    76 /*!
    80 /*!
    77 	
    81 
    78 	\sa
    82 	\sa
    79  */
    83  */
    80 bool SettingsCustomItem::canSetModelIndex(const QModelIndex &index) const
    84 bool SettingsCustomItem::canSetModelIndex(const QModelIndex &index) const
    81 {
    85 {
    82 	HbDataFormModelItem::DataItemType itemType = 
    86 	HbDataFormModelItem::DataItemType itemType =
    83 			static_cast<HbDataFormModelItem::DataItemType>(
    87 			static_cast<HbDataFormModelItem::DataItemType>(
    84 			index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    88 			index.data(HbDataFormModelItem::ItemTypeRole).toInt());
    85 
    89 
    86 	if(itemType >= HbDataFormModelItem::CustomItemBase && 
    90 	if(itemType >= HbDataFormModelItem::CustomItemBase &&
    87 			itemType <= (HbDataFormModelItem::CustomItemBase + 50)) {
    91 			itemType <= (HbDataFormModelItem::CustomItemBase + 50)) {
    88 		return true;
    92 		return true;
    89 	} else {
    93 	} else {
    90 		return false;
    94 		return false;
    91 	}
    95 	}
    95 void SettingsCustomItem::restore()
    99 void SettingsCustomItem::restore()
    96 {
   100 {
    97 	HbDataFormModelItem::DataItemType itemType =
   101 	HbDataFormModelItem::DataItemType itemType =
    98 			static_cast<HbDataFormModelItem::DataItemType>(
   102 			static_cast<HbDataFormModelItem::DataItemType>(
    99 			modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
   103 			modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt());
   100 	
   104 
   101 	HbDataFormModel* model =
   105 	HbDataFormModel* model =
   102 			static_cast<HbDataFormModel*>(
   106 			static_cast<HbDataFormModel*>(
   103 			static_cast<HbAbstractViewItem*>(this)->itemView()->model());
   107 			static_cast<HbAbstractViewItem*>(this)->itemView()->model());
   104 	HbDataFormModelItem* modlItem = model->itemFromIndex(modelIndex()); 
   108 	HbDataFormModelItem* modlItem = model->itemFromIndex(modelIndex());
   105 	
   109 
   106 	switch (itemType) {
   110 	switch (itemType) {
   107 		case (TimeItemOffset + HbDataFormModelItem::CustomItemBase):
   111 		case (TimeItemOffset + HbDataFormModelItem::CustomItemBase):
   108 		mTimeWidget->setProperty("text", modlItem->contentWidgetData("text"));
   112 		mTimeWidget->setProperty("text", modlItem->contentWidgetData("text"));
   109 		break;
   113 		break;
   110 		
   114 
   111 		case (DateItemOffset + HbDataFormModelItem::CustomItemBase):
   115 		case (DateItemOffset + HbDataFormModelItem::CustomItemBase):
   112 		mDateWidget->setProperty("text", modlItem->contentWidgetData("text"));
   116 		mDateWidget->setProperty("text", modlItem->contentWidgetData("text"));
   113 		break;
   117 		break;
   114 		
   118 
   115 		case (PlaceItemOffset + HbDataFormModelItem::CustomItemBase):
   119 		case (PlaceItemOffset + HbDataFormModelItem::CustomItemBase):
   116 		mPlaceWidget->setProperty("text", modlItem->contentWidgetData("text"));
   120 		mPlaceWidget->setProperty("text", modlItem->contentWidgetData("text"));
   117 		break;
   121 		break;
   118 		case (50 + HbDataFormModelItem::CustomItemBase):
   122 		case (50 + HbDataFormModelItem::CustomItemBase):
   119 
   123 
   174 			connect(
   178 			connect(
   175 					regSettingsItem, SIGNAL(clicked()),
   179 					regSettingsItem, SIGNAL(clicked()),
   176 					this, SLOT(launchRegSettingsView()));
   180 					this, SLOT(launchRegSettingsView()));
   177 			return regSettingsItem;
   181 			return regSettingsItem;
   178 		}
   182 		}
   179 		
   183 
   180 		case (50 + HbDataFormModelItem::CustomItemBase):
   184 		case (50 + HbDataFormModelItem::CustomItemBase):
   181 		{
   185 		{
   182 			HbListWidget *workdaysItem = new HbListWidget();
   186 			HbListWidget *workdaysItem = new HbListWidget();
   183 			workdaysItem->setSelectionMode(HbAbstractItemView::MultiSelection);
   187 			workdaysItem->setSelectionMode(HbAbstractItemView::MultiSelection);
   184 			QItemSelectionModel *model = 0;
   188 			QItemSelectionModel *model = 0;
   185 			model = workdaysItem->selectionModel();
   189 			model = workdaysItem->selectionModel();
   186 			for (int index = 0; index < mWeekdaysList.count(); ++index) {
   190 			for (int index = 0; index < mWeekdaysList.count(); ++index) {
   187 				workdaysItem->addItem(mWeekdaysList.at(index));
   191 				workdaysItem->addItem(mWeekdaysList.at(index));
   188 			}
   192 			}
   189 			
   193 
   190 			QString workdaysString = workdaysSetting();
   194 			QString workdaysString = workdaysSetting();
   191 			for (int i = 0, index = workdaysString.size() - 1;
   195 			for (int i = 0, index = workdaysString.size() - 1;
   192 					index >= 0; ++i, index--) {
   196 					index >= 0; ++i, index--) {
   193 				if (workdaysString.at(index) == QChar('0')) {
   197 				if (workdaysString.at(index) == QChar('0')) {
   194 					// Not a workday.
   198 					// Not a workday.
   200 					model->select(
   204 					model->select(
   201 							model->model()->index(i,0),
   205 							model->model()->index(i,0),
   202 							QItemSelectionModel::Select);
   206 							QItemSelectionModel::Select);
   203 				}
   207 				}
   204 			}
   208 			}
   205 			
   209 
   206 			return workdaysItem;
   210 			return workdaysItem;
   207 		}
   211 		}
   208 
   212 
   209 		default:
   213 		default:
   210 			return 0;
   214 			return 0;
   240 	timePicker->setDisplayFormat(tumblerDisplayFormat);
   244 	timePicker->setDisplayFormat(tumblerDisplayFormat);
   241 	// Set the tumbler as the content widget.
   245 	// Set the tumbler as the content widget.
   242 	mTimePickerDialog->setContentWidget(timePicker);
   246 	mTimePickerDialog->setContentWidget(timePicker);
   243 	timePicker->setTime(QTime::currentTime());
   247 	timePicker->setTime(QTime::currentTime());
   244 
   248 
   245 	HbAction *okAction =
   249 	mOkAction = new HbAction(
   246 		new HbAction(QString(hbTrId("txt_common_button_ok")), mTimePickerDialog);
   250 			QString(hbTrId("txt_common_button_ok")), mTimePickerDialog);
   247 	mTimePickerDialog->setPrimaryAction(okAction);
   251 	mCancelAction = new HbAction(
   248 	connect(
   252 			QString(hbTrId("txt_common_button_cancel")), mTimePickerDialog);
   249 			okAction, SIGNAL(triggered()),
   253 
   250 			this, SLOT(handleTimeOkAction()));
   254 	mTimePickerDialog->addAction(mOkAction);
   251 
   255 	mTimePickerDialog->addAction(mCancelAction);
   252 	HbAction *cancelAction =
   256 
   253 		new HbAction(QString(hbTrId("txt_common_button_cancel")),
   257 	mTimePickerDialog->open(this, SLOT(selectedAction(HbAction*)));
   254 		    mTimePickerDialog);
   258 }
   255 	mTimePickerDialog->setSecondaryAction( cancelAction );
   259 
   256 	connect(
   260 /*!
   257 			cancelAction, SIGNAL(triggered()),
   261 	Handles the ok action of time/date picker dialog.
   258 			this, SLOT(handleTimeCancelAction()));
   262  */
   259 
   263 void SettingsCustomItem::handleOkAction()
   260 	mTimePickerDialog->exec();
   264 {
   261 }
   265 	if (mTimePickerDialog) {
   262 
   266 		// Get the time from the time picker.
   263 /*!
   267 		QTime newTime = static_cast<HbDateTimePicker *> (
   264 	Handles the ok action of time picker dialog.
   268 				mTimePickerDialog->contentWidget())->time();
   265  */
   269 
   266 void SettingsCustomItem::handleTimeOkAction()
   270 		QString timeFormatString = mSettingsUtility->timeFormatString();
   267 {
   271 
   268 	// Get the time from the time picker.
   272 		// If time returned by the picker is valid, then only update.
   269 	QTime newTime = static_cast<HbDateTimePicker *> (
   273 		if (newTime.isValid()) {
   270 			mTimePickerDialog->contentWidget())->time();
   274 			// Update the display text on form item.
   271 
   275 			mTimeWidget->setText(newTime.toString(timeFormatString));
   272 	QString timeFormatString = mSettingsUtility->timeFormatString();
   276 			// Update the system time.
   273 	// Update the display text on form item.
   277 			mTimezoneClient->setDateTime(QDateTime(QDate::currentDate(), newTime));
   274 	mTimeWidget->setText(newTime.toString(timeFormatString));
   278 		}
   275 	mSettingsUtility->setTime(newTime.toString(timeFormatString));
   279 	} else if(mDatePickerDialog) {
   276 
   280 		// Get the time from the time picker.
   277 	// Close the dialog.
   281 		QDate newDate = static_cast<HbDateTimePicker *> (
   278 	handleTimeCancelAction();
   282 				mDatePickerDialog->contentWidget())->date();
   279 }
   283 
   280 
   284 		QString dateFormatString = mSettingsUtility->dateFormatString();
   281 /*!
   285 
   282 	Handles the cancel action of time picker dialog.
   286 		// If date returned by the picker is valid, then only update.
   283  */
   287 		if (newDate.isValid()) {
   284 void SettingsCustomItem::handleTimeCancelAction()
   288 			// Update the display text on form item.
   285 {
   289 			mDateWidget->setText(newDate.toString(dateFormatString));
   286 	// Close the dialog.
   290 			// Update the system date.
   287 	mTimePickerDialog->close();
   291 			mTimezoneClient->setDateTime(QDateTime(newDate, QTime::currentTime()));
   288 	mTimePickerDialog->deleteLater();
   292 		}
       
   293 	}
   289 }
   294 }
   290 
   295 
   291 /*!
   296 /*!
   292 	Launches the date picker dialog.
   297 	Launches the date picker dialog.
   293  */
   298  */
   313 	datePicker->setMinimumDate(QDate(2010, 01, 01));
   318 	datePicker->setMinimumDate(QDate(2010, 01, 01));
   314 	// Set the tumbler as the content widget.
   319 	// Set the tumbler as the content widget.
   315 	mDatePickerDialog->setContentWidget(datePicker);
   320 	mDatePickerDialog->setContentWidget(datePicker);
   316 	datePicker->setDate(QDate::currentDate());
   321 	datePicker->setDate(QDate::currentDate());
   317 
   322 
   318 	HbAction *okAction =
   323 	mOkAction = new HbAction(
   319 		new HbAction(QString(hbTrId("txt_common_button_ok")), mDatePickerDialog);
   324 			QString(hbTrId("txt_common_button_ok")), mDatePickerDialog);
   320 	mDatePickerDialog->setPrimaryAction(okAction);
   325 
   321 	connect(
   326 	mCancelAction = new HbAction(
   322 			okAction, SIGNAL(triggered()),
   327 			QString(hbTrId("txt_common_button_cancel")),mDatePickerDialog);
   323 			this, SLOT(handleDateOkAction()));
   328 
   324 
   329 	mDatePickerDialog->addAction(mOkAction);
   325 	HbAction *cancelAction =
   330 	mDatePickerDialog->addAction(mCancelAction);
   326 		new HbAction(QString(hbTrId("txt_common_button_cancel")),
   331 
   327 		    mDatePickerDialog);
   332 	mDatePickerDialog->open(this, SLOT(selectedAction(HbAction*)));
   328 	mDatePickerDialog->setSecondaryAction( cancelAction );
       
   329 	connect(
       
   330 			cancelAction, SIGNAL(triggered()),
       
   331 			this, SLOT(handleDateCancelAction()));
       
   332 
       
   333 	mDatePickerDialog->exec();
       
   334 }
       
   335 
       
   336 /*!
       
   337 	Handles the ok action of date picker dialog.
       
   338  */
       
   339 void SettingsCustomItem::handleDateOkAction()
       
   340 {
       
   341 	// Get the time from the time picker.
       
   342 	QDate newDate = static_cast<HbDateTimePicker *> (
       
   343 			mDatePickerDialog->contentWidget())->date();
       
   344 
       
   345 	QString dateFormatString = mSettingsUtility->dateFormatString();
       
   346 	// Update the display text on form item.
       
   347 	mDateWidget->setText(newDate.toString(dateFormatString));
       
   348 	mSettingsUtility->setDate(newDate.toString(dateFormatString));
       
   349 
       
   350 	// Close the dialog.
       
   351 	handleDateCancelAction();
       
   352 }
       
   353 
       
   354 /*!
       
   355 	Handles the ok action of date picker dialog.
       
   356  */
       
   357 void SettingsCustomItem::handleDateCancelAction()
       
   358 {
       
   359 	// Close the dialog.
       
   360 	mDatePickerDialog->close();
       
   361 	mDatePickerDialog->deleteLater();
       
   362 }
   333 }
   363 
   334 
   364 /*!
   335 /*!
   365 	Launches cityselectionlist for timezone selection.
   336 	Launches cityselectionlist for timezone selection.
   366  */
   337  */
   380 	\param info Will contain the location info selected by the user.
   351 	\param info Will contain the location info selected by the user.
   381  */
   352  */
   382 void SettingsCustomItem::updatePlaceItem(LocationInfo info)
   353 void SettingsCustomItem::updatePlaceItem(LocationInfo info)
   383 {
   354 {
   384 	if (-1 != info.timezoneId) {
   355 	if (-1 != info.timezoneId) {
   385 		// Construct the timezone client.
       
   386 		mTimezoneClient = new TimezoneClient();
       
   387 		mTimezoneClient->setAsCurrentLocationL(info);
   356 		mTimezoneClient->setAsCurrentLocationL(info);
   388 	}
   357 	}
   389 }
   358 }
   390 
   359 
   391 /*!
   360 /*!
   394 void SettingsCustomItem::launchRegSettingsView()
   363 void SettingsCustomItem::launchRegSettingsView()
   395 {
   364 {
   396 	ClockRegionalSettingsView *view =
   365 	ClockRegionalSettingsView *view =
   397 			new ClockRegionalSettingsView(*mSettingsUtility);
   366 			new ClockRegionalSettingsView(*mSettingsUtility);
   398 	view->showView();
   367 	view->showView();
       
   368 }
       
   369 
       
   370 /*!
       
   371 	Slot to handle the selected action.
       
   372  */
       
   373 void SettingsCustomItem::selectedAction(HbAction *action)
       
   374 {
       
   375 	if (action==mOkAction) {
       
   376 		handleOkAction();
       
   377 	}
   399 }
   378 }
   400 
   379 
   401 /*!
   380 /*!
   402 	Returns the workdays setting string based on start of week setting.
   381 	Returns the workdays setting string based on start of week setting.
   403  */
   382  */