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