19 // System includes |
19 // System includes |
20 #include <HbView> |
20 #include <HbView> |
21 #include <HbAction> |
21 #include <HbAction> |
22 #include <HbDataForm> |
22 #include <HbDataForm> |
23 #include <HbDataFormModel> |
23 #include <HbDataFormModel> |
|
24 #include <HbExtendedLocale> |
24 #include <HbDataFormModelItem> |
25 #include <HbDataFormModelItem> |
25 #include <HbDataFormViewItem> |
26 #include <HbDataFormViewItem> |
26 #include <HbMainWindow> |
27 #include <HbMainWindow> |
27 #include <HbInstance> |
28 #include <HbInstance> |
28 #include <HbPushButton> |
29 #include <HbPushButton> |
29 #include <HbExtendedLocale> |
|
30 #include <HbListWidget> |
30 #include <HbListWidget> |
31 #include <HbComboBox> |
31 #include <HbComboBox> |
32 #include <HBListWidgetItem> |
32 #include <HbListWidgetItem> |
33 #include <HbApplication> |
33 #include <HbTranslator> |
34 #include <QTranslator> |
|
35 |
34 |
36 // User includes |
35 // User includes |
37 #include "clockregionalsettingsview.h" |
36 #include "clockregionalsettingsview.h" |
38 #include "clocksettingsdocloader.h" |
37 #include "clocksettingsdocloader.h" |
39 #include "clocksettingsdefines.h" |
38 #include "clocksettingsdefines.h" |
47 */ |
46 */ |
48 |
47 |
49 /*! |
48 /*! |
50 Default constructor. |
49 Default constructor. |
51 */ |
50 */ |
52 ClockRegionalSettingsView::ClockRegionalSettingsView( |
51 ClockRegionalSettingsView::ClockRegionalSettingsView(QObject *parent) |
53 SettingsUtility &utility, QObject *parent) |
|
54 :QObject(parent), |
52 :QObject(parent), |
55 mView(0), |
53 mView(0), |
56 mBackAction(0), |
54 mLoader(0) |
57 mLoader(0), |
|
58 mSettingsUtility(utility) |
|
59 { |
55 { |
60 // Construct the document loader. |
56 // Construct the document loader. |
61 mLoader = new ClockSettingsDocLoader; |
57 mLoader = new ClockSettingsDocLoader; |
62 |
58 |
|
59 // Construct the settignsutility. |
|
60 mSettingsUtility = new SettingsUtility(); |
|
61 |
63 // Load the translation file and install the editor specific translator |
62 // Load the translation file and install the editor specific translator |
64 mTranslator = new QTranslator; |
63 mTranslator = new HbTranslator("clocksettingsview"); |
65 //QString lang = QLocale::system().name(); |
64 mTranslator->loadCommon(); |
66 //QString path = "Z:/resource/qt/translations/"; |
65 |
67 mTranslator->load("clocksettingsview",":/translations"); |
|
68 // TODO: Load the appropriate .qm file based on locale |
|
69 //bool loaded = mTranslator->load("caleneditor_" + lang, path); |
|
70 HbApplication::instance()->installTranslator(mTranslator); |
|
71 // Create the custom prototype. |
66 // Create the custom prototype. |
72 mCustomPrototype = new SettingsCustomItem(); |
67 mCustomPrototype = new SettingsCustomItem(); |
73 } |
68 } |
74 |
69 |
75 /*! |
70 /*! |
132 HbMainWindow *window = hbInstance->allMainWindows().first(); |
134 HbMainWindow *window = hbInstance->allMainWindows().first(); |
133 window->addView(mView); |
135 window->addView(mView); |
134 window->setCurrentView(mView); |
136 window->setCurrentView(mView); |
135 |
137 |
136 // Add the back softkey. |
138 // Add the back softkey. |
137 mBackAction = new HbAction(Hb::BackAction); |
139 HbAction *backAction = new HbAction(Hb::BackNaviAction); |
138 mView->setNavigationAction(mBackAction); |
140 mView->setNavigationAction(backAction); |
139 connect( |
141 connect( |
140 mBackAction, SIGNAL(triggered()), |
142 backAction, SIGNAL(triggered()), |
141 this, SLOT(handleBackAction())); |
143 this, SLOT(handleBackAction())); |
142 } |
144 } |
143 |
145 |
144 /*! |
146 /*! |
145 The view is removed from main window and a deleteLater is called on `this'. |
147 The view is removed from main window and a deleteLater is called on `this'. |
231 Called when the time format toggle item is clicked. Here we update the |
233 Called when the time format toggle item is clicked. Here we update the |
232 value in the locale. |
234 value in the locale. |
233 */ |
235 */ |
234 void ClockRegionalSettingsView::handleTimeFormatChange() |
236 void ClockRegionalSettingsView::handleTimeFormatChange() |
235 { |
237 { |
236 // mSettingsUtility.setTimeFormat(mTimeFormatItem->text()); |
238 // mSettingsUtility->setTimeFormat(mTimeFormatItem->text()); |
237 mSettingsUtility.setTimeFormat( |
239 mSettingsUtility->setTimeFormat( |
238 mTimeFormatItem->contentWidgetData("text").toString()); |
240 mTimeFormatItem->contentWidgetData("text").toString()); |
239 } |
241 } |
240 |
242 |
241 /*! |
243 /*! |
242 Called when the time separator toggle item is clicked. Here we update the |
244 Called when the time separator toggle item is clicked. Here we update the |
243 value in the locale. |
245 value in the locale. |
244 */ |
246 */ |
245 void ClockRegionalSettingsView::handleTimeSeparatorChange() |
247 void ClockRegionalSettingsView::handleTimeSeparatorChange() |
246 { |
248 { |
247 // mSettingsUtility.setTimeSeparator(mTimeSeparatorItem->text()); |
249 // mSettingsUtility->setTimeSeparator(mTimeSeparatorItem->text()); |
248 mSettingsUtility.setTimeSeparator( |
250 mSettingsUtility->setTimeSeparator( |
249 mTimeSeparatorItem->contentWidgetData("text").toString()); |
251 mTimeSeparatorItem->contentWidgetData("text").toString()); |
250 } |
252 } |
251 |
253 |
252 /*! |
254 /*! |
253 */ |
255 */ |
254 void ClockRegionalSettingsView::handleDateFormatChange(QString text) |
256 void ClockRegionalSettingsView::handleDateFormatChange(QString text) |
255 { |
257 { |
256 mSettingsUtility.setDateFormat(text); |
258 mSettingsUtility->setDateFormat(text); |
257 } |
259 } |
258 |
260 |
259 /*! |
261 /*! |
260 Called when the date separator item is changed. Here we update the |
262 Called when the date separator item is changed. Here we update the |
261 value in the locale. |
263 value in the locale. |
262 */ |
264 */ |
263 void ClockRegionalSettingsView::handleDateSeparatorChange(QString text) |
265 void ClockRegionalSettingsView::handleDateSeparatorChange(QString text) |
264 { |
266 { |
265 mSettingsUtility.setDateSeparator(text); |
267 mSettingsUtility->setDateSeparator(text); |
266 } |
268 } |
267 |
269 |
268 /*! |
270 /*! |
269 This slot is called any item in the data form is changed. |
271 This slot is called any item in the data form is changed. |
270 */ |
272 */ |
271 void ClockRegionalSettingsView::handleDataChanged( |
273 void ClockRegionalSettingsView::handleDataChanged( |
272 const QModelIndex& topLeft, const QModelIndex& bottomRight) |
274 const QModelIndex& topLeft, const QModelIndex& bottomRight) |
273 { |
275 { |
274 qDebug("clock: ClockRegionalSettingsView::handleDataChanged() -->"); |
|
275 |
|
276 Q_UNUSED(bottomRight) |
276 Q_UNUSED(bottomRight) |
277 |
277 |
278 |
278 |
279 switch (topLeft.row()) { |
279 switch (topLeft.row()) { |
280 case 5: |
280 case 5: |
281 { |
281 { |
282 // The Start of week item. |
282 // The Start of week item. |
283 if (mStartOfWeekItem != 0) { |
283 if (mStartOfWeekItem != 0) |
|
284 { |
284 int index = mStartOfWeekItem->currentIndex(); |
285 int index = mStartOfWeekItem->currentIndex(); |
285 mSettingsUtility.setStartOfWeek(index); |
286 mSettingsUtility->setStartOfWeek(index); |
286 |
287 //update the week days |
287 QStringList weekdays = weekdayList(); |
288 updateWeekDays(); |
288 QString workdays = mCustomPrototype->workdaysSetting(); |
289 } |
289 QItemSelectionModel *model = 0; |
|
290 model = mWorkdaysItem->selectionModel(); |
|
291 |
|
292 for (int i = 0, index = workdays.size() - 1; |
|
293 i < mWorkdaysItem->count(); ++i, index--) { |
|
294 QString str = weekdays[i]; |
|
295 mWorkdaysItem->item(i)->setText(str); |
|
296 |
|
297 QChar ch = workdays.at(index); |
|
298 if ( ch == QChar('0')) { |
|
299 // Not a workday. |
|
300 model->select( |
|
301 model->model()->index(i,0), |
|
302 QItemSelectionModel::Deselect); |
|
303 } else { |
|
304 // Workday. |
|
305 model->select( |
|
306 model->model()->index(i,0), |
|
307 QItemSelectionModel::Select); |
|
308 } |
|
309 } |
|
310 } |
|
311 } |
290 } |
312 break; |
291 break; |
313 |
292 |
314 default: |
293 default: |
315 break; |
294 break; |
348 if (!mFormModel) { |
327 if (!mFormModel) { |
349 createModel(); |
328 createModel(); |
350 } |
329 } |
351 |
330 |
352 // Get the locale. |
331 // Get the locale. |
353 HbExtendedLocale locale = HbExtendedLocale::system(); |
332 HbExtendedLocale locale = HbExtendedLocale::system(); |
354 |
333 |
355 // Time format item. |
334 // Time format item. |
356 mTimeFormatItem = mFormModel->appendDataFormItem( |
335 mTimeFormatItem = mFormModel->appendDataFormItem( |
357 HbDataFormModelItem::ToggleValueItem, |
336 HbDataFormModelItem::ToggleValueItem, |
358 hbTrId("txt_clock_setlabel_time_format")); |
337 hbTrId("txt_clock_setlabel_time_format")); |
359 int index = mSettingsUtility.timeFormat(mTimeFormatStringList); |
338 int index = mSettingsUtility->timeFormat(mTimeFormatStringList); |
360 if (0 == index) { |
339 if (0 == index) { |
361 mTimeFormatItem->setContentWidgetData("text", mTimeFormatStringList[0]); |
340 mTimeFormatItem->setContentWidgetData("text", mTimeFormatStringList[0]); |
362 mTimeFormatItem->setContentWidgetData("additionalText", mTimeFormatStringList[1]); |
341 mTimeFormatItem->setContentWidgetData("additionalText", mTimeFormatStringList[1]); |
363 } else { |
342 } else { |
364 mTimeFormatItem->setContentWidgetData("text", mTimeFormatStringList[1]); |
343 mTimeFormatItem->setContentWidgetData("text", mTimeFormatStringList[1]); |
370 |
349 |
371 // Time separator item. |
350 // Time separator item. |
372 mTimeSeparatorItem = mFormModel->appendDataFormItem( |
351 mTimeSeparatorItem = mFormModel->appendDataFormItem( |
373 HbDataFormModelItem::ToggleValueItem, |
352 HbDataFormModelItem::ToggleValueItem, |
374 hbTrId("txt_clock_setlabel_time_separator")); |
353 hbTrId("txt_clock_setlabel_time_separator")); |
375 index = mSettingsUtility.timeSeparator(mTimeSeparatorStringList); |
354 index = mSettingsUtility->timeSeparator(mTimeSeparatorStringList); |
376 if (0 == index) { |
355 if (0 == index) { |
377 mTimeSeparatorItem->setContentWidgetData("text", mTimeSeparatorStringList[0]); |
356 mTimeSeparatorItem->setContentWidgetData("text", mTimeSeparatorStringList[0]); |
378 mTimeSeparatorItem->setContentWidgetData( |
357 mTimeSeparatorItem->setContentWidgetData( |
379 "additionalText", mTimeSeparatorStringList[1]); |
358 "additionalText", mTimeSeparatorStringList[1]); |
380 } else { |
359 } else { |
388 |
367 |
389 // Date format. |
368 // Date format. |
390 mDateFormatItem = mFormModel->appendDataFormItem( |
369 mDateFormatItem = mFormModel->appendDataFormItem( |
391 HbDataFormModelItem::ComboBoxItem, |
370 HbDataFormModelItem::ComboBoxItem, |
392 hbTrId("txt_clock_setlabel_date_format")); |
371 hbTrId("txt_clock_setlabel_date_format")); |
393 index = mSettingsUtility.dateFormat(mDateFormatStringList); |
372 index = mSettingsUtility->dateFormat(mDateFormatStringList); |
394 |
373 |
395 mDateFormatItem->setContentWidgetData("items", mDateFormatStringList); |
374 mDateFormatItem->setContentWidgetData("items", mDateFormatStringList); |
396 mDateFormatItem->setContentWidgetData("currentIndex",index); |
375 mDateFormatItem->setContentWidgetData("currentIndex",index); |
397 mForm->addConnection( |
376 mForm->addConnection( |
398 mDateFormatItem, SIGNAL(currentIndexChanged(QString)), |
377 mDateFormatItem, SIGNAL(currentIndexChanged(QString)), |
400 |
379 |
401 // Date separator. |
380 // Date separator. |
402 mDateSeparatorItem = mFormModel->appendDataFormItem( |
381 mDateSeparatorItem = mFormModel->appendDataFormItem( |
403 HbDataFormModelItem::ComboBoxItem, |
382 HbDataFormModelItem::ComboBoxItem, |
404 hbTrId("txt_clock_setlabel_date_separator")); |
383 hbTrId("txt_clock_setlabel_date_separator")); |
405 index = mSettingsUtility.dateSeparator(mDateSeparatorStringList); |
384 index = mSettingsUtility->dateSeparator(mDateSeparatorStringList); |
406 |
385 |
407 mDateSeparatorItem->setContentWidgetData("items", mDateSeparatorStringList); |
386 mDateSeparatorItem->setContentWidgetData("items", mDateSeparatorStringList); |
408 mDateSeparatorItem->setContentWidgetData("currentIndex",index); |
387 mDateSeparatorItem->setContentWidgetData("currentIndex",index); |
409 mForm->addConnection( |
388 mForm->addConnection( |
410 mDateSeparatorItem, SIGNAL(currentIndexChanged(QString)), |
389 mDateSeparatorItem, SIGNAL(currentIndexChanged(QString)), |
469 } |
448 } |
470 |
449 |
471 return weekDays; |
450 return weekDays; |
472 } |
451 } |
473 |
452 |
|
453 |
|
454 /*! |
|
455 update the start week on . |
|
456 */ |
|
457 |
|
458 void ClockRegionalSettingsView::updateWeekStartOn() |
|
459 { |
|
460 if (mStartOfWeekItem != 0) |
|
461 { |
|
462 HbExtendedLocale locale; |
|
463 HbExtendedLocale::WeekDay weekdDayStart = locale.startOfWeek(); |
|
464 int currentDay = mStartOfWeekItem->currentIndex(); |
|
465 if(currentDay == weekdDayStart ) |
|
466 { |
|
467 return; |
|
468 } |
|
469 else |
|
470 { |
|
471 mStartOfWeekItem->setCurrentIndex(weekdDayStart); |
|
472 updateWeekDays(); |
|
473 } |
|
474 } |
|
475 } |
|
476 |
|
477 /*! |
|
478 update the week days . |
|
479 */ |
|
480 void ClockRegionalSettingsView::updateWeekDays() |
|
481 { |
|
482 QStringList weekdays = weekdayList(); |
|
483 QString workdays = mCustomPrototype->workdaysSetting(); |
|
484 QItemSelectionModel *model = 0; |
|
485 model = mWorkdaysItem->selectionModel(); |
|
486 |
|
487 for (int i = 0, index = workdays.size() - 1; |
|
488 i < mWorkdaysItem->count(); ++i, index--) |
|
489 { |
|
490 QString str = weekdays[i]; |
|
491 mWorkdaysItem->item(i)->setText(str); |
|
492 |
|
493 QChar ch = workdays.at(index); |
|
494 if ( ch == QChar('0')) |
|
495 { |
|
496 // Not a workday. |
|
497 model->select( |
|
498 model->model()->index(i,0), |
|
499 QItemSelectionModel::Deselect); |
|
500 } |
|
501 else |
|
502 { |
|
503 // Workday. |
|
504 model->select( |
|
505 model->model()->index(i,0), |
|
506 QItemSelectionModel::Select);} |
|
507 } |
|
508 } |
474 // End of file --Don't remove this. |
509 // End of file --Don't remove this. |