|
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: Connection UI implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <E32std.h> |
|
20 #include <CIMPSSAPSettings.h> |
|
21 #include <CPEngNWSessionSlotID2.h> |
|
22 #include <CPEngNWSessionSlotManager2.h> |
|
23 #include <PEngPresenceEngineConsts2.h> |
|
24 #include <CPEngNWSessionSlot2.h> |
|
25 #include <sysutil.h> |
|
26 |
|
27 #include "CIMPSPresenceConnectionUiImp.h" |
|
28 #include "MCnUiConnectionHandler.h" |
|
29 #include "MCnUiSignaller.h" |
|
30 #include "CCnUiUiControlContext.h" |
|
31 #include "CCnUiConnModeRewaker.h" |
|
32 #include "CnUiErrors.h" |
|
33 #include "IMPSCommonUiDebugPrint.h" |
|
34 |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 // Two-phased constructor. |
|
38 CIMPSPresenceConnectionUiImp* CIMPSPresenceConnectionUiImp::NewL( |
|
39 TIMPSConnectionClient aClient, |
|
40 CIMPSSAPSettingsStore* aSapStore ) |
|
41 { |
|
42 CIMPSPresenceConnectionUiImp* self = |
|
43 new ( ELeave ) CIMPSPresenceConnectionUiImp( aClient, aSapStore ); |
|
44 |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); //self |
|
48 |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 // Destructor |
|
54 CIMPSPresenceConnectionUiImp::~CIMPSPresenceConnectionUiImp() |
|
55 { |
|
56 delete iConnModeRewaker; |
|
57 delete iConnHandler; |
|
58 } |
|
59 |
|
60 |
|
61 // C++ default constructor can NOT contain any code, that |
|
62 // might leave. |
|
63 // |
|
64 CIMPSPresenceConnectionUiImp::CIMPSPresenceConnectionUiImp( TIMPSConnectionClient aClient, |
|
65 CIMPSSAPSettingsStore* aSapStore ) |
|
66 : iSapStoreProxy( aSapStore ), iClient( aClient ) |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 // Symbian OS default constructor can leave. |
|
72 void CIMPSPresenceConnectionUiImp::ConstructL() |
|
73 { |
|
74 // set the client information to the TLS |
|
75 User::LeaveIfError( Dll::SetTls( reinterpret_cast<TAny*>( iClient ) ) ); |
|
76 iConnHandler = CreateConnHandlerL( iSapStoreProxy ); |
|
77 iConnModeRewaker = CCnUiConnModeRewaker::NewL(); |
|
78 ReStoreNWSessionOwnershipL(); |
|
79 } |
|
80 |
|
81 |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CIMPSPresenceConnectionUiImp::LoginL() |
|
85 // |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TInt CIMPSPresenceConnectionUiImp::LoginL( TIMPSConnectionClient aClient, |
|
89 TIMPSLoginType aLoginType, |
|
90 CPEngNWSessionSlotID2& aNWSessionSlotID, |
|
91 MIMPSConnProcessObserver* aObserver, |
|
92 CIMPSSAPSettings* aSap /*= NULL*/, |
|
93 TBool aLastLoginSap /*= EFalse*/ ) |
|
94 { |
|
95 |
|
96 if ( LoggedInL( aClient ) ) |
|
97 { |
|
98 // it seems we are already logged in |
|
99 return KErrAlreadyExists; |
|
100 } |
|
101 |
|
102 // Check disk space |
|
103 if ( SysUtil::FFSSpaceBelowCriticalLevelL( NULL, 0 ) ) |
|
104 { |
|
105 // Don't show any own notes here |
|
106 User::Leave( KErrDiskFull ); |
|
107 } |
|
108 |
|
109 iConnModeRewaker->SuspendLC(); |
|
110 |
|
111 // add two extra param if user want to login to last server only |
|
112 CCnUiUiControlContext* uiCC = CCnUiUiControlContext::NewLC( aClient, |
|
113 iSapStoreProxy, |
|
114 *iConnModeRewaker, |
|
115 *iConnHandler, |
|
116 aObserver ); |
|
117 |
|
118 TInt retStatus = uiCC->DoLoginL( aLoginType, aNWSessionSlotID, aSap, aLastLoginSap ); |
|
119 CleanupStack::PopAndDestroy( 2 ); //uiCC, Resume ReWake |
|
120 |
|
121 return MapToUiLoginReturnStatus( retStatus ); |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CIMPSPresenceConnectionUiImp::LogoutL() |
|
127 // |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CIMPSPresenceConnectionUiImp::LogoutL( const CPEngNWSessionSlotID2& aNWSessionSlotID, |
|
131 MIMPSConnProcessObserver* aObserver ) |
|
132 { |
|
133 TIMPSConnectionClient client; |
|
134 |
|
135 if ( 0 == aNWSessionSlotID.AppId().Compare( KPEngAppIdIM ) ) |
|
136 { |
|
137 client = EIMPSConnClientIM; |
|
138 } |
|
139 else |
|
140 { |
|
141 client = EIMPSConnClientPEC; |
|
142 } |
|
143 |
|
144 //if client isn't logged in, nothing to do.. |
|
145 if ( !iConnHandler->TheClientLoggedInL( client ) ) |
|
146 { |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 iConnModeRewaker->SuspendLC(); |
|
151 |
|
152 CCnUiUiControlContext* uiCC = CCnUiUiControlContext::NewLC( client, |
|
153 iSapStoreProxy, |
|
154 *iConnModeRewaker, |
|
155 *iConnHandler, |
|
156 aObserver ); |
|
157 |
|
158 |
|
159 uiCC->DoLogoutL( aNWSessionSlotID ); |
|
160 CleanupStack::PopAndDestroy( 2 ); //uiCC, Resume ReWake |
|
161 |
|
162 return KErrNone; |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CIMPSPresenceConnectionUiImp::HandleApplicationExitL() |
|
168 // |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TInt CIMPSPresenceConnectionUiImp::HandleApplicationExitL( |
|
172 TIMPSConnectionClient aClient, |
|
173 TIMPSExitType aExitType, |
|
174 const CPEngNWSessionSlotID2& aNWSessionSlotID, |
|
175 MIMPSConnProcessObserver* aObserver ) |
|
176 { |
|
177 //if client isn't logged in, nothing to do.. |
|
178 if ( !iConnHandler->TheClientLoggedInL( aClient ) ) |
|
179 { |
|
180 return KErrNone; |
|
181 } |
|
182 |
|
183 //logged in, handle as normal commands |
|
184 |
|
185 if ( aExitType == EIMPSLeaveSessionOpenExit ) |
|
186 { |
|
187 // we are supposed to store the ownership here |
|
188 StoreNWSessionOwnershipL( aNWSessionSlotID ); |
|
189 return KErrNone; |
|
190 } |
|
191 |
|
192 iConnModeRewaker->SuspendLC(); |
|
193 CCnUiUiControlContext* uiCC = CCnUiUiControlContext::NewLC( aClient, |
|
194 iSapStoreProxy, |
|
195 *iConnModeRewaker, |
|
196 *iConnHandler, |
|
197 aObserver ); |
|
198 |
|
199 TInt retStatus = uiCC->DoHandleApplicationExitL( aExitType, aNWSessionSlotID ); |
|
200 CleanupStack::PopAndDestroy( 2 ); //uiCC, Resume ReWake |
|
201 |
|
202 if ( retStatus == KErrCancel ) |
|
203 { |
|
204 // query was shown, and user selected to leave the session open |
|
205 StoreNWSessionOwnershipL( aNWSessionSlotID ); |
|
206 } |
|
207 |
|
208 return retStatus; |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CIMPSPresenceConnectionUiImp::GetActiveNWSessionSlotIDL() |
|
214 // |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 CPEngNWSessionSlotID2* CIMPSPresenceConnectionUiImp::GetActiveNWSessionSlotIDL( |
|
218 TIMPSConnectionClient aClient ) |
|
219 { |
|
220 CPEngNWSessionSlotManager2* slotManager = CPEngNWSessionSlotManager2::NewLC(); |
|
221 |
|
222 CPEngNWSessionSlotID2* pattern = CPEngNWSessionSlotID2::NewLC(); |
|
223 pattern->SetServiceAddressMatchAnyL(); |
|
224 pattern->SetUserIdMatchAnyL(); |
|
225 if ( aClient == EIMPSConnClientPEC ) |
|
226 { |
|
227 pattern->SetAppIdL( KPEngAppIdPEC ); |
|
228 } |
|
229 else |
|
230 { |
|
231 pattern->SetAppIdL( KPEngAppIdIM ); |
|
232 } |
|
233 |
|
234 RPointerArray< CPEngNWSessionSlotID2 > array; |
|
235 TInt error( slotManager->GetNWSessionSlots( array, |
|
236 *pattern, |
|
237 EPEngNWPresenceSessionOpen ) ); |
|
238 if ( error != KErrNone ) |
|
239 { |
|
240 array.ResetAndDestroy(); |
|
241 User::Leave( error ); |
|
242 } |
|
243 CleanupStack::PopAndDestroy( 2, slotManager ); // pattern, slotManager |
|
244 CleanupStack::PushL( TCleanupItem( DestroyCloseModelArray, &array ) ); |
|
245 |
|
246 CPEngNWSessionSlotID2* slotID = NULL; |
|
247 |
|
248 if ( array.Count() > 0 ) |
|
249 { |
|
250 // only one active slot per application at the moment |
|
251 CPEngNWSessionSlotID2* tempSlotID = array[ 0 ]; |
|
252 |
|
253 slotID = tempSlotID->CloneL(); |
|
254 } |
|
255 else |
|
256 { |
|
257 // not found |
|
258 User::Leave( KErrNotFound ); |
|
259 } |
|
260 CleanupStack::PopAndDestroy(); //array |
|
261 return slotID; |
|
262 } |
|
263 |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CIMPSPresenceConnectionUiImp::GetLoggedInSapL() |
|
267 // |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 TInt CIMPSPresenceConnectionUiImp::GetLoggedInSapL( const CPEngNWSessionSlotID2& aNWSessionSlotID, |
|
271 CIMPSSAPSettings& aSap ) |
|
272 { |
|
273 iSapStoreProxy.PushOwnedSapStoreReleaseLC(); |
|
274 TIMPSConnectionClient client; |
|
275 if ( 0 == aNWSessionSlotID.AppId().Compare( KPEngAppIdIM ) ) |
|
276 { |
|
277 client = EIMPSConnClientIM; |
|
278 } |
|
279 else |
|
280 { |
|
281 client = EIMPSConnClientPEC; |
|
282 } |
|
283 |
|
284 TBool connected = iConnHandler->GetLoggedInSapL( aSap, client ); |
|
285 CleanupStack::PopAndDestroy(); //PushOwnedSapStoreReleaseLC |
|
286 |
|
287 if ( connected ) |
|
288 { |
|
289 return KErrNone; |
|
290 } |
|
291 else |
|
292 { |
|
293 aSap.Reset(); |
|
294 return KErrNotFound; |
|
295 } |
|
296 } |
|
297 |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CIMPSPresenceConnectionUiImp::PureServiceStatusL() |
|
301 // |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 TPEngNWSessionSlotState CIMPSPresenceConnectionUiImp::PureServiceStatusL( |
|
305 const CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
306 { |
|
307 return iConnHandler->ServiceStatusL( aNWSessionSlotID ); |
|
308 } |
|
309 |
|
310 |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CIMPSPresenceConnectionUiImp::CurrentConnectionOperationL() |
|
314 // |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 TIMPSConnectionOperation CIMPSPresenceConnectionUiImp::CurrentConnectionOperationL( |
|
318 HBufC*& aAddtionalDesc ) |
|
319 { |
|
320 aAddtionalDesc = NULL; |
|
321 TIMPSConnectionOperation currectOp = EIMPSConnOppUnknown; |
|
322 |
|
323 MCnUiSignaller* loginSignaller = CreateConnUiSignallerLC(); |
|
324 |
|
325 if ( loginSignaller->OperationRunning() ) |
|
326 { |
|
327 currectOp = EIMPSConnOppClientLogin; |
|
328 |
|
329 loginSignaller->OperationDetailsL( aAddtionalDesc ); |
|
330 if ( !aAddtionalDesc ) |
|
331 { |
|
332 //method semantic promises that if the operation is |
|
333 //EIMPSConnOppClientLogin, it will always have a |
|
334 //server name as aAddtionalDesc ==> create empty buf if missing server name |
|
335 aAddtionalDesc = HBufC::NewL( 0 ); |
|
336 } |
|
337 } |
|
338 CleanupStack::PopAndDestroy(); //loginSignaller |
|
339 |
|
340 return currectOp; |
|
341 } |
|
342 |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CIMPSPresenceConnectionUiImp::MapToUiLoginReturnStatus() |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 TInt CIMPSPresenceConnectionUiImp::MapToUiLoginReturnStatus( TInt aOperationResult ) |
|
349 { |
|
350 TInt mappedError = KErrNone; |
|
351 |
|
352 switch ( aOperationResult ) |
|
353 { |
|
354 //falltrough |
|
355 case KErrNone: // Login succeeded |
|
356 case KErrCancel: //User has cancelled the login at some point. |
|
357 { |
|
358 //these are returned as is |
|
359 mappedError = aOperationResult; |
|
360 break; |
|
361 } |
|
362 |
|
363 case KCnUiErrorNoProperDefaultSap: |
|
364 { |
|
365 //Missing the whole default SAP / or no SAP's at all |
|
366 mappedError = KErrNotFound; |
|
367 break; |
|
368 } |
|
369 |
|
370 case KCnUiErrorSapMissingCompulsoryFields: |
|
371 { |
|
372 //Default or selected SAP to login was missing some required fields. |
|
373 mappedError = KErrArgument; |
|
374 break; |
|
375 } |
|
376 |
|
377 case KCnUiErrorClientAlreadyConnected: |
|
378 { |
|
379 //Current client is already logged in. (Thus not a real error.) |
|
380 mappedError = KErrAlreadyExists; |
|
381 break; |
|
382 } |
|
383 |
|
384 default: |
|
385 { |
|
386 //General failure during login (no connection to network, network access denied, etc..) |
|
387 mappedError = KErrGeneral; |
|
388 break; |
|
389 } |
|
390 } |
|
391 |
|
392 return mappedError; |
|
393 } |
|
394 |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // CIMPSPresenceConnectionUiImp::StoreNWSessionOwnership() |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 void CIMPSPresenceConnectionUiImp::StoreNWSessionOwnershipL( |
|
401 const CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
402 { |
|
403 IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSPresenceConnectionUiImp::StoreNWSessionOwnership()" ) ); |
|
404 |
|
405 CPEngNWSessionSlot2* sessionSlot = CPEngNWSessionSlot2::NewLC( aNWSessionSlotID ); |
|
406 |
|
407 // get the ownership of this slot |
|
408 User::LeaveIfError( sessionSlot->OpenNWPresenceSessionOwnership() ); |
|
409 |
|
410 // store the ownership so that PECEngine does not close the session when |
|
411 // session slot objects are deleted |
|
412 TInt err = sessionSlot->StoreNWPresenceSessionOwnership( aNWSessionSlotID.AppId() ); |
|
413 // Ignore KErrAlreadyExists |
|
414 if ( err != KErrAlreadyExists && err != KErrNone ) |
|
415 { |
|
416 User::Leave( err ); |
|
417 } |
|
418 |
|
419 CleanupStack::PopAndDestroy( sessionSlot ); // sessionSlot, slotID |
|
420 } |
|
421 |
|
422 // ----------------------------------------------------------------------------- |
|
423 // CIMPSPresenceConnectionUiImp::ReStoreNWSessionOwnership() |
|
424 // ----------------------------------------------------------------------------- |
|
425 // |
|
426 void CIMPSPresenceConnectionUiImp::ReStoreNWSessionOwnershipL() |
|
427 { |
|
428 IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSPresenceConnectionUiImp::ReStoreNWSessionOwnership()" ) ); |
|
429 |
|
430 CPEngNWSessionSlotID2* slotID = NULL; |
|
431 |
|
432 // get the active network session slot |
|
433 TRAPD( err, slotID = GetActiveNWSessionSlotIDL( iClient ) ); |
|
434 if ( err == KErrNotFound ) |
|
435 { |
|
436 // no active network session slot for this client |
|
437 // we can just return |
|
438 return; |
|
439 } |
|
440 else if ( err != KErrNone ) |
|
441 { |
|
442 User::Leave( err ); |
|
443 } |
|
444 |
|
445 // we got the active slot's ID |
|
446 CleanupStack::PushL( slotID ); |
|
447 |
|
448 CPEngNWSessionSlot2* sessionSlot = CPEngNWSessionSlot2::NewLC( *slotID ); |
|
449 |
|
450 TPtrC ownership; |
|
451 if ( iClient == EIMPSConnClientPEC ) |
|
452 { |
|
453 ownership.Set( KPEngAppIdPEC() ); |
|
454 } |
|
455 else |
|
456 { |
|
457 ownership.Set( KPEngAppIdIM() ); |
|
458 } |
|
459 |
|
460 // restore the ownership so that PECEngine will close the session when |
|
461 // session slot objects are deleted |
|
462 err = sessionSlot->RestoreNWPresenceSessionOwnership( ownership ); |
|
463 |
|
464 if ( err == KErrNotFound ) |
|
465 { |
|
466 // there was no stored session ownership |
|
467 // so we really don't need to do anything |
|
468 CleanupStack::PopAndDestroy( 2, slotID ); // sessionSlot, slotID |
|
469 return; |
|
470 } |
|
471 else if ( err != KErrNone ) |
|
472 { |
|
473 User::Leave( err ); |
|
474 } |
|
475 |
|
476 // give this slot to connection handler |
|
477 iConnHandler->SetSessionSlotL( sessionSlot ); |
|
478 CleanupStack::Pop( sessionSlot ); |
|
479 |
|
480 CleanupStack::PopAndDestroy( slotID ); // sessionSlot |
|
481 } |
|
482 |
|
483 // ----------------------------------------------------------------------------- |
|
484 // CIMPSPresenceConnectionUiImp::LoggedInL() |
|
485 // ----------------------------------------------------------------------------- |
|
486 // |
|
487 TBool CIMPSPresenceConnectionUiImp::LoggedInL( TIMPSConnectionClient aClient ) |
|
488 { |
|
489 CPEngNWSessionSlotID2* slotID = NULL; |
|
490 TRAPD( err, slotID = GetActiveNWSessionSlotIDL( aClient ) ); |
|
491 if ( err == KErrNotFound ) |
|
492 { |
|
493 // no session slots -> not logged in |
|
494 return EFalse; |
|
495 } |
|
496 else |
|
497 { |
|
498 // for other errors we have to leave |
|
499 User::LeaveIfError( err ); |
|
500 } |
|
501 // slot found, we are logged in |
|
502 delete slotID; |
|
503 return ETrue; |
|
504 } |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CIMPSPresenceConnectionUiImp::DisplayDomainSelectionQueryL |
|
508 // ----------------------------------------------------------------------------- |
|
509 // |
|
510 TInt CIMPSPresenceConnectionUiImp::DisplayDomainSelectionQueryL( |
|
511 TDes& aSelectedDomain, |
|
512 CIMPSSAPSettings* aSap ) |
|
513 { |
|
514 return CCnUiUiControlContext::DisplayDomainSelectionQueryL( |
|
515 aSelectedDomain, aSap ); |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CIMPSPresenceConnectionUiImp::DestroyCloseModelArray() |
|
520 // |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 void CIMPSPresenceConnectionUiImp::DestroyCloseModelArray( TAny* aObject ) |
|
524 { |
|
525 reinterpret_cast< RPointerArray< CPEngNWSessionSlotID2 >* >( aObject )->ResetAndDestroy(); |
|
526 } |
|
527 |
|
528 // End of File |
|
529 |