1 /* |
|
2 * Copyright (c) 2006-2007 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: Model for managing SIP profiles. |
|
15 * Version : %version: 16 % << Don't touch! Updated by Synergy at check-out. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "mussipprofilemodel.h" |
|
22 #include "muslogger.h" |
|
23 #include "mussettings.inl" |
|
24 #include <aknnotewrappers.h> |
|
25 #include <StringLoader.h> |
|
26 #include <aknview.h> |
|
27 #include <sipmanagedprofileregistry.h> |
|
28 #include <sipmanagedprofile.h> |
|
29 #include <sipprofileregistry.h> |
|
30 #include "mussettingsmodel.h" |
|
31 |
|
32 |
|
33 const TInt KUnknownProfileId = 0; |
|
34 |
|
35 /** |
|
36 * VSC Enable/Disable is of type TBool |
|
37 */ |
|
38 const TUint32 KMuSVSCDisable = 200; |
|
39 |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 CMusSIPProfileModel::CMusSIPProfileModel() |
|
49 { |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 void CMusSIPProfileModel::ConstructL() |
|
57 { |
|
58 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ConstructL()" ) |
|
59 iEngine = CSIPManagedProfileRegistry::NewL( *this ); |
|
60 iEngine->ProfilesL( iProfiles ); |
|
61 SortProfilesL(); |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 CMusSIPProfileModel* CMusSIPProfileModel::NewL() |
|
69 { |
|
70 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::NewL()" ) |
|
71 CMusSIPProfileModel* self = new( ELeave ) CMusSIPProfileModel(); |
|
72 |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop( self ); |
|
76 |
|
77 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::NewL()" ) |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CMusSIPProfileModel::~CMusSIPProfileModel() |
|
86 { |
|
87 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
|
88 iProfiles.ResetAndDestroy(); |
|
89 delete iEngine; |
|
90 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // Returns reference to the locally cached SIP profile array. |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 RPointerArray<CSIPProfile>& CMusSIPProfileModel::ProfileArrayL() |
|
98 { |
|
99 MUS_LOG( "[MUSSET] <-> CMusSIPProfileModel::ProfileArrayL()" ) |
|
100 return iProfiles; |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // Returns index to the default SIP profile in locally cached array. |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CMusSIPProfileModel::DefaultProfileIndex() |
|
108 { |
|
109 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileIndex()" ) |
|
110 TInt index( KErrNotFound ); |
|
111 |
|
112 for ( TInt i = 0; i < iProfiles.Count(); i++ ) |
|
113 { |
|
114 TBool defProfile( EFalse ); |
|
115 if ( |
|
116 KErrNone == |
|
117 iProfiles[i]->GetParameter( KSIPDefaultProfile, defProfile ) |
|
118 && defProfile ) |
|
119 { |
|
120 index = i; |
|
121 break; |
|
122 } |
|
123 } |
|
124 |
|
125 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileIndex()( %d )", |
|
126 index ) |
|
127 return index; |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // Returns id of the default SIP profile. If default SIP profile is not found |
|
132 // KUnknownProfileId is returned. |
|
133 // ---------------------------------------------------------------------------- |
|
134 // |
|
135 TUint32 CMusSIPProfileModel::DefaultProfileId() |
|
136 { |
|
137 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileId()" ) |
|
138 TUint32 id( KUnknownProfileId ); |
|
139 |
|
140 for ( TInt i = 0; i < iProfiles.Count(); i++ ) |
|
141 { |
|
142 TBool defProfile( EFalse ); |
|
143 TInt error = iProfiles[i]->GetParameter( KSIPDefaultProfile, defProfile ); |
|
144 if ( error == KErrNone && defProfile ) |
|
145 { |
|
146 iProfiles[i]->GetParameter( KSIPProfileId, id ); |
|
147 break; |
|
148 } |
|
149 } |
|
150 |
|
151 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileId()( %d )", |
|
152 id ) |
|
153 return id; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // Disable SIP Registration. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CMusSIPProfileModel::DisableProfileL() |
|
161 { |
|
162 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DisableProfileL " ) |
|
163 CSIPManagedProfile* managedProfile = static_cast<CSIPManagedProfile*>( |
|
164 iEngine->ProfileL( DefaultProfileId()) ); |
|
165 CleanupStack::PushL( managedProfile ); |
|
166 //Disable registration from profile.dat file |
|
167 MUS_LOG( "Add registration parameter profile.dat file " ) |
|
168 TInt err = managedProfile->SetParameter( KMuSVSCDisable, (TBool)ETrue ); |
|
169 User::LeaveIfError(err); |
|
170 iEngine->SaveL( *managedProfile ); |
|
171 CleanupStack::PopAndDestroy( managedProfile ); |
|
172 MUS_LOG( "[MUSSET] <- CMusAvaRegisterAvailability::DisableProfileL " ) |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // Enable SIP Registration. |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CMusSIPProfileModel::EnableProfileL() |
|
180 { |
|
181 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::EnableProfileL " ) |
|
182 CSIPManagedProfile* managedProfile = static_cast<CSIPManagedProfile*>( |
|
183 iEngine->ProfileL( DefaultProfileId() ) ); |
|
184 CleanupStack::PushL( managedProfile ); |
|
185 //Disable registration from profile.dat file |
|
186 MUS_LOG( "Add registration parameter profile.dat file " ) |
|
187 TInt err = managedProfile->SetParameter( KMuSVSCDisable, (TBool)EFalse ); |
|
188 User::LeaveIfError(err); |
|
189 iEngine->SaveL( *managedProfile ); |
|
190 CleanupStack::PopAndDestroy( managedProfile ); |
|
191 MUS_LOG( "[MUSSET] <- CMusAvaRegisterAvailability::EnableRegisterL " ) |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // if SIP Registration enabled. |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 TBool CMusSIPProfileModel::ProfileEnabledL() |
|
199 { |
|
200 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileEnabledL " ) |
|
201 CSIPManagedProfile* managedProfile = static_cast<CSIPManagedProfile*>( |
|
202 iEngine->ProfileL( DefaultProfileId() ) ); |
|
203 CleanupStack::PushL( managedProfile ); |
|
204 //Activation status from profile.dat file |
|
205 TBool enabled = EFalse; |
|
206 MUS_LOG( "Get registration parameter from profile.dat file " ) |
|
207 TInt err = managedProfile->GetParameter( KMuSVSCDisable, enabled ); |
|
208 MUS_LOG1( "KMuSVSCDisable value %d )", |
|
209 enabled ) |
|
210 CleanupStack::PopAndDestroy( managedProfile ); |
|
211 MUS_LOG( "[MUSSET] <- CMusAvaRegisterAvailability::ProfileEnabledL " ) |
|
212 return enabled; |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // Returns index of the default SIP profile on locally cached array. If default |
|
217 // SIP profile is not found, KErrNotFound is returned. |
|
218 // ---------------------------------------------------------------------------- |
|
219 // |
|
220 TInt CMusSIPProfileModel::ProfileIndexByIdL( TUint32 aId ) |
|
221 { |
|
222 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileIndexByIdL()" ) |
|
223 TInt index( KErrNotFound ); |
|
224 |
|
225 for ( TInt i = 0; i < iProfiles.Count(); i++ ) |
|
226 { |
|
227 TUint32 id( KUnknownProfileId ); |
|
228 TInt error = iProfiles[i]->GetParameter( KSIPProfileId, id ); |
|
229 if ( error == KErrNone && id == aId ) |
|
230 { |
|
231 index = i; |
|
232 break; |
|
233 } |
|
234 } |
|
235 |
|
236 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::ProfileIndexByIdL()( %d )", |
|
237 index ) |
|
238 return index; |
|
239 } |
|
240 |
|
241 |
|
242 // ---------------------------------------------------------------------------- |
|
243 // Returns profile ID by index. |
|
244 // ---------------------------------------------------------------------------- |
|
245 // |
|
246 TUint32 CMusSIPProfileModel::ProfileIdByIndex( TUint aIndex ) |
|
247 { |
|
248 MUS_LOG1( "[MUSSET] -> CMusSIPProfileModel::ProfileIdByIndex()( %d )", |
|
249 aIndex ) |
|
250 TUint32 profileId( KUnknownProfileId ); |
|
251 if ( aIndex < iProfiles.Count() ) |
|
252 { |
|
253 if ( iProfiles[aIndex]->GetParameter( KSIPProfileId, profileId ) ) |
|
254 { |
|
255 profileId = KUnknownProfileId; |
|
256 } |
|
257 } |
|
258 |
|
259 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileIdByIndex()" ) |
|
260 return profileId; |
|
261 } |
|
262 |
|
263 // ---------------------------------------------------------------------------- |
|
264 // Sorts internal array of SIP profiles by id. Used algorithm is generally |
|
265 // slower than quicksort and selectionsort but very feasible for expected |
|
266 // amount of items to be sorted and complexity vise. |
|
267 // ---------------------------------------------------------------------------- |
|
268 // |
|
269 void CMusSIPProfileModel::SortProfilesL() |
|
270 { |
|
271 TUint32 profileIdFirst( 0 ); |
|
272 TUint32 profileIdSecond( 0 ); |
|
273 for ( TInt a = 0; a < iProfiles.Count() - 1; a++ ) |
|
274 { |
|
275 for ( TInt b = a + 1; b < iProfiles.Count(); b++ ) |
|
276 { |
|
277 User::LeaveIfError( iProfiles[a]->GetParameter( |
|
278 KSIPProfileId, profileIdFirst ) ); |
|
279 User::LeaveIfError( iProfiles[b]->GetParameter( |
|
280 KSIPProfileId, profileIdSecond ) ); |
|
281 if ( profileIdFirst > profileIdSecond ) |
|
282 { |
|
283 CSIPProfile* tmp = iProfiles[b]; |
|
284 iProfiles[b] = iProfiles[a]; |
|
285 iProfiles[a] = tmp; |
|
286 } |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 // ---------------------------------------------------------------------------- |
|
292 // From class MSIPProfileRegistryObserver. |
|
293 // Notifies of an event in SIP profile registry. |
|
294 // ---------------------------------------------------------------------------- |
|
295 // |
|
296 void CMusSIPProfileModel::ProfileRegistryEventOccurred( |
|
297 TUint32 aSIPProfileId, TEvent aEvent ) |
|
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 |
|
333 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) |
|
334 } |
|
335 |
|
336 // ---------------------------------------------------------------------------- |
|
337 // From class MSIPProfileRegistryObserver. |
|
338 // An asynchronous error has occurred related to SIP profile |
|
339 // ---------------------------------------------------------------------------- |
|
340 // |
|
341 void CMusSIPProfileModel::ProfileRegistryErrorOccurred( |
|
342 TUint32 /*aSIPProfileId*/, |
|
343 TInt /*aError*/ ) |
|
344 { |
|
345 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryErrorOccurred()" ) |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------------------------------- |
|
349 //Set CMusSettingsModel to handle ProfileRegistry Event. |
|
350 // ---------------------------------------------------------------------------- |
|
351 // |
|
352 void CMusSIPProfileModel::SetCMusSettingsModel(CMusSettingsModel* aCMusSettingsModel) |
|
353 { |
|
354 iCMusSettingsModel = aCMusSettingsModel; |
|
355 } |
|