|
1 /* |
|
2 * Copyright (c) 2009-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 * WLAN Sniffer list widget class. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 #include <QSharedPointer> |
|
21 #include <HbListWidget> |
|
22 #include <HbListWidgetItem> |
|
23 #include <HbAbstractViewItem> |
|
24 #include <HbStringUtil> |
|
25 #include <cmmanagerdefines_shim.h> |
|
26 |
|
27 // User includes |
|
28 |
|
29 #include "wlanqtutils.h" |
|
30 #include "wlanqtutilsap.h" |
|
31 #include "wlanqtutilsiap.h" |
|
32 |
|
33 #include "wlansniffer.h" |
|
34 #include "wlansnifferlistitem.h" |
|
35 #include "wlansnifferlistwidget.h" |
|
36 |
|
37 #include "OstTraceDefinitions.h" |
|
38 #ifdef OST_TRACE_COMPILER_IN_USE |
|
39 #include "wlansnifferlistwidgetTraces.h" |
|
40 #endif |
|
41 |
|
42 /*! |
|
43 \class WlanSnifferListWidget |
|
44 \brief WLAN Sniffer Custom List Widget implementation. |
|
45 */ |
|
46 |
|
47 // External function prototypes |
|
48 |
|
49 // Local constants |
|
50 |
|
51 // ======== LOCAL FUNCTIONS ======== |
|
52 |
|
53 /*! |
|
54 String comparator for list view. Used for locale-aware SSID comparison |
|
55 in list view. |
|
56 |
|
57 @param [in] string1 String #1 to compare. |
|
58 @param [in] string2 String #2 to compare. |
|
59 |
|
60 @return Zero (0), if strings are considered to be same, |
|
61 Positive (>0) if string1 is considered to be "greater than" string2. |
|
62 Negative (<0) if string1 is considered to be "less than" string2. |
|
63 */ |
|
64 |
|
65 static int WlanSsidStringComparator( |
|
66 const QString &string1, |
|
67 const QString &string2) |
|
68 { |
|
69 return HbStringUtil::compareC(string1, string2); |
|
70 } |
|
71 |
|
72 // ======== MEMBER FUNCTIONS ======== |
|
73 |
|
74 /*! |
|
75 Constructor. |
|
76 |
|
77 @param [in] listWidget List Widget created to customize. |
|
78 */ |
|
79 |
|
80 WlanSnifferListWidget::WlanSnifferListWidget(HbListWidget *listWidget) : |
|
81 mListWidget(listWidget) |
|
82 { |
|
83 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY); |
|
84 |
|
85 // Set custom WLAN list item layout |
|
86 mListWidget->setLayoutName("wlanlistitem"); |
|
87 |
|
88 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT); |
|
89 } |
|
90 |
|
91 /*! |
|
92 Destructor. |
|
93 */ |
|
94 |
|
95 WlanSnifferListWidget::~WlanSnifferListWidget() |
|
96 { |
|
97 OstTraceFunctionEntry0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_ENTRY); |
|
98 OstTraceFunctionExit0(DUP1_WLANSNIFFERLISTWIDGET_WLANSNIFFERLISTWIDGET_EXIT); |
|
99 } |
|
100 |
|
101 /*! |
|
102 Updates the list widget content with the given IAPs and APs. |
|
103 |
|
104 @param [in] iaps New WLAN IAP list. |
|
105 @param [in] aps New WLAN AP list. |
|
106 @param [in] connectedIapId IAP ID of the connected WLAN or |
|
107 IapIdNone if not connected. |
|
108 */ |
|
109 |
|
110 void WlanSnifferListWidget::updateContent( |
|
111 QList< QSharedPointer<WlanQtUtilsIap> > &iaps, |
|
112 QList< QSharedPointer<WlanQtUtilsAp> > &aps, |
|
113 int connectedIapId) |
|
114 { |
|
115 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_UPDATESCANSTATUS_ENTRY); |
|
116 |
|
117 traceListContent(); |
|
118 |
|
119 // Sort the scan result lists |
|
120 sortIaps(iaps, connectedIapId); |
|
121 sortAps(aps); |
|
122 |
|
123 // Remove items, which are not present in new IAP or AP lists |
|
124 removeLostItems(iaps, aps); |
|
125 |
|
126 // Add items, which are only found in the new IAP and AP lists. |
|
127 // Also update the icons of existing items (connection mode and |
|
128 // signal strength may have changed) |
|
129 addDiscoveredItemsAndUpdateRest(iaps, aps, connectedIapId); |
|
130 |
|
131 traceListContent(); |
|
132 |
|
133 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_UPDATESCANSTATUS_EXIT); |
|
134 } |
|
135 |
|
136 /*! |
|
137 Scroll the list widget to given row. |
|
138 |
|
139 @param [in] row Row to scroll to. Indexing starts from zero. |
|
140 */ |
|
141 |
|
142 void WlanSnifferListWidget::scrollTo(int row) |
|
143 { |
|
144 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SCROLLTO_ENTRY); |
|
145 |
|
146 OstTrace1( |
|
147 TRACE_NORMAL, |
|
148 WLANSNIFFERLISTWIDGET_SCROLLTO, |
|
149 "WlanSnifferListWidget::scrollTo;row=%d", |
|
150 row); |
|
151 |
|
152 // Check that the row exists |
|
153 if (row < mListWidget->count()) { |
|
154 // Do the scrolling |
|
155 QModelIndex index = mListWidget->model()->index(row, 0); |
|
156 mListWidget->scrollTo(index); |
|
157 } |
|
158 |
|
159 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SCROLLTO_EXIT); |
|
160 } |
|
161 |
|
162 /*! |
|
163 IAP list sorting. Sorts IAPs into alphabetical order taking localization |
|
164 into account. |
|
165 |
|
166 @param [in,out] iaps WLAN IAP list. |
|
167 @param [in] connectedIapId IAP ID of the connected WLAN or |
|
168 IapIdNone if not connected. |
|
169 */ |
|
170 |
|
171 void WlanSnifferListWidget::sortIaps( |
|
172 QList< QSharedPointer<WlanQtUtilsIap> > &iaps, |
|
173 int connectedIapId) |
|
174 { |
|
175 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SORTIAPS_ENTRY); |
|
176 |
|
177 // Order the list by IAP name |
|
178 qSort( |
|
179 iaps.begin(), |
|
180 iaps.end(), |
|
181 WlanSnifferListWidget::iapLessThan); |
|
182 |
|
183 // Find the possible connected IAP |
|
184 int connectedIndex = 0; |
|
185 for (int i = 0; i < iaps.size(); i++) { |
|
186 if (iaps[i]->value(WlanQtUtilsIap::ConfIdIapId).toInt() == connectedIapId) { |
|
187 connectedIndex = i; |
|
188 break; |
|
189 } |
|
190 } |
|
191 |
|
192 // Move the possible connected IAP to the beginning |
|
193 if (connectedIndex) { |
|
194 OstTraceExt2( |
|
195 TRACE_NORMAL, |
|
196 WLANSNIFFERLISTWIDGET_SORTIAPS_MOVE_CONNECTED, |
|
197 "WlanSnifferListWidget::sortIaps Moving connected IAP to top;connectedIapId=%d;connectedIndex=%d", |
|
198 connectedIapId, |
|
199 connectedIndex); |
|
200 |
|
201 iaps.move(connectedIndex, 0); |
|
202 } |
|
203 |
|
204 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SORTIAPS_EXIT); |
|
205 } |
|
206 |
|
207 /*! |
|
208 AP list sorting. Sorts APs into alphabetical order taking localization |
|
209 into account. |
|
210 |
|
211 @param [in,out] aps WLAN AP list. |
|
212 */ |
|
213 |
|
214 void WlanSnifferListWidget::sortAps( |
|
215 QList< QSharedPointer<WlanQtUtilsAp> > &aps) |
|
216 { |
|
217 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SORTAPS_ENTRY); |
|
218 |
|
219 // Order the list by AP SSID |
|
220 qSort( |
|
221 aps.begin(), |
|
222 aps.end(), |
|
223 WlanSnifferListWidget::apLessThan); |
|
224 |
|
225 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SORTAPS_EXIT); |
|
226 } |
|
227 |
|
228 /*! |
|
229 Compares two WLAN IAPs. Comparison is done with the IAP name. |
|
230 |
|
231 @param[in] iap1 IAP to compare with. |
|
232 @param[in] iap2 IAP to compare. |
|
233 |
|
234 @return Returns true if the first iap is "less than" the second one. |
|
235 */ |
|
236 |
|
237 bool WlanSnifferListWidget::iapLessThan( |
|
238 const QSharedPointer<WlanQtUtilsIap> iap1, |
|
239 const QSharedPointer<WlanQtUtilsIap> iap2) |
|
240 { |
|
241 // Primary comparison is based on the name |
|
242 int result = HbStringUtil::compareC( |
|
243 iap1->value(WlanQtUtilsIap::ConfIdName).toString(), |
|
244 iap2->value(WlanQtUtilsIap::ConfIdName).toString()); |
|
245 |
|
246 return (result < 0) ? true : false; |
|
247 } |
|
248 |
|
249 /*! |
|
250 Compares two WLAN APs. Comparison is done with the AP SSID. |
|
251 |
|
252 @param[in] ap1 AP to compare with. |
|
253 @param[in] ap2 AP to compare. |
|
254 |
|
255 @return Returns true if the first ap is "less than" the second one. |
|
256 */ |
|
257 |
|
258 bool WlanSnifferListWidget::apLessThan( |
|
259 const QSharedPointer<WlanQtUtilsAp> ap1, |
|
260 const QSharedPointer<WlanQtUtilsAp> ap2) |
|
261 { |
|
262 // Use AP comparison function with localized SSID comparison |
|
263 int result = WlanQtUtilsAp::compare( |
|
264 ap1.data(), |
|
265 ap2.data(), |
|
266 WlanSsidStringComparator); |
|
267 |
|
268 return (result < 0) ? true : false; |
|
269 } |
|
270 |
|
271 /*! |
|
272 Function for finding the given IAP from the old Wlan list. |
|
273 |
|
274 @param [in] iap IAP to find. |
|
275 |
|
276 @return Found WLAN List Widget item, 0 if not found. |
|
277 */ |
|
278 |
|
279 WlanSnifferListItem *WlanSnifferListWidget::findFromOldList( |
|
280 QSharedPointer<WlanQtUtilsIap> iap) |
|
281 { |
|
282 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP_ENTRY); |
|
283 |
|
284 WlanSnifferListItem *result = NULL; |
|
285 QVariant iapData = iap->value(WlanQtUtilsIap::ConfIdIapId); |
|
286 for (int row = 0; row < mListWidget->count(); row++) { |
|
287 HbListWidgetItem *item = mListWidget->item(row); |
|
288 if (item->data() == iapData) { |
|
289 result = static_cast<WlanSnifferListItem *>(item); |
|
290 break; |
|
291 } |
|
292 } |
|
293 |
|
294 OstTraceExt2( |
|
295 TRACE_DUMP, |
|
296 WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP, |
|
297 "WlanSnifferListWidget::findFromOldList;iapId=%d;found=%hhu", |
|
298 iapData.toInt(), |
|
299 (result != NULL) ? true : false); |
|
300 |
|
301 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_IAP_EXIT); |
|
302 return result; |
|
303 } |
|
304 |
|
305 /*! |
|
306 Function for finding the given AP from the old Wlan list. |
|
307 |
|
308 @param [in] ap AP to find. |
|
309 |
|
310 @return Found WLAN List Widget item, 0 if not found. |
|
311 */ |
|
312 |
|
313 WlanSnifferListItem *WlanSnifferListWidget::findFromOldList( |
|
314 QSharedPointer<WlanQtUtilsAp> ap) |
|
315 { |
|
316 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP_ENTRY); |
|
317 |
|
318 WlanSnifferListItem *result = NULL; |
|
319 for (int row = 0; row < mListWidget->count(); row++) { |
|
320 HbListWidgetItem *item = mListWidget->item(row); |
|
321 if (item->data().canConvert<WlanQtUtilsAp>()) { |
|
322 WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>(); |
|
323 if (WlanQtUtilsAp::compare(ap.data(), &oldAp) == 0) { |
|
324 result = static_cast<WlanSnifferListItem *>(item); |
|
325 break; |
|
326 } |
|
327 } |
|
328 } |
|
329 |
|
330 #ifdef OST_TRACE_COMPILER_IN_USE |
|
331 QString tmp(ap.data()->value(WlanQtUtilsAp::ConfIdSsid).toString()); |
|
332 TPtrC16 ssid(tmp.utf16(), tmp.length()); |
|
333 OstTraceExt2( |
|
334 TRACE_NORMAL, |
|
335 WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP, |
|
336 "WlanSnifferListWidget::findFromOldList;found=%hhu;ssid=%S", |
|
337 (result != NULL) ? true : false, |
|
338 ssid); |
|
339 #endif |
|
340 |
|
341 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_FINDFROMOLDLIST_AP_EXIT); |
|
342 return result; |
|
343 } |
|
344 |
|
345 /*! |
|
346 Function for creating a new list item from the given IAP. |
|
347 |
|
348 @param [in] iap WLAN IAP to create. |
|
349 @param [in] connectedIapId IAP ID of the connected WLAN or |
|
350 IapIdNone if not connected. |
|
351 |
|
352 @return New WLAN List Widget item. |
|
353 */ |
|
354 |
|
355 HbListWidgetItem *WlanSnifferListWidget::listItemCreate( |
|
356 QSharedPointer<WlanQtUtilsIap> iap, |
|
357 int connectedIapId) |
|
358 { |
|
359 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_ENTRY); |
|
360 |
|
361 WlanSnifferListItem *item = new WlanSnifferListItem(); |
|
362 item->setNetworkName(iap->value(WlanQtUtilsIap::ConfIdName).toString()); |
|
363 // Note: WPS icon is needed only in IAP setup, no longer here |
|
364 if (iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() != |
|
365 CMManagerShim::WlanSecModeOpen) { |
|
366 item->setSecureIcon("qtg_small_lock"); |
|
367 } |
|
368 |
|
369 item->setLeftIcon( |
|
370 leftIconChoose( |
|
371 iap->value(WlanQtUtilsIap::ConfIdIapId).toInt(), |
|
372 connectedIapId)); |
|
373 item->setSignalIcon( |
|
374 signalStrengthIconChoose( |
|
375 iap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt())); |
|
376 |
|
377 item->setData(iap->value(WlanQtUtilsIap::ConfIdIapId)); |
|
378 |
|
379 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_IAP_EXIT); |
|
380 return item; |
|
381 } |
|
382 |
|
383 /*! |
|
384 Function for creating a new list item from the given AP. |
|
385 |
|
386 @param [in] ap WLAN AP to create. |
|
387 |
|
388 @return New WLAN List Widget item. |
|
389 */ |
|
390 |
|
391 HbListWidgetItem *WlanSnifferListWidget::listItemCreate( |
|
392 QSharedPointer<WlanQtUtilsAp> ap) |
|
393 { |
|
394 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_ENTRY); |
|
395 |
|
396 WlanSnifferListItem *item = new WlanSnifferListItem(); |
|
397 item->setNetworkName(ap->value(WlanQtUtilsAp::ConfIdSsid).toString()); |
|
398 if (ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()) { |
|
399 // WPS is supported, use a dedicated security icon |
|
400 item->setSecureIcon("qtg_small_wifi"); |
|
401 } else if (ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt() |
|
402 != CMManagerShim::WlanSecModeOpen) { |
|
403 // Other secure networks |
|
404 item->setSecureIcon("qtg_small_lock"); |
|
405 } |
|
406 item->setSignalIcon( |
|
407 signalStrengthIconChoose( |
|
408 ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt())); |
|
409 |
|
410 QVariant data; |
|
411 data.setValue(*ap); |
|
412 item->setData(data); |
|
413 |
|
414 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LISTITEMCREATE_AP_EXIT); |
|
415 return item; |
|
416 } |
|
417 |
|
418 /*! |
|
419 Function for selecting the correct signal strength icon. |
|
420 |
|
421 @param [in] signalStrength Signal strength. |
|
422 |
|
423 @return Signal strength icon logical name. |
|
424 */ |
|
425 |
|
426 QString WlanSnifferListWidget::signalStrengthIconChoose(int signalStrength) |
|
427 { |
|
428 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_SIGNALSTRENGTHICONCHOOSE_ENTRY); |
|
429 |
|
430 QString iconName; |
|
431 if (signalStrength <= SignalStrengthHigh) { |
|
432 iconName = "qtg_small_signal_good"; |
|
433 } else if (signalStrength <= SignalStrengthMedium) { |
|
434 iconName = "qtg_small_signal_medium"; |
|
435 } else { |
|
436 iconName = "qtg_small_signal_low"; |
|
437 } |
|
438 |
|
439 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_SIGNALSTRENGTHICONCHOOSE_EXIT); |
|
440 return iconName; |
|
441 } |
|
442 |
|
443 /*! |
|
444 Function for selecting the correct "left" icon, which is different for |
|
445 connected and not connected IAPs. |
|
446 |
|
447 @param [in] iapId IAP ID of the WLAN IAP. |
|
448 @param [in] connectedIapId IAP ID of the connected WLAN or |
|
449 IapIdNone if not connected. |
|
450 |
|
451 @return Icon logical name of the "left" icon. |
|
452 */ |
|
453 |
|
454 QString WlanSnifferListWidget::leftIconChoose( |
|
455 int iapId, |
|
456 int connectedIapId) |
|
457 { |
|
458 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_LEFTICONCHOOSE_ENTRY); |
|
459 |
|
460 QString iconName; |
|
461 if (iapId == connectedIapId) { |
|
462 iconName = "qtg_small_connection"; |
|
463 } else { |
|
464 iconName = "qtg_small_wlan"; |
|
465 } |
|
466 |
|
467 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_LEFTICONCHOOSE_EXIT); |
|
468 return iconName; |
|
469 } |
|
470 |
|
471 /*! |
|
472 Function for removing from the old Wlan list those items, which are |
|
473 not present in the given new lists. |
|
474 |
|
475 @param [in] iaps New WLAN IAP list. |
|
476 @param [in] aps New WLAN AP list. |
|
477 */ |
|
478 |
|
479 void WlanSnifferListWidget::removeLostItems( |
|
480 const QList< QSharedPointer<WlanQtUtilsIap> > &iaps, |
|
481 const QList< QSharedPointer<WlanQtUtilsAp> > &aps) |
|
482 { |
|
483 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_ENTRY); |
|
484 |
|
485 int row = 0; |
|
486 // Loop through all rows in the current list and try to find the items from |
|
487 // the new lists |
|
488 while (row < mListWidget->count()) { |
|
489 bool found = false; |
|
490 const HbListWidgetItem *item = mListWidget->item(row); |
|
491 if (item->data().canConvert<int>()) { |
|
492 // Item was an IAP, try to find it from the new IAP list |
|
493 foreach (QSharedPointer<WlanQtUtilsIap> iap, iaps) { |
|
494 if (iap->value(WlanQtUtilsIap::ConfIdIapId) == |
|
495 item->data()) { |
|
496 found = true; |
|
497 break; |
|
498 } |
|
499 } |
|
500 } else { |
|
501 // Item has to be an AP, try to find it from the new AP list |
|
502 Q_ASSERT(item->data().canConvert<WlanQtUtilsAp>()); |
|
503 WlanQtUtilsAp oldAp = item->data().value<WlanQtUtilsAp>(); |
|
504 foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) { |
|
505 if (WlanQtUtilsAp::compare(newAp.data(), &oldAp) == 0) { |
|
506 found = true; |
|
507 break; |
|
508 } |
|
509 } |
|
510 } |
|
511 if (found == false) { |
|
512 // Item was lost. Remove this row and delete it. Don't increment |
|
513 // row index, because the next item now has the same row index |
|
514 // as this one had |
|
515 delete mListWidget->takeItem(row); |
|
516 |
|
517 OstTrace1( |
|
518 TRACE_NORMAL, |
|
519 WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS, |
|
520 "WlanSnifferListWidget::removeLostItems Removed;row=%d", |
|
521 row); |
|
522 } else { |
|
523 // Item still exists, move on to next row |
|
524 row++; |
|
525 } |
|
526 } |
|
527 |
|
528 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_REMOVELOSTITEMS_EXIT); |
|
529 } |
|
530 |
|
531 /*! |
|
532 Function for adding to the Wlan list those items, which are new |
|
533 in the given new lists. Also, icons and order of the existing list |
|
534 items are updated. |
|
535 |
|
536 @param [in] iaps New WLAN IAP list. |
|
537 @param [in] aps New WLAN AP list. |
|
538 @param [in] connectedIapId IAP ID of the connected WLAN or |
|
539 IapIdNone if not connected. |
|
540 */ |
|
541 |
|
542 void WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest( |
|
543 const QList< QSharedPointer<WlanQtUtilsIap> > &iaps, |
|
544 const QList< QSharedPointer<WlanQtUtilsAp> > &aps, |
|
545 int connectedIapId) |
|
546 { |
|
547 OstTraceFunctionEntry0(WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ENTRY); |
|
548 |
|
549 int row = 0; |
|
550 // Loop through new IAPs and try to find them from the old list |
|
551 foreach (QSharedPointer<WlanQtUtilsIap> newIap, iaps) { |
|
552 WlanSnifferListItem *oldItem = findFromOldList(newIap); |
|
553 if (oldItem != NULL) { |
|
554 // Match found, update icons |
|
555 oldItem->setLeftIcon( |
|
556 leftIconChoose( |
|
557 newIap->value(WlanQtUtilsIap::ConfIdIapId).toInt(), |
|
558 connectedIapId)); |
|
559 oldItem->setSignalIcon( |
|
560 signalStrengthIconChoose( |
|
561 newIap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt())); |
|
562 // Also move the IAP to new row, if necessary (IAP order changes |
|
563 // when IAPs are connected/disconnected) |
|
564 int oldRow = mListWidget->row(oldItem); |
|
565 if (row != oldRow) { |
|
566 OstTraceExt2( |
|
567 TRACE_NORMAL, |
|
568 WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_MOVE, |
|
569 "WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest Moved;oldRow=%d;row=%d", |
|
570 oldRow, |
|
571 row); |
|
572 mListWidget->takeItem(oldRow); |
|
573 mListWidget->insertItem(row, oldItem); |
|
574 } |
|
575 } else { |
|
576 // New item discovered, add it to the list. Row is the same as the |
|
577 // index of the item in the new scan list |
|
578 OstTrace1( |
|
579 TRACE_NORMAL, |
|
580 WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ADD_IAP, |
|
581 "WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest Added IAP;row=%d", |
|
582 row); |
|
583 mListWidget->insertItem(row, listItemCreate(newIap, connectedIapId)); |
|
584 } |
|
585 // Move to next row |
|
586 row++; |
|
587 } |
|
588 // Repeat the same for new APs. Notice that row index continues from |
|
589 // previous loop |
|
590 foreach (QSharedPointer<WlanQtUtilsAp> newAp, aps) { |
|
591 WlanSnifferListItem *oldItem = findFromOldList(newAp); |
|
592 if (oldItem != NULL) { |
|
593 oldItem->setSignalIcon( |
|
594 signalStrengthIconChoose( |
|
595 newAp->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt())); |
|
596 // Notice that AP order may not change, they are always in |
|
597 // alphabetical order |
|
598 } else { |
|
599 OstTrace1( |
|
600 TRACE_NORMAL, |
|
601 WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_ADD_AP, |
|
602 "WlanSnifferListWidget::addDiscoveredItemsAndUpdateRest Added AP;row=%d", |
|
603 row); |
|
604 mListWidget->insertItem(row, listItemCreate(newAp)); |
|
605 } |
|
606 row++; |
|
607 } |
|
608 |
|
609 OstTraceFunctionExit0(WLANSNIFFERLISTWIDGET_ADDDISCOVEREDITEMSANDUPDATEREST_EXIT); |
|
610 } |
|
611 |
|
612 /*! |
|
613 This function traces the contents of the list. |
|
614 */ |
|
615 |
|
616 void WlanSnifferListWidget::traceListContent() const |
|
617 { |
|
618 #ifdef OST_TRACE_COMPILER_IN_USE |
|
619 for (int row = 0; row < mListWidget->count(); row++) { |
|
620 HbListWidgetItem *item = mListWidget->item(row); |
|
621 if (item->data().canConvert<int>()) { |
|
622 OstTraceExt2( |
|
623 TRACE_DUMP, |
|
624 WLANSNIFFERLISTWIDGET_TRACELISTCONTENT_IAP, |
|
625 "WlanSnifferListWidget::traceListContent IAP;row=%d;id=%d", |
|
626 row, |
|
627 item->data().toInt()); |
|
628 } else { |
|
629 Q_ASSERT(item->data().canConvert<WlanQtUtilsAp>()); |
|
630 WlanQtUtilsAp ap = item->data().value<WlanQtUtilsAp>(); |
|
631 QString tmp(ap.value(WlanQtUtilsAp::ConfIdSsid).toString()); |
|
632 TPtrC16 ssid(tmp.utf16(), tmp.length()); |
|
633 OstTraceExt2( |
|
634 TRACE_DUMP, |
|
635 WLANSNIFFERLISTWIDGET_TRACELISTCONTENT_AP, |
|
636 "WlanSnifferListWidget::traceListContent AP;row=%d;ssid=%S", |
|
637 row, |
|
638 ssid); |
|
639 } |
|
640 } |
|
641 #endif |
|
642 } |