|
1 /* |
|
2 * Copyright (c) 2006 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: This class provides the functions to manipulate the a category |
|
15 * table in the podcast collection database. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef MPXDBCATEGORY_H |
|
21 #define MPXDBCATEGORY_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "mpxdbtable.h" |
|
25 #include "mpxmediageneraldefs.h" |
|
26 #include "mpxpodcastdefs.h" |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class CMPXMediaArray; |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * Responsible for managing all category tables |
|
35 * |
|
36 * @lib mpxpodcastdbplugin.lib |
|
37 */ |
|
38 class CMPXDbCategory : |
|
39 public CMPXDbTable |
|
40 { |
|
41 public: |
|
42 |
|
43 /** |
|
44 * Two-phased constructor. Leaves on failure. Places the instance on the |
|
45 * cleanup stack. |
|
46 * @param aDbManager Database manager |
|
47 * @param aCategory Category to identify the table |
|
48 * @return New CMPXDbCategory instance |
|
49 */ |
|
50 static CMPXDbCategory* NewLC(CMPXDbManager& aDbManager, |
|
51 TMPXGeneralCategory aCategory); |
|
52 |
|
53 /** |
|
54 * Two-phased constructor. Leaves on failure. |
|
55 * @param aDbManager Database manager |
|
56 * @param aCategory Category to identify the table |
|
57 * @return New CMPXDbCategory instance |
|
58 */ |
|
59 static CMPXDbCategory* NewL(CMPXDbManager& aDbManager, |
|
60 TMPXGeneralCategory aCategory); |
|
61 |
|
62 /** |
|
63 * Destructor. |
|
64 */ |
|
65 virtual ~CMPXDbCategory(); |
|
66 |
|
67 public: |
|
68 |
|
69 /** |
|
70 * Add a row to the lookup table |
|
71 * @param aName This is the name to be entered into the row |
|
72 * @param aDriveId The Drive Id the name (category) belongs |
|
73 * @param aNewRecord indicates to the caller if a new record is created. ETrue |
|
74 * if a new row is created in the table; otherwise EFalse. |
|
75 * @param aCaseSensitive indicates whether case sensitivity should be taken |
|
76 * into consideration when generating the unique row id |
|
77 * @return The unique id of the row added. |
|
78 */ |
|
79 TUint32 AddItemL(const TDesC& aName, TInt aDriveId, TBool& aNewRecord, |
|
80 TBool aCaseSensitive = ETrue); |
|
81 |
|
82 /** |
|
83 * Get the name field for a given ID. |
|
84 * @param aId identifies the category item |
|
85 * @return name that matches aId. Ownership is abandoned. |
|
86 */ |
|
87 HBufC* GetNameL(TUint32 aId); |
|
88 |
|
89 /** |
|
90 * Gets the total number of items in the category table. |
|
91 * @return number of items |
|
92 */ |
|
93 TInt CountL(); |
|
94 |
|
95 /** |
|
96 * Find record(s) matching the criteria |
|
97 * @param aCriteria, selection criteria |
|
98 * @param aAttrs, attributes for the matching record(s) |
|
99 * @param aMediaArray returns the matching record(s) |
|
100 */ |
|
101 void FindAllL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs, |
|
102 CMPXMediaArray& aMediaArray); |
|
103 |
|
104 /** |
|
105 * Decrement the number of episodes in the row. If the count gets to 0, remove the row. |
|
106 * @param aId The ID of the row to decrement. |
|
107 * @param aDriveId The drive Id the name (category) belongs to. Episodes on different |
|
108 * drives may belong to the same podcast title or composer; consequently, |
|
109 * one row for each podcast title/composer id and drive ID pair will exist |
|
110 * in the look up table with a count existing for each row |
|
111 * that tracks the number number of episodes on that drive with that |
|
112 * podcast title/composer. |
|
113 * @param aItemChangedMessages Returns the changed messages if valid |
|
114 */ |
|
115 void DecrementEpisodesForCategoryL(const TUint32 aId, TInt aDriveId, |
|
116 CMPXMessageArray* aItemChangedMessages); |
|
117 |
|
118 /** |
|
119 * Deletes a category. |
|
120 * @param aId identifies the category |
|
121 * @param aDriveId category drive |
|
122 */ |
|
123 void DeleteCategoryL(TUint32 aId, TInt aDriveId); |
|
124 |
|
125 /** |
|
126 * Gets details for one category item. |
|
127 * @param aId identifies the category item |
|
128 * @param aAttrs attributes to be returned |
|
129 * @param aMedia returns the requested attributes for te item |
|
130 * @leave KErrNotFound if there is no item with the specified ID |
|
131 */ |
|
132 void GetCategoryItemL(TUint32 aId, const TArray<TMPXAttribute>& aAttrs, CMPXMedia& aMedia); |
|
133 |
|
134 /** |
|
135 * Gets the details for multiple category items. |
|
136 * @param aAttrs attributes to be returned |
|
137 * @param aMediaArray inout parameter, on input contains the IDs of the category items to |
|
138 * be returned, on exit contains the requested attributes for these items |
|
139 */ |
|
140 void GetCategoryItemsL(const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray); |
|
141 |
|
142 /** |
|
143 * Gets the details for all category items. |
|
144 * @param aAttrs attributes to be returned |
|
145 * @param aMediaArray returns the requested attributes for all items |
|
146 */ |
|
147 void GetAllCategoryItemsL(const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray); |
|
148 |
|
149 /** |
|
150 * Checks if the specified category item exists. |
|
151 * @param aDriveId drive to check or KDbManagerAllDrives |
|
152 * @param aId identifies the category item |
|
153 * @return ETrue if it exists, EFalse otherwise |
|
154 */ |
|
155 TBool CategoryItemExistsL(TInt aDriveId, TUint32 aId); |
|
156 |
|
157 /** |
|
158 * Gets the number of episodes for a category item |
|
159 * @param aDriveId drive to check or KDbManagerAllDrives |
|
160 * @param aId identifies the category item |
|
161 * @return number of episodes |
|
162 */ |
|
163 TInt GetEpisodeCountL(TInt aDriveId, TUint32 aId); |
|
164 |
|
165 private: |
|
166 |
|
167 /** |
|
168 * Updates the media with information from the table |
|
169 * @param aRecord record containing the source fields |
|
170 * @param aAttrs attributes to be returned |
|
171 * @param aMedia returns the requested attributes |
|
172 */ |
|
173 void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs, |
|
174 CMPXMedia& aMedia); |
|
175 |
|
176 /** |
|
177 * Returns the category record for a given ID |
|
178 * @param aId identifies the category item |
|
179 * @return rowset |
|
180 */ |
|
181 RSqlStatement GetCategoryRecordL(TUint32 aId); |
|
182 |
|
183 /** |
|
184 * Replaces the table placeholder in the string parameter with the |
|
185 * category table name. |
|
186 * @param aQuery raw query string |
|
187 * @return processed query string, ownership is transferred. |
|
188 */ |
|
189 HBufC* PreProcessStringLC(const TDesC& aQuery); |
|
190 |
|
191 /** |
|
192 * Processes a recordset by constructing media instances and adding them |
|
193 * to the specified array. |
|
194 * @param aAttrs attributes to be returned |
|
195 * @param aRecordset recordset to be processed |
|
196 * @param aMediaArray returns the media instances |
|
197 */ |
|
198 void ProcessRecordsetL(const TArray<TMPXAttribute>& aAttrs, |
|
199 RSqlStatement& aRecordset, CMPXMediaArray& aMediaArray); |
|
200 |
|
201 private: // from MMPXTable |
|
202 |
|
203 /** |
|
204 * @see MMPXTable |
|
205 */ |
|
206 virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable); |
|
207 |
|
208 /** |
|
209 * @see MMPXTable |
|
210 */ |
|
211 virtual void DropTableL(RSqlDatabase& aDatabase); |
|
212 |
|
213 /** |
|
214 * @see MMPXTable |
|
215 */ |
|
216 virtual TBool CheckTableL(RSqlDatabase& aDatabase); |
|
217 |
|
218 private: |
|
219 |
|
220 /** |
|
221 * C++ constructor. |
|
222 * @param aDbManager Database manager insteance to be used |
|
223 * @param aCategory category for this instance |
|
224 */ |
|
225 CMPXDbCategory(CMPXDbManager& aDbManager, TMPXGeneralCategory aCategory); |
|
226 |
|
227 /** |
|
228 * Second-phase constructor. |
|
229 */ |
|
230 void ConstructL(); |
|
231 |
|
232 private: |
|
233 |
|
234 /** |
|
235 * Columns in the category table |
|
236 */ |
|
237 enum TCategoryColumns |
|
238 { |
|
239 ECategoryUniqueId = KMPXTableDefaultIndex, |
|
240 ECategoryName, |
|
241 ECategoryEpisodeCount |
|
242 }; |
|
243 |
|
244 protected: // Data |
|
245 |
|
246 HBufC* iTableName; // owned |
|
247 TMPXGeneralCategory iCategory; // identifies this table |
|
248 }; |
|
249 |
|
250 #endif // CMPXDbCategory_H |
|
251 |
|
252 // End of File |
|
253 |