photosgallery/viewframework/views/listview/src/glxpreviewthumbnailbinding.cpp
branchRCL_3
changeset 11 71da52165949
parent 9 6b87b143d312
child 13 bcb43dc84c44
equal deleted inserted replaced
9:6b87b143d312 11:71da52165949
    26 
    26 
    27 #include <glxtracer.h>
    27 #include <glxtracer.h>
    28 #include <glxlog.h>
    28 #include <glxlog.h>
    29 
    29 
    30 #include <glxuistd.h>                    // Fetch context priority def'ns
    30 #include <glxuistd.h>                    // Fetch context priority def'ns
    31 
    31 #include <mglxcache.h> 
    32 #include <ganes/HgDoubleGraphicList.h>
    32 #include <ganes/HgDoubleGraphicList.h>
    33 
    33 
    34 
    34 
    35 const TInt KInitialThumbnailsTimeDelay(100000);
    35 const TInt KInitialThumbnailsTimeDelay(100000);
    36 const TInt KWaitCount(5);
    36 const TInt KWaitCount(10);
    37 const TInt KThumbnailStartTimeDelay(250000);
    37 const TInt KThumbnailStartTimeDelay(250000);
    38 const TInt KThumbnailIntervalTimeDelay(50000);
       
    39 const TInt KPreviewThumbnailFetchCount(1);
    38 const TInt KPreviewThumbnailFetchCount(1);
    40 
    39 
    41 // ----------------------------------------------------------------------------
    40 
    42 // CWaitScheduler::NewL()
       
    43 // ---------------------------------------------------------------------------- 
       
    44 CGlxWaitScheduler* CGlxWaitScheduler::NewL()
       
    45     {
       
    46     TRACER("CGlxWaitScheduler::NewL()");    
       
    47     CGlxWaitScheduler* self = new( ELeave ) CGlxWaitScheduler();
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( );
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 CGlxWaitScheduler::CGlxWaitScheduler()
       
    55 : CActive( EPriorityStandard )
       
    56     {
       
    57     TRACER("CGlxWaitScheduler::CGlxWaitScheduler()");    
       
    58     CActiveScheduler::Add( this );
       
    59     }
       
    60 
       
    61 void CGlxWaitScheduler::ConstructL()
       
    62     {
       
    63     TRACER("CGlxWaitScheduler::ConstructL()");
       
    64     // Do nothing
       
    65     }
       
    66 
       
    67 CGlxWaitScheduler::~CGlxWaitScheduler()
       
    68     {
       
    69     TRACER("CGlxWaitScheduler::~CGlxWaitScheduler()");     
       
    70     Cancel();
       
    71     }
       
    72 
       
    73 void CGlxWaitScheduler::WaitForRequest()
       
    74     {
       
    75     TRACER("CGlxWaitScheduler::WaitForRequest()");     
       
    76     SetActive();
       
    77     iScheduler.Start();
       
    78     }
       
    79 
       
    80 void CGlxWaitScheduler::RunL()
       
    81     {
       
    82     TRACER("CGlxWaitScheduler::RunL()");     
       
    83     iScheduler.AsyncStop();
       
    84     }
       
    85 
       
    86 void CGlxWaitScheduler::DoCancel()
       
    87     {
       
    88     TRACER("CGlxWaitScheduler::DoCancel()");   
       
    89     //Do nothing
       
    90     }
       
    91 
    41 
    92 // ----------------------------------------------------------------------------
    42 // ----------------------------------------------------------------------------
    93 // NewL
    43 // NewL
    94 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    95 //
    45 //
   146                         GlxFullThumbnailAttributeId(ETrue,
    96                         GlxFullThumbnailAttributeId(ETrue,
   147                             iGridIconSize.iWidth,iGridIconSize.iHeight) );
    97                             iGridIconSize.iWidth,iGridIconSize.iHeight) );
   148     iThumbnailContext->SetDefaultSpec(iGridIconSize.iWidth,
    98     iThumbnailContext->SetDefaultSpec(iGridIconSize.iWidth,
   149                                                 iGridIconSize.iHeight);
    99                                                 iGridIconSize.iHeight);
   150     iThumbnailContext->AddAttributeL(tnAttr);
   100     iThumbnailContext->AddAttributeL(tnAttr);
   151     iBitmapScaler = CBitmapScaler::NewL();
       
   152     }
   101     }
   153 
   102 
   154 // ----------------------------------------------------------------------------
   103 // ----------------------------------------------------------------------------
   155 // Destructor
   104 // Destructor
   156 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
   173 	    {
   122 	    {
   174 	    iTimer->Cancel();
   123 	    iTimer->Cancel();
   175 	    }
   124 	    }
   176 	delete iTimer;
   125 	delete iTimer;
   177 	iTimer = NULL;
   126 	iTimer = NULL;
   178 	iPreviewItemCount.Close();
   127 	iPreviewItemCount.Close();	
   179 	
       
   180 	if(iBitmapScaler)
       
   181 	    {
       
   182         delete iBitmapScaler;
       
   183 	    iBitmapScaler = NULL;
       
   184 	    }
       
   185 	}
   128 	}
   186 
   129 
   187 // ----------------------------------------------------------------------------
   130 // ----------------------------------------------------------------------------
   188 // TimerTickedL: we need to update only when required i.e, when the thumbnail count 
   131 // TimerTickedL: we need to update only when required i.e, when the thumbnail count 
   189 // has not reached till the max limit to be shown
   132 // has not reached till the max limit to be shown
   206             const CGlxThumbnailAttribute* value = item.ThumbnailAttribute(
   149             const CGlxThumbnailAttribute* value = item.ThumbnailAttribute(
   207                     thumbnailAttribute );
   150                     thumbnailAttribute );
   208             if (value)
   151             if (value)
   209                 {
   152                 {
   210                 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   153                 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   211 				bitmap->Duplicate( value->iBitmap->Handle());
   154                 ScaleBitmapToListSizeL(value->iBitmap, bitmap);
   212                 //ScaleBitmapToListSizeL(value->iBitmap, bitmap);
   155                 GLX_LOG_INFO1("iObserver.PreviewTNReadyL() iTrial=%d", iTrial);
   213                 iObserver.PreviewTNReadyL(bitmap, NULL,iProgressIndex);
   156                 iObserver.PreviewTNReadyL(bitmap, NULL,iPopulateListTNs);
   214                 }
   157                 }
   215     	    }
   158     	    }
   216        	}
   159        	}
   217     else if (iPopulateListTNs && iMediaList && iMediaList->Count() == 0)
   160     else if (iPopulateListTNs && iMediaList && iMediaList->Count() == 0)
   218 	    {
   161 	    {
   219 	    if (iTrial == KWaitCount)
   162 	    if (iTrial == KWaitCount)
   220 		    {		   
   163 		    {		   
   221 		    iObserver.PreviewTNReadyL(NULL, NULL, KErrNotFound);
   164 		    iObserver.PreviewTNReadyL(NULL, NULL, iPopulateListTNs);
   222 		    iTrial=0;
   165 		    iTrial=0;
   223 		    return;
   166 		    return;
   224 		    }
   167 		    }
   225 	    iTrial++;
   168 	    iTrial++;
   226 	    }
   169 	    }
   238 		const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( 
   181 		const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( 
   239 		        thumbnailAttribute );
   182 		        thumbnailAttribute );
   240 		if (value)
   183 		if (value)
   241 			{
   184 			{
   242 			CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   185 			CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   243 			bitmap->Duplicate( value->iBitmap->Handle());
   186 		    ScaleBitmapToListSizeL(value->iBitmap, bitmap);
   244 		    //ScaleBitmapToListSizeL(value->iBitmap, bitmap);
   187 			GLX_LOG_INFO1("iObserver.PreviewTNReadyL() iTrialCount=%d", iTrialCount);
   245 			iObserver.PreviewTNReadyL(bitmap, NULL,iProgressIndex);
   188 			iObserver.PreviewTNReadyL(bitmap, NULL,iPopulateListTNs);
   246 			}
   189 			}
   247 		else
   190 		else
   248 			{
   191 			{
   249 			if (iTrialCount == KWaitCount)
   192 			if (iTrialCount == KWaitCount)
   250 				{				
   193 				{				
   251 				iObserver.PreviewTNReadyL(NULL, NULL, KErrNotFound);
   194 				iObserver.PreviewTNReadyL(NULL, NULL, iPopulateListTNs);
   252 				iTrialCount=0;
   195 				iTrialCount=0;
   253 				return;
   196 				return;
   254 				}
   197 				}
   255 			iTrialCount++;
   198 			iTrialCount++;
   256 			}
   199 			}
   281 // This function basically closes the old medialist if any for ex. Tags, 
   224 // This function basically closes the old medialist if any for ex. Tags, 
   282 // Captured.. and then opens a new medialist with teh required filter.
   225 // Captured.. and then opens a new medialist with teh required filter.
   283 // ----------------------------------------------------------------------------
   226 // ----------------------------------------------------------------------------
   284 //    
   227 //    
   285 void CGlxPreviewThumbnailBinding::HandleItemChangedL(const CMPXCollectionPath& aPath,
   228 void CGlxPreviewThumbnailBinding::HandleItemChangedL(const CMPXCollectionPath& aPath,
   286         TBool aPopulateListTNs, TBool aBackwardNavigation)
   229         TBool aPopulateListTNs, TBool  aIsRefreshNeeded, TBool aBackwardNavigation)
   287     {
   230     {
   288     TRACER("CGlxPreviewThumbnailBinding::HandleItemChangedL");
   231     TRACER("CGlxPreviewThumbnailBinding::HandleItemChangedL");
   289     iTimerTicked = EFalse;
   232     iTimerTicked = EFalse;
   290     iPopulateListTNs = aPopulateListTNs;
   233     iPopulateListTNs = aPopulateListTNs;
   291     iBackwardNavigation = aBackwardNavigation;
       
   292     iProgressIndex = KErrNone;
   234     iProgressIndex = KErrNone;
       
   235     iIsRefreshNeeded = aIsRefreshNeeded;
   293 
   236 
   294     // remove and close old medialist   
   237     // remove and close old medialist   
   295     if( iMediaList )
   238     if( iMediaList )
   296 	    {
   239 	    {
   297 	    // Reset the trial and the trialCount to 0 while deleting the medialist 
   240 	    // Reset the trial and the trialCount to 0 while deleting the medialist 
   305 	    
   248 	    
   306     iMediaList = MGlxMediaList::InstanceL(aPath, KGlxIdNone, iPreviewFilter);
   249     iMediaList = MGlxMediaList::InstanceL(aPath, KGlxIdNone, iPreviewFilter);
   307     iMediaList->AddContextL(iThumbnailContext, KGlxFetchContextPriorityNormal);
   250     iMediaList->AddContextL(iThumbnailContext, KGlxFetchContextPriorityNormal);
   308 	// adding the medialist to observ any changes or updates done
   251 	// adding the medialist to observ any changes or updates done
   309 	iMediaList->AddMediaListObserverL(this);
   252 	iMediaList->AddMediaListObserverL(this);
       
   253 
       
   254 	if(aBackwardNavigation)
       
   255 	    {
       
   256 	    //On backward navigation start the timer manually, since we do not  
       
   257         //get the attribute callback.
       
   258         StartTimer(iPopulateListTNs);        
       
   259         }
   310     }
   260     }
   311 
   261 
   312 // ----------------------------------------------------------------------------
   262 // ----------------------------------------------------------------------------
   313 // StartTimer - Starts the timer based on the flag populateListTN's
   263 // StartTimer - Starts the timer based on the flag populateListTN's
   314 // where the flag will be true, when initially the first thumbnails in the list
   264 // where the flag will be true, when initially the first thumbnails in the list
   326         iTimer->Cancel();
   276         iTimer->Cancel();
   327         }
   277         }
   328         
   278         
   329     if (iPopulateListTNs)
   279     if (iPopulateListTNs)
   330         {
   280         {
   331         if (iBackwardNavigation)
   281          iTimer->Start(KThumbnailStartTimeDelay, 
   332             {
       
   333             iTimer->Start(KThumbnailIntervalTimeDelay, KThumbnailIntervalTimeDelay/KWaitCount,
       
   334                     TCallBack(IsTimeL,this));
       
   335             }
       
   336         else
       
   337             {
       
   338             iTimer->Start(KThumbnailStartTimeDelay, 
       
   339                     KInitialThumbnailsTimeDelay, TCallBack(IsTimeL,this));
   282                     KInitialThumbnailsTimeDelay, TCallBack(IsTimeL,this));
   340             }
       
   341         }
   283         }
   342      }
   284      }
   343 
   285 
   344 // ----------------------------------------------------------------------------
   286 // ----------------------------------------------------------------------------
   345 // StopTimer - Stop the timer
   287 // StopTimer - Stop the timer
   399         const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( 
   341         const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( 
   400                 thumbnailAttribute );
   342                 thumbnailAttribute );
   401         if (value)
   343         if (value)
   402 	        {
   344 	        {
   403             iPreviewItemCount.AppendL( aItemIndex );
   345             iPreviewItemCount.AppendL( aItemIndex );
       
   346             // sometimes we get HandleAttributesAvailableL callback after some delay
       
   347             // when we do cache cleanup. 
       
   348             if(!iPopulateListTNs)
       
   349             	{
       
   350             	iPopulateListTNs = ETrue;
       
   351             	StartTimer(iPopulateListTNs);
       
   352             	} 
   404             }
   353             }
   405         }
   354         }
   406     }
   355     }
   407     
   356     
   408 // ----------------------------------------------------------------------------
   357 // ----------------------------------------------------------------------------
   481 // HandlePopulatedL
   430 // HandlePopulatedL
   482 // ----------------------------------------------------------------------------
   431 // ----------------------------------------------------------------------------
   483 //
   432 //
   484 void CGlxPreviewThumbnailBinding::HandlePopulatedL( MGlxMediaList* /*aList*/ )
   433 void CGlxPreviewThumbnailBinding::HandlePopulatedL( MGlxMediaList* /*aList*/ )
   485     {
   434     {
   486     TRACER("CGlxPreviewThumbnailBinding::HandlePopulatedL()");
   435 	TRACER("CGlxPreviewThumbnailBinding::HandlePopulatedL()");
   487     //Start the timer
   436 
   488     StartTimer(iPopulateListTNs);
   437 	// Do cache cleanup. If iIsRefreshNeeded is set,
   489     }
   438 	// then clean up the item at 0th index 
       
   439 	if (iPopulateListTNs && iIsRefreshNeeded)
       
   440 		{
       
   441 		if (iMediaList && iMediaList->Count() > 0)
       
   442 			{
       
   443 			GLX_LOG_INFO("**** Cache Cleanup ****");
       
   444 			MGlxCache* cacheManager = MGlxCache::InstanceL();
       
   445 			cacheManager->ForceCleanupMedia(iMediaList->IdSpaceId(0),
       
   446 					iMediaList->Item(0).Id());
       
   447 			cacheManager->Close();
       
   448 			}
       
   449 		}
       
   450 	//Start the timer
       
   451 	StartTimer(iPopulateListTNs);
       
   452 	}
   490 
   453 
   491 // ----------------------------------------------------------------------------
   454 // ----------------------------------------------------------------------------
   492 // ScaleBitmapToListSizeL
   455 // ScaleBitmapToListSizeL
   493 // ----------------------------------------------------------------------------
   456 // ----------------------------------------------------------------------------
   494 //
   457 //
   495 void CGlxPreviewThumbnailBinding::ScaleBitmapToListSizeL(
   458 void CGlxPreviewThumbnailBinding::ScaleBitmapToListSizeL(
   496                              CFbsBitmap* aSrcBitmap, CFbsBitmap* aDestBitmap)
   459         CFbsBitmap* aSrcBitmap, CFbsBitmap* aDestBitmap)
   497     {      
   460     {
   498     TRACER("CGlxPreviewThumbnailBinding::ScaleBitmapToListSizeL()");      
   461     TRACER("CGlxPreviewThumbnailBinding::ScaleBitmapToListSizeL()");
   499 
   462     TSize destSize = CHgDoubleGraphicList::PreferredImageSize();
   500     // Create the bitmap with the list preferred size
   463     TSize srcSize = aSrcBitmap->SizeInPixels();
   501     aDestBitmap->Create(CHgDoubleGraphicList::PreferredImageSize(), EColor16MU);
   464     if (destSize.iHeight * srcSize.iWidth < destSize.iWidth * srcSize.iHeight)
   502 
   465         {
   503     CGlxWaitScheduler* waitScheduler = CGlxWaitScheduler::NewL();
   466         // Source has taller aspect than target so reduce target width
   504     CleanupStack::PushL( waitScheduler );
   467         destSize.iWidth = ((destSize.iHeight * srcSize.iWidth)
   505 
   468                 / (srcSize.iHeight));
   506     iBitmapScaler->Scale(&waitScheduler->iStatus, *aSrcBitmap, 
   469         }
   507             *aDestBitmap, ETrue);
   470     else
   508     waitScheduler->WaitForRequest();
   471         {
   509 
   472         // Source has wider aspect than target so reduce target height
   510     CleanupStack::PopAndDestroy( waitScheduler );
   473         destSize.iHeight = (destSize.iWidth * srcSize.iHeight)
   511     }
   474                 / srcSize.iWidth;
       
   475         }
       
   476     aDestBitmap->Create(destSize, aSrcBitmap->DisplayMode());
       
   477     CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(aDestBitmap);
       
   478     CleanupStack::PushL(bitmapDevice);
       
   479     CFbsBitGc* bitmapGc = CFbsBitGc::NewL();
       
   480     CleanupStack::PushL(bitmapGc);
       
   481     bitmapGc->Activate(bitmapDevice);
       
   482     bitmapGc->DrawBitmap(TRect(destSize), aSrcBitmap);
       
   483     CleanupStack::PopAndDestroy(bitmapGc);
       
   484     CleanupStack::PopAndDestroy(bitmapDevice);
       
   485     }