1 /* |
|
2 * Copyright (c) 2007-2008 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: Implementation of CWsfWlanInfoSortingBlackList |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // EXTERNAL INCLUDES |
|
21 #include <StringLoader.h> |
|
22 #include <aknselectionlist.h> |
|
23 #include <aknnotewrappers.h> |
|
24 #include <utf.h> |
|
25 |
|
26 // CLASS HEADER |
|
27 #include "wsfwlaninfosortingblacklist.h" |
|
28 |
|
29 // INTERNAL INCLUDES |
|
30 #include <wsfwlaninfosorting.rsg> |
|
31 #include "wsfwlaninfoarray.h" |
|
32 #include "wsfwlanssidselectiondlg2.h" |
|
33 #include "wsflogger.h" |
|
34 |
|
35 |
|
36 /** |
|
37 * SSID array granularity |
|
38 */ |
|
39 static const TInt KIntSsidArrayGranularity = 3; |
|
40 |
|
41 /** |
|
42 * SSID blacklist table name in DB |
|
43 */ |
|
44 _LIT( KBlackListTableName,"WIZARD_BLACKLIST"); |
|
45 |
|
46 /** |
|
47 * SSID column name in blacklist table |
|
48 */ |
|
49 _LIT( KBlackListTableIdColumnName,"WIZARD_BLACKLIST_SSID"); |
|
50 |
|
51 |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // CWsfWlanInfoSortingBlackList::NewLC |
|
55 // ---------------------------------------------------------------------------- |
|
56 // |
|
57 CWsfWlanInfoSortingBlackList* CWsfWlanInfoSortingBlackList::NewLC( |
|
58 RDbNamedDatabase& aDatabase ) |
|
59 { |
|
60 CWsfWlanInfoSortingBlackList* thisPtr = |
|
61 new (ELeave) CWsfWlanInfoSortingBlackList( aDatabase ); |
|
62 CleanupStack::PushL( thisPtr ); |
|
63 thisPtr->ConstructL(); |
|
64 return thisPtr; |
|
65 } |
|
66 |
|
67 |
|
68 // ---------------------------------------------------------------------------- |
|
69 // CWsfWlanInfoSortingBlackList::NewL |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 CWsfWlanInfoSortingBlackList* CWsfWlanInfoSortingBlackList::NewL( |
|
73 RDbNamedDatabase& aDatabase ) |
|
74 { |
|
75 CWsfWlanInfoSortingBlackList* thisPtr = NewLC( aDatabase ); |
|
76 CleanupStack::Pop( thisPtr ); |
|
77 return thisPtr; |
|
78 } |
|
79 |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CWsfWlanInfoSortingBlackList::CWsfWlanInfoSortingBlackList |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CWsfWlanInfoSortingBlackList::CWsfWlanInfoSortingBlackList( |
|
86 RDbNamedDatabase& aDatabase ): |
|
87 iDefsDb( &aDatabase ) |
|
88 { |
|
89 } |
|
90 |
|
91 |
|
92 // ---------------------------------------------------------------------------- |
|
93 // CWsfWlanInfoSortingBlackList::~CWsfWlanInfoSortingBlackList |
|
94 // ---------------------------------------------------------------------------- |
|
95 // |
|
96 CWsfWlanInfoSortingBlackList::~CWsfWlanInfoSortingBlackList() |
|
97 { |
|
98 // free the blacklist entries... |
|
99 if ( iBlackListSsids ) |
|
100 { |
|
101 iBlackListSsids->Reset(); |
|
102 } |
|
103 delete iBlackListSsids; |
|
104 |
|
105 iBlackListSsidTable.Close(); |
|
106 } |
|
107 |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CWsfWlanInfoSortingBlackList::ConstructL |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 void CWsfWlanInfoSortingBlackList::ConstructL() |
|
114 { |
|
115 CheckTableL(); |
|
116 iBlackListSsids = new (ELeave) CDesC8ArrayFlat( KIntSsidArrayGranularity ); |
|
117 } |
|
118 |
|
119 |
|
120 // ---------------------------------------------------------------------------- |
|
121 // CWsfWlanInfoSortingBlackList::BlackListItemCount |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CWsfWlanInfoSortingBlackList::BlackListItemCount() const |
|
125 { |
|
126 return iBlackListSsids->Count(); |
|
127 } |
|
128 |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CWsfWlanInfoSortingBlackList::Compare |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CWsfWlanInfoSortingBlackList::Compare( const TWsfWlanInfo& /*aInfoLeft*/, |
|
135 const TWsfWlanInfo& /*aInfoRight*/ ) |
|
136 { |
|
137 return 0; |
|
138 } |
|
139 |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // CWsfWlanInfoSortingBlackList::SetupOnRuleMatch |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 TBool CWsfWlanInfoSortingBlackList::SetupOnRuleMatch( TWsfWlanInfo& aInfoLeft ) |
|
146 { |
|
147 // look through the ssid array - and look for a match |
|
148 TInt rulePosition( 0 ); |
|
149 |
|
150 if ( aInfoLeft.BlackListEntry() ) |
|
151 { |
|
152 return ETrue; |
|
153 } |
|
154 |
|
155 if ( iBlackListSsids->FindIsq( aInfoLeft.iSsid, rulePosition ) == 0 ) |
|
156 { |
|
157 // the rule matches.... |
|
158 aInfoLeft.SetBlackListEntry( ETrue ); |
|
159 return ETrue; |
|
160 } |
|
161 |
|
162 return EFalse; |
|
163 } |
|
164 |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CWsfWlanInfoSortingBlackList::MarkMatchedFilterL |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 void CWsfWlanInfoSortingBlackList::MarkMatchedFilterL( |
|
171 TWsfWlanInfo& aFilterEntry ) |
|
172 { |
|
173 aFilterEntry.SetBlackListEntry( ETrue ); |
|
174 } |
|
175 |
|
176 |
|
177 // ---------------------------------------------------------------------------- |
|
178 // CWsfWlanInfoSortingBlackList::EditFilterDefsL |
|
179 // ---------------------------------------------------------------------------- |
|
180 // |
|
181 void CWsfWlanInfoSortingBlackList::EditFilterDefsL( |
|
182 CWsfWlanInfoArray& aInfoArray ) |
|
183 { |
|
184 LOG_ENTERFN( "CWsfWlanInfoSortingBlackList::EditFilterDefsL" ); |
|
185 |
|
186 // ok - lets map aInfoArray contents and iBlackListSsids and build our selves |
|
187 // a list of blacklist entries and current non sorted entries... |
|
188 |
|
189 // first loop through the aInfoArray and ... |
|
190 |
|
191 // make 16 bit copy of the ssid array... |
|
192 TInt arrayItemCount( iBlackListSsids->Count() + aInfoArray.Count() ); |
|
193 if ( !arrayItemCount ) |
|
194 { |
|
195 // there's nothing to edit |
|
196 // just return before showing edit dialog |
|
197 return; |
|
198 } |
|
199 |
|
200 LOG_WRITE( "there are items to show" ); |
|
201 CDesCArrayFlat *arrayOfItems = |
|
202 new (ELeave) CDesCArrayFlat( arrayItemCount ); |
|
203 CleanupStack::PushL( arrayOfItems ); |
|
204 |
|
205 |
|
206 // go through the ssid's in aInfoArray and append them to the array |
|
207 TInt wlanArrayCount( aInfoArray.Count() ); |
|
208 TWsfWlanInfo* wlanInfo( NULL ); |
|
209 TWsfWlanInfo* connectedWlan( NULL ); |
|
210 for ( TInt loopCounter( 0 ); loopCounter < wlanArrayCount; ++loopCounter ) |
|
211 { |
|
212 wlanInfo = aInfoArray.At( loopCounter ); |
|
213 |
|
214 // formerly (custfav or hidden -> does not appear in the list): |
|
215 // if ( wlanInfo->BrandId() || wlanInfo->Hidden() ) |
|
216 // instead now (connected -> does not appear in the list): |
|
217 if ( wlanInfo->Connected() ) |
|
218 { |
|
219 connectedWlan = wlanInfo; |
|
220 continue; |
|
221 } |
|
222 HBufC* ssid = wlanInfo->GetSsidAsUnicodeLC(); |
|
223 arrayOfItems->AppendL( *ssid ); |
|
224 CleanupStack::PopAndDestroy( ssid ); |
|
225 } |
|
226 |
|
227 // simple alphabetical sort |
|
228 arrayOfItems->Sort(); |
|
229 |
|
230 LOG_WRITE( "items added, list sorted" ); |
|
231 |
|
232 |
|
233 // now insert the already selected items onto the top |
|
234 CArrayFix<TInt> *selectedItems = new (ELeave) CArrayFixFlat<TInt>( |
|
235 arrayItemCount ); |
|
236 CleanupStack::PushL( selectedItems ); |
|
237 |
|
238 HBufC* connectedSsid( NULL ); |
|
239 if ( connectedWlan ) |
|
240 { |
|
241 connectedSsid = connectedWlan->GetSsidAsUnicodeLC(); |
|
242 } |
|
243 |
|
244 TBool connectedBlacklisted( EFalse ); |
|
245 |
|
246 TInt blackListLength( iBlackListSsids->Count() ); |
|
247 TInt index( 0 ); |
|
248 for ( TInt loopCounter( 0 ); loopCounter < blackListLength; ++loopCounter ) |
|
249 { |
|
250 HBufC* ssidUnicode = TWsfWlanInfo::GetSsidAsUnicodeLC( |
|
251 iBlackListSsids->MdcaPoint( loopCounter ) ); |
|
252 |
|
253 if ( !connectedWlan || ssidUnicode->Compare( *connectedSsid ) ) |
|
254 { |
|
255 // only add the ssid to the list if it is not connected right now |
|
256 arrayOfItems->InsertL( index, *ssidUnicode ); |
|
257 // these are already selected |
|
258 selectedItems->AppendL( index ); |
|
259 ++index; |
|
260 } |
|
261 else if ( connectedWlan && !ssidUnicode->Compare( *connectedSsid ) ) |
|
262 { |
|
263 connectedBlacklisted = ETrue; |
|
264 } |
|
265 |
|
266 |
|
267 CleanupStack::PopAndDestroy( ssidUnicode ); |
|
268 } |
|
269 |
|
270 if ( !arrayOfItems->Count() ) |
|
271 { |
|
272 // there's nothing to edit |
|
273 // just return before showing edit dialog |
|
274 if ( connectedWlan ) |
|
275 { |
|
276 CleanupStack::PopAndDestroy( connectedSsid ); |
|
277 } |
|
278 |
|
279 CleanupStack::PopAndDestroy( selectedItems ); |
|
280 CleanupStack::PopAndDestroy( arrayOfItems ); |
|
281 return; |
|
282 } |
|
283 |
|
284 LOG_WRITE( "creating the dialog" ); |
|
285 CWsfWlanSsidSelectionDlg2* dlg = CWsfWlanSsidSelectionDlg2::NewL( |
|
286 *arrayOfItems, *selectedItems ); |
|
287 dlg->PrepareLC( R_QTN_PREFERRED_FILTER_SELECTION_DIALOG2 ); |
|
288 |
|
289 LOG_WRITE( "launching the dialog" ); |
|
290 if ( dlg->RunLD() ) |
|
291 { |
|
292 LOG_WRITE( "dialog closed" ); |
|
293 // go throught the list of selected items... and store them... |
|
294 iBlackListSsids->Reset(); |
|
295 |
|
296 TInt selectedCount( selectedItems->Count() ); |
|
297 |
|
298 for ( TInt loopCounter( 0 ); loopCounter < selectedCount; ++loopCounter ) |
|
299 { |
|
300 TPtrC ssid = arrayOfItems->MdcaPoint( selectedItems->At( |
|
301 loopCounter ) ); |
|
302 HBufC8* ssidUtf8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
303 ssid ); |
|
304 CleanupStack::PushL( ssidUtf8 ); |
|
305 iBlackListSsids->AppendL( *ssidUtf8 ); |
|
306 CleanupStack::PopAndDestroy( ssidUtf8 ); |
|
307 } |
|
308 |
|
309 if ( connectedBlacklisted ) |
|
310 { |
|
311 HBufC8* ssidUtf8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
312 *connectedSsid ); |
|
313 CleanupStack::PushL( ssidUtf8 ); |
|
314 iBlackListSsids->AppendL( *ssidUtf8 ); |
|
315 CleanupStack::PopAndDestroy( ssidUtf8 ); |
|
316 } |
|
317 |
|
318 iBlackListSsids->Sort(); |
|
319 SaveDefsL(); |
|
320 } |
|
321 |
|
322 if ( connectedWlan ) |
|
323 { |
|
324 CleanupStack::PopAndDestroy( connectedSsid ); |
|
325 } |
|
326 |
|
327 CleanupStack::PopAndDestroy( selectedItems ); |
|
328 CleanupStack::PopAndDestroy( arrayOfItems ); |
|
329 } |
|
330 |
|
331 |
|
332 // ---------------------------------------------------------------------------- |
|
333 // CWsfWlanInfoSortingBlackList::ReadFilterDefsL |
|
334 // ---------------------------------------------------------------------------- |
|
335 // |
|
336 void CWsfWlanInfoSortingBlackList::ReadFilterDefsL() |
|
337 { |
|
338 RestoreDefsL(); |
|
339 } |
|
340 |
|
341 |
|
342 // ---------------------------------------------------------------------------- |
|
343 // CWsfWlanInfoSortingBlackList::SaveDefsL |
|
344 // ---------------------------------------------------------------------------- |
|
345 // |
|
346 void CWsfWlanInfoSortingBlackList::SaveDefsL() |
|
347 { |
|
348 LOG_ENTERFN( "CWsfWlanInfoSortingBlackList::SaveDefsL" ); |
|
349 |
|
350 // clear the db-table |
|
351 if ( iBlackListSsidTable.FirstL() != EFalse ) |
|
352 { |
|
353 do |
|
354 { |
|
355 iBlackListSsidTable.DeleteL(); |
|
356 } |
|
357 while ( iBlackListSsidTable.NextL() ); |
|
358 } |
|
359 |
|
360 // and add the iBlackListSsids contents there.... |
|
361 TInt ssidCount( iBlackListSsids->Count() ); |
|
362 |
|
363 if ( ssidCount ) |
|
364 { |
|
365 // there are items |
|
366 CDbColSet* colSet = iBlackListSsidTable.ColSetL(); |
|
367 CleanupStack::PushL( colSet ); |
|
368 TDbColNo ssidColumnNumber = colSet->ColNo( |
|
369 KBlackListTableIdColumnName ); |
|
370 |
|
371 for ( TInt i( 0 ); i < ssidCount; ++i ) |
|
372 { |
|
373 iBlackListSsidTable.InsertL(); |
|
374 iBlackListSsidTable.SetColL( ssidColumnNumber, |
|
375 iBlackListSsids->MdcaPoint( i ) ); |
|
376 iBlackListSsidTable.PutL(); |
|
377 } |
|
378 CleanupStack::PopAndDestroy( colSet ); |
|
379 } |
|
380 |
|
381 } |
|
382 |
|
383 |
|
384 // ---------------------------------------------------------------------------- |
|
385 // CWsfWlanInfoSortingBlackList::RestoreDefsL |
|
386 // ---------------------------------------------------------------------------- |
|
387 // |
|
388 void CWsfWlanInfoSortingBlackList::RestoreDefsL() |
|
389 { |
|
390 LOG_ENTERFN( "CWsfWlanInfoSortingBlackList::RestoreDefsL" ); |
|
391 iBlackListSsids->Reset(); |
|
392 iBlackListSsidTable.Reset(); |
|
393 // go through the table and fill the ssid array... |
|
394 if ( iBlackListSsidTable.FirstL() ) |
|
395 { |
|
396 CDbColSet* colSet = iBlackListSsidTable.ColSetL(); |
|
397 CleanupStack::PushL( colSet ); |
|
398 TDbColNo ssidColumnNumber = colSet->ColNo( |
|
399 KBlackListTableIdColumnName ); |
|
400 do |
|
401 { |
|
402 iBlackListSsidTable.GetL(); |
|
403 iBlackListSsids->AppendL( iBlackListSsidTable.ColDes8( |
|
404 ssidColumnNumber ) ); |
|
405 } |
|
406 while ( iBlackListSsidTable.NextL() ); |
|
407 |
|
408 CleanupStack::PopAndDestroy( colSet ); |
|
409 // sort the array... |
|
410 iBlackListSsids->Sort(); |
|
411 |
|
412 } |
|
413 } |
|
414 |
|
415 |
|
416 // ---------------------------------------------------------------------------- |
|
417 // CWsfWlanInfoSortingBlackList::CheckTableL |
|
418 // ---------------------------------------------------------------------------- |
|
419 // |
|
420 void CWsfWlanInfoSortingBlackList::CheckTableL() |
|
421 { |
|
422 LOG_ENTERFN( "CWsfWlanInfoSortingBlackList::CheckTableL" ); |
|
423 |
|
424 TInt tableStatus = iBlackListSsidTable.Open( *iDefsDb, |
|
425 KBlackListTableName ); |
|
426 if ( tableStatus == KErrNotFound ) |
|
427 { |
|
428 // the table does not exist... create it |
|
429 CDbColSet *ssidTableColumnSet = CDbColSet::NewLC(); |
|
430 |
|
431 ssidTableColumnSet->AddL( TDbCol( KBlackListTableIdColumnName, |
|
432 EDbColText8 ) ); |
|
433 |
|
434 iDefsDb->Begin(); |
|
435 User::LeaveIfError( iDefsDb->CreateTable( KBlackListTableName, |
|
436 *ssidTableColumnSet ) ); |
|
437 iDefsDb->Commit(); |
|
438 |
|
439 CleanupStack::PopAndDestroy( ssidTableColumnSet ); |
|
440 } |
|
441 |
|
442 if ( tableStatus != KErrNone ) |
|
443 { |
|
444 User::LeaveIfError( iBlackListSsidTable.Open( *iDefsDb, |
|
445 KBlackListTableName ) ); |
|
446 } |
|
447 } |
|
448 |
|
449 |
|
450 |
|
451 |
|