|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Thumbnail storage implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 31/07/2007 by Simon Brooks |
|
23 */ |
|
24 |
|
25 // INCLUDE FILES |
|
26 |
|
27 #include "glxtndatabase.h" |
|
28 |
|
29 #include <glxassert.h> |
|
30 #include <glxtracer.h> |
|
31 #include <glxlog.h> |
|
32 #include <driveinfo.h> |
|
33 #include <pathinfo.h> |
|
34 #include <e32des16.h> |
|
35 #include <e32std.h> |
|
36 #include <bautils.h> |
|
37 #include <centralrepository.h> |
|
38 |
|
39 #include "glxtnfileinfo.h" |
|
40 #include "glxtnvolumedatabase.h" |
|
41 |
|
42 // ============================ CONSTANTS =============================== |
|
43 _LIT(KDriveNameFormat, "%c:\\"); |
|
44 |
|
45 const TInt KLoggingDriveLetterLength = 8; |
|
46 const TInt KGlxmediaSerialIdLength = 64; |
|
47 const TUint32 KGlxTnMassStorageNotFreshlyFlashed = 0x00000001 ; |
|
48 const TUint32 KGlxTnSDCardVolumeId = 0x00000001 ; |
|
49 const TUint32 KGlxTnHardDriveFlashState = 0x00000002 ; |
|
50 |
|
51 const TInt KRepositoryId = 0x2000A09 ; |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CGlxtnThumbnailDatabase::CGlxtnThumbnailDatabase |
|
56 // C++ default constructor can NOT contain any code, that might leave. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CGlxtnThumbnailDatabase::CGlxtnThumbnailDatabase() |
|
60 { |
|
61 TRACER("CGlxtnThumbnailDatabase::CGlxtnThumbnailDatabase()"); |
|
62 iInternalDrive = PathInfo::PhoneMemoryRootPath().Left( KMaxDriveName ); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CGlxtnThumbnailDatabase::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CGlxtnThumbnailDatabase::ConstructL(const TDesC& aDbFilename, |
|
71 MGlxtnThumbnailStorageObserver* aStorageObserver) |
|
72 { |
|
73 TRACER("void CGlxtnThumbnailDatabase::ConstructL()"); |
|
74 User::LeaveIfError(iFs.Connect()); |
|
75 |
|
76 User::LeaveIfError(iFs.PrivatePath(iDatabasePath)); |
|
77 iDatabasePath.Append(aDbFilename); |
|
78 iStorageObserver = aStorageObserver; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CGlxtnThumbnailDatabase::NewL |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C CGlxtnThumbnailDatabase* CGlxtnThumbnailDatabase::NewL( |
|
87 const TDesC& aDbFilename, |
|
88 MGlxtnThumbnailStorageObserver* aStorageObserver) |
|
89 { |
|
90 TRACER("CGlxtnThumbnailDatabase* CGlxtnThumbnailDatabase::NewL()"); |
|
91 CGlxtnThumbnailDatabase* self = new (ELeave) CGlxtnThumbnailDatabase; |
|
92 |
|
93 CleanupStack::PushL(self); |
|
94 self->ConstructL(aDbFilename, aStorageObserver); |
|
95 CleanupStack::Pop( self ); |
|
96 |
|
97 return self; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // Destructor |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 CGlxtnThumbnailDatabase::~CGlxtnThumbnailDatabase() |
|
105 { |
|
106 TRACER("CGlxtnThumbnailDatabase::~CGlxtnThumbnailDatabase()"); |
|
107 iDatabaseArray.ResetAndDestroy(); |
|
108 iFs.Close(); |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // LoadThumbnailDataL |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CGlxtnThumbnailDatabase::LoadThumbnailDataL(HBufC8*& aData, |
|
116 TGlxImageDataFormat& aFormat, const TGlxMediaId& aId, |
|
117 const CGlxtnFileInfo& aFileInfo, const TSize& aSize, |
|
118 TRequestStatus* aStatus) |
|
119 { |
|
120 TRACER("void CGlxtnThumbnailDatabase::LoadThumbnailDataL()"); |
|
121 if ( iClientStatus ) |
|
122 { |
|
123 User::Leave(KErrNotReady); |
|
124 } |
|
125 |
|
126 iCurrentOperation = ELoading; |
|
127 iLoadData = &aData; |
|
128 iLoadFormat = &aFormat; |
|
129 iMediaId = aId; |
|
130 iFileInfo = &aFileInfo; |
|
131 iSize = aSize; |
|
132 |
|
133 OpenDatabaseL( iInternalDrive )->GetThumbnailIdL( iMediaId ); |
|
134 |
|
135 iClientStatus = aStatus; |
|
136 *iClientStatus = KRequestPending; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // SaveThumbnailDataL |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CGlxtnThumbnailDatabase::SaveThumbnailDataL(const TDesC8& aData, |
|
144 TGlxImageDataFormat aFormat, const TGlxMediaId& aId, |
|
145 const CGlxtnFileInfo& aFileInfo, const TSize& aSize, |
|
146 TRequestStatus* aStatus) |
|
147 { |
|
148 TRACER("void CGlxtnThumbnailDatabase::SaveThumbnailDataL()"); |
|
149 if ( iClientStatus ) |
|
150 { |
|
151 User::Leave(KErrNotReady); |
|
152 } |
|
153 |
|
154 iCurrentOperation = ESaving; |
|
155 iSaveData.Set(aData); |
|
156 ASSERT(iSaveData.Length() == aData.Length()); |
|
157 iSaveFormat = aFormat; |
|
158 iMediaId = aId; |
|
159 iFileInfo = &aFileInfo; |
|
160 iSize = aSize; |
|
161 |
|
162 OpenDatabaseL( iInternalDrive )->GetThumbnailIdL( iMediaId ); |
|
163 |
|
164 iClientStatus = aStatus; |
|
165 *iClientStatus = KRequestPending; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // DeleteThumbnailsL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CGlxtnThumbnailDatabase::DeleteThumbnailsL(const TGlxMediaId& aId, |
|
173 const CGlxtnFileInfo& aFileInfo, TRequestStatus* aStatus) |
|
174 { |
|
175 TRACER("void CGlxtnThumbnailDatabase::DeleteThumbnailsL()"); |
|
176 if ( iClientStatus ) |
|
177 { |
|
178 User::Leave(KErrNotReady); |
|
179 } |
|
180 iCurrentOperation = EDeleting; |
|
181 iMediaId = aId; |
|
182 iFileInfo = &aFileInfo; |
|
183 |
|
184 OpenDatabaseL( iInternalDrive )->GetThumbnailIdL( iMediaId ); |
|
185 |
|
186 iClientStatus = aStatus; |
|
187 *iClientStatus = KRequestPending; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CleanupThumbnailsL |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CGlxtnThumbnailDatabase::CleanupThumbnailsL(TRequestStatus* aStatus) |
|
195 { |
|
196 TRACER("void CGlxtnThumbnailDatabase::CleanupThumbnailsL()"); |
|
197 if ( iClientStatus ) |
|
198 { |
|
199 User::Leave(KErrNotReady); |
|
200 } |
|
201 |
|
202 OpenDatabaseL( iInternalDrive ); |
|
203 GLX_ASSERT_ALWAYS( iDatabaseArray.Count() > 0, |
|
204 Panic( EGlxPanicLogicError ), "No databases to clean" ); |
|
205 |
|
206 iDatabaseIndex = 0; |
|
207 iDatabaseArray[iDatabaseIndex]->CleanupDatabaseL(); |
|
208 |
|
209 iClientStatus = aStatus; |
|
210 *iClientStatus = KRequestPending; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // IsThumbnailAvailableL |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CGlxtnThumbnailDatabase::IsThumbnailAvailableL(const TGlxMediaId& aId, |
|
218 const CGlxtnFileInfo& aFileInfo, |
|
219 const TSize& aSize, TRequestStatus* aStatus) |
|
220 { |
|
221 TRACER("void CGlxtnThumbnailDatabase::IsThumbnailAvailableL()"); |
|
222 if ( iClientStatus ) |
|
223 { |
|
224 User::Leave(KErrNotReady); |
|
225 } |
|
226 |
|
227 iCurrentOperation = ECheckingAvailable; |
|
228 iMediaId = aId; |
|
229 iFileInfo = &aFileInfo; |
|
230 iSize = aSize; |
|
231 |
|
232 OpenDatabaseL( iInternalDrive )->GetThumbnailIdL( iMediaId ); |
|
233 |
|
234 iClientStatus = aStatus; |
|
235 *iClientStatus = KRequestPending; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // StorageCancel |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CGlxtnThumbnailDatabase::StorageCancel() |
|
243 { |
|
244 TRACER("void CGlxtnThumbnailDatabase::StorageCancel()"); |
|
245 TInt count = iDatabaseArray.Count(); |
|
246 for ( TInt i = 0; i < count; i++ ) |
|
247 { |
|
248 iDatabaseArray[i]->Cancel(); |
|
249 } |
|
250 |
|
251 if ( iClientStatus ) |
|
252 { |
|
253 User::RequestComplete(iClientStatus, KErrCancel); |
|
254 } |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // NotifyBackgroundError |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CGlxtnThumbnailDatabase::NotifyBackgroundError( |
|
262 const TGlxMediaId& aId, TInt aError ) |
|
263 { |
|
264 TRACER("void CGlxtnThumbnailDatabase::NotifyBackgroundError()"); |
|
265 if ( iStorageObserver ) |
|
266 { |
|
267 iStorageObserver->BackgroundThumbnailError(aId, aError); |
|
268 } |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // HandleDatabaseError |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CGlxtnThumbnailDatabase::HandleDatabaseError(TInt aError) |
|
276 { |
|
277 TRACER("void CGlxtnThumbnailDatabase::HandleDatabaseError()"); |
|
278 __ASSERT_DEBUG(KErrNone != aError, Panic(EGlxPanicIllegalArgument)); |
|
279 __ASSERT_DEBUG(iClientStatus, Panic(EGlxPanicNotInitialised)); |
|
280 |
|
281 // Recover from database file corruption |
|
282 // though the database file opening is successful |
|
283 if (aError == KErrCorruptThumbnailDatabase) |
|
284 { |
|
285 RecoverFromDatabaseError(); |
|
286 aError = KErrCorrupt; |
|
287 } |
|
288 else if (aError == KErrEofThumbnailDatabase) |
|
289 { |
|
290 RecoverFromDatabaseError(); |
|
291 aError = KErrEof; |
|
292 } |
|
293 |
|
294 if ( iClientStatus ) |
|
295 { |
|
296 User::RequestComplete(iClientStatus, aError); |
|
297 } |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // RecoverFromDatabaseError |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 void CGlxtnThumbnailDatabase::RecoverFromDatabaseError() |
|
305 { |
|
306 TRACER("void CGlxtnThumbnailDatabase::RecoverFromDatabaseError()"); |
|
307 GLX_LOG_INFO("*** Database Corrupted ***"); |
|
308 |
|
309 TFileName path(iFileInfo->FilePath().Left(KMaxDriveName)); |
|
310 TInt count = iDatabaseArray.Count(); |
|
311 for ( TInt i = 0; i < count; i++ ) |
|
312 { |
|
313 if ( 0 == path.CompareF(iDatabaseArray[i]->Drive()) ) |
|
314 { |
|
315 |
|
316 CGlxtnVolumeDatabase* volDb = iDatabaseArray[i]; |
|
317 iDatabaseArray.Remove(i); |
|
318 |
|
319 delete volDb; |
|
320 volDb = NULL; |
|
321 |
|
322 break; |
|
323 } |
|
324 } |
|
325 |
|
326 path.Append(iDatabasePath); |
|
327 DeleteFile(path); |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // HandleThumbnailIdFromMediaIdL |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 void CGlxtnThumbnailDatabase::HandleThumbnailIdFromMediaIdL( |
|
335 const TGlxtnThumbnailId& aThumbId ) |
|
336 { |
|
337 TRACER("void CGlxtnThumbnailDatabase::HandleThumbnailIdFromMediaIdL()"); |
|
338 if ( aThumbId == KGlxIdNone ) |
|
339 { |
|
340 CGlxtnVolumeDatabase* db = OpenDatabaseL(iInternalDrive); |
|
341 iThumbId = db->GetThumbnailId(); |
|
342 // Store thumbnail ID to speed up future lookups |
|
343 db->StoreThumbnailIdL(iMediaId, iThumbId); |
|
344 } |
|
345 else |
|
346 { |
|
347 iThumbId = aThumbId; |
|
348 if(iCurrentOperation == EDeleting) |
|
349 { |
|
350 OpenDatabaseL( iInternalDrive )->DeleteIdL( iMediaId ); |
|
351 } |
|
352 else |
|
353 { |
|
354 DoHandleThumbnailIdL(); |
|
355 } |
|
356 } |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // HandleMediaIdDeletedL |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CGlxtnThumbnailDatabase::HandleMediaIdDeletedL() |
|
364 { |
|
365 TRACER("void CGlxtnThumbnailDatabase::HandleMediaIdDeletedL()"); |
|
366 OpenDatabaseL(iFileInfo->FilePath())->DeleteThumbnailsL(iThumbId); |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // HandleThumbnailsDeletedL |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 void CGlxtnThumbnailDatabase::HandleThumbnailsDeletedL() |
|
374 { |
|
375 TRACER("void CGlxtnThumbnailDatabase::HandleThumbnailsDeletedL()"); |
|
376 OpenDatabaseL(iFileInfo->FilePath())->DeleteItemL(iThumbId); |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // HandleItemsDeletedL |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 void CGlxtnThumbnailDatabase::HandleItemDeletedL() |
|
384 { |
|
385 TRACER("void CGlxtnThumbnailDatabase::HandleItemDeletedL()"); |
|
386 __ASSERT_DEBUG(iClientStatus, Panic(EGlxPanicNotInitialised)); |
|
387 if ( iClientStatus ) |
|
388 { |
|
389 User::RequestComplete(iClientStatus, KErrNone); |
|
390 } |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // HandleThumbnailIdFromFilenameL |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CGlxtnThumbnailDatabase::HandleThumbnailIdFromFilenameL( |
|
398 const TGlxtnThumbnailId& aThumbId ) |
|
399 { |
|
400 TRACER("void CGlxtnThumbnailDatabase::HandleThumbnailIdFromFilenameL()"); |
|
401 iThumbId = aThumbId; |
|
402 if(iCurrentOperation == EDeleting) |
|
403 { |
|
404 GLX_LOG_INFO1("GlxtnThumbnailDatabase::HandleThumbnailIdFromFilenameL Current Operation Deleting. aThumbId = %d", aThumbId.Value()); |
|
405 OpenDatabaseL(iFileInfo->FilePath())->DeleteThumbnailsL(iThumbId); |
|
406 } |
|
407 else |
|
408 { |
|
409 GLX_LOG_INFO1("GlxtnThumbnailDatabase::HandleThumbnailIdFromFilenameL Current Operation NOT Deleting. aThumbId = %d", aThumbId.Value()); |
|
410 // Store thumbnail ID to speed up future lookups |
|
411 OpenDatabaseL( iInternalDrive )->StoreThumbnailIdL( |
|
412 iMediaId, iThumbId ); |
|
413 } |
|
414 } |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // HandleThumbnailIdStoredL |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 void CGlxtnThumbnailDatabase::HandleThumbnailIdStoredL() |
|
421 { |
|
422 TRACER("void CGlxtnThumbnailDatabase::HandleThumbnailIdStoredL()"); |
|
423 DoHandleThumbnailIdL(); |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // HandleThumbnail |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CGlxtnThumbnailDatabase::HandleThumbnail( |
|
431 TGlxImageDataFormat aFormat, HBufC8* aData ) |
|
432 { |
|
433 TRACER("void CGlxtnThumbnailDatabase::HandleThumbnail()"); |
|
434 __ASSERT_DEBUG(iClientStatus, Panic(EGlxPanicNotInitialised)); |
|
435 if ( iClientStatus ) |
|
436 { |
|
437 *iLoadData = aData; |
|
438 *iLoadFormat = aFormat; |
|
439 User::RequestComplete(iClientStatus, KErrNone); |
|
440 } |
|
441 else |
|
442 { |
|
443 // Data loaded, but client doesn't want it (shouldn't ever happen) |
|
444 delete aData; |
|
445 } |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // HandleThumbnailStored |
|
450 // ----------------------------------------------------------------------------- |
|
451 // |
|
452 void CGlxtnThumbnailDatabase::HandleThumbnailStored() |
|
453 { |
|
454 TRACER("void CGlxtnThumbnailDatabase::HandleThumbnailStored()"); |
|
455 if ( iStorageObserver ) |
|
456 { |
|
457 iStorageObserver->ThumbnailAvailable(iMediaId, iSize); |
|
458 } |
|
459 |
|
460 __ASSERT_DEBUG(iClientStatus, Panic(EGlxPanicNotInitialised)); |
|
461 if ( iClientStatus ) |
|
462 { |
|
463 User::RequestComplete(iClientStatus, KErrNone); |
|
464 } |
|
465 } |
|
466 |
|
467 // ----------------------------------------------------------------------------- |
|
468 // HandleAvailabilityChecked |
|
469 // ----------------------------------------------------------------------------- |
|
470 // |
|
471 void CGlxtnThumbnailDatabase::HandleAvailabilityChecked(TInt aResult) |
|
472 { |
|
473 TRACER("void CGlxtnThumbnailDatabase::HandleAvailabilityChecked()"); |
|
474 __ASSERT_DEBUG(iClientStatus, Panic(EGlxPanicNotInitialised)); |
|
475 if ( iClientStatus ) |
|
476 { |
|
477 GLX_LOG_INFO1("HandleAvailabilityChecked+ aResult= %d [0-Av / 1-NotAv]", aResult); |
|
478 User::RequestComplete(iClientStatus, aResult); |
|
479 } |
|
480 } |
|
481 |
|
482 // ----------------------------------------------------------------------------- |
|
483 // HandleDatabaseCleanedL |
|
484 // ----------------------------------------------------------------------------- |
|
485 // |
|
486 void CGlxtnThumbnailDatabase::HandleDatabaseCleanedL() |
|
487 { |
|
488 TRACER("void CGlxtnThumbnailDatabase::HandleDatabaseCleanedL()"); |
|
489 |
|
490 // the following three lines of code make the assumption that (in the worst case) (atleast) |
|
491 // some databases are not present in the iDatabaseArray. This would then prevent those |
|
492 // from being cleaned, since only the databases contained in the iDatabaseArray will be cleaned. |
|
493 // this will in effect cause those databases to keep growing. |
|
494 |
|
495 // The OpenDatabaseL method also adds the database into iDatabaseArray if it |
|
496 // already was not part of it. Here we are using this behaviour of the method |
|
497 |
|
498 OpenDatabaseL(DriveInfo::EDefaultPhoneMemory); |
|
499 OpenDatabaseL(DriveInfo::EDefaultMassStorage); |
|
500 OpenDatabaseL(DriveInfo::EDefaultRemovableMassStorage); |
|
501 |
|
502 iDatabaseIndex++; |
|
503 if(iDatabaseIndex < iDatabaseArray.Count()) |
|
504 { |
|
505 // cleanup next database |
|
506 iDatabaseArray[iDatabaseIndex]->CleanupDatabaseL(); |
|
507 } |
|
508 else |
|
509 { |
|
510 // Finished cleanup |
|
511 __ASSERT_DEBUG(iClientStatus, Panic(EGlxPanicNotInitialised)); |
|
512 if ( iClientStatus ) |
|
513 { |
|
514 User::RequestComplete(iClientStatus, KErrNone); |
|
515 } |
|
516 } |
|
517 } |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // DoHandleThumbnailIdL |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 void CGlxtnThumbnailDatabase::DoHandleThumbnailIdL() |
|
524 { |
|
525 TRACER("void CGlxtnThumbnailDatabase::DoHandleThumbnailIdL()"); |
|
526 CGlxtnVolumeDatabase* db = OpenDatabaseL(iFileInfo->FilePath()); |
|
527 |
|
528 switch ( iCurrentOperation ) |
|
529 { |
|
530 case ELoading: |
|
531 db->GetThumbnailL(iThumbId, iSize); |
|
532 break; |
|
533 case ESaving: |
|
534 db->StoreItemsL(iThumbId, iFileInfo); |
|
535 db->StoreThumbnailL(iThumbId, iSize, iSaveFormat, iSaveData); |
|
536 break; |
|
537 case ECheckingAvailable: |
|
538 db->CheckAvailableL(iThumbId, iSize); |
|
539 break; |
|
540 default: |
|
541 Panic(EGlxPanicIllegalState); |
|
542 break; |
|
543 } |
|
544 } |
|
545 |
|
546 // ----------------------------------------------------------------------------- |
|
547 // OpenDatabaseL |
|
548 // ----------------------------------------------------------------------------- |
|
549 // |
|
550 CGlxtnVolumeDatabase* CGlxtnThumbnailDatabase::OpenDatabaseL(const TDesC& aDrive) |
|
551 { |
|
552 TRACER("CGlxtnVolumeDatabase* CGlxtnThumbnailDatabase::OpenDatabaseL(const TDesC& aDrive)"); |
|
553 TBuf<KMaxFSNameLength> drive; |
|
554 drive.Append(aDrive.Left(KMaxDriveName)); |
|
555 TDriveUnit driveNumber(aDrive); |
|
556 if (EDriveZ == driveNumber) |
|
557 { |
|
558 GLX_LOG_INFO("CGlxtnThumbnailDatabase::OpenDatabaseL EDriveZ == DriveNumber"); |
|
559 drive.FillZ(0); |
|
560 drive.Append(iInternalDrive); |
|
561 } |
|
562 |
|
563 TInt count = iDatabaseArray.Count(); |
|
564 for ( TInt i = 0; i < count; i++ ) |
|
565 { |
|
566 if ( 0 == drive.CompareF(iDatabaseArray[i]->Drive()) ) |
|
567 { |
|
568 return iDatabaseArray[i]; |
|
569 } |
|
570 } |
|
571 |
|
572 // Get path of DB on specified drive |
|
573 TFileName path(drive); |
|
574 path.Append(iDatabasePath); |
|
575 |
|
576 // If the media(removable drive) has changed or the mass storage has been reflashed, |
|
577 // then the existing thumbnail database (if any) needs to be regenerated as per the new images in the media. |
|
578 // else there might be a mismatch between the existing images and their thumbnails. this is achieved by the \ |
|
579 // following function |
|
580 DeleteDBIfStorageChangedL(path); |
|
581 |
|
582 CGlxtnVolumeDatabase* database = CGlxtnVolumeDatabase::NewLC(*this, iFs, path); |
|
583 GLX_LOG_INFO("New Volume database creation attempted. "); |
|
584 iDatabaseArray.AppendL(database); |
|
585 CleanupStack::Pop(database); |
|
586 |
|
587 // The thumbnail id is placed only in the IDs table of the thumbnail database in the internal phone memory, |
|
588 // irrespective of which drive the images or their databses are placed in. |
|
589 // And since the thumbnail id has to be unique across drives, the 'next' thumbnail Id to be used |
|
590 // is initialized by incrementing the thumbnail id in the internal drive by one. |
|
591 if (KErrNone == drive.CompareF(iInternalDrive)) |
|
592 { |
|
593 database->InitializeThumbIdL(); |
|
594 } |
|
595 return database; |
|
596 } |
|
597 // ----------------------------------------------------------------------------- |
|
598 // DeleteFile |
|
599 // |
|
600 // Common function for deletion of files. |
|
601 // This function removes any 'read only' protection that may be there on the file |
|
602 // ----------------------------------------------------------------------------- |
|
603 // |
|
604 void CGlxtnThumbnailDatabase::DeleteFile(const TDesC& aPath) |
|
605 { |
|
606 GLX_LOG_ENTRY_EXIT("void CGlxtnThumbnailDatabase::DeleteFile()"); |
|
607 |
|
608 if (BaflUtils::FileExists( iFs, aPath )) |
|
609 { |
|
610 GLX_LOG_INFO("void CGlxtnThumbnailDatabase::DeleteFile(): File Exists, Now check if it is read only"); |
|
611 |
|
612 TUint fileAttributes = KEntryAttNormal; |
|
613 iFs.Att(aPath, fileAttributes ) ; |
|
614 |
|
615 if ( fileAttributes & KEntryAttReadOnly ) |
|
616 { |
|
617 GLX_LOG_INFO("void CGlxtnThumbnailDatabase::DeleteFile(): File is Read-Only . Make it 'not Read-Only' "); |
|
618 iFs.SetAtt(aPath, 0 , KEntryAttReadOnly); |
|
619 } |
|
620 |
|
621 GLX_LOG_INFO("void CGlxtnThumbnailDatabase::DeleteFile(): File is (or is made) 'Not Read-Only'. Delete it"); |
|
622 iFs.Delete(aPath); |
|
623 |
|
624 GLX_LOG_INFO("void CGlxtnThumbnailDatabase::DeleteFile(): File Deleted"); |
|
625 } |
|
626 } |
|
627 |
|
628 |
|
629 // ----------------------------------------------------------------------------- |
|
630 // DeleteDBIfStorageChanged |
|
631 // |
|
632 // This case is useful if the device hard drive was reflashed after the last access. |
|
633 // or the Memory card has changed after last access to the Memorycard. |
|
634 // ----------------------------------------------------------------------------- |
|
635 // |
|
636 void CGlxtnThumbnailDatabase::DeleteDBIfStorageChangedL(TFileName aPath) |
|
637 { |
|
638 TRACER("CGlxtnThumbnailDatabase::DeleteDBIfStorageChangedL"); |
|
639 |
|
640 TUint driveStatus = 0 ; |
|
641 TPtrC drive(aPath.Left(KMaxDriveName)); |
|
642 TDriveUnit driveNumber(drive); |
|
643 TDriveUnit romDrive(EDriveZ); |
|
644 |
|
645 // this will make sure that we are not dealing with the intenral phone memory. |
|
646 if ((0 != drive.CompareF(PathInfo::PhoneMemoryRootPath().Left( KMaxDriveName ))) && |
|
647 (0 != drive.CompareF(romDrive.Name()))) |
|
648 { |
|
649 GLX_LOG_INFO("Not Phone Memory / ROM"); |
|
650 |
|
651 CRepository * pCenRep = CRepository::NewLC(TUid::Uid( KRepositoryId )); |
|
652 |
|
653 // that leaves the memory card and the hard drive |
|
654 User::LeaveIfError(DriveInfo::GetDriveStatus( iFs, driveNumber, driveStatus ) ); |
|
655 |
|
656 // take care of the removable drives now |
|
657 if (driveStatus & DriveInfo::EDriveRemovable) |
|
658 { |
|
659 GLX_LOG_INFO("CGlxtnThumbnailDatabase::DeleteDBIfStorageChangedL. DriveInfo::EDriveRemovable"); |
|
660 |
|
661 // get the serial number of the drive. |
|
662 TBuf8<KGlxmediaSerialIdLength> serialNumDriveBuf ; |
|
663 serialNumDriveBuf.FillZ(KGlxmediaSerialIdLength); |
|
664 iFs.GetMediaSerialNumber( serialNumDriveBuf, driveNumber ) ; |
|
665 |
|
666 // get the serial number from the Cen Rep. |
|
667 TBuf8<KGlxmediaSerialIdLength> serialNumCenRepBuf ; |
|
668 serialNumCenRepBuf.FillZ(KGlxmediaSerialIdLength); |
|
669 pCenRep->Get(KGlxTnSDCardVolumeId, serialNumCenRepBuf) ; |
|
670 |
|
671 if (serialNumCenRepBuf.Compare(serialNumDriveBuf)) |
|
672 { |
|
673 GLX_LOG_INFO("SerialNumCenRepBuf.Compare(serialNumDriveBuf) returned a difference between the drive ids"); |
|
674 |
|
675 User::LeaveIfError(pCenRep->Set(KGlxTnSDCardVolumeId, serialNumDriveBuf)) ; |
|
676 |
|
677 // delete the database so that later when we try to open the database a |
|
678 // new database is created. |
|
679 DeleteFile(aPath); |
|
680 GLX_LOG_INFO("CGlxtnThumbnailDatabase::DeleteDBIfStorageChangedL(): Deleted file"); |
|
681 } |
|
682 } |
|
683 else |
|
684 // a rough assumption here. if this is not an internal drive and if it is not a removable drive |
|
685 // then it must most probably be the hard drive. |
|
686 { |
|
687 GLX_LOG_INFO("CGlxtnThumbnailDatabase::DeleteDBIfStorageChangedL(): Mass Memory"); |
|
688 TInt freshlyFlashed = 0 ; |
|
689 pCenRep->Get(KGlxTnHardDriveFlashState , freshlyFlashed) ; |
|
690 |
|
691 // The default value set in a freshly flased drive for this key ID is 0. |
|
692 // (theorotically anything other than int(1) can be used as a |
|
693 // value for the cenrep key ID KGlxTnHardDriveFlashState.) |
|
694 if ( KGlxTnMassStorageNotFreshlyFlashed != freshlyFlashed ) |
|
695 { |
|
696 User::LeaveIfError(pCenRep->Set(KGlxTnHardDriveFlashState , TInt(KGlxTnMassStorageNotFreshlyFlashed)) ); |
|
697 |
|
698 // delete the database so that later when we try to open the database a |
|
699 // new database is created. |
|
700 DeleteFile(aPath); |
|
701 GLX_LOG_INFO("CGlxtnThumbnailDatabase::DeleteDBIfStorageChangedL(): Deleted File"); |
|
702 } |
|
703 } |
|
704 CleanupStack::PopAndDestroy(pCenRep); |
|
705 } |
|
706 } |
|
707 |
|
708 // OpenDatabaseL |
|
709 // ----------------------------------------------------------------------------- |
|
710 // |
|
711 CGlxtnVolumeDatabase* CGlxtnThumbnailDatabase::OpenDatabaseL(const DriveInfo::TDefaultDrives& aDrive) |
|
712 { |
|
713 TRACER("void CGlxtnThumbnailDatabase::OpenDatabaseL(const DriveInfo::TDefaultDrives& aDrive)"); |
|
714 GLX_LOG_ENTRY_EXIT("void CGlxtnThumbnailDatabase::OpenDatabaseL(const DriveInfo::TDefaultDrives& aDrive)"); |
|
715 |
|
716 TBuf<KLoggingDriveLetterLength> drivePath; |
|
717 if ( KErrNone == DriveName(aDrive , drivePath)) |
|
718 { |
|
719 return OpenDatabaseL(drivePath) ; |
|
720 } |
|
721 else |
|
722 { |
|
723 return NULL; |
|
724 } |
|
725 } |
|
726 // ----------------------------------------------------------------------------- |
|
727 // DriveName |
|
728 // ----------------------------------------------------------------------------- |
|
729 // |
|
730 TInt CGlxtnThumbnailDatabase::DriveName(const TInt& aDefaultDrive, TDes& aDriveName) |
|
731 { |
|
732 TRACER("void CGlxtnThumbnailDatabase::DriveName()"); |
|
733 GLX_LOG_ENTRY_EXIT("void CGlxtnThumbnailDatabase::DriveName()"); |
|
734 GLX_LOG_INFO1("DriveName aDefaultDrive = %d", aDefaultDrive); |
|
735 TChar driveLetter; |
|
736 TInt error = DriveInfo::GetDefaultDrive(aDefaultDrive, driveLetter); |
|
737 |
|
738 if ( KErrNotSupported != error ) |
|
739 { |
|
740 TUint driveStatus = 0 ; |
|
741 TDriveUnit driveNumber(aDefaultDrive); |
|
742 error = DriveInfo::GetDriveStatus( iFs, driveNumber, driveStatus ); |
|
743 GLX_LOG_INFO1("GetDriveStatus returns = %d", error); |
|
744 if (error == KErrNone && ( driveStatus & DriveInfo::EDrivePresent )) |
|
745 { |
|
746 aDriveName.Format(KDriveNameFormat, TUint(driveLetter)); |
|
747 GLX_LOG_INFO1("aDriveName=%S", &aDriveName); |
|
748 } |
|
749 else |
|
750 { |
|
751 error = KErrNotReady; |
|
752 } |
|
753 } |
|
754 GLX_LOG_INFO1("DriveName returns = %d", error); |
|
755 return error; |
|
756 } |
|
757 // End of File |