clock/clockui/clocksettingsview/src/clockregionalsettingsview.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
--- a/clock/clockui/clocksettingsview/src/clockregionalsettingsview.cpp	Mon May 03 12:30:32 2010 +0300
+++ b/clock/clockui/clocksettingsview/src/clockregionalsettingsview.cpp	Mon Jun 28 15:22:02 2010 +0530
@@ -21,17 +21,16 @@
 #include <HbAction>
 #include <HbDataForm>
 #include <HbDataFormModel>
+#include <HbExtendedLocale>
 #include <HbDataFormModelItem>
 #include <HbDataFormViewItem>
 #include <HbMainWindow>
 #include <HbInstance>
 #include <HbPushButton>
-#include <HbExtendedLocale>
 #include <HbListWidget>
 #include <HbComboBox>
-#include <HBListWidgetItem>
-#include <HbApplication>
-#include <QTranslator>
+#include <HbListWidgetItem>
+#include <HbTranslator>
 
 // User includes
 #include "clockregionalsettingsview.h"
@@ -49,25 +48,21 @@
 /*!
 	Default constructor.
  */
-ClockRegionalSettingsView::ClockRegionalSettingsView(
-		SettingsUtility &utility, QObject *parent)
+ClockRegionalSettingsView::ClockRegionalSettingsView(QObject *parent)
 :QObject(parent),
  mView(0),
- mBackAction(0),
- mLoader(0),
- mSettingsUtility(utility)
+ mLoader(0)
 {
 	// Construct the document loader.
 	mLoader = new ClockSettingsDocLoader;
 	
+	// Construct the settignsutility.
+	mSettingsUtility = new SettingsUtility();
+	
 	// Load the translation file and install the editor specific translator
-    mTranslator = new QTranslator;
-    //QString lang = QLocale::system().name();
-    //QString path = "Z:/resource/qt/translations/";
-    mTranslator->load("clocksettingsview",":/translations");
-    // TODO: Load the appropriate .qm file based on locale
-    //bool loaded = mTranslator->load("caleneditor_" + lang, path);
-    HbApplication::instance()->installTranslator(mTranslator);
+    mTranslator = new HbTranslator("clocksettingsview");
+    mTranslator->loadCommon();
+    
 	// Create the custom prototype.
 	mCustomPrototype = new SettingsCustomItem();
 }
@@ -81,8 +76,15 @@
 		delete mLoader;
 		mLoader = 0;
 	}
+	
+	if (mSettingsUtility) {
+        delete mSettingsUtility;
+        mSettingsUtility = 0;
+	}
+	if(mFormModel){
+		delete mFormModel;
+	}
 // Remove the translator
-    HbApplication::instance()->removeTranslator(mTranslator);
     if (mTranslator) {
         delete mTranslator;
         mTranslator = 0;
@@ -134,10 +136,10 @@
 	window->setCurrentView(mView);
 
 	// Add the back softkey.
-	mBackAction = new HbAction(Hb::BackAction);
-	mView->setNavigationAction(mBackAction);
+	HbAction *backAction = new HbAction(Hb::BackNaviAction);
+	mView->setNavigationAction(backAction);
 	connect(
-			mBackAction, SIGNAL(triggered()),
+			backAction, SIGNAL(triggered()),
 			this, SLOT(handleBackAction()));
 }
 
@@ -233,8 +235,8 @@
  */
 void ClockRegionalSettingsView::handleTimeFormatChange()
 {
-//	mSettingsUtility.setTimeFormat(mTimeFormatItem->text());
-	mSettingsUtility.setTimeFormat(
+//	mSettingsUtility->setTimeFormat(mTimeFormatItem->text());
+	mSettingsUtility->setTimeFormat(
 			mTimeFormatItem->contentWidgetData("text").toString());
 }
 
@@ -244,8 +246,8 @@
  */
 void ClockRegionalSettingsView::handleTimeSeparatorChange()
 {
-//	mSettingsUtility.setTimeSeparator(mTimeSeparatorItem->text());
-	mSettingsUtility.setTimeSeparator(
+//	mSettingsUtility->setTimeSeparator(mTimeSeparatorItem->text());
+	mSettingsUtility->setTimeSeparator(
 			mTimeSeparatorItem->contentWidgetData("text").toString());
 }
 
@@ -253,7 +255,7 @@
  */
 void ClockRegionalSettingsView::handleDateFormatChange(QString text)
 {
-	mSettingsUtility.setDateFormat(text);
+	mSettingsUtility->setDateFormat(text);
 }
 
 /*!
@@ -262,7 +264,7 @@
  */
 void ClockRegionalSettingsView::handleDateSeparatorChange(QString text)
 {
-	mSettingsUtility.setDateSeparator(text);
+	mSettingsUtility->setDateSeparator(text);
 }
 
 /*!
@@ -271,8 +273,6 @@
 void ClockRegionalSettingsView::handleDataChanged(
 		const QModelIndex& topLeft, const QModelIndex& bottomRight)
 {
-	qDebug("clock: ClockRegionalSettingsView::handleDataChanged() -->");
-
 	Q_UNUSED(bottomRight)
 
 
@@ -280,34 +280,13 @@
 		case 5:
 		{
 		// The Start of week item.
-		if (mStartOfWeekItem != 0) {
+		if (mStartOfWeekItem != 0)
+		    {
 			int index = mStartOfWeekItem->currentIndex();
-			mSettingsUtility.setStartOfWeek(index);
-			
-			QStringList weekdays = weekdayList();
-			QString workdays = mCustomPrototype->workdaysSetting();
-			QItemSelectionModel *model = 0;
-			model = mWorkdaysItem->selectionModel();
-			
-			for (int i = 0, index = workdays.size() - 1;
-					i < mWorkdaysItem->count(); ++i, index--) {
-				QString str = weekdays[i];
-				mWorkdaysItem->item(i)->setText(str);
-				
-				QChar ch = workdays.at(index);
-				if ( ch == QChar('0')) {
-					// Not a workday.
-					model->select(
-							model->model()->index(i,0),
-							QItemSelectionModel::Deselect);
-				} else {
-					// Workday.
-					model->select(
-							model->model()->index(i,0),
-							QItemSelectionModel::Select);
-				}
-			}
-		}
+			mSettingsUtility->setStartOfWeek(index);
+			//update the week days
+			updateWeekDays();
+		    }
 		}
 		break;
 
@@ -350,13 +329,13 @@
 	}
 
 	// Get the locale.
-	 HbExtendedLocale locale = HbExtendedLocale::system();
+	HbExtendedLocale locale  = HbExtendedLocale::system();
 
 	// Time format item.
 	 mTimeFormatItem = mFormModel->appendDataFormItem(
 			HbDataFormModelItem::ToggleValueItem,
 			hbTrId("txt_clock_setlabel_time_format"));
-	int index = mSettingsUtility.timeFormat(mTimeFormatStringList);
+	int index = mSettingsUtility->timeFormat(mTimeFormatStringList);
 	if (0 == index) {
 		mTimeFormatItem->setContentWidgetData("text", mTimeFormatStringList[0]);
 		mTimeFormatItem->setContentWidgetData("additionalText", mTimeFormatStringList[1]);
@@ -372,7 +351,7 @@
 	mTimeSeparatorItem = mFormModel->appendDataFormItem(
 			HbDataFormModelItem::ToggleValueItem,
 			hbTrId("txt_clock_setlabel_time_separator"));
-	index = mSettingsUtility.timeSeparator(mTimeSeparatorStringList);
+	index = mSettingsUtility->timeSeparator(mTimeSeparatorStringList);
 	if (0 == index) {
 		mTimeSeparatorItem->setContentWidgetData("text", mTimeSeparatorStringList[0]);
 		mTimeSeparatorItem->setContentWidgetData(
@@ -390,7 +369,7 @@
 	mDateFormatItem = mFormModel->appendDataFormItem(
 			HbDataFormModelItem::ComboBoxItem,
 			hbTrId("txt_clock_setlabel_date_format"));
-	index = mSettingsUtility.dateFormat(mDateFormatStringList);
+	index = mSettingsUtility->dateFormat(mDateFormatStringList);
 
 	mDateFormatItem->setContentWidgetData("items", mDateFormatStringList);
 	mDateFormatItem->setContentWidgetData("currentIndex",index);
@@ -402,7 +381,7 @@
 	mDateSeparatorItem = mFormModel->appendDataFormItem(
 			HbDataFormModelItem::ComboBoxItem,
 			hbTrId("txt_clock_setlabel_date_separator"));
-	index = mSettingsUtility.dateSeparator(mDateSeparatorStringList);
+	index = mSettingsUtility->dateSeparator(mDateSeparatorStringList);
 
 	mDateSeparatorItem->setContentWidgetData("items", mDateSeparatorStringList);
 	mDateSeparatorItem->setContentWidgetData("currentIndex",index);
@@ -471,4 +450,60 @@
 	return weekDays;
 }
 
+
+/*!
+    update the start week on .
+ */
+
+void ClockRegionalSettingsView::updateWeekStartOn()
+{
+if (mStartOfWeekItem != 0)
+    {
+    HbExtendedLocale locale;
+    HbExtendedLocale::WeekDay weekdDayStart = locale.startOfWeek();
+    int currentDay = mStartOfWeekItem->currentIndex();
+    if(currentDay == weekdDayStart )
+        {
+        return;
+        }
+    else
+        {
+        mStartOfWeekItem->setCurrentIndex(weekdDayStart);
+        updateWeekDays();
+        }
+    }
+}
+
+/*!
+    update the  week days .
+ */
+void ClockRegionalSettingsView::updateWeekDays()
+{
+QStringList weekdays = weekdayList();
+QString workdays = mCustomPrototype->workdaysSetting();
+QItemSelectionModel *model = 0;
+model = mWorkdaysItem->selectionModel();
+
+for (int i = 0, index = workdays.size() - 1;
+        i < mWorkdaysItem->count(); ++i, index--)
+    {
+    QString str = weekdays[i];
+    mWorkdaysItem->item(i)->setText(str);
+
+    QChar ch = workdays.at(index);
+    if ( ch == QChar('0')) 
+        {
+        // Not a workday.
+        model->select(
+        model->model()->index(i,0),
+        QItemSelectionModel::Deselect);
+        }
+    else
+        {
+        // Workday.
+        model->select(
+        model->model()->index(i,0),
+        QItemSelectionModel::Select);}
+        }
+}
 // End of file	--Don't remove this.