photosgallery/collectionframework/thumbnailcreator/inc/glxtnvolumedatabase.h
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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:    Definition of CGlxtnVolumeDatabase
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  * @internal reviewed 30/07/2007 by Simon Brooks
       
    23  */
       
    24 
       
    25 #ifndef GLXTNVOLUMEDATABASE_H
       
    26 #define GLXTNVOLUMEDATABASE_H
       
    27 
       
    28 #include <e32base.h>
       
    29 #include <d32dbms.h>    // For RDbStoreDatabase
       
    30 #include <f32file.h>    // For TDriveName
       
    31 
       
    32 #include <glxmediaid.h>
       
    33 #include "glxtnstd.h"   // For TGlxImageDataFormat
       
    34 #include "mglxtnvolumedatabaseobserver.h"   // For TGlxtnThumbnailId
       
    35 
       
    36 class CFileStore;
       
    37 class CGlxtnFileInfo;
       
    38 class MGlxtnVolumeDatabaseObserver;
       
    39 
       
    40 const TInt KErrCorruptThumbnailDatabase = -10001;
       
    41 const TInt KErrEofThumbnailDatabase = -10002;
       
    42 
       
    43 /**
       
    44  * CGlxtnVolumeDatabase implements the database for a single volume.
       
    45  *
       
    46  * @author Dan Rhodes
       
    47  * @ingroup glx_thumbnail_creator
       
    48  */
       
    49 NONSHARABLE_CLASS(CGlxtnVolumeDatabase) : public CActive
       
    50     {
       
    51 public:
       
    52     /**
       
    53     * Static constructor.
       
    54     * @param aObserver Observer of database operations.
       
    55     * @param aFs File server handle.
       
    56     * @param aPath Full path to the database file to use.
       
    57     */
       
    58     static CGlxtnVolumeDatabase* NewLC(MGlxtnVolumeDatabaseObserver& aObserver,
       
    59                                        RFs& aFs, 
       
    60                                        const TDesC& aPath);
       
    61 
       
    62     /**
       
    63     * Destructor
       
    64     */
       
    65     ~CGlxtnVolumeDatabase();
       
    66 
       
    67     /**
       
    68     * Get the drive this database is stored on
       
    69     */
       
    70     const TDesC& Drive() const;
       
    71 
       
    72     /**
       
    73     * Look up thumbnail ID from Ids table
       
    74     * @param aMediaId Media item ID.
       
    75     */
       
    76     void GetThumbnailIdL( const TGlxMediaId& aMediaId );
       
    77 
       
    78     /**
       
    79     * Look up thumbnail ID from Items table.  If not found, add new record.
       
    80     * @param aInfo File info for media item.
       
    81     */
       
    82     void GetThumbnailIdL(const CGlxtnFileInfo* aInfo);
       
    83 
       
    84     /**
       
    85     * Retrieve the thumbnail id to be assigned to the next thumbnail that gets stored in teh database. 
       
    86     * @param None.
       
    87     */
       
    88     TGlxtnThumbnailId GetThumbnailId();
       
    89 
       
    90     /**
       
    91     * Add record to Ids table
       
    92     * @param aMediaId Media item ID.
       
    93     * @param aThumbId Thumbnail ID.
       
    94     */
       
    95     void StoreThumbnailIdL( const TGlxMediaId& aMediaId,
       
    96                             const TGlxtnThumbnailId& aThumbId );
       
    97     /**
       
    98     * Look up thumbnail from Thumbnails table
       
    99     * @param aThumbId Thumbnail ID.
       
   100     * @param aSize Thumbnail size.
       
   101     */
       
   102     void GetThumbnailL( const TGlxtnThumbnailId& aThumbId, const TSize& aSize );
       
   103     /**
       
   104     * Check if a particular thumbnail is in Thumbnails table
       
   105     * @param aThumbId Thumbnail ID.
       
   106     * @param aSize Thumbnail size.
       
   107     */
       
   108     void CheckAvailableL( const TGlxtnThumbnailId& aThumbId, const TSize& aSize );
       
   109     /**
       
   110     * Add record to Thumbnails table
       
   111     * @param aThumbId Thumbnail ID.
       
   112     * @param aSize Thumbnail size.
       
   113     * @param aFormat Thumbnail data format.
       
   114     * @param aData Thumbnail binary data.
       
   115     */
       
   116     void StoreThumbnailL( const TGlxtnThumbnailId& aThumbId, const TSize& aSize,
       
   117                         TGlxImageDataFormat aFormat, const TDesC8& aData );
       
   118 
       
   119     /**
       
   120     * Add record to Items table, if not found.
       
   121     * @param aThumbId Thumbnail Id.
       
   122     * @param aInfo File info for media item.
       
   123     */
       
   124     void StoreItemsL( const TGlxtnThumbnailId& aThumbId, const CGlxtnFileInfo* aInfo );
       
   125 
       
   126     /**
       
   127     * Initialize thumbnail identifier to the last known value plus one.
       
   128     */
       
   129     void InitializeThumbIdL();
       
   130 
       
   131     /**
       
   132     * Delete a record from the Ids table
       
   133     * @param aMediaId MediaId of record to delete.
       
   134     */
       
   135     void DeleteIdL( const TGlxMediaId& aMediaId );
       
   136     
       
   137     /**
       
   138     * Delete a record from the Thumbnails table
       
   139     * @param aThumbId ThumbId of records to delete.
       
   140     */
       
   141     void DeleteThumbnailsL( const TGlxtnThumbnailId& aThumbId );
       
   142     
       
   143     /**
       
   144     * Delete a record from the Items table
       
   145     * @param aThumbId ThumbId of record to delete.
       
   146     */
       
   147     void DeleteItemL( const TGlxtnThumbnailId& aThumbId );
       
   148     
       
   149     /**
       
   150     * Cleanup Database (remove entries that do not have corresponding file)
       
   151     */
       
   152     void CleanupDatabaseL();
       
   153     
       
   154 protected:  // From CActive
       
   155     void DoCancel();
       
   156     void RunL();
       
   157     TInt RunError(TInt aError);
       
   158 
       
   159 private:
       
   160     /**
       
   161     * Default constructor.
       
   162     * @param aObserver Observer of database operations.
       
   163     * @param aFs File server handle.
       
   164     */
       
   165     CGlxtnVolumeDatabase(MGlxtnVolumeDatabaseObserver& aObserver, RFs& aFs);
       
   166     /**
       
   167     * 2nd phase constructor.
       
   168     * @param aPath Full path to the database file to use.
       
   169     */
       
   170     void ConstructL(const TDesC& aPath);
       
   171 
       
   172     /**
       
   173     * Open an existing database.
       
   174     * @param aFs File server handle.
       
   175     * @param aPath Full path to the database file to use.
       
   176     */
       
   177     void OpenDbL(RFs& aFs, const TDesC& aFilename);
       
   178 
       
   179     /**
       
   180     * Create a new database.
       
   181     * @param aFs File server handle.
       
   182     * @param aPath Full path to the database file to use.
       
   183     */
       
   184     void CreateDbL(RFs& aFs, const TDesC& aFilename);
       
   185 
       
   186     /**
       
   187     * Add record to Items table
       
   188     * @return Thumbnail ID of new record.
       
   189     */
       
   190     TGlxtnThumbnailId DoAddItemL();
       
   191 
       
   192     /**
       
   193     * Evaluate a view based on a SQL query.
       
   194     * @param aQuery The SQL select statement.
       
   195     */
       
   196     void EvaluateQueryL( const TDbQuery &aQuery );
       
   197 
       
   198     /**
       
   199     * Execute a SQL data update statement.
       
   200     * @param aSql The SQL statement.
       
   201     */
       
   202     void UpdateDataL( const TDesC& aSql );
       
   203 
       
   204     /**
       
   205     * Test and cleanup a row in Items table
       
   206     */
       
   207     void CleanupRowL();
       
   208  
       
   209     /**
       
   210     * Modify SQL string to handle quotes correctly
       
   211     * @param aText String to be modified
       
   212     * @return New HBufC containing modified string
       
   213     */
       
   214     HBufC* QuoteSqlStringLC(const TDesC& aText);
       
   215 
       
   216 private:
       
   217     enum TDatabaseState
       
   218         {
       
   219         EStateIdle, 
       
   220         EStateGettingIdFromMediaId, 
       
   221         EStateGettingIdFromFilename,
       
   222         EStateGettingThumbnail,
       
   223         EStateDeletingId,
       
   224         EStateDeletingThumbnails,
       
   225         EStateDeletingItem,
       
   226         EStateCheckingAvailability,
       
   227         EStateCleaning,
       
   228         EStateCleaningDeletingThumbnails
       
   229         };
       
   230 
       
   231     /** Observer of this database */
       
   232     MGlxtnVolumeDatabaseObserver& iObserver;
       
   233     /** File server session */
       
   234     RFs& iFs;
       
   235     /** Drive name of the volume */
       
   236     TDriveName iDrive;
       
   237     /** Handle to the database */
       
   238     RDbStoreDatabase iDatabase;
       
   239     /** Store used by the database */
       
   240     CFileStore* iStore;
       
   241     /** ID for next stored thumbnail */
       
   242     TUint iNextThumbId;
       
   243     /** File info for media item current query relates to (not owned) */
       
   244     const CGlxtnFileInfo* iInfo;
       
   245     /** Current state */
       
   246     TDatabaseState iState;
       
   247     /** View used for current query */
       
   248     RDbView iView;
       
   249     /** Updater to update a table */
       
   250     RDbUpdate iDbUpdater;
       
   251     /** Table used for query/deletion of rows in table */
       
   252     RDbTable iTable;
       
   253     /** Flag to determine if cleanup operation did anything requiring compacting */
       
   254     TBool iItemsCleaned;
       
   255     };
       
   256 
       
   257 #endif  // GLXTNVOLUMEDATABASE_H