|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Store for thumbnails. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef THUMBNAILSTORE_H |
|
20 #define THUMBNAILSTORE_H |
|
21 |
|
22 #include <sqldb.h> |
|
23 #include "thumbnailcenrep.h" |
|
24 #include "thumbnailmanagerconstants.h" |
|
25 #include "thumbnaillog.h" |
|
26 #include "thumbnailserver.h" |
|
27 |
|
28 class RFs; |
|
29 class CFbsBitmap; |
|
30 class CThumbnailServer; |
|
31 |
|
32 /** |
|
33 * Database transaction |
|
34 * |
|
35 * @since S60 v5.0 |
|
36 */ |
|
37 class RThumbnailTransaction |
|
38 { |
|
39 enum TState |
|
40 { |
|
41 EOpen, EError, EClosed |
|
42 }; |
|
43 public: |
|
44 RThumbnailTransaction( RSqlDatabase& aDatabase ); |
|
45 |
|
46 void BeginL(); |
|
47 void Close(); |
|
48 void CommitL(); |
|
49 TInt Rollback(); |
|
50 |
|
51 private: |
|
52 RSqlDatabase& iDatabase; |
|
53 TState iState; |
|
54 }; |
|
55 |
|
56 |
|
57 /** |
|
58 * Store for thumbnails. |
|
59 * |
|
60 * @since S60 v5.0 |
|
61 */ |
|
62 class CThumbnailStore: public CBase |
|
63 { |
|
64 // Bitmasked Flags |
|
65 typedef enum |
|
66 { |
|
67 KThumbnailDbFlagCropped = 1, |
|
68 KThumbnailDbFlagBlacklisted = 2, |
|
69 KThumbnailDbFlagDeleted = 4 |
|
70 }TThumbnailDbFlags; |
|
71 |
|
72 public: |
|
73 |
|
74 /** |
|
75 * Two-phased constructor. |
|
76 * |
|
77 * @since S60 v5.0 |
|
78 * @param aFs File server. |
|
79 * @param aDrive Drive the store used for |
|
80 * @param aCenter Pointer to cenrep data handler |
|
81 * @return New CThumbnailStore instance. |
|
82 */ |
|
83 static CThumbnailStore* NewL( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer ); |
|
84 |
|
85 /** |
|
86 * Destructor |
|
87 * |
|
88 * @since S60 v5.0 |
|
89 */ |
|
90 virtual ~CThumbnailStore(); |
|
91 |
|
92 /** |
|
93 * Stores thumbnail image. |
|
94 * |
|
95 * @since S60 v5.0 |
|
96 * @param aPath Path of the image from which thumbnail was created. |
|
97 * @param aThumbnail Thumbnail bitmap. |
|
98 * @param aOriginalSize Original size of image. |
|
99 * @param aCropped Enabled if image is cropped. |
|
100 * @param aThumbnailSize Prededined size of requested thumbnail. |
|
101 * @param aThumbFromPath Thumbnail created from associated path. |
|
102 */ |
|
103 void StoreThumbnailL( const TDesC& aPath, CFbsBitmap* aThumbnail, const |
|
104 TSize& aOriginalSize, TBool aCropped, const TThumbnailSize aThumbnailSize, |
|
105 const TThumbnailId aThumbnailId = 0, const TBool aThumbFromPath = ETrue, |
|
106 TBool aBlackListed = EFalse ); |
|
107 |
|
108 /** |
|
109 * Fetches thumbnail image. |
|
110 * |
|
111 * @since S60 v5.0 |
|
112 * @param aPath Path of the media object whose thumbnail is |
|
113 * to be retrieved. |
|
114 * @param aThumbnail Pointer to get the fetched thumbnail bitmap. |
|
115 * Caller assumes ownership. |
|
116 * @param aData Pointer to get the fetched thumbnail JPEG. |
|
117 * Caller assumes ownership. |
|
118 |
|
119 * @param aAllowUpscaling If enabled, allow fetching thumbnails that |
|
120 * are smaller than requested. |
|
121 * @param aThumbnailSize Prededined size of requested thumbnail. |
|
122 * |
|
123 * @param aThumbnailSize Reference to real size of TN. |
|
124 */ |
|
125 void FetchThumbnailL( const TDesC& aPath, |
|
126 CFbsBitmap* & aThumbnail, |
|
127 TDesC8* & aData, |
|
128 const TThumbnailSize aThumbnailSize, |
|
129 TSize &aThumbnailRealSize |
|
130 ); |
|
131 |
|
132 /** |
|
133 * Fetches thumbnail image. |
|
134 * |
|
135 * @since S60 v5.0 |
|
136 * @param aThumbnailId Path of the media object whose thumbnail is |
|
137 * to be retrieved. |
|
138 * @param aThumbnail Pointer to get the fetched thumbnail bitmap. |
|
139 * Caller assumes ownership. |
|
140 * @param aData Pointer to get the fetched thumbnail JPEG. |
|
141 * Caller assumes ownership. |
|
142 * @param aThumbnailSize Minimum size of the thumbnail |
|
143 * . |
|
144 * @param aThumbnailSize Reference to real size of TN. |
|
145 * |
|
146 * @return KErrNone, otherwise KErrNotFound if thumbnail not found from DB |
|
147 */ |
|
148 TInt FetchThumbnailL( TThumbnailId aThumbnailId, |
|
149 CFbsBitmap*& aThumbnail, |
|
150 TDesC8* & aData, |
|
151 TThumbnailSize aThumbnailSize, |
|
152 TSize &aThumbnailRealSize |
|
153 ); |
|
154 |
|
155 |
|
156 /** |
|
157 * Delete thumbnails. |
|
158 * |
|
159 * @since S60 v5.0 |
|
160 * @param aPath Path of the media object whose thumbnail is |
|
161 * to be deleted. |
|
162 */ |
|
163 void DeleteThumbnailsL( const TDesC& aPath ); |
|
164 |
|
165 /** |
|
166 * Delete thumbnails. |
|
167 * |
|
168 * @since S60 TB9.1 |
|
169 * @param aTNId Id of the media object whose thumbnail is |
|
170 * to be deleted. |
|
171 */ |
|
172 void DeleteThumbnailsL( const TThumbnailId& aTNId ); |
|
173 |
|
174 /** |
|
175 * Persistent sizes. |
|
176 * |
|
177 * @since S60 v5.0 |
|
178 * @return List of thumbnail sizes (including othe parameters) which |
|
179 * are stored for later access. |
|
180 */ |
|
181 void SetPersistentSizes(const RArray < TThumbnailPersistentSize > &aSizes); |
|
182 |
|
183 /** |
|
184 * Get persistent sizes not yet in database |
|
185 * |
|
186 * @since S60 v5.0 |
|
187 * @param aPath Path where missing sizes are associated |
|
188 * @param aMissingSizes List of missing thumbnail sizes |
|
189 */ |
|
190 void GetMissingSizesAndIDsL( const TDesC& aPath, TInt aSourceType, RArray < |
|
191 TThumbnailPersistentSize > & aMissingSizes, TBool& aMissingIDs ); |
|
192 |
|
193 /** |
|
194 * Get persistent sizes not yet in database |
|
195 * |
|
196 * @since S60 TB9.1 |
|
197 * @param aId Id of TN where missing sizes are associated |
|
198 * @param aMissingSizes List of missing thumbnail sizes |
|
199 */ |
|
200 void GetMissingSizesL( const TThumbnailId aId, RArray < |
|
201 TThumbnailPersistentSize > & aMissingSizes ); |
|
202 |
|
203 /** |
|
204 * Find store for thumbnails. |
|
205 * |
|
206 * @since S60 TB9.1 |
|
207 * @param aThumbnailId Id of thumbnails to be updated. |
|
208 */ |
|
209 void FindStoreL(TThumbnailId aThumbnailId); |
|
210 |
|
211 /** |
|
212 * Updates path for thumbnails in current store. |
|
213 * |
|
214 * @since S60 v5.0 |
|
215 * @param aItemId Id for thumbnails to be updated. |
|
216 * @param aNewPath New path for thumbnails. |
|
217 * @return ETrue, if path was updated |
|
218 */ |
|
219 TBool UpdateStoreL( TThumbnailId aItemId, const TDesC& aNewPath ); |
|
220 |
|
221 /** |
|
222 * Updates path for thumbnails in current store. |
|
223 * |
|
224 * @since S60 v5.0 |
|
225 * @param aItemId Id for thumbnails to be updated. |
|
226 * @param aNewPath New path for thumbnails. |
|
227 */ |
|
228 void UpdateStoreL( const TDesC& aPath, TThumbnailId aNewId ); |
|
229 |
|
230 /** |
|
231 * Check modification timestamp |
|
232 * |
|
233 * @since S60 v5.0 |
|
234 * @param aItemId Id for thumbnails to be updated. |
|
235 * @param aModified new MDS timestamp |
|
236 * @return ETrue, if given timestamp was newer than in DB |
|
237 */ |
|
238 TBool CheckModifiedL( const TThumbnailId aItemId, const TInt64 aModified ); |
|
239 |
|
240 /** |
|
241 * Fetches thumbnails from store to be moved. |
|
242 * |
|
243 * @since S60 v5.0 |
|
244 * @param aItemId Id for thumbnails to be updated. |
|
245 * @param aThumbnails Array for thumbnails to be moved. |
|
246 */ |
|
247 void FetchThumbnailsL(TThumbnailId aItemId, RArray < TThumbnailDatabaseData* >& aThumbnails); |
|
248 |
|
249 /** |
|
250 * Stores thumbnails in to new store. |
|
251 * |
|
252 * @since S60 v5.0 |
|
253 * @param aNewPath New path for thumbnails. |
|
254 * @param aThumbnails Array for thumbnails to be moved. |
|
255 */ |
|
256 void StoreThumbnailsL(const TDesC& aNewPath, RArray < TThumbnailDatabaseData* >& aThumbnails); |
|
257 |
|
258 /** |
|
259 * Stores thumbnails in to new store. |
|
260 * |
|
261 * @since S60 v5.0 |
|
262 * @param aNewPath New path for thumbnails. |
|
263 * @param aThumbnails Array for thumbnails to be moved. |
|
264 */ |
|
265 TInt CheckImeiL(); |
|
266 |
|
267 /** |
|
268 * Stores thumbnails in to new store. |
|
269 * |
|
270 * @since S60 v5.0 |
|
271 * @param aNewPath New path for thumbnails. |
|
272 * @param aThumbnails Array for thumbnails to be moved. |
|
273 */ |
|
274 TInt CheckVersionL(); |
|
275 |
|
276 /** |
|
277 * Stores thumbnails in to new store. |
|
278 * |
|
279 * @since S60 v5.0 |
|
280 * @param aNewPath New path for thumbnails. |
|
281 * @param aThumbnails Array for thumbnails to be moved. |
|
282 */ |
|
283 TInt CheckMediaIDL(); |
|
284 |
|
285 /** |
|
286 * Stores thumbnails in to new store. |
|
287 * |
|
288 * @since S60 v5.0 |
|
289 * @param aNewPath New path for thumbnails. |
|
290 * @param aThumbnails Array for thumbnails to be moved. |
|
291 */ |
|
292 void AddVersionAndImeiL(); |
|
293 |
|
294 /** |
|
295 * Stores thumbnails in to new store. |
|
296 * |
|
297 * @since S60 v5.0 |
|
298 * @param aNewPath New path for thumbnails. |
|
299 * @param aThumbnails Array for thumbnails to be moved. |
|
300 */ |
|
301 void ResetThumbnailIDs(); |
|
302 |
|
303 /** |
|
304 * Stores thumbnails in to new store. |
|
305 * |
|
306 * @since S60 v5.0 |
|
307 * @param aNewPath New path for thumbnails. |
|
308 * @param aThumbnails Array for thumbnails to be moved. |
|
309 */ |
|
310 void UpdateImeiL(); |
|
311 |
|
312 /** |
|
313 * Checks that database rowids match. |
|
314 * |
|
315 * @since S60 v5.0 |
|
316 */ |
|
317 |
|
318 TInt CheckRowIDsL(); |
|
319 |
|
320 private: |
|
321 /** |
|
322 * C++ default constructor |
|
323 * |
|
324 * @since S60 v5.0 |
|
325 * @param aFs File server. |
|
326 * @param aDrive Drive the store used for |
|
327 * @return New CThumbnailStore instance. |
|
328 */ |
|
329 CThumbnailStore( RFs& aFs, TInt aDrive, TDesC& aImei, CThumbnailServer* aServer); |
|
330 |
|
331 /** |
|
332 * Symbian 2nd phase constructor can leave. |
|
333 * |
|
334 * @since S60 v5.0 |
|
335 */ |
|
336 void ConstructL(); |
|
337 |
|
338 /** |
|
339 * Create database tables. |
|
340 * |
|
341 * @since S60 v5.0 |
|
342 */ |
|
343 void CreateTablesL(); |
|
344 |
|
345 /** |
|
346 * Stores thumbnail image. |
|
347 * |
|
348 * @since S60 v5.0 |
|
349 * @param aPath Path of the image from which thumbnail was created. |
|
350 * @param aData Data. |
|
351 * @param aSize Size of thumbnail. |
|
352 * @param aOriginalSize Original size of image. |
|
353 * @param aFormat Format of the image. |
|
354 * @param aFlags Flags. |
|
355 * @param aThumbnailSize Associated size of the thumbnail to be deleted |
|
356 * @param aThumbFromPath Thumbnail created from associated path. |
|
357 */ |
|
358 void StoreThumbnailL( const TDesC& aPath, const TDes8& aData, const TSize& |
|
359 aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, |
|
360 const TThumbnailSize& aThumbnailSize, const TThumbnailId aThumbnailId = 0, |
|
361 const TBool aThumbFromPath = ETrue); |
|
362 |
|
363 /** |
|
364 * Finds possible existing duplicate thumbnail. |
|
365 * |
|
366 * @since S60 v5.0 |
|
367 * @param aPath Path of the image from which thumbnail was created. |
|
368 * @param aThumbnailId ID of the thumbnail |
|
369 * @param aThumbnailSize Associated size of the thumbnail to be deleted |
|
370 */ |
|
371 TBool FindDuplicateL( const TDesC& aPath, const TThumbnailId aThumbnailId, |
|
372 const TThumbnailSize& aThumbnailSize ); |
|
373 |
|
374 /** |
|
375 * Flush RAM cache containing generated TNs to persistent storage. |
|
376 * |
|
377 * @since S60 TB9.1 |
|
378 * @param aForce which forces logic to flush cache table. |
|
379 */ |
|
380 void FlushCacheTable( TBool aForce = EFalse ); |
|
381 |
|
382 /** |
|
383 * Start db auto flush timer |
|
384 * |
|
385 * @since S60 TB9.1 |
|
386 */ |
|
387 void StartAutoFlush(); |
|
388 |
|
389 /** |
|
390 * Stop db auto flush timer |
|
391 * |
|
392 * @since S60 TB9.1 |
|
393 */ |
|
394 void StopAutoFlush(); |
|
395 |
|
396 /** |
|
397 * Callback for harvesting complete timer |
|
398 * |
|
399 * @since S60 v5.0 |
|
400 */ |
|
401 static TInt AutoFlushTimerCallBack(TAny* aAny); |
|
402 |
|
403 /** |
|
404 * Checks timestamp of blacklisted entry to timestamp of file, from |
|
405 * which thumbnail entry was created, in filesystem |
|
406 * |
|
407 * @param aPath Path from which thumbnail created |
|
408 * @param aTempTable Indication whether data in temp table |
|
409 * @param aModified On return contains indication whether file modified |
|
410 */ |
|
411 void CheckModifiedByPathL( const TDesC& aPath, TBool aTempTable, TBool& aModified ); |
|
412 |
|
413 /** |
|
414 * Checks timestamp of blacklisted entry to timestamp of file, from |
|
415 * which thumbnail entry was created, in filesystem |
|
416 * |
|
417 * @param aId Thumbnail id |
|
418 * @param aTempTable Indication whether data in temp table |
|
419 * @param aModified On return contains indication whether file modified |
|
420 */ |
|
421 void CheckModifiedByIdL( TUint32 aId, TBool aTempTable, TBool& aModified ); |
|
422 |
|
423 /** |
|
424 * Removes blacklisted flag from all entrys |
|
425 * |
|
426 */ |
|
427 void RemoveDbFlagL(TThumbnailDbFlags aFlag); |
|
428 |
|
429 private: |
|
430 // data |
|
431 |
|
432 /** |
|
433 * Fileserver. |
|
434 */ |
|
435 RFs& iFs; |
|
436 |
|
437 /** |
|
438 * Drive number |
|
439 */ |
|
440 TInt iDrive; |
|
441 |
|
442 /** |
|
443 * Thumbnail database. |
|
444 */ |
|
445 RSqlDatabase iDatabase; |
|
446 |
|
447 /** |
|
448 * Persistent sizes. |
|
449 */ |
|
450 RArray < TThumbnailPersistentSize > iPersistentSizes; |
|
451 |
|
452 /** |
|
453 * Count of cached TNs not yet committed to db |
|
454 */ |
|
455 TInt iBatchItemCount; |
|
456 |
|
457 /** |
|
458 * Phones IMEI code |
|
459 */ |
|
460 TDesC& iImei; |
|
461 |
|
462 /** |
|
463 * ThumbnailServer |
|
464 */ |
|
465 |
|
466 CThumbnailServer* iServer; |
|
467 |
|
468 #ifdef _DEBUG |
|
469 TUint32 iThumbCounter; |
|
470 #endif |
|
471 /** |
|
472 * Periodic timer handling automatic flushing of db cache |
|
473 */ |
|
474 CPeriodic* iAutoFlushTimer; |
|
475 }; |
|
476 |
|
477 #endif // THUMBNAILSTORE_H |