|
1 /* |
|
2 * Copyright (c) 2009 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: Service icon manager |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "spbserviceiconprovider.h" |
|
19 |
|
20 #include <cbsfactory.h> |
|
21 #include <mbsaccess.h> |
|
22 #include <gulicon.h> |
|
23 #include <TPbk2IconId.h> |
|
24 #include <AknIconUtils.h> |
|
25 #include <fbs.h> |
|
26 #include <Pbk2NamesListExUID.h> |
|
27 |
|
28 // CONSTS |
|
29 |
|
30 namespace { |
|
31 |
|
32 // Application id for branded icons |
|
33 _LIT8( KApplicationId, "xsp" ); |
|
34 |
|
35 // Staring index for icon id's |
|
36 const TInt KIconIndexStartValue = 500; |
|
37 |
|
38 // Used UID for icon id's |
|
39 const TInt KIconUidValue = KPbk2NamesListExtPluginUID2; |
|
40 } |
|
41 |
|
42 /** |
|
43 * Icon information container class |
|
44 */ |
|
45 NONSHARABLE_CLASS( CSpbIconItem ) : public CBase, public MSpbServiceIcon |
|
46 { |
|
47 public: |
|
48 |
|
49 /** |
|
50 * Constructor |
|
51 */ |
|
52 static CSpbIconItem* NewLC( |
|
53 const TPbk2IconId& aIconId, |
|
54 const TDesC8& aBrandId, |
|
55 const TDesC8& aBrandIconId, |
|
56 CBSFactory& aBrandFactory ); |
|
57 |
|
58 /** |
|
59 * Destructor |
|
60 */ |
|
61 ~CSpbIconItem(); |
|
62 |
|
63 private: |
|
64 |
|
65 /** |
|
66 * Constructor |
|
67 */ |
|
68 inline CSpbIconItem( |
|
69 const TPbk2IconId& aIconId, |
|
70 CBSFactory& aBrandFactory ); |
|
71 |
|
72 /** |
|
73 * Constructor |
|
74 */ |
|
75 inline void ConstructL( |
|
76 const TDesC8& aBrandId, |
|
77 const TDesC8& aBrandIconId ); |
|
78 |
|
79 public: // From MPbk2ServiceIcon |
|
80 const TPtrC8 BrandId() const { return *iBrandId; } |
|
81 const TPtrC8 BrandIconId() const { return *iBrandIconId; } |
|
82 const TPbk2IconId& IconId() const { return iIconId; } |
|
83 TBool IsValid() const { return iValid; } |
|
84 |
|
85 public: |
|
86 |
|
87 /** |
|
88 * Precreate icon from branding server. Calling this method makes the next |
|
89 * call to CreateIconLC faster because the icon is already cached. |
|
90 */ |
|
91 void PreCreateIconL(); |
|
92 |
|
93 /** |
|
94 * Create branded icon from branding server. Ownership of the returned |
|
95 * icon is transferred to caller. |
|
96 * |
|
97 * @return branded icon |
|
98 */ |
|
99 CGulIcon* CreateIconLC(); |
|
100 |
|
101 public: // find helpers |
|
102 |
|
103 /** |
|
104 * Helper class to store full branding information |
|
105 */ |
|
106 class TBrandId |
|
107 { |
|
108 public: |
|
109 TBrandId( const TDesC8& aBrand, const TDesC8& aIcon ) : |
|
110 iBrandId( aBrand ), iBrandIconId( aIcon ) {} |
|
111 const TPtrC8 iBrandId; |
|
112 const TPtrC8 iBrandIconId; |
|
113 }; |
|
114 |
|
115 /** |
|
116 * Comparison method to check if icon item matches with brand id |
|
117 */ |
|
118 static TBool EqualBrand( const TBrandId* aId, const CSpbIconItem& aItem ); |
|
119 |
|
120 /** |
|
121 * Comparison method to check if icon item matches icon id |
|
122 */ |
|
123 static TBool EqualId( const TPbk2IconId* aId, const CSpbIconItem& aItem ); |
|
124 |
|
125 private: |
|
126 |
|
127 /* |
|
128 * Returns Access based on language |
|
129 */ |
|
130 MBSAccess* AccessL(); |
|
131 |
|
132 private: |
|
133 /// Own. Branding id for icon |
|
134 HBufC8* iBrandId; |
|
135 /// Own. Branding element id for icon |
|
136 HBufC8* iBrandIconId; |
|
137 /// Own. Bitmap cache for icon |
|
138 CFbsBitmap* iBitmap; |
|
139 /// Own. Mask cache for icon |
|
140 CFbsBitmap* iMask; |
|
141 /// Icon ID |
|
142 TPbk2IconId iIconId; |
|
143 /// Not own. Branding server interface |
|
144 CBSFactory& iBrandFactory; |
|
145 /// Is icon valid (e.g. no loading errors occured) |
|
146 TBool iValid; |
|
147 }; |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CSpbIconItem::NewLC |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 CSpbIconItem* CSpbIconItem::NewLC( |
|
155 const TPbk2IconId& aIconId, |
|
156 const TDesC8& aBrandId, |
|
157 const TDesC8& aBrandIconId, |
|
158 CBSFactory& aBrandFactory ) |
|
159 { |
|
160 CSpbIconItem* self = new(ELeave) CSpbIconItem( aIconId, aBrandFactory ); |
|
161 CleanupStack::PushL( self ); |
|
162 self->ConstructL( aBrandId, aBrandIconId ); |
|
163 return self; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CSpbIconItem::~CSpbIconItem |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 CSpbIconItem::~CSpbIconItem() |
|
171 { |
|
172 delete iBrandId; |
|
173 delete iBrandIconId; |
|
174 delete iBitmap; |
|
175 delete iMask; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CSpbIconItem::CSpbIconItem |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 inline CSpbIconItem::CSpbIconItem( |
|
183 const TPbk2IconId& aIconId, |
|
184 CBSFactory& aBrandFactory ) : |
|
185 iIconId( aIconId ), |
|
186 iBrandFactory( aBrandFactory ), |
|
187 iValid( ETrue ) |
|
188 { |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CSpbIconItem::ConstructL |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 inline void CSpbIconItem::ConstructL( |
|
196 const TDesC8& aBrandId, |
|
197 const TDesC8& aBrandIconId ) |
|
198 { |
|
199 iBrandId = aBrandId.AllocL(); |
|
200 iBrandIconId = aBrandIconId.AllocL(); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // CSpbIconItem::EqualBrand |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 TBool CSpbIconItem::EqualBrand( const TBrandId* aId, const CSpbIconItem& aItem ) |
|
208 { |
|
209 if( aId->iBrandId.Compare( *aItem.iBrandId ) || |
|
210 aId->iBrandIconId.Compare( *aItem.iBrandIconId ) ) |
|
211 { |
|
212 // not equal |
|
213 return EFalse; |
|
214 } |
|
215 // equal |
|
216 return ETrue; |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CSpbIconItem::EqualId |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 TBool CSpbIconItem::EqualId( const TPbk2IconId* aId, const CSpbIconItem& aItem ) |
|
224 { |
|
225 return aItem.iIconId == *aId; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CSpbIconItem::AccessL |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 MBSAccess* CSpbIconItem::AccessL() |
|
233 { |
|
234 MBSAccess* access = NULL; |
|
235 TInt err = 0; |
|
236 // try with user lang |
|
237 TRAP( err, access = iBrandFactory.CreateAccessL( *iBrandId, User::Language() ) ); |
|
238 if( err ) |
|
239 { |
|
240 // didn't find it, use international english |
|
241 access = iBrandFactory.CreateAccessL( *iBrandId, ELangInternationalEnglish ); |
|
242 } |
|
243 return access; |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // CSpbIconItem::PreCreateIconL |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 void CSpbIconItem::PreCreateIconL() |
|
252 { |
|
253 // set invalid until loading is successful |
|
254 iValid = EFalse; |
|
255 |
|
256 // access based on language |
|
257 MBSAccess* access = AccessL(); |
|
258 CleanupClosePushL( *access ); |
|
259 |
|
260 // get icon from branding server |
|
261 CFbsBitmap* bitmap = NULL; |
|
262 CFbsBitmap* mask = NULL; |
|
263 access->GetBitmapL( *iBrandIconId, bitmap, mask ); |
|
264 CleanupStack::PopAndDestroy(); // access |
|
265 |
|
266 // store icon locally for now |
|
267 delete iBitmap; |
|
268 iBitmap = bitmap; |
|
269 delete iMask; |
|
270 iMask = mask; |
|
271 iValid = ETrue; |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CSpbIconItem::CreateIconLC |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 CGulIcon* CSpbIconItem::CreateIconLC() |
|
279 { |
|
280 if( !iBitmap ) |
|
281 { |
|
282 // we don't have the icon pre-created. create it now. |
|
283 PreCreateIconL(); |
|
284 } |
|
285 CGulIcon* icon = CGulIcon::NewL( iBitmap, iMask ); |
|
286 iBitmap = NULL; // give out ownership |
|
287 iMask = NULL; |
|
288 CleanupStack::PushL( icon ); |
|
289 return icon; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // CSpbServiceIconProvider::NewL |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 CSpbServiceIconProvider* CSpbServiceIconProvider::NewL() |
|
297 { |
|
298 CSpbServiceIconProvider* self = new( ELeave ) CSpbServiceIconProvider; |
|
299 CleanupStack::PushL( self ); |
|
300 self->ConstructL(); |
|
301 CleanupStack::Pop( self ); |
|
302 return self; |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // CSpbServiceIconProvider::~CSpbServiceIconProvider |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 CSpbServiceIconProvider::~CSpbServiceIconProvider() |
|
310 { |
|
311 iIconArray.ResetAndDestroy(); |
|
312 delete iBrandFactory; |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // CSpbServiceIconProvider::CSpbServiceIconProvider |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 inline CSpbServiceIconProvider::CSpbServiceIconProvider() : |
|
320 iNextFreeIconIndex( KIconIndexStartValue ) |
|
321 { |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // CSpbServiceIconProvider::ConstructL |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 inline void CSpbServiceIconProvider::ConstructL() |
|
329 { |
|
330 // no default brand used |
|
331 iBrandFactory = CBSFactory::NewL( KNullDesC8, KApplicationId ); |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // CSpbServiceIconProvider::GetBrandedIconL |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 MSpbServiceIcon* CSpbServiceIconProvider::GetBrandedIconL( |
|
339 const TDesC8& aBrandId, const TDesC8& aIconId ) |
|
340 { |
|
341 CSpbIconItem::TBrandId brand( aBrandId, aIconId ); |
|
342 TInt index = iIconArray.Find( brand, &CSpbIconItem::EqualBrand ); |
|
343 |
|
344 if( index < 0 ) |
|
345 { |
|
346 // New icon. Create it |
|
347 CSpbIconItem* icon = CSpbIconItem::NewLC( |
|
348 TPbk2IconId( TUid::Uid( KIconUidValue ), iNextFreeIconIndex++ ), |
|
349 aBrandId, aIconId, *iBrandFactory ); |
|
350 |
|
351 index = iIconArray.Count(); |
|
352 iIconArray.AppendL( icon ); |
|
353 CleanupStack::Pop( icon ); |
|
354 |
|
355 // attempt pre-creation. if it fails the icon is marked as invalid |
|
356 TRAP_IGNORE( icon->PreCreateIconL() ); |
|
357 } |
|
358 return iIconArray[index]; |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // CSpbServiceIconProvider::CreateIconLC |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 CGulIcon* CSpbServiceIconProvider::CreateIconLC( const TPbk2IconId& aIconId ) |
|
366 { |
|
367 TInt index = iIconArray.Find( aIconId, &CSpbIconItem::EqualId ); |
|
368 if( index < 0 ) |
|
369 { |
|
370 User::Leave( KErrNotFound ); |
|
371 } |
|
372 |
|
373 return iIconArray[index]->CreateIconLC(); |
|
374 } |
|
375 |
|
376 |
|
377 // end of file |