|
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: The class MPXDbCommonUtil which contains utilities functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MPXDBCOMMONUTIL_H |
|
20 #define MPXDBCOMMONUTIL_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <apmstd.h> |
|
24 #include <f32file.h> |
|
25 #include <badesca.h> |
|
26 #include <mpxmediageneraldefs.h> |
|
27 #include <mpxmessagegeneraldefs.h> |
|
28 #include <mpxcollectionmessagedefs.h> |
|
29 #include <mpxmessage2.h> |
|
30 #include <mpxcollectionpath.h> |
|
31 |
|
32 #include "mpxdbcommonstd.h" |
|
33 |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class CMPXRowSet; |
|
37 class CMPXDatabase; |
|
38 class CMPXMedia; |
|
39 class CMPXMediaArray; |
|
40 class RSqlStatement; |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 /** |
|
45 * This static class contains utilities functions used by MPX Collection DB Plugins |
|
46 */ |
|
47 class MPXDbCommonUtil |
|
48 { |
|
49 |
|
50 public: |
|
51 |
|
52 /** |
|
53 * Set HBufC data member. |
|
54 * Free the memory and set the aBuf to the new location. |
|
55 * @param aBuf, the buf to be set |
|
56 * @param aSource, source descriptor |
|
57 * @param aMaxLen, max length allowed in aBuf, -1 is unlimited. |
|
58 * @return KErrOverflow if the length of source is greater than MaxLen |
|
59 */ |
|
60 IMPORT_C static TInt SetHBuf(HBufC*& aBuf, |
|
61 const TDesC* aSource, |
|
62 TInt aMaxLen = -1); |
|
63 |
|
64 /** |
|
65 * Replace the single quote in the SQL string |
|
66 * @param aSrc source descriptor |
|
67 * @param aTrg target descriptor |
|
68 */ |
|
69 IMPORT_C static void FindAndReplaceSingleQuote(const TDesC& aSrc, TDes& aTrg); |
|
70 |
|
71 /** |
|
72 * Delete from file system (includes read-only files) |
|
73 * @param aFs File server session handle |
|
74 * @param aFile File path to be deleted |
|
75 * @return KErrNone if file deleted successfully |
|
76 * System-wide error code otherwise |
|
77 */ |
|
78 IMPORT_C static TInt DeleteFile(RFs& aFs, const TDesC& aFile); |
|
79 |
|
80 /** |
|
81 * Get the drive Id with a given volume unique Id |
|
82 * @param aFs File server session handle |
|
83 * @param aVolumeId volume ID to match |
|
84 * @return drive Id. If volume Id not found, return KErrNotFound |
|
85 */ |
|
86 IMPORT_C static TInt GetDriveIdMatchVolIdL(RFs& aFs, TUint aVolumeId); |
|
87 |
|
88 /** |
|
89 * Get the volume Id with a given drive Id |
|
90 * @param aFs File server session handle |
|
91 * @param aDriveId: a drive ID to match |
|
92 * @return volume Id. If no correspending media is found for given |
|
93 * aDriveId, 0 will return |
|
94 */ |
|
95 IMPORT_C static TUint GetVolIdMatchDriveIdL(RFs& aFs, TInt aDriveId); |
|
96 |
|
97 /** |
|
98 * Generate a 32bits Unique Id with MD5 |
|
99 * If the input is a filename, only the path part will be hashed |
|
100 * The drive part of the path will be replaced by the corresponding |
|
101 * volume Id in order to maintain uniquenss as one media may mount as |
|
102 * different drive letter in different devices |
|
103 * @param aFs File server session handle |
|
104 * @param aTableId Use category as table Id |
|
105 * @param aName Category name or file name as input to encoder |
|
106 * @param aCaseSensitve ETrue if case sensitivity should be taken |
|
107 * into account when generating unique ID |
|
108 * @return unique Id |
|
109 * NOTE If aName given is a path and the drive/media doesn't |
|
110 * exist (e.g. MMC not inserted), full path will be hashed |
|
111 */ |
|
112 IMPORT_C static TUint32 GenerateUniqueIdL(RFs& aFs, TMPXGeneralCategory aTableId, |
|
113 const TDesC& aName, TBool aCaseSensitive); |
|
114 |
|
115 /** |
|
116 * Create a media object with title, type, category and ID and append it to the media array |
|
117 * @param aArray media array |
|
118 * @param aTitle title |
|
119 * @param aType attribute type |
|
120 * @param aCat attribute category |
|
121 * @param aId unique ID |
|
122 * @param aNonPermissibleActions bitmask specifying the non-permissible actions for the entry |
|
123 * @param aDbflag Dbflag value for the new media entry |
|
124 */ |
|
125 IMPORT_C static void AppendMediaL(CMPXMediaArray& aArray, const TDesC& aTitle, TMPXGeneralType aType, |
|
126 TMPXGeneralCategory aCat, TMPXItemId aId = 0, TInt aNonPermissibleActions = 0, |
|
127 TUint aDbflag = 0); |
|
128 |
|
129 /** |
|
130 * Create a media object with title, type, category and ID and prepend it to the media array |
|
131 * @param aArray media array |
|
132 * @param aTitle title |
|
133 * @param aType attribute type |
|
134 * @param aCat attribute category |
|
135 * @param aId unique ID |
|
136 * @param aNonPermissibleActions bitmask specifying the non-permissible actions for the entry |
|
137 * @param aDbflag Dbflag value for the new media entry |
|
138 * @param aPos postion of the new item, 0 is the first item |
|
139 */ |
|
140 IMPORT_C static void PrependMediaL(CMPXMediaArray& aArray, const TDesC& aTitle, TMPXGeneralType aType, |
|
141 TMPXGeneralCategory aCat, TMPXItemId aId = 0, TInt aNonPermissibleActions = 0, |
|
142 TUint aDbflag = 0, |
|
143 TInt aPos = 0); |
|
144 |
|
145 /** |
|
146 * Fill in the supported UID array based on what is requested in the attribute array |
|
147 * @param aAttrs requested attributes |
|
148 * @param aSupportedIds supported UID array |
|
149 */ |
|
150 IMPORT_C static void FillInSupportedUIDsL(const TArray<TMPXAttribute>& aAttrs, RArray<TInt>& aSupportedIds); |
|
151 |
|
152 /** |
|
153 * Fill in the message with item changed information |
|
154 * @param aMessage a message to be filled with the supplied information |
|
155 * @param aId item id |
|
156 * @param aChangeType change type |
|
157 * @param aCategory category of the item changed |
|
158 * @param aUid plugin UID |
|
159 * @param aDeprecatedId deprecated id of the item after it's been moved/renamed |
|
160 */ |
|
161 IMPORT_C static void FillItemChangedMessageL(CMPXMessage& aMessage, TMPXItemId aId, |
|
162 TMPXChangeEventType aChangeType, TMPXGeneralCategory aCategory, TUint aUid, |
|
163 TMPXItemId aDeprecatedId = 0); |
|
164 |
|
165 /** |
|
166 * Constructs an item changed message and adds it to the array |
|
167 * @param aMessageArray array to add the message to |
|
168 * @param aId item ID |
|
169 * @param aChangeType change type |
|
170 * @param aCategory category of the item changed |
|
171 * @param aUid plugin UID |
|
172 * @param aDeprecatedId deprecated id of the item after it's been moved/renamed |
|
173 */ |
|
174 IMPORT_C static void AddItemChangedMessageL(CMPXMessageArray& aMessageArray, TMPXItemId aId, |
|
175 TMPXChangeEventType aChangeType, TMPXGeneralCategory aCategory, TUint aUid, |
|
176 TMPXItemId aDeprecatedId = 0); |
|
177 |
|
178 /** |
|
179 * Find the matching item changed message from the array |
|
180 * @param aMessageArray array containing item changed messages |
|
181 * @param aMessage the message to search for in the array. |
|
182 * @return KErrNotFound if the message cannot be found in the array; otherwise, |
|
183 * the index of the 1st matching message in the array. |
|
184 */ |
|
185 IMPORT_C static TInt FindItemChangedMessageL(const CMPXMessageArray& aMessageArray, |
|
186 const CMPXMessage& aMessage); |
|
187 |
|
188 /** |
|
189 * Get the DRM protection type of the file |
|
190 * @param aFile the file to retrieve the DRM type |
|
191 * @return DRM protection type of the file |
|
192 */ |
|
193 IMPORT_C static TMCDrmType GetDRMTypeL(const TDesC& aFile); |
|
194 |
|
195 /** |
|
196 * Processes the string for single quotes |
|
197 * @param aString source string |
|
198 * @return processed string |
|
199 */ |
|
200 IMPORT_C static HBufC* ProcessSingleQuotesLC(const TDesC& aString); |
|
201 |
|
202 /** |
|
203 * Processes the string for pattern characters so that they will be treated |
|
204 * as normal characters. |
|
205 * @param aString source string |
|
206 * @return processed string where those pattern characters will no longer be |
|
207 * treated as special characters, they will be treated as regular |
|
208 * characters. |
|
209 */ |
|
210 IMPORT_C static HBufC* ProcessPatternCharsLC(const TDesC& aString); |
|
211 |
|
212 /** |
|
213 * Constructs an SQL criterion (name = value) |
|
214 * @param aCriterion name string |
|
215 * @param aValue value |
|
216 * @return criterion string on the CS |
|
217 */ |
|
218 IMPORT_C static HBufC* SqlCriterionLC( |
|
219 const TDesC& aCriterion, TInt aValue); |
|
220 |
|
221 /** |
|
222 * Constructs an SQL criterion (name = value) |
|
223 * @param aCriterion name string |
|
224 * @param aValue value |
|
225 * @return criterion string on the CS |
|
226 */ |
|
227 IMPORT_C static HBufC* SqlCriterion64LC( |
|
228 const TDesC& aCriterion, TInt64 aValue); |
|
229 |
|
230 /** |
|
231 * Constructs an SQL criterion (name = value) |
|
232 * @param aCriterion name string |
|
233 * @param aValue1 value1 |
|
234 * @param aValue2 value2 |
|
235 * @return criterion string on the CS |
|
236 */ |
|
237 IMPORT_C static HBufC* SqlCriterionLC( |
|
238 const TDesC& aCriterion, TInt aValue1, TInt aValue2); |
|
239 |
|
240 /** |
|
241 * Constructs an SQL criterion (name = value) |
|
242 * @param aCriterion name string |
|
243 * @param aValue1 TInt64 value1 |
|
244 * @param aValue2 TInt64 value2 |
|
245 * @return criterion string on the CS |
|
246 */ |
|
247 IMPORT_C static HBufC* SqlCriterion64LC( |
|
248 const TDesC& aCriterion, TInt64 aValue1, TInt64 aValue2); |
|
249 |
|
250 /** |
|
251 * Constructs an SQL criterion (name = value) |
|
252 * @param aCriterion name string |
|
253 * @param aValue value string |
|
254 * @return criterion string on the CS |
|
255 */ |
|
256 IMPORT_C static HBufC* SqlCriterionLC( |
|
257 const TDesC& aCriterion, const TDesC& aValue); |
|
258 |
|
259 /** |
|
260 * Constructs an SQL criterion (name = value) |
|
261 * @param aCriterion name string |
|
262 * @param aValue1 value1 |
|
263 * @param aValue2 value2 |
|
264 * @return criterion string on the CS |
|
265 */ |
|
266 IMPORT_C static HBufC* SqlCriterionLC( |
|
267 const TDesC& aCriterion, const TDesC& aValue1, const TDesC& aValue2); |
|
268 |
|
269 /** |
|
270 * Constructs an SQL criterion (name = value) |
|
271 * @param aCriterion name string |
|
272 * @param aValue1 value1 |
|
273 * @param aValue2 value2 |
|
274 * @param aValue3 value3 |
|
275 * @param aValue4 value4 |
|
276 * @return criterion string on the CS |
|
277 */ |
|
278 IMPORT_C static HBufC* SqlCriterionLC( |
|
279 const TDesC& aCriterion, const TDesC& aValue1, TInt aValue2, |
|
280 const TDesC& aValue3, TInt aValue4); |
|
281 |
|
282 /** |
|
283 * Constructs an SQL criterion (name = value) and adds it to the array |
|
284 * @param aCriteriaArray array to add the criterion to |
|
285 * @param aCriterion name |
|
286 * @param aValue value |
|
287 * @return number of characters in the criterion string |
|
288 */ |
|
289 IMPORT_C static TInt AddSqlCriterionL(CDesCArray& aCriteriaArray, const TDesC& aCriterion, |
|
290 TInt aValue); |
|
291 |
|
292 /** |
|
293 * Constructs an SQL criterion (name = value) and adds it to the array |
|
294 * @param aCriteriaArray array to add the criterion to |
|
295 * @param aCriterion name |
|
296 * @param aValue value |
|
297 * @return number of characters in the criterion string |
|
298 */ |
|
299 IMPORT_C static TInt AddSqlCriterionL(CDesCArray& aCriteriaArray, const TDesC& aCriterion, |
|
300 const TDesC& aValue); |
|
301 |
|
302 /** |
|
303 * Create a full path with input drive Id and path |
|
304 * @param aDriveId a drive Id to added in front of path |
|
305 * @param aPath path contains path and filename |
|
306 * @return created full path, ownership transferred to client |
|
307 */ |
|
308 IMPORT_C static HBufC* CreateFullPathL(TInt aDriveId, const TDesC& aPath); |
|
309 |
|
310 /** |
|
311 * Appends a name and a string value to the parameter arrays. |
|
312 * @param aFields field names array to append to |
|
313 * @param aValues field values array to append to |
|
314 * @param aField field name |
|
315 * @param aValue field value |
|
316 */ |
|
317 IMPORT_C static void AppendValueL(CDesCArray& aFields, CDesCArray& aValues, |
|
318 const TDesC& aField, const TDesC& aValue); |
|
319 |
|
320 /** |
|
321 * Appends a name and an int value to the parameter arrays. |
|
322 * @param aFields field names array to append to |
|
323 * @param aValues field values array to append to |
|
324 * @param aField field name |
|
325 * @param aValue field value |
|
326 */ |
|
327 IMPORT_C static void AppendValueL(CDesCArray& aFields, CDesCArray& aValues, |
|
328 const TDesC& aField, TUint32 aValue); |
|
329 |
|
330 /** |
|
331 * Returns the MIME type for a given URI |
|
332 * @param aUri URI |
|
333 * @return the MIME type |
|
334 */ |
|
335 IMPORT_C static TDataType GetMimeTypeForUriL(const TDesC& aUri); |
|
336 |
|
337 /** |
|
338 * Constructs a string from the specified array like: |
|
339 * <item1>aSeparator<item2>aSeparator...<itemN> |
|
340 * @param aArray source array |
|
341 * @param aSeparator separator string |
|
342 * @return constructed string on the CS |
|
343 */ |
|
344 IMPORT_C static HBufC* StringFromArrayLC(const CDesCArray& aArray, const TDesC& aSeparator); |
|
345 |
|
346 /** |
|
347 * Constructs a string from two arrays like: |
|
348 * <aNameArray.item1>aValueSeparator<aValueArray.item1>aEntitySeparator... |
|
349 * @param aNameArray array containing the names |
|
350 * @param aValueArray array containing the values |
|
351 * @param aValueSeparator value separator |
|
352 * @param aEntitySeparator entity separator |
|
353 * @return constructed string on the CS |
|
354 */ |
|
355 IMPORT_C static HBufC* StringFromArraysLC(const CDesCArray& aNameArray, |
|
356 const CDesCArray& aValueArray, const TDesC& aValueSeparator, |
|
357 const TDesC& aEntitySeparator); |
|
358 |
|
359 /** |
|
360 * Converts TTime to a datetime string representation. |
|
361 * @param aTime TTime object |
|
362 * @return string containing date and time on the CS |
|
363 */ |
|
364 IMPORT_C static HBufC* TTimeToDesLC(const TTime& aTime); |
|
365 |
|
366 /** |
|
367 * Converts string representation of datetime into TTime. |
|
368 * @param aDateTime string, containing date and time |
|
369 * @return aTime TTime object |
|
370 */ |
|
371 IMPORT_C static TTime DesToTTimeL(const TDesC& aDateTime); |
|
372 |
|
373 /** |
|
374 * Returns the current time in the string format used by the database. |
|
375 * @return string containing current date and time on the CS |
|
376 */ |
|
377 IMPORT_C static HBufC* CurrentTimeDesLC(); |
|
378 |
|
379 /** |
|
380 * Returns the current date in the string format used by the database. |
|
381 * @return string containing current date on the CS |
|
382 */ |
|
383 IMPORT_C static HBufC* CurrentDateDesLC(); |
|
384 |
|
385 /** |
|
386 * Fills the drive from the URI. if the URI does not include a drive letter |
|
387 * the method does not modify aDrive and returns KErrNotFound |
|
388 * @param aUri URI to be analysed |
|
389 * @param aDrive returns the drive |
|
390 * @return system error code |
|
391 */ |
|
392 IMPORT_C static TInt GetDriveL(const TDesC& aUri, TDriveUnit& aDrive); |
|
393 |
|
394 /** |
|
395 * Checks if a specified attribute exists in the attribute array |
|
396 * @param aAttrs attribute array |
|
397 * @param aAttribute attribute to be checked |
|
398 * @return ETrue if the attribute exists, Efalse otherwise |
|
399 */ |
|
400 IMPORT_C static TBool AttributeExists(const TArray<TMPXAttribute>& aAttrs, |
|
401 const TMPXAttribute& aAttribute); |
|
402 |
|
403 /** |
|
404 * Reads the value of a text field. This method is required because on ARMv5 |
|
405 * the RSqlStatement::ColumnTextL method does not return KNullDesC for empty |
|
406 * text fields. |
|
407 * @param aStatement recordset to read the field from |
|
408 * @param aField field index |
|
409 * @return Text field value or KNullDesC if empty |
|
410 */ |
|
411 IMPORT_C static TPtrC GetColumnTextL(RSqlStatement& aStatement, TInt aField); |
|
412 |
|
413 private: |
|
414 /** |
|
415 * Create a media object with title, type, category and ID and push onto the CS. |
|
416 * @param aTitle title |
|
417 * @param aType attribute type |
|
418 * @param aCat attribute category |
|
419 * @param aId unique ID |
|
420 * @param aNonPermissibleActions bitmask specifying the non-permissible actions for the entry |
|
421 * @param aDbflag Dbflag value for the new media entry |
|
422 */ |
|
423 static CMPXMedia* ConstructMediaLC(const TDesC& aTitle, TMPXGeneralType aType, |
|
424 TMPXGeneralCategory aCat, TMPXItemId aId, TInt aNonPermissibleActions, |
|
425 TUint aDbflag); |
|
426 }; |
|
427 |
|
428 #endif // MPXDBCOMMONUTIL_H |
|
429 |
|
430 // End of File |
|
431 |