|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "mussipprofilemodel.h" |
|
21 #include "muslogger.h" |
|
22 #include <aknnotewrappers.h> |
|
23 #include <StringLoader.h> |
|
24 #include <aknview.h> |
|
25 #include <sipmanagedprofileregistry.h> |
|
26 |
|
27 |
|
28 const TInt KSIPGranularity = 5; |
|
29 const TInt KUnknownProfileId = 0; |
|
30 |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 |
|
35 CMusSIPProfileModel::CMusSIPProfileModel() |
|
36 { |
|
37 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::CMusSIPProfileModel()" ) |
|
38 } |
|
39 |
|
40 |
|
41 void CMusSIPProfileModel::ConstructL() |
|
42 { |
|
43 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ConstructL()" ) |
|
44 iEngine = CSIPManagedProfileRegistry::NewL( *this ); |
|
45 ReadArrayFromEngineL(); |
|
46 } |
|
47 |
|
48 |
|
49 CMusSIPProfileModel* CMusSIPProfileModel::NewL() |
|
50 { |
|
51 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::NewL()" ) |
|
52 CMusSIPProfileModel* self = new( ELeave ) CMusSIPProfileModel(); |
|
53 |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop( self ); |
|
57 |
|
58 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::NewL()" ) |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 CMusSIPProfileModel::~CMusSIPProfileModel() |
|
64 { |
|
65 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
|
66 DeleteProfiles(); |
|
67 delete iEngine; |
|
68 iEngine = NULL; |
|
69 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::~CMusSIPProfileModel()" ) |
|
70 } |
|
71 |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // Returns pointer to the locally cached SIP profile array. |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 CArrayPtr<CSIPManagedProfile>* CMusSIPProfileModel::ProfileArrayL() |
|
78 { |
|
79 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileArrayL()" ) |
|
80 ReadProfileListFromEngineSafeL(); |
|
81 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileArrayL()" ) |
|
82 return iProfiles; |
|
83 } |
|
84 |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // Returns index to the default SIP profile in locally cached array. |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 TInt CMusSIPProfileModel::DefaultProfileIndex() |
|
91 { |
|
92 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileIndex()" ) |
|
93 TInt index( KErrNotFound ); |
|
94 |
|
95 for ( TInt i = 0; i < iProfiles->Count(); i++ ) |
|
96 { |
|
97 TBool defProfile( EFalse ); |
|
98 if ( |
|
99 KErrNone == |
|
100 iProfiles->At( i )->GetParameter( KSIPDefaultProfile, defProfile ) |
|
101 && defProfile ) |
|
102 { |
|
103 index = i; |
|
104 break; |
|
105 } |
|
106 } |
|
107 |
|
108 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileIndex()( %d )", |
|
109 index ) |
|
110 return index; |
|
111 } |
|
112 |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // Returns id of the default SIP profile. If default SIP profile is not found |
|
116 // KUnknownProfileId is returned. |
|
117 // ---------------------------------------------------------------------------- |
|
118 // |
|
119 TUint32 CMusSIPProfileModel::DefaultProfileId() |
|
120 { |
|
121 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::DefaultProfileId()" ) |
|
122 TUint32 id( KUnknownProfileId ); |
|
123 |
|
124 for ( TInt i = 0; i < iProfiles->Count(); i++ ) |
|
125 { |
|
126 TBool defProfile( EFalse ); |
|
127 if ( |
|
128 KErrNone == |
|
129 iProfiles->At( i )->GetParameter( KSIPDefaultProfile, defProfile ) |
|
130 && defProfile ) |
|
131 { |
|
132 iProfiles->At( i )->GetParameter( KSIPProfileId, id ); |
|
133 break; |
|
134 } |
|
135 } |
|
136 |
|
137 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::DefaultProfileId()( %d )", |
|
138 id ) |
|
139 return id; |
|
140 } |
|
141 |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // Returns index of the default SIP profile on locally cached array. If default |
|
145 // SIP profile is not found, KErrNotFound is returned. |
|
146 // ---------------------------------------------------------------------------- |
|
147 // |
|
148 TInt CMusSIPProfileModel::ProfileIndexByIdL( TUint32 aId ) |
|
149 { |
|
150 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ProfileIndexByIdL()" ) |
|
151 TInt index( KErrNotFound ); |
|
152 |
|
153 ReadProfileListFromEngineSafeL(); |
|
154 for ( TInt i = 0; i < iProfiles->Count(); i++ ) |
|
155 { |
|
156 TUint32 id( KUnknownProfileId ); |
|
157 |
|
158 if ( KErrNone == iProfiles->At( i )->GetParameter( KSIPProfileId, id ) |
|
159 && id == aId ) |
|
160 { |
|
161 index = i; |
|
162 break; |
|
163 } |
|
164 } |
|
165 |
|
166 MUS_LOG1( "[MUSSET] <- CMusSIPProfileModel::ProfileIndexByIdL()( %d )", |
|
167 index ) |
|
168 return index; |
|
169 } |
|
170 |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // Returns profile ID by index. |
|
174 // ---------------------------------------------------------------------------- |
|
175 // |
|
176 TUint32 CMusSIPProfileModel::ProfileIdByIndex( TUint aIndex ) |
|
177 { |
|
178 MUS_LOG1( "[MUSSET] -> CMusSIPProfileModel::ProfileIdByIndex()( %d )", |
|
179 aIndex ) |
|
180 TUint32 profileId( KUnknownProfileId ); |
|
181 if ( iProfiles->Count() > aIndex ) |
|
182 { |
|
183 if ( iProfiles->At( aIndex )->GetParameter( |
|
184 KSIPProfileId, profileId ) ) |
|
185 { |
|
186 profileId = KUnknownProfileId; |
|
187 } |
|
188 } |
|
189 |
|
190 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileIdByIndex()" ) |
|
191 return profileId; |
|
192 } |
|
193 |
|
194 |
|
195 // ---------------------------------------------------------------------------- |
|
196 // Reads SIP profiles from SIP Profile Client array to locally cached array. |
|
197 // ---------------------------------------------------------------------------- |
|
198 // |
|
199 void CMusSIPProfileModel::ReadArrayFromEngineL() |
|
200 { |
|
201 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ReadArrayFromEngineL()" ) |
|
202 |
|
203 DeleteProfiles(); |
|
204 |
|
205 // Create the profile pointer array |
|
206 iProfiles = |
|
207 new ( ELeave ) CArrayPtrFlat<CSIPManagedProfile>( KSIPGranularity ); |
|
208 |
|
209 RPointerArray<CSIPProfile> profilePointerArray; |
|
210 TCleanupItem clItem( ResetAndDestroy, &profilePointerArray ); |
|
211 CleanupStack::PushL( clItem ); |
|
212 |
|
213 iEngine->ProfilesL( profilePointerArray ); |
|
214 for ( TInt i = 0; i < profilePointerArray.Count(); i++ ) |
|
215 { |
|
216 iProfiles->AppendL( |
|
217 static_cast<CSIPManagedProfile*>( profilePointerArray[i] ) ); |
|
218 } |
|
219 |
|
220 profilePointerArray.Reset(); |
|
221 CleanupStack::PopAndDestroy(); // clItem (profilePointerArray) |
|
222 |
|
223 SortProfilesL(); |
|
224 |
|
225 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ReadArrayFromEngineL()" ) |
|
226 } |
|
227 |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // Sorts internal array of SIP profiles by id. Used algorithm is generally |
|
231 // slower than quicksort and selectionsort but very feasible for expected |
|
232 // amount of items to be sorted and complexity vise. |
|
233 // ---------------------------------------------------------------------------- |
|
234 // |
|
235 void CMusSIPProfileModel::SortProfilesL() |
|
236 { |
|
237 TUint32 profileIdFirst( 0 ); |
|
238 TUint32 profileIdSecond( 0 ); |
|
239 for ( TInt a = 0; a < iProfiles->Count() - 1; a++ ) |
|
240 { |
|
241 for ( TInt b = a + 1; b < iProfiles->Count(); b++ ) |
|
242 { |
|
243 User::LeaveIfError( iProfiles->At( a )->GetParameter( |
|
244 KSIPProfileId, profileIdFirst ) ); |
|
245 User::LeaveIfError( iProfiles->At( b )->GetParameter( |
|
246 KSIPProfileId, profileIdSecond ) ); |
|
247 if ( profileIdFirst > profileIdSecond ) |
|
248 { |
|
249 CSIPManagedProfile* tmp = iProfiles->At( b ); |
|
250 iProfiles->At( b ) = iProfiles->At( a ); |
|
251 iProfiles->At( a ) = tmp; |
|
252 } |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 |
|
258 // ---------------------------------------------------------------------------- |
|
259 // Deletes internally cached SIP profiles. |
|
260 // ---------------------------------------------------------------------------- |
|
261 // |
|
262 void CMusSIPProfileModel::DeleteProfiles() |
|
263 { |
|
264 if ( iProfiles ) |
|
265 { |
|
266 iProfiles->ResetAndDestroy(); |
|
267 delete iProfiles; |
|
268 iProfiles = NULL; |
|
269 } |
|
270 } |
|
271 |
|
272 |
|
273 // ---------------------------------------------------------------------------- |
|
274 // From class MSIPProfileRegistryObserver. |
|
275 // Notifies of an event in SIP profile registry. |
|
276 // ---------------------------------------------------------------------------- |
|
277 // |
|
278 void CMusSIPProfileModel::ProfileRegistryEventOccurred( |
|
279 TUint32 /*aSIPProfileId*/, TEvent /*aEvent*/ ) |
|
280 { |
|
281 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryEventOccurred()" ) |
|
282 } |
|
283 |
|
284 |
|
285 // ---------------------------------------------------------------------------- |
|
286 // From class MSIPProfileRegistryObserver. |
|
287 // An asynchronous error has occurred related to SIP profile |
|
288 // ---------------------------------------------------------------------------- |
|
289 // |
|
290 void CMusSIPProfileModel::ProfileRegistryErrorOccurred( |
|
291 TUint32 /*aSIPProfileId*/, |
|
292 TInt /*aError*/ ) |
|
293 { |
|
294 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ProfileRegistryErrorOccurred()" ) |
|
295 } |
|
296 |
|
297 |
|
298 // ---------------------------------------------------------------------------- |
|
299 // Reads SIP profile list from engine; if reading fails, old cached list is |
|
300 // kept and returned. |
|
301 // ---------------------------------------------------------------------------- |
|
302 // |
|
303 void CMusSIPProfileModel::ReadProfileListFromEngineSafeL() |
|
304 { |
|
305 MUS_LOG( |
|
306 "[MUSSET] -> CMusSIPProfileModel::ReadProfileListFromEngineSafeL()" ) |
|
307 // To prevent complete disaster it we'll save the pointer of the old array |
|
308 CArrayPtrFlat<CSIPManagedProfile>* profiles = iProfiles; |
|
309 iProfiles = 0; |
|
310 TRAPD( error, ReadArrayFromEngineL() ); |
|
311 |
|
312 if ( error ) |
|
313 { |
|
314 // Problems with re-reading profiles; use existing array |
|
315 DeleteProfiles(); |
|
316 iProfiles = profiles; |
|
317 User::Leave( error ); |
|
318 } |
|
319 else |
|
320 { |
|
321 // No problems; delete backup array |
|
322 profiles->ResetAndDestroy(); |
|
323 delete profiles; |
|
324 } |
|
325 MUS_LOG( |
|
326 "[MUSSET] <- CMusSIPProfileModel::ReadProfileListFromEngineSafeL()" ) |
|
327 } |
|
328 |
|
329 |
|
330 // ---------------------------------------------------------------------------- |
|
331 // For deleting RPointerArray in case of leave (used in association with |
|
332 // TCleanupItem). |
|
333 // ---------------------------------------------------------------------------- |
|
334 // |
|
335 void CMusSIPProfileModel::ResetAndDestroy( TAny* aPointerArray ) |
|
336 { |
|
337 MUS_LOG( "[MUSSET] -> CMusSIPProfileModel::ResetAndDestroy()" ) |
|
338 RPointerArray<CSIPProfile>* array = |
|
339 static_cast<RPointerArray<CSIPProfile>*>( aPointerArray ); |
|
340 array->ResetAndDestroy(); |
|
341 array->Close(); |
|
342 MUS_LOG( "[MUSSET] <- CMusSIPProfileModel::ResetAndDestroy()" ) |
|
343 } |