|
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 is for Positioning Supl Settings plugin |
|
15 * for Positioning Settings's Advanced view |
|
16 * |
|
17 */ |
|
18 #include "possuplsettings.h" |
|
19 #include "possuplsettingsengine.h" |
|
20 #include "possettingsadvop.h" |
|
21 |
|
22 #include <QtCore> |
|
23 #include <QDebug> |
|
24 #include <hbcheckbox.h> |
|
25 #include <hbmenu.h> |
|
26 #include <hbaction.h> |
|
27 #include <hbradiobuttonlist.h> |
|
28 #include <hblabel.h> |
|
29 #include <hbdialog.h> |
|
30 |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // PosSuplSettingsPlugin::PosSuplSettingsPlugin |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 PosSuplSettingsPlugin::PosSuplSettingsPlugin() : |
|
37 mSuplSettingsEngine(0), mGroup(0), mOperation(0), mSignalMapper(0), |
|
38 mMainMenu(0), mPrimaryAction(0), mRadioButtonList(0), |
|
39 mDeleteQuery(0) |
|
40 { |
|
41 qDebug() << "+ PosSuplSettingsPlugin::PosSuplSettingsPlugin()"; |
|
42 mSuplSettingsEngine = new PosSuplSettingsEngine(); |
|
43 qDebug() << "- PosSuplSettingsPlugin::PosSuplSettingsPlugin()"; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // PosSuplSettingsPlugin::~PosSuplSettingsPlugin |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 PosSuplSettingsPlugin::~PosSuplSettingsPlugin() |
|
51 { |
|
52 qDebug() << "+ PosSuplSettingsPlugin::~PosSuplSettingsPlugin()"; |
|
53 |
|
54 if (mSuplSettingsEngine) |
|
55 { |
|
56 delete mSuplSettingsEngine; |
|
57 mSuplSettingsEngine = 0; |
|
58 } |
|
59 |
|
60 if (mGroup && mOperation) |
|
61 { |
|
62 mOperation->removeItem(mGroup); |
|
63 mGroup = 0; |
|
64 } |
|
65 |
|
66 if (mMainMenu) |
|
67 { |
|
68 delete mMainMenu; |
|
69 mMainMenu = 0; |
|
70 } |
|
71 ///// |
|
72 QObject::disconnect(mSignalMapper, SIGNAL(mapped(int)), this, |
|
73 SLOT(changeServerUsage(int))); |
|
74 |
|
75 if (mSignalMapper) |
|
76 { |
|
77 delete mSignalMapper; |
|
78 mSignalMapper = NULL; |
|
79 } |
|
80 |
|
81 if (mPrimaryAction) |
|
82 { |
|
83 delete mPrimaryAction; |
|
84 mPrimaryAction = 0; |
|
85 } |
|
86 |
|
87 if (mRadioButtonList) |
|
88 { |
|
89 mRadioButtonList->reset(); |
|
90 delete mRadioButtonList; |
|
91 } |
|
92 |
|
93 if (mDeleteQuery) |
|
94 { |
|
95 delete mDeleteQuery; |
|
96 } |
|
97 /// |
|
98 |
|
99 // delete the signal mapper instances |
|
100 int cnt = mSignalMapperList.count(); |
|
101 for (int i = 0; i < cnt ; ++i) |
|
102 { |
|
103 QObject::disconnect(mSignalMapperList[i], SIGNAL(signalmapped()), |
|
104 mSignalMapper, SLOT(map())); |
|
105 delete mSignalMapperList[i]; |
|
106 mSignalMapperList[i] = NULL; |
|
107 } |
|
108 |
|
109 /// |
|
110 |
|
111 mServerList.clear(); |
|
112 mSignalMapperList.clear(); |
|
113 mDeleteableServerList.clear(); |
|
114 qDebug() << "- PosSuplSettingsPlugin::~PosSuplSettingsPlugin()"; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // PosSuplSettingsPlugin::initialise |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 int PosSuplSettingsPlugin::initialise(PosSettingsAdvOp* operation) |
|
122 { |
|
123 qDebug() << "+ PosSuplSettingsPlugin::initialise()"; |
|
124 |
|
125 int result = 0; |
|
126 // Assign to the member variable |
|
127 mOperation = operation; |
|
128 |
|
129 // create the signal mapper |
|
130 mSignalMapper = new QSignalMapper(); |
|
131 |
|
132 //get the list of server present for positioning |
|
133 if (mSuplSettingsEngine) |
|
134 { |
|
135 result = mSuplSettingsEngine->suplServerList(mServerList); |
|
136 } |
|
137 |
|
138 // if no error while getting the server list then add the group |
|
139 // for Positioning servers |
|
140 if (result == 0) |
|
141 { |
|
142 mGroup = new HbDataFormModelItem(HbDataFormModelItem::GroupItem, |
|
143 hbTrId("txt_loe_subtitle_positioning_servers"), 0); |
|
144 //Add the group to the data form |
|
145 operation->appendDataFormItem(mGroup); |
|
146 //list all the server inside the group |
|
147 listServers(); |
|
148 } |
|
149 QObject::connect(mSuplSettingsEngine, SIGNAL(serverListUpdated()), this, |
|
150 SLOT(updateList())); |
|
151 |
|
152 qDebug() << "- PosSuplSettingsPlugin::initialise()" << "result = " |
|
153 << result; |
|
154 |
|
155 return result; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // PosSuplSettingsPlugin::ChangeServerUsage |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void PosSuplSettingsPlugin::changeServerUsage(int value) |
|
163 { |
|
164 qDebug() << "+ PosSuplSettingsPlugin::changeServerUsage()"; |
|
165 //toggle the value based on the slpid |
|
166 if (!mServerList[value].serverEnabled) |
|
167 { |
|
168 mSuplSettingsEngine->enableServer(mServerList[value].slpId, true); |
|
169 } |
|
170 else |
|
171 { |
|
172 mSuplSettingsEngine->enableServer(mServerList[value].slpId, false); |
|
173 } |
|
174 qDebug() << "- PosSuplSettingsPlugin::changeServerUsage()"; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // PosSuplSettingsPlugin::listServers |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void PosSuplSettingsPlugin::listServers() |
|
182 { |
|
183 qDebug() << "+ PosSuplSettingsPlugin::listServers()"; |
|
184 |
|
185 qDebug() << "mServerList.count = " << mServerList.count(); |
|
186 |
|
187 //create a serverlist iterator |
|
188 QList<PosServerParams>::const_iterator serveriterator; |
|
189 |
|
190 // Get the server names and display |
|
191 for (serveriterator = mServerList.begin(); serveriterator |
|
192 != mServerList.end(); ++serveriterator) |
|
193 { |
|
194 qDebug() << "server name = " << serveriterator->serverAdd; |
|
195 if (serveriterator->serverAdd.length() > 0) |
|
196 { |
|
197 //for each server create new checkbox item |
|
198 HbDataFormModelItem* checkBox = new HbDataFormModelItem( |
|
199 HbDataFormModelItem::CheckBoxItem, QString(), 0); |
|
200 |
|
201 //set the widget data to the server name |
|
202 checkBox->setContentWidgetData("text", QString(hbTrId( |
|
203 "txt_loe_list_use_1")).arg(serveriterator->serverAdd)); |
|
204 |
|
205 //if the server is enabled set the initial state of the checkbox |
|
206 if (serveriterator->serverEnabled) |
|
207 { |
|
208 checkBox->setContentWidgetData("checkState", Qt::Checked); |
|
209 } |
|
210 else |
|
211 { |
|
212 checkBox->setContentWidgetData("checkState", Qt::Unchecked); |
|
213 } |
|
214 |
|
215 qDebug() << "Adding checkbox in the group"; |
|
216 |
|
217 //this part of code is called when the servers are added and |
|
218 //Advanced view is in the background. Since there is no group |
|
219 // a new group has to be created to add the servers |
|
220 mOperation->appendDataFormItem(checkBox, mGroup); |
|
221 |
|
222 //create an object of dummy signal mapper class |
|
223 //this is done to send the index info to the slots |
|
224 //since checkbox is not of QObject type and dummy class is |
|
225 // created. |
|
226 PosSettingsSignalMapper* signalMapper = |
|
227 new PosSettingsSignalMapper(); |
|
228 mSignalMapperList.append(signalMapper); |
|
229 |
|
230 //add connection for statechanged of the checkbox, depending on which the |
|
231 // add connections on change of check box state |
|
232 mOperation->addConnection(checkBox, SIGNAL(stateChanged(int)), |
|
233 mSignalMapperList[serveriterator - mServerList.begin()], |
|
234 SLOT(signalmap())); |
|
235 |
|
236 QObject::connect(mSignalMapperList[serveriterator |
|
237 - mServerList.begin()], SIGNAL(signalmapped()), |
|
238 mSignalMapper, SLOT(map())); |
|
239 |
|
240 // set mapping of each check box item to its index |
|
241 if (mSignalMapper) |
|
242 { |
|
243 mSignalMapper->setMapping(mSignalMapperList[serveriterator |
|
244 - mServerList.begin()], (serveriterator |
|
245 - mServerList.begin())); |
|
246 } |
|
247 } |
|
248 } |
|
249 |
|
250 //use signal mapper to connect |
|
251 QObject::connect(mSignalMapper, SIGNAL(mapped(int)), this, |
|
252 SLOT(changeServerUsage(int))); |
|
253 |
|
254 qDebug() << "mDeleteableServerList.count before reset = " |
|
255 << mDeleteableServerList.count(); |
|
256 |
|
257 //refresh the list of deleteable servers in case any deleteable server is added |
|
258 mDeleteableServerList.clear(); |
|
259 |
|
260 if (mSuplSettingsEngine) |
|
261 { |
|
262 mSuplSettingsEngine->deletableServerList(mDeleteableServerList); |
|
263 } |
|
264 |
|
265 qDebug() << "mDeleteableServerList.count after fetch = " |
|
266 << mDeleteableServerList.count(); |
|
267 |
|
268 //if the server list is <=1 while updating the list the menu is destroyed |
|
269 if (mDeleteableServerList.count() == 0) |
|
270 { |
|
271 if (mMainMenu) |
|
272 { |
|
273 delete mMainMenu; |
|
274 mMainMenu = 0; |
|
275 } |
|
276 } |
|
277 else |
|
278 { |
|
279 delete mMainMenu; |
|
280 mMainMenu = 0; |
|
281 createMenu(); |
|
282 } |
|
283 qDebug() << "- PosSuplSettingsPlugin::listServers()"; |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // PosSuplSettingsPlugin::updateList |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 void PosSuplSettingsPlugin::updateList() |
|
291 { |
|
292 qDebug() << "+ PosSuplSettingsPlugin::updateList()"; |
|
293 int result = 0; |
|
294 int oldChildCount = 0; |
|
295 |
|
296 if (mGroup) |
|
297 { |
|
298 qDebug() << "Store the group info"; |
|
299 |
|
300 oldChildCount = mGroup->childCount(); |
|
301 |
|
302 // remove all connections |
|
303 int count = mSignalMapperList.count(); |
|
304 qDebug() << "mSignalMapperList.count() = " << count; |
|
305 |
|
306 for (int i = 0; i < count; ++i) |
|
307 { |
|
308 QObject::disconnect(mSignalMapperList[i], SIGNAL(signalmapped()), |
|
309 mSignalMapper, SLOT(map())); |
|
310 } |
|
311 QObject::disconnect(mSignalMapper, SIGNAL(mapped(int)), this, |
|
312 SLOT(changeServerUsage(int))); |
|
313 |
|
314 qDebug() << "oldChildCount = " << oldChildCount; |
|
315 |
|
316 //remove the children in the group |
|
317 if (oldChildCount > 0) |
|
318 { |
|
319 qDebug() << "removing the children"; |
|
320 //mGroup->removeChildren(0, oldChildCount); |
|
321 //ToDo: Hack from HbDataForm team |
|
322 for (int i = 0; i < oldChildCount; ++i) |
|
323 { |
|
324 mGroup->removeChild(0); |
|
325 } |
|
326 } |
|
327 } |
|
328 else |
|
329 { |
|
330 qDebug() << "Creating new group "; |
|
331 |
|
332 mGroup = new HbDataFormModelItem(HbDataFormModelItem::GroupItem, |
|
333 hbTrId("txt_loe_subtitle_positioning_servers"), 0); |
|
334 mOperation->appendDataFormItem(mGroup); |
|
335 } |
|
336 |
|
337 qDebug() << "mServerList.count() before clean = " << mServerList.count(); |
|
338 |
|
339 //clear the list and get the list of server present for positioning |
|
340 mServerList.clear(); |
|
341 if (mSuplSettingsEngine) |
|
342 { |
|
343 result = mSuplSettingsEngine->suplServerList(mServerList); |
|
344 } |
|
345 qDebug() << "result = " << result; |
|
346 |
|
347 //update the new list to the group |
|
348 if (result == 0) |
|
349 { |
|
350 listServers(); |
|
351 } |
|
352 if (result == -1) |
|
353 { |
|
354 qDebug() << "Removing the group from form"; |
|
355 //remove the group |
|
356 mOperation->removeItem(mGroup); |
|
357 mGroup = 0; |
|
358 // delete the menu |
|
359 if (mMainMenu) |
|
360 { |
|
361 delete mMainMenu; |
|
362 mMainMenu = 0; |
|
363 } |
|
364 } |
|
365 qDebug() << "- PosSuplSettingsPlugin::updateList()"; |
|
366 } |
|
367 |
|
368 // --------------------------------------------------------------------------- |
|
369 // PosSuplSettingsPlugin::onDeleteServer |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 void PosSuplSettingsPlugin::onDeleteServer() |
|
373 { |
|
374 qDebug() << "+ PosSuplSettingsPlugin::onDeleteServer()"; |
|
375 //list that will contain the deleteable servers names |
|
376 QStringList contentList; |
|
377 |
|
378 //get the deleteable server list from the engine |
|
379 QList<PosServerParams>::const_iterator iterator; |
|
380 |
|
381 qDebug() << "mDeleteableServerList.count = " |
|
382 << mDeleteableServerList.count(); |
|
383 |
|
384 //add the server names to the string list |
|
385 for (iterator = mDeleteableServerList.constBegin(); iterator |
|
386 != mDeleteableServerList.constEnd(); ++iterator) |
|
387 { |
|
388 //Copy the address to Qstring object |
|
389 qDebug() << "deletable server = " << iterator->serverAdd; |
|
390 contentList << iterator->serverAdd; |
|
391 } |
|
392 |
|
393 // delete the mRadioButtonList before creating it,each time the delete |
|
394 // query needs to be popped up |
|
395 if (mRadioButtonList != 0) |
|
396 { |
|
397 delete mRadioButtonList; |
|
398 mRadioButtonList = 0; |
|
399 } |
|
400 //create a radion button list of the deletable servers |
|
401 mRadioButtonList = new HbRadioButtonList(); |
|
402 mRadioButtonList->setItems(contentList); |
|
403 QObject::connect(mRadioButtonList, SIGNAL(itemSelected(int)), this, |
|
404 SLOT(setPrimaryAction(int))); |
|
405 |
|
406 // delete the mDeleteQuery before creating it,each time the delete |
|
407 // query needs to be popped up |
|
408 |
|
409 if (mDeleteQuery != 0) |
|
410 { |
|
411 delete mDeleteQuery; |
|
412 mDeleteQuery = 0; |
|
413 } |
|
414 //create the query dialog and attach the radio button to the dialog |
|
415 mDeleteQuery = new HbDialog(); |
|
416 |
|
417 mDeleteQuery->setTimeout(HbDialog::NoTimeout); |
|
418 |
|
419 //set the proper layout for the mDeleteQuery dialog |
|
420 qreal lMargin = 0; |
|
421 qreal rMargin = 0; |
|
422 qreal tMargin = 0; |
|
423 |
|
424 if (mDeleteQuery->style()->parameter("hb-param-margin-gene-left", |
|
425 lMargin) && mDeleteQuery->style()->parameter( |
|
426 "hb-param-margin-gene-right", rMargin) |
|
427 && mDeleteQuery->style()->parameter( |
|
428 "hb-param-margin-gene-top", tMargin)) |
|
429 { |
|
430 HbLabel * heading = new HbLabel(QString(hbTrId( |
|
431 "txt_loe_info_select_server_to_delete"))); |
|
432 heading->setContentsMargins(lMargin, tMargin, rMargin, 0); |
|
433 mDeleteQuery->setHeadingWidget(heading); |
|
434 } |
|
435 |
|
436 // delete the mPrimaryAction before creating it,each time the delete |
|
437 // query needs to be popped up |
|
438 if (mPrimaryAction != 0) |
|
439 { |
|
440 delete mPrimaryAction; |
|
441 mPrimaryAction = 0; |
|
442 } |
|
443 //the primary action that will come in the SK1 of the Dialog box |
|
444 mPrimaryAction |
|
445 = new HbAction(QString(hbTrId("txt_common_button_delete"))); |
|
446 |
|
447 mDeleteQuery->addAction(mPrimaryAction); |
|
448 mDeleteQuery->addAction(new HbAction(QString(hbTrId( |
|
449 "txt_common_button_cancel")))); |
|
450 QObject::connect(mPrimaryAction, SIGNAL(triggered()), this, |
|
451 SLOT(deleteServer())); |
|
452 |
|
453 //set the content Widget |
|
454 mDeleteQuery->setContentWidget(mRadioButtonList); |
|
455 |
|
456 //the Primary action is disabled since no server from the list is selected |
|
457 mPrimaryAction->setDisabled(true); |
|
458 |
|
459 mDeleteQuery->show(); |
|
460 |
|
461 qDebug() << "- PosSuplSettingsPlugin::onDeleteServer()"; |
|
462 } |
|
463 |
|
464 // --------------------------------------------------------------------------- |
|
465 // PosSuplSettingsPlugin::createMenu |
|
466 // --------------------------------------------------------------------------- |
|
467 // |
|
468 void PosSuplSettingsPlugin::createMenu() |
|
469 { |
|
470 qDebug() << "+ PosSuplSettingsPlugin::createMenu()"; |
|
471 mMainMenu = new HbMenu(); |
|
472 HbAction* action = mMainMenu->addAction(hbTrId( |
|
473 "txt_loe_opt_delete_server")); |
|
474 |
|
475 QObject::connect(action, SIGNAL(triggered()), this, |
|
476 SLOT(onDeleteServer())); |
|
477 |
|
478 mOperation->addAction(action, HbView::OptionsMenu); |
|
479 qDebug() << "- PosSuplSettingsPlugin::createMenu()"; |
|
480 } |
|
481 |
|
482 // --------------------------------------------------------------------------- |
|
483 // PosSuplSettingsPlugin::setPrimaryAction |
|
484 // --------------------------------------------------------------------------- |
|
485 // |
|
486 void PosSuplSettingsPlugin::setPrimaryAction(int /*itemSelected*/) |
|
487 { |
|
488 //enable the primary Action |
|
489 if (mPrimaryAction) |
|
490 { |
|
491 mPrimaryAction->setEnabled(true); |
|
492 } |
|
493 } |
|
494 |
|
495 // --------------------------------------------------------------------------- |
|
496 // PosSuplSettingsPlugin::deleteServer |
|
497 // --------------------------------------------------------------------------- |
|
498 // |
|
499 void PosSuplSettingsPlugin::deleteServer() |
|
500 { |
|
501 //get the index of the selected servers |
|
502 int serverIndex = mRadioButtonList->selected(); |
|
503 |
|
504 if( serverIndex != -1 ) |
|
505 { |
|
506 if (mSuplSettingsEngine) |
|
507 { |
|
508 //delete the server |
|
509 mSuplSettingsEngine->deleteServer( |
|
510 mDeleteableServerList[serverIndex].slpId); |
|
511 } |
|
512 } |
|
513 } |
|
514 Q_EXPORT_PLUGIN2(possuplsettings, PosSuplSettingsPlugin) |
|
515 ; |
|
516 |