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