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