60
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Utility that contains HUI related slideshow code
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
// INCLUDES
|
|
22 |
#include "shwthumbnailloader.h"
|
|
23 |
|
|
24 |
// DEPENDENCIES
|
|
25 |
#include <mpxattributespecs.h>
|
|
26 |
#include <mpxmediadrmdefs.h>
|
|
27 |
#include <glxlog.h>
|
|
28 |
#include <glxtracer.h>
|
|
29 |
|
|
30 |
#include <glxmedialistiterator.h>
|
|
31 |
#include <mglxmedialistobserver.h>
|
|
32 |
#include <mglxmedialist.h>
|
|
33 |
#include <glxthumbnailcontext.h>
|
|
34 |
#include <glxattributecontext.h>
|
|
35 |
#include <glxmediageneraldefs.h>
|
|
36 |
#include <glxattributeretriever.h>
|
|
37 |
|
|
38 |
#include "shwslideshowenginepanic.h"
|
|
39 |
#include "shwthumbnailcontext.h"
|
|
40 |
#include "shwcallback.h"
|
|
41 |
|
|
42 |
#include "shwconstants.h" // for context priorities
|
|
43 |
|
|
44 |
using namespace NShwSlideshow;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* CShwThumbnailLoaderImpl
|
|
48 |
* Implementation dependencies for the thumbnail loading
|
|
49 |
*/
|
|
50 |
NONSHARABLE_CLASS( CShwThumbnailLoader::CShwThumbnailLoaderImpl )
|
|
51 |
: public CBase,
|
|
52 |
public MGlxMediaListObserver
|
|
53 |
{
|
|
54 |
public:
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Constructor
|
|
58 |
* inlined as only ever called inside this cpp
|
|
59 |
* @param aMedialist the media list
|
|
60 |
*/
|
|
61 |
inline CShwThumbnailLoaderImpl(
|
|
62 |
MGlxMediaList& aMedialist,
|
|
63 |
MShwThumbnailLoadObserver& aErrorHandler );
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Destructor.
|
|
67 |
* inlined as only ever called inside this cpp
|
|
68 |
*/
|
|
69 |
inline ~CShwThumbnailLoaderImpl();
|
|
70 |
|
|
71 |
/**
|
|
72 |
* 2nd phase constructor
|
|
73 |
* inlined as only ever called inside this cpp
|
|
74 |
*/
|
|
75 |
inline void ConstructL();
|
|
76 |
|
|
77 |
/**
|
|
78 |
* @ref CShwThumbnailLoader::LoadAndNotifyL
|
|
79 |
* inlined as only ever called inside this cpp
|
|
80 |
*/
|
|
81 |
inline void LoadAndNotifyL( TInt aIndex, TSize aSize );
|
|
82 |
|
|
83 |
/**
|
|
84 |
* @ref CShwThumbnailLoader::Unload
|
|
85 |
* inlined as only ever called inside this cpp
|
|
86 |
*/
|
|
87 |
inline void Unload( TInt aIndex );
|
|
88 |
|
|
89 |
/**
|
|
90 |
* @ref CShwThumbnailLoader::ImageSizeL
|
|
91 |
* inlined as only ever called inside this cpp
|
|
92 |
*/
|
|
93 |
inline TSize ImageSizeL( TInt aIndex );
|
|
94 |
|
|
95 |
public: // from MGlxMediaListObserver
|
|
96 |
|
|
97 |
/// @ref MGlxMediaListObserver::HandleItemAddedL
|
|
98 |
void HandleItemAddedL(
|
|
99 |
TInt aStartIndex, TInt aEndIndex, MGlxMediaList* aList );
|
|
100 |
/// @ref MGlxMediaListObserver::HandleMediaL
|
|
101 |
void HandleMediaL(
|
|
102 |
TInt aListIndex, MGlxMediaList* aList );
|
|
103 |
/// @ref MGlxMediaListObserver::HandleItemRemovedL
|
|
104 |
void HandleItemRemovedL(
|
|
105 |
TInt aStartIndex, TInt aEndIndex, MGlxMediaList* aList );
|
|
106 |
/// @ref MGlxMediaListObserver::HandleItemModifiedL
|
|
107 |
void HandleItemModifiedL(
|
|
108 |
const RArray<TInt>& aItemIndexes, MGlxMediaList* aList );
|
|
109 |
/// @ref MGlxMediaListObserver::HandleAttributesAvailableL
|
|
110 |
void HandleAttributesAvailableL(
|
|
111 |
TInt aItemIndex,
|
|
112 |
const RArray<TMPXAttribute>& aAttributes,
|
|
113 |
MGlxMediaList* aList );
|
|
114 |
/// @ref MGlxMediaListObserver::HandleFocusChangedL
|
|
115 |
void HandleFocusChangedL(
|
|
116 |
NGlxListDefs::TFocusChangeType aType,
|
|
117 |
TInt aNewIndex,
|
|
118 |
TInt aOldIndex,
|
|
119 |
MGlxMediaList* aList );
|
|
120 |
/// @ref MGlxMediaListObserver::HandleItemSelectedL
|
|
121 |
void HandleItemSelectedL(
|
|
122 |
TInt aIndex, TBool aSelected, MGlxMediaList* aList );
|
|
123 |
/// @ref MGlxMediaListObserver::HandleMessageL
|
|
124 |
void HandleMessageL(
|
|
125 |
const CMPXMessage& aMessage, MGlxMediaList* aList );
|
|
126 |
/// @ref MGlxMediaListObserver::HandleError
|
|
127 |
void HandleError( TInt aError );
|
|
128 |
|
|
129 |
private: // Implementation
|
|
130 |
|
|
131 |
// implementation of the error handler
|
|
132 |
inline void DoHandleErrorL();
|
|
133 |
// Helper functions to find an element in the array given an index
|
|
134 |
// used in three places, load, unload and handleattributes available
|
|
135 |
// @param the index of the element to find
|
|
136 |
// @return the index of the element in the array, KErrNotFound otherwise
|
|
137 |
inline TInt Find( TInt aIndex );
|
|
138 |
// @return the context if found, NULL otherwise
|
|
139 |
inline CShwThumbnailContext* FindContext( TInt aIndex );
|
|
140 |
// Helper function to create the size context
|
|
141 |
inline void AddSizeContextL();
|
|
142 |
/// Helper function to notify client of successfull or failed thumbnail load
|
|
143 |
inline void NofifyClientIfInterestedL( TInt aIndex, TBool aSuccess );
|
|
144 |
// Helper function to remove high quality context from given index
|
|
145 |
inline void RemoveHighQualityContext( TInt aIndex );
|
|
146 |
|
|
147 |
public: // TCallBack API
|
|
148 |
|
|
149 |
// Helper function to notify thumbnail completion asynchronously
|
|
150 |
inline TInt CompletedNotifyL();
|
|
151 |
// Helper function to notify thumbnail failure asynchronously
|
|
152 |
inline TInt ErrorNotifyL();
|
|
153 |
// Helper function to handle the error
|
|
154 |
inline TInt AsyncErrorHandleL();
|
|
155 |
|
|
156 |
private: // Implementation & Data
|
|
157 |
|
|
158 |
/// Ref: the media list
|
|
159 |
MGlxMediaList& iMedialist;
|
|
160 |
/// Ref: the error handler
|
|
161 |
MShwThumbnailLoadObserver& iThumbnailObserver;
|
|
162 |
/// Own: the array for the thumbnail notifications
|
|
163 |
RArray< TInt > iNotificationIndexes;
|
|
164 |
/// Own: the array for already completed indexes
|
|
165 |
RArray< TInt > iCompletedIndexes;
|
|
166 |
/// Own: the array for already faulty indexes
|
|
167 |
RArray< TInt > iErrorIndexes;
|
|
168 |
/// Own: the array of high quality contexts
|
|
169 |
RPointerArray< CShwThumbnailContext > iHighQualityContexts;
|
|
170 |
/// Own: the size context
|
|
171 |
CGlxDefaultAttributeContext* iSizeContext;
|
|
172 |
/// Own: async callback needed in case image is already loaded
|
|
173 |
CAsyncCallBack* iCompletedCallBack;
|
|
174 |
/// Own: async callback needed in case image had already an error
|
|
175 |
CAsyncCallBack* iErrorCallBack;
|
|
176 |
/// Own: async callback for showing the out of memory system dialog
|
|
177 |
CAsyncCallBack* iErrorHandlerCallBack;
|
|
178 |
/// Own: the error code
|
|
179 |
TInt iError;
|
|
180 |
|
|
181 |
};
|
|
182 |
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
// C++ Constructor. Save a few bits of rom with inlining
|
|
185 |
// -----------------------------------------------------------------------------
|
|
186 |
inline CShwThumbnailLoader::CShwThumbnailLoader()
|
|
187 |
{
|
|
188 |
}
|
|
189 |
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
// NewL. Static construction
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
CShwThumbnailLoader* CShwThumbnailLoader::NewL(
|
|
194 |
MGlxMediaList& aMedialist, MShwThumbnailLoadObserver& aErrorHandler )
|
|
195 |
{
|
|
196 |
TRACER("CShwThumbnailLoader::NewLs");
|
|
197 |
CShwThumbnailLoader* self = new( ELeave ) CShwThumbnailLoader;
|
|
198 |
CleanupStack::PushL( self );
|
|
199 |
|
|
200 |
// 2nd phase >>
|
|
201 |
// create implementation
|
|
202 |
self->iImpl =
|
|
203 |
new( ELeave ) CShwThumbnailLoaderImpl( aMedialist, aErrorHandler );
|
|
204 |
// call 2nd phase
|
|
205 |
self->iImpl->ConstructL();
|
|
206 |
// << 2nd phase
|
|
207 |
// pop the stack
|
|
208 |
CleanupStack::Pop( self );
|
|
209 |
return self;
|
|
210 |
}
|
|
211 |
|
|
212 |
// -----------------------------------------------------------------------------
|
|
213 |
// Destructor
|
|
214 |
// -----------------------------------------------------------------------------
|
|
215 |
CShwThumbnailLoader::~CShwThumbnailLoader()
|
|
216 |
{
|
|
217 |
TRACER("CShwThumbnailLoader::~CShwThumbnailLoader");
|
|
218 |
delete iImpl;
|
|
219 |
}
|
|
220 |
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
// LoadThumbnailAndNotifyL.
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
void CShwThumbnailLoader::LoadAndNotifyL( TInt aIndex, TSize aSize )
|
|
225 |
{
|
|
226 |
TRACER("CShwThumbnailLoader::LoadAndNotifyL");
|
|
227 |
// forward
|
|
228 |
iImpl->LoadAndNotifyL( aIndex, aSize );
|
|
229 |
}
|
|
230 |
|
|
231 |
// -----------------------------------------------------------------------------
|
|
232 |
// Unload.
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
void CShwThumbnailLoader::Unload( TInt aIndex )
|
|
235 |
{
|
|
236 |
TRACER("CShwThumbnailLoader::Unload");
|
|
237 |
// forward
|
|
238 |
iImpl->Unload( aIndex );
|
|
239 |
}
|
|
240 |
|
|
241 |
// -----------------------------------------------------------------------------
|
|
242 |
// CShwThumbnailLoaderImpl::ImageSizeL.
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
TSize CShwThumbnailLoader::ImageSizeL( TInt aIndex )
|
|
245 |
{
|
|
246 |
TRACER("CShwThumbnailLoader::ImageSizeL");
|
|
247 |
// forward
|
|
248 |
return iImpl->ImageSizeL( aIndex );
|
|
249 |
}
|
|
250 |
|
|
251 |
// -----------------------------------------------------------------------------
|
|
252 |
// CShwThumbnailLoaderImpl::C++ Constructor. Save a few bits of rom with inlining
|
|
253 |
// -----------------------------------------------------------------------------
|
|
254 |
inline CShwThumbnailLoader::CShwThumbnailLoaderImpl::CShwThumbnailLoaderImpl(
|
|
255 |
MGlxMediaList& aMedialist, MShwThumbnailLoadObserver& aErrorHandler )
|
|
256 |
: iMedialist( aMedialist ),
|
|
257 |
iThumbnailObserver( aErrorHandler )
|
|
258 |
{
|
|
259 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::CShwThumbnailLoaderImpl()");
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
// CShwThumbnailLoaderImpl::Destructor.
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
inline CShwThumbnailLoader::CShwThumbnailLoaderImpl::~CShwThumbnailLoaderImpl()
|
|
266 |
{
|
|
267 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::~CShwThumbnailLoaderImpl()");
|
|
268 |
// delete asynch callbacks, delete also cancels them
|
|
269 |
delete iCompletedCallBack;
|
|
270 |
delete iErrorCallBack;
|
|
271 |
delete iErrorHandlerCallBack;
|
|
272 |
|
|
273 |
// size context, remove NULL does nothing
|
|
274 |
iMedialist.RemoveContext( iSizeContext );
|
|
275 |
delete iSizeContext;
|
|
276 |
|
|
277 |
// Remove all contexts from the media list
|
|
278 |
TInt count = iHighQualityContexts.Count();
|
|
279 |
while ( count-- > 0 )
|
|
280 |
{
|
|
281 |
// get the fetch context so that we can remove it from the media list
|
|
282 |
MGlxFetchContext* context = iHighQualityContexts[ count ]->Context();
|
|
283 |
// high quality context, remove NULL does nothing
|
|
284 |
iMedialist.RemoveContext( context );
|
|
285 |
};
|
|
286 |
// delete the contexts array, this deletes the CShwThumbnailContexts
|
|
287 |
iHighQualityContexts.ResetAndDestroy();
|
|
288 |
|
|
289 |
// remove us from media list observers
|
|
290 |
iMedialist.RemoveMediaListObserver( this );
|
|
291 |
|
|
292 |
// close notification indexes array
|
|
293 |
iNotificationIndexes.Close();
|
|
294 |
// close also the already completed indexes array
|
|
295 |
iCompletedIndexes.Close();
|
|
296 |
// close also the errornous indexes array
|
|
297 |
iErrorIndexes.Close();
|
|
298 |
}
|
|
299 |
|
|
300 |
// -----------------------------------------------------------------------------
|
|
301 |
// CShwThumbnailLoaderImpl::ConstructL
|
|
302 |
// -----------------------------------------------------------------------------
|
|
303 |
inline void CShwThumbnailLoader::CShwThumbnailLoaderImpl::ConstructL()
|
|
304 |
{
|
|
305 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::ConstructL");
|
|
306 |
// retrieve the size of images with own context
|
|
307 |
AddSizeContextL();
|
|
308 |
|
|
309 |
// add us as media list observer
|
|
310 |
iMedialist.AddMediaListObserverL( this );
|
|
311 |
|
|
312 |
// create async callback object to give
|
|
313 |
// callbacks once scheduler runs, give this high priority so that it
|
|
314 |
// is faster than the timers we have
|
|
315 |
iCompletedCallBack = new( ELeave ) CAsyncCallBack( CActive::EPriorityHigh );
|
|
316 |
// set the callback
|
|
317 |
iCompletedCallBack->Set(TShwCallBack<CShwThumbnailLoaderImpl,
|
|
318 |
&CShwThumbnailLoaderImpl::CompletedNotifyL> (this));
|
|
319 |
|
|
320 |
// create async callback to give error callbacks once scheduler runs
|
|
321 |
iErrorCallBack = new( ELeave ) CAsyncCallBack( CActive::EPriorityHigh );
|
|
322 |
// set the callback
|
|
323 |
iErrorCallBack->Set(TShwCallBack<CShwThumbnailLoaderImpl,
|
|
324 |
&CShwThumbnailLoaderImpl::ErrorNotifyL> (this));
|
|
325 |
|
|
326 |
// create async callback to give callback once we run onto errors
|
|
327 |
iErrorHandlerCallBack = new( ELeave ) CAsyncCallBack( CActive::EPriorityHigh );
|
|
328 |
// set the callback
|
|
329 |
iErrorHandlerCallBack->Set(TShwCallBack<CShwThumbnailLoaderImpl,
|
|
330 |
&CShwThumbnailLoaderImpl::AsyncErrorHandleL> (this));
|
|
331 |
}
|
|
332 |
|
|
333 |
// -----------------------------------------------------------------------------
|
|
334 |
// CShwThumbnailLoaderImpl::ImageSizeL.
|
|
335 |
// -----------------------------------------------------------------------------
|
|
336 |
inline TSize CShwThumbnailLoader::CShwThumbnailLoaderImpl::ImageSizeL(
|
|
337 |
TInt aIndex )
|
|
338 |
{
|
|
339 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::ImageSizeL");
|
|
340 |
GLX_LOG_INFO1( "CShwThumbnailLoader::ImageSizeL for index %d", aIndex );
|
|
341 |
|
|
342 |
// default to KErrNotFound
|
|
343 |
TSize size( KErrNotFound, KErrNotFound );
|
|
344 |
|
|
345 |
// get the media item
|
|
346 |
TGlxMedia item = iMedialist.Item( aIndex );
|
|
347 |
// get its dimensions, if they are not available, size is not modified
|
|
348 |
// if size is not available, GetDimensions returns EFalse
|
|
349 |
if( !item.GetDimensions( size ) )
|
|
350 |
{
|
|
351 |
// size was not available so try to fetch it with attribute retriever
|
|
352 |
(void)GlxAttributeRetriever::RetrieveL(
|
|
353 |
*iSizeContext, iMedialist,
|
|
354 |
EFalse /*aShowDialog*/ );
|
|
355 |
// get the media item again since its just a copy and the old one
|
|
356 |
// might not have had the CGlxMedia* set
|
|
357 |
item = iMedialist.Item( aIndex );
|
|
358 |
// cast to (void) tells the compiler we ignore
|
|
359 |
// the fetcher error as there is nothing to do if the fetch fails
|
|
360 |
// in that case the size will be (KErrNotFound,KErrNotFound)
|
|
361 |
// try getting the dimensions again
|
|
362 |
(void)item.GetDimensions( size );
|
|
363 |
}
|
|
364 |
|
|
365 |
GLX_LOG_INFO2(
|
|
366 |
"CShwThumbnailLoader::ImageSizeL (%d,%d)", size.iWidth, size.iHeight );
|
|
367 |
|
|
368 |
return size;
|
|
369 |
}
|
|
370 |
|
|
371 |
// -----------------------------------------------------------------------------
|
|
372 |
// CShwThumbnailLoaderImpl::LoadAndNotifyL.
|
|
373 |
// -----------------------------------------------------------------------------
|
|
374 |
inline void CShwThumbnailLoader::CShwThumbnailLoaderImpl::LoadAndNotifyL(
|
|
375 |
TInt aIndex, TSize aSize )
|
|
376 |
{
|
|
377 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::LoadAndNotifyL");
|
|
378 |
GLX_LOG_INFO1( "CShwThumbnailLoader::LoadAndNotifyL %d", aIndex );
|
|
379 |
|
|
380 |
// check whether a context already exists for this index
|
|
381 |
CShwThumbnailContext* context = FindContext( aIndex );
|
|
382 |
if( !context )
|
|
383 |
{
|
|
384 |
// create new context for the index with the given size
|
|
385 |
context = CShwThumbnailContext::NewLC( aIndex, aSize, iMedialist );
|
|
386 |
iHighQualityContexts.AppendL( context );
|
|
387 |
CleanupStack::Pop( context );
|
|
388 |
// add the context to the medialist with priority
|
|
389 |
iMedialist.AddContextL(
|
|
390 |
context->Context(), KHighQualityContextPriority );
|
|
391 |
}
|
|
392 |
|
|
393 |
// add the index to notifications array so that we know to give
|
|
394 |
// either success or error notification once for the request
|
|
395 |
// Note that we can have multiple requests for same index
|
|
396 |
iNotificationIndexes.InsertInOrderAllowRepeatsL( aIndex );
|
|
397 |
|
|
398 |
// need to check if the thumbnail is already loaded
|
|
399 |
// when request count is zero (KErrNone) the thumbnail is fully loaded
|
|
400 |
TInt requestCount = context->RequestCountL( &iMedialist );
|
|
401 |
if( requestCount == KErrNone )
|
|
402 |
{
|
|
403 |
// thumbnail is already there
|
|
404 |
// we cant give the callback right away as the client is expecting
|
|
405 |
// this method to be always asynchronous
|
|
406 |
GLX_LOG_INFO1(
|
|
407 |
"CShwThumbnailLoader::Thumbnail already loaded %d", aIndex );
|
|
408 |
// insert index to completed array
|
|
409 |
// Note that we can have multiple requests for same index
|
|
410 |
iCompletedIndexes.InsertInOrderAllowRepeatsL( aIndex );
|
|
411 |
// cancel the old callback
|
|
412 |
iCompletedCallBack->Cancel();
|
|
413 |
// make the callback
|
|
414 |
iCompletedCallBack->CallBack();
|
|
415 |
}
|
|
416 |
else if ( requestCount < KErrNone )
|
|
417 |
{
|
|
418 |
// thumbnail had already and error
|
|
419 |
GLX_LOG_INFO2(
|
|
420 |
"CShwThumbnailLoader::Thumbnail error %d at index, %d",
|
|
421 |
requestCount, aIndex );
|
|
422 |
// we cant give the callback right away as the client is expecting
|
|
423 |
// this method to be always asynchronous
|
|
424 |
// Note that we can have multiple requests for same index
|
|
425 |
iErrorIndexes.InsertInOrderAllowRepeatsL( aIndex );
|
|
426 |
// cancel the old callback
|
|
427 |
iErrorCallBack->Cancel();
|
|
428 |
// make the callback
|
|
429 |
iErrorCallBack->CallBack();
|
|
430 |
}
|
|
431 |
}
|
|
432 |
|
|
433 |
// -----------------------------------------------------------------------------
|
|
434 |
// CShwThumbnailLoaderImpl::Unload
|
|
435 |
// -----------------------------------------------------------------------------
|
|
436 |
inline void CShwThumbnailLoader::CShwThumbnailLoaderImpl::Unload( TInt aIndex )
|
|
437 |
{
|
|
438 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::Unload");
|
|
439 |
GLX_LOG_INFO1( "CShwThumbnailLoader::Unload %d", aIndex );
|
|
440 |
|
|
441 |
// client is no longer interested on this indes so remove it from the
|
|
442 |
// notifications
|
|
443 |
TInt index;
|
|
444 |
while( ( index = iNotificationIndexes.Find( aIndex ) ) != KErrNotFound )
|
|
445 |
{
|
|
446 |
// remove the index from array
|
|
447 |
iNotificationIndexes.Remove( index );
|
|
448 |
}
|
|
449 |
|
|
450 |
// remove context for this index
|
|
451 |
RemoveHighQualityContext( aIndex );
|
|
452 |
}
|
|
453 |
|
|
454 |
// -----------------------------------------------------------------------------
|
|
455 |
// CShwThumbnailLoaderImpl::HandleItemAddedL.
|
|
456 |
// -----------------------------------------------------------------------------
|
|
457 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleItemAddedL(
|
|
458 |
TInt /*aStartIndex*/, TInt /*aEndIndex*/, MGlxMediaList* /*aList*/ )
|
|
459 |
{
|
|
460 |
}
|
|
461 |
|
|
462 |
// -----------------------------------------------------------------------------
|
|
463 |
// CShwThumbnailLoaderImpl::HandleMediaL.
|
|
464 |
// -----------------------------------------------------------------------------
|
|
465 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleMediaL(
|
|
466 |
TInt /*aListIndex*/, MGlxMediaList* /*aList*/ )
|
|
467 |
{
|
|
468 |
}
|
|
469 |
// -----------------------------------------------------------------------------
|
|
470 |
// CShwThumbnailLoaderImpl::HandleItemRemovedL.
|
|
471 |
// -----------------------------------------------------------------------------
|
|
472 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleItemRemovedL(
|
|
473 |
TInt /*aStartIndex*/, TInt /*aEndIndex*/, MGlxMediaList* /*aList*/ )
|
|
474 |
{
|
|
475 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleItemRemovedL");
|
|
476 |
// check if we still got some items to show
|
|
477 |
if( iMedialist.Count() < 1 )
|
|
478 |
{
|
|
479 |
// the media list is empty so call our error handler
|
|
480 |
iThumbnailObserver.HandleMediaListEmpty();
|
|
481 |
}
|
|
482 |
}
|
|
483 |
|
|
484 |
// -----------------------------------------------------------------------------
|
|
485 |
// CShwThumbnailLoaderImpl::HandleItemModifiedL.
|
|
486 |
// -----------------------------------------------------------------------------
|
|
487 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleItemModifiedL(
|
|
488 |
const RArray<TInt>& /*aItemIndexes*/, MGlxMediaList* /*aList*/ )
|
|
489 |
{
|
|
490 |
}
|
|
491 |
|
|
492 |
// -----------------------------------------------------------------------------
|
|
493 |
// CShwThumbnailLoaderImpl::HandleAttributesAvailableL.
|
|
494 |
// -----------------------------------------------------------------------------
|
|
495 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleAttributesAvailableL(
|
|
496 |
TInt aItemIndex, const RArray<TMPXAttribute>& aAttributes/**/,
|
|
497 |
MGlxMediaList* /*aList*/ )
|
|
498 |
{
|
|
499 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleAttributesAvailableL");
|
|
500 |
//done to verify context availability
|
|
501 |
TInt attributeCount = aAttributes.Count();
|
|
502 |
for(TInt i = 0; i < attributeCount; i++ )
|
|
503 |
{
|
|
504 |
TMPXAttribute attr = aAttributes[i];
|
|
505 |
}
|
|
506 |
|
|
507 |
GLX_LOG_INFO1(
|
|
508 |
"CShwThumbnailLoader::HandleAttributesAvailableL %d", aItemIndex );
|
|
509 |
// check if the thumbnail was fully loaded, first find the related context
|
|
510 |
CShwThumbnailContext* context = FindContext( aItemIndex );
|
|
511 |
if( context )
|
|
512 |
{
|
|
513 |
// Check if there was an error
|
|
514 |
TInt requestCount = context->RequestCountL( &iMedialist );
|
|
515 |
if ( requestCount == KErrNone )
|
|
516 |
{
|
|
517 |
// no error, notify client
|
|
518 |
GLX_LOG_INFO1(
|
|
519 |
"CShwThumbnailLoader::Thumbnail loaded %d", aItemIndex );
|
|
520 |
// notidy client of success if it is interested on this index
|
|
521 |
NofifyClientIfInterestedL( aItemIndex, ETrue );
|
|
522 |
}
|
|
523 |
else if ( requestCount < 0 )
|
|
524 |
{
|
|
525 |
GLX_LOG_INFO1(
|
|
526 |
"CShwThumbnailLoader::Thumbnail load failed %d", aItemIndex );
|
|
527 |
// remove the context since there is an error in loading it
|
|
528 |
// need to remove first as error handler may add new contexts
|
|
529 |
RemoveHighQualityContext( aItemIndex );
|
|
530 |
// notidy client of error if it is interested on this index
|
|
531 |
NofifyClientIfInterestedL( aItemIndex, EFalse );
|
|
532 |
}
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
// -----------------------------------------------------------------------------
|
|
537 |
// CShwThumbnailLoaderImpl::HandleFocusChangedL.
|
|
538 |
// -----------------------------------------------------------------------------
|
|
539 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleFocusChangedL(
|
|
540 |
NGlxListDefs::TFocusChangeType /*aType*/, TInt /*aNewIndex*/,
|
|
541 |
TInt /*aOldIndex*/, MGlxMediaList* /*aList*/ )
|
|
542 |
{
|
|
543 |
}
|
|
544 |
|
|
545 |
// -----------------------------------------------------------------------------
|
|
546 |
// CShwThumbnailLoaderImpl::HandleItemSelectedL.
|
|
547 |
// -----------------------------------------------------------------------------
|
|
548 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleItemSelectedL(
|
|
549 |
TInt /*aIndex*/, TBool /*aSelected*/, MGlxMediaList* /*aList*/ )
|
|
550 |
{
|
|
551 |
}
|
|
552 |
|
|
553 |
// -----------------------------------------------------------------------------
|
|
554 |
// CShwThumbnailLoaderImpl::HandleMessageL.
|
|
555 |
// -----------------------------------------------------------------------------
|
|
556 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleMessageL(
|
|
557 |
const CMPXMessage& /*aMessage*/, MGlxMediaList* /*aList*/ )
|
|
558 |
{
|
|
559 |
}
|
|
560 |
|
|
561 |
// -----------------------------------------------------------------------------
|
|
562 |
// CShwThumbnailLoaderImpl::HandleError.
|
|
563 |
// -----------------------------------------------------------------------------
|
|
564 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleError(
|
|
565 |
TInt aError )
|
|
566 |
{
|
|
567 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleError");
|
|
568 |
GLX_LOG_INFO1( "CShwThumbnailLoader::CShwThumbnailLoaderImpl::HandleError %d", aError );
|
|
569 |
// need to remember the error
|
|
570 |
iError = aError;
|
|
571 |
// make asynch callback since we cant leave, this is the perfect way to
|
|
572 |
// handle error as the real processing will be in RunL so it can leave and
|
|
573 |
// can show a system error note. It is safe to call CallBack even is previous
|
|
574 |
// one did not complete
|
|
575 |
iErrorHandlerCallBack->CallBack();
|
|
576 |
}
|
|
577 |
|
|
578 |
// -----------------------------------------------------------------------------
|
|
579 |
// CShwThumbnailLoaderImpl::DoHandleErrorL.
|
|
580 |
// -----------------------------------------------------------------------------
|
|
581 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::DoHandleErrorL()
|
|
582 |
{
|
|
583 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::DoHandleErrorL");
|
|
584 |
GLX_LOG_INFO1( "CShwThumbnailLoader::DoHandleError %d", iError );
|
|
585 |
// variable to tell if the error was in some of our fetch contexts
|
|
586 |
TBool errorInHighQualityContexts = EFalse;
|
|
587 |
// check if it was any of our high quality fetch contexts
|
|
588 |
TInt count = iHighQualityContexts.Count();
|
|
589 |
// ask all high quality contexts
|
|
590 |
while ( count-- > 0 )
|
|
591 |
{
|
|
592 |
CShwThumbnailContext* context = iHighQualityContexts[ count ];
|
|
593 |
// need to TRAP in case RequestCountL leaves, since if it does
|
|
594 |
// we need to tell our observer that there is a problem
|
|
595 |
// requestCount needs to be volatile so that it does get
|
|
596 |
// optimized to a register and get its initial value returned in leave
|
|
597 |
volatile TInt requestCount = KErrNone;
|
|
598 |
TRAPD( error, requestCount = context->RequestCountL( &iMedialist ) );
|
|
599 |
// ask if this context had an error or RequestCountL did leave
|
|
600 |
if( ( requestCount < KErrNone )||
|
|
601 |
( error != KErrNone ) )
|
|
602 |
{
|
|
603 |
// take the index as cant use context once it is removed
|
|
604 |
TInt index = context->Index();
|
|
605 |
// remove the context since there is an error in loading it
|
|
606 |
// need to remove first as error handler may add new contexts
|
|
607 |
RemoveHighQualityContext( index );
|
|
608 |
// notidy client of error if it is interested on this index
|
|
609 |
NofifyClientIfInterestedL( index, EFalse );
|
|
610 |
// set the flag to tell that there was an error in context
|
|
611 |
errorInHighQualityContexts = ETrue;
|
|
612 |
}
|
|
613 |
}
|
|
614 |
// check if it was out of memory and in our contexts
|
|
615 |
if( KErrNoMemory == iError && errorInHighQualityContexts )
|
|
616 |
{
|
|
617 |
// just leave with KErrNoMemory, system will then show the dialog
|
|
618 |
User::Leave( KErrNoMemory );
|
|
619 |
}
|
|
620 |
}
|
|
621 |
|
|
622 |
// -----------------------------------------------------------------------------
|
|
623 |
// CShwThumbnailLoaderImpl::Find.
|
|
624 |
// -----------------------------------------------------------------------------
|
|
625 |
inline TInt CShwThumbnailLoader::CShwThumbnailLoaderImpl::Find( TInt aIndex )
|
|
626 |
{
|
|
627 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::Find");
|
|
628 |
GLX_LOG_INFO1( "CShwThumbnailLoader::Find %d", aIndex );
|
|
629 |
// take the count
|
|
630 |
TInt index = iHighQualityContexts.Count();
|
|
631 |
// browse through all indexes ( count-1 -> 0 )
|
|
632 |
while ( index-- > 0 )
|
|
633 |
{
|
|
634 |
// Check if the index belongs to the array
|
|
635 |
CShwThumbnailContext* context = iHighQualityContexts[ index ];
|
|
636 |
if ( context->Index() == aIndex )
|
|
637 |
{
|
|
638 |
break;
|
|
639 |
}
|
|
640 |
}
|
|
641 |
// if match was not found, index is -1 which is KErrNotFound
|
|
642 |
return index;
|
|
643 |
}
|
|
644 |
|
|
645 |
// -----------------------------------------------------------------------------
|
|
646 |
// CShwThumbnailLoaderImpl::FindContext.
|
|
647 |
// -----------------------------------------------------------------------------
|
|
648 |
inline CShwThumbnailContext*
|
|
649 |
CShwThumbnailLoader::CShwThumbnailLoaderImpl::FindContext( TInt aIndex )
|
|
650 |
{
|
|
651 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::FindContext");
|
|
652 |
GLX_LOG_INFO1( "CShwThumbnailLoader::FindContext %d", aIndex );
|
|
653 |
// by default return NULL
|
|
654 |
CShwThumbnailContext* context = NULL;
|
|
655 |
// reuse the Find
|
|
656 |
TInt index = Find( aIndex );
|
|
657 |
// if it was found
|
|
658 |
if( index != KErrNotFound )
|
|
659 |
{
|
|
660 |
// set the context
|
|
661 |
context = iHighQualityContexts[ index ];
|
|
662 |
}
|
|
663 |
// and return it
|
|
664 |
return context;
|
|
665 |
}
|
|
666 |
|
|
667 |
// -----------------------------------------------------------------------------
|
|
668 |
// CShwThumbnailLoaderImpl::AddSizeContextL
|
|
669 |
// -----------------------------------------------------------------------------
|
|
670 |
inline void CShwThumbnailLoader::CShwThumbnailLoaderImpl::AddSizeContextL()
|
|
671 |
{
|
|
672 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::AddSizeContextL");
|
|
673 |
// Create the fetch context to retrieve the attribute
|
|
674 |
iSizeContext = CGlxDefaultAttributeContext::NewL();
|
|
675 |
// Set the range offsets relative to the focus item
|
|
676 |
// e.g. 0, 1, [2], 3, 4. Focus @ 2 => frontOffset = 2, rearOffset = 2
|
|
677 |
iSizeContext->SetRangeOffsets( KSizeContextOffset, KSizeContextOffset );
|
|
678 |
|
|
679 |
// Add the size attribute to the context
|
|
680 |
iSizeContext->AddAttributeL( KGlxMediaGeneralDimensions );
|
|
681 |
|
|
682 |
// Add Drm attribute to the context,
|
|
683 |
// By default Drm attrib would be ETrue if not fetched already and
|
|
684 |
// shall result in reduced thumbnail size request
|
|
685 |
iSizeContext->AddAttributeL(KMPXMediaDrmProtected);
|
|
686 |
|
|
687 |
// add the context with its priority
|
|
688 |
iMedialist.AddContextL( iSizeContext, KSizeContextPriority );
|
|
689 |
}
|
|
690 |
|
|
691 |
// -----------------------------------------------------------------------------
|
|
692 |
// CShwThumbnailLoaderImpl::NofifyClientIfInterestedL.
|
|
693 |
// -----------------------------------------------------------------------------
|
|
694 |
void CShwThumbnailLoader::CShwThumbnailLoaderImpl::NofifyClientIfInterestedL(
|
|
695 |
TInt aIndex, TBool aSuccess )
|
|
696 |
{
|
|
697 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::NofifyClientIfInterestedL");
|
|
698 |
GLX_LOG_INFO1( "CShwThumbnailLoaderImpl::NofifyClientIfInterestedL %d", aIndex );
|
|
699 |
// go through all the notification indexes
|
|
700 |
TInt arrayIndex = iNotificationIndexes.Find( aIndex );
|
|
701 |
if( KErrNotFound != arrayIndex )
|
|
702 |
{
|
|
703 |
// need to remove the index first as handle may insert new ones
|
|
704 |
// remove the index from array so we dont call twice
|
|
705 |
iNotificationIndexes.Remove( arrayIndex );
|
|
706 |
if( aSuccess )
|
|
707 |
{
|
|
708 |
// let the client know that the thumbnail is there
|
|
709 |
iThumbnailObserver.HandleThumbnailLoadedL( aIndex );
|
|
710 |
}
|
|
711 |
else
|
|
712 |
{
|
|
713 |
// let the client know that there was an error
|
|
714 |
iThumbnailObserver.HandleThumbnailLoadFailureL( aIndex );
|
|
715 |
}
|
|
716 |
}
|
|
717 |
}
|
|
718 |
|
|
719 |
// -----------------------------------------------------------------------------
|
|
720 |
// CShwThumbnailLoaderImpl::RemoveHighQualityContext
|
|
721 |
// -----------------------------------------------------------------------------
|
|
722 |
inline void CShwThumbnailLoader::CShwThumbnailLoaderImpl::
|
|
723 |
RemoveHighQualityContext( TInt aIndex )
|
|
724 |
{
|
|
725 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::RemoveHighQualityContext");
|
|
726 |
GLX_LOG_INFO1( "CShwThumbnailLoaderImpl::RemoveHighQualityContext %d", aIndex );
|
|
727 |
// check if there is a context for this index
|
|
728 |
TInt arrayIndex = Find( aIndex );
|
|
729 |
if( KErrNotFound != arrayIndex )
|
|
730 |
{
|
|
731 |
// get the context
|
|
732 |
CShwThumbnailContext* context = iHighQualityContexts[ arrayIndex ];
|
|
733 |
// remove the context from the media list
|
|
734 |
iMedialist.RemoveContext( context->Context() );
|
|
735 |
// and remove the context from the array
|
|
736 |
iHighQualityContexts.Remove( arrayIndex );
|
|
737 |
// finally delete the context
|
|
738 |
delete context;
|
|
739 |
}
|
|
740 |
}
|
|
741 |
|
|
742 |
// -----------------------------------------------------------------------------
|
|
743 |
// CShwThumbnailLoaderImpl::CompletedNotifyL
|
|
744 |
// -----------------------------------------------------------------------------
|
|
745 |
inline TInt CShwThumbnailLoader::CShwThumbnailLoaderImpl::CompletedNotifyL()
|
|
746 |
{
|
|
747 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::CompletedNotifyL");
|
|
748 |
// then we need to also remove all notifications for the given index
|
|
749 |
TInt count = iCompletedIndexes.Count();
|
|
750 |
while( count-- > 0 )
|
|
751 |
{
|
|
752 |
// take the index
|
|
753 |
TInt index = iCompletedIndexes[ count ];
|
|
754 |
// remove the index from array before calling observer as observer
|
|
755 |
// may add new indexes to the array
|
|
756 |
iCompletedIndexes.Remove( count );
|
|
757 |
// notidy client of success if it is interested on this index
|
|
758 |
NofifyClientIfInterestedL( index, ETrue );
|
|
759 |
}
|
|
760 |
// need to return value to please TCallBack API
|
|
761 |
return KErrNone;
|
|
762 |
}
|
|
763 |
|
|
764 |
// -----------------------------------------------------------------------------
|
|
765 |
// CShwThumbnailLoaderImpl::ErrorNotifyL
|
|
766 |
// -----------------------------------------------------------------------------
|
|
767 |
inline TInt CShwThumbnailLoader::CShwThumbnailLoaderImpl::ErrorNotifyL()
|
|
768 |
{
|
|
769 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::ErrorNotifyL");
|
|
770 |
// then we need to also remove all notifications for the given index
|
|
771 |
TInt count = iErrorIndexes.Count();
|
|
772 |
while( count-- > 0 )
|
|
773 |
{
|
|
774 |
// take the index
|
|
775 |
TInt index = iErrorIndexes[ count ];
|
|
776 |
// remove the index from array before calling observer as observer
|
|
777 |
// may add new indexes to the array
|
|
778 |
iErrorIndexes.Remove( count );
|
|
779 |
// remove the context since there is an error in loading it
|
|
780 |
// need to remove first as error handler may add new contexts
|
|
781 |
RemoveHighQualityContext( index );
|
|
782 |
// notidy client of error if it is interested on this index
|
|
783 |
NofifyClientIfInterestedL( index, EFalse );
|
|
784 |
}
|
|
785 |
// need to return value to please TCallBack API
|
|
786 |
return KErrNone;
|
|
787 |
}
|
|
788 |
|
|
789 |
// -----------------------------------------------------------------------------
|
|
790 |
// CShwThumbnailLoaderImpl::AsyncErrorHandleL
|
|
791 |
// -----------------------------------------------------------------------------
|
|
792 |
inline TInt CShwThumbnailLoader::CShwThumbnailLoaderImpl::AsyncErrorHandleL()
|
|
793 |
{
|
|
794 |
TRACER("CShwThumbnailLoader::CShwThumbnailLoaderImpl::AsyncErrorHandleL");
|
|
795 |
// handle the error
|
|
796 |
DoHandleErrorL();
|
|
797 |
// need to return value to please TCallBack API
|
|
798 |
return KErrNone;
|
|
799 |
}
|