23 #include "mussettings.inl" |
23 #include "mussettings.inl" |
24 #include <aknnotewrappers.h> |
24 #include <aknnotewrappers.h> |
25 #include <StringLoader.h> |
25 #include <StringLoader.h> |
26 #include <aknview.h> |
26 #include <aknview.h> |
27 #include <sipmanagedprofileregistry.h> |
27 #include <sipmanagedprofileregistry.h> |
|
28 #include <sipmanagedprofile.h> |
28 #include <sipprofileregistry.h> |
29 #include <sipprofileregistry.h> |
29 |
30 #include "mussettingsmodel.h" |
30 |
31 |
31 const TInt KSIPGranularity = 5; |
32 |
32 const TInt KUnknownProfileId = 0; |
33 const TInt KUnknownProfileId = 0; |
33 |
34 |
34 /** |
35 /** |
35 * VSC Enable/Disable is of type TBool |
36 * VSC Enable/Disable is of type TBool |
36 */ |
37 */ |
38 |
39 |
39 |
40 |
40 // ======== MEMBER FUNCTIONS ======== |
41 // ======== MEMBER FUNCTIONS ======== |
41 |
42 |
42 |
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
43 CMusSIPProfileModel::CMusSIPProfileModel() |
48 CMusSIPProfileModel::CMusSIPProfileModel() |
44 { |
49 { |
45 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::CMusSIPProfileModel()" ) |
50 } |
46 } |
51 |
47 |
52 // ---------------------------------------------------------------------------- |
48 |
53 // |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
49 void CMusSIPProfileModel::ConstructL() |
56 void CMusSIPProfileModel::ConstructL() |
50 { |
57 { |
51 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ConstructL()" ) |
58 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ConstructL()" ) |
52 iEngine = CSIPManagedProfileRegistry::NewL( *this ); |
59 iEngine = CSIPManagedProfileRegistry::NewL( *this ); |
53 ReadArrayFromEngineL(); |
60 iEngine->ProfilesL( iProfiles ); |
54 } |
61 SortProfilesL(); |
55 |
62 } |
56 |
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
57 CMusSIPProfileModel* CMusSIPProfileModel::NewL() |
68 CMusSIPProfileModel* CMusSIPProfileModel::NewL() |
58 { |
69 { |
59 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::NewL()" ) |
70 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::NewL()" ) |
60 CMusSIPProfileModel* self = new( ELeave ) CMusSIPProfileModel(); |
71 CMusSIPProfileModel* self = new( ELeave ) CMusSIPProfileModel(); |
61 |
72 |
65 |
76 |
66 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::NewL()" ) |
77 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::NewL()" ) |
67 return self; |
78 return self; |
68 } |
79 } |
69 |
80 |
70 |
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
71 CMusSIPProfileModel::~CMusSIPProfileModel() |
85 CMusSIPProfileModel::~CMusSIPProfileModel() |
72 { |
86 { |
73 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
87 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
74 DeleteProfiles(); |
88 iProfiles.ResetAndDestroy(); |
75 delete iEngine; |
89 delete iEngine; |
76 iEngine = NULL; |
|
77 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
90 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
78 } |
91 } |
79 |
92 |
80 |
93 // ---------------------------------------------------------------------------- |
81 // ---------------------------------------------------------------------------- |
94 // Returns reference to the locally cached SIP profile array. |
82 // Returns pointer to the locally cached SIP profile array. |
95 // ---------------------------------------------------------------------------- |
83 // ---------------------------------------------------------------------------- |
96 // |
84 // |
97 RPointerArray<CSIPProfile>& CMusSIPProfileModel::ProfileArrayL() |
85 CArrayPtr<CSIPManagedProfile>* CMusSIPProfileModel::ProfileArrayL() |
98 { |
86 { |
99 MUS_LOG( "[MUSSET] <-> CMusSIPProfileModel::ProfileArrayL()" ) |
87 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileArrayL()" ) |
|
88 ReadProfileListFromEngineSafeL(); |
|
89 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileArrayL()" ) |
|
90 return iProfiles; |
100 return iProfiles; |
91 } |
101 } |
92 |
|
93 |
102 |
94 // ---------------------------------------------------------------------------- |
103 // ---------------------------------------------------------------------------- |
95 // Returns index to the default SIP profile in locally cached array. |
104 // Returns index to the default SIP profile in locally cached array. |
96 // ---------------------------------------------------------------------------- |
105 // ---------------------------------------------------------------------------- |
97 // |
106 // |
98 TInt CMusSIPProfileModel::DefaultProfileIndex() |
107 TInt CMusSIPProfileModel::DefaultProfileIndex() |
99 { |
108 { |
100 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileIndex()" ) |
109 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileIndex()" ) |
101 TInt index( KErrNotFound ); |
110 TInt index( KErrNotFound ); |
102 |
111 |
103 for ( TInt i = 0; i < iProfiles->Count(); i++ ) |
112 for ( TInt i = 0; i < iProfiles.Count(); i++ ) |
104 { |
113 { |
105 TBool defProfile( EFalse ); |
114 TBool defProfile( EFalse ); |
106 if ( |
115 if ( |
107 KErrNone == |
116 KErrNone == |
108 iProfiles->At( i )->GetParameter( KSIPDefaultProfile, defProfile ) |
117 iProfiles[i]->GetParameter( KSIPDefaultProfile, defProfile ) |
109 && defProfile ) |
118 && defProfile ) |
110 { |
119 { |
111 index = i; |
120 index = i; |
112 break; |
121 break; |
113 } |
122 } |
116 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileIndex()( %d )", |
125 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileIndex()( %d )", |
117 index ) |
126 index ) |
118 return index; |
127 return index; |
119 } |
128 } |
120 |
129 |
121 |
|
122 // ---------------------------------------------------------------------------- |
130 // ---------------------------------------------------------------------------- |
123 // Returns id of the default SIP profile. If default SIP profile is not found |
131 // Returns id of the default SIP profile. If default SIP profile is not found |
124 // KUnknownProfileId is returned. |
132 // KUnknownProfileId is returned. |
125 // ---------------------------------------------------------------------------- |
133 // ---------------------------------------------------------------------------- |
126 // |
134 // |
127 TUint32 CMusSIPProfileModel::DefaultProfileId() |
135 TUint32 CMusSIPProfileModel::DefaultProfileId() |
128 { |
136 { |
129 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileId()" ) |
137 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileId()" ) |
130 TUint32 id( KUnknownProfileId ); |
138 TUint32 id( KUnknownProfileId ); |
131 |
139 |
132 for ( TInt i = 0; i < iProfiles->Count(); i++ ) |
140 for ( TInt i = 0; i < iProfiles.Count(); i++ ) |
133 { |
141 { |
134 TBool defProfile( EFalse ); |
142 TBool defProfile( EFalse ); |
135 if ( |
143 TInt error = iProfiles[i]->GetParameter( KSIPDefaultProfile, defProfile ); |
136 KErrNone == |
144 if ( error == KErrNone && defProfile ) |
137 iProfiles->At( i )->GetParameter( KSIPDefaultProfile, defProfile ) |
145 { |
138 && defProfile ) |
146 iProfiles[i]->GetParameter( KSIPProfileId, id ); |
139 { |
|
140 iProfiles->At( i )->GetParameter( KSIPProfileId, id ); |
|
141 break; |
147 break; |
142 } |
148 } |
143 } |
149 } |
144 |
150 |
145 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileId()( %d )", |
151 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileId()( %d )", |
146 id ) |
152 id ) |
147 return id; |
153 return id; |
148 } |
154 } |
|
155 |
149 // ----------------------------------------------------------------------------- |
156 // ----------------------------------------------------------------------------- |
150 // Disable SIP Registration. |
157 // Disable SIP Registration. |
151 // ----------------------------------------------------------------------------- |
158 // ----------------------------------------------------------------------------- |
152 // |
159 // |
153 void CMusSIPProfileModel::DisableProfileL() |
160 void CMusSIPProfileModel::DisableProfileL() |
202 enabled ) |
209 enabled ) |
203 CleanupStack::PopAndDestroy( managedProfile ); |
210 CleanupStack::PopAndDestroy( managedProfile ); |
204 MUS_LOG( "[MUSSET] <- CMusAvaRegisterAvailability::ProfileEnabledL " ) |
211 MUS_LOG( "[MUSSET] <- CMusAvaRegisterAvailability::ProfileEnabledL " ) |
205 return enabled; |
212 return enabled; |
206 } |
213 } |
|
214 |
207 // ---------------------------------------------------------------------------- |
215 // ---------------------------------------------------------------------------- |
208 // Returns index of the default SIP profile on locally cached array. If default |
216 // Returns index of the default SIP profile on locally cached array. If default |
209 // SIP profile is not found, KErrNotFound is returned. |
217 // SIP profile is not found, KErrNotFound is returned. |
210 // ---------------------------------------------------------------------------- |
218 // ---------------------------------------------------------------------------- |
211 // |
219 // |
212 TInt CMusSIPProfileModel::ProfileIndexByIdL( TUint32 aId ) |
220 TInt CMusSIPProfileModel::ProfileIndexByIdL( TUint32 aId ) |
213 { |
221 { |
214 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileIndexByIdL()" ) |
222 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileIndexByIdL()" ) |
215 TInt index( KErrNotFound ); |
223 TInt index( KErrNotFound ); |
216 |
224 |
217 ReadProfileListFromEngineSafeL(); |
225 for ( TInt i = 0; i < iProfiles.Count(); i++ ) |
218 for ( TInt i = 0; i < iProfiles->Count(); i++ ) |
|
219 { |
226 { |
220 TUint32 id( KUnknownProfileId ); |
227 TUint32 id( KUnknownProfileId ); |
221 |
228 TInt error = iProfiles[i]->GetParameter( KSIPProfileId, id ); |
222 if ( KErrNone == iProfiles->At( i )->GetParameter( KSIPProfileId, id ) |
229 if ( error == KErrNone && id == aId ) |
223 && id == aId ) |
|
224 { |
230 { |
225 index = i; |
231 index = i; |
226 break; |
232 break; |
227 } |
233 } |
228 } |
234 } |
240 TUint32 CMusSIPProfileModel::ProfileIdByIndex( TUint aIndex ) |
246 TUint32 CMusSIPProfileModel::ProfileIdByIndex( TUint aIndex ) |
241 { |
247 { |
242 MUS_LOG1( "[MUSSET] -> CMusSIPProfileModel::ProfileIdByIndex()( %d )", |
248 MUS_LOG1( "[MUSSET] -> CMusSIPProfileModel::ProfileIdByIndex()( %d )", |
243 aIndex ) |
249 aIndex ) |
244 TUint32 profileId( KUnknownProfileId ); |
250 TUint32 profileId( KUnknownProfileId ); |
245 if ( iProfiles->Count() > aIndex ) |
251 if ( aIndex < iProfiles.Count() ) |
246 { |
252 { |
247 if ( iProfiles->At( aIndex )->GetParameter( |
253 if ( iProfiles[aIndex]->GetParameter( KSIPProfileId, profileId ) ) |
248 KSIPProfileId, profileId ) ) |
|
249 { |
254 { |
250 profileId = KUnknownProfileId; |
255 profileId = KUnknownProfileId; |
251 } |
256 } |
252 } |
257 } |
253 |
258 |
254 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileIdByIndex()" ) |
259 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileIdByIndex()" ) |
255 return profileId; |
260 return profileId; |
256 } |
261 } |
257 |
|
258 |
|
259 // ---------------------------------------------------------------------------- |
|
260 // Reads SIP profiles from SIP Profile Client array to locally cached array. |
|
261 // ---------------------------------------------------------------------------- |
|
262 // |
|
263 void CMusSIPProfileModel::ReadArrayFromEngineL() |
|
264 { |
|
265 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ReadArrayFromEngineL()" ) |
|
266 |
|
267 DeleteProfiles(); |
|
268 |
|
269 // Create the profile pointer array |
|
270 iProfiles = |
|
271 new ( ELeave ) CArrayPtrFlat<CSIPManagedProfile>( KSIPGranularity ); |
|
272 |
|
273 RPointerArray<CSIPProfile> profilePointerArray; |
|
274 TCleanupItem clItem( ResetAndDestroy, &profilePointerArray ); |
|
275 CleanupStack::PushL( clItem ); |
|
276 |
|
277 iEngine->ProfilesL( profilePointerArray ); |
|
278 for ( TInt i = 0; i < profilePointerArray.Count(); i++ ) |
|
279 { |
|
280 iProfiles->AppendL( |
|
281 static_cast<CSIPManagedProfile*>( profilePointerArray[i] ) ); |
|
282 } |
|
283 |
|
284 profilePointerArray.Reset(); |
|
285 CleanupStack::PopAndDestroy(); // clItem (profilePointerArray) |
|
286 |
|
287 SortProfilesL(); |
|
288 |
|
289 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ReadArrayFromEngineL()" ) |
|
290 } |
|
291 |
|
292 |
262 |
293 // ---------------------------------------------------------------------------- |
263 // ---------------------------------------------------------------------------- |
294 // Sorts internal array of SIP profiles by id. Used algorithm is generally |
264 // Sorts internal array of SIP profiles by id. Used algorithm is generally |
295 // slower than quicksort and selectionsort but very feasible for expected |
265 // slower than quicksort and selectionsort but very feasible for expected |
296 // amount of items to be sorted and complexity vise. |
266 // amount of items to be sorted and complexity vise. |
298 // |
268 // |
299 void CMusSIPProfileModel::SortProfilesL() |
269 void CMusSIPProfileModel::SortProfilesL() |
300 { |
270 { |
301 TUint32 profileIdFirst( 0 ); |
271 TUint32 profileIdFirst( 0 ); |
302 TUint32 profileIdSecond( 0 ); |
272 TUint32 profileIdSecond( 0 ); |
303 for ( TInt a = 0; a < iProfiles->Count() - 1; a++ ) |
273 for ( TInt a = 0; a < iProfiles.Count() - 1; a++ ) |
304 { |
274 { |
305 for ( TInt b = a + 1; b < iProfiles->Count(); b++ ) |
275 for ( TInt b = a + 1; b < iProfiles.Count(); b++ ) |
306 { |
276 { |
307 User::LeaveIfError( iProfiles->At( a )->GetParameter( |
277 User::LeaveIfError( iProfiles[a]->GetParameter( |
308 KSIPProfileId, profileIdFirst ) ); |
278 KSIPProfileId, profileIdFirst ) ); |
309 User::LeaveIfError( iProfiles->At( b )->GetParameter( |
279 User::LeaveIfError( iProfiles[b]->GetParameter( |
310 KSIPProfileId, profileIdSecond ) ); |
280 KSIPProfileId, profileIdSecond ) ); |
311 if ( profileIdFirst > profileIdSecond ) |
281 if ( profileIdFirst > profileIdSecond ) |
312 { |
282 { |
313 CSIPManagedProfile* tmp = iProfiles->At( b ); |
283 CSIPProfile* tmp = iProfiles[b]; |
314 iProfiles->At( b ) = iProfiles->At( a ); |
284 iProfiles[b] = iProfiles[a]; |
315 iProfiles->At( a ) = tmp; |
285 iProfiles[a] = tmp; |
316 } |
286 } |
317 } |
287 } |
318 } |
288 } |
319 } |
289 } |
320 |
|
321 |
|
322 // ---------------------------------------------------------------------------- |
|
323 // Deletes internally cached SIP profiles. |
|
324 // ---------------------------------------------------------------------------- |
|
325 // |
|
326 void CMusSIPProfileModel::DeleteProfiles() |
|
327 { |
|
328 if ( iProfiles ) |
|
329 { |
|
330 iProfiles->ResetAndDestroy(); |
|
331 delete iProfiles; |
|
332 iProfiles = NULL; |
|
333 } |
|
334 } |
|
335 |
|
336 |
290 |
337 // ---------------------------------------------------------------------------- |
291 // ---------------------------------------------------------------------------- |
338 // From class MSIPProfileRegistryObserver. |
292 // From class MSIPProfileRegistryObserver. |
339 // Notifies of an event in SIP profile registry. |
293 // Notifies of an event in SIP profile registry. |
340 // ---------------------------------------------------------------------------- |
294 // ---------------------------------------------------------------------------- |
341 // |
295 // |
342 void CMusSIPProfileModel::ProfileRegistryEventOccurred( |
296 void CMusSIPProfileModel::ProfileRegistryEventOccurred( |
343 TUint32 /*aSIPProfileId*/, TEvent /*aEvent*/ ) |
297 TUint32 aSIPProfileId, TEvent aEvent ) |
344 { |
298 { |
|
299 MUS_LOG("[MUSSET] -> CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) |
|
300 MUS_LOG2(" SIPProfileId is %d,Event is %d",aSIPProfileId,aEvent) |
|
301 |
|
302 // We revert back to default settings if the profile used by MuS is deleted |
|
303 if ( aEvent == EProfileDestroyed ) |
|
304 { |
|
305 TRAP_IGNORE( |
|
306 //if the profile is the profile used by mush |
|
307 if ( MultimediaSharingSettings::SipProfileSettingL() == |
|
308 aSIPProfileId ) |
|
309 { |
|
310 //set the profile to default |
|
311 MultimediaSharingSettings::SetSipProfileSettingL( |
|
312 CMusSettingsModel::KVsSipProfileDefault ); |
|
313 //set mush off |
|
314 MultimediaSharingSettings::SetActivationSettingL( |
|
315 MusSettingsKeys::EActiveInHomeNetworks ); |
|
316 } |
|
317 ); |
|
318 } |
|
319 |
|
320 if ( aEvent == EProfileCreated || |
|
321 aEvent == EProfileUpdated || |
|
322 aEvent == EProfileDestroyed ) |
|
323 { |
|
324 // Profiles have been manipulated in SIP side, we must delete client |
|
325 // side profile objects and retrieve them again. If fetching fails, |
|
326 // we have empty array which is better than showing wrong values to |
|
327 // user. |
|
328 iProfiles.ResetAndDestroy(); |
|
329 TRAP_IGNORE( iEngine->ProfilesL( iProfiles ) ); |
|
330 TRAP_IGNORE( SortProfilesL() ); |
|
331 } |
|
332 |
345 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) |
333 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) |
346 } |
334 } |
347 |
|
348 |
335 |
349 // ---------------------------------------------------------------------------- |
336 // ---------------------------------------------------------------------------- |
350 // From class MSIPProfileRegistryObserver. |
337 // From class MSIPProfileRegistryObserver. |
351 // An asynchronous error has occurred related to SIP profile |
338 // An asynchronous error has occurred related to SIP profile |
352 // ---------------------------------------------------------------------------- |
339 // ---------------------------------------------------------------------------- |
356 TInt /*aError*/ ) |
343 TInt /*aError*/ ) |
357 { |
344 { |
358 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryErrorOccurred()" ) |
345 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryErrorOccurred()" ) |
359 } |
346 } |
360 |
347 |
361 |
348 // ---------------------------------------------------------------------------- |
362 // ---------------------------------------------------------------------------- |
349 //Set CMusSettingsModel to handle ProfileRegistry Event. |
363 // Reads SIP profile list from engine; if reading fails, old cached list is |
350 // ---------------------------------------------------------------------------- |
364 // kept and returned. |
351 // |
365 // ---------------------------------------------------------------------------- |
352 void CMusSIPProfileModel::SetCMusSettingsModel(CMusSettingsModel* aCMusSettingsModel) |
366 // |
353 { |
367 void CMusSIPProfileModel::ReadProfileListFromEngineSafeL() |
354 iCMusSettingsModel = aCMusSettingsModel; |
368 { |
355 } |
369 MUS_LOG( |
|
370 "[MUSSET] -> CMusSIPProfileModel::ReadProfileListFromEngineSafeL()" ) |
|
371 // To prevent complete disaster it we'll save the pointer of the old array |
|
372 CArrayPtrFlat<CSIPManagedProfile>* profiles = iProfiles; |
|
373 iProfiles = 0; |
|
374 TRAPD( error, ReadArrayFromEngineL() ); |
|
375 |
|
376 if ( error ) |
|
377 { |
|
378 // Problems with re-reading profiles; use existing array |
|
379 DeleteProfiles(); |
|
380 iProfiles = profiles; |
|
381 User::Leave( error ); |
|
382 } |
|
383 else |
|
384 { |
|
385 // No problems; delete backup array |
|
386 profiles->ResetAndDestroy(); |
|
387 delete profiles; |
|
388 } |
|
389 MUS_LOG( |
|
390 "[MUSSET] <- CMusSIPProfileModel::ReadProfileListFromEngineSafeL()" ) |
|
391 } |
|
392 |
|
393 |
|
394 // ---------------------------------------------------------------------------- |
|
395 // For deleting RPointerArray in case of leave (used in association with |
|
396 // TCleanupItem). |
|
397 // ---------------------------------------------------------------------------- |
|
398 // |
|
399 void CMusSIPProfileModel::ResetAndDestroy( TAny* aPointerArray ) |
|
400 { |
|
401 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ResetAndDestroy()" ) |
|
402 RPointerArray<CSIPProfile>* array = |
|
403 static_cast<RPointerArray<CSIPProfile>*>( aPointerArray ); |
|
404 array->ResetAndDestroy(); |
|
405 array->Close(); |
|
406 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ResetAndDestroy()" ) |
|
407 } |
|