diff -r fd30d51f876b -r a949c2543c15 clock/clockui/clocksettingsview/src/settingscustomitem.cpp --- a/clock/clockui/clocksettingsview/src/settingscustomitem.cpp Mon May 03 12:30:32 2010 +0300 +++ b/clock/clockui/clocksettingsview/src/settingscustomitem.cpp Fri May 14 15:51:09 2010 +0300 @@ -54,6 +54,8 @@ { // Construct the settignsutility. mSettingsUtility = new SettingsUtility(); + // Construct the timezone client. + mTimezoneClient = TimezoneClient::getInstance(); } /*! @@ -61,7 +63,9 @@ */ SettingsCustomItem::~SettingsCustomItem() { - + if (!mTimezoneClient->isNull()) { + mTimezoneClient->deleteInstance(); + } } /*! @@ -74,16 +78,16 @@ } /*! - + \sa */ bool SettingsCustomItem::canSetModelIndex(const QModelIndex &index) const { - HbDataFormModelItem::DataItemType itemType = + HbDataFormModelItem::DataItemType itemType = static_cast( index.data(HbDataFormModelItem::ItemTypeRole).toInt()); - if(itemType >= HbDataFormModelItem::CustomItemBase && + if(itemType >= HbDataFormModelItem::CustomItemBase && itemType <= (HbDataFormModelItem::CustomItemBase + 50)) { return true; } else { @@ -97,21 +101,21 @@ HbDataFormModelItem::DataItemType itemType = static_cast( modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); - + HbDataFormModel* model = static_cast( static_cast(this)->itemView()->model()); - HbDataFormModelItem* modlItem = model->itemFromIndex(modelIndex()); - + HbDataFormModelItem* modlItem = model->itemFromIndex(modelIndex()); + switch (itemType) { case (TimeItemOffset + HbDataFormModelItem::CustomItemBase): mTimeWidget->setProperty("text", modlItem->contentWidgetData("text")); break; - + case (DateItemOffset + HbDataFormModelItem::CustomItemBase): mDateWidget->setProperty("text", modlItem->contentWidgetData("text")); break; - + case (PlaceItemOffset + HbDataFormModelItem::CustomItemBase): mPlaceWidget->setProperty("text", modlItem->contentWidgetData("text")); break; @@ -176,7 +180,7 @@ this, SLOT(launchRegSettingsView())); return regSettingsItem; } - + case (50 + HbDataFormModelItem::CustomItemBase): { HbListWidget *workdaysItem = new HbListWidget(); @@ -186,7 +190,7 @@ for (int index = 0; index < mWeekdaysList.count(); ++index) { workdaysItem->addItem(mWeekdaysList.at(index)); } - + QString workdaysString = workdaysSetting(); for (int i = 0, index = workdaysString.size() - 1; index >= 0; ++i, index--) { @@ -202,7 +206,7 @@ QItemSelectionModel::Select); } } - + return workdaysItem; } @@ -242,50 +246,51 @@ mTimePickerDialog->setContentWidget(timePicker); timePicker->setTime(QTime::currentTime()); - HbAction *okAction = - new HbAction(QString(hbTrId("txt_common_button_ok")), mTimePickerDialog); - mTimePickerDialog->setPrimaryAction(okAction); - connect( - okAction, SIGNAL(triggered()), - this, SLOT(handleTimeOkAction())); + mOkAction = new HbAction( + QString(hbTrId("txt_common_button_ok")), mTimePickerDialog); + mCancelAction = new HbAction( + QString(hbTrId("txt_common_button_cancel")), mTimePickerDialog); - HbAction *cancelAction = - new HbAction(QString(hbTrId("txt_common_button_cancel")), - mTimePickerDialog); - mTimePickerDialog->setSecondaryAction( cancelAction ); - connect( - cancelAction, SIGNAL(triggered()), - this, SLOT(handleTimeCancelAction())); + mTimePickerDialog->addAction(mOkAction); + mTimePickerDialog->addAction(mCancelAction); - mTimePickerDialog->exec(); + mTimePickerDialog->open(this, SLOT(selectedAction(HbAction*))); } /*! - Handles the ok action of time picker dialog. + Handles the ok action of time/date picker dialog. */ -void SettingsCustomItem::handleTimeOkAction() +void SettingsCustomItem::handleOkAction() { - // Get the time from the time picker. - QTime newTime = static_cast ( - mTimePickerDialog->contentWidget())->time(); + if (mTimePickerDialog) { + // Get the time from the time picker. + QTime newTime = static_cast ( + mTimePickerDialog->contentWidget())->time(); - QString timeFormatString = mSettingsUtility->timeFormatString(); - // Update the display text on form item. - mTimeWidget->setText(newTime.toString(timeFormatString)); - mSettingsUtility->setTime(newTime.toString(timeFormatString)); + QString timeFormatString = mSettingsUtility->timeFormatString(); - // Close the dialog. - handleTimeCancelAction(); -} + // If time returned by the picker is valid, then only update. + if (newTime.isValid()) { + // Update the display text on form item. + mTimeWidget->setText(newTime.toString(timeFormatString)); + // Update the system time. + mTimezoneClient->setDateTime(QDateTime(QDate::currentDate(), newTime)); + } + } else if(mDatePickerDialog) { + // Get the time from the time picker. + QDate newDate = static_cast ( + mDatePickerDialog->contentWidget())->date(); -/*! - Handles the cancel action of time picker dialog. - */ -void SettingsCustomItem::handleTimeCancelAction() -{ - // Close the dialog. - mTimePickerDialog->close(); - mTimePickerDialog->deleteLater(); + QString dateFormatString = mSettingsUtility->dateFormatString(); + + // If date returned by the picker is valid, then only update. + if (newDate.isValid()) { + // Update the display text on form item. + mDateWidget->setText(newDate.toString(dateFormatString)); + // Update the system date. + mTimezoneClient->setDateTime(QDateTime(newDate, QTime::currentTime())); + } + } } /*! @@ -315,50 +320,16 @@ mDatePickerDialog->setContentWidget(datePicker); datePicker->setDate(QDate::currentDate()); - HbAction *okAction = - new HbAction(QString(hbTrId("txt_common_button_ok")), mDatePickerDialog); - mDatePickerDialog->setPrimaryAction(okAction); - connect( - okAction, SIGNAL(triggered()), - this, SLOT(handleDateOkAction())); - - HbAction *cancelAction = - new HbAction(QString(hbTrId("txt_common_button_cancel")), - mDatePickerDialog); - mDatePickerDialog->setSecondaryAction( cancelAction ); - connect( - cancelAction, SIGNAL(triggered()), - this, SLOT(handleDateCancelAction())); - - mDatePickerDialog->exec(); -} + mOkAction = new HbAction( + QString(hbTrId("txt_common_button_ok")), mDatePickerDialog); -/*! - Handles the ok action of date picker dialog. - */ -void SettingsCustomItem::handleDateOkAction() -{ - // Get the time from the time picker. - QDate newDate = static_cast ( - mDatePickerDialog->contentWidget())->date(); + mCancelAction = new HbAction( + QString(hbTrId("txt_common_button_cancel")),mDatePickerDialog); - QString dateFormatString = mSettingsUtility->dateFormatString(); - // Update the display text on form item. - mDateWidget->setText(newDate.toString(dateFormatString)); - mSettingsUtility->setDate(newDate.toString(dateFormatString)); - - // Close the dialog. - handleDateCancelAction(); -} + mDatePickerDialog->addAction(mOkAction); + mDatePickerDialog->addAction(mCancelAction); -/*! - Handles the ok action of date picker dialog. - */ -void SettingsCustomItem::handleDateCancelAction() -{ - // Close the dialog. - mDatePickerDialog->close(); - mDatePickerDialog->deleteLater(); + mDatePickerDialog->open(this, SLOT(selectedAction(HbAction*))); } /*! @@ -382,8 +353,6 @@ void SettingsCustomItem::updatePlaceItem(LocationInfo info) { if (-1 != info.timezoneId) { - // Construct the timezone client. - mTimezoneClient = new TimezoneClient(); mTimezoneClient->setAsCurrentLocationL(info); } } @@ -399,6 +368,16 @@ } /*! + Slot to handle the selected action. + */ +void SettingsCustomItem::selectedAction(HbAction *action) +{ + if (action==mOkAction) { + handleOkAction(); + } +} + +/*! Returns the workdays setting string based on start of week setting. */ QString SettingsCustomItem::workdaysSetting()