|
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 TCmCommonUi::ShowNoteL( R_CMWIZARD_NEW_METHOD_ADDED, |
|
237 *destName, |
|
238 TCmCommonUi::ECmOkNote ); |
|
239 |
|
240 CleanupStack::PopAndDestroy( destName ); |
|
241 |
|
242 // Here's a tricky one: if 'aTargetDestination' was NULL, then |
|
243 // I had to create 'targetDest' myself (with |
|
244 // iCmManager.DestinationL), consequently I have to |
|
245 // free it up, too. |
|
246 if ( !aTargetDestination ) |
|
247 { |
|
248 CleanupStack::PopAndDestroy( targetDest ); |
|
249 } |
|
250 } |
|
251 else // Wi-Fi may have set IAP in database. So, delete it. |
|
252 { |
|
253 CLOG_WRITE( "CCmWizard::CreateConnectionMethodL, handling cancel add destination -- start" ); |
|
254 RArray<TUint32> additionalCms; |
|
255 CleanupClosePushL (additionalCms); |
|
256 |
|
257 plugin->GetAdditionalUids( additionalCms ); |
|
258 CLOG_WRITE_1( "CCmWizard::CreateConnectionMethodL, addtionalCms count [%d]", additionalCms.Count() ); |
|
259 for ( TInt i = 0; i<additionalCms.Count(); i++) |
|
260 { |
|
261 CCmPluginBase* cm = iCmManager.GetConnectionMethodL( additionalCms[i] ); |
|
262 CleanupStack::PushL(cm); |
|
263 cm->DeleteL( ETrue ); |
|
264 CleanupStack::PopAndDestroy( cm ); |
|
265 } |
|
266 // If plugin hasn't got Iap Id, it's "normal" CM which has not been saved |
|
267 // into CommsDat yet. Otherwise it's Wifi CM and has to be deleted by using |
|
268 // DeleteL() method. |
|
269 if( plugin->GetIntAttributeL( ECmIapId ) ) |
|
270 { |
|
271 plugin->DeleteL( ETrue ); |
|
272 } |
|
273 |
|
274 CleanupStack::PopAndDestroy( &additionalCms ); |
|
275 CLOG_WRITE( "CCmWizard::CreateConnectionMethodL, handling cancel add destination -- end" ); |
|
276 } |
|
277 } |
|
278 CleanupStack::PopAndDestroy( plugin ); |
|
279 } |
|
280 |
|
281 return index; |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // CCmWizard::DialogDismissedL |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 void CCmWizard::DialogDismissedL( TInt aButtonId ) |
|
289 { |
|
290 LOGGER_ENTERFN( "CCmWizard::DialogDismissedL" ); |
|
291 |
|
292 CLOG_WRITE_1( "CCmWizard::DialogDismissedL, aButtonId: [%d]", aButtonId ); |
|
293 if ( aButtonId == EAknSoftkeyCancel ) |
|
294 { |
|
295 if ( iCheckConnDlg != NULL ) |
|
296 { |
|
297 CLOG_WRITE( "CCmWizard::CheckConnDlg is not NULL" ); |
|
298 iCheckConnDlgCancelled = ETrue; |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // CCmWizard::AutoCheckForCmsL |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 TBool CCmWizard::AutoCheckForCmsL() const |
|
308 { |
|
309 LOGGER_ENTERFN( "CCmWizard::AutoCheckForCmsL" ); |
|
310 // Automatically check for available conn methods? |
|
311 TInt retval = |
|
312 TCmCommonUi::ShowConfirmationQueryL( R_CMWIZARD_AUTOMATIC_CHECK ); |
|
313 |
|
314 return ( retval == EAknSoftkeyYes || retval == EAknSoftkeyOk ) |
|
315 ? ETrue : EFalse; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CCmWizard::ManualCheckForCmsL |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 TBool CCmWizard::ManualCheckForCmsL() const |
|
323 { |
|
324 LOGGER_ENTERFN( "CCmWizard::ManualCheckForCmsL" ); |
|
325 // Manually configure CMs? |
|
326 TInt retval = |
|
327 TCmCommonUi::ShowConfirmationQueryL( |
|
328 R_CMWIZARD_MANUAL_CONFIGURATION ); |
|
329 |
|
330 return ( retval == EAknSoftkeyYes || retval == EAknSoftkeyOk ) |
|
331 ? ETrue : EFalse; |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // CCmWizard::CheckForCmsL |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 void CCmWizard::CheckForCmsL( RArray<TUint32>& aCoverageArray ) |
|
339 { |
|
340 LOGGER_ENTERFN( "CCmWizard::CheckForCmsL" ); |
|
341 // Show a wait dialog |
|
342 iCheckConnDlgCancelled = FALSE; |
|
343 iCheckConnDlg = new (ELeave) CAknWaitDialog( |
|
344 ( REINTERPRET_CAST( CEikDialog**, &iCheckConnDlg )) ); |
|
345 |
|
346 iCheckConnDlg->SetCallback( this ); |
|
347 |
|
348 iCheckConnDlg->SetTone( CAknNoteDialog::EConfirmationTone ); |
|
349 |
|
350 HBufC* text = StringLoader::LoadLC( R_CMWIZARD_CHECKING_METHODS ); |
|
351 iCheckConnDlg->SetTextL( *text ); |
|
352 CleanupStack::PopAndDestroy( text ); |
|
353 |
|
354 iCheckConnDlg->ExecuteLD( R_CMMANAGER_WAIT_NOTE ); |
|
355 |
|
356 RArray<TUint32> bearers( KCmArrayMediumGranularity ); |
|
357 CleanupClosePushL( bearers ); |
|
358 |
|
359 iCmManager.SupportedBearersL( bearers ); |
|
360 |
|
361 for ( TInt i = 0; i < bearers.Count() && !iCheckConnDlgCancelled; i++ ) |
|
362 { |
|
363 TBool avail( EFalse ); |
|
364 |
|
365 TRAPD( err, avail = iCmManager.GetBearerInfoBoolL( bearers[i], ECmCoverage ) ); |
|
366 |
|
367 CLOG_WRITE_2( "CCmWizard::CheckForCms, bearer [%d] coverage error [%d]", i, err ); |
|
368 |
|
369 if( err ) |
|
370 { |
|
371 continue; |
|
372 } |
|
373 |
|
374 |
|
375 if ( avail && |
|
376 iCmManager.GetBearerInfoBoolL( bearers[i], ECmAddToAvailableList ) ) |
|
377 { |
|
378 aCoverageArray.AppendL( bearers[i] ); |
|
379 CLOG_WRITE_1( "CCmWizard::CheckForCms, bearer [%d] appended", i ); |
|
380 } |
|
381 } |
|
382 |
|
383 CleanupStack::PopAndDestroy( &bearers ); |
|
384 |
|
385 // Dismiss wait dialog |
|
386 if( !iCheckConnDlgCancelled ) |
|
387 { |
|
388 CLOG_WRITE( "CCmWizard::CheckForCms, cancelling wait dlg" ); |
|
389 iCheckConnDlg->SetCallback( NULL ); |
|
390 iCheckConnDlg->ProcessFinishedL(); |
|
391 CLOG_WRITE( "CCmWizard::CheckForCms, wait dialog deleted" ); |
|
392 } |
|
393 else |
|
394 { |
|
395 CLOG_WRITE( "CCmWizard::CheckForCms, wait dlg was already cancelled" ); |
|
396 } |
|
397 |
|
398 |
|
399 // Set the member to NULL every case |
|
400 iCheckConnDlg = NULL; |
|
401 } |
|
402 |
|
403 |
|
404 |
|
405 // --------------------------------------------------------------------------- |
|
406 // CCmWizard::FindTargetDestinationL |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 TUint32 CCmWizard::FindTargetDestinationL( CCmPluginBase* aPlugin ) |
|
410 { |
|
411 LOGGER_ENTERFN( "CCmWizard::FindTargetDestinationL" ); |
|
412 |
|
413 // Tries to read the destination id |
|
414 TUint32 targetDestId (0); |
|
415 TRAPD( err, targetDestId = |
|
416 aPlugin->GetIntAttributeL( ECmNextLayerSNAPId ) ); |
|
417 |
|
418 // only supported by virtual bearers, don't leave |
|
419 if ( err && err != KErrNotSupported ) |
|
420 { |
|
421 User::Leave( err ); |
|
422 } |
|
423 |
|
424 // targetDestId == 0 means that not destination but a connection |
|
425 // method have been selected |
|
426 if ( targetDestId == 0 ) |
|
427 { |
|
428 // Now the destination containing the connection method |
|
429 // should be obtained |
|
430 TUint32 targetCmId (0); |
|
431 TRAPD( err, targetCmId = |
|
432 aPlugin->GetIntAttributeL( ECmNextLayerIapId ) ); |
|
433 |
|
434 // only supported by virtual bearers, don't leave |
|
435 if ( err && err != KErrNotSupported ) |
|
436 { |
|
437 User::Leave( err ); |
|
438 } |
|
439 |
|
440 targetDestId = FindParentDestinationL( targetCmId ); |
|
441 } |
|
442 |
|
443 return targetDestId; |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // CCmWizard::FindParentDestinationL |
|
448 // --------------------------------------------------------------------------- |
|
449 // |
|
450 TUint32 CCmWizard::FindParentDestinationL( TUint32 aCmId ) |
|
451 { |
|
452 LOGGER_ENTERFN( "CCmWizard::FindParentDestinationL" ); |
|
453 |
|
454 TBool found = EFalse; |
|
455 TUint32 targetDestId (0); |
|
456 |
|
457 RArray<TUint32> destinations; |
|
458 |
|
459 iCmManager.AllDestinationsL( destinations ); |
|
460 CleanupClosePushL( destinations ); |
|
461 |
|
462 RArray<TUint32> cms; |
|
463 |
|
464 for ( TInt i = 0; i < destinations.Count() && !found; i++ ) |
|
465 { |
|
466 CCmDestinationImpl* dest = |
|
467 iCmManager.DestinationL( destinations[i] ); |
|
468 CleanupStack::PushL( dest ); |
|
469 dest->ConnectMethodIdArrayL( cms ); |
|
470 CleanupClosePushL( cms ); |
|
471 |
|
472 for ( TInt j = 0; j < cms.Count() && !found; j++ ) |
|
473 { |
|
474 if( cms[j] == aCmId) |
|
475 { |
|
476 targetDestId = destinations[i]; |
|
477 found = ETrue; |
|
478 } |
|
479 } |
|
480 CleanupStack::PopAndDestroy( &cms ); |
|
481 CleanupStack::PopAndDestroy( dest ); |
|
482 } |
|
483 |
|
484 CleanupStack::PopAndDestroy( &destinations ); |
|
485 |
|
486 return targetDestId; |
|
487 } |