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