|
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: Manager of visual lists |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 31/07/2007 by Rowland Cook |
|
23 */ |
|
24 |
|
25 #include "glxvisualiconmanager.h" |
|
26 |
|
27 #include <data_caging_path_literals.hrh> |
|
28 #include <alf/alftexture.h> |
|
29 #include <alf/alfvisual.h> |
|
30 #include <mpxmediageneraldefs.h> |
|
31 |
|
32 #include <glxlog.h> |
|
33 #include <glxtracer.h> |
|
34 |
|
35 #include <glxanimationfactory.h> |
|
36 #include <glxassert.h> |
|
37 #include <glxerrormanager.h> |
|
38 #include <glxerrors.h> |
|
39 #include <glxuiutility.h> |
|
40 #include <glxicons.mbg> // icons |
|
41 #include <glxthumbnailattributeinfo.h> |
|
42 #include <glxuistd.h> |
|
43 #include <mglxanimation.h> |
|
44 #include <mglxmedialist.h> |
|
45 #include <glxtexturemanager.h> |
|
46 #include "mglxvisuallist.h" |
|
47 |
|
48 #include "glxitemvisual.h" |
|
49 |
|
50 |
|
51 /// How long the image-loading animation should last for (in milliseconds) |
|
52 const TInt KGlxImageLoadingAnimationDuration = 400 * KGlxAnimationSlowDownFactor; |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // 1st phase constructor |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C CGlxVisualIconManager* CGlxVisualIconManager::NewL( |
|
60 MGlxMediaList& aMediaList, MGlxVisualList& aVisualList) |
|
61 { |
|
62 TRACER("CGlxVisualIconManager::NewL"); |
|
63 GLX_LOG_INFO("CGlxVisualIconManager::NewL "); |
|
64 // get the ui utility |
|
65 CGlxUiUtility* utility = CGlxUiUtility::UtilityL(); |
|
66 CleanupClosePushL( *utility ); |
|
67 CGlxVisualIconManager* self = |
|
68 new ( ELeave ) CGlxVisualIconManager( |
|
69 utility->GlxTextureManager(), aMediaList, aVisualList); |
|
70 CleanupStack::PopAndDestroy( utility ); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Destructor |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C CGlxVisualIconManager::~CGlxVisualIconManager() |
|
82 { |
|
83 TRACER("CGlxVisualIconManager::~CGlxVisualIconManager"); |
|
84 GLX_LOG_INFO("CGlxVisualIconManager::~CGlxVisualIconManager"); |
|
85 // remove us from the medialist and visual list observer |
|
86 iMediaList.RemoveMediaListObserver(this); |
|
87 iVisualList.RemoveObserver( this ); |
|
88 |
|
89 TInt animCount = iAnimations.Count(); |
|
90 |
|
91 for ( TInt animIndex = 0; animIndex < animCount; animIndex++ ) |
|
92 { |
|
93 delete iAnimations[animIndex]; |
|
94 } |
|
95 iAnimations.Reset(); |
|
96 |
|
97 iIconTextureArray.Reset(); |
|
98 |
|
99 if( iWhiteTexture ) |
|
100 { |
|
101 iTextureManager.RemoveTexture( *iWhiteTexture ); |
|
102 } |
|
103 |
|
104 iThumbnailIcons.Close(); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // HandleVisualAddedL |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CGlxVisualIconManager::HandleVisualAddedL( CAlfVisual* aVisual, |
|
112 TInt aIndex, MGlxVisualList* aList ) |
|
113 { |
|
114 TRACER("CGlxVisualIconManager::HandleVisualAddedL"); |
|
115 GLX_LOG_INFO("CGlxVisualIconManager::HandleVisualAddedL"); |
|
116 if ( aIndex >= 0 && aIndex < iMediaList.Count() ) |
|
117 { |
|
118 CheckThumbnailAttributesL( aIndex ); |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // HandleError |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CGlxVisualIconManager::HandleError( TInt aError ) |
|
127 { |
|
128 TRACER("CGlxVisualIconManager::HandleError"); |
|
129 GLX_LOG_INFO1("CGlxVisualIconManager::HandleError: %d",aError); |
|
130 TRAP_IGNORE( DoHandleErrorL( aError ) ); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // DoHandleErrorL |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 void CGlxVisualIconManager::DoHandleErrorL( TInt /*aError*/ ) |
|
138 { |
|
139 TRACER("CGlxVisualIconManager::DoHandleErrorL"); |
|
140 GLX_LOG_INFO("CGlxVisualIconManager::DoHandleErrorL"); |
|
141 // Check for items for which fetching a thumbnail has failed, and replace |
|
142 // the default icon with broken icon |
|
143 TInt count = iMediaList.Count(); |
|
144 for ( TInt i = 0; i < count; i++ ) |
|
145 { |
|
146 CGlxVisualObject* visItem = iVisualList.Item( i ); |
|
147 |
|
148 // Only need to check that visual item exitst or not |
|
149 if ( visItem ) |
|
150 { |
|
151 const CAlfTexture* iconTexture = SelectIconTextureL( i ); |
|
152 |
|
153 if ( iDefaultIconTexture != iconTexture ) |
|
154 { |
|
155 visItem->RemoveIcon( *iDefaultIconTexture ); |
|
156 |
|
157 visItem->SetStatus( CGlxVisualObject::EHasErrorIcon ); |
|
158 visItem->AddIconL( *iconTexture, |
|
159 NGlxIconMgrDefs::EGlxIconCentred, |
|
160 ETrue, EFalse, 0, 1.0, 1.0 ); |
|
161 visItem->SetScaleMode(CAlfImageVisual::EScaleNormal); |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // Constructor |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 CGlxVisualIconManager::CGlxVisualIconManager( |
|
172 CGlxTextureManager& aTextureManager, |
|
173 MGlxMediaList& aMediaList, |
|
174 MGlxVisualList& aVisualList ) |
|
175 : CGlxIconManager( aMediaList, aVisualList ), |
|
176 iTextureManager( aTextureManager ) |
|
177 { |
|
178 TRACER("CGlxVisualIconManager::CGlxVisualIconManager"); |
|
179 GLX_LOG_INFO("CGlxVisualIconManager::CGlxVisualIconManager"); |
|
180 // No implementation |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // 2nd phase construction |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CGlxVisualIconManager::ConstructL() |
|
188 { |
|
189 TRACER("CGlxVisualIconManager::ConstructL"); |
|
190 GLX_LOG_INFO("CGlxVisualIconManager::ConstructL"); |
|
191 BaseConstructL(); |
|
192 |
|
193 //iWhiteTexture = |
|
194 // &( iTextureManager.CreateFlatColourTextureL( KRgbWhite ) ); |
|
195 |
|
196 // create 'default' icon |
|
197 TFileName resFile(KDC_APP_BITMAP_DIR); |
|
198 resFile.Append(KGlxIconsFilename); |
|
199 // get the ui utility |
|
200 CGlxUiUtility* utility = CGlxUiUtility::UtilityL(); |
|
201 CleanupClosePushL( *utility ); |
|
202 TSize iconSize = utility->GetGridIconSize(); |
|
203 CleanupStack::PopAndDestroy( utility ); |
|
204 iDefaultIconTexture = |
|
205 &(iTextureManager.CreateIconTextureL( |
|
206 EMbmGlxiconsQgn_prop_image_notcreated, resFile, iconSize ) ); |
|
207 |
|
208 iBrokenIconTexture = |
|
209 &(iTextureManager.CreateIconTextureL( |
|
210 EMbmGlxiconsQgn_prop_image_corrupted, resFile, iconSize ) ); |
|
211 |
|
212 iEmptyIconTexture = |
|
213 &(iTextureManager.CreateIconTextureL( |
|
214 EMbmGlxiconsQgn_prop_image_notcreated, resFile, iconSize ) ); |
|
215 |
|
216 // add as observers |
|
217 iMediaList.AddMediaListObserverL(this); |
|
218 iVisualList.AddObserverL(this); |
|
219 |
|
220 |
|
221 // check for any visual already present in list |
|
222 TInt itemCount = iMediaList.Count(); |
|
223 for ( TInt i = 0; i < itemCount; i++ ) |
|
224 { |
|
225 CheckThumbnailAttributesL( i ); |
|
226 } |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CheckThumbnailAttributesL |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CGlxVisualIconManager::CheckThumbnailAttributesL( TInt aIndex ) |
|
234 { |
|
235 TRACER("CGlxVisualIconManager::CheckThumbnailAttributesL"); |
|
236 GLX_LOG_INFO1("CGlxVisualIconManager::CheckThumbnailAttributesL: %d",aIndex); |
|
237 CGlxVisualObject* visItem = iVisualList.Item( aIndex ); |
|
238 |
|
239 if ( visItem ) |
|
240 { |
|
241 TBool thumbnail = visItem->SetObserver( *this ); |
|
242 const TGlxMedia& item = iMediaList.Item( aIndex ); |
|
243 TInt thumbnailError = GlxErrorManager::HasAttributeErrorL( |
|
244 item.Properties(), KGlxMediaIdThumbnail ); |
|
245 |
|
246 if ( thumbnail && thumbnailError == KErrNone ) |
|
247 { |
|
248 visItem->SetStatus( CGlxVisualObject::EHasThumbnail ); |
|
249 } |
|
250 else |
|
251 { |
|
252 const CAlfTexture* iconTexture = iDefaultIconTexture; |
|
253 visItem->SetScaleMode(CAlfImageVisual::EScaleNormal); |
|
254 TIconInfo icon; |
|
255 if ( item.GetIconInfo( icon ) ) |
|
256 { |
|
257 // The item has its own icon |
|
258 // In this case we treat the icon as a thumbnail |
|
259 // i.e. we want it to scale appropriate to its |
|
260 // position in the view |
|
261 visItem->SetStatus( CGlxVisualObject::EHasOtherIcon ); |
|
262 |
|
263 GLX_ASSERT_DEBUG( iThumbnailIcons.Count() == iIconTextureArray.Count(), |
|
264 Panic( EGlxPanicIllegalState ), "Icon array mismatch" ); |
|
265 |
|
266 // Check if icon texture already generated |
|
267 TInt pos = iThumbnailIcons.Find( icon, MatchIcon ); |
|
268 |
|
269 if ( pos == KErrNotFound ) |
|
270 { |
|
271 // Ask texture manager to generate icon |
|
272 /// @todo Should specify a size here |
|
273 iconTexture = |
|
274 &iUiUtility->GlxTextureManager().CreateIconTextureL( |
|
275 icon.bitmapId, icon.bmpfile ); |
|
276 |
|
277 iThumbnailIcons.ReserveL( iThumbnailIcons.Count() + 1 ); |
|
278 iIconTextureArray.AppendL( iconTexture ); |
|
279 // Can't fail because of reservation |
|
280 iThumbnailIcons.AppendL( icon ); |
|
281 } |
|
282 else |
|
283 { |
|
284 iconTexture = iIconTextureArray[pos]; |
|
285 } |
|
286 // add to visual |
|
287 //@Migration info: Required? |
|
288 //visItem->SetImage( THuiImage( *iconTexture ) ); |
|
289 } |
|
290 else |
|
291 { |
|
292 iconTexture = SelectIconTextureL( aIndex ); |
|
293 if ( iDefaultIconTexture == iconTexture ) |
|
294 { |
|
295 visItem->SetStatus( CGlxVisualObject::EHasDefaultIcon ); |
|
296 } |
|
297 else |
|
298 { |
|
299 visItem->SetStatus( CGlxVisualObject::EHasErrorIcon ); |
|
300 } |
|
301 // add to visual |
|
302 visItem->AddIconL( *iconTexture, NGlxIconMgrDefs::EGlxIconCentred, |
|
303 ETrue, EFalse, 0, 1.0, 1.0 ); |
|
304 // } |
|
305 } |
|
306 } |
|
307 } |
|
308 } |
|
309 |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // AnimateImageLoaded |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 void CGlxVisualIconManager::AnimateImageLoadedL( CAlfVisual* aItemVisual) |
|
316 { |
|
317 TRACER("CGlxVisualIconManager::AnimateImageLoadedL"); |
|
318 GLX_LOG_INFO("CGlxVisualIconManager::AnimateImageLoadedL"); |
|
319 MGlxAnimation* anim = |
|
320 GlxAnimationFactory::CreateImageLoadingAnimationL( *aItemVisual, *iWhiteTexture ); |
|
321 |
|
322 CleanupStack::PushL(anim); |
|
323 iAnimations.InsertInAddressOrderL(anim); |
|
324 CleanupStack::Pop(anim); |
|
325 |
|
326 anim->AnimateL( KGlxImageLoadingAnimationDuration, this ); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // AnimationComplete |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CGlxVisualIconManager::AnimationComplete(MGlxAnimation* aAnimation) |
|
334 { |
|
335 TRACER("CGlxVisualIconManager::AnimationComplete"); |
|
336 GLX_LOG_INFO("CGlxVisualIconManager::AnimationComplete"); |
|
337 TInt animIndex = iAnimations.FindInAddressOrder(aAnimation); |
|
338 |
|
339 if ( animIndex != KErrNotFound ) |
|
340 { |
|
341 iAnimations.Remove(animIndex); |
|
342 } |
|
343 |
|
344 delete aAnimation; |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // IsDrmVideoItem to be done |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 TBool CGlxVisualIconManager::IsDrmVideoItem( const TGlxMedia& aItem ) |
|
352 { |
|
353 TRACER("CGlxVisualIconManager::IsDrmVideoItem"); |
|
354 GLX_LOG_INFO("CGlxVisualIconManager::IsDrmVideoItem"); |
|
355 if ( aItem.IsDrmProtected() && aItem.Category() == EMPXVideo ) |
|
356 { |
|
357 return ETrue; |
|
358 } |
|
359 return EFalse; |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // VisualStatusChangedL |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 void CGlxVisualIconManager::VisualStatusChangedL( CGlxVisualObject& aObject, |
|
367 TInt aListIndex, TBool aHasThumbnail ) |
|
368 { |
|
369 TRACER("CGlxVisualIconManager::VisualStatusChangedL"); |
|
370 GLX_LOG_INFO("CGlxVisualIconManager::VisualStatusChangedL"); |
|
371 // Note: The visual may not yet be in the visual list |
|
372 |
|
373 if ( aHasThumbnail ) |
|
374 { |
|
375 // Remove icons |
|
376 if ( CGlxVisualObject::EHasDefaultIcon == aObject.Status() ) |
|
377 { |
|
378 aObject.RemoveIcon( *iDefaultIconTexture ); |
|
379 } |
|
380 else if ( CGlxVisualObject::EHasErrorIcon == aObject.Status() ) |
|
381 { |
|
382 aObject.RemoveIcon( *iBrokenIconTexture ); |
|
383 aObject.RemoveIcon( *iEmptyIconTexture ); |
|
384 } |
|
385 |
|
386 aObject.SetStatus( CGlxVisualObject::EHasThumbnail ); |
|
387 } |
|
388 else |
|
389 { |
|
390 if ( CGlxVisualObject::EHasThumbnail == aObject.Status() ) |
|
391 { |
|
392 const CAlfTexture* iconTexture = SelectIconTextureL( aListIndex ); |
|
393 if ( iDefaultIconTexture == iconTexture ) |
|
394 { |
|
395 aObject.SetStatus( CGlxVisualObject::EHasDefaultIcon ); |
|
396 } |
|
397 else |
|
398 { |
|
399 aObject.SetStatus( CGlxVisualObject::EHasErrorIcon ); |
|
400 } |
|
401 |
|
402 aObject.AddIconL( *iconTexture, NGlxIconMgrDefs::EGlxIconCentred, |
|
403 ETrue, EFalse, 0, 1.0, 1.0 ); |
|
404 aObject.SetScaleMode(CAlfImageVisual::EScaleNormal); |
|
405 } |
|
406 } |
|
407 } |
|
408 |
|
409 // --------------------------------------------------------------------------- |
|
410 // ThumbnailLoadedL |
|
411 // --------------------------------------------------------------------------- |
|
412 // |
|
413 void CGlxVisualIconManager::ThumbnailLoadedL( CGlxVisualObject& aObject ) |
|
414 { |
|
415 TRACER("CGlxVisualIconManager::ThumbnailLoadedL"); |
|
416 GLX_LOG_INFO("CGlxVisualIconManager::ThumbnailLoadedL"); |
|
417 AnimateImageLoadedL( aObject.Visual() ); |
|
418 } |
|
419 |
|
420 // --------------------------------------------------------------------------- |
|
421 // SelectIconTextureL |
|
422 // --------------------------------------------------------------------------- |
|
423 // |
|
424 const CAlfTexture* CGlxVisualIconManager::SelectIconTextureL( TInt aIndex ) |
|
425 { |
|
426 TRACER(" CGlxVisualIconManager::SelectIconTextureL"); |
|
427 GLX_LOG_INFO(" CGlxVisualIconManager::SelectIconTextureL"); |
|
428 const CAlfTexture* iconTexture = iDefaultIconTexture; |
|
429 |
|
430 const TGlxMedia& item = iMediaList.Item( aIndex ); |
|
431 TInt thumbnailError = GlxErrorManager::HasAttributeErrorL( |
|
432 item.Properties(), KGlxMediaIdThumbnail ); |
|
433 |
|
434 if ( KErrGlxEmptyContainer == thumbnailError ) |
|
435 { |
|
436 iconTexture = iEmptyIconTexture; |
|
437 } |
|
438 else if ( KErrNone == thumbnailError || |
|
439 // If the error is not supported display the default icon, not the corrupted icon. e.g. real media |
|
440 thumbnailError == KErrNotSupported || |
|
441 |
|
442 IsDrmVideoItem( item ) ) |
|
443 { |
|
444 // Use default icon |
|
445 // Test whether the item is a DRM'd video to fix error EDKZ-77UJZA |
|
446 // as DRM'd videos should show the default icon not the broken icon |
|
447 } |
|
448 else |
|
449 { |
|
450 iconTexture = iBrokenIconTexture; |
|
451 } |
|
452 |
|
453 return iconTexture; |
|
454 } |
|
455 |
|
456 // --------------------------------------------------------------------------- |
|
457 // MatchIcon |
|
458 // --------------------------------------------------------------------------- |
|
459 // |
|
460 TBool CGlxVisualIconManager::MatchIcon( const TIconInfo& aIcon1, |
|
461 const TIconInfo& aIcon2 ) |
|
462 { |
|
463 TRACER("CGlxVisualIconManager::MatchIcon"); |
|
464 GLX_LOG_INFO("CGlxVisualIconManager::MatchIcon "); |
|
465 return ( aIcon1.bmpfile == aIcon2.bmpfile && |
|
466 aIcon1.bitmapId == aIcon2.bitmapId ); |
|
467 } |