|
1 /* |
|
2 * Copyright (c) 2004 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: Login SAP select UI control. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <E32std.h> |
|
20 #include <CIMPSSAPSettingsStore.h> |
|
21 #include <CIMPSSAPSettings.h> |
|
22 #include <CIMPSSAPSettingsList.h> |
|
23 |
|
24 #include "CCnUiLoginSAPSelectUiCntrlStep.h" |
|
25 #include "CnUiSapLoginDataRefresher.h" |
|
26 #include "cnuitermsofusedialoghandler.h" |
|
27 |
|
28 #include "MCnUiUiControlContext.h" |
|
29 #include "MCnUiUiFacade.h" |
|
30 #include "MCnUiSignaller.h" |
|
31 |
|
32 #include "CnUiErrors.h" |
|
33 |
|
34 #include <barsc.h> |
|
35 #include "CnUiResourceFileName.h" |
|
36 |
|
37 #include "MIMPSSharedData.h" |
|
38 #include "CIMPSSharedDataFactory.h" |
|
39 #include "impspresenceconnectionuiconstsng.h" |
|
40 #include <impsconnectionuing.rsg> |
|
41 |
|
42 #include "VariantKeys.h" |
|
43 #include <centralrepository.h> |
|
44 |
|
45 // ================= MEMBER FUNCTIONS ======================= |
|
46 // Two-phased constructor. |
|
47 CCnUiLoginSAPSelectUiCntrlStep* CCnUiLoginSAPSelectUiCntrlStep::NewLC( |
|
48 MCnUiUiControlContext& aCCntxt, |
|
49 CIMPSSAPSettings& aLoginSap, |
|
50 TIMPSLoginType aLoginType, |
|
51 TBool aLastLoginSap /*= EFalse*/ ) |
|
52 { |
|
53 CCnUiLoginSAPSelectUiCntrlStep* self = new ( ELeave ) |
|
54 CCnUiLoginSAPSelectUiCntrlStep( aCCntxt, |
|
55 aLoginSap, |
|
56 aLoginType, |
|
57 aLastLoginSap ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 // Destructor |
|
65 CCnUiLoginSAPSelectUiCntrlStep::~CCnUiLoginSAPSelectUiCntrlStep() |
|
66 { |
|
67 iRFs.Close(); |
|
68 delete iSharedData; |
|
69 } |
|
70 |
|
71 |
|
72 // C++ default constructor can NOT contain any code, that |
|
73 // might leave. |
|
74 // |
|
75 CCnUiLoginSAPSelectUiCntrlStep::CCnUiLoginSAPSelectUiCntrlStep( MCnUiUiControlContext& aCCntxt, |
|
76 CIMPSSAPSettings& aLoginSap, |
|
77 TIMPSLoginType aLoginType, |
|
78 TBool aLastLoginSap /*= EFalse*/ ) |
|
79 : iCCntxt( aCCntxt ), |
|
80 iLoginSap( aLoginSap ), |
|
81 iLoginType( aLoginType ), |
|
82 iLoginSapUpdateNeeded( EFalse ), |
|
83 iLoginSapUid( KIMPSSettingsNullUid ), |
|
84 iLastLoginSap( aLastLoginSap ) |
|
85 { |
|
86 } |
|
87 |
|
88 |
|
89 // Symbian OS default constructor can leave. |
|
90 void CCnUiLoginSAPSelectUiCntrlStep::ConstructL() |
|
91 { |
|
92 iSharedData = CIMPSSharedDataFactory::CreateTemporaryKeyHandlerL( NULL, KBrandingUid ); |
|
93 } |
|
94 |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CCnUiLoginSAPSelectUiCntrlStep::RunStepL() |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TInt CCnUiLoginSAPSelectUiCntrlStep::RunStepL() |
|
101 { |
|
102 //First make sure that there isn't already another login |
|
103 //operation running (if there is, then no need to select SAP...) |
|
104 if ( iCCntxt.Signaller().OperationRunning() ) |
|
105 { |
|
106 ShowSimultanousLoginOperationNoteL(); |
|
107 return KCnUiErrorLoginOperationAlreadyInUse; |
|
108 } |
|
109 |
|
110 CIMPSSAPSettings* defaultSap = CIMPSSAPSettings::NewLC(); |
|
111 TInt loadStatus( LoadDefaultSapL( *defaultSap ) ); |
|
112 // an error will occur if there is no default sap |
|
113 // in this case we can ignore the error |
|
114 if ( loadStatus == KErrNone ) |
|
115 { |
|
116 // to get the first dialog branded also |
|
117 iCCntxt.ProcessObserverProxy().NotifyAccessingSapL( *defaultSap ); |
|
118 } |
|
119 |
|
120 //load SAP |
|
121 loadStatus = KErrNone; |
|
122 if ( !iLastLoginSap ) |
|
123 { |
|
124 if ( ( iLoginType == EIMPSApplicationLaunch ) || |
|
125 ( iLoginType == EIMPSAAConnectionStart ) ) |
|
126 { |
|
127 loadStatus = LoadDefaultSapL( iLoginSap ); |
|
128 } |
|
129 else |
|
130 { |
|
131 loadStatus = SelectSapManuallyL( iLoginSap ); |
|
132 } |
|
133 } |
|
134 //quit if loading failed |
|
135 if ( loadStatus != KErrNone ) |
|
136 { |
|
137 iLoginSap.Reset(); |
|
138 CleanupStack::PopAndDestroy( defaultSap ); |
|
139 return loadStatus; |
|
140 } |
|
141 |
|
142 //SAP selected successfully |
|
143 //notify observers from accessing the login SAP |
|
144 //this must be done here before reading the resource |
|
145 //since there might be branding involved in selecting the server |
|
146 iCCntxt.ProcessObserverProxy().NotifyAccessingSapL( iLoginSap ); |
|
147 |
|
148 //Signal to other clients that login operation is started. |
|
149 if ( iCCntxt.Signaller().SignalOperationL( iLoginSap.SAPName() ) == KErrInUse ) |
|
150 { |
|
151 //some other client has started the login |
|
152 //during SAP selection... |
|
153 ShowSimultanousLoginOperationNoteL(); |
|
154 return KCnUiErrorLoginOperationAlreadyInUse; |
|
155 } |
|
156 |
|
157 //if the SAP is missing both user details, it needs to be |
|
158 //saved after succesful login |
|
159 if ( ( iLoginSap.SAPUserId().Length() == 0 ) && |
|
160 ( iLoginSap.SAPUserPassword().Length() == 0 ) ) |
|
161 { |
|
162 iLoginSapUid = iLoginSap.Uid(); |
|
163 iLoginSapUpdateNeeded = ETrue; |
|
164 } |
|
165 |
|
166 //initial login data query in manual login mode |
|
167 if ( iLoginType == EIMPSManualLogin ) |
|
168 { |
|
169 if ( !CnUiSapLoginDataRefresher::RefreshLoginDataL( iCCntxt.Ui(), |
|
170 iLoginSap, |
|
171 EFalse ) ) |
|
172 { |
|
173 //user didn't accept the initial login data query |
|
174 iCCntxt.Ui().ShowNoteL( ECnUiConnCanceled ); |
|
175 CleanupStack::PopAndDestroy( defaultSap ); |
|
176 return KErrCancel; |
|
177 } |
|
178 } |
|
179 |
|
180 // Check Terms of use variation |
|
181 if ( ReadResourceIntValueL( RSC_CHAT_VARIATION_IMPSCU_TOU_MESSAGE ) |
|
182 && iLoginSap.SAPUserId().Length() > 0 ) |
|
183 { |
|
184 TInt retVal = CnUiTermsOfUseDialogHandler::HandleTermsOfUseDialogL( |
|
185 iLoginSap, iCCntxt.Ui(), iCCntxt.SapStoreL() ); |
|
186 |
|
187 if ( retVal == KErrCancel ) |
|
188 { |
|
189 // User canceled ToU query, login cancelled |
|
190 // note is already shown inside HandleTermsOfUseDialogL |
|
191 // method, switch to default SAP and return KErrCancel |
|
192 iCCntxt.ProcessObserverProxy().NotifyAccessingSapL( *defaultSap ); |
|
193 CleanupStack::PopAndDestroy( defaultSap ); |
|
194 return retVal; |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 CleanupStack::PopAndDestroy( defaultSap ); |
|
200 return KErrNone; |
|
201 } |
|
202 |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CCnUiLoginSAPSelectUiCntrlStep::HandleCompleteL() |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TCnUiHandleCompleteStatus CCnUiLoginSAPSelectUiCntrlStep::HandleCompleteL() |
|
210 { |
|
211 iCCntxt.Signaller().CancelOperationSignal(); |
|
212 |
|
213 if ( iLoginSapUpdateNeeded ) |
|
214 { |
|
215 CIMPSSAPSettingsStore& sapStore = iCCntxt.SapStoreL(); |
|
216 CIMPSSAPSettings* tmpSap = CIMPSSAPSettings::NewLC(); |
|
217 |
|
218 //try load logged in SAP |
|
219 TRAPD( err, sapStore.GetSAPL( iLoginSapUid, tmpSap ) ); |
|
220 if ( err == KErrNone ) |
|
221 { |
|
222 //could load succesfully the login SAP |
|
223 //update the new username / password to it as needed |
|
224 //NOTE! Can't directly store whole SAP because some |
|
225 //other steps might have altered it... |
|
226 |
|
227 TInt showUidPwQueries = ReadResourceIntValueL( RSC_CHAT_VARIATION_IMPSCU_SAVE_PW_QUERY ); |
|
228 |
|
229 if ( ! showUidPwQueries ) |
|
230 { |
|
231 // must not store the user id, password here. |
|
232 // IM application will do it in this case. |
|
233 tmpSap->SetSAPUserIdL( iLoginSap.SAPUserId() ); |
|
234 tmpSap->SetSAPUserPasswordL( iLoginSap.SAPUserPassword() ); |
|
235 sapStore.UpdateOldSAPL( tmpSap, iLoginSapUid ); |
|
236 } |
|
237 } |
|
238 |
|
239 if ( err == KErrNotFound ) //ignore login SAP not found error |
|
240 { |
|
241 err = KErrNone; |
|
242 } |
|
243 |
|
244 //handle errors by leaving |
|
245 User::LeaveIfError( err ); |
|
246 CleanupStack::PopAndDestroy( tmpSap ); //tmpSap |
|
247 } |
|
248 |
|
249 return ECnUiStepContinueTeardown; |
|
250 } |
|
251 |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CCnUiLoginSAPSelectUiCntrlStep::UndoStepL() |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CCnUiLoginSAPSelectUiCntrlStep::UndoStepL() |
|
258 { |
|
259 iCCntxt.Signaller().CancelOperationSignal(); |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CCnUiLoginSAPSelectUiCntrlStep::ShowSimultanousLoginOperationNoteL() |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CCnUiLoginSAPSelectUiCntrlStep::ShowSimultanousLoginOperationNoteL() |
|
268 { |
|
269 HBufC* serverName = NULL; |
|
270 iCCntxt.Signaller().OperationDetailsL( serverName ); |
|
271 |
|
272 //OperationDetailsL() returns the HBufC ownership |
|
273 CleanupStack::PushL( serverName ); |
|
274 iCCntxt.Ui().ShowNoteL( ECnUiConnOperationAllreadyRunning, *serverName ); |
|
275 CleanupStack::PopAndDestroy( serverName ); //serverName |
|
276 } |
|
277 |
|
278 |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CCnUiLoginSAPSelectUiCntrlStep::LoadDefaultSapL() |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 TInt CCnUiLoginSAPSelectUiCntrlStep::LoadDefaultSapL( CIMPSSAPSettings& aSap ) |
|
285 { |
|
286 CIMPSSAPSettingsStore& sapStore = iCCntxt.SapStoreL(); |
|
287 |
|
288 TIMPSConnectionClient client( ConnectionClient() ); |
|
289 TIMPSAccessGroup accessGroup; |
|
290 if ( client == EIMPSConnClientIM ) |
|
291 { |
|
292 accessGroup = EIMPSIMAccessGroup; |
|
293 } |
|
294 else |
|
295 { |
|
296 accessGroup = EIMPSPECAccessGroup; |
|
297 } |
|
298 //SAP store might not have any SAP => get default leaves |
|
299 TRAPD( err, sapStore.GetDefaultL( &aSap, accessGroup ) ); |
|
300 if ( err == KErrNotFound ) |
|
301 { |
|
302 //handle not found error by returning it |
|
303 return KCnUiErrorNoProperDefaultSap; |
|
304 } |
|
305 |
|
306 //and others by leaving |
|
307 User::LeaveIfError( err ); |
|
308 return KErrNone; |
|
309 } |
|
310 |
|
311 |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CCnUiLoginSAPSelectUiCntrlStep::SelectSapManuallyL() |
|
315 // SAP load. |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 TInt CCnUiLoginSAPSelectUiCntrlStep::SelectSapManuallyL( CIMPSSAPSettings& aSap ) |
|
319 { |
|
320 TInt indexToHiglight = KErrNotFound; //UI handles this by higlighting the first |
|
321 TInt selection = KErrNotFound; |
|
322 TInt retStatus = KErrNone; |
|
323 |
|
324 CIMPSSAPSettingsList* servers = ServerListLC( indexToHiglight ); |
|
325 if ( servers->MdcaCount() == 0 ) |
|
326 { |
|
327 //No SAPs at all |
|
328 retStatus = KCnUiErrorNoProperDefaultSap; |
|
329 } |
|
330 |
|
331 else if ( servers->MdcaCount() == 1 ) |
|
332 { |
|
333 //one SAP -> use it |
|
334 LoadSapByServerListL( *servers, 0, aSap ); //one SAP --> its index is zero |
|
335 retStatus = KErrNone; |
|
336 } |
|
337 |
|
338 else |
|
339 { |
|
340 if ( iCCntxt.Ui().ServerToUseQueryL( *servers, |
|
341 indexToHiglight, |
|
342 selection ) ) |
|
343 { |
|
344 //load sap according the user selection |
|
345 LoadSapByServerListL( *servers, selection, aSap ); |
|
346 retStatus = KErrNone; |
|
347 } |
|
348 |
|
349 else |
|
350 { |
|
351 //User declined the query |
|
352 retStatus = KErrCancel; |
|
353 } |
|
354 } |
|
355 |
|
356 CleanupStack::PopAndDestroy(); //servers |
|
357 return retStatus; |
|
358 } |
|
359 |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CCnUiLoginSAPSelectUiCntrlStep::ServerListLC() |
|
363 // SAP loading |
|
364 // ----------------------------------------------------------------------------- |
|
365 // |
|
366 CIMPSSAPSettingsList* CCnUiLoginSAPSelectUiCntrlStep::ServerListLC( TInt& aIndexToHighlight ) |
|
367 { |
|
368 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
369 |
|
370 CIMPSSAPSettingsStore& sapStore = iCCntxt.SapStoreL(); |
|
371 |
|
372 TIMPSConnectionClient client( ConnectionClient() ); |
|
373 TIMPSAccessGroup accessGroup; |
|
374 if ( client == EIMPSConnClientIM ) |
|
375 { |
|
376 accessGroup = EIMPSIMAccessGroup; |
|
377 } |
|
378 else |
|
379 { |
|
380 accessGroup = EIMPSPECAccessGroup; |
|
381 } |
|
382 sapStore.PopulateSAPSettingsListL( *sapList, accessGroup ); |
|
383 |
|
384 //get the default server index |
|
385 TUint32 defaultUid( KIMPSSettingsNullUid ); |
|
386 |
|
387 TRAPD( err, sapStore.GetDefaultL( defaultUid, accessGroup ) ); |
|
388 if ( err == KErrNone ) |
|
389 { |
|
390 //default was defined and could retrieve a UID for it |
|
391 //==>report its index |
|
392 aIndexToHighlight = sapList->IndexForUid( defaultUid ); |
|
393 } |
|
394 |
|
395 else if ( err == KErrNotFound ) |
|
396 { |
|
397 //if there wasn't a default sap defined for some reason, |
|
398 //return the index as KErrNotFound |
|
399 aIndexToHighlight = KErrNotFound; |
|
400 err = KErrNone; |
|
401 } |
|
402 |
|
403 //Handle other errors by leaving |
|
404 User::LeaveIfError( err ); |
|
405 |
|
406 return sapList; //returns the ownership of sapList |
|
407 } |
|
408 |
|
409 |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // CCnUiLoginSAPSelectUiCntrlStep::LoadSapByServerListL() |
|
413 // SAP loading |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 void CCnUiLoginSAPSelectUiCntrlStep::LoadSapByServerListL( const CIMPSSAPSettingsList& aList, |
|
417 TInt aIndexOfSelectedServer, |
|
418 CIMPSSAPSettings& aSap ) |
|
419 { |
|
420 if ( ( aIndexOfSelectedServer < 0 ) || |
|
421 ( aIndexOfSelectedServer > aList.Count() ) ) |
|
422 { |
|
423 User::Leave( KErrArgument ); |
|
424 } |
|
425 |
|
426 TUint32 uid = aList.UidForIndex( aIndexOfSelectedServer ); |
|
427 |
|
428 CIMPSSAPSettingsStore& sapStore = iCCntxt.SapStoreL(); |
|
429 sapStore.GetSAPL( uid, &aSap ); |
|
430 } |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // CCnUiLoginSAPSelectUiCntrlStep::ConnectionClient() |
|
434 // Client information loading |
|
435 // ----------------------------------------------------------------------------- |
|
436 // |
|
437 TIMPSConnectionClient CCnUiLoginSAPSelectUiCntrlStep::ConnectionClient() |
|
438 { |
|
439 // rvct does not support casting from TAny* to enumeration value |
|
440 TInt returnValue = ( TInt )Dll::Tls(); |
|
441 return ( TIMPSConnectionClient )returnValue; |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // CCnUiLoginSAPSelectUiCntrlStep::OpenResourceFileLC() |
|
446 // !!!Notice!!!. Two variables in cleanupstack after call of this method. |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 void CCnUiLoginSAPSelectUiCntrlStep::OpenResourceFileLC( RResourceFile& aResourceFile ) |
|
450 { |
|
451 TFileName resourceFileName; |
|
452 iRFs.Close(); |
|
453 User::LeaveIfError( iRFs.Connect() ); |
|
454 |
|
455 TInt err = iSharedData->GetStringKey( ( TIMPSSharedKeys )KBrandingResourceKey, resourceFileName ); |
|
456 if ( err || !resourceFileName.Length() ) |
|
457 { |
|
458 CnUiResourceFileName::NearestVariationForCurrentLanguage( iRFs, resourceFileName ); |
|
459 } |
|
460 aResourceFile.OpenL( iRFs, resourceFileName ); |
|
461 CleanupClosePushL( aResourceFile ); |
|
462 aResourceFile.ConfirmSignatureL(); |
|
463 } |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // CCnUiLoginSAPSelectUiCntrlStep::ReadResourceIntValueL() |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 TInt CCnUiLoginSAPSelectUiCntrlStep::ReadResourceIntValueL( TInt aResourceId ) |
|
470 { |
|
471 |
|
472 TInt val( 0 ); |
|
473 TInt err ( KErrNone ); |
|
474 |
|
475 CRepository* rep = 0; |
|
476 |
|
477 TRAP( err, rep = CRepository::NewL( KCRUidIMNG ) ); |
|
478 |
|
479 if ( err == KErrNone ) |
|
480 { |
|
481 TInt key = aResourceId + KIMCUStartVariationID; |
|
482 |
|
483 err = rep->Get( key, val ); |
|
484 |
|
485 delete rep; |
|
486 } |
|
487 |
|
488 if ( err != KErrNone ) |
|
489 { |
|
490 |
|
491 RResourceFile resFile; |
|
492 OpenResourceFileLC( resFile ); // Two items in cleanup stack. |
|
493 |
|
494 aResourceId = aResourceId + RSC_CRRSS_CHAT_VARIATION_IMPSCU_START_ID; |
|
495 |
|
496 // read the data to a buffer |
|
497 TInt plainResourceId = 0x00000fff & aResourceId; // Remove offset from id |
|
498 HBufC8* rawDataBuf = resFile.AllocReadLC( plainResourceId ); |
|
499 |
|
500 // it's now as ascii code: \x00 for 0, \x01 for 1, etc. |
|
501 TUint value = ( *rawDataBuf )[ 0 ]; |
|
502 |
|
503 CleanupStack::PopAndDestroy( 2 ); // rawDataBuf, resFile |
|
504 |
|
505 val = value; |
|
506 } |
|
507 |
|
508 return val; |
|
509 } |
|
510 |
|
511 // End of File |