|
1 /* |
|
2 * Copyright (c) 2002-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: Application settings SAP settings extension |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCAAppSettingsSAPExt.h" |
|
22 #include "ChatDefinitions.h" |
|
23 #include "ChatDebugPrint.h" |
|
24 |
|
25 #include <cimpspresenceconnectionuing.h> |
|
26 #include <CIMPSSAPSettingsStore.h> |
|
27 #include <CIMPSSAPSettings.h> |
|
28 #include <CIMPSSAPSettingsList.h> |
|
29 #include <CPEngNWSessionSlotID2.h> |
|
30 #include <PathInfo.h> |
|
31 #include <bautils.h> |
|
32 #include <eikenv.h> |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 //Removed the ownership of iConnUI from this file and made it a reference |
|
37 //APPUI owns this connection UI instance and shares the same with this component. |
|
38 |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CCAAppSettingsSAPExt::CCAAppSettingsSAPExt |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CCAAppSettingsSAPExt::CCAAppSettingsSAPExt( CIMPSPresenceConnectionUi& aConnUi, |
|
47 TBool aPreserveSessionIdInExit ) |
|
48 : iConnUI( aConnUi ), |
|
49 iPreserveSessionIdInExit( aPreserveSessionIdInExit ) |
|
50 { |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCAAppSettingsSAPExt::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CCAAppSettingsSAPExt::ConstructL( CIMPSSAPSettings* aSap ) |
|
59 { |
|
60 iSapSettings = CIMPSSAPSettingsStore::NewL(); |
|
61 iSap = aSap; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CCAAppSettingsSAPExt::NewL |
|
66 // Two-phased constructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CCAAppSettingsSAPExt* CCAAppSettingsSAPExt::NewL( CIMPSPresenceConnectionUi& aConnUi, |
|
70 TBool aPreserveSessionIdInExit /* = EFalse */, |
|
71 CIMPSSAPSettings* aSap /* = NULL */ ) |
|
72 |
|
73 { |
|
74 CCAAppSettingsSAPExt* self = CCAAppSettingsSAPExt::NewLC( aConnUi, |
|
75 aPreserveSessionIdInExit, aSap ); |
|
76 |
|
77 CleanupStack::Pop(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CCAAppSettingsSAPExt::NewLC |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CCAAppSettingsSAPExt* CCAAppSettingsSAPExt::NewLC( CIMPSPresenceConnectionUi& aConnUi, |
|
87 TBool aPreserveSessionIdInExit /* = EFalse */, |
|
88 CIMPSSAPSettings* aSap /* = NULL */ ) |
|
89 { |
|
90 CCAAppSettingsSAPExt* self = new( ELeave ) CCAAppSettingsSAPExt( aConnUi, |
|
91 aPreserveSessionIdInExit ); |
|
92 CleanupStack::PushL( self ); |
|
93 self->ConstructL( aSap ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 // Destructor |
|
99 // CodeScanner warning ignored because HandleApplicationExitL |
|
100 // needs to be called to keep connection alive. |
|
101 // Otherwise destroying iConnUI would close the connection. |
|
102 CCAAppSettingsSAPExt::~CCAAppSettingsSAPExt() // CSI: 23 # See comment above |
|
103 { |
|
104 if ( iPreserveSessionIdInExit ) |
|
105 { |
|
106 TRAPD( err, |
|
107 { |
|
108 // this class was invoked from IM Launcher call chain, |
|
109 // when Always Online is active. now make sure the IMPSCUI |
|
110 // Session Id is given to an instance existing in Always Online |
|
111 // (otherwise it'll be deleted and logout will happen) |
|
112 CPEngNWSessionSlotID2* sessionSlotID = |
|
113 iConnUI.GetActiveNWSessionSlotIDL( EIMPSConnClientIM ); |
|
114 CleanupStack::PushL( sessionSlotID ); |
|
115 iConnUI.HandleApplicationExitL( EIMPSConnClientIM, |
|
116 EIMPSLeaveSessionOpenExit, |
|
117 *sessionSlotID ); |
|
118 CleanupStack::PopAndDestroy( sessionSlotID ); |
|
119 } ); // TRAPD |
|
120 |
|
121 if ( err != KErrNone ) |
|
122 { |
|
123 CActiveScheduler::Current()->Error( err ); |
|
124 } |
|
125 // now it's safe to exit even in Always Online case |
|
126 } |
|
127 |
|
128 delete iSapSettings; |
|
129 } |
|
130 |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CCAAppSettingsSAPExt::SetIntValueL |
|
134 // Sets int value to SAP settings |
|
135 // (other items were commented in a header). |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CCAAppSettingsSAPExt::SetIntValueL( const TDesC& aKey, TInt aValue ) |
|
139 { |
|
140 CHAT_DP_TXT( "CCAAppSettingsSAPExt::SetIntValueL" ); |
|
141 CIMPSSAPSettings* sap = NULL; |
|
142 if ( !iSap ) |
|
143 { |
|
144 sap = StoredSAPLC(); |
|
145 } |
|
146 else |
|
147 { |
|
148 sap = iSap; |
|
149 } |
|
150 if ( sap ) |
|
151 { |
|
152 TInt id( sap->Uid() ); |
|
153 CHAT_DP( D_CHAT_LIT( "found sap (%d), setting value %d" ), id, aValue ); |
|
154 sap->SetOpaqueInt( aKey, aValue ); |
|
155 |
|
156 // update sap |
|
157 iSapSettings->UpdateOldSAPL( sap, id ); |
|
158 if ( !iSap ) |
|
159 { |
|
160 CleanupStack::PopAndDestroy( sap ); |
|
161 } |
|
162 } |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CCAAppSettingsSAPExt::IntValueL |
|
167 // Gets int value from SAP settings |
|
168 // (other items were commented in a header). |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TInt CCAAppSettingsSAPExt::IntValueL( const TDesC& aKey ) |
|
172 { |
|
173 CHAT_DP_TXT( "CCAAppSettingsSAPExt::IntValueL" ); |
|
174 TInt ret( KErrNotFound ); |
|
175 CIMPSSAPSettings* sap = NULL; |
|
176 if ( !iSap ) |
|
177 { |
|
178 sap = StoredSAPLC(); |
|
179 } |
|
180 else |
|
181 { |
|
182 sap = iSap; |
|
183 } |
|
184 if ( sap ) |
|
185 { |
|
186 #ifdef _DEBUG |
|
187 TInt id( sap->Uid() ); |
|
188 CHAT_DP( D_CHAT_LIT( "found sap (%d), getting value.." ), id ); |
|
189 #endif//_DEBUG |
|
190 sap->GetOpaqueInt( aKey, ret ); |
|
191 if ( !iSap ) |
|
192 { |
|
193 CleanupStack::PopAndDestroy( sap ); |
|
194 } |
|
195 } |
|
196 CHAT_DP( D_CHAT_LIT( "value %d" ), ret ); |
|
197 return ret; |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CCAAppSettingsSAPExt::SetToneFileNameL |
|
202 // (other items were commented in a header). |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CCAAppSettingsSAPExt::SetToneFileNameL( const TDesC& aToneFileName ) |
|
206 { |
|
207 CIMPSSAPSettings* sap = NULL; |
|
208 if ( !iSap ) |
|
209 { |
|
210 sap = StoredSAPLC(); |
|
211 } |
|
212 else |
|
213 { |
|
214 sap = iSap; |
|
215 } |
|
216 |
|
217 // populate the list of sapsettings |
|
218 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
219 iSapSettings->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
220 |
|
221 // and find our sap.. because logged in SAP has UID of zero, we must |
|
222 // find the correct UID manually from list |
|
223 TInt index( KErrNotFound ); |
|
224 sapList->FindNameL( sap->SAPName(), index ); |
|
225 |
|
226 if ( index != KErrNotFound ) |
|
227 { |
|
228 // found it, update the correct sap |
|
229 CIMPSSAPSettings* storedSap = CIMPSSAPSettings::NewLC(); |
|
230 |
|
231 TUint32 sapUid = sapList->UidForIndex( index ); |
|
232 iSapSettings->GetSAPL( sapUid, storedSap ); |
|
233 storedSap->SetOpaqueDesC16( KIMAlertTonePath(), aToneFileName ); |
|
234 iSapSettings->UpdateOldSAPL( storedSap, sapUid ); |
|
235 CleanupStack::PopAndDestroy( storedSap ); |
|
236 } |
|
237 if ( !iSap ) |
|
238 { |
|
239 CleanupStack::PopAndDestroy( 2, sap ); |
|
240 } |
|
241 else |
|
242 { |
|
243 CleanupStack::PopAndDestroy( sapList ); |
|
244 } |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CCAAppSettingsSAPExt::GetToneFileNameL |
|
249 // (other items were commented in a header). |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CCAAppSettingsSAPExt::GetToneFileNameL( TDes& aToneFileName ) |
|
253 { |
|
254 CIMPSSAPSettings* sap = NULL; |
|
255 if ( !iSap ) |
|
256 { |
|
257 sap = StoredSAPLC(); |
|
258 } |
|
259 else |
|
260 { |
|
261 sap = iSap; |
|
262 } |
|
263 |
|
264 // populate the list of sapsettings |
|
265 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
266 iSapSettings->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
267 |
|
268 // and find our sap.. because logged in SAP has UID of zero, we must |
|
269 // find the correct UID manually from list |
|
270 TInt index( KErrNotFound ); |
|
271 sapList->FindNameL( sap->SAPName(), index ); |
|
272 |
|
273 if ( index != KErrNotFound ) |
|
274 { |
|
275 // found it, update the correct sap |
|
276 CIMPSSAPSettings* storedSap = CIMPSSAPSettings::NewLC(); |
|
277 iSapSettings->GetSAPL( sapList->UidForIndex( index ), storedSap ); |
|
278 |
|
279 TPtrC audioPath; |
|
280 storedSap->GetOpaqueDesC16( KIMAlertTonePath(), audioPath ); |
|
281 aToneFileName.Copy( audioPath.Left( aToneFileName.MaxLength() ) ); |
|
282 CleanupStack::PopAndDestroy( storedSap ); |
|
283 } |
|
284 else |
|
285 { |
|
286 aToneFileName.Copy( KNullDesC() ); |
|
287 } |
|
288 |
|
289 if ( !iSap ) |
|
290 { |
|
291 CleanupStack::PopAndDestroy( 2, sap ); |
|
292 } |
|
293 else |
|
294 { |
|
295 CleanupStack::PopAndDestroy( sapList ); |
|
296 } |
|
297 } |
|
298 |
|
299 |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CCAAppSettingsSAPExt::StoredSAPLC |
|
303 // Gets editable stored SAP |
|
304 // (other items were commented in a header). |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 CIMPSSAPSettings* CCAAppSettingsSAPExt::StoredSAPLC() |
|
308 { |
|
309 CIMPSSAPSettings* sap = CIMPSSAPSettings::NewLC(); |
|
310 |
|
311 TBool isLoggedIn( EFalse ); |
|
312 |
|
313 TInt err; |
|
314 TRAP( err, isLoggedIn = iConnUI.LoggedInL( EIMPSConnClientIM ) ); |
|
315 |
|
316 if ( isLoggedIn ) |
|
317 { |
|
318 CPEngNWSessionSlotID2* sessionSlotId = |
|
319 iConnUI.GetActiveNWSessionSlotIDL( EIMPSConnClientIM ); |
|
320 CleanupStack::PushL( sessionSlotId ); |
|
321 iConnUI.GetLoggedInSapL( *sessionSlotId, *sap ); |
|
322 |
|
323 // populate the list of sapsettings |
|
324 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
325 iSapSettings->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
326 |
|
327 // and find our sap.. because logged in SAP has UID of zero, we must |
|
328 // find the correct UID manually from list |
|
329 TInt index( KErrNotFound ); |
|
330 TPtrC name( sap->SAPName() ); |
|
331 CHAT_DP( D_CHAT_LIT( "logged to to %S, trying to find sap" ), &name ); |
|
332 sapList->FindNameL( name, index ); |
|
333 |
|
334 if ( index != KErrNotFound ) |
|
335 { |
|
336 CHAT_DP( D_CHAT_LIT( "found it in index %d" ), index ); |
|
337 // found it, update the correct sap |
|
338 CIMPSSAPSettings* storedSap = CIMPSSAPSettings::NewLC(); |
|
339 iSapSettings->GetSAPL( sapList->UidForIndex( index ), storedSap ); |
|
340 CleanupStack::Pop( storedSap ); |
|
341 CleanupStack::PopAndDestroy( 3, sap ); // sapList, sessionslot, sap |
|
342 CleanupStack::PushL( storedSap ); |
|
343 sap = storedSap; |
|
344 } |
|
345 else |
|
346 { |
|
347 CHAT_DP( D_CHAT_LIT( "not found" ) ); |
|
348 CleanupStack::PopAndDestroy( 3, sap ); // sapList, sessionSlotId, sap |
|
349 return NULL; |
|
350 } |
|
351 } |
|
352 else if ( iSapSettings ) |
|
353 { |
|
354 iSapSettings->GetDefaultL( sap, EIMPSIMAccessGroup ); |
|
355 } |
|
356 |
|
357 return sap; |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CCAAppSettingsSAPExt::CurrentSAPLC |
|
362 // (other items were commented in a header). |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 CIMPSSAPSettings* CCAAppSettingsSAPExt::CurrentSAPLC() |
|
366 { |
|
367 CIMPSSAPSettings* sap = CIMPSSAPSettings::NewLC(); |
|
368 |
|
369 TBool isLoggedIn( EFalse ); |
|
370 TInt err; |
|
371 TRAP( err, isLoggedIn = iConnUI.LoggedInL( EIMPSConnClientIM ) ); |
|
372 |
|
373 if ( isLoggedIn ) |
|
374 { |
|
375 CPEngNWSessionSlotID2* sessionSlotId = iConnUI.GetActiveNWSessionSlotIDL( EIMPSConnClientIM ); |
|
376 CleanupStack::PushL( sessionSlotId ); |
|
377 iConnUI.GetLoggedInSapL( *sessionSlotId, *sap ); |
|
378 CleanupStack::PopAndDestroy( sessionSlotId ); |
|
379 } |
|
380 else |
|
381 { |
|
382 iSapSettings->GetDefaultL( sap, EIMPSIMAccessGroup ); |
|
383 } |
|
384 return sap; |
|
385 } |
|
386 |
|
387 // End of File |