|
1 /* |
|
2 * Copyright (c) 2010 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: This class is for first basic view for positioning settings |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "possettingsform.h" |
|
20 #include "possettingspushbuttonitem.h" |
|
21 #include "possettingsgroupboxitem.h" |
|
22 #include "checkcustomviewitem.h" |
|
23 #include "possettingsengine.h" |
|
24 #include "possettingsadvview.h" |
|
25 #include <QDebug> |
|
26 #include <hbdataformmodelitem.h> |
|
27 #include <hbdataformmodel.h> |
|
28 #include <hbinstance.h> |
|
29 #include <hbaction.h> |
|
30 #include <hbstyleloader.h> |
|
31 |
|
32 static const QString FILE_PATH_CSS = ":/data"; |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // PosSettingsForm::PosSettingsForm |
|
36 // Constructor |
|
37 // --------------------------------------------------------------------------- |
|
38 PosSettingsForm::PosSettingsForm( |
|
39 PosSettingsEngine& settingsEngine, |
|
40 QGraphicsItem *parent ): |
|
41 HbDataForm( parent ),mSettingsEngine( settingsEngine ) |
|
42 { |
|
43 qDebug() << "+ PosSettingsForm::PosSettingsForm()"; |
|
44 //initialize the form model |
|
45 initSettingModel(); |
|
46 |
|
47 // slots for required signals on required controls |
|
48 addConnection( mGpsPosType, SIGNAL(released()), |
|
49 this, SLOT(onPressedGps()) ); |
|
50 addConnection( mWirelessPosType, SIGNAL(released()), |
|
51 this, SLOT(onPressedWireless()) ); |
|
52 addConnection( mBgPosType, SIGNAL(released()), |
|
53 this, SLOT(onPressedBackground()) ); |
|
54 addConnection( mAdvancedSettings, SIGNAL(clicked()), |
|
55 this, SLOT(onPressedAdvanced()) ); |
|
56 |
|
57 //to check runtime if any positioning technology installed/removed or if its visibility is changed. |
|
58 connect(&mSettingsEngine, SIGNAL(positionTechnologyChange()),this, SLOT(validateVisibility()) ); |
|
59 |
|
60 //validate visibility of controls based on visibility of positioning technology |
|
61 validateVisibility(); |
|
62 qDebug() << "- PosSettingsForm::PosSettingsForm()"; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // PosSettingsForm::~PosSettingsForm |
|
67 // Destructor |
|
68 // --------------------------------------------------------------------------- |
|
69 PosSettingsForm::~PosSettingsForm() |
|
70 { |
|
71 qDebug() << "+ PosSettingsForm::PosSettingsForm()"; |
|
72 // Remove custom layouts |
|
73 HbStyleLoader::unregisterFilePath(FILE_PATH_CSS); |
|
74 |
|
75 //TODO Disconnect of mSettingsEngine positionTechnologyChange |
|
76 |
|
77 removeConnection( mAdvancedSettings, SIGNAL(clicked()), |
|
78 this, SLOT(onPressedAdvanced()) ); |
|
79 removeConnection( mGpsPosType, SIGNAL(released), |
|
80 this, SLOT(onPressedGps()) ); |
|
81 removeConnection( mWirelessPosType, SIGNAL(released), |
|
82 this, SLOT(onPressedWireless()) ); |
|
83 removeConnection( mBgPosType, SIGNAL(released), |
|
84 this, SLOT(onPressedBackground()) ); |
|
85 |
|
86 //ToDo: removeAllConnection crashes with Kern-Exec3 error |
|
87 //removeAllConnection(); |
|
88 qDebug() << "- PosSettingsForm::PosSettingsForm()"; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // PosSettingsForm::initSettingModel |
|
93 // --------------------------------------------------------------------------- |
|
94 void PosSettingsForm::initSettingModel() |
|
95 { |
|
96 qDebug() << "+ PosSettingsForm::initSettingModel()"; |
|
97 HbDataFormModel *model = new HbDataFormModel(0); |
|
98 this->setModel(model); |
|
99 |
|
100 //set prototype for custom controls |
|
101 QList<HbAbstractViewItem *> protoTypeList = this->itemPrototypes(); |
|
102 protoTypeList.append(new PosSettingsPushButtonItem(this) ); |
|
103 protoTypeList.append(new CheckCustomViewItem()); |
|
104 protoTypeList.append(new PosSettingsGroupboxItem(this)); |
|
105 this->setItemPrototypes(protoTypeList); |
|
106 |
|
107 // Set custom layouts |
|
108 HbStyleLoader::registerFilePath(FILE_PATH_CSS); |
|
109 |
|
110 //Heading |
|
111 mHeading = model->appendDataFormItem(static_cast<HbDataFormModelItem::DataItemType>(GroupboxItem), |
|
112 QString(), |
|
113 model->invisibleRootItem()); |
|
114 mHeading->setContentWidgetData("heading", |
|
115 hbTrId("txt_loe_subtitle_positioning_settings")); |
|
116 |
|
117 |
|
118 |
|
119 //GPS |
|
120 createPosTypeModelItem(PosTypeIndexGps); |
|
121 model->appendDataFormItem(mGpsPosType, model->invisibleRootItem()); |
|
122 //Wireless |
|
123 createPosTypeModelItem(PosTypeIndexWireless); |
|
124 model->appendDataFormItem(mWirelessPosType, model->invisibleRootItem()); |
|
125 //Background |
|
126 createPosTypeModelItem(PosTypeIndexBackground); |
|
127 model->appendDataFormItem(mBgPosType, model->invisibleRootItem()); |
|
128 |
|
129 //Advance |
|
130 mAdvancedSettings = model->appendDataFormItem(static_cast<HbDataFormModelItem::DataItemType>(PushButtonItem), |
|
131 QString(), |
|
132 model->invisibleRootItem()); |
|
133 mAdvancedSettings->setContentWidgetData("text", |
|
134 hbTrId("txt_loe_button_advanced")); |
|
135 |
|
136 |
|
137 setPosTypeState(PosTypeIndexGps); |
|
138 setPosTypeState(PosTypeIndexWireless); |
|
139 setPosTypeState(PosTypeIndexBackground); |
|
140 qDebug() << "- PosSettingsForm::initSettingModel()"; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // PosSettingsForm::onPressedAdvanced |
|
145 // --------------------------------------------------------------------------- |
|
146 void PosSettingsForm::onPressedAdvanced() |
|
147 { |
|
148 qDebug() << "+ PosSettingsForm::onPressedAdvanced()"; |
|
149 mAdvancedView = new PosSettingsAdvView(); |
|
150 HbMainWindow* mainWindow = hbInstance->allMainWindows().at(0); |
|
151 |
|
152 mainWindow->addView(mAdvancedView); |
|
153 mainWindow->setCurrentView(mAdvancedView); |
|
154 |
|
155 //take back action from controlpanel main window. |
|
156 mBackAction = new HbAction(Hb::BackNaviAction ,mAdvancedView); |
|
157 mAdvancedView->setNavigationAction(mBackAction); |
|
158 |
|
159 connect(mBackAction, SIGNAL(triggered()), this, SLOT(closeAdvancedView())); |
|
160 mAdvancedView->show(); |
|
161 qDebug() << "- PosSettingsForm::onPressedAdvanced()"; |
|
162 } |
|
163 // --------------------------------------------------------------------------- |
|
164 // PosSettingsForm::closeAdvancedView |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void PosSettingsForm::closeAdvancedView() |
|
168 { |
|
169 qDebug() << "+ PosSettingsForm::closeAdvancedView()"; |
|
170 disconnect(mBackAction, SIGNAL(triggered()), this, SLOT(closeAdvancedView())); |
|
171 |
|
172 HbMainWindow* mainWindow = hbInstance->allMainWindows().at(0); |
|
173 mainWindow->removeView(mAdvancedView); |
|
174 |
|
175 mAdvancedView->setParent(NULL); |
|
176 |
|
177 delete mAdvancedView; |
|
178 mAdvancedView = NULL; |
|
179 |
|
180 // refresh first view |
|
181 setPosTypeState( PosTypeIndexGps); |
|
182 setPosTypeState( PosTypeIndexWireless); |
|
183 setPosTypeState( PosTypeIndexBackground); |
|
184 validatePosTypeVisibility(PosTypeIndexBackground); |
|
185 qDebug() << "- PosSettingsForm::closeAdvancedView()"; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // PosSettingsForm::onPressedGps |
|
190 // --------------------------------------------------------------------------- |
|
191 void PosSettingsForm::onPressedGps() |
|
192 { |
|
193 qDebug() << "+ PosSettingsForm::onPressedGps()"; |
|
194 validatePosTypeVisibility(PosTypeIndexBackground); |
|
195 |
|
196 int state = mGpsPosType->contentWidgetData("checkState").toInt(); |
|
197 if(state == Qt::Checked) |
|
198 { //if Gps enable |
|
199 mSettingsEngine.setPositionTechnologyState(StateEnable, PositionTechnologyGps); |
|
200 } |
|
201 else |
|
202 { //if Gps disable |
|
203 mSettingsEngine.setPositionTechnologyState(StateDisable, PositionTechnologyGps); |
|
204 } |
|
205 qDebug() << "- PosSettingsForm::onPressedGps()"; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // PosSettingsForm::onPressedWireless |
|
210 // --------------------------------------------------------------------------- |
|
211 void PosSettingsForm::onPressedWireless() |
|
212 { |
|
213 qDebug() << "+ PosSettingsForm::onPressedWireless()"; |
|
214 validatePosTypeVisibility(PosTypeIndexBackground); |
|
215 int state = mWirelessPosType->contentWidgetData("checkState").toInt(); |
|
216 if(state == Qt::Checked) |
|
217 { |
|
218 //if Wireless enable |
|
219 mSettingsEngine.setPositionTechnologyState(StateEnable, PositionTechnologyNetwork); |
|
220 } |
|
221 else |
|
222 { //if Wireless disable |
|
223 mSettingsEngine.setPositionTechnologyState(StateDisable, PositionTechnologyNetwork); |
|
224 } |
|
225 qDebug() << "- PosSettingsForm::onPressedWireless()"; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // PosSettingsForm::onPressedBackground |
|
230 // --------------------------------------------------------------------------- |
|
231 void PosSettingsForm::onPressedBackground() |
|
232 { |
|
233 qDebug() << "+ PosSettingsForm::onPressedBackground()"; |
|
234 int state = mBgPosType->contentWidgetData("checkState").toInt(); |
|
235 if(state == Qt::Checked) |
|
236 { |
|
237 //if Bg enable |
|
238 mSettingsEngine.setBackGroundPositioningState(StateEnable); |
|
239 mSettingsEngine.setCRBackgroundPositioningStatus(StateEnable); |
|
240 } |
|
241 else |
|
242 { //if Bg disable; |
|
243 mSettingsEngine.setBackGroundPositioningState(StateDisable); |
|
244 mSettingsEngine.setCRBackgroundPositioningStatus(StateDisable); |
|
245 } |
|
246 qDebug() << "- PosSettingsForm::onPressedBackground()"; |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // PosSettingsForm::validatePosTypeVisibility |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void PosSettingsForm::validatePosTypeVisibility(PosTypeIndex posTypeModelItemIndex) |
|
254 { |
|
255 qDebug() << "+ PosSettingsForm::validatePosTypeVisibility()"; |
|
256 bool valid = false; |
|
257 HbDataFormModelItem* posTypeModelItem = NULL; //does not own |
|
258 int posIndex = posTypeModelItemIndex; |
|
259 switch(posTypeModelItemIndex) { |
|
260 case PosTypeIndexGps: { |
|
261 valid = mSettingsEngine.isPositionTechnologyAvailable(PositionTechnologyGps); |
|
262 posTypeModelItem = mGpsPosType; |
|
263 break; |
|
264 } |
|
265 case PosTypeIndexWireless: { |
|
266 valid = mSettingsEngine.isPositionTechnologyAvailable(PositionTechnologyNetwork); |
|
267 posTypeModelItem = mWirelessPosType; |
|
268 HbDataFormModel* model = static_cast<HbDataFormModel*>(this->model()); |
|
269 //if GPS is not there, it will be at position 1 |
|
270 if(!model->indexFromItem(mGpsPosType).isValid()) { |
|
271 --posIndex ; |
|
272 } |
|
273 break; |
|
274 } |
|
275 case PosTypeIndexBackground: { |
|
276 //if Gps and Wireless are not marked, then make Background invisible |
|
277 valid = (mGpsPosType->contentWidgetData("checkState").toInt() == Qt::Checked || |
|
278 mWirelessPosType->contentWidgetData("checkState").toInt() == Qt::Checked); |
|
279 posTypeModelItem = mBgPosType; |
|
280 HbDataFormModel* model = static_cast<HbDataFormModel*>(this->model()); |
|
281 |
|
282 //if GPS is not there, decremenet position |
|
283 if(!model->indexFromItem(mGpsPosType).isValid()) { |
|
284 --posIndex; |
|
285 } |
|
286 //if Wireless is not there, decremenet position |
|
287 if(!model->indexFromItem(mWirelessPosType).isValid()) { |
|
288 --posIndex; |
|
289 } |
|
290 //if no gps no wireless, quit control-panel application |
|
291 if(posIndex == PosTypeIndexGps-1) { |
|
292 qApp->quit(); |
|
293 } |
|
294 break; |
|
295 } |
|
296 default:{ |
|
297 break; |
|
298 } |
|
299 |
|
300 } |
|
301 qDebug() << "valid =" << valid; |
|
302 insertOrRemovePosTypeModelItem(valid, posTypeModelItem, posTypeModelItemIndex, posIndex); |
|
303 qDebug() << "- PosSettingsForm::validatePosTypeVisibility()"; |
|
304 } |
|
305 |
|
306 // --------------------------------------------------------------------------- |
|
307 // PosSettingsForm::InsertOrRemovePosTypeModelItem |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 void PosSettingsForm::insertOrRemovePosTypeModelItem(bool insert, HbDataFormModelItem* posTypeModelItem, |
|
311 PosTypeIndex posTypeModelItemIndex, int posIndex) |
|
312 { |
|
313 qDebug() << "+ PosSettingsForm::insertOrRemovePosTypeModelItem()"; |
|
314 HbDataFormModel* model = static_cast<HbDataFormModel*>(this->model()); |
|
315 if(!insert) { |
|
316 if(model->indexFromItem(posTypeModelItem).isValid()) { |
|
317 if(model->removeItem(posTypeModelItem)) { |
|
318 //Note: In removeItem, modelitem is removed and then deleted too. |
|
319 // So next time when we want to check if it is present, we have to create dummy modelitem |
|
320 // else with existing handle, we will get kern exec 3 error |
|
321 createPosTypeModelItem(posTypeModelItemIndex); |
|
322 if(posTypeModelItem == mBgPosType) { |
|
323 mSettingsEngine.setBackGroundPositioningState(StateDisable); |
|
324 } |
|
325 } |
|
326 } |
|
327 } |
|
328 else { |
|
329 if(!model->indexFromItem(posTypeModelItem).isValid()) { |
|
330 model->insertDataFormItem(posIndex,posTypeModelItem); |
|
331 addPosTypeConnection(posTypeModelItem); |
|
332 |
|
333 if(posTypeModelItem == mBgPosType) { |
|
334 //Restore to old state in case of background positioning. |
|
335 if(mSettingsEngine.cRBackgroundPositioningStatus()) { |
|
336 mSettingsEngine.setBackGroundPositioningState(StateEnable); |
|
337 } |
|
338 else { |
|
339 mSettingsEngine.setBackGroundPositioningState(StateDisable); |
|
340 } |
|
341 setPosTypeState(PosTypeIndexBackground); |
|
342 } |
|
343 else //Restore old state of GPS/Wireless |
|
344 setPosTypeState(posTypeModelItemIndex); |
|
345 } |
|
346 } |
|
347 qDebug() << "- PosSettingsForm::insertOrRemovePosTypeModelItem()"; |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // PosSettingsForm::createPosTypeModelItem |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void PosSettingsForm::createPosTypeModelItem(PosTypeIndex posTypeModelItemIndex) |
|
355 { |
|
356 qDebug() << "+ PosSettingsForm::createPosTypeModelItem()"; |
|
357 HbDataFormModel* model = static_cast<HbDataFormModel*>(this->model()); |
|
358 switch(posTypeModelItemIndex) { |
|
359 case PosTypeIndexGps: { |
|
360 mGpsPosType = new HbDataFormModelItem(HbDataFormModelItem::CheckBoxItem, |
|
361 QString(), |
|
362 model->invisibleRootItem()); |
|
363 mGpsPosType->setData(HbDataFormModelItem::DescriptionRole, hbTrId("txt_loe_info_enable_for_most_accurate_positioning")); |
|
364 mGpsPosType->setContentWidgetData("text", hbTrId("txt_loe_list_gps")); |
|
365 break; |
|
366 } |
|
367 case PosTypeIndexWireless: { |
|
368 mWirelessPosType = new HbDataFormModelItem(HbDataFormModelItem::CheckBoxItem, |
|
369 QString(), |
|
370 model->invisibleRootItem()); |
|
371 mWirelessPosType->setData(HbDataFormModelItem::DescriptionRole, hbTrId("txt_loe_info_use_wifi_and_mobile_networks_to_get")); |
|
372 mWirelessPosType->setContentWidgetData("text", hbTrId("txt_loe_list_wireless_networks")); |
|
373 break; |
|
374 } |
|
375 case PosTypeIndexBackground:{ |
|
376 mBgPosType = new HbDataFormModelItem(HbDataFormModelItem::CheckBoxItem, |
|
377 QString(), |
|
378 model->invisibleRootItem()); |
|
379 mBgPosType->setData(HbDataFormModelItem::DescriptionRole, hbTrId("txt_loe_info_enable_applications_and_services_upda")); |
|
380 mBgPosType->setContentWidgetData("text", hbTrId("txt_loe_list_background_positioning")); |
|
381 break; |
|
382 } |
|
383 default: { |
|
384 break; |
|
385 } |
|
386 } |
|
387 qDebug() << "- PosSettingsForm::createPosTypeModelItem()"; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // PosSettingsForm::validateVisibility |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void PosSettingsForm::validateVisibility() |
|
395 { |
|
396 qDebug() << "+ PosSettingsForm::validateVisibility()"; |
|
397 validatePosTypeVisibility(PosTypeIndexGps); |
|
398 validatePosTypeVisibility(PosTypeIndexWireless); |
|
399 validatePosTypeVisibility(PosTypeIndexBackground); |
|
400 qDebug() << "- PosSettingsForm::validateVisibility()"; |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // PosSettingsForm::setPosTypeState |
|
405 // --------------------------------------------------------------------------- |
|
406 void PosSettingsForm::setPosTypeState(PosTypeIndex posTypeModelItemIndex) |
|
407 { |
|
408 qDebug() << "+ PosSettingsForm::setPosTypeState()"; |
|
409 int state = Qt::Unchecked; |
|
410 switch(posTypeModelItemIndex){ |
|
411 case PosTypeIndexGps: { |
|
412 if(mSettingsEngine.isPositionTechnologyEnabled(PositionTechnologyGps)) |
|
413 state = Qt::Checked; |
|
414 mGpsPosType->setContentWidgetData("checkState", state); |
|
415 break; |
|
416 } |
|
417 case PosTypeIndexWireless: { |
|
418 if(mSettingsEngine.isPositionTechnologyEnabled(PositionTechnologyNetwork)) |
|
419 state = Qt::Checked; |
|
420 mWirelessPosType->setContentWidgetData("checkState",state); |
|
421 break; |
|
422 } |
|
423 case PosTypeIndexBackground: { |
|
424 if(mSettingsEngine.isBackGroundPositioningEnabled()) |
|
425 state = Qt::Checked; |
|
426 mBgPosType->setContentWidgetData("checkState",state); |
|
427 break; |
|
428 } |
|
429 default : { |
|
430 break; |
|
431 } |
|
432 } |
|
433 qDebug() << "- PosSettingsForm::setPosTypeState()"; |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // PosSettingsForm::addPosTypeConnection |
|
438 // --------------------------------------------------------------------------- |
|
439 void PosSettingsForm::addPosTypeConnection(HbDataFormModelItem* posTypeModelItem) |
|
440 { |
|
441 qDebug() << "+ PosSettingsForm::addPosTypeConnection()"; |
|
442 if(posTypeModelItem == mGpsPosType) |
|
443 { |
|
444 addConnection( mGpsPosType, SIGNAL(released()), |
|
445 this, SLOT(onPressedGps()) ); |
|
446 qDebug() << "- PosSettingsForm::addPosTypeConnection()"; |
|
447 return; |
|
448 } |
|
449 |
|
450 if(posTypeModelItem == mWirelessPosType) |
|
451 { |
|
452 addConnection( mWirelessPosType, SIGNAL(released()), |
|
453 this, SLOT(onPressedWireless()) ); |
|
454 qDebug() << "- PosSettingsForm::addPosTypeConnection()"; |
|
455 return; |
|
456 } |
|
457 if(posTypeModelItem == mBgPosType) |
|
458 { |
|
459 addConnection( mBgPosType, SIGNAL(released()), |
|
460 this, SLOT(onPressedBackground()) ); |
|
461 qDebug() << "- PosSettingsForm::addPosTypeConnection()"; |
|
462 return; |
|
463 } |
|
464 } |
|
465 //EOF |