photosgallery/viewframework/views/listview/src/glxpreviewthumbnailbinding.cpp
changeset 0 4e91876724a2
child 2 7d9067c6fcb1
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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 : Class defination for preview thumbnail in list view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mglxmedialist.h>
       
    20 #include <glxthumbnailcontext.h>
       
    21 #include <glxfilterfactory.h>                         // For TGlxFilterFactory
       
    22 #include <glxthumbnailattributeinfo.h>
       
    23 #include "glxpreviewthumbnailbinding.h"
       
    24 #include "glxgeneraluiutilities.h"
       
    25 #include <glxuiutility.h>                               // For UiUtility instance
       
    26 
       
    27 #include <glxtracer.h>
       
    28 #include <glxlog.h>
       
    29 
       
    30 #include <glxuistd.h>                    // Fetch context priority def'ns
       
    31 
       
    32 const TInt KInitialThumbnailsTimeDelay(100000);
       
    33 const TInt KWaitCount(5);
       
    34 const TInt KThumbnailStartTimeDelay(2000000);
       
    35 const TInt KThumbnailIntervalTimeDelay(2000000);
       
    36 const TInt KPreviewThumbnailFetchCount(18);
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // NewL
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CGlxPreviewThumbnailBinding* CGlxPreviewThumbnailBinding::NewL(
       
    43         MPreviewTNObserver& aObserver)
       
    44 	{
       
    45 	TRACER("CGlxPreviewThumbnailBinding::NewL");
       
    46 	CGlxPreviewThumbnailBinding* self = CGlxPreviewThumbnailBinding::NewLC(aObserver);
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;	
       
    49 	}
       
    50 
       
    51 // ----------------------------------------------------------------------------
       
    52 // NewLC
       
    53 // ----------------------------------------------------------------------------
       
    54 //
       
    55 CGlxPreviewThumbnailBinding* CGlxPreviewThumbnailBinding::NewLC(
       
    56         MPreviewTNObserver& aObserver)
       
    57 	{
       
    58 	TRACER("CGlxPreviewThumbnailBinding::NewLC");
       
    59 	CGlxPreviewThumbnailBinding* self = new(ELeave)CGlxPreviewThumbnailBinding(aObserver);
       
    60 	CleanupStack::PushL(self);
       
    61     self->ConstructL();
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // Constructor
       
    67 // ----------------------------------------------------------------------------
       
    68 //
       
    69 CGlxPreviewThumbnailBinding::CGlxPreviewThumbnailBinding(
       
    70         MPreviewTNObserver& aObserver)
       
    71 : iObserver(aObserver)
       
    72 	{
       
    73 	}
       
    74 
       
    75 // ----------------------------------------------------------------------------
       
    76 // ConstructL
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 void CGlxPreviewThumbnailBinding::ConstructL()
       
    80     {
       
    81     TRACER("CGlxPreviewThumbnailBinding::ConstructL");
       
    82     iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
    83     CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
    84     iGridIconSize = uiUtility->GetGridIconSize();
       
    85     uiUtility->Close() ;
       
    86     }
       
    87 
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // Destructor
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CGlxPreviewThumbnailBinding::~CGlxPreviewThumbnailBinding()
       
    94 	{
       
    95 	TRACER("CGlxPreviewThumbnailBinding::~CGlxPreviewThumbnailBinding");
       
    96     // close any medialist that exist
       
    97 	if( iMediaList )
       
    98 		{
       
    99         iMediaList->RemoveMediaListObserver( this );
       
   100         iMediaList->RemoveContext(iThumbnailContext);
       
   101         delete iThumbnailContext;
       
   102         iMediaList->Close();
       
   103         iMediaList = NULL;
       
   104 		}
       
   105 		
       
   106 	// cancel any outstanding request of the timer
       
   107 	if(iTimer->IsActive())
       
   108 	    {
       
   109 	    iTimer->Cancel();
       
   110 	    }
       
   111 	delete iTimer;
       
   112 	iTimer = NULL;
       
   113 	iPreviewItemCount.Close();
       
   114 	}
       
   115 
       
   116 // ----------------------------------------------------------------------------
       
   117 // TimerTickedL: we need to update only when required i.e, when the thumbnail count 
       
   118 // has not reached till the max limit to be shown
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 void CGlxPreviewThumbnailBinding::TimerTickedL()
       
   122     {
       
   123     TRACER("CGlxPreviewThumbnailBinding::TimerTickedL");
       
   124     
       
   125     if(iMediaList && iMediaList->Count() && iPreviewItemCount.Count() )
       
   126        	{
       
   127     	TInt thumbnailIndex = iPreviewItemCount[iProgressIndex];
       
   128     	if(thumbnailIndex < iMediaList->Count())
       
   129     	    {
       
   130             const TGlxMedia& item = iMediaList->Item(thumbnailIndex);
       
   131             TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   132                 GlxFullThumbnailAttributeId( ETrue,  iGridIconSize.iWidth,
       
   133                         iGridIconSize.iHeight ) );
       
   134             
       
   135             const CGlxThumbnailAttribute* value = item.ThumbnailAttribute(
       
   136                     thumbnailAttribute );
       
   137             if (value)
       
   138                 {
       
   139                 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   140                 bitmap->Duplicate( value->iBitmap->Handle());
       
   141                 iObserver.PreviewTNReadyL(bitmap, NULL,iProgressIndex);
       
   142                 iProgressIndex++;
       
   143                 if (iProgressIndex >= KPreviewThumbnailFetchCount || 
       
   144                     iProgressIndex >= iPreviewItemCount.Count() ||
       
   145                     iProgressIndex >= iMediaList->Count())
       
   146                     {
       
   147                     iProgressIndex = 0;
       
   148                     }
       
   149                 }
       
   150     	    }
       
   151        	}
       
   152     else if (iPopulateListTNs && iMediaList && iMediaList->Count() == 0)
       
   153 	    {
       
   154 	    if (iTrial == KWaitCount)
       
   155 		    {		   
       
   156 		    iObserver.PreviewTNReadyL(NULL, NULL, KErrNotFound);
       
   157 		    iTrial=0;
       
   158 		    return;
       
   159 		    }
       
   160 	    iTrial++;
       
   161 	    }
       
   162     else if(iMediaList && iMediaList->Count() )
       
   163     	{
       
   164 		if(iProgressIndex > iMediaList->Count()-1 )
       
   165 			{
       
   166 			iProgressIndex = 0;
       
   167 			}
       
   168 		const TGlxMedia& item = iMediaList->Item(iProgressIndex);
       
   169 		TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   170 			GlxFullThumbnailAttributeId( ETrue,  iGridIconSize.iWidth, 
       
   171 			        iGridIconSize.iHeight ) );
       
   172 		
       
   173 		const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( 
       
   174 		        thumbnailAttribute );
       
   175 		if (value)
       
   176 			{
       
   177 			CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   178 			bitmap->Duplicate( value->iBitmap->Handle());
       
   179 			iObserver.PreviewTNReadyL(bitmap, NULL,iProgressIndex);
       
   180 			iProgressIndex++;
       
   181 			if (iProgressIndex >= KPreviewThumbnailFetchCount || 
       
   182 				iProgressIndex >= iMediaList->Count())
       
   183 				{
       
   184 				iProgressIndex = 0;
       
   185 				}
       
   186 			}
       
   187 		else
       
   188 			{
       
   189 			if (iTrialCount == KWaitCount)
       
   190 				{				
       
   191 				iObserver.PreviewTNReadyL(NULL, NULL, KErrNotFound);
       
   192 				iTrialCount=0;
       
   193 				return;
       
   194 				}
       
   195 			iTrialCount++;
       
   196 			}
       
   197     	}   
       
   198     }
       
   199 // ----------------------------------------------------------------------------
       
   200 // IsTimeL callback function invoked when timer expires
       
   201 // ----------------------------------------------------------------------------
       
   202 //    
       
   203 TInt CGlxPreviewThumbnailBinding::IsTimeL( TAny* aSelf )
       
   204     {
       
   205     TRACER("CGlxPreviewThumbnailBinding::IsTimeL");
       
   206     if (aSelf)
       
   207         {
       
   208         TRACER("CGlxPreviewThumbnailBinding::IsTimeL");
       
   209         CGlxPreviewThumbnailBinding* self = static_cast<CGlxPreviewThumbnailBinding*>(aSelf);
       
   210         if(self)
       
   211             {
       
   212             self->TimerTickedL();
       
   213            }
       
   214         }
       
   215     return KErrNone;        
       
   216     }
       
   217 
       
   218 
       
   219 // ----------------------------------------------------------------------------
       
   220 // HandleItemChangedL
       
   221 // This function basically closes the old medialist if any for ex. Tags, 
       
   222 // Captured.. and then opens a new medialist with teh required filter.
       
   223 // ----------------------------------------------------------------------------
       
   224 //    
       
   225 void CGlxPreviewThumbnailBinding::HandleItemChangedL(const CMPXCollectionPath& aPath,
       
   226         TBool aPopulateListTNs )
       
   227     {
       
   228     TRACER("CGlxPreviewThumbnailBinding::HandleItemChangedL");
       
   229     iTimerTicked = EFalse;
       
   230     iPopulateListTNs = aPopulateListTNs;
       
   231     iProgressIndex = KErrNone;
       
   232 
       
   233     // remove and close old medialist   
       
   234     if( iMediaList )
       
   235 	    {
       
   236 	    // Reset the trial and the trialCount to 0 while deleting the medialist 
       
   237 	    iTrial = 0;
       
   238 	    iTrialCount = 0;
       
   239 	    iMediaList->RemoveMediaListObserver( this );
       
   240         iMediaList->RemoveContext(iThumbnailContext);
       
   241         delete iThumbnailContext;
       
   242         iThumbnailContext = NULL;
       
   243         iMediaList->Close();
       
   244         iMediaList = NULL;
       
   245 	    }
       
   246 	    
       
   247 	// Filter that filters out any GIF, corrupted images    
       
   248     CMPXFilter* filter = NULL;
       
   249     filter = TGlxFilterFactory::CreatePreviewFilterL(); 
       
   250     CleanupStack::PushL( filter );
       
   251     // create new medialist with the required filter which filters out all DRM, GIFS and corrupt 
       
   252     // thumbnial
       
   253 	iMediaList = MGlxMediaList::InstanceL( aPath ,KGlxIdNone, filter);
       
   254 	iThumbnailContext = CGlxThumbnailContext::NewL( &iThumbnailIterator ); // set the thumbnail context
       
   255 	iThumbnailIterator.SetRange( KPreviewThumbnailFetchCount ); // request for fifiteen thumbnails
       
   256 	iThumbnailContext->SetDefaultSpec( iGridIconSize.iWidth,iGridIconSize.iHeight );
       
   257 	iMediaList->AddContextL(iThumbnailContext ,KGlxFetchContextPriorityNormal );
       
   258 	// adding the medialist to observ any changes or updates done
       
   259 	iMediaList->AddMediaListObserverL(this);
       
   260 	CleanupStack::PopAndDestroy( filter );
       
   261 	
       
   262 	//Start the timer
       
   263 	StartTimer(iPopulateListTNs);
       
   264     }
       
   265 
       
   266 // ----------------------------------------------------------------------------
       
   267 // StartTimer - Starts the timer based on the flag populateListTN's
       
   268 // where the flag will be true, when initially the first thumbnails in the list
       
   269 // are populated.
       
   270 // ----------------------------------------------------------------------------
       
   271 //    
       
   272 void CGlxPreviewThumbnailBinding::StartTimer(TBool aPopulateListTNs)
       
   273     {
       
   274     TRACER("CGlxPreviewThumbnailBinding::StartTimer");
       
   275     
       
   276     iPopulateListTNs = aPopulateListTNs;
       
   277     
       
   278     if (iTimer)
       
   279         {
       
   280         iTimer->Cancel();
       
   281         }
       
   282         
       
   283     if (iPopulateListTNs)
       
   284         {
       
   285         iTimer->Start(KInitialThumbnailsTimeDelay, KInitialThumbnailsTimeDelay, 
       
   286             TCallBack(IsTimeL,this));   
       
   287         }
       
   288     else
       
   289         {
       
   290         iTimer->Start(KThumbnailStartTimeDelay, KThumbnailIntervalTimeDelay,
       
   291             TCallBack(IsTimeL,this));               
       
   292         }
       
   293     }
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 // HasFirstThumbnail
       
   297 // ----------------------------------------------------------------------------
       
   298 // 
       
   299  TBool CGlxPreviewThumbnailBinding::HasFirstThumbnail( const RArray< TMPXAttribute >& aAttributes )
       
   300      {
       
   301      TRACER("CGlxPreviewThumbnailBinding::HasFirstThumbnail");
       
   302      TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   303                                           GlxFullThumbnailAttributeId( ETrue, 
       
   304                                                iGridIconSize.iWidth,
       
   305                                                    iGridIconSize.iHeight) );
       
   306                                                           
       
   307      TIdentityRelation< TMPXAttribute > match ( &TMPXAttribute::Match );
       
   308      return ( KErrNotFound != aAttributes.Find( thumbnailAttribute, match ) );    
       
   309      }
       
   310 // ----------------------------------------------------------------------------
       
   311 // HandleItemAddedL
       
   312 // ----------------------------------------------------------------------------
       
   313 // 
       
   314 void CGlxPreviewThumbnailBinding::HandleItemAddedL( TInt /*aStartIndex*/, TInt 
       
   315     /*aEndIndex*/, MGlxMediaList* /*aList*/ )
       
   316     {
       
   317     }
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // HandleItemRemoved
       
   321 // ----------------------------------------------------------------------------
       
   322 //  
       
   323 void CGlxPreviewThumbnailBinding::HandleItemRemovedL( TInt /*aStartIndex*/, TInt 
       
   324     /*aEndIndex*/, MGlxMediaList* /*aList*/ )
       
   325     {
       
   326 
       
   327     }
       
   328 
       
   329 // ----------------------------------------------------------------------------
       
   330 // HandleAttributesAvailableL
       
   331 // Inside this function we are going to append the index for which we have valid 
       
   332 // thumbnails and when the number of available thumbnails become equal to the 
       
   333 // number of slots where thumbnail to be shown we go for updating them to visual
       
   334 // item.
       
   335 // ----------------------------------------------------------------------------
       
   336 //  
       
   337 void CGlxPreviewThumbnailBinding::HandleAttributesAvailableL( TInt aItemIndex, 
       
   338     const RArray<TMPXAttribute>& aAttributes, MGlxMediaList* /*aList*/ )
       
   339     {
       
   340     TRACER("CGlxPreviewThumbnailBinding::HandleAttributesAvailableL");
       
   341 
       
   342     TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   343         GlxFullThumbnailAttributeId( ETrue,  iGridIconSize.iWidth, 
       
   344                 iGridIconSize.iHeight ) );
       
   345                                                          
       
   346     TIdentityRelation< TMPXAttribute > match ( &TMPXAttribute::Match );
       
   347     
       
   348     if (KErrNotFound != aAttributes.Find( thumbnailAttribute, match ))
       
   349     	{
       
   350 		const TGlxMedia& item = iMediaList->Item( aItemIndex );
       
   351         const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( 
       
   352                 thumbnailAttribute );
       
   353         if (value)
       
   354 	        {
       
   355             iPreviewItemCount.AppendL( aItemIndex );
       
   356             }
       
   357         }
       
   358     }
       
   359     
       
   360 // ----------------------------------------------------------------------------
       
   361 // HandleFocusChangedL
       
   362 // ----------------------------------------------------------------------------
       
   363 //  
       
   364 void CGlxPreviewThumbnailBinding::HandleFocusChangedL( NGlxListDefs::
       
   365     TFocusChangeType /*aType*/, TInt /*aNewIndex*/, TInt /*aOldIndex*/, 
       
   366     MGlxMediaList* /*aList*/ )
       
   367     {
       
   368     
       
   369     }
       
   370 
       
   371 // ----------   ------------------------------------------------------------------
       
   372 // HandleItemSelected
       
   373 // ----------------------------------------------------------------------------
       
   374 //  
       
   375 void CGlxPreviewThumbnailBinding::HandleItemSelectedL(TInt /*aIndex*/, 
       
   376     TBool /*aSelected*/, MGlxMediaList* /*aList*/ )
       
   377     {
       
   378 
       
   379     }
       
   380 
       
   381 // ----------------------------------------------------------------------------
       
   382 // HandleMessageL
       
   383 // ----------------------------------------------------------------------------
       
   384 //    
       
   385  void CGlxPreviewThumbnailBinding::HandleMessageL( const CMPXMessage& /*aMessage*/, 
       
   386     MGlxMediaList* /*aList*/ )
       
   387     {
       
   388     
       
   389     }
       
   390   
       
   391 // ----------------------------------------------------------------------------
       
   392 // HandleError
       
   393 // ----------------------------------------------------------------------------
       
   394 //
       
   395 void CGlxPreviewThumbnailBinding::HandleError( TInt /*aError*/ ) 
       
   396     {
       
   397     
       
   398     }
       
   399   
       
   400 // ----------------------------------------------------------------------------
       
   401 // HandleCommandCompleteL
       
   402 // ----------------------------------------------------------------------------
       
   403 //  
       
   404 void CGlxPreviewThumbnailBinding::HandleCommandCompleteL( CMPXCommand* 
       
   405         /*aCommandResult*/, 
       
   406     TInt /*aError*/, MGlxMediaList* /*aList*/ )
       
   407     {
       
   408     
       
   409     }
       
   410   
       
   411 // ----------------------------------------------------------------------------
       
   412 // HandleMediaL
       
   413 // ----------------------------------------------------------------------------
       
   414 //  
       
   415 void CGlxPreviewThumbnailBinding::HandleMediaL( TInt /*aListIndex*/, 
       
   416         MGlxMediaList* /*aList*/ )
       
   417     {
       
   418     
       
   419     }
       
   420   
       
   421 // ----------------------------------------------------------------------------
       
   422 // HandleItemModifiedL
       
   423 // ----------------------------------------------------------------------------
       
   424 //  
       
   425 void CGlxPreviewThumbnailBinding::HandleItemModifiedL( const RArray<TInt>& 
       
   426         /*aItemIndexes*/,
       
   427     MGlxMediaList* /*aList*/ )
       
   428     {
       
   429     
       
   430     }