imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp
changeset 14 2edacbf5d3f9
parent 1 235a7fc86938
child 15 7197e789b953
equal deleted inserted replaced
1:235a7fc86938 14:2edacbf5d3f9
    20 #include <e32cmn.h>
    20 #include <e32cmn.h>
    21 #include <fbs.h>
    21 #include <fbs.h>
    22 #include <imageconversion.h>
    22 #include <imageconversion.h>
    23 #include <e32base.h>
    23 #include <e32base.h>
    24 #include <exifread.h>
    24 #include <exifread.h>
    25 
    25 #include <bautils.h>  
    26 #include <iclextjpegapi.h>
    26 #include <IclExtJpegApi.h>
       
    27 
    27 #include "thumbnailstore.h"
    28 #include "thumbnailstore.h"
    28 #include "thumbnailsql.h"
    29 #include "thumbnailsql.h"
    29 #include "thumbnaillog.h"
    30 #include "thumbnaillog.h"
    30 #include "thumbnailmanageruids.hrh"
    31 #include "thumbnailmanageruids.hrh"
    31 #include "thumbnailcenrep.h"
    32 #include "thumbnailcenrep.h"
    32 #include "thumbnailpanic.h"
    33 #include "thumbnailpanic.h"
    33 #include "thumbnailmanagerconstants.h"
    34 #include "thumbnailmanagerconstants.h"
    34 #include "thumbnailserver.h"
    35 #include "thumbnailserver.h"
    35 
    36 
    36 
    37 
    37 
       
    38 _LIT8( KThumbnailSqlConfig, "page_size=16384; cache_size=32;" );
    38 _LIT8( KThumbnailSqlConfig, "page_size=16384; cache_size=32;" );
    39 
    39 
    40 const TInt KStreamBufferSize = 1024 * 8;
    40 const TInt KStreamBufferSize = 1024 * 8;
    41 const TInt KMajor = 3;
    41 const TInt KMajor = 3;
    42 const TInt KMinor = 2;
    42 const TInt KMinor = 2;
    43 
    43 
    44 // Database path without drive letter
    44 // Database path without drive letter
    45 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v2.db" );
    45 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v3.db" );
       
    46 
       
    47 _LIT( KDrv, ":");
    46 
    48 
    47 // Allow access to database only for the server process
    49 // Allow access to database only for the server process
    48 const TSecurityPolicy KThumbnailDatabaseSecurityPolicy( TSecureId(
    50 const TSecurityPolicy KThumbnailDatabaseSecurityPolicy( TSecureId(
    49     THUMBNAIL_MANAGER_SERVER_UID ));
    51     THUMBNAIL_MANAGER_SERVER_UID ));
    50 
    52 
    72         iState = EOpen;
    74         iState = EOpen;
    73         }
    75         }
    74     else
    76     else
    75         {
    77         {
    76         iState = EError;
    78         iState = EError;
       
    79 #ifdef _DEBUG
       
    80     TPtrC errorMsg = iDatabase.LastErrorMessage();
       
    81     TN_DEBUG3( "RThumbnailTransaction::BeginL() lastError %S, ret = %d" , &errorMsg, err);
       
    82 #endif
    77         User::Leave( err );
    83         User::Leave( err );
    78         }
    84         }
    79     }
    85     }
    80 
    86 
    81 
    87 
    96 // RThumbnailTransaction::CommitL()
   102 // RThumbnailTransaction::CommitL()
    97 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
    98 //
   104 //
    99 void RThumbnailTransaction::CommitL()
   105 void RThumbnailTransaction::CommitL()
   100     {
   106     {
   101     User::LeaveIfError( iDatabase.Exec( KThumbnailCommitTransaction ));
   107     TInt ret = iDatabase.Exec( KThumbnailCommitTransaction );
       
   108     
       
   109 #ifdef _DEBUG
       
   110     TPtrC errorMsg = iDatabase.LastErrorMessage();
       
   111     TN_DEBUG3( "RThumbnailTransaction::CommitL() lastError %S, ret = %d" , &errorMsg, ret);
       
   112 #endif  
       
   113     User::LeaveIfError( ret );
       
   114     
   102     iState = EClosed;
   115     iState = EClosed;
   103     }
   116     }
   104 
   117 
   105 
   118 
   106 // ---------------------------------------------------------------------------
   119 // ---------------------------------------------------------------------------
   141 //
   154 //
   142 CThumbnailStore::~CThumbnailStore()
   155 CThumbnailStore::~CThumbnailStore()
   143     {
   156     {
   144     TN_DEBUG1( "CThumbnailStore::~CThumbnailStore()" );
   157     TN_DEBUG1( "CThumbnailStore::~CThumbnailStore()" );
   145     
   158     
   146     delete iDiskFullNotifier;
   159     if(iActivityManager)
   147     iDiskFullNotifier = NULL; 
   160         {
       
   161         delete iActivityManager;
       
   162         iActivityManager = NULL;
       
   163         }
       
   164     
       
   165     if(iDiskFullNotifier)
       
   166         {
       
   167         delete iDiskFullNotifier;
       
   168         iDiskFullNotifier = NULL;
       
   169         }
   148 
   170 
   149     if(!iServer->IsFormatting())
   171     if(!iServer->IsFormatting())
   150         {
   172         {
   151  	    FlushCacheTable( ETrue );
   173  	    FlushCacheTable( ETrue );
   152         }
   174         }
   192     TChar driveChar = 0;
   214     TChar driveChar = 0;
   193     User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar ));
   215     User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar ));
   194     pathPtr.Append( driveChar );
   216     pathPtr.Append( driveChar );
   195     pathPtr.Append( KThumbnailDatabaseName );
   217     pathPtr.Append( KThumbnailDatabaseName );
   196     
   218     
       
   219 	//start disk space monitor
   197     iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, 
   220     iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, 
   198                                             KDiskFullThreshold,
   221                                             KDiskFullThreshold,
   199                                             pathPtr );
   222                                             pathPtr );
   200 
   223 
       
   224     CleanupStack::PopAndDestroy( databasePath );
       
   225     
       
   226     OpenDatabaseL();
       
   227              
       
   228     // to monitor device activity
       
   229     iActivityManager = CTMActivityManager::NewL( this, KStoreMaintenanceIdle);
       
   230     iActivityManager->Start();
       
   231     
       
   232     // once in every mount
       
   233     iDeleteThumbs = ETrue;
       
   234     iCheckFilesExist = ETrue;
       
   235     iLastCheckedRowID = -1;
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // OpenDatabaseL database file
       
   240 // ---------------------------------------------------------------------------
       
   241 TInt CThumbnailStore::OpenDatabaseFileL()
       
   242     {
       
   243     TN_DEBUG1( "CThumbnailStore::OpenDatabaseFile()" );
       
   244     HBufC* databasePath = HBufC::NewLC( KMaxFileName );
       
   245     TPtr pathPtr = databasePath->Des();
       
   246     TChar driveChar = 0;
       
   247     User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar ));
       
   248     pathPtr.Append( driveChar );
       
   249     pathPtr.Append( KThumbnailDatabaseName );
       
   250     
       
   251     TInt ret = iDatabase.Open( pathPtr );
       
   252     CleanupStack::PopAndDestroy( databasePath );
       
   253     return ret;
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // OpenDatabaseL database
       
   258 // ---------------------------------------------------------------------------
       
   259 TInt CThumbnailStore::OpenDatabaseL()
       
   260     {
       
   261     TN_DEBUG1( "CThumbnailStore::OpenDatabaseL()" );
       
   262         
       
   263     iDatabase.Close();
       
   264     
       
   265     TBool newDatabase(EFalse);
       
   266     TInt error = KErrNone;
       
   267     
       
   268     TInt err = OpenDatabaseFileL();
       
   269    
       
   270    if ( err == KErrNotFound )
       
   271        {
       
   272        // db not found, create new
       
   273        RecreateDatabaseL( EFalse);
       
   274        newDatabase = ETrue;
       
   275        err = KErrNone;
       
   276        }
       
   277    else if ( err == KErrNone)
       
   278        {
       
   279        // db found, check version and rowids
       
   280        error = CheckVersionL();
       
   281        if(error == KErrNone)
       
   282            {
       
   283            error = CheckRowIDsL();
       
   284            }  
       
   285        }
       
   286    
       
   287    TN_DEBUG3( "CThumbnailStore::ConstructL() -- error = %d, err = %d", error, err);
       
   288    
       
   289    // if wrong version, corrupted database or other error opening db
       
   290    if ( error == KErrNotSupported || (err != KErrNone && err != KErrNotFound) )
       
   291        {
       
   292        RecreateDatabaseL( ETrue);
       
   293        }
       
   294    else if(!newDatabase)
       
   295        {
       
   296        if(ResetThumbnailIDs() == KSqlErrCorrupt)
       
   297            {
       
   298            RecreateDatabaseL( ETrue);
       
   299            }
       
   300        
       
   301        //check ownership
       
   302        error = CheckImeiL();
       
   303        
       
   304        if(error != KErrNone)
       
   305            {
       
   306            if(error == KSqlErrCorrupt)
       
   307                {
       
   308                RecreateDatabaseL( ETrue);
       
   309                }
       
   310            //take ownership
       
   311            error = UpdateImeiL();
       
   312            
       
   313            if(error == KSqlErrCorrupt)
       
   314                {
       
   315                RecreateDatabaseL( ETrue);
       
   316                }
       
   317            
       
   318            //Touch blacklisted items
       
   319            TRAP(error, PrepareBlacklistedItemsForRetryL( ) );
       
   320            
       
   321            if(error == KSqlErrCorrupt)
       
   322                {
       
   323                RecreateDatabaseL( ETrue);
       
   324                }
       
   325            }
       
   326        
       
   327        //check is MMC known
       
   328        if(CheckMediaIDL() != KErrNone )
       
   329            {
       
   330            //Touch blacklisted items
       
   331            TRAP(error, PrepareBlacklistedItemsForRetryL() );
       
   332            
       
   333            if(error == KSqlErrCorrupt)
       
   334                {
       
   335                RecreateDatabaseL( ETrue);
       
   336                }
       
   337            }
       
   338        }
       
   339    
       
   340    PrepareDbL();
       
   341    return KErrNone;
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // PrepareDbL database tables
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CThumbnailStore::PrepareDbL()
       
   349     {
       
   350     TN_DEBUG1( "CThumbnailStore::PrepareDbL()" );
       
   351     TInt err(KErrNone);
       
   352     
       
   353     // add tables
       
   354     TRAPD(tableError, CreateTablesL() );
       
   355       
       
   356     if(!tableError)
       
   357       {
       
   358       TRAPD(err, AddVersionAndImeiL());
       
   359       if (err == KSqlErrCorrupt)
       
   360           {
       
   361           RecreateDatabaseL( ETrue);
       
   362           }
       
   363       User::LeaveIfError(err);
       
   364       }
       
   365           
       
   366       err = iDatabase.Exec( KThumbnailCreateTempInfoTable );
       
   367 #ifdef _DEBUG
       
   368   if(err < 0)
       
   369       {
       
   370        TPtrC errorMsg = iDatabase.LastErrorMessage();
       
   371        TN_DEBUG2( "CThumbnailStore::ConstructL() KThumbnailCreateTempInfoTable %S" , &errorMsg);
       
   372       }
       
   373 #endif
       
   374     User::LeaveIfError( err );
       
   375 
       
   376   err = iDatabase.Exec( KThumbnailCreateTempInfoDataTable );
       
   377 #ifdef _DEBUG
       
   378   if(err < 0)
       
   379       {
       
   380        TPtrC errorMsg = iDatabase.LastErrorMessage();
       
   381        TN_DEBUG2( "CThumbnailStore::ConstructL() KThumbnailCreateTempInfoDataTable %S" , &errorMsg);
       
   382       }
       
   383 #endif
       
   384        User::LeaveIfError( err );
       
   385 }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // Create database tables
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 void CThumbnailStore::CreateTablesL()
       
   392     {
       
   393     TN_DEBUG1( "CThumbnailStore::CreateTablesL()" );
       
   394     
       
   395     TInt err = 0;
       
   396     err = iDatabase.Exec( KThumbnailCreateInfoTable );
       
   397     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTable err=%d", err );
       
   398     err = iDatabase.Exec( KThumbnailCreateInfoDataTable );
       
   399     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoDataTable err=%d", err );
       
   400     
       
   401     err = iDatabase.Exec(KThumbnailDeletedTable);
       
   402     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailDeletedTable err=%d", err );
       
   403     
       
   404     err = iDatabase.Exec(KThumbnailVersionTable);
       
   405     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailVersionTable err=%d", err );
       
   406     
       
   407     err = iDatabase.Exec( KThumbnailCreateInfoTableIndex1 );
       
   408     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTableIndex1 err=%d", err );
       
   409 
       
   410     err = iDatabase.Exec( KThumbnailCreateDeletedTableIndex );
       
   411     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateDeletedTableIndex err=%d", err );
       
   412     
       
   413     User::LeaveIfError( err );
       
   414     }
       
   415 
       
   416 void CThumbnailStore::RecreateDatabaseL(const TBool aDelete)
       
   417     {
       
   418     TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL()" );
       
   419     
   201     TVolumeInfo volumeinfo;
   420     TVolumeInfo volumeinfo;
   202     iFs.Volume(volumeinfo, iDrive);
   421     iFs.Volume(volumeinfo, iDrive);
   203     TUint id = volumeinfo.iUniqueID;
   422     TUint id = volumeinfo.iUniqueID;
   204     TBuf<50> mediaid;
   423     TBuf<50> mediaid;
   205     mediaid.Num(id);
   424     mediaid.Num(id);
   206     TBool newDatabase(EFalse);
   425     
   207     
   426     // delete db and create new
   208     TInt error = KErrNone;
   427     iDatabase.Close();
   209     
   428     
   210     TInt err = iDatabase.Open( pathPtr );
   429     HBufC* databasePath = HBufC::NewLC( KMaxFileName );
   211     if ( err == KErrNotFound )
   430     TPtr pathPtr = databasePath->Des();
   212         {
   431     TChar driveChar = 0;
   213         // db not found, create new
   432     User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar ));
   214         TN_DEBUG1( "CThumbnailStore::ConstructL() -- 1 creating database" );
   433     pathPtr.Append( driveChar );
   215         const TDesC8& config = KThumbnailSqlConfig;
   434     pathPtr.Append( KThumbnailDatabaseName );
   216 
   435     
   217         RSqlSecurityPolicy securityPolicy;
   436     TInt err(KErrNone);
   218         CleanupClosePushL( securityPolicy );
   437     
   219         securityPolicy.Create( KThumbnailDatabaseSecurityPolicy );
   438     if(aDelete)
   220 
   439         {
   221         iDatabase.CreateL( pathPtr, securityPolicy, &config );
       
   222         CleanupStack::PopAndDestroy( &securityPolicy );
       
   223 
       
   224         TN_DEBUG1( "CThumbnailStore::ConstructL() -- 1 database created ok" );
       
   225                 
       
   226         RFile64 file;
       
   227         file.Create(iFs, mediaid, EFileShareReadersOrWriters );
       
   228         file.Close();
       
   229         newDatabase = ETrue;
       
   230         }
       
   231     else if ( err == KErrNone)
       
   232         {
       
   233         // db found, check version and rowids
       
   234         error = CheckVersionL();
       
   235         if(error == KErrNone)
       
   236             {
       
   237             error = CheckRowIDsL();
       
   238             }  
       
   239         }
       
   240     
       
   241     // if wrong version, corrupted database or other error opening db
       
   242     if ( error == KErrNotSupported || (err != KErrNone && err != KErrNotFound) )
       
   243         {
       
   244         TN_DEBUG1( "CThumbnailStore::ConstructL() -- delete databases" );
       
   245         
       
   246         // delete db and create new
       
   247         iDatabase.Close();
       
   248         iDatabase.Delete(pathPtr);
   440         iDatabase.Delete(pathPtr);
   249         
   441         }
   250         TN_DEBUG1( "CThumbnailStore::ConstructL() -- 2 creating database" );
   442         
   251         
   443     const TDesC8& config = KThumbnailSqlConfig;
   252         const TDesC8& config = KThumbnailSqlConfig;
   444 
   253 
   445     RSqlSecurityPolicy securityPolicy;
   254         RSqlSecurityPolicy securityPolicy;
   446     CleanupClosePushL( securityPolicy );
   255         CleanupClosePushL( securityPolicy );
   447     securityPolicy.Create( KThumbnailDatabaseSecurityPolicy );
   256         securityPolicy.Create( KThumbnailDatabaseSecurityPolicy );
   448 
   257 
   449     TRAP(err, iDatabase.CreateL( pathPtr, securityPolicy, &config ));
   258         iDatabase.CreateL( pathPtr, securityPolicy, &config );
   450     CleanupStack::PopAndDestroy( &securityPolicy );
   259         CleanupStack::PopAndDestroy( &securityPolicy );
   451     
   260 
   452         
   261         TN_DEBUG1( "CThumbnailStore::ConstructL() -- 2 database created ok" );
   453 #ifdef _DEBUG
   262         
   454     if(err < 0)
   263         RFile64 file;
   455         {
   264         file.Create(iFs, mediaid, EFileShareReadersOrWriters );
   456         TPtrC errorMsg = iDatabase.LastErrorMessage();
   265         file.Close();
   457         TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() KThumbnailInsertTempThumbnailInfoData %S" , &errorMsg);
   266         }
   458         }
   267     else if(!newDatabase)
   459 #endif
   268         {
   460     TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- database created err = %d", err );
   269         //check ownership
   461     User::LeaveIfError( err );
   270         if(CheckImeiL() != KErrNone)
       
   271             {
       
   272             ResetThumbnailIDs();
       
   273             
       
   274             //take ownership
       
   275             UpdateImeiL();
       
   276             
       
   277             //Remove blacklist markings
       
   278             TRAP_IGNORE( RemoveDbFlagL( KThumbnailDbFlagBlacklisted ) );
       
   279             }
       
   280         
       
   281         //check is MMC known
       
   282         if(CheckMediaIDL() != KErrNone )
       
   283             {
       
   284             ResetThumbnailIDs();
       
   285             
       
   286             //Remove blacklist markings
       
   287             TRAP_IGNORE( RemoveDbFlagL( KThumbnailDbFlagBlacklisted ) );
       
   288             }
       
   289         }
       
   290               
       
   291     CleanupStack::PopAndDestroy( databasePath );
   462     CleanupStack::PopAndDestroy( databasePath );
   292     
   463     
   293     // add tables
   464     RFile64 file;
   294     TRAPD(tableError, CreateTablesL() );
   465     file.Create(iFs, mediaid, EFileShareReadersOrWriters );
   295     
   466     file.Close();
   296     if(!tableError)
   467     
   297         {
   468     OpenDatabaseFileL();
   298         AddVersionAndImeiL();
   469     }
   299         }
       
   300     
       
   301     err = iDatabase.Exec( KThumbnailCreateTempInfoTable );
       
   302     TN_DEBUG2("CThumbnailStore::CreateTablesL() KThumbnailCreateTempInfoTable %d", err);
       
   303     User::LeaveIfError( err );
       
   304     err = iDatabase.Exec( KThumbnailCreateTempInfoDataTable );
       
   305     TN_DEBUG2("CThumbnailStore::CreateTablesL() KThumbnailCreateTempInfoDataTable %d", err);
       
   306     User::LeaveIfError( err );
       
   307     }
       
   308 
       
   309 
   470 
   310 // ---------------------------------------------------------------------------
   471 // ---------------------------------------------------------------------------
   311 // CThumbnailStore::StoreThumbnailL()
   472 // CThumbnailStore::StoreThumbnailL()
   312 // Stores thumbnail image.
   473 // Stores thumbnail image.
   313 // ---------------------------------------------------------------------------
   474 // ---------------------------------------------------------------------------
   314 //
   475 //
   315 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, const TDes8& aData,
   476 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, const TDes8& aData,
   316     const TSize& aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, 
   477     const TSize& aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, 
   317 	const TThumbnailSize& aThumbnailSize, TThumbnailId aThumbnailId, const TBool aThumbFromPath )
   478 	const TThumbnailSize& aThumbnailSize, const TInt64 aModified, const TBool aThumbFromPath )
   318     {
   479     {
   319     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( const TDes8& ) in" );
   480     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( const TDes8& ) in" );
   320 
   481 
   321 #ifdef _DEBUG
   482 #ifdef _DEBUG
   322     TTime aStart, aStop;
   483     TTime aStart, aStop;
   363 
   524 
   364     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   525     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   365     User::LeaveIfError( paramIndex );
   526     User::LeaveIfError( paramIndex );
   366     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   527     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   367     
   528     
   368     if( aThumbnailId > 0 )
       
   369         {
       
   370         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   371         User::LeaveIfError( paramIndex );
       
   372         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   373         }
       
   374     else
       
   375         {
       
   376         TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( ) aThumbnailId == 0" );
       
   377         }
       
   378     
       
   379     // orientation temporarily to 0
   529     // orientation temporarily to 0
   380     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOrientation );
   530     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOrientation );
   381     User::LeaveIfError( paramIndex );
   531     User::LeaveIfError( paramIndex );
   382     User::LeaveIfError( stmt.BindInt( paramIndex, 0 ));
   532     User::LeaveIfError( stmt.BindInt( paramIndex, 0 ));
   383     
   533     
   388     User::LeaveIfError( stmt.BindInt( paramIndex, fromPath ));
   538     User::LeaveIfError( stmt.BindInt( paramIndex, fromPath ));
   389     
   539     
   390     // try getting modification time from file
   540     // try getting modification time from file
   391     TTime timeStamp;
   541     TTime timeStamp;
   392     
   542     
   393     if (aPath.Length())
   543     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp aModified %Ld", aModified );
   394         {
   544         
   395         iFs.Modified(aPath, timeStamp);
   545     if( aModified )
       
   546         {
       
   547         timeStamp = aModified;
   396         }
   548         }
   397     else
   549     else
   398         {
   550         {
   399         // otherwise current time
   551 
   400         timeStamp.UniversalTime();
   552         if (aPath.Length())
   401         }
   553             {
   402     
   554             iFs.Modified(aPath, timeStamp);
       
   555             TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp       iFs %Ld", timeStamp.Int64() );
       
   556             }
       
   557         else
       
   558             {
       
   559             // otherwise current time
       
   560             timeStamp.UniversalTime();
       
   561             TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp   current %Ld", timeStamp.Int64() );
       
   562             }
       
   563         }
       
   564         
       
   565    TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp       set %Ld", timeStamp.Int64());
       
   566    
   403     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamModified );
   567     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamModified );
   404     User::LeaveIfError( paramIndex );
   568     User::LeaveIfError( paramIndex );
   405     User::LeaveIfError( stmt.BindInt64( paramIndex, timeStamp.Int64() ));
   569     User::LeaveIfError( stmt.BindInt64( paramIndex, timeStamp.Int64() ));
   406     
   570     
   407     User::LeaveIfError( stmt.Exec());
   571     User::LeaveIfError( stmt.Exec());
   411     CleanupClosePushL( stmtData );
   575     CleanupClosePushL( stmtData );
   412     // Insert into ThumbnailInfoData
   576     // Insert into ThumbnailInfoData
   413     TInt err = stmtData.Prepare( iDatabase, KThumbnailInsertTempThumbnailInfoData );
   577     TInt err = stmtData.Prepare( iDatabase, KThumbnailInsertTempThumbnailInfoData );
   414        
   578        
   415 #ifdef _DEBUG
   579 #ifdef _DEBUG
   416     TPtrC errorMsg = iDatabase.LastErrorMessage();
   580     if(err < 0)
   417     TN_DEBUG2( "CThumbnailStore::FetchThumbnailL() KThumbnailInsertTempThumbnailInfoData %S" , &errorMsg);
   581         {
       
   582         TPtrC errorMsg = iDatabase.LastErrorMessage();
       
   583         TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() KThumbnailInsertTempThumbnailInfoData %S" , &errorMsg);
       
   584         }
   418 #endif    
   585 #endif    
   419     User::LeaveIfError( err );
   586     User::LeaveIfError( err );
   420     
   587     
   421     paramIndex = stmtData.ParameterIndex( KThumbnailSqlParamData );
   588     paramIndex = stmtData.ParameterIndex( KThumbnailSqlParamData );
   422     User::LeaveIfError( paramIndex );
   589     User::LeaveIfError( paramIndex );
   449 // Stores thumbnail image.
   616 // Stores thumbnail image.
   450 // ---------------------------------------------------------------------------
   617 // ---------------------------------------------------------------------------
   451 //
   618 //
   452 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, CFbsBitmap*
   619 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, CFbsBitmap*
   453     aThumbnail, const TSize& aOriginalSize, TBool /*aCropped*/, const TThumbnailSize aThumbnailSize, 
   620     aThumbnail, const TSize& aOriginalSize, TBool /*aCropped*/, const TThumbnailSize aThumbnailSize, 
   454     const TThumbnailId aThumbnailId, const TBool aThumbFromPath, TBool aBlackListed )
   621     const TInt64 aModified, TBool aThumbFromPath, TBool aBlackListed )
   455     {
   622     {
   456     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( CFbsBitmap* ) in" );
   623     TSize thumbSize = aThumbnail->SizeInPixels();
       
   624     TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( CFbsBitmap ) aThumbnailSize = %d, aThumbnailSize(%d,%d) IN", aThumbnailSize, thumbSize.iWidth, thumbSize.iHeight );
   457 
   625 
   458     __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer ));
   626     __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer ));
       
   627     
       
   628     // don't store custom/unknown sizes or zero sizes
       
   629     if(aThumbnailSize == ECustomThumbnailSize || aThumbnailSize == EUnknownThumbnailSize 
       
   630             || thumbSize.iWidth <= 0 || thumbSize.iHeight <= 0 )
       
   631         {
       
   632         TN_DEBUG1( "CThumbnailStore::StoreThumbnailL() not stored");
       
   633         return;
       
   634         }
       
   635     
       
   636     HBufC* path = aPath.AllocLC();
       
   637     TPtr ptr(path->Des());
       
   638     StripDriveLetterL( ptr );
   459 
   639 
   460     // check for duplicates
   640     // check for duplicates
   461     TBool exists = FindDuplicateL(aPath, aThumbnailId, aThumbnailSize);
   641     TBool exists = FindDuplicateL(*path, aThumbnailSize);
   462     
   642     
   463     TSize thumbSize = aThumbnail->SizeInPixels();
       
   464     for ( TInt i = iPersistentSizes.Count(); --i >= 0; )
   643     for ( TInt i = iPersistentSizes.Count(); --i >= 0; )
   465         {
   644         {
   466         TThumbnailPersistentSize & persistentSize = iPersistentSizes[i];
   645         TThumbnailPersistentSize & persistentSize = iPersistentSizes[i];
   467         
   646         
   468         // don't store duplicates or custom/unknown sizes
   647         // don't store duplicates or zero sizes
   469         if ( !exists && (aThumbnailSize != ECustomThumbnailSize && 
   648         if ( !exists )
   470                          aThumbnailSize != EUnknownThumbnailSize &&
       
   471                          thumbSize.iWidth > 0 && thumbSize.iHeight > 0 ))
       
   472             {
   649             {
   473             TInt flags = 0;
   650             TInt flags = 0;
   474             if ( persistentSize.iCrop )
   651             if ( persistentSize.iCrop )
   475                 {
   652                 {
   476                 flags |= KThumbnailDbFlagCropped;
   653                 flags |= KThumbnailDbFlagCropped;
   509                 User::WaitForRequest( request);
   686                 User::WaitForRequest( request);
   510                   
   687                   
   511                 if(request== KErrNone)
   688                 if(request== KErrNone)
   512                   {
   689                   {
   513                   TPtr8 ptr  = data->Des(); 
   690                   TPtr8 ptr  = data->Des(); 
   514                   StoreThumbnailL( aPath, ptr, aThumbnail->SizeInPixels(), aOriginalSize,
   691                   StoreThumbnailL( *path, ptr, aThumbnail->SizeInPixels(), aOriginalSize,
   515                           EThumbnailFormatJpeg, flags, aThumbnailSize, aThumbnailId, aThumbFromPath  );
   692                           EThumbnailFormatJpeg, flags, aThumbnailSize, aModified, aThumbFromPath  );
   516                   }
   693                   }
   517              
   694              
   518                 delete iFrameImageData;
   695                 delete iFrameImageData;
   519                 iFrameImageData = NULL;          
   696                 iFrameImageData = NULL;          
   520                 
   697                 
   529                 CleanupStack::PushL( buf );
   706                 CleanupStack::PushL( buf );
   530                 RBufWriteStream stream;
   707                 RBufWriteStream stream;
   531                 stream.Open( *buf );
   708                 stream.Open( *buf );
   532                 aThumbnail->ExternalizeL( stream );
   709                 aThumbnail->ExternalizeL( stream );
   533             
   710             
   534                 StoreThumbnailL( aPath, buf->Ptr( 0 ), aThumbnail->SizeInPixels(),
   711                 StoreThumbnailL( *path, buf->Ptr( 0 ), aThumbnail->SizeInPixels(),
   535                     aOriginalSize, EThumbnailFormatFbsBitmap, flags, aThumbnailSize, aThumbnailId );
   712                     aOriginalSize, EThumbnailFormatFbsBitmap, flags, aThumbnailSize, aModified);
   536   
   713   
   537                 CleanupStack::PopAndDestroy( buf );
   714                 CleanupStack::PopAndDestroy( buf );
   538                 }
   715                 }
   539             
   716             
   540             break;
   717             break;
   541             }
   718             }
   542         }
   719         }
   543     
   720     
       
   721     CleanupStack::PopAndDestroy( path );
       
   722     
   544     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( CFbsBitmap* ) out" );
   723     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( CFbsBitmap* ) out" );
   545     }
   724     }
   546 
   725 
   547 
       
   548 // ---------------------------------------------------------------------------
   726 // ---------------------------------------------------------------------------
   549 // Finds possible existing duplicate thumbnail.
   727 // Finds possible existing duplicate thumbnail.
   550 // ---------------------------------------------------------------------------
   728 // ---------------------------------------------------------------------------
   551 //
   729 //
   552 TBool CThumbnailStore::FindDuplicateL( const TDesC& aPath, const TThumbnailId aThumbnailId,
   730 TBool CThumbnailStore::FindDuplicateL( const TDesC& aPath, const TThumbnailSize& aThumbnailSize )
   553                                        const TThumbnailSize& aThumbnailSize )
       
   554     {
   731     {
   555     TN_DEBUG1( "CThumbnailStore::FindDuplicateL()" );
   732     TN_DEBUG1( "CThumbnailStore::FindDuplicateL()" );
   556     
   733     
   557     TInt rowStatus = 0;
   734     TInt rowStatus = 0;
   558     TInt paramIndex = 0;
   735     TInt paramIndex = 0;
   563     
   740     
   564     User::LeaveIfError( stmt.Prepare( iDatabase, KTempFindDuplicate ));
   741     User::LeaveIfError( stmt.Prepare( iDatabase, KTempFindDuplicate ));
   565     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   742     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   566     User::LeaveIfError( paramIndex );
   743     User::LeaveIfError( paramIndex );
   567     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   744     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   568         
       
   569     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   570     User::LeaveIfError( paramIndex );
       
   571     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   572     
   745     
   573     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   746     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   574     User::LeaveIfError( paramIndex );
   747     User::LeaveIfError( paramIndex );
   575     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   748     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   576     
   749     
   586         User::LeaveIfError( stmt.Prepare( iDatabase, KFindDuplicate ));
   759         User::LeaveIfError( stmt.Prepare( iDatabase, KFindDuplicate ));
   587         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   760         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   588         User::LeaveIfError( paramIndex );
   761         User::LeaveIfError( paramIndex );
   589         User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   762         User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   590             
   763             
   591         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   592         User::LeaveIfError( paramIndex );
       
   593         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   594         
       
   595         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   764         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   596         User::LeaveIfError( paramIndex );
   765         User::LeaveIfError( paramIndex );
   597         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   766         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   598         
   767         
   599         rowStatus = stmt.Next();
   768         rowStatus = stmt.Next();
   614         TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate in temp table" );
   783         TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate in temp table" );
   615         
   784         
   616         found = ETrue;
   785         found = ETrue;
   617         }
   786         }
   618     
   787     
       
   788     // check if duplicate in Deleted
       
   789     if (found)
       
   790         {
       
   791         stmt.Close();
       
   792         CleanupStack::PopAndDestroy( &stmt );
       
   793         CleanupClosePushL( stmt );     
       
   794             
       
   795         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlFindDeleted ));
       
   796         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
   797         User::LeaveIfError( paramIndex );
       
   798         User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
       
   799         
       
   800         rowStatus = stmt.Next();
       
   801         
       
   802         if(rowStatus == KSqlAtRow)
       
   803             {
       
   804             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate marked deleted" );
       
   805             
       
   806             DeleteThumbnailsL(aPath, ETrue);
       
   807             
       
   808             TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate force-deleted" );
       
   809             
       
   810             found = EFalse;
       
   811             }
       
   812         }
       
   813     
   619     stmt.Close();
   814     stmt.Close();
   620     CleanupStack::PopAndDestroy( &stmt );
   815     CleanupStack::PopAndDestroy( &stmt );
   621     
   816     
   622     return found;
   817     return found;
   623     }
   818     }
   624 
   819 
   625 
       
   626 // ---------------------------------------------------------------------------
       
   627 // Create database tables
       
   628 // ---------------------------------------------------------------------------
       
   629 //
       
   630 void CThumbnailStore::CreateTablesL()
       
   631     {
       
   632     TN_DEBUG1( "CThumbnailStore::CreateTablesL()" );
       
   633     TInt err = 0;
       
   634     err = iDatabase.Exec( KThumbnailCreateInfoTable );
       
   635     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTable err=%d", err );
       
   636     err = iDatabase.Exec( KThumbnailCreateInfoDataTable );
       
   637     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoDataTable err=%d", err );
       
   638     err = iDatabase.Exec( KThumbnailCreateInfoTableIndex1 );
       
   639     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTableIndex1 err=%d", err );
       
   640     err = iDatabase.Exec( KThumbnailCreateInfoTableIndex2 );
       
   641     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTableIndex2 err=%d", err );
       
   642     err = iDatabase.Exec(KThumbnailVersionTable);
       
   643     TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailVersionTable err=%d", err );
       
   644     User::LeaveIfError( err );
       
   645     }
       
   646 
       
   647 
       
   648 // ---------------------------------------------------------------------------
   820 // ---------------------------------------------------------------------------
   649 // Get missing sizes by Path
   821 // Get missing sizes by Path
   650 // ---------------------------------------------------------------------------
   822 // ---------------------------------------------------------------------------
   651 //     
   823 //     
   652 void CThumbnailStore::GetMissingSizesAndIDsL( const TDesC& aPath, TInt aSourceType, RArray <
   824 void CThumbnailStore::GetMissingSizesL( const TDesC& aPath, TInt aSourceType, RArray <
   653     TThumbnailPersistentSize > & aMissingSizes, TBool& aMissingIDs )
   825     TThumbnailPersistentSize > & aMissingSizes, TBool aCheckGridSizeOnly )
   654     {
   826     {
   655     TN_DEBUG2( "CThumbnailStore::GetMissingSizesAndIDsL() aSourceType == %d", aSourceType );
   827     TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() aSourceType == %d", aSourceType );
       
   828     
       
   829     HBufC* path = aPath.AllocLC();
       
   830     TPtr ptr(path->Des());
       
   831     StripDriveLetterL( ptr );
       
   832     
   656     // define sizes to be checked
   833     // define sizes to be checked
   657     const TInt count = iPersistentSizes.Count();
   834     const TInt count = iPersistentSizes.Count();
   658     
   835     
   659     for ( TInt i = 0 ; i < count; i++ )
   836     for ( TInt i = 0 ; i < count; i++ )
   660         {
   837         {
   661         if ( iPersistentSizes[ i ].iSourceType == aSourceType && iPersistentSizes[ i ].iAutoCreate)
   838         if ( iPersistentSizes[ i ].iSourceType == aSourceType && iPersistentSizes[ i ].iAutoCreate)
   662             {
   839             {
   663             aMissingSizes.Append( iPersistentSizes[ i ] );
   840             //if generating only grid size for image or video, other sizes are not missing
       
   841             if( aCheckGridSizeOnly )
       
   842 			{
       
   843 				if( (iPersistentSizes[i].iSourceType == TThumbnailPersistentSize::EImage || iPersistentSizes[i].iSourceType == TThumbnailPersistentSize::EVideo )&&
       
   844                      iPersistentSizes[i].iSizeType != TThumbnailPersistentSize::EGrid )
       
   845                     {
       
   846                     TN_DEBUG4( "CThumbnailStore::GetMissingSizesL() skip, aCheckGridSizeOnly = %d and  iPersistentSizes[%d].iSizeType == %d", 
       
   847                             aCheckGridSizeOnly, i, iPersistentSizes[i].iSizeType );
       
   848                     }
       
   849 				else
       
   850 				    {
       
   851                     aMissingSizes.Append( iPersistentSizes[ i ] );
       
   852 				    }
       
   853 			}
       
   854             else
       
   855                 {
       
   856                 aMissingSizes.Append( iPersistentSizes[ i ] );
       
   857                 }
   664             }
   858             }
   665         }
   859         }
   666     
   860     
   667     TInt missingSizeCount = aMissingSizes.Count();
   861     TInt missingSizeCount = aMissingSizes.Count();
   668     aMissingIDs = EFalse;
   862         
   669         
   863     TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() missingSizeCount == %d", missingSizeCount );
   670     TN_DEBUG3( "CThumbnailStore::GetMissingSizesAndIDsL() missingSizeCount == %d, missingIDs == %d", missingSizeCount, aMissingIDs );
       
   671     
   864     
   672     // check temp table first
   865     // check temp table first
   673     RSqlStatement stmt;
   866     RSqlStatement stmt;
   674     CleanupClosePushL( stmt );
   867     CleanupClosePushL( stmt );
   675     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempSizeByPath ));
   868     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempSizeByPath ));
   676     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   869     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   677     User::LeaveIfError( paramIndex );
   870     User::LeaveIfError( paramIndex );
   678     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   871     User::LeaveIfError( stmt.BindText( paramIndex, *path ));
   679        
   872        
   680     TInt rowStatus = stmt.Next();
   873     TInt rowStatus = stmt.Next();
   681 
   874 
   682     TInt round = 1;
   875     TInt round = 1;
   683     TInt size = 0;
   876     TInt size = 0;
   684     TInt id = 0;
       
   685     
   877     
   686     while (round <= 2)
   878     while (round <= 2)
   687         {
   879         {
   688         while ( rowStatus == KSqlAtRow && missingSizeCount > 0 )
   880         while ( rowStatus == KSqlAtRow && missingSizeCount > 0 )
   689             {
   881             {
   690             size = stmt.ColumnInt( 0 );
   882             size = stmt.ColumnInt( 0 );
   691             id = stmt.ColumnInt( 1 );
       
   692 			
   883 			
   693 			TN_DEBUG2( "CThumbnailStore::GetMissingSizesAndIDsL() id == %d", id );
       
   694             
       
   695 			//if TNId is not valid mark that some are missing so that UpdateDb is run later
       
   696             if ( id <= 0)
       
   697                 {
       
   698                 TN_DEBUG1( "CThumbnailStore::GetMissingSizesAndIDsL() missing ID");
       
   699                 aMissingIDs = ETrue;
       
   700                 }
       
   701             
       
   702             missingSizeCount = aMissingSizes.Count();
   884             missingSizeCount = aMissingSizes.Count();
   703             for ( TInt i = 0; i < missingSizeCount; i++ )
   885             for ( TInt i = 0; i < missingSizeCount; i++ )
   704                 {
   886                 {
   705                 if ( aMissingSizes[ i ].iType == size )
   887                 if ( aMissingSizes[ i ].iType == size )
   706                     {
   888                     {
   717         CleanupStack::PopAndDestroy( &stmt );
   899         CleanupStack::PopAndDestroy( &stmt );
   718         
   900         
   719         // all found
   901         // all found
   720         if (missingSizeCount == 0)
   902         if (missingSizeCount == 0)
   721             {
   903             {
       
   904             CleanupStack::PopAndDestroy( path );
   722             return;
   905             return;
   723             }
   906             }
   724         else if (round == 1)
   907         else if (round == 1)
   725             {
   908             {
   726             // change to real table
   909             // change to real table
   727             CleanupClosePushL( stmt );
   910             CleanupClosePushL( stmt );
   728             User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectSizeByPath ));
   911             User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectSizeByPath ));
   729             paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   912             paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   730             User::LeaveIfError( paramIndex );
   913             User::LeaveIfError( paramIndex );
   731             User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   914             User::LeaveIfError( stmt.BindText( paramIndex, *path ));
   732             rowStatus = stmt.Next();    
   915             rowStatus = stmt.Next();    
   733             }
   916             }
   734         
   917         
   735         round++;
   918         round++;
   736         }
   919         }
   737     }
   920     
   738 
   921     CleanupStack::PopAndDestroy( path );
   739 
   922     }
   740 // ---------------------------------------------------------------------------
       
   741 // CThumbnailStore::FetchThumbnailL()
       
   742 // Fetches thumbnail image.
       
   743 // ---------------------------------------------------------------------------
       
   744 //
       
   745 TInt CThumbnailStore::FetchThumbnailL( TThumbnailId aThumbnailId, 
       
   746         CFbsBitmap*& aThumbnail, TDesC8* & aData, TThumbnailSize aThumbnailSize, TSize &aThumbnailRealSize )
       
   747     {
       
   748     TN_DEBUG3( "CThumbnailStore::FetchThumbnailL(%d) aThumbnailSize == %d", aThumbnailId, aThumbnailSize );
       
   749      delete aThumbnail;
       
   750      aThumbnail = NULL;
       
   751 
       
   752      RSqlStatement stmt;
       
   753      CleanupClosePushL( stmt );
       
   754      
       
   755      TInt paramIndex = 0;
       
   756      TInt found = KErrNotFound;
       
   757      TInt rowStatus = 0;
       
   758      TInt column = 0;
       
   759      TInt count = 0;
       
   760      TThumbnailSize thumbnailImage = EUnknownThumbnailSize;
       
   761      TThumbnailSize thumbnailVideo = EUnknownThumbnailSize;
       
   762      TThumbnailSize thumbnailAudio = EUnknownThumbnailSize;
       
   763      TBool inTempTable( ETrue );
       
   764      
       
   765      if(aThumbnailSize == EFullScreenThumbnailSize)
       
   766          {
       
   767          thumbnailImage = EImageFullScreenThumbnailSize;
       
   768          thumbnailVideo = EVideoFullScreenThumbnailSize;
       
   769          thumbnailAudio = EAudioFullScreenThumbnailSize;
       
   770          }
       
   771      else if(aThumbnailSize == EGridThumbnailSize)
       
   772          {
       
   773          thumbnailImage = EImageGridThumbnailSize;
       
   774          thumbnailVideo = EVideoGridThumbnailSize;
       
   775          thumbnailAudio = EAudioGridThumbnailSize;
       
   776          }
       
   777      else if(aThumbnailSize == EListThumbnailSize)
       
   778          {
       
   779          thumbnailImage = EImageListThumbnailSize;
       
   780          thumbnailVideo = EVideoListThumbnailSize;
       
   781          thumbnailAudio = EAudioListThumbnailSize;
       
   782          }
       
   783      
       
   784      if(aThumbnailSize == EFullScreenThumbnailSize ||
       
   785         aThumbnailSize == EGridThumbnailSize ||
       
   786         aThumbnailSize == EListThumbnailSize )
       
   787          {
       
   788          TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- No DataType -- TEMP TABLE lookup" );
       
   789          User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempInfoByIdv2 ));
       
   790          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   791          User::LeaveIfError( paramIndex );
       
   792          User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   793              
       
   794          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSizeImage );
       
   795          User::LeaveIfError( paramIndex );
       
   796          User::LeaveIfError( stmt.BindInt( paramIndex, thumbnailImage ));
       
   797          
       
   798          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSizeVideo );
       
   799          User::LeaveIfError( paramIndex );
       
   800          User::LeaveIfError( stmt.BindInt( paramIndex, thumbnailVideo ));
       
   801          
       
   802          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSizeAudio );
       
   803          User::LeaveIfError( paramIndex );
       
   804          User::LeaveIfError( stmt.BindInt( paramIndex, thumbnailAudio ));
       
   805              
       
   806          rowStatus = stmt.Next();
       
   807          //if not found from temp table, look from real table
       
   808          if(rowStatus != KSqlAtRow)
       
   809            {
       
   810            TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- No DataType -- MAIN TABLE lookup" );
       
   811            inTempTable = EFalse;
       
   812            stmt.Close();
       
   813            CleanupStack::PopAndDestroy( &stmt );
       
   814            CleanupClosePushL( stmt );
       
   815                 
       
   816            User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectInfoByIdv2 ));
       
   817              
       
   818            paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   819            User::LeaveIfError( paramIndex );
       
   820            User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   821                  
       
   822            paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSizeImage );
       
   823            User::LeaveIfError( paramIndex );
       
   824            User::LeaveIfError( stmt.BindInt( paramIndex, thumbnailImage ));
       
   825                     
       
   826            paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSizeVideo );
       
   827            User::LeaveIfError( paramIndex );
       
   828            User::LeaveIfError( stmt.BindInt( paramIndex, thumbnailVideo ));
       
   829                     
       
   830            paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSizeAudio );
       
   831            User::LeaveIfError( paramIndex );
       
   832            User::LeaveIfError( stmt.BindInt( paramIndex, thumbnailAudio ));
       
   833              
       
   834            rowStatus = stmt.Next();
       
   835            }               
       
   836          }
       
   837      else
       
   838          {
       
   839          TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" );
       
   840          User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempInfoById ));
       
   841          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   842          User::LeaveIfError( paramIndex );
       
   843          User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   844      
       
   845          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
       
   846          User::LeaveIfError( paramIndex );
       
   847          User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
       
   848      
       
   849          rowStatus = stmt.Next();
       
   850 
       
   851          //if not found from temp table, look from real table
       
   852          if(rowStatus != KSqlAtRow)
       
   853             {
       
   854             TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- MAIN TABLE lookup" );
       
   855             inTempTable = EFalse;
       
   856             stmt.Close();
       
   857             CleanupStack::PopAndDestroy( &stmt );
       
   858             CleanupClosePushL( stmt );
       
   859         
       
   860             User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectInfoById ));
       
   861      
       
   862             paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
   863             User::LeaveIfError( paramIndex );
       
   864             User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
   865          
       
   866             paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
       
   867             User::LeaveIfError( paramIndex );
       
   868             User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
       
   869      
       
   870             rowStatus = stmt.Next();
       
   871             }
       
   872          }
       
   873      if(rowStatus == KSqlAtRow)
       
   874         {
       
   875          TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail found" );
       
   876          // Check whether blacklisted thumbnail entry modified. 
       
   877          // If thumbnail is marked as blacklisted and timestamp has 
       
   878          // changed, delete thumbnails from tables and leave with 
       
   879          // KErrNotFound to get thumbnail regenerated.
       
   880          column = 4;
       
   881          TInt flags = stmt.ColumnInt( column );
       
   882          if( flags & KThumbnailDbFlagBlacklisted )
       
   883              {
       
   884              TBool modified = EFalse;
       
   885              CheckModifiedByIdL( aThumbnailId, inTempTable, modified );
       
   886              if( modified )
       
   887                  {
       
   888                  // Close db to get deletion of thumbnails executed.
       
   889                  stmt.Close();
       
   890                  CleanupStack::PopAndDestroy( &stmt );
       
   891                  DeleteThumbnailsL( aThumbnailId );
       
   892                  User::Leave( KErrNotFound );
       
   893                  }
       
   894              else
       
   895                  {
       
   896                  User::Leave( KErrCompletion );
       
   897                  }
       
   898              }
       
   899          
       
   900          found = KErrNone;
       
   901          count = 0;
       
   902          count++;
       
   903          column = 0;
       
   904          TInt format = stmt.ColumnInt( column++ );  
       
   905          if(format == 1 /*TThumbnailFormat::EThumbnailFormatJpeg */ )
       
   906              {
       
   907              TPtrC8 ptr = stmt.ColumnBinaryL( column++ );
       
   908              HBufC8* data = ptr.AllocL() ;
       
   909              aThumbnail = NULL;
       
   910              aData = data;     
       
   911              
       
   912           } else {
       
   913              TPtrC8 ptr = stmt.ColumnBinaryL( column );
       
   914              RDesReadStream stream( ptr );
       
   915              aThumbnail = new( ELeave )CFbsBitmap();
       
   916              aThumbnail->InternalizeL( stream );
       
   917              aData = NULL;
       
   918           }
       
   919          
       
   920         //fetch real size of TN
       
   921         column = 2;
       
   922         aThumbnailRealSize.iWidth = stmt.ColumnInt( column++ );
       
   923         aThumbnailRealSize.iHeight = stmt.ColumnInt( column );
       
   924         }
       
   925      else
       
   926          {
       
   927          TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail NOT found" );
       
   928          }
       
   929          
       
   930      stmt.Close();
       
   931      CleanupStack::PopAndDestroy( &stmt );
       
   932 
       
   933      User::LeaveIfError( found );
       
   934      return found;
       
   935     }
       
   936 
       
   937 
   923 
   938 // ---------------------------------------------------------------------------
   924 // ---------------------------------------------------------------------------
   939 // CThumbnailStore::FetchThumbnailL()
   925 // CThumbnailStore::FetchThumbnailL()
   940 // Fetches thumbnail image.
   926 // Fetches thumbnail image.
   941 // ---------------------------------------------------------------------------
   927 // ---------------------------------------------------------------------------
   944     aThumbnail, TDesC8* & aData, const TThumbnailSize aThumbnailSize, TSize &aThumbnailRealSize )
   930     aThumbnail, TDesC8* & aData, const TThumbnailSize aThumbnailSize, TSize &aThumbnailRealSize )
   945     {
   931     {
   946     TN_DEBUG3( "CThumbnailStore::FetchThumbnailL(%S) aThumbnailSize==%d", &aPath, aThumbnailSize );
   932     TN_DEBUG3( "CThumbnailStore::FetchThumbnailL(%S) aThumbnailSize==%d", &aPath, aThumbnailSize );
   947     delete aThumbnail;
   933     delete aThumbnail;
   948     aThumbnail = NULL;
   934     aThumbnail = NULL;
   949 
   935     
       
   936     HBufC* path = aPath.AllocLC();
       
   937     TPtr ptr(path->Des());
       
   938     StripDriveLetterL( ptr );
       
   939     
   950     RSqlStatement stmt;
   940     RSqlStatement stmt;
   951     CleanupClosePushL( stmt );
   941     CleanupClosePushL( stmt );
   952     
   942     
   953     TInt paramIndex = 0;
   943     TInt paramIndex = 0;
   954     TInt found = KErrNotFound;
   944     TInt found = KErrNotFound;
   959     TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" );
   949     TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" );
   960     TInt err = stmt.Prepare( iDatabase, KThumbnailSelectTempInfoByPath );
   950     TInt err = stmt.Prepare( iDatabase, KThumbnailSelectTempInfoByPath );
   961 
   951 
   962 #ifdef _DEBUG
   952 #ifdef _DEBUG
   963     TPtrC errorMsg = iDatabase.LastErrorMessage();
   953     TPtrC errorMsg = iDatabase.LastErrorMessage();
   964     TN_DEBUG2( "CThumbnailStore::FetchThumbnailL() %S" , &errorMsg);
   954     TN_DEBUG2( "CThumbnailStore::FetchThumbnailL() KThumbnailSelectTempInfoByPath %S" , &errorMsg);
   965 #endif
   955 #endif
   966     User::LeaveIfError( err );
   956     User::LeaveIfError( err );
   967     
   957     
   968     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   958     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   969     User::LeaveIfError( paramIndex );
   959     User::LeaveIfError( paramIndex );
   970     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   960     User::LeaveIfError( stmt.BindText( paramIndex, *path ));
   971     
   961     
   972     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   962     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   973     User::LeaveIfError( paramIndex );
   963     User::LeaveIfError( paramIndex );
   974     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   964     User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   975     
   965     
   986        
   976        
   987        User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectInfoByPath ));
   977        User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectInfoByPath ));
   988     
   978     
   989         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   979         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
   990         User::LeaveIfError( paramIndex );
   980         User::LeaveIfError( paramIndex );
   991         User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
   981         User::LeaveIfError( stmt.BindText( paramIndex, *path ));
   992         
   982         
   993         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   983         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
   994         User::LeaveIfError( paramIndex );
   984         User::LeaveIfError( paramIndex );
   995         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   985         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize ));
   996     
   986     
  1004         // If thumbnail is marked as blacklisted and timestamp has 
   994         // If thumbnail is marked as blacklisted and timestamp has 
  1005         // changed, delete thumbnails from tables and leave with 
   995         // changed, delete thumbnails from tables and leave with 
  1006         // KErrNotFound to get thumbnail regenerated.
   996         // KErrNotFound to get thumbnail regenerated.
  1007         column = 4;
   997         column = 4;
  1008         TInt flags = stmt.ColumnInt( column );
   998         TInt flags = stmt.ColumnInt( column );
  1009         if( flags & KThumbnailDbFlagBlacklisted && aPath.Length() )
   999         if( flags & KThumbnailDbFlagBlacklisted && (*path).Length() )
  1010             {
  1000             {
  1011             TBool modified = EFalse;
  1001             TBool modified = EFalse;
  1012             CheckModifiedByPathL( aPath, inTempTable, modified );
  1002             CheckModifiedByPathL( aPath, inTempTable, modified );
  1013             if( modified )
  1003             if( modified )
  1014                 {
  1004                 {
  1015                 // Close db to get deletion of thumbnails executed.
  1005                 // Close db to get deletion of thumbnails executed.
  1016                 stmt.Close();
  1006                 stmt.Close();
  1017                 CleanupStack::PopAndDestroy( &stmt );
  1007                 CleanupStack::PopAndDestroy( &stmt );
  1018                 DeleteThumbnailsL( aPath );
  1008                 DeleteThumbnailsL( *path );
  1019                 User::Leave( KErrNotFound );
  1009                 User::Leave( KErrNotFound );
  1020                 }
  1010                 }
  1021             else
  1011             else
  1022                 {
  1012                 {
  1023                 User::Leave( KErrCompletion );
  1013                 User::Leave( KErrCompletion );
  1055         TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail NOT found" );
  1045         TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail NOT found" );
  1056         }
  1046         }
  1057         
  1047         
  1058     stmt.Close();
  1048     stmt.Close();
  1059     CleanupStack::PopAndDestroy( &stmt );
  1049     CleanupStack::PopAndDestroy( &stmt );
  1060 
  1050     CleanupStack::PopAndDestroy( path );
       
  1051     
  1061     User::LeaveIfError( found );
  1052     User::LeaveIfError( found );
  1062     }
  1053     }
  1063 
  1054 
  1064 // -----------------------------------------------------------------------------
  1055 // -----------------------------------------------------------------------------
  1065 // Delete thumbnails for given object file by Path
  1056 // Delete thumbnails for given object file by Path
  1066 // -----------------------------------------------------------------------------
  1057 // -----------------------------------------------------------------------------
  1067 //
  1058 //
  1068 void CThumbnailStore::DeleteThumbnailsL( const TDesC& aPath )
  1059 void CThumbnailStore::DeleteThumbnailsL( const TDesC& aPath, TBool aForce, 
  1069     {
  1060                                          TBool aTransaction )
  1070     RThumbnailTransaction transaction( iDatabase );
  1061     {
  1071     CleanupClosePushL( transaction );
  1062     TN_DEBUG2( "CThumbnailStore::DeleteThumbnailsL(%S)", &aPath );
  1072     transaction.BeginL();
  1063 #ifdef _DEBUG
  1073     RSqlStatement stmt;
  1064     TTime aStart, aStop;
  1074     CleanupClosePushL( stmt );
  1065     aStart.UniversalTime();
  1075     
  1066 #endif
  1076     TInt paramIndex = 0;
  1067     TInt paramIndex = 0;
  1077     TInt paramIndex1 = 0;
  1068     TInt paramIndex1 = 0;
  1078     TInt paramIndex2 = 0;
  1069     TInt paramIndex2 = 0;
  1079     TInt rowStatus = 0;
  1070     TInt rowStatus = 0;
  1080     TInt column = 0;
  1071     TInt column = 0;
  1081     TInt rowid = 0;
  1072     TInt64 rowid = 0;
  1082     TInt deleteCount = 0;
  1073     TInt count = 0;
  1083     
  1074 
       
  1075     HBufC* path = aPath.AllocLC();
       
  1076     TPtr ptr(path->Des());
       
  1077     StripDriveLetterL( ptr );
       
  1078     
       
  1079     RThumbnailTransaction transaction( iDatabase );
       
  1080     if (aTransaction)
       
  1081         {
       
  1082         CleanupClosePushL( transaction );    
       
  1083         transaction.BeginL();
       
  1084         }
       
  1085         
       
  1086     RSqlStatement stmt;
       
  1087     RSqlStatement stmt_info;
       
  1088     RSqlStatement stmt_infodata;
       
  1089     
       
  1090     CleanupClosePushL( stmt );
       
  1091     CleanupClosePushL( stmt_info );
       
  1092     CleanupClosePushL( stmt_infodata );
       
  1093         
  1084     TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup" );
  1094     TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup" );
  1085     TInt err = stmt.Prepare( iDatabase, KTempThumbnailSqlSelectRowIDInfoByPath);
  1095     
  1086     User::LeaveIfError( err );
  1096     User::LeaveIfError( stmt.Prepare( iDatabase, KTempThumbnailSqlSelectRowIDInfoByPath) );
       
  1097     User::LeaveIfError( stmt_info.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoByPath) );
       
  1098     User::LeaveIfError( stmt_infodata.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoDataByPath) );
  1087     
  1099     
  1088     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
  1100     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
  1089     User::LeaveIfError( paramIndex );
  1101     User::LeaveIfError( paramIndex );
  1090     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
  1102     User::LeaveIfError( stmt.BindText( paramIndex, *path ));
  1091     
  1103     
  1092     rowStatus = stmt.Next();
  1104     rowStatus = stmt.Next();
  1093     RSqlStatement stmt_info;
       
  1094     CleanupClosePushL( stmt_info );
       
  1095     err = stmt_info.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoByPath);
       
  1096     RSqlStatement stmt_infodata;
       
  1097     CleanupClosePushL( stmt_infodata );
       
  1098     err = stmt_infodata.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoDataByPath);
       
  1099     
       
  1100     
  1105     
  1101     while(rowStatus == KSqlAtRow)
  1106     while(rowStatus == KSqlAtRow)
  1102        {  
  1107         {  
  1103        rowid = stmt.ColumnInt( column ); 
  1108         rowid = stmt.ColumnInt64( column ); 
  1104        paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
  1109         paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
  1105        User::LeaveIfError( paramIndex1 );
  1110         User::LeaveIfError( paramIndex1 );
  1106        User::LeaveIfError( stmt_info.BindInt( paramIndex1, rowid ));
  1111         User::LeaveIfError( stmt_info.BindInt64( paramIndex1, rowid ));
  1107        
  1112        
  1108        deleteCount = stmt_info.Exec();
  1113         TInt err = stmt_info.Exec();
  1109        stmt_info.Reset();
  1114         stmt_info.Reset();
  1110        User::LeaveIfError( deleteCount );
  1115         User::LeaveIfError( err );
  1111              
  1116              
  1112        paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );
  1117         paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );
  1113        User::LeaveIfError( paramIndex2 );
  1118         User::LeaveIfError( paramIndex2 );
  1114        User::LeaveIfError( stmt_infodata.BindInt( paramIndex2, rowid ));
  1119         User::LeaveIfError( stmt_infodata.BindInt64( paramIndex2, rowid ));
  1115              
  1120              
  1116        deleteCount = stmt_infodata.Exec();
  1121         err = stmt_infodata.Exec();
  1117        stmt_infodata.Reset();
  1122         stmt_infodata.Reset();
  1118        User::LeaveIfError( deleteCount );
  1123         User::LeaveIfError( err );
       
  1124         
       
  1125         TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup - thumbnail deleted" );
  1119        
  1126        
  1120        TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup - thumbnail deleted" );
  1127         // fetch another row (temp table rowIDs are updated immediately)
       
  1128         stmt.Reset();
  1121        
  1129        
  1122        // fetch another row (temp table rowIDs are updated immediately)
  1130         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
  1123        stmt.Reset();
  1131         User::LeaveIfError( paramIndex );
       
  1132         User::LeaveIfError( stmt.BindText( paramIndex, *path ));
  1124        
  1133        
  1125        paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
  1134         rowStatus = stmt.Next();   
  1126        User::LeaveIfError( paramIndex );
  1135         }
  1127        User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
       
  1128        
       
  1129        rowStatus = stmt.Next();   
       
  1130        }
       
  1131     stmt_infodata.Close();
       
  1132     stmt_info.Close();
       
  1133     CleanupStack::PopAndDestroy( &stmt_infodata );
       
  1134     CleanupStack::PopAndDestroy( &stmt_info );
       
  1135     
       
  1136 
       
  1137     //look from real table 
       
  1138     TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" );
       
  1139     stmt.Close();
       
  1140     CleanupStack::PopAndDestroy( &stmt );
       
  1141     CleanupClosePushL( stmt );   
       
  1142     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectRowIDInfoByPath ));
       
  1143     
       
  1144     User::LeaveIfError( err );
       
  1145     
       
  1146     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1147     User::LeaveIfError( paramIndex );
       
  1148     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
       
  1149          
       
  1150     rowStatus = stmt.Next();   
       
  1151     CleanupClosePushL( stmt_info );
       
  1152     err = stmt_info.Prepare( iDatabase, KThumbnailSqlDeleteInfoByPath);
       
  1153     CleanupClosePushL( stmt_infodata );
       
  1154     err = stmt_infodata.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByPath);
       
  1155        
       
  1156        
       
  1157     while(rowStatus == KSqlAtRow)
       
  1158        { 
       
  1159        rowid = stmt.ColumnInt( column ); 
       
  1160        paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
       
  1161        User::LeaveIfError( paramIndex1 );
       
  1162        User::LeaveIfError( stmt_info.BindInt( paramIndex1, rowid ));
       
  1163           
       
  1164        deleteCount = stmt_info.Exec();
       
  1165        stmt_info.Reset();
       
  1166        User::LeaveIfError( deleteCount );
       
  1167                 
       
  1168        paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );  
       
  1169        User::LeaveIfError( paramIndex2 );
       
  1170        User::LeaveIfError( stmt_infodata.BindInt( paramIndex2, rowid ));
       
  1171                 
       
  1172        deleteCount = stmt_infodata.Exec();
       
  1173        stmt_infodata.Reset();
       
  1174        User::LeaveIfError( deleteCount );
       
  1175        
       
  1176        TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup - thumbnail deleted" );
       
  1177        
       
  1178        rowStatus = stmt.Next();
       
  1179        }
       
  1180     
  1136     
  1181     stmt_infodata.Close();
  1137     stmt_infodata.Close();
  1182     stmt_info.Close();
  1138     stmt_info.Close();
  1183     stmt.Close();
  1139     stmt.Close();
       
  1140     
  1184     CleanupStack::PopAndDestroy( &stmt_infodata );
  1141     CleanupStack::PopAndDestroy( &stmt_infodata );
  1185     CleanupStack::PopAndDestroy( &stmt_info );
  1142     CleanupStack::PopAndDestroy( &stmt_info );
       
  1143     CleanupStack::PopAndDestroy( &stmt );
       
  1144     
       
  1145     // if forcing instant delete
       
  1146     if (aForce)
       
  1147         {
       
  1148         //look from real table 
       
  1149         TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" );
       
  1150         
       
  1151         CleanupClosePushL( stmt );
       
  1152         CleanupClosePushL( stmt_info );
       
  1153         CleanupClosePushL( stmt_infodata );
       
  1154         
       
  1155         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectRowIDInfoByPath ));
       
  1156         User::LeaveIfError( stmt_info.Prepare( iDatabase, KThumbnailSqlDeleteInfoByPath) );
       
  1157         User::LeaveIfError( stmt_infodata.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByPath) );
       
  1158 
       
  1159         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1160         User::LeaveIfError( paramIndex );
       
  1161         User::LeaveIfError( stmt.BindText( paramIndex, *path ));
       
  1162              
       
  1163         rowStatus = stmt.Next();   
       
  1164            
       
  1165         while(rowStatus == KSqlAtRow)
       
  1166             { 
       
  1167             rowid = stmt.ColumnInt64( column ); 
       
  1168             paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
       
  1169             User::LeaveIfError( paramIndex1 );
       
  1170             User::LeaveIfError( stmt_info.BindInt64( paramIndex1, rowid ));
       
  1171                
       
  1172             TInt err = stmt_info.Exec();
       
  1173             stmt_info.Reset();
       
  1174             User::LeaveIfError( err );
       
  1175                     
       
  1176             paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );  
       
  1177             User::LeaveIfError( paramIndex2 );
       
  1178             User::LeaveIfError( stmt_infodata.BindInt64( paramIndex2, rowid ));
       
  1179                     
       
  1180             err = stmt_infodata.Exec();
       
  1181             stmt_infodata.Reset();
       
  1182             User::LeaveIfError( err );
       
  1183            
       
  1184             TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup - thumbnail deleted" );
       
  1185             
       
  1186             rowStatus = stmt.Next();
       
  1187             }
       
  1188         
       
  1189         stmt_infodata.Close();
       
  1190         stmt_info.Close();
       
  1191         CleanupStack::PopAndDestroy( &stmt_infodata );
       
  1192         CleanupStack::PopAndDestroy( &stmt_info );
       
  1193         } 
       
  1194     else
       
  1195         {
       
  1196         // only add path to deleted table
       
  1197         CleanupClosePushL( stmt );  
       
  1198         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlInsertDeleted ) );
       
  1199         
       
  1200         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1201         User::LeaveIfError( paramIndex );
       
  1202         User::LeaveIfError( stmt.BindText( paramIndex, *path ));
       
  1203         
       
  1204         count = stmt.Exec();
       
  1205         }
       
  1206     
       
  1207     stmt.Close();
  1186     CleanupStack::PopAndDestroy( &stmt );    
  1208     CleanupStack::PopAndDestroy( &stmt );    
  1187     transaction.CommitL();
  1209     
  1188     CleanupStack::PopAndDestroy( &transaction );
  1210     if (aTransaction)
  1189     }
  1211         {
  1190 
  1212         transaction.CommitL();
  1191 // -----------------------------------------------------------------------------
  1213         CleanupStack::PopAndDestroy( &transaction );
  1192 // Delete thumbnails for given object file by Id
  1214         }
  1193 // -----------------------------------------------------------------------------
       
  1194 //
       
  1195 void CThumbnailStore::DeleteThumbnailsL( const TThumbnailId& aTNId )
       
  1196     {
       
  1197 #ifdef _DEBUG
       
  1198     TTime aStart, aStop;
       
  1199     aStart.UniversalTime();
       
  1200 #endif
       
  1201         
       
  1202     TInt paramIndex = 0;
       
  1203     TInt paramIndex1 = 0;
       
  1204     TInt paramIndex2 = 0;
       
  1205     TInt rowStatus = 0;
       
  1206     TInt column = 0;
       
  1207     TInt rowid = 0;
       
  1208     TInt deleteCount = 0;
       
  1209       
       
  1210     RThumbnailTransaction transaction( iDatabase );
       
  1211     CleanupClosePushL( transaction );
       
  1212     transaction.BeginL();
       
  1213     RSqlStatement stmt;
       
  1214     CleanupClosePushL( stmt );
       
  1215     
       
  1216     TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByIdL() -- TEMP TABLE lookup" );
       
  1217     TInt err = stmt.Prepare( iDatabase, KTempThumbnailSqlSelectRowIDInfoByID);
       
  1218     User::LeaveIfError( err );
       
  1219         
       
  1220     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1221     User::LeaveIfError( paramIndex );
       
  1222     User::LeaveIfError( stmt.BindInt( paramIndex, aTNId ));
       
  1223         
       
  1224     rowStatus = stmt.Next();
       
  1225     RSqlStatement stmt_info;
       
  1226     CleanupClosePushL( stmt_info );
       
  1227     err = stmt_info.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoByID);
       
  1228     RSqlStatement stmt_infodata;
       
  1229     CleanupClosePushL( stmt_infodata );
       
  1230     err = stmt_infodata.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoDataByID);
       
  1231         
       
  1232         
       
  1233     while(rowStatus == KSqlAtRow)
       
  1234        {  
       
  1235        rowid = stmt.ColumnInt( column ); 
       
  1236        paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
       
  1237        User::LeaveIfError( paramIndex1 );
       
  1238        User::LeaveIfError( stmt_info.BindInt( paramIndex1, rowid ));
       
  1239            
       
  1240        err = stmt_info.Exec();
       
  1241        stmt_info.Reset();
       
  1242        User::LeaveIfError( err );
       
  1243                  
       
  1244        paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );
       
  1245        User::LeaveIfError( paramIndex2 );
       
  1246        User::LeaveIfError( stmt_infodata.BindInt( paramIndex2, rowid ));
       
  1247                  
       
  1248        err = stmt_infodata.Exec();
       
  1249        stmt_infodata.Reset();
       
  1250        User::LeaveIfError( err );
       
  1251        deleteCount++;
       
  1252        
       
  1253        TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByIdL() -- TEMP TABLE lookup - thumbnail deleted" );
       
  1254        
       
  1255        // fetch another row (temp table rowIDs are updated immediately)
       
  1256        stmt.Reset();
       
  1257        
       
  1258        paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1259        User::LeaveIfError( paramIndex );
       
  1260        User::LeaveIfError( stmt.BindInt( paramIndex, aTNId ));
       
  1261        
       
  1262        rowStatus = stmt.Next();    
       
  1263        }
       
  1264     
       
  1265     stmt_infodata.Close();
       
  1266     stmt_info.Close();
       
  1267     CleanupStack::PopAndDestroy( &stmt_infodata );
       
  1268     CleanupStack::PopAndDestroy( &stmt_info );
       
  1269         
       
  1270     
       
  1271     //look from real table       
       
  1272     TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByIdL() -- MAIN TABLE lookup" );
       
  1273     stmt.Close();
       
  1274     CleanupStack::PopAndDestroy( &stmt );
       
  1275     CleanupClosePushL( stmt );   
       
  1276     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectRowIDInfoByID ));
       
  1277         
       
  1278     User::LeaveIfError( err );
       
  1279         
       
  1280     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1281     User::LeaveIfError( paramIndex );
       
  1282     User::LeaveIfError( stmt.BindInt( paramIndex, aTNId ));
       
  1283              
       
  1284     rowStatus = stmt.Next();   
       
  1285     CleanupClosePushL( stmt_info );
       
  1286     err = stmt_info.Prepare( iDatabase, KThumbnailSqlDeleteInfoByID);
       
  1287     CleanupClosePushL( stmt_infodata );
       
  1288     err = stmt_infodata.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByID);
       
  1289            
       
  1290            
       
  1291     while(rowStatus == KSqlAtRow)
       
  1292        { 
       
  1293        rowid = stmt.ColumnInt( column ); 
       
  1294        paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
       
  1295        User::LeaveIfError( paramIndex1 );
       
  1296        User::LeaveIfError( stmt_info.BindInt( paramIndex1, rowid ));
       
  1297               
       
  1298        err = stmt_info.Exec();
       
  1299        stmt_info.Reset();
       
  1300        User::LeaveIfError( err );
       
  1301                     
       
  1302        paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );  
       
  1303        User::LeaveIfError( paramIndex2 );
       
  1304        User::LeaveIfError( stmt_infodata.BindInt( paramIndex2, rowid ));
       
  1305                     
       
  1306        err = stmt_infodata.Exec();
       
  1307        stmt_infodata.Reset();
       
  1308        User::LeaveIfError( err );
       
  1309        deleteCount++;
       
  1310        
       
  1311        TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByIdL() -- MAIN TABLE lookup - thumbnail deleted" );
       
  1312        
       
  1313        rowStatus = stmt.Next();
       
  1314        }
       
  1315         
       
  1316     stmt_infodata.Close();
       
  1317     stmt_info.Close();
       
  1318     stmt.Close();
       
  1319     CleanupStack::PopAndDestroy( &stmt_infodata );
       
  1320     CleanupStack::PopAndDestroy( &stmt_info );
       
  1321     CleanupStack::PopAndDestroy( &stmt );    
       
  1322     transaction.CommitL();
       
  1323     CleanupStack::PopAndDestroy( &transaction );
       
  1324     
  1215     
  1325 #ifdef _DEBUG
  1216 #ifdef _DEBUG
  1326     aStop.UniversalTime();
  1217     aStop.UniversalTime();
  1327     TN_DEBUG2( "CThumbnailStore::DeleteThumbnailsByIdL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  1218     TN_DEBUG2( "CThumbnailStore::DeleteThumbnailByPathL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  1328 #endif
  1219 #endif
  1329     
  1220     
  1330     if(!deleteCount)
  1221     // start maintenance if rows in main table were marked
  1331         {
  1222     if (!aForce && count > 0)
  1332         User::Leave(KErrNotFound);
  1223         {
  1333         }
  1224         TN_DEBUG2( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup - %d rows marked deleted", count);
  1334     }
  1225         
  1335 
  1226         iDeleteThumbs = ETrue;
       
  1227         iActivityManager->Start();
       
  1228         }
       
  1229     
       
  1230     CleanupStack::PopAndDestroy( path );
       
  1231     }
  1336 
  1232 
  1337 // ---------------------------------------------------------------------------
  1233 // ---------------------------------------------------------------------------
  1338 // CThumbnailStore::PersistentSizes()
  1234 // CThumbnailStore::PersistentSizes()
  1339 // ---------------------------------------------------------------------------
  1235 // ---------------------------------------------------------------------------
  1340 //
  1236 //
  1379     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailBeginTransaction %d", err_begin);
  1275     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailBeginTransaction %d", err_begin);
  1380     
  1276     
  1381     TInt err_tempinfo = iDatabase.Exec( KThumbnailMoveFromTempInfoToMainTable );
  1277     TInt err_tempinfo = iDatabase.Exec( KThumbnailMoveFromTempInfoToMainTable );
  1382     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailMoveFromTempInfoToMainTable %d", err_tempinfo);
  1278     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailMoveFromTempInfoToMainTable %d", err_tempinfo);
  1383     
  1279     
       
  1280 #ifdef _DEBUG
       
  1281     if(err_tempinfo < 0)
       
  1282         {
       
  1283         TPtrC errorMsg = iDatabase.LastErrorMessage();
       
  1284         TN_DEBUG2( "CThumbnailStore::FlushCacheTable() lastError %S", &errorMsg);
       
  1285         }
       
  1286 #endif
       
  1287     
       
  1288     if(err_tempinfo == KSqlErrCorrupt || err_tempinfo == KErrCorrupt )
       
  1289         {
       
  1290         TRAP_IGNORE(RecreateDatabaseL(ETrue));
       
  1291         TRAP_IGNORE(OpenDatabaseL());
       
  1292         return;
       
  1293         }
       
  1294     
  1384     TInt err_tempdata = iDatabase.Exec( KThumbnailMoveFromTempDataToMainTable );
  1295     TInt err_tempdata = iDatabase.Exec( KThumbnailMoveFromTempDataToMainTable );
  1385     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailMoveFromTempDataToMainTable %d", err_tempdata);
  1296     
       
  1297 #ifdef _DEBUG
       
  1298     if(err_tempdata < 0)
       
  1299         {
       
  1300         TPtrC errorMsg2 = iDatabase.LastErrorMessage();
       
  1301         TN_DEBUG2( "CThumbnailStore::FlushCacheTable() KThumbnailMoveFromTempDataToMainTable %S", &errorMsg2);
       
  1302         }
       
  1303 #endif
       
  1304     if(err_tempdata == KSqlErrCorrupt || err_tempdata == KErrCorrupt )
       
  1305         {
       
  1306         TRAP_IGNORE(RecreateDatabaseL(ETrue));
       
  1307         TRAP_IGNORE(OpenDatabaseL());
       
  1308         return;
       
  1309         }
       
  1310     
  1386     
  1311     
  1387     TInt err_delinfo = iDatabase.Exec( KThumbnailDeleteFromTempInfoTable );
  1312     TInt err_delinfo = iDatabase.Exec( KThumbnailDeleteFromTempInfoTable );
  1388     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailDeleteFromTempInfoTable %d", err_delinfo);
  1313     TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailDeleteFromTempInfoTable %d", err_delinfo);
  1389     
  1314     
  1390     TInt err_deldata = iDatabase.Exec( KThumbnailDeleteFromTempDataTable );
  1315     TInt err_deldata = iDatabase.Exec( KThumbnailDeleteFromTempDataTable );
  1406     aStop.UniversalTime();
  1331     aStop.UniversalTime();
  1407     TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  1332     TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  1408 #endif
  1333 #endif
  1409 
  1334 
  1410     TN_DEBUG1("CThumbnailStore::FlushCacheTable() out");
  1335     TN_DEBUG1("CThumbnailStore::FlushCacheTable() out");
  1411     }
       
  1412 
       
  1413 
       
  1414 // -----------------------------------------------------------------------------
       
  1415 // Find store for thumbnails by Id
       
  1416 // -----------------------------------------------------------------------------
       
  1417 //
       
  1418 void CThumbnailStore::FindStoreL(TThumbnailId aThumbnailId)
       
  1419     {
       
  1420     TN_DEBUG2( "CThumbnailStore::FindStore( %d )", aThumbnailId );
       
  1421      RSqlStatement stmt;
       
  1422      CleanupClosePushL( stmt );
       
  1423          
       
  1424      TInt paramIndex = 0;
       
  1425      TInt found = KErrNotFound;
       
  1426      TInt rowStatus = 0;
       
  1427          
       
  1428      TN_DEBUG1( "CThumbnailStore::FindStore() -- TEMP TABLE lookup" );
       
  1429      User::LeaveIfError( stmt.Prepare( iDatabase, KTempThumbnailSqlSelectRowIDInfoByID ));
       
  1430      paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1431      User::LeaveIfError( paramIndex );
       
  1432      User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
  1433          
       
  1434      rowStatus = stmt.Next();
       
  1435 
       
  1436     //if not found from temp table, look from real table
       
  1437     if(rowStatus != KSqlAtRow)
       
  1438         {
       
  1439         TN_DEBUG1( "CThumbnailStore::FindStore() -- MAIN TABLE lookup" );
       
  1440         stmt.Close();
       
  1441         CleanupStack::PopAndDestroy( &stmt );
       
  1442         CleanupClosePushL( stmt );
       
  1443             
       
  1444         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectRowIDInfoByID ));
       
  1445          
       
  1446         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1447         User::LeaveIfError( paramIndex );
       
  1448         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailId ));
       
  1449             
       
  1450         rowStatus = stmt.Next();
       
  1451         }
       
  1452 
       
  1453     if( rowStatus == KSqlAtRow )
       
  1454         {
       
  1455         TN_DEBUG1( "CThumbnailStore::FindStore() -- thumbnail found" );
       
  1456         found = KErrNone;
       
  1457         }
       
  1458     else
       
  1459         {
       
  1460         TN_DEBUG1( "CThumbnailStore::FindStore() -- thumbnail NOT found" );
       
  1461         }
       
  1462              
       
  1463     stmt.Close();
       
  1464     CleanupStack::PopAndDestroy( &stmt );
       
  1465 
       
  1466     User::LeaveIfError( found );
       
  1467     }
       
  1468 
       
  1469 // -----------------------------------------------------------------------------
       
  1470 // Updates path in current store by Id
       
  1471 // -----------------------------------------------------------------------------
       
  1472 //
       
  1473 TBool CThumbnailStore::UpdateStoreL( TThumbnailId aItemId, const TDesC& aNewPath )
       
  1474     {
       
  1475     TN_DEBUG3( "CThumbnailStore::UpdateStore( %d, %S) by ID", aItemId, &aNewPath);
       
  1476 
       
  1477     TBool doUpdate(EFalse);
       
  1478     TPath oldPath;
       
  1479     TInt column = 0;
       
  1480     
       
  1481     RSqlStatement stmt;
       
  1482     CleanupClosePushL( stmt );
       
  1483        
       
  1484     //check if path needs updating in temp table
       
  1485     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempPathByID ));
       
  1486     
       
  1487     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1488     User::LeaveIfError( paramIndex );
       
  1489     User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1490      
       
  1491     TInt rowStatus = stmt.Next();
       
  1492 
       
  1493      //if not found from temp table, look from real table
       
  1494      if(rowStatus != KSqlAtRow)
       
  1495          {
       
  1496          stmt.Close();
       
  1497          CleanupStack::PopAndDestroy( &stmt );
       
  1498          CleanupClosePushL( stmt );
       
  1499          
       
  1500          //check if path needs updating in main table
       
  1501          User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectPathByID ));
       
  1502          
       
  1503          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1504          User::LeaveIfError( paramIndex );
       
  1505          User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1506           
       
  1507          rowStatus = stmt.Next();
       
  1508          }
       
  1509      
       
  1510      if(rowStatus == KSqlAtRow)
       
  1511          {
       
  1512            TN_DEBUG1( "CThumbnailStore::UpdateStore() -- matching TN ID found" );
       
  1513            oldPath = stmt.ColumnTextL(column);
       
  1514             
       
  1515             if(oldPath.CompareF(aNewPath) != 0)
       
  1516                 {
       
  1517                 TN_DEBUG1( "CThumbnailStore::UpdateStore() -- path no match" );
       
  1518                 doUpdate = ETrue;
       
  1519                 }
       
  1520             else
       
  1521                 {
       
  1522                 TN_DEBUG1( "CThumbnailStore::UpdateStore() -- path match, skip..." );
       
  1523                 }
       
  1524          }
       
  1525      
       
  1526     stmt.Close();
       
  1527     CleanupStack::PopAndDestroy( &stmt );
       
  1528         
       
  1529     if(!doUpdate)
       
  1530         {
       
  1531         TN_DEBUG2( "CThumbnailStore::UpdateStore() -- no need to update old path=%S", &oldPath );
       
  1532         return EFalse;
       
  1533         }
       
  1534     
       
  1535     //Encapsulate update to Transaction
       
  1536     RThumbnailTransaction transaction( iDatabase );
       
  1537     CleanupClosePushL( transaction );
       
  1538     transaction.BeginL();
       
  1539 	
       
  1540     CleanupClosePushL( stmt );
       
  1541      
       
  1542     TN_DEBUG1( "CThumbnailStore::UpdateStore() -- do temp path update" );
       
  1543 
       
  1544     User::LeaveIfError( stmt.Prepare( iDatabase, KTempThumbnailSqlUpdateById ));
       
  1545     
       
  1546     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1547     User::LeaveIfError( paramIndex );
       
  1548     User::LeaveIfError( stmt.BindText( paramIndex, aNewPath ));
       
  1549        
       
  1550     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1551     User::LeaveIfError( paramIndex );
       
  1552     User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1553     User::LeaveIfError( stmt.Exec());
       
  1554     
       
  1555     stmt.Close();
       
  1556     CleanupStack::PopAndDestroy( &stmt );
       
  1557     CleanupClosePushL( stmt );
       
  1558     
       
  1559     TN_DEBUG1( "CThumbnailStore::UpdateStore() -- do main table path update" );
       
  1560              
       
  1561     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlUpdateById ));
       
  1562                 
       
  1563     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1564     User::LeaveIfError( paramIndex );
       
  1565     User::LeaveIfError( stmt.BindText( paramIndex, aNewPath ));
       
  1566 
       
  1567     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1568     User::LeaveIfError( paramIndex );
       
  1569     User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));  
       
  1570             
       
  1571     User::LeaveIfError( stmt.Exec());   
       
  1572     CleanupStack::PopAndDestroy( &stmt );
       
  1573     
       
  1574     // Commit transaction
       
  1575     transaction.CommitL();
       
  1576     CleanupStack::PopAndDestroy( &transaction );
       
  1577     
       
  1578     return ETrue;
       
  1579     }
       
  1580 
       
  1581 // -----------------------------------------------------------------------------
       
  1582 // Update IDs by Path
       
  1583 // -----------------------------------------------------------------------------
       
  1584 //
       
  1585 void CThumbnailStore::UpdateStoreL( const TDesC& aPath, TThumbnailId aNewId )
       
  1586     {
       
  1587     TN_DEBUG3( "CThumbnailStore::UpdateStore( %S, %d ) by Path", &aPath, aNewId);
       
  1588     
       
  1589 #ifdef _DEBUG
       
  1590     TTime aStart, aStop;
       
  1591     aStart.UniversalTime();
       
  1592 #endif
       
  1593     
       
  1594     //Encapsulate update to Transaction
       
  1595     RThumbnailTransaction transaction( iDatabase );
       
  1596     CleanupClosePushL( transaction );
       
  1597     transaction.BeginL();
       
  1598     
       
  1599     RSqlStatement stmt;
       
  1600     CleanupClosePushL( stmt );
       
  1601        
       
  1602     TN_DEBUG1( "CThumbnailStore::UpdateStoreL() -- do temp ID update" );
       
  1603     
       
  1604     TInt err = stmt.Prepare( iDatabase, KTempThumbnailUpdateIdByPath );
       
  1605     
       
  1606 #ifdef _DEBUG
       
  1607     TPtrC errorMsg = iDatabase.LastErrorMessage();
       
  1608     TN_DEBUG2( "CThumbnailStore::UpdateStoreL() KTempThumbnailUpdateIdByPath %S" , &errorMsg);
       
  1609 #endif
       
  1610     
       
  1611     User::LeaveIfError( err );
       
  1612     
       
  1613     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1614     User::LeaveIfError( paramIndex );
       
  1615     User::LeaveIfError( stmt.BindInt( paramIndex, aNewId ));
       
  1616     
       
  1617     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1618     User::LeaveIfError( paramIndex );
       
  1619     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
       
  1620     
       
  1621     err =  stmt.Exec();
       
  1622     
       
  1623     TN_DEBUG2( "CThumbnailStore::UpdateStoreL() err==%d", err );
       
  1624     
       
  1625     stmt.Close();
       
  1626     CleanupStack::PopAndDestroy( &stmt );
       
  1627     CleanupClosePushL( stmt );
       
  1628     
       
  1629     TN_DEBUG1( "CThumbnailStore::UpdateStoreL() -- do main table ID update" );
       
  1630     
       
  1631     err = stmt.Prepare( iDatabase, KThumbnailUpdateIdByPath );
       
  1632     
       
  1633 #ifdef _DEBUG
       
  1634     TPtrC errorMsg2 = iDatabase.LastErrorMessage();
       
  1635     TN_DEBUG2( "CThumbnailStore::UpdateStoreL() KThumbnailUpdateIdByPath %S" , &errorMsg2);
       
  1636 #endif    
       
  1637     
       
  1638     User::LeaveIfError( err );
       
  1639     
       
  1640     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1641     User::LeaveIfError( paramIndex );
       
  1642     User::LeaveIfError( stmt.BindInt( paramIndex, aNewId ));
       
  1643     
       
  1644     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1645     User::LeaveIfError( paramIndex );
       
  1646     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
       
  1647     
       
  1648     err =  stmt.Exec();
       
  1649     
       
  1650     TN_DEBUG2( "CThumbnailStore::UpdateStoreL() err==%d", err );
       
  1651     
       
  1652     stmt.Close();
       
  1653     CleanupStack::PopAndDestroy( &stmt ); 
       
  1654     
       
  1655     // Commit transaction
       
  1656     transaction.CommitL();
       
  1657     CleanupStack::PopAndDestroy( &transaction );
       
  1658     
       
  1659 #ifdef _DEBUG
       
  1660     aStop.UniversalTime();
       
  1661     TN_DEBUG2( "CThumbnailStore::UpdateStoreL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
  1662 #endif
       
  1663     }
       
  1664 
       
  1665 // -----------------------------------------------------------------------------
       
  1666 // Checks if given modification timestamp is newer than in DB
       
  1667 // -----------------------------------------------------------------------------
       
  1668 //
       
  1669 TBool CThumbnailStore::CheckModifiedL( const TThumbnailId aItemId, const TInt64 aModified )
       
  1670     {
       
  1671     TN_DEBUG2( "CThumbnailStore::CheckModifiedL( %d )", aItemId);
       
  1672 
       
  1673     TInt column = 0;
       
  1674     
       
  1675     RSqlStatement stmt;
       
  1676     CleanupClosePushL( stmt );
       
  1677        
       
  1678     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempModifiedByID ));
       
  1679     
       
  1680     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1681     User::LeaveIfError( paramIndex );
       
  1682     User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1683      
       
  1684     TInt rowStatus = stmt.Next();
       
  1685 
       
  1686      //if not found from temp table, look from real table
       
  1687      if(rowStatus != KSqlAtRow)
       
  1688          {
       
  1689          stmt.Close();
       
  1690          CleanupStack::PopAndDestroy( &stmt );
       
  1691          CleanupClosePushL( stmt );
       
  1692          
       
  1693          User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectModifiedByID ));
       
  1694          
       
  1695          paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1696          User::LeaveIfError( paramIndex );
       
  1697          User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1698           
       
  1699          rowStatus = stmt.Next();
       
  1700          }
       
  1701      
       
  1702      TBool modified = EFalse;
       
  1703      
       
  1704      if(rowStatus == KSqlAtRow)
       
  1705          {
       
  1706          TInt64 oldModified = stmt.ColumnInt64( column );
       
  1707          
       
  1708          if (oldModified < aModified)
       
  1709              {
       
  1710              TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is newer than original" );
       
  1711              modified = ETrue;
       
  1712              }
       
  1713          else if (oldModified > aModified)
       
  1714              {
       
  1715              TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is older than original" );
       
  1716              }
       
  1717          else if (oldModified == aModified)
       
  1718              {
       
  1719              TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is the same as original" );
       
  1720              }
       
  1721          }
       
  1722      
       
  1723     stmt.Close();
       
  1724     CleanupStack::PopAndDestroy( &stmt ); 
       
  1725     
       
  1726     return modified;
       
  1727     }
       
  1728 
       
  1729 // -----------------------------------------------------------------------------
       
  1730 // Fetches thumbnails from store by Id
       
  1731 // -----------------------------------------------------------------------------
       
  1732 //
       
  1733 void CThumbnailStore::FetchThumbnailsL(TThumbnailId aItemId, RArray < TThumbnailDatabaseData* >& aThumbnails)
       
  1734     {
       
  1735     TN_DEBUG1( "CThumbnailStore::FetchThumbnails()" );
       
  1736     RSqlStatement stmt;
       
  1737     CleanupClosePushL( stmt );
       
  1738     
       
  1739     // first temp table
       
  1740     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempById ));
       
  1741 
       
  1742     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1743     User::LeaveIfError( paramIndex );
       
  1744     User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1745 
       
  1746     TInt rowStatus = stmt.Next();
       
  1747     
       
  1748     TPath path;
       
  1749     TPath tnPath;
       
  1750     while ( rowStatus == KSqlAtRow)
       
  1751         {
       
  1752         TN_DEBUG1( "CThumbnailStore::FetchThumbnails() -- thumbnail found from temp table" );
       
  1753         
       
  1754         TInt column = 0;
       
  1755             
       
  1756         TThumbnailDatabaseData* newRow = new(ELeave) TThumbnailDatabaseData;
       
  1757             
       
  1758         TInt err = stmt.ColumnText( column++, newRow->iPath );
       
  1759         newRow->iTnId = stmt.ColumnInt( column++ );
       
  1760         newRow->iSize = stmt.ColumnInt( column++ );
       
  1761         newRow->iFormat = stmt.ColumnInt( column++ );
       
  1762         err = stmt.ColumnText( column++, newRow->iTnPath);
       
  1763         newRow->iWidth = stmt.ColumnInt( column++ );
       
  1764         newRow->iHeight = stmt.ColumnInt( column++ );
       
  1765         newRow->iOrigWidth = stmt.ColumnInt( column++ );
       
  1766         newRow->iOrigHeight = stmt.ColumnInt( column++ );
       
  1767         newRow->iFlags = stmt.ColumnInt( column++ );
       
  1768         newRow->iVideoPosition = stmt.ColumnInt( column++ );
       
  1769         newRow->iOrientation = stmt.ColumnInt( column++ );
       
  1770         newRow->iThumbFromPath = stmt.ColumnInt( column++ );
       
  1771         newRow->iModified = stmt.ColumnInt64( column++ );
       
  1772         
       
  1773         if(newRow->iFormat == 0)
       
  1774             {
       
  1775             TPtrC8 ptr = stmt.ColumnBinaryL( column++ );
       
  1776             RDesReadStream stream( ptr );
       
  1777             newRow->iBlob = new( ELeave )CFbsBitmap();
       
  1778             newRow->iBlob->InternalizeL( stream );
       
  1779             }
       
  1780         else if(newRow->iFormat == 1)
       
  1781             {
       
  1782             TPtrC8 ptr = stmt.ColumnBinaryL( column++ );
       
  1783             HBufC8* data = ptr.AllocL() ;
       
  1784             newRow->iBlob = NULL;
       
  1785             newRow->iData = data;
       
  1786             }
       
  1787         
       
  1788         aThumbnails.Append( newRow );
       
  1789                
       
  1790         rowStatus = stmt.Next();
       
  1791         }
       
  1792     
       
  1793     // then real table
       
  1794     stmt.Close();
       
  1795     CleanupStack::PopAndDestroy(&stmt); 
       
  1796     CleanupClosePushL( stmt );
       
  1797     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectById ));
       
  1798 
       
  1799     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1800     User::LeaveIfError( paramIndex );
       
  1801     User::LeaveIfError( stmt.BindInt( paramIndex, aItemId ));
       
  1802 
       
  1803     rowStatus = stmt.Next();
       
  1804     while ( rowStatus == KSqlAtRow)
       
  1805         {
       
  1806         TN_DEBUG1( "CThumbnailStore::FetchThumbnails() -- thumbnail found from real table" );
       
  1807         
       
  1808         TInt column = 0;
       
  1809         
       
  1810         TThumbnailDatabaseData* newRow = new(ELeave) TThumbnailDatabaseData;
       
  1811         
       
  1812         TInt err = stmt.ColumnText( column++, newRow->iPath );
       
  1813         newRow->iTnId = stmt.ColumnInt( column++ );
       
  1814         newRow->iSize = stmt.ColumnInt( column++ );
       
  1815         newRow->iFormat = stmt.ColumnInt( column++ );
       
  1816         err = stmt.ColumnText( column++, newRow->iTnPath);
       
  1817         newRow->iWidth = stmt.ColumnInt( column++ );
       
  1818         newRow->iHeight = stmt.ColumnInt( column++ );
       
  1819         newRow->iOrigWidth = stmt.ColumnInt( column++ );
       
  1820         newRow->iOrigHeight = stmt.ColumnInt( column++ );
       
  1821         newRow->iFlags = stmt.ColumnInt( column++ );
       
  1822         newRow->iVideoPosition = stmt.ColumnInt( column++ );
       
  1823         newRow->iOrientation = stmt.ColumnInt( column++ );
       
  1824         newRow->iThumbFromPath = stmt.ColumnInt( column++ );
       
  1825         newRow->iModified = stmt.ColumnInt64( column++ );
       
  1826         
       
  1827         if(newRow->iFormat == 0)
       
  1828             {
       
  1829             TPtrC8 ptr = stmt.ColumnBinaryL( column++ );
       
  1830             RDesReadStream stream( ptr );
       
  1831             newRow->iBlob = new( ELeave )CFbsBitmap();
       
  1832             newRow->iBlob->InternalizeL( stream );
       
  1833             }
       
  1834         else if(newRow->iFormat == 1)
       
  1835             {
       
  1836             TPtrC8 ptr = stmt.ColumnBinaryL( column++ );
       
  1837             HBufC8* data = ptr.AllocL() ;
       
  1838             newRow->iBlob = NULL;
       
  1839             newRow->iData = data;
       
  1840             }
       
  1841         
       
  1842         aThumbnails.Append( newRow );
       
  1843               
       
  1844         rowStatus = stmt.Next();
       
  1845         }
       
  1846     
       
  1847     stmt.Close();
       
  1848     CleanupStack::PopAndDestroy( &stmt );
       
  1849     }
       
  1850 
       
  1851 // -----------------------------------------------------------------------------
       
  1852 // Stores thumbnails to store
       
  1853 // -----------------------------------------------------------------------------
       
  1854 //
       
  1855 
       
  1856 void CThumbnailStore::StoreThumbnailsL(const TDesC& aNewPath, RArray < TThumbnailDatabaseData* >& aThumbnails)
       
  1857     {
       
  1858     TN_DEBUG1( "CThumbnailStore::StoreThumbnails()" );
       
  1859     
       
  1860     TInt ThumbnailCount = aThumbnails.Count();
       
  1861     RSqlStatement stmt;
       
  1862     for ( TInt i = 0; i < ThumbnailCount; i++ )
       
  1863         {
       
  1864         RThumbnailTransaction transaction( iDatabase );
       
  1865         CleanupClosePushL( transaction );
       
  1866         transaction.BeginL();
       
  1867         
       
  1868         CleanupClosePushL( stmt );
       
  1869           
       
  1870         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailInsertThumbnailInfoByPathAndId ));
       
  1871         
       
  1872         TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1873         User::LeaveIfError( paramIndex );
       
  1874         User::LeaveIfError( stmt.BindText( paramIndex, aNewPath ));
       
  1875         
       
  1876         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamWidth );
       
  1877         User::LeaveIfError( paramIndex );
       
  1878         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iWidth ));
       
  1879         
       
  1880         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamHeight );
       
  1881         User::LeaveIfError( paramIndex );
       
  1882         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iHeight ));
       
  1883         
       
  1884         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOriginalWidth );
       
  1885         User::LeaveIfError( paramIndex );
       
  1886         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iOrigWidth ));
       
  1887         
       
  1888         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOriginalHeight );
       
  1889         User::LeaveIfError( paramIndex );
       
  1890         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iOrigHeight ));
       
  1891         
       
  1892         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamFormat );
       
  1893         User::LeaveIfError( paramIndex );
       
  1894         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iFormat ));
       
  1895         
       
  1896         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamFlags );
       
  1897         User::LeaveIfError( paramIndex );
       
  1898         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iFlags ));
       
  1899         
       
  1900         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize );
       
  1901         User::LeaveIfError( paramIndex );
       
  1902         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iSize ));
       
  1903         
       
  1904         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
       
  1905         User::LeaveIfError( paramIndex );
       
  1906         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iTnId ));
       
  1907         
       
  1908         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOrientation );
       
  1909         User::LeaveIfError( paramIndex );
       
  1910         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iOrientation ));
       
  1911         
       
  1912         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamThumbFromPath );
       
  1913         User::LeaveIfError( paramIndex );
       
  1914         User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnails[ i ]->iThumbFromPath ));
       
  1915         
       
  1916         paramIndex = stmt.ParameterIndex( KThumbnailSqlParamModified );
       
  1917         User::LeaveIfError( paramIndex );
       
  1918         User::LeaveIfError( stmt.BindInt64( paramIndex, aThumbnails[ i ]->iModified ));
       
  1919         
       
  1920         User::LeaveIfError( stmt.Exec());    
       
  1921         CleanupStack::PopAndDestroy( &stmt );
       
  1922         
       
  1923         RSqlStatement stmtData;
       
  1924         CleanupClosePushL( stmtData );
       
  1925         TInt err = stmtData.Prepare( iDatabase, KThumbnailInsertTempThumbnailInfoData );
       
  1926         
       
  1927         if(aThumbnails[ i ]->iFormat == 0)
       
  1928             {
       
  1929             CBufFlat* buf = CBufFlat::NewL( KStreamBufferSize );
       
  1930             CleanupStack::PushL( buf );
       
  1931             RBufWriteStream stream;
       
  1932             stream.Open( *buf );
       
  1933             aThumbnails[ i ]->iBlob->ExternalizeL( stream );
       
  1934             paramIndex = stmtData.ParameterIndex( KThumbnailSqlParamData );
       
  1935             User::LeaveIfError( paramIndex );
       
  1936             User::LeaveIfError( stmtData.BindBinary( paramIndex, buf->Ptr( 0 ) ));
       
  1937             CleanupStack::PopAndDestroy( buf );
       
  1938             delete aThumbnails[i]->iBlob;
       
  1939             aThumbnails[i]->iBlob = NULL;
       
  1940             }
       
  1941         else if(aThumbnails[ i ]->iFormat == 1)
       
  1942             {
       
  1943             paramIndex = stmtData.ParameterIndex( KThumbnailSqlParamData );
       
  1944             User::LeaveIfError( paramIndex );
       
  1945             User::LeaveIfError( stmtData.BindBinary( paramIndex, *aThumbnails[ i ]->iData ));
       
  1946             delete aThumbnails[i]->iData;
       
  1947             aThumbnails[i]->iData = NULL;
       
  1948             }
       
  1949         
       
  1950         User::LeaveIfError( stmtData.Exec());
       
  1951         CleanupStack::PopAndDestroy( &stmtData );
       
  1952         
       
  1953         // Commit transaction
       
  1954         transaction.CommitL();
       
  1955         CleanupStack::PopAndDestroy( &transaction );
       
  1956         
       
  1957         delete aThumbnails[i];
       
  1958         aThumbnails[i] = NULL;
       
  1959         iBatchItemCount++;                          
       
  1960         }
       
  1961     
       
  1962     FlushCacheTable();
       
  1963     }
  1336     }
  1964 
  1337 
  1965 // -----------------------------------------------------------------------------
  1338 // -----------------------------------------------------------------------------
  1966 // CheckVersionAndImeiL()
  1339 // CheckVersionAndImeiL()
  1967 // -----------------------------------------------------------------------------
  1340 // -----------------------------------------------------------------------------
  1979     TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion );
  1352     TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion );
  1980     if(ret < 0 )
  1353     if(ret < 0 )
  1981        {  
  1354        {  
  1982        stmt.Close();
  1355        stmt.Close();
  1983        CleanupStack::PopAndDestroy( &stmt ); 
  1356        CleanupStack::PopAndDestroy( &stmt ); 
       
  1357 
       
  1358        TN_DEBUG1( "CThumbnailStore::CheckImeiL() failed" );
  1984        return KErrNotSupported;
  1359        return KErrNotSupported;
  1985        }
  1360        }
  1986               
  1361               
  1987     rowStatus = stmt.Next();
  1362     rowStatus = stmt.Next();
  1988     
  1363     
  1992        stmt.ColumnText( column++, imei);  
  1367        stmt.ColumnText( column++, imei);  
  1993        }
  1368        }
  1994     
  1369     
  1995     stmt.Close();
  1370     stmt.Close();
  1996     CleanupStack::PopAndDestroy( &stmt ); 
  1371     CleanupStack::PopAndDestroy( &stmt ); 
       
  1372     
       
  1373     if(ret < 0 )
       
  1374         {
       
  1375 #ifdef _DEBUG
       
  1376    		 TPtrC errorMsg = iDatabase.LastErrorMessage();
       
  1377     	TN_DEBUG2( "RThumbnailTransaction::CheckImeiL() lastError %S, ret = %d" , &errorMsg);
       
  1378 #endif
       
  1379         return ret;
       
  1380         }
  1997     
  1381     
  1998     if( imei == iImei )
  1382     if( imei == iImei )
  1999       {
  1383       {
  2000       return KErrNone;  
  1384       return KErrNone;  
  2001       }
  1385       }
  2002     else
  1386     else
  2003       {
  1387       {
       
  1388       TN_DEBUG1( "CThumbnailStore::CheckImeiL() mismatch" );
  2004       return KErrNotSupported;  
  1389       return KErrNotSupported;  
  2005       }
  1390       }
  2006     }
  1391     }
  2007 
  1392 
  2008 // -----------------------------------------------------------------------------
  1393 // -----------------------------------------------------------------------------
  2024     TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion );
  1409     TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion );
  2025     if(ret < 0 )
  1410     if(ret < 0 )
  2026        {  
  1411        {  
  2027        stmt.Close();
  1412        stmt.Close();
  2028        CleanupStack::PopAndDestroy( &stmt ); 
  1413        CleanupStack::PopAndDestroy( &stmt ); 
       
  1414        TN_DEBUG1( "CThumbnailStore::CheckVersionL() unknown version" );
  2029        return KErrNotSupported;
  1415        return KErrNotSupported;
  2030        }
  1416        }
  2031               
  1417               
  2032     rowStatus = stmt.Next();
  1418     rowStatus = stmt.Next();
  2033     
  1419     
  2037        minor = stmt.ColumnInt( column++);
  1423        minor = stmt.ColumnInt( column++);
  2038        }
  1424        }
  2039     
  1425     
  2040     stmt.Close();
  1426     stmt.Close();
  2041     CleanupStack::PopAndDestroy( &stmt ); 
  1427     CleanupStack::PopAndDestroy( &stmt ); 
       
  1428     
       
  1429     if(ret < 0 )
       
  1430         {
       
  1431 #ifdef _DEBUG
       
  1432    		 TPtrC errorMsg = iDatabase.LastErrorMessage();
       
  1433     	TN_DEBUG2( "RThumbnailTransaction::CheckVersionL() lastError %S, ret = %d" , &errorMsg);
       
  1434 #endif
       
  1435         return ret;
       
  1436         }
  2042     
  1437     
  2043     if(major == KMajor && minor == KMinor )
  1438     if(major == KMajor && minor == KMinor )
  2044       {
  1439       {
  2045       return KErrNone;  
  1440       return KErrNone;  
  2046       }
  1441       }
  2114 
  1509 
  2115 // -----------------------------------------------------------------------------
  1510 // -----------------------------------------------------------------------------
  2116 // ResetThumbnailIDs()
  1511 // ResetThumbnailIDs()
  2117 // -----------------------------------------------------------------------------
  1512 // -----------------------------------------------------------------------------
  2118 //
  1513 //
  2119 void CThumbnailStore::ResetThumbnailIDs()
  1514 TInt CThumbnailStore::ResetThumbnailIDs()
  2120     {
  1515     {
  2121     TN_DEBUG1( "CThumbnailStore::ResetThumbnailIDs()" );
  1516     TN_DEBUG1( "CThumbnailStore::ResetThumbnailIDs()" );
  2122 
  1517 
  2123     TInt err = iDatabase.Exec( KTempThumbnailResetIDs );
  1518     TInt err = iDatabase.Exec( KTempThumbnailResetIDs );
  2124     TN_DEBUG2( "CThumbnailStore::ResetThumbnailIDs() KThumbnailResetIDs - temp table, err=%d", err );
  1519     TN_DEBUG2( "CThumbnailStore::ResetThumbnailIDs() KThumbnailResetIDs - temp table, err=%d", err );
  2125     
  1520 
       
  1521     if(err < 0)
       
  1522         {
       
  1523 #ifdef _DEBUG
       
  1524         TPtrC errorMsg = iDatabase.LastErrorMessage();
       
  1525         TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg);
       
  1526 #endif
       
  1527         return err;
       
  1528     }
       
  1529 
  2126     err = iDatabase.Exec( KThumbnailResetIDs );
  1530     err = iDatabase.Exec( KThumbnailResetIDs );
  2127     TN_DEBUG2( "CThumbnailStore::ResetThumbnailIDs() KThumbnailResetIDs - main table, err=%d", err );
  1531     TN_DEBUG2( "CThumbnailStore::ResetThumbnailIDs() KThumbnailResetIDs - main table, err=%d", err );
       
  1532     
       
  1533 	if(err < 0)
       
  1534         {
       
  1535 #ifdef _DEBUG
       
  1536         TPtrC errorMsg2 = iDatabase.LastErrorMessage();
       
  1537         TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2);
       
  1538 #endif
       
  1539         return err;
       
  1540         }
       
  1541 	return KErrNone;
  2128     }
  1542     }
  2129 
  1543 
  2130 
  1544 
  2131 // -----------------------------------------------------------------------------
  1545 // -----------------------------------------------------------------------------
  2132 // UpdateImeiL()
  1546 // UpdateImeiL()
  2133 // -----------------------------------------------------------------------------
  1547 // -----------------------------------------------------------------------------
  2134 //
  1548 //
  2135 void CThumbnailStore::UpdateImeiL()
  1549 TInt CThumbnailStore::UpdateImeiL()
  2136     {
  1550     {
  2137     TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" );
  1551     TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" );
  2138     RSqlStatement stmt;
  1552     RSqlStatement stmt;
  2139     CleanupClosePushL( stmt );
  1553     CleanupClosePushL( stmt );
  2140          
  1554          
  2145     User::LeaveIfError( paramIndex );
  1559     User::LeaveIfError( paramIndex );
  2146     User::LeaveIfError( stmt.BindText( paramIndex, iImei ));
  1560     User::LeaveIfError( stmt.BindText( paramIndex, iImei ));
  2147     
  1561     
  2148     TInt err =  stmt.Exec();
  1562     TInt err =  stmt.Exec();
  2149     
  1563     
  2150     TN_DEBUG2( "CThumbnailStore::UpdateImeiL() err==%d", err );
  1564     if(err < 0)
  2151     
  1565         {
  2152     User::LeaveIfError( err );
  1566 #ifdef _DEBUG
       
  1567         TPtrC errorMsg2 = iDatabase.LastErrorMessage();
       
  1568         TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2);
       
  1569 #endif
       
  1570         return ret;
       
  1571         }
  2153     
  1572     
  2154     stmt.Close();
  1573     stmt.Close();
  2155     CleanupStack::PopAndDestroy( &stmt ); 
  1574     CleanupStack::PopAndDestroy( &stmt );
       
  1575     return KErrNone;
  2156     }
  1576     }
  2157 
  1577 
  2158 // -----------------------------------------------------------------------------
  1578 // -----------------------------------------------------------------------------
  2159 // StartAutoFlush()
  1579 // StartAutoFlush()
  2160 // -----------------------------------------------------------------------------
  1580 // -----------------------------------------------------------------------------
  2178         {
  1598         {
  2179         TN_DEBUG2( "CThumbnailStore::StartAutoFlush() - Error creating timer (%d)", err );
  1599         TN_DEBUG2( "CThumbnailStore::StartAutoFlush() - Error creating timer (%d)", err );
  2180         }
  1600         }
  2181     else
  1601     else
  2182         {
  1602         {
  2183         iAutoFlushTimer->Start( KAutoFlushTimeout, KAutoFlushTimeout, 
  1603         iAutoFlushTimer->Start( KAutoFlushTimeout * 1000000, KAutoFlushTimeout * 1000000, 
  2184                                 TCallBack(AutoFlushTimerCallBack, this));
  1604                                 TCallBack(AutoFlushTimerCallBack, this));
  2185         }
  1605         }
  2186     }
  1606     }
  2187 
  1607 
  2188 // -----------------------------------------------------------------------------
  1608 // -----------------------------------------------------------------------------
  2196         {
  1616         {
  2197         iAutoFlushTimer->Cancel();
  1617         iAutoFlushTimer->Cancel();
  2198         }
  1618         }
  2199     }
  1619     }
  2200 
  1620 
       
  1621 // -----------------------------------------------------------------------------
       
  1622 // StartMaintenance()
       
  1623 // -----------------------------------------------------------------------------
       
  1624 //
       
  1625 void CThumbnailStore::StartMaintenance()
       
  1626     {
       
  1627     TN_DEBUG1( "CThumbnailStore::StartMaintenance()");
       
  1628     TInt err = KErrNone;
       
  1629     
       
  1630     if( iMaintenanceTimer && iMaintenanceTimer->IsActive() )
       
  1631         {
       
  1632         return;
       
  1633         }
       
  1634     else if (!iMaintenanceTimer)
       
  1635         {
       
  1636         TRAP(err, iMaintenanceTimer = CPeriodic::NewL(CActive::EPriorityIdle) );
       
  1637         }
       
  1638     
       
  1639     if (err != KErrNone && !iMaintenanceTimer)
       
  1640         {
       
  1641         TN_DEBUG2( "CThumbnailStore::StartMaintenanceTimer() - Error creating timer (%d)", err );
       
  1642         }
       
  1643     else
       
  1644         {
       
  1645         iMaintenanceTimer->Start( KStoreMaintenancePeriodic, KStoreMaintenancePeriodic, 
       
  1646                                   TCallBack(MaintenanceTimerCallBack, this));
       
  1647         }
       
  1648     }
       
  1649 
  2201 // ---------------------------------------------------------------------------
  1650 // ---------------------------------------------------------------------------
  2202 // CThumbnailStore::AutoFlushTimerCallBack()
  1651 // CThumbnailStore::AutoFlushTimerCallBack()
  2203 // ---------------------------------------------------------------------------
  1652 // ---------------------------------------------------------------------------
  2204 //
  1653 //
  2205 TInt CThumbnailStore::AutoFlushTimerCallBack(TAny* aAny)
  1654 TInt CThumbnailStore::AutoFlushTimerCallBack(TAny* aAny)
  2206     {
  1655     {
  2207     TN_DEBUG1( "CThumbnailStore::AutoFlushTimerCallBack()");
  1656     TN_DEBUG1( "CThumbnailStore::AutoFlushTimerCallBack()");
  2208     CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny );
  1657     CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny );
  2209     
  1658     
  2210     self->FlushCacheTable(ETrue);
  1659     self->FlushCacheTable(ETrue);
       
  1660 
       
  1661     return KErrNone; // Return value ignored by CPeriodic
       
  1662     }
       
  1663 
       
  1664 // ---------------------------------------------------------------------------
       
  1665 // CThumbnailStore::MaintenanceTimerCallBack()
       
  1666 // ---------------------------------------------------------------------------
       
  1667 //
       
  1668 TInt CThumbnailStore::MaintenanceTimerCallBack(TAny* aAny)
       
  1669     {
       
  1670     CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny );
       
  1671  
       
  1672     self->iMaintenanceTimer->Cancel();
       
  1673     
       
  1674     if (self->iIdle)
       
  1675         {
       
  1676         TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive);
       
  1677     
       
  1678         // thumbmnail deletion
       
  1679         if (self->iDeleteThumbs)
       
  1680             {
       
  1681             TInt deleteCount = 0;
       
  1682             
       
  1683             // delete marked rows from database
       
  1684             TRAPD( err, deleteCount = self->DeleteMarkedL() );
       
  1685             if (err != KErrNone)
       
  1686                 {
       
  1687                 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - cleanup failed, err %d", err);
       
  1688                 return err;
       
  1689                 }
       
  1690             
       
  1691             // no more marked rows
       
  1692             if (deleteCount < KStoreMaintenanceDeleteLimit || deleteCount == 0)
       
  1693                 {
       
  1694                 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - cleanup finished, store %d", self->iDrive);
       
  1695                 self->iDeleteThumbs = EFalse;
       
  1696                 }     
       
  1697             }
       
  1698         
       
  1699         // file existance check
       
  1700         else if (self->iCheckFilesExist)
       
  1701             {
       
  1702             TBool finished = EFalse;
       
  1703         
       
  1704             TRAPD( err, finished = self->FileExistenceCheckL() );
       
  1705             if (err != KErrNone)
       
  1706                 {
       
  1707                 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - file existance check failed, err %d", err);
       
  1708                 return err;
       
  1709                 }
       
  1710         
       
  1711             // all files checked.
       
  1712             if (finished)
       
  1713                 {
       
  1714                 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - file existance check finished, store %d", self->iDrive);
       
  1715                 self->iCheckFilesExist = EFalse;
       
  1716                 }
       
  1717             }
       
  1718         
       
  1719         // next round
       
  1720         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
       
  1721             {
       
  1722             self->StartMaintenance();
       
  1723             }  
       
  1724         else
       
  1725             {
       
  1726             // no need to monitor activity anymore
       
  1727             self->iActivityManager->Cancel();
       
  1728             }
       
  1729         }
       
  1730     else
       
  1731         {
       
  1732         TN_DEBUG1( "CThumbnailStore::MaintenanceTimerCallBack() - device not idle");
       
  1733         }
  2211 
  1734 
  2212     return KErrNone; // Return value ignored by CPeriodic
  1735     return KErrNone; // Return value ignored by CPeriodic
  2213     }
  1736     }
  2214 
  1737 
  2215 TInt CThumbnailStore::CheckRowIDsL()
  1738 TInt CThumbnailStore::CheckRowIDsL()
  2226     TInt ret = stmt.Prepare( iDatabase, KGetInfoRowID );
  1749     TInt ret = stmt.Prepare( iDatabase, KGetInfoRowID );
  2227     if(ret < 0)
  1750     if(ret < 0)
  2228         {
  1751         {
  2229         stmt.Close();
  1752         stmt.Close();
  2230         CleanupStack::PopAndDestroy( &stmt );
  1753         CleanupStack::PopAndDestroy( &stmt );
       
  1754         TN_DEBUG1( "CThumbnailStore::CheckRowIDs() failed 1 %d");
  2231         return KErrNotSupported;
  1755         return KErrNotSupported;
  2232         }
  1756         }
  2233     rowStatus = stmt.Next();
  1757     rowStatus = stmt.Next();
  2234                 
  1758                 
  2235     if ( rowStatus == KSqlAtRow)    
  1759     if ( rowStatus == KSqlAtRow)    
  2236         {        
  1760         {        
  2237         inforows = stmt.ColumnInt64( column );  
  1761         inforows = stmt.ColumnInt64( column );  
  2238         }
  1762         }
  2239             
  1763                 
  2240     stmt.Close();
  1764     stmt.Close();
  2241     CleanupStack::PopAndDestroy( &stmt );
  1765     CleanupStack::PopAndDestroy( &stmt );
       
  1766     
       
  1767     if(ret < 0)
       
  1768         {
       
  1769 #ifdef _DEBUG
       
  1770 		TPtrC errorMsg2 = iDatabase.LastErrorMessage();
       
  1771 	    TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2);
       
  1772 #endif
       
  1773         return ret;
       
  1774         }
  2242             
  1775             
  2243     CleanupClosePushL( stmt );
  1776     CleanupClosePushL( stmt );
  2244     ret = stmt.Prepare( iDatabase, KGetDataRowID );
  1777     ret = stmt.Prepare( iDatabase, KGetDataRowID );
  2245     if(ret < 0)
  1778     if(ret < 0)
  2246         {
  1779         {
  2247         stmt.Close();
  1780         stmt.Close();
  2248         CleanupStack::PopAndDestroy( &stmt );
  1781         CleanupStack::PopAndDestroy( &stmt );
       
  1782         TN_DEBUG1( "CThumbnailStore::CheckRowIDs() failed 2");
  2249         return KErrNotSupported;
  1783         return KErrNotSupported;
  2250         }
  1784         }
  2251     rowStatus = stmt.Next();
  1785     rowStatus = stmt.Next();
  2252                        
  1786                        
  2253     if ( rowStatus == KSqlAtRow)    
  1787     if ( rowStatus == KSqlAtRow)    
  2255         datarows = stmt.ColumnInt64( column );  
  1789         datarows = stmt.ColumnInt64( column );  
  2256         }
  1790         }
  2257             
  1791             
  2258     stmt.Close();
  1792     stmt.Close();
  2259     CleanupStack::PopAndDestroy( &stmt );
  1793     CleanupStack::PopAndDestroy( &stmt );
       
  1794     
       
  1795     if(ret < 0)
       
  1796         {
       
  1797 #ifdef _DEBUG
       
  1798 		TPtrC errorMsg2 = iDatabase.LastErrorMessage();
       
  1799 	    TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2);
       
  1800 #endif
       
  1801         return ret;
       
  1802         }
  2260             
  1803             
  2261     if( inforows != datarows)
  1804     if( inforows != datarows)
  2262         {
  1805         {
  2263         TN_DEBUG1( "CThumbnailStore::CheckRowIDsL() - tables out of sync" );
  1806         TN_DEBUG1( "CThumbnailStore::CheckRowIDsL() - tables out of sync" );
  2264         return KErrNotSupported;
  1807         return KErrNotSupported;
  2267         {
  1810         {
  2268         return KErrNone;
  1811         return KErrNone;
  2269         }
  1812         }
  2270     }
  1813     }
  2271 
  1814 
  2272 void CThumbnailStore::CheckModifiedByIdL( TUint32 aId, TBool aTempTable,
  1815 TBool CThumbnailStore::CheckModifiedByPathL( const TDesC& aPath, const TInt64 aModified, TBool& modifiedChanged )
  2273     TBool& aModified )
  1816     {
  2274     {
  1817     TN_DEBUG2( "CThumbnailStore::CheckModifiedByPathL() %S", &aPath);
  2275     TN_DEBUG1( "CThumbnailStore::CheckModifiedByIdL()");
  1818     
       
  1819     HBufC* path = aPath.AllocLC();
       
  1820     TPtr ptr(path->Des());
       
  1821     StripDriveLetterL( ptr );
       
  1822 	
       
  1823     TBool ret(EFalse);
       
  1824 
       
  1825     modifiedChanged = EFalse;
       
  1826 
       
  1827    TInt column = 0;
       
  1828    
       
  1829    RSqlStatement stmt;
       
  1830    CleanupClosePushL( stmt );
       
  1831       
       
  1832    User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempModifiedByPath ));
       
  1833    
       
  1834    TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1835    User::LeaveIfError( paramIndex );
       
  1836    User::LeaveIfError( stmt.BindText( paramIndex, *path ));
       
  1837     
       
  1838    TInt rowStatus = stmt.Next();
       
  1839    
       
  1840    TBool checkMain = EFalse;
       
  1841    
       
  1842    TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- temp" );
       
  1843    
       
  1844    while(rowStatus == KSqlAtRow || !checkMain)
       
  1845        {
       
  1846        if(rowStatus == KSqlAtRow)
       
  1847            {
       
  1848            ret = ETrue;
       
  1849            TInt64 oldModified = stmt.ColumnInt64( column );
       
  1850            
       
  1851            TN_DEBUG2( "CThumbnailStore::CheckModifiedL() -- timestamp old %Ld", oldModified);
       
  1852            TN_DEBUG2( "CThumbnailStore::CheckModifiedL() -- timestamp mds %Ld", aModified);
       
  1853           
       
  1854            if (oldModified < aModified)
       
  1855                {
       
  1856                TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is newer than original" );
       
  1857                modifiedChanged = ETrue;
       
  1858                break;
       
  1859                }
       
  1860            else if (oldModified > aModified)
       
  1861                {
       
  1862                TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is older than original" );
       
  1863                }
       
  1864            else if (oldModified == aModified)
       
  1865                {
       
  1866                TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is the same as original" );
       
  1867                }
       
  1868             }
       
  1869            
       
  1870        rowStatus = stmt.Next();
       
  1871        
       
  1872        //switch to main table if modified not found from temp
       
  1873        if(rowStatus != KSqlAtRow && !checkMain && !modifiedChanged)
       
  1874            {
       
  1875            TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- main" );
       
  1876            //come here only once
       
  1877            checkMain = ETrue;
       
  1878            
       
  1879            stmt.Close();
       
  1880            CleanupStack::PopAndDestroy( &stmt );
       
  1881            CleanupClosePushL( stmt );
       
  1882            
       
  1883            User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectModifiedByPath ));
       
  1884            
       
  1885            paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
       
  1886            User::LeaveIfError( paramIndex );
       
  1887            User::LeaveIfError( stmt.BindText( paramIndex, *path ));
       
  1888             
       
  1889            rowStatus = stmt.Next();
       
  1890            }
       
  1891        }
       
  1892     
       
  1893    stmt.Close();
       
  1894    CleanupStack::PopAndDestroy( &stmt ); 
       
  1895    
       
  1896    CleanupStack::PopAndDestroy( path );
       
  1897    
       
  1898    return ret;
       
  1899 }
       
  1900 	
       
  1901 // -----------------------------------------------------------------------------
       
  1902 // PrepareBlacklistedItemsForRetryL()
       
  1903 // -----------------------------------------------------------------------------
       
  1904 //
       
  1905 void CThumbnailStore::PrepareBlacklistedItemsForRetryL()
       
  1906     {
       
  1907     TN_DEBUG1( "CThumbnailStore::PrepareBlacklistedItemsForRetry()" );
  2276     
  1908     
  2277     RSqlStatement stmt;
  1909     RSqlStatement stmt;
  2278     CleanupClosePushL( stmt );
  1910     CleanupClosePushL( stmt );
  2279     TInt column( 0 );
  1911 
  2280     
  1912     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailTouchBlacklistedRows ));
  2281     if( aTempTable )
  1913     
  2282         {
  1914     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamFlag );
  2283         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempPathModifiedByID ) );
  1915     User::LeaveIfError( paramIndex );
  2284         }
  1916     User::LeaveIfError( stmt.BindInt( paramIndex, KThumbnailDbFlagBlacklisted ));
  2285     else
  1917     TInt err = stmt.Exec();
  2286         {
  1918    
  2287         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectPathModifiedByID ) );
  1919     TN_DEBUG2( "CThumbnailStore::PrepareBlacklistedItemsForRetryL() - main table, err=%d", err );
  2288         }
  1920     
  2289     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamId );
  1921     CleanupStack::PopAndDestroy( &stmt );
  2290     User::LeaveIfError( paramIndex );
  1922     }
  2291     User::LeaveIfError( stmt.BindInt( paramIndex, aId ));
  1923 
  2292      
  1924 // -----------------------------------------------------------------------------
  2293     TInt rowStatus = stmt.Next();
  1925 // DeleteMarkedL()
  2294     
  1926 // -----------------------------------------------------------------------------
  2295     if(rowStatus == KSqlAtRow)
  1927 //
  2296         {
  1928 TInt CThumbnailStore::DeleteMarkedL()
  2297         TPath path = stmt.ColumnTextL(column++);
  1929     {
       
  1930 #ifdef _DEBUG
       
  1931     TTime aStart, aStop;
       
  1932     aStart.UniversalTime();
       
  1933 #endif
       
  1934     
       
  1935     TN_DEBUG1( "CThumbnailStore::DeleteMarkedL()" );
       
  1936     
       
  1937     TInt paramIndex = 0;
       
  1938     TInt paramIndex1 = 0;
       
  1939     TInt paramIndex2 = 0;
       
  1940     TInt rowStatus = 0;
       
  1941     TInt column = 0;
       
  1942     TInt64 rowid = 0;
       
  1943     TInt deleteCount = 0;
       
  1944       
       
  1945     RThumbnailTransaction transaction( iDatabase );
       
  1946     CleanupClosePushL( transaction );
       
  1947     transaction.BeginL();
       
  1948     
       
  1949     RSqlStatement stmt;
       
  1950     RSqlStatement stmt_info;
       
  1951     RSqlStatement stmt_infodata;
       
  1952     CleanupClosePushL( stmt );
       
  1953     
       
  1954     // select marked rows
       
  1955     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectMarked ));
       
  1956     
       
  1957     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamLimit );
       
  1958     User::LeaveIfError( paramIndex );
       
  1959     User::LeaveIfError( stmt.BindInt( paramIndex, KStoreMaintenanceDeleteLimit ));
       
  1960              
       
  1961     rowStatus = stmt.Next();  
       
  1962     
       
  1963     CleanupClosePushL( stmt_info );
       
  1964     User::LeaveIfError( stmt_info.Prepare( iDatabase, KThumbnailSqlDeleteInfoByRowID) );
       
  1965     CleanupClosePushL( stmt_infodata );
       
  1966     User::LeaveIfError( stmt_infodata.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByRowID) );    
  2298            
  1967            
  2299         if (path.Length())
  1968     while(rowStatus == KSqlAtRow)
  2300             {
  1969        { 
  2301             TInt64 modified = stmt.ColumnInt64( column );
  1970        rowid = stmt.ColumnInt64( column ); 
  2302             TTime timeStamp;
  1971        paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID );
  2303             iFs.Modified( path, timeStamp );
  1972        User::LeaveIfError( paramIndex1 );
  2304             
  1973        User::LeaveIfError( stmt_info.BindInt64( paramIndex1, rowid ));
  2305             if( modified != timeStamp.Int64() )
  1974               
  2306                 {
  1975        TInt err = stmt_info.Exec();
  2307                 aModified = ETrue;
  1976        stmt_info.Reset();
  2308                 }
  1977        User::LeaveIfError( err );
  2309             }
  1978                     
  2310         }
  1979        paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID );  
  2311     
  1980        User::LeaveIfError( paramIndex2 );
       
  1981        User::LeaveIfError( stmt_infodata.BindInt64( paramIndex2, rowid ));
       
  1982                     
       
  1983        err = stmt_infodata.Exec();
       
  1984        stmt_infodata.Reset();
       
  1985        User::LeaveIfError( err );
       
  1986        deleteCount++;
       
  1987        
       
  1988        TN_DEBUG1( "CThumbnailStore::DeleteMarkedL() - thumbnail deleted" );
       
  1989        
       
  1990        rowStatus = stmt.Next();
       
  1991        }
       
  1992         
       
  1993     stmt_infodata.Close();
       
  1994     stmt_info.Close();
  2312     stmt.Close();
  1995     stmt.Close();
  2313     CleanupStack::PopAndDestroy( &stmt );
  1996     CleanupStack::PopAndDestroy( &stmt_infodata );
  2314     }
  1997     CleanupStack::PopAndDestroy( &stmt_info );
  2315 
  1998     CleanupStack::PopAndDestroy( &stmt );    
  2316 void CThumbnailStore::CheckModifiedByPathL( const TDesC& aPath, TBool aTempTable,
  1999     
  2317     TBool& aModified )
  2000     // remove successfully deleted paths from Deleted table
  2318     {
  2001     if (deleteCount > 0)
  2319     TN_DEBUG1( "CThumbnailStore::CheckModifiedByPathL()");
  2002         {
       
  2003         CleanupClosePushL( stmt );  
       
  2004         User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) ); 
       
  2005         
       
  2006         stmt.Close();
       
  2007         CleanupStack::PopAndDestroy( &stmt );
       
  2008         }
       
  2009     
       
  2010     transaction.CommitL();
       
  2011     CleanupStack::PopAndDestroy( &transaction );
       
  2012     
       
  2013 #ifdef _DEBUG
       
  2014     aStop.UniversalTime();
       
  2015     TN_DEBUG2( "CThumbnailStore::DeleteMarkedL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
  2016 #endif
       
  2017     
       
  2018     return deleteCount;
       
  2019     }
       
  2020 
       
  2021 // -----------------------------------------------------------------------------
       
  2022 // FileExistenceCheckL()
       
  2023 // -----------------------------------------------------------------------------
       
  2024 //
       
  2025 TInt CThumbnailStore::FileExistenceCheckL()
       
  2026     {
       
  2027 #ifdef _DEBUG
       
  2028     TTime aStart, aStop;
       
  2029     aStart.UniversalTime();
       
  2030 #endif
       
  2031     
       
  2032     TN_DEBUG1( "CThumbnailStore::FileExistenceCheckL()" );
       
  2033     
       
  2034     TInt paramIndex = 0;
       
  2035     TInt rowStatus = 0; 
       
  2036     TInt column = 0;
       
  2037     TInt64 rowid = 0;
       
  2038     TFileName path;
       
  2039     TFileName prevPath;
       
  2040     TFileName full;
       
  2041     TInt count = 0;
       
  2042     
       
  2043     TBool finished = EFalse;
       
  2044     
       
  2045     TChar dChar = 0;
       
  2046     User::LeaveIfError( iFs.DriveToChar( iDrive, dChar ));
       
  2047     
       
  2048     RThumbnailTransaction transaction( iDatabase );
       
  2049     CleanupClosePushL( transaction );    
       
  2050     transaction.BeginL();
  2320     
  2051     
  2321     RSqlStatement stmt;
  2052     RSqlStatement stmt;
  2322     CleanupClosePushL( stmt );
  2053     CleanupClosePushL( stmt );
  2323     TInt column( 0 );
  2054     
  2324     
  2055     // get rows
  2325     if( aTempTable )
  2056     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectAllPaths ));
  2326         {
  2057     
  2327         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempModifiedByPath ) );
  2058     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamRowID );
  2328         }
  2059     User::LeaveIfError( paramIndex );
  2329     else
  2060     User::LeaveIfError( stmt.BindInt64( paramIndex, iLastCheckedRowID ));
  2330         {
  2061     
  2331         User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectModifiedByPath ) );
  2062     paramIndex = stmt.ParameterIndex( KThumbnailSqlParamLimit );
  2332         }
  2063     User::LeaveIfError( paramIndex );
  2333     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath );
  2064     User::LeaveIfError( stmt.BindInt( paramIndex, KStoreMaintenanceExistLimit ));
  2334     User::LeaveIfError( paramIndex );
  2065              
  2335     User::LeaveIfError( stmt.BindText( paramIndex, aPath ));
  2066     rowStatus = stmt.Next();     
  2336      
  2067            
  2337     TInt rowStatus = stmt.Next();
  2068     while(rowStatus == KSqlAtRow)
  2338     
  2069         {
  2339     if(rowStatus == KSqlAtRow)
  2070         column = 0;
  2340         {
  2071         path.Zero();
  2341         TInt64 modified = stmt.ColumnInt64( column );
  2072         
  2342         TTime timeStamp;
  2073         rowid = stmt.ColumnInt64( column++ );
  2343         iFs.Modified( aPath, timeStamp );
  2074         stmt.ColumnText( column, path );
  2344         
  2075     
  2345         if( modified != timeStamp.Int64() )
  2076         full.Zero();
       
  2077         full.Append(dChar);
       
  2078         full.Append(KDrv);
       
  2079         full.Append(path);
       
  2080         
       
  2081         // if path matches previous one, skip
       
  2082         if (path.CompareF(prevPath) != 0)
  2346             {
  2083             {
  2347             aModified = ETrue;
  2084             // file doesn't exist anymore, mark thumbs deleted
       
  2085             if(!BaflUtils::FileExists( iFs, full ))
       
  2086                 {
       
  2087                 TN_DEBUG2( "CThumbnailStore::FileExistenceCheckL(%S) - not found", &full );
       
  2088                 DeleteThumbnailsL(path, EFalse, EFalse);                    
       
  2089                 }
       
  2090             
       
  2091             prevPath.Zero();
       
  2092             prevPath.Append(path);
  2348             }
  2093             }
  2349         }
  2094         
  2350     
  2095         iLastCheckedRowID = rowid;
       
  2096         count++;
       
  2097        
       
  2098         // get next
       
  2099         rowStatus = stmt.Next();
       
  2100         }
       
  2101     
       
  2102     if (count < KStoreMaintenanceExistLimit)
       
  2103         {
       
  2104         // all rows checked
       
  2105         finished = ETrue;
       
  2106         }
       
  2107         
  2351     stmt.Close();
  2108     stmt.Close();
  2352     CleanupStack::PopAndDestroy( &stmt );
  2109     CleanupStack::PopAndDestroy( &stmt );    
  2353     }
  2110     
  2354 
  2111     transaction.CommitL();
  2355 // -----------------------------------------------------------------------------
  2112     CleanupStack::PopAndDestroy( &transaction );
  2356 // RemoveDbFlagL()
  2113     
  2357 // -----------------------------------------------------------------------------
  2114 #ifdef _DEBUG
  2358 //
  2115     aStop.UniversalTime();
  2359 void CThumbnailStore::RemoveDbFlagL(TThumbnailDbFlags aFlag)
  2116     TN_DEBUG2( "CThumbnailStore::FileExistenceCheckL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  2360     {
  2117 #endif
  2361     TN_DEBUG1( "CThumbnailStore::RemoveBlacklistedFlag()" );
  2118     
  2362     
  2119     return finished;
  2363     RSqlStatement stmt;
  2120     }
  2364     CleanupClosePushL( stmt );
  2121 
  2365 
  2122 // -----------------------------------------------------------------------------
  2366     User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailRemoveBlacklistedFlag ));
  2123 // StripDriveLetter
  2367     
  2124 // -----------------------------------------------------------------------------
  2368     TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamFlag );
  2125 //
  2369     User::LeaveIfError( paramIndex );
  2126 void CThumbnailStore::StripDriveLetterL( TDes& aPath )
  2370     User::LeaveIfError( stmt.BindInt( paramIndex, aFlag ));
  2127     {
  2371 
  2128     TInt pos = aPath.Find(KDrv);
  2372     TInt err = stmt.Exec();
  2129     
  2373    
  2130     // if URI contains drive letter
  2374     TN_DEBUG2( "CThumbnailStore::RemoveBlacklistedFlag() - main table, err=%d", err );
  2131     if ( pos == 1 )
  2375     
  2132         {
  2376     CleanupStack::PopAndDestroy( &stmt );
  2133         aPath.Delete(0,pos+1);
       
  2134         }
  2377     }
  2135     }
  2378 
  2136 
  2379 void CThumbnailStore::HandleDiskSpaceNotificationL( TBool aDiskFull )
  2137 void CThumbnailStore::HandleDiskSpaceNotificationL( TBool aDiskFull )
  2380     {
  2138     {
  2381     TN_DEBUG2( "CThumbnailStore::HandleDiskSpaceNotificationL() aDiskFull = %d", aDiskFull );
  2139     TN_DEBUG2( "CThumbnailStore::HandleDiskSpaceNotificationL() aDiskFull = %d", aDiskFull );
  2382     iDiskFull = aDiskFull;
  2140     iDiskFull = aDiskFull;
  2383     }
  2141     }
  2384 
  2142 
  2385 
  2143 #ifdef _DEBUG
  2386 void CThumbnailStore::HandleDiskSpaceError(TInt aError )
  2144 void CThumbnailStore::HandleDiskSpaceError(TInt aError )
  2387     {
  2145 #else
  2388     if (aError != KErrNone)
  2146 void CThumbnailStore::HandleDiskSpaceError(TInt /*aError*/ )
  2389         {
  2147 #endif
  2390         TN_DEBUG2( "CThumbnailStore::HandleDiskSpaceError() aError = %d", aError );
  2148     {
  2391         }
  2149     TN_DEBUG2( "CThumbnailStore::HandleDiskSpaceError() aError = %d", aError );
  2392     }
  2150     }
  2393 
  2151 
  2394 TBool CThumbnailStore::IsDiskFull()
  2152 TBool CThumbnailStore::IsDiskFull()
  2395     {
  2153     {
  2396     return iDiskFull;
  2154     return iDiskFull;
  2397     }
  2155     }
       
  2156 
       
  2157 // -----------------------------------------------------------------------------
       
  2158 // ActivityDetected()
       
  2159 // -----------------------------------------------------------------------------
       
  2160 //
       
  2161 void CThumbnailStore::ActivityChanged(const TBool aActive)
       
  2162     {
       
  2163     TN_DEBUG2( "CThumbnailStore::ActivityChanged() aActive == %d", aActive);
       
  2164     
       
  2165     if( aActive )
       
  2166         {
       
  2167         iIdle = EFalse;
       
  2168         }
       
  2169     else
       
  2170         {
       
  2171         TInt MPXHarvesting(0);
       
  2172         TInt DaemonProcessing(0);
       
  2173         TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting);
       
  2174         if(!ret)
       
  2175             return;
       
  2176         
       
  2177         TN_DEBUG2( "CThumbnailStore::ActivityChanged() KMPXHarvesting == %d", KMPXHarvesting);
       
  2178         
       
  2179         ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing);
       
  2180         
       
  2181         if(!ret)
       
  2182             return;
       
  2183         
       
  2184         TN_DEBUG2( "CThumbnailStore::ActivityChanged() DaemonProcessing == %d", DaemonProcessing);
       
  2185         
       
  2186         if(!MPXHarvesting && !DaemonProcessing)
       
  2187             {
       
  2188             TN_DEBUG1( "CThumbnailStore::ActivityChanged() - starting maintenance");
       
  2189             iIdle = ETrue;
       
  2190             StartMaintenance();
       
  2191             }
       
  2192         }
       
  2193     }
       
  2194 
       
  2195 // CThumbnailStoreDiskSpaceNotifierAO class
  2398 
  2196 
  2399 CThumbnailStoreDiskSpaceNotifierAO* CThumbnailStoreDiskSpaceNotifierAO::NewL(
  2197 CThumbnailStoreDiskSpaceNotifierAO* CThumbnailStoreDiskSpaceNotifierAO::NewL(
  2400         MThumbnailStoreDiskSpaceNotifierObserver& aObserver, TInt64 aThreshold, const TDesC& aFilename)
  2198         MThumbnailStoreDiskSpaceNotifierObserver& aObserver, TInt64 aThreshold, const TDesC& aFilename)
  2401     {
  2199     {
  2402     CThumbnailStoreDiskSpaceNotifierAO* self = 
  2200     CThumbnailStoreDiskSpaceNotifierAO* self = 
  2435     RFs::CharToDrive( driveChar, driveNumber );
  2233     RFs::CharToDrive( driveChar, driveNumber );
  2436     
  2234     
  2437     return (TDriveNumber)driveNumber;
  2235     return (TDriveNumber)driveNumber;
  2438     }
  2236     }
  2439 
  2237 
  2440 
       
  2441 CThumbnailStoreDiskSpaceNotifierAO::~CThumbnailStoreDiskSpaceNotifierAO()
  2238 CThumbnailStoreDiskSpaceNotifierAO::~CThumbnailStoreDiskSpaceNotifierAO()
  2442     {
  2239     {
  2443     TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::~CThumbnailStoreDiskSpaceNotifierAO()");
  2240     TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::~CThumbnailStoreDiskSpaceNotifierAO()");
  2444     Cancel();
  2241     Cancel();
  2445 
  2242 
  2453 
  2250 
  2454     if ( iState == CThumbnailStoreDiskSpaceNotifierAO::ENormal )
  2251     if ( iState == CThumbnailStoreDiskSpaceNotifierAO::ENormal )
  2455         {
  2252         {
  2456         TInt status = iStatus.Int();
  2253         TInt status = iStatus.Int();
  2457         
  2254         
       
  2255         TInt ret(KErrNone);
       
  2256         
  2458         switch( status )
  2257         switch( status )
  2459             {
  2258             {
  2460             case KErrNone:
  2259             case KErrNone:
  2461                 iFileServerSession.Volume( volumeInfo, iDrive );
  2260                 ret = iFileServerSession.Volume( volumeInfo, iDrive );
  2462                 
  2261                 
  2463                 // Check if free space is less than threshold level
  2262                 if(!ret)
  2464                 if( volumeInfo.iFree < iThreshold )
       
  2465                     {
  2263                     {
  2466                     iDiskFull = ETrue;
  2264                     
  2467                     iObserver.HandleDiskSpaceNotificationL( iDiskFull );
  2265                     // Check if free space is less than threshold level
  2468                     iState = EIterate;
  2266                     if( volumeInfo.iFree < iThreshold )
  2469                     iIterationCount = 0;
  2267                         {
  2470                     SetActive();
  2268                         TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() FULL");
  2471                     TRequestStatus* status = &iStatus;
  2269                         iDiskFull = ETrue;
  2472                     User::RequestComplete( status, KErrNone );
  2270                         iObserver.HandleDiskSpaceNotificationL( iDiskFull );
  2473                     return;
  2271                         iState = EIterate;
       
  2272                         iIterationCount = 0;
       
  2273                         SetActive();
       
  2274                         TRequestStatus* status = &iStatus;
       
  2275                         User::RequestComplete( status, KErrNone );
       
  2276                         return;
       
  2277                         }
       
  2278                     else
       
  2279                         {
       
  2280                         TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() NOT FULL");
       
  2281                         iDiskFull = EFalse;
       
  2282                         iObserver.HandleDiskSpaceNotificationL( iDiskFull );
       
  2283                         }
  2474                     }
  2284                     }
  2475                 else
  2285                 else
  2476                     {
  2286                     {
       
  2287                     TN_DEBUG2( "CThumbnailStoreDiskSpaceNotifierAO::RunL() error %d NOT FULL", ret);
  2477                     iDiskFull = EFalse;
  2288                     iDiskFull = EFalse;
  2478                     iObserver.HandleDiskSpaceNotificationL( iDiskFull );
  2289                     iObserver.HandleDiskSpaceNotificationL( iDiskFull );
       
  2290                     User::Leave( ret );
  2479                     }
  2291                     }
       
  2292                 
  2480                 StartNotifier();
  2293                 StartNotifier();
  2481                 break;
  2294                 break;
  2482 
  2295 
  2483             case KErrArgument:
  2296             case KErrArgument:
  2484                 TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::GetDriveNumberL() KErrArgument");
  2297                 TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() KErrArgument");
  2485                 User::Leave( status );
  2298                 User::Leave( status );
  2486                 break;
  2299                 break;
  2487             default:
  2300             default:
  2488                 break;
  2301                 break;
  2489             }
  2302             }
  2507             else
  2320             else
  2508                 {
  2321                 {
  2509                 iFileServerSession.Volume( volumeInfo, iDrive );
  2322                 iFileServerSession.Volume( volumeInfo, iDrive );
  2510                 if ( volumeInfo.iFree >= iThreshold )
  2323                 if ( volumeInfo.iFree >= iThreshold )
  2511                     {
  2324                     {
       
  2325                     TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() NOT FULL");
  2512                     iDiskFull = EFalse;
  2326                     iDiskFull = EFalse;
  2513                     }
  2327                     }
  2514                 }
  2328                 }
  2515             }
  2329             }
  2516         else
  2330         else
  2517             {
  2331             {
       
  2332             TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() NOT FULL");
  2518             iDiskFull = EFalse;
  2333             iDiskFull = EFalse;
  2519             }
  2334             }
  2520         iState = ENormal;
  2335         iState = ENormal;
  2521         iIterationCount = 0;
  2336         iIterationCount = 0;
  2522         StartNotifier();            
  2337         StartNotifier();            
  2523         }
  2338         }
  2524     else
  2339     else
  2525         {
  2340         {
       
  2341         TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() KErrGeneral");
  2526         User::Leave( KErrGeneral );
  2342         User::Leave( KErrGeneral );
  2527         }
  2343         }
  2528     }
  2344     }
  2529 
  2345 
  2530 TInt CThumbnailStoreDiskSpaceNotifierAO::RunError(TInt aError)
  2346 TInt CThumbnailStoreDiskSpaceNotifierAO::RunError(TInt aError)
  2531     {
  2347     {
  2532     TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunError()");
  2348     TN_DEBUG2( "CThumbnailStoreDiskSpaceNotifierAO::RunError() %d", aError);
       
  2349     
  2533     iObserver.HandleDiskSpaceError( aError );
  2350     iObserver.HandleDiskSpaceError( aError );
  2534     
  2351     
  2535     return KErrNone;
  2352     return KErrNone;
  2536     }
  2353     }
  2537 
  2354 
  2538 void CThumbnailStoreDiskSpaceNotifierAO::DoCancel()
  2355 void CThumbnailStoreDiskSpaceNotifierAO::DoCancel()
  2539     {
  2356     {
  2540     TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::DoCancel()");
  2357     TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::DoCancel()");
       
  2358     
  2541     if( IsActive() )
  2359     if( IsActive() )
  2542         {   
  2360         {   
  2543         iFileServerSession.NotifyDiskSpaceCancel();
  2361         iFileServerSession.NotifyDiskSpaceCancel();
  2544         }
  2362         }
  2545     }
  2363     }
  2559     TInt KMessageSlotCount = 2; // slots for NotifyDiskSpace and NotifyDiskSpaceCancel
  2377     TInt KMessageSlotCount = 2; // slots for NotifyDiskSpace and NotifyDiskSpaceCancel
  2560 
  2378 
  2561     User::LeaveIfError( iFileServerSession.Connect( KMessageSlotCount ) );
  2379     User::LeaveIfError( iFileServerSession.Connect( KMessageSlotCount ) );
  2562     
  2380     
  2563     TVolumeInfo volumeInfo;
  2381     TVolumeInfo volumeInfo;
  2564     iFileServerSession.Volume( volumeInfo, iDrive );    
  2382     TInt ret = iFileServerSession.Volume( volumeInfo, iDrive );
  2565     if ( volumeInfo.iFree < iThreshold )
  2383     
  2566         {
  2384     if( !ret )
  2567         iDiskFull = ETrue;
  2385         {
       
  2386         if ( volumeInfo.iFree < iThreshold )
       
  2387             {
       
  2388             TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::ConstructL() FULL");
       
  2389             iDiskFull = ETrue;
       
  2390             }
       
  2391         }
       
  2392     else
       
  2393         {
       
  2394         TN_DEBUG2( "CThumbnailStoreDiskSpaceNotifierAO::ConstructL() error %d NOT FULL", ret);
       
  2395         iDiskFull = EFalse;
       
  2396         User::Leave( ret );
  2568         }
  2397         }
  2569 
  2398 
  2570     iObserver.HandleDiskSpaceNotificationL( iDiskFull );
  2399     iObserver.HandleDiskSpaceNotificationL( iDiskFull );
  2571     
  2400     
  2572     StartNotifier();
  2401     StartNotifier();