|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Definition file for class ClockSettingsView. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <QGraphicsLinearLayout> |
|
21 #include <QItemSelectionModel> |
|
22 #include <HbDataFormModelItem> |
|
23 #include <HbDataFormModel> |
|
24 #include <HbPushButton> |
|
25 #include <HbLabel> |
|
26 #include <HbDateTimePicker> |
|
27 #include <HbAction> |
|
28 #include <HbListWidget> |
|
29 #include <HbExtendedLocale> |
|
30 #include <HbListWidgetItem> |
|
31 |
|
32 // User includes |
|
33 #include "settingscustomitem.h" |
|
34 #include "settingsdatatypes.h" |
|
35 #include "settingsutility.h" |
|
36 #include "clockcityselectionlist.h" |
|
37 #include "timezoneclient.h" |
|
38 #include "clockregionalsettingsview.h" |
|
39 |
|
40 /*! |
|
41 \class SettingsCustomItem |
|
42 |
|
43 This class is responsible for creating custom items for clock settings. |
|
44 */ |
|
45 |
|
46 /*! |
|
47 Default Constructor. |
|
48 |
|
49 \param parent The parent. |
|
50 */ |
|
51 |
|
52 SettingsCustomItem::SettingsCustomItem(QGraphicsItem *parent) |
|
53 :HbDataFormViewItem(parent) |
|
54 { |
|
55 // Construct the settignsutility. |
|
56 mSettingsUtility = new SettingsUtility(); |
|
57 } |
|
58 |
|
59 /*! |
|
60 Destructor. |
|
61 */ |
|
62 SettingsCustomItem::~SettingsCustomItem() |
|
63 { |
|
64 |
|
65 } |
|
66 |
|
67 /*! |
|
68 \reimp |
|
69 Creates SettingsCustomItem. |
|
70 */ |
|
71 HbAbstractViewItem* SettingsCustomItem::createItem() |
|
72 { |
|
73 return new SettingsCustomItem(*this); |
|
74 } |
|
75 |
|
76 /*! |
|
77 |
|
78 \sa |
|
79 */ |
|
80 bool SettingsCustomItem::canSetModelIndex(const QModelIndex &index) const |
|
81 { |
|
82 HbDataFormModelItem::DataItemType itemType = |
|
83 static_cast<HbDataFormModelItem::DataItemType>( |
|
84 index.data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
85 |
|
86 if(itemType >= HbDataFormModelItem::CustomItemBase && |
|
87 itemType <= (HbDataFormModelItem::CustomItemBase + 50)) { |
|
88 return true; |
|
89 } else { |
|
90 return false; |
|
91 } |
|
92 |
|
93 } |
|
94 |
|
95 void SettingsCustomItem::restore() |
|
96 { |
|
97 HbDataFormModelItem::DataItemType itemType = |
|
98 static_cast<HbDataFormModelItem::DataItemType>( |
|
99 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
100 |
|
101 HbDataFormModel* model = |
|
102 static_cast<HbDataFormModel*>( |
|
103 static_cast<HbAbstractViewItem*>(this)->itemView()->model()); |
|
104 HbDataFormModelItem* modlItem = model->itemFromIndex(modelIndex()); |
|
105 |
|
106 switch (itemType) { |
|
107 case (TimeItemOffset + HbDataFormModelItem::CustomItemBase): |
|
108 mTimeWidget->setProperty("text", modlItem->contentWidgetData("text")); |
|
109 break; |
|
110 |
|
111 case (DateItemOffset + HbDataFormModelItem::CustomItemBase): |
|
112 mDateWidget->setProperty("text", modlItem->contentWidgetData("text")); |
|
113 break; |
|
114 |
|
115 case (PlaceItemOffset + HbDataFormModelItem::CustomItemBase): |
|
116 mPlaceWidget->setProperty("text", modlItem->contentWidgetData("text")); |
|
117 break; |
|
118 /* case (RegionalItemOffset + HbDataFormModelItem::CustomItemBase): |
|
119 |
|
120 break;*/ |
|
121 case (50 + HbDataFormModelItem::CustomItemBase): |
|
122 |
|
123 break; |
|
124 default: |
|
125 break; |
|
126 } |
|
127 } |
|
128 |
|
129 void SettingsCustomItem::setWeekdaysList(QStringList list) |
|
130 { |
|
131 mWeekdaysList = list; |
|
132 } |
|
133 |
|
134 /*! |
|
135 \reimp |
|
136 Creates custom data form item. |
|
137 */ |
|
138 HbWidget* SettingsCustomItem::createCustomWidget() |
|
139 { |
|
140 HbDataFormModelItem::DataItemType itemType = |
|
141 static_cast<HbDataFormModelItem::DataItemType>(modelIndex() |
|
142 .data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
143 |
|
144 switch (itemType) { |
|
145 case (TimeItemOffset + HbDataFormModelItem::CustomItemBase): |
|
146 { |
|
147 mTimeWidget = new HbPushButton(this); |
|
148 connect( |
|
149 mTimeWidget, SIGNAL(clicked()), |
|
150 this, SLOT(launchTimePicker())); |
|
151 return mTimeWidget; |
|
152 } |
|
153 |
|
154 case (DateItemOffset + HbDataFormModelItem::CustomItemBase): |
|
155 { |
|
156 mDateWidget = new HbPushButton(this); |
|
157 connect( |
|
158 mDateWidget, SIGNAL(clicked()), |
|
159 this, SLOT(launchDatePicker())); |
|
160 return mDateWidget; |
|
161 } |
|
162 |
|
163 case (PlaceItemOffset + HbDataFormModelItem::CustomItemBase): |
|
164 { |
|
165 mPlaceWidget = new HbPushButton(this); |
|
166 connect( |
|
167 mPlaceWidget, SIGNAL(clicked()), |
|
168 this, SLOT(launchCitySelectionList())); |
|
169 return mPlaceWidget; |
|
170 } |
|
171 |
|
172 case (RegionalItemOffset + HbDataFormModelItem::CustomItemBase): |
|
173 { |
|
174 HbPushButton *regSettingsItem = new HbPushButton(this); |
|
175 regSettingsItem->setText( |
|
176 QString(hbTrId("txt_clock_button_regional_date_time_settings"))); |
|
177 connect( |
|
178 regSettingsItem, SIGNAL(clicked()), |
|
179 this, SLOT(launchRegSettingsView())); |
|
180 return regSettingsItem; |
|
181 } |
|
182 |
|
183 case (50 + HbDataFormModelItem::CustomItemBase): |
|
184 { |
|
185 HbListWidget *workdaysItem = new HbListWidget(); |
|
186 workdaysItem->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
187 QItemSelectionModel *model = 0; |
|
188 model = workdaysItem->selectionModel(); |
|
189 for (int index = 0; index < mWeekdaysList.count(); ++index) { |
|
190 workdaysItem->addItem(mWeekdaysList.at(index)); |
|
191 } |
|
192 |
|
193 QString workdaysString = workdaysSetting(); |
|
194 for (int i = 0, index = workdaysString.size() - 1; |
|
195 index >= 0; ++i, index--) { |
|
196 if (workdaysString.at(index) == QChar('0')) { |
|
197 // Not a workday. |
|
198 model->select( |
|
199 model->model()->index(i,0), |
|
200 QItemSelectionModel::Deselect); |
|
201 } else { |
|
202 // Workday. |
|
203 model->select( |
|
204 model->model()->index(i,0), |
|
205 QItemSelectionModel::Select); |
|
206 } |
|
207 } |
|
208 |
|
209 return workdaysItem; |
|
210 } |
|
211 |
|
212 default: |
|
213 return 0; |
|
214 } |
|
215 } |
|
216 |
|
217 /*! |
|
218 Launches the time picker dialog. |
|
219 */ |
|
220 void SettingsCustomItem::launchTimePicker() |
|
221 { |
|
222 if (mTimePickerDialog) { |
|
223 delete mTimePickerDialog; |
|
224 } |
|
225 |
|
226 // Create the dialog. |
|
227 mTimePickerDialog = new HbDialog; |
|
228 mTimePickerDialog->setTimeout(HbDialog::NoTimeout); |
|
229 mTimePickerDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
230 |
|
231 // Set the heading for the dialog. |
|
232 HbLabel * timeLabel = |
|
233 new HbLabel(hbTrId("txt_clock_setlabel_time"), mTimePickerDialog); |
|
234 mTimePickerDialog->setHeadingWidget(timeLabel); |
|
235 |
|
236 QStringList timeSeparator; |
|
237 int index = mSettingsUtility->timeFormat(timeSeparator); |
|
238 QString tumblerDisplayFormat = mSettingsUtility->timeFormatString() |
|
239 .replace(timeSeparator.at(index), QString(".")); |
|
240 |
|
241 // Create the tumbler. |
|
242 HbDateTimePicker *timePicker = new HbDateTimePicker(mTimePickerDialog); |
|
243 timePicker->setDisplayFormat(tumblerDisplayFormat); |
|
244 // Set the tumbler as the content widget. |
|
245 mTimePickerDialog->setContentWidget(timePicker); |
|
246 timePicker->setTime(QTime::currentTime()); |
|
247 |
|
248 HbAction *okAction = |
|
249 new HbAction(QString(hbTrId("txt_common_button_ok")), mTimePickerDialog); |
|
250 mTimePickerDialog->setPrimaryAction(okAction); |
|
251 connect( |
|
252 okAction, SIGNAL(triggered()), |
|
253 this, SLOT(handleTimeOkAction())); |
|
254 |
|
255 HbAction *cancelAction = |
|
256 new HbAction(QString(hbTrId("txt_common_button_cancel")), |
|
257 mTimePickerDialog); |
|
258 mTimePickerDialog->setSecondaryAction( cancelAction ); |
|
259 connect( |
|
260 cancelAction, SIGNAL(triggered()), |
|
261 this, SLOT(handleTimeCancelAction())); |
|
262 |
|
263 mTimePickerDialog->exec(); |
|
264 } |
|
265 |
|
266 /*! |
|
267 Handles the ok action of time picker dialog. |
|
268 */ |
|
269 void SettingsCustomItem::handleTimeOkAction() |
|
270 { |
|
271 // Get the time from the time picker. |
|
272 QTime newTime = static_cast<HbDateTimePicker *> ( |
|
273 mTimePickerDialog->contentWidget())->time(); |
|
274 |
|
275 QString timeFormatString = mSettingsUtility->timeFormatString(); |
|
276 // Update the display text on form item. |
|
277 mTimeWidget->setText(newTime.toString(timeFormatString)); |
|
278 mSettingsUtility->setTime(newTime.toString(timeFormatString)); |
|
279 |
|
280 // Close the dialog. |
|
281 handleTimeCancelAction(); |
|
282 } |
|
283 |
|
284 /*! |
|
285 Handles the cancel action of time picker dialog. |
|
286 */ |
|
287 void SettingsCustomItem::handleTimeCancelAction() |
|
288 { |
|
289 // Close the dialog. |
|
290 mTimePickerDialog->close(); |
|
291 mTimePickerDialog->deleteLater(); |
|
292 } |
|
293 |
|
294 /*! |
|
295 Launches the date picker dialog. |
|
296 */ |
|
297 void SettingsCustomItem::launchDatePicker() |
|
298 { |
|
299 if (mDatePickerDialog) { |
|
300 delete mDatePickerDialog; |
|
301 } |
|
302 |
|
303 // Create the dialog. |
|
304 mDatePickerDialog = new HbDialog; |
|
305 mDatePickerDialog->setTimeout(HbDialog::NoTimeout); |
|
306 mDatePickerDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
307 |
|
308 // Set the heading for the dialog. |
|
309 HbLabel * timeLabel = |
|
310 new HbLabel(hbTrId("txt_clock_setlabel_date"), mDatePickerDialog); |
|
311 mDatePickerDialog->setHeadingWidget(timeLabel); |
|
312 |
|
313 // Create the tumbler. |
|
314 HbDateTimePicker *datePicker = new HbDateTimePicker(mDatePickerDialog); |
|
315 datePicker->setDisplayFormat(mSettingsUtility->dateFormatString()); |
|
316 datePicker->setMinimumDate(QDate(2010, 01, 01)); |
|
317 // Set the tumbler as the content widget. |
|
318 mDatePickerDialog->setContentWidget(datePicker); |
|
319 datePicker->setDate(QDate::currentDate()); |
|
320 |
|
321 HbAction *okAction = |
|
322 new HbAction(QString(hbTrId("txt_common_button_ok")), mDatePickerDialog); |
|
323 mDatePickerDialog->setPrimaryAction(okAction); |
|
324 connect( |
|
325 okAction, SIGNAL(triggered()), |
|
326 this, SLOT(handleDateOkAction())); |
|
327 |
|
328 HbAction *cancelAction = |
|
329 new HbAction(QString(hbTrId("txt_common_button_cancel")), |
|
330 mDatePickerDialog); |
|
331 mDatePickerDialog->setSecondaryAction( cancelAction ); |
|
332 connect( |
|
333 cancelAction, SIGNAL(triggered()), |
|
334 this, SLOT(handleDateCancelAction())); |
|
335 |
|
336 mDatePickerDialog->exec(); |
|
337 } |
|
338 |
|
339 /*! |
|
340 Handles the ok action of date picker dialog. |
|
341 */ |
|
342 void SettingsCustomItem::handleDateOkAction() |
|
343 { |
|
344 // Get the time from the time picker. |
|
345 QDate newDate = static_cast<HbDateTimePicker *> ( |
|
346 mDatePickerDialog->contentWidget())->date(); |
|
347 |
|
348 QString dateFormatString = mSettingsUtility->dateFormatString(); |
|
349 // Update the display text on form item. |
|
350 mDateWidget->setText(newDate.toString(dateFormatString)); |
|
351 mSettingsUtility->setDate(newDate.toString(dateFormatString)); |
|
352 |
|
353 // Close the dialog. |
|
354 handleDateCancelAction(); |
|
355 } |
|
356 |
|
357 /*! |
|
358 Handles the ok action of date picker dialog. |
|
359 */ |
|
360 void SettingsCustomItem::handleDateCancelAction() |
|
361 { |
|
362 // Close the dialog. |
|
363 mDatePickerDialog->close(); |
|
364 mDatePickerDialog->deleteLater(); |
|
365 } |
|
366 |
|
367 /*! |
|
368 Launches cityselectionlist for timezone selection. |
|
369 */ |
|
370 void SettingsCustomItem::launchCitySelectionList() |
|
371 { |
|
372 mCitySelectionList = new ClockCitySelectionList(this); |
|
373 connect( |
|
374 mCitySelectionList, SIGNAL(citySelected(LocationInfo)), |
|
375 this, SLOT(updatePlaceItem(LocationInfo))); |
|
376 |
|
377 mCitySelectionList->showCityList(); |
|
378 } |
|
379 |
|
380 /*! |
|
381 Launches cityselectionlist for timezone selection. |
|
382 |
|
383 \param info Will contain the location info selected by the user. |
|
384 */ |
|
385 void SettingsCustomItem::updatePlaceItem(LocationInfo info) |
|
386 { |
|
387 if (-1 != info.timezoneId) { |
|
388 // Construct the timezone client. |
|
389 mTimezoneClient = new TimezoneClient(); |
|
390 mTimezoneClient->setAsCurrentLocationL(info); |
|
391 } |
|
392 } |
|
393 |
|
394 /*! |
|
395 Launches the regional settings view. |
|
396 */ |
|
397 void SettingsCustomItem::launchRegSettingsView() |
|
398 { |
|
399 ClockRegionalSettingsView *view = |
|
400 new ClockRegionalSettingsView(*mSettingsUtility); |
|
401 view->showView(); |
|
402 } |
|
403 |
|
404 /*! |
|
405 Returns the workdays setting string based on start of week setting. |
|
406 */ |
|
407 QString SettingsCustomItem::workdaysSetting() |
|
408 { |
|
409 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
410 // 0(Sun)0(sat)1(Fri)1(Thu)1(Wed)1(Tue)1(Mon) |
|
411 QString workdaysString = locale.workDays(); |
|
412 QString workdays = workdaysString; |
|
413 HbExtendedLocale::WeekDay startOfWeekIndex = |
|
414 HbExtendedLocale::system().startOfWeek(); |
|
415 int max = workdaysString.size() - 1; |
|
416 for (int index = max - startOfWeekIndex, i = max; i >= 0; i--) { |
|
417 QChar ch = workdaysString.at(index); |
|
418 workdays.replace(i, 1, ch); |
|
419 if (index == 0) { |
|
420 index = max; |
|
421 } else { |
|
422 index--; |
|
423 } |
|
424 } |
|
425 // workdays.append('\0'); |
|
426 |
|
427 return workdays; |
|
428 } |
|
429 |
|
430 // End of file --Don't remove this. |