imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp
changeset 31 d429f823a6b7
parent 30 b67379558a75
child 33 221be23823c5
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp	Tue Jul 06 14:37:18 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp	Thu Jul 08 15:45:05 2010 +0300
@@ -166,9 +166,9 @@
 // Two-phased constructor.
 // ---------------------------------------------------------------------------
 //
-CThumbnailStore* CThumbnailStore::NewL( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer )
+CThumbnailStore* CThumbnailStore::NewL( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer, const TBool aReadOnly )
     {
-    CThumbnailStore* self = new( ELeave )CThumbnailStore( aFs, aDrive, aImei, aServer );
+    CThumbnailStore* self = new( ELeave )CThumbnailStore( aFs, aDrive, aImei, aServer, aReadOnly );
     CleanupStack::PushL( self );
     self->ConstructL();
     CleanupStack::Pop( self );
@@ -222,9 +222,9 @@
 // C++ default constructor can NOT contain any code, that might leave.
 // ---------------------------------------------------------------------------
 //
-CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): 
-    iFs( aFs ), iDrive( aDrive ), iDriveChar( 0 ), iBatchItemCount(0), iImei(aImei), 
-    iServer(aServer), iDiskFull(EFalse), iUnrecoverable(ETrue), iBatchFlushItemCount(KMInBatchItems)
+CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer, const TBool aReadOnly ): 
+    iFs( aFs ), iDrive( aDrive ), iDriveChar( 0 ), iBatchItemCount(0), iImei(aImei), iServer(aServer), iDiskFullNotifier(NULL), 
+    iDiskFull(EFalse), iActivityManager(NULL), iUnrecoverable(ETrue), iBatchFlushItemCount(KMInBatchItems), iReadOnly(aReadOnly)
     {
     // no implementation required
     }
@@ -241,31 +241,39 @@
 #ifdef _DEBUG
     iThumbCounter = 0;
 #endif
-    
-    HBufC* databasePath = HBufC::NewLC( KMaxFileName );
-    TPtr pathPtr = databasePath->Des();
-    User::LeaveIfError( RFs::DriveToChar( iDrive, iDriveChar ));
-    pathPtr.Append( iDriveChar );
-    pathPtr.Append( KThumbnailDatabaseName );
-    
-	//start disk space monitor
-    iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, 
-                                            KDiskFullThreshold,
-                                            pathPtr );
+    if(!iReadOnly)
+        {
+        HBufC* databasePath = HBufC::NewLC( KMaxFileName );
+        TPtr pathPtr = databasePath->Des();
+        User::LeaveIfError( RFs::DriveToChar( iDrive, iDriveChar ));
+        pathPtr.Append( iDriveChar );
+        pathPtr.Append( KThumbnailDatabaseName );
+        
+        //start disk space monitor
+        iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, 
+                                                KDiskFullThreshold,
+                                                pathPtr );
 
-    CleanupStack::PopAndDestroy( databasePath );
+        CleanupStack::PopAndDestroy( databasePath );
+    
+        TN_DEBUG2( "CThumbnailStore::ConstructL() drive: %d", iDrive );
     
-    TN_DEBUG2( "CThumbnailStore::ConstructL() drive: %d", iDrive );
+        OpenDatabaseL();
     
-    OpenDatabaseL();
+        // to monitor device activity
+        iActivityManager = CTMActivityManager::NewL( this, KStoreMaintenanceIdle);
+        iActivityManager->Start();
     
-    // to monitor device activity
-    iActivityManager = CTMActivityManager::NewL( this, KStoreMaintenanceIdle);
-    iActivityManager->Start();
-    
-    iDeleteThumbs = ETrue;
-    iCheckFilesExist = ETrue;
-    iLastCheckedRowID = -1;
+        iDeleteThumbs = ETrue;
+        iCheckFilesExist = ETrue;
+        }
+    else
+        {
+	    TN_DEBUG1( "CThumbnailStore::ConstructL() - read only, dymmy mode..." );
+        iDeleteThumbs = EFalse;
+        iCheckFilesExist = EFalse;
+        iLastCheckedRowID = -1;
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -1121,6 +1129,12 @@
 	const TThumbnailSize& aThumbnailSize, const TInt64 aModified, const TBool aThumbFromPath )
     {
     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( private ) in" );
+    
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::StoreThumbnailL() read only, skip..." );
+        return;
+        }
 
 #ifdef _DEBUG
     TTime aStart, aStop;
@@ -1272,6 +1286,12 @@
     {
     TSize thumbSize = aThumbnail->SizeInPixels();
     TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( public ) aThumbnailSize = %d, aThumbnailSize(%d,%d) IN", aThumbnailSize, thumbSize.iWidth, thumbSize.iHeight );
+    
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::StoreThumbnailL() read only, skip..." );
+        return;
+        }
 
     __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer ));
     
@@ -1319,17 +1339,20 @@
                 CleanupStack::PushL( data );
                 
                 CImageEncoder* encoder = NULL;
-                TRAPD( decErr, encoder = CExtJpegEncoder::DataNewL( CExtJpegEncoder::EHwImplementation, data, CImageEncoder::EOptionAlwaysThread ) );
+				
+				CImageEncoder::TOptions options = ( CImageEncoder::TOptions )( CImageEncoder::EOptionAlwaysThread );
+				
+                TRAPD( decErr, encoder = CExtJpegEncoder::DataNewL( CExtJpegEncoder::EHwImplementation, data, options ) );
                 if ( decErr != KErrNone )
                     {
                     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( public ) - HW CExtJpegEncoder failed %d", decErr);
                 
-                    TRAPD( decErr, encoder = CExtJpegEncoder::DataNewL( CExtJpegEncoder::ESwImplementation, data, CImageEncoder::EOptionAlwaysThread ) );
+                    TRAPD( decErr, encoder = CExtJpegEncoder::DataNewL( CExtJpegEncoder::ESwImplementation, data, options ) );
                     if ( decErr != KErrNone )
                         {
                         TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( public ) - SW CExtJpegEncoder failed %d", decErr);
                     
-                        TRAPD( decErr, encoder = CImageEncoder::DataNewL( data,  KJpegMime(), CImageEncoder::EOptionAlwaysThread ) );
+                        TRAPD( decErr, encoder = CImageEncoder::DataNewL( data,  KJpegMime(), options ) );
                         if ( decErr != KErrNone )
                             {
                             TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( public ) - CImageEncoder failed %d", decErr);
@@ -1362,7 +1385,7 @@
                 
                 // Set some format specific data
                 imageData->iSampleScheme = TJpegImageData::EColor444;
-                imageData->iQualityFactor = 75;
+                imageData->iQualityFactor = 80;
                 
                 // imageData - ownership passed to frameImageData after AppendImageData
                 User::LeaveIfError(frameImageData->AppendImageData(imageData));
@@ -1432,6 +1455,12 @@
 TBool CThumbnailStore::FindDuplicateL( const TDesC& aPath, const TThumbnailSize& aThumbnailSize )
     {
     TN_DEBUG1( "CThumbnailStore::FindDuplicateL()" );
+	
+	if(iReadOnly)
+		{
+		TN_DEBUG1( "CThumbnailStore::FindDuplicateL() read only, skip..." );
+		return EFalse;
+		}
     
     User::LeaveIfError( CheckDbState() );
     
@@ -1528,6 +1557,12 @@
     {
     TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() aSourceType == %d", aSourceType );
     
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::GetMissingSizesL() read only, skip..." );
+		return;
+        }
+    
     User::LeaveIfError( CheckDbState() );
     
     HBufC* path = aPath.AllocLC();
@@ -1637,6 +1672,12 @@
     {
     TN_DEBUG3( "CThumbnailStore::FetchThumbnailL(%S) aThumbnailSize==%d", &aPath, aThumbnailSize );
     
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() read only, skip..." );
+        User::Leave( KErrNotFound );
+        }
+    
     User::LeaveIfError( CheckDbState() );
     
     HBufC* path = aPath.AllocLC();
@@ -1761,6 +1802,12 @@
     {
     TN_DEBUG2( "CThumbnailStore::DeleteThumbnailsL(%S)", &aPath );
 
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsL() read only, skip..." );
+        return;
+        }
+    
 #ifdef _DEBUG
     TTime aStart, aStop;
     aStart.UniversalTime();
@@ -1960,6 +2007,12 @@
     {
     TN_DEBUG2( "CThumbnailStore::RenameThumbnailsL(%S)", &aCurrentPath );
     
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::RenameThumbnailsL() read only, skip..." );
+        return;
+        }
+    
 #ifdef _DEBUG
     TTime aStart, aStop;
     aStart.UniversalTime();
@@ -2049,6 +2102,12 @@
     
     StopAutoFlush();
     
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::FlushCacheTable() read only, skip..." );
+        return;
+        }
+    
     if(iBatchItemCount <= 0 || CheckDbState() != KErrNone)
         {
         // cache empty or db unusable
@@ -2190,6 +2249,12 @@
     {
     TN_DEBUG1( "CThumbnailStore::StartAutoFlush()" );
     
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::StartAutoFlush() read only, skip..." );
+        return;
+        }
+    
     TInt err = KErrNone;
     
     if( iAutoFlushTimer )
@@ -2371,6 +2436,13 @@
     {
     TN_DEBUG2( "CThumbnailStore::CheckModifiedByPathL() %S", &aPath);
     
+    if(iReadOnly)
+    	{
+    	TN_DEBUG1( "CThumbnailStore::CheckModifiedByPathL() read only, skip..." );
+		modifiedChanged = EFalse;
+    	return ETrue;
+    	}
+	
     User::LeaveIfError( CheckDbState() );
     
     HBufC* path = aPath.AllocLC();
@@ -2450,6 +2522,16 @@
     return ret;
 }
 	
+
+// -----------------------------------------------------------------------------
+// IsReadOnly()
+// -----------------------------------------------------------------------------
+//
+TBool CThumbnailStore::IsReadOnly()
+    {
+    return iReadOnly;
+    }
+
 // -----------------------------------------------------------------------------
 // PrepareBlacklistedItemsForRetryL()
 // -----------------------------------------------------------------------------
@@ -2480,6 +2562,12 @@
 TInt CThumbnailStore::DeleteMarkedL()
     {
     TN_DEBUG1( "CThumbnailStore::DeleteMarkedL()" );
+    
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::DeleteMarkedL() read only, skip..." );
+        return KErrAccessDenied;
+        }
    
 #ifdef _DEBUG
     TTime aStart, aStop;
@@ -2571,6 +2659,12 @@
 TInt CThumbnailStore::FileExistenceCheckL()
     {
     TN_DEBUG1( "CThumbnailStore::FileExistenceCheckL()" );
+	
+    if(iReadOnly)
+		{
+		TN_DEBUG1( "CThumbnailStore::FileExistenceCheckL() read only, skip..." );
+		return ETrue;
+		}
     
 #ifdef _DEBUG
     TTime aStart, aStop;
@@ -2693,7 +2787,7 @@
 //
 TInt CThumbnailStore::CheckDbState()
     {
-    if (iUnrecoverable)
+    if (iUnrecoverable && !iReadOnly)
         {
         TN_DEBUG1( "CThumbnailStore::CheckDbState() - database in unrecoverable state" );
         __ASSERT_DEBUG( !iUnrecoverable, ThumbnailPanic( EThumbnailDatabaseUnrecoverable ));
@@ -2723,6 +2817,11 @@
 
 TBool CThumbnailStore::IsDiskFull()
     {
+    if(iReadOnly)
+        {
+        TN_DEBUG1( "CThumbnailStore::IsDiskFull() read only, skip..." );
+        return EFalse;
+        }
     return iDiskFull;
     }
 
@@ -2734,6 +2833,12 @@
     {
     TN_DEBUG2( "CThumbnailStore::ActivityChanged() aActive == %d", aActive);
     
+    if( iReadOnly )
+        {
+        TN_DEBUG1( "CThumbnailStore::ActivityChanged() read only, skip..." );
+        return;
+        }
+    
     if( aActive )
         {
         iIdle = EFalse;