imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp
branchRCL_3
changeset 38 2b4b06654caa
parent 37 f759b6186ab5
child 40 6257223ede8a
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp	Thu Jul 15 18:59:26 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp	Thu Aug 19 10:13:51 2010 +0300
@@ -43,6 +43,7 @@
 _LIT8( KThumbnailMimeImage, "image" );
 _LIT8( KThumbnailMimeVideo, "video" );
 _LIT8( KThumbnailMimeAudio, "audio" );
+_LIT8( KThumbnailMimeContact, "contact" );
 
 const TChar KThumbnailMimeSeparatorChar = '/';
 const TChar KThumbnailMimeWildCardChar = '*';
@@ -415,6 +416,7 @@
             "CThumbnailServer::ThreadFunctionL() -- CActiveScheduler::Start() out" );
         // Comes here if server gets shut down
         delete server;
+        server = NULL;
         CleanupStack::PopAndDestroy( scheduler );
         }
     }
@@ -442,7 +444,10 @@
         iSessionCount );
     iSessionCount--;
     
-    iProcessor->RemoveTasks(aSession);
+    if(iProcessor)
+        {
+        iProcessor->RemoveTasks(aSession);
+        }
     
     TN_DEBUG2( "CThumbnailServer::DropSession() aSession = 0x%08x", aSession );        
     
@@ -458,7 +463,7 @@
             {
             TN_DEBUG2( "CThumbnailServer::DropSession() - ref->iSession = 0x%08x", ref->iSession );
         
-            delete ref->iBitmap;            
+            delete ref->iBitmap;
             bpiter.RemoveCurrent();
                         
             TN_DEBUG2( "CThumbnailServer::DropSession() - deleted bitmap, left=%d", iBitmapPool.Count());
@@ -555,12 +560,12 @@
     if (!aCheckExist)
         {
         StoreForPathL( aPath )->StoreThumbnailL( aPath, aBitmap, aOriginalSize,
-                       aCropped, aThumbnailSize, aModified, aThumbFromPath );
+                       aCropped, aThumbnailSize, aModified, aThumbFromPath, EFalse );
         }    
     else if(BaflUtils::FileExists( iFs, aPath))
         {
         StoreForPathL( aPath )->StoreThumbnailL( aPath, aBitmap, aOriginalSize,
-                       aCropped, aThumbnailSize, aModified, aThumbFromPath );
+                       aCropped, aThumbnailSize, aModified, aThumbFromPath, EFalse );
         }
     else
         {
@@ -569,7 +574,7 @@
     
     if( iFetchedChecker )    
         {
-        iFetchedChecker->SetFetchResult( aPath, KErrNone );
+        iFetchedChecker->SetFetchResult( aPath, aThumbnailSize, KErrNone );
         }
     }
 
@@ -584,7 +589,7 @@
     TN_DEBUG3( "CThumbnailServer::FetchThumbnailL(aPath=%S aThumbnailSize=%d)", &aPath, aThumbnailSize );
     if( iFetchedChecker )
         {
-        TInt err( iFetchedChecker->LastFetchResult( aPath ) );
+        TInt err( iFetchedChecker->LastFetchResult( aPath, aThumbnailSize ) );
         if ( err == KErrNone ) // To avoid useless sql gets that fails for sure
             {
             // custom sizes are not stored to db, skip fetching
@@ -596,7 +601,7 @@
             TRAP( err, StoreForPathL( aPath )->FetchThumbnailL( aPath, aThumbnail, aData, aThumbnailSize, aOriginalSize) );
             if ( err != KErrNone )
                 {
-                iFetchedChecker->SetFetchResult( aPath, err );
+                iFetchedChecker->SetFetchResult( aPath, aThumbnailSize, err );
                 }
             }
         User::LeaveIfError( err );
@@ -665,7 +670,7 @@
     
     if( iFetchedChecker ) 
         {
-        iFetchedChecker->SetFetchResult( aPath, KErrNone );
+        iFetchedChecker->DeleteFetchResult( aPath );
         }
     }
 
@@ -851,7 +856,7 @@
         if ( ref->iSession == aRequestId.iSession && 
              ref->iRequestId == aRequestId.iRequestId )
             {            
-            delete ref->iBitmap;            
+            delete ref->iBitmap;
             bpiter.RemoveCurrent();                        
                         
             TN_DEBUG2( "CThumbnailServer::DequeTask() - deleted bitmap, left=%d", 
@@ -943,7 +948,7 @@
         }
     else
         {
-        if(iFormatting)
+        if( iFormatting )
            {
            TN_DEBUG1( "CThumbnailServer::StoreForDriveL() - FORMATTING! - ABORT");
            User::Leave( KErrNotSupported );
@@ -952,17 +957,31 @@
         TVolumeInfo volumeInfo;
         TInt err = iFs.Volume( volumeInfo, aDrive );
         
-        if ( err || volumeInfo.iDrive.iDriveAtt& KDriveAttRom ||
-            volumeInfo.iDrive.iDriveAtt& KDriveAttRemote ||
-            volumeInfo.iDrive.iMediaAtt& KMediaAttWriteProtected ||
-            volumeInfo.iDrive.iMediaAtt& KMediaAttLocked )
+        if ( err )
+            {
+            // Locked
+            TN_DEBUG2( "CThumbnailServer::StoreForDriveL() - err %d", err);
+            User::Leave( err);
+            }
+        else if( volumeInfo.iDrive.iMediaAtt& KMediaAttLocked )
             {
-            // We don't support ROM disks or remote mounts. Media
-            // must be read-write and not locked.
-            User::Leave( KErrAccessDenied);
+            TN_DEBUG1( "CThumbnailServer::StoreForDriveL() - locked");
+            User::Leave( KErrAccessDenied );
             }
-        
-        res = CThumbnailStore::NewL( iFs, aDrive, iImei, this );
+		else if ( volumeInfo.iDrive.iDriveAtt& KDriveAttRom ||
+            volumeInfo.iDrive.iDriveAtt& KDriveAttRemote ||
+            volumeInfo.iDrive.iMediaAtt& KMediaAttWriteProtected )
+            {
+            // We support ROM disks and remote disks in read only mode.
+            TN_DEBUG1( "CThumbnailServer::StoreForDriveL() - rom/remote/write protected");
+            res = CThumbnailStore::NewL( iFs, aDrive, iImei, this, ETrue );
+            }
+        else
+            {
+            TN_DEBUG1( "CThumbnailServer::StoreForDriveL() - normal");
+            res = CThumbnailStore::NewL( iFs, aDrive, iImei, this, EFalse );
+            }
+			
         CleanupStack::PushL( res );
         iStores.InsertL( aDrive, res );
         res->SetPersistentSizes(iPersistentSizes);
@@ -1056,6 +1075,7 @@
     if (store)
         {
         delete *store;
+        *store = NULL;
         iStores.Remove( aDrive );
         }
     }
@@ -1144,7 +1164,7 @@
           // If drive-list entry is zero, drive is not available
             continue;
            }
-            
+
         TInt err = iFs.Volume(volumeInfo, drive);
         TInt err_drive = iFs.Drive(driveInfo, drive);    
         
@@ -1166,8 +1186,15 @@
             // ignore errors
             TRAP_IGNORE( StoreForDriveL( drive ));
             
-            TN_DEBUG2( "CThumbnailServer::MemoryCardStatusChangedL() update KItemsleft == %d", KErrNotReady);
-            RProperty::Set(KTAGDPSNotification, KItemsleft, KErrNotReady );
+            TUint driveStatus(0);
+            DriveInfo::GetDriveStatus(iFs, drive, driveStatus);
+            TN_DEBUG2( "CThumbnailServer::MemoryCardStatusChangedL() driveStatus = %d", driveStatus);
+            if (!(driveStatus & DriveInfo::EDriveUsbMemory) && 
+			    !(driveStatus & DriveInfo::EDriveRemote))
+                {
+                TN_DEBUG2( "CThumbnailServer::MemoryCardStatusChangedL() update KItemsleft = %d", KErrNotReady);
+                RProperty::Set(KTAGDPSNotification, KItemsleft, KErrNotReady );
+                }
 			
             TInt index = iUnmountedDrives.Find( drive );
             
@@ -1252,62 +1279,45 @@
     TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL()");
     
     // 1. check path change
-    // 2. check orientation change
-    // 3. check timestamp change
-
-    TBool orientationChanged = EFalse;
+    // 2. check timestamp change
     TBool modifiedChanged = EFalse;
     
     CThumbnailStore* store = StoreForPathL( aPath );
    
-    // placeholder for orientation check
-    orientationChanged = EFalse;
-    
-    if (orientationChanged)
+    TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - exist");
+        
+    TBool exists = store->CheckModifiedByPathL(aPath, aModified, modifiedChanged);
+       
+    if(!exists)
         {
-        TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - orientation updated");
-        
-        // orientation updated, no need to check further
-        return ETrue;
+        TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - exists NO");
+        //not found, needs to be generated
+        return EFalse;
+        }
+    
+    TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified ?");
+    
+    if (modifiedChanged)
+        {
+        TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified YES");
+            
+        // delete old thumbs
+        store->DeleteThumbnailsL(aPath, ETrue);
+            
+        if( iFetchedChecker ) 
+            {
+            iFetchedChecker->DeleteFetchResult( aPath );
+            }
+            
+        // need to create new thumbs
         }
     else
         {
-        TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - exist");
-        
-        TBool exists = store->CheckModifiedByPathL(aPath, aModified, modifiedChanged);
-       
-        if(!exists)
-            {
-            TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - exists NO");
-            //not found, needs to be generated
-            return EFalse;
-            }
-        
-        TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified ?");
+        TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified NO");
         
-        if (modifiedChanged)
-            {
-            TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified YES");
-            
-            // delete old thumbs
-            store->DeleteThumbnailsL(aPath, ETrue);
-            
-            if( iFetchedChecker ) 
-                {
-                iFetchedChecker->SetFetchResult( aPath, KErrNone );
-                }
-            
-            // need to create new thumbs
-            }
-        else
-            {
-            TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified NO");
-            
-            // not modified
-            return ETrue;
-            }
+        // not modified
+        return ETrue;
         }
-  
     
     TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - no thumbs found, create new");
     
@@ -1326,8 +1336,7 @@
     
     if( iFetchedChecker ) 
         {
-        iFetchedChecker->SetFetchResult( aNewPath, iFetchedChecker->LastFetchResult(aCurrentPath) );
-        iFetchedChecker->SetFetchResult( aCurrentPath, KErrNone );
+        iFetchedChecker->RenameFetchResultL( aNewPath, aCurrentPath );
         }
     }
 
@@ -1338,8 +1347,7 @@
 TInt CThumbnailServer::MimeTypeFromFileExt( const TDesC& aFileName, TDataType& aMimeType )
     {
     TBool found = ETrue;
-    TParsePtrC parse( aFileName );
-    TPtrC ext( parse.Ext() );
+    TPtrC ext( aFileName.Right(KExtLength) ); // tparse panics with virtual URI
     
     if ( ext.CompareF( KJpegExt ) == 0 || ext.CompareF( KJpgExt ) == 0)
         {
@@ -1449,6 +1457,14 @@
         {
         aMimeType = TDataType( KMatroskaVideoMime );
         } 
+    else if ( ext.CompareF( KContactExt ) == 0 )
+        {
+        aMimeType = TDataType( KContactMime );
+        } 
+    else if ( ext.CompareF( KAlbumArtExt ) == 0 )
+        {
+        aMimeType = TDataType( KAlbumArtMime );
+        }
     else
         {
         aMimeType = TDataType( KNullDesC8 );
@@ -1486,6 +1502,10 @@
         {
         return TThumbnailPersistentSize::EAudio;
         }
+    else if (mediaType.Compare(KThumbnailMimeContact) == 0)
+        {
+        return TThumbnailPersistentSize::EContact;
+        }
 
     return TThumbnailPersistentSize::EUnknownSourceType;        
     }
@@ -1515,6 +1535,11 @@
         case EAudioFullScreenThumbnailSize:
             sourceType = TThumbnailPersistentSize::EAudio;
             break;
+        case EContactListThumbnailSize:
+        case EContactGridThumbnailSize:
+        case EContactFullScreenThumbnailSize:
+            sourceType = TThumbnailPersistentSize::EContact;
+            break;
         default:
             sourceType = TThumbnailPersistentSize::EUnknownSourceType;  
         }
@@ -1534,24 +1559,30 @@
          mimeType.CompareF( KJpeg2000Mime ) == 0 ||
          mimeType.CompareF( KGifMime ) == 0 ||
          mimeType.CompareF( KPngMime ) == 0 ||
-         mimeType.CompareF( KBmpMime ) == 0 ||
+         mimeType.CompareF( KSvgMime ) == 0 ||
          mimeType.CompareF( KMpgMime1 ) == 0 ||
          mimeType.CompareF( KMpeg4Mime ) == 0 ||
          mimeType.CompareF( KMp4Mime ) == 0 ||
          mimeType.CompareF( KAviMime ) == 0 ||
-         mimeType.CompareF( KVideo3gppMime ) == 0 ||
-         mimeType.CompareF( KVideoWmvMime ) == 0 ||
-         mimeType.CompareF( KRealVideoMime ) == 0 ||
          mimeType.CompareF( KMp3Mime ) == 0 ||
+         mimeType.CompareF( KNonEmbeddArtMime ) == 0 ||
+         mimeType.CompareF( KM4aMime ) == 0  ||
          mimeType.CompareF( KAacMime ) == 0 ||
          mimeType.CompareF( KWmaMime ) == 0 ||
+         mimeType.CompareF( KBmpMime ) == 0 ||         
+         mimeType.CompareF( KAudio3gppMime ) == 0 ||
+         mimeType.CompareF( KVideo3gppMime ) == 0 ||
          mimeType.CompareF( KAudioAmrMime ) == 0 ||
+         mimeType.CompareF( KVideoWmvMime ) == 0 ||
          mimeType.CompareF( KRealAudioMime ) == 0 ||
-         mimeType.CompareF( KM4aMime ) == 0  ||
-         mimeType.CompareF( KFlashVideoMime ) == 0 ||
+         mimeType.CompareF( KPmRealAudioPluginMime ) == 0 ||
          mimeType.CompareF( KPmRealVideoPluginMime ) == 0 ||
          mimeType.CompareF( KPmRealVbVideoPluginMime ) == 0 ||
-         mimeType.CompareF( KPmRealAudioPluginMime ) == 0 )
+         mimeType.CompareF( KRealVideoMime ) == 0 ||
+         mimeType.CompareF( KFlashVideoMime ) == 0 ||
+         mimeType.CompareF( KMatroskaVideoMime ) == 0 ||
+         mimeType.CompareF( KContactMime ) == 0 ||
+         mimeType.CompareF( KAlbumArtMime ) == 0 )
         {
         return ETrue;
         }
@@ -1585,6 +1616,7 @@
             "CThumbnailServer::E32Main() -- thread function out, result=%d",
             result );
         delete cleanup;
+        cleanup = NULL;
         }
     if ( result != KErrNone )
         {