|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Settings manager |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CCASettingsManager.h" // Own header |
|
20 #include "MCASettingsObserver.h" |
|
21 #include "ChatDebugPrint.h" |
|
22 #include "chatdebugassert.h" |
|
23 #include "PrivateEngineDefinitions.h" |
|
24 #include "CCASDCRVariator.h" |
|
25 #include "ImpsCSPAllErrors.h" |
|
26 #include "impsbuilddefinitions.h" |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <CIMPSSAPSettingsStore.h> |
|
30 #include <CIMPSSAPSettings.h> |
|
31 #include <CIMPSSAPSettingsList.h> |
|
32 #include <centralrepository.h> |
|
33 |
|
34 // CONSTANTS |
|
35 |
|
36 // Separators for Alias table, to separate items from each other |
|
37 // e.g [userid][itemsep][alias][tablesep][userid][itemsep][alias] etc... |
|
38 // |
|
39 const TUint KAliasItemSeparator = 0x10; |
|
40 const TUint KAliasTableSeparator = 0x11; |
|
41 const TInt KSeparatorSize = 2; // bytes |
|
42 |
|
43 // Maximum length for alias table. |
|
44 // See CIMPSSAPSettings::SetOpaqueDesC16 for description of this value |
|
45 const TInt KMaxAliasDataLength = |
|
46 NCentralRepositoryConstants::KMaxUnicodeStringLength - |
|
47 5 - 10; // 10 == KCAOwnAlias().Length() ! |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // Two-phased constructor. |
|
52 CCASettingsManager* CCASettingsManager::NewL( TUid aIdentifier ) |
|
53 { |
|
54 CCASettingsManager* self = new ( ELeave ) CCASettingsManager; |
|
55 |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aIdentifier ); |
|
58 CleanupStack::Pop( self ); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 // Destructor |
|
64 CCASettingsManager::~CCASettingsManager() |
|
65 { |
|
66 iObserverList.Close(); |
|
67 delete iSDCRVariator; |
|
68 delete iSapSettingsStore; |
|
69 delete iDefaultSap; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------- |
|
73 // CCASettingsManager::AddObserverL |
|
74 // --------------------------------------------------------- |
|
75 // |
|
76 void CCASettingsManager::AddObserverL( const MCASettingsObserver* aObserver ) |
|
77 { |
|
78 if ( aObserver ) |
|
79 { |
|
80 TInt err( iObserverList.Append( aObserver ) ); |
|
81 User::LeaveIfError( err ); |
|
82 } |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CCASettingsManager::RemoveObserver |
|
87 // --------------------------------------------------------- |
|
88 // |
|
89 void CCASettingsManager::RemoveObserver( const MCASettingsObserver* aObserver ) |
|
90 { |
|
91 TInt index( iObserverList.Find( aObserver ) ); |
|
92 |
|
93 if ( index != KErrNotFound ) |
|
94 { |
|
95 iObserverList.Remove( index ); |
|
96 } |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CCASettingsManager::Value |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 TBool CCASettingsManager::Value( TCASettingFlags aSetting, |
|
104 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
105 { |
|
106 TInt value( 0 ); |
|
107 TBool ok( EFalse ); |
|
108 |
|
109 TRAPD( err, |
|
110 { |
|
111 CIMPSSAPSettings* sap = GetSAPLC( aSap ); |
|
112 |
|
113 if ( iSettingsFaceLift && !sap ) |
|
114 { |
|
115 ok = ( iSDCRVariator->GetInt( aSetting, value ) == KErrNone ); |
|
116 } |
|
117 else if ( sap ) |
|
118 { |
|
119 TPtrC settingName( ConvertSettingInteger( aSetting ) ); |
|
120 if ( settingName.Length() > 0 ) |
|
121 { |
|
122 ok = ( sap->GetOpaqueInt( settingName, value ) == KErrNone ); |
|
123 } |
|
124 } |
|
125 |
|
126 if ( !ok ) |
|
127 { |
|
128 if ( iSDCRVariator->GetInt( aSetting, value ) != KErrNone ) |
|
129 { |
|
130 value = DefaultBooleanValue( aSetting ); |
|
131 } |
|
132 } |
|
133 |
|
134 CleanupStack::PopAndDestroy( sap ); |
|
135 CHAT_DP( D_CHAT_LIT( "CCASettingsManager::Value( %d ) = %d" ), |
|
136 aSetting, value ); |
|
137 } ); // TRAPD |
|
138 |
|
139 if ( err ) |
|
140 { |
|
141 CActiveScheduler::Current()->Error( err ); |
|
142 return EFalse; |
|
143 } |
|
144 else |
|
145 { |
|
146 return value; |
|
147 } |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------- |
|
151 // CCASettingsManager::Value |
|
152 // --------------------------------------------------------- |
|
153 // |
|
154 TInt CCASettingsManager::Value( TCASettingIntegers aSetting, |
|
155 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
156 { |
|
157 TInt value( 0 ); |
|
158 TBool ok( EFalse ); |
|
159 |
|
160 TRAPD( err, |
|
161 { |
|
162 CIMPSSAPSettings* sap = GetSAPLC( aSap ); |
|
163 |
|
164 if ( iSettingsFaceLift && !sap ) |
|
165 { |
|
166 ok = ( iSDCRVariator->GetInt( aSetting, value ) == KErrNone ); |
|
167 } |
|
168 else if ( sap ) |
|
169 { |
|
170 TPtrC settingName( ConvertSettingInteger( aSetting ) ); |
|
171 if ( settingName.Length() > 0 ) |
|
172 { |
|
173 ok = ( sap->GetOpaqueInt( ConvertSettingInteger( aSetting ), value ) == KErrNone ); |
|
174 } |
|
175 } |
|
176 |
|
177 if ( !ok ) |
|
178 { |
|
179 if ( iSDCRVariator->GetInt( aSetting, value ) != KErrNone ) |
|
180 { |
|
181 value = DefaultIntegerValue( aSetting ); |
|
182 } |
|
183 } |
|
184 |
|
185 CleanupStack::PopAndDestroy( sap ); |
|
186 CHAT_DP( D_CHAT_LIT( "CCASettingsManager::Value( %d ) = %d" ), |
|
187 aSetting, value ); |
|
188 } ); // TRAPD |
|
189 |
|
190 if ( err ) |
|
191 { |
|
192 CActiveScheduler::Current()->Error( err ); |
|
193 return EFalse; |
|
194 } |
|
195 else |
|
196 { |
|
197 return value; |
|
198 } |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CCASettingsManager::ValueL |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 HBufC* CCASettingsManager::ValueL( TCASettingStrings aSetting, |
|
206 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
207 { |
|
208 TInt length( ( aSetting & EStringsLengthMask ) >> EStringsLengthShift ); |
|
209 |
|
210 // Check if those enum definitions where reasonable |
|
211 if ( !length ) |
|
212 { |
|
213 User::Leave( EInvalidStringEnumDefinition ); |
|
214 } |
|
215 |
|
216 HBufC* temp = HBufC::NewLC( length ); |
|
217 TPtr str( temp->Des() ); |
|
218 |
|
219 CIMPSSAPSettings* sap = GetSAPLC( aSap ); |
|
220 TInt ok( EFalse ); |
|
221 if ( sap ) |
|
222 { |
|
223 TPtrC settingName( ConvertSettingInteger( aSetting ) ); |
|
224 if ( settingName.Length() > 0 ) |
|
225 { |
|
226 TPtrC strC( KNullDesC ); |
|
227 ok = ( sap->GetOpaqueDesC16( settingName, strC ) == KErrNone ); |
|
228 |
|
229 str.Copy( strC ); |
|
230 } |
|
231 } |
|
232 |
|
233 if ( !ok ) |
|
234 { |
|
235 if ( iSDCRVariator->GetString( aSetting, str ) != KErrNone ) |
|
236 { |
|
237 // default to empty |
|
238 str.Copy( KNullDesC ); |
|
239 } |
|
240 } |
|
241 |
|
242 CHAT_DP( D_CHAT_LIT( "CCASettingsManager::Value( %d ) = %S" ), |
|
243 aSetting, temp ); |
|
244 |
|
245 CleanupStack::PopAndDestroy( sap ); |
|
246 CleanupStack::Pop( temp ); |
|
247 return temp; |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------- |
|
251 // CCASettingsManager::SetValueL |
|
252 // --------------------------------------------------------- |
|
253 // |
|
254 void CCASettingsManager::SetValueL( TCASettingFlags aSetting, TBool aValue, |
|
255 RArray<TInt>* aIgnoreRollback /*= NULL*/, |
|
256 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
257 { |
|
258 TBool oldValue( Value( aSetting, aSap ) ); |
|
259 SetIntValueL( aSetting, aValue, oldValue, aIgnoreRollback, aSap ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------- |
|
263 // CCASettingsManager::SetValueL |
|
264 // --------------------------------------------------------- |
|
265 // |
|
266 void CCASettingsManager::SetValueL( TCASettingIntegers aSetting, TInt aValue, |
|
267 RArray<TInt>* aIgnoreRollback /*= NULL*/, |
|
268 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
269 { |
|
270 TInt oldValue( Value( aSetting, aSap ) ); |
|
271 SetIntValueL( aSetting, aValue, oldValue, aIgnoreRollback, aSap ); |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------- |
|
275 // CCASettingsManager::SetIntValueL |
|
276 // --------------------------------------------------------- |
|
277 // |
|
278 void CCASettingsManager::SetIntValueL( TInt aSetting, TInt aValue, |
|
279 TInt aOldValue, |
|
280 RArray<TInt>* aIgnoreRollback /*= NULL*/, |
|
281 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
282 { |
|
283 if ( aValue != aOldValue ) |
|
284 { |
|
285 CIMPSSAPSettings* sap = GetSAPLC( aSap ); |
|
286 StoreL( sap, aSetting, aValue ); |
|
287 |
|
288 TInt leave( KErrNone ); |
|
289 |
|
290 TRAP( leave, NotifyObserversL( aSetting ) ); |
|
291 |
|
292 if ( leave ) |
|
293 { |
|
294 //roll back |
|
295 TBool rollback( ETrue ); |
|
296 if ( aIgnoreRollback ) |
|
297 { |
|
298 // rollback if the error code is not found from the list |
|
299 rollback = ( aIgnoreRollback->Find( leave ) == KErrNotFound ); |
|
300 } |
|
301 |
|
302 if ( rollback ) |
|
303 { |
|
304 StoreL( sap, aSetting, aOldValue ); |
|
305 } |
|
306 User::Leave( leave ); |
|
307 } |
|
308 |
|
309 CleanupStack::PopAndDestroy( sap ); |
|
310 } |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------- |
|
314 // CCASettingsManager::SetValueL |
|
315 // --------------------------------------------------------- |
|
316 // |
|
317 void CCASettingsManager::SetValueL( TCASettingStrings aSetting, |
|
318 const TDesC& aValue, |
|
319 RArray<TInt>* aIgnoreRollback /*= NULL*/, |
|
320 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
321 { |
|
322 TInt length( ( aSetting & EStringsLengthMask ) >> EStringsLengthShift ); |
|
323 |
|
324 if ( length < aValue.Length() ) |
|
325 { |
|
326 User::Leave( EStringTooLong ); |
|
327 } |
|
328 |
|
329 HBufC* oldValue = NULL; |
|
330 |
|
331 TRAPD( err, oldValue = ValueL( aSetting ) ); |
|
332 if ( err != EOwnUserIdNotAvailable ) |
|
333 { |
|
334 User::LeaveIfError( err ); |
|
335 } |
|
336 |
|
337 if ( oldValue ) |
|
338 { |
|
339 CleanupStack::PushL( oldValue ); |
|
340 } |
|
341 |
|
342 if ( !oldValue || aValue != *oldValue ) |
|
343 { |
|
344 CHAT_DP( D_CHAT_LIT( "CCASettingsManager::Value( %d ) = %S" ), |
|
345 aSetting, &aValue ); |
|
346 CIMPSSAPSettings* sap = GetSAPLC( aSap ); |
|
347 StoreL( sap, aSetting, aValue ); |
|
348 |
|
349 TInt leave( KErrNone ); |
|
350 |
|
351 TRAP( leave, NotifyObserversL( aSetting ) ); |
|
352 |
|
353 if ( leave && oldValue ) |
|
354 { |
|
355 //roll back |
|
356 TBool rollback( ETrue ); |
|
357 if ( aIgnoreRollback ) |
|
358 { |
|
359 // rollback if the error code is not found from the list |
|
360 rollback = ( aIgnoreRollback->Find( leave ) == KErrNotFound ); |
|
361 } |
|
362 |
|
363 if ( rollback ) |
|
364 { |
|
365 StoreL( sap, aSetting, *oldValue ); |
|
366 } |
|
367 } |
|
368 User::LeaveIfError( leave ); |
|
369 CleanupStack::PopAndDestroy( sap ); |
|
370 } |
|
371 |
|
372 if ( oldValue ) |
|
373 { |
|
374 CleanupStack::PopAndDestroy( oldValue ); |
|
375 } |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------- |
|
379 // CCASettingsManager::FlushData |
|
380 // --------------------------------------------------------- |
|
381 // |
|
382 void CCASettingsManager::FlushData() |
|
383 { |
|
384 TInt err = iSDCRVariator->FlushData(); |
|
385 if ( err != KErrNone ) |
|
386 { |
|
387 CActiveScheduler::Current()->Error( err ); |
|
388 } |
|
389 } |
|
390 |
|
391 // Symbian OS default constructor can leave. |
|
392 void CCASettingsManager::ConstructL( TUid aIdentifier ) |
|
393 { |
|
394 iSDCRVariator = CCASDCRVariator::NewL( aIdentifier ); |
|
395 iSapSettingsStore = CIMPSSAPSettingsStore::NewL(); |
|
396 |
|
397 // populate the list of sapsettings |
|
398 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
399 iSapSettingsStore->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
400 |
|
401 CIMPSSAPSettings* sap = CIMPSSAPSettings::NewLC(); |
|
402 TRAPD( err, iSapSettingsStore->GetDefaultL( sap, EIMPSIMAccessGroup ) ); |
|
403 if ( err == KErrNotFound ) |
|
404 { |
|
405 CleanupStack::PopAndDestroy( sap ); |
|
406 sap = NULL; |
|
407 } |
|
408 else |
|
409 { |
|
410 CleanupStack::Pop( sap ); |
|
411 } |
|
412 iDefaultSap = sap; |
|
413 |
|
414 CleanupStack::PopAndDestroy( sapList ); |
|
415 |
|
416 |
|
417 #ifdef RD_SETTINGS_FACELIFT |
|
418 iSettingsFaceLift = ETrue; |
|
419 #endif |
|
420 } |
|
421 |
|
422 // C++ default constructor can NOT contain any code, that |
|
423 // might leave. |
|
424 // |
|
425 CCASettingsManager::CCASettingsManager() |
|
426 { |
|
427 } |
|
428 |
|
429 // --------------------------------------------------------- |
|
430 // CCASettingsManager::NotifyObserversL |
|
431 // --------------------------------------------------------- |
|
432 // |
|
433 void CCASettingsManager::NotifyObserversL( TInt aEnum ) |
|
434 { |
|
435 TInt observerCount( iObserverList.Count() ); |
|
436 |
|
437 CHAT_DP( D_CHAT_LIT( "CCASettingsManager::NotifyObserversL(%d), changed \ |
|
438 enum: %d" ), observerCount, aEnum ); |
|
439 |
|
440 for ( TInt i( 0 ); i < observerCount; ++i ) |
|
441 { |
|
442 ( *iObserverList[i] ).HandleSettingsChangeL( aEnum ); |
|
443 } |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------- |
|
447 // CCASettingsManager::DefaultIntegerValue |
|
448 // --------------------------------------------------------- |
|
449 // |
|
450 TInt CCASettingsManager::DefaultIntegerValue( TInt aEnum ) const |
|
451 { |
|
452 switch ( aEnum ) |
|
453 { |
|
454 case EMessageFlowSettingLevel: |
|
455 { |
|
456 return KDefaultMessageFlowSettingLevel; |
|
457 } |
|
458 case EFriendsListOrdering : |
|
459 { |
|
460 return EAlphabetical; |
|
461 } |
|
462 default: |
|
463 { |
|
464 // Default default value will be zero for integers |
|
465 return 0; |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------- |
|
471 // CCASettingsManager::DefaultBooleanValue |
|
472 // --------------------------------------------------------- |
|
473 // |
|
474 TBool CCASettingsManager::DefaultBooleanValue( TInt aEnum ) const |
|
475 { |
|
476 switch ( aEnum ) |
|
477 { |
|
478 case EFirstLoginDone: |
|
479 { |
|
480 return KDefaultFirstLoginDone; |
|
481 } |
|
482 case EDefaultScreenNameInUse: |
|
483 { |
|
484 return KDefaultDefaultScreenNameInUse; |
|
485 } |
|
486 case EAutomaticPresenceUpdate: |
|
487 { |
|
488 return KDefaultAutomaticPresenceUpdate; |
|
489 } |
|
490 case EUpdateSelectedContacts: |
|
491 { |
|
492 return KDefaultUpdateSelectedContacts; |
|
493 } |
|
494 case EShowHistory: |
|
495 { |
|
496 return KDefaultShowHistory; |
|
497 } |
|
498 case EShowOffline: |
|
499 { |
|
500 return KDefaultShowOffline; |
|
501 } |
|
502 case EShowTimeStamps: |
|
503 { |
|
504 return KDefaultShowTimeStamps; |
|
505 } |
|
506 |
|
507 default: |
|
508 { |
|
509 return EFalse; |
|
510 } |
|
511 } |
|
512 } |
|
513 |
|
514 // --------------------------------------------------------- |
|
515 // CCASettingsManager::ConvertSettingInteger |
|
516 // --------------------------------------------------------- |
|
517 // |
|
518 const TDesC& CCASettingsManager::ConvertSettingInteger( TInt aEnum ) const |
|
519 { |
|
520 switch ( aEnum ) |
|
521 { |
|
522 // TCASettingFlags |
|
523 case EFirstLoginDone: |
|
524 { |
|
525 return KCAFirstLoginDone(); |
|
526 } |
|
527 case EDefaultScreenNameInUse: |
|
528 { |
|
529 return KCADefaultScreenNameInUse(); |
|
530 } |
|
531 case EAutomaticPresenceUpdate: |
|
532 { |
|
533 return KCAAutomaticPresenceUpdate(); |
|
534 } |
|
535 case EUpdateSelectedContacts: |
|
536 { |
|
537 return KCAUpdateSelectedContacts(); |
|
538 } |
|
539 case EShowHistory: |
|
540 { |
|
541 return KCAShowHistory(); |
|
542 } |
|
543 case EShowOffline: |
|
544 { |
|
545 return KCAShowOffline(); |
|
546 } |
|
547 case EShowTimeStamps: |
|
548 { |
|
549 return KCAShowTimeStamps(); |
|
550 } |
|
551 |
|
552 // TCASettingIntegers |
|
553 case EAuthorizeIMPresence: |
|
554 { |
|
555 return KCAAuthIMPr(); |
|
556 } |
|
557 case EReceiveIMessages: |
|
558 { |
|
559 return KCAReceiveIMessages(); |
|
560 } |
|
561 case EReceiveInvitations: |
|
562 { |
|
563 return KCAReceiveInvitations(); |
|
564 } |
|
565 case EMessageFlowSettingLevel: |
|
566 { |
|
567 return KCAMsgFlow(); |
|
568 } |
|
569 case EFriendsListOrdering: |
|
570 { |
|
571 return KCAFriendsListOrdering(); |
|
572 } |
|
573 |
|
574 // TCASettingStrings |
|
575 case EDefaultScreenName: |
|
576 { |
|
577 return KCADefaultNick(); |
|
578 } |
|
579 case EOwnAlias: |
|
580 { |
|
581 return KCAOwnAlias(); |
|
582 } |
|
583 case EOwnWVUserID: // flowthrough |
|
584 case EServiceAddress: |
|
585 case EStatusMsgOnline: |
|
586 case EStatusMsgAway: |
|
587 case EStatusMsgBusy: |
|
588 { |
|
589 // these will be saved to cenrep currently |
|
590 // as we don't have to support multiple |
|
591 // connections |
|
592 return KNullDesC(); |
|
593 } |
|
594 |
|
595 default: |
|
596 { |
|
597 // shouldn't be here |
|
598 __CHAT_ASSERT_DEBUG( EFalse ); |
|
599 return KNullDesC(); |
|
600 } |
|
601 } |
|
602 } |
|
603 |
|
604 // --------------------------------------------------------- |
|
605 // CCASettingsManager::GetSAPLC |
|
606 // --------------------------------------------------------- |
|
607 // |
|
608 CIMPSSAPSettings* CCASettingsManager::GetSAPLC( CIMPSSAPSettings* aSap ) |
|
609 { |
|
610 if ( aSap ) |
|
611 { |
|
612 CIMPSSAPSettingsList* sapList = |
|
613 CIMPSSAPSettingsList::NewLC(); |
|
614 iSapSettingsStore->PopulateSAPSettingsListL( *sapList, |
|
615 EIMPSIMAccessGroup ); |
|
616 // update information that welcome note was shown, |
|
617 // and find our sap... because logged in SAP |
|
618 // has UID of zero, we must find the correct UID |
|
619 // manually from list |
|
620 TInt index( KErrNotFound ); |
|
621 TInt err = sapList->FindNameL( aSap->SAPName(), index ); |
|
622 |
|
623 // err would be zero if found else err may be any non zero value |
|
624 CIMPSSAPSettings* storedSap = NULL; |
|
625 if ( index != KErrNotFound && err == KErrNone ) |
|
626 { |
|
627 // found it, update the correct sap |
|
628 storedSap = CIMPSSAPSettings::NewLC(); |
|
629 |
|
630 TUint32 sapUid = sapList->UidForIndex( index ); |
|
631 iSapSettingsStore->GetSAPL( sapUid, storedSap ); |
|
632 CleanupStack::Pop( storedSap ); |
|
633 } |
|
634 CleanupStack::PopAndDestroy( sapList ); |
|
635 CleanupStack::PushL( storedSap ); |
|
636 return storedSap; |
|
637 } |
|
638 else |
|
639 { |
|
640 #ifdef RD_SETTINGS_FACELIFT |
|
641 if ( iDefaultSap ) |
|
642 { |
|
643 CIMPSSAPSettings* sap = GetSAPLC( iDefaultSap ); |
|
644 return sap; |
|
645 } |
|
646 else |
|
647 { |
|
648 CleanupStack::PushL( static_cast<CBase*>( NULL ) ); |
|
649 return NULL; |
|
650 } |
|
651 #else |
|
652 CleanupStack::PushL( static_cast<CBase*>( NULL ) ); |
|
653 return NULL; |
|
654 #endif //RD_SETTINGS_FACELIFT |
|
655 } |
|
656 } |
|
657 |
|
658 // --------------------------------------------------------- |
|
659 // CCASettingsManager::StoreL |
|
660 // --------------------------------------------------------- |
|
661 // |
|
662 void CCASettingsManager::StoreL( CIMPSSAPSettings* aSap, |
|
663 TInt aSetting, |
|
664 TInt aValue ) |
|
665 { |
|
666 TBool ok( EFalse ); |
|
667 if ( aSap ) |
|
668 { |
|
669 CIMPSSAPSettingsList* sapList = |
|
670 CIMPSSAPSettingsList::NewLC(); |
|
671 iSapSettingsStore->PopulateSAPSettingsListL( *sapList, |
|
672 EIMPSIMAccessGroup ); |
|
673 // Because logged in SAP hs UID of zero, |
|
674 // we must find the correct UID manually from list |
|
675 TInt index( KErrNotFound ); |
|
676 sapList->FindNameL( aSap->SAPName(), index ); |
|
677 if ( index == KErrNotFound ) |
|
678 { |
|
679 User::Leave( index ); |
|
680 } |
|
681 |
|
682 if ( index != KErrNotFound ) |
|
683 { |
|
684 // found it, update the correct sap |
|
685 CIMPSSAPSettings* storedSap = |
|
686 CIMPSSAPSettings::NewLC(); |
|
687 |
|
688 TUint32 sapUid = sapList->UidForIndex( index ); |
|
689 iSapSettingsStore->GetSAPL( sapUid, storedSap ); |
|
690 |
|
691 TPtrC settingName( ConvertSettingInteger( aSetting ) ); |
|
692 if ( settingName.Length() > 0 ) |
|
693 { |
|
694 storedSap->SetOpaqueInt( settingName, aValue ); |
|
695 // update sap |
|
696 iSapSettingsStore->UpdateOldSAPL( storedSap, sapUid ); |
|
697 ok = ETrue; |
|
698 } |
|
699 |
|
700 CleanupStack::PopAndDestroy( storedSap ); |
|
701 } |
|
702 CleanupStack::PopAndDestroy( sapList ); |
|
703 } |
|
704 |
|
705 if ( !ok ) |
|
706 { |
|
707 // not saved to SAP, use cenrep |
|
708 User::LeaveIfError( iSDCRVariator->SetInt( aSetting, aValue ) ); |
|
709 } |
|
710 } |
|
711 |
|
712 // --------------------------------------------------------- |
|
713 // CCASettingsManager::StoreL |
|
714 // --------------------------------------------------------- |
|
715 // |
|
716 void CCASettingsManager::StoreL( CIMPSSAPSettings* aSap, |
|
717 TInt aSetting, |
|
718 const TDesC& aValue ) |
|
719 { |
|
720 TBool ok( EFalse ); |
|
721 if ( aSap ) |
|
722 { |
|
723 CIMPSSAPSettingsList* sapList = |
|
724 CIMPSSAPSettingsList::NewLC(); |
|
725 iSapSettingsStore->PopulateSAPSettingsListL( *sapList, |
|
726 EIMPSIMAccessGroup ); |
|
727 // Because logged in SAP hs UID of zero, |
|
728 // we must find the correct UID manually from list |
|
729 TInt index( KErrNotFound ); |
|
730 sapList->FindNameL( aSap->SAPName(), index ); |
|
731 if ( index == KErrNotFound ) |
|
732 { |
|
733 User::Leave( index ); |
|
734 } |
|
735 |
|
736 if ( index != KErrNotFound ) |
|
737 { |
|
738 // found it, update the correct sap |
|
739 CIMPSSAPSettings* storedSap = |
|
740 CIMPSSAPSettings::NewLC(); |
|
741 |
|
742 TUint32 sapUid = sapList->UidForIndex( index ); |
|
743 iSapSettingsStore->GetSAPL( sapUid, storedSap ); |
|
744 |
|
745 TPtrC settingName( ConvertSettingInteger( aSetting ) ); |
|
746 if ( settingName.Length() > 0 ) |
|
747 { |
|
748 storedSap->SetOpaqueDesC16( settingName, aValue ); |
|
749 // update sap |
|
750 iSapSettingsStore->UpdateOldSAPL( storedSap, sapUid ); |
|
751 ok = ETrue; |
|
752 } |
|
753 CleanupStack::PopAndDestroy( storedSap ); |
|
754 } |
|
755 CleanupStack::PopAndDestroy( sapList ); |
|
756 } |
|
757 |
|
758 if ( !ok ) |
|
759 { |
|
760 // not saved to SAP, use cenrep |
|
761 User::LeaveIfError( iSDCRVariator->SetString( aSetting, aValue ) ); |
|
762 } |
|
763 } |
|
764 |
|
765 // --------------------------------------------------------- |
|
766 // CCASettingsManager::SetDefaultSapL |
|
767 // --------------------------------------------------------- |
|
768 // |
|
769 void CCASettingsManager::SetDefaultSapL( CIMPSSAPSettings* aSap ) |
|
770 { |
|
771 CIMPSSAPSettings* tempSap = GetSAPLC( aSap ); |
|
772 CleanupStack::Pop( tempSap ); |
|
773 delete iDefaultSap; |
|
774 iDefaultSap = tempSap; |
|
775 } |
|
776 |
|
777 // --------------------------------------------------------- |
|
778 // CCASettingsManager::OwnAliasL() |
|
779 // --------------------------------------------------------- |
|
780 // |
|
781 HBufC* CCASettingsManager::OwnAliasL() |
|
782 { |
|
783 CHAT_DP_FUNC_ENTER( "CCASettingsManager::OwnAliasL" ); |
|
784 |
|
785 // Read aliasdata from SAP settings |
|
786 CIMPSSAPSettings* sap = GetSAPLC( NULL ); |
|
787 if ( !sap ) |
|
788 { |
|
789 User::Leave( KErrNotReady ); |
|
790 } |
|
791 TPtrC settingName( ConvertSettingInteger( MCASettings::EOwnAlias ) ); |
|
792 TPtrC alias( KNullDesC ); |
|
793 |
|
794 // aliasTable has all different aliases for each userID |
|
795 // format [userID]\x10[Alias]\0x11[userID]\x10[Alias],... |
|
796 if ( sap->GetOpaqueDesC16( settingName, alias ) != KErrNone ) |
|
797 { |
|
798 alias.Set( KNullDesC ); |
|
799 } |
|
800 |
|
801 // current user ID |
|
802 HBufC* userId = ValueL( MCASettings::EOwnWVUserID ); |
|
803 CleanupStack::PushL( userId ); |
|
804 |
|
805 TInt index = KErrNotFound; |
|
806 TInt length = 0; |
|
807 LocateAliasL( alias, *userId, index, length ); |
|
808 |
|
809 HBufC* ret = NULL; // if not found -> NULL |
|
810 if ( index != KErrNotFound ) |
|
811 { |
|
812 // Alias found |
|
813 ret = alias.Mid( index, length ).AllocL(); |
|
814 } |
|
815 |
|
816 CleanupStack::PopAndDestroy( 2, sap ); // sap, userId |
|
817 CHAT_DP_FUNC_DONE( "CCASettingsManager::OwnAliasL" ); |
|
818 return ret; // NULL or ALIAS |
|
819 } |
|
820 |
|
821 // --------------------------------------------------------- |
|
822 // CCASettingsManager::SetOwnAliasL() |
|
823 // --------------------------------------------------------- |
|
824 // |
|
825 void CCASettingsManager::SetOwnAliasL( const TDesC& aAlias ) |
|
826 { |
|
827 CHAT_DP_FUNC_ENTER( "CCASettingsManager::SetOwnAliasL" ); |
|
828 |
|
829 // Read aliasdata from SAP settings |
|
830 CIMPSSAPSettings* sap = GetSAPLC( NULL ); |
|
831 if ( !sap ) |
|
832 { |
|
833 User::Leave( KErrNotReady ); |
|
834 } |
|
835 TPtrC settingName( ConvertSettingInteger( MCASettings::EOwnAlias ) ); |
|
836 TPtrC aliases( KNullDesC ); |
|
837 |
|
838 // aliasTable has all different aliases for each userID |
|
839 // format [userID]\x10[Alias]\0x11[userID]\x10[Alias],... |
|
840 if ( sap->GetOpaqueDesC16( settingName, aliases ) != KErrNone ) |
|
841 { |
|
842 aliases.Set( KNullDesC ); |
|
843 } |
|
844 |
|
845 // current user ID |
|
846 HBufC* userId = ValueL( MCASettings::EOwnWVUserID ); |
|
847 CleanupStack::PushL( userId ); |
|
848 |
|
849 // Search for alias |
|
850 TInt index = KErrNotFound; |
|
851 TInt length = 0; |
|
852 LocateAliasL( aliases, *userId, index, length ); |
|
853 |
|
854 HBufC* newAliasBuf = NULL; |
|
855 if ( index == KErrNotFound ) |
|
856 { |
|
857 // Alias not found -> Append to table. |
|
858 newAliasBuf = HBufC::NewLC( aliases.Length() + |
|
859 userId->Length() + |
|
860 aAlias.Length() + |
|
861 KSeparatorSize * 2 ); |
|
862 TPtr newAliases( newAliasBuf->Des() ); |
|
863 newAliases.Set( newAliasBuf->Des() ); |
|
864 newAliases.Copy( aliases ); |
|
865 if ( newAliases.Length() > 0 ) |
|
866 { |
|
867 // only add separator if this is not the first alias |
|
868 newAliases.Append( TChar( KAliasTableSeparator ) ); |
|
869 } |
|
870 newAliases.Append( *userId ); |
|
871 newAliases.Append( TChar( KAliasItemSeparator ) ); |
|
872 |
|
873 index = newAliases.Length(); |
|
874 length = aAlias.Length(); |
|
875 newAliases.Append( aAlias ); |
|
876 } |
|
877 else |
|
878 { |
|
879 // Alias Found -> Replace in table. |
|
880 newAliasBuf = HBufC::NewLC( aliases.Length() + |
|
881 aAlias.Length() ); |
|
882 TPtr newAliases( newAliasBuf->Des() ); |
|
883 newAliases.Set( newAliasBuf->Des() ); |
|
884 newAliases.Copy( aliases ); |
|
885 newAliases.Replace( index, length, aAlias ); |
|
886 } |
|
887 |
|
888 // Trim new data to fit into SAP settings |
|
889 TPtr data( newAliasBuf->Des() ); |
|
890 TInt findPos = 0; |
|
891 while ( data.Length() > KMaxAliasDataLength ) |
|
892 { |
|
893 TInt pos = data.Mid( findPos ).Locate( TChar( KAliasTableSeparator ) ) + 1; |
|
894 TBool nonRemovable = ( findPos < index ) && ( index < findPos + pos ); |
|
895 if ( pos != KErrNotFound ) |
|
896 { |
|
897 if ( !nonRemovable ) |
|
898 { |
|
899 // this is not the newly updated alias -> remove it |
|
900 data.Delete( findPos, pos ); |
|
901 if ( index > findPos ) |
|
902 { |
|
903 index -= pos; |
|
904 } |
|
905 } |
|
906 else |
|
907 { |
|
908 // could not delete -> continue from new pos |
|
909 findPos += pos; |
|
910 } |
|
911 } |
|
912 else |
|
913 { |
|
914 // last item. We have to remove something to fit data into |
|
915 // settings! |
|
916 TInt delLen = data.Mid( findPos ).Length(); |
|
917 if ( delLen == 0 ) |
|
918 { |
|
919 // If we end up here, it means we have already deleted |
|
920 // everything we can. All we can do now is to clear the whole |
|
921 // data and break out. This means we don't define Alias. |
|
922 // This case is only possible if userId and Alias exceeds the |
|
923 // capasity of SAP setting store. |
|
924 // |
|
925 __CHAT_ASSERT_DEBUG( ETrue ); |
|
926 data.Zero(); |
|
927 break; |
|
928 } |
|
929 data.Delete( findPos, delLen ); |
|
930 } |
|
931 } |
|
932 |
|
933 // Write to store |
|
934 StoreL( sap, MCASettings::EOwnAlias, *newAliasBuf ); |
|
935 |
|
936 CleanupStack::PopAndDestroy( 3, sap ); // sap, userId, newAliasBuf |
|
937 CHAT_DP_FUNC_DONE( "CCASettingsManager::SetOwnAliasL" ); |
|
938 } |
|
939 |
|
940 // --------------------------------------------------------- |
|
941 // CCASettingsManager::LocateAliasL() |
|
942 // --------------------------------------------------------- |
|
943 // |
|
944 void CCASettingsManager::LocateAliasL( const TDesC& aAliasTable, |
|
945 const TDesC& aUserId, |
|
946 TInt& aIndex, |
|
947 TInt& aLength ) |
|
948 { |
|
949 CHAT_DP_TXT( "Finding alias from setting table..." ); |
|
950 aIndex = KErrNotFound; |
|
951 aLength = 0; |
|
952 if ( aAliasTable.Length() == 0 || aUserId.Length() == 0 ) |
|
953 { |
|
954 // nothing to search! |
|
955 return; |
|
956 } |
|
957 |
|
958 HBufC* findPattern = HBufC::NewLC( aUserId.Length() + |
|
959 KSeparatorSize ); |
|
960 TPtr find( findPattern->Des() ); |
|
961 find.Copy( aUserId ); |
|
962 TInt len = find.Length(); |
|
963 find.Append( TChar( KAliasItemSeparator ) ); |
|
964 TInt len2 = find.Length(); |
|
965 |
|
966 aIndex = aAliasTable.Find( find ); |
|
967 if ( aIndex == KErrNotFound ) |
|
968 { |
|
969 // not found |
|
970 CHAT_DP_TXT( "...Alias not found" ); |
|
971 CleanupStack::PopAndDestroy( findPattern ); |
|
972 return; |
|
973 } |
|
974 |
|
975 // found it, get length |
|
976 aIndex += find.Length(); |
|
977 TPtrC rest( aAliasTable.Mid( aIndex ) ); |
|
978 aLength = rest.Locate( TChar( KAliasTableSeparator ) ); |
|
979 if ( aLength == KErrNotFound ) |
|
980 { |
|
981 // this was last item |
|
982 aLength = rest.Length(); |
|
983 } |
|
984 CleanupStack::PopAndDestroy( findPattern ); |
|
985 CHAT_DP( D_CHAT_LIT( "...Alias found at pos:%d length:%d" ), |
|
986 aIndex, aLength ); |
|
987 return; |
|
988 } |
|
989 |
|
990 // End of File |