Revision: 201013 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 14 Apr 2010 16:16:51 +0300
branchRCL_3
changeset 10 ee674526fac5
parent 9 dea39715fc05
child 11 85a88bc05e45
Revision: 201013 Kit: 201015
imagehandling_plat/thumbnailmanager_api/inc/thumbnailmanager.h
imagehandling_plat/thumbnailmanager_api/tsrc/conf/ThumbnailManagerTest.cfg
imagehandling_plat/thumbnailmanager_api/tsrc/group/bld.inf
imagehandling_plat/thumbnailmanager_api/tsrc/inc/ThumbnailManagerTest.h
imagehandling_plat/thumbnailmanager_api/tsrc/src/ThumbnailManagerTestBlocks.cpp
imagehandlingutilities/thumbnailmanager/inc/thumbnailmanagerconstants.h
imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/ThumbnailManager_0x102830AB_v9.20.4_SA_S60.50_Euro1.sis
imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/ThumbnailManager_0x102830AB_v9.20.5_SA_S60.50_Euro1.sis
imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/package.pkg
imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/stub.pkg
imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/thumbnailmanager_stub.sis
imagehandlingutilities/thumbnailmanager/sis/thumbnailmanagercenrep/package.pkg
imagehandlingutilities/thumbnailmanager/thumbagdaemon/inc/thumbagprocessor.h
imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp
imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailmanagerimpl.h
imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailrequestactive.h
imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailsession.h
imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailmanagerimpl.cpp
imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailrequestactive.cpp
imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailsession.cpp
imagehandlingutilities/thumbnailmanager/thumbnailserver/group/thumbnailserver.mmp
imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailfetchedchecker.h
imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailserver.h
imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailserversession.h
imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailsql.h
imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailstore.h
imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailfetchedchecker.cpp
imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp
imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserversession.cpp
imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp
--- a/imagehandling_plat/thumbnailmanager_api/inc/thumbnailmanager.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandling_plat/thumbnailmanager_api/inc/thumbnailmanager.h	Wed Apr 14 16:16:51 2010 +0300
@@ -548,6 +548,23 @@
       */
       virtual void UpdateThumbnailsL( const TThumbnailId aItemId, const TDesC& aPath,
                                       const TInt aOrientation, const TInt64 aModified, const TInt aPriority  ) = 0;
+      
+      /**
+       * Rename Thumbnails. This is an asynchronous
+       * operation, which always returns immediately.
+       *
+       * @since S60 v5.0
+       * @param aCurrentPath     Current path of the Thumbnail
+       * @param aNewPath         New path for the Thumbnail
+       * @param aPriority        Priority for this operation
+       * @return                 Thumbnail request ID. This can be used to
+       *                         cancel the request or change priority.
+       *                         The ID is specific to this CThumbnailManager
+       *                         instance and may not be shared with other
+       *                         instances.
+       */
+       virtual TThumbnailRequestId RenameThumbnailsL( const TDesC& aCurrentPath, 
+               const TDesC& aNewPath, TInt aPriority = CActive::EPriorityIdle ) = 0;
 
 };
 
--- a/imagehandling_plat/thumbnailmanager_api/tsrc/conf/ThumbnailManagerTest.cfg	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandling_plat/thumbnailmanager_api/tsrc/conf/ThumbnailManagerTest.cfg	Wed Apr 14 16:16:51 2010 +0300
@@ -15,7 +15,6 @@
 *
 */
 
-
 [StifSettings]
 TestThreadStackSize= 32768
 TestThreadMinHeap= 4096
@@ -37,25 +36,26 @@
 // ---------------------------------------------------------------------------
 [Define]
 
-KErrNotFound -1
-KErrNotSupported -5
-KErrArgument -6
+KErrNotFound      -1
+KErrGeneral       -2
+KErrNotSupported  -5
+KErrArgument      -6
 
 KMaxTInt 2147483647
 
 // Delay between test cases (milliseconds)
 KTestDelay 1000
 
-KOneSecondDelay 1000
-KFiveSecondDelay 5000
-KTenSecondDelay 5000
+KOneSecondDelay   1000
+KFiveSecondDelay  5000
+KTenSecondDelay   10000
 
 // A delay to make sure the client-server request to generate a thumbnail
 // reaches the server, but doesn't have enough time to complete yet
 // (milliseconds)
-KClientServerDelay 150
-KClientServerDelay2 25
-KClientServerDelay3 10
+KClientServerDelay   150
+KClientServerDelay2  25
+KClientServerDelay3  10
 
 // From TDisplayMode: value for 24-bit display mode
 EColor16M 8
@@ -83,7 +83,10 @@
 EVideoFullScreenThumbnailSize 7      
 EAudioGridThumbnailSize 8
 EAudioListThumbnailSize 9
-EAudioFullScreenThumbnailSize 10 
+EAudioFullScreenThumbnailSize 10
+EGridThumbnailSize = 11
+EListThumbnailSize = 12
+EFullScreenThumbnailSize = 13
 
 // Custom sizes
 KCustomSizeX 111
@@ -1594,24 +1597,17 @@
 
 
 // ---------------------------------------------------------------------------
-// Get thumbnail by id
+// Create thumbnail with id
 // ---------------------------------------------------------------------------
 [Test]
-title Get thumbnail by id
+title Create thumbnail with id
 create ThumbnailManagerTest tn
 tn CreateInstanceL
 tn SetDisplayModeL EColor16M
 
 tn SetThumbnailEnumSizeL EImageGridThumbnailSize
 tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg 99999
-tn DeleteThumbnails
-tn CreateThumbnails
-waittestclass tn
-
-pause KTenSecondDelay
-
-tn SetFlagsL EDoNotCreate
-tn GetThumbnailByIdL 99999
+tn GetThumbnailL
 waittestclass tn
 tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
 tn DeleteThumbnails
@@ -1794,7 +1790,19 @@
 tn GetThumbnailL
 allownextresult KErrNotFound
 waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance
 
+// delete thumbnail which is not in database yet
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
+tn CreateThumbnails
+tn DeleteThumbnails
+tn DeleteSourceInstance
+
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\Videoclip.mp4
+tn CreateThumbnails
 tn DeleteThumbnails
 tn DeleteSourceInstance
 
@@ -1804,89 +1812,10 @@
 [Endtest]
 
 // ---------------------------------------------------------------------------
-// Delete thumbnails by id
-// ---------------------------------------------------------------------------
-[Test]
-title Delete thumbnails by id
-create ThumbnailManagerTest tn
-tn CreateInstanceL
-tn SetDisplayModeL EColor16M
-
-tn SetThumbnailEnumSizeL EImageGridThumbnailSize
-tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg 99999
-tn DeleteThumbnails
-tn CreateThumbnails
-waittestclass tn
-
-pause KTenSecondDelay
-
-tn SetFlagsL EDoNotCreate
-tn GetThumbnailByIdL 99999
-waittestclass tn
-tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
-
-tn DeleteThumbnailsByIdL 99999
-pause KOneSecondDelay
-
-tn GetThumbnailByIdL 99999
-allownextresult KErrNotFound
-waittestclass tn
-
-tn DeleteSourceInstance
-tn DeleteInstance
-delete tn
-pause KTestDelay
-[Endtest]
-
-
-// ---------------------------------------------------------------------------
-// Update path
+// Delete thumbnail when requests are pending
 // ---------------------------------------------------------------------------
 [Test]
-title Update path
-create ThumbnailManagerTest tn
-tn CreateInstanceL
-tn SetDisplayModeL EColor16M
-
-tn SetThumbnailEnumSizeL EImageGridThumbnailSize
-tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg 99999
-tn DeleteThumbnails
-tn CreateThumbnails
-waittestclass tn
-tn DeleteSourceInstance
-
-pause KTenSecondDelay
-
-tn UpdatePathL 99999 \data\ThumbnailManagerTest\updated_path.bmp
-waittestclass tn
-
-pause KTenSecondDelay
-
-tn SetFlagsL EDoNotCreate
-tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
-tn GetThumbnailL
-allownextresult KErrNotFound
-waittestclass tn
-tn DeleteSourceInstance
-
-tn CreateSourceInstancePathL \data\ThumbnailManagerTest\updated_path.bmp 99999
-tn GetThumbnailByIdL 99999
-waittestclass tn
-tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
-tn DeleteSourceInstance
-tn DeleteThumbnailsByIdL 99999
-
-tn DeleteInstance
-delete tn
-pause KTestDelay
-[Endtest]
-
-
-// ---------------------------------------------------------------------------
-// Delete engine when requests are pending
-// ---------------------------------------------------------------------------
-[Test]
-title Delete engine when requests are pending
+title Delete thumbnail when requests are pending
 create ThumbnailManagerTest tn
 tn CreateInstanceL
 
@@ -1981,13 +1910,13 @@
 // Second request with negative priority
 tn SetThumbnailSizeL 1 1
 tn CreateSourceInstanceHandleL \data\ThumbnailManagerTest\TALL_400x800.bmp
-tn GetThumbnailL 0 -50
+tn GetThumbnailL 0 -100
 tn DeleteSourceInstance
 
 // Third request with positive priority
 tn SetThumbnailSizeL 40 30
 tn CreateSourceInstanceHandleL \data\ThumbnailManagerTest\SVG_640x480.svg
-tn GetThumbnailL 0 50
+tn GetThumbnailL 0 0
 tn DeleteSourceInstance
 
 // First request should complete first, since the server started processing
@@ -2120,9 +2049,9 @@
 
 tn DeleteSourceInstance
 
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
 tn CreateSourceInstancePathL \data\ThumbnailManagerTest\camera.jpg
 tn SetFlagsL EDoNotCreate
-tn SetThumbnailEnumSizeL EImageGridThumbnailSize
 tn GetThumbnailL
 waittestclass tn
 tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
@@ -2137,3 +2066,283 @@
 delete tn
 pause KTestDelay
 [Endtest]
+
+// ---------------------------------------------------------------------------
+// Load MP3 thumbnail with PNG album art
+// ---------------------------------------------------------------------------
+[Test]
+title Create MP3 PNG album art thumbnail
+create ThumbnailManagerTest tn
+tn CreateInstanceL
+tn SetDisplayModeL EColor16M
+
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\mp3_png.mp3
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EAudioFullScreenThumbnailSize
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EAudioFullScreenThumbnailSize EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance 
+
+tn DeleteInstance
+delete tn
+pause KTestDelay
+[Endtest]
+
+
+// ---------------------------------------------------------------------------
+// Test WMA png & empty album arts
+// ---------------------------------------------------------------------------
+[Test]
+title Test WMA png & empty album arts
+create ThumbnailManagerTest tn
+tn CreateInstanceL
+tn SetDisplayModeL EColor16M
+
+// try to create thumbnail from PNG
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\wma_png.wma
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EAudioFullScreenThumbnailSize
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance  
+
+// try to create thumbnail without album art
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\wma_empty.wma
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EAudioFullScreenThumbnailSize
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance 
+
+tn DeleteInstance
+delete tn
+pause KTestDelay
+[Endtest]
+
+// ---------------------------------------------------------------------------
+// Create thumbnail preview with EXIF 
+// ---------------------------------------------------------------------------
+[Test]
+title Create thumbnail preview with EXIF
+create ThumbnailManagerTest tn
+tn CreateInstanceL
+tn SetDisplayModeL EColor16M
+
+// jpg with exif
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn SetQualityPreferenceL EOptimizeForQualityWithPreview
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance 
+
+// png with exif
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\exif.png
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn SetQualityPreferenceL EOptimizeForQualityWithPreview
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance 
+
+// no exif
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\no_exif.jpg
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn SetQualityPreferenceL EOptimizeForQualityWithPreview
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance 
+
+tn DeleteInstance
+delete tn
+pause KTestDelay
+[Endtest]
+
+// ---------------------------------------------------------------------------
+// Create thumbnails by Url
+// ---------------------------------------------------------------------------
+[Test]
+title Create thumbnails by Url
+create ThumbnailManagerTest tn
+tn CreateInstanceL
+tn SetDisplayModeL EColor16M
+
+// try to create thumbnail from image
+tn CreateThumbnailsByUrlL \data\ThumbnailManagerTest\RGB_VGA.jpg
+waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance  
+
+// try to create thumbnail from music
+tn CreateThumbnailsByUrlL \data\ThumbnailManagerTest\mp3_png.mp3
+waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance  
+
+// try to create thumbnail from video
+tn CreateThumbnailsByUrlL \data\ThumbnailManagerTest\Videoclip.mp4
+waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance  
+
+tn DeleteInstance
+delete tn
+pause KTestDelay
+[Endtest]
+
+// ---------------------------------------------------------------------------
+// Get thumbnails
+// ---------------------------------------------------------------------------
+[Test]
+title Get thumbnails
+create ThumbnailManagerTest tn
+tn CreateInstanceL
+tn SetDisplayModeL EColor16M
+
+// Get thumbnail with url
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
+tn DeleteThumbnails
+tn CreateThumbnails
+waittestclass tn
+
+pause KTenSecondDelay
+
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance
+
+// Get thumbnail with EDoNotCreate flag on
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
+tn SetFlagsL EDoNotCreate
+tn DeleteThumbnails
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+tn DeleteThumbnails
+
+tn DeleteSourceInstance
+tn DeleteInstance
+delete tn
+pause KTestDelay
+[Endtest]
+
+// ---------------------------------------------------------------------------
+// Run multiple tests
+// ---------------------------------------------------------------------------
+[Test]
+title Run multiple tests
+create ThumbnailManagerTest tn
+tn CreateInstanceL
+tn SetDisplayModeL EColor16M
+
+// using path
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EImageFullScreenThumbnailSize
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageFullScreenThumbnailSize EColor16M
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL ECustomThumbnailSize
+tn SetThumbnailSizeL KCustomSizeX KCustomSizeY
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailL KCustomSizeX KCustomSizeY EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance 
+
+// mp3 using handle
+tn CreateSourceInstanceHandleL \data\ThumbnailManagerTest\mp3.mp3
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EAudioGridThumbnailSize
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EAudioGridThumbnailSize EColor16M
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL EAudioFullScreenThumbnailSize
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EAudioFullScreenThumbnailSize EColor16M
+tn DeleteThumbnails
+tn SetThumbnailEnumSizeL ECustomThumbnailSize
+tn SetThumbnailSizeL KCustomSizeX KCustomSizeY
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailL KCustomSizeX KCustomSizeY EColor16M
+tn DeleteThumbnails
+tn DeleteSourceInstance
+
+// corrupted file
+tn SetThumbnailEnumSizeL ECustomThumbnailSize
+tn SetThumbnailSizeL KCustomSizeX KCustomSizeY
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\not_jpg.jpg
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+tn DeleteSourceInstance
+tn CreateSourceInstanceBufferL \data\ThumbnailManagerTest\not_jpg.jpg image/jpeg
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+tn DeleteSourceInstance
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\not_3gp.3gp
+tn GetThumbnailL
+allownextresult KErrNotSupported
+waittestclass tn
+tn DeleteSourceInstance
+
+// delete one thumbnail
+tn SetThumbnailEnumSizeL EImageGridThumbnailSize
+tn CreateSourceInstancePathL \data\ThumbnailManagerTest\RGB_VGA.jpg
+tn DeleteThumbnails
+tn GetThumbnailL
+waittestclass tn
+tn CheckThumbnailCenrepL EImageGridThumbnailSize EColor16M
+tn DeleteThumbnails
+pause KTenSecondDelay
+tn SetFlagsL EDoNotCreate
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+
+// delete all persistent thumbnails created
+tn SetFlagsL EDefaultFlags
+tn CreateThumbnails
+waittestclass tn
+pause KTenSecondDelay
+tn DeleteThumbnails
+pause KTenSecondDelay
+tn SetFlagsL EDoNotCreate
+tn GetThumbnailL
+allownextresult KErrNotFound
+waittestclass tn
+tn DeleteThumbnails
+tn DeleteSourceInstance
+
+tn DeleteInstance
+delete tn
+pause KTestDelay
+[Endtest]
\ No newline at end of file
--- a/imagehandling_plat/thumbnailmanager_api/tsrc/group/bld.inf	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandling_plat/thumbnailmanager_api/tsrc/group/bld.inf	Wed Apr 14 16:16:51 2010 +0300
@@ -44,5 +44,10 @@
 ../data/mmc/ThumbnailManagerTest/TestMBM.mbm /epoc32/winscw/c/data/ThumbnailManagerTest/TestMBM.mbm
 ../data/mmc/ThumbnailManagerTest/mp3.mp3 /epoc32/winscw/c/data/ThumbnailManagerTest/mp3.mp3
 ../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/camera.jpg
-
+../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/mp3_png.mp3
+../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/no_exif.jpg
+../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/wma.wma
+../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/wma_empty.wma
+../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/wma_png.wma
+../data/mmc/ThumbnailManagerTest/camera.jpg /epoc32/winscw/c/data/ThumbnailManagerTest/exif.jpg
 //  End of File
--- a/imagehandling_plat/thumbnailmanager_api/tsrc/inc/ThumbnailManagerTest.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandling_plat/thumbnailmanager_api/tsrc/inc/ThumbnailManagerTest.h	Wed Apr 14 16:16:51 2010 +0300
@@ -146,7 +146,7 @@
         virtual TInt CheckDisplayModeL( CStifItemParser& aItem );
 
         virtual TInt DeleteThumbnails( CStifItemParser& aItem );
-        virtual TInt DeleteThumbnailsByIdL( CStifItemParser& aItem );
+        virtual TInt CreateThumbnailsByUrlL( CStifItemParser& aItem );
         
         virtual TInt CreateThumbnails( CStifItemParser& aItem );
         virtual TInt UpdatePathL( CStifItemParser& aItem );
--- a/imagehandling_plat/thumbnailmanager_api/tsrc/src/ThumbnailManagerTestBlocks.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandling_plat/thumbnailmanager_api/tsrc/src/ThumbnailManagerTestBlocks.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -87,7 +87,7 @@
         ENTRY( "SetDisplayModeL", CThumbnailManagerTest::SetDisplayModeL ),
         ENTRY( "CheckDisplayModeL", CThumbnailManagerTest::CheckDisplayModeL ),
         ENTRY( "DeleteThumbnails", CThumbnailManagerTest::DeleteThumbnails ),
-        ENTRY( "DeleteThumbnailsByIdL", CThumbnailManagerTest::DeleteThumbnailsByIdL ),
+        ENTRY( "CreateThumbnailsByUrlL", CThumbnailManagerTest::CreateThumbnailsByUrlL ),
         ENTRY( "CreateThumbnails", CThumbnailManagerTest::CreateThumbnails ),
         ENTRY( "UpdatePathL", CThumbnailManagerTest::UpdatePathL ),
         ENTRY( "GetSupportedMimeTypesL", CThumbnailManagerTest::GetSupportedMimeTypesL )
@@ -735,15 +735,86 @@
     return KErrNone;
     }
 
-TInt CThumbnailManagerTest::DeleteThumbnailsByIdL( CStifItemParser&  aItem )
+TInt CThumbnailManagerTest::CreateThumbnailsByUrlL( CStifItemParser&  aItem )
     {
+    _LIT( KPanicTxt, "CreateSrcPath" );
+    __ASSERT_ALWAYS( !iObjectSource, User::Panic( KPanicTxt, 0 ));
+
+    TPtrC path;
+    User::LeaveIfError( aItem.GetNextString( path ));
+
     TInt id = 0;
-    User::LeaveIfError( aItem.GetNextInt( id ));
+    aItem.GetNextInt( id );
+    
+    TFileName filePath( iDataPath );
+    filePath.Append( path );
+    filePath.ZeroTerminate();
+    
+    iLog->Log( _L( "CreateSourceInstancePathL - path = %S" ), &filePath );
+    
+    delete iObjectSource;
+    iObjectSource = NULL;
+    
+    iObjectSource = CThumbnailObjectSource::NewL( filePath, id );
     
-    iEngine->DeleteThumbnails( id );
+    id = iEngine->CreateThumbnails( *iObjectSource );
+    if (id < 0)
+        {
+        iLog->Log( _L( "CreateThumbnails - error %d" ), id );
+        return id;  
+        }
+    else
+        {
+        iPreviousRequestId = id;
+        iLog->Log( _L( "CreateThumbnails - request id %d" ), iPreviousRequestId );
+        }
+    
+    iCreateThumbnails = ETrue;
+    
     return KErrNone;
     }
+
+/*
+TInt CThumbnailManagerTest::GetThumbnailsByUrlL( CStifItemParser&  aItem )
+    {
+    _LIT( KPanicTxt, "CreateSrcPath" );
+    __ASSERT_ALWAYS( !iObjectSource, User::Panic( KPanicTxt, 0 ));
+
+    TPtrC path;
+    User::LeaveIfError( aItem.GetNextString( path ));
+
+    TInt id = 0;
+    aItem.GetNextInt( id );
     
+    TFileName filePath( iDataPath );
+    filePath.Append( path );
+    filePath.ZeroTerminate();
+    
+    iLog->Log( _L( "CreateSourceInstancePathL - path = %S" ), &filePath );
+    
+    delete iObjectSource;
+    iObjectSource = NULL;
+    
+    iObjectSource = CThumbnailObjectSource::NewL( filePath, id );
+    
+    id = iEngine->GetThumbnailL( *iObjectSource );
+    if (id < 0)
+        {
+        iLog->Log( _L( "GetThumbnails - error %d" ), id );
+        return id;  
+        }
+    else
+        {
+        iPreviousRequestId = id;
+        iLog->Log( _L( "GetThumbnails - request id %d" ), iPreviousRequestId );
+        }
+    
+    iCreateThumbnails = ETrue;
+    
+    return KErrNone;
+    }
+
+*/
     
 TInt CThumbnailManagerTest::CreateThumbnails( CStifItemParser& aItem )
     {
@@ -773,6 +844,7 @@
     return KErrNone;
     }
 
+
 TInt CThumbnailManagerTest::UpdatePathL( CStifItemParser& aItem )
     {
     _LIT( KPanicTxt, "UpdatePath" );
--- a/imagehandlingutilities/thumbnailmanager/inc/thumbnailmanagerconstants.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/inc/thumbnailmanagerconstants.h	Wed Apr 14 16:16:51 2010 +0300
@@ -50,9 +50,18 @@
 const TInt KDaemonProcessing = 0x00000040;
 
 //insert to temp table first wo indexing and move data to main table as batch
-const TUint KMaxBatchItems = 36;
+//actual batch size will vary and will be between min...max batch size values below
+//minimum batch size
+const TUint KMInBatchItems = 3;
+//maximum batch size
+const TUint KMaxBatchItems = 18;
+//Max allowed flush time
+const TUint KMaxFlushDelay = 3000; //ms
+
 //how many items daemon will query at once from MDS
 const TUint KMaxQueryItems = 100;
+// max items for PH & AllItems query
+const TUint KMaxQueryItems2 = 100;
 
 // maximum number of active client side queue requests
 const TUint KMaxClientRequests = 2;
@@ -432,7 +441,7 @@
      */
     EDeleteThumbnailsById,
     
-    EReserved1,
+    ERenameThumbnails,
     
     /**
      * Update thumbnails by given Id.
Binary file imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/ThumbnailManager_0x102830AB_v9.20.4_SA_S60.50_Euro1.sis has changed
Binary file imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/ThumbnailManager_0x102830AB_v9.20.5_SA_S60.50_Euro1.sis has changed
--- a/imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/package.pkg	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/package.pkg	Wed Apr 14 16:16:51 2010 +0300
@@ -17,7 +17,7 @@
 &EN
 
 ; Header
-#{"Thumbnail Manager"},(0x102830AB), 9, 20, 4, TYPE=SA, RU
+#{"Thumbnail Manager"},(0x102830AB), 9, 20, 5, TYPE=SA, RU
 
 ; Localised Vendor name
 %{"Nokia"}
--- a/imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/stub.pkg	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/stub.pkg	Wed Apr 14 16:16:51 2010 +0300
@@ -17,7 +17,7 @@
 &EN
 
 ; Header
-#{"ThumbnailManager"},(0x102830AB), 9, 20, 4, TYPE=SA
+#{"ThumbnailManager"},(0x102830AB), 9, 20, 5, TYPE=SA
 
 ; Localised Vendor name
 %{"Nokia"}
Binary file imagehandlingutilities/thumbnailmanager/sis/thumbnailmanager/thumbnailmanager_stub.sis has changed
--- a/imagehandlingutilities/thumbnailmanager/sis/thumbnailmanagercenrep/package.pkg	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/sis/thumbnailmanagercenrep/package.pkg	Wed Apr 14 16:16:51 2010 +0300
@@ -17,7 +17,7 @@
 &EN
 
 ; Header
-#{"Thumbnail Manager Cenrep"},(0x10202BE9), 9, 20, 4, TYPE=SP
+#{"Thumbnail Manager Cenrep"},(0x10202BE9), 9, 20, 5, TYPE=SP
 
 ; Localised Vendor name
 %{"Symbian Software Ltd."}
--- a/imagehandlingutilities/thumbnailmanager/thumbagdaemon/inc/thumbagprocessor.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbagdaemon/inc/thumbagprocessor.h	Wed Apr 14 16:16:51 2010 +0300
@@ -243,6 +243,13 @@
      */
     void UpdatePSValues(const TBool aDefine = EFalse);
        
+    /**
+     * Comparison function for logaritmic use of queue arrays
+     * 
+     * @since S60 v5.0
+     */
+    static TInt Compare(const TItemId& aLeft, const TItemId& aRight);
+        
 private:
     
     // not own
--- a/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -201,11 +201,62 @@
 // CThumbAGProcessor::HandleQueryNewResults()
 // -----------------------------------------------------------------------------
 //
-void CThumbAGProcessor::HandleQueryNewResults( CMdEQuery& /*aQuery*/,
-                                               const TInt /*aFirstNewItemIndex*/,
-                                               const TInt /*aNewItemCount*/ )
+void CThumbAGProcessor::HandleQueryNewResults( CMdEQuery& aQuery,
+                                               const TInt aFirstNewItemIndex,
+                                               const TInt aNewItemCount )
     {
-    // No implementation required
+    // PH & AllItems query results are handled here
+    if (aNewItemCount > 0)
+        {
+        if(&aQuery == iQueryPlaceholders)
+            {
+            TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults - iQueryPlaceholders, %d new", aNewItemCount);
+            
+            for(TInt i = aFirstNewItemIndex; i < iQueryPlaceholders->Count(); i++)
+                {    
+                const CMdEObject* object = &iQueryPlaceholders->Result(i);
+              
+                if(!object)
+                    {
+                    continue;
+                    }
+              
+                if(!object->Placeholder())
+                    {
+                    TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults %d not placeholder", object->Id());
+                    continue;
+                    }
+               
+                // ignore if fails
+                iPlaceholderQueue.InsertInOrder(object->Id(), Compare);               
+                }  
+            }
+        else if(&aQuery == iQueryAllItems)
+            {
+            TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults - QueryAllItems, %d new", aNewItemCount);
+    
+            for(TInt i = aFirstNewItemIndex; i < iQueryAllItems->Count(); i++)
+                {    
+                const CMdEObject* object = &iQueryAllItems->Result(i);
+               
+                if(!object)
+                    {
+                    continue;
+                    }
+               
+                if (iAddQueue.FindInOrder(object->Id(), Compare) == KErrNotFound && 
+                    iModifyQueue.FindInOrder(object->Id(), Compare) == KErrNotFound )
+                    {
+                    // ignore if fails
+                    iAddQueue.InsertInOrder(object->Id(), Compare);
+                    }
+                }
+            }    
+        }
+    else
+        {
+        TN_DEBUG1( "CThumbAGProcessor::HandleQueryNewResults - error, no new items");
+        }
     }
 
 // -----------------------------------------------------------------------------
@@ -221,67 +272,28 @@
         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - iQueryPlaceholders completed");
         
         iPlaceholderQueue.Reset();
-        // if no errors in query
-        if (aError == KErrNone )
+        
+        //free query
+        delete iQueryPlaceholders;
+        iQueryPlaceholders = NULL;
+       
+        if(iDoQueryAllItems)
             {
-            for(TInt i = 0; i < iQueryPlaceholders->Count(); i++)
-               {    
-               const CMdEObject* object = &iQueryPlaceholders->Result(i);
-              
-               if(!object)
-                   {
-                   continue;
-                   }
-              
-               if(!object->Placeholder())
-                   {
-                   TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted %d not placeholder", object->Id());
-                   continue;
-                   }
-              
-               /*if (iPlaceholderQueue.Find( object->Id() ) == KErrNotFound)
-                   {
-                   TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted %d added to placeholder queue", object->Id());*/
-                   TRAP_IGNORE( iPlaceholderQueue.AppendL( object->Id() )); 
-                 //}
-               }
-           }
-           delete iQueryPlaceholders;
-           iQueryPlaceholders = NULL;
-           
-           if(iDoQueryAllItems)
-               {
-               iDoQueryAllItems = EFalse;
-               TRAP_IGNORE(QueryAllItemsL());
-               }
+            iDoQueryAllItems = EFalse;
+            TRAP_IGNORE(QueryAllItemsL());
+            }
         }
     else if(&aQuery == iQueryAllItems)
         {
         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - QueryAllItems completed");
-        // if no errors in query
-        if (aError == KErrNone )
-            {
-            for(TInt i = 0; i < iQueryAllItems->Count(); i++)
-                {    
-                const CMdEObject* object = &iQueryAllItems->Result(i);
-               
-                if(!object)
-                    {
-                    continue;
-                    }
-               
-                if (iAddQueue.Find( object->Id() ) == KErrNotFound && iModifyQueue.Find( object->Id()) == KErrNotFound  )
-                    {
-                    TRAP_IGNORE( iAddQueue.AppendL( object->Id() ));
-                    }
-                }
+
 #ifdef _DEBUG
 TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted IN-COUNTERS---------- Amount: %d, Add",iQueryAllItems->Count());
 #endif
-            }
-            //free query
-            delete iQueryAllItems;
-            iQueryAllItems = NULL;
+       
+        //free query
+        delete iQueryAllItems;
+        iQueryAllItems = NULL;
         }
     else if(&aQuery == iQuery )
         {
@@ -302,7 +314,7 @@
                 {
                 TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() some result items missing");
                 
-                RArray<TItemId> iQueryQueueDelta;
+                RArray<TItemId> queryQueueDelta;
                 
                 TInt itemIndex(KErrNotFound);
                 
@@ -324,23 +336,26 @@
                      if(!found)
                          {
                          TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing from results item %d", iQueryQueue[queryItem] );
-                         iQueryQueueDelta.Append( iQueryQueue[queryItem] );
+                         
+                         // ignore if fails
+                         queryQueueDelta.InsertInOrder(iQueryQueue[queryItem], Compare);
                          }
                      }
                  
-                 TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing items total count %d", iQueryQueueDelta.Count()); 
+                 TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing items total count %d", queryQueueDelta.Count()); 
                  //cleanup from previous queue it item is not found from MDS
-                 while(iQueryQueueDelta.Count())
+                 while(queryQueueDelta.Count())
                      {
-                     itemIndex = iLastQueue->Find(iQueryQueueDelta[0]);
+                     itemIndex = iLastQueue->FindInOrder(queryQueueDelta[0], Compare);
+                     
                      if(itemIndex >= 0)
                          {
                          TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove items %d", iQueryQueue[0]);
                          iLastQueue->Remove( itemIndex );
                          }
-                     iQueryQueueDelta.Remove(0);
+                     queryQueueDelta.Remove(0);
                      }
-                 iQueryQueueDelta.Close();
+                 queryQueueDelta.Close();
                 }
             
             // no results, reset query
@@ -359,7 +374,7 @@
             //cleanup current queue
             while(iQueryQueue.Count())
                 {
-                itemIndex = iLastQueue->Find(iQueryQueue[0]);
+                itemIndex = iLastQueue->FindInOrder(iQueryQueue[0], Compare);
                 if(itemIndex >= 0)
                     {
                     iLastQueue->Remove( itemIndex );
@@ -479,9 +494,10 @@
         for (int i=0; i<aIDArray.Count(); i++)
             {
             // do not to append to Add queue if exist already in Add or 2nd Add queue (just processed)     
-            if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i] ) == KErrNotFound)
+            if (iAddQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound && 
+                i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound)
                 {
-                iAddQueue.AppendL(aIDArray[i]);
+                User::LeaveIfError(iAddQueue.InsertInOrder(aIDArray[i], Compare));    
                 }
             }
         }
@@ -490,12 +506,11 @@
         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
         
         if(iPHHarvesting)
-            {
-        
+            {        
             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting active, treat like add" );
             for (int i=0; i<aIDArray.Count(); i++)
                 {
-                TInt itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
+                TInt itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare);
                                 
                 if (itemIndex >= 0)
                     {
@@ -503,10 +518,11 @@
                     iPlaceholderQueue.Remove( itemIndex );
                     }
                 
-                if(iAddQueue.Find( aIDArray[i]) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i]) == KErrNotFound )
+                if(iAddQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound && 
+                   i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound)
                     {
                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to add queue");
-                    iAddQueue.Append( aIDArray[i]);
+                    User::LeaveIfError(iAddQueue.InsertInOrder(aIDArray[i], Compare));
                     }
                 }
             }
@@ -518,7 +534,7 @@
             
             for (int i=0; i<aIDArray.Count(); i++)
                 {
-                itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
+                itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare);
                 
                 if (itemIndex >= 0)
                     {
@@ -528,7 +544,7 @@
                 else
                     {
                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify");
-                    itemIndex = iAddQueue.Find( aIDArray[i] );
+                    itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare);
                                     
                     if (itemIndex >= 0)
                         {
@@ -536,9 +552,8 @@
                         iAddQueue.Remove( itemIndex );
                         }
 					else
-						{
-						
-						itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] );
+						{						
+						itemIndex = i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare);
                                     
 	                    if (itemIndex >= 0)
 	                        {
@@ -548,7 +563,7 @@
 					}
                     
                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue");
-                    iModifyQueue.AppendL(aIDArray[i]);
+                    User::LeaveIfError(iModifyQueue.InsertInOrder(aIDArray[i], Compare));
                     
                     SetForceRun( ETrue );
                     } 
@@ -562,14 +577,14 @@
             for (int i=0; i<aIDArray.Count(); i++)
                 {
                 // can be removed from Add queue
-                TInt itemIndex = iAddQueue.Find( aIDArray[i] );
+                TInt itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare);
                 if(itemIndex >= 0)
                     {
                     iAddQueue.Remove(itemIndex);
                     }
     
                 // ..and Modify Queue
-                itemIndex = iModifyQueue.Find( aIDArray[i] );
+                itemIndex = iModifyQueue.FindInOrder(aIDArray[i], Compare);
                 if(itemIndex >= 0)
                     {
                     iModifyQueue.Remove(itemIndex);
@@ -657,9 +672,10 @@
             if(iLastQueue == &iAddQueue || iLastQueue == &iModifyQueue)
                 {
                 TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() );
-                if(i2ndRoundGenerateQueue.Find(aObject->Id()) == KErrNotFound)
+                if(i2ndRoundGenerateQueue.FindInOrder(aObject->Id(), Compare) == KErrNotFound)
                     {
-                    i2ndRoundGenerateQueue.Append( aObject->Id() );
+                    // ignore if fails
+                    i2ndRoundGenerateQueue.InsertInOrder(aObject->Id(), Compare);
                     }
                 }
             
@@ -730,11 +746,11 @@
     TInt maxCount = aIDArray.Count();
         
     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
-    
+      
     for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++)
         {
         TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[i] );
-        iQueryQueue.Append( aIDArray[i] );
+        iQueryQueue.InsertInOrder(aIDArray[i], Compare);
         }
     
     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
@@ -836,7 +852,7 @@
     audioPHObjectCondition.SetPlaceholderOnly( ETrue );
     audioPHObjectCondition.SetNotPresent( ETrue );
     
-    iQueryPlaceholders->FindL();  
+    iQueryPlaceholders->FindL(KMaxTInt, KMaxQueryItems2);   
    
     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - end" );
     }
@@ -1009,7 +1025,7 @@
             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
             iProcessingCount--;
             
-            TInt itemIndex = iLastQueue->Find( object->Id());
+            TInt itemIndex = iLastQueue->FindInOrder(object->Id(), Compare);
             if(itemIndex >= 0)
                 {
                 iLastQueue->Remove(itemIndex);
@@ -1019,7 +1035,7 @@
             if ( object )
                 {
                 //remove item from queryQueue when request is issued 
-                itemIndex = iQueryQueue.Find( object->Id());
+                itemIndex = iQueryQueue.FindInOrder(object->Id(), Compare);
                 if(itemIndex >= 0)
                     {
                     iQueryQueue.Remove(itemIndex);
@@ -1044,9 +1060,10 @@
                 {
                 if(iLastQueue)
                     {
-                    if(iLastQueue->Find( iQueryQueue[0]) == KErrNotFound)
+                    if(iLastQueue->FindInOrder(iQueryQueue[0], Compare) == KErrNotFound)
                         {
-                        iLastQueue->Append(iQueryQueue[0]);
+                        //ignore if fails
+                        iLastQueue->InsertInOrder(iQueryQueue[0], Compare);
                         }
                     }
                 iQueryQueue.Remove(0);
@@ -1087,9 +1104,10 @@
                 {
                 if(iLastQueue)
                     {
-                    if(iLastQueue->Find( iQueryQueue[0]) == KErrNotFound)
+                    if(iLastQueue->FindInOrder(iQueryQueue[0], Compare) == KErrNotFound)
                         {
-                        iLastQueue->Append(iQueryQueue[0]);
+                        //ignore if fails
+                        iLastQueue->InsertInOrder(iQueryQueue[0], Compare);
                         }
                     }
                 iQueryQueue.Remove(0);
@@ -1349,13 +1367,6 @@
         return;
         }
         
-    if( !IsActive() )
-        {
-        SetActive();
-        TRequestStatus* statusPtr = &iStatus;
-        User::RequestComplete( statusPtr, KErrNone );
-        }
-    
     //check if forced run needs to continue
     if (iModifyQueue.Count())
         {
@@ -1366,6 +1377,14 @@
         iModify = EFalse;
         SetForceRun( EFalse );
         }
+    
+    if( !IsActive() && ((!iActive && !iQueryActive) || iForceRun ))
+        {
+        TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - Activated");
+        SetActive();
+        TRequestStatus* statusPtr = &iStatus;
+        User::RequestComplete( statusPtr, KErrNone );
+        }
 
     UpdatePSValues();
     }
@@ -1462,32 +1481,28 @@
         {
         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
 
-        itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
-                         
+        itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare);                        
         if(itemIndex >= 0)
             {
             iPlaceholderQueue.Remove(itemIndex);
             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" );
             }
                 
-        itemIndex = iAddQueue.Find( aIDArray[i] );
-        
+        itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare);       
         if(itemIndex >= 0)
             {
             iAddQueue.Remove(itemIndex);
             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" );
             }
 
-        itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] );
-                
+        itemIndex = i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare);               
         if(itemIndex >= 0)
             {
             i2ndRoundGenerateQueue.Remove(itemIndex);
             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - i2ndRoundGenerateQueue" );
             }
         
-        itemIndex = iModifyQueue.Find( aIDArray[i] );
-         
+        itemIndex = iModifyQueue.FindInOrder(aIDArray[i], Compare);       
         if(itemIndex >= 0)
             {
             iModifyQueue.Remove(itemIndex);
@@ -1499,34 +1514,19 @@
 		        }
             }
             
-        itemIndex = iQueryQueue.Find( aIDArray[i] );
-                     
+        itemIndex = iQueryQueue.FindInOrder(aIDArray[i], Compare);                    
         if(itemIndex >= 0)
             {
             iQueryQueue.Remove(itemIndex);
             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iQueryQueue" );
             }
-        
-        itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
-                      
+         
+        itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare); 
         if(itemIndex >= 0)
         	{
             iPlaceholderQueue.Remove(itemIndex);
             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" );
             }
-        
-        /*
-        if( aRemoveFromDelete )
-            {
-            itemIndex = iRemoveQueue.Find( aIDArray[i] );
-             
-            if(itemIndex >= 0)
-                {
-                iRemoveQueue.Remove(itemIndex);
-                TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" );
-                continue;
-                }
-            }*/
         }
     
     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
@@ -1593,7 +1593,7 @@
     
     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
     
-    iQueryAllItems->FindL();  
+    iQueryAllItems->FindL(KMaxTInt, KMaxQueryItems2);  
     
     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - end" );
     }
@@ -1811,4 +1811,15 @@
         }
     }
 
+// ---------------------------------------------------------------------------
+// CThumbAGProcessor::Compare
+// Comparison function for logaritmic use of queue arrays
+// ---------------------------------------------------------------------------
+//
+TInt CThumbAGProcessor::Compare(const TItemId& aLeft, const TItemId& aRight)
+    {  
+    return (aLeft - aRight);
+    }
+
+
 // End of file
--- a/imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailmanagerimpl.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailmanagerimpl.h	Wed Apr 14 16:16:51 2010 +0300
@@ -337,6 +337,23 @@
      void UpdateThumbnailsL( const TThumbnailId aItemId, const TDesC& aPath,
                              const TInt aOrientation, const TInt64 aModified, TInt aPriority );
 
+     /**
+      * Rename Thumbnails. This is an asynchronous
+      * operation, which always returns immediately.
+      *
+      * @since S60 v5.0
+      * @param aCurrentPath     Current path of the Thumbnail
+      * @param aNewPath         New path for the Thumbnail
+      * @param aPriority        Priority for this operation
+      * @return                 Thumbnail request ID. This can be used to
+      *                         cancel the request or change priority.
+      *                         The ID is specific to this CThumbnailManager
+      *                         instance and may not be shared with other
+      *                         instances.
+      */
+     TThumbnailRequestId RenameThumbnailsL( const TDesC& aCurrentPath, 
+             const TDesC& aNewPath, TInt aPriority = CActive::EPriorityIdle );
+     
 private:
 
     /**
--- a/imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailrequestactive.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailrequestactive.h	Wed Apr 14 16:16:51 2010 +0300
@@ -40,7 +40,8 @@
     EReqSetThumbnailBitmap = 3,
     EReqUpdateThumbnails = 4,
     EReqGetThumbnailHandleLater = 5,
-    EReqDeleteThumbnails = 6
+    EReqDeleteThumbnails = 6,
+    EReqRenameThumbnails = 7
 };
 
 /**
@@ -223,6 +224,17 @@
         const TInt aPriority );   
     
     /**
+     * Rename thumbnails.
+     *
+     * @since S60 v5.0
+     * @param aCurrentPath     Current path of the Thumbnail
+     * @param aNewPath         New path for the Thumbnail
+     * @param aPriority        Priority for this operation
+     */
+    void RenameThumbnails( const TDesC& aCurrentPath, const TDesC& aNewPath, 
+        const TInt aPriority );    
+    
+    /**
      * Start active request.
      *
      * @since S60 v5.0
--- a/imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailsession.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailclient/inc/thumbnailsession.h	Wed Apr 14 16:16:51 2010 +0300
@@ -192,6 +192,13 @@
     void UpdateThumbnails( const TDesC& aPath, const TInt aOrientation, const TInt64 aModified,
                            TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus);
 
+    /**
+     * Rename thumbnails.
+     *
+     * @since S60 v5.0
+     */
+    void RenameThumbnails( TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus );
+    
 private:
 
     /**
--- a/imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailmanagerimpl.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailmanagerimpl.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -147,7 +147,7 @@
     TInt aPriority, TBool aGeneratePersistentSizesOnly)
     {
     iRequestId++;
-    TN_DEBUG4( "CThumbnailManagerImpl::GetThumbnailL() URI==%S, iThumbnailSize==%d %d", &aObjectSource.Uri(), iThumbnailSize, iRequestId );
+    TN_DEBUG4( "CThumbnailManagerImpl::GetThumbnailL() URI==%S, iThumbnailSize==%d, req %d", &aObjectSource.Uri(), iThumbnailSize, iRequestId );
     
     __ASSERT_DEBUG(( iRequestId > 0 ), ThumbnailPanic( EThumbnailWrongId ));
 
@@ -208,7 +208,7 @@
     aThumbnailId, TAny* aClientData /*= NULL*/, TInt aPriority)
     {
     iRequestId++;
-    TN_DEBUG5( "CThumbnailManagerImpl::GetThumbnailL() reqid==%d, aThumbnailId==%d, iThumbnailSize==%d %d", iRequestId, aThumbnailId, iThumbnailSize, iRequestId );
+    TN_DEBUG4( "CThumbnailManagerImpl::GetThumbnailL() aThumbnailId==%d, iThumbnailSize==%d, req %d", aThumbnailId, iThumbnailSize, iRequestId );
 
     __ASSERT_DEBUG(( iRequestId > 0 ), ThumbnailPanic( EThumbnailWrongId ));
 
@@ -613,7 +613,7 @@
                                                TInt aPriority )
     {
     iRequestId++;
-    TN_DEBUG4( "CThumbnailManagerImpl::UpdateThumbnailsL() URI==%S, aItemId==%d %d", &aPath, aItemId, iRequestId); 
+    TN_DEBUG4( "CThumbnailManagerImpl::UpdateThumbnailsL() URI==%S, aItemId==%d, req %d", &aPath, aItemId, iRequestId); 
     
     __ASSERT_DEBUG(( iRequestId > 0 ), ThumbnailPanic( EThumbnailWrongId ));
     
@@ -633,6 +633,35 @@
     }
 
 // ---------------------------------------------------------------------------
+// CThumbnailManagerImpl::RenameThumbnailsL()
+// Renames thumbnails by given path
+// ---------------------------------------------------------------------------
+//
+TThumbnailRequestId CThumbnailManagerImpl::RenameThumbnailsL( const TDesC& aCurrentPath, 
+        const TDesC& aNewPath, TInt aPriority )
+    {
+    iRequestId++;
+    TN_DEBUG3( "CThumbnailManagerImpl::RenameThumbnailsL() URI==%S, req %d", &aCurrentPath, iRequestId); 
+    
+    __ASSERT_DEBUG(( iRequestId > 0 ), ThumbnailPanic( EThumbnailWrongId ));
+    
+    TInt priority = ValidatePriority(aPriority);
+    
+    CThumbnailRequestActive* getThumbnailActive = CThumbnailRequestActive::NewL
+        ( iFs, iSession, iObserver, iRequestId, priority, iRequestQueue );
+    CleanupStack::PushL( getThumbnailActive );
+    
+    getThumbnailActive->RenameThumbnails( aCurrentPath, aNewPath, priority );
+    
+    iRequestQueue->AddRequestL( getThumbnailActive );
+    CleanupStack::Pop( getThumbnailActive );
+    
+    iRequestQueue->Process();
+    
+    return iRequestId;
+    }
+
+// ---------------------------------------------------------------------------
 // CThumbnailManagerImpl::ValidatePriority()
 // Check that given priority is in range of CActive::TPriority 
 // ---------------------------------------------------------------------------
--- a/imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailrequestactive.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailrequestactive.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -186,7 +186,12 @@
                 iSession.DeleteThumbnails( iParams.iThumbnailId, iParamsPckg, iStatus );
                 }
             break;
-            } 
+            }
+        case EReqRenameThumbnails:
+            {
+            iSession.RenameThumbnails( iParamsPckg, iStatus );
+            break;
+            }  
         default:
             {
             break;
@@ -220,12 +225,15 @@
     
     iTimer->Cancel();
     
-    if (iRequestType == EReqDeleteThumbnails || iCanceled)
+    if (iRequestType == EReqDeleteThumbnails || iCanceled ||
+        iRequestType == EReqRenameThumbnails)
         {
+        TN_DEBUG1( "CThumbnailRequestActive::RunL() - rename/delete/canceled" );
+    
         iFile.Close();
         iMyFileHandle.Close();
     
-        // no action for delete or canceled request
+        // no action for delete/rename or canceled request
         iRequestQueue->RequestComplete(this);
         
 #ifdef _DEBUG
@@ -747,6 +755,22 @@
     }
 
 // ---------------------------------------------------------------------------
+// CThumbnailRequestActive::RenameThumbnails()
+// Rename thumbnails.
+// ---------------------------------------------------------------------------
+//
+void CThumbnailRequestActive::RenameThumbnails( const TDesC& aCurrentPath, 
+        const TDesC& aNewPath, const TInt aPriority )
+    {
+    iRequestType = EReqRenameThumbnails;
+    
+    iParams.iRequestId = iRequestId;
+    iParams.iPriority = aPriority;
+    iParams.iFileName = aCurrentPath;
+    iParams.iTargetUri = aNewPath;
+    }
+
+// ---------------------------------------------------------------------------
 // Request 2nd phase thumbnail
 // ---------------------------------------------------------------------------
 //
--- a/imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailsession.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailclient/src/thumbnailsession.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -338,6 +338,18 @@
             
     SendReceive( EUpdateThumbnails, args, aStatus );  
     }
+
+// ---------------------------------------------------------------------------
+// Rename thumbnails.
+// ---------------------------------------------------------------------------
+//
+void RThumbnailSession::RenameThumbnails( TThumbnailRequestParamsPckg& aParams, 
+                                          TRequestStatus& aStatus )
+    {
+    TIpcArgs args( &aParams, KCheckValue);
+            
+    SendReceive( ERenameThumbnails, args, aStatus ); 
+    }
     
 
 // End of file
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/group/thumbnailserver.mmp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/group/thumbnailserver.mmp	Wed Apr 14 16:16:51 2010 +0300
@@ -50,6 +50,7 @@
 SOURCE                  thumbnailcenrep.cpp 
 SOURCE                  thumbnailmemorycardobserver.cpp 
 SOURCE		        thumbnaildecodetask.cpp
+SOURCE                  thumbnailfetchedchecker.cpp
 #ifdef RD_MDS_2_5
 SOURCE			thumbnailmdsquerytask.cpp
 #endif // RD_MDS_2_5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailfetchedchecker.h	Wed Apr 14 16:16:51 2010 +0300
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+ *
+*/
+#ifndef THUMBNAILFETCHEDCHECKER_H
+#define THUMBNAILFETCHEDCHECKER_H
+
+#include <e32base.h>
+
+NONSHARABLE_CLASS( CThumbnailFetchedChecker ): public CBase
+    {
+public:
+    static CThumbnailFetchedChecker* NewL();
+    virtual ~CThumbnailFetchedChecker();
+public:
+    TInt LastFetchResult( const TDesC& aUri );
+    void SetFetchResult( const TDesC& aUri, TInt aError );
+    void Reset();
+private:
+    CThumbnailFetchedChecker();
+    
+    NONSHARABLE_CLASS( CEntry ) : public CBase
+        {
+    public:
+        static CEntry* New( const TDesC& aUri, TInt aError );
+        static TInt FindCB( const TDesC* aUri, const CEntry& aEntry );
+        static TInt InsertCB( const CEntry& aEntry1, const CEntry& aEntry2 );
+        CEntry();
+        virtual ~CEntry();
+    public:
+        HBufC* iUri;
+        TInt iError;
+        };
+
+private:
+    RPointerArray< CEntry > iNotFetched;
+};
+
+#endif // THUMBNAILFETCHEDCHECKER_H
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailserver.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailserver.h	Wed Apr 14 16:16:51 2010 +0300
@@ -45,6 +45,7 @@
 class CThumbnailServerSession;
 class CThumbnailDiskUnmountObserver;
 class CThumbnailMemoryCardObserver;
+class CThumbnailFetchedChecker;
 
 /**
  * Helper function to destroy all objects which are referred to
@@ -373,6 +374,15 @@
     TBool UpdateThumbnailsL( const TDesC& aPath,
                              const TInt aOrientation, const TInt64 aModified );
     
+    /**
+     * Rename thumbnails.
+     *
+     * @since S60 v5.0
+     * @param aCurrentPath     Current path of the Thumbnail
+     * @param aNewPath         New path for the Thumbnail
+     */
+    void RenameThumbnailsL( const TDesC& aCurrentPath, const TDesC& aNewPath );
+    
     /** 
      * Resolve mime type from file extension
      *
@@ -451,6 +461,7 @@
     
     TBool IsFormatting();
   
+    inline CThumbnailFetchedChecker& FetchedChecker() const { return *iFetchedChecker; }
 protected: // Functions from base classes
 
     /**
@@ -674,6 +685,11 @@
 #ifdef _DEBUG
     TUint32 iPlaceholderCounter;
 #endif
+    /**
+     * Fetched checker.
+     * Own.
+     */
+    CThumbnailFetchedChecker* iFetchedChecker;
 };
 
 #endif // THUMBNAILSERVER_H
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailserversession.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailserversession.h	Wed Apr 14 16:16:51 2010 +0300
@@ -254,6 +254,14 @@
     void UpdateThumbnailsL( const RMessage2& aMessage );
     
     /**
+     * Rename thumbnails.
+     * 
+     * @since S60 v5.0
+     * @param aMessage Message.
+     */
+    void RenameThumbnailsL( const RMessage2& aMessage );
+    
+    /**
      * Checks if client thread is still alive and RMessage2 handle valid.
      *
      * @since S60 v5.0
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailsql.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailsql.h	Wed Apr 14 16:16:51 2010 +0300
@@ -94,6 +94,7 @@
 _LIT( KThumbnailSqlParamData, ":Data" );
 _LIT( KThumbnailSqlParamFlags, ":Flags" );
 _LIT( KThumbnailSqlParamPath, ":Path" );
+_LIT( KThumbnailSqlParamNewPath, ":NewPath" );
 _LIT( KThumbnailSqlParamWidth, ":Width" );
 _LIT( KThumbnailSqlParamHeight, ":Height" );
 _LIT( KThumbnailSqlParamOriginalWidth, ":OrigWidth" );
@@ -199,6 +200,10 @@
         "WHERE NOT EXISTS (SELECT Path FROM ThumbnailInfo "
         "WHERE ThumbnailDeleted.Path = ThumbnailInfo.Path);" );
 
+// rename thumb
+_LIT8( KThumbnailRename, "UPDATE ThumbnailInfo SET Path = :NewPath WHERE Path = :Path;" );
+_LIT8( KThumbnailTempRename, "UPDATE TempThumbnailInfo SET Path = :NewPath WHERE Path = :Path;" );
+
 // reset blacklisted
 _LIT8( KThumbnailTouchBlacklistedRows, "UPDATE ThumbnailInfo SET Modified = 0 WHERE Flags & :Flag" );
 
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailstore.h	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailstore.h	Wed Apr 14 16:16:51 2010 +0300
@@ -273,6 +273,15 @@
                             TBool aTransaction = ETrue);
     
     /**
+     * Rename thumbnails.
+     *
+     * @since S60 v5.0
+     * @param aCurrentPath     Current path of the Thumbnail
+     * @param aNewPath         New path for the Thumbnail
+     */
+    void RenameThumbnailsL( const TDesC& aCurrentPath, const TDesC& aNewPath );    
+    
+    /**
      * Persistent sizes.
      *
      * @since S60 v5.0
@@ -325,7 +334,7 @@
      *
      * @since S60 v5.0
      */
-    TInt UpdateImeiL();
+    void UpdateImeiL();
     
     /**
      * Checks that database rowids match.
@@ -625,6 +634,18 @@
     RSqlStatement iStmt_KThumbnailSqlDeleteInfoByRowID;
     RSqlStatement iStmt_KThumbnailSqlDeleteInfoDataByRowID;
     RSqlStatement iStmt_KThumbnailSelectAllPaths;
+    RSqlStatement iStmt_KThumbnailRename;
+    RSqlStatement iStmt_KThumbnailTempRename;
+    
+    /**
+     * Dynamic batch size
+     */
+    TInt iBatchFlushItemCount;
+
+    /**
+     * Measure time spend in flush
+     */
+    TTime iStartFlush, iStopFlush;
 
 };
 // End of File
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailfetchedchecker.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -0,0 +1,174 @@
+/*
+* Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+ *
+*/
+
+#include "thumbnailfetchedchecker.h"
+
+const int KMaxStoredEntries = 50;
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CThumbnailFetchedChecker()
+// -----------------------------------------------------------------------------
+//
+CThumbnailFetchedChecker* CThumbnailFetchedChecker::NewL()
+    {
+    return new (ELeave) CThumbnailFetchedChecker();
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CThumbnailFetchedChecker()
+// -----------------------------------------------------------------------------
+//
+CThumbnailFetchedChecker::CThumbnailFetchedChecker()
+    {
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::~CThumbnailFetchedChecker()
+// -----------------------------------------------------------------------------
+//
+CThumbnailFetchedChecker::~CThumbnailFetchedChecker()
+    {
+    iNotFetched.ResetAndDestroy();
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::LastFetchResult()
+// -----------------------------------------------------------------------------
+//
+TInt CThumbnailFetchedChecker::LastFetchResult( const TDesC& aUri )
+    {
+    TInt i = iNotFetched.FindInOrder( aUri, CEntry::FindCB );
+    if ( i >= 0 && i < iNotFetched.Count() )
+        {
+        return iNotFetched[ i ]->iError;
+        }
+    return KErrNone;
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::SetFetchResult()
+// -----------------------------------------------------------------------------
+//
+void CThumbnailFetchedChecker::SetFetchResult( const TDesC& aUri, TInt aError )
+    {
+    if ( aError == KErrNone )
+        {
+        // Do not store successful results
+        TInt i = iNotFetched.FindInOrder( aUri, CEntry::FindCB );
+        if ( i >= 0 && i < iNotFetched.Count() )
+            {
+            delete iNotFetched[ i ];
+            iNotFetched.Remove( i );
+            }
+        }
+    else
+        {
+        // Add or update
+        CEntry* entry = CEntry::New( aUri, aError );
+        if ( entry )
+            {
+            TInt err = iNotFetched.Find( entry );
+            if ( err != KErrNotFound )
+                {
+                TInt i = iNotFetched.FindInOrder( aUri, CEntry::FindCB );
+                if ( i >= 0 && i < iNotFetched.Count() )
+                    {
+                    iNotFetched[ i ]->iError = aError;
+                    }
+                }
+            else 
+                {
+                if( iNotFetched.Count() < KMaxStoredEntries )
+                    {
+                    TInt err = iNotFetched.InsertInOrder( entry, CEntry::InsertCB );
+                    if ( err != KErrNone )
+                        {
+                        delete entry;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::Reset()
+// -----------------------------------------------------------------------------
+//
+void CThumbnailFetchedChecker::Reset()
+    {
+    iNotFetched.ResetAndDestroy();
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CEntry::New()
+// -----------------------------------------------------------------------------
+//
+CThumbnailFetchedChecker::CEntry* CThumbnailFetchedChecker::CEntry::New(
+        const TDesC& aUri, TInt aError )
+    {
+    CEntry* self = new (ELeave) CEntry();
+    if ( self )
+        {
+        self->iUri = aUri.Alloc();
+        self->iError = aError;
+        if ( !self->iUri )
+            {
+            delete self;
+            self = NULL;
+            }
+        }
+    return self;
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CEntry::FindCB()
+// -----------------------------------------------------------------------------
+//
+TInt CThumbnailFetchedChecker::CEntry::FindCB(
+    const TDesC* aUri, const CThumbnailFetchedChecker::CEntry& aEntry )
+    {
+    return aUri->CompareF( *( aEntry.iUri ) );
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CEntry::InsertCB()
+// -----------------------------------------------------------------------------
+//
+TInt CThumbnailFetchedChecker::CEntry::InsertCB(
+        const CThumbnailFetchedChecker::CEntry& aEntry1,
+        const CThumbnailFetchedChecker::CEntry& aEntry2 )
+    {
+    return aEntry1.iUri->CompareF( *( aEntry2.iUri ) );
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CEntry::CEntry()
+// -----------------------------------------------------------------------------
+//
+CThumbnailFetchedChecker::CEntry::CEntry()
+    {
+    }
+
+// -----------------------------------------------------------------------------
+// CThumbnailFetchedChecker::CEntry::~CEntry()
+// -----------------------------------------------------------------------------
+//
+CThumbnailFetchedChecker::CEntry::~CEntry()
+    {
+    delete iUri;
+    }
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -36,6 +36,7 @@
 #include "thumbnailcenrep.h"
 #include "thumbnailmemorycardobserver.h"
 #include "tmgetimei.h"
+#include "thumbnailfetchedchecker.h"
 
 
 _LIT8( KThumbnailMimeWildCard, "*" );
@@ -73,7 +74,7 @@
     ERequestThumbByBufferAsync,
     ERequestSetThumbnailByBuffer,
     EDeleteThumbnailsById,
-    EReserved1,
+    ERenameThumbnails,
     EUpdateThumbnails,
     ERequestSetThumbnailByBitmap,
     EThumbnailServerRequestCount,
@@ -96,7 +97,7 @@
     CPolicyServer::ECustomCheck,    // ERequestThumbByBufferAsync
     CPolicyServer::ECustomCheck,    // ERequestSetThumbnailByBuffer
     CPolicyServer::ECustomCheck,    // EDeleteThumbnailsById
-    CPolicyServer::ECustomCheck,    
+    CPolicyServer::ECustomCheck,    // ERenameThumbnails
     CPolicyServer::ECustomCheck,    // EUpdateThumbnails
     CPolicyServer::ECustomCheck,    // ERequestSetThumbnailByBitmap
     CPolicyServer::ECustomCheck,    // EThumbnailServerRequestCount
@@ -142,7 +143,8 @@
         case EGetMimeTypeList:
         case ERequestSetThumbnailByBuffer:
         case EDeleteThumbnailsById:
-        case EUpdateThumbnails:   
+        case EUpdateThumbnails:
+        case ERenameThumbnails:    
         case ERequestSetThumbnailByBitmap:
             {
             if( aMsg.HasCapability( ECapabilityReadDeviceData ) && 
@@ -152,8 +154,6 @@
                 }
             break;
             }
-
-        case EReserved1:
         case EThumbnailServerRequestCount:
         default:
             {
@@ -254,6 +254,7 @@
     //OpenStoresL();
     
     AddUnmountObserversL();
+    iFetchedChecker = CThumbnailFetchedChecker::NewL();
     }
 
 
@@ -267,6 +268,7 @@
 
     iShutdown = ETrue;
     
+    delete iFetchedChecker;
     delete iShutdownObserver;
     delete iProcessor;
     
@@ -536,6 +538,10 @@
         {
         TN_DEBUG1( "CThumbnailServer::StoreThumbnailL() - file doesn't exists anymore, skip store!");
         }
+    if( iFetchedChecker )    
+        {
+        iFetchedChecker->SetFetchResult( aPath, KErrNone );
+        }
     }
 
 
@@ -547,8 +553,23 @@
     aThumbnail, TDesC8* & aData, const TThumbnailSize aThumbnailSize, TSize &aOriginalSize )
     {
     TN_DEBUG3( "CThumbnailServer::FetchThumbnailL(aPath=%S aThumbnailSize=%d)", &aPath, aThumbnailSize );
-
-    StoreForPathL( aPath )->FetchThumbnailL( aPath, aThumbnail, aData, aThumbnailSize, aOriginalSize);
+    if( iFetchedChecker )
+        {
+        TInt err( iFetchedChecker->LastFetchResult( aPath ) );
+        if ( err == KErrNone ) // To avoid useless sql gets that fails for sure
+            {
+            TRAP( err, StoreForPathL( aPath )->FetchThumbnailL( aPath, aThumbnail, aData, aThumbnailSize, aOriginalSize) );
+            if ( err != KErrNone )
+                {
+                iFetchedChecker->SetFetchResult( aPath, err );
+                }
+            }
+        User::LeaveIfError( err );
+        }
+    else
+        {
+        StoreForPathL( aPath )->FetchThumbnailL( aPath, aThumbnail, aData, aThumbnailSize, aOriginalSize);
+        }
     }
 
 
@@ -600,6 +621,10 @@
     TN_DEBUG2( "CThumbnailServer::DeleteThumbnailsL(%S)", &aPath);
     
     StoreForPathL( aPath )->DeleteThumbnailsL( aPath );
+    if( iFetchedChecker ) 
+        {
+        iFetchedChecker->SetFetchResult( aPath, KErrNone );
+        }
     }
 
 // -----------------------------------------------------------------------------
@@ -1193,6 +1218,17 @@
     }
 
 // -----------------------------------------------------------------------------
+// Renames thumbnails.
+// -----------------------------------------------------------------------------
+//
+void CThumbnailServer::RenameThumbnailsL( const TDesC& aCurrentPath, const TDesC& aNewPath )
+    {
+    TN_DEBUG2( "CThumbnailServer::RenameThumbnailsL(%S)", &aCurrentPath);
+    
+    StoreForPathL( aCurrentPath )->RenameThumbnailsL( aCurrentPath, aNewPath );
+    }
+
+// -----------------------------------------------------------------------------
 // CThumbnailServer::MimeTypeFromFileExt()
 // -----------------------------------------------------------------------------
 //
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserversession.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserversession.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -133,7 +133,12 @@
                 {
                 UpdateThumbnailsL( aMessage );
                 break;
-                }                  
+                }       
+        case ERenameThumbnails:
+                {
+                RenameThumbnailsL( aMessage );
+                break;
+                } 
         default:
                 {
                 err = KErrUnknown;
@@ -338,6 +343,38 @@
     }
 
 // -----------------------------------------------------------------------------
+// CThumbnailServerSession::RenameThumbnailsL()
+// Rename thumbnails.
+// -----------------------------------------------------------------------------
+//
+void CThumbnailServerSession::RenameThumbnailsL( const RMessage2& aMessage )
+    {
+    if(aMessage.Int1() != KCheckValue)
+       {
+       TN_DEBUG1( "CThumbnailServerSession::RenameThumbnailsL() - error in aMessage - leaving" );
+       User::Leave(KErrArgument);
+       }
+    
+    // read message params
+    aMessage.ReadL( 0, iRequestParams );
+    const TThumbnailRequestParams& params = iRequestParams();
+    
+    // renaming only inside one store
+    if (params.iFileName.Left(1).CompareF( params.iTargetUri.Left(1) ) == 0)
+        {
+        Server()->RenameThumbnailsL( params.iFileName, params.iTargetUri );
+        
+        aMessage.Complete( KErrNone );
+        }
+    else
+        {
+        aMessage.Complete( KErrNotSupported );
+        }
+    
+    iMessage = RMessage2();
+    }
+
+// -----------------------------------------------------------------------------
 // CThumbnailServerSession::RequestThumbByIdAsyncL()
 // -----------------------------------------------------------------------------
 //
--- a/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp	Wed Mar 31 22:04:49 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp	Wed Apr 14 16:16:51 2010 +0300
@@ -35,7 +35,7 @@
 #include "thumbnailserver.h"
 
 
-_LIT8( KThumbnailSqlConfig, "page_size=16384; cache_size=32;" );
+_LIT8( KThumbnailSqlConfig, "page_size=1024; cache_size=32;" );
 
 const TInt KStreamBufferSize = 1024 * 8;
 const TInt KMajor = 3;
@@ -44,7 +44,7 @@
 const TInt KStoreUnrecoverableErr = KErrCorrupt;
 
 // Database path without drive letter
-_LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v3.db" );
+_LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v4.db" );
 
 _LIT( KDrv, ":");
 
@@ -167,10 +167,6 @@
         iDiskFullNotifier = NULL;
         }
 
-    if(!iServer->IsFormatting())
-        {
- 	    FlushCacheTable( ETrue );
-        }
     if( iAutoFlushTimer )
         {
         iAutoFlushTimer->Cancel();
@@ -178,6 +174,18 @@
         iAutoFlushTimer = NULL;
         }
     
+    if( iMaintenanceTimer )
+        {
+        iMaintenanceTimer->Cancel();
+        delete iMaintenanceTimer;
+        iMaintenanceTimer = NULL;
+        }
+    
+    if(!iServer->IsFormatting())
+        {
+ 	    FlushCacheTable( ETrue );
+        }
+    
     CloseStatements();   
     iDatabase.Close();
     
@@ -191,7 +199,7 @@
 //
 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)
+    iServer(aServer), iDiskFull(EFalse), iUnrecoverable(ETrue), iBatchFlushItemCount(KMInBatchItems)
     {
     // no implementation required
     }
@@ -293,18 +301,16 @@
                 checkError = CheckRowIDs();
                 }
             }
-        else
+
+        // if db file not found, wrong version, corrupted database or other error opening db
+        if ( err != KErrNone || checkError == KErrNotSupported )
             {
-            // if db file not found, wrong version, corrupted database or other error opening db
-            if ( checkError == KErrNotSupported || err != KErrNone )
-                {
-                CleanupClosePushL(iDatabase);
-                RecreateDatabaseL(ETrue);
-                CleanupStack::Pop(&iDatabase);
-                
-                aNewDatabase = ETrue;
-                }
-            }
+            CleanupClosePushL(iDatabase);
+            RecreateDatabaseL(ETrue);
+            CleanupStack::Pop(&iDatabase);
+            
+            aNewDatabase = ETrue;
+            }          
         }    
    
     // opened existing database file
@@ -319,7 +325,7 @@
         if(imeiError != KErrNone)
             {
             //take ownership
-            imeiError = UpdateImeiL();
+            TRAP(imeiError, UpdateImeiL() );
             
             //Touch blacklisted items
             TRAP(blistError, PrepareBlacklistedItemsForRetryL() );
@@ -332,9 +338,7 @@
             TRAP(blistError2, PrepareBlacklistedItemsForRetryL() );
             }
         
-        if(imeiError == KSqlErrCorrupt || imeiError == KErrCorrupt ||
-           blistError == KSqlErrCorrupt || blistError == KErrCorrupt || 
-           blistError2 == KSqlErrCorrupt || blistError2 == KErrCorrupt )
+        if(imeiError != KErrNone || blistError != KErrNone || blistError2 != KErrNone )
             {
             CleanupClosePushL(iDatabase);
             RecreateDatabaseL(ETrue);
@@ -745,31 +749,30 @@
 // UpdateImeiL()
 // -----------------------------------------------------------------------------
 //
-TInt CThumbnailStore::UpdateImeiL()
+void CThumbnailStore::UpdateImeiL()
     {
     TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" );
     RSqlStatement stmt;
     CleanupClosePushL( stmt );
             
-    TInt ret = stmt.Prepare( iDatabase, KThumbnailUpdateIMEI );
+    User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailUpdateIMEI ) );
     
     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei );
     User::LeaveIfError( paramIndex );
     User::LeaveIfError( stmt.BindText( paramIndex, iImei ));
     
-    TInt err =  stmt.Exec();
+    TInt err = stmt.Exec();
     
     if(err < 0)
         {
 #ifdef _DEBUG
-        TPtrC errorMsg2 = iDatabase.LastErrorMessage();
-        TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2);
+        TPtrC errorMsg = iDatabase.LastErrorMessage();
+        TN_DEBUG2( "RThumbnailTransaction::UpdateImeiL() lastError %S" , &errorMsg);
 #endif
-        return ret;
+        User::Leave(err);
         }
     
     CleanupStack::PopAndDestroy( &stmt );
-    return KErrNone;
     }
 
 // ---------------------------------------------------------------------------
@@ -961,6 +964,22 @@
 #endif
     User::LeaveIfError( err );
     
+    err = iStmt_KThumbnailRename.Prepare( iDatabase, KThumbnailRename );
+#ifdef _DEBUG
+    msg.Append( iDatabase.LastErrorMessage() );
+    TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailRename %S" , &msg );
+    msg.Zero();
+#endif
+    User::LeaveIfError( err );
+    
+    err = iStmt_KThumbnailTempRename.Prepare( iDatabase, KThumbnailTempRename );
+#ifdef _DEBUG
+    msg.Append( iDatabase.LastErrorMessage() );
+    TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailTempRename %S" , &msg );
+    msg.Zero();
+#endif
+    User::LeaveIfError( err );
+    
     TN_DEBUG1("CThumbnailStore::PrepareStatementsL() end");
     }
 
@@ -1005,6 +1024,8 @@
     iStmt_KThumbnailSqlDeleteInfoByRowID.Close();
     iStmt_KThumbnailSqlDeleteInfoDataByRowID.Close();
     iStmt_KThumbnailSelectAllPaths.Close();
+    iStmt_KThumbnailRename.Close();
+    iStmt_KThumbnailTempRename.Close();
     
     TN_DEBUG1("CThumbnailStore::CloseStatements() end");
     }
@@ -1347,10 +1368,11 @@
         found = ETrue;
         }
     
+    CleanupStack::PopAndDestroy( stmt );
+    
     // check if duplicate in Deleted
     if (found)
         {
-        CleanupStack::PopAndDestroy( stmt );
         stmt = &iStmt_KThumbnailSqlFindDeleted;
         CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));   
             
@@ -1360,6 +1382,8 @@
         
         rowStatus = stmt->Next();
         
+        CleanupStack::PopAndDestroy( stmt );
+        
         if(rowStatus == KSqlAtRow)
             {
             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate marked deleted" );
@@ -1372,8 +1396,6 @@
             }
         }
     
-    CleanupStack::PopAndDestroy( stmt );
-    
     return found;
     }
 
@@ -1695,10 +1717,10 @@
         rowStatus = stmt->Next();   
         }
     
-    CleanupStack::PopAndDestroy( stmt );
+    CleanupStack::PopAndDestroy( stmt_infodata );
     CleanupStack::PopAndDestroy( stmt_info );
-    CleanupStack::PopAndDestroy( stmt_infodata );
-    
+    CleanupStack::PopAndDestroy( stmt );
+        
     // if forcing instant delete
     if (aForce)
         {
@@ -1744,6 +1766,9 @@
         
         CleanupStack::PopAndDestroy( stmt_infodata );
         CleanupStack::PopAndDestroy( stmt_info );
+        
+		//remove delete mark
+        User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) );
         } 
     else
         {
@@ -1783,6 +1808,84 @@
     CleanupStack::PopAndDestroy( path );
     }
 
+// -----------------------------------------------------------------------------
+// Rename thumbnails
+// -----------------------------------------------------------------------------
+//
+void CThumbnailStore::RenameThumbnailsL( const TDesC& aCurrentPath, const TDesC& aNewPath )
+    {
+    TN_DEBUG2( "CThumbnailStore::RenameThumbnailsL(%S)", &aCurrentPath );
+    
+#ifdef _DEBUG
+    TTime aStart, aStop;
+    aStart.UniversalTime();
+#endif
+    
+    User::LeaveIfError( CheckDbState() );
+    
+    TInt paramIndex = 0;
+
+    HBufC* path = aCurrentPath.AllocLC();
+    TPtr ptr(path->Des());
+    StripDriveLetterL( ptr );
+    
+    HBufC* newPath = aNewPath.AllocLC();
+    TPtr ptr2(newPath->Des());
+    StripDriveLetterL( ptr2 );
+    
+    RThumbnailTransaction transaction( iDatabase );
+    CleanupClosePushL( transaction );    
+    transaction.BeginL();
+        
+    TN_DEBUG1( "CThumbnailStore::RenameThumbnailsL() -- TEMP TABLE" );
+    
+    RSqlStatement* stmt = NULL;
+    stmt = &iStmt_KThumbnailTempRename;
+    CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
+    
+    paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
+    User::LeaveIfError( paramIndex );
+    User::LeaveIfError( stmt->BindText( paramIndex, *path ));
+    
+    paramIndex = stmt->ParameterIndex( KThumbnailSqlParamNewPath );
+    User::LeaveIfError( paramIndex );
+    User::LeaveIfError( stmt->BindText( paramIndex, *newPath ));
+    
+    User::LeaveIfError( stmt->Exec() );
+    
+    TN_DEBUG1( "CThumbnailStore::RenameThumbnailsL() -- MAIN TABLE" );
+    
+    CleanupStack::PopAndDestroy( stmt );
+    stmt = &iStmt_KThumbnailRename;
+    CleanupStack::PushL(TCleanupItem(ResetStatement, stmt));
+    
+    paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath );
+    User::LeaveIfError( paramIndex );
+    User::LeaveIfError( stmt->BindText( paramIndex, *path ));
+    
+    paramIndex = stmt->ParameterIndex( KThumbnailSqlParamNewPath );
+    User::LeaveIfError( paramIndex );
+    User::LeaveIfError( stmt->BindText( paramIndex, *newPath ));
+    
+    User::LeaveIfError( stmt->Exec() );
+    
+    CleanupStack::PopAndDestroy( stmt );
+    
+    // if thumb was for some reason already marked deleted, clean from deleted
+    User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) );
+    
+    transaction.CommitL();
+    CleanupStack::PopAndDestroy( &transaction );
+    
+    CleanupStack::PopAndDestroy( newPath );
+    CleanupStack::PopAndDestroy( path );
+    
+#ifdef _DEBUG
+    aStop.UniversalTime();
+    TN_DEBUG2( "CThumbnailStore::RenameThumbnailsL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
+#endif      
+    }
+
 // ---------------------------------------------------------------------------
 // CThumbnailStore::PersistentSizes()
 // ---------------------------------------------------------------------------
@@ -1808,17 +1911,15 @@
         return;
         }
     
-    if(iBatchItemCount < KMaxBatchItems && !aForce)
+    if(iBatchItemCount < iBatchFlushItemCount && !aForce)
        {
        //some items in cache
        StartAutoFlush();
        return;
        }
     
-#ifdef _DEBUG
-    TTime aStart, aStop;
-    aStart.UniversalTime();
-#endif
+    
+    iStartFlush.UniversalTime();
     
     // Move data from temp table to main....
     TInt err_begin = iDatabase.Exec( KThumbnailBeginTransaction );
@@ -1872,15 +1973,26 @@
         TRAP_IGNORE(OpenDatabaseL(ETrue));
         }
     
+	//adjust batch size dynamically between min and max based on read flush speed. 
+    iStopFlush.UniversalTime();
+    TInt aFlushDelay = (TInt)iStopFlush.MicroSecondsFrom(iStartFlush).Int64()/1000;
+    TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", aFlushDelay);
+    
     //cache flushed
     iBatchItemCount = 0;
     
-#ifdef _DEBUG
-    aStop.UniversalTime();
-    TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
-#endif
+    //increase batch count if there room for one more item (based on average time per item)
+    if( aFlushDelay < KMaxFlushDelay && iBatchFlushItemCount < KMaxBatchItems )
+        {
+        iBatchFlushItemCount++;
+        }
+    //decrease batch count if we exeeced max time allowed in flushing the TEMP table
+    else if(aFlushDelay > KMaxFlushDelay && iBatchFlushItemCount > KMInBatchItems )
+        {
+        iBatchFlushItemCount--;
+        }
 
-    TN_DEBUG1("CThumbnailStore::FlushCacheTable() out");
+    TN_DEBUG2("CThumbnailStore::FlushCacheTable() out iBatchFlushItemCount = %d", iBatchFlushItemCount);
     }
 
 // -----------------------------------------------------------------------------