imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailstore.h
changeset 14 2edacbf5d3f9
parent 1 235a7fc86938
child 15 7197e789b953
equal deleted inserted replaced
1:235a7fc86938 14:2edacbf5d3f9
    23 #include <e32base.h>
    23 #include <e32base.h>
    24 #include <f32file.h>
    24 #include <f32file.h>
    25 #include "thumbnailcenrep.h"
    25 #include "thumbnailcenrep.h"
    26 #include "thumbnailmanagerconstants.h"
    26 #include "thumbnailmanagerconstants.h"
    27 #include "thumbnaillog.h"
    27 #include "thumbnaillog.h"
    28 #include "thumbnailserver.h"
    28 #include "tmactivitymanager.h"
    29 
    29 
    30 class RFs;
    30 class RFs;
    31 class CFbsBitmap;
    31 class CFbsBitmap;
    32 class CThumbnailServer;
    32 class CThumbnailServer;
    33 
    33 
    55     TState iState;
    55     TState iState;
    56 };
    56 };
    57 
    57 
    58 
    58 
    59 /**
    59 /**
    60 * MMdSDiskSpaceNotifierObserver
    60 * MThumbnailStoreDiskSpaceNotifierObserver
    61 * Observer interface for a disk space notifier.
    61 * Observer interface for a disk space notifier.
    62 */
    62 */
    63 class MThumbnailStoreDiskSpaceNotifierObserver
    63 class MThumbnailStoreDiskSpaceNotifierObserver
    64     {
    64     {
    65     public :
    65     public :
    78         virtual void HandleDiskSpaceError(TInt aError) = 0;
    78         virtual void HandleDiskSpaceError(TInt aError) = 0;
    79 
    79 
    80     };
    80     };
    81 
    81 
    82 /**
    82 /**
    83 * CMSDiskSpaceNotifierAO.
    83 * CThumbnailStoreDiskSpaceNotifierAO.
    84 * A disk space notifier class
    84 * A disk space notifier class
    85 */
    85 */
    86 class CThumbnailStoreDiskSpaceNotifierAO : public CActive
    86 class CThumbnailStoreDiskSpaceNotifierAO : public CActive
    87     {
    87     {
    88     public:
    88     public:
   185 /**
   185 /**
   186  *  Store for thumbnails.
   186  *  Store for thumbnails.
   187  *
   187  *
   188  *  @since S60 v5.0
   188  *  @since S60 v5.0
   189  */
   189  */
   190 class CThumbnailStore: public CBase, public MThumbnailStoreDiskSpaceNotifierObserver
   190 class CThumbnailStore: public CBase, 
       
   191                        public MThumbnailStoreDiskSpaceNotifierObserver,
       
   192                        public MTMActivityManagerObserver
   191     {
   193     {
   192     // Bitmasked Flags
   194     // Bitmasked Flags
   193     typedef enum 
   195     typedef enum 
   194     {
   196     {
   195     KThumbnailDbFlagCropped = 1,
   197     KThumbnailDbFlagCropped = 1,
   227      * @param aCropped Enabled if image is cropped.
   229      * @param aCropped Enabled if image is cropped.
   228      * @param aThumbnailSize Prededined size of requested thumbnail.
   230      * @param aThumbnailSize Prededined size of requested thumbnail.
   229      * @param aThumbFromPath Thumbnail created from associated path.
   231      * @param aThumbFromPath Thumbnail created from associated path.
   230      */
   232      */
   231     void StoreThumbnailL( const TDesC& aPath, CFbsBitmap* aThumbnail, const
   233     void StoreThumbnailL( const TDesC& aPath, CFbsBitmap* aThumbnail, const
   232         TSize& aOriginalSize, TBool aCropped, const TThumbnailSize aThumbnailSize,
   234         TSize& aOriginalSize, TBool aCropped, const TThumbnailSize aThumbnailSize, 
   233         const TThumbnailId aThumbnailId = 0, const TBool aThumbFromPath = ETrue,
   235         const TInt64 aModified,
       
   236         const TBool aThumbFromPath = ETrue,
   234         TBool aBlackListed = EFalse );
   237         TBool aBlackListed = EFalse );
   235 
   238 
   236     /**
   239     /**
   237      * Fetches thumbnail image.
   240      * Fetches thumbnail image.
   238      *
   241      *
   256             const TThumbnailSize aThumbnailSize,
   259             const TThumbnailSize aThumbnailSize,
   257             TSize &aThumbnailRealSize 
   260             TSize &aThumbnailRealSize 
   258             );
   261             );
   259     
   262     
   260     /**
   263     /**
   261      * Fetches thumbnail image.
       
   262      *
       
   263      * @since S60 v5.0
       
   264      * @param aThumbnailId           Path of the media object whose thumbnail is
       
   265      *                        to be retrieved.
       
   266      * @param aThumbnail      Pointer to get the fetched thumbnail bitmap.
       
   267      *                        Caller assumes ownership.
       
   268      * @param aData           Pointer to get the fetched thumbnail JPEG.
       
   269      *                        Caller assumes ownership.                      
       
   270      * @param aThumbnailSize    Minimum size of the thumbnail
       
   271      * .
       
   272      * @param aThumbnailSize    Reference to real size of TN.
       
   273      * 
       
   274      * @return KErrNone, otherwise KErrNotFound if thumbnail not found from DB
       
   275      */    
       
   276     TInt FetchThumbnailL( TThumbnailId aThumbnailId, 
       
   277             CFbsBitmap*& aThumbnail, 
       
   278             TDesC8* & aData, 
       
   279             TThumbnailSize aThumbnailSize, 
       
   280             TSize &aThumbnailRealSize 
       
   281             );
       
   282     
       
   283 
       
   284     /**
       
   285      * Delete thumbnails.
   264      * Delete thumbnails.
   286      *
   265      *
   287      * @since S60 v5.0
   266      * @since S60 v5.0
   288      * @param aPath           Path of the media object whose thumbnail is
   267      * @param aPath           Path of the media object whose thumbnail is
   289      *                        to be deleted.
   268      *                        to be deleted.
   290      */
   269      * @param aForce          Force to delete instantly 
   291     void DeleteThumbnailsL( const TDesC& aPath );
   270      * @param aTransaction    Create a transaction 
   292     
   271      */
   293     /**
   272     void DeleteThumbnailsL( const TDesC& aPath, TBool aForce = EFalse,
   294       * Delete thumbnails.
   273                             TBool aTransaction = ETrue);
   295       *
   274     
   296       * @since S60 TB9.1
       
   297       * @param aTNId           Id of the media object whose thumbnail is
       
   298       *                        to be deleted.
       
   299       */
       
   300      void DeleteThumbnailsL( const TThumbnailId& aTNId );
       
   301 
       
   302     /**
   275     /**
   303      * Persistent sizes.
   276      * Persistent sizes.
   304      *
   277      *
   305      * @since S60 v5.0
   278      * @since S60 v5.0
   306      * @return List of thumbnail sizes (including othe parameters) which
   279      * @return List of thumbnail sizes (including othe parameters) which
   312      * Get persistent sizes not yet in database
   285      * Get persistent sizes not yet in database
   313      *
   286      *
   314      * @since S60 v5.0
   287      * @since S60 v5.0
   315      * @param aPath Path where missing sizes are associated
   288      * @param aPath Path where missing sizes are associated
   316      * @param aMissingSizes List of missing thumbnail sizes
   289      * @param aMissingSizes List of missing thumbnail sizes
   317      */
   290      * @param aCheckGridSizeOnly check only is grid size missing
   318     void GetMissingSizesAndIDsL( const TDesC& aPath, TInt aSourceType, RArray <
   291      */
   319             TThumbnailPersistentSize > & aMissingSizes, TBool& aMissingIDs );
   292     void GetMissingSizesL( const TDesC& aPath, TInt aSourceType, RArray <
   320     
   293             TThumbnailPersistentSize > & aMissingSizes, TBool aCheckGridSizeOnly  );
   321     /**
   294         
   322        * Get persistent sizes not yet in database
   295     /**
   323        *
   296      * Check IMEI (owner) of db
   324        * @since S60 TB9.1
   297      *
   325        * @param aId Id of TN where missing sizes are associated
   298      * @since S60 v5.0
   326        * @param aMissingSizes List of missing thumbnail sizes
       
   327        */
       
   328       void GetMissingSizesL( const TThumbnailId aId, RArray <
       
   329           TThumbnailPersistentSize > & aMissingSizes );
       
   330  
       
   331     /**
       
   332      * Find store for thumbnails.
       
   333      *
       
   334      * @since S60 TB9.1
       
   335      * @param aThumbnailId Id of thumbnails to be updated.
       
   336      */
       
   337     void FindStoreL(TThumbnailId aThumbnailId);
       
   338     
       
   339     /**
       
   340      * Updates path for thumbnails in current store.
       
   341      *
       
   342      * @since S60 v5.0
       
   343      * @param aItemId Id for thumbnails to be updated.
       
   344      * @param aNewPath New path for thumbnails.
       
   345      * @return ETrue, if path was updated
       
   346      */     
       
   347     TBool UpdateStoreL( TThumbnailId aItemId, const TDesC& aNewPath );
       
   348     
       
   349     /**
       
   350      * Updates path for thumbnails in current store.
       
   351      *
       
   352      * @since S60 v5.0
       
   353      * @param aItemId Id for thumbnails to be updated.
       
   354      * @param aNewPath New path for thumbnails.
       
   355      */  
       
   356     void UpdateStoreL( const TDesC& aPath, TThumbnailId aNewId );
       
   357     
       
   358     /**
       
   359      * Check modification timestamp
       
   360      *
       
   361      * @since S60 v5.0
       
   362      * @param aItemId Id for thumbnails to be updated.
       
   363      * @param aModified new MDS timestamp
       
   364      * @return ETrue, if given timestamp was newer than in DB
       
   365      */     
       
   366     TBool CheckModifiedL( const TThumbnailId aItemId, const TInt64 aModified );    
       
   367     
       
   368     /**
       
   369      * Fetches thumbnails from store to be moved.
       
   370      *
       
   371      * @since S60 v5.0
       
   372      * @param aItemId Id for thumbnails to be updated.
       
   373      * @param aThumbnails Array for thumbnails to be moved.
       
   374      */  
       
   375     void FetchThumbnailsL(TThumbnailId aItemId, RArray < TThumbnailDatabaseData* >& aThumbnails);
       
   376     
       
   377     /**
       
   378      * Stores thumbnails in to new store.
       
   379      *
       
   380      * @since S60 v5.0
       
   381      * @param aNewPath New path for thumbnails.
       
   382      * @param aThumbnails Array for thumbnails to be moved.
       
   383      */  
       
   384     void StoreThumbnailsL(const TDesC& aNewPath, RArray < TThumbnailDatabaseData* >& aThumbnails);
       
   385     
       
   386     /**
       
   387      * Stores thumbnails in to new store.
       
   388      *
       
   389      * @since S60 v5.0
       
   390      * @param aNewPath New path for thumbnails.
       
   391      * @param aThumbnails Array for thumbnails to be moved.
       
   392      */  
   299      */  
   393     TInt CheckImeiL();
   300     TInt CheckImeiL();
   394     
   301     
   395     /**
   302     /**
   396      * Stores thumbnails in to new store.
   303      * Check version of db
   397      *
   304      *
   398      * @since S60 v5.0
   305      * @since S60 v5.0
   399      * @param aNewPath New path for thumbnails.
       
   400      * @param aThumbnails Array for thumbnails to be moved.
       
   401      */  
   306      */  
   402     TInt CheckVersionL();
   307     TInt CheckVersionL();
   403     
   308     
   404     /**
   309     /**
   405      * Stores thumbnails in to new store.
   310      * Check mediaid of store
   406      *
   311      *
   407      * @since S60 v5.0
   312      * @since S60 v5.0
   408      * @param aNewPath New path for thumbnails.
       
   409      * @param aThumbnails Array for thumbnails to be moved.
       
   410      */  
   313      */  
   411     TInt CheckMediaIDL();
   314     TInt CheckMediaIDL();
   412     
   315     
   413     /**
   316     /**
   414      * Stores thumbnails in to new store.
   317      * Add version and IMEI to db
   415      *
   318      *
   416      * @since S60 v5.0
   319      * @since S60 v5.0
   417      * @param aNewPath New path for thumbnails.
       
   418      * @param aThumbnails Array for thumbnails to be moved.
       
   419      */  
   320      */  
   420     void AddVersionAndImeiL();
   321     void AddVersionAndImeiL();
   421     
   322     
   422     /**
   323     /**
   423      * Stores thumbnails in to new store.
   324      * Reset TNID column
   424      *
   325      *
   425      * @since S60 v5.0
   326      * @since S60 v5.0
   426      * @param aNewPath New path for thumbnails.
       
   427      * @param aThumbnails Array for thumbnails to be moved.
       
   428      */  
   327      */  
   429     void ResetThumbnailIDs();
   328     TInt ResetThumbnailIDs();
   430     
   329     
   431     /**
   330     /**
   432      * Stores thumbnails in to new store.
   331      * Update IMEI to db
   433      *
   332      *
   434      * @since S60 v5.0
   333      * @since S60 v5.0
   435      * @param aNewPath New path for thumbnails.
   334      */
   436      * @param aThumbnails Array for thumbnails to be moved.
   335     TInt UpdateImeiL();
   437      */
       
   438     void UpdateImeiL();
       
   439     
   336     
   440     /**
   337     /**
   441      * Checks that database rowids match.
   338      * Checks that database rowids match.
   442      *
   339      *
   443      * @since S60 v5.0
   340      * @since S60 v5.0
   444      */
   341      */
   445     
   342     
   446     TInt CheckRowIDsL();
   343     TInt CheckRowIDsL();
   447     
   344     
       
   345     /**
       
   346      * Check is disk full
       
   347      *
       
   348      * @since S60 v5.0
       
   349      */
   448     TBool IsDiskFull();
   350     TBool IsDiskFull();
       
   351     
       
   352     /**
       
   353      * Checks timestamp of blacklisted entry to timestamp of file, from
       
   354      * which thumbnail entry was created, in filesystem
       
   355      *
       
   356      * @param aPath Path from which thumbnail created
       
   357      * @param aModified current timestampt
       
   358      * @contains indication whether file modified
       
   359      */
       
   360     TBool CheckModifiedByPathL( const TDesC& aPath, const TInt64 aModified, TBool& modifiedChanged);
   449 
   361 
   450 private:
   362 private:
   451     /**
   363     /**
   452      * C++ default constructor
   364      * C++ default constructor
   453      *
   365      *
   462      * Symbian 2nd phase constructor can leave.
   374      * Symbian 2nd phase constructor can leave.
   463      *
   375      *
   464      * @since S60 v5.0
   376      * @since S60 v5.0
   465      */
   377      */
   466     void ConstructL();
   378     void ConstructL();
   467 
   379     
   468     /**
   380     /**
   469      * Create database tables.
   381      * Starts constructing database
       
   382      *
       
   383      * @since S60 v5.0
       
   384      */
       
   385     void PrepareDbL();
       
   386     
       
   387     /**
       
   388      * Open database
       
   389      *
       
   390      * @since S60 v5.0
       
   391      */
       
   392     TInt OpenDatabaseL();
       
   393     
       
   394     /**
       
   395      * Open database
       
   396      *
       
   397      * @since S60 v5.0
       
   398      */
       
   399     TInt OpenDatabaseFileL();
       
   400 
       
   401     /**
       
   402      * Construct database tables
   470      *
   403      *
   471      * @since S60 v5.0
   404      * @since S60 v5.0
   472      */
   405      */
   473     void CreateTablesL();
   406     void CreateTablesL();
       
   407     
       
   408     /**
       
   409      * Delete and create database
       
   410      *
       
   411      * @since S60 v5.0
       
   412      */
       
   413     void RecreateDatabaseL( const TBool aDelete);
   474 
   414 
   475     /**
   415     /**
   476      * Stores thumbnail image.
   416      * Stores thumbnail image.
   477      *
   417      *
   478      * @since S60 v5.0
   418      * @since S60 v5.0
   485      * @param aThumbnailSize Associated size of the thumbnail to be deleted
   425      * @param aThumbnailSize Associated size of the thumbnail to be deleted
   486      * @param aThumbFromPath Thumbnail created from associated path.
   426      * @param aThumbFromPath Thumbnail created from associated path.
   487      */
   427      */
   488     void StoreThumbnailL( const TDesC& aPath, const TDes8& aData, const TSize&
   428     void StoreThumbnailL( const TDesC& aPath, const TDes8& aData, const TSize&
   489         aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, 
   429         aSize, const TSize& aOriginalSize, const TThumbnailFormat& aFormat, TInt aFlags, 
   490         const TThumbnailSize& aThumbnailSize, const TThumbnailId aThumbnailId = 0,
   430         const TThumbnailSize& aThumbnailSize, const TInt64 aModified,
   491         const TBool aThumbFromPath = ETrue);
   431         const TBool aThumbFromPath = ETrue);
   492 
   432 
   493     /**
   433     /**
   494      * Finds possible existing duplicate thumbnail.
   434      * Finds possible existing duplicate thumbnail.
   495      *
   435      *
   496      * @since S60 v5.0
   436      * @since S60 v5.0
   497      * @param aPath Path of the image from which thumbnail was created.
   437      * @param aPath Path of the image from which thumbnail was created.
   498      * @param aThumbnailId ID of the thumbnail
   438      * @param aThumbnailId ID of the thumbnail
   499      * @param aThumbnailSize Associated size of the thumbnail to be deleted
   439      * @param aThumbnailSize Associated size of the thumbnail to be deleted
   500      */
   440      */
   501     TBool FindDuplicateL( const TDesC& aPath, const TThumbnailId aThumbnailId,
   441     TBool FindDuplicateL( const TDesC& aPath, const TThumbnailSize& aThumbnailSize );    
   502                           const TThumbnailSize& aThumbnailSize );    
       
   503     
   442     
   504     /**
   443     /**
   505      * Flush RAM cache containing generated TNs to persistent storage.
   444      * Flush RAM cache containing generated TNs to persistent storage.
   506      *
   445      *
   507      * @since S60 TB9.1
   446      * @since S60 TB9.1
   521      *
   460      *
   522      * @since S60 TB9.1
   461      * @since S60 TB9.1
   523      */
   462      */
   524     void StopAutoFlush();
   463     void StopAutoFlush();
   525     
   464     
       
   465     void StartMaintenance();
       
   466     
   526     /**
   467     /**
   527      * Callback for harvesting complete timer
   468      * Callback for harvesting complete timer
   528      *
   469      *
   529      * @since S60 v5.0
   470      * @since S60 v5.0
   530      */
   471      */
   531     static TInt AutoFlushTimerCallBack(TAny* aAny);
   472     static TInt AutoFlushTimerCallBack(TAny* aAny);
   532     
   473     
   533     /**
   474     /**
   534      * Checks timestamp of blacklisted entry to timestamp of file, from
   475      * Callback for maintenance timer
   535      * which thumbnail entry was created, in filesystem
   476      *
   536      *
   477      * @since S60 v5.0
   537      * @param aPath Path from which thumbnail created
   478      */
   538      * @param aTempTable Indication whether data in temp table
   479     static TInt MaintenanceTimerCallBack(TAny* aAny);
   539      * @param aModified On return contains indication whether file modified
   480     
   540      */
   481     /**
   541     void CheckModifiedByPathL( const TDesC& aPath, TBool aTempTable, TBool& aModified  );
   482     * Touches blacklisted items
   542     
       
   543     /**
       
   544      * Checks timestamp of blacklisted entry to timestamp of file, from
       
   545      * which thumbnail entry was created, in filesystem
       
   546      *
       
   547      * @param aId Thumbnail id
       
   548      * @param aTempTable Indication whether data in temp table
       
   549      * @param aModified On return contains indication whether file modified
       
   550      */
       
   551     void CheckModifiedByIdL( TUint32 aId, TBool aTempTable, TBool& aModified  );
       
   552     
       
   553     /**
       
   554     * Removes blacklisted flag from all entrys
       
   555     *
   483     *
   556     */
   484     */
   557     void RemoveDbFlagL(TThumbnailDbFlags aFlag);
   485     void PrepareBlacklistedItemsForRetryL();
       
   486     
       
   487     /**
       
   488     * Deletes thumbs added to Deleted table
       
   489     *
       
   490     */
       
   491     TInt DeleteMarkedL();
       
   492     
       
   493     /**
       
   494     * Checks if thumbnail source files are still in the file system.
       
   495     * If not, delete corresponding thumbs.
       
   496     *
       
   497     * @return ETrue, if finished.
       
   498     */
       
   499     TBool FileExistenceCheckL();
       
   500     
       
   501     /**
       
   502      * Strips drive letter from URI.
       
   503      *
       
   504      * @since S60 v5.0
       
   505      * @param aPath Path.
       
   506      */
       
   507     void StripDriveLetterL( TDes& aPath );
   558     
   508     
   559 public : // From MThumbnailStoreDiskSpaceNotifierObserver
   509 public : // From MThumbnailStoreDiskSpaceNotifierObserver
   560     void HandleDiskSpaceNotificationL(TBool aDiskFull);
   510     void HandleDiskSpaceNotificationL(TBool aDiskFull);
   561 
   511 
   562     void HandleDiskSpaceError(TInt aError);
   512     void HandleDiskSpaceError(TInt aError);
       
   513     
       
   514 private: //From MTMActivityManagerObserver
       
   515     void ActivityChanged(const TBool aActive);
   563     
   516     
   564 private:
   517 private:
   565     // data
   518     // data
   566 
   519 
   567     /**
   520     /**
   601     CThumbnailServer* iServer;
   554     CThumbnailServer* iServer;
   602   
   555   
   603 #ifdef _DEBUG
   556 #ifdef _DEBUG
   604     TUint32 iThumbCounter;
   557     TUint32 iThumbCounter;
   605 #endif
   558 #endif
       
   559 
   606     /**
   560     /**
   607      * Periodic timer handling automatic flushing of db cache
   561      * Periodic timer handling automatic flushing of db cache
   608      */
   562      */
   609     CPeriodic* iAutoFlushTimer;
   563     CPeriodic* iAutoFlushTimer;
   610     
   564 
       
   565     /**
       
   566      * Periodic timer handling db maintenance
       
   567      */
       
   568     CPeriodic* iMaintenanceTimer; 
       
   569 	   
   611     /**
   570     /**
   612     * Notifier for situations where free disk space runs out.
   571     * Notifier for situations where free disk space runs out.
   613     */
   572     */
   614     CThumbnailStoreDiskSpaceNotifierAO* iDiskFullNotifier;
   573     CThumbnailStoreDiskSpaceNotifierAO* iDiskFullNotifier;
   615     
   574     
   616     TBool iDiskFull;
   575     TBool iDiskFull;
       
   576     
       
   577     CTMActivityManager* iActivityManager;
       
   578     
       
   579     // device idle
       
   580     TBool iIdle;
       
   581     
       
   582     // delete thumbs
       
   583     TBool iDeleteThumbs;
       
   584     
       
   585     // check if thumb source files still exist
       
   586     TBool iCheckFilesExist;
       
   587     TInt64 iLastCheckedRowID;
   617 };
   588 };
   618 // End of File
   589 // End of File
   619 
   590 
   620 
   591 
   621 #endif // THUMBNAILSTORE_H
   592 #endif // THUMBNAILSTORE_H