|
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: Definition of CNcdPurchaseHistoryDb |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_NCDPURCHASEHISTORYIMPL_H |
|
20 #define C_NCDPURCHASEHISTORYIMPL_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <d32dbms.h> |
|
24 #include <f32file.h> |
|
25 |
|
26 #include "catalogscommunicable.h" |
|
27 #include "ncdnodefunctionids.h" |
|
28 |
|
29 class CNcdPurchaseHistoryFilter; |
|
30 class CNcdPurchaseDetails; |
|
31 class MCatalogsBaseMessage; |
|
32 class RFs; |
|
33 |
|
34 /** |
|
35 * Purchase history. |
|
36 */ |
|
37 class CNcdPurchaseHistoryDb : public CCatalogsCommunicable |
|
38 { |
|
39 public: // Enumerations |
|
40 |
|
41 /** |
|
42 * Column numbers for rowsets. |
|
43 */ |
|
44 enum TPurchaseColumns |
|
45 { |
|
46 EPurchaseId = 1, |
|
47 EEventId, |
|
48 EClientUid, |
|
49 ENamespace, |
|
50 EEntityId, |
|
51 EItemName, |
|
52 EItemPurpose, |
|
53 ECatalogName, |
|
54 EDownloadInfo, |
|
55 EPurchaseOptionId, |
|
56 EPurchaseOptionName, |
|
57 EPurchaseOptionPrice, |
|
58 EFinalPrice, |
|
59 EPaymentMethodName, |
|
60 EPurchaseTime, |
|
61 EDownloadedFiles, |
|
62 EFileInstallInfos, |
|
63 EIcon, |
|
64 EDownloadAccessPoint, |
|
65 EDescription, |
|
66 EVersion, |
|
67 EServerUri, |
|
68 EItemType, |
|
69 ETotalContentSize, |
|
70 EOriginNodeId, |
|
71 ELastOperationTime, |
|
72 ELastOperationErrorCode, |
|
73 EHasIcon, |
|
74 EAttributes |
|
75 }; |
|
76 |
|
77 /** |
|
78 * Sorting order of the purchases. ENewestFirst order sorts purchases |
|
79 * from newest to oldest. EOldestFirst order sorts purchases from oldest |
|
80 * to newest. ENone will not sort at all and results may come in any |
|
81 * order. |
|
82 */ |
|
83 enum TSortingOrder |
|
84 { |
|
85 ENewestFirst, EOldestFirst, ENone |
|
86 }; |
|
87 |
|
88 public: // Construction & destruction |
|
89 |
|
90 /** |
|
91 * Constructor. |
|
92 * |
|
93 * @param aDbFilename Filename of the database. |
|
94 * @return CNcdPurchaseHistoryDb* Purchase history. |
|
95 */ |
|
96 static CNcdPurchaseHistoryDb* NewL( |
|
97 const TDesC& aDbFilename ); |
|
98 |
|
99 /** |
|
100 * Constructor. |
|
101 * |
|
102 * @param aDbFilename Filename of the database. |
|
103 * @return CNcdPurchaseHistoryDb* Purchase history. |
|
104 */ |
|
105 static CNcdPurchaseHistoryDb* NewLC( |
|
106 const TDesC& aDbFilename ); |
|
107 |
|
108 /** |
|
109 * Destructor. |
|
110 */ |
|
111 ~CNcdPurchaseHistoryDb(); |
|
112 |
|
113 public: // From CCatalogsCommunicable |
|
114 |
|
115 /** |
|
116 * @see CCatalogsCommunicable::ReceiveMessage |
|
117 */ |
|
118 virtual void ReceiveMessage( MCatalogsBaseMessage* aMessage, |
|
119 TInt aFunctionNumber ); |
|
120 |
|
121 /** |
|
122 * @see CCatalogsCommunicable::CounterPartLost |
|
123 */ |
|
124 virtual void CounterPartLost( const MCatalogsSession& aSession ); |
|
125 |
|
126 private: // Construction |
|
127 |
|
128 /** |
|
129 * Private constructor. |
|
130 * |
|
131 * @param aDbFilename Filename of the database. |
|
132 */ |
|
133 void ConstructL( const TDesC& aDbFilename ); |
|
134 |
|
135 /** |
|
136 * Private constructor. |
|
137 */ |
|
138 CNcdPurchaseHistoryDb(); |
|
139 |
|
140 public: // New functions |
|
141 |
|
142 /** |
|
143 * Save purchase details into the purchase database. |
|
144 * |
|
145 * @since S60 v3.2 |
|
146 * @param aPurchase Details that will be saved. |
|
147 * @param aSaveIcon ETrue as default, which informs that the icon |
|
148 * should be saved. This will replace an old icon if it existed. |
|
149 * So, if an old icon was to be kept, EFalse should be used. |
|
150 */ |
|
151 void SavePurchaseL( CNcdPurchaseDetails& aPurchase, |
|
152 TBool aSaveIcon = ETrue ); |
|
153 |
|
154 /** |
|
155 * Remove purchase from the purchase history. |
|
156 * |
|
157 * @since S60 v3.2 |
|
158 * @param aPurchaseId ID of the purchase to be removed. |
|
159 */ |
|
160 void RemovePurchaseL( TUint aPurchaseId ); |
|
161 |
|
162 /** |
|
163 * Get purchase IDs from purchase history. |
|
164 * |
|
165 * @since S60 v3.2 |
|
166 * @param aFilter Filter used to get certain purchase IDs from the |
|
167 * purchase history. |
|
168 * @param aSortingOrder Sorting order used in returned array. |
|
169 * @return Array of purchase IDs. Can be empty. |
|
170 */ |
|
171 RArray<TUint> PurchaseIdsL( |
|
172 const CNcdPurchaseHistoryFilter& aFilter, |
|
173 const TSortingOrder aSortingOrder ); |
|
174 |
|
175 /** |
|
176 * Get purchase details from purchase history. |
|
177 * |
|
178 * @since S60 v3.2 |
|
179 * @param aPurchaseId ID of the purchase. PurchaseIdsL function can be |
|
180 * used to get purchase IDs. |
|
181 * @param aLoadIcon If EFalse, the icon is not loaded. ETrue by default |
|
182 * @return Purchase details. Ownership is transferred to the caller. |
|
183 * @throw KErrNotFound if purchase is not found. |
|
184 */ |
|
185 CNcdPurchaseDetails* PurchaseL( TUint aPurchaseId, |
|
186 TBool aLoadIcon = ETrue ); |
|
187 |
|
188 /** |
|
189 * Get count of events occurred to the purchase history. |
|
190 * |
|
191 * @since S60 v3.2 |
|
192 * @return TUint Count of purchase events. |
|
193 */ |
|
194 TUint EventCountL(); |
|
195 |
|
196 |
|
197 /** |
|
198 * Ensures that purchase details have the correct amount of |
|
199 * filepaths and install infos. |
|
200 * |
|
201 * Filepaths are added/removed so that DownloadFiles().MdcaCount() equals |
|
202 * DownloadInfoCount(). Added filepaths are empty |
|
203 * |
|
204 * Install infos are removed so that DownloadInfoCount() is always greater |
|
205 * than or equal to InstallInfoCount() |
|
206 * |
|
207 * @param aDetails Details to validate |
|
208 */ |
|
209 static void ValidatePurchaseDetailsL( CNcdPurchaseDetails& aDetails ); |
|
210 |
|
211 |
|
212 private: // New private functions |
|
213 |
|
214 /** |
|
215 * This function handles save purchase request. |
|
216 * |
|
217 * @since S60 v3.2 |
|
218 * @param aMessage Message. |
|
219 * @param aSaveIcon ETrue as default, which informs that the icon |
|
220 * should be saved. This will replace an old icon if it existed. |
|
221 * So, if an old icon was to be kept, EFalse should be used. |
|
222 */ |
|
223 void SavePurchaseRequestL( MCatalogsBaseMessage& aMessage, |
|
224 TBool aSaveIcon = ETrue ); |
|
225 |
|
226 /** |
|
227 * This function handles remove purchase request. |
|
228 * |
|
229 * @since S60 v3.2 |
|
230 * @param aMessage Message. |
|
231 */ |
|
232 void RemovePurchaseRequestL( MCatalogsBaseMessage& aMessage ); |
|
233 |
|
234 /** |
|
235 * This function handles purchase IDs request. |
|
236 * |
|
237 * @since S60 v3.2 |
|
238 * @param aMessage Message. |
|
239 */ |
|
240 void GetPurchaseIdsRequestL( MCatalogsBaseMessage& aMessage ); |
|
241 |
|
242 /** |
|
243 * This function handles get purchase request. |
|
244 * |
|
245 * @since S60 v3.2 |
|
246 * @param aMessage Message. |
|
247 * @param aLoadIcon ETrue if the icon should be loaded from the database |
|
248 */ |
|
249 void GetPurchaseRequestL( MCatalogsBaseMessage& aMessage, |
|
250 TBool aLoadIcon ); |
|
251 |
|
252 /** |
|
253 * This function handles event count request. |
|
254 * |
|
255 * @since S60 v3.2 |
|
256 * @param aMessage Message. |
|
257 */ |
|
258 void EventCountRequestL( MCatalogsBaseMessage& aMessage ); |
|
259 |
|
260 /** |
|
261 * This function handles release request. |
|
262 * |
|
263 * @since S60 v3.2 |
|
264 * @param aMessage Message. |
|
265 */ |
|
266 void ReleaseRequest( MCatalogsBaseMessage& aMessage ); |
|
267 |
|
268 /** |
|
269 * Insert new purchase into the purchase history. |
|
270 * |
|
271 * @since S60 v3.2 |
|
272 * @param aPurchase Purchase. |
|
273 * @param aNewEventCount New purchase event count. |
|
274 */ |
|
275 void NewPurchaseL( |
|
276 CNcdPurchaseDetails& aPurchase, |
|
277 TUint aNewEventCount ); |
|
278 |
|
279 /** |
|
280 * Update details of old purchase. |
|
281 * |
|
282 * @since S60 v3.2 |
|
283 * @param aView Database view used in update. |
|
284 * @param aPurchase Purchase. |
|
285 * @param aNewEventCount New purchase event count. |
|
286 * @param aSaveIcon ETrue if the icon data should be saved |
|
287 */ |
|
288 void UpdatePurchaseL( |
|
289 RDbRowSet& aView, |
|
290 CNcdPurchaseDetails& aPurchase, |
|
291 TUint aNewEventCount, |
|
292 TBool aSaveIcon ); |
|
293 |
|
294 /** |
|
295 * Set database view with new values. |
|
296 * |
|
297 * @since S60 v3.2 |
|
298 * @param aView Database view to be set. |
|
299 * @param aPurchase New purchase details. |
|
300 * @param aNewEventCount New purchase event count. |
|
301 * @param aSaveIcon ETrue if the icon data should be saved |
|
302 */ |
|
303 void SetPurchaseViewL( |
|
304 RDbRowSet& aView, |
|
305 CNcdPurchaseDetails& aPurchase, |
|
306 TUint aNewEventCount, |
|
307 TBool aSaveIcon ); |
|
308 |
|
309 /** |
|
310 * Set count of events occurred to the purchase history. |
|
311 * |
|
312 * @since S60 v3.2 |
|
313 * @param aEventCount New purchase event count. |
|
314 */ |
|
315 void SetEventCountL( TUint aEventCount ); |
|
316 |
|
317 /** |
|
318 * Checks if purchase exists in the database. |
|
319 * |
|
320 * @since S60 v3.2 |
|
321 * @param aPurchaseId ID of the purchase. |
|
322 * @return ETrue if purchase existed in the database. |
|
323 */ |
|
324 TBool PurchaseExistsL( TUint aPurchaseId ); |
|
325 |
|
326 private: // Data members |
|
327 |
|
328 // Name of the database. |
|
329 HBufC* iDbFilename; |
|
330 // File server session. |
|
331 RFs iFs; |
|
332 // Database. |
|
333 RDbNamedDatabase iDatabase; |
|
334 |
|
335 // The message is set when ReceiveMessage is called. The message |
|
336 // is used in the CounterPartLost-function that informs the message |
|
337 // if the session has been lost. |
|
338 MCatalogsBaseMessage* iMessage; |
|
339 }; |
|
340 |
|
341 #endif // C_NCDPURCHASEHISTORYIMPL_H |