changeset 15 | 7197e789b953 |
parent 14 | 2edacbf5d3f9 |
child 17 | ffa62e555b02 |
14:2edacbf5d3f9 | 15:7197e789b953 |
---|---|
19 #include <s32mem.h> |
19 #include <s32mem.h> |
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 #include <bautils.h> |
25 #include <bautils.h> |
26 #include <IclExtJpegApi.h> |
26 #include <IclExtJpegApi.h> |
27 |
27 |
28 #include "thumbnailstore.h" |
28 #include "thumbnailstore.h" |
29 #include "thumbnailsql.h" |
29 #include "thumbnailsql.h" |
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 const TInt KStoreUnrecoverableErr = KErrCorrupt; |
|
45 |
|
44 // Database path without drive letter |
46 // Database path without drive letter |
45 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v3.db" ); |
47 _LIT( KThumbnailDatabaseName, ":[102830AB]thumbnail_v3.db" ); |
46 |
48 |
47 _LIT( KDrv, ":"); |
49 _LIT( KDrv, ":"); |
48 |
50 |
59 iDatabase( aDatabase ), iState( EClosed ) |
61 iDatabase( aDatabase ), iState( EClosed ) |
60 { |
62 { |
61 // No implementation required |
63 // No implementation required |
62 } |
64 } |
63 |
65 |
64 |
|
65 // --------------------------------------------------------------------------- |
66 // --------------------------------------------------------------------------- |
66 // RThumbnailTransaction::BeginL() |
67 // RThumbnailTransaction::BeginL() |
67 // --------------------------------------------------------------------------- |
68 // --------------------------------------------------------------------------- |
68 // |
69 // |
69 void RThumbnailTransaction::BeginL() |
70 void RThumbnailTransaction::BeginL() |
82 #endif |
83 #endif |
83 User::Leave( err ); |
84 User::Leave( err ); |
84 } |
85 } |
85 } |
86 } |
86 |
87 |
87 |
|
88 // --------------------------------------------------------------------------- |
88 // --------------------------------------------------------------------------- |
89 // RThumbnailTransaction::Close() |
89 // RThumbnailTransaction::Close() |
90 // --------------------------------------------------------------------------- |
90 // --------------------------------------------------------------------------- |
91 // |
91 // |
92 void RThumbnailTransaction::Close() |
92 void RThumbnailTransaction::Close() |
94 if ( iState != EClosed ) |
94 if ( iState != EClosed ) |
95 { |
95 { |
96 Rollback(); |
96 Rollback(); |
97 } |
97 } |
98 } |
98 } |
99 |
|
100 |
99 |
101 // --------------------------------------------------------------------------- |
100 // --------------------------------------------------------------------------- |
102 // RThumbnailTransaction::CommitL() |
101 // RThumbnailTransaction::CommitL() |
103 // --------------------------------------------------------------------------- |
102 // --------------------------------------------------------------------------- |
104 // |
103 // |
113 User::LeaveIfError( ret ); |
112 User::LeaveIfError( ret ); |
114 |
113 |
115 iState = EClosed; |
114 iState = EClosed; |
116 } |
115 } |
117 |
116 |
118 |
|
119 // --------------------------------------------------------------------------- |
117 // --------------------------------------------------------------------------- |
120 // RThumbnailTransaction::Rollback() |
118 // RThumbnailTransaction::Rollback() |
121 // --------------------------------------------------------------------------- |
119 // --------------------------------------------------------------------------- |
122 // |
120 // |
123 TInt RThumbnailTransaction::Rollback() |
121 TInt RThumbnailTransaction::Rollback() |
127 { |
125 { |
128 iState = EClosed; |
126 iState = EClosed; |
129 } |
127 } |
130 return err; |
128 return err; |
131 } |
129 } |
130 |
|
132 |
131 |
133 // ======== MEMBER FUNCTIONS ======== |
132 // ======== MEMBER FUNCTIONS ======== |
134 |
133 |
135 // --------------------------------------------------------------------------- |
134 // --------------------------------------------------------------------------- |
136 // CThumbnailStore::NewL() |
135 // CThumbnailStore::NewL() |
152 // Destructor. |
151 // Destructor. |
153 // --------------------------------------------------------------------------- |
152 // --------------------------------------------------------------------------- |
154 // |
153 // |
155 CThumbnailStore::~CThumbnailStore() |
154 CThumbnailStore::~CThumbnailStore() |
156 { |
155 { |
157 TN_DEBUG1( "CThumbnailStore::~CThumbnailStore()" ); |
156 TN_DEBUG2( "CThumbnailStore::~CThumbnailStore() drive: %d", iDrive ); |
158 |
157 |
159 if(iActivityManager) |
158 if(iActivityManager) |
160 { |
159 { |
161 delete iActivityManager; |
160 delete iActivityManager; |
162 iActivityManager = NULL; |
161 iActivityManager = NULL; |
177 iAutoFlushTimer->Cancel(); |
176 iAutoFlushTimer->Cancel(); |
178 delete iAutoFlushTimer; |
177 delete iAutoFlushTimer; |
179 iAutoFlushTimer = NULL; |
178 iAutoFlushTimer = NULL; |
180 } |
179 } |
181 |
180 |
181 CloseStatements(); |
|
182 iDatabase.Close(); |
182 iDatabase.Close(); |
183 |
|
183 TN_DEBUG1( "CThumbnailStore::~CThumbnailStore() - database closed" ); |
184 TN_DEBUG1( "CThumbnailStore::~CThumbnailStore() - database closed" ); |
184 } |
185 } |
185 |
|
186 |
186 |
187 // --------------------------------------------------------------------------- |
187 // --------------------------------------------------------------------------- |
188 // CThumbnailStore::CThumbnailStore() |
188 // CThumbnailStore::CThumbnailStore() |
189 // C++ default constructor can NOT contain any code, that might leave. |
189 // C++ default constructor can NOT contain any code, that might leave. |
190 // --------------------------------------------------------------------------- |
190 // --------------------------------------------------------------------------- |
191 // |
191 // |
192 CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): |
192 CThumbnailStore::CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ): |
193 iFs( aFs ), iDrive( aDrive ), iBatchItemCount(0), iImei(aImei), iServer(aServer), iDiskFull(EFalse) |
193 iFs( aFs ), iDrive( aDrive ), iDriveChar( 0 ), iBatchItemCount(0), iImei(aImei), |
194 iServer(aServer), iDiskFull(EFalse), iUnrecoverable(ETrue) |
|
194 { |
195 { |
195 // no implementation required |
196 // no implementation required |
196 } |
197 } |
197 |
|
198 |
198 |
199 // --------------------------------------------------------------------------- |
199 // --------------------------------------------------------------------------- |
200 // CThumbnailStore::ConstructL() |
200 // CThumbnailStore::ConstructL() |
201 // Symbian 2nd phase constructor can leave. |
201 // Symbian 2nd phase constructor can leave. |
202 // --------------------------------------------------------------------------- |
202 // --------------------------------------------------------------------------- |
206 TN_DEBUG1( "CThumbnailStore::ConstructL()" ); |
206 TN_DEBUG1( "CThumbnailStore::ConstructL()" ); |
207 |
207 |
208 #ifdef _DEBUG |
208 #ifdef _DEBUG |
209 iThumbCounter = 0; |
209 iThumbCounter = 0; |
210 #endif |
210 #endif |
211 |
|
212 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
|
213 TPtr pathPtr = databasePath->Des(); |
|
214 User::LeaveIfError( RFs::DriveToChar( iDrive, iDriveChar )); |
|
215 pathPtr.Append( iDriveChar ); |
|
216 pathPtr.Append( KThumbnailDatabaseName ); |
|
217 |
|
218 //start disk space monitor |
|
219 iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, |
|
220 KDiskFullThreshold, |
|
221 pathPtr ); |
|
222 |
|
223 CleanupStack::PopAndDestroy( databasePath ); |
|
224 |
|
225 TN_DEBUG2( "CThumbnailStore::ConstructL() drive: %d", iDrive ); |
|
226 |
|
227 OpenDatabaseL(); |
|
228 |
|
229 // to monitor device activity |
|
230 iActivityManager = CTMActivityManager::NewL( this, KStoreMaintenanceIdle); |
|
231 iActivityManager->Start(); |
|
232 |
|
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()" ); |
|
211 |
244 |
212 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
245 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
213 TPtr pathPtr = databasePath->Des(); |
246 TPtr pathPtr = databasePath->Des(); |
214 TChar driveChar = 0; |
247 TChar driveChar = 0; |
215 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
248 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
216 pathPtr.Append( driveChar ); |
249 pathPtr.Append( driveChar ); |
217 pathPtr.Append( KThumbnailDatabaseName ); |
250 pathPtr.Append( KThumbnailDatabaseName ); |
218 |
251 |
219 //start disk space monitor |
|
220 iDiskFullNotifier = CThumbnailStoreDiskSpaceNotifierAO::NewL( *this, |
|
221 KDiskFullThreshold, |
|
222 pathPtr ); |
|
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 TInt ret = iDatabase.Open( pathPtr ); |
252 CleanupStack::PopAndDestroy( databasePath ); |
253 CleanupStack::PopAndDestroy( databasePath ); |
253 return ret; |
254 return ret; |
254 } |
255 } |
255 |
256 |
256 // --------------------------------------------------------------------------- |
257 // --------------------------------------------------------------------------- |
257 // OpenDatabaseL database |
258 // OpenDatabaseL database |
258 // --------------------------------------------------------------------------- |
259 // --------------------------------------------------------------------------- |
259 TInt CThumbnailStore::OpenDatabaseL() |
260 TInt CThumbnailStore::OpenDatabaseL( TBool aNewDatabase ) |
260 { |
261 { |
261 TN_DEBUG1( "CThumbnailStore::OpenDatabaseL()" ); |
262 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() drive: %d", iDrive ); |
262 |
263 |
263 iDatabase.Close(); |
264 iDatabase.Close(); |
264 |
265 iUnrecoverable = ETrue; |
265 TBool newDatabase(EFalse); |
266 |
266 TInt error = KErrNone; |
267 TInt checkError = KErrNone; |
267 |
268 TInt blistError = KErrNone; |
268 TInt err = OpenDatabaseFileL(); |
269 TInt blistError2 = KErrNone; |
270 TInt imeiError = KErrNone; |
|
271 TInt err = KErrNone; |
|
272 |
|
273 if (aNewDatabase) |
|
274 { |
|
275 // delete existing and create new |
|
276 CleanupClosePushL(iDatabase); |
|
277 RecreateDatabaseL(ETrue); |
|
278 CleanupStack::Pop(&iDatabase); |
|
279 } |
|
280 else |
|
281 { |
|
282 // just open old |
|
283 err = OpenDatabaseFileL(); |
|
284 |
|
285 TN_DEBUG2( "CThumbnailStore::OpenDatabaseL() -- err = %d", err); |
|
286 |
|
287 if ( err == KErrNone) |
|
288 { |
|
289 // db found, check version and rowids |
|
290 checkError = CheckVersion(); |
|
291 if(checkError == KErrNone) |
|
292 { |
|
293 checkError = CheckRowIDs(); |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 // if db file not found, wrong version, corrupted database or other error opening db |
|
299 if ( checkError == KErrNotSupported || err != KErrNone ) |
|
300 { |
|
301 CleanupClosePushL(iDatabase); |
|
302 RecreateDatabaseL(ETrue); |
|
303 CleanupStack::Pop(&iDatabase); |
|
304 |
|
305 aNewDatabase = ETrue; |
|
306 } |
|
307 } |
|
308 } |
|
269 |
309 |
270 if ( err == KErrNotFound ) |
310 // opened existing database file |
271 { |
311 if(!aNewDatabase) |
272 // db not found, create new |
312 { |
273 RecreateDatabaseL( EFalse); |
313 // add temp tables |
274 newDatabase = ETrue; |
314 CreateTempTablesL(); |
275 err = KErrNone; |
315 |
276 } |
316 //check ownership |
277 else if ( err == KErrNone) |
317 imeiError = CheckImei(); |
278 { |
318 |
279 // db found, check version and rowids |
319 if(imeiError != KErrNone) |
280 error = CheckVersionL(); |
320 { |
281 if(error == KErrNone) |
321 //take ownership |
282 { |
322 imeiError = UpdateImeiL(); |
283 error = CheckRowIDsL(); |
323 |
284 } |
324 //Touch blacklisted items |
285 } |
325 TRAP(blistError, PrepareBlacklistedItemsForRetryL() ); |
326 } |
|
327 |
|
328 //check if MMC is known |
|
329 if(CheckMediaIDL() != KErrNone) |
|
330 { |
|
331 //Touch blacklisted items |
|
332 TRAP(blistError2, PrepareBlacklistedItemsForRetryL() ); |
|
333 } |
|
334 |
|
335 if(imeiError == KSqlErrCorrupt || imeiError == KErrCorrupt || |
|
336 blistError == KSqlErrCorrupt || blistError == KErrCorrupt || |
|
337 blistError2 == KSqlErrCorrupt || blistError2 == KErrCorrupt ) |
|
338 { |
|
339 CleanupClosePushL(iDatabase); |
|
340 RecreateDatabaseL(ETrue); |
|
341 CleanupStack::Pop(&iDatabase); |
|
342 } |
|
343 } |
|
286 |
344 |
287 TN_DEBUG3( "CThumbnailStore::ConstructL() -- error = %d, err = %d", error, err); |
345 PrepareStatementsL(); |
288 |
346 |
289 // if wrong version, corrupted database or other error opening db |
347 // database now usable |
290 if ( error == KErrNotSupported || (err != KErrNone && err != KErrNotFound) ) |
348 iUnrecoverable = EFalse; |
291 { |
349 |
292 RecreateDatabaseL( ETrue); |
350 return KErrNone; |
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 } |
351 } |
343 |
352 |
344 // --------------------------------------------------------------------------- |
353 // --------------------------------------------------------------------------- |
345 // PrepareDbL database tables |
354 // PrepareDbL database tables |
346 // --------------------------------------------------------------------------- |
355 // --------------------------------------------------------------------------- |
347 // |
356 // |
348 void CThumbnailStore::PrepareDbL() |
357 void CThumbnailStore::PrepareDbL() |
349 { |
358 { |
350 TN_DEBUG1( "CThumbnailStore::PrepareDbL()" ); |
359 TN_DEBUG1( "CThumbnailStore::PrepareDbL()" ); |
351 TInt err(KErrNone); |
360 |
352 |
361 // add persistent tables |
353 // add tables |
362 CreateTablesL(); |
354 TRAPD(tableError, CreateTablesL() ); |
|
355 |
363 |
356 if(!tableError) |
364 AddVersionAndImeiL(); |
357 { |
365 |
358 TRAPD(err, AddVersionAndImeiL()); |
366 // add temp tables |
359 if (err == KSqlErrCorrupt) |
367 CreateTempTablesL(); |
360 { |
368 } |
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 |
369 |
387 // --------------------------------------------------------------------------- |
370 // --------------------------------------------------------------------------- |
388 // Create database tables |
371 // Create database tables |
389 // --------------------------------------------------------------------------- |
372 // --------------------------------------------------------------------------- |
390 // |
373 // |
391 void CThumbnailStore::CreateTablesL() |
374 void CThumbnailStore::CreateTablesL() |
392 { |
375 { |
393 TN_DEBUG1( "CThumbnailStore::CreateTablesL()" ); |
376 TN_DEBUG1( "CThumbnailStore::CreateTablesL()" ); |
394 |
377 |
395 TInt err = 0; |
378 TInt err = KErrNone; |
396 err = iDatabase.Exec( KThumbnailCreateInfoTable ); |
379 err = iDatabase.Exec( KThumbnailCreateInfoTable ); |
397 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTable err=%d", err ); |
380 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTable err=%d", err ); |
381 User::LeaveIfError( err ); |
|
382 |
|
398 err = iDatabase.Exec( KThumbnailCreateInfoDataTable ); |
383 err = iDatabase.Exec( KThumbnailCreateInfoDataTable ); |
399 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoDataTable err=%d", err ); |
384 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoDataTable err=%d", err ); |
385 User::LeaveIfError( err ); |
|
400 |
386 |
401 err = iDatabase.Exec(KThumbnailDeletedTable); |
387 err = iDatabase.Exec(KThumbnailDeletedTable); |
402 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailDeletedTable err=%d", err ); |
388 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailDeletedTable err=%d", err ); |
389 User::LeaveIfError( err ); |
|
390 |
|
391 err = iDatabase.Exec( KThumbnailCreateInfoTableIndex1 ); |
|
392 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTableIndex1 err=%d", err ); |
|
393 User::LeaveIfError( err ); |
|
394 |
|
395 err = iDatabase.Exec( KThumbnailCreateDeletedTableIndex ); |
|
396 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateDeletedTableIndex err=%d", err ); |
|
397 User::LeaveIfError( err ); |
|
403 |
398 |
404 err = iDatabase.Exec(KThumbnailVersionTable); |
399 err = iDatabase.Exec(KThumbnailVersionTable); |
405 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailVersionTable err=%d", err ); |
400 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailVersionTable err=%d", err ); |
406 |
401 User::LeaveIfError( err ); |
407 err = iDatabase.Exec( KThumbnailCreateInfoTableIndex1 ); |
402 } |
408 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateInfoTableIndex1 err=%d", err ); |
403 |
409 |
404 // --------------------------------------------------------------------------- |
410 err = iDatabase.Exec( KThumbnailCreateDeletedTableIndex ); |
405 // Create temp tables |
411 TN_DEBUG2( "CThumbnailStore::CreateTablesL() KThumbnailCreateDeletedTableIndex err=%d", err ); |
406 // --------------------------------------------------------------------------- |
407 // |
|
408 void CThumbnailStore::CreateTempTablesL() |
|
409 { |
|
410 TN_DEBUG1( "CThumbnailStore::CreateTempTablesL()" ); |
|
411 |
|
412 TInt err = iDatabase.Exec( KThumbnailCreateTempInfoTable ); |
|
413 |
|
414 #ifdef _DEBUG |
|
415 if(err < 0) |
|
416 { |
|
417 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
|
418 TN_DEBUG2( "CThumbnailStore::PrepareDbL() KThumbnailCreateTempInfoTable %S" , &errorMsg); |
|
419 } |
|
420 #endif |
|
421 |
|
422 User::LeaveIfError( err ); |
|
423 |
|
424 err = iDatabase.Exec( KThumbnailCreateTempInfoDataTable ); |
|
425 |
|
426 #ifdef _DEBUG |
|
427 if(err < 0) |
|
428 { |
|
429 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
|
430 TN_DEBUG2( "CThumbnailStore::PrepareDbL() KThumbnailCreateTempInfoDataTable %S" , &errorMsg); |
|
431 } |
|
432 #endif |
|
412 |
433 |
413 User::LeaveIfError( err ); |
434 User::LeaveIfError( err ); |
414 } |
435 } |
415 |
436 |
416 void CThumbnailStore::RecreateDatabaseL(const TBool aDelete) |
437 void CThumbnailStore::RecreateDatabaseL(const TBool aDelete) |
417 { |
438 { |
418 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL()" ); |
439 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() drive: %d", iDrive ); |
419 |
440 |
420 TVolumeInfo volumeinfo; |
441 TVolumeInfo volumeinfo; |
421 iFs.Volume(volumeinfo, iDrive); |
442 User::LeaveIfError( iFs.Volume(volumeinfo, iDrive) ); |
422 TUint id = volumeinfo.iUniqueID; |
443 TUint id = volumeinfo.iUniqueID; |
423 TBuf<50> mediaid; |
444 TBuf<50> mediaid; |
424 mediaid.Num(id); |
445 mediaid.Num(id); |
425 |
446 |
426 // delete db and create new |
|
427 iDatabase.Close(); |
447 iDatabase.Close(); |
448 iUnrecoverable = ETrue; |
|
449 |
|
450 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() database closed" ); |
|
428 |
451 |
429 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
452 HBufC* databasePath = HBufC::NewLC( KMaxFileName ); |
430 TPtr pathPtr = databasePath->Des(); |
453 TPtr pathPtr = databasePath->Des(); |
431 TChar driveChar = 0; |
454 User::LeaveIfError( RFs::DriveToChar( iDrive, iDriveChar )); |
432 User::LeaveIfError( RFs::DriveToChar( iDrive, driveChar )); |
455 pathPtr.Append( iDriveChar ); |
433 pathPtr.Append( driveChar ); |
|
434 pathPtr.Append( KThumbnailDatabaseName ); |
456 pathPtr.Append( KThumbnailDatabaseName ); |
435 |
457 |
436 TInt err(KErrNone); |
458 TInt err(KErrNone); |
437 |
459 |
460 // delete old if necessary |
|
438 if(aDelete) |
461 if(aDelete) |
439 { |
462 { |
440 iDatabase.Delete(pathPtr); |
463 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() delete database" ); |
464 TInt del = iDatabase.Delete(pathPtr); |
|
465 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() deleted database, err: %d", del ); |
|
441 } |
466 } |
442 |
467 |
443 const TDesC8& config = KThumbnailSqlConfig; |
468 const TDesC8& config = KThumbnailSqlConfig; |
444 |
469 |
445 RSqlSecurityPolicy securityPolicy; |
470 RSqlSecurityPolicy securityPolicy; |
446 CleanupClosePushL( securityPolicy ); |
471 CleanupClosePushL( securityPolicy ); |
447 securityPolicy.Create( KThumbnailDatabaseSecurityPolicy ); |
472 securityPolicy.CreateL( KThumbnailDatabaseSecurityPolicy ); |
448 |
473 |
449 TRAP(err, iDatabase.CreateL( pathPtr, securityPolicy, &config )); |
474 // create new |
475 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() create new" ); |
|
476 TRAP(err, iDatabase.CreateL( pathPtr, securityPolicy, &config )); |
|
477 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- database created, err = %d", err ); |
|
478 User::LeaveIfError(err); |
|
479 |
|
450 CleanupStack::PopAndDestroy( &securityPolicy ); |
480 CleanupStack::PopAndDestroy( &securityPolicy ); |
451 |
481 |
452 |
482 // add tables |
453 #ifdef _DEBUG |
483 TRAPD(prepareErr, PrepareDbL() ); |
484 |
|
485 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- prepare tables, err = %d", prepareErr ); |
|
486 |
|
487 TInt mediaidErr(KErrNone); |
|
488 |
|
489 // write media id file if doesn't exist |
|
490 if(!BaflUtils::FileExists( iFs, mediaid )) |
|
491 { |
|
492 RFile64 file; |
|
493 mediaidErr = file.Create(iFs, mediaid, EFileShareReadersOrWriters ); |
|
494 file.Close(); |
|
495 |
|
496 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- mediaID file created, err = %d", mediaidErr ); |
|
497 } |
|
498 |
|
499 // delete db if not fully complete |
|
500 if (prepareErr < 0 || mediaidErr < 0) |
|
501 { |
|
502 iDatabase.Close(); |
|
503 TN_DEBUG1( "CThumbnailStore::RecreateDatabaseL() delete database" ); |
|
504 TInt del = iDatabase.Delete(pathPtr); |
|
505 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() deleted database, err: %d", del ); |
|
506 } |
|
507 |
|
508 User::LeaveIfError( prepareErr ); |
|
509 User::LeaveIfError( mediaidErr ); |
|
510 |
|
511 CleanupStack::PopAndDestroy( databasePath ); |
|
512 } |
|
513 |
|
514 TInt CThumbnailStore::CheckRowIDs() |
|
515 { |
|
516 TN_DEBUG1( "CThumbnailStore::CheckRowIDs()"); |
|
517 |
|
518 RSqlStatement stmt; |
|
519 TInt column = 0; |
|
520 TInt rowStatus = 0; |
|
521 TInt64 inforows = -1; |
|
522 TInt64 datarows = -1; |
|
523 |
|
524 TInt ret = stmt.Prepare( iDatabase, KGetInfoRowID ); |
|
525 if(ret < 0) |
|
526 { |
|
527 stmt.Close(); |
|
528 TN_DEBUG1( "CThumbnailStore::CheckRowIDs() failed 1 %d"); |
|
529 return KErrNotSupported; |
|
530 } |
|
531 rowStatus = stmt.Next(); |
|
532 |
|
533 if ( rowStatus == KSqlAtRow) |
|
534 { |
|
535 inforows = stmt.ColumnInt64( column ); |
|
536 } |
|
537 |
|
538 stmt.Close(); |
|
539 |
|
540 if(ret < 0) |
|
541 { |
|
542 #ifdef _DEBUG |
|
543 TPtrC errorMsg2 = iDatabase.LastErrorMessage(); |
|
544 TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2); |
|
545 #endif |
|
546 return ret; |
|
547 } |
|
548 |
|
549 ret = stmt.Prepare( iDatabase, KGetDataRowID ); |
|
550 if(ret < 0) |
|
551 { |
|
552 stmt.Close(); |
|
553 TN_DEBUG1( "CThumbnailStore::CheckRowIDs() failed 2"); |
|
554 return KErrNotSupported; |
|
555 } |
|
556 rowStatus = stmt.Next(); |
|
557 |
|
558 if ( rowStatus == KSqlAtRow) |
|
559 { |
|
560 datarows = stmt.ColumnInt64( column ); |
|
561 } |
|
562 |
|
563 stmt.Close(); |
|
564 |
|
565 if(ret < 0) |
|
566 { |
|
567 #ifdef _DEBUG |
|
568 TPtrC errorMsg2 = iDatabase.LastErrorMessage(); |
|
569 TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2); |
|
570 #endif |
|
571 return ret; |
|
572 } |
|
573 |
|
574 if( inforows != datarows) |
|
575 { |
|
576 TN_DEBUG1( "CThumbnailStore::CheckRowIDsL() - tables out of sync" ); |
|
577 return KErrNotSupported; |
|
578 } |
|
579 else |
|
580 { |
|
581 return KErrNone; |
|
582 } |
|
583 } |
|
584 |
|
585 // ----------------------------------------------------------------------------- |
|
586 // CheckVersion() |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 TInt CThumbnailStore::CheckVersion() |
|
590 { |
|
591 TN_DEBUG1( "CThumbnailStore::CheckVersion()" ); |
|
592 RSqlStatement stmt; |
|
593 |
|
594 TInt rowStatus = 0; |
|
595 TInt column = 0; |
|
596 TInt minor = 0; |
|
597 TInt major = 0; |
|
598 |
|
599 TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion ); |
|
600 if(ret < 0 ) |
|
601 { |
|
602 stmt.Close(); |
|
603 TN_DEBUG1( "CThumbnailStore::CheckVersion() unknown version" ); |
|
604 return KErrNotSupported; |
|
605 } |
|
606 |
|
607 rowStatus = stmt.Next(); |
|
608 |
|
609 if ( rowStatus == KSqlAtRow) |
|
610 { |
|
611 major = stmt.ColumnInt( column++); |
|
612 minor = stmt.ColumnInt( column++); |
|
613 } |
|
614 |
|
615 stmt.Close(); |
|
616 |
|
617 if(ret < 0 ) |
|
618 { |
|
619 #ifdef _DEBUG |
|
620 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
|
621 TN_DEBUG2( "RThumbnailTransaction::CheckVersion() lastError %S, ret = %d" , &errorMsg); |
|
622 #endif |
|
623 return ret; |
|
624 } |
|
625 |
|
626 if(major == KMajor && minor == KMinor ) |
|
627 { |
|
628 return KErrNone; |
|
629 } |
|
630 else |
|
631 { |
|
632 TN_DEBUG1( "CThumbnailStore::CheckVersion() - wrong DB version" ); |
|
633 return KErrNotSupported; |
|
634 } |
|
635 } |
|
636 |
|
637 // ----------------------------------------------------------------------------- |
|
638 // CheckImei() |
|
639 // ----------------------------------------------------------------------------- |
|
640 // |
|
641 TInt CThumbnailStore::CheckImei() |
|
642 { |
|
643 TN_DEBUG1( "CThumbnailStore::CheckImei()" ); |
|
644 RSqlStatement stmt; |
|
645 |
|
646 TInt rowStatus = 0; |
|
647 TInt column = 0; |
|
648 TBuf<KImeiBufferSize> imei; |
|
649 |
|
650 TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion ); |
|
651 if(ret < 0 ) |
|
652 { |
|
653 stmt.Close(); |
|
654 TN_DEBUG1( "CThumbnailStore::CheckImei() failed" ); |
|
655 return KErrNotSupported; |
|
656 } |
|
657 |
|
658 rowStatus = stmt.Next(); |
|
659 |
|
660 if ( rowStatus == KSqlAtRow) |
|
661 { |
|
662 column = 2; // imei column |
|
663 stmt.ColumnText( column, imei); |
|
664 } |
|
665 |
|
666 stmt.Close(); |
|
667 |
|
668 if(ret < 0 ) |
|
669 { |
|
670 #ifdef _DEBUG |
|
671 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
|
672 TN_DEBUG2( "RThumbnailTransaction::CheckImei() lastError %S, ret = %d" , &errorMsg); |
|
673 #endif |
|
674 return ret; |
|
675 } |
|
676 |
|
677 if( imei == iImei ) |
|
678 { |
|
679 return KErrNone; |
|
680 } |
|
681 else |
|
682 { |
|
683 TN_DEBUG1( "CThumbnailStore::CheckImei() mismatch" ); |
|
684 return KErrNotSupported; |
|
685 } |
|
686 } |
|
687 |
|
688 // ----------------------------------------------------------------------------- |
|
689 // CheckMediaID() |
|
690 // ----------------------------------------------------------------------------- |
|
691 // |
|
692 TInt CThumbnailStore::CheckMediaIDL() |
|
693 { |
|
694 TN_DEBUG1( "CThumbnailStore::CheckMediaIDL()" ); |
|
695 |
|
696 TVolumeInfo volumeinfo; |
|
697 User::LeaveIfError( iFs.Volume(volumeinfo, iDrive) ); |
|
698 TUint id = volumeinfo.iUniqueID; |
|
699 TBuf<50> mediaid; |
|
700 mediaid.Num(id); |
|
701 |
|
702 if(!BaflUtils::FileExists( iFs, mediaid )) |
|
703 { |
|
704 RFile64 file; |
|
705 TInt err = file.Create(iFs, mediaid, EFileShareReadersOrWriters ); |
|
706 file.Close(); |
|
707 TN_DEBUG2( "CThumbnailStore::CheckMediaIDL() -- mediaID file created, err = %d", err ); |
|
708 |
|
709 return KErrNotSupported; |
|
710 } |
|
711 |
|
712 return KErrNone; |
|
713 } |
|
714 |
|
715 // ---------------------------------------------------------------------------- |
|
716 // AddVersionAndImeiL() |
|
717 // ----------------------------------------------------------------------------- |
|
718 // |
|
719 void CThumbnailStore::AddVersionAndImeiL() |
|
720 { |
|
721 TN_DEBUG1( "CThumbnailStore::AddVersionAndImei()" ); |
|
722 RSqlStatement stmt; |
|
723 CleanupClosePushL( stmt ); |
|
724 |
|
725 TInt paramIndex = 0; |
|
726 |
|
727 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailInsertToVersion )); |
|
728 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei ); |
|
729 User::LeaveIfError( paramIndex ); |
|
730 User::LeaveIfError( stmt.BindText( paramIndex, iImei )); |
|
731 |
|
732 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamMinor ); |
|
733 User::LeaveIfError( paramIndex ); |
|
734 User::LeaveIfError( stmt.BindInt( paramIndex, KMinor )); |
|
735 |
|
736 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamMajor ); |
|
737 User::LeaveIfError( paramIndex ); |
|
738 User::LeaveIfError( stmt.BindInt( paramIndex, KMajor )); |
|
739 |
|
740 User::LeaveIfError( stmt.Exec()); |
|
741 CleanupStack::PopAndDestroy( &stmt ); |
|
742 } |
|
743 |
|
744 // ----------------------------------------------------------------------------- |
|
745 // UpdateImeiL() |
|
746 // ----------------------------------------------------------------------------- |
|
747 // |
|
748 TInt CThumbnailStore::UpdateImeiL() |
|
749 { |
|
750 TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" ); |
|
751 RSqlStatement stmt; |
|
752 CleanupClosePushL( stmt ); |
|
753 |
|
754 TInt ret = stmt.Prepare( iDatabase, KThumbnailUpdateIMEI ); |
|
755 |
|
756 TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei ); |
|
757 User::LeaveIfError( paramIndex ); |
|
758 User::LeaveIfError( stmt.BindText( paramIndex, iImei )); |
|
759 |
|
760 TInt err = stmt.Exec(); |
|
761 |
|
454 if(err < 0) |
762 if(err < 0) |
455 { |
763 { |
456 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
764 #ifdef _DEBUG |
457 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() KThumbnailInsertTempThumbnailInfoData %S" , &errorMsg); |
765 TPtrC errorMsg2 = iDatabase.LastErrorMessage(); |
458 } |
766 TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2); |
459 #endif |
767 #endif |
460 TN_DEBUG2( "CThumbnailStore::RecreateDatabaseL() -- database created err = %d", err ); |
768 return ret; |
461 User::LeaveIfError( err ); |
769 } |
462 CleanupStack::PopAndDestroy( databasePath ); |
770 |
463 |
771 CleanupStack::PopAndDestroy( &stmt ); |
464 RFile64 file; |
772 return KErrNone; |
465 file.Create(iFs, mediaid, EFileShareReadersOrWriters ); |
773 } |
466 file.Close(); |
774 |
467 |
775 // --------------------------------------------------------------------------- |
468 OpenDatabaseFileL(); |
776 // CThumbnailStore::PrepareStatementsL() |
777 // --------------------------------------------------------------------------- |
|
778 // |
|
779 void CThumbnailStore::PrepareStatementsL() |
|
780 { |
|
781 TN_DEBUG1("CThumbnailStore::PrepareStatementsL()"); |
|
782 |
|
783 TInt err = KErrNone; |
|
784 #ifdef _DEBUG |
|
785 TFileName msg; |
|
786 #endif |
|
787 |
|
788 err = iStmt_KThumbnailSelectInfoByPath.Prepare( iDatabase, KThumbnailSelectInfoByPath ); |
|
789 #ifdef _DEBUG |
|
790 msg.Append( iDatabase.LastErrorMessage() ); |
|
791 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectInfoByPath %S" , &msg ); |
|
792 msg.Zero(); |
|
793 #endif |
|
794 User::LeaveIfError( err ); |
|
795 |
|
796 err = iStmt_KThumbnailSelectTempInfoByPath.Prepare( iDatabase, KThumbnailSelectTempInfoByPath ); |
|
797 #ifdef _DEBUG |
|
798 msg.Append( iDatabase.LastErrorMessage() ); |
|
799 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectTempInfoByPath %S" , &msg ); |
|
800 msg.Zero(); |
|
801 #endif |
|
802 User::LeaveIfError( err ); |
|
803 |
|
804 err = iStmt_KThumbnailInsertTempThumbnailInfo.Prepare( iDatabase, KThumbnailInsertTempThumbnailInfo ); |
|
805 #ifdef _DEBUG |
|
806 msg.Append( iDatabase.LastErrorMessage() ); |
|
807 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailInsertTempThumbnailInfo %S" , &msg ); |
|
808 msg.Zero(); |
|
809 #endif |
|
810 User::LeaveIfError( err ); |
|
811 |
|
812 err = iStmt_KThumbnailInsertTempThumbnailInfoData.Prepare( iDatabase, KThumbnailInsertTempThumbnailInfoData ); |
|
813 #ifdef _DEBUG |
|
814 msg.Append( iDatabase.LastErrorMessage() ); |
|
815 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailInsertTempThumbnailInfoData %S" , &msg ); |
|
816 msg.Zero(); |
|
817 #endif |
|
818 User::LeaveIfError( err ); |
|
819 |
|
820 err = iStmt_KThumbnailSelectModifiedByPath.Prepare( iDatabase, KThumbnailSelectModifiedByPath ); |
|
821 #ifdef _DEBUG |
|
822 msg.Append( iDatabase.LastErrorMessage() ); |
|
823 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectModifiedByPath %S" , &msg ); |
|
824 msg.Zero(); |
|
825 #endif |
|
826 User::LeaveIfError( err ); |
|
827 |
|
828 err = iStmt_KThumbnailSelectTempModifiedByPath.Prepare( iDatabase, KThumbnailSelectTempModifiedByPath ); |
|
829 #ifdef _DEBUG |
|
830 msg.Append( iDatabase.LastErrorMessage() ); |
|
831 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectTempModifiedByPath %S" , &msg ); |
|
832 msg.Zero(); |
|
833 #endif |
|
834 User::LeaveIfError( err ); |
|
835 |
|
836 err = iStmt_KThumbnailFindDuplicate.Prepare( iDatabase, KThumbnailFindDuplicate ); |
|
837 #ifdef _DEBUG |
|
838 msg.Append( iDatabase.LastErrorMessage() ); |
|
839 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailFindDuplicate %S" , &msg ); |
|
840 msg.Zero(); |
|
841 #endif |
|
842 User::LeaveIfError( err ); |
|
843 |
|
844 err = iStmt_KThumbnailTempFindDuplicate.Prepare( iDatabase, KThumbnailTempFindDuplicate ); |
|
845 #ifdef _DEBUG |
|
846 msg.Append( iDatabase.LastErrorMessage() ); |
|
847 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailTempFindDuplicate %S" , &msg ); |
|
848 msg.Zero(); |
|
849 #endif |
|
850 User::LeaveIfError( err ); |
|
851 |
|
852 err = iStmt_KThumbnailSqlFindDeleted.Prepare( iDatabase, KThumbnailSqlFindDeleted ); |
|
853 #ifdef _DEBUG |
|
854 msg.Append( iDatabase.LastErrorMessage() ); |
|
855 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlFindDeleted %S" , &msg ); |
|
856 msg.Zero(); |
|
857 #endif |
|
858 User::LeaveIfError( err ); |
|
859 |
|
860 err = iStmt_KThumbnailSelectSizeByPath.Prepare( iDatabase, KThumbnailSelectSizeByPath ); |
|
861 #ifdef _DEBUG |
|
862 msg.Append( iDatabase.LastErrorMessage() ); |
|
863 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectSizeByPath %S" , &msg ); |
|
864 msg.Zero(); |
|
865 #endif |
|
866 User::LeaveIfError( err ); |
|
867 |
|
868 err = iStmt_KThumbnailSelectTempSizeByPath.Prepare( iDatabase, KThumbnailSelectTempSizeByPath ); |
|
869 #ifdef _DEBUG |
|
870 msg.Append( iDatabase.LastErrorMessage() ); |
|
871 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectTempSizeByPath %S" , &msg ); |
|
872 msg.Zero(); |
|
873 #endif |
|
874 User::LeaveIfError( err ); |
|
875 |
|
876 err = iStmt_KThumbnailSqlSelectRowIDInfoByPath.Prepare( iDatabase, KThumbnailSqlSelectRowIDInfoByPath ); |
|
877 #ifdef _DEBUG |
|
878 msg.Append( iDatabase.LastErrorMessage() ); |
|
879 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlSelectRowIDInfoByPath %S" , &msg ); |
|
880 msg.Zero(); |
|
881 #endif |
|
882 User::LeaveIfError( err ); |
|
883 |
|
884 err = iStmt_KThumbnailSqlDeleteInfoByPath.Prepare( iDatabase, KThumbnailSqlDeleteInfoByPath ); |
|
885 #ifdef _DEBUG |
|
886 msg.Append( iDatabase.LastErrorMessage() ); |
|
887 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlDeleteInfoByPath %S" , &msg ); |
|
888 msg.Zero(); |
|
889 #endif |
|
890 User::LeaveIfError( err ); |
|
891 |
|
892 err = iStmt_KThumbnailSqlDeleteInfoDataByPath.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByPath ); |
|
893 #ifdef _DEBUG |
|
894 msg.Append( iDatabase.LastErrorMessage() ); |
|
895 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlDeleteInfoDataByPath %S" , &msg ); |
|
896 msg.Zero(); |
|
897 #endif |
|
898 User::LeaveIfError( err ); |
|
899 |
|
900 err = iStmt_KTempThumbnailSqlSelectRowIDInfoByPath.Prepare( iDatabase, KTempThumbnailSqlSelectRowIDInfoByPath ); |
|
901 #ifdef _DEBUG |
|
902 msg.Append( iDatabase.LastErrorMessage() ); |
|
903 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KTempThumbnailSqlSelectRowIDInfoByPath %S" , &msg ); |
|
904 msg.Zero(); |
|
905 #endif |
|
906 User::LeaveIfError( err ); |
|
907 |
|
908 err = iStmt_KTempThumbnailSqlDeleteInfoByPath.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoByPath ); |
|
909 #ifdef _DEBUG |
|
910 msg.Append( iDatabase.LastErrorMessage() ); |
|
911 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KTempThumbnailSqlDeleteInfoByPath %S" , &msg ); |
|
912 msg.Zero(); |
|
913 #endif |
|
914 User::LeaveIfError( err ); |
|
915 |
|
916 err = iStmt_KTempThumbnailSqlDeleteInfoDataByPath.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoDataByPath ); |
|
917 #ifdef _DEBUG |
|
918 msg.Append( iDatabase.LastErrorMessage() ); |
|
919 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KTempThumbnailSqlDeleteInfoDataByPath %S" , &msg ); |
|
920 msg.Zero(); |
|
921 #endif |
|
922 User::LeaveIfError( err ); |
|
923 |
|
924 err = iStmt_KThumbnailSqlInsertDeleted.Prepare( iDatabase, KThumbnailSqlInsertDeleted ); |
|
925 #ifdef _DEBUG |
|
926 msg.Append( iDatabase.LastErrorMessage() ); |
|
927 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlInsertDeleted %S" , &msg ); |
|
928 msg.Zero(); |
|
929 #endif |
|
930 User::LeaveIfError( err ); |
|
931 |
|
932 err = iStmt_KThumbnailSqlSelectMarked.Prepare( iDatabase, KThumbnailSqlSelectMarked ); |
|
933 #ifdef _DEBUG |
|
934 msg.Append( iDatabase.LastErrorMessage() ); |
|
935 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlSelectMarked %S" , &msg ); |
|
936 msg.Zero(); |
|
937 #endif |
|
938 User::LeaveIfError( err ); |
|
939 |
|
940 err = iStmt_KThumbnailSqlDeleteInfoByRowID.Prepare( iDatabase, KThumbnailSqlDeleteInfoByRowID ); |
|
941 #ifdef _DEBUG |
|
942 msg.Append( iDatabase.LastErrorMessage() ); |
|
943 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlDeleteInfoByRowID %S" , &msg ); |
|
944 msg.Zero(); |
|
945 #endif |
|
946 User::LeaveIfError( err ); |
|
947 |
|
948 err = iStmt_KThumbnailSqlDeleteInfoDataByRowID.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByRowID ); |
|
949 #ifdef _DEBUG |
|
950 msg.Append( iDatabase.LastErrorMessage() ); |
|
951 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSqlDeleteInfoDataByRowID %S" , &msg ); |
|
952 msg.Zero(); |
|
953 #endif |
|
954 User::LeaveIfError( err ); |
|
955 |
|
956 err = iStmt_KThumbnailSelectAllPaths.Prepare( iDatabase, KThumbnailSelectAllPaths ); |
|
957 #ifdef _DEBUG |
|
958 msg.Append( iDatabase.LastErrorMessage() ); |
|
959 TN_DEBUG2( "CThumbnailStore::PrepareStatementsL() KThumbnailSelectAllPaths %S" , &msg ); |
|
960 msg.Zero(); |
|
961 #endif |
|
962 User::LeaveIfError( err ); |
|
963 |
|
964 TN_DEBUG1("CThumbnailStore::PrepareStatementsL() end"); |
|
965 } |
|
966 |
|
967 // --------------------------------------------------------------------------- |
|
968 // CThumbnailStore::ResetStatement() |
|
969 // --------------------------------------------------------------------------- |
|
970 // |
|
971 void CThumbnailStore::ResetStatement( TAny* aStmt ) |
|
972 { |
|
973 // called by CleanupStack::PopAndDestroy() |
|
974 // just reset so that there's no need to prepare again |
|
975 ((RSqlStatement*)aStmt)->Reset(); |
|
976 } |
|
977 |
|
978 // --------------------------------------------------------------------------- |
|
979 // CThumbnailStore::CloseStatements() |
|
980 // --------------------------------------------------------------------------- |
|
981 // |
|
982 void CThumbnailStore::CloseStatements() |
|
983 { |
|
984 TN_DEBUG1("CThumbnailStore::CloseStatements()"); |
|
985 |
|
986 iStmt_KThumbnailSelectInfoByPath.Close(); |
|
987 iStmt_KThumbnailSelectTempInfoByPath.Close(); |
|
988 iStmt_KThumbnailInsertTempThumbnailInfo.Close(); |
|
989 iStmt_KThumbnailInsertTempThumbnailInfoData.Close(); |
|
990 iStmt_KThumbnailSelectModifiedByPath.Close(); |
|
991 iStmt_KThumbnailSelectTempModifiedByPath.Close(); |
|
992 iStmt_KThumbnailFindDuplicate.Close(); |
|
993 iStmt_KThumbnailTempFindDuplicate.Close(); |
|
994 iStmt_KThumbnailSqlFindDeleted.Close(); |
|
995 iStmt_KThumbnailSelectSizeByPath.Close(); |
|
996 iStmt_KThumbnailSelectTempSizeByPath.Close(); |
|
997 iStmt_KThumbnailSqlSelectRowIDInfoByPath.Close(); |
|
998 iStmt_KThumbnailSqlDeleteInfoByPath.Close(); |
|
999 iStmt_KThumbnailSqlDeleteInfoDataByPath.Close(); |
|
1000 iStmt_KTempThumbnailSqlSelectRowIDInfoByPath.Close(); |
|
1001 iStmt_KTempThumbnailSqlDeleteInfoByPath.Close(); |
|
1002 iStmt_KTempThumbnailSqlDeleteInfoDataByPath.Close(); |
|
1003 iStmt_KThumbnailSqlInsertDeleted.Close(); |
|
1004 iStmt_KThumbnailSqlSelectMarked.Close(); |
|
1005 iStmt_KThumbnailSqlDeleteInfoByRowID.Close(); |
|
1006 iStmt_KThumbnailSqlDeleteInfoDataByRowID.Close(); |
|
1007 iStmt_KThumbnailSelectAllPaths.Close(); |
|
1008 |
|
1009 TN_DEBUG1("CThumbnailStore::CloseStatements() end"); |
|
469 } |
1010 } |
470 |
1011 |
471 // --------------------------------------------------------------------------- |
1012 // --------------------------------------------------------------------------- |
472 // CThumbnailStore::StoreThumbnailL() |
1013 // CThumbnailStore::StoreThumbnailL() |
473 // Stores thumbnail image. |
1014 // Stores thumbnail image. |
487 //Encapsulate insert to Transaction |
1028 //Encapsulate insert to Transaction |
488 RThumbnailTransaction transaction( iDatabase ); |
1029 RThumbnailTransaction transaction( iDatabase ); |
489 CleanupClosePushL( transaction ); |
1030 CleanupClosePushL( transaction ); |
490 transaction.BeginL(); |
1031 transaction.BeginL(); |
491 |
1032 |
492 RSqlStatement stmt; |
1033 // Insert into TempThumbnailInfo |
493 CleanupClosePushL( stmt ); |
1034 RSqlStatement* stmt = NULL; |
494 // Insert into ThumbnailInfo |
1035 stmt = &iStmt_KThumbnailInsertTempThumbnailInfo; |
495 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailInsertThumbnailInfoByPathAndId )); |
1036 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
496 |
1037 |
497 TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1038 TInt paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
498 User::LeaveIfError( paramIndex ); |
1039 User::LeaveIfError( paramIndex ); |
499 User::LeaveIfError( stmt.BindText( paramIndex, aPath )); |
1040 User::LeaveIfError( stmt->BindText( paramIndex, aPath )); |
500 |
1041 |
501 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamWidth ); |
1042 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamWidth ); |
502 User::LeaveIfError( paramIndex ); |
1043 User::LeaveIfError( paramIndex ); |
503 User::LeaveIfError( stmt.BindInt( paramIndex, aSize.iWidth )); |
1044 User::LeaveIfError( stmt->BindInt( paramIndex, aSize.iWidth )); |
504 |
1045 |
505 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamHeight ); |
1046 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamHeight ); |
506 User::LeaveIfError( paramIndex ); |
1047 User::LeaveIfError( paramIndex ); |
507 User::LeaveIfError( stmt.BindInt( paramIndex, aSize.iHeight )); |
1048 User::LeaveIfError( stmt->BindInt( paramIndex, aSize.iHeight )); |
508 |
1049 |
509 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOriginalWidth ); |
1050 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamOriginalWidth ); |
510 User::LeaveIfError( paramIndex ); |
1051 User::LeaveIfError( paramIndex ); |
511 User::LeaveIfError( stmt.BindInt( paramIndex, aOriginalSize.iWidth )); |
1052 User::LeaveIfError( stmt->BindInt( paramIndex, aOriginalSize.iWidth )); |
512 |
1053 |
513 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOriginalHeight ); |
1054 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamOriginalHeight ); |
514 User::LeaveIfError( paramIndex ); |
1055 User::LeaveIfError( paramIndex ); |
515 User::LeaveIfError( stmt.BindInt( paramIndex, aOriginalSize.iHeight )); |
1056 User::LeaveIfError( stmt->BindInt( paramIndex, aOriginalSize.iHeight )); |
516 |
1057 |
517 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamFormat ); |
1058 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamFormat ); |
518 User::LeaveIfError( paramIndex ); |
1059 User::LeaveIfError( paramIndex ); |
519 User::LeaveIfError( stmt.BindInt( paramIndex, aFormat )); |
1060 User::LeaveIfError( stmt->BindInt( paramIndex, aFormat )); |
520 |
1061 |
521 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamFlags ); |
1062 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamFlags ); |
522 User::LeaveIfError( paramIndex ); |
1063 User::LeaveIfError( paramIndex ); |
523 User::LeaveIfError( stmt.BindInt( paramIndex, aFlags )); |
1064 User::LeaveIfError( stmt->BindInt( paramIndex, aFlags )); |
524 |
1065 |
525 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize ); |
1066 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamSize ); |
526 User::LeaveIfError( paramIndex ); |
1067 User::LeaveIfError( paramIndex ); |
527 User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize )); |
1068 User::LeaveIfError( stmt->BindInt( paramIndex, aThumbnailSize )); |
528 |
1069 |
529 // orientation temporarily to 0 |
1070 // orientation temporarily to 0 |
530 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamOrientation ); |
1071 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamOrientation ); |
531 User::LeaveIfError( paramIndex ); |
1072 User::LeaveIfError( paramIndex ); |
532 User::LeaveIfError( stmt.BindInt( paramIndex, 0 )); |
1073 User::LeaveIfError( stmt->BindInt( paramIndex, 0 )); |
533 |
1074 |
534 // thumb from associated path |
1075 // thumb from associated path |
535 TInt fromPath = aThumbFromPath; |
1076 TInt fromPath = aThumbFromPath; |
536 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamThumbFromPath ); |
1077 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamThumbFromPath ); |
537 User::LeaveIfError( paramIndex ); |
1078 User::LeaveIfError( paramIndex ); |
538 User::LeaveIfError( stmt.BindInt( paramIndex, fromPath )); |
1079 User::LeaveIfError( stmt->BindInt( paramIndex, fromPath )); |
539 |
1080 |
540 // try getting modification time from file |
1081 // try getting modification time from file |
541 TTime timeStamp; |
1082 TTime timeStamp; |
542 |
1083 |
543 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp aModified %Ld", aModified ); |
1084 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp aModified %Ld", aModified ); |
546 { |
1087 { |
547 timeStamp = aModified; |
1088 timeStamp = aModified; |
548 } |
1089 } |
549 else |
1090 else |
550 { |
1091 { |
551 |
1092 TInt timeErr = KErrNone; |
1093 |
|
552 if (aPath.Length()) |
1094 if (aPath.Length()) |
553 { |
1095 { |
554 iFs.Modified(aPath, timeStamp); |
1096 // need to add drive letter |
555 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp iFs %Ld", timeStamp.Int64() ); |
1097 TFileName path; |
556 } |
1098 path.Append(iDriveChar); |
557 else |
1099 path.Append(KDrv); |
1100 path.Append(aPath); |
|
1101 |
|
1102 timeErr = iFs.Modified(path, timeStamp); |
|
1103 |
|
1104 if (timeErr != KErrNone) |
|
1105 { |
|
1106 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() error getting timeStamp: %d", timeErr ); |
|
1107 } |
|
1108 else |
|
1109 { |
|
1110 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp iFs %Ld", timeStamp.Int64() ); |
|
1111 } |
|
1112 } |
|
1113 |
|
1114 if (!aPath.Length() || timeErr != KErrNone) |
|
558 { |
1115 { |
559 // otherwise current time |
1116 // otherwise current time |
560 timeStamp.UniversalTime(); |
1117 timeStamp.UniversalTime(); |
561 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp current %Ld", timeStamp.Int64() ); |
1118 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp current %Ld", timeStamp.Int64() ); |
562 } |
1119 } |
563 } |
1120 } |
564 |
1121 |
565 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp set %Ld", timeStamp.Int64()); |
1122 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() timeStamp set %Ld", timeStamp.Int64()); |
566 |
1123 |
567 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamModified ); |
1124 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamModified ); |
568 User::LeaveIfError( paramIndex ); |
1125 User::LeaveIfError( paramIndex ); |
569 User::LeaveIfError( stmt.BindInt64( paramIndex, timeStamp.Int64() )); |
1126 User::LeaveIfError( stmt->BindInt64( paramIndex, timeStamp.Int64() )); |
570 |
1127 |
571 User::LeaveIfError( stmt.Exec()); |
1128 User::LeaveIfError( stmt->Exec()); |
572 CleanupStack::PopAndDestroy( &stmt ); |
1129 CleanupStack::PopAndDestroy( stmt ); |
573 |
1130 |
574 RSqlStatement stmtData; |
1131 // Insert into TempThumbnailInfoData |
575 CleanupClosePushL( stmtData ); |
1132 RSqlStatement* stmtData = NULL; |
576 // Insert into ThumbnailInfoData |
1133 stmtData = &iStmt_KThumbnailInsertTempThumbnailInfoData; |
577 TInt err = stmtData.Prepare( iDatabase, KThumbnailInsertTempThumbnailInfoData ); |
1134 CleanupStack::PushL(TCleanupItem(ResetStatement, stmtData)); |
578 |
1135 |
579 #ifdef _DEBUG |
1136 paramIndex = stmtData->ParameterIndex( KThumbnailSqlParamData ); |
580 if(err < 0) |
|
581 { |
|
582 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
|
583 TN_DEBUG2( "CThumbnailStore::StoreThumbnailL() KThumbnailInsertTempThumbnailInfoData %S" , &errorMsg); |
|
584 } |
|
585 #endif |
|
586 User::LeaveIfError( err ); |
|
587 |
|
588 paramIndex = stmtData.ParameterIndex( KThumbnailSqlParamData ); |
|
589 User::LeaveIfError( paramIndex ); |
1137 User::LeaveIfError( paramIndex ); |
590 User::LeaveIfError( stmtData.BindBinary( paramIndex, aData )); |
1138 User::LeaveIfError( stmtData->BindBinary( paramIndex, aData )); |
591 |
1139 |
592 User::LeaveIfError( stmtData.Exec()); |
1140 User::LeaveIfError( stmtData->Exec()); |
593 CleanupStack::PopAndDestroy( &stmtData ); |
1141 CleanupStack::PopAndDestroy( stmtData ); |
594 |
1142 |
595 // Commit transaction |
1143 // Commit transaction |
596 transaction.CommitL(); |
1144 transaction.CommitL(); |
597 CleanupStack::PopAndDestroy( &transaction ); |
1145 CleanupStack::PopAndDestroy( &transaction ); |
598 |
1146 |
622 { |
1170 { |
623 TSize thumbSize = aThumbnail->SizeInPixels(); |
1171 TSize thumbSize = aThumbnail->SizeInPixels(); |
624 TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( CFbsBitmap ) aThumbnailSize = %d, aThumbnailSize(%d,%d) IN", aThumbnailSize, thumbSize.iWidth, thumbSize.iHeight ); |
1172 TN_DEBUG4( "CThumbnailStore::StoreThumbnailL( CFbsBitmap ) aThumbnailSize = %d, aThumbnailSize(%d,%d) IN", aThumbnailSize, thumbSize.iWidth, thumbSize.iHeight ); |
625 |
1173 |
626 __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer )); |
1174 __ASSERT_DEBUG(( aThumbnail ), ThumbnailPanic( EThumbnailNullPointer )); |
1175 |
|
1176 User::LeaveIfError( CheckDbState() ); |
|
627 |
1177 |
628 // don't store custom/unknown sizes or zero sizes |
1178 // don't store custom/unknown sizes or zero sizes |
629 if(aThumbnailSize == ECustomThumbnailSize || aThumbnailSize == EUnknownThumbnailSize |
1179 if(aThumbnailSize == ECustomThumbnailSize || aThumbnailSize == EUnknownThumbnailSize |
630 || thumbSize.iWidth <= 0 || thumbSize.iHeight <= 0 ) |
1180 || thumbSize.iWidth <= 0 || thumbSize.iHeight <= 0 ) |
631 { |
1181 { |
660 |
1210 |
661 if( (aThumbnailSize == EImageFullScreenThumbnailSize || aThumbnailSize == EVideoFullScreenThumbnailSize || |
1211 if( (aThumbnailSize == EImageFullScreenThumbnailSize || aThumbnailSize == EVideoFullScreenThumbnailSize || |
662 aThumbnailSize == EAudioFullScreenThumbnailSize) && !aBlackListed ) |
1212 aThumbnailSize == EAudioFullScreenThumbnailSize) && !aBlackListed ) |
663 { |
1213 { |
664 HBufC8* data = NULL; |
1214 HBufC8* data = NULL; |
665 CImageEncoder* iEncoder = CImageEncoder::DataNewL( data, KJpegMime(), CImageEncoder::EOptionAlwaysThread ); |
1215 CleanupStack::PushL( data ); |
1216 |
|
1217 CImageEncoder* encoder = CImageEncoder::DataNewL( data, KJpegMime(), CImageEncoder::EOptionAlwaysThread ); |
|
1218 CleanupStack::Pop( data ); |
|
1219 CleanupStack::PushL( encoder ); |
|
1220 |
|
1221 CFrameImageData* frameImageData = CFrameImageData::NewL(); |
|
1222 CleanupStack::PushL( frameImageData ); |
|
1223 |
|
666 TJpegImageData* imageData = new (ELeave) TJpegImageData(); |
1224 TJpegImageData* imageData = new (ELeave) TJpegImageData(); |
667 |
1225 CleanupStack::PushL( imageData ); |
1226 |
|
668 // Set some format specific data |
1227 // Set some format specific data |
669 imageData->iSampleScheme = TJpegImageData::EColor444; |
1228 imageData->iSampleScheme = TJpegImageData::EColor444; |
670 imageData->iQualityFactor = 75; //? |
1229 imageData->iQualityFactor = 75; |
671 |
1230 |
672 CFrameImageData* iFrameImageData = CFrameImageData::NewL(); |
1231 // imageData - ownership passed to frameImageData after AppendImageData |
673 |
1232 User::LeaveIfError(frameImageData->AppendImageData(imageData)); |
674 // frameData - ownership passed to iFrameImageData after AppendImageData |
1233 CleanupStack::Pop( imageData ); |
675 User::LeaveIfError(iFrameImageData->AppendImageData(imageData)); |
1234 |
676 |
1235 |
677 #ifdef _DEBUG |
1236 #ifdef _DEBUG |
678 TN_DEBUG4( "CThumbnailStore::StoreThumbnailL() size %d x %d displaymode %d ", |
1237 TN_DEBUG4( "CThumbnailStore::StoreThumbnailL() size %d x %d displaymode %d ", |
679 aThumbnail->SizeInPixels().iWidth, |
1238 aThumbnail->SizeInPixels().iWidth, |
680 aThumbnail->SizeInPixels().iHeight, |
1239 aThumbnail->SizeInPixels().iHeight, |
681 aThumbnail->DisplayMode()); |
1240 aThumbnail->DisplayMode()); |
682 #endif |
1241 #endif |
683 |
1242 |
684 TRequestStatus request; |
1243 TRequestStatus request; |
685 iEncoder->Convert( &request, *aThumbnail, iFrameImageData); |
1244 encoder->Convert( &request, *aThumbnail, frameImageData); |
686 User::WaitForRequest( request); |
1245 User::WaitForRequest( request); |
687 |
|
688 if(request== KErrNone) |
|
689 { |
|
690 TPtr8 ptr = data->Des(); |
|
691 StoreThumbnailL( *path, ptr, aThumbnail->SizeInPixels(), aOriginalSize, |
|
692 EThumbnailFormatJpeg, flags, aThumbnailSize, aModified, aThumbFromPath ); |
|
693 } |
|
694 |
|
695 delete iFrameImageData; |
|
696 iFrameImageData = NULL; |
|
697 |
1246 |
698 delete iEncoder; |
1247 CleanupStack::PopAndDestroy( frameImageData ); |
699 iEncoder = NULL; |
1248 CleanupStack::PopAndDestroy( encoder ); |
1249 |
|
1250 if(request == KErrNone) |
|
1251 { |
|
1252 CleanupStack::PushL( data ); |
|
1253 TPtr8 ptr = data->Des(); |
|
1254 StoreThumbnailL( *path, ptr, aThumbnail->SizeInPixels(), |
|
1255 aOriginalSize, EThumbnailFormatJpeg, flags, |
|
1256 aThumbnailSize, aModified, aThumbFromPath ); |
|
1257 CleanupStack::Pop( data ); |
|
1258 } |
|
1259 |
|
700 delete data; |
1260 delete data; |
701 data = NULL; |
1261 data = NULL; |
702 } |
1262 } |
703 else |
1263 else |
704 { |
1264 { |
705 CBufFlat* buf = CBufFlat::NewL( KStreamBufferSize ); |
1265 CBufFlat* buf = CBufFlat::NewL( KStreamBufferSize ); |
706 CleanupStack::PushL( buf ); |
1266 CleanupStack::PushL( buf ); |
707 RBufWriteStream stream; |
1267 RBufWriteStream stream; |
708 stream.Open( *buf ); |
1268 stream.Open( *buf ); |
709 aThumbnail->ExternalizeL( stream ); |
1269 aThumbnail->ExternalizeL( stream ); |
710 |
1270 |
711 StoreThumbnailL( *path, buf->Ptr( 0 ), aThumbnail->SizeInPixels(), |
1271 StoreThumbnailL( *path, buf->Ptr( 0 ), aThumbnail->SizeInPixels(), |
712 aOriginalSize, EThumbnailFormatFbsBitmap, flags, aThumbnailSize, aModified); |
1272 aOriginalSize, EThumbnailFormatFbsBitmap, flags, |
1273 aThumbnailSize, aModified); |
|
713 |
1274 |
714 CleanupStack::PopAndDestroy( buf ); |
1275 CleanupStack::PopAndDestroy( buf ); |
715 } |
1276 } |
716 |
1277 |
717 break; |
1278 break; |
729 // |
1290 // |
730 TBool CThumbnailStore::FindDuplicateL( const TDesC& aPath, const TThumbnailSize& aThumbnailSize ) |
1291 TBool CThumbnailStore::FindDuplicateL( const TDesC& aPath, const TThumbnailSize& aThumbnailSize ) |
731 { |
1292 { |
732 TN_DEBUG1( "CThumbnailStore::FindDuplicateL()" ); |
1293 TN_DEBUG1( "CThumbnailStore::FindDuplicateL()" ); |
733 |
1294 |
1295 User::LeaveIfError( CheckDbState() ); |
|
1296 |
|
734 TInt rowStatus = 0; |
1297 TInt rowStatus = 0; |
735 TInt paramIndex = 0; |
1298 TInt paramIndex = 0; |
736 TInt found = EFalse; |
1299 TInt found = EFalse; |
737 |
1300 |
738 RSqlStatement stmt; |
1301 RSqlStatement* stmt = NULL; |
739 CleanupClosePushL( stmt ); |
1302 stmt = &iStmt_KThumbnailTempFindDuplicate; |
740 |
1303 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
741 User::LeaveIfError( stmt.Prepare( iDatabase, KTempFindDuplicate )); |
1304 |
742 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1305 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
743 User::LeaveIfError( paramIndex ); |
1306 User::LeaveIfError( paramIndex ); |
744 User::LeaveIfError( stmt.BindText( paramIndex, aPath )); |
1307 User::LeaveIfError( stmt->BindText( paramIndex, aPath )); |
745 |
1308 |
746 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize ); |
1309 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamSize ); |
747 User::LeaveIfError( paramIndex ); |
1310 User::LeaveIfError( paramIndex ); |
748 User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize )); |
1311 User::LeaveIfError( stmt->BindInt( paramIndex, aThumbnailSize )); |
749 |
1312 |
750 rowStatus = stmt.Next(); |
1313 rowStatus = stmt->Next(); |
751 |
1314 |
752 //if not found from temp table, look from real table |
1315 //if not found from temp table, look from real table |
753 if(rowStatus != KSqlAtRow) |
1316 if(rowStatus != KSqlAtRow) |
754 { |
1317 { |
755 stmt.Close(); |
1318 CleanupStack::PopAndDestroy( stmt ); |
756 CleanupStack::PopAndDestroy( &stmt ); |
1319 stmt = &iStmt_KThumbnailFindDuplicate; |
757 CleanupClosePushL( stmt ); |
1320 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
758 |
1321 |
759 User::LeaveIfError( stmt.Prepare( iDatabase, KFindDuplicate )); |
1322 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
760 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
|
761 User::LeaveIfError( paramIndex ); |
1323 User::LeaveIfError( paramIndex ); |
762 User::LeaveIfError( stmt.BindText( paramIndex, aPath )); |
1324 User::LeaveIfError( stmt->BindText( paramIndex, aPath )); |
763 |
1325 |
764 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize ); |
1326 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamSize ); |
765 User::LeaveIfError( paramIndex ); |
1327 User::LeaveIfError( paramIndex ); |
766 User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize )); |
1328 User::LeaveIfError( stmt->BindInt( paramIndex, aThumbnailSize )); |
767 |
1329 |
768 rowStatus = stmt.Next(); |
1330 rowStatus = stmt->Next(); |
769 |
1331 |
770 if(rowStatus == KSqlAtRow) |
1332 if(rowStatus == KSqlAtRow) |
771 { |
1333 { |
772 TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate in main table" ); |
1334 TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate in main table" ); |
773 |
1335 |
786 } |
1348 } |
787 |
1349 |
788 // check if duplicate in Deleted |
1350 // check if duplicate in Deleted |
789 if (found) |
1351 if (found) |
790 { |
1352 { |
791 stmt.Close(); |
1353 CleanupStack::PopAndDestroy( stmt ); |
792 CleanupStack::PopAndDestroy( &stmt ); |
1354 stmt = &iStmt_KThumbnailSqlFindDeleted; |
793 CleanupClosePushL( stmt ); |
1355 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
794 |
1356 |
795 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlFindDeleted )); |
1357 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
796 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
|
797 User::LeaveIfError( paramIndex ); |
1358 User::LeaveIfError( paramIndex ); |
798 User::LeaveIfError( stmt.BindText( paramIndex, aPath )); |
1359 User::LeaveIfError( stmt->BindText( paramIndex, aPath )); |
799 |
1360 |
800 rowStatus = stmt.Next(); |
1361 rowStatus = stmt->Next(); |
801 |
1362 |
802 if(rowStatus == KSqlAtRow) |
1363 if(rowStatus == KSqlAtRow) |
803 { |
1364 { |
804 TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate marked deleted" ); |
1365 TN_DEBUG1( "CThumbnailStore::FindDuplicateL() - duplicate marked deleted" ); |
805 |
1366 |
809 |
1370 |
810 found = EFalse; |
1371 found = EFalse; |
811 } |
1372 } |
812 } |
1373 } |
813 |
1374 |
814 stmt.Close(); |
1375 CleanupStack::PopAndDestroy( stmt ); |
815 CleanupStack::PopAndDestroy( &stmt ); |
|
816 |
1376 |
817 return found; |
1377 return found; |
818 } |
1378 } |
819 |
1379 |
820 // --------------------------------------------------------------------------- |
1380 // --------------------------------------------------------------------------- |
824 void CThumbnailStore::GetMissingSizesL( const TDesC& aPath, TInt aSourceType, RArray < |
1384 void CThumbnailStore::GetMissingSizesL( const TDesC& aPath, TInt aSourceType, RArray < |
825 TThumbnailPersistentSize > & aMissingSizes, TBool aCheckGridSizeOnly ) |
1385 TThumbnailPersistentSize > & aMissingSizes, TBool aCheckGridSizeOnly ) |
826 { |
1386 { |
827 TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() aSourceType == %d", aSourceType ); |
1387 TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() aSourceType == %d", aSourceType ); |
828 |
1388 |
1389 User::LeaveIfError( CheckDbState() ); |
|
1390 |
|
829 HBufC* path = aPath.AllocLC(); |
1391 HBufC* path = aPath.AllocLC(); |
830 TPtr ptr(path->Des()); |
1392 TPtr ptr(path->Des()); |
831 StripDriveLetterL( ptr ); |
1393 StripDriveLetterL( ptr ); |
832 |
1394 |
833 // define sizes to be checked |
1395 // define sizes to be checked |
837 { |
1399 { |
838 if ( iPersistentSizes[ i ].iSourceType == aSourceType && iPersistentSizes[ i ].iAutoCreate) |
1400 if ( iPersistentSizes[ i ].iSourceType == aSourceType && iPersistentSizes[ i ].iAutoCreate) |
839 { |
1401 { |
840 //if generating only grid size for image or video, other sizes are not missing |
1402 //if generating only grid size for image or video, other sizes are not missing |
841 if( aCheckGridSizeOnly ) |
1403 if( aCheckGridSizeOnly ) |
842 { |
1404 { |
843 if( (iPersistentSizes[i].iSourceType == TThumbnailPersistentSize::EImage || iPersistentSizes[i].iSourceType == TThumbnailPersistentSize::EVideo )&& |
1405 if( (iPersistentSizes[i].iSourceType == TThumbnailPersistentSize::EImage || iPersistentSizes[i].iSourceType == TThumbnailPersistentSize::EVideo )&& |
844 iPersistentSizes[i].iSizeType != TThumbnailPersistentSize::EGrid ) |
1406 iPersistentSizes[i].iSizeType != TThumbnailPersistentSize::EGrid ) |
845 { |
1407 { |
846 TN_DEBUG4( "CThumbnailStore::GetMissingSizesL() skip, aCheckGridSizeOnly = %d and iPersistentSizes[%d].iSizeType == %d", |
1408 TN_DEBUG4( "CThumbnailStore::GetMissingSizesL() skip, aCheckGridSizeOnly = %d and iPersistentSizes[%d].iSizeType == %d", |
847 aCheckGridSizeOnly, i, iPersistentSizes[i].iSizeType ); |
1409 aCheckGridSizeOnly, i, iPersistentSizes[i].iSizeType ); |
848 } |
1410 } |
849 else |
1411 else |
850 { |
1412 { |
851 aMissingSizes.Append( iPersistentSizes[ i ] ); |
1413 aMissingSizes.AppendL( iPersistentSizes[ i ] ); |
852 } |
1414 } |
853 } |
1415 } |
854 else |
1416 else |
855 { |
1417 { |
856 aMissingSizes.Append( iPersistentSizes[ i ] ); |
1418 aMissingSizes.AppendL( iPersistentSizes[ i ] ); |
857 } |
1419 } |
858 } |
1420 } |
859 } |
1421 } |
860 |
1422 |
861 TInt missingSizeCount = aMissingSizes.Count(); |
1423 TInt missingSizeCount = aMissingSizes.Count(); |
862 |
1424 |
863 TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() missingSizeCount == %d", missingSizeCount ); |
1425 TN_DEBUG2( "CThumbnailStore::GetMissingSizesL() missingSizeCount == %d", missingSizeCount ); |
864 |
1426 |
865 // check temp table first |
1427 // check temp table first |
866 RSqlStatement stmt; |
1428 RSqlStatement* stmt = NULL; |
867 CleanupClosePushL( stmt ); |
1429 stmt = &iStmt_KThumbnailSelectTempSizeByPath; |
868 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempSizeByPath )); |
1430 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
869 TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1431 |
1432 TInt paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
|
870 User::LeaveIfError( paramIndex ); |
1433 User::LeaveIfError( paramIndex ); |
871 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1434 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
872 |
1435 |
873 TInt rowStatus = stmt.Next(); |
1436 TInt rowStatus = stmt->Next(); |
874 |
1437 |
875 TInt round = 1; |
1438 TInt round = 1; |
876 TInt size = 0; |
1439 TInt size = 0; |
877 |
1440 |
878 while (round <= 2) |
1441 while (round <= 2) |
879 { |
1442 { |
880 while ( rowStatus == KSqlAtRow && missingSizeCount > 0 ) |
1443 while ( rowStatus == KSqlAtRow && missingSizeCount > 0 ) |
881 { |
1444 { |
882 size = stmt.ColumnInt( 0 ); |
1445 size = stmt->ColumnInt( 0 ); |
883 |
1446 |
884 missingSizeCount = aMissingSizes.Count(); |
1447 missingSizeCount = aMissingSizes.Count(); |
885 for ( TInt i = 0; i < missingSizeCount; i++ ) |
1448 for ( TInt i = 0; i < missingSizeCount; i++ ) |
886 { |
1449 { |
887 if ( aMissingSizes[ i ].iType == size ) |
1450 if ( aMissingSizes[ i ].iType == size ) |
891 missingSizeCount--; |
1454 missingSizeCount--; |
892 break; |
1455 break; |
893 } |
1456 } |
894 } |
1457 } |
895 |
1458 |
896 rowStatus = stmt.Next(); |
1459 rowStatus = stmt->Next(); |
897 } |
1460 } |
898 stmt.Close(); |
1461 |
899 CleanupStack::PopAndDestroy( &stmt ); |
1462 CleanupStack::PopAndDestroy( stmt ); |
900 |
1463 |
901 // all found |
1464 // all found |
902 if (missingSizeCount == 0) |
1465 if (missingSizeCount == 0) |
903 { |
1466 { |
904 CleanupStack::PopAndDestroy( path ); |
1467 CleanupStack::PopAndDestroy( path ); |
905 return; |
1468 return; |
906 } |
1469 } |
907 else if (round == 1) |
1470 else if (round == 1) |
908 { |
1471 { |
909 // change to real table |
1472 // change to real table |
910 CleanupClosePushL( stmt ); |
1473 stmt = &iStmt_KThumbnailSelectSizeByPath; |
911 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectSizeByPath )); |
1474 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
912 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1475 |
1476 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
|
913 User::LeaveIfError( paramIndex ); |
1477 User::LeaveIfError( paramIndex ); |
914 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1478 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
915 rowStatus = stmt.Next(); |
1479 rowStatus = stmt->Next(); |
916 } |
1480 } |
917 |
1481 |
918 round++; |
1482 round++; |
919 } |
1483 } |
920 |
1484 |
928 // |
1492 // |
929 void CThumbnailStore::FetchThumbnailL( const TDesC& aPath, CFbsBitmap* & |
1493 void CThumbnailStore::FetchThumbnailL( const TDesC& aPath, CFbsBitmap* & |
930 aThumbnail, TDesC8* & aData, const TThumbnailSize aThumbnailSize, TSize &aThumbnailRealSize ) |
1494 aThumbnail, TDesC8* & aData, const TThumbnailSize aThumbnailSize, TSize &aThumbnailRealSize ) |
931 { |
1495 { |
932 TN_DEBUG3( "CThumbnailStore::FetchThumbnailL(%S) aThumbnailSize==%d", &aPath, aThumbnailSize ); |
1496 TN_DEBUG3( "CThumbnailStore::FetchThumbnailL(%S) aThumbnailSize==%d", &aPath, aThumbnailSize ); |
933 delete aThumbnail; |
1497 |
934 aThumbnail = NULL; |
1498 User::LeaveIfError( CheckDbState() ); |
935 |
1499 |
936 HBufC* path = aPath.AllocLC(); |
1500 HBufC* path = aPath.AllocLC(); |
937 TPtr ptr(path->Des()); |
1501 TPtr ptr(path->Des()); |
938 StripDriveLetterL( ptr ); |
1502 StripDriveLetterL( ptr ); |
939 |
|
940 RSqlStatement stmt; |
|
941 CleanupClosePushL( stmt ); |
|
942 |
1503 |
943 TInt paramIndex = 0; |
1504 TInt paramIndex = 0; |
944 TInt found = KErrNotFound; |
1505 TInt found = KErrNotFound; |
945 TInt rowStatus = 0; |
1506 TInt rowStatus = 0; |
946 TInt column = 0; |
1507 TInt column = 0; |
947 TBool inTempTable = ETrue; |
1508 TBool inTempTable = ETrue; |
948 |
1509 |
949 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" ); |
1510 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- TEMP TABLE lookup" ); |
950 TInt err = stmt.Prepare( iDatabase, KThumbnailSelectTempInfoByPath ); |
1511 |
951 |
1512 RSqlStatement* stmt = NULL; |
952 #ifdef _DEBUG |
1513 stmt = &iStmt_KThumbnailSelectTempInfoByPath; |
953 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
1514 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
954 TN_DEBUG2( "CThumbnailStore::FetchThumbnailL() KThumbnailSelectTempInfoByPath %S" , &errorMsg); |
1515 |
955 #endif |
1516 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
956 User::LeaveIfError( err ); |
|
957 |
|
958 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
|
959 User::LeaveIfError( paramIndex ); |
1517 User::LeaveIfError( paramIndex ); |
960 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1518 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
961 |
1519 |
962 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize ); |
1520 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamSize ); |
963 User::LeaveIfError( paramIndex ); |
1521 User::LeaveIfError( paramIndex ); |
964 User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize )); |
1522 User::LeaveIfError( stmt->BindInt( paramIndex, aThumbnailSize )); |
965 |
1523 |
966 rowStatus = stmt.Next(); |
1524 rowStatus = stmt->Next(); |
967 |
1525 |
968 //if not found from temp table, look from real table |
1526 //if not found from temp table, look from real table |
969 if(rowStatus != KSqlAtRow) |
1527 if(rowStatus != KSqlAtRow) |
970 { |
1528 { |
971 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- MAIN TABLE lookup" ); |
1529 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- MAIN TABLE lookup" ); |
972 inTempTable = EFalse; |
1530 inTempTable = EFalse; |
973 stmt.Close(); |
1531 |
974 CleanupStack::PopAndDestroy( &stmt ); |
1532 CleanupStack::PopAndDestroy( stmt ); |
975 CleanupClosePushL( stmt ); |
1533 stmt = &iStmt_KThumbnailSelectInfoByPath; |
976 |
1534 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
977 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectInfoByPath )); |
1535 |
978 |
1536 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
979 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
|
980 User::LeaveIfError( paramIndex ); |
1537 User::LeaveIfError( paramIndex ); |
981 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1538 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
982 |
1539 |
983 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamSize ); |
1540 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamSize ); |
984 User::LeaveIfError( paramIndex ); |
1541 User::LeaveIfError( paramIndex ); |
985 User::LeaveIfError( stmt.BindInt( paramIndex, aThumbnailSize )); |
1542 User::LeaveIfError( stmt->BindInt( paramIndex, aThumbnailSize )); |
986 |
1543 |
987 rowStatus = stmt.Next(); |
1544 rowStatus = stmt->Next(); |
988 } |
1545 } |
989 |
1546 |
990 if(rowStatus == KSqlAtRow) |
1547 if(rowStatus == KSqlAtRow) |
991 { |
1548 { |
992 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail found" ); |
1549 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail found" ); |
1550 |
|
993 // Check whether blacklisted thumbnail entry modified. |
1551 // Check whether blacklisted thumbnail entry modified. |
994 // If thumbnail is marked as blacklisted and timestamp has |
1552 // If thumbnail is marked as blacklisted and timestamp has |
995 // changed, delete thumbnails from tables and leave with |
1553 // changed, delete thumbnails from tables and leave with |
996 // KErrNotFound to get thumbnail regenerated. |
1554 // KErrNotFound to get thumbnail regenerated. |
997 column = 4; |
1555 column = 4; |
998 TInt flags = stmt.ColumnInt( column ); |
1556 TInt flags = stmt->ColumnInt( column ); |
999 if( flags & KThumbnailDbFlagBlacklisted && (*path).Length() ) |
1557 if( flags & KThumbnailDbFlagBlacklisted && (*path).Length() ) |
1000 { |
1558 { |
1001 TBool modified = EFalse; |
1559 TBool modified = EFalse; |
1002 CheckModifiedByPathL( aPath, inTempTable, modified ); |
1560 CheckModifiedByPathL( aPath, inTempTable, modified ); |
1003 if( modified ) |
1561 if( modified ) |
1004 { |
1562 { |
1005 // Close db to get deletion of thumbnails executed. |
1563 // Close db to get deletion of thumbnails executed. |
1006 stmt.Close(); |
|
1007 CleanupStack::PopAndDestroy( &stmt ); |
1564 CleanupStack::PopAndDestroy( &stmt ); |
1008 DeleteThumbnailsL( *path ); |
1565 DeleteThumbnailsL( *path ); |
1009 User::Leave( KErrNotFound ); |
1566 User::Leave( KErrNotFound ); |
1010 } |
1567 } |
1011 else |
1568 else |
1015 } |
1572 } |
1016 else if( !(flags & KThumbnailDbFlagBlacklisted) ) |
1573 else if( !(flags & KThumbnailDbFlagBlacklisted) ) |
1017 { |
1574 { |
1018 found = KErrNone; |
1575 found = KErrNone; |
1019 column = 0; |
1576 column = 0; |
1020 TInt format = stmt.ColumnInt( column++ ); |
1577 TInt format = stmt->ColumnInt( column++ ); |
1021 if(format == 1 /*TThumbnailFormat::EThumbnailFormatJpeg */ ) |
1578 if(format == 1 /*TThumbnailFormat::EThumbnailFormatJpeg */ ) |
1022 { |
1579 { |
1023 TPtrC8 ptr = stmt.ColumnBinaryL( column++ ); |
1580 TPtrC8 ptr = stmt->ColumnBinaryL( column++ ); |
1024 HBufC8* data = ptr.AllocL() ; |
1581 HBufC8* data = ptr.AllocL() ; |
1025 aThumbnail = NULL; |
1582 aThumbnail = NULL; |
1026 aData = data; |
1583 aData = data; |
1027 |
1584 } |
1028 } else { |
1585 else |
1029 |
1586 { |
1030 TPtrC8 ptr = stmt.ColumnBinaryL( column++ ); |
1587 TPtrC8 ptr = stmt->ColumnBinaryL( column++ ); |
1031 RDesReadStream stream( ptr ); |
1588 RDesReadStream stream( ptr ); |
1032 aThumbnail = new( ELeave )CFbsBitmap(); |
1589 aThumbnail = new( ELeave )CFbsBitmap(); |
1033 aThumbnail->InternalizeL( stream ); |
1590 CleanupStack::PushL( aThumbnail ); |
1034 aData = NULL; |
1591 aThumbnail->InternalizeL( stream ); |
1035 } |
1592 CleanupStack::Pop( aThumbnail ); |
1593 aData = NULL; |
|
1594 } |
|
1036 |
1595 |
1037 //fetch real size of TN |
1596 //fetch real size of TN |
1038 column = 2; |
1597 column = 2; |
1039 aThumbnailRealSize.iWidth = stmt.ColumnInt( column++ ); |
1598 aThumbnailRealSize.iWidth = stmt->ColumnInt( column++ ); |
1040 aThumbnailRealSize.iHeight = stmt.ColumnInt( column ); |
1599 aThumbnailRealSize.iHeight = stmt->ColumnInt( column ); |
1041 } |
1600 } |
1042 } |
1601 } |
1043 else |
1602 else |
1044 { |
1603 { |
1045 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail NOT found" ); |
1604 TN_DEBUG1( "CThumbnailStore::FetchThumbnailL() -- thumbnail NOT found" ); |
1046 } |
1605 } |
1047 |
1606 |
1048 stmt.Close(); |
1607 CleanupStack::PopAndDestroy( stmt ); |
1049 CleanupStack::PopAndDestroy( &stmt ); |
|
1050 CleanupStack::PopAndDestroy( path ); |
1608 CleanupStack::PopAndDestroy( path ); |
1051 |
1609 |
1052 User::LeaveIfError( found ); |
1610 User::LeaveIfError( found ); |
1053 } |
1611 } |
1054 |
1612 |
1058 // |
1616 // |
1059 void CThumbnailStore::DeleteThumbnailsL( const TDesC& aPath, TBool aForce, |
1617 void CThumbnailStore::DeleteThumbnailsL( const TDesC& aPath, TBool aForce, |
1060 TBool aTransaction ) |
1618 TBool aTransaction ) |
1061 { |
1619 { |
1062 TN_DEBUG2( "CThumbnailStore::DeleteThumbnailsL(%S)", &aPath ); |
1620 TN_DEBUG2( "CThumbnailStore::DeleteThumbnailsL(%S)", &aPath ); |
1621 |
|
1063 #ifdef _DEBUG |
1622 #ifdef _DEBUG |
1064 TTime aStart, aStop; |
1623 TTime aStart, aStop; |
1065 aStart.UniversalTime(); |
1624 aStart.UniversalTime(); |
1066 #endif |
1625 #endif |
1626 |
|
1627 User::LeaveIfError( CheckDbState() ); |
|
1628 |
|
1067 TInt paramIndex = 0; |
1629 TInt paramIndex = 0; |
1068 TInt paramIndex1 = 0; |
1630 TInt paramIndex1 = 0; |
1069 TInt paramIndex2 = 0; |
1631 TInt paramIndex2 = 0; |
1070 TInt rowStatus = 0; |
1632 TInt rowStatus = 0; |
1071 TInt column = 0; |
1633 TInt column = 0; |
1081 { |
1643 { |
1082 CleanupClosePushL( transaction ); |
1644 CleanupClosePushL( transaction ); |
1083 transaction.BeginL(); |
1645 transaction.BeginL(); |
1084 } |
1646 } |
1085 |
1647 |
1086 RSqlStatement stmt; |
|
1087 RSqlStatement stmt_info; |
|
1088 RSqlStatement stmt_infodata; |
|
1089 |
|
1090 CleanupClosePushL( stmt ); |
|
1091 CleanupClosePushL( stmt_info ); |
|
1092 CleanupClosePushL( stmt_infodata ); |
|
1093 |
|
1094 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup" ); |
1648 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup" ); |
1095 |
1649 |
1096 User::LeaveIfError( stmt.Prepare( iDatabase, KTempThumbnailSqlSelectRowIDInfoByPath) ); |
1650 RSqlStatement* stmt = NULL; |
1097 User::LeaveIfError( stmt_info.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoByPath) ); |
1651 RSqlStatement* stmt_info = NULL; |
1098 User::LeaveIfError( stmt_infodata.Prepare( iDatabase, KTempThumbnailSqlDeleteInfoDataByPath) ); |
1652 RSqlStatement* stmt_infodata = NULL; |
1099 |
1653 |
1100 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1654 stmt = &iStmt_KTempThumbnailSqlSelectRowIDInfoByPath; |
1655 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
|
1656 stmt_info = &iStmt_KTempThumbnailSqlDeleteInfoByPath; |
|
1657 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt_info)); |
|
1658 stmt_infodata = &iStmt_KTempThumbnailSqlDeleteInfoDataByPath; |
|
1659 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt_infodata)); |
|
1660 |
|
1661 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
|
1101 User::LeaveIfError( paramIndex ); |
1662 User::LeaveIfError( paramIndex ); |
1102 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1663 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1103 |
1664 |
1104 rowStatus = stmt.Next(); |
1665 rowStatus = stmt->Next(); |
1105 |
1666 |
1106 while(rowStatus == KSqlAtRow) |
1667 while(rowStatus == KSqlAtRow) |
1107 { |
1668 { |
1108 rowid = stmt.ColumnInt64( column ); |
1669 rowid = stmt->ColumnInt64( column ); |
1109 paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID ); |
1670 paramIndex1 = stmt_info->ParameterIndex( KThumbnailSqlParamRowID ); |
1110 User::LeaveIfError( paramIndex1 ); |
1671 User::LeaveIfError( paramIndex1 ); |
1111 User::LeaveIfError( stmt_info.BindInt64( paramIndex1, rowid )); |
1672 User::LeaveIfError( stmt_info->BindInt64( paramIndex1, rowid )); |
1112 |
1673 |
1113 TInt err = stmt_info.Exec(); |
1674 TInt err = stmt_info->Exec(); |
1114 stmt_info.Reset(); |
1675 stmt_info->Reset(); |
1115 User::LeaveIfError( err ); |
1676 User::LeaveIfError( err ); |
1116 |
1677 |
1117 paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID ); |
1678 paramIndex2 = stmt_infodata->ParameterIndex( KThumbnailSqlParamRowID ); |
1118 User::LeaveIfError( paramIndex2 ); |
1679 User::LeaveIfError( paramIndex2 ); |
1119 User::LeaveIfError( stmt_infodata.BindInt64( paramIndex2, rowid )); |
1680 User::LeaveIfError( stmt_infodata->BindInt64( paramIndex2, rowid )); |
1120 |
1681 |
1121 err = stmt_infodata.Exec(); |
1682 err = stmt_infodata->Exec(); |
1122 stmt_infodata.Reset(); |
1683 stmt_infodata->Reset(); |
1123 User::LeaveIfError( err ); |
1684 User::LeaveIfError( err ); |
1124 |
1685 |
1125 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup - thumbnail deleted" ); |
1686 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailsByPathL() -- TEMP TABLE lookup - thumbnail deleted" ); |
1126 |
1687 |
1127 // fetch another row (temp table rowIDs are updated immediately) |
1688 // fetch another row (temp table rowIDs are updated immediately) |
1128 stmt.Reset(); |
1689 stmt->Reset(); |
1129 |
1690 |
1130 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1691 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1131 User::LeaveIfError( paramIndex ); |
1692 User::LeaveIfError( paramIndex ); |
1132 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1693 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1133 |
1694 |
1134 rowStatus = stmt.Next(); |
1695 rowStatus = stmt->Next(); |
1135 } |
1696 } |
1136 |
1697 |
1137 stmt_infodata.Close(); |
1698 CleanupStack::PopAndDestroy( stmt ); |
1138 stmt_info.Close(); |
1699 CleanupStack::PopAndDestroy( stmt_info ); |
1139 stmt.Close(); |
1700 CleanupStack::PopAndDestroy( stmt_infodata ); |
1140 |
|
1141 CleanupStack::PopAndDestroy( &stmt_infodata ); |
|
1142 CleanupStack::PopAndDestroy( &stmt_info ); |
|
1143 CleanupStack::PopAndDestroy( &stmt ); |
|
1144 |
1701 |
1145 // if forcing instant delete |
1702 // if forcing instant delete |
1146 if (aForce) |
1703 if (aForce) |
1147 { |
1704 { |
1148 //look from real table |
1705 //look from real table |
1149 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" ); |
1706 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup" ); |
1150 |
1707 |
1151 CleanupClosePushL( stmt ); |
1708 stmt = &iStmt_KThumbnailSqlSelectRowIDInfoByPath; |
1152 CleanupClosePushL( stmt_info ); |
1709 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1153 CleanupClosePushL( stmt_infodata ); |
1710 stmt_info = &iStmt_KThumbnailSqlDeleteInfoByPath; |
1154 |
1711 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt_info)); |
1155 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectRowIDInfoByPath )); |
1712 stmt_infodata = &iStmt_KThumbnailSqlDeleteInfoDataByPath; |
1156 User::LeaveIfError( stmt_info.Prepare( iDatabase, KThumbnailSqlDeleteInfoByPath) ); |
1713 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt_infodata)); |
1157 User::LeaveIfError( stmt_infodata.Prepare( iDatabase, KThumbnailSqlDeleteInfoDataByPath) ); |
1714 |
1158 |
1715 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1159 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
|
1160 User::LeaveIfError( paramIndex ); |
1716 User::LeaveIfError( paramIndex ); |
1161 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1717 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1162 |
1718 |
1163 rowStatus = stmt.Next(); |
1719 rowStatus = stmt->Next(); |
1164 |
1720 |
1165 while(rowStatus == KSqlAtRow) |
1721 while(rowStatus == KSqlAtRow) |
1166 { |
1722 { |
1167 rowid = stmt.ColumnInt64( column ); |
1723 rowid = stmt->ColumnInt64( column ); |
1168 paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID ); |
1724 paramIndex1 = stmt_info->ParameterIndex( KThumbnailSqlParamRowID ); |
1169 User::LeaveIfError( paramIndex1 ); |
1725 User::LeaveIfError( paramIndex1 ); |
1170 User::LeaveIfError( stmt_info.BindInt64( paramIndex1, rowid )); |
1726 User::LeaveIfError( stmt_info->BindInt64( paramIndex1, rowid )); |
1171 |
1727 |
1172 TInt err = stmt_info.Exec(); |
1728 TInt err = stmt_info->Exec(); |
1173 stmt_info.Reset(); |
1729 stmt_info->Reset(); |
1174 User::LeaveIfError( err ); |
1730 User::LeaveIfError( err ); |
1175 |
1731 |
1176 paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID ); |
1732 paramIndex2 = stmt_infodata->ParameterIndex( KThumbnailSqlParamRowID ); |
1177 User::LeaveIfError( paramIndex2 ); |
1733 User::LeaveIfError( paramIndex2 ); |
1178 User::LeaveIfError( stmt_infodata.BindInt64( paramIndex2, rowid )); |
1734 User::LeaveIfError( stmt_infodata->BindInt64( paramIndex2, rowid )); |
1179 |
1735 |
1180 err = stmt_infodata.Exec(); |
1736 err = stmt_infodata->Exec(); |
1181 stmt_infodata.Reset(); |
1737 stmt_infodata->Reset(); |
1182 User::LeaveIfError( err ); |
1738 User::LeaveIfError( err ); |
1183 |
1739 |
1184 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup - thumbnail deleted" ); |
1740 TN_DEBUG1( "CThumbnailStore::DeleteThumbnailByPathL() -- MAIN TABLE lookup - thumbnail deleted" ); |
1185 |
1741 |
1186 rowStatus = stmt.Next(); |
1742 rowStatus = stmt->Next(); |
1187 } |
1743 } |
1188 |
1744 |
1189 stmt_infodata.Close(); |
1745 CleanupStack::PopAndDestroy( stmt_infodata ); |
1190 stmt_info.Close(); |
1746 CleanupStack::PopAndDestroy( stmt_info ); |
1191 CleanupStack::PopAndDestroy( &stmt_infodata ); |
|
1192 CleanupStack::PopAndDestroy( &stmt_info ); |
|
1193 } |
1747 } |
1194 else |
1748 else |
1195 { |
1749 { |
1196 // only add path to deleted table |
1750 // only add path to deleted table |
1197 CleanupClosePushL( stmt ); |
1751 stmt = &iStmt_KThumbnailSqlInsertDeleted; |
1198 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlInsertDeleted ) ); |
1752 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1199 |
1753 |
1200 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
1754 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1201 User::LeaveIfError( paramIndex ); |
1755 User::LeaveIfError( paramIndex ); |
1202 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
1756 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1203 |
1757 |
1204 count = stmt.Exec(); |
1758 count = stmt->Exec(); |
1205 } |
1759 } |
1206 |
1760 |
1207 stmt.Close(); |
1761 CleanupStack::PopAndDestroy( stmt ); |
1208 CleanupStack::PopAndDestroy( &stmt ); |
|
1209 |
1762 |
1210 if (aTransaction) |
1763 if (aTransaction) |
1211 { |
1764 { |
1212 transaction.CommitL(); |
1765 transaction.CommitL(); |
1213 CleanupStack::PopAndDestroy( &transaction ); |
1766 CleanupStack::PopAndDestroy( &transaction ); |
1247 { |
1800 { |
1248 TN_DEBUG1("CThumbnailStore::FlushCacheTable() in"); |
1801 TN_DEBUG1("CThumbnailStore::FlushCacheTable() in"); |
1249 |
1802 |
1250 StopAutoFlush(); |
1803 StopAutoFlush(); |
1251 |
1804 |
1252 if(iBatchItemCount <= 0) |
1805 if(iBatchItemCount <= 0 || CheckDbState() != KErrNone) |
1253 { |
1806 { |
1254 // cache empty |
1807 // cache empty or db unusable |
1255 return; |
1808 return; |
1256 } |
1809 } |
1257 |
1810 |
1258 if(iBatchItemCount < KMaxBatchItems && !aForce) |
1811 if(iBatchItemCount < KMaxBatchItems && !aForce) |
1259 { |
1812 { |
1260 //some items in cache |
1813 //some items in cache |
1261 StartAutoFlush(); |
1814 StartAutoFlush(); |
1262 return; |
1815 return; |
1263 } |
1816 } |
1264 |
1817 |
1265 //cache full, flush now |
|
1266 iBatchItemCount = 0; |
|
1267 |
|
1268 #ifdef _DEBUG |
1818 #ifdef _DEBUG |
1269 TTime aStart, aStop; |
1819 TTime aStart, aStop; |
1270 aStart.UniversalTime(); |
1820 aStart.UniversalTime(); |
1271 #endif |
1821 #endif |
1272 |
1822 |
1283 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
1833 TPtrC errorMsg = iDatabase.LastErrorMessage(); |
1284 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() lastError %S", &errorMsg); |
1834 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() lastError %S", &errorMsg); |
1285 } |
1835 } |
1286 #endif |
1836 #endif |
1287 |
1837 |
1288 if(err_tempinfo == KSqlErrCorrupt || err_tempinfo == KErrCorrupt ) |
|
1289 { |
|
1290 TRAP_IGNORE(RecreateDatabaseL(ETrue)); |
|
1291 TRAP_IGNORE(OpenDatabaseL()); |
|
1292 return; |
|
1293 } |
|
1294 |
|
1295 TInt err_tempdata = iDatabase.Exec( KThumbnailMoveFromTempDataToMainTable ); |
1838 TInt err_tempdata = iDatabase.Exec( KThumbnailMoveFromTempDataToMainTable ); |
1296 |
1839 |
1297 #ifdef _DEBUG |
1840 #ifdef _DEBUG |
1298 if(err_tempdata < 0) |
1841 if(err_tempdata < 0) |
1299 { |
1842 { |
1300 TPtrC errorMsg2 = iDatabase.LastErrorMessage(); |
1843 TPtrC errorMsg2 = iDatabase.LastErrorMessage(); |
1301 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() KThumbnailMoveFromTempDataToMainTable %S", &errorMsg2); |
1844 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() KThumbnailMoveFromTempDataToMainTable %S", &errorMsg2); |
1302 } |
1845 } |
1303 #endif |
1846 #endif |
1304 if(err_tempdata == KSqlErrCorrupt || err_tempdata == KErrCorrupt ) |
|
1305 { |
|
1306 TRAP_IGNORE(RecreateDatabaseL(ETrue)); |
|
1307 TRAP_IGNORE(OpenDatabaseL()); |
|
1308 return; |
|
1309 } |
|
1310 |
|
1311 |
1847 |
1312 TInt err_delinfo = iDatabase.Exec( KThumbnailDeleteFromTempInfoTable ); |
1848 TInt err_delinfo = iDatabase.Exec( KThumbnailDeleteFromTempInfoTable ); |
1313 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailDeleteFromTempInfoTable %d", err_delinfo); |
1849 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailDeleteFromTempInfoTable %d", err_delinfo); |
1314 |
1850 |
1315 TInt err_deldata = iDatabase.Exec( KThumbnailDeleteFromTempDataTable ); |
1851 TInt err_deldata = iDatabase.Exec( KThumbnailDeleteFromTempDataTable ); |
1316 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailDeleteFromTempDataTable %d", err_deldata); |
1852 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailDeleteFromTempDataTable %d", err_deldata); |
1317 |
1853 |
1318 |
|
1319 if( err_tempinfo < 0 || err_tempdata < 0 || err_delinfo < 0 || err_deldata < 0 ) |
1854 if( err_tempinfo < 0 || err_tempdata < 0 || err_delinfo < 0 || err_deldata < 0 ) |
1320 { |
1855 { |
1321 TInt err = iDatabase.Exec( KThumbnailRollbackTransaction ); |
1856 TInt err = iDatabase.Exec( KThumbnailRollbackTransaction ); |
1322 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailRollbackTransaction %d", err); |
1857 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailRollbackTransaction %d", err); |
1323 } |
1858 } |
1325 { |
1860 { |
1326 TInt err_commit = iDatabase.Exec( KThumbnailCommitTransaction ); |
1861 TInt err_commit = iDatabase.Exec( KThumbnailCommitTransaction ); |
1327 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailCommitTransaction %d", err_commit); |
1862 TN_DEBUG2("CThumbnailStore::FlushCacheTable() KThumbnailCommitTransaction %d", err_commit); |
1328 } |
1863 } |
1329 |
1864 |
1865 // db got corrupted |
|
1866 if(err_tempinfo == KSqlErrCorrupt || err_tempinfo == KErrCorrupt || |
|
1867 err_tempdata == KSqlErrCorrupt || err_tempdata == KErrCorrupt) |
|
1868 { |
|
1869 TN_DEBUG1("CThumbnailStore::FlushCacheTable() db corrupted"); |
|
1870 |
|
1871 // open new |
|
1872 TRAP_IGNORE(OpenDatabaseL(ETrue)); |
|
1873 } |
|
1874 |
|
1875 //cache flushed |
|
1876 iBatchItemCount = 0; |
|
1877 |
|
1330 #ifdef _DEBUG |
1878 #ifdef _DEBUG |
1331 aStop.UniversalTime(); |
1879 aStop.UniversalTime(); |
1332 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000); |
1880 TN_DEBUG2( "CThumbnailStore::FlushCacheTable() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000); |
1333 #endif |
1881 #endif |
1334 |
1882 |
1335 TN_DEBUG1("CThumbnailStore::FlushCacheTable() out"); |
1883 TN_DEBUG1("CThumbnailStore::FlushCacheTable() out"); |
1336 } |
|
1337 |
|
1338 // ----------------------------------------------------------------------------- |
|
1339 // CheckVersionAndImeiL() |
|
1340 // ----------------------------------------------------------------------------- |
|
1341 // |
|
1342 TInt CThumbnailStore::CheckImeiL() |
|
1343 { |
|
1344 TN_DEBUG1( "CThumbnailStore::CheckImeiL()" ); |
|
1345 RSqlStatement stmt; |
|
1346 CleanupClosePushL( stmt ); |
|
1347 |
|
1348 TInt rowStatus = 0; |
|
1349 TInt column = 0; |
|
1350 TBuf<KImeiBufferSize> imei; |
|
1351 |
|
1352 TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion ); |
|
1353 if(ret < 0 ) |
|
1354 { |
|
1355 stmt.Close(); |
|
1356 CleanupStack::PopAndDestroy( &stmt ); |
|
1357 |
|
1358 TN_DEBUG1( "CThumbnailStore::CheckImeiL() failed" ); |
|
1359 return KErrNotSupported; |
|
1360 } |
|
1361 |
|
1362 rowStatus = stmt.Next(); |
|
1363 |
|
1364 if ( rowStatus == KSqlAtRow) |
|
1365 { |
|
1366 column=2; |
|
1367 stmt.ColumnText( column++, imei); |
|
1368 } |
|
1369 |
|
1370 stmt.Close(); |
|
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 } |
|
1381 |
|
1382 if( imei == iImei ) |
|
1383 { |
|
1384 return KErrNone; |
|
1385 } |
|
1386 else |
|
1387 { |
|
1388 TN_DEBUG1( "CThumbnailStore::CheckImeiL() mismatch" ); |
|
1389 return KErrNotSupported; |
|
1390 } |
|
1391 } |
|
1392 |
|
1393 // ----------------------------------------------------------------------------- |
|
1394 // CheckVersionAndImeiL() |
|
1395 // ----------------------------------------------------------------------------- |
|
1396 // |
|
1397 TInt CThumbnailStore::CheckVersionL() |
|
1398 { |
|
1399 TN_DEBUG1( "CThumbnailStore::CheckVersionL()" ); |
|
1400 RSqlStatement stmt; |
|
1401 CleanupClosePushL( stmt ); |
|
1402 |
|
1403 TInt rowStatus = 0; |
|
1404 TInt column = 0; |
|
1405 TInt minor = 0; |
|
1406 TInt major = 0; |
|
1407 |
|
1408 |
|
1409 TInt ret = stmt.Prepare( iDatabase, KThumbnailSelectFromVersion ); |
|
1410 if(ret < 0 ) |
|
1411 { |
|
1412 stmt.Close(); |
|
1413 CleanupStack::PopAndDestroy( &stmt ); |
|
1414 TN_DEBUG1( "CThumbnailStore::CheckVersionL() unknown version" ); |
|
1415 return KErrNotSupported; |
|
1416 } |
|
1417 |
|
1418 rowStatus = stmt.Next(); |
|
1419 |
|
1420 if ( rowStatus == KSqlAtRow) |
|
1421 { |
|
1422 major = stmt.ColumnInt( column++); |
|
1423 minor = stmt.ColumnInt( column++); |
|
1424 } |
|
1425 |
|
1426 stmt.Close(); |
|
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 } |
|
1437 |
|
1438 if(major == KMajor && minor == KMinor ) |
|
1439 { |
|
1440 return KErrNone; |
|
1441 } |
|
1442 else |
|
1443 { |
|
1444 TN_DEBUG1( "CThumbnailStore::CheckVersionL() - wrong DB version" ); |
|
1445 return KErrNotSupported; |
|
1446 } |
|
1447 } |
|
1448 |
|
1449 |
|
1450 // ----------------------------------------------------------------------------- |
|
1451 // CheckVersionAndImeiL() |
|
1452 // ----------------------------------------------------------------------------- |
|
1453 // |
|
1454 TInt CThumbnailStore::CheckMediaIDL() |
|
1455 { |
|
1456 |
|
1457 TN_DEBUG1( "CThumbnailStore::CheckMediaIDL()" ); |
|
1458 TInt err = 0; |
|
1459 |
|
1460 TVolumeInfo volumeinfo; |
|
1461 err = iFs.Volume(volumeinfo, iDrive); |
|
1462 TUint id = volumeinfo.iUniqueID; |
|
1463 TBuf<50> mediaid; |
|
1464 mediaid.Num(id); |
|
1465 |
|
1466 RFile64 file; |
|
1467 err = file.Open(iFs, mediaid, EFileShareReadersOrWriters); |
|
1468 if(err) |
|
1469 { |
|
1470 file.Create(iFs, mediaid, EFileShareReadersOrWriters ); |
|
1471 file.Close(); |
|
1472 return KErrNotSupported; |
|
1473 } |
|
1474 file.Close(); |
|
1475 return KErrNone; |
|
1476 } |
|
1477 |
|
1478 // ----------------------------------------------------------------------------- |
|
1479 // AddVersionAndImeiL() |
|
1480 // ----------------------------------------------------------------------------- |
|
1481 // |
|
1482 void CThumbnailStore::AddVersionAndImeiL() |
|
1483 { |
|
1484 |
|
1485 TN_DEBUG1( "CThumbnailStore::AddVersionAndImei()" ); |
|
1486 RSqlStatement stmt; |
|
1487 CleanupClosePushL( stmt ); |
|
1488 |
|
1489 TInt paramIndex = 0; |
|
1490 |
|
1491 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailInsertToVersion )); |
|
1492 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei ); |
|
1493 User::LeaveIfError( paramIndex ); |
|
1494 User::LeaveIfError( stmt.BindText( paramIndex, iImei )); |
|
1495 |
|
1496 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamMinor ); |
|
1497 User::LeaveIfError( paramIndex ); |
|
1498 User::LeaveIfError( stmt.BindInt( paramIndex, KMinor )); |
|
1499 |
|
1500 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamMajor ); |
|
1501 User::LeaveIfError( paramIndex ); |
|
1502 User::LeaveIfError( stmt.BindInt( paramIndex, KMajor )); |
|
1503 |
|
1504 User::LeaveIfError( stmt.Exec()); |
|
1505 stmt.Close(); |
|
1506 CleanupStack::PopAndDestroy( &stmt ); |
|
1507 |
|
1508 } |
|
1509 |
|
1510 // ----------------------------------------------------------------------------- |
|
1511 // ResetThumbnailIDs() |
|
1512 // ----------------------------------------------------------------------------- |
|
1513 // |
|
1514 TInt CThumbnailStore::ResetThumbnailIDs() |
|
1515 { |
|
1516 TN_DEBUG1( "CThumbnailStore::ResetThumbnailIDs()" ); |
|
1517 |
|
1518 TInt err = iDatabase.Exec( KTempThumbnailResetIDs ); |
|
1519 TN_DEBUG2( "CThumbnailStore::ResetThumbnailIDs() KThumbnailResetIDs - temp table, err=%d", err ); |
|
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 |
|
1530 err = iDatabase.Exec( KThumbnailResetIDs ); |
|
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; |
|
1542 } |
|
1543 |
|
1544 |
|
1545 // ----------------------------------------------------------------------------- |
|
1546 // UpdateImeiL() |
|
1547 // ----------------------------------------------------------------------------- |
|
1548 // |
|
1549 TInt CThumbnailStore::UpdateImeiL() |
|
1550 { |
|
1551 TN_DEBUG1( "CThumbnailStore::UpdateImeiL()" ); |
|
1552 RSqlStatement stmt; |
|
1553 CleanupClosePushL( stmt ); |
|
1554 |
|
1555 |
|
1556 TInt ret = stmt.Prepare( iDatabase, KThumbnailUpdateIMEI ); |
|
1557 |
|
1558 TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamImei ); |
|
1559 User::LeaveIfError( paramIndex ); |
|
1560 User::LeaveIfError( stmt.BindText( paramIndex, iImei )); |
|
1561 |
|
1562 TInt err = stmt.Exec(); |
|
1563 |
|
1564 if(err < 0) |
|
1565 { |
|
1566 #ifdef _DEBUG |
|
1567 TPtrC errorMsg2 = iDatabase.LastErrorMessage(); |
|
1568 TN_DEBUG2( "RThumbnailTransaction::ResetThumbnailIDs() lastError %S, ret = %d" , &errorMsg2); |
|
1569 #endif |
|
1570 return ret; |
|
1571 } |
|
1572 |
|
1573 stmt.Close(); |
|
1574 CleanupStack::PopAndDestroy( &stmt ); |
|
1575 return KErrNone; |
|
1576 } |
1884 } |
1577 |
1885 |
1578 // ----------------------------------------------------------------------------- |
1886 // ----------------------------------------------------------------------------- |
1579 // StartAutoFlush() |
1887 // StartAutoFlush() |
1580 // ----------------------------------------------------------------------------- |
1888 // ----------------------------------------------------------------------------- |
1668 TInt CThumbnailStore::MaintenanceTimerCallBack(TAny* aAny) |
1976 TInt CThumbnailStore::MaintenanceTimerCallBack(TAny* aAny) |
1669 { |
1977 { |
1670 CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny ); |
1978 CThumbnailStore* self = static_cast<CThumbnailStore*>( aAny ); |
1671 |
1979 |
1672 self->iMaintenanceTimer->Cancel(); |
1980 self->iMaintenanceTimer->Cancel(); |
1981 |
|
1982 TInt MPXHarvesting(0); |
|
1983 TInt DaemonProcessing(0); |
|
1984 TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting); |
|
1985 if(ret != KErrNone || MPXHarvesting) |
|
1986 { |
|
1987 TN_DEBUG3( "CThumbnailStore::MaintenanceTimerCallBack() KMPXHarvesting err == %d, MPXHarvesting == %d", ret, MPXHarvesting); |
|
1988 self->iIdle = EFalse; |
|
1989 } |
|
1990 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() KMPXHarvesting == %d", MPXHarvesting); |
|
1991 |
|
1992 ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing); |
|
1993 if(ret != KErrNone || DaemonProcessing) |
|
1994 { |
|
1995 TN_DEBUG3( "CThumbnailStore::MaintenanceTimerCallBack() KDaemonProcessing err == %d, DaemonProcessing == %d", ret, DaemonProcessing); |
|
1996 self->iIdle = EFalse; |
|
1997 } |
|
1998 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() DaemonProcessing == %d", DaemonProcessing); |
|
1673 |
1999 |
1674 if (self->iIdle) |
2000 if (self->iIdle) |
1675 { |
2001 { |
1676 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive); |
2002 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - maintenance, store %d", self->iDrive); |
1677 |
2003 |
1694 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - cleanup finished, store %d", self->iDrive); |
2020 TN_DEBUG2( "CThumbnailStore::MaintenanceTimerCallBack() - cleanup finished, store %d", self->iDrive); |
1695 self->iDeleteThumbs = EFalse; |
2021 self->iDeleteThumbs = EFalse; |
1696 } |
2022 } |
1697 } |
2023 } |
1698 |
2024 |
1699 // file existance check |
2025 // file existence check |
1700 else if (self->iCheckFilesExist) |
2026 else if (self->iCheckFilesExist) |
1701 { |
2027 { |
1702 TBool finished = EFalse; |
2028 TBool finished = EFalse; |
1703 |
2029 |
1704 TRAPD( err, finished = self->FileExistenceCheckL() ); |
2030 TRAPD( err, finished = self->FileExistenceCheckL() ); |
1733 } |
2059 } |
1734 |
2060 |
1735 return KErrNone; // Return value ignored by CPeriodic |
2061 return KErrNone; // Return value ignored by CPeriodic |
1736 } |
2062 } |
1737 |
2063 |
1738 TInt CThumbnailStore::CheckRowIDsL() |
|
1739 { |
|
1740 TN_DEBUG1( "CThumbnailStore::CheckRowIDs()"); |
|
1741 |
|
1742 RSqlStatement stmt; |
|
1743 CleanupClosePushL( stmt ); |
|
1744 TInt column = 0; |
|
1745 TInt rowStatus = 0; |
|
1746 TInt64 inforows = 0; |
|
1747 TInt64 datarows = 0; |
|
1748 |
|
1749 TInt ret = stmt.Prepare( iDatabase, KGetInfoRowID ); |
|
1750 if(ret < 0) |
|
1751 { |
|
1752 stmt.Close(); |
|
1753 CleanupStack::PopAndDestroy( &stmt ); |
|
1754 TN_DEBUG1( "CThumbnailStore::CheckRowIDs() failed 1 %d"); |
|
1755 return KErrNotSupported; |
|
1756 } |
|
1757 rowStatus = stmt.Next(); |
|
1758 |
|
1759 if ( rowStatus == KSqlAtRow) |
|
1760 { |
|
1761 inforows = stmt.ColumnInt64( column ); |
|
1762 } |
|
1763 |
|
1764 stmt.Close(); |
|
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 } |
|
1775 |
|
1776 CleanupClosePushL( stmt ); |
|
1777 ret = stmt.Prepare( iDatabase, KGetDataRowID ); |
|
1778 if(ret < 0) |
|
1779 { |
|
1780 stmt.Close(); |
|
1781 CleanupStack::PopAndDestroy( &stmt ); |
|
1782 TN_DEBUG1( "CThumbnailStore::CheckRowIDs() failed 2"); |
|
1783 return KErrNotSupported; |
|
1784 } |
|
1785 rowStatus = stmt.Next(); |
|
1786 |
|
1787 if ( rowStatus == KSqlAtRow) |
|
1788 { |
|
1789 datarows = stmt.ColumnInt64( column ); |
|
1790 } |
|
1791 |
|
1792 stmt.Close(); |
|
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 } |
|
1803 |
|
1804 if( inforows != datarows) |
|
1805 { |
|
1806 TN_DEBUG1( "CThumbnailStore::CheckRowIDsL() - tables out of sync" ); |
|
1807 return KErrNotSupported; |
|
1808 } |
|
1809 else |
|
1810 { |
|
1811 return KErrNone; |
|
1812 } |
|
1813 } |
|
1814 |
|
1815 TBool CThumbnailStore::CheckModifiedByPathL( const TDesC& aPath, const TInt64 aModified, TBool& modifiedChanged ) |
2064 TBool CThumbnailStore::CheckModifiedByPathL( const TDesC& aPath, const TInt64 aModified, TBool& modifiedChanged ) |
1816 { |
2065 { |
1817 TN_DEBUG2( "CThumbnailStore::CheckModifiedByPathL() %S", &aPath); |
2066 TN_DEBUG2( "CThumbnailStore::CheckModifiedByPathL() %S", &aPath); |
2067 |
|
2068 User::LeaveIfError( CheckDbState() ); |
|
1818 |
2069 |
1819 HBufC* path = aPath.AllocLC(); |
2070 HBufC* path = aPath.AllocLC(); |
1820 TPtr ptr(path->Des()); |
2071 TPtr ptr(path->Des()); |
1821 StripDriveLetterL( ptr ); |
2072 StripDriveLetterL( ptr ); |
1822 |
2073 |
1823 TBool ret(EFalse); |
2074 TBool ret(EFalse); |
1824 |
2075 |
1825 modifiedChanged = EFalse; |
2076 modifiedChanged = EFalse; |
1826 |
2077 |
1827 TInt column = 0; |
2078 TInt column = 0; |
1828 |
2079 |
1829 RSqlStatement stmt; |
2080 RSqlStatement* stmt = NULL; |
1830 CleanupClosePushL( stmt ); |
2081 stmt = &iStmt_KThumbnailSelectTempModifiedByPath; |
1831 |
2082 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1832 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectTempModifiedByPath )); |
|
1833 |
2083 |
1834 TInt paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
2084 TInt paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1835 User::LeaveIfError( paramIndex ); |
2085 User::LeaveIfError( paramIndex ); |
1836 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
2086 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1837 |
2087 |
1838 TInt rowStatus = stmt.Next(); |
2088 TInt rowStatus = stmt->Next(); |
1839 |
2089 |
1840 TBool checkMain = EFalse; |
2090 TBool checkMain = EFalse; |
1841 |
2091 |
1842 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- temp" ); |
2092 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- temp" ); |
1843 |
2093 |
1844 while(rowStatus == KSqlAtRow || !checkMain) |
2094 while(rowStatus == KSqlAtRow || !checkMain) |
1845 { |
2095 { |
1846 if(rowStatus == KSqlAtRow) |
2096 if(rowStatus == KSqlAtRow) |
1847 { |
2097 { |
1848 ret = ETrue; |
2098 ret = ETrue; |
1849 TInt64 oldModified = stmt.ColumnInt64( column ); |
2099 TInt64 oldModified = stmt->ColumnInt64( column ); |
1850 |
2100 |
1851 TN_DEBUG2( "CThumbnailStore::CheckModifiedL() -- timestamp old %Ld", oldModified); |
2101 TN_DEBUG2( "CThumbnailStore::CheckModifiedL() -- timestamp old %Ld", oldModified); |
1852 TN_DEBUG2( "CThumbnailStore::CheckModifiedL() -- timestamp mds %Ld", aModified); |
2102 TN_DEBUG2( "CThumbnailStore::CheckModifiedL() -- timestamp mds %Ld", aModified); |
1853 |
2103 |
1854 if (oldModified < aModified) |
2104 if (oldModified < aModified) |
1855 { |
2105 { |
1856 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is newer than original" ); |
2106 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is newer than original" ); |
1857 modifiedChanged = ETrue; |
2107 modifiedChanged = ETrue; |
1858 break; |
2108 break; |
1859 } |
2109 } |
1860 else if (oldModified > aModified) |
2110 else if (oldModified > aModified) |
1861 { |
2111 { |
1862 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is older than original" ); |
2112 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is older than original" ); |
1863 } |
2113 } |
1864 else if (oldModified == aModified) |
2114 else if (oldModified == aModified) |
1865 { |
2115 { |
1866 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is the same as original" ); |
2116 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- timestamp is the same as original" ); |
1867 } |
2117 } |
1868 } |
2118 } |
1869 |
2119 |
1870 rowStatus = stmt.Next(); |
2120 rowStatus = stmt->Next(); |
1871 |
2121 |
1872 //switch to main table if modified not found from temp |
2122 //switch to main table if modified not found from temp |
1873 if(rowStatus != KSqlAtRow && !checkMain && !modifiedChanged) |
2123 if(rowStatus != KSqlAtRow && !checkMain && !modifiedChanged) |
1874 { |
2124 { |
1875 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- main" ); |
2125 TN_DEBUG1( "CThumbnailStore::CheckModifiedL() -- main" ); |
1876 //come here only once |
2126 //come here only once |
1877 checkMain = ETrue; |
2127 checkMain = ETrue; |
1878 |
2128 |
1879 stmt.Close(); |
2129 CleanupStack::PopAndDestroy( stmt ); |
1880 CleanupStack::PopAndDestroy( &stmt ); |
2130 stmt = &iStmt_KThumbnailSelectModifiedByPath; |
1881 CleanupClosePushL( stmt ); |
2131 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
1882 |
2132 |
1883 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectModifiedByPath )); |
2133 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamPath ); |
1884 |
2134 User::LeaveIfError( paramIndex ); |
1885 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamPath ); |
2135 User::LeaveIfError( stmt->BindText( paramIndex, *path )); |
1886 User::LeaveIfError( paramIndex ); |
|
1887 User::LeaveIfError( stmt.BindText( paramIndex, *path )); |
|
1888 |
2136 |
1889 rowStatus = stmt.Next(); |
2137 rowStatus = stmt->Next(); |
1890 } |
2138 } |
1891 } |
2139 } |
1892 |
2140 |
1893 stmt.Close(); |
2141 CleanupStack::PopAndDestroy( stmt ); |
1894 CleanupStack::PopAndDestroy( &stmt ); |
2142 CleanupStack::PopAndDestroy( path ); |
1895 |
2143 |
1896 CleanupStack::PopAndDestroy( path ); |
2144 return ret; |
1897 |
|
1898 return ret; |
|
1899 } |
2145 } |
1900 |
2146 |
1901 // ----------------------------------------------------------------------------- |
2147 // ----------------------------------------------------------------------------- |
1902 // PrepareBlacklistedItemsForRetryL() |
2148 // PrepareBlacklistedItemsForRetryL() |
1903 // ----------------------------------------------------------------------------- |
2149 // ----------------------------------------------------------------------------- |
1925 // DeleteMarkedL() |
2171 // DeleteMarkedL() |
1926 // ----------------------------------------------------------------------------- |
2172 // ----------------------------------------------------------------------------- |
1927 // |
2173 // |
1928 TInt CThumbnailStore::DeleteMarkedL() |
2174 TInt CThumbnailStore::DeleteMarkedL() |
1929 { |
2175 { |
2176 TN_DEBUG1( "CThumbnailStore::DeleteMarkedL()" ); |
|
2177 |
|
1930 #ifdef _DEBUG |
2178 #ifdef _DEBUG |
1931 TTime aStart, aStop; |
2179 TTime aStart, aStop; |
1932 aStart.UniversalTime(); |
2180 aStart.UniversalTime(); |
1933 #endif |
2181 #endif |
1934 |
2182 |
1935 TN_DEBUG1( "CThumbnailStore::DeleteMarkedL()" ); |
2183 User::LeaveIfError( CheckDbState() ); |
1936 |
2184 |
1937 TInt paramIndex = 0; |
2185 TInt paramIndex = 0; |
1938 TInt paramIndex1 = 0; |
2186 TInt paramIndex1 = 0; |
1939 TInt paramIndex2 = 0; |
2187 TInt paramIndex2 = 0; |
1940 TInt rowStatus = 0; |
2188 TInt rowStatus = 0; |
1944 |
2192 |
1945 RThumbnailTransaction transaction( iDatabase ); |
2193 RThumbnailTransaction transaction( iDatabase ); |
1946 CleanupClosePushL( transaction ); |
2194 CleanupClosePushL( transaction ); |
1947 transaction.BeginL(); |
2195 transaction.BeginL(); |
1948 |
2196 |
1949 RSqlStatement stmt; |
2197 RSqlStatement* stmt = NULL; |
1950 RSqlStatement stmt_info; |
2198 RSqlStatement* stmt_info = NULL; |
1951 RSqlStatement stmt_infodata; |
2199 RSqlStatement* stmt_infodata = NULL; |
1952 CleanupClosePushL( stmt ); |
2200 |
2201 stmt = &iStmt_KThumbnailSqlSelectMarked; |
|
2202 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
|
2203 stmt_info = &iStmt_KThumbnailSqlDeleteInfoByRowID; |
|
2204 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt_info)); |
|
2205 stmt_infodata = &iStmt_KThumbnailSqlDeleteInfoDataByRowID; |
|
2206 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt_infodata)); |
|
1953 |
2207 |
1954 // select marked rows |
2208 // select marked rows |
1955 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSqlSelectMarked )); |
2209 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamLimit ); |
1956 |
|
1957 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamLimit ); |
|
1958 User::LeaveIfError( paramIndex ); |
2210 User::LeaveIfError( paramIndex ); |
1959 User::LeaveIfError( stmt.BindInt( paramIndex, KStoreMaintenanceDeleteLimit )); |
2211 User::LeaveIfError( stmt->BindInt( paramIndex, KStoreMaintenanceDeleteLimit )); |
1960 |
2212 |
1961 rowStatus = stmt.Next(); |
2213 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) ); |
|
1967 |
2214 |
1968 while(rowStatus == KSqlAtRow) |
2215 while(rowStatus == KSqlAtRow) |
1969 { |
2216 { |
1970 rowid = stmt.ColumnInt64( column ); |
2217 rowid = stmt->ColumnInt64( column ); |
1971 paramIndex1 = stmt_info.ParameterIndex( KThumbnailSqlParamRowID ); |
2218 paramIndex1 = stmt_info->ParameterIndex( KThumbnailSqlParamRowID ); |
1972 User::LeaveIfError( paramIndex1 ); |
2219 User::LeaveIfError( paramIndex1 ); |
1973 User::LeaveIfError( stmt_info.BindInt64( paramIndex1, rowid )); |
2220 User::LeaveIfError( stmt_info->BindInt64( paramIndex1, rowid )); |
1974 |
2221 |
1975 TInt err = stmt_info.Exec(); |
2222 TInt err = stmt_info->Exec(); |
1976 stmt_info.Reset(); |
2223 stmt_info->Reset(); |
1977 User::LeaveIfError( err ); |
2224 User::LeaveIfError( err ); |
1978 |
2225 |
1979 paramIndex2 = stmt_infodata.ParameterIndex( KThumbnailSqlParamRowID ); |
2226 paramIndex2 = stmt_infodata->ParameterIndex( KThumbnailSqlParamRowID ); |
1980 User::LeaveIfError( paramIndex2 ); |
2227 User::LeaveIfError( paramIndex2 ); |
1981 User::LeaveIfError( stmt_infodata.BindInt64( paramIndex2, rowid )); |
2228 User::LeaveIfError( stmt_infodata->BindInt64( paramIndex2, rowid )); |
1982 |
2229 |
1983 err = stmt_infodata.Exec(); |
2230 err = stmt_infodata->Exec(); |
1984 stmt_infodata.Reset(); |
2231 stmt_infodata->Reset(); |
1985 User::LeaveIfError( err ); |
2232 User::LeaveIfError( err ); |
1986 deleteCount++; |
2233 deleteCount++; |
1987 |
2234 |
1988 TN_DEBUG1( "CThumbnailStore::DeleteMarkedL() - thumbnail deleted" ); |
2235 TN_DEBUG1( "CThumbnailStore::DeleteMarkedL() - thumbnail deleted" ); |
1989 |
2236 |
1990 rowStatus = stmt.Next(); |
2237 rowStatus = stmt->Next(); |
1991 } |
2238 } |
1992 |
2239 |
1993 stmt_infodata.Close(); |
2240 CleanupStack::PopAndDestroy( stmt_infodata ); |
1994 stmt_info.Close(); |
2241 CleanupStack::PopAndDestroy( stmt_info ); |
1995 stmt.Close(); |
2242 CleanupStack::PopAndDestroy( stmt ); |
1996 CleanupStack::PopAndDestroy( &stmt_infodata ); |
|
1997 CleanupStack::PopAndDestroy( &stmt_info ); |
|
1998 CleanupStack::PopAndDestroy( &stmt ); |
|
1999 |
2243 |
2000 // remove successfully deleted paths from Deleted table |
2244 // remove successfully deleted paths from Deleted table |
2001 if (deleteCount > 0) |
2245 if (deleteCount > 0) |
2002 { |
2246 { |
2003 CleanupClosePushL( stmt ); |
|
2004 User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) ); |
2247 User::LeaveIfError( iDatabase.Exec( KThumbnailSqlDeleteFromDeleted ) ); |
2005 |
|
2006 stmt.Close(); |
|
2007 CleanupStack::PopAndDestroy( &stmt ); |
|
2008 } |
2248 } |
2009 |
2249 |
2010 transaction.CommitL(); |
2250 transaction.CommitL(); |
2011 CleanupStack::PopAndDestroy( &transaction ); |
2251 CleanupStack::PopAndDestroy( &transaction ); |
2012 |
2252 |
2022 // FileExistenceCheckL() |
2262 // FileExistenceCheckL() |
2023 // ----------------------------------------------------------------------------- |
2263 // ----------------------------------------------------------------------------- |
2024 // |
2264 // |
2025 TInt CThumbnailStore::FileExistenceCheckL() |
2265 TInt CThumbnailStore::FileExistenceCheckL() |
2026 { |
2266 { |
2267 TN_DEBUG1( "CThumbnailStore::FileExistenceCheckL()" ); |
|
2268 |
|
2027 #ifdef _DEBUG |
2269 #ifdef _DEBUG |
2028 TTime aStart, aStop; |
2270 TTime aStart, aStop; |
2029 aStart.UniversalTime(); |
2271 aStart.UniversalTime(); |
2030 #endif |
2272 #endif |
2031 |
2273 |
2032 TN_DEBUG1( "CThumbnailStore::FileExistenceCheckL()" ); |
2274 User::LeaveIfError( CheckDbState() ); |
2033 |
2275 |
2034 TInt paramIndex = 0; |
2276 TInt paramIndex = 0; |
2035 TInt rowStatus = 0; |
2277 TInt rowStatus = 0; |
2036 TInt column = 0; |
2278 TInt column = 0; |
2037 TInt64 rowid = 0; |
2279 TInt64 rowid = 0; |
2040 TFileName full; |
2282 TFileName full; |
2041 TInt count = 0; |
2283 TInt count = 0; |
2042 |
2284 |
2043 TBool finished = EFalse; |
2285 TBool finished = EFalse; |
2044 |
2286 |
2045 TChar dChar = 0; |
|
2046 User::LeaveIfError( iFs.DriveToChar( iDrive, dChar )); |
|
2047 |
|
2048 RThumbnailTransaction transaction( iDatabase ); |
2287 RThumbnailTransaction transaction( iDatabase ); |
2049 CleanupClosePushL( transaction ); |
2288 CleanupClosePushL( transaction ); |
2050 transaction.BeginL(); |
2289 transaction.BeginL(); |
2051 |
2290 |
2052 RSqlStatement stmt; |
2291 // get rows |
2053 CleanupClosePushL( stmt ); |
2292 RSqlStatement* stmt = NULL; |
2054 |
2293 stmt = &iStmt_KThumbnailSelectAllPaths; |
2055 // get rows |
2294 CleanupStack::PushL(TCleanupItem(ResetStatement, stmt)); |
2056 User::LeaveIfError( stmt.Prepare( iDatabase, KThumbnailSelectAllPaths )); |
2295 |
2057 |
2296 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamRowID ); |
2058 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamRowID ); |
|
2059 User::LeaveIfError( paramIndex ); |
2297 User::LeaveIfError( paramIndex ); |
2060 User::LeaveIfError( stmt.BindInt64( paramIndex, iLastCheckedRowID )); |
2298 User::LeaveIfError( stmt->BindInt64( paramIndex, iLastCheckedRowID )); |
2061 |
2299 |
2062 paramIndex = stmt.ParameterIndex( KThumbnailSqlParamLimit ); |
2300 paramIndex = stmt->ParameterIndex( KThumbnailSqlParamLimit ); |
2063 User::LeaveIfError( paramIndex ); |
2301 User::LeaveIfError( paramIndex ); |
2064 User::LeaveIfError( stmt.BindInt( paramIndex, KStoreMaintenanceExistLimit )); |
2302 User::LeaveIfError( stmt->BindInt( paramIndex, KStoreMaintenanceExistLimit )); |
2065 |
2303 |
2066 rowStatus = stmt.Next(); |
2304 rowStatus = stmt->Next(); |
2067 |
2305 |
2068 while(rowStatus == KSqlAtRow) |
2306 while(rowStatus == KSqlAtRow) |
2069 { |
2307 { |
2070 column = 0; |
2308 column = 0; |
2071 path.Zero(); |
2309 path.Zero(); |
2072 |
2310 |
2073 rowid = stmt.ColumnInt64( column++ ); |
2311 rowid = stmt->ColumnInt64( column++ ); |
2074 stmt.ColumnText( column, path ); |
2312 stmt->ColumnText( column, path ); |
2075 |
2313 |
2076 full.Zero(); |
2314 full.Zero(); |
2077 full.Append(dChar); |
2315 full.Append(iDriveChar); |
2078 full.Append(KDrv); |
2316 full.Append(KDrv); |
2079 full.Append(path); |
2317 full.Append(path); |
2080 |
2318 |
2081 // if path matches previous one, skip |
2319 // if path matches previous one, skip |
2082 if (path.CompareF(prevPath) != 0) |
2320 if (path.CompareF(prevPath) != 0) |
2094 |
2332 |
2095 iLastCheckedRowID = rowid; |
2333 iLastCheckedRowID = rowid; |
2096 count++; |
2334 count++; |
2097 |
2335 |
2098 // get next |
2336 // get next |
2099 rowStatus = stmt.Next(); |
2337 rowStatus = stmt->Next(); |
2100 } |
2338 } |
2101 |
2339 |
2102 if (count < KStoreMaintenanceExistLimit) |
2340 if (count < KStoreMaintenanceExistLimit) |
2103 { |
2341 { |
2104 // all rows checked |
2342 // all rows checked |
2105 finished = ETrue; |
2343 finished = ETrue; |
2106 } |
2344 } |
2107 |
2345 |
2108 stmt.Close(); |
2346 CleanupStack::PopAndDestroy( stmt ); |
2109 CleanupStack::PopAndDestroy( &stmt ); |
|
2110 |
2347 |
2111 transaction.CommitL(); |
2348 transaction.CommitL(); |
2112 CleanupStack::PopAndDestroy( &transaction ); |
2349 CleanupStack::PopAndDestroy( &transaction ); |
2113 |
2350 |
2114 #ifdef _DEBUG |
2351 #ifdef _DEBUG |
2129 |
2366 |
2130 // if URI contains drive letter |
2367 // if URI contains drive letter |
2131 if ( pos == 1 ) |
2368 if ( pos == 1 ) |
2132 { |
2369 { |
2133 aPath.Delete(0,pos+1); |
2370 aPath.Delete(0,pos+1); |
2371 } |
|
2372 } |
|
2373 |
|
2374 // ----------------------------------------------------------------------------- |
|
2375 // CheckDbState |
|
2376 // ----------------------------------------------------------------------------- |
|
2377 // |
|
2378 TInt CThumbnailStore::CheckDbState() |
|
2379 { |
|
2380 if (iUnrecoverable) |
|
2381 { |
|
2382 TN_DEBUG1( "CThumbnailStore::CheckDbState() - database in unrecoverable state" ); |
|
2383 __ASSERT_DEBUG( !iUnrecoverable, ThumbnailPanic( EThumbnailDatabaseUnrecoverable )); |
|
2384 |
|
2385 return KStoreUnrecoverableErr; |
|
2386 } |
|
2387 else |
|
2388 { |
|
2389 return KErrNone; |
|
2134 } |
2390 } |
2135 } |
2391 } |
2136 |
2392 |
2137 void CThumbnailStore::HandleDiskSpaceNotificationL( TBool aDiskFull ) |
2393 void CThumbnailStore::HandleDiskSpaceNotificationL( TBool aDiskFull ) |
2138 { |
2394 { |
2168 } |
2424 } |
2169 else |
2425 else |
2170 { |
2426 { |
2171 TInt MPXHarvesting(0); |
2427 TInt MPXHarvesting(0); |
2172 TInt DaemonProcessing(0); |
2428 TInt DaemonProcessing(0); |
2429 |
|
2173 TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting); |
2430 TInt ret = RProperty::Get(KTAGDPSNotification, KMPXHarvesting, MPXHarvesting); |
2174 if(!ret) |
2431 if(ret != KErrNone || MPXHarvesting) |
2432 { |
|
2433 TN_DEBUG3( "CThumbnailStore::ActivityChanged() KMPXHarvesting err == %d, MPXHarvesting == %d", ret, MPXHarvesting); |
|
2434 iIdle = EFalse; |
|
2175 return; |
2435 return; |
2176 |
2436 } |
2177 TN_DEBUG2( "CThumbnailStore::ActivityChanged() KMPXHarvesting == %d", KMPXHarvesting); |
|
2178 |
2437 |
2179 ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing); |
2438 ret = RProperty::Get(KTAGDPSNotification, KDaemonProcessing, DaemonProcessing); |
2180 |
2439 if(ret != KErrNone || DaemonProcessing) |
2181 if(!ret) |
2440 { |
2441 TN_DEBUG3( "CThumbnailStore::ActivityChanged() KDaemonProcessing err == %d DaemonProcessing == %d", ret, DaemonProcessing ); |
|
2442 iIdle = EFalse; |
|
2182 return; |
2443 return; |
2183 |
2444 } |
2184 TN_DEBUG2( "CThumbnailStore::ActivityChanged() DaemonProcessing == %d", DaemonProcessing); |
2445 |
2185 |
2446 TN_DEBUG1( "CThumbnailStore::ActivityChanged() - starting maintenance"); |
2186 if(!MPXHarvesting && !DaemonProcessing) |
2447 iIdle = ETrue; |
2187 { |
2448 StartMaintenance(); |
2188 TN_DEBUG1( "CThumbnailStore::ActivityChanged() - starting maintenance"); |
2449 } |
2189 iIdle = ETrue; |
2450 } |
2190 StartMaintenance(); |
2451 |
2191 } |
2452 |
2192 } |
2453 // ----------------------------------------------------------------------------- |
2193 } |
|
2194 |
|
2195 // CThumbnailStoreDiskSpaceNotifierAO class |
2454 // CThumbnailStoreDiskSpaceNotifierAO class |
2196 |
2455 // ----------------------------------------------------------------------------- |
2456 // |
|
2197 CThumbnailStoreDiskSpaceNotifierAO* CThumbnailStoreDiskSpaceNotifierAO::NewL( |
2457 CThumbnailStoreDiskSpaceNotifierAO* CThumbnailStoreDiskSpaceNotifierAO::NewL( |
2198 MThumbnailStoreDiskSpaceNotifierObserver& aObserver, TInt64 aThreshold, const TDesC& aFilename) |
2458 MThumbnailStoreDiskSpaceNotifierObserver& aObserver, TInt64 aThreshold, const TDesC& aFilename) |
2199 { |
2459 { |
2200 CThumbnailStoreDiskSpaceNotifierAO* self = |
2460 CThumbnailStoreDiskSpaceNotifierAO* self = |
2201 CThumbnailStoreDiskSpaceNotifierAO::NewLC( aObserver, aThreshold, aFilename); |
2461 CThumbnailStoreDiskSpaceNotifierAO::NewLC( aObserver, aThreshold, aFilename); |
2258 { |
2518 { |
2259 case KErrNone: |
2519 case KErrNone: |
2260 ret = iFileServerSession.Volume( volumeInfo, iDrive ); |
2520 ret = iFileServerSession.Volume( volumeInfo, iDrive ); |
2261 |
2521 |
2262 if(!ret) |
2522 if(!ret) |
2263 { |
2523 { |
2264 |
|
2265 // Check if free space is less than threshold level |
2524 // Check if free space is less than threshold level |
2266 if( volumeInfo.iFree < iThreshold ) |
2525 if( volumeInfo.iFree < iThreshold ) |
2267 { |
2526 { |
2268 TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() FULL"); |
2527 TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() FULL"); |
2269 iDiskFull = ETrue; |
2528 iDiskFull = ETrue; |
2303 } |
2562 } |
2304 else if ( iState == CThumbnailStoreDiskSpaceNotifierAO::EIterate ) |
2563 else if ( iState == CThumbnailStoreDiskSpaceNotifierAO::EIterate ) |
2305 { |
2564 { |
2306 const TInt KMaxIterations = 10; |
2565 const TInt KMaxIterations = 10; |
2307 |
2566 |
2308 iFileServerSession.Volume( volumeInfo, iDrive ); |
2567 User::LeaveIfError( iFileServerSession.Volume( volumeInfo, iDrive ) ); |
2309 if ( volumeInfo.iFree < iThreshold ) |
2568 if ( volumeInfo.iFree < iThreshold ) |
2310 { |
2569 { |
2311 iObserver.HandleDiskSpaceNotificationL( iDiskFull ); |
2570 iObserver.HandleDiskSpaceNotificationL( iDiskFull ); |
2312 ++iIterationCount; |
2571 ++iIterationCount; |
2313 if ( iIterationCount < KMaxIterations ) |
2572 if ( iIterationCount < KMaxIterations ) |
2317 User::RequestComplete( status, KErrNone ); |
2576 User::RequestComplete( status, KErrNone ); |
2318 return; |
2577 return; |
2319 } |
2578 } |
2320 else |
2579 else |
2321 { |
2580 { |
2322 iFileServerSession.Volume( volumeInfo, iDrive ); |
2581 User::LeaveIfError( iFileServerSession.Volume( volumeInfo, iDrive ) ); |
2323 if ( volumeInfo.iFree >= iThreshold ) |
2582 if ( volumeInfo.iFree >= iThreshold ) |
2324 { |
2583 { |
2325 TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() NOT FULL"); |
2584 TN_DEBUG1( "CThumbnailStoreDiskSpaceNotifierAO::RunL() NOT FULL"); |
2326 iDiskFull = EFalse; |
2585 iDiskFull = EFalse; |
2327 } |
2586 } |