imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailstore.cpp
changeset 25 cb86b71cae0a
parent 22 a67f74060682
child 29 4bdfb6b5c9b4
equal deleted inserted replaced
22:a67f74060682 25:cb86b71cae0a
    42 const TInt KMinor = 2;
    42 const TInt KMinor = 2;
    43 
    43 
    44 const TInt KStoreUnrecoverableErr = KErrCorrupt;
    44 const TInt KStoreUnrecoverableErr = KErrCorrupt;
    45 
    45 
    46 // Database path without drive letter
    46 // Database path without drive letter
       
    47 //Symbian^4 v5
    47 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v5.db" );
    48 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v5.db" );
    48 
    49 
    49 _LIT( KDrv, ":");
    50 _LIT( KDrv, ":");
    50 
    51 
    51 // Allow access to database only for the server process
    52 // Allow access to database only for the server process
  1066 //
  1067 //
  1067 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, const TDes8& aData,
  1068 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, const TDes8& aData,
  1068     const TSize& aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, 
  1069     const TSize& aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, 
  1069 	const TThumbnailSize& aThumbnailSize, const TInt64 aModified, const TBool aThumbFromPath )
  1070 	const TThumbnailSize& aThumbnailSize, const TInt64 aModified, const TBool aThumbFromPath )
  1070     {
  1071     {
  1071     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( const TDes8& ) in" );
  1072     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( private ) in" );
  1072 
  1073 
  1073 #ifdef _DEBUG
  1074 #ifdef _DEBUG
  1074     TTime aStart, aStop;
  1075     TTime aStart, aStop;
  1075     aStart.UniversalTime();
  1076     aStart.UniversalTime();
  1076 #endif
  1077 #endif
  1129     User::LeaveIfError( stmt->BindInt( paramIndex, fromPath ));
  1130     User::LeaveIfError( stmt->BindInt( paramIndex, fromPath ));
  1130     
  1131     
  1131     // try getting modification time from file
  1132     // try getting modification time from file
  1132     TTime timeStamp;
  1133     TTime timeStamp;
  1133     
  1134     
  1134     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp aModified %Ld", aModified );
  1135     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( private ) timeStamp aModified %Ld", aModified );
  1135         
  1136         
  1136     if( aModified )
  1137     if( aModified )
  1137         {
  1138         {
  1138         timeStamp = aModified;
  1139         timeStamp = aModified;
  1139         }
  1140         }
  1151         
  1152         
  1152             timeErr = iFs.Modified(path, timeStamp);
  1153             timeErr = iFs.Modified(path, timeStamp);
  1153             
  1154             
  1154             if (timeErr != KErrNone)
  1155             if (timeErr != KErrNone)
  1155                 {
  1156                 {
  1156                 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() error getting timeStamp: %d", timeErr );
  1157                 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( private ) error getting timeStamp: %d", timeErr );
  1157                 }
  1158                 }
  1158             else
  1159             else
  1159                 {
  1160                 {
  1160                 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp       iFs %Ld", timeStamp.Int64() );
  1161                 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( private ) timeStamp       iFs %Ld", timeStamp.Int64() );
  1161                 }
  1162                 }
  1162             }
  1163             }
  1163         
  1164         
  1164         if (!aPath.Length() || timeErr != KErrNone)
  1165         if (!aPath.Length() || timeErr != KErrNone)
  1165             {
  1166             {
  1166             // otherwise current time
  1167             // otherwise current time
  1167             timeStamp.UniversalTime();
  1168             timeStamp.UniversalTime();
  1168             TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp   current %Ld", timeStamp.Int64() );
  1169             TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( private ) timeStamp   current %Ld", timeStamp.Int64() );
  1169             }
  1170             }
  1170         }
  1171         }
  1171         
  1172         
  1172    TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp       set %Ld", timeStamp.Int64());
  1173    TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( private ) timeStamp       set %Ld", timeStamp.Int64());
  1173    
  1174    
  1174     paramIndex = stmt->ParameterIndex( KThumbnailSqlParamModified );
  1175     paramIndex = stmt->ParameterIndex( KThumbnailSqlParamModified );
  1175     User::LeaveIfError( paramIndex );
  1176     User::LeaveIfError( paramIndex );
  1176     User::LeaveIfError( stmt->BindInt64( paramIndex, timeStamp.Int64() ));
  1177     User::LeaveIfError( stmt->BindInt64( paramIndex, timeStamp.Int64() ));
  1177     
  1178     
  1201 #ifdef _DEBUG
  1202 #ifdef _DEBUG
  1202     iThumbCounter++;
  1203     iThumbCounter++;
  1203     TN_DEBUG2( "CThumbnailStore::THUMBSTORE-COUNTER----------, Thumbs = %d", iThumbCounter );
  1204     TN_DEBUG2( "CThumbnailStore::THUMBSTORE-COUNTER----------, Thumbs = %d", iThumbCounter );
  1204     
  1205     
  1205     aStop.UniversalTime();
  1206     aStop.UniversalTime();
  1206     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() insert to table %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  1207     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( private ) insert to table %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
  1207 #endif 
  1208 #endif 
  1208     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( const TDes8& ) out" );
  1209     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( private ) out" );
  1209     }
  1210     }
  1210 
  1211 
  1211 
  1212 
  1212 // ---------------------------------------------------------------------------
  1213 // ---------------------------------------------------------------------------
  1213 // CThumbnailStore::StoreThumbnailL()
  1214 // CThumbnailStore::StoreThumbnailL()
  1217 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, CFbsBitmap*
  1218 void CThumbnailStore::StoreThumbnailL( const TDesC& aPath, CFbsBitmap*
  1218     aThumbnail, const TSize& aOriginalSize, TBool /*aCropped*/, const TThumbnailSize aThumbnailSize, 
  1219     aThumbnail, const TSize& aOriginalSize, TBool /*aCropped*/, const TThumbnailSize aThumbnailSize, 
  1219     const TInt64 aModified, TBool aThumbFromPath, TBool aBlackListed )
  1220     const TInt64 aModified, TBool aThumbFromPath, TBool aBlackListed )
  1220     {
  1221     {
  1221     TSize thumbSize = aThumbnail->SizeInPixels();
  1222     TSize thumbSize = aThumbnail->SizeInPixels();
  1222     TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( CFbsBitmap ) aThumbnailSize = %d, aThumbnailSize(%d,%d) IN", aThumbnailSize, thumbSize.iWidth, thumbSize.iHeight );
  1223     TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( public ) aThumbnailSize = %d, aThumbnailSize(%d,%d) IN", aThumbnailSize, thumbSize.iWidth, thumbSize.iHeight );
  1223 
  1224 
  1224     __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer ));
  1225     __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer ));
  1225     
  1226     
  1226     User::LeaveIfError( CheckDbState() );
  1227     User::LeaveIfError( CheckDbState() );
  1227     
  1228     
  1228     // don't store custom/unknown sizes or zero sizes
  1229     // don't store custom/unknown sizes or zero sizes
  1229     if(aThumbnailSize == ECustomThumbnailSize || aThumbnailSize == EUnknownThumbnailSize 
  1230     if(aThumbnailSize == ECustomThumbnailSize || aThumbnailSize == EUnknownThumbnailSize 
  1230             || thumbSize.iWidth <= 0 || thumbSize.iHeight <= 0 )
  1231             || thumbSize.iWidth <= 0 || thumbSize.iHeight <= 0 )
  1231         {
  1232         {
  1232         TN_DEBUG1( "CThumbnailStore::StoreThumbnailL() not stored");
  1233         TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( public ) not stored");
  1233         return;
  1234         return;
  1234         }
  1235         }
  1235     
  1236     
  1236     HBufC* path = aPath.AllocLC();
  1237     HBufC* path = aPath.AllocLC();
  1237     TPtr ptr(path->Des());
  1238     TPtr ptr(path->Des());
  1259                 }
  1260                 }
  1260             
  1261             
  1261             if( (aThumbnailSize == EImageFullScreenThumbnailSize || aThumbnailSize == EVideoFullScreenThumbnailSize ||
  1262             if( (aThumbnailSize == EImageFullScreenThumbnailSize || aThumbnailSize == EVideoFullScreenThumbnailSize ||
  1262                  aThumbnailSize == EAudioFullScreenThumbnailSize) && !aBlackListed )
  1263                  aThumbnailSize == EAudioFullScreenThumbnailSize) && !aBlackListed )
  1263                 {
  1264                 {
       
  1265                 TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( public ) - encode jpg" );
       
  1266             
  1264                 HBufC8* data = NULL;
  1267                 HBufC8* data = NULL;
  1265                 CleanupStack::PushL( data );
  1268                 CleanupStack::PushL( data );
  1266                 
  1269                 
  1267                 CImageEncoder* encoder = CImageEncoder::DataNewL( data,  KJpegMime(), CImageEncoder::EOptionAlwaysThread );
  1270                 CImageEncoder* encoder = CImageEncoder::DataNewL( data,  KJpegMime(), CImageEncoder::EOptionAlwaysThread );
  1268                 CleanupStack::Pop( data );
  1271                 CleanupStack::Pop( data );
  1280                 
  1283                 
  1281                 // imageData - ownership passed to frameImageData after AppendImageData
  1284                 // imageData - ownership passed to frameImageData after AppendImageData
  1282                 User::LeaveIfError(frameImageData->AppendImageData(imageData));
  1285                 User::LeaveIfError(frameImageData->AppendImageData(imageData));
  1283                 CleanupStack::Pop( imageData );
  1286                 CleanupStack::Pop( imageData );
  1284                 
  1287                 
  1285                 
  1288 #ifdef _DEBUG
  1286 #ifdef _DEBUG
  1289         TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( public ) - size: %d x %d, displaymode: %d ", 
  1287         TN_DEBUG4( "CThumbnailStore::StoreThumbnailL() size %d x %d displaymode %d ", 
       
  1288                 aThumbnail->SizeInPixels().iWidth, 
  1290                 aThumbnail->SizeInPixels().iWidth, 
  1289                 aThumbnail->SizeInPixels().iHeight, 
  1291                 aThumbnail->SizeInPixels().iHeight, 
  1290                 aThumbnail->DisplayMode());
  1292                 aThumbnail->DisplayMode());
  1291 #endif
  1293 #endif
  1292                 
  1294                 
  1296                 
  1298                 
  1297                 CleanupStack::PopAndDestroy( frameImageData );
  1299                 CleanupStack::PopAndDestroy( frameImageData );
  1298                 CleanupStack::PopAndDestroy( encoder );
  1300                 CleanupStack::PopAndDestroy( encoder );
  1299                 
  1301                 
  1300                 if(request == KErrNone)
  1302                 if(request == KErrNone)
  1301                     {
  1303                     {           
       
  1304                     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( public ) - encoding ok" );    
       
  1305                 
  1302                     CleanupStack::PushL( data );
  1306                     CleanupStack::PushL( data );
  1303                     TPtr8 ptr = data->Des(); 
  1307                     TPtr8 ptr = data->Des(); 
  1304                     StoreThumbnailL( *path, ptr, aThumbnail->SizeInPixels(), 
  1308                     StoreThumbnailL( *path, ptr, aThumbnail->SizeInPixels(), 
  1305                                      aOriginalSize, EThumbnailFormatJpeg, flags, 
  1309                                      aOriginalSize, EThumbnailFormatJpeg, flags, 
  1306                                      aThumbnailSize, aModified, aThumbFromPath  );
  1310                                      aThumbnailSize, aModified, aThumbFromPath  );
  1307                     CleanupStack::Pop( data );
  1311                     CleanupStack::Pop( data );
       
  1312                     }
       
  1313                 else
       
  1314                     {
       
  1315                     TN_DEBUG2( "CThumbnailStore::StoreThumbnailL( public ) - encoding failed: %d", request.Int() );
  1308                     }
  1316                     }
  1309                 
  1317                 
  1310                 delete data;
  1318                 delete data;
  1311                 data = NULL;
  1319                 data = NULL;
  1312                 }
  1320                 }
  1329             }
  1337             }
  1330         }
  1338         }
  1331     
  1339     
  1332     CleanupStack::PopAndDestroy( path );
  1340     CleanupStack::PopAndDestroy( path );
  1333     
  1341     
  1334     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( CFbsBitmap* ) out" );
  1342     TN_DEBUG1( "CThumbnailStore::StoreThumbnailL( public ) out" );
  1335     }
  1343     }
  1336 
  1344 
  1337 // ---------------------------------------------------------------------------
  1345 // ---------------------------------------------------------------------------
  1338 // Finds possible existing duplicate thumbnail.
  1346 // Finds possible existing duplicate thumbnail.
  1339 // ---------------------------------------------------------------------------
  1347 // ---------------------------------------------------------------------------
  2210         TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive);
  2218         TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive);
  2211     
  2219     
  2212         // thumbmnail deletion
  2220         // thumbmnail deletion
  2213         if (self->iDeleteThumbs)
  2221         if (self->iDeleteThumbs)
  2214             {
  2222             {
       
  2223             TN_DEBUG1( "CThumbnailStore::MaintenanceTimerCallBack() - cleanup");
       
  2224         
  2215             TInt deleteCount = 0;
  2225             TInt deleteCount = 0;
  2216             
  2226             
  2217             // delete marked rows from database
  2227             // delete marked rows from database
  2218             TRAPD( err, deleteCount = self->DeleteMarkedL() );
  2228             TRAPD( err, deleteCount = self->DeleteMarkedL() );
  2219             if (err != KErrNone)
  2229             if (err != KErrNone)
  2231             }
  2241             }
  2232         
  2242         
  2233         // file existence check
  2243         // file existence check
  2234         else if (self->iCheckFilesExist)
  2244         else if (self->iCheckFilesExist)
  2235             {
  2245             {
       
  2246             TN_DEBUG1( "CThumbnailStore::MaintenanceTimerCallBack() - file existence check");
       
  2247         
  2236             TBool finished = EFalse;
  2248             TBool finished = EFalse;
  2237         
  2249         
  2238             TRAPD( err, finished = self->FileExistenceCheckL() );
  2250             TRAPD( err, finished = self->FileExistenceCheckL() );
  2239             if (err != KErrNone)
  2251             if (err != KErrNone)
  2240                 {
  2252                 {
  2251             }
  2263             }
  2252         
  2264         
  2253         // next round
  2265         // next round
  2254         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
  2266         if (self->iIdle && ( self->iDeleteThumbs || self->iCheckFilesExist) )
  2255             {
  2267             {
       
  2268             TN_DEBUG1( "CThumbnailStore::MaintenanceTimerCallBack() - continue maintenance");
  2256             self->StartMaintenance();
  2269             self->StartMaintenance();
  2257             }  
  2270             }  
  2258         else if (!self->iDeleteThumbs && !self->iCheckFilesExist)
  2271         else if (!self->iDeleteThumbs && !self->iCheckFilesExist)
  2259             {
  2272             {
       
  2273             TN_DEBUG1( "CThumbnailStore::MaintenanceTimerCallBack() - no more maintenance");
       
  2274         
  2260             // no need to monitor activity anymore
  2275             // no need to monitor activity anymore
  2261             self->iActivityManager->Cancel();
  2276             self->iActivityManager->Cancel();
  2262             }
  2277             }
  2263         }
  2278         }
  2264     else
  2279     else