|
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: FTU wizard plugin view implementaion |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QObject> |
|
20 #include <QDate> |
|
21 #include <QTime> |
|
22 #include <qabstractitemmodel.h> |
|
23 #include <hbdataform.h> |
|
24 #include <hbview.h> |
|
25 #include <hbdataformmodel.h> |
|
26 #include <hbpushbutton.h> |
|
27 #include <hbdataformviewitem.h> |
|
28 #include <hbdatetimepicker.h> |
|
29 #include <hbaction.h> |
|
30 #include <xqsettingsmanager.h> |
|
31 #include <xqsettingskey.h> |
|
32 |
|
33 // User includes |
|
34 #include "settingsutility.h" |
|
35 #include "timezoneclient.h" |
|
36 #include "ftudatetimeview.h" |
|
37 #include "ftudatetimecustomitem.h" |
|
38 #include "ftudatetimeprivatecrkeys.h" |
|
39 |
|
40 /*! |
|
41 \class FtuDateTimeView |
|
42 This is the view class for the FTU plugin |
|
43 */ |
|
44 /*! |
|
45 \enum FtuDateTimeView::dateTimePicker |
|
46 This enum defines different pickers to be launched(date picker/time picker) |
|
47 */ |
|
48 /*! |
|
49 \var FtuDateTimeView::datePicker |
|
50 Date picker. |
|
51 */ |
|
52 /*! |
|
53 \var FtuDateTimeView::timePicker |
|
54 Time picker. |
|
55 */ |
|
56 |
|
57 /*! |
|
58 Constructor. |
|
59 */ |
|
60 FtuDateTimeView::FtuDateTimeView() : |
|
61 HbView(), |
|
62 mDatePicker(NULL), |
|
63 mTimePicker(NULL), |
|
64 mDatetimepopup(NULL) |
|
65 { |
|
66 //TODO: Localisation has to be done |
|
67 // set title for wizard |
|
68 setTitle("Date and Time"); |
|
69 mDateTimePlaceForm = new HbDataForm(); |
|
70 |
|
71 QList <HbAbstractViewItem*> prototypes = mDateTimePlaceForm->itemPrototypes(); |
|
72 FtuDateTimeCustomItem *customItem = |
|
73 new FtuDateTimeCustomItem(mDateTimePlaceForm); |
|
74 prototypes.append(customItem); |
|
75 mDateTimePlaceForm->setItemPrototypes(prototypes); |
|
76 |
|
77 // Construct the settings utility. |
|
78 mSettingsUtility = new SettingsUtility(); |
|
79 mTimeZoneClient = new TimezoneClient(); |
|
80 mTimeAutoUpdate = mTimeZoneClient->timeUpdateOn(); |
|
81 } |
|
82 |
|
83 /*! |
|
84 Destructor. |
|
85 */ |
|
86 FtuDateTimeView::~FtuDateTimeView() |
|
87 { |
|
88 delete mDateTimePlaceForm; |
|
89 delete mDateTimePlaceModel; |
|
90 delete mSettingsUtility; |
|
91 } |
|
92 /*! |
|
93 Creates the main view. |
|
94 */ |
|
95 void FtuDateTimeView::constructView() |
|
96 { |
|
97 createMainLayout(); |
|
98 setWidget(mDateTimePlaceForm); |
|
99 } |
|
100 |
|
101 /*! |
|
102 Implemantation to create the main layout using the dataform. |
|
103 */ |
|
104 void FtuDateTimeView::createMainLayout() |
|
105 { |
|
106 if (mDateTimePlaceForm->model()) { |
|
107 delete mDateTimePlaceForm->model(); |
|
108 mDateTimePlaceForm->setModel(0); |
|
109 } |
|
110 |
|
111 mDateTimePlaceModel = new HbDataFormModel(); |
|
112 |
|
113 // Populates the datetime and place groups |
|
114 populateDateTimeGroup(); |
|
115 populatePlaceGroup(); |
|
116 |
|
117 setItemDisplayed(); |
|
118 mDateTimePlaceForm->setModel(mDateTimePlaceModel); |
|
119 } |
|
120 |
|
121 /*! |
|
122 Populates the Date and Time Group. |
|
123 */ |
|
124 void FtuDateTimeView::populateDateTimeGroup() |
|
125 { |
|
126 HbDataFormModelItem *dateTimeGroup = |
|
127 mDateTimePlaceModel->appendDataFormGroup |
|
128 (QString(tr("Date and Time")), |
|
129 mDateTimePlaceModel->invisibleRootItem()); |
|
130 |
|
131 //Custom Date item |
|
132 mDateItem = mDateTimePlaceModel->appendDataFormItem( |
|
133 HbDataFormModelItem::CustomItemBase, |
|
134 QString(tr("Date")), dateTimeGroup); |
|
135 // Custom Time item |
|
136 mTimeItem = mDateTimePlaceModel->appendDataFormItem( |
|
137 HbDataFormModelItem::CustomItemBase, |
|
138 QString(tr("Time")), dateTimeGroup); |
|
139 // Auto TimeUpdate item |
|
140 mAutoTimeUpdateItem = mDateTimePlaceModel->appendDataFormItem( |
|
141 HbDataFormModelItem::CustomItemBase, |
|
142 QString(tr("Time Autoupdate")), dateTimeGroup); |
|
143 |
|
144 // Connect the items to the proper slots |
|
145 mDateTimePlaceForm->addConnection(mDateItem, SIGNAL(clicked()), this, |
|
146 SLOT(populateDatePicker())); |
|
147 mDateTimePlaceForm->addConnection(mTimeItem, SIGNAL(clicked()), this, |
|
148 SLOT(populateTimePicker())); |
|
149 mDateTimePlaceForm->addConnection(mAutoTimeUpdateItem, SIGNAL(clicked()), |
|
150 this, SLOT(setAutoTimeupDate())); |
|
151 } |
|
152 |
|
153 /*! |
|
154 Populates the Place Group. |
|
155 */ |
|
156 void FtuDateTimeView::populatePlaceGroup() |
|
157 { |
|
158 mPlaceGroup = mDateTimePlaceModel->appendDataFormGroup(QString(tr("Place")), |
|
159 mDateTimePlaceModel->invisibleRootItem()); |
|
160 // Custom country item |
|
161 mCountryItem = mDateTimePlaceModel->appendDataFormItem( |
|
162 HbDataFormModelItem::CustomItemBase, |
|
163 QString(tr("Country")), mPlaceGroup); |
|
164 // Custom city item |
|
165 mCityItem = mDateTimePlaceModel->appendDataFormItem( |
|
166 HbDataFormModelItem::CustomItemBase, |
|
167 QString(tr("City")), mPlaceGroup); |
|
168 |
|
169 // Connect the items to the proper slots |
|
170 mDateTimePlaceForm->addConnection(mCountryItem, SIGNAL(clicked()), this, |
|
171 SLOT(populateCitySelectionList())); |
|
172 mDateTimePlaceForm->addConnection(mCityItem, SIGNAL(clicked()), this, |
|
173 SLOT(populateCitySelectionList())); |
|
174 |
|
175 |
|
176 } |
|
177 |
|
178 /*! |
|
179 Sets the item index. |
|
180 */ |
|
181 void FtuDateTimeView::setItemDisplayed() |
|
182 { |
|
183 // Display the items with proper data |
|
184 mDateItem->setContentWidgetData("text", mSettingsUtility->date()); |
|
185 mTimeItem->setContentWidgetData("text", mSettingsUtility->time()); |
|
186 |
|
187 if (mTimeAutoUpdate) { |
|
188 mAutoTimeUpdateItem->setContentWidgetData("text", tr("ON")); |
|
189 } else { |
|
190 mAutoTimeUpdateItem->setContentWidgetData("text", tr("OFF")); |
|
191 } |
|
192 mCountryItem->setContentWidgetData("text", |
|
193 mTimeZoneClient->getCurrentZoneInfoL().countryName); |
|
194 mCityItem->setContentWidgetData("text", |
|
195 mTimeZoneClient->getCurrentZoneInfoL().cityName); |
|
196 |
|
197 // Set the date,time,country and city fields disable |
|
198 // if auto time update is ON |
|
199 if (mTimeAutoUpdate) { |
|
200 mDateItem->setEnabled(false); |
|
201 mTimeItem->setEnabled(false); |
|
202 mCountryItem->setEnabled(false); |
|
203 mCityItem->setEnabled(false); |
|
204 } |
|
205 } |
|
206 |
|
207 /*! |
|
208 Populates the Date Picker. |
|
209 */ |
|
210 void FtuDateTimeView::populateDatePicker() |
|
211 { |
|
212 if (mDatetimepopup) { |
|
213 delete mDatetimepopup; |
|
214 mDatetimepopup = NULL; |
|
215 } |
|
216 mDatetimepopup = new HbDialog(); |
|
217 |
|
218 mDatetimepopup->setDismissPolicy(HbDialog::NoDismiss); |
|
219 mDatetimepopup->setTimeout(HbDialog::NoDismiss); |
|
220 |
|
221 if(mDatePicker) { |
|
222 mDatePicker = NULL; |
|
223 } |
|
224 mDatePicker = new HbDateTimePicker(QDate::currentDate(), |
|
225 this); |
|
226 mDatePicker->setMinimumDate(QDate::fromString("01/01/1900", "dd/MM/yyyy")); |
|
227 mDatePicker->setMaximumDate(QDate::fromString("31/12/2100", "dd/MM/yyyy")); |
|
228 mDatePicker->setDisplayFormat(mSettingsUtility->dateFormatString()); |
|
229 |
|
230 // Sets the primary action and secondary action |
|
231 HbAction *primaryAction = new HbAction(tr("OK"), mDatetimepopup); |
|
232 HbAction *secondaryAction = new HbAction(tr("Cancel"), mDatetimepopup); |
|
233 |
|
234 mDatetimepopup->setPrimaryAction(primaryAction); |
|
235 mDatetimepopup->setSecondaryAction(secondaryAction); |
|
236 mDatetimepopup->setContentWidget(mDatePicker); |
|
237 |
|
238 connect(primaryAction, SIGNAL(triggered()), this, SLOT(updateDate())); |
|
239 connect(secondaryAction, SIGNAL(triggered()), mDatetimepopup, SLOT(close())); |
|
240 mDatetimepopup->exec(); |
|
241 } |
|
242 |
|
243 /*! |
|
244 Populates the Time Picker. |
|
245 */ |
|
246 void FtuDateTimeView::populateTimePicker() |
|
247 { |
|
248 if (mDatetimepopup) { |
|
249 delete mDatetimepopup; |
|
250 mDatetimepopup = NULL; |
|
251 } |
|
252 mDatetimepopup = new HbDialog(); |
|
253 mDatetimepopup->setDismissPolicy(HbDialog::NoDismiss); |
|
254 mDatetimepopup->setTimeout(HbDialog::NoDismiss); |
|
255 |
|
256 if(mTimePicker) { |
|
257 mTimePicker = NULL; |
|
258 } |
|
259 mTimePicker = new HbDateTimePicker(QTime().currentTime(), |
|
260 this); |
|
261 mTimePicker->setDisplayFormat(mSettingsUtility->timeFormatString()); |
|
262 |
|
263 // Sets the primary action and secondary action |
|
264 HbAction *primaryAction = new HbAction(tr("OK"), mDatetimepopup); |
|
265 HbAction *secondaryAction = new HbAction(tr("Cancel"), mDatetimepopup); |
|
266 |
|
267 mDatetimepopup->setPrimaryAction(primaryAction); |
|
268 mDatetimepopup->setSecondaryAction(secondaryAction); |
|
269 |
|
270 mDatetimepopup->setContentWidget(mTimePicker); |
|
271 |
|
272 connect(primaryAction, SIGNAL(triggered()), this, SLOT(updateTime())); |
|
273 connect(secondaryAction, SIGNAL(triggered()), mDatetimepopup, SLOT(close())); |
|
274 |
|
275 mDatetimepopup->exec(); |
|
276 } |
|
277 |
|
278 /*! |
|
279 Sets the Auto Time update. |
|
280 */ |
|
281 void FtuDateTimeView::setAutoTimeupDate() |
|
282 { |
|
283 if (mTimeAutoUpdate) { |
|
284 mAutoTimeUpdateItem->setContentWidgetData("text", "OFF"); |
|
285 // Set the fields enabled if auto time update is OFF |
|
286 mDateItem->setEnabled(true); |
|
287 mTimeItem->setEnabled(true); |
|
288 mCountryItem->setEnabled(true); |
|
289 mCityItem->setEnabled(true); |
|
290 // SetAutomaticTimeUpdate OFF, UnLoad the Plugins |
|
291 setAutomaticTimeUpdateOff(false); |
|
292 } else { |
|
293 mAutoTimeUpdateItem->setContentWidgetData("text", "ON"); |
|
294 // Set the fields disabled if auto time update is ON |
|
295 mDateItem->setEnabled(false); |
|
296 mTimeItem->setEnabled(false); |
|
297 mCountryItem->setEnabled(false); |
|
298 mCityItem->setEnabled(false); |
|
299 // SetAutomaticTimeUpdate ON, Load the Plugins |
|
300 setAutomaticTimeUpdateOff(true); |
|
301 } |
|
302 wizardEditedDate(QDate::currentDate()); |
|
303 } |
|
304 |
|
305 /*! |
|
306 Populates the City Selection List. |
|
307 */ |
|
308 void FtuDateTimeView::populateCitySelectionList() |
|
309 { |
|
310 if(mCitySelectionList) { |
|
311 mCitySelectionList = NULL; |
|
312 } |
|
313 mCitySelectionList = new ClockCitySelectionList(mTimeZoneClient, this); |
|
314 connect(mCitySelectionList,SIGNAL(citySelected(LocationInfo)), |
|
315 SLOT(HandleLocationChange(LocationInfo))); |
|
316 mCitySelectionList->showCityList(); |
|
317 } |
|
318 |
|
319 /*! |
|
320 Slot to handle the case when a city has been selected from the city. |
|
321 \param info of type LocationInfo which contains the city selected. |
|
322 */ |
|
323 void FtuDateTimeView::HandleLocationChange(LocationInfo location) |
|
324 { |
|
325 // Check if the location is valid. If its not valid the timezoneId will be -1 |
|
326 if(location.timezoneId != -1) { |
|
327 // Set the location |
|
328 mTimeZoneClient->setAsCurrentLocationL(location); |
|
329 mCountryItem->setContentWidgetData("text", location.countryName); |
|
330 mCityItem->setContentWidgetData("text", location.cityName); |
|
331 } |
|
332 // Cleanup |
|
333 mCitySelectionList->deleteLater(); |
|
334 } |
|
335 |
|
336 /*! |
|
337 Sets the device date. |
|
338 */ |
|
339 void FtuDateTimeView::updateDate() |
|
340 { |
|
341 QDate date = mDatePicker->date(); |
|
342 // Set device Date |
|
343 if (date.isValid()) { |
|
344 mDateItem->setContentWidgetData("text", |
|
345 date.toString(mSettingsUtility->dateFormatString())); |
|
346 mTimeZoneClient->setDateTime(QDateTime(date, QTime::currentTime())); |
|
347 wizardEditedDate(date); |
|
348 } |
|
349 } |
|
350 |
|
351 /*! |
|
352 Sets the device time. |
|
353 */ |
|
354 void FtuDateTimeView::updateTime() |
|
355 { |
|
356 QTime time = mTimePicker->time(); |
|
357 // Set device Time |
|
358 if (time.isValid()) { |
|
359 mTimeItem->setContentWidgetData("text", |
|
360 time.toString(mSettingsUtility->timeFormatString())); |
|
361 mTimeZoneClient->setDateTime(QDateTime(QDate::currentDate(), time)); |
|
362 wizardEditedDate(QDate::currentDate()); |
|
363 } |
|
364 |
|
365 } |
|
366 |
|
367 /*! |
|
368 Gets the wizard completed status. |
|
369 */ |
|
370 QDate FtuDateTimeView::getWizardCompletedDate() |
|
371 { |
|
372 XQSettingsManager *settingsManager = new XQSettingsManager(); |
|
373 XQSettingsKey *ftuPluginDateCenrepKey = |
|
374 new XQSettingsKey(XQSettingsKey::TargetCentralRepository, |
|
375 KCRUidClockApp, KFtuPluginDate); |
|
376 // Read the initial values from the cenrep |
|
377 QString dateString = settingsManager->readItemValue(*ftuPluginDateCenrepKey, |
|
378 XQSettingsManager::TypeString).toString(); |
|
379 QDate completedDate = QDate::fromString(dateString, |
|
380 mSettingsUtility->dateFormatString()); |
|
381 |
|
382 // Cleanup. |
|
383 delete ftuPluginDateCenrepKey; |
|
384 delete settingsManager; |
|
385 |
|
386 return completedDate; |
|
387 } |
|
388 |
|
389 /*! |
|
390 Gets the wizard Edited date. |
|
391 */ |
|
392 void FtuDateTimeView::wizardEditedDate(const QDate &date) |
|
393 { |
|
394 XQSettingsManager *settingsManager = new XQSettingsManager(); |
|
395 XQSettingsKey *ftuPluginDateCenrepKey = |
|
396 new XQSettingsKey(XQSettingsKey::TargetCentralRepository, |
|
397 KCRUidClockApp, KFtuPluginDate); |
|
398 QString dateString = date.toString(mSettingsUtility->dateFormatString()); |
|
399 settingsManager->writeItemValue(*ftuPluginDateCenrepKey,dateString); |
|
400 |
|
401 // Cleanup. |
|
402 delete ftuPluginDateCenrepKey; |
|
403 delete settingsManager; |
|
404 } |
|
405 |
|
406 /*! |
|
407 To set AutomaticTimeUpdate |
|
408 */ |
|
409 void FtuDateTimeView::setAutomaticTimeUpdateOff(bool value) |
|
410 { |
|
411 mTimeZoneClient->setTimeUpdateOn(value); |
|
412 mTimeAutoUpdate = value; |
|
413 } |
|
414 // End of file --Don't remove this. |