|
1 /* |
|
2 * Copyright (c) 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 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include <fbs.h> |
|
22 #include <s32mem.h> |
|
23 #include <bitdev.h> |
|
24 #include <mbsaccess.h> |
|
25 #include <cbsbitmap.h> |
|
26 #include <cbsfactory.h> |
|
27 #include "cmssession.h" |
|
28 #include <AknIconUtils.h> |
|
29 #include "cmspresencedata.h" |
|
30 #include "cmscommondefines.h" |
|
31 |
|
32 #include <presencetrafficlights.mbg> |
|
33 #include "presencetrafficlighticons.h" |
|
34 |
|
35 #include <contactpresencebrandids.h> |
|
36 |
|
37 // This must be in line with contactpresence.dll implementation |
|
38 _LIT( KPresenceTrafficLightsMif, "\\resource\\apps\\presencetrafficlights.mif" ); |
|
39 |
|
40 // ---------------------------------------------------- |
|
41 // CCmsPresenceData::CCmsPresenceData |
|
42 // |
|
43 // ---------------------------------------------------- |
|
44 // |
|
45 CCmsPresenceData::CCmsPresenceData( RCmsContact& aContact ) |
|
46 : iElementIdText(NULL), iContact( aContact ) |
|
47 { |
|
48 |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------- |
|
52 // CCmsPresenceData::NewL |
|
53 // |
|
54 // ---------------------------------------------------- |
|
55 // |
|
56 CCmsPresenceData* CCmsPresenceData::NewL( RCmsContact& aContact ) |
|
57 { |
|
58 CCmsPresenceData* self = new ( ELeave ) CCmsPresenceData( aContact ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------- |
|
66 // CCmsPresenceData::ConstructL |
|
67 // |
|
68 // ---------------------------------------------------- |
|
69 // |
|
70 void CCmsPresenceData::ConstructL() |
|
71 { |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------- |
|
75 // CCmsPresenceData::~CCmsPresenceData |
|
76 // |
|
77 // ---------------------------------------------------- |
|
78 // |
|
79 EXPORT_C CCmsPresenceData::~CCmsPresenceData() |
|
80 { |
|
81 //The client owns these two guys |
|
82 //delete iMask; |
|
83 //delete iBitmap; |
|
84 delete iBrandId; |
|
85 delete iBrandedText; |
|
86 delete iUserIdentity; |
|
87 delete iElementIdText; |
|
88 delete iElementIdImage; |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------- |
|
92 // CCmsPresenceData::Mask |
|
93 // |
|
94 // ---------------------------------------------------- |
|
95 // |
|
96 EXPORT_C CFbsBitmap* CCmsPresenceData::Mask() const |
|
97 { |
|
98 return iMask; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------- |
|
102 // CCmsPresenceData::~CCmsPresenceData |
|
103 // |
|
104 // ---------------------------------------------------- |
|
105 // |
|
106 EXPORT_C CFbsBitmap* CCmsPresenceData::Bitmap() const |
|
107 { |
|
108 return iBitmap; |
|
109 } |
|
110 |
|
111 // ---------------------------------------------------- |
|
112 // CCmsPresenceData::CompilePresenceDataL |
|
113 // |
|
114 // ---------------------------------------------------- |
|
115 // |
|
116 EXPORT_C TInt CCmsPresenceData::PreparePresenceDataL( TSize aBitmapSize ) |
|
117 { |
|
118 #ifdef _DEBUG |
|
119 RCmsSession::WriteToLog( _L8( "CCmsPresenceData::PreparePresenceDataL()" ) ); |
|
120 #endif |
|
121 TInt error = KErrNotFound; |
|
122 CBSFactory* factory = CreateBrandingFactoryL(); |
|
123 if( factory ) |
|
124 { |
|
125 CleanupStack::PushL( factory ); |
|
126 |
|
127 //reset brand text here |
|
128 delete iBrandedText; |
|
129 iBrandedText = NULL; |
|
130 |
|
131 if ( !iBrandId->Des().Length() ) |
|
132 { |
|
133 // presence cache is reset |
|
134 iMask = new ( ELeave ) CFbsBitmap(); |
|
135 iBitmap = new ( ELeave ) CFbsBitmap(); |
|
136 } |
|
137 else if ( iBrandId->Des().Compare( KTrafficLightService ) ) |
|
138 { |
|
139 error = DoGetIconFromBrandSrvL( *factory, aBitmapSize ); |
|
140 } |
|
141 else |
|
142 { |
|
143 error = DoGetIconFromFileL( aBitmapSize ); |
|
144 } |
|
145 CleanupStack::PopAndDestroy(factory); //factory |
|
146 } |
|
147 return error; |
|
148 } |
|
149 |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CCmsPresenceIconHandler::ElementIdImage |
|
153 // |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 TPtrC8 CCmsPresenceData::ElementIdImage() |
|
157 { |
|
158 return iElementIdImage ? iElementIdImage->Des() : TPtrC8(); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CCmsPresenceIconHandler::CreateBrandingFactoryL |
|
163 // |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 CBSFactory* CCmsPresenceData::CreateBrandingFactoryL() |
|
167 { |
|
168 CBSFactory* factory = NULL; |
|
169 if( iBrandId ) |
|
170 { |
|
171 factory = CBSFactory::NewL( KCPBrandDefaultId, KCPBrandAppId ); |
|
172 } |
|
173 else |
|
174 { |
|
175 #ifdef _DEBUG |
|
176 RCmsSession::WriteToLog( _L8( " Brand ID is NULL, cannot create branding factory" ) ); |
|
177 #endif |
|
178 } |
|
179 return factory; |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CCmsPresenceIconHandler::CopyBitmapL |
|
184 // |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 CFbsBitmap* CCmsPresenceData::CopyBitmapL( CFbsBitmap& aBitmap ) |
|
188 { |
|
189 // Create a temporary bitmap |
|
190 CFbsBitmap* newBitmap = new( ELeave ) CFbsBitmap(); |
|
191 CleanupStack::PushL( newBitmap ); |
|
192 User::LeaveIfError( newBitmap->Create( aBitmap.SizeInPixels(), aBitmap.DisplayMode() ) ); |
|
193 // Create a bitmap device |
|
194 CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( newBitmap ); |
|
195 CleanupStack::PushL( device ); |
|
196 // Create a bitmap context |
|
197 CBitmapContext* context = NULL; |
|
198 User::LeaveIfError( device->CreateBitmapContext( context ) ); |
|
199 CleanupStack::PushL( context ); |
|
200 // Copy contents of aBitmap into the new bitmap |
|
201 context->BitBlt( TPoint( 0,0 ), &aBitmap ); |
|
202 CleanupStack::PopAndDestroy( 2 ); // context, device |
|
203 CleanupStack::Pop(); //newBitmap |
|
204 return newBitmap; |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------- |
|
208 // CCmsPresenceData::BrandedText |
|
209 // |
|
210 // ---------------------------------------------------- |
|
211 // |
|
212 EXPORT_C TPtrC CCmsPresenceData::BrandedText() const |
|
213 { |
|
214 return iBrandedText ? iBrandedText->Des() : TPtrC(); |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------- |
|
218 // CCmsPresenceData::UserIdentity |
|
219 // |
|
220 // ---------------------------------------------------- |
|
221 // |
|
222 EXPORT_C TPtrC8 CCmsPresenceData::UserIdentity() const |
|
223 { |
|
224 return iUserIdentity ? iUserIdentity->Des() : TPtrC8(); |
|
225 } |
|
226 |
|
227 // ---------------------------------------------------- |
|
228 // CCmsPresenceData::ServiceType |
|
229 // |
|
230 // ---------------------------------------------------- |
|
231 // |
|
232 EXPORT_C TUint32 CCmsPresenceData::ServiceType() const |
|
233 { |
|
234 return ( TUint32 )iServiceType; |
|
235 } |
|
236 |
|
237 // ---------------------------------------------------- |
|
238 // CCmsPresenceData::AssignDataL |
|
239 // |
|
240 // ---------------------------------------------------- |
|
241 // |
|
242 void CCmsPresenceData::AssignDataL( TInt aFieldType, const TDesC8& aFieldData ) |
|
243 { |
|
244 #ifdef _DEBUG |
|
245 RCmsSession::WriteToLog( _L8( "CCmsPresenceData::AssignDataL()" ) ); |
|
246 #endif |
|
247 switch( aFieldType ) |
|
248 { |
|
249 case KPresenceDataBrandId: |
|
250 delete iBrandId; |
|
251 iBrandId = NULL; |
|
252 iBrandId = aFieldData.AllocL(); |
|
253 break; |
|
254 case KPresenceDataElementTextId: |
|
255 delete iElementIdText; |
|
256 iElementIdText = NULL; |
|
257 iElementIdText = aFieldData.AllocL(); |
|
258 break; |
|
259 case KPresenceDataElementImageId: |
|
260 delete iElementIdImage; |
|
261 iElementIdImage = NULL; |
|
262 iElementIdImage = aFieldData.AllocL(); |
|
263 break; |
|
264 case KPresenceDataLanguageId: |
|
265 { |
|
266 TLex8 lex( aFieldData ); |
|
267 lex.Val( iLanguageId ); |
|
268 } |
|
269 break; |
|
270 case KPresenceDataServiceType: |
|
271 { |
|
272 TLex8 lex( aFieldData ); |
|
273 lex.Val( iServiceType ); |
|
274 } |
|
275 break; |
|
276 case KPresenceDataUserIdentity: |
|
277 delete iUserIdentity; |
|
278 iUserIdentity = NULL; |
|
279 iUserIdentity = aFieldData.AllocL(); |
|
280 break; |
|
281 default: |
|
282 break; |
|
283 } |
|
284 } |
|
285 |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CCmsPresenceIconHandler::DoGetIconFromBrandSrvL |
|
289 // |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 TInt CCmsPresenceData::DoGetIconFromBrandSrvL( CBSFactory& aFactory, TSize aBitmapSize ) |
|
293 { |
|
294 TLanguage userLang = User::Language(); |
|
295 TLanguage defLang = ELangInternationalEnglish; |
|
296 |
|
297 //Search for BrandPackage using PhoneLanguage |
|
298 //PhoneLanguage gets the Highest Priority |
|
299 TRAPD(err, DoGetIconFromBrandSrvL( aFactory, aBitmapSize, ( TLanguage ) userLang )); |
|
300 |
|
301 if ( ( err ) && ( iLanguageId != KErrNotFound ) && ( iLanguageId != userLang ) ) |
|
302 { |
|
303 //The next priority goes to BrandLanguage set in the SpSettings/service table |
|
304 //during provisioning |
|
305 //Search for BrandPackage using this BrandLanguage |
|
306 TRAP( err, DoGetIconFromBrandSrvL( aFactory, aBitmapSize, ( TLanguage ) iLanguageId ) ); |
|
307 } |
|
308 |
|
309 |
|
310 if ( ( err ) && ( userLang != defLang ) && ( iLanguageId != defLang ) ) |
|
311 { |
|
312 //Fetching of brand with UserLang & with the one mentioned in the Servicetable |
|
313 //was not successfull. |
|
314 //Finally try with Default Language ID and even if this fails |
|
315 //proceed without any brand icons/texts |
|
316 TRAP( err, DoGetIconFromBrandSrvL( aFactory, aBitmapSize, ( TLanguage ) defLang ) ); |
|
317 } |
|
318 |
|
319 return err; |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CCmsPresenceIconHandler::DoGetIconFromBrandSrvL |
|
325 // |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 TInt CCmsPresenceData::DoGetIconFromBrandSrvL( CBSFactory& aFactory, TSize aBitmapSize, TLanguage aLanguage ) |
|
329 { |
|
330 TInt error = KErrNone; |
|
331 |
|
332 MBSAccess* access = aFactory.CreateAccessLC( iBrandId->Des(), ( TLanguage )aLanguage ); |
|
333 |
|
334 CFbsBitmap* mask = NULL; |
|
335 CFbsBitmap* bitmap = NULL; |
|
336 |
|
337 TRAP( error, access->GetBitmapL( ElementIdImage(), bitmap, mask ) ); |
|
338 if( KErrNone == error ) |
|
339 { |
|
340 CleanupStack::PushL( mask ); |
|
341 CleanupStack::PushL( bitmap ); |
|
342 AknIconUtils::SetSize( mask, aBitmapSize ); |
|
343 AknIconUtils::SetSize( bitmap, aBitmapSize ); |
|
344 iMask = CopyBitmapL( *mask ); |
|
345 iBitmap = CopyBitmapL( *bitmap ); |
|
346 CleanupStack::PopAndDestroy( 2 ); //bitmap, mask |
|
347 } |
|
348 else |
|
349 { |
|
350 //instantiate bitmaps |
|
351 iMask = new ( ELeave ) CFbsBitmap(); |
|
352 iBitmap = new ( ELeave ) CFbsBitmap(); |
|
353 } |
|
354 |
|
355 delete iBrandedText; |
|
356 iBrandedText = NULL; |
|
357 if ( iElementIdText && iElementIdText->Length() ) |
|
358 { |
|
359 iBrandedText = access->GetTextL( iElementIdText->Des() ); |
|
360 } |
|
361 |
|
362 CleanupStack::PopAndDestroy(); //access |
|
363 return error; |
|
364 } |
|
365 |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // CCmsPresenceIconHandler::DoGetIconFromFileL |
|
369 // |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 TInt CCmsPresenceData::DoGetIconFromFileL( TSize aBitmapSize ) |
|
373 { |
|
374 TInt error = KErrNone; |
|
375 |
|
376 CFbsBitmap *bitmap = NULL; |
|
377 CFbsBitmap *mask = NULL; |
|
378 |
|
379 TInt bitmapId(0); |
|
380 TInt maskId(0); |
|
381 |
|
382 if ( !(ElementIdImage().CompareF( KTrafficOnline ))) |
|
383 { |
|
384 bitmapId = EMbmPresencetrafficlightsQgn_prop_im_friend_on; |
|
385 maskId = EMbmPresencetrafficlightsQgn_prop_im_friend_on_mask; |
|
386 } |
|
387 else if ( !(ElementIdImage().CompareF( KTrafficOffline ))) |
|
388 { |
|
389 bitmapId = EMbmPresencetrafficlightsQgn_prop_im_friend_off; |
|
390 maskId = EMbmPresencetrafficlightsQgn_prop_im_friend_off_mask; |
|
391 } |
|
392 else |
|
393 { |
|
394 } |
|
395 |
|
396 TRAP(error, AknIconUtils::CreateIconL( |
|
397 bitmap, |
|
398 mask, |
|
399 KPresenceTrafficLightsMif, |
|
400 bitmapId, |
|
401 maskId)); |
|
402 |
|
403 if ( error ) |
|
404 { |
|
405 //instantiate bitmaps |
|
406 iMask = new ( ELeave ) CFbsBitmap(); |
|
407 iBitmap = new ( ELeave ) CFbsBitmap(); |
|
408 } |
|
409 else |
|
410 { |
|
411 AknIconUtils::SetSize( bitmap, aBitmapSize ); |
|
412 AknIconUtils::SetSize( mask, aBitmapSize ); |
|
413 iBitmap = bitmap; |
|
414 iMask = mask; |
|
415 } |
|
416 |
|
417 return error; |
|
418 |
|
419 } |
|
420 |
|
421 // End of File |