|
1 /* |
|
2 * Copyright (c) 2002-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: |
|
15 * Service manager for external service providers. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <barsread.h> |
|
22 #include <Pbk2DataCaging.hrh> |
|
23 #include <Pbk2Presentation.rsg> |
|
24 #include <RPbk2LocalizedResourceFile.h> |
|
25 #include "CPbk2ServiceManager.h" |
|
26 #include "Pbk2PresentationUtils.h" |
|
27 #include <spsettings.h> |
|
28 #include <spproperty.h> |
|
29 #include <spentry.h> |
|
30 #include <cbsfactory.h> |
|
31 #include <mbsaccess.h> |
|
32 #include <fbs.h> |
|
33 #include <contactpresencebrandids.h> |
|
34 #include <spnotifychange.h> |
|
35 #include <PbkUID.h> |
|
36 |
|
37 //constants |
|
38 const TInt KMaxBufLength = 128; |
|
39 |
|
40 void CPbk2ServiceManager::TService::Delete() |
|
41 { |
|
42 delete iBitmap; |
|
43 iBitmap = NULL; |
|
44 delete iMask; |
|
45 iBitmap = NULL; |
|
46 } |
|
47 |
|
48 EXPORT_C CPbk2ServiceManager* CPbk2ServiceManager::NewL(RFs& aRFs) |
|
49 { |
|
50 CPbk2ServiceManager* self = new (ELeave) CPbk2ServiceManager(aRFs); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 CPbk2ServiceManager::~CPbk2ServiceManager() |
|
58 { |
|
59 if(iSPNotifyChange) |
|
60 { |
|
61 iSPNotifyChange->NotifyChangeCancel(); |
|
62 } |
|
63 |
|
64 delete iSPNotifyChange; |
|
65 iSpIdsToObserve.Close(); //Empty, no entries |
|
66 delete iSettings; |
|
67 DeleteData(); |
|
68 } |
|
69 |
|
70 void CPbk2ServiceManager::DeleteData() |
|
71 { |
|
72 for (TInt i = 0; i < iServices.Count(); i++) |
|
73 { |
|
74 iServices[i].Delete(); |
|
75 } |
|
76 iServices.Close(); |
|
77 |
|
78 for (TInt i = 0; i < iStringsOwner.Count(); i++) |
|
79 { |
|
80 delete iStringsOwner[i]; |
|
81 } |
|
82 iStringsOwner.Close(); |
|
83 iBitmapIdCounter = 0; |
|
84 } |
|
85 |
|
86 CPbk2ServiceManager::CPbk2ServiceManager(RFs& aRFs) : |
|
87 iRFs(aRFs) |
|
88 { |
|
89 } |
|
90 |
|
91 void CPbk2ServiceManager::ConstructL() |
|
92 { |
|
93 iSettings = CSPSettings::NewL(); |
|
94 iSPNotifyChange = CSPNotifyChange::NewL(*this); |
|
95 iSPNotifyChange->NotifyChangeL( iSpIdsToObserve ); |
|
96 iRunRefreshData = ETrue; |
|
97 } |
|
98 |
|
99 EXPORT_C const CPbk2ServiceManager::RServicesArray& CPbk2ServiceManager::Services() |
|
100 { |
|
101 //If got one or more notifications of changed data run refresh first |
|
102 if(iRunRefreshData) |
|
103 { |
|
104 iRunRefreshData = EFalse; |
|
105 TRAP_IGNORE( RunRefreshDataL() ); |
|
106 } |
|
107 |
|
108 return iServices; |
|
109 } |
|
110 |
|
111 EXPORT_C void CPbk2ServiceManager::RefreshDataL() |
|
112 { |
|
113 iRunRefreshData = ETrue; |
|
114 } |
|
115 |
|
116 void CPbk2ServiceManager::RunRefreshDataL() |
|
117 { |
|
118 DeleteData(); |
|
119 ReadWellKnownServicesL(); |
|
120 AppendInstalledServicesL(); |
|
121 UpdateBrandingInfoL(); |
|
122 } |
|
123 |
|
124 |
|
125 void CPbk2ServiceManager::ReadWellKnownServicesL() |
|
126 { |
|
127 RPbk2LocalizedResourceFile resFile( &iRFs ); |
|
128 resFile.OpenLC(KPbk2RomFileDrive, |
|
129 KDC_RESOURCE_FILES_DIR, |
|
130 Pbk2PresentationUtils::PresentationResourceFile()); |
|
131 |
|
132 // Read well known services from resource |
|
133 TResourceReader reader; |
|
134 reader.SetBuffer( resFile.AllocReadLC( |
|
135 R_PHONEBOOK2_WELL_KNOWN_SERVICES ) ); |
|
136 TInt count = reader.ReadInt16(); |
|
137 HBufC* buf = NULL; |
|
138 for (TInt i = 0; i < count; i++) |
|
139 { |
|
140 TService service; |
|
141 buf = reader.ReadHBufCL(); |
|
142 CleanupStack::PushL(buf); |
|
143 service.iName.Set(*buf); |
|
144 iStringsOwner.AppendL(buf); |
|
145 CleanupStack::Pop(buf); |
|
146 buf = reader.ReadHBufCL(); |
|
147 CleanupStack::PushL(buf); |
|
148 service.iDisplayName.Set(*buf); |
|
149 iStringsOwner.AppendL(buf); |
|
150 CleanupStack::Pop(buf); |
|
151 service.iFlags = EWellKnown; |
|
152 service.iBitmap = service.iMask = NULL; |
|
153 service.iBitmapId = 0; |
|
154 service.iBrandId.Set(KNullDesC); |
|
155 service.iApplicationId.Set(TPtrC8(KCPBrandAppId)); |
|
156 AppendServiceL(service); |
|
157 } |
|
158 CleanupStack::PopAndDestroy(2, &resFile); |
|
159 } |
|
160 |
|
161 void CPbk2ServiceManager::AppendInstalledServicesL() |
|
162 { |
|
163 RIdArray idArray; |
|
164 CleanupClosePushL(idArray); |
|
165 User::LeaveIfError(iSettings->FindServiceIdsL(idArray)); |
|
166 const TInt granularity = 16; |
|
167 CDesCArrayFlat* names = new (ELeave) CDesCArrayFlat(granularity); |
|
168 CleanupStack::PushL(names); |
|
169 User::LeaveIfError(iSettings->FindServiceNamesL(idArray, *names)); |
|
170 |
|
171 //Append if not yet in iServices, otherwise update iServices |
|
172 for (TInt ni = 0; ni < names->Count(); ni++) |
|
173 { |
|
174 TBool found = EFalse; |
|
175 TInt si = 0; |
|
176 while(si < iServices.Count()&& !found) |
|
177 { |
|
178 iServices[si].iName.CompareF(names->operator[](ni)) ? |
|
179 si++ :found=ETrue; |
|
180 } |
|
181 |
|
182 //For installed well-known services the service data needs to be updated. |
|
183 //For non-well known services some service attributes are first checked |
|
184 //to decide whether to add or skip the service. |
|
185 if( found ) |
|
186 { |
|
187 //Update existing |
|
188 UpdateServiceL(iServices[si], idArray[ni], names->operator[](ni)); |
|
189 } |
|
190 else |
|
191 { |
|
192 //Append new if ok to add |
|
193 TBool okToAppend(ETrue); |
|
194 |
|
195 // Check whether the service is VCC. |
|
196 // If so, when the VoIP service is becoming available, |
|
197 // the VCC item should be in a same field for UI displaying. |
|
198 CSPEntry *entry = CSPEntry::NewLC(); |
|
199 TInt ret = iSettings->FindEntryL( idArray[ni], *entry ); |
|
200 if( ret == KErrNone ) |
|
201 { |
|
202 const CSPProperty* prop = NULL; |
|
203 ret = entry->GetProperty( prop, ESubPropertyVccVDI); |
|
204 if( ret == KErrNone ) |
|
205 { |
|
206 okToAppend = EFalse; |
|
207 } |
|
208 } |
|
209 CleanupStack::PopAndDestroy(); //entry |
|
210 // Check whether service supports cs voice call. If so, discard it. |
|
211 CSPProperty* servAttrMask = CSPProperty::NewLC(); |
|
212 ret = iSettings->FindPropertyL( |
|
213 idArray[ni], EPropertyServiceAttributeMask, *servAttrMask ); |
|
214 |
|
215 if( ret == KErrNone ) |
|
216 { |
|
217 TInt mask(0); |
|
218 servAttrMask->GetValue(mask); |
|
219 okToAppend = !(mask & ESupportsCSVoiceCall); |
|
220 } |
|
221 CleanupStack::PopAndDestroy(servAttrMask); |
|
222 |
|
223 if(okToAppend) |
|
224 { |
|
225 TService service; |
|
226 UpdateServiceL(service, idArray[ni], names->operator[](ni)); |
|
227 AppendServiceL(service); |
|
228 } |
|
229 } |
|
230 } |
|
231 CleanupStack::PopAndDestroy(names); |
|
232 CleanupStack::PopAndDestroy(); //idArray |
|
233 } |
|
234 |
|
235 void CPbk2ServiceManager::UpdateServiceL( |
|
236 TService& aService, |
|
237 TServiceId aServiceId, |
|
238 const TDesC& aServiceName ) |
|
239 { |
|
240 //Set service name |
|
241 HBufC* name = HBufC::NewLC(aServiceName.Length()); |
|
242 iStringsOwner.AppendL(name); |
|
243 CleanupStack::Pop(name); |
|
244 name->Des().Copy(aServiceName); |
|
245 |
|
246 //iName & iDisplayName will not be set if the service |
|
247 //doesnt belong to the list of well known services |
|
248 //Thus it makes sense that We copy the ServiceName provisioned |
|
249 //in the Service Table to both iName as well as iDisplayName |
|
250 //This iDisplayName will be visible to the end user. |
|
251 if ( !aService.iName.Length() ) |
|
252 { |
|
253 aService.iName.Set(*name); |
|
254 } |
|
255 if ( !aService.iDisplayName.Length() ) |
|
256 { |
|
257 aService.iDisplayName.Set(*name); |
|
258 } |
|
259 aService.iFlags = EInstalled; |
|
260 aService.iBitmap = aService.iMask = NULL; |
|
261 aService.iBitmapId = 0; |
|
262 |
|
263 //Brand id |
|
264 CSPProperty* prop = CSPProperty::NewLC(); |
|
265 HBufC* brandID = HBufC::NewLC(KMaxBufLength); |
|
266 |
|
267 if (iSettings->FindPropertyL(aServiceId, EPropertyBrandId, *prop) == KErrNone) |
|
268 { |
|
269 TPtr des = brandID->Des(); |
|
270 if (prop->GetValue(des) != KErrNone) |
|
271 { |
|
272 des.Zero(); |
|
273 } |
|
274 } |
|
275 |
|
276 aService.iBrandId.Set(*brandID); |
|
277 aService.iServiceId = aServiceId; |
|
278 iStringsOwner.AppendL(brandID); |
|
279 |
|
280 //Appid |
|
281 aService.iApplicationId.Set(TPtrC8(KCPBrandAppId)); |
|
282 CleanupStack::Pop(brandID); |
|
283 CleanupStack::PopAndDestroy(prop); |
|
284 } |
|
285 |
|
286 void CPbk2ServiceManager::AppendServiceL(TService aService) |
|
287 { |
|
288 iServices.AppendL(aService); |
|
289 } |
|
290 |
|
291 void CPbk2ServiceManager::UpdateBrandingInfoL() |
|
292 { |
|
293 TLanguage userLang = User::Language(); |
|
294 TLanguage defLang = ELangInternationalEnglish; |
|
295 for (TInt i = 0; i < iServices.Count(); i++) |
|
296 { |
|
297 TLanguage servLang = ELangTest; |
|
298 //ELangTest CAN BE USED AS DEFAULT VALUE AS THIS DOES NOT BELONG TO ANY LANG |
|
299 //SEE THE HEADER FILE e32lang.h |
|
300 if(iServices[i].iBrandId.Length()) |
|
301 { |
|
302 //Search for BrandPackage using PhoneLanguage |
|
303 //PhoneLanguage gets the Highest Priority |
|
304 TRAPD(err, UpdateBrandL(iServices[i], userLang )); |
|
305 if (err) |
|
306 { |
|
307 //The next priority goes to BrandLanguage set in the SpSettings/service table |
|
308 //during provisioning |
|
309 //Search for BrandPackage using this BrandLanguage |
|
310 CSPProperty* prop = CSPProperty::NewLC(); |
|
311 if(!iSettings->FindPropertyL( |
|
312 iServices[i].iServiceId, EPropertyBrandLanguage, *prop)) |
|
313 { |
|
314 if(!prop->GetValue((TInt&)servLang)) |
|
315 { |
|
316 if (userLang != servLang) |
|
317 { |
|
318 TRAP(err, UpdateBrandL(iServices[i], servLang )); |
|
319 } |
|
320 } |
|
321 } |
|
322 CleanupStack::PopAndDestroy(prop); |
|
323 } |
|
324 |
|
325 if ( ( err ) && ( servLang != defLang ) && ( userLang != defLang ) ) |
|
326 { |
|
327 //Fetching of brand with UserLang & with the one mentioned in the Servicetable |
|
328 //was not successfull. |
|
329 //Finally try with Default Language ID and even if this fails |
|
330 //proceed without any brand icons/texts |
|
331 TRAP( err, UpdateBrandL( iServices[i], defLang ) ); |
|
332 } |
|
333 } |
|
334 } |
|
335 } |
|
336 |
|
337 void CPbk2ServiceManager::UpdateBrandL( TService& aService, TLanguage aLanguage ) |
|
338 { |
|
339 HBufC8* brandID = HBufC8::NewLC(aService.iBrandId.Length()); |
|
340 brandID->Des().Copy(aService.iBrandId); |
|
341 |
|
342 CBSFactory* bsFactory = CBSFactory::NewL( KCPBrandDefaultId, aService.iApplicationId ); |
|
343 CleanupStack::PushL(bsFactory); |
|
344 MBSAccess* access = bsFactory->CreateAccessLC(*brandID, aLanguage); //leaves if none found |
|
345 CFbsBitmap* bitmap = NULL; |
|
346 CFbsBitmap* mask = NULL; |
|
347 access->GetBitmapL(KCPBrandElementIdServiceIcon, bitmap, mask); |
|
348 CleanupStack::PushL(bitmap); |
|
349 CleanupStack::PushL(mask); |
|
350 |
|
351 //Update service |
|
352 if(bitmap) |
|
353 { |
|
354 aService.iBitmap = bitmap; |
|
355 aService.iMask = mask; |
|
356 aService.iBitmapId = ++iBitmapIdCounter; |
|
357 } |
|
358 CleanupStack::Pop(2); //bitmap, mask |
|
359 //Get Localised Name of Service |
|
360 HBufC* localizedName = access->GetTextLC(KCPBrandElementIdLocalizedServiceName); |
|
361 if(localizedName) |
|
362 { |
|
363 aService.iDisplayName.Set(*localizedName); |
|
364 iStringsOwner.AppendL(localizedName); |
|
365 } |
|
366 |
|
367 CleanupStack::Pop(); //localizedName |
|
368 CleanupStack::PopAndDestroy(3, brandID); |
|
369 } |
|
370 |
|
371 // from MSPNotifyChangeObserver |
|
372 void CPbk2ServiceManager::HandleNotifyChange( TUint /*aServiceId*/ ) |
|
373 { |
|
374 iRunRefreshData = ETrue; |
|
375 } |
|
376 |
|
377 // from MSPNotifyChangeObserver |
|
378 void CPbk2ServiceManager::HandleError( TInt /*aError*/ ) |
|
379 { |
|
380 } |
|
381 |
|
382 |
|
383 // End of File |