|
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 media item cache |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxcachemanager.h" |
|
22 |
|
23 #include <mpxcollectionutility.h> |
|
24 #include <glxtracer.h> |
|
25 #include <glxthumbnailattributeinfo.h> |
|
26 #include <glxthumbnail.h> |
|
27 #include <glxsingletonstore.h> |
|
28 #include <glximageviewermanager.h> |
|
29 |
|
30 #include "glxcache.h" |
|
31 #include "glxerrormanager.h" |
|
32 #include "glxgarbagecollector.h" |
|
33 #include "glxmedialist.h" |
|
34 #include <hal.h> |
|
35 #include <glxcollectionpluginimageviewer.hrh> |
|
36 #include <mpxmediacollectiondetaildefs.h> |
|
37 #include <mpxmediadrmdefs.h> |
|
38 #include <f32file.h> |
|
39 #include <lbsposition.h> |
|
40 #include <apgcli.h> |
|
41 #include <glxappui.h> |
|
42 #include <aknViewAppUi.h> |
|
43 #include <caf/content.h> |
|
44 #include <caf/attributeset.h> |
|
45 #include <caf/caferr.h> |
|
46 #include <DRMHelper.h> |
|
47 |
|
48 #ifdef USE_S60_TNM |
|
49 #include <thumbnaildata.h> |
|
50 const TInt KMaxGridThumbnailWidth = 200; |
|
51 _LIT(KFileIdentifier, ":\\"); |
|
52 #endif |
|
53 |
|
54 _LIT(KDefaultType, "image/jpg"); |
|
55 /// How long to wait before rechecking for cleared temporary errors |
|
56 /// @todo Find optimal value for this |
|
57 const TInt KGlxTemporaryErrorRecheckPeriodInSeconds = 5; |
|
58 |
|
59 const TInt KGlxLowerMemoryLimitForCleanUp = 31500000; // 30 MB |
|
60 const TInt KGlxUpperMemoryLimitForCleanUp = 52500000; // 50 MB |
|
61 const TInt KGlxNoOfPagesToFlushInCriticalLowMemory = 4; |
|
62 // ----------------------------------------------------------------------------- |
|
63 // InstanceL |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CGlxCacheManager* CGlxCacheManager::InstanceL() |
|
67 { |
|
68 TRACER("CGlxCacheManager::InstanceL"); |
|
69 |
|
70 return CGlxSingletonStore::InstanceL(&NewL); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // NewL |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CGlxCacheManager* CGlxCacheManager::NewL() |
|
78 { |
|
79 TRACER("CGlxCacheManager::NewL"); |
|
80 |
|
81 CGlxCacheManager* self = new( ELeave ) CGlxCacheManager(); |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL(); |
|
84 CleanupStack::Pop(self); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // Close |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CGlxCacheManager::Close() |
|
93 { |
|
94 TRACER("CGlxCacheManager::Close"); |
|
95 |
|
96 CGlxSingletonStore::Close(this); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // Constructor |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CGlxCacheManager::CGlxCacheManager() |
|
104 { |
|
105 TRACER("CGlxCacheManager::Default Constructor"); |
|
106 |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // ConstructL |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CGlxCacheManager::ConstructL() |
|
114 { |
|
115 TRACER("CGlxCacheManager::ConstructL"); |
|
116 |
|
117 iGarbageCollector = CGlxGarbageCollector::NewL( iCaches ); |
|
118 iTempErrorTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
119 iMaintainCacheCallback = new ( ELeave ) |
|
120 CAsyncCallBack( TCallBack( MaintainCacheL, this ), CActive::EPriorityStandard ); |
|
121 |
|
122 #ifdef USE_S60_TNM |
|
123 iTnEngine = CThumbnailManager::NewL( *this); |
|
124 iTnEngine->SetDisplayModeL( EColor16M ); |
|
125 #endif |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // Destructor |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 CGlxCacheManager::~CGlxCacheManager() |
|
133 { |
|
134 TRACER("CGlxCacheManager::Destructor"); |
|
135 |
|
136 iObserverList.ResetAndDestroy(); |
|
137 iCaches.ResetAndDestroy(); |
|
138 delete iTempThumbnail; |
|
139 iRequestedItemIds.Reset(); |
|
140 iRequestedAttrs.Reset(); |
|
141 iRequestedItemIndexes.Reset(); |
|
142 if(iReader) |
|
143 { |
|
144 delete iReader; |
|
145 } |
|
146 |
|
147 delete iGarbageCollector; |
|
148 |
|
149 if (iTempErrorTimer) |
|
150 { |
|
151 iTempErrorTimer->Cancel(); |
|
152 delete iTempErrorTimer; |
|
153 } |
|
154 |
|
155 #ifdef USE_S60_TNM |
|
156 GLX_DEBUG2("CGlxCacheManager::~CGlxCacheManager() TN Ids count()=%d", |
|
157 iThumbnailRequestIds.Count()); |
|
158 for (TInt i = 0; i < iThumbnailRequestIds.Count(); i++) |
|
159 { |
|
160 iTnEngine->CancelRequest(iThumbnailRequestIds[i].iId); |
|
161 } |
|
162 iThumbnailRequestIds.Reset(); |
|
163 delete iTnEngine; |
|
164 delete iMPXMedia; |
|
165 #endif |
|
166 |
|
167 delete iMaintainCacheCallback; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // HandleWindowChangedL |
|
172 // From MVieMediaItemListManager |
|
173 // The list calls this function to hint the list manager, that the items |
|
174 // the list contains might not all be loaded, and it would be nice if the list |
|
175 // manager could load the missing items to the cache. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CGlxCacheManager::HandleWindowChangedL(CGlxMediaList* /*aList*/) |
|
179 { |
|
180 TRACER("CGlxCacheManager::HandleWindowChangedL"); |
|
181 GLX_LOG_INFO("---- MGallery - CGlxCacheManager::HandleWindowChangedL()---- "); |
|
182 iMaintainCacheCallback->CallBack(); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CancelPreviousRequest |
|
187 // This API cancels the pending attributes and thumbnail request |
|
188 // when the media item in focus is NULL |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CGlxCacheManager::CancelPreviousRequest() |
|
192 { |
|
193 TRACER("CGlxCacheManager::CancelPreviousRequest"); |
|
194 |
|
195 // iRequestOwner is NULL, if there are no pending attribute/thumbnail request |
|
196 // If no pending request, do nothing, else cancel the the pending requests |
|
197 if(iRequestOwner) |
|
198 { |
|
199 MMPXCollection& collection = iRequestOwner->Collection(); |
|
200 // Cancel the pending attribute request |
|
201 collection.CancelRequest(); |
|
202 |
|
203 #ifdef USE_S60_TNM |
|
204 GLX_DEBUG2("CGlxCacheManager::CancelPreviousRequest() iThumbnailRequestIds.Count() %d", iThumbnailRequestIds.Count()); |
|
205 |
|
206 // Check if any thumbnail requests are pending and cancel the requests. |
|
207 for (TInt i = 0; i < iThumbnailRequestIds.Count(); i++) |
|
208 { |
|
209 iTnEngine->CancelRequest(iThumbnailRequestIds[i].iId); |
|
210 } |
|
211 iThumbnailRequestIds.Reset(); |
|
212 #endif |
|
213 iRequestOwner = NULL; |
|
214 } |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // HandleGarbageCollection |
|
219 // Garbage Collection Quick or with Timer |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CGlxCacheManager::HandleGarbageCollectionL(TBool aStart) |
|
223 { |
|
224 TRACER("CGlxCacheManager::HandleGarbageCollection"); |
|
225 GLX_DEBUG2("CGlxCacheManager::HandleGarbageCollectionL() aStart=%d", aStart); |
|
226 TInt freeMemory = 0; |
|
227 HAL::Get(HALData::EMemoryRAMFree, freeMemory); |
|
228 GLX_DEBUG2("CGlxCacheManager::HandleGarbageCollectionL() freeMemory=%d", freeMemory); |
|
229 |
|
230 if (aStart) |
|
231 { |
|
232 if (freeMemory < KGlxLowerMemoryLimitForCleanUp) |
|
233 { |
|
234 // 2 page - 30 Items for Flush |
|
235 TInt count = 2; |
|
236 if (freeMemory < (KGlxLowerMemoryLimitForCleanUp / 2)) |
|
237 { |
|
238 // If Memory is below this limit it's ok i can wait for 60 items to clean-up |
|
239 count = KGlxNoOfPagesToFlushInCriticalLowMemory; |
|
240 } |
|
241 // Cancel Clean-up before Flush Page; Clean-up will be starting just after Flush page |
|
242 iGarbageCollector->CancelCleanup(); |
|
243 iGarbageCollector->FlushPagesL(count); |
|
244 iGarbageCollector->CleanupL(); |
|
245 iCleanUpOnGoing = ETrue; // Clean up is Started now i can call CancelClean-up to Stop Clean Up |
|
246 } |
|
247 else if ((freeMemory < KGlxUpperMemoryLimitForCleanUp) |
|
248 && !iCleanUpOnGoing) |
|
249 { |
|
250 iGarbageCollector->CleanupL(); |
|
251 iCleanUpOnGoing = ETrue; // Clean up is Started now i can call CancelClean-up to Stop Clean Up |
|
252 } |
|
253 // This is Added to Keep Assure Clean-up is not going to Disturb normal Flow if there is Enough Memory |
|
254 // We Remove this Code After Evaluation of Use of this Code |
|
255 else if (iCleanUpOnGoing) |
|
256 { |
|
257 iGarbageCollector->CancelCleanup(); |
|
258 iCleanUpOnGoing = EFalse; |
|
259 } |
|
260 } |
|
261 else if (freeMemory < KGlxLowerMemoryLimitForCleanUp) |
|
262 { |
|
263 // 2 page - 30 Items for Flush |
|
264 TInt count = 2; |
|
265 if (freeMemory < (KGlxLowerMemoryLimitForCleanUp / 2)) |
|
266 { |
|
267 // If Memory is below this limit it's ok i can wait for 60 items to clean-up |
|
268 count = KGlxNoOfPagesToFlushInCriticalLowMemory; |
|
269 } |
|
270 // Cancel Clean-up before Flush Page; Clean-up will be starting just after Flush page |
|
271 iGarbageCollector->CancelCleanup(); |
|
272 iGarbageCollector->FlushPagesL(count); |
|
273 iGarbageCollector->CleanupL(); |
|
274 iCleanUpOnGoing = ETrue; // Clean up is Started now i can call CancelClean-up to Stop Clean Up |
|
275 } |
|
276 else if(iCleanUpOnGoing) |
|
277 { |
|
278 iGarbageCollector->CancelCleanup(); |
|
279 iCleanUpOnGoing = EFalse; |
|
280 } |
|
281 GLX_DEBUG2("CGlxCacheManager::HandleGarbageCollectionL() iCleanUpOnGoing=%d", iCleanUpOnGoing); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // Match |
|
286 // return ETrue if path levels match |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 TBool CGlxCacheManager::Match(const CMPXCollectionPath& aPath1, |
|
290 const CMPXCollectionPath& aPath2) |
|
291 { |
|
292 TRACER("CGlxCacheManager::Match"); |
|
293 |
|
294 TInt levels1 = aPath1.Levels(); |
|
295 TInt levels2 = aPath2.Levels(); |
|
296 |
|
297 // Paths must be as deep to match |
|
298 if (levels1 != levels2) |
|
299 { |
|
300 return EFalse; |
|
301 } |
|
302 |
|
303 // Check if all levels match |
|
304 for (TInt i = 0; i < levels1; i++) |
|
305 { |
|
306 if (aPath1.Index(i) != aPath2.Index(i)) |
|
307 { |
|
308 return EFalse; |
|
309 } |
|
310 } |
|
311 |
|
312 return ETrue; |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // HandleCollectionMediaL |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CGlxCacheManager::HandleCollectionMediaL( |
|
320 const TGlxIdSpaceId& aIdSpaceId, const CMPXMedia& aMedia, |
|
321 TInt aError, TBool aRequestNextAttr) |
|
322 { |
|
323 TRACER("CGlxCacheManager::HandleCollectionMediaL"); |
|
324 |
|
325 iRequestOwner = NULL; |
|
326 |
|
327 if ( KErrNone == aError ) |
|
328 { |
|
329 // Update the cache |
|
330 CGlxCache* cache = FindCacheForceCreateL(aIdSpaceId); |
|
331 cache->MediaUpdatedL(aMedia); |
|
332 } |
|
333 else |
|
334 { |
|
335 RPointerArray< MGlxMediaUser > users; |
|
336 CleanupClosePushL( users ); |
|
337 |
|
338 TInt idCount = iRequestedItemIds.Count(); |
|
339 if(idCount) |
|
340 { |
|
341 CGlxMedia* item = MediaForceCreateL(aIdSpaceId, iRequestedItemIds[0]); |
|
342 GlxErrorManager::SetAttributeErrorL(item, iRequestedAttrs, aError); |
|
343 |
|
344 // Keep track of media lists to notify later |
|
345 TInt userCount = item->UserCount(); |
|
346 for ( TInt userIndex = 0; userIndex < userCount; userIndex++ ) |
|
347 { |
|
348 users.InsertInAddressOrderL( &item->User( userIndex ) ); |
|
349 } |
|
350 } |
|
351 // Notify all affected users of error |
|
352 TInt userCount = users.Count(); |
|
353 for ( TInt i = 0; i < userCount; i++ ) |
|
354 { |
|
355 users[ i ]->HandleError( aError ); |
|
356 } |
|
357 |
|
358 CleanupStack::PopAndDestroy( &users ); |
|
359 } |
|
360 if ( aRequestNextAttr ) |
|
361 { |
|
362 MaintainCacheL(); |
|
363 } |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // FindCacheForceCreateL |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 CGlxCache* CGlxCacheManager::FindCacheForceCreateL(const TGlxIdSpaceId& aIdSpaceId) |
|
371 { |
|
372 TRACER("CGlxCacheManager::FindCacheForceCreateL"); |
|
373 |
|
374 CGlxCache* cache = NULL; |
|
375 |
|
376 // Look for existing cache |
|
377 TInt index = iCaches.FindInOrder(aIdSpaceId, (&CacheOrderByKey)); |
|
378 if ( KErrNotFound == index ) |
|
379 { |
|
380 // Not found: create one |
|
381 TLinearOrder<CGlxCache> orderer (&CacheOrderById); |
|
382 cache = new (ELeave) CGlxCache(aIdSpaceId, this); |
|
383 |
|
384 CleanupStack::PushL(cache); |
|
385 iCaches.InsertInOrderL(cache, orderer); |
|
386 CleanupStack::Pop(cache); |
|
387 } |
|
388 else |
|
389 { |
|
390 cache = iCaches[index]; |
|
391 } |
|
392 |
|
393 return cache; |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // Media |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 CGlxMedia* CGlxCacheManager::Media( const TGlxIdSpaceId& aIdSpaceId, |
|
401 const TGlxMediaId& aMediaId ) const |
|
402 { |
|
403 TRACER("CGlxCacheManager::Media"); |
|
404 |
|
405 // Look for the correct subcache |
|
406 TInt index = iCaches.FindInOrder( aIdSpaceId, &CacheOrderByKey ); |
|
407 |
|
408 if ( KErrNotFound == index ) |
|
409 { |
|
410 // No caches exist with this space id |
|
411 return NULL; |
|
412 } |
|
413 else |
|
414 { |
|
415 return iCaches[index]->Media( aMediaId ); |
|
416 } |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // MediaForceCreateL |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 CGlxMedia* CGlxCacheManager::MediaForceCreateL(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aMediaId) |
|
424 { |
|
425 TRACER("CGlxCacheManager::MediaForceCreateL"); |
|
426 |
|
427 CGlxCache* cache = FindCacheForceCreateL(aIdSpaceId); |
|
428 return cache->FindItemForceCreateL(aMediaId); |
|
429 } |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // AddObserverL |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 void CGlxCacheManager::AddObserverL(MGlxCacheObserver* aObserver) |
|
436 { |
|
437 TRACER("CGlxCacheManager::AddObserverL"); |
|
438 |
|
439 if ( aObserver ) |
|
440 { |
|
441 if ( KErrNotFound == iObserverList.Find( aObserver )) |
|
442 { |
|
443 iObserverList.AppendL(aObserver); |
|
444 } |
|
445 } |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // RemoveObserver |
|
450 // ----------------------------------------------------------------------------- |
|
451 // |
|
452 void CGlxCacheManager::RemoveObserver(MGlxCacheObserver* aObserver) |
|
453 { |
|
454 TRACER("CGlxCacheManager::RemoveObserver"); |
|
455 |
|
456 if ( aObserver ) |
|
457 { |
|
458 TInt index = iObserverList.Find( aObserver ); |
|
459 if ( KErrNotFound != index ) |
|
460 { |
|
461 iObserverList.Remove(index); |
|
462 } |
|
463 } |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // Refresh |
|
468 // --------------------------------------------------------------------------- |
|
469 // |
|
470 void CGlxCacheManager::RefreshL() |
|
471 { |
|
472 TRACER("CGlxCacheManager::Refresh"); |
|
473 |
|
474 if ( !iRequestOwner ) |
|
475 { |
|
476 // Currently idle, so trigger timer immediately to begin refresh |
|
477 iTempErrorTimer->Cancel(); |
|
478 iTempErrorTimer->Start( 0, 0, |
|
479 TCallBack( TempErrorTimerCallbackL, this ) ); |
|
480 |
|
481 HandleGarbageCollectionL(ETrue); // Clean-up is needed here; Considering Current Memory Condition |
|
482 } |
|
483 } |
|
484 |
|
485 // ----------------------------------------------------------------------------- |
|
486 // MaintainCache |
|
487 // ----------------------------------------------------------------------------- |
|
488 // |
|
489 TInt CGlxCacheManager::MaintainCacheL(TAny* aPtr) |
|
490 { |
|
491 TRACER("CGlxCacheManager::MaintainCache"); |
|
492 |
|
493 CGlxCacheManager* self |
|
494 = reinterpret_cast<CGlxCacheManager*>( aPtr ); |
|
495 self->MaintainCacheL(); |
|
496 |
|
497 // Clean-up is needed here; Considering Current Memory Condition |
|
498 // For Every HandleWindowChangedL; We Should not do Clean-up |
|
499 self->HandleGarbageCollectionL(ETrue); |
|
500 return 0; |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // MaintainCacheL |
|
505 // ----------------------------------------------------------------------------- |
|
506 // |
|
507 void CGlxCacheManager::MaintainCacheL() |
|
508 { |
|
509 TRACER("CGlxCacheManager::MaintainCacheL"); |
|
510 |
|
511 // Handle lists in priority order: all data for the highest priority list |
|
512 // is retrieved before the data for a lower priority list. NOTE: This |
|
513 // may need to be changed, since it might not always lead to the best |
|
514 // user experienced. (It may be sensible to retrieve item properties |
|
515 // for a lower priority list before all thumbnails for a higher priority |
|
516 // list, but this probably depends on the speed of the data sources. |
|
517 // It might be wise to decouple the contexts from the media lists |
|
518 |
|
519 if (!iRequestOwner) |
|
520 { |
|
521 iTempError = EFalse; |
|
522 iTempErrorTimer->Cancel(); |
|
523 |
|
524 RPointerArray<CGlxMediaList>& mediaLists = CGlxMediaList::MediaListsL(); |
|
525 iRequestedItemIds.Reset(); |
|
526 iRequestedAttrs.Reset(); |
|
527 iRequestedItemIndexes.Reset(); |
|
528 |
|
529 TInt listCount = mediaLists.Count(); |
|
530 |
|
531 // Request attributes in the fetch contexts |
|
532 for (TInt listIndex = 0; listIndex < listCount && !iRequestOwner; listIndex++) |
|
533 { |
|
534 CGlxMediaList* list = mediaLists[listIndex]; |
|
535 |
|
536 CMPXAttributeSpecs* attrSpecs = NULL; |
|
537 |
|
538 list->AttributeRequestL(iRequestedItemIndexes, iRequestedItemIds, iRequestedAttrs, attrSpecs ); |
|
539 CleanupStack::PushL(attrSpecs); |
|
540 |
|
541 TInt itemIdsCount = iRequestedItemIds.Count(); |
|
542 if (itemIdsCount > 0) |
|
543 { |
|
544 if (attrSpecs) |
|
545 { |
|
546 GLX_DEBUG2("CGlxCacheManager::MaintainCacheL() attrSpecs->Count() %d", attrSpecs->Count()); |
|
547 } |
|
548 |
|
549 TGlxMediaId itemId = iRequestedItemIds[0]; |
|
550 |
|
551 CMPXCollectionPath* path = RequestAsPathLC( *list ); |
|
552 |
|
553 // Add request for id, if does not exist already. Id is used to |
|
554 // identify which media object the attribute belongs to when |
|
555 // it is returned |
|
556 TIdentityRelation<TMPXAttribute> match (&TMPXAttribute::Match); |
|
557 if (iRequestedAttrs.Find(KMPXMediaGeneralId, match) == KErrNotFound) |
|
558 { |
|
559 iRequestedAttrs.AppendL(KMPXMediaGeneralId); |
|
560 } |
|
561 |
|
562 // Create the empty bitmap, if the request is for a bitmap |
|
563 TIdentityRelation<TMPXAttribute> matchContent(&TMPXAttribute::MatchContentId); |
|
564 TMPXAttribute tnAttr(KGlxMediaIdThumbnail, 0); |
|
565 if (iRequestedAttrs.Find(tnAttr, matchContent) != KErrNotFound) |
|
566 { |
|
567 #ifdef USE_S60_TNM |
|
568 if (iRequestedItemIndexes.Count()) |
|
569 { |
|
570 // Cancel Clean-up is needed here |
|
571 HandleGarbageCollectionL(EFalse); |
|
572 |
|
573 TSize tnSize; |
|
574 const TMPXAttributeData sizeAttrib = { KGlxMediaIdThumbnail , KGlxAttribSpecThumbnailSize }; |
|
575 if (attrSpecs && attrSpecs->IsSupported(sizeAttrib)) |
|
576 { |
|
577 tnSize = attrSpecs->ValueTObjectL<TSize>(sizeAttrib); |
|
578 } |
|
579 |
|
580 const TGlxMedia& item = list->Item( iRequestedItemIndexes[0] ); |
|
581 TBool priority = ETrue; |
|
582 const TMPXAttributeData priorityAttrib = { KGlxMediaIdThumbnail , KGlxAttribSpecThumbnailQualityOverSpeed }; |
|
583 if (attrSpecs && attrSpecs->IsSupported(priorityAttrib)) |
|
584 { |
|
585 priority = attrSpecs->ValueTObjectL<TBool>(priorityAttrib); |
|
586 } |
|
587 |
|
588 TGlxIdSpaceId spaceId = list->IdSpaceId(iRequestedItemIndexes[0]); |
|
589 GLX_DEBUG1("CGlxCacheManager::MaintainCacheL() requesting TN attribute (Medialist) Uri"); |
|
590 if (item.Uri().Find(KFileIdentifier) != KErrNotFound) |
|
591 { |
|
592 #ifdef _DEBUG |
|
593 iStartTime.HomeTime(); // Get home time |
|
594 #endif |
|
595 if (tnSize.iWidth < KMaxGridThumbnailWidth) |
|
596 { |
|
597 iTnEngine->SetFlagsL(CThumbnailManager::ECropToAspectRatio); |
|
598 iTnEngine->SetThumbnailSizeL(EGridThumbnailSize); |
|
599 GLX_DEBUG1("MaintainCacheL() - Fetch TN attrib - EGridThumbnailSize"); |
|
600 } |
|
601 else |
|
602 { |
|
603 iTnEngine->SetFlagsL(CThumbnailManager::EDefaultFlags); |
|
604 iTnEngine->SetThumbnailSizeL(EFullScreenThumbnailSize); |
|
605 GLX_DEBUG1("MaintainCacheL() - Fetch TN attrib - EFullScreenThumbnailSize"); |
|
606 } |
|
607 |
|
608 if (priority) |
|
609 { |
|
610 iTnEngine->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQuality); |
|
611 GLX_DEBUG1("MaintainCacheL() - Fetch TN attrib - EOptimizeForQuality"); |
|
612 } |
|
613 else |
|
614 { |
|
615 iTnEngine->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQualityWithPreview); |
|
616 GLX_DEBUG1("MaintainCacheL() - Fetch TN attrib - EOptimizeForQualityWithPreview"); |
|
617 } |
|
618 |
|
619 if (list->Collection().UidL().iUid == KGlxCollectionPluginImageViewerImplementationUid) |
|
620 { |
|
621 _LIT( KPrivateFolder, "\\Private\\" ); // Platsec private folder |
|
622 TParsePtrC parse( item.Uri() ); |
|
623 if( parse.PathPresent() && |
|
624 parse.Path().Length() > KPrivateFolder().Length() && |
|
625 parse.Path().Left( KPrivateFolder().Length() ).CompareF( KPrivateFolder ) == 0 ) |
|
626 { |
|
627 CreateImageViewerInstanceL(); |
|
628 GLX_DEBUG1("KGlxCollectionPluginImageViewerImplementationUid - Fetch (Private) TN!"); |
|
629 if ( &(iImageViewerInstance->ImageFileHandle()) ) |
|
630 { |
|
631 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(iImageViewerInstance->ImageFileHandle()); |
|
632 iThumbnailRequestIds.AppendL(TLoadingTN(iTnEngine->GetThumbnailL(*source), spaceId, tnSize, itemId)); |
|
633 CleanupStack::PopAndDestroy(source); |
|
634 } |
|
635 DeleteImageViewerInstance(); |
|
636 } |
|
637 else |
|
638 { |
|
639 GLX_DEBUG1("KGlxCollectionPluginImageViewerImplementationUid - Fetch TN!"); |
|
640 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(item.Uri(), 0); |
|
641 iThumbnailRequestIds.AppendL(TLoadingTN(iTnEngine->GetThumbnailL(*source), spaceId, tnSize, itemId)); |
|
642 CleanupStack::PopAndDestroy(source); |
|
643 } |
|
644 } |
|
645 else |
|
646 { |
|
647 GLX_DEBUG1("GENERAL NON IV CASE - Fetch TN"); |
|
648 GLX_DEBUG2("itemId = [%d] ", itemId.Value()); |
|
649 CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(item.Uri(), 0); |
|
650 iThumbnailRequestIds.AppendL(TLoadingTN( |
|
651 iTnEngine->GetThumbnailL(*source), |
|
652 spaceId, tnSize, itemId)); |
|
653 CleanupStack::PopAndDestroy(source); |
|
654 } |
|
655 iThumbnailId = itemId; |
|
656 } |
|
657 else |
|
658 { |
|
659 delete iTempThumbnail; |
|
660 iTempThumbnail = NULL; |
|
661 iTempThumbnail = new (ELeave) CFbsBitmap; |
|
662 User::LeaveIfError(iTempThumbnail->Create(TSize(), KGlxThumbnailDisplayMode)); |
|
663 iThumbnailId = itemId; |
|
664 GLX_DEBUG2("CGlxCacheManager::MaintainCacheL() requesting TN (DataSourceMde) attribute itemId %d", itemId.Value()); |
|
665 |
|
666 // Set bitmap handle in attribute spec |
|
667 if (attrSpecs) |
|
668 { |
|
669 TMPXAttribute thHandleAttrSpec(KGlxMediaIdThumbnail, KGlxAttribSpecThumbnailBitmapHandle); |
|
670 attrSpecs->SetTObjectValueL<TInt>(thHandleAttrSpec, iTempThumbnail->Handle()); |
|
671 } |
|
672 |
|
673 // Cancel Clean-up is needed here |
|
674 // This is Going to Highly Used Call |
|
675 // Can Think about an Ulternative. |
|
676 HandleGarbageCollectionL(EFalse); |
|
677 |
|
678 GLX_DEBUG3("MGallery - CGlxCacheManager::MaintainCacheL() requesting attribute for list %x and item %d", list, itemId.Value()); |
|
679 |
|
680 // Use list's isolated collection |
|
681 MMPXCollection& collection = list->Collection(); |
|
682 |
|
683 // Issue the request |
|
684 collection.MediaL(*path, iRequestedAttrs.Array(), attrSpecs); |
|
685 } |
|
686 } |
|
687 } |
|
688 else |
|
689 { |
|
690 GLX_DEBUG3("MGallery - CGlxCacheManager::MaintainCacheL() requesting attribute for list %x and item %d", list, itemId.Value()); |
|
691 |
|
692 // Use list's isolated collection |
|
693 MMPXCollection& collection = list->Collection(); |
|
694 if (collection.UidL().iUid == KGlxCollectionPluginImageViewerImplementationUid) |
|
695 { |
|
696 CreateImageViewerInstanceL(); |
|
697 TInt mediaCnt = list->Count(); |
|
698 TInt errInImage = KErrNone; |
|
699 |
|
700 GLX_DEBUG3("Image Viewer Collection - Attrib population! mediaCnt=%d, Media Id=%d", |
|
701 mediaCnt, itemId.Value()); |
|
702 |
|
703 delete iMPXMedia; |
|
704 iMPXMedia = NULL; |
|
705 |
|
706 TFileName fileName(KNullDesC); |
|
707 //retrieve the filename as per the caller app. |
|
708 if(iImageViewerInstance->IsPrivate()) |
|
709 { |
|
710 const TGlxMedia& item = list->Item( iRequestedItemIndexes[0] ); |
|
711 // If there is an URI available, then the request is due to EPathChanged message |
|
712 // due to a file save from Image Viewer, and attribs needs to be re-populated. |
|
713 // So, use the same URI; Oherwise getting fullname from handle might result in a crash. |
|
714 if (item.Uri().Length()) |
|
715 { |
|
716 fileName.Append(item.Uri()); |
|
717 } |
|
718 else |
|
719 { |
|
720 // private path |
|
721 RFile64& imageHandle = iImageViewerInstance->ImageFileHandle(); |
|
722 if ( &imageHandle ) |
|
723 { |
|
724 if (iImageViewerInstance->IsPrivateGif()) |
|
725 { |
|
726 __ASSERT_DEBUG(iImageViewerInstance->ImageUri(), Panic(EGlxPanicNullPointer)); |
|
727 fileName.Append( |
|
728 iImageViewerInstance->ImageUri()->Des()); |
|
729 } |
|
730 else |
|
731 { |
|
732 fileName.Append(imageHandle.FullName( |
|
733 fileName)); |
|
734 } |
|
735 } |
|
736 else |
|
737 { |
|
738 errInImage = KErrArgument; |
|
739 } |
|
740 } |
|
741 } |
|
742 else |
|
743 { |
|
744 // user data path |
|
745 if ( iImageViewerInstance->ImageUri() ) |
|
746 { |
|
747 fileName.Append(iImageViewerInstance->ImageUri()->Des()); |
|
748 RFs fs; |
|
749 CleanupClosePushL(fs); |
|
750 TInt err = fs.Connect(); |
|
751 errInImage = KErrArgument; |
|
752 if(err == KErrNone) |
|
753 { |
|
754 if (fs.IsValidName(fileName)) |
|
755 { |
|
756 errInImage = KErrNone; |
|
757 } |
|
758 } |
|
759 CleanupStack::PopAndDestroy(&fs); |
|
760 } |
|
761 else |
|
762 { |
|
763 errInImage = KErrArgument; |
|
764 } |
|
765 } |
|
766 |
|
767 iMPXMedia = CMPXMedia::NewL(); |
|
768 |
|
769 if (errInImage != KErrNone) |
|
770 { |
|
771 HandleGarbageCollectionL(EFalse); |
|
772 CleanupStack::PopAndDestroy(path); |
|
773 iRequestOwner = list; |
|
774 CleanupStack::PopAndDestroy(attrSpecs); |
|
775 TGlxIdSpaceId spaceId = list->IdSpaceId(iRequestedItemIndexes[0]); |
|
776 HandleCollectionMediaL(spaceId, *iMPXMedia, errInImage); |
|
777 DeleteImageViewerInstance(); |
|
778 return; |
|
779 } |
|
780 |
|
781 if(!iReader) |
|
782 { |
|
783 TRAP(errInImage, iReader = CGlxImageReader::NewL()); |
|
784 } |
|
785 |
|
786 for ( TInt i = 0; i < iRequestedAttrs.Count(); i++ ) |
|
787 { |
|
788 if ( iRequestedAttrs[i] == KMPXMediaGeneralId ) |
|
789 { |
|
790 iMPXMedia->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, |
|
791 (TMPXItemId)itemId.Value()); |
|
792 } |
|
793 else if ( iRequestedAttrs[i] == KMPXMediaGeneralType ) |
|
794 { |
|
795 iMPXMedia->SetTObjectValueL(KMPXMediaGeneralType, EMPXItem); |
|
796 } |
|
797 else if ( iRequestedAttrs[i] == KMPXMediaGeneralCategory ) |
|
798 { |
|
799 iMPXMedia->SetTObjectValueL(KMPXMediaGeneralCategory, EMPXImage); |
|
800 } |
|
801 else if ( iRequestedAttrs[i] == KMPXMediaGeneralUri ) |
|
802 { |
|
803 iMPXMedia->SetTextValueL(KMPXMediaGeneralUri, fileName); |
|
804 } |
|
805 else if ( iRequestedAttrs[i] == KMPXMediaGeneralTitle ) |
|
806 { |
|
807 TParsePtrC parser(fileName); |
|
808 iMPXMedia->SetTextValueL(KMPXMediaGeneralTitle, parser.Name()); |
|
809 } |
|
810 else if ((iRequestedAttrs[i] == KGlxMediaGeneralLastModifiedDate) |
|
811 || (iRequestedAttrs[i] == KMPXMediaGeneralDate)) |
|
812 { |
|
813 // Image viewer use case, no need of genaral date, |
|
814 // but, the same is added for attribute completion purpose. |
|
815 TMPXAttribute attrib = iRequestedAttrs[i]; |
|
816 TTime time; |
|
817 time.HomeTime(); |
|
818 if (errInImage == KErrNone) |
|
819 { |
|
820 if (iImageViewerInstance->IsPrivate()) |
|
821 { |
|
822 RFile64 & imageHandle = |
|
823 iImageViewerInstance->ImageFileHandle(); |
|
824 if (imageHandle.SubSessionHandle() |
|
825 != KNullHandle) |
|
826 { |
|
827 imageHandle.Modified(time); |
|
828 } |
|
829 } |
|
830 else |
|
831 { |
|
832 RFs fs; |
|
833 CleanupClosePushL(fs); |
|
834 TInt err = fs.Connect(); |
|
835 if (err == KErrNone) |
|
836 { |
|
837 TEntry entry; |
|
838 fs.Entry(fileName, entry); |
|
839 time = entry.iModified; |
|
840 } |
|
841 CleanupStack::PopAndDestroy(&fs); |
|
842 } |
|
843 } |
|
844 iMPXMedia->SetTObjectValueL(attrib, |
|
845 time.Int64()); |
|
846 } |
|
847 else if ( iRequestedAttrs[i] == KMPXMediaGeneralSize ) |
|
848 { |
|
849 TInt64 size = 0; |
|
850 TInt err = KErrNotFound; |
|
851 if (errInImage == KErrNone) |
|
852 { |
|
853 if (iImageViewerInstance->IsPrivate()) |
|
854 { |
|
855 RFile64& imageHandle = |
|
856 iImageViewerInstance->ImageFileHandle(); |
|
857 if (imageHandle.SubSessionHandle() |
|
858 != KNullHandle) |
|
859 { |
|
860 err = imageHandle.Size(size); |
|
861 } |
|
862 } |
|
863 else |
|
864 { |
|
865 RFs fs; |
|
866 CleanupClosePushL(fs); |
|
867 err = fs.Connect(); |
|
868 if (err == KErrNone) |
|
869 { |
|
870 TEntry entry; |
|
871 fs.Entry(fileName, entry); |
|
872 size = (TUint) entry.iSize; |
|
873 } |
|
874 CleanupStack::PopAndDestroy(&fs); |
|
875 } |
|
876 |
|
877 if (err != KErrNone) |
|
878 { |
|
879 size = 0; |
|
880 } |
|
881 } |
|
882 iMPXMedia->SetTObjectValueL( |
|
883 KMPXMediaGeneralSize, size); |
|
884 } |
|
885 else if ( iRequestedAttrs[i] == KMPXMediaGeneralDrive ) |
|
886 { |
|
887 TParsePtrC parser(fileName); |
|
888 iMPXMedia->SetTextValueL(KMPXMediaGeneralDrive, parser.Drive()); |
|
889 } |
|
890 else if ( iRequestedAttrs[i] == KMPXMediaGeneralMimeType ) |
|
891 { |
|
892 if(errInImage == KErrNone) |
|
893 { |
|
894 TDataType dataType; |
|
895 GetMimeTypeL(fileName, dataType); |
|
896 iMPXMedia->SetTextValueL(KMPXMediaGeneralMimeType, dataType.Des()); |
|
897 } |
|
898 else |
|
899 { |
|
900 iMPXMedia->SetTextValueL(KMPXMediaGeneralMimeType, KDefaultType); |
|
901 } |
|
902 } |
|
903 else if ( iRequestedAttrs[i] == KMPXMediaGeneralDuration ) |
|
904 { |
|
905 iMPXMedia->SetTObjectValueL(KMPXMediaGeneralDuration, 0); |
|
906 } |
|
907 else if ( iRequestedAttrs[i] == KGlxMediaGeneralSystemItem) |
|
908 { |
|
909 iMPXMedia->SetTObjectValueL(KGlxMediaGeneralSystemItem, EFalse); |
|
910 } |
|
911 else if ( iRequestedAttrs[i] == KGlxMediaGeneralDimensions ) |
|
912 { |
|
913 TSize dimensions = TSize(); |
|
914 if(errInImage == KErrNone) |
|
915 { |
|
916 //need to fetch the original file dimensions |
|
917 dimensions = iReader->GetDimensions(); |
|
918 iMPXMedia->SetTObjectValueL(KGlxMediaGeneralDimensions, dimensions); |
|
919 } |
|
920 else |
|
921 { |
|
922 iMPXMedia->SetTObjectValueL(KGlxMediaGeneralDimensions, dimensions); |
|
923 } |
|
924 } |
|
925 else if ( iRequestedAttrs[i] == KGlxMediaGeneralFramecount ) |
|
926 { |
|
927 TInt fcount = 1; |
|
928 if(errInImage == KErrNone) |
|
929 { |
|
930 fcount = iReader->GetFrameCount(); |
|
931 } |
|
932 GLX_DEBUG2("Imageviewer Collection framecount(%d)", fcount); |
|
933 iMPXMedia->SetTObjectValueL(KGlxMediaGeneralFramecount, fcount); |
|
934 } |
|
935 else if ( iRequestedAttrs[i] == KMPXMediaGeneralComment ) |
|
936 { |
|
937 iMPXMedia->SetTextValueL(KMPXMediaGeneralComment, KNullDesC); |
|
938 } |
|
939 else if (iRequestedAttrs[i] == KMPXMediaDrmProtected ) |
|
940 { |
|
941 TBool protection = EFalse; |
|
942 if(errInImage == KErrNone) |
|
943 { |
|
944 protection = iReader->GetDRMRightsL |
|
945 (ContentAccess::EIsProtected); |
|
946 } |
|
947 else if (errInImage == KErrCANoRights |
|
948 || errInImage == KErrCAPendingRights |
|
949 || errInImage == KErrCACorruptRights) |
|
950 { |
|
951 protection = ETrue; |
|
952 } |
|
953 iMPXMedia->SetTObjectValueL( |
|
954 KMPXMediaDrmProtected, protection); |
|
955 } |
|
956 else if ( iRequestedAttrs[i] == KGlxMediaGeneralDRMRightsValid ) |
|
957 { |
|
958 TInt rightsValid = EGlxDrmRightsValidityUnknown; |
|
959 if(errInImage == KErrNone) |
|
960 { |
|
961 TBool canView = iReader->GetDRMRightsL( |
|
962 ContentAccess::ECanView); |
|
963 rightsValid |
|
964 = canView |
|
965 ? EGlxDrmRightsValid |
|
966 : EGlxDrmRightsInvalid; |
|
967 } |
|
968 else if (errInImage == KErrCANoRights |
|
969 || errInImage == KErrCACorruptRights) |
|
970 { |
|
971 rightsValid = EGlxDrmRightsInvalid; |
|
972 } |
|
973 iMPXMedia->SetTObjectValueL( |
|
974 KGlxMediaGeneralDRMRightsValid, |
|
975 rightsValid); |
|
976 } |
|
977 else if ( iRequestedAttrs[i] == KMPXMediaGeneralCount ) |
|
978 { |
|
979 iMPXMedia->SetTObjectValueL(KMPXMediaGeneralCount, 1); |
|
980 } |
|
981 else if ( iRequestedAttrs[i] == KMPXMediaColDetailSpaceId ) |
|
982 { |
|
983 TGlxIdSpaceId spaceId = list->IdSpaceId(iRequestedItemIndexes[0]); |
|
984 iMPXMedia->SetTObjectValueL(KMPXMediaColDetailSpaceId, |
|
985 spaceId.Value()); |
|
986 } |
|
987 else if ( iRequestedAttrs[i] == KGlxMediaGeneralSlideshowableContent ) |
|
988 { |
|
989 iMPXMedia->SetTObjectValueL(KGlxMediaGeneralSlideshowableContent, -1); |
|
990 } |
|
991 else if ( iRequestedAttrs[i] == KGlxMediaGeneralLocation) |
|
992 { |
|
993 // Set the attribute to a TCoordinate initialised to NaN. |
|
994 iMPXMedia->SetTObjectValueL(KGlxMediaGeneralLocation, TCoordinate()); |
|
995 } |
|
996 else |
|
997 { |
|
998 DeleteImageViewerInstance(); |
|
999 User::Leave(KErrNotSupported); |
|
1000 } |
|
1001 } |
|
1002 |
|
1003 HandleGarbageCollectionL(EFalse); |
|
1004 CleanupStack::PopAndDestroy(path); |
|
1005 iRequestOwner = list; |
|
1006 CleanupStack::PopAndDestroy(attrSpecs); |
|
1007 TGlxIdSpaceId spaceId = list->IdSpaceId(iRequestedItemIndexes[0]); |
|
1008 HandleCollectionMediaL(spaceId, *iMPXMedia, KErrNone); |
|
1009 DeleteImageViewerInstance(); |
|
1010 delete iReader; |
|
1011 iReader = NULL; |
|
1012 return; |
|
1013 } |
|
1014 else |
|
1015 { |
|
1016 // Issue the request |
|
1017 collection.MediaL(*path, iRequestedAttrs.Array(), attrSpecs); |
|
1018 } |
|
1019 } |
|
1020 #else // USE_S60_TNM |
|
1021 delete iTempThumbnail; |
|
1022 iTempThumbnail = NULL; |
|
1023 iTempThumbnail = new (ELeave) CFbsBitmap; |
|
1024 User::LeaveIfError(iTempThumbnail->Create(TSize(), KGlxThumbnailDisplayMode)); |
|
1025 iThumbnailId = itemId; |
|
1026 |
|
1027 // Set bitmap handle in attribute spec |
|
1028 if (attrSpecs) |
|
1029 { |
|
1030 TMPXAttribute thHandleAttrSpec(KGlxMediaIdThumbnail, KGlxAttribSpecThumbnailBitmapHandle); |
|
1031 attrSpecs->SetTObjectValueL<TInt>(thHandleAttrSpec, iTempThumbnail->Handle()); |
|
1032 } |
|
1033 // Cancel Clean-up is needed here |
|
1034 // This is Going to Highly Used Call |
|
1035 // Can Think about an Ulternative. |
|
1036 HandleGarbageCollectionL(EFalse); |
|
1037 } |
|
1038 |
|
1039 GLX_DEBUG3("MGallery - CGlxCacheManager::MaintainCacheL() requesting attribute for list %x and item %d", list, itemId.Value()); |
|
1040 |
|
1041 // Use list's isolated collection |
|
1042 MMPXCollection& collection = list->Collection(); |
|
1043 |
|
1044 // Issue the request |
|
1045 collection.MediaL(*path, iRequestedAttrs.Array(), attrSpecs); |
|
1046 #endif |
|
1047 CleanupStack::PopAndDestroy(path); |
|
1048 |
|
1049 iRequestOwner = list; |
|
1050 } |
|
1051 |
|
1052 CleanupStack::PopAndDestroy(attrSpecs); |
|
1053 } |
|
1054 |
|
1055 if (iRequestedItemIds.Count()) |
|
1056 { |
|
1057 GLX_DEBUG1("CGlxCacheManager::MaintainCacheL() - Cleanup needed here!"); |
|
1058 // Clean-up is needed here; Considering Current Memory Condition |
|
1059 HandleGarbageCollectionL(ETrue); |
|
1060 } |
|
1061 |
|
1062 if ( !iRequestOwner ) |
|
1063 { |
|
1064 if ( iTempError ) |
|
1065 { |
|
1066 // Reawaken in a while to check again |
|
1067 StartTempErrorTimer(); |
|
1068 } |
|
1069 } |
|
1070 } |
|
1071 } |
|
1072 |
|
1073 // ----------------------------------------------------------------------------- |
|
1074 // BroadcastAttributesAvailableL |
|
1075 // ----------------------------------------------------------------------------- |
|
1076 // |
|
1077 void CGlxCacheManager::BroadcastAttributesAvailableL(const TGlxIdSpaceId& aIdSpaceId, |
|
1078 const TGlxMediaId& aMediaId, |
|
1079 const RArray<TMPXAttribute>& aAttributes, |
|
1080 const CGlxMedia* aMedia) |
|
1081 { |
|
1082 TRACER("CGlxCacheManager::BroadcastAttributesAvailableL"); |
|
1083 |
|
1084 TInt count = iObserverList.Count(); |
|
1085 TInt i; |
|
1086 for ( i = 0; i < count; i++ ) |
|
1087 { |
|
1088 iObserverList[i]->HandleAttributesAvailableL(aIdSpaceId, aMediaId, aAttributes, aMedia); |
|
1089 } |
|
1090 } |
|
1091 |
|
1092 /** |
|
1093 * Cleanup the media of the given media id: broadcast this to all observers |
|
1094 * @param aMediaId The media id of the item |
|
1095 */ |
|
1096 void CGlxCacheManager::CleanupMedia(const TGlxMediaId& aMediaId) |
|
1097 { |
|
1098 TRACER("CGlxCacheManager::CleanupMedia"); |
|
1099 TInt count = iObserverList.Count(); |
|
1100 GLX_DEBUG2("CGlxCacheManager::CleanupMedia - aMediaId = %d", aMediaId.Value()); |
|
1101 TInt i; |
|
1102 for ( i = 0; i < count; i++ ) |
|
1103 { |
|
1104 iObserverList[i]->CleanupMedia(aMediaId); |
|
1105 } |
|
1106 } |
|
1107 |
|
1108 // ----------------------------------------------------------------------------- |
|
1109 // Handles modification of item in a cache |
|
1110 // ----------------------------------------------------------------------------- |
|
1111 void CGlxCacheManager::HandleItemModified(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aMediaId, const RArray<TMPXAttribute>& aAttributes) |
|
1112 { |
|
1113 TRACER("CGlxCacheManager::HandleItemModified"); |
|
1114 |
|
1115 // Look for the correct subcache |
|
1116 TInt index = iCaches.FindInOrder(aIdSpaceId, (&CacheOrderByKey)); |
|
1117 if (index != KErrNotFound) |
|
1118 { |
|
1119 iCaches[index]->HandleItemModified(aMediaId, aAttributes); |
|
1120 } |
|
1121 } |
|
1122 |
|
1123 // ----------------------------------------------------------------------------- |
|
1124 // CacheOrderById |
|
1125 // ----------------------------------------------------------------------------- |
|
1126 // |
|
1127 TInt CGlxCacheManager::CacheOrderById(const CGlxCache& aItem1, const CGlxCache& aItem2) |
|
1128 { |
|
1129 TRACER("CGlxCacheManager::CacheOrderById"); |
|
1130 |
|
1131 // Cannot do aItem1.IdSpaceId() - aItem2.IdSpaceId(), since IdSpaceId().Value() returns an unsigned value |
|
1132 TGlxIdSpaceId id1 = aItem1.IdSpaceId(); |
|
1133 TGlxIdSpaceId id2 = aItem2.IdSpaceId(); |
|
1134 if (id1 < id2) |
|
1135 { |
|
1136 return -1; |
|
1137 } |
|
1138 |
|
1139 if (id1 > id2) |
|
1140 { |
|
1141 return 1; |
|
1142 } |
|
1143 |
|
1144 return 0; |
|
1145 } |
|
1146 |
|
1147 // ----------------------------------------------------------------------------- |
|
1148 // CacheOrderByKey |
|
1149 // ----------------------------------------------------------------------------- |
|
1150 // |
|
1151 TInt CGlxCacheManager::CacheOrderByKey(const TGlxIdSpaceId* aIdSpaceId, const CGlxCache& aItem2) |
|
1152 { |
|
1153 TRACER("CGlxCacheManager::CacheOrderByKey"); |
|
1154 |
|
1155 TGlxIdSpaceId id2 = aItem2.IdSpaceId(); |
|
1156 if (*aIdSpaceId < id2) |
|
1157 { |
|
1158 return -1; |
|
1159 } |
|
1160 |
|
1161 if (*aIdSpaceId > id2) |
|
1162 { |
|
1163 return 1; |
|
1164 } |
|
1165 |
|
1166 return 0; |
|
1167 } |
|
1168 |
|
1169 // ----------------------------------------------------------------------------- |
|
1170 // TempThumbnail |
|
1171 // ----------------------------------------------------------------------------- |
|
1172 // |
|
1173 CFbsBitmap* CGlxCacheManager::TempThumbnail() |
|
1174 { |
|
1175 TRACER("CGlxCacheManager::TempThumbnail"); |
|
1176 |
|
1177 return iTempThumbnail; |
|
1178 } |
|
1179 |
|
1180 // ----------------------------------------------------------------------------- |
|
1181 // TempThumbnailId |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // |
|
1184 TGlxMediaId CGlxCacheManager::TempThumbnailId() |
|
1185 { |
|
1186 TRACER("CGlxCacheManager::TempThumbnailId"); |
|
1187 |
|
1188 return iThumbnailId; |
|
1189 } |
|
1190 |
|
1191 // ----------------------------------------------------------------------------- |
|
1192 // SetTempThumbnail |
|
1193 // ----------------------------------------------------------------------------- |
|
1194 // |
|
1195 void CGlxCacheManager::SetTempThumbnailToNull() |
|
1196 { |
|
1197 TRACER("CGlxCacheManager::SetTempThumbnailToNull"); |
|
1198 |
|
1199 iTempThumbnail = NULL; |
|
1200 } |
|
1201 |
|
1202 // ----------------------------------------------------------------------------- |
|
1203 // ErrorsOnRequestedItemsL |
|
1204 // ----------------------------------------------------------------------------- |
|
1205 // |
|
1206 TBool CGlxCacheManager::ErrorsOnRequestedItemsL() |
|
1207 { |
|
1208 TRACER("CGlxCacheManager::ErrorsOnRequestedItemsL"); |
|
1209 |
|
1210 TBool errorFound = EFalse; |
|
1211 |
|
1212 TInt itemCount = iRequestedItemIds.Count(); |
|
1213 TInt attrCount = iRequestedAttrs.Count(); |
|
1214 |
|
1215 for ( TInt itemIndex = 0; itemIndex < itemCount && !errorFound; itemIndex++ ) |
|
1216 { |
|
1217 CGlxMedia* media = Media(iRequestedItemsIdSpace, iRequestedItemIds[itemIndex]); |
|
1218 |
|
1219 if ( media ) |
|
1220 { |
|
1221 for ( TInt attrIndex = 0; attrIndex < attrCount && !errorFound; attrIndex++ ) |
|
1222 { |
|
1223 errorFound = (KErrNone != GlxErrorManager::HasAttributeErrorL(media, iRequestedAttrs[attrIndex])); |
|
1224 } |
|
1225 } |
|
1226 } |
|
1227 |
|
1228 return errorFound; |
|
1229 } |
|
1230 |
|
1231 // ----------------------------------------------------------------------------- |
|
1232 // Caches |
|
1233 // ----------------------------------------------------------------------------- |
|
1234 // |
|
1235 const RPointerArray<CGlxCache>& CGlxCacheManager::Caches() |
|
1236 { |
|
1237 TRACER("CGlxCacheManager::Caches"); |
|
1238 |
|
1239 return iCaches; |
|
1240 } |
|
1241 |
|
1242 // ----------------------------------------------------------------------------- |
|
1243 // SetTemporaryErrorFlag |
|
1244 // ----------------------------------------------------------------------------- |
|
1245 // |
|
1246 void CGlxCacheManager::SetTemporaryErrorFlag() |
|
1247 { |
|
1248 TRACER("CGlxCacheManager::SetTemporaryErrorFlag"); |
|
1249 |
|
1250 iTempError = ETrue; |
|
1251 } |
|
1252 |
|
1253 // ----------------------------------------------------------------------------- |
|
1254 // StartTempErrorTimer |
|
1255 // ----------------------------------------------------------------------------- |
|
1256 // |
|
1257 void CGlxCacheManager::StartTempErrorTimer() |
|
1258 { |
|
1259 TRACER("CGlxCacheManager::StartTempErrorTimer"); |
|
1260 |
|
1261 iTempErrorTimer->Cancel(); |
|
1262 iTempErrorTimer->Start( |
|
1263 TTimeIntervalMicroSeconds32(KGlxTemporaryErrorRecheckPeriodInSeconds * 1000000), |
|
1264 TTimeIntervalMicroSeconds32(KGlxTemporaryErrorRecheckPeriodInSeconds * 1000000), |
|
1265 TCallBack(&CGlxCacheManager::TempErrorTimerCallbackL,(TAny *)this)); |
|
1266 } |
|
1267 |
|
1268 // ----------------------------------------------------------------------------- |
|
1269 // TempErrorTimerCallbackL |
|
1270 // ----------------------------------------------------------------------------- |
|
1271 // |
|
1272 TInt CGlxCacheManager::TempErrorTimerCallbackL(TAny* aPtr) |
|
1273 { |
|
1274 TRACER("CGlxCacheManager::TempErrorTimerCallback"); |
|
1275 |
|
1276 CGlxCacheManager* self = (CGlxCacheManager*) aPtr; |
|
1277 |
|
1278 if ( self ) |
|
1279 { |
|
1280 self->TempErrorTimerCompleteL(); |
|
1281 } |
|
1282 |
|
1283 return 0; |
|
1284 } |
|
1285 |
|
1286 // ----------------------------------------------------------------------------- |
|
1287 // TempErrorTimerComplete |
|
1288 // ----------------------------------------------------------------------------- |
|
1289 // |
|
1290 void CGlxCacheManager::TempErrorTimerCompleteL() |
|
1291 { |
|
1292 TRACER("CGlxCacheManager::TempErrorTimerComplete"); |
|
1293 |
|
1294 iTempErrorTimer->Cancel(); |
|
1295 TRAPD(err, MaintainCacheL()); |
|
1296 |
|
1297 // If MaintainCacheL leaves, force gabage collection to start and restart timer |
|
1298 if ( KErrNone != err ) |
|
1299 { |
|
1300 if ( KErrNoMemory == err ) |
|
1301 { |
|
1302 HandleGarbageCollectionL(ETrue); |
|
1303 } |
|
1304 |
|
1305 if ( !iRequestOwner ) |
|
1306 { |
|
1307 StartTempErrorTimer(); |
|
1308 } |
|
1309 } |
|
1310 } |
|
1311 |
|
1312 // ----------------------------------------------------------------------------- |
|
1313 // Create a path with the request items |
|
1314 // ----------------------------------------------------------------------------- |
|
1315 // |
|
1316 inline CMPXCollectionPath* CGlxCacheManager::RequestAsPathLC(const CGlxMediaList& aList) |
|
1317 { |
|
1318 TRACER("CGlxCacheManager::RequestAsPathLC"); |
|
1319 |
|
1320 CMPXCollectionPath* path = aList.PathLC( NGlxListDefs::EPathParent ); |
|
1321 |
|
1322 RArray<TMPXItemId> mpxIds; |
|
1323 CleanupClosePushL( mpxIds ); |
|
1324 |
|
1325 TInt itemIdsCount = iRequestedItemIds.Count(); |
|
1326 |
|
1327 // Reserve space for all items |
|
1328 mpxIds.ReserveL( itemIdsCount ); |
|
1329 |
|
1330 for (TInt i = 0; i < itemIdsCount; ++i) |
|
1331 { |
|
1332 mpxIds.AppendL( iRequestedItemIds[ i ].Value() ); |
|
1333 } |
|
1334 |
|
1335 path->AppendL( mpxIds.Array() ); |
|
1336 path->SelectAllL(); |
|
1337 |
|
1338 CleanupStack::PopAndDestroy( &mpxIds ); |
|
1339 |
|
1340 return path; |
|
1341 } |
|
1342 |
|
1343 // ----------------------------------------------------------------------------- |
|
1344 // HandleListDeleted |
|
1345 // ----------------------------------------------------------------------------- |
|
1346 void CGlxCacheManager::HandleListDeleted(CGlxMediaList* aList) |
|
1347 { |
|
1348 TRACER("CGlxCacheManager::HandleListDeleted"); |
|
1349 |
|
1350 if (iRequestOwner == aList) |
|
1351 { |
|
1352 iRequestOwner = NULL; |
|
1353 |
|
1354 TRAP_IGNORE( MaintainCacheL() ); |
|
1355 } |
|
1356 } |
|
1357 |
|
1358 // ----------------------------------------------------------------------------- |
|
1359 // Inform cache manager to reserve users for an item, for a particular cache |
|
1360 // ----------------------------------------------------------------------------- |
|
1361 // |
|
1362 void CGlxCacheManager::ReserveUsersL(const TGlxIdSpaceId& aIdSpaceId, TInt aCount) |
|
1363 { |
|
1364 TRACER("CGlxCacheManager::ReserveUsersL"); |
|
1365 |
|
1366 // Look for existing cache |
|
1367 TInt index = iCaches.FindInOrder( aIdSpaceId, ( &CacheOrderByKey ) ); |
|
1368 if (index != KErrNotFound) |
|
1369 { |
|
1370 iCaches[index]->ReserveUsersL( aCount ); |
|
1371 } |
|
1372 } |
|
1373 |
|
1374 //OOM |
|
1375 // ----------------------------------------------------------------------------- |
|
1376 // Start cache cleanup on Low memory event from OOM |
|
1377 // ----------------------------------------------------------------------------- |
|
1378 // |
|
1379 void CGlxCacheManager::ReleaseRAML(TBool aFlushOnRequest) |
|
1380 { |
|
1381 TRACER("CGlxCacheManager::ReleaseRAM"); |
|
1382 if (aFlushOnRequest) |
|
1383 { |
|
1384 HandleGarbageCollectionL(aFlushOnRequest); |
|
1385 } |
|
1386 else |
|
1387 { |
|
1388 iGarbageCollector->CleanupL(); |
|
1389 } |
|
1390 } |
|
1391 |
|
1392 // ----------------------------------------------------------------------------- |
|
1393 // Force a cleanup on particular media id : remove all attributes |
|
1394 // ----------------------------------------------------------------------------- |
|
1395 // |
|
1396 void CGlxCacheManager::ForceCleanupMedia(TGlxIdSpaceId aSpaceId, |
|
1397 TGlxMediaId aMediaId) |
|
1398 { |
|
1399 TRACER("CGlxCacheManager::ForceCleanupMedia"); |
|
1400 TInt spaceIdIndex = iCaches.FindInOrder( aSpaceId, &CacheOrderByKey ); |
|
1401 if ( KErrNotFound != spaceIdIndex ) |
|
1402 { |
|
1403 if ( iCaches[spaceIdIndex]->Media( aMediaId ) ) |
|
1404 { |
|
1405 TInt mediaIdIndex = iCaches[spaceIdIndex]->FindMediaIndexInCache(aMediaId); |
|
1406 if ( KErrNotFound != mediaIdIndex ) |
|
1407 { |
|
1408 iCaches[spaceIdIndex]->Delete(mediaIdIndex); |
|
1409 } |
|
1410 } |
|
1411 } |
|
1412 } |
|
1413 |
|
1414 // ----------------------------------------------------------------------------- |
|
1415 // Stop cache cleanup on good memory event from OOM |
|
1416 // ----------------------------------------------------------------------------- |
|
1417 // |
|
1418 void CGlxCacheManager::StopRAMReleaseL() |
|
1419 { |
|
1420 TRACER("CGlxCacheManager::StopRAMRelease"); |
|
1421 iGarbageCollector->CancelCleanup(); |
|
1422 |
|
1423 } |
|
1424 //OOM |
|
1425 |
|
1426 #ifdef USE_S60_TNM |
|
1427 // ----------------------------------------------------------------------------- |
|
1428 // CGlxCacheManager::FindLoadingById() |
|
1429 // ----------------------------------------------------------------------------- |
|
1430 // |
|
1431 TInt CGlxCacheManager::FindLoadingById(TThumbnailRequestId aId, TBool aRemove) |
|
1432 { |
|
1433 TRACER("CGlxCacheManager::FindLoadingById"); |
|
1434 TInt index = KErrNotFound; |
|
1435 for(TInt i = 0; i < iThumbnailRequestIds.Count(); ++i) |
|
1436 { |
|
1437 if(iThumbnailRequestIds[i].iId == aId) |
|
1438 { |
|
1439 index = i; |
|
1440 if(aRemove) |
|
1441 { |
|
1442 iThumbnailRequestIds.Remove(i); |
|
1443 } |
|
1444 break; |
|
1445 } |
|
1446 } |
|
1447 return index; |
|
1448 } |
|
1449 |
|
1450 // ----------------------------------------------------------------------------- |
|
1451 // CGlxCacheManager::ThumbnailPreviewReady() |
|
1452 // ----------------------------------------------------------------------------- |
|
1453 // |
|
1454 void CGlxCacheManager::ThumbnailPreviewReady(MThumbnailData& aThumbnail, |
|
1455 TThumbnailRequestId aId) |
|
1456 { |
|
1457 TRACER("CGlxCacheManager::ThumbnailPreviewReady"); |
|
1458 TInt error = KErrNotSupported; |
|
1459 if ( aThumbnail.Bitmap() ) |
|
1460 { |
|
1461 GLX_DEBUG1("CGlxCacheManager::ThumbnailPreviewReady preview aval"); |
|
1462 error = KErrNone; |
|
1463 } |
|
1464 ThumbnailReadyL(error, aThumbnail, aId, EFalse); |
|
1465 } |
|
1466 |
|
1467 // ----------------------------------------------------------------------------- |
|
1468 // CGlxCacheManager::ThumbnailReady() |
|
1469 // ----------------------------------------------------------------------------- |
|
1470 // |
|
1471 void CGlxCacheManager::ThumbnailReady(TInt aError, |
|
1472 MThumbnailData& aThumbnail, TThumbnailRequestId aId) |
|
1473 { |
|
1474 TRACER("CGlxCacheManager::ThumbnailReady"); |
|
1475 GLX_DEBUG2("CGlxCacheManager::ThumbnailReady aError=%d", aError); |
|
1476 ThumbnailReadyL(aError, aThumbnail, aId, ETrue); |
|
1477 } |
|
1478 |
|
1479 // ----------------------------------------------------------------------------- |
|
1480 // CGlxCacheManager::ThumbnailReadyL() |
|
1481 // ----------------------------------------------------------------------------- |
|
1482 // |
|
1483 void CGlxCacheManager::ThumbnailReadyL(TInt aError, MThumbnailData& aThumbnail, |
|
1484 TThumbnailRequestId aId, TBool aQuality) |
|
1485 { |
|
1486 TRACER("CGlxCacheManager::ThumbnailReadyL"); |
|
1487 GLX_DEBUG3("CGlxCacheManager::ThumbnailReadyL aError=%d, aQuality=%d", |
|
1488 aError, aQuality); |
|
1489 |
|
1490 #ifdef _DEBUG |
|
1491 iStopTime.HomeTime(); // Get home time |
|
1492 GLX_DEBUG2("=>CGlxCacheManager::ThumbnailReadyL - TN Fetch took <%d> us", |
|
1493 (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64()); |
|
1494 #endif |
|
1495 |
|
1496 TInt reqIndex = FindLoadingById(aId, EFalse); |
|
1497 |
|
1498 if (reqIndex == KErrNotFound) |
|
1499 { |
|
1500 return; |
|
1501 } |
|
1502 |
|
1503 delete iMPXMedia; |
|
1504 iMPXMedia = NULL; |
|
1505 |
|
1506 iMPXMedia = CMPXMedia::NewL(); |
|
1507 if (aError == KErrNone) |
|
1508 { |
|
1509 delete iTempThumbnail; |
|
1510 iTempThumbnail = NULL; |
|
1511 iTempThumbnail = aThumbnail.DetachBitmap(); |
|
1512 |
|
1513 CGlxThumbnailAttribute* tnAttribute = new (ELeave) CGlxThumbnailAttribute; |
|
1514 CleanupStack::PushL(tnAttribute); |
|
1515 tnAttribute->iDimensions = iThumbnailRequestIds[reqIndex].iSize; |
|
1516 tnAttribute->iThumbnailQuality = aQuality; |
|
1517 |
|
1518 iMPXMedia->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, |
|
1519 iThumbnailRequestIds[reqIndex].iThumbnailId.Value()); |
|
1520 TUint attributeId = GlxFullThumbnailAttributeId(aQuality, |
|
1521 iThumbnailRequestIds[reqIndex].iSize.iWidth, |
|
1522 iThumbnailRequestIds[reqIndex].iSize.iHeight); |
|
1523 iMPXMedia->SetNoNewLCObjectL( |
|
1524 TMPXAttribute(KGlxMediaIdThumbnail, attributeId), tnAttribute); |
|
1525 CleanupStack::PopAndDestroy(tnAttribute); |
|
1526 |
|
1527 } |
|
1528 |
|
1529 HandleCollectionMediaL(iThumbnailRequestIds[reqIndex].iSpaceId, |
|
1530 *iMPXMedia, aError, aQuality); |
|
1531 if (aQuality) |
|
1532 { |
|
1533 FindLoadingById(aId, ETrue); |
|
1534 } |
|
1535 } |
|
1536 #endif |
|
1537 |
|
1538 // ----------------------------------------------------------------------------- |
|
1539 // GetMimeTypeL() |
|
1540 // ----------------------------------------------------------------------------- |
|
1541 // |
|
1542 void CGlxCacheManager::GetMimeTypeL(TFileName& aFileName, TDataType& aMimeType) |
|
1543 { |
|
1544 TRACER("CGlxCacheManager::GetMimeTypeL"); |
|
1545 RApaLsSession session; |
|
1546 User::LeaveIfError( session.Connect() ); |
|
1547 CleanupClosePushL( session ); |
|
1548 |
|
1549 if (iImageViewerInstance->IsPrivate()) |
|
1550 { |
|
1551 TDataRecognitionResult result; |
|
1552 TInt err = session.RecognizeData(iImageViewerInstance->ImageFileHandle(), result); |
|
1553 GLX_DEBUG2("CGlxCacheManager::GetMimeTypeL(FileHandle) err=%d", err); |
|
1554 if (err == KErrNone) |
|
1555 { |
|
1556 aMimeType = result.iDataType; |
|
1557 } |
|
1558 } |
|
1559 else |
|
1560 { |
|
1561 TUid uid; |
|
1562 TDataType dataType; |
|
1563 TInt err = session.AppForDocument(aFileName, uid, dataType); |
|
1564 GLX_DEBUG2("CGlxCacheManager::GetMimeTypeL(FileName) err=%d", err); |
|
1565 |
|
1566 if (err == KErrNone) |
|
1567 { |
|
1568 aMimeType = dataType; |
|
1569 } |
|
1570 } |
|
1571 CleanupStack::PopAndDestroy(&session); |
|
1572 } |
|
1573 |
|
1574 // ----------------------------------------------------------------------------- |
|
1575 // CreateImageViewerInstanceL |
|
1576 // ----------------------------------------------------------------------------- |
|
1577 // |
|
1578 void CGlxCacheManager::CreateImageViewerInstanceL() |
|
1579 { |
|
1580 TRACER("CGlxCacheManager::CreateImageViewerInstanceL"); |
|
1581 iImageViewerInstance = CGlxImageViewerManager::InstanceL(); |
|
1582 __ASSERT_ALWAYS(iImageViewerInstance, Panic(EGlxPanicNullPointer)); |
|
1583 } |
|
1584 |
|
1585 // ----------------------------------------------------------------------------- |
|
1586 // DeleteImageViewerInstance |
|
1587 // ----------------------------------------------------------------------------- |
|
1588 // |
|
1589 void CGlxCacheManager::DeleteImageViewerInstance() |
|
1590 { |
|
1591 TRACER("CGlxCacheManager::DeleteImageViewerInstance"); |
|
1592 if ( iImageViewerInstance ) |
|
1593 { |
|
1594 iImageViewerInstance->DeleteInstance(); |
|
1595 } |
|
1596 } |
|
1597 |
|
1598 //End of file |