|
1 /* |
|
2 * Copyright (c) 2008-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: Thumbnail background generation task implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 31/07/2007 by Simon Brooks |
|
23 */ |
|
24 |
|
25 // INCLUDE FILES |
|
26 |
|
27 #include "glxtnbackgroundgenerationtask.h" |
|
28 |
|
29 #include <fbs.h> |
|
30 #include <glxassert.h> |
|
31 #include <glxtracer.h> |
|
32 #include <glxthumbnail.h> |
|
33 #include <featmgr.h> |
|
34 #include <bldvariant.hrh> // For feature constants |
|
35 |
|
36 #include "glxtnfileinfo.h" |
|
37 #include "glxtnfileutility.h" |
|
38 #include "glxtnimageutility.h" |
|
39 #include "glxtnvideoutility.h" |
|
40 #include "mglxtnstorage.h" |
|
41 #include "mglxtnthumbnailcreatorclient.h" |
|
42 |
|
43 |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CGlxtnBackgroundGenerationTask::CGlxtnBackgroundGenerationTask |
|
49 // C++ default constructor can NOT contain any code, that might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CGlxtnBackgroundGenerationTask::CGlxtnBackgroundGenerationTask( |
|
53 const TGlxMediaId& iItemId, CGlxtnFileUtility& aFileUtility, |
|
54 MGlxtnThumbnailCreatorClient& aClient, |
|
55 CGlxSettingsModel::TSupportedOrientations aSupportedOrientations) : |
|
56 CGlxtnSaveThumbnailTask(KGlxtnTaskIdBackgroundThumbnailGeneration, |
|
57 iItemId, aClient.ThumbnailStorage()), |
|
58 iClient(&aClient), iFileUtility(aFileUtility), |
|
59 iSupportedOrientations(aSupportedOrientations) |
|
60 { |
|
61 TRACER("CGlxtnBackgroundGenerationTask::CGlxtnBackgroundGenerationTask()"); |
|
62 // Background task is always low priority |
|
63 SetPriority(EPriorityLow); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CGlxtnBackgroundGenerationTask::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CGlxtnBackgroundGenerationTask::ConstructL() |
|
72 { |
|
73 TRACER("void CGlxtnBackgroundGenerationTask::ConstructL()"); |
|
74 iImageUtility = new (ELeave) CGlxtnImageUtility(iFileUtility.FsSession()); |
|
75 LayoutSpecificDataL(); |
|
76 |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CGlxtnBackgroundGenerationTask::NewL |
|
81 // Two-phased constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CGlxtnBackgroundGenerationTask* CGlxtnBackgroundGenerationTask::NewL( |
|
85 const TGlxMediaId& iItemId, CGlxtnFileUtility& aFileUtility, |
|
86 MGlxtnThumbnailCreatorClient& aClient, |
|
87 CGlxSettingsModel::TSupportedOrientations aSupportedOrientations) |
|
88 { |
|
89 TRACER("CGlxtnBackgroundGenerationTask* CGlxtnBackgroundGenerationTask::NewL()"); |
|
90 CGlxtnBackgroundGenerationTask* self |
|
91 = new (ELeave) CGlxtnBackgroundGenerationTask( |
|
92 iItemId, aFileUtility, aClient, |
|
93 aSupportedOrientations); |
|
94 CleanupStack::PushL(self); |
|
95 self->ConstructL(); |
|
96 CleanupStack::Pop( self ); |
|
97 |
|
98 return self; |
|
99 } |
|
100 |
|
101 // Destructor |
|
102 CGlxtnBackgroundGenerationTask::~CGlxtnBackgroundGenerationTask() |
|
103 { |
|
104 TRACER("Destructor CGlxtnBackgroundGenerationTask::~CGlxtnBackgroundGenerationTask()"); |
|
105 delete iImageUtility; |
|
106 delete iVideoUtility; |
|
107 delete iImage; |
|
108 delete iFilteredImage; |
|
109 iSizes.Close(); |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // DoStartL |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TBool CGlxtnBackgroundGenerationTask::DoStartL(TRequestStatus& aStatus) |
|
117 { |
|
118 TRACER("CGlxtnBackgroundGenerationTask::DoStartL()"); |
|
119 // Sizes to generate, largest first |
|
120 |
|
121 |
|
122 iSizes.AppendL(iGridIconSize); |
|
123 if( CGlxSettingsModel::ELandscapeAndPortrait == iSupportedOrientations ) |
|
124 { |
|
125 iSizes.AppendL(iCoverflowIconSize); |
|
126 iSizes.AppendL(TSize(iCoverflowIconSize.iHeight, iCoverflowIconSize.iWidth)); |
|
127 } |
|
128 else if(CGlxSettingsModel::ELandscape == iSupportedOrientations) |
|
129 { |
|
130 iSizes.AppendL(iCoverflowIconSize); |
|
131 } |
|
132 else |
|
133 { |
|
134 iSizes.AppendL(TSize(iCoverflowIconSize.iHeight, iCoverflowIconSize.iWidth)); |
|
135 } |
|
136 |
|
137 iFileInfo = new (ELeave) CGlxtnFileInfo; |
|
138 iClient->FetchFileInfoL(iFileInfo, ItemId(), &aStatus); |
|
139 iState = EStateFetchingUri; |
|
140 |
|
141 return ETrue; // Request has been issued |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // DoCancel |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CGlxtnBackgroundGenerationTask::DoCancel() |
|
149 { |
|
150 TRACER("void CGlxtnBackgroundGenerationTask::DoCancel()"); |
|
151 CGlxtnSaveThumbnailTask::DoCancel(); |
|
152 |
|
153 Storage()->NotifyBackgroundError(ItemId(), KErrCancel); |
|
154 |
|
155 if ( iClient && EStateFetchingUri == iState ) |
|
156 { |
|
157 iClient->CancelFetchUri(ItemId()); |
|
158 } |
|
159 |
|
160 iImageUtility->Cancel(); |
|
161 |
|
162 if ( iVideoUtility ) |
|
163 { |
|
164 iVideoUtility->Cancel(); |
|
165 } |
|
166 |
|
167 iFileUtility.ClearBadFileMarker(); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // DoRunL |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 TBool CGlxtnBackgroundGenerationTask::DoRunL(TRequestStatus& aStatus) |
|
175 { |
|
176 TRACER("TBool CGlxtnBackgroundGenerationTask::DoRunL()"); |
|
177 User::LeaveIfError(aStatus.Int()); |
|
178 |
|
179 TBool active = EFalse; |
|
180 |
|
181 switch ( iState ) |
|
182 { |
|
183 case EStateFetchingUri: |
|
184 { |
|
185 iImageDecoded = EFalse; |
|
186 iBadFileMarkerNotNeededFlag = ETrue; |
|
187 // Client is no longer needed |
|
188 iClient->ThumbnailFetchComplete(ItemId(), |
|
189 EGlxThumbnailQualityHigh, KErrNone); |
|
190 iClient = NULL; |
|
191 |
|
192 User::LeaveIfNull(iFileInfo); |
|
193 |
|
194 TBool isVideo, isProtected; |
|
195 iFileInfo->IdentifyFileL(isVideo, isProtected); |
|
196 // if DRM protected leave |
|
197 // assume DRM capablity not present |
|
198 if(isProtected) |
|
199 { |
|
200 User::Leave(KErrAccessDenied); |
|
201 } |
|
202 |
|
203 active = CheckNextL(aStatus); |
|
204 } |
|
205 break; |
|
206 |
|
207 case EStateDecoding: |
|
208 iImageUtility->FreeDecoder(); |
|
209 iImageDecoded = ETrue; |
|
210 FilterThumbnailL(aStatus); |
|
211 active = ETrue; |
|
212 break; |
|
213 |
|
214 case EStateFiltering: |
|
215 ScaleThumbnailL(aStatus); |
|
216 active = ETrue; |
|
217 break; |
|
218 |
|
219 case EStateSaving: |
|
220 active = ProcessNextL(aStatus); |
|
221 break; |
|
222 |
|
223 case EStateChecking: |
|
224 if ( KGlxThumbnailNotAvailable == aStatus.Int() ) |
|
225 { |
|
226 iTodoSizes.AppendL(iSize); |
|
227 } |
|
228 active = CheckNextL(aStatus); |
|
229 break; |
|
230 |
|
231 case EStateScaling: |
|
232 EncodeThumbnailL(aStatus); |
|
233 active = ETrue; |
|
234 break; |
|
235 |
|
236 case EStateEncoding: |
|
237 SaveThumbnailL(aStatus); |
|
238 active = ETrue; |
|
239 break; |
|
240 |
|
241 default: |
|
242 GLX_ASSERT_ALWAYS( EFalse, Panic( EGlxPanicIllegalState ), |
|
243 "CGlxtnBackgroundGenerationTask: Illegal state" ); |
|
244 break; |
|
245 } |
|
246 |
|
247 if ( !active ) |
|
248 { |
|
249 if( !iBadFileMarkerNotNeededFlag ) |
|
250 { |
|
251 iFileUtility.ClearBadFileMarker(); |
|
252 } |
|
253 // Send notification that we've finished |
|
254 Storage()->NotifyBackgroundError( ItemId(), KErrNone ); |
|
255 } |
|
256 |
|
257 return active; // Task is complete |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // DoRunError |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 TBool CGlxtnBackgroundGenerationTask::DoRunError(TInt aError) |
|
265 { |
|
266 TRACER("CGlxtnBackgroundGenerationTask::DoRunError()"); |
|
267 if( !iBadFileMarkerNotNeededFlag ) |
|
268 { |
|
269 iFileUtility.ClearBadFileMarker(); |
|
270 } |
|
271 if ( iClient ) |
|
272 { |
|
273 iClient->ThumbnailFetchComplete( |
|
274 ItemId(), EGlxThumbnailQualityHigh, aError); |
|
275 } |
|
276 else |
|
277 { |
|
278 Storage()->NotifyBackgroundError(ItemId(), aError); |
|
279 } |
|
280 |
|
281 return EFalse; // Task is complete |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CheckNextL |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 TBool CGlxtnBackgroundGenerationTask::CheckNextL(TRequestStatus& aStatus) |
|
289 { |
|
290 TRACER("CGlxtnBackgroundGenerationTask::CheckNextL()"); |
|
291 if ( iSizes.Count() == 0 ) |
|
292 { |
|
293 return ProcessNextL(aStatus); |
|
294 } |
|
295 |
|
296 iSize = iSizes[0]; |
|
297 iSizes.Remove(0); |
|
298 |
|
299 Storage()->IsThumbnailAvailableL(ItemId(), *iFileInfo, iSize, &aStatus); |
|
300 iState = EStateChecking; |
|
301 return ETrue; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // ProcessNextL |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 TBool CGlxtnBackgroundGenerationTask::ProcessNextL(TRequestStatus& aStatus) |
|
309 { |
|
310 TRACER("TBool CGlxtnBackgroundGenerationTask::ProcessNextL()"); |
|
311 if ( iTodoSizes.Count() == 0 ) |
|
312 { |
|
313 return EFalse; |
|
314 } |
|
315 |
|
316 iSize = iTodoSizes[0]; |
|
317 if( iImageDecoded ) |
|
318 { |
|
319 FilterThumbnailL(aStatus); |
|
320 } |
|
321 else |
|
322 { |
|
323 DecodeImageL(aStatus); |
|
324 } |
|
325 return ETrue; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // FilterThumbnailL |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 void CGlxtnBackgroundGenerationTask::FilterThumbnailL(TRequestStatus& aStatus) |
|
333 { |
|
334 TRACER("void CGlxtnBackgroundGenerationTask::FilterThumbnailL()"); |
|
335 // Create thumbnail bitmap of required size |
|
336 TSize targetSize(iTodoSizes[0]); |
|
337 iTodoSizes.Remove(0); |
|
338 iImageUtility->AdjustSize(targetSize, iImage->SizeInPixels()); |
|
339 |
|
340 delete iThumbnail; |
|
341 iThumbnail = NULL; |
|
342 iThumbnail = new (ELeave) CFbsBitmap; |
|
343 User::LeaveIfError(iThumbnail->Create(targetSize, KGlxThumbnailDisplayMode)); |
|
344 |
|
345 iImageUtility->FilterImageL(&aStatus, iImage, iFilteredImage, iThumbnail); |
|
346 iState = EStateFiltering; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // ScaleThumbnailL |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 void CGlxtnBackgroundGenerationTask::ScaleThumbnailL(TRequestStatus& aStatus) |
|
354 { |
|
355 TRACER("void CGlxtnBackgroundGenerationTask::ScaleThumbnailL()"); |
|
356 TSize targetSize(iSize); |
|
357 const TSize srcSize = iImage->SizeInPixels(); |
|
358 iImageUtility->AdjustSize(targetSize, iImage->SizeInPixels()); |
|
359 iImageUtility->ScaleImageL(aStatus, *iImage, srcSize, *iThumbnail, targetSize); |
|
360 iState = EStateScaling; |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // DecodeImageL |
|
365 // ----------------------------------------------------------------------------- |
|
366 // |
|
367 void CGlxtnBackgroundGenerationTask::DecodeImageL(TRequestStatus& aStatus) |
|
368 { |
|
369 TRACER("void CGlxtnBackgroundGenerationTask::DecodeImageL()"); |
|
370 iBadFileMarkerNotNeededFlag = EFalse; |
|
371 iFileUtility.CheckBadFileListL( iFileInfo->FilePath() ); |
|
372 TBool isVideo, isProtected; |
|
373 iFileInfo->IdentifyFileL(isVideo, isProtected); |
|
374 if ( isVideo ) |
|
375 { |
|
376 iVideoUtility = new (ELeave) CGlxtnVideoUtility; |
|
377 iVideoUtility->GetVideoFrameL(&aStatus, iImage, |
|
378 iFileInfo->FilePath(), iTodoSizes, KGlxThumbnailDisplayMode); |
|
379 } |
|
380 else |
|
381 { |
|
382 iImage = iImageUtility->DecodeImageL(aStatus, |
|
383 iFileInfo->FilePath(), iTodoSizes, KGlxThumbnailDisplayMode); |
|
384 } |
|
385 delete iFilteredImage; |
|
386 iFilteredImage = NULL; |
|
387 iState = EStateDecoding; |
|
388 } |
|
389 // ----------------------------------------------------------------------------- |
|
390 // LayoutSpecificDataL |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 void CGlxtnBackgroundGenerationTask::LayoutSpecificDataL() |
|
394 { |
|
395 TRACER("void CGlxtnBackgroundGenerationTask::LayoutSpecificDataL()"); |
|
396 // Sets up TLS, must be done before FeatureManager is used. |
|
397 FeatureManager::InitializeLibL(); |
|
398 |
|
399 if(FeatureManager::FeatureSupported( KFeatureIdLayout640_360_Touch ) || FeatureManager::FeatureSupported( KFeatureIdLayout360_640_Touch )) |
|
400 { |
|
401 iGridIconSize = TSize(111,83); |
|
402 iCoverflowIconSize = TSize(640,360); |
|
403 } |
|
404 else if(FeatureManager::FeatureSupported(KFeatureIdLayout640_480_Touch) || FeatureManager::FeatureSupported(KFeatureIdLayout480_640_Touch) || |
|
405 FeatureManager::FeatureSupported(KFeatureIdLayout640_480) || FeatureManager::FeatureSupported(KFeatureIdLayout480_640)) |
|
406 { |
|
407 iGridIconSize = TSize(146,110); |
|
408 iCoverflowIconSize = TSize(640,480); |
|
409 } |
|
410 else |
|
411 { |
|
412 iGridIconSize = TSize(146,110); |
|
413 iCoverflowIconSize = TSize(640,480); |
|
414 } |
|
415 // Frees the TLS. Must be done after FeatureManager is used. |
|
416 FeatureManager::UnInitializeLib(); |
|
417 |
|
418 |
|
419 } |
|
420 |
|
421 // End of File |