|
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 ClockCitySelectionListPrivate. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <QStandardItemModel> |
|
21 #include <QModelIndex> |
|
22 #include <QGraphicsScene> |
|
23 #include <QTimer> |
|
24 #include <HbDocumentLoader> |
|
25 #include <HbView> |
|
26 #include <HbListView> |
|
27 #include <HbListViewItem> |
|
28 #include <HbMainWindow> |
|
29 #include <HbInstance> |
|
30 #include <HbStyleLoader> |
|
31 #include <HbAction> |
|
32 #include <HbSearchPanel> |
|
33 #include <HbLineEdit> |
|
34 #include <HbDialog> |
|
35 #include <HbLabel> |
|
36 #include <HbComboBox> |
|
37 #include <HbExtendedLocale> |
|
38 #include <HbAbstractItemView> |
|
39 #include <HbShrinkingVkbHost> |
|
40 |
|
41 // User includes |
|
42 #include "clockcityselectionlist_p.h" |
|
43 #include "clockcityselectionlist.h" |
|
44 #include "clockcitylistproxymodel.h" |
|
45 #include "clockcityselectionlistcommon.h" |
|
46 |
|
47 #include "timezoneclient.h" |
|
48 #include "clockdatatypes.h" |
|
49 #include "OstTraceDefinitions.h" |
|
50 #ifdef OST_TRACE_COMPILER_IN_USE |
|
51 #include "clockcityselectionlist_pTraces.h" |
|
52 #endif |
|
53 |
|
54 |
|
55 /*! |
|
56 \class ClockCitySelectionListPrivate |
|
57 |
|
58 This is the private implementation class for ClockCitySelectionList class. |
|
59 */ |
|
60 |
|
61 /*! |
|
62 Default constructor. |
|
63 |
|
64 \param client The pointer to an object of TimezoneClient. |
|
65 \param parent of type QObject. |
|
66 */ |
|
67 ClockCitySelectionListPrivate::ClockCitySelectionListPrivate( |
|
68 TimezoneClient *client, QObject *parent) |
|
69 :QObject(parent), |
|
70 mLoader(0), |
|
71 mOwnsClient(false) |
|
72 { |
|
73 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_CLOCKCITYSELECTIONLISTPRIVATE_ENTRY ); |
|
74 // First get the q-pointer. |
|
75 q_ptr = static_cast<ClockCitySelectionList *> (parent); |
|
76 |
|
77 mClient = client; |
|
78 if (!mClient) { |
|
79 mClient = TimezoneClient::getInstance(); |
|
80 mOwnsClient = true; |
|
81 } |
|
82 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_CLOCKCITYSELECTIONLISTPRIVATE_EXIT ); |
|
83 } |
|
84 |
|
85 /*! |
|
86 Destructor. |
|
87 */ |
|
88 ClockCitySelectionListPrivate::~ClockCitySelectionListPrivate() |
|
89 { |
|
90 OstTraceFunctionEntry0( DUP1_CLOCKCITYSELECTIONLISTPRIVATE_CLOCKCITYSELECTIONLISTPRIVATE_ENTRY ); |
|
91 if (mOwnsClient) { |
|
92 mClient->deleteInstance(); |
|
93 } |
|
94 if (mLoader) { |
|
95 mLoader->reset(); |
|
96 delete mLoader; |
|
97 mLoader = 0; |
|
98 } |
|
99 if (mListModel) { |
|
100 delete mListModel; |
|
101 } |
|
102 if (mTimeZoneOffsetList.count()) { |
|
103 mTimeZoneOffsetList.clear(); |
|
104 } |
|
105 if(mCountryList.count()) { |
|
106 mCountryList.clear(); |
|
107 } |
|
108 if (mVirtualKeyboard) { |
|
109 delete mVirtualKeyboard; |
|
110 } |
|
111 |
|
112 OstTraceFunctionExit0( DUP1_CLOCKCITYSELECTIONLISTPRIVATE_CLOCKCITYSELECTIONLISTPRIVATE_EXIT ); |
|
113 } |
|
114 |
|
115 /*! |
|
116 Populates the list model by getting the data from timezone client. |
|
117 */ |
|
118 void ClockCitySelectionListPrivate::populateListModel() |
|
119 { |
|
120 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_POPULATELISTMODEL_ENTRY ); |
|
121 // First get the data from the timezone client. |
|
122 QList<LocationInfo> &infoList = mClient->getLocations(); |
|
123 |
|
124 // Sanity check. |
|
125 if (!mListModel) { |
|
126 mListModel = new QStandardItemModel(0, 1, this); |
|
127 } |
|
128 // Clear the model before starting population. |
|
129 mListModel->removeRows(0,infoList.count()-1); |
|
130 mListModel->insertRows(0, infoList.count()); |
|
131 mListModel->setColumnCount(1); |
|
132 |
|
133 for (int iter = 0; iter < infoList.count(); iter++) { |
|
134 QModelIndex index = mListModel->index(iter, 0); |
|
135 |
|
136 // Get the location info and add it to the model. |
|
137 LocationInfo info = infoList.at(iter); |
|
138 QString displayString; |
|
139 displayString += info.cityName; |
|
140 displayString += ", "; |
|
141 displayString += info.countryName; |
|
142 mListModel->setData(index, displayString, Qt::DisplayRole); |
|
143 mListModel->setData(index, displayString, Qt::UserRole + 100); |
|
144 |
|
145 // Now save the timezone and city group ids. |
|
146 mListModel->setData( |
|
147 index, QVariant(info.timezoneId), Qt::UserRole + 101); |
|
148 mListModel->setData( |
|
149 index, QVariant(info.cityGroupId), Qt::UserRole + 102); |
|
150 mListModel->setData( |
|
151 index, info.cityName, Qt::UserRole + 103); |
|
152 mListModel->setData( |
|
153 index, info.countryName, Qt::UserRole + 104); |
|
154 } |
|
155 |
|
156 // Cleanup. |
|
157 infoList.clear(); |
|
158 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_POPULATELISTMODEL_EXIT ); |
|
159 } |
|
160 |
|
161 /*! |
|
162 Slot to handle the case when a list item is activated. Here we return the |
|
163 city selected by the user. We emit a signal notifying this event and close |
|
164 the editor. |
|
165 */ |
|
166 void ClockCitySelectionListPrivate::handleItemActivated( |
|
167 const QModelIndex &index) |
|
168 { |
|
169 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEITEMACTIVATED_ENTRY ); |
|
170 LocationInfo selectedInfo; |
|
171 selectedInfo.timezoneId = index.data(Qt::UserRole + 101).value<int>(); |
|
172 selectedInfo.cityGroupId = index.data(Qt::UserRole + 102).value<int>(); |
|
173 selectedInfo.cityName = index.data(Qt::UserRole + 103).value<QString>(); |
|
174 selectedInfo.countryName = index.data(Qt::UserRole + 104).value<QString>(); |
|
175 selectedInfo.zoneOffset = |
|
176 mClient->getStandardOffset(selectedInfo.timezoneId); |
|
177 selectedInfo.dstOn = mClient->isDSTOnL(selectedInfo.timezoneId); |
|
178 |
|
179 // We have the information. Now emit a signal to notify clients if any. |
|
180 emit q_ptr->citySelected(selectedInfo); |
|
181 |
|
182 // Close the list. |
|
183 closeCityList(); |
|
184 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEITEMACTIVATED_EXIT ); |
|
185 } |
|
186 |
|
187 /*! |
|
188 Slot to handle back action is pressed. |
|
189 */ |
|
190 void ClockCitySelectionListPrivate::handleBackAction() |
|
191 { |
|
192 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEBACKACTION_ENTRY ); |
|
193 LocationInfo info; |
|
194 info.timezoneId = -1; |
|
195 |
|
196 // Test code... |
|
197 int rowCount = mListModel->rowCount(); |
|
198 QStandardItem *item = mListModel->item(0); |
|
199 QString text = item->data(Qt::DisplayRole).value<QString>(); |
|
200 int tz = item->data(Qt::UserRole + 100).value<int>(); |
|
201 int cg = item->data(Qt::UserRole + 101).value<int>(); |
|
202 QString ci = item->data(Qt::UserRole + 102).value<QString>(); |
|
203 QString co = item->data(Qt::UserRole + 103).value<QString>(); |
|
204 |
|
205 // Emit the signal to notify the closure. |
|
206 emit q_ptr->citySelected(info); |
|
207 |
|
208 // Close the list. |
|
209 closeCityList(); |
|
210 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEBACKACTION_EXIT ); |
|
211 } |
|
212 |
|
213 /*! |
|
214 closes the city selection list. |
|
215 */ |
|
216 void ClockCitySelectionListPrivate::closeCityList() |
|
217 { |
|
218 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_CLOSECITYLIST_ENTRY ); |
|
219 // We are done, lets remove the view off the main window. |
|
220 HbMainWindow *window = hbInstance->allMainWindows().at(0); |
|
221 window->removeView(mView); |
|
222 |
|
223 if (mLoader) { |
|
224 mLoader->reset(); |
|
225 delete mLoader; |
|
226 mLoader = 0; |
|
227 } |
|
228 |
|
229 if (mListModel) { |
|
230 delete mListModel; |
|
231 } |
|
232 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_CLOSECITYLIST_EXIT ); |
|
233 } |
|
234 |
|
235 /*! |
|
236 Updates the search criteria with the proxy model. |
|
237 |
|
238 \param criteria The string entered by the user. |
|
239 */ |
|
240 void ClockCitySelectionListPrivate::updateSearchCriteria( |
|
241 const QString &criteria) |
|
242 { |
|
243 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_UPDATESEARCHCRITERIA_ENTRY ); |
|
244 int originalMask = mListView->enabledAnimations(); |
|
245 mListView->setEnabledAnimations(HbAbstractItemView::TouchDown); |
|
246 |
|
247 // Create the reg ex so that search is performed for match immediately |
|
248 // after word boundary. |
|
249 QString searchPattern("\\b"); |
|
250 searchPattern.append(criteria); |
|
251 |
|
252 QRegExp searchExp; |
|
253 searchExp.setPattern(searchPattern); |
|
254 |
|
255 mProxyModel->setFilterRegExp(searchExp); |
|
256 mProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
257 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_UPDATESEARCHCRITERIA_EXIT ); |
|
258 } |
|
259 |
|
260 /*! |
|
261 Handles add own city menu action |
|
262 */ |
|
263 void ClockCitySelectionListPrivate::handleAddOwnCityAction() |
|
264 { |
|
265 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEADDOWNCITYACTION_ENTRY ); |
|
266 if (mAddOwnCityDialog) { |
|
267 delete mAddOwnCityDialog; |
|
268 } |
|
269 |
|
270 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
271 |
|
272 connect( |
|
273 window, SIGNAL(orientationChanged(Qt::Orientation)), |
|
274 this, SLOT(loadSection(Qt::Orientation))); |
|
275 |
|
276 mAddCityDocloader = new HbDocumentLoader(); |
|
277 bool success = false; |
|
278 mAddCityDocloader->load(":/xml/clockaddcitydialog.docml", &success); |
|
279 if (!success) { |
|
280 qFatal("Unable to load the document."); |
|
281 } |
|
282 |
|
283 // Get the dialog. |
|
284 mAddOwnCityDialog = static_cast<HbDialog *> (mAddCityDocloader->findWidget("dialog")); |
|
285 if (!mAddOwnCityDialog) { |
|
286 qFatal("Unable to get the selection view."); |
|
287 } |
|
288 mAddOwnCityDialog->setTimeout(HbDialog::NoTimeout); |
|
289 mAddOwnCityDialog->setDismissPolicy(HbDialog::NoDismiss); |
|
290 mAddOwnCityDialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
291 |
|
292 // Find the elements from the docml. |
|
293 mCityNameEdit = static_cast<HbLineEdit *> (mAddCityDocloader->findWidget("cityNameLineEdit")); |
|
294 |
|
295 mTimeZoneComboBox = static_cast<HbComboBox *> (mAddCityDocloader->findWidget("timezoneCombobox")); |
|
296 if (mTimeZoneComboBox) { |
|
297 addTimeZoneField(); |
|
298 } |
|
299 |
|
300 mCountryComboBox = static_cast<HbComboBox *> (mAddCityDocloader->findWidget("counrtyCombobox")); |
|
301 addCountryListField(); |
|
302 |
|
303 mOkAction = static_cast<HbAction *> (mAddCityDocloader->findObject("okAction")); |
|
304 |
|
305 mAddOwnCityDialog->open(this, SLOT(selectedAction(HbAction*))); |
|
306 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEADDOWNCITYACTION_EXIT ); |
|
307 } |
|
308 |
|
309 /*! |
|
310 Hanldes Ok action of add own city dialog |
|
311 */ |
|
312 void ClockCitySelectionListPrivate::handleOkAction() |
|
313 { |
|
314 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEOKACTION_ENTRY ); |
|
315 QString cityName = mCityNameEdit->text(); |
|
316 |
|
317 // Add the city if city name is not empty |
|
318 if (!cityName.isEmpty()) { |
|
319 int selectedTZOffset = |
|
320 mTimeZoneOffsetList.at(mTimeZoneComboBox->currentIndex()); |
|
321 |
|
322 QString selectedCountry = mCountryComboBox->currentText(); |
|
323 int selectedCityGroupId(-1); |
|
324 int selectedTimeZoneId(-1); |
|
325 for (int index=0;index<mCountryList.count();index++) { |
|
326 LocationInfo selectedInfo = mCountryList.at(index); |
|
327 if(!(selectedCountry.compare(selectedInfo.countryName))) { |
|
328 selectedCityGroupId = selectedInfo.cityGroupId; |
|
329 selectedTimeZoneId = selectedInfo.timezoneId; |
|
330 } |
|
331 } |
|
332 |
|
333 // Add the new city to the city list. |
|
334 LocationInfo addedCity = |
|
335 mClient->addCity(selectedTimeZoneId,cityName,selectedCityGroupId); |
|
336 |
|
337 if (!addedCity.cityName.compare(cityName)) { |
|
338 // Refresh the city list. |
|
339 populateListModel(); |
|
340 } |
|
341 } |
|
342 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLEOKACTION_EXIT ); |
|
343 } |
|
344 |
|
345 /*! |
|
346 Handles the selection of time zone offset. |
|
347 Populates the country list. |
|
348 */ |
|
349 void ClockCitySelectionListPrivate::handleTimeZoneSelection(int index) |
|
350 { |
|
351 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLETIMEZONESELECTION_ENTRY ); |
|
352 // Get the selected time zone offset. |
|
353 int selectedTimeZoneOffset = mTimeZoneOffsetList.at(index); |
|
354 |
|
355 if(mCountryList.count()) { |
|
356 mCountryList.clear(); |
|
357 } |
|
358 |
|
359 // Get country list for the offset selected |
|
360 mCountryList = mClient->getCountriesForUTCOffset(selectedTimeZoneOffset); |
|
361 int countryListCount = mCountryList.count(); |
|
362 QStringList countries; |
|
363 for(int index=0;index<countryListCount;index++) { |
|
364 countries.append(mCountryList.at(index).countryName); |
|
365 |
|
366 qSort(countries); |
|
367 mCountryComboBox->setItems(countries); |
|
368 } |
|
369 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_HANDLETIMEZONESELECTION_EXIT ); |
|
370 } |
|
371 |
|
372 /*! |
|
373 Slot to handle the selected action |
|
374 */ |
|
375 void ClockCitySelectionListPrivate::selectedAction(HbAction *action) |
|
376 { |
|
377 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_SELECTEDACTION_ENTRY ); |
|
378 if (action==mOkAction) { |
|
379 handleOkAction(); |
|
380 } |
|
381 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_SELECTEDACTION_EXIT ); |
|
382 } |
|
383 |
|
384 /*! |
|
385 Slot to handle the orientation change. |
|
386 */ |
|
387 void ClockCitySelectionListPrivate::loadSection(Qt::Orientation orientation) |
|
388 { |
|
389 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_LOADSECTION_ENTRY ); |
|
390 bool loadSuccess; |
|
391 if (mAddOwnCityDialog) { |
|
392 if (Qt::Horizontal == orientation) { |
|
393 mAddCityDocloader->load(":/xml/clockaddcitydialog.docml", |
|
394 "landscape", &loadSuccess); |
|
395 } else if (Qt::Vertical == orientation) { |
|
396 mAddCityDocloader->load(":/xml/clockaddcitydialog.docml", |
|
397 "portrait", &loadSuccess); |
|
398 } |
|
399 } |
|
400 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_LOADSECTION_EXIT ); |
|
401 } |
|
402 |
|
403 /*! |
|
404 Slot to handle close action of search panel. |
|
405 This slot cancels the search and dismisses the vkb. |
|
406 */ |
|
407 void ClockCitySelectionListPrivate::cancelSearch() |
|
408 { |
|
409 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_CANCELSEARCH_ENTRY ); |
|
410 // Clear the search criteria. |
|
411 mSearchBox->setCriteria(QString("")); |
|
412 |
|
413 // Hide the virtual keyborad. |
|
414 QInputContext *ic = qApp->inputContext(); |
|
415 if (ic) { |
|
416 QEvent *event = new QEvent(QEvent::CloseSoftwareInputPanel); |
|
417 ic->filterEvent(event); |
|
418 delete event; |
|
419 } |
|
420 |
|
421 // Set focus to the first city in the list. |
|
422 mListView->scrollTo(mProxyModel->index(0, 0)); |
|
423 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_CANCELSEARCH_EXIT ); |
|
424 } |
|
425 |
|
426 /*! |
|
427 Focuses the line edit when the city selection list is opened. |
|
428 */ |
|
429 void ClockCitySelectionListPrivate::focusLineEdit() |
|
430 { |
|
431 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_FOCUSLINEEDIT_ENTRY ); |
|
432 if (mSearchBox) { |
|
433 // mView->scene()->setFocusItem(mSearchBox); |
|
434 HbLineEdit *searchBoxEditor = 0; |
|
435 searchBoxEditor = static_cast<HbLineEdit*>( |
|
436 mSearchBox->primitive("lineedit")); |
|
437 |
|
438 if (searchBoxEditor) { |
|
439 searchBoxEditor->setInputMethodHints(Qt::ImhNoPredictiveText); |
|
440 /* HbMainWindow *window = hbInstance->allMainWindows().at(0); |
|
441 window->scene()->setFocusItem(searchBoxEditor);*/ |
|
442 |
|
443 // searchBoxEditor->setCursorPosition(0); |
|
444 searchBoxEditor->setFocus(); |
|
445 } |
|
446 |
|
447 QInputContext *ic = qApp->inputContext(); |
|
448 if (ic) { |
|
449 QEvent *event = new QEvent(QEvent::RequestSoftwareInputPanel); |
|
450 ic->filterEvent(event); |
|
451 delete event; |
|
452 } |
|
453 } |
|
454 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_FOCUSLINEEDIT_EXIT ); |
|
455 } |
|
456 |
|
457 /*! |
|
458 Displays the city selection list. |
|
459 */ |
|
460 void ClockCitySelectionListPrivate::showCityList() |
|
461 { |
|
462 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_SHOWCITYLIST_ENTRY ); |
|
463 // Construct the document loader. |
|
464 bool success = false; |
|
465 mLoader = new HbDocumentLoader; |
|
466 mLoader->load(":/xml/clockcityselectionlist.docml", &success); |
|
467 if (!success) { |
|
468 qFatal("Unable to load the document."); |
|
469 } |
|
470 |
|
471 // Get the selection view. |
|
472 mView = static_cast<HbView *> (mLoader->findWidget(CITYSELECTIONLISTVIEW)); |
|
473 if (!mView) { |
|
474 qFatal("Unable to get the selection view."); |
|
475 } |
|
476 // Set the shrinking vkb host to prevent pushing of the list. |
|
477 mVirtualKeyboard = new HbShrinkingVkbHost(mView); |
|
478 |
|
479 // Get the list view. |
|
480 mListView = static_cast<HbListView *> (mLoader->findWidget(CITYLISTVIEW)); |
|
481 if (!mListView) { |
|
482 qFatal("Unable to get the list view."); |
|
483 } |
|
484 |
|
485 // Get the searchPanel. |
|
486 mSearchBox = static_cast<HbSearchPanel *> (mLoader->findWidget("lineEdit")); |
|
487 if (!mSearchBox) { |
|
488 qFatal("Unable to get the searchpanel."); |
|
489 } |
|
490 mSearchBox->setProgressive(true); |
|
491 mSearchBox->setSearchOptionsEnabled(false); |
|
492 |
|
493 connect( |
|
494 mSearchBox, SIGNAL(criteriaChanged(QString)), |
|
495 this, SLOT(updateSearchCriteria(QString))); |
|
496 connect(mSearchBox, SIGNAL(exitClicked()), |
|
497 this, SLOT(cancelSearch())); |
|
498 |
|
499 // Construct the source model. |
|
500 if (!mListModel) { |
|
501 mListModel = new QStandardItemModel(0, 1, this); |
|
502 } |
|
503 // Construct the proxy model. |
|
504 mProxyModel = new ClockCityListProxyModel(this); |
|
505 mProxyModel->setDynamicSortFilter(true); |
|
506 mProxyModel->setSourceModel(mListModel); |
|
507 mProxyModel->setFilterRole(Qt::UserRole + 100); |
|
508 |
|
509 // Construct the model for the list. |
|
510 QTimer::singleShot(1, this, SLOT(populateListModel())); |
|
511 |
|
512 // Set the model to the list. |
|
513 mListView->setModel(mProxyModel); |
|
514 |
|
515 // Listen for list item activated signal. |
|
516 connect( |
|
517 mListView, SIGNAL(activated(QModelIndex)), |
|
518 this, SLOT(handleItemActivated(QModelIndex))); |
|
519 |
|
520 // Read the actions for menu |
|
521 mAddOwnCityAction = static_cast<HbAction *>( |
|
522 mLoader->findObject(ADDOWNCITYACTION)); |
|
523 |
|
524 // Listen for menu triggered signal |
|
525 connect( |
|
526 mAddOwnCityAction, SIGNAL(triggered()), |
|
527 this, SLOT(handleAddOwnCityAction())); |
|
528 |
|
529 // Add the view to the main window and show it. |
|
530 HbMainWindow *window = hbInstance->allMainWindows().at(0); |
|
531 mBackAction = new HbAction(Hb::BackNaviAction, this); |
|
532 mView->setNavigationAction(mBackAction); |
|
533 connect( |
|
534 mBackAction, SIGNAL(triggered()), |
|
535 this, SLOT(handleBackAction())); |
|
536 |
|
537 window->addView(mView); |
|
538 window->setCurrentView(mView); |
|
539 |
|
540 // Focus the search box. |
|
541 focusLineEdit(); |
|
542 |
|
543 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_SHOWCITYLIST_EXIT ); |
|
544 } |
|
545 |
|
546 /*! |
|
547 Get all the time zone offset texts. |
|
548 */ |
|
549 QStringList ClockCitySelectionListPrivate::getOffsetTexts() |
|
550 { |
|
551 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_GETOFFSETTEXTS_ENTRY ); |
|
552 int offsetCount(mTimeZoneOffsetList.count()); |
|
553 |
|
554 // Get all the time zone offsets |
|
555 if (!offsetCount) { |
|
556 mTimeZoneOffsetList = mClient->getAllTimeZoneOffsets(); |
|
557 offsetCount = mTimeZoneOffsetList.count(); |
|
558 } |
|
559 |
|
560 QStringList offsetTextList; |
|
561 int offsetvalue; |
|
562 QString offsetText; |
|
563 int hours; |
|
564 int minutes; |
|
565 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
566 for(int index=0;index<offsetCount;index++) { |
|
567 offsetvalue = mTimeZoneOffsetList.at(index); |
|
568 hours = offsetvalue/60; |
|
569 minutes = offsetvalue%60; |
|
570 |
|
571 if (hours>0) { |
|
572 offsetText += "+"; |
|
573 } else if (hours<0) { |
|
574 offsetText += "-"; |
|
575 } |
|
576 |
|
577 offsetText += locale.format( |
|
578 QTime(qAbs(hours),qAbs(minutes),0,0), |
|
579 r_qtn_time_durat_short_with_zero); |
|
580 |
|
581 offsetTextList.append(offsetText); |
|
582 offsetText.clear(); |
|
583 } |
|
584 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_GETOFFSETTEXTS_EXIT ); |
|
585 return offsetTextList; |
|
586 } |
|
587 |
|
588 /*! |
|
589 Add city name edit field to add own city popup. |
|
590 */ |
|
591 void ClockCitySelectionListPrivate::addCityNameField() |
|
592 { |
|
593 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_ADDCITYNAMEFIELD_ENTRY ); |
|
594 mCityNameEdit = new HbLineEdit(); |
|
595 mCityNameEdit->setFocus(Qt::MouseFocusReason); |
|
596 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_ADDCITYNAMEFIELD_EXIT ); |
|
597 } |
|
598 |
|
599 /*! |
|
600 Add timezone field to add own city popup. |
|
601 */ |
|
602 void ClockCitySelectionListPrivate::addTimeZoneField() |
|
603 { |
|
604 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_ADDTIMEZONEFIELD_ENTRY ); |
|
605 // mTimeZoneComboBox = new HbComboBox(); |
|
606 |
|
607 QStringList texts = getOffsetTexts(); |
|
608 mTimeZoneComboBox->addItems(texts); |
|
609 |
|
610 // Get the home city information. |
|
611 LocationInfo homeCityInfo = mClient->getCurrentZoneInfoL(); |
|
612 mCurrentTZOffsetIndex = mTimeZoneOffsetList.indexOf( |
|
613 homeCityInfo.zoneOffset); |
|
614 mTimeZoneComboBox->setCurrentIndex(mCurrentTZOffsetIndex); |
|
615 |
|
616 connect( |
|
617 mTimeZoneComboBox, SIGNAL(currentIndexChanged(int)), |
|
618 this, SLOT(handleTimeZoneSelection(int))); |
|
619 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_ADDTIMEZONEFIELD_EXIT ); |
|
620 } |
|
621 |
|
622 /*! |
|
623 Add country list field to add own city popup. |
|
624 */ |
|
625 void ClockCitySelectionListPrivate::addCountryListField() |
|
626 { |
|
627 OstTraceFunctionEntry0( CLOCKCITYSELECTIONLISTPRIVATE_ADDCOUNTRYLISTFIELD_ENTRY ); |
|
628 // Populate the country list based on the current TZ offset selected. |
|
629 handleTimeZoneSelection(mCurrentTZOffsetIndex); |
|
630 OstTraceFunctionExit0( CLOCKCITYSELECTIONLISTPRIVATE_ADDCOUNTRYLISTFIELD_EXIT ); |
|
631 } |
|
632 |
|
633 // End of file --Don't remove this. |