|
1 /* |
|
2 * Copyright (c) 2008 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: CAknIconSrvPrecacher class. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifdef PRECACHE2 |
|
20 #include <e32std.h> |
|
21 #include <fbs.h> |
|
22 #include <barsread.h> |
|
23 #include <barsc.h> |
|
24 #include "AknIconSrvPrecacher.h" |
|
25 #include "AknIconSrv.h" |
|
26 #include <AknIconSrv.rsg> |
|
27 #include "AknIconTraces.h" |
|
28 |
|
29 #include "AknIconSrv.h" |
|
30 #include "AknIconLoader.h" |
|
31 #include "AknIconSrvCache.h" |
|
32 #include "AknIconSrvDef.h" |
|
33 #include "AknIconManager.h" |
|
34 #include "AknIconSrvIconItem.h" |
|
35 #include "AknIconSrvUtils.h" |
|
36 #include "AknIconUtils.h" |
|
37 #include "mifconvdefs.h" |
|
38 #include "AknSvgFormatHandler.h" |
|
39 #include "akniconconfig.h" |
|
40 #include "AknIconFormatHandlerFactory.h" |
|
41 |
|
42 _LIT( KAknIconResourceFile, "z:\\resource\\akniconsrv.rsc" ); |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // 2 Phase Construction |
|
46 // ----------------------------------------------------------------------------- |
|
47 CAknIconSrvPrecacher::CAknIconSrvPrecacher( CAknIconServer& aServer ) : |
|
48 iServer(aServer) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // 2 Phase Construction |
|
54 // ----------------------------------------------------------------------------- |
|
55 CAknIconSrvPrecacher* CAknIconSrvPrecacher::NewL( CAknIconServer& aServer ) |
|
56 { |
|
57 CAknIconSrvPrecacher* self = new( ELeave ) CAknIconSrvPrecacher( aServer ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // 2 Phase Construction |
|
66 // ----------------------------------------------------------------------------- |
|
67 void CAknIconSrvPrecacher::ConstructL() |
|
68 { |
|
69 User::LeaveIfError( iFs.Connect() ); |
|
70 iSvgFormatHandler = CAknSvgFormatHandler::NewL(); |
|
71 User::LeaveIfError( RFbsSession::Connect() ); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // Destructor |
|
76 // ----------------------------------------------------------------------------- |
|
77 CAknIconSrvPrecacher::~CAknIconSrvPrecacher() |
|
78 { |
|
79 delete iLoader; |
|
80 delete iSvgFormatHandler; |
|
81 RFbsSession::Disconnect(); |
|
82 iFs.Close(); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // Start reading from precache list |
|
87 // ----------------------------------------------------------------------------- |
|
88 void CAknIconSrvPrecacher::Start() |
|
89 { |
|
90 HBufC8* res = NULL ; |
|
91 TRAPD(err, res = SetupL()); |
|
92 if (err == KErrNone) |
|
93 { |
|
94 TResourceReader reader; |
|
95 reader.SetBuffer( res ); |
|
96 |
|
97 TRAPD(merror, ReadPrecacheItemsL( reader)); |
|
98 |
|
99 if(merror != KErrNone) |
|
100 { |
|
101 #ifdef __AKNICON_TRACES |
|
102 RDebug::Printf("Error Processing Precacher List"); |
|
103 #endif |
|
104 } |
|
105 |
|
106 iServer.iPrecacheComplete = ETrue; |
|
107 RThread thread; |
|
108 thread.Suspend(); |
|
109 |
|
110 while (iServer.iFreePrecacheBitmapHandles.Count()) |
|
111 { |
|
112 CFbsBitmap* bitmap = iServer.iFreePrecacheBitmapHandles[0]; |
|
113 delete bitmap; |
|
114 iServer.iFreePrecacheBitmapHandles.Remove(0); |
|
115 } |
|
116 iServer.iFreePrecacheBitmapHandles.Close(); |
|
117 } |
|
118 if(res) |
|
119 { |
|
120 delete res; |
|
121 } |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // read each item from the list |
|
126 // ----------------------------------------------------------------------------- |
|
127 TInt CAknIconSrvPrecacher::ReadPrecacheItemsL(TResourceReader& aReader) |
|
128 { |
|
129 TInt count = aReader.ReadInt16(); |
|
130 if (count > 0) |
|
131 { |
|
132 User::LeaveIfError( iSkinSession.Connect( ) ); |
|
133 |
|
134 CAknsSrvChunkLookup* lookup = iSkinSession.CreateChunkLookupL(); |
|
135 CleanupStack::PushL( lookup ); |
|
136 |
|
137 |
|
138 iCurrentFileName.Zero(); |
|
139 |
|
140 |
|
141 for ( TInt i = 0 ; i < count ; i++ ) |
|
142 { |
|
143 #ifdef __AKNICON_TRACES |
|
144 RDebug::Printf("precache loop,%d,%d",i,count); |
|
145 #endif |
|
146 |
|
147 TRAPD(error,ProcessEntryL(lookup, aReader)); |
|
148 |
|
149 if(error != KErrNone) |
|
150 { |
|
151 #ifdef __AKNICON_TRACES |
|
152 RDebug::Printf("Error Processing Precacher List"); |
|
153 #endif |
|
154 } |
|
155 |
|
156 } |
|
157 |
|
158 CleanupStack::PopAndDestroy( 1 ); // lookup |
|
159 iSkinSession.Close(); |
|
160 |
|
161 } |
|
162 return count; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // read each entry into iNewprecached items |
|
167 // ----------------------------------------------------------------------------- |
|
168 void CAknIconSrvPrecacher::ProcessEntryL(CAknsSrvChunkLookup* lookup, TResourceReader& aReader) |
|
169 { |
|
170 TAknIconParams info; |
|
171 info.iRotationAngle = 0; |
|
172 info.iColor = KColorNotDefined; |
|
173 |
|
174 TFileName file; |
|
175 |
|
176 TInt skinIdMajor = aReader.ReadInt32(); |
|
177 TInt skinIdMinor = aReader.ReadInt32(); |
|
178 |
|
179 HBufC* temp; |
|
180 temp = aReader.ReadHBufC16L(); |
|
181 |
|
182 |
|
183 if (temp) |
|
184 { |
|
185 file.Copy(temp->Des()); |
|
186 delete temp; |
|
187 } |
|
188 else |
|
189 { |
|
190 file.Zero(); |
|
191 } |
|
192 |
|
193 info.iBitmapId = aReader.ReadInt32(); |
|
194 info.iMaskId = aReader.ReadInt32(); |
|
195 TInt width = aReader.ReadInt32(); |
|
196 TInt height = aReader.ReadInt32(); |
|
197 info.iSize = TSize(width,height); |
|
198 info.iMode = (TScaleMode)aReader.ReadInt32(); |
|
199 info.iAppIcon = EFalse; |
|
200 // Convert icon ID to MIF ID |
|
201 if ( info.iBitmapId >= KMifIdFirst ) |
|
202 { |
|
203 info.iBitmapId -= KMifIdFirst; |
|
204 } |
|
205 if ( info.iMaskId >= KMifIdFirst ) |
|
206 { |
|
207 info.iMaskId -= KMifIdFirst; |
|
208 } |
|
209 |
|
210 if (skinIdMajor != -1 || skinIdMinor != -1) |
|
211 { |
|
212 TAknsItemID id = { skinIdMajor, skinIdMinor }; |
|
213 CAknsItemDef* def = lookup->LookupAndCreateDefL( id ); |
|
214 if ( def ) |
|
215 { |
|
216 CleanupStack::PushL( def ); |
|
217 |
|
218 TAknsItemType type = def->Type(); |
|
219 |
|
220 switch ( type ) |
|
221 { |
|
222 case EAknsITBitmap: |
|
223 { |
|
224 info.iBitmapId=(*static_cast<CAknsBitmapItemDef*>( def )).Index(); |
|
225 if ( info.iBitmapId >= KMifIdFirst ) |
|
226 { |
|
227 info.iBitmapId -= KMifIdFirst; |
|
228 } |
|
229 info.iMaskId = -1; |
|
230 file = (*static_cast<CAknsBitmapItemDef*>( def )).Filename(); |
|
231 break; |
|
232 } |
|
233 case EAknsITMaskedBitmap: |
|
234 { |
|
235 info.iBitmapId=(*static_cast<CAknsBitmapItemDef*>( def )).Index(); |
|
236 if ( info.iBitmapId >= KMifIdFirst ) |
|
237 { |
|
238 info.iBitmapId -= KMifIdFirst; |
|
239 } |
|
240 info.iMaskId = info.iBitmapId + 1; |
|
241 |
|
242 file = (*static_cast<CAknsBitmapItemDef*>( def )).Filename(); |
|
243 break; |
|
244 } |
|
245 default: |
|
246 { |
|
247 break; |
|
248 } |
|
249 } |
|
250 CleanupStack::PopAndDestroy(); // def |
|
251 } |
|
252 } |
|
253 if (file.Length() == 0) |
|
254 { |
|
255 #ifdef __AKNICON_TRACES |
|
256 RDebug::Printf("Precacher resource: File name invalid"); |
|
257 #endif |
|
258 |
|
259 return; |
|
260 } |
|
261 |
|
262 if ( iCurrentFileName != file || iLoader == NULL ) |
|
263 { |
|
264 delete iLoader; |
|
265 iLoader = NULL; |
|
266 iLoader = CAknIconLoader::NewL( iFs, file ); |
|
267 #ifdef _NGATESTING |
|
268 iLoader->SetIconTypeConfig(iServer.iConfigIconType, iServer.iNGADirectory); |
|
269 #endif |
|
270 |
|
271 iCurrentFileName = file; |
|
272 } |
|
273 if( iLoader == NULL ) |
|
274 { |
|
275 #ifdef __AKNICON_TRACES |
|
276 RDebug::Printf("Precacher resource: Unable to create iLoader"); |
|
277 #endif |
|
278 |
|
279 return; |
|
280 } |
|
281 TPtrC8 iconData ; |
|
282 iconData.Set(iLoader->IconL( info.iBitmapId )); |
|
283 |
|
284 TDisplayMode bitmapDepth; |
|
285 bitmapDepth = (TDisplayMode)iLoader->IconDepthL( info.iBitmapId ); |
|
286 |
|
287 /* TDisplayMode maskDepth; |
|
288 maskDepth = */(TDisplayMode)iLoader->MaskDepthL( info.iBitmapId ); |
|
289 |
|
290 iSvgFormatHandler->SupportedDisplayMode(bitmapDepth, iServer.iIconMode ); |
|
291 |
|
292 |
|
293 TInt iconHandle; |
|
294 |
|
295 iSvgFormatHandler->PrepareIconL( iconData, iconHandle ); |
|
296 |
|
297 |
|
298 iLoader->FreeIcon(); |
|
299 |
|
300 iSvgFormatHandler->UsePreparedIconL( iconHandle ); |
|
301 |
|
302 |
|
303 |
|
304 CFbsBitmap* bitmap = new( ELeave ) CFbsBitmap; |
|
305 CleanupStack::PushL( bitmap ); |
|
306 |
|
307 CFbsBitmap* mask = NULL; |
|
308 if ( info.iMaskId >= 0 ) |
|
309 { |
|
310 mask = new( ELeave ) CFbsBitmap; |
|
311 CleanupStack::PushL( mask ); |
|
312 } |
|
313 |
|
314 TAknContentDimensions dimensions; |
|
315 |
|
316 dimensions = AknIconSrvUtils::RenderPreparedIconL( |
|
317 *iSvgFormatHandler, |
|
318 bitmap, |
|
319 mask, |
|
320 bitmapDepth, |
|
321 iServer.IconDepth(), |
|
322 info.iSize, |
|
323 (TScaleMode)info.iMode, |
|
324 0 //RotationAngle |
|
325 ); |
|
326 |
|
327 |
|
328 |
|
329 iSvgFormatHandler->UnprepareIcon( iconHandle ); |
|
330 |
|
331 // |
|
332 if (file.Left( KAknIconDefaultDirLength ) == KAknIconDefaultDir ) |
|
333 { |
|
334 info.iFileName = file.Mid( KAknIconDefaultDirLength ); |
|
335 info.SetDefaultIconDirUsed(); |
|
336 } |
|
337 else |
|
338 { |
|
339 info.iFileName = file; |
|
340 } |
|
341 // |
|
342 CAknIconSrvIconItem* item; |
|
343 |
|
344 item = CAknIconSrvIconItem::NewL( info, bitmap, mask, dimensions, *(iServer.iFileNameCache )); |
|
345 CleanupStack::PushL(item);//item |
|
346 |
|
347 item->iUserCount--; |
|
348 |
|
349 if ( mask ) |
|
350 { |
|
351 item->iUserCount--; |
|
352 } |
|
353 item->iPrecacheItem = ETrue; |
|
354 iServer.iNewPrecachedItems.AppendL(item); |
|
355 CleanupStack::Pop(); // item |
|
356 |
|
357 if ( mask ) |
|
358 { |
|
359 CleanupStack::Pop(); // mask |
|
360 } |
|
361 CleanupStack::Pop(); //bitmap |
|
362 |
|
363 } |
|
364 |
|
365 HBufC8* CAknIconSrvPrecacher::SetupL() |
|
366 { |
|
367 RResourceFile file; |
|
368 file.OpenL( iFs, KAknIconResourceFile ) ; |
|
369 CleanupClosePushL( file ); |
|
370 HBufC8* res =file.AllocReadLC( R_PRECACHE_LIST2 ); |
|
371 CleanupStack::Pop(1); // res |
|
372 CleanupStack::PopAndDestroy(1);//file |
|
373 |
|
374 return res; |
|
375 |
|
376 } |
|
377 #endif |
|
378 // ------------------------------EndOfFile------------------------------------------- |
|
379 |