imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailgeneratetask.cpp
branchRCL_3
changeset 5 82749d516180
parent 1 235a7fc86938
child 7 2eb74cf6572e
equal deleted inserted replaced
1:235a7fc86938 5:82749d516180
    18 
    18 
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <fbs.h>
    20 #include <fbs.h>
    21 
    21 
    22 #include <thumbnailmanager.h>
    22 #include <thumbnailmanager.h>
    23 
       
    24 #include "thumbnailgeneratetask.h"
    23 #include "thumbnailgeneratetask.h"
    25 #include "thumbnailscaletask.h"
    24 #include "thumbnailscaletask.h"
    26 #include "thumbnailprovider.h"
    25 #include "thumbnailprovider.h"
    27 #include "thumbnailserver.h"
    26 #include "thumbnailserver.h"
    28 #include "thumbnailtaskprocessor.h"
    27 #include "thumbnailtaskprocessor.h"
   156       
   155       
   157     if(effectiveTargetSize == TSize())
   156     if(effectiveTargetSize == TSize())
   158         {
   157         {
   159         iProvider->SetTargetSize( croppedTargetSize );
   158         iProvider->SetTargetSize( croppedTargetSize );
   160         }
   159         }
   161 		
   160 	
       
   161     TInt providerErr;
       
   162     
   162     if ( !iBuffer )
   163     if ( !iBuffer )
   163         {
   164         {
   164         iProvider->GetThumbnailL( iServer.Fs(), iFile, iMimeType, iFlags,
   165         TRAP(providerErr, iProvider->GetThumbnailL( iServer.Fs(), iFile, iMimeType, iFlags,
   165             iDisplayMode, iQualityPreference );
   166             iDisplayMode, iQualityPreference ) );
   166         }
   167         }
   167     else
   168     else
   168         {
   169         {
   169         iProvider->GetThumbnailL( iServer.Fs(), iBuffer, iMimeType, iFlags,
   170         TRAP( providerErr, iProvider->GetThumbnailL( iServer.Fs(), iBuffer, iMimeType, iFlags,
   170             iDisplayMode, iQualityPreference );
   171             iDisplayMode, iQualityPreference ));
   171         }
   172         }
       
   173     
       
   174     DoBlacklisting( providerErr, TSize(0,0) );
       
   175     
       
   176     User::LeaveIfError( providerErr );
   172     }
   177     }
   173 
   178 
   174 
   179 
   175 // ---------------------------------------------------------------------------
   180 // ---------------------------------------------------------------------------
   176 // CThumbnailGenerateTask::RunL()
   181 // CThumbnailGenerateTask::RunL()
   275 
   280 
   276     if ( aError )
   281     if ( aError )
   277         {
   282         {
   278         delete aBitmap;
   283         delete aBitmap;
   279         aBitmap = NULL;
   284         aBitmap = NULL;
   280         // Create a temporary bitmap of size 1 for storing blacklisted thumbnail
   285 
   281         // Because no actual bitmap data is generated, there is no reason to 
   286         DoBlacklisting( aError, aOriginalSize );
   282         // add bitmap to server bitmap pool. Completion of client request with
   287             
   283         // error code just results in applications showing their default bitmap. 
       
   284         if( iFilename != KNullDesC || iTargetUri != KNullDesC )
       
   285             {
       
   286             if ( aError == KErrNotSupported ||
       
   287                     aError == KErrCorrupt ||
       
   288                     aError == KErrCompletion)
       
   289                 {
       
   290                 TRAPD( err, CreateBlackListedL( aOriginalSize ) );
       
   291                 if (err != KErrNone)
       
   292                     {
       
   293                     TN_DEBUG2( "CThumbnailGenerateTask::ThumbnailProviderReady() - blacklisting failed with code %d", err );
       
   294                     }
       
   295                 }
       
   296             }
       
   297         Complete( aError );
   288         Complete( aError );
   298         }
   289         }
   299     else
   290     else
   300         {
   291         {
   301         // CreateScaleTasksL will take ownership of bitmap
   292         // CreateScaleTasksL will take ownership of bitmap
   322 void CThumbnailGenerateTask::CreateScaleTasksL( CFbsBitmap* aBitmap )
   313 void CThumbnailGenerateTask::CreateScaleTasksL( CFbsBitmap* aBitmap )
   323     {
   314     {
   324     __ASSERT_DEBUG(( aBitmap ), ThumbnailPanic( EThumbnailNullPointer ));
   315     __ASSERT_DEBUG(( aBitmap ), ThumbnailPanic( EThumbnailNullPointer ));
   325 
   316 
   326     CleanupStack::PushL( aBitmap );
   317     CleanupStack::PushL( aBitmap );
   327     iServer.AddBitmapToPoolL( iRequestId.iSession, aBitmap );
   318     iServer.AddBitmapToPoolL( iRequestId.iSession, aBitmap, iRequestId );
   328 
   319 
   329     // Keep pointer so we can delete bitmap from pool
   320     // Keep pointer so we can delete bitmap from pool
   330     iBitmap = aBitmap;
   321     iBitmap = aBitmap;
   331     CleanupStack::Pop( aBitmap );
   322     CleanupStack::Pop( aBitmap );
   332 
   323 
   474 // Stores a blacklisted thumbnail
   465 // Stores a blacklisted thumbnail
   475 // ---------------------------------------------------------------------------
   466 // ---------------------------------------------------------------------------
   476 //
   467 //
   477 void CThumbnailGenerateTask::CreateBlackListedL( const TSize& aOriginalSize )
   468 void CThumbnailGenerateTask::CreateBlackListedL( const TSize& aOriginalSize )
   478     {
   469     {
       
   470     TN_DEBUG1( "CThumbnailGenerateTask::CreateBlackListedL()");
   479     CFbsBitmap* tempBitmap = 0;
   471     CFbsBitmap* tempBitmap = 0;
   480     tempBitmap = new (ELeave) CFbsBitmap();
   472     tempBitmap = new (ELeave) CFbsBitmap();
   481     CleanupStack::PushL( tempBitmap );
   473     CleanupStack::PushL( tempBitmap );
   482     TSize tempSize( 1, 1 );
   474     TSize tempSize( 1, 1 );
   483     User::LeaveIfError( tempBitmap->Create( tempSize, iDisplayMode ) );
   475     User::LeaveIfError( tempBitmap->Create( tempSize, iDisplayMode ) );
   484     
   476     
   485     // Instead of creating a blacklisted entry of requested size (iThumbnailSize) in thumbnail db,
   477     // Instead of creating a blacklisted entry of requested size (iThumbnailSize) in thumbnail db,
   486     // consider blacklisting all sizes (hence the changes are needed in thumbnail fetching logic too).
   478     // consider blacklisting all sizes (hence the changes are needed in thumbnail fetching logic too).
   487     // However, decoding of source to thumnail could succeed in other sizes, which makes blacklisting
   479     // However, decoding of source to thumnail could succeed in other sizes, which makes blacklisting
   488     // of requested size only meaningful. 
   480     // of requested size only meaningful. 
       
   481     
   489     if(iFilename != KNullDesC)
   482     if(iFilename != KNullDesC)
   490         {
   483         {
   491         iServer.StoreForPathL( iFilename )->StoreThumbnailL( 
   484         iServer.StoreForPathL( iFilename )->StoreThumbnailL( 
   492             iFilename, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iThumbnailId, EFalse, ETrue );
   485             iFilename, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iThumbnailId, EFalse, ETrue );
   493         }
   486         }
   497             iTargetUri, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iThumbnailId, EFalse, ETrue );
   490             iTargetUri, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iThumbnailId, EFalse, ETrue );
   498         }
   491         }
   499 
   492 
   500     CleanupStack::PopAndDestroy( tempBitmap );
   493     CleanupStack::PopAndDestroy( tempBitmap );
   501     }
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // Checks is blacklisting needed
       
   498 // ---------------------------------------------------------------------------
       
   499 //
       
   500 void CThumbnailGenerateTask::DoBlacklisting( const TInt aError, const TSize& aOriginalSize )
       
   501     {
       
   502     TN_DEBUG1( "CThumbnailGenerateTask::DoBlacklisting()");
       
   503     // Create a temporary bitmap of size 1 for storing blacklisted thumbnail
       
   504     // Because no actual bitmap data is generated, there is no reason to 
       
   505     // add bitmap to server bitmap pool. Completion of client request with
       
   506     // error code just results in applications showing their default bitmap. 
       
   507     if( aError != KErrNone && (iFilename != KNullDesC || iTargetUri != KNullDesC ))
       
   508         {
       
   509         if ( aError == KErrNotSupported ||
       
   510             aError == KErrCorrupt ||
       
   511             aError == KErrCompletion ||
       
   512             aError == KErrUnderflow)
       
   513             {
       
   514         
       
   515         if(iMissingSizes)
       
   516             {
       
   517             TN_DEBUG2( "CThumbnailGenerateTask::DoBlacklisting() - blacklist missing sizes count = %d", iMissingSizes->Count() );
       
   518 
       
   519             for ( TInt i( 0 ); i < iMissingSizes->Count(); i++ )
       
   520                 {
       
   521                 iThumbnailSize = (*iMissingSizes)[ i ].iType;
       
   522                 TRAPD( err, CreateBlackListedL( aOriginalSize ) );
       
   523                 if (err != KErrNone)
       
   524                    {
       
   525                    TN_DEBUG3( "CThumbnailGenerateTask::DoBlacklisting() - blacklisting missing size %d failed with code %d", iThumbnailSize, err );
       
   526                    }
       
   527                 }
       
   528             return;
       
   529             }
       
   530         else
       
   531             {
       
   532             TN_DEBUG1( "CThumbnailGenerateTask::DoBlacklisting() - blacklist single size" );
       
   533             TRAPD( err, CreateBlackListedL( aOriginalSize ) );
       
   534             if (err != KErrNone)
       
   535                 {
       
   536                 TN_DEBUG2( "CThumbnailGenerateTask::DoBlacklisting() - blacklisting failed with code %d", err );
       
   537                 }
       
   538             return;
       
   539             }
       
   540         }
       
   541     TN_DEBUG1( "CThumbnailGenerateTask::DoBlacklisting() - not blacklisted " );        
       
   542     }
       
   543 }
       
   544 
       
   545