author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:14:08 +0300 | |
branch | RCL_3 |
changeset 56 | 2cbbefa9af78 |
parent 53 | 3de6c4cf6b67 |
child 66 | 1f1dad4af8f8 |
permissions | -rw-r--r-- |
53 | 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 CMPXDbCommonUtil which contains utilities functions |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDE FILES |
|
20 |
#include <bautils.h> |
|
21 |
#include <caf/data.h> |
|
22 |
#include <caf/virtualpathptr.h> |
|
23 |
#include <hash.h> |
|
24 |
#include <apgcli.h> |
|
25 |
#include <apmstd.h> |
|
26 |
#include <sqldb.h> |
|
27 |
||
28 |
#include <mpxmediageneraldefs.h> |
|
29 |
#include <mpxmediamusicdefs.h> |
|
30 |
#include <mpxmediaaudiodefs.h> |
|
31 |
#include <mpxmediadrmdefs.h> |
|
32 |
#include <mpxmediacollectiondetaildefs.h> |
|
33 |
#include <mpxmedia.h> |
|
34 |
#include <mpxmediaarray.h> |
|
35 |
#include <mpxlog.h> |
|
36 |
||
37 |
#include "mpxdbcommonstd.h" |
|
38 |
#include "mpxdbcommondef.h" |
|
39 |
#include "mpxdbcommonutil.h" |
|
40 |
||
41 |
// CONSTANTS |
|
42 |
_LIT(KPathStart, ":\\"); |
|
43 |
||
44 |
// ============================ FILE EXTENSION TO MIME MAP ============================== |
|
45 |
||
46 |
// ---------------------------------------------------------------------------------------------------------- |
|
47 |
// Statically allocated Mime Map |
|
48 |
// ---------------------------------------------------------------------------------------------------------- |
|
49 |
// |
|
50 |
||
51 |
_LIT( KExtensionAac, "aac" ); |
|
52 |
_LIT( KExtensionAif, "aif"); |
|
53 |
_LIT( KExtensionAifc, "aifc"); |
|
54 |
_LIT( KExtensionAiff, "aiff"); |
|
55 |
_LIT( KExtensionAmr, "amr" ); |
|
56 |
_LIT( KExtensionAu, "au" ); |
|
57 |
_LIT( KExtensionAwb, "awb" ); |
|
58 |
_LIT( KExtensionMid, "mid" ); |
|
59 |
_LIT( KExtensionMidi, "midi" ); |
|
60 |
_LIT( KExtensionMka, "mka" ); |
|
61 |
_LIT( KExtensionMp3, "mp3" ); |
|
62 |
_LIT( KExtensionOgg, "ogg"); |
|
63 |
_LIT( KExtensionRa, "ra"); |
|
64 |
_LIT( KExtensionRam, "ram"); |
|
65 |
_LIT( KExtensionRmi, "rmi"); |
|
66 |
_LIT( KExtensionSnd, "snd" ); |
|
67 |
_LIT( KExtensionSpMid, "spmid" ); |
|
68 |
_LIT( KExtensionWav, "wav" ); |
|
69 |
_LIT( KExtensionWma, "wma" ); |
|
70 |
||
71 |
_LIT8( KMimeTypeAac, "audio/aac" ); |
|
72 |
_LIT8( KMimeTypeAiff, "audio/x-aiff"); |
|
73 |
_LIT8( KMimeTypeAmr, "audio/amr" ); |
|
74 |
_LIT8( KMimeTypeAu, "audio/au" ); |
|
75 |
_LIT8( KMimeTypeAwb, "audio/amr-wb" ); |
|
76 |
_LIT8( KMimeTypeBasic, "audio/basic"); |
|
77 |
_LIT8( KMimeTypeMatroska, "audio/x-matroska"); |
|
78 |
_LIT8( KMimeTypeMid, "audio/mid"); |
|
79 |
_LIT8( KMimeTypeMidi, "audio/midi" ); |
|
80 |
_LIT8( KMimeTypeMpeg, "audio/mpeg" ); |
|
81 |
_LIT8( KMimeTypeOgg, "audio/ogg"); |
|
82 |
_LIT8( KMimeTypeReal, "audio/x-pn-realaudio"); |
|
83 |
_LIT8( KMimeTypeSpMidi, "audio/sp-midi" ); |
|
84 |
_LIT8( KMimeTypeWav, "audio/wav" ); |
|
85 |
_LIT8( KMimeTypeWma, "audio/x-ms-wma"); |
|
86 |
||
87 |
struct TMimeMapItem { |
|
88 |
const TDesC * iExt; |
|
89 |
const TDesC8 * iType; |
|
90 |
}; |
|
91 |
||
92 |
// We need to explicitly cast here as LitC::operator& requires writable DLL data (even though it is just a cast) |
|
93 |
#define MIME_MAP_ITEM(ext,type) { &REINTERPRET_CAST(const TDesC&, ext), &REINTERPRET_CAST(const TDesC8&, type) } |
|
94 |
||
95 |
// THIS ARRAY MUST BE SORTED BY EXTENSION |
|
96 |
static const TMimeMapItem KMimeMap [] = { |
|
97 |
MIME_MAP_ITEM( KExtensionAac, KMimeTypeAac), |
|
98 |
MIME_MAP_ITEM( KExtensionAif, KMimeTypeAiff ), |
|
99 |
MIME_MAP_ITEM( KExtensionAifc, KMimeTypeAiff ), |
|
100 |
MIME_MAP_ITEM( KExtensionAiff, KMimeTypeAiff ), |
|
101 |
MIME_MAP_ITEM( KExtensionAmr, KMimeTypeAmr ), |
|
102 |
MIME_MAP_ITEM( KExtensionAu, KMimeTypeAu ), // KMimeTypeAudioBasic? "audio/x-au"? |
|
103 |
MIME_MAP_ITEM( KExtensionAwb, KMimeTypeAwb ), |
|
104 |
MIME_MAP_ITEM( KExtensionMid, KMimeTypeMidi ), |
|
105 |
MIME_MAP_ITEM( KExtensionMidi, KMimeTypeMidi ), |
|
106 |
MIME_MAP_ITEM( KExtensionMka, KMimeTypeMatroska ), |
|
107 |
MIME_MAP_ITEM( KExtensionMp3, KMimeTypeMpeg ), |
|
108 |
MIME_MAP_ITEM( KExtensionOgg, KMimeTypeOgg ), |
|
109 |
MIME_MAP_ITEM( KExtensionRa, KMimeTypeReal ), |
|
110 |
MIME_MAP_ITEM( KExtensionRam, KMimeTypeReal ), |
|
111 |
MIME_MAP_ITEM( KExtensionRmi, KMimeTypeMid ), |
|
112 |
MIME_MAP_ITEM( KExtensionSnd, KMimeTypeBasic ), |
|
113 |
MIME_MAP_ITEM( KExtensionSpMid, KMimeTypeSpMidi ), |
|
114 |
MIME_MAP_ITEM( KExtensionWav, KMimeTypeWav ), // "audio/x-wav"? |
|
115 |
MIME_MAP_ITEM( KExtensionWma, KMimeTypeWma ) |
|
116 |
}; |
|
117 |
||
118 |
// ---------------------------------------------------------------------------------------------------------- |
|
119 |
// Look for Mime Type from map by file extension |
|
120 |
// Returns NULL if file extension is not known |
|
121 |
// ---------------------------------------------------------------------------------------------------------- |
|
122 |
// |
|
123 |
static const TDesC8 * FindMimeTypeFromMap ( const TDesC& aFilename ) |
|
124 |
{ |
|
125 |
// extract extension |
|
126 |
TPtrC extension; |
|
127 |
TInt pos = aFilename.LocateReverseF( '.' ); |
|
128 |
if ( pos < 0 || ++pos >= aFilename.Length() ) |
|
129 |
{ |
|
130 |
return NULL; |
|
131 |
} |
|
132 |
extension.Set( aFilename.Mid( pos ) ); |
|
133 |
||
134 |
// binary search from Mime Map |
|
135 |
TUint begin = 0; |
|
136 |
TUint end = sizeof KMimeMap / sizeof (TMimeMapItem); |
|
137 |
while (begin < end) |
|
138 |
{ |
|
139 |
TUint at = (begin + end) / 2; |
|
140 |
const TMimeMapItem & item = KMimeMap[at]; |
|
141 |
TInt r = item.iExt->CompareF(extension); |
|
142 |
if (r == 0) |
|
143 |
{ |
|
144 |
return item.iType; |
|
145 |
} |
|
146 |
else if (r > 0) |
|
147 |
{ |
|
148 |
end = at; |
|
149 |
} |
|
150 |
else |
|
151 |
{ |
|
152 |
begin = at + 1; |
|
153 |
} |
|
154 |
} |
|
155 |
return NULL; |
|
156 |
} |
|
157 |
||
158 |
// ============================ MEMBER FUNCTIONS ============================== |
|
159 |
||
160 |
// ---------------------------------------------------------------------------------------------------------- |
|
161 |
// Set HBufC data member. |
|
162 |
// ---------------------------------------------------------------------------------------------------------- |
|
163 |
// |
|
164 |
EXPORT_C TInt MPXDbCommonUtil::SetHBuf( |
|
165 |
HBufC*& aBuf, |
|
166 |
const TDesC* aSource, |
|
167 |
TInt aMaxLen /*= -1*/) |
|
168 |
{ |
|
169 |
TInt ret( KErrNone ); |
|
170 |
delete aBuf; |
|
171 |
aBuf = NULL; |
|
172 |
||
173 |
if (aSource) |
|
174 |
{ |
|
175 |
if (aMaxLen != -1 && aSource->Length() > aMaxLen) |
|
176 |
{ |
|
177 |
aBuf = aSource->Left(aMaxLen).Alloc(); |
|
178 |
ret = KErrOverflow; |
|
179 |
} |
|
180 |
else |
|
181 |
{ |
|
182 |
aBuf = aSource->Alloc(); |
|
183 |
} |
|
184 |
} |
|
185 |
else |
|
186 |
{ |
|
187 |
aBuf = HBufC::New(0); |
|
188 |
} |
|
189 |
||
190 |
if (!aBuf) |
|
191 |
{ |
|
192 |
ret = KErrNoMemory; |
|
193 |
} |
|
194 |
||
195 |
return ret; |
|
196 |
} |
|
197 |
||
198 |
// ---------------------------------------------------------------------------------------------------------- |
|
199 |
// Replace single quotes `'` with two single quotes `''` as text queries are |
|
200 |
// delimited by single quotes |
|
201 |
// also replace 0x00 and '\t' as they will cause crash in SQLite and UI respectively |
|
202 |
// ---------------------------------------------------------------------------------------------------------- |
|
203 |
// |
|
204 |
EXPORT_C void MPXDbCommonUtil::FindAndReplaceSingleQuote(const TDesC& aSrc, TDes& aTrg) |
|
205 |
{ |
|
206 |
TText ch; |
|
207 |
TInt srcLen(aSrc.Length()); |
|
208 |
||
209 |
for (TInt i = 0; i < srcLen; ++i) |
|
210 |
{ |
|
211 |
ch = aSrc[i]; |
|
212 |
if((ch == 0) || (ch == TText('\t'))) |
|
213 |
{ |
|
214 |
aTrg.Append(TText(' ')); |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
aTrg.Append(ch); |
|
219 |
if (ch == TText('\'')) |
|
220 |
{ |
|
221 |
aTrg.Append(ch); |
|
222 |
} |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
// ---------------------------------------------------------------------------------------------------------- |
|
228 |
// Delete file from file system |
|
229 |
// ---------------------------------------------------------------------------------------------------------- |
|
230 |
// |
|
231 |
EXPORT_C TInt MPXDbCommonUtil::DeleteFile( |
|
232 |
RFs& aFs, |
|
233 |
const TDesC& aFile) |
|
234 |
{ |
|
235 |
TInt ret(KErrNone); |
|
236 |
if(BaflUtils::FileExists(aFs, aFile)) |
|
237 |
{ |
|
238 |
ret = aFs.Delete(aFile); |
|
239 |
||
240 |
if (ret == KErrAccessDenied) |
|
241 |
{ |
|
242 |
aFs.SetAtt(aFile,KEntryAttNormal,KEntryAttReadOnly); |
|
243 |
ret = aFs.Delete(aFile); |
|
244 |
} |
|
245 |
} |
|
246 |
return ret; |
|
247 |
} |
|
248 |
||
249 |
// ---------------------------------------------------------------------------------------------------------- |
|
250 |
// Get the drive Id with a given volume unique Id |
|
251 |
// ---------------------------------------------------------------------------------------------------------- |
|
252 |
// |
|
253 |
EXPORT_C TInt MPXDbCommonUtil::GetDriveIdMatchVolIdL( |
|
254 |
RFs& aFs, |
|
255 |
TUint aVolumeId) |
|
256 |
{ |
|
257 |
TDriveList driveList; |
|
258 |
TBool found(EFalse); |
|
259 |
TInt driveNum(EDriveA); |
|
260 |
||
261 |
User::LeaveIfError(aFs.DriveList(driveList)); |
|
262 |
for (; driveNum <= EDriveZ; ++driveNum) |
|
263 |
{ |
|
264 |
if (driveList[driveNum]) |
|
265 |
{ |
|
266 |
TVolumeInfo volInfo; |
|
267 |
||
268 |
if ((aFs.Volume(volInfo, driveNum) == KErrNone) && |
|
269 |
(volInfo.iUniqueID == aVolumeId)) |
|
270 |
{ |
|
271 |
found = ETrue; |
|
272 |
break; |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
if (!found) |
|
278 |
{ |
|
279 |
driveNum = KErrNotFound; |
|
280 |
} |
|
281 |
||
282 |
return driveNum; |
|
283 |
} |
|
284 |
||
285 |
// ---------------------------------------------------------------------------------------------------------- |
|
286 |
// Get the volume Id with a given drive Id |
|
287 |
// ---------------------------------------------------------------------------------------------------------- |
|
288 |
// |
|
289 |
EXPORT_C TUint MPXDbCommonUtil::GetVolIdMatchDriveIdL( |
|
290 |
RFs& aFs, |
|
291 |
TInt aDriveId) |
|
292 |
{ |
|
293 |
TUint volId (0); |
|
294 |
TVolumeInfo volInfo; |
|
295 |
TInt err = aFs.Volume(volInfo, aDriveId); |
|
296 |
if (err == KErrNone) |
|
297 |
{ |
|
298 |
volId = volInfo.iUniqueID; |
|
299 |
} |
|
300 |
else if (err == KErrNotReady) |
|
301 |
{ |
|
302 |
volId = 0; |
|
303 |
} |
|
304 |
else |
|
305 |
{ |
|
306 |
User::Leave(err); |
|
307 |
} |
|
308 |
||
309 |
return volId; |
|
310 |
} |
|
311 |
||
312 |
// ---------------------------------------------------------------------------- |
|
313 |
// Generate a 32bits Unique Id with MD5 |
|
314 |
// ---------------------------------------------------------------------------- |
|
315 |
// |
|
316 |
EXPORT_C TUint32 MPXDbCommonUtil::GenerateUniqueIdL( |
|
317 |
RFs& aFs, |
|
318 |
TMPXGeneralCategory aTableId, |
|
319 |
const TDesC& aName, |
|
320 |
TBool aCaseSensitive) |
|
321 |
{ |
|
322 |
MPX_FUNC("MPXDbCommonUtil::GenerateUniqueIdL"); |
|
323 |
||
324 |
TInt extractPos(0); |
|
325 |
||
326 |
if( aName.Find(KPathStart) == KMCPathStartWithColon ) |
|
327 |
{ |
|
328 |
// aName is a filename |
|
329 |
extractPos = KMCPathStartPos; // c:\..., include first '\' of the path |
|
330 |
} |
|
331 |
||
56
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
332 |
HBufC* fileNameBuf = HBufC::NewLC(aName.Length()+KMCIntegerLen); |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
333 |
TPtr fileName(fileNameBuf->Des()); |
53 | 334 |
if( extractPos ) |
335 |
{ |
|
336 |
// append volume's unique Id to path to maintain uniqueness |
|
337 |
TDriveUnit driveUnit( aName ); |
|
338 |
TUint volId = MPXDbCommonUtil::GetVolIdMatchDriveIdL(aFs, driveUnit); |
|
339 |
if( volId ) |
|
340 |
{ |
|
341 |
fileName.AppendNum( volId ); |
|
342 |
} |
|
343 |
else |
|
344 |
{ |
|
345 |
// If media/drive doesn't exist, using whole path |
|
346 |
extractPos = 0; |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
// append the path part |
|
351 |
fileName.Append( aName.Mid( extractPos ) ); |
|
352 |
||
353 |
if( !aCaseSensitive ) |
|
354 |
{ |
|
355 |
fileName.LowerCase(); |
|
356 |
} |
|
357 |
||
358 |
TInt narrowFileLen(0); |
|
359 |
TPtrC8 narrowFileName; |
|
360 |
#if defined(_UNICODE) |
|
56
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
361 |
narrowFileLen = fileNameBuf->Des().Length() * 2; |
53 | 362 |
narrowFileName.Set((TUint8*)fileName.Ptr(), narrowFileLen); |
363 |
#else |
|
364 |
narrowFileLen = fileName.Length(); |
|
365 |
narrowFileName.Set(fileName.Ptr(), narrowFileLen); |
|
366 |
#endif |
|
367 |
||
368 |
CMD5* hasher = CMD5::NewL(); |
|
369 |
CleanupStack::PushL( hasher ); |
|
370 |
hasher->Reset(); |
|
371 |
TBuf8<16> hash( hasher->Hash( narrowFileName ) ); //hashed to 128bits |
|
372 |
CleanupStack::PopAndDestroy( hasher ); |
|
373 |
||
374 |
const TText8* ptr = hash.Ptr(); |
|
375 |
||
376 |
TUint32 uniqueId(0); |
|
377 |
uniqueId = aTableId << 28; |
|
378 |
uniqueId |= (ptr[3]&0x0F)<<24 | (ptr[2]<<16) | (ptr[1]<<8) | ptr[0]; |
|
56
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
379 |
|
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
380 |
CleanupStack::PopAndDestroy(fileNameBuf); |
2cbbefa9af78
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
381 |
|
53 | 382 |
return uniqueId; |
383 |
} |
|
384 |
||
385 |
// --------------------------------------------------------------------------- |
|
386 |
// Append an item into the media array |
|
387 |
// --------------------------------------------------------------------------- |
|
388 |
// |
|
389 |
EXPORT_C void MPXDbCommonUtil::AppendMediaL( |
|
390 |
CMPXMediaArray& aArray, |
|
391 |
const TDesC& aTitle, |
|
392 |
TMPXGeneralType aType, |
|
393 |
TMPXGeneralCategory aCat, |
|
394 |
TMPXItemId aId, |
|
395 |
TInt aNonPermissibleActions, |
|
396 |
TUint aDbflag) |
|
397 |
{ |
|
398 |
MPX_FUNC("MPXDbCommonUtil::AppendMediaL"); |
|
399 |
||
400 |
CMPXMedia* entry = ConstructMediaLC(aTitle, aType, aCat, aId, aNonPermissibleActions, aDbflag); |
|
401 |
aArray.AppendL(*entry); |
|
402 |
CleanupStack::PopAndDestroy(entry); |
|
403 |
} |
|
404 |
||
405 |
// ---------------------------------------------------------------------------- |
|
406 |
// Append an item into the media array |
|
407 |
// ---------------------------------------------------------------------------- |
|
408 |
// |
|
409 |
EXPORT_C void MPXDbCommonUtil::PrependMediaL( |
|
410 |
CMPXMediaArray& aArray, |
|
411 |
const TDesC& aTitle, |
|
412 |
TMPXGeneralType aType, |
|
413 |
TMPXGeneralCategory aCat, |
|
414 |
TMPXItemId aId /* = 0 */, |
|
415 |
TInt aNonPermissibleActions /* = 0 */, |
|
416 |
TUint aDbflag /* = 0 */, |
|
417 |
TInt aPos /* = 0 */) |
|
418 |
{ |
|
419 |
MPX_FUNC("MPXDbCommonUtil::PrependMediaL"); |
|
420 |
||
421 |
CMPXMedia* entry = ConstructMediaLC(aTitle, aType, aCat, aId, aNonPermissibleActions, aDbflag); |
|
422 |
User::LeaveIfError(aArray.Insert(*entry, aPos)); |
|
423 |
CleanupStack::PopAndDestroy(entry); |
|
424 |
} |
|
425 |
||
426 |
// ---------------------------------------------------------------------------- |
|
427 |
// Append an item into the media array |
|
428 |
// ---------------------------------------------------------------------------- |
|
429 |
// |
|
430 |
EXPORT_C void MPXDbCommonUtil::FillInSupportedUIDsL( |
|
431 |
const TArray<TMPXAttribute>& aAttrs, |
|
432 |
RArray<TInt>& aSupportedIds) |
|
433 |
{ |
|
434 |
MPX_FUNC("MPXDbCommonUtil::FillInSupportedUIDs"); |
|
435 |
||
436 |
TInt attrCount(aAttrs.Count()); |
|
437 |
for (TInt i = 0; i < attrCount; ++i) |
|
438 |
{ |
|
439 |
if (aAttrs[i].ContentId() == KMPXMediaIdGeneral) |
|
440 |
{ |
|
441 |
aSupportedIds.AppendL(KMPXMediaIdGeneral); |
|
442 |
} |
|
443 |
else if (aAttrs[i].ContentId() == KMPXMediaIdMusic) |
|
444 |
{ |
|
445 |
aSupportedIds.AppendL(KMPXMediaIdMusic); |
|
446 |
} |
|
447 |
else if (aAttrs[i].ContentId() == KMPXMediaIdAudio) |
|
448 |
{ |
|
449 |
aSupportedIds.AppendL(KMPXMediaIdAudio); |
|
450 |
} |
|
451 |
else if (aAttrs[i].ContentId() == KMPXMediaIdDrm) |
|
452 |
{ |
|
453 |
aSupportedIds.AppendL(KMPXMediaIdDrm); |
|
454 |
} |
|
455 |
else if (aAttrs[i].ContentId() == KMPXMediaIdCollectionDetails) |
|
456 |
{ |
|
457 |
aSupportedIds.AppendL(KMPXMediaIdCollectionDetails); |
|
458 |
} |
|
459 |
else |
|
460 |
{ |
|
461 |
// ignore attribute |
|
462 |
} |
|
463 |
} |
|
464 |
} |
|
465 |
||
466 |
// ---------------------------------------------------------------------------- |
|
467 |
// Fill in change event message with the given info |
|
468 |
// ---------------------------------------------------------------------------- |
|
469 |
// |
|
470 |
EXPORT_C void MPXDbCommonUtil::FillItemChangedMessageL( |
|
471 |
CMPXMessage& aMessage, |
|
472 |
TMPXItemId aId, |
|
473 |
TMPXChangeEventType aChangeType, |
|
474 |
TMPXGeneralCategory aCategory, |
|
475 |
TUint aUid, |
|
476 |
TMPXItemId aDeprecatedId) |
|
477 |
{ |
|
478 |
MPX_FUNC("MPXDbCommonUtil::FillItemChangedMessageL"); |
|
479 |
MPX_DEBUG5("MPXDbCommonUtil::FillItemChangedMessageL: type [%d], category [%d], id[0x%x], oldId[0x%x]", |
|
480 |
aChangeType, aCategory, aId.iId1, aDeprecatedId.iId1); |
|
481 |
||
482 |
aMessage.SetTObjectValueL<TMPXMessageId>(KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
483 |
aMessage.SetTObjectValueL<TUid>(KMPXMessageCollectionId, TUid::Uid(aUid)); |
|
484 |
aMessage.SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, aChangeType); |
|
485 |
aMessage.SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, aCategory); |
|
486 |
aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, aId); |
|
487 |
||
488 |
if ((aDeprecatedId != 0) && (aId != aDeprecatedId)) |
|
489 |
{ |
|
490 |
aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aDeprecatedId); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
// ---------------------------------------------------------------------------- |
|
495 |
// Add an item changed message to the message array |
|
496 |
// ---------------------------------------------------------------------------- |
|
497 |
// |
|
498 |
EXPORT_C void MPXDbCommonUtil::AddItemChangedMessageL( |
|
499 |
CMPXMessageArray& aMessageArray, |
|
500 |
TMPXItemId aId, |
|
501 |
TMPXChangeEventType aChangeType, |
|
502 |
TMPXGeneralCategory aCategory, |
|
503 |
TUint aUid, |
|
504 |
TMPXItemId aDeprecatedId /* = 0 */) |
|
505 |
{ |
|
506 |
MPX_FUNC("MPXDbCommonUtil::AddItemChangedMessageL"); |
|
507 |
CMPXMessage* message = CMPXMedia::NewL(); |
|
508 |
CleanupStack::PushL(message); |
|
509 |
||
510 |
FillItemChangedMessageL(*message, aId, aChangeType, aCategory, aUid, aDeprecatedId); |
|
511 |
if (FindItemChangedMessageL(aMessageArray, *message) == KErrNotFound) |
|
512 |
{ |
|
513 |
aMessageArray.AppendL(*message); // ownership xfer |
|
514 |
} |
|
515 |
CleanupStack::PopAndDestroy(message); |
|
516 |
} |
|
517 |
||
518 |
// ---------------------------------------------------------------------------- |
|
519 |
// Find the message in the array, if not KErrNotFound is returned; otherwise the |
|
520 |
// index of the first matching message is returned |
|
521 |
// ---------------------------------------------------------------------------- |
|
522 |
// |
|
523 |
EXPORT_C TInt MPXDbCommonUtil::FindItemChangedMessageL( |
|
524 |
const CMPXMessageArray& aMessageArray, |
|
525 |
const CMPXMessage& aMessage) |
|
526 |
{ |
|
527 |
MPX_FUNC("MPXDbCommonUtil::FindItemChangedMessageL"); |
|
528 |
||
529 |
TInt index(KErrNotFound); |
|
530 |
TInt messageCount(aMessageArray.Count()); |
|
531 |
||
532 |
for (TInt i = 0; i < messageCount; ++i) |
|
533 |
{ |
|
534 |
CMPXMessage* message = aMessageArray.AtL(i); |
|
535 |
||
536 |
if (message->IsSupported(KMPXMessageGeneralId) && |
|
537 |
message->IsSupported(KMPXMessageCollectionId) && |
|
538 |
message->IsSupported(KMPXMessageChangeEventType) && |
|
539 |
message->IsSupported(KMPXMessageMediaGeneralCategory) && |
|
540 |
message->IsSupported(KMPXMessageMediaGeneralId) && |
|
541 |
aMessage.IsSupported(KMPXMessageGeneralId) && |
|
542 |
aMessage.IsSupported(KMPXMessageCollectionId) && |
|
543 |
aMessage.IsSupported(KMPXMessageChangeEventType) && |
|
544 |
aMessage.IsSupported(KMPXMessageMediaGeneralCategory) && |
|
545 |
aMessage.IsSupported(KMPXMessageMediaGeneralId)) |
|
546 |
{ |
|
547 |
if (message->ValueTObjectL<TMPXMessageId>(KMPXMessageGeneralId) == aMessage.ValueTObjectL<TMPXMessageId>(KMPXMessageGeneralId) && |
|
548 |
message->ValueTObjectL<TUid>(KMPXMessageCollectionId) == aMessage.ValueTObjectL<TUid>(KMPXMessageCollectionId) && |
|
549 |
message->ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType) == aMessage.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType) && |
|
550 |
message->ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory) == aMessage.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory) && |
|
551 |
message->ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId) == aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId)) |
|
552 |
{ |
|
553 |
if (!message->IsSupported(KMPXMessageMediaDeprecatedId) && |
|
554 |
!aMessage.IsSupported(KMPXMessageMediaDeprecatedId)) |
|
555 |
{ |
|
556 |
index = i; |
|
557 |
break; |
|
558 |
} |
|
559 |
else if (message->IsSupported(KMPXMessageMediaDeprecatedId) && |
|
560 |
aMessage.IsSupported(KMPXMessageMediaDeprecatedId)) |
|
561 |
{ |
|
562 |
if (message->ValueTObjectL<TMPXItemId>(KMPXMessageMediaDeprecatedId) == |
|
563 |
aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaDeprecatedId)) |
|
564 |
{ |
|
565 |
index = i; |
|
566 |
break; |
|
567 |
} |
|
568 |
} |
|
569 |
else |
|
570 |
{ |
|
571 |
// else do nothing |
|
572 |
} |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
return index; |
|
578 |
} |
|
579 |
||
580 |
// ---------------------------------------------------------------------------- |
|
581 |
// Get the DRM protection type of the file |
|
582 |
// ---------------------------------------------------------------------------- |
|
583 |
// |
|
584 |
EXPORT_C TMCDrmType MPXDbCommonUtil::GetDRMTypeL(const TDesC& aFile) |
|
585 |
{ |
|
586 |
MPX_FUNC("MPXDbCommonUtil::GetDRMTypeL"); |
|
587 |
||
588 |
using namespace ContentAccess; |
|
589 |
TInt drmProtected(0); |
|
590 |
TVirtualPathPtr virtualPath(aFile, KDefaultContentObject); |
|
591 |
CData* content = CData::NewL(virtualPath, EPeek, EContentShareReadOnly); |
|
592 |
CleanupStack::PushL(content); |
|
593 |
User::LeaveIfError(content->GetAttribute(EIsProtected, drmProtected)); |
|
594 |
CleanupStack::PopAndDestroy( content ); |
|
595 |
return drmProtected? EMCDrmOmaDrm : EMCDrmNone; |
|
596 |
} |
|
597 |
||
598 |
// ---------------------------------------------------------------------------- |
|
599 |
// MPXDbUtil::ProcessSingleQuotesLC |
|
600 |
// ---------------------------------------------------------------------------- |
|
601 |
// |
|
602 |
EXPORT_C HBufC* MPXDbCommonUtil::ProcessSingleQuotesLC( |
|
603 |
const TDesC& aString) |
|
604 |
{ |
|
605 |
MPX_FUNC("MPXDbCommonUtil::ProcessSingleQuotesLC"); |
|
606 |
||
607 |
// reserve space for all single quotes (double the size) |
|
608 |
HBufC* value = HBufC::NewLC(aString.Length() * 2); |
|
609 |
TPtr valuePtr(value->Des()); |
|
610 |
||
611 |
MPXDbCommonUtil::FindAndReplaceSingleQuote(aString, valuePtr); |
|
612 |
||
613 |
return value; |
|
614 |
} |
|
615 |
||
616 |
// ---------------------------------------------------------------------------- |
|
617 |
// MPXDbUtil::ProcessPatternCharsLC |
|
618 |
// 1) a percentage needs to be escaped for sqlite followed by |
|
619 |
// another percentage sign for escaping % for descriptor formatting, i.e. |
|
620 |
// % --> %% (this percentage will be treated as a percentage instead of |
|
621 |
// pattern matching) |
|
622 |
// 2) since back slash is used for escaping the pattern characters, user |
|
623 |
// specified back slash should be escapped as well, i.e. \ --> \\ |
|
624 |
// ---------------------------------------------------------------------------- |
|
625 |
// |
|
626 |
EXPORT_C HBufC* MPXDbCommonUtil::ProcessPatternCharsLC( |
|
627 |
const TDesC& aString) |
|
628 |
{ |
|
629 |
MPX_FUNC("MPXDbCommonUtil::ProcessPatternCharsLC"); |
|
630 |
||
631 |
// reserve space for all percentage signs (triple the size because % should |
|
632 |
// be replaced by %%) |
|
633 |
TInt srcLen(aString.Length()); |
|
634 |
HBufC* targetString = HBufC::NewLC(aString.Length() * 3); |
|
635 |
TPtr targetStringPtr(targetString->Des()); |
|
636 |
||
637 |
TPtrC ch; |
|
638 |
for (TInt i = 0; i < srcLen; ++i) |
|
639 |
{ |
|
640 |
ch.Set(&aString[i], 1); |
|
641 |
if (ch.CompareF(KMCPercentage) == 0) |
|
642 |
{ |
|
643 |
targetStringPtr.Append(KMCPercentage); |
|
644 |
} |
|
645 |
else if ( ch.CompareF( KMCBackSlash ) == 0 ) |
|
646 |
{ |
|
647 |
targetStringPtr.Append(KMCBackSlash); |
|
648 |
} |
|
649 |
targetStringPtr.Append(ch); |
|
650 |
} |
|
651 |
||
652 |
MPX_DEBUG3(" original=%S, new=%S", &aString, targetString); |
|
653 |
||
654 |
return targetString; |
|
655 |
} |
|
656 |
||
657 |
// ---------------------------------------------------------------------------- |
|
658 |
// Constructs an int SQL criterion |
|
659 |
// ---------------------------------------------------------------------------- |
|
660 |
// |
|
661 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
662 |
const TDesC& aCriterion, |
|
663 |
TInt aValue) |
|
664 |
{ |
|
665 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC"); |
|
666 |
||
667 |
HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + KMCIntegerLen); |
|
668 |
TPtr ptr = sqlCriterion->Des(); |
|
669 |
ptr.Format(aCriterion, aValue); |
|
670 |
return sqlCriterion; |
|
671 |
} |
|
672 |
||
673 |
// ---------------------------------------------------------------------------- |
|
674 |
// Constructs an int64 SQL criterion |
|
675 |
// ---------------------------------------------------------------------------- |
|
676 |
// |
|
677 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterion64LC( |
|
678 |
const TDesC& aCriterion, |
|
679 |
TInt64 aValue) |
|
680 |
{ |
|
681 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterion64LC"); |
|
682 |
||
683 |
HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + KMCInt64Len); |
|
684 |
TPtr ptr = sqlCriterion->Des(); |
|
685 |
ptr.Format(aCriterion, aValue); |
|
686 |
return sqlCriterion; |
|
687 |
} |
|
688 |
||
689 |
// ---------------------------------------------------------------------------- |
|
690 |
// Constructs an SQL criterion using two int values |
|
691 |
// ---------------------------------------------------------------------------- |
|
692 |
// |
|
693 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
694 |
const TDesC& aCriterion, |
|
695 |
TInt aValue1, |
|
696 |
TInt aValue2) |
|
697 |
{ |
|
698 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 2"); |
|
699 |
||
700 |
HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + 2 * KMCIntegerLen); |
|
701 |
TPtr ptr = sqlCriterion->Des(); |
|
702 |
ptr.Format(aCriterion, aValue1, aValue2); |
|
703 |
return sqlCriterion; |
|
704 |
} |
|
705 |
||
706 |
// ---------------------------------------------------------------------------- |
|
707 |
// Constructs an SQL criterion using two int64 values |
|
708 |
// ---------------------------------------------------------------------------- |
|
709 |
// |
|
710 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterion64LC( |
|
711 |
const TDesC& aCriterion, |
|
712 |
TInt64 aValue1, |
|
713 |
TInt64 aValue2) |
|
714 |
{ |
|
715 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterion64LC 2"); |
|
716 |
||
717 |
HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + 2 * KMCInt64Len); |
|
718 |
TPtr ptr = sqlCriterion->Des(); |
|
719 |
ptr.Format(aCriterion, aValue1, aValue2); |
|
720 |
return sqlCriterion; |
|
721 |
} |
|
722 |
||
723 |
// ---------------------------------------------------------------------------- |
|
724 |
// Constructs a descriptor SQL criterion |
|
725 |
// ---------------------------------------------------------------------------- |
|
726 |
// |
|
727 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
728 |
const TDesC& aCriterion, |
|
729 |
const TDesC& aValue) |
|
730 |
{ |
|
731 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 3"); |
|
732 |
||
733 |
HBufC* value = ProcessSingleQuotesLC(aValue); |
|
734 |
||
735 |
HBufC* sqlCriterion = HBufC::NewL(aCriterion.Length() + value->Length()); |
|
736 |
TPtr ptr(sqlCriterion->Des()); |
|
737 |
ptr.Format(aCriterion, value); |
|
738 |
||
739 |
CleanupStack::PopAndDestroy(value); |
|
740 |
CleanupStack::PushL(sqlCriterion); |
|
741 |
return sqlCriterion; |
|
742 |
} |
|
743 |
||
744 |
// ---------------------------------------------------------------------------- |
|
745 |
// Constructs a descriptor SQL criterion |
|
746 |
// ---------------------------------------------------------------------------- |
|
747 |
// |
|
748 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
749 |
const TDesC& aCriterion, |
|
750 |
const TDesC& aValue1, |
|
751 |
const TDesC& aValue2) |
|
752 |
{ |
|
753 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 3"); |
|
754 |
||
755 |
HBufC* value1 = ProcessSingleQuotesLC(aValue1); |
|
756 |
HBufC* value2 = ProcessSingleQuotesLC(aValue2); |
|
757 |
||
758 |
HBufC* sqlCriterion = HBufC::NewL(aCriterion.Length() + |
|
759 |
value1->Length() + |
|
760 |
value2->Length()); |
|
761 |
TPtr ptr(sqlCriterion->Des()); |
|
762 |
ptr.Format(aCriterion, value1, value2); |
|
763 |
||
764 |
CleanupStack::PopAndDestroy(value2); |
|
765 |
CleanupStack::PopAndDestroy(value1); |
|
766 |
CleanupStack::PushL(sqlCriterion); |
|
767 |
return sqlCriterion; |
|
768 |
} |
|
769 |
||
770 |
// ---------------------------------------------------------------------------- |
|
771 |
// Constructs a descriptor SQL criterion |
|
772 |
// ---------------------------------------------------------------------------- |
|
773 |
// |
|
774 |
EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
775 |
const TDesC& aCriterion, |
|
776 |
const TDesC& aValue1, |
|
777 |
TInt aValue2, |
|
778 |
const TDesC& aValue3, |
|
779 |
TInt aValue4) |
|
780 |
{ |
|
781 |
MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 3"); |
|
782 |
||
783 |
HBufC* value1 = ProcessSingleQuotesLC(aValue1); |
|
784 |
HBufC* value3 = ProcessSingleQuotesLC(aValue3); |
|
785 |
||
786 |
HBufC* sqlCriterion = HBufC::NewL(aCriterion.Length() + |
|
787 |
value1->Length() + |
|
788 |
value3->Length() + |
|
789 |
2 * KMCIntegerLen); |
|
790 |
TPtr ptr(sqlCriterion->Des()); |
|
791 |
ptr.Format(aCriterion, value1, aValue2, value3, aValue4); |
|
792 |
||
793 |
CleanupStack::PopAndDestroy(value3); |
|
794 |
CleanupStack::PopAndDestroy(value1); |
|
795 |
CleanupStack::PushL(sqlCriterion); |
|
796 |
return sqlCriterion; |
|
797 |
} |
|
798 |
||
799 |
// ---------------------------------------------------------------------------- |
|
800 |
// Constructs and adds an int SQL criterion to the criteria array |
|
801 |
// ---------------------------------------------------------------------------- |
|
802 |
// |
|
803 |
EXPORT_C TInt MPXDbCommonUtil::AddSqlCriterionL( |
|
804 |
CDesCArray& aSqlCriteria, |
|
805 |
const TDesC& aCriterion, |
|
806 |
TInt aValue) |
|
807 |
{ |
|
808 |
MPX_FUNC("MPXDbCommonUtil::AddSqlCriterionL"); |
|
809 |
||
810 |
HBufC* sqlCriterion = SqlCriterionLC(aCriterion, aValue); |
|
811 |
TInt length = sqlCriterion->Length(); |
|
812 |
aSqlCriteria.AppendL(*sqlCriterion); |
|
813 |
CleanupStack::PopAndDestroy(sqlCriterion); |
|
814 |
return length; |
|
815 |
} |
|
816 |
||
817 |
// ---------------------------------------------------------------------------- |
|
818 |
// Constructs and adds a string SQL criterion to the criteria array |
|
819 |
// ---------------------------------------------------------------------------- |
|
820 |
// |
|
821 |
EXPORT_C TInt MPXDbCommonUtil::AddSqlCriterionL( |
|
822 |
CDesCArray& aSqlCriteria, |
|
823 |
const TDesC& aCriterion, |
|
824 |
const TDesC& aValue) |
|
825 |
{ |
|
826 |
MPX_FUNC("MPXDbCommonUtil::AddSqlCriterionL"); |
|
827 |
||
828 |
HBufC* sqlCriterion = SqlCriterionLC(aCriterion, aValue); |
|
829 |
TInt length = sqlCriterion->Length(); |
|
830 |
aSqlCriteria.AppendL(*sqlCriterion); |
|
831 |
CleanupStack::PopAndDestroy(sqlCriterion); |
|
832 |
return length; |
|
833 |
} |
|
834 |
||
835 |
||
836 |
// ---------------------------------------------------------------------------- |
|
837 |
// Create a full path with input drive Id and path |
|
838 |
// ---------------------------------------------------------------------------- |
|
839 |
// |
|
840 |
EXPORT_C HBufC* MPXDbCommonUtil::CreateFullPathL( |
|
841 |
TInt aDriveId, |
|
842 |
const TDesC& aPath) |
|
843 |
{ |
|
844 |
MPX_FUNC("MPXDbCommonUtil::CreateFullPathL"); |
|
845 |
||
846 |
HBufC* hbuf = HBufC::NewLC(aPath.Length() + KMaxDriveName); |
|
847 |
TPtr fullPath(hbuf->Des()); |
|
848 |
||
849 |
if (aDriveId != KErrNotFound) |
|
850 |
{ |
|
851 |
TDriveUnit driveUnit(aDriveId); |
|
852 |
fullPath.Copy(driveUnit.Name()); |
|
853 |
} |
|
854 |
||
855 |
fullPath.Append(aPath); |
|
856 |
CleanupStack::Pop(hbuf); |
|
857 |
return hbuf; |
|
858 |
} |
|
859 |
||
860 |
// ---------------------------------------------------------------------------- |
|
861 |
// MPXDbCommonUtil::AppendValueL |
|
862 |
// ---------------------------------------------------------------------------- |
|
863 |
// |
|
864 |
EXPORT_C void MPXDbCommonUtil::AppendValueL( |
|
865 |
CDesCArray& aFields, |
|
866 |
CDesCArray& aValues, |
|
867 |
const TDesC& aField, |
|
868 |
const TDesC& aValue) |
|
869 |
{ |
|
870 |
MPX_FUNC("MPXDbCommonUtil::AppendValueL"); |
|
871 |
||
872 |
aFields.AppendL(aField); |
|
873 |
||
874 |
HBufC* value = HBufC::NewLC(aValue.Length() * 2 + 2); |
|
875 |
TPtr valuePtr(value->Des()); |
|
876 |
||
877 |
MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue, valuePtr); |
|
878 |
||
879 |
// use 'value' instead of value, 0 length strings should be '' |
|
880 |
// |
|
881 |
if( valuePtr.Length() ) |
|
882 |
{ |
|
883 |
valuePtr.Insert(0, KMCSingleQuote); |
|
884 |
valuePtr.Append(KMCSingleQuote); |
|
885 |
} |
|
886 |
else |
|
887 |
{ |
|
888 |
valuePtr.Append(KMCSingleQuote); |
|
889 |
valuePtr.Append(KMCSingleQuote); |
|
890 |
} |
|
891 |
aValues.AppendL(valuePtr); |
|
892 |
||
893 |
CleanupStack::PopAndDestroy(value); |
|
894 |
} |
|
895 |
||
896 |
// ---------------------------------------------------------------------------- |
|
897 |
// MPXDbCommonUtil::AppendValueL |
|
898 |
// ---------------------------------------------------------------------------- |
|
899 |
// |
|
900 |
EXPORT_C void MPXDbCommonUtil::AppendValueL( |
|
901 |
CDesCArray& aFields, |
|
902 |
CDesCArray& aValues, |
|
903 |
const TDesC& aField, |
|
904 |
TUint32 aValue) |
|
905 |
{ |
|
906 |
MPX_FUNC("MPXDbCommonUtil::AppendValueL"); |
|
907 |
||
908 |
aFields.AppendL(aField); |
|
909 |
TBuf<KMCIntegerLen> value; |
|
910 |
value.AppendNum(static_cast<TInt64>(aValue)); |
|
911 |
aValues.AppendL(value); |
|
912 |
} |
|
913 |
||
914 |
// ---------------------------------------------------------------------------- |
|
915 |
// Gets the MIME type for a specified URI |
|
916 |
// ---------------------------------------------------------------------------- |
|
917 |
// |
|
918 |
EXPORT_C TDataType MPXDbCommonUtil::GetMimeTypeForUriL( |
|
919 |
const TDesC& aUri) |
|
920 |
{ |
|
921 |
MPX_FUNC("MPXDbUtil::GetMimeTypeForUriL"); |
|
922 |
||
923 |
if ( const TDesC8 * type = FindMimeTypeFromMap (aUri) ) |
|
924 |
{ |
|
925 |
return TDataType(*type); |
|
926 |
} |
|
927 |
||
928 |
RApaLsSession appArc; |
|
929 |
User::LeaveIfError(appArc.Connect()); |
|
930 |
CleanupClosePushL(appArc); |
|
931 |
TUid dummyUid(KNullUid); |
|
932 |
TDataType mimeType; |
|
933 |
appArc.AppForDocument(aUri, dummyUid, mimeType); |
|
934 |
CleanupStack::PopAndDestroy(&appArc); |
|
935 |
||
936 |
return mimeType; |
|
937 |
} |
|
938 |
||
939 |
// ---------------------------------------------------------------------------- |
|
940 |
// MPXDbCommonUtil::StringFromArrayLC |
|
941 |
// ---------------------------------------------------------------------------- |
|
942 |
// |
|
943 |
EXPORT_C HBufC* MPXDbCommonUtil::StringFromArrayLC( |
|
944 |
const CDesCArray& aArray, |
|
945 |
const TDesC& aSeparator) |
|
946 |
{ |
|
947 |
MPX_FUNC("MPXDbCommonUtil::StringFromArrayLC"); |
|
948 |
||
949 |
HBufC* str(NULL); |
|
950 |
TInt count(aArray.Count()); |
|
951 |
if (count) |
|
952 |
{ |
|
953 |
TInt len(0); |
|
954 |
TInt index(0); |
|
955 |
for (index = 0; index < count; ++index) |
|
956 |
{ |
|
957 |
len += aArray[index].Length(); |
|
958 |
} |
|
959 |
||
960 |
str = HBufC::NewLC(len + (aSeparator.Length() * (count - 1))); |
|
961 |
TPtr ptr(str->Des()); |
|
962 |
TPtrC16 item; |
|
963 |
for (index = 0; index < count; ++index) |
|
964 |
{ |
|
965 |
item.Set(aArray[index]); |
|
966 |
ptr.Append(item); |
|
967 |
MPX_DEBUG2("aArray[index] %S", &item); |
|
968 |
if (index < (count - 1)) |
|
969 |
{ |
|
970 |
ptr.Append(aSeparator); |
|
971 |
} |
|
972 |
} |
|
973 |
} |
|
974 |
else |
|
975 |
{ |
|
976 |
str = HBufC::NewLC(0); |
|
977 |
} |
|
978 |
||
979 |
return str; |
|
980 |
} |
|
981 |
||
982 |
// ---------------------------------------------------------------------------- |
|
983 |
// MPXDbCommonUtil::StringFromArraysLC |
|
984 |
// ---------------------------------------------------------------------------- |
|
985 |
// |
|
986 |
EXPORT_C HBufC* MPXDbCommonUtil::StringFromArraysLC( |
|
987 |
const CDesCArray& aNameArray, |
|
988 |
const CDesCArray& aValueArray, |
|
989 |
const TDesC& aValueSeparator, |
|
990 |
const TDesC& aEntitySeparator) |
|
991 |
{ |
|
992 |
MPX_FUNC("MPXDbCommonUtil::StringFromArraysLC"); |
|
993 |
||
994 |
// calculate the length of the SET string |
|
995 |
TInt len(0); |
|
996 |
TInt index(0); |
|
997 |
TInt count(aNameArray.Count()); |
|
998 |
for (index = 0; index < count; ++index) |
|
999 |
{ |
|
1000 |
len += aNameArray[index].Length() + aValueArray[index].Length(); |
|
1001 |
} |
|
1002 |
||
1003 |
// construct the result string |
|
1004 |
HBufC* result = HBufC::NewLC(len + |
|
1005 |
((aValueSeparator.Length() + aEntitySeparator.Length()) * count)); |
|
1006 |
TPtr resultPtr(result->Des()); |
|
1007 |
for (index = 0; index < count; ++index) |
|
1008 |
{ |
|
1009 |
resultPtr.Append(aNameArray[index]); |
|
1010 |
resultPtr.Append(aValueSeparator); |
|
1011 |
resultPtr.Append(aValueArray[index]); |
|
1012 |
||
1013 |
if (index < count - 1) |
|
1014 |
{ |
|
1015 |
resultPtr.Append(aEntitySeparator); |
|
1016 |
} |
|
1017 |
} |
|
1018 |
||
1019 |
return result; |
|
1020 |
} |
|
1021 |
||
1022 |
// ---------------------------------------------------------------------------- |
|
1023 |
// MPXDbCommonUtil::TTimeToDesLC |
|
1024 |
// Converts a TTime to the internal SQLite format (YYYY-MM-DD HH:MM:SS). |
|
1025 |
// ---------------------------------------------------------------------------- |
|
1026 |
// |
|
1027 |
EXPORT_C HBufC* MPXDbCommonUtil::TTimeToDesLC( |
|
1028 |
const TTime& aTime) |
|
1029 |
{ |
|
1030 |
MPX_FUNC("MPXDbCommonUtil::TTimeToDesLC"); |
|
1031 |
||
1032 |
HBufC* dateTime; |
|
1033 |
if (aTime == Time::NullTTime()) |
|
1034 |
{ |
|
1035 |
dateTime = HBufC::NewLC(0); |
|
1036 |
} |
|
1037 |
else |
|
1038 |
{ |
|
1039 |
_LIT(KDateTimeFormat, "%04d-%02d-%02d %02d:%02d:%02d"); |
|
1040 |
||
1041 |
TTime time(0); |
|
1042 |
||
1043 |
// negative time means BC, but format string will be invalid with our format, |
|
1044 |
// i.e. %04d in KDateTimeFormat when year is -1 will result in "00-1" and |
|
1045 |
// the whole string becomes "00-1-01-01 00:00:00" which will result in error, |
|
1046 |
// so set to 0 in such cases |
|
1047 |
TDateTime dt = aTime>time ? aTime.DateTime() : time.DateTime(); |
|
1048 |
TInt dateTimeLen = KDateTimeFormat().Length(); |
|
1049 |
dateTime = HBufC::NewLC(dateTimeLen); |
|
1050 |
TPtr dateTimePtr = dateTime->Des(); |
|
1051 |
dateTimePtr.Format(KDateTimeFormat, |
|
1052 |
dt.Year(), |
|
1053 |
dt.Month() + 1, // zero based |
|
1054 |
dt.Day() + 1, // zero based |
|
1055 |
dt.Hour(), |
|
1056 |
dt.Minute(), |
|
1057 |
dt.Second()); |
|
1058 |
} |
|
1059 |
return dateTime; |
|
1060 |
} |
|
1061 |
||
1062 |
// ---------------------------------------------------------------------------- |
|
1063 |
// MPXDbCommonUtil::DesToTTimeL |
|
1064 |
// Converts a date time string in the internal SQLite format (YYYY-MM-DD HH:MM:SS) |
|
1065 |
// to a TTime. TTime can only parse in the DD-MM-YYYY HH:MM:SS format. |
|
1066 |
// ---------------------------------------------------------------------------- |
|
1067 |
// |
|
1068 |
EXPORT_C TTime MPXDbCommonUtil::DesToTTimeL( |
|
1069 |
const TDesC& aDateTime) |
|
1070 |
{ |
|
1071 |
MPX_FUNC("MPXDbCommonUtil::DesToTTimeL"); |
|
1072 |
||
1073 |
TTime time(0); |
|
1074 |
if (aDateTime.Length() != 0) |
|
1075 |
{ |
|
1076 |
_LIT(KDash, "-"); |
|
1077 |
_LIT(KSpace, " "); |
|
1078 |
||
1079 |
TLocale locale; |
|
1080 |
TDateFormat iDateFormat = locale.DateFormat(); |
|
1081 |
||
1082 |
HBufC* dateTime = HBufC::NewLC(aDateTime.Length()); |
|
1083 |
TPtr dateTimePtr = dateTime->Des(); |
|
1084 |
||
1085 |
//as TTime::Parse is locale dependent, check it: |
|
1086 |
if(iDateFormat==EDateEuropean) |
|
1087 |
{ |
|
1088 |
dateTimePtr.Append(aDateTime.Mid(8, 2));//day DD |
|
1089 |
dateTimePtr.Append(KDash); |
|
1090 |
dateTimePtr.Append(aDateTime.Mid(5, 2));//month MM |
|
1091 |
dateTimePtr.Append(KDash); |
|
1092 |
dateTimePtr.Append(aDateTime.Left(4));//year YYYY |
|
1093 |
dateTimePtr.Append(KSpace); |
|
1094 |
} |
|
1095 |
else if(iDateFormat==EDateJapanese) |
|
1096 |
{ |
|
1097 |
dateTimePtr.Append(aDateTime.Left(4));//year YYYY |
|
1098 |
dateTimePtr.Append(KDash); |
|
1099 |
dateTimePtr.Append(aDateTime.Mid(5, 2));//month MM |
|
1100 |
dateTimePtr.Append(KDash); |
|
1101 |
dateTimePtr.Append(aDateTime.Mid(8, 2));//day DD |
|
1102 |
dateTimePtr.Append(KSpace); |
|
1103 |
} |
|
1104 |
else //iDateFormat==EDateAmerican |
|
1105 |
{ |
|
1106 |
dateTimePtr.Append(aDateTime.Mid(5, 2));//month MM |
|
1107 |
dateTimePtr.Append(KDash); |
|
1108 |
dateTimePtr.Append(aDateTime.Mid(8, 2));//day DD |
|
1109 |
dateTimePtr.Append(KDash); |
|
1110 |
dateTimePtr.Append(aDateTime.Left(4));//year YYYY |
|
1111 |
dateTimePtr.Append(KSpace); |
|
1112 |
} |
|
1113 |
||
1114 |
// When colon (:) is set as Date separator in Date and Time setting, |
|
1115 |
// colon in Time descriptors is parsed as Date separator. |
|
1116 |
if ( locale.DateSeparator(1) == ':') |
|
1117 |
{ |
|
1118 |
_LIT(KDot, "."); |
|
1119 |
||
1120 |
// time HH.MM.SS |
|
1121 |
dateTimePtr.Append( aDateTime.Mid(11, 2) ); |
|
1122 |
dateTimePtr.Append( KDot ); |
|
1123 |
dateTimePtr.Append( aDateTime.Mid(14, 2) ); |
|
1124 |
dateTimePtr.Append( KDot ); |
|
1125 |
dateTimePtr.Append( aDateTime.Mid(17, 2) ); |
|
1126 |
} |
|
1127 |
else |
|
1128 |
{ |
|
1129 |
dateTimePtr.Append(aDateTime.Right(8));//time HH:MM:SS |
|
1130 |
} |
|
1131 |
||
1132 |
User::LeaveIfError(time.Parse(dateTimePtr)); |
|
1133 |
CleanupStack::PopAndDestroy(dateTime); |
|
1134 |
} |
|
1135 |
else |
|
1136 |
{ |
|
1137 |
time = Time::NullTTime(); |
|
1138 |
} |
|
1139 |
return time; |
|
1140 |
} |
|
1141 |
||
1142 |
// ---------------------------------------------------------------------------- |
|
1143 |
// MPXDbCommonUtil::CurrentTimeDesLC |
|
1144 |
// ---------------------------------------------------------------------------- |
|
1145 |
// |
|
1146 |
EXPORT_C HBufC* MPXDbCommonUtil::CurrentTimeDesLC() |
|
1147 |
{ |
|
1148 |
MPX_FUNC("MPXDbCommonUtil::CurrentTimeDesLC"); |
|
1149 |
||
1150 |
TTime time; |
|
1151 |
time.HomeTime(); |
|
1152 |
||
1153 |
return TTimeToDesLC(time); |
|
1154 |
} |
|
1155 |
||
1156 |
// ---------------------------------------------------------------------------- |
|
1157 |
// MPXDbCommonUtil::CurrentDateDesLC |
|
1158 |
// ---------------------------------------------------------------------------- |
|
1159 |
// |
|
1160 |
EXPORT_C HBufC* MPXDbCommonUtil::CurrentDateDesLC() |
|
1161 |
{ |
|
1162 |
MPX_FUNC("MPXDbCommonUtil::CurrentDateDesLC"); |
|
1163 |
||
1164 |
TTime time; |
|
1165 |
time.HomeTime(); |
|
1166 |
||
1167 |
// Round off to the nearest hour |
|
1168 |
TDateTime date(time.DateTime()); |
|
1169 |
date.SetMinute(0); |
|
1170 |
date.SetSecond(0); |
|
1171 |
date.SetMicroSecond(0); |
|
1172 |
||
1173 |
return TTimeToDesLC(TTime(date)); |
|
1174 |
} |
|
1175 |
||
1176 |
// ---------------------------------------------------------------------------- |
|
1177 |
// MPXDbCommonUtil::GetDriveL |
|
1178 |
// ---------------------------------------------------------------------------- |
|
1179 |
// |
|
1180 |
EXPORT_C TInt MPXDbCommonUtil::GetDriveL( |
|
1181 |
const TDesC& aUri, |
|
1182 |
TDriveUnit& aDrive) |
|
1183 |
{ |
|
1184 |
MPX_FUNC("MPXDbCommonUtil::GetDriveL"); |
|
1185 |
||
1186 |
TInt err(KErrNotFound); |
|
1187 |
TParsePtrC parser(aUri); |
|
1188 |
if (parser.Drive().Length()) |
|
1189 |
{ |
|
1190 |
aDrive = TDriveUnit(aUri); |
|
1191 |
err = KErrNone; |
|
1192 |
} |
|
1193 |
||
1194 |
return err; |
|
1195 |
} |
|
1196 |
||
1197 |
// ---------------------------------------------------------------------------- |
|
1198 |
// MPXDbCommonUtil::AttributeExistsL |
|
1199 |
// ---------------------------------------------------------------------------- |
|
1200 |
// |
|
1201 |
EXPORT_C TBool MPXDbCommonUtil::AttributeExists( |
|
1202 |
const TArray<TMPXAttribute>& aAttrs, |
|
1203 |
const TMPXAttribute& aAttribute) |
|
1204 |
{ |
|
1205 |
MPX_FUNC("MPXDbCommonUtil::AttributeExists"); |
|
1206 |
||
1207 |
TBool ret(EFalse); |
|
1208 |
||
1209 |
TUint content(aAttribute.ContentId()); |
|
1210 |
TUint attribute(aAttribute.AttributeId()); |
|
1211 |
||
1212 |
TInt count(aAttrs.Count()); |
|
1213 |
for (TInt i = 0; i < count; ++i) |
|
1214 |
{ |
|
1215 |
if ((aAttrs[i].ContentId() == content) && |
|
1216 |
(aAttrs[i].AttributeId() & attribute)) |
|
1217 |
{ |
|
1218 |
ret = ETrue; |
|
1219 |
break; |
|
1220 |
} |
|
1221 |
} |
|
1222 |
||
1223 |
return ret; |
|
1224 |
} |
|
1225 |
||
1226 |
// ---------------------------------------------------------------------------- |
|
1227 |
// MPXDbCommonUtil::ConstructMediaLC |
|
1228 |
// ---------------------------------------------------------------------------- |
|
1229 |
// |
|
1230 |
CMPXMedia* MPXDbCommonUtil::ConstructMediaLC( |
|
1231 |
const TDesC& aTitle, |
|
1232 |
TMPXGeneralType aType, |
|
1233 |
TMPXGeneralCategory aCat, |
|
1234 |
TMPXItemId aId, |
|
1235 |
TInt aNonPermissibleActions, |
|
1236 |
TUint aDbflag) |
|
1237 |
{ |
|
1238 |
MPX_FUNC("MPXDbCommonUtil::ConstructMediaLC"); |
|
1239 |
||
1240 |
RArray<TInt> supportedIds; |
|
1241 |
CleanupClosePushL(supportedIds); |
|
1242 |
supportedIds.AppendL(KMPXMediaIdGeneral); |
|
1243 |
CMPXMedia* entry = CMPXMedia::NewL(supportedIds.Array()); |
|
1244 |
CleanupStack::PopAndDestroy(&supportedIds); |
|
1245 |
CleanupStack::PushL(entry); |
|
1246 |
entry->SetTextValueL(KMPXMediaGeneralTitle, aTitle); |
|
1247 |
entry->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, aType); |
|
1248 |
entry->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, aCat); |
|
1249 |
entry->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, aId); |
|
1250 |
entry->SetTObjectValueL<TUint>(KMPXMediaGeneralFlags, aDbflag); |
|
1251 |
||
1252 |
if (aNonPermissibleActions) |
|
1253 |
{ |
|
1254 |
// set non-permissible actions |
|
1255 |
entry->SetTObjectValueL<TMPXGeneralNonPermissibleActions>(KMPXMediaGeneralNonPermissibleActions, |
|
1256 |
static_cast<TMPXGeneralNonPermissibleActions>(aNonPermissibleActions)); |
|
1257 |
} |
|
1258 |
||
1259 |
return entry; |
|
1260 |
} |
|
1261 |
||
1262 |
// ---------------------------------------------------------------------------- |
|
1263 |
// MPXDbCommonUtil::GetColumnTextL |
|
1264 |
// ---------------------------------------------------------------------------- |
|
1265 |
// |
|
1266 |
EXPORT_C TPtrC MPXDbCommonUtil::GetColumnTextL( |
|
1267 |
RSqlStatement& aStatement, |
|
1268 |
TInt aField) |
|
1269 |
{ |
|
1270 |
MPX_FUNC("MPXDbCommonUtil::GetColumnTextL"); |
|
1271 |
||
1272 |
TPtrC text; |
|
1273 |
if (aStatement.ColumnSize(aField)) |
|
1274 |
{ |
|
1275 |
text.Set(aStatement.ColumnTextL(aField)); |
|
1276 |
} |
|
1277 |
else |
|
1278 |
{ |
|
1279 |
text.Set(KNullDesC); |
|
1280 |
} |
|
1281 |
||
1282 |
return text; |
|
1283 |
} |
|
1284 |
||
1285 |
// ---------------------------------------------------------------------------- |
|
1286 |
// Add an album item changed message to the message array |
|
1287 |
// ---------------------------------------------------------------------------- |
|
1288 |
// |
|
1289 |
EXPORT_C void MPXDbCommonUtil::AddItemAlbumChangedMessageL( |
|
1290 |
CMPXMessageArray& aMessageArray, |
|
1291 |
TMPXItemId aId, |
|
1292 |
TMPXChangeEventType aChangeType, |
|
1293 |
TMPXGeneralCategory aCategory, |
|
1294 |
TUint aUid, |
|
1295 |
TBool aAlbumArt, |
|
1296 |
TMPXItemId aDeprecatedId) |
|
1297 |
{ |
|
1298 |
MPX_FUNC("MPXDbCommonUtil::AddItemChangedMessageL"); |
|
1299 |
CMPXMessage* message = CMPXMedia::NewL(); |
|
1300 |
CleanupStack::PushL(message); |
|
1301 |
||
1302 |
FillItemChangedMessageL(*message, aId, aChangeType, aCategory, aUid, |
|
1303 |
aDeprecatedId ); |
|
1304 |
if ( aAlbumArt ) |
|
1305 |
{ |
|
1306 |
message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aId); |
|
1307 |
} |
|
1308 |
if (FindItemChangedMessageL(aMessageArray, *message) == KErrNotFound) |
|
1309 |
{ |
|
1310 |
aMessageArray.AppendL(*message); // ownership xfer |
|
1311 |
} |
|
1312 |
CleanupStack::PopAndDestroy(message); |
|
1313 |
} |
|
1314 |
// End of File |