|
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: |
|
15 * Data item for representing access points in UI. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QObject> |
|
20 #include <HbMenu> |
|
21 #include <HbAction> |
|
22 #include <HbDocumentLoader> |
|
23 #include <HbRadioButtonList> |
|
24 #include <HbDialog> |
|
25 #include <HbMessageBox> |
|
26 #include <HbPopup> |
|
27 #include <HbLabel> |
|
28 #include <HbDataFormViewItem> |
|
29 #include <HbDataForm> |
|
30 #include <HbDataFormModel> |
|
31 #include <HbParameterLengthLimiter> |
|
32 #include <cpbasesettingview.h> |
|
33 #include <cpsettingformitemdata.h> |
|
34 #include <cpsettingformentryitemdata.h> |
|
35 #include <cpitemdatahelper.h> |
|
36 #include <cmdestination_shim.h> |
|
37 #include <cmmanager_shim.h> |
|
38 #include <cmconnectionmethod_shim.h> |
|
39 |
|
40 // User includes |
|
41 #include "cpiapitem.h" |
|
42 #include "cpdestinationentryitem.h" |
|
43 #include "cpbearerapplugininterface.h" |
|
44 #include "OstTraceDefinitions.h" |
|
45 #ifdef OST_TRACE_COMPILER_IN_USE |
|
46 #include "cpiapitemTraces.h" |
|
47 #endif |
|
48 /*! |
|
49 \class CpIapItem |
|
50 \brief This class represents access point in data model. |
|
51 It takes care of all access point related operations. |
|
52 */ |
|
53 |
|
54 // External function prototypes |
|
55 |
|
56 // Local constants |
|
57 |
|
58 // ======== LOCAL FUNCTIONS ======== |
|
59 |
|
60 // ======== MEMBER FUNCTIONS ======== |
|
61 |
|
62 /*! |
|
63 Constructor. |
|
64 |
|
65 @param[in] itemDataHelper Helper for connecting signals and slots. |
|
66 @param[in] iapId Unique ID if the access point this object represents. |
|
67 @param[in] iapName Name of the access point this object represents. |
|
68 @param[in] destId Unique ID of the destination that contains reference to |
|
69 the access point this object represents. |
|
70 @param[in] bearerPlugin Pointer to the object that implements settings view |
|
71 for this access point. |
|
72 */ |
|
73 CpIapItem::CpIapItem( |
|
74 CpItemDataHelper &itemDataHelper, |
|
75 int iapId, |
|
76 const QString &iapName, |
|
77 int destId, |
|
78 bool apProtected, |
|
79 CpBearerApPluginInterface *bearerPlugin) : |
|
80 CpSettingFormEntryItemData(CpSettingFormEntryItemData::ButtonEntryItem, itemDataHelper), |
|
81 mIapId(iapId), |
|
82 mIapName(iapName), |
|
83 mDestId(destId), |
|
84 mItemDataHelper(&itemDataHelper), |
|
85 mBearerPlugin(bearerPlugin), |
|
86 mMoveOngoing(false), |
|
87 mDialog(0), |
|
88 mList(0) |
|
89 { |
|
90 OstTraceFunctionEntry0(CPIAPITEM_CPIAPITEM_ENTRY); |
|
91 try { |
|
92 mCmm = new CmManagerShim(); |
|
93 } catch (const std::exception&) { |
|
94 OstTrace0(TRACE_NORMAL, CPIAPITEM_CPIAPITEM, "CpIapItem::CpIapItem: Exception caught"); |
|
95 mCmm = NULL; |
|
96 } |
|
97 |
|
98 // Fix connections |
|
99 itemDataHelper.removeConnection(this,SIGNAL(pressed()),this,SLOT(onLaunchView())); |
|
100 if (!apProtected) { |
|
101 itemDataHelper.addConnection( |
|
102 this, |
|
103 SIGNAL(longPress(QPointF)), |
|
104 this, |
|
105 SLOT(showItemMenu(QPointF))); |
|
106 itemDataHelper.addConnection(this,SIGNAL(clicked()),this,SLOT(onLaunchView())); |
|
107 itemDataHelper.addConnection( |
|
108 this, |
|
109 SIGNAL(visibleChanged()), |
|
110 this, |
|
111 SLOT(updateIap())); |
|
112 } |
|
113 OstTraceFunctionExit0(CPIAPITEM_CPIAPITEM_EXIT); |
|
114 } |
|
115 |
|
116 /*! |
|
117 Destructor |
|
118 */ |
|
119 CpIapItem::~CpIapItem() |
|
120 { |
|
121 OstTraceFunctionEntry0(DUP1_CPIAPITEM_CPIAPITEM_ENTRY); |
|
122 delete mCmm; |
|
123 OstTraceFunctionExit0(DUP1_CPIAPITEM_CPIAPITEM_EXIT); |
|
124 } |
|
125 |
|
126 /*! |
|
127 Shows user the item specific menu. The menu is triggered by long pressing |
|
128 the access point item. |
|
129 |
|
130 @param[in] position Preferred position for the item specific menu. |
|
131 */ |
|
132 void CpIapItem::showItemMenu(QPointF position) |
|
133 { |
|
134 OstTraceFunctionEntry0(CPIAPITEM_SHOWITEMMENU_ENTRY); |
|
135 if (isCmManagerAvailable()) { |
|
136 bool settingsReadSuccessful = true; |
|
137 bool cmConnected = false; |
|
138 try { |
|
139 CmConnectionMethodShim *cm = mCmm->connectionMethod(mIapId); |
|
140 cmConnected = cm->getBoolAttribute(CMManagerShim::CmConnected); |
|
141 delete cm; |
|
142 } |
|
143 catch (const std::exception&) { |
|
144 OstTrace0(TRACE_NORMAL, CPIAPITEM_SHOWITEMMENU, "CpIapItem::showItemMenu: Exception caught"); |
|
145 settingsReadSuccessful = false; |
|
146 } |
|
147 if (settingsReadSuccessful) { |
|
148 // Settings could be read from commsdat: show menu. |
|
149 createItemMenu(cmConnected, position)->show(); |
|
150 } |
|
151 } |
|
152 OstTraceFunctionExit0(CPIAPITEM_SHOWITEMMENU_EXIT); |
|
153 } |
|
154 |
|
155 /*! |
|
156 Prompts user for destination where access point is to be |
|
157 added and then makes the move in commsdat. |
|
158 */ |
|
159 void CpIapItem::moveIap() |
|
160 { |
|
161 OstTraceFunctionEntry0(CPIAPITEM_MOVEIAP_ENTRY); |
|
162 mMoveOngoing = true; |
|
163 queryDestination(); |
|
164 OstTraceFunctionExit0(CPIAPITEM_MOVEIAP_EXIT); |
|
165 } |
|
166 |
|
167 /*! |
|
168 Shows confirmation query for access point deletion. |
|
169 */ |
|
170 void CpIapItem::showDeleteConfirmation() |
|
171 { |
|
172 OstTraceFunctionEntry0(CPIAPITEM_SHOWDELETECONFIRMATION_ENTRY); |
|
173 HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
|
174 note->clearActions(); |
|
175 note->setAttribute(Qt::WA_DeleteOnClose); |
|
176 note->setText(HbParameterLengthLimiter( |
|
177 "txt_occ_info_delete_access_point_1").arg(mIapName)); |
|
178 HbAction *primaryAction = new HbAction(hbTrId("txt_common_button_yes")); |
|
179 bool connected = connect( |
|
180 primaryAction, |
|
181 SIGNAL(triggered()), |
|
182 this, |
|
183 SLOT(deleteConfirmed())); |
|
184 Q_ASSERT(connected); |
|
185 note->addAction(primaryAction); |
|
186 note->addAction(new HbAction(hbTrId("txt_common_button_no"))); |
|
187 note->setTimeout(HbPopup::NoTimeout); |
|
188 note->show(); |
|
189 OstTraceFunctionExit0(CPIAPITEM_SHOWDELETECONFIRMATION_EXIT); |
|
190 } |
|
191 |
|
192 /*! |
|
193 Prompts user for target destination and then adds access point |
|
194 that this object represents to the prompted destination. |
|
195 */ |
|
196 void CpIapItem::shareIap() |
|
197 { |
|
198 OstTraceFunctionEntry0(CPIAPITEM_SHAREIAP_ENTRY); |
|
199 mMoveOngoing = false; |
|
200 queryDestination(); |
|
201 OstTraceFunctionExit0(CPIAPITEM_SHAREIAP_EXIT); |
|
202 } |
|
203 |
|
204 /*! |
|
205 Completes either saving or sharing of access point by |
|
206 making the move in commsdat. |
|
207 */ |
|
208 void CpIapItem::queryDialogClosed() |
|
209 { |
|
210 OstTraceFunctionEntry0(CPIAPITEM_QUERYDIALOGCLOSED_ENTRY); |
|
211 if (mMoveOngoing) { |
|
212 saveMove(mDestinationList[mList->selected()]); |
|
213 } else { |
|
214 saveShare(mDestinationList[mList->selected()]); |
|
215 } |
|
216 OstTraceFunctionExit0(CPIAPITEM_QUERYDIALOGCLOSED_EXIT); |
|
217 } |
|
218 |
|
219 /*! |
|
220 Completes the deletion process by deleting access point from |
|
221 commsdat. |
|
222 */ |
|
223 void CpIapItem::deleteConfirmed() |
|
224 { |
|
225 OstTraceFunctionEntry0(CPIAPITEM_DELETECONFIRMED_ENTRY); |
|
226 bool deleteSuccessful = true; |
|
227 try { |
|
228 if (mDestId != 0) { |
|
229 CmDestinationShim *destination = mCmm->destination(mDestId); |
|
230 CmConnectionMethodShim *cm = destination->connectionMethodByID(mIapId); |
|
231 destination->deleteConnectionMethod(cm); |
|
232 destination->update(); |
|
233 delete cm; |
|
234 delete destination; |
|
235 } else { |
|
236 CmConnectionMethodShim *cm = mCmm->connectionMethod(mIapId); |
|
237 cm->deleteConnectionMethod(); |
|
238 delete cm; |
|
239 } |
|
240 } catch (const std::exception&) { |
|
241 OstTrace0(TRACE_NORMAL, DUP1_CPIAPITEM_DELETECONFIRMED, "CpIapItem::deleteConfirmed: Exception caught"); |
|
242 deleteSuccessful = false; |
|
243 } |
|
244 if (deleteSuccessful) { |
|
245 this->deleteLater(); |
|
246 OstTrace0(TRACE_NORMAL, CPIAPITEM_DELETECONFIRMED, "CpIapItem::deleteConfirmed: Emit access point changed signal"); |
|
247 emit iapChanged(); |
|
248 } else { |
|
249 showErrorNote(hbTrId("txt_occ_info_unable_to_save_setting")); |
|
250 } |
|
251 OstTraceFunctionExit0(CPIAPITEM_DELETECONFIRMED_EXIT); |
|
252 } |
|
253 |
|
254 /*! |
|
255 Updates access point item name when the item becomes visible. |
|
256 */ |
|
257 void CpIapItem::updateIap() |
|
258 { |
|
259 OstTrace0( TRACE_FLOW, CPIAPITEM_UPDATEIAP_ENTRY, "CpIapItem::updateIap entry" ); |
|
260 try { |
|
261 CmConnectionMethodShim *cm = mCmm->connectionMethod(mIapId); |
|
262 this->setContentWidgetData("text", cm->getStringAttribute(CMManagerShim::CmName)); |
|
263 delete cm; |
|
264 } catch (const std::exception&) { |
|
265 OstTrace0( TRACE_NORMAL, CPIAPITEM_UPDATEIAP, "CpIapItem::updateIap: exception caught, CM name reading failed" ); |
|
266 } |
|
267 OstTrace0( TRACE_FLOW, DUP1_CPIAPITEM_UPDATEIAP_EXIT, "CpIapItem::updateIap exit" ); |
|
268 } |
|
269 |
|
270 /*! |
|
271 Opens Iap settings view. |
|
272 */ |
|
273 void CpIapItem::openIap() |
|
274 { |
|
275 onLaunchView(); |
|
276 } |
|
277 |
|
278 /*! |
|
279 Gets access point specific view from bearer plugin. |
|
280 |
|
281 \return Returns settings view containing access point settings. |
|
282 */ |
|
283 CpBaseSettingView *CpIapItem::createSettingView() const |
|
284 { |
|
285 OstTraceFunctionEntry0(CPIAPITEM_CREATESETTINGVIEW_ENTRY); |
|
286 CpBaseSettingView *view = NULL; |
|
287 if (mBearerPlugin != NULL) { |
|
288 CmConnectionMethodShim *cm = mCmm->connectionMethod(mIapId); |
|
289 bool cmConnected = cm->getBoolAttribute(CMManagerShim::CmConnected); |
|
290 delete cm; |
|
291 |
|
292 // Do not open connected AP |
|
293 if (!cmConnected) { |
|
294 view = mBearerPlugin->createSettingView(mIapId); |
|
295 } |
|
296 } |
|
297 OstTraceFunctionExit0(CPIAPITEM_CREATESETTINGVIEW_EXIT); |
|
298 return view; |
|
299 } |
|
300 |
|
301 /*! |
|
302 Prompts user for destination. |
|
303 */ |
|
304 void CpIapItem::queryDestination() |
|
305 { |
|
306 OstTraceFunctionEntry0(CPIAPITEM_QUERYDESTINATION_ENTRY); |
|
307 bool readingSuccessful = true; |
|
308 QStringList destinations; |
|
309 try { |
|
310 mCmm->allDestinations(mDestinationList); |
|
311 |
|
312 for (int i = 0; i < mDestinationList.count(); i++) { |
|
313 CmDestinationShim *destination = mCmm->destination(mDestinationList[i]); |
|
314 if ((destination->id() != mDestId) |
|
315 && !destination->isHidden()) { |
|
316 |
|
317 QString dest = destination->name(); |
|
318 destinations.append(dest); |
|
319 } else { |
|
320 // Remove this destination from list to sync both lists |
|
321 mDestinationList.removeAt(i); |
|
322 i--; |
|
323 } |
|
324 delete destination; |
|
325 } |
|
326 } catch (const std::exception&) { |
|
327 OstTrace0(TRACE_NORMAL, CPIAPITEM_QUERYDESTINATION, "CpIapItem::queryDestination: exception caught"); |
|
328 readingSuccessful = false; |
|
329 } |
|
330 |
|
331 if (readingSuccessful) { |
|
332 // Load DocML |
|
333 bool ok = false; |
|
334 HbDocumentLoader *loader = new HbDocumentLoader(); |
|
335 loader->load(":/docml/cpdestinationplugindialogs.docml", &ok); |
|
336 mDialog = qobject_cast<HbDialog *>(loader->findWidget("dialog")); |
|
337 HbLabel *heading = qobject_cast<HbLabel *>(loader->findWidget("heading")); |
|
338 heading->setPlainText(hbTrId("txt_occ_dialog_select_network_destination_to_be_ac")); |
|
339 mList = qobject_cast<HbRadioButtonList *>(loader->findWidget("radioButtonList")); |
|
340 mList->setItems(destinations); |
|
341 mList->setSelected(0); |
|
342 mOk = qobject_cast<HbAction *>(loader->findObject("okAction")); |
|
343 bool connected = connect(mOk, |
|
344 SIGNAL(triggered()), |
|
345 this, |
|
346 SLOT(queryDialogClosed())); |
|
347 Q_ASSERT(connected); |
|
348 mDialog->show(); |
|
349 delete loader; |
|
350 } else { |
|
351 OstTrace0(TRACE_NORMAL, DUP1_CPIAPITEM_QUERYDESTINATION, " CpIapItem::queryDestination: exception caught"); |
|
352 showErrorNote(hbTrId("txt_occ_info_unable_to_read_settings")); |
|
353 } |
|
354 OstTraceFunctionExit0(CPIAPITEM_QUERYDESTINATION_EXIT); |
|
355 } |
|
356 |
|
357 /*! |
|
358 Shares access point to given destination. |
|
359 |
|
360 @param[in] id Target destination's ID |
|
361 */ |
|
362 void CpIapItem::saveShare(int id) |
|
363 { |
|
364 OstTraceFunctionEntry0(CPIAPITEM_SAVESHARE_ENTRY); |
|
365 try { |
|
366 CmConnectionMethodShim *cm; |
|
367 CmDestinationShim *source = mCmm->destination(mDestId); |
|
368 cm = source->connectionMethodByID(mIapId); |
|
369 delete source; |
|
370 CmDestinationShim *target = mCmm->destination(id); |
|
371 target->addConnectionMethod(cm); |
|
372 target->update(); |
|
373 delete cm; |
|
374 delete target; |
|
375 OstTrace0(TRACE_NORMAL, CPIAPITEM_SAVESHARE, "CpIapItem::saveShare: Emit access point changed signal"); |
|
376 emit iapChanged(); |
|
377 } catch (const std::exception&) { |
|
378 OstTrace0(TRACE_NORMAL, DUP1_CPIAPITEM_SAVESHARE, "CpIapItem::saveShare: Exception caught"); |
|
379 showErrorNote(hbTrId("txt_occ_info_unable_to_read_settings")); |
|
380 } |
|
381 OstTraceFunctionExit0(CPIAPITEM_SAVESHARE_EXIT); |
|
382 } |
|
383 |
|
384 /*! |
|
385 Moves access point from current destination to given destination. |
|
386 |
|
387 @param[in] id Target destination's ID |
|
388 */ |
|
389 void CpIapItem::saveMove(int id) |
|
390 { |
|
391 OstTraceFunctionEntry0(CPIAPITEM_SAVEMOVE_ENTRY); |
|
392 try { |
|
393 // Make move in commsdat |
|
394 CmConnectionMethodShim *cm = NULL; |
|
395 if (mDestId != 0) { |
|
396 CmDestinationShim *source = mCmm->destination(mDestId); |
|
397 cm = source->connectionMethodByID(mIapId); |
|
398 source->removeConnectionMethod(cm); |
|
399 source->update(); |
|
400 delete source; |
|
401 } else { |
|
402 cm = mCmm->connectionMethod(mIapId); |
|
403 } |
|
404 CmDestinationShim *target = mCmm->destination(id); |
|
405 target->addConnectionMethod(cm); |
|
406 target->update(); |
|
407 delete target; |
|
408 delete cm; |
|
409 } |
|
410 catch (const std::exception&) { |
|
411 OstTrace0(TRACE_NORMAL, DUP1_CPIAPITEM_SAVEMOVE, "CpIapItem::saveMove: Exception caught"); |
|
412 showErrorNote(hbTrId("txt_occ_info_unable_to_save_setting")); |
|
413 } |
|
414 OstTrace0(TRACE_NORMAL, CPIAPITEM_SAVEMOVE, "CpIapItem::saveMove: Emit access point changed signal"); |
|
415 emit iapChanged(); |
|
416 OstTraceFunctionExit0(CPIAPITEM_SAVEMOVE_EXIT); |
|
417 } |
|
418 |
|
419 /*! |
|
420 Tests if CmManagerShim has been created successfully |
|
421 earlier. If not, it retries. |
|
422 */ |
|
423 bool CpIapItem::isCmManagerAvailable() |
|
424 { |
|
425 OstTraceFunctionEntry0(CPIAPITEM_ISCMMANAGERAVAILABLE_ENTRY); |
|
426 bool retval = false; |
|
427 if (mCmm == NULL) { |
|
428 try { |
|
429 mCmm = new CmManagerShim(); |
|
430 retval = true; |
|
431 } |
|
432 catch (const std::exception&) { |
|
433 OstTrace0(TRACE_NORMAL, CPIAPITEM_ISCMMANAGERAVAILABLE, "CpIapItem::isCmManagerAvailable: Exception caught"); |
|
434 mCmm = NULL; |
|
435 } |
|
436 } else { |
|
437 retval = true; |
|
438 } |
|
439 OstTraceFunctionExit0(CPIAPITEM_ISCMMANAGERAVAILABLE_EXIT); |
|
440 return retval; |
|
441 } |
|
442 |
|
443 /*! |
|
444 Helper function for creating item specific menu. |
|
445 |
|
446 @param[in] protLvl Effective protection level for this |
|
447 access point. |
|
448 */ |
|
449 HbMenu *CpIapItem::createItemMenu( |
|
450 bool cmConnected, |
|
451 const QPointF &position) |
|
452 { |
|
453 OstTraceFunctionEntry0(CPIAPITEM_CREATEITEMMENU_ENTRY); |
|
454 HbMenu* menu = new HbMenu(); |
|
455 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
456 HbAction* openIapAction |
|
457 = menu->addAction(hbTrId("txt_common_menu_open")); |
|
458 bool connected = connect(openIapAction, SIGNAL(triggered()), this, SLOT(openIap())); |
|
459 Q_ASSERT(connected); |
|
460 HbAction* moveIapAction |
|
461 = menu->addAction(hbTrId("txt_occ_menu_move_to_other_destination")); |
|
462 connected = connect(moveIapAction, SIGNAL(triggered()), this, SLOT(moveIap())); |
|
463 Q_ASSERT(connected); |
|
464 HbAction* deleteIapAction |
|
465 = menu->addAction(hbTrId("txt_common_menu_delete")); |
|
466 connected = connect( |
|
467 deleteIapAction, |
|
468 SIGNAL(triggered()), |
|
469 this, |
|
470 SLOT(showDeleteConfirmation())); |
|
471 Q_ASSERT(connected); |
|
472 HbAction* shareIapAction |
|
473 = menu->addAction(hbTrId("txt_occ_menu_share_to_other_destination")); |
|
474 connected = connect(shareIapAction, SIGNAL(triggered()), this, SLOT(shareIap())); |
|
475 Q_ASSERT(connected); |
|
476 |
|
477 if (cmConnected) { |
|
478 // Disable operations for connected APs |
|
479 openIapAction->setDisabled(true); |
|
480 moveIapAction->setDisabled(true); |
|
481 deleteIapAction->setDisabled(true); |
|
482 shareIapAction->setDisabled(true); |
|
483 } |
|
484 |
|
485 // Can't share uncategorised APs |
|
486 if (mDestId == 0) |
|
487 { |
|
488 shareIapAction->setDisabled(true); |
|
489 } |
|
490 |
|
491 menu->setPreferredPos(position); |
|
492 OstTraceFunctionExit0(CPIAPITEM_CREATEITEMMENU_EXIT); |
|
493 return menu; |
|
494 } |
|
495 |
|
496 /*! |
|
497 Helper function for showing error notes. |
|
498 |
|
499 @param[in] info Info string to be shown in note. |
|
500 */ |
|
501 void CpIapItem::showErrorNote(const QString &info) |
|
502 { |
|
503 OstTraceFunctionEntry0(CPIAPITEM_SHOWERRORNOTE_ENTRY); |
|
504 HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation); |
|
505 note->clearActions(); |
|
506 note->setAttribute(Qt::WA_DeleteOnClose); |
|
507 note->setText(info); |
|
508 note->setTimeout(HbPopup::NoTimeout); |
|
509 HbAction *errorOk = new HbAction(hbTrId("txt_common_button_ok")); |
|
510 note->addAction(errorOk); |
|
511 note->show(); |
|
512 OstTraceFunctionExit0(CPIAPITEM_SHOWERRORNOTE_EXIT); |
|
513 } |