imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailgeneratetask.cpp
branchGCC_SURGE
changeset 32 a0ee3f735f8b
parent 30 b67379558a75
child 31 d429f823a6b7
child 36 c5df59b4ae2d
equal deleted inserted replaced
26:ea43e3e86079 32:a0ee3f735f8b
    41     aProcessor, CThumbnailServer& aServer, RFile64* aFile, TDesC8* aBuffer,
    41     aProcessor, CThumbnailServer& aServer, RFile64* aFile, TDesC8* aBuffer,
    42     const TDataType* aMimeType, CThumbnailManager::TThumbnailFlags aFlags,
    42     const TDataType* aMimeType, CThumbnailManager::TThumbnailFlags aFlags,
    43     const TSize& aSize, TDisplayMode aDisplayMode, TInt aPriority,
    43     const TSize& aSize, TDisplayMode aDisplayMode, TInt aPriority,
    44     RArray < TThumbnailPersistentSize >* aMissingSizes, const TDesC& aTargetUri,
    44     RArray < TThumbnailPersistentSize >* aMissingSizes, const TDesC& aTargetUri,
    45     TThumbnailSize aThumbnailSize, const TInt64 aModified, 
    45     TThumbnailSize aThumbnailSize, const TInt64 aModified, 
    46     const CThumbnailManager::TThumbnailQualityPreference aQualityPreference ): 
    46     const CThumbnailManager::TThumbnailQualityPreference aQualityPreference,
       
    47     TBool aVirtualUri ): 
    47     CThumbnailTask( aProcessor, aPriority ), iServer( aServer ), 
    48     CThumbnailTask( aProcessor, aPriority ), iServer( aServer ), 
    48     iFlags( aFlags ), iSize( aSize ), iDisplayMode( aDisplayMode ),
    49     iFlags( aFlags ), iSize( aSize ), iDisplayMode( aDisplayMode ),
    49     iMissingSizes( aMissingSizes ), iTargetUri( aTargetUri ),
    50     iMissingSizes( aMissingSizes ), iTargetUri( aTargetUri ),
    50     iThumbnailSize( aThumbnailSize ), iModified(aModified),
    51     iThumbnailSize( aThumbnailSize ), iModified(aModified),
    51     iQualityPreference( aQualityPreference )
    52     iQualityPreference( aQualityPreference ), iVirtualUri( aVirtualUri )
    52     {
    53     {
    53     TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::CThumbnailGenerateTask()", this);
    54     TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::CThumbnailGenerateTask()", this);
    54     
    55     
    55     if ( !aBuffer && aFile)
    56     if ( !aBuffer && aFile)
    56         {
    57         {
   122     CThumbnailTask::StartL();
   123     CThumbnailTask::StartL();
   123     
   124     
   124 #ifdef _DEBUG
   125 #ifdef _DEBUG
   125     aStart.UniversalTime();
   126     aStart.UniversalTime();
   126 #endif
   127 #endif
   127 
   128    
   128       
   129     TBuf8< KMaxDataTypeLength > mimeType;
   129     TParsePtrC parse(iFilename);
   130 
   130     TPtrC ext(parse.Ext());
   131     if ( (!iVirtualUri && iFilename.Right(KExtLength).CompareF(KNonEmbeddedArtExt) == 0) ||
   131     TBuf8< KMaxDataTypeLength > mimeType;                
   132          (iVirtualUri && iTargetUri.Right(KExtLength).CompareF(KContactExt) == 0) ) // tparse panics with virtual URI
   132     if  (ext.CompareF(KNonEmbeddedArtExt)== 0) 
   133         {         
   133         {       
       
   134         mimeType.Copy( KImageMime );  		
   134         mimeType.Copy( KImageMime );  		
   135         }
   135         }
   136     else
   136     else
   137         {
   137         {
   138         mimeType = iMimeType.Des8();
   138         mimeType = iMimeType.Des8();
   139         }
   139         }
   140     iProvider = iServer.ResolveProviderL(mimeType);
   140     iProvider = iServer.ResolveProviderL(mimeType);
   141        	
   141        	
   142     TN_DEBUG3( "CThumbnailGenerateTask(0x%08x) -- provider UID 0x%08x", this,
   142     TN_DEBUG3( "CThumbnailGenerateTask(0x%08x) -- provider UID 0x%08x", this, iProvider->Uid());
   143         iProvider->Uid());
       
   144 
   143 
   145     __ASSERT_DEBUG(( iProvider ), ThumbnailPanic( EThumbnailNullPointer ));
   144     __ASSERT_DEBUG(( iProvider ), ThumbnailPanic( EThumbnailNullPointer ));
   146 
   145 
   147     iProvider->CancelGetThumbnail();
   146     iProvider->CancelGetThumbnail();
   148     iProvider->Reset();
   147     iProvider->Reset();
   196 // ---------------------------------------------------------------------------
   195 // ---------------------------------------------------------------------------
   197 //
   196 //
   198 void CThumbnailGenerateTask::DoCancel()
   197 void CThumbnailGenerateTask::DoCancel()
   199     {
   198     {
   200     TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::DoCancel()", this );
   199     TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::DoCancel()", this );
       
   200     
   201     if ( iProvider )
   201     if ( iProvider )
   202         {
   202         {
   203         iProvider->CancelGetThumbnail();
   203         iProvider->CancelGetThumbnail();
   204         }
   204         }
   205     }
   205     }
   238                {
   238                {
   239                aCroppedTargetSize.iWidth = Max( aCroppedTargetSize.iWidth,
   239                aCroppedTargetSize.iWidth = Max( aCroppedTargetSize.iWidth,
   240                    size.iSize.iWidth );
   240                    size.iSize.iWidth );
   241                aCroppedTargetSize.iHeight = Max( aCroppedTargetSize.iHeight,
   241                aCroppedTargetSize.iHeight = Max( aCroppedTargetSize.iHeight,
   242                    size.iSize.iHeight );
   242                    size.iSize.iHeight );
       
   243                
   243                if(iBuffer)
   244                if(iBuffer)
   244                  {
   245                  {
   245                  iFlags = ( CThumbnailManager::TThumbnailFlags ) (iFlags | CThumbnailManager::ECropToAspectRatio);
   246                  iFlags = ( CThumbnailManager::TThumbnailFlags ) (iFlags | CThumbnailManager::ECropToAspectRatio);
   246                  aEffectiveTargetSize = aCroppedTargetSize;
   247                  aEffectiveTargetSize = aCroppedTargetSize;
   247                  }
   248                  }
   326     CleanupStack::Pop( aBitmap );
   327     CleanupStack::Pop( aBitmap );
   327 
   328 
   328     // compTask is the scale task which returns the bitmap to the client
   329     // compTask is the scale task which returns the bitmap to the client
   329     CThumbnailScaleTask* complTask = NULL;
   330     CThumbnailScaleTask* complTask = NULL;
   330 	
   331 	
       
   332     TInt err1 = KErrNone;
       
   333     TInt err2 = KErrNone;
       
   334     TBool isPublic = ETrue;
       
   335     TBool isPublic2 = ETrue;
       
   336     
       
   337     if(iFilename != KNullDesC)
       
   338         {
       
   339         TRAP(err1, iServer.StoreForPathL(iFilename));
       
   340         
       
   341         isPublic = iServer.IsPublicPath( iFilename );
       
   342         }           
       
   343     if(iTargetUri != KNullDesC )
       
   344         {
       
   345         TRAP(err2, iServer.StoreForPathL(iTargetUri));
       
   346         
       
   347         isPublic2 = iServer.IsPublicPath( iTargetUri );
       
   348         }
       
   349     
       
   350     // check if need to create more than one scale task
   331     if ( iMissingSizes )
   351     if ( iMissingSizes )
   332         {
   352         {
   333         const TInt count = iMissingSizes->Count();
   353         const TInt count = iMissingSizes->Count();
   334         
   354         
   335         for ( TInt i( 0 ); i < count; i++ )
   355         for ( TInt i( 0 ); i < count; i++ )
   354                     TN_DEBUG2( "*iMissingSizes)[ i ].iWidth == %d", (*iMissingSizes)[ i ].iSize.iWidth );
   374                     TN_DEBUG2( "*iMissingSizes)[ i ].iWidth == %d", (*iMissingSizes)[ i ].iSize.iWidth );
   355                     TN_DEBUG2( "*iMissingSizes)[ i ].iHeight == %d", (*iMissingSizes)[ i ].iSize.iHeight );
   375                     TN_DEBUG2( "*iMissingSizes)[ i ].iHeight == %d", (*iMissingSizes)[ i ].iSize.iHeight );
   356                     }
   376                     }
   357                 }
   377                 }
   358             
   378             
   359             CThumbnailScaleTask* scaleTask = CThumbnailScaleTask::NewL( iProcessor, iServer, iFilename,
   379             CThumbnailScaleTask* complTask = CThumbnailScaleTask::NewL( iProcessor, iServer, iFilename,
   360                 aBitmap, iOriginalSize, (*iMissingSizes)[ i ].iSize, (*iMissingSizes)[ i ].iCrop, iDisplayMode,
   380                 aBitmap, iOriginalSize, (*iMissingSizes)[ i ].iSize, (*iMissingSizes)[ i ].iCrop, iDisplayMode,
   361                 KMaxPriority, iTargetUri, (*iMissingSizes)[ i ].iType, iModified, iScaledBitmapToPool, iEXIF,
   381                 KMaxPriority, iTargetUri, (*iMissingSizes)[ i ].iType, iModified, iScaledBitmapToPool, iEXIF,
   362                 iRequestId);
   382                 iRequestId, iVirtualUri);
   363             CleanupStack::PushL( scaleTask );
   383             CleanupStack::PushL( complTask );
   364             
   384             
   365             TInt err1 = KErrNone;
       
   366             TInt err2 = KErrNone;
       
   367             if(iFilename != KNullDesC)
       
   368                 {
       
   369                 TRAP(err1, iServer.StoreForPathL(iFilename));
       
   370                 }
       
   371             if(iTargetUri != KNullDesC)
       
   372                 {
       
   373                 TRAP(err2, iServer.StoreForPathL(iTargetUri));
       
   374                 }
       
   375             // if trying to access Z drive, don't try to store
   385             // if trying to access Z drive, don't try to store
   376             // don't want to store custom sizes
   386             // don't want to store custom sizes
   377             if( err1 == KErrAccessDenied || err2 == KErrAccessDenied ||
   387             // don't store if from private directory
   378                     (*iMissingSizes)[ i ].iType == ECustomThumbnailSize || 
   388             if( !isPublic || !isPublic2 ||
   379                     (*iMissingSizes)[ i ].iType == EUnknownThumbnailSize )
   389                 err1 == KErrAccessDenied || err2 == KErrAccessDenied ||
   380                 {
   390                 (*iMissingSizes)[ i ].iType == ECustomThumbnailSize || 
   381                 scaleTask->SetDoStore( EFalse );
   391                 (*iMissingSizes)[ i ].iType == EUnknownThumbnailSize )
       
   392                 {
       
   393                 complTask->SetDoStore( EFalse );
   382                 TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::CreateScaleTasksL() - do not store", this );
   394                 TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::CreateScaleTasksL() - do not store", this );
   383                 }
   395                 }
   384             else
   396             else
   385                 {
   397                 {
   386                 scaleTask->SetDoStore( ETrue );
   398                 complTask->SetDoStore( ETrue );
   387                 }
   399                 }
   388             
   400             
   389             iProcessor.AddTaskL( scaleTask );
   401             iProcessor.AddTaskL( complTask );
   390             CleanupStack::Pop( scaleTask );
   402             CleanupStack::Pop( complTask );
   391             
   403             
   392             // completion to first task, because task processor works like stack
   404             // completion to first task, because task processor works like stack
   393             if( i == 0 )
   405             if( i == 0 )
   394                 {
   406                 {
   395                 // compTask is now responsible for completing the RMessage
   407                 // compTask is now responsible for completing the RMessage
   396                 scaleTask->SetMessageData( iRequestId, iMessage, iClientThread );
   408                 complTask->SetMessageData( iRequestId, iMessage, iClientThread );
   397                 ResetMessageData();
   409                 ResetMessageData();
   398                 }
   410                 }
   399             }
   411             }
   400         }
   412         }
   401     else
   413     else
   414             }
   426             }
   415         
   427         
   416         complTask = CThumbnailScaleTask::NewL( iProcessor, iServer, iFilename,
   428         complTask = CThumbnailScaleTask::NewL( iProcessor, iServer, iFilename,
   417             aBitmap, iOriginalSize, iSize, iFlags& CThumbnailManager
   429             aBitmap, iOriginalSize, iSize, iFlags& CThumbnailManager
   418             ::ECropToAspectRatio, iDisplayMode, KMaxPriority, iTargetUri,
   430             ::ECropToAspectRatio, iDisplayMode, KMaxPriority, iTargetUri,
   419             iThumbnailSize, iModified, iScaledBitmapToPool, iEXIF, iRequestId );
   431             iThumbnailSize, iModified, iScaledBitmapToPool, iEXIF, iRequestId,
       
   432             iVirtualUri);
   420         CleanupStack::PushL( complTask );
   433         CleanupStack::PushL( complTask );
   421         
   434         
   422         TInt err1 = KErrNone;
       
   423         TInt err2 = KErrNone;
       
   424         if(iFilename != KNullDesC)
       
   425             {
       
   426             TRAP(err1, iServer.StoreForPathL(iFilename));
       
   427             }
       
   428         if(iTargetUri != KNullDesC)
       
   429             {
       
   430             TRAP(err2, iServer.StoreForPathL(iTargetUri));
       
   431             }
       
   432         // if trying to access Z drive, don't try to store
   435         // if trying to access Z drive, don't try to store
   433         // don't want to store custom sizes
   436         // don't want to store custom sizes
   434         if( err1 == KErrAccessDenied || err2 == KErrAccessDenied ||
   437         if( !isPublic || !isPublic2 ||
       
   438             err1 == KErrAccessDenied || err2 == KErrAccessDenied ||
   435             iThumbnailSize == ECustomThumbnailSize || 
   439             iThumbnailSize == ECustomThumbnailSize || 
   436             iThumbnailSize == EUnknownThumbnailSize )
   440             iThumbnailSize == EUnknownThumbnailSize )
   437             {
   441             {
   438             complTask->SetDoStore( EFalse );
   442             complTask->SetDoStore( EFalse );
   439             TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::CreateScaleTasksL() - do not store", this );
   443             TN_DEBUG2( "CThumbnailGenerateTask(0x%08x)::CreateScaleTasksL() - do not store", this );
   486     // of requested size only meaningful. 
   490     // of requested size only meaningful. 
   487     
   491     
   488     if(iFilename != KNullDesC)
   492     if(iFilename != KNullDesC)
   489         {
   493         {
   490         iServer.StoreForPathL( iFilename )->StoreThumbnailL( 
   494         iServer.StoreForPathL( iFilename )->StoreThumbnailL( 
   491             iFilename, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iModified, EFalse, ETrue );
   495             iFilename, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iModified, !iVirtualUri, ETrue );
   492 		//remove result from fetched checker
   496 		//remove result from fetched checker
   493         iServer.FetchedChecker().SetFetchResult( iFilename, KErrNone );
   497         iServer.FetchedChecker().SetFetchResult( iFilename, KErrNone );
   494         }
   498         }
   495     else if(iTargetUri != KNullDesC)
   499     else if(iTargetUri != KNullDesC)
   496         {
   500         {
   497         iServer.StoreForPathL( iTargetUri )->StoreThumbnailL( 
   501         iServer.StoreForPathL( iTargetUri )->StoreThumbnailL( 
   498             iTargetUri, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iModified, EFalse, ETrue );
   502             iTargetUri, tempBitmap, aOriginalSize, EFalse, iThumbnailSize, iModified, !iVirtualUri, ETrue );
   499 		//remove result from fetched checker
   503 		//remove result from fetched checker
   500         iServer.FetchedChecker().SetFetchResult( iTargetUri, KErrNone );
   504         iServer.FetchedChecker().SetFetchResult( iTargetUri, KErrNone );
   501         }
   505         }
   502 
   506 
   503     CleanupStack::PopAndDestroy( tempBitmap );
   507     CleanupStack::PopAndDestroy( tempBitmap );