|
1 /* |
|
2 * Copyright (c) 2006 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: Wizard used for adding connection methods |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <AknWaitDialog.h> |
|
19 #include <cmmanager.rsg> |
|
20 #include <StringLoader.h> |
|
21 #include <avkon.hrh> |
|
22 #include "cmwizard.h" |
|
23 #include <cmcommonconstants.h> |
|
24 #include <cmcommonui.h> |
|
25 #include "cmdestinationimpl.h" |
|
26 #include "cmlogger.h" |
|
27 #include "cmmanagerimpl.h" |
|
28 #include <cmpluginbaseeng.h> |
|
29 #include <cmpluginbase.h> |
|
30 #include "selectdestinationdlg.h" |
|
31 |
|
32 using namespace CMManager; |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CCmWizard::CCmWizard |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CCmWizard::CCmWizard( CCmManagerImpl& aCmManager ) |
|
39 : iCmManager( aCmManager ) |
|
40 { |
|
41 CLOG_CREATE; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CCmWizard::~CCmWizard |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CCmWizard::~CCmWizard() |
|
49 { |
|
50 if( iCheckConnDlg ) |
|
51 { |
|
52 delete iCheckConnDlg; |
|
53 } |
|
54 CLOG_CLOSE; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CCmWizard::CreateConnectionMethodL |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 TInt CCmWizard::CreateConnectionMethodL |
|
62 ( CCmDestinationImpl* aTargetDestination ) |
|
63 { |
|
64 TInt index( KErrCancel ); |
|
65 |
|
66 LOGGER_ENTERFN( "CCmWizard::CreateConnectionMethodL" ); |
|
67 TBool wizardCancelled = EFalse; // indicates if the wizard has got cancelled |
|
68 TUint32 bearerType = 0; |
|
69 TBool manuallyConfigure ( EFalse ); |
|
70 |
|
71 if ( AutoCheckForCmsL() ) |
|
72 { |
|
73 RArray<TUint32> availableBearers( KCmArrayMediumGranularity ); |
|
74 CleanupClosePushL( availableBearers ); |
|
75 |
|
76 CLOG_WRITE( "CCmWizard::Starting CheckForCms" ); |
|
77 CheckForCmsL( availableBearers ); |
|
78 |
|
79 // If user has cancelled the dialog, then (s)he wanted to terminate |
|
80 // the whole procedure. |
|
81 if ( iCheckConnDlgCancelled ) |
|
82 { |
|
83 CLOG_WRITE( "CCmWizard::wizardCancelled" ); |
|
84 wizardCancelled = ETrue; |
|
85 } |
|
86 else |
|
87 { |
|
88 // If there's coverage for at least one of the bearer types |
|
89 if ( availableBearers.Count() ) |
|
90 { |
|
91 CLOG_WRITE_1( "CCmWizard::CreateConnectionMethodL av. bearers: [%d]", |
|
92 availableBearers.Count() ); |
|
93 // Show available conn methods in a list from which user has to |
|
94 // select. |
|
95 bearerType = TCmCommonUi::ShowAvailableMethodsL |
|
96 ( availableBearers, |
|
97 iCmManager ); |
|
98 if ( !bearerType ) |
|
99 { |
|
100 wizardCancelled = ETrue; |
|
101 CLOG_WRITE( "CCmWizard::wizardCancelled" ); |
|
102 } |
|
103 } |
|
104 else // no coverage at all |
|
105 { |
|
106 CLOG_WRITE( "CCmWizard::CreateConnectionMethodL no available bearers, manual selection." ); |
|
107 // "Do you want to configure conn methods manually?" |
|
108 if ( ManualCheckForCmsL() ) |
|
109 { |
|
110 // Yes, select a bearer manually |
|
111 bearerType = TCmCommonUi::SelectBearerL( iCmManager ); |
|
112 if ( !bearerType ) |
|
113 { |
|
114 // Cancelled dialog |
|
115 wizardCancelled = ETrue; |
|
116 } |
|
117 else |
|
118 { |
|
119 manuallyConfigure = ETrue; |
|
120 } |
|
121 } |
|
122 else |
|
123 { |
|
124 // No, user has cancelled the dialog |
|
125 wizardCancelled = ETrue; |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 CleanupStack::PopAndDestroy( &availableBearers ); |
|
131 } |
|
132 else // "No" for checking conn methods automatically |
|
133 { |
|
134 CLOG_WRITE( "CCmWizard::AutoCheckForCmsL returned FALSE" ); |
|
135 // Manual bearer selection |
|
136 bearerType = TCmCommonUi::SelectBearerL( iCmManager ); |
|
137 if ( !bearerType ) |
|
138 { |
|
139 // Cancelled dialog |
|
140 wizardCancelled = ETrue; |
|
141 } |
|
142 else |
|
143 { |
|
144 manuallyConfigure = ETrue; |
|
145 } |
|
146 } |
|
147 |
|
148 if ( !wizardCancelled ) |
|
149 { |
|
150 CCmPluginBase* plugin = iCmManager.CreateConnectionMethodL( |
|
151 bearerType, aTargetDestination ); |
|
152 CleanupStack::PushL( plugin ); |
|
153 |
|
154 CLOG_WRITE( "CCmWizard::CreateConnectionMethodL plugin created, starting initialization" ); |
|
155 |
|
156 // Bearer-specific UI-supported initialization is done by plug-ins |
|
157 TBool ret = EFalse; |
|
158 TRAPD(err, ret = plugin->InitializeWithUiL( manuallyConfigure ) ); |
|
159 if ( err == KErrNone && ret ) |
|
160 { |
|
161 CCmDestinationImpl* targetDest = aTargetDestination; |
|
162 // If target destination is not yet specified... |
|
163 if ( !aTargetDestination ) |
|
164 { |
|
165 // For virtual bearers: eliminated the underlying destination |
|
166 // from the destination selection dialog |
|
167 TUint32 targetDestId( 0 ); |
|
168 |
|
169 RArray<TUint32> destArray( iCmManager.DestinationCountL() ); |
|
170 CleanupClosePushL( destArray ); |
|
171 iCmManager.AllDestinationsL( destArray ); |
|
172 // now do the filtering |
|
173 plugin->FilterPossibleParentsL( destArray ); |
|
174 |
|
175 if ( !destArray.Count() ) |
|
176 { |
|
177 // there are no destinations to put the CM into |
|
178 TCmCommonUi::ShowNoteL( R_CMWIZARD_NO_VPN_STACKING, |
|
179 TCmCommonUi::ECmErrorNote ); |
|
180 |
|
181 CleanupStack::PopAndDestroy( &destArray ); |
|
182 CleanupStack::PopAndDestroy( plugin ); |
|
183 |
|
184 CLOG_WRITE_1( "CCmWizard::CreateConnectionMethodL no valid parents after filtering, index: [%d]", index ); |
|
185 return index; |
|
186 } |
|
187 |
|
188 // ... then let the user select a destination. |
|
189 CSelectDestinationDlg* dlg = CSelectDestinationDlg::NewL( targetDestId, |
|
190 iCmManager, |
|
191 &destArray ); |
|
192 dlg->ExecuteLD( R_CMMANAGER_LIST_QUERY_WITH_MSGBOX ); |
|
193 |
|
194 CleanupStack::PopAndDestroy( &destArray ); |
|
195 |
|
196 if ( targetDestId ) |
|
197 { |
|
198 // CREATE an object based on an ID. |
|
199 targetDest = iCmManager.DestinationL( targetDestId ); |
|
200 CleanupStack::PushL( targetDest ); |
|
201 } |
|
202 } |
|
203 |
|
204 CLOG_WRITE_1( "CCmWizard::CreateConnectionMethodL target dest: [0x%x]", |
|
205 targetDest ); |
|
206 |
|
207 // If the target destination is still unspecified at this point, |
|
208 // then the only reason could be that the previous dialog was |
|
209 // cancelled ==> do something only if we have the target |
|
210 // destination |
|
211 if ( targetDest ) |
|
212 { |
|
213 plugin->UpdateL(); // commit changes |
|
214 |
|
215 index = iCmManager.CopyConnectionMethodL( *targetDest, |
|
216 *plugin ); |
|
217 |
|
218 RArray<TUint32> additionalCms; |
|
219 CleanupClosePushL (additionalCms); |
|
220 plugin->GetAdditionalUids( additionalCms ); |
|
221 if ( additionalCms.Count() ) |
|
222 {//if there are additional cms created, move them to the target destination as well |
|
223 for ( TInt i = 0; i<additionalCms.Count(); i++) |
|
224 { |
|
225 CCmPluginBase* cm = iCmManager.GetConnectionMethodL( additionalCms[i] ); |
|
226 CleanupStack::PushL(cm); |
|
227 iCmManager.CopyConnectionMethodL( *targetDest, |
|
228 *cm ); |
|
229 CleanupStack::PopAndDestroy( cm ); |
|
230 } |
|
231 } |
|
232 CleanupStack::PopAndDestroy( &additionalCms ); |
|
233 |
|
234 HBufC* destName = targetDest->NameLC(); |
|
235 |
|
236 CleanupStack::PopAndDestroy( destName ); |
|
237 |
|
238 // Here's a tricky one: if 'aTargetDestination' was NULL, then |
|
239 // I had to create 'targetDest' myself (with |
|
240 // iCmManager.DestinationL), consequently I have to |
|
241 // free it up, too. |
|
242 if ( !aTargetDestination ) |
|
243 { |
|
244 CleanupStack::PopAndDestroy( targetDest ); |
|
245 } |
|
246 } |
|
247 else // Wi-Fi may have set IAP in database. So, delete it. |
|
248 { |
|
249 CLOG_WRITE( "CCmWizard::CreateConnectionMethodL, handling cancel add destination -- start" ); |
|
250 RArray<TUint32> additionalCms; |
|
251 CleanupClosePushL (additionalCms); |
|
252 |
|
253 plugin->GetAdditionalUids( additionalCms ); |
|
254 CLOG_WRITE_1( "CCmWizard::CreateConnectionMethodL, addtionalCms count [%d]", additionalCms.Count() ); |
|
255 for ( TInt i = 0; i<additionalCms.Count(); i++) |
|
256 { |
|
257 CCmPluginBase* cm = iCmManager.GetConnectionMethodL( additionalCms[i] ); |
|
258 CleanupStack::PushL(cm); |
|
259 cm->DeleteL( ETrue ); |
|
260 CleanupStack::PopAndDestroy( cm ); |
|
261 } |
|
262 // If plugin hasn't got Iap Id, it's "normal" CM which has not been saved |
|
263 // into CommsDat yet. Otherwise it's Wifi CM and has to be deleted by using |
|
264 // DeleteL() method. |
|
265 if( plugin->GetIntAttributeL( ECmIapId ) ) |
|
266 { |
|
267 plugin->DeleteL( ETrue ); |
|
268 } |
|
269 |
|
270 CleanupStack::PopAndDestroy( &additionalCms ); |
|
271 CLOG_WRITE( "CCmWizard::CreateConnectionMethodL, handling cancel add destination -- end" ); |
|
272 } |
|
273 } |
|
274 CleanupStack::PopAndDestroy( plugin ); |
|
275 } |
|
276 |
|
277 return index; |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // CCmWizard::DialogDismissedL |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void CCmWizard::DialogDismissedL( TInt aButtonId ) |
|
285 { |
|
286 LOGGER_ENTERFN( "CCmWizard::DialogDismissedL" ); |
|
287 |
|
288 CLOG_WRITE_1( "CCmWizard::DialogDismissedL, aButtonId: [%d]", aButtonId ); |
|
289 if ( aButtonId == EAknSoftkeyCancel ) |
|
290 { |
|
291 if ( iCheckConnDlg != NULL ) |
|
292 { |
|
293 CLOG_WRITE( "CCmWizard::CheckConnDlg is not NULL" ); |
|
294 iCheckConnDlgCancelled = ETrue; |
|
295 } |
|
296 } |
|
297 |
|
298 if ( iWait.IsStarted() ) |
|
299 { |
|
300 iWait.AsyncStop(); |
|
301 } |
|
302 iCheckConnDlg = NULL; |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // CCmWizard::AutoCheckForCmsL |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 TBool CCmWizard::AutoCheckForCmsL() const |
|
310 { |
|
311 LOGGER_ENTERFN( "CCmWizard::AutoCheckForCmsL" ); |
|
312 // Automatically check for available conn methods? |
|
313 TInt retval = |
|
314 TCmCommonUi::ShowConfirmationQueryL( R_CMWIZARD_AUTOMATIC_CHECK ); |
|
315 |
|
316 return ( retval == EAknSoftkeyYes || retval == EAknSoftkeyOk ) |
|
317 ? ETrue : EFalse; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CCmWizard::ManualCheckForCmsL |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 TBool CCmWizard::ManualCheckForCmsL() const |
|
325 { |
|
326 LOGGER_ENTERFN( "CCmWizard::ManualCheckForCmsL" ); |
|
327 // Manually configure CMs? |
|
328 TInt retval = |
|
329 TCmCommonUi::ShowConfirmationQueryL( |
|
330 R_CMWIZARD_MANUAL_CONFIGURATION ); |
|
331 |
|
332 return ( retval == EAknSoftkeyYes || retval == EAknSoftkeyOk ) |
|
333 ? ETrue : EFalse; |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CCmWizard::CheckForCmsL |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CCmWizard::CheckForCmsL( RArray<TUint32>& aCoverageArray ) |
|
341 { |
|
342 LOGGER_ENTERFN( "CCmWizard::CheckForCmsL" ); |
|
343 // Show a wait dialog |
|
344 iCheckConnDlgCancelled = FALSE; |
|
345 iCheckConnDlg = new (ELeave) CAknWaitDialog( |
|
346 ( REINTERPRET_CAST( CEikDialog**, &iCheckConnDlg )) ); |
|
347 |
|
348 iCheckConnDlg->SetCallback( this ); |
|
349 |
|
350 iCheckConnDlg->SetTone( CAknNoteDialog::EConfirmationTone ); |
|
351 |
|
352 HBufC* text = StringLoader::LoadLC( R_CMWIZARD_CHECKING_METHODS ); |
|
353 iCheckConnDlg->SetTextL( *text ); |
|
354 CleanupStack::PopAndDestroy( text ); |
|
355 |
|
356 iCheckConnDlg->ExecuteLD( R_CMMANAGER_WAIT_NOTE ); |
|
357 |
|
358 RArray<TUint32> bearers( KCmArrayMediumGranularity ); |
|
359 CleanupClosePushL( bearers ); |
|
360 |
|
361 iCmManager.SupportedBearersL( bearers ); |
|
362 |
|
363 for ( TInt i = 0; i < bearers.Count() && !iCheckConnDlgCancelled; i++ ) |
|
364 { |
|
365 TBool avail( EFalse ); |
|
366 |
|
367 TRAPD( err, avail = iCmManager.GetBearerInfoBoolL( bearers[i], ECmCoverage ) ); |
|
368 |
|
369 CLOG_WRITE_2( "CCmWizard::CheckForCms, bearer [%d] coverage error [%d]", i, err ); |
|
370 |
|
371 if( err ) |
|
372 { |
|
373 continue; |
|
374 } |
|
375 |
|
376 |
|
377 if ( avail && |
|
378 iCmManager.GetBearerInfoBoolL( bearers[i], ECmAddToAvailableList ) ) |
|
379 { |
|
380 aCoverageArray.AppendL( bearers[i] ); |
|
381 CLOG_WRITE_1( "CCmWizard::CheckForCms, bearer [%d] appended", i ); |
|
382 } |
|
383 } |
|
384 |
|
385 CleanupStack::PopAndDestroy( &bearers ); |
|
386 |
|
387 // Dismiss wait dialog |
|
388 if( !iCheckConnDlgCancelled ) |
|
389 { |
|
390 CLOG_WRITE( "CCmWizard::CheckForCms, cancelling wait dlg" ); |
|
391 iCheckConnDlg->ProcessFinishedL(); |
|
392 |
|
393 // Wait here in case wait note has not yet been dismissed. |
|
394 // This happens in hw when Themes/effects is enabled. |
|
395 if ( iCheckConnDlg != NULL ) |
|
396 { |
|
397 iWait.Start(); |
|
398 } |
|
399 CLOG_WRITE( "CCmWizard::CheckForCms, wait dialog deleted" ); |
|
400 } |
|
401 else |
|
402 { |
|
403 CLOG_WRITE( "CCmWizard::CheckForCms, wait dlg was already cancelled" ); |
|
404 } |
|
405 |
|
406 // Set the member to NULL every case |
|
407 iCheckConnDlg = NULL; |
|
408 } |
|
409 |
|
410 |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // CCmWizard::FindTargetDestinationL |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 TUint32 CCmWizard::FindTargetDestinationL( CCmPluginBase* aPlugin ) |
|
417 { |
|
418 LOGGER_ENTERFN( "CCmWizard::FindTargetDestinationL" ); |
|
419 |
|
420 // Tries to read the destination id |
|
421 TUint32 targetDestId (0); |
|
422 TRAPD( err, targetDestId = |
|
423 aPlugin->GetIntAttributeL( ECmNextLayerSNAPId ) ); |
|
424 |
|
425 // only supported by virtual bearers, don't leave |
|
426 if ( err && err != KErrNotSupported ) |
|
427 { |
|
428 User::Leave( err ); |
|
429 } |
|
430 |
|
431 // targetDestId == 0 means that not destination but a connection |
|
432 // method have been selected |
|
433 if ( targetDestId == 0 ) |
|
434 { |
|
435 // Now the destination containing the connection method |
|
436 // should be obtained |
|
437 TUint32 targetCmId (0); |
|
438 TRAPD( err, targetCmId = |
|
439 aPlugin->GetIntAttributeL( ECmNextLayerIapId ) ); |
|
440 |
|
441 // only supported by virtual bearers, don't leave |
|
442 if ( err && err != KErrNotSupported ) |
|
443 { |
|
444 User::Leave( err ); |
|
445 } |
|
446 |
|
447 targetDestId = FindParentDestinationL( targetCmId ); |
|
448 } |
|
449 |
|
450 return targetDestId; |
|
451 } |
|
452 |
|
453 // --------------------------------------------------------------------------- |
|
454 // CCmWizard::FindParentDestinationL |
|
455 // --------------------------------------------------------------------------- |
|
456 // |
|
457 TUint32 CCmWizard::FindParentDestinationL( TUint32 aCmId ) |
|
458 { |
|
459 LOGGER_ENTERFN( "CCmWizard::FindParentDestinationL" ); |
|
460 |
|
461 TBool found = EFalse; |
|
462 TUint32 targetDestId (0); |
|
463 |
|
464 RArray<TUint32> destinations; |
|
465 |
|
466 iCmManager.AllDestinationsL( destinations ); |
|
467 CleanupClosePushL( destinations ); |
|
468 |
|
469 RArray<TUint32> cms; |
|
470 |
|
471 for ( TInt i = 0; i < destinations.Count() && !found; i++ ) |
|
472 { |
|
473 CCmDestinationImpl* dest = |
|
474 iCmManager.DestinationL( destinations[i] ); |
|
475 CleanupStack::PushL( dest ); |
|
476 dest->ConnectMethodIdArrayL( cms ); |
|
477 CleanupClosePushL( cms ); |
|
478 |
|
479 for ( TInt j = 0; j < cms.Count() && !found; j++ ) |
|
480 { |
|
481 if( cms[j] == aCmId) |
|
482 { |
|
483 targetDestId = destinations[i]; |
|
484 found = ETrue; |
|
485 } |
|
486 } |
|
487 CleanupStack::PopAndDestroy( &cms ); |
|
488 CleanupStack::PopAndDestroy( dest ); |
|
489 } |
|
490 |
|
491 CleanupStack::PopAndDestroy( &destinations ); |
|
492 |
|
493 return targetDestId; |
|
494 } |