|
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 |
|
332 TBuf<KMaxFileName+KMCIntegerLen> fileName; |
|
333 if( extractPos ) |
|
334 { |
|
335 // append volume's unique Id to path to maintain uniqueness |
|
336 TDriveUnit driveUnit( aName ); |
|
337 TUint volId = MPXDbCommonUtil::GetVolIdMatchDriveIdL(aFs, driveUnit); |
|
338 if( volId ) |
|
339 { |
|
340 fileName.AppendNum( volId ); |
|
341 } |
|
342 else |
|
343 { |
|
344 // If media/drive doesn't exist, using whole path |
|
345 extractPos = 0; |
|
346 } |
|
347 } |
|
348 |
|
349 // append the path part |
|
350 fileName.Append( aName.Mid( extractPos ) ); |
|
351 |
|
352 if( !aCaseSensitive ) |
|
353 { |
|
354 fileName.LowerCase(); |
|
355 } |
|
356 |
|
357 TInt narrowFileLen(0); |
|
358 TPtrC8 narrowFileName; |
|
359 #if defined(_UNICODE) |
|
360 narrowFileLen = fileName.Length() * 2; |
|
361 narrowFileName.Set((TUint8*)fileName.Ptr(), narrowFileLen); |
|
362 #else |
|
363 narrowFileLen = fileName.Length(); |
|
364 narrowFileName.Set(fileName.Ptr(), narrowFileLen); |
|
365 #endif |
|
366 |
|
367 CMD5* hasher = CMD5::NewL(); |
|
368 CleanupStack::PushL( hasher ); |
|
369 hasher->Reset(); |
|
370 TBuf8<16> hash( hasher->Hash( narrowFileName ) ); //hashed to 128bits |
|
371 CleanupStack::PopAndDestroy( hasher ); |
|
372 |
|
373 const TText8* ptr = hash.Ptr(); |
|
374 |
|
375 TUint32 uniqueId(0); |
|
376 uniqueId = aTableId << 28; |
|
377 uniqueId |= (ptr[3]&0x0F)<<24 | (ptr[2]<<16) | (ptr[1]<<8) | ptr[0]; |
|
378 return uniqueId; |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // Append an item into the media array |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 EXPORT_C void MPXDbCommonUtil::AppendMediaL( |
|
386 CMPXMediaArray& aArray, |
|
387 const TDesC& aTitle, |
|
388 TMPXGeneralType aType, |
|
389 TMPXGeneralCategory aCat, |
|
390 TMPXItemId aId, |
|
391 TInt aNonPermissibleActions, |
|
392 TUint aDbflag) |
|
393 { |
|
394 MPX_FUNC("MPXDbCommonUtil::AppendMediaL"); |
|
395 |
|
396 CMPXMedia* entry = ConstructMediaLC(aTitle, aType, aCat, aId, aNonPermissibleActions, aDbflag); |
|
397 aArray.AppendL(*entry); |
|
398 CleanupStack::PopAndDestroy(entry); |
|
399 } |
|
400 |
|
401 // ---------------------------------------------------------------------------- |
|
402 // Append an item into the media array |
|
403 // ---------------------------------------------------------------------------- |
|
404 // |
|
405 EXPORT_C void MPXDbCommonUtil::PrependMediaL( |
|
406 CMPXMediaArray& aArray, |
|
407 const TDesC& aTitle, |
|
408 TMPXGeneralType aType, |
|
409 TMPXGeneralCategory aCat, |
|
410 TMPXItemId aId /* = 0 */, |
|
411 TInt aNonPermissibleActions /* = 0 */, |
|
412 TUint aDbflag /* = 0 */, |
|
413 TInt aPos /* = 0 */) |
|
414 { |
|
415 MPX_FUNC("MPXDbCommonUtil::PrependMediaL"); |
|
416 |
|
417 CMPXMedia* entry = ConstructMediaLC(aTitle, aType, aCat, aId, aNonPermissibleActions, aDbflag); |
|
418 User::LeaveIfError(aArray.Insert(*entry, aPos)); |
|
419 CleanupStack::PopAndDestroy(entry); |
|
420 } |
|
421 |
|
422 // ---------------------------------------------------------------------------- |
|
423 // Append an item into the media array |
|
424 // ---------------------------------------------------------------------------- |
|
425 // |
|
426 EXPORT_C void MPXDbCommonUtil::FillInSupportedUIDsL( |
|
427 const TArray<TMPXAttribute>& aAttrs, |
|
428 RArray<TInt>& aSupportedIds) |
|
429 { |
|
430 MPX_FUNC("MPXDbCommonUtil::FillInSupportedUIDs"); |
|
431 |
|
432 TInt attrCount(aAttrs.Count()); |
|
433 for (TInt i = 0; i < attrCount; ++i) |
|
434 { |
|
435 if (aAttrs[i].ContentId() == KMPXMediaIdGeneral) |
|
436 { |
|
437 aSupportedIds.AppendL(KMPXMediaIdGeneral); |
|
438 } |
|
439 else if (aAttrs[i].ContentId() == KMPXMediaIdMusic) |
|
440 { |
|
441 aSupportedIds.AppendL(KMPXMediaIdMusic); |
|
442 } |
|
443 else if (aAttrs[i].ContentId() == KMPXMediaIdAudio) |
|
444 { |
|
445 aSupportedIds.AppendL(KMPXMediaIdAudio); |
|
446 } |
|
447 else if (aAttrs[i].ContentId() == KMPXMediaIdDrm) |
|
448 { |
|
449 aSupportedIds.AppendL(KMPXMediaIdDrm); |
|
450 } |
|
451 else if (aAttrs[i].ContentId() == KMPXMediaIdCollectionDetails) |
|
452 { |
|
453 aSupportedIds.AppendL(KMPXMediaIdCollectionDetails); |
|
454 } |
|
455 else |
|
456 { |
|
457 // ignore attribute |
|
458 } |
|
459 } |
|
460 } |
|
461 |
|
462 // ---------------------------------------------------------------------------- |
|
463 // Fill in change event message with the given info |
|
464 // ---------------------------------------------------------------------------- |
|
465 // |
|
466 EXPORT_C void MPXDbCommonUtil::FillItemChangedMessageL( |
|
467 CMPXMessage& aMessage, |
|
468 TMPXItemId aId, |
|
469 TMPXChangeEventType aChangeType, |
|
470 TMPXGeneralCategory aCategory, |
|
471 TUint aUid, |
|
472 TMPXItemId aDeprecatedId) |
|
473 { |
|
474 MPX_FUNC("MPXDbCommonUtil::FillItemChangedMessageL"); |
|
475 MPX_DEBUG5("MPXDbCommonUtil::FillItemChangedMessageL: type [%d], category [%d], id[0x%x], oldId[0x%x]", |
|
476 aChangeType, aCategory, aId.iId1, aDeprecatedId.iId1); |
|
477 |
|
478 aMessage.SetTObjectValueL<TMPXMessageId>(KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
479 aMessage.SetTObjectValueL<TUid>(KMPXMessageCollectionId, TUid::Uid(aUid)); |
|
480 aMessage.SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, aChangeType); |
|
481 aMessage.SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, aCategory); |
|
482 aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, aId); |
|
483 |
|
484 if ((aDeprecatedId != 0) && (aId != aDeprecatedId)) |
|
485 { |
|
486 aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aDeprecatedId); |
|
487 } |
|
488 } |
|
489 |
|
490 // ---------------------------------------------------------------------------- |
|
491 // Add an item changed message to the message array |
|
492 // ---------------------------------------------------------------------------- |
|
493 // |
|
494 EXPORT_C void MPXDbCommonUtil::AddItemChangedMessageL( |
|
495 CMPXMessageArray& aMessageArray, |
|
496 TMPXItemId aId, |
|
497 TMPXChangeEventType aChangeType, |
|
498 TMPXGeneralCategory aCategory, |
|
499 TUint aUid, |
|
500 TMPXItemId aDeprecatedId /* = 0 */) |
|
501 { |
|
502 MPX_FUNC("MPXDbCommonUtil::AddItemChangedMessageL"); |
|
503 CMPXMessage* message = CMPXMedia::NewL(); |
|
504 CleanupStack::PushL(message); |
|
505 |
|
506 FillItemChangedMessageL(*message, aId, aChangeType, aCategory, aUid, aDeprecatedId); |
|
507 if (FindItemChangedMessageL(aMessageArray, *message) == KErrNotFound) |
|
508 { |
|
509 aMessageArray.AppendL(*message); // ownership xfer |
|
510 } |
|
511 CleanupStack::PopAndDestroy(message); |
|
512 } |
|
513 |
|
514 // ---------------------------------------------------------------------------- |
|
515 // Find the message in the array, if not KErrNotFound is returned; otherwise the |
|
516 // index of the first matching message is returned |
|
517 // ---------------------------------------------------------------------------- |
|
518 // |
|
519 EXPORT_C TInt MPXDbCommonUtil::FindItemChangedMessageL( |
|
520 const CMPXMessageArray& aMessageArray, |
|
521 const CMPXMessage& aMessage) |
|
522 { |
|
523 MPX_FUNC("MPXDbCommonUtil::FindItemChangedMessageL"); |
|
524 |
|
525 TInt index(KErrNotFound); |
|
526 TInt messageCount(aMessageArray.Count()); |
|
527 |
|
528 for (TInt i = 0; i < messageCount; ++i) |
|
529 { |
|
530 CMPXMessage* message = aMessageArray.AtL(i); |
|
531 |
|
532 if (message->IsSupported(KMPXMessageGeneralId) && |
|
533 message->IsSupported(KMPXMessageCollectionId) && |
|
534 message->IsSupported(KMPXMessageChangeEventType) && |
|
535 message->IsSupported(KMPXMessageMediaGeneralCategory) && |
|
536 message->IsSupported(KMPXMessageMediaGeneralId) && |
|
537 aMessage.IsSupported(KMPXMessageGeneralId) && |
|
538 aMessage.IsSupported(KMPXMessageCollectionId) && |
|
539 aMessage.IsSupported(KMPXMessageChangeEventType) && |
|
540 aMessage.IsSupported(KMPXMessageMediaGeneralCategory) && |
|
541 aMessage.IsSupported(KMPXMessageMediaGeneralId)) |
|
542 { |
|
543 if (message->ValueTObjectL<TMPXMessageId>(KMPXMessageGeneralId) == aMessage.ValueTObjectL<TMPXMessageId>(KMPXMessageGeneralId) && |
|
544 message->ValueTObjectL<TUid>(KMPXMessageCollectionId) == aMessage.ValueTObjectL<TUid>(KMPXMessageCollectionId) && |
|
545 message->ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType) == aMessage.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType) && |
|
546 message->ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory) == aMessage.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory) && |
|
547 message->ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId) == aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId)) |
|
548 { |
|
549 if (!message->IsSupported(KMPXMessageMediaDeprecatedId) && |
|
550 !aMessage.IsSupported(KMPXMessageMediaDeprecatedId)) |
|
551 { |
|
552 index = i; |
|
553 break; |
|
554 } |
|
555 else if (message->IsSupported(KMPXMessageMediaDeprecatedId) && |
|
556 aMessage.IsSupported(KMPXMessageMediaDeprecatedId)) |
|
557 { |
|
558 if (message->ValueTObjectL<TMPXItemId>(KMPXMessageMediaDeprecatedId) == |
|
559 aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaDeprecatedId)) |
|
560 { |
|
561 index = i; |
|
562 break; |
|
563 } |
|
564 } |
|
565 else |
|
566 { |
|
567 // else do nothing |
|
568 } |
|
569 } |
|
570 } |
|
571 } |
|
572 |
|
573 return index; |
|
574 } |
|
575 |
|
576 // ---------------------------------------------------------------------------- |
|
577 // Get the DRM protection type of the file |
|
578 // ---------------------------------------------------------------------------- |
|
579 // |
|
580 EXPORT_C TMCDrmType MPXDbCommonUtil::GetDRMTypeL(const TDesC& aFile) |
|
581 { |
|
582 MPX_FUNC("MPXDbCommonUtil::GetDRMTypeL"); |
|
583 |
|
584 using namespace ContentAccess; |
|
585 TInt drmProtected(0); |
|
586 TVirtualPathPtr virtualPath(aFile, KDefaultContentObject); |
|
587 CData* content = CData::NewL(virtualPath, EPeek, EContentShareReadOnly); |
|
588 CleanupStack::PushL(content); |
|
589 User::LeaveIfError(content->GetAttribute(EIsProtected, drmProtected)); |
|
590 CleanupStack::PopAndDestroy( content ); |
|
591 return drmProtected? EMCDrmOmaDrm : EMCDrmNone; |
|
592 } |
|
593 |
|
594 // ---------------------------------------------------------------------------- |
|
595 // MPXDbUtil::ProcessSingleQuotesLC |
|
596 // ---------------------------------------------------------------------------- |
|
597 // |
|
598 EXPORT_C HBufC* MPXDbCommonUtil::ProcessSingleQuotesLC( |
|
599 const TDesC& aString) |
|
600 { |
|
601 MPX_FUNC("MPXDbCommonUtil::ProcessSingleQuotesLC"); |
|
602 |
|
603 // reserve space for all single quotes (double the size) |
|
604 HBufC* value = HBufC::NewLC(aString.Length() * 2); |
|
605 TPtr valuePtr(value->Des()); |
|
606 |
|
607 MPXDbCommonUtil::FindAndReplaceSingleQuote(aString, valuePtr); |
|
608 |
|
609 return value; |
|
610 } |
|
611 |
|
612 // ---------------------------------------------------------------------------- |
|
613 // MPXDbUtil::ProcessPatternCharsLC |
|
614 // 1) a percentage needs to be escaped for sqlite followed by |
|
615 // another percentage sign for escaping % for descriptor formatting, i.e. |
|
616 // % --> %% (this percentage will be treated as a percentage instead of |
|
617 // pattern matching) |
|
618 // 2) since back slash is used for escaping the pattern characters, user |
|
619 // specified back slash should be escapped as well, i.e. \ --> \\ |
|
620 // ---------------------------------------------------------------------------- |
|
621 // |
|
622 EXPORT_C HBufC* MPXDbCommonUtil::ProcessPatternCharsLC( |
|
623 const TDesC& aString) |
|
624 { |
|
625 MPX_FUNC("MPXDbCommonUtil::ProcessPatternCharsLC"); |
|
626 |
|
627 // reserve space for all percentage signs (triple the size because % should |
|
628 // be replaced by %%) |
|
629 TInt srcLen(aString.Length()); |
|
630 HBufC* targetString = HBufC::NewLC(aString.Length() * 3); |
|
631 TPtr targetStringPtr(targetString->Des()); |
|
632 |
|
633 TPtrC ch; |
|
634 for (TInt i = 0; i < srcLen; ++i) |
|
635 { |
|
636 ch.Set(&aString[i], 1); |
|
637 if (ch.CompareF(KMCPercentage) == 0) |
|
638 { |
|
639 targetStringPtr.Append(KMCPercentage); |
|
640 } |
|
641 else if ( ch.CompareF( KMCBackSlash ) == 0 ) |
|
642 { |
|
643 targetStringPtr.Append(KMCBackSlash); |
|
644 } |
|
645 targetStringPtr.Append(ch); |
|
646 } |
|
647 |
|
648 MPX_DEBUG3(" original=%S, new=%S", &aString, targetString); |
|
649 |
|
650 return targetString; |
|
651 } |
|
652 |
|
653 // ---------------------------------------------------------------------------- |
|
654 // Constructs an int SQL criterion |
|
655 // ---------------------------------------------------------------------------- |
|
656 // |
|
657 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
658 const TDesC& aCriterion, |
|
659 TInt aValue) |
|
660 { |
|
661 MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC"); |
|
662 |
|
663 HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + KMCIntegerLen); |
|
664 TPtr ptr = sqlCriterion->Des(); |
|
665 ptr.Format(aCriterion, aValue); |
|
666 return sqlCriterion; |
|
667 } |
|
668 |
|
669 // ---------------------------------------------------------------------------- |
|
670 // Constructs an int64 SQL criterion |
|
671 // ---------------------------------------------------------------------------- |
|
672 // |
|
673 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterion64LC( |
|
674 const TDesC& aCriterion, |
|
675 TInt64 aValue) |
|
676 { |
|
677 MPX_FUNC("MPXDbCommonUtil::SqlCriterion64LC"); |
|
678 |
|
679 HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + KMCInt64Len); |
|
680 TPtr ptr = sqlCriterion->Des(); |
|
681 ptr.Format(aCriterion, aValue); |
|
682 return sqlCriterion; |
|
683 } |
|
684 |
|
685 // ---------------------------------------------------------------------------- |
|
686 // Constructs an SQL criterion using two int values |
|
687 // ---------------------------------------------------------------------------- |
|
688 // |
|
689 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
690 const TDesC& aCriterion, |
|
691 TInt aValue1, |
|
692 TInt aValue2) |
|
693 { |
|
694 MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 2"); |
|
695 |
|
696 HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + 2 * KMCIntegerLen); |
|
697 TPtr ptr = sqlCriterion->Des(); |
|
698 ptr.Format(aCriterion, aValue1, aValue2); |
|
699 return sqlCriterion; |
|
700 } |
|
701 |
|
702 // ---------------------------------------------------------------------------- |
|
703 // Constructs an SQL criterion using two int64 values |
|
704 // ---------------------------------------------------------------------------- |
|
705 // |
|
706 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterion64LC( |
|
707 const TDesC& aCriterion, |
|
708 TInt64 aValue1, |
|
709 TInt64 aValue2) |
|
710 { |
|
711 MPX_FUNC("MPXDbCommonUtil::SqlCriterion64LC 2"); |
|
712 |
|
713 HBufC* sqlCriterion = HBufC::NewLC(aCriterion.Length() + 2 * KMCInt64Len); |
|
714 TPtr ptr = sqlCriterion->Des(); |
|
715 ptr.Format(aCriterion, aValue1, aValue2); |
|
716 return sqlCriterion; |
|
717 } |
|
718 |
|
719 // ---------------------------------------------------------------------------- |
|
720 // Constructs a descriptor SQL criterion |
|
721 // ---------------------------------------------------------------------------- |
|
722 // |
|
723 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
724 const TDesC& aCriterion, |
|
725 const TDesC& aValue) |
|
726 { |
|
727 MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 3"); |
|
728 |
|
729 HBufC* value = ProcessSingleQuotesLC(aValue); |
|
730 |
|
731 HBufC* sqlCriterion = HBufC::NewL(aCriterion.Length() + value->Length()); |
|
732 TPtr ptr(sqlCriterion->Des()); |
|
733 ptr.Format(aCriterion, value); |
|
734 |
|
735 CleanupStack::PopAndDestroy(value); |
|
736 CleanupStack::PushL(sqlCriterion); |
|
737 return sqlCriterion; |
|
738 } |
|
739 |
|
740 // ---------------------------------------------------------------------------- |
|
741 // Constructs a descriptor SQL criterion |
|
742 // ---------------------------------------------------------------------------- |
|
743 // |
|
744 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
745 const TDesC& aCriterion, |
|
746 const TDesC& aValue1, |
|
747 const TDesC& aValue2) |
|
748 { |
|
749 MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 3"); |
|
750 |
|
751 HBufC* value1 = ProcessSingleQuotesLC(aValue1); |
|
752 HBufC* value2 = ProcessSingleQuotesLC(aValue2); |
|
753 |
|
754 HBufC* sqlCriterion = HBufC::NewL(aCriterion.Length() + |
|
755 value1->Length() + |
|
756 value2->Length()); |
|
757 TPtr ptr(sqlCriterion->Des()); |
|
758 ptr.Format(aCriterion, value1, value2); |
|
759 |
|
760 CleanupStack::PopAndDestroy(value2); |
|
761 CleanupStack::PopAndDestroy(value1); |
|
762 CleanupStack::PushL(sqlCriterion); |
|
763 return sqlCriterion; |
|
764 } |
|
765 |
|
766 // ---------------------------------------------------------------------------- |
|
767 // Constructs a descriptor SQL criterion |
|
768 // ---------------------------------------------------------------------------- |
|
769 // |
|
770 EXPORT_C HBufC* MPXDbCommonUtil::SqlCriterionLC( |
|
771 const TDesC& aCriterion, |
|
772 const TDesC& aValue1, |
|
773 TInt aValue2, |
|
774 const TDesC& aValue3, |
|
775 TInt aValue4) |
|
776 { |
|
777 MPX_FUNC("MPXDbCommonUtil::SqlCriterionLC 3"); |
|
778 |
|
779 HBufC* value1 = ProcessSingleQuotesLC(aValue1); |
|
780 HBufC* value3 = ProcessSingleQuotesLC(aValue3); |
|
781 |
|
782 HBufC* sqlCriterion = HBufC::NewL(aCriterion.Length() + |
|
783 value1->Length() + |
|
784 value3->Length() + |
|
785 2 * KMCIntegerLen); |
|
786 TPtr ptr(sqlCriterion->Des()); |
|
787 ptr.Format(aCriterion, value1, aValue2, value3, aValue4); |
|
788 |
|
789 CleanupStack::PopAndDestroy(value3); |
|
790 CleanupStack::PopAndDestroy(value1); |
|
791 CleanupStack::PushL(sqlCriterion); |
|
792 return sqlCriterion; |
|
793 } |
|
794 |
|
795 // ---------------------------------------------------------------------------- |
|
796 // Constructs and adds an int SQL criterion to the criteria array |
|
797 // ---------------------------------------------------------------------------- |
|
798 // |
|
799 EXPORT_C TInt MPXDbCommonUtil::AddSqlCriterionL( |
|
800 CDesCArray& aSqlCriteria, |
|
801 const TDesC& aCriterion, |
|
802 TInt aValue) |
|
803 { |
|
804 MPX_FUNC("MPXDbCommonUtil::AddSqlCriterionL"); |
|
805 |
|
806 HBufC* sqlCriterion = SqlCriterionLC(aCriterion, aValue); |
|
807 TInt length = sqlCriterion->Length(); |
|
808 aSqlCriteria.AppendL(*sqlCriterion); |
|
809 CleanupStack::PopAndDestroy(sqlCriterion); |
|
810 return length; |
|
811 } |
|
812 |
|
813 // ---------------------------------------------------------------------------- |
|
814 // Constructs and adds a string SQL criterion to the criteria array |
|
815 // ---------------------------------------------------------------------------- |
|
816 // |
|
817 EXPORT_C TInt MPXDbCommonUtil::AddSqlCriterionL( |
|
818 CDesCArray& aSqlCriteria, |
|
819 const TDesC& aCriterion, |
|
820 const TDesC& aValue) |
|
821 { |
|
822 MPX_FUNC("MPXDbCommonUtil::AddSqlCriterionL"); |
|
823 |
|
824 HBufC* sqlCriterion = SqlCriterionLC(aCriterion, aValue); |
|
825 TInt length = sqlCriterion->Length(); |
|
826 aSqlCriteria.AppendL(*sqlCriterion); |
|
827 CleanupStack::PopAndDestroy(sqlCriterion); |
|
828 return length; |
|
829 } |
|
830 |
|
831 |
|
832 // ---------------------------------------------------------------------------- |
|
833 // Create a full path with input drive Id and path |
|
834 // ---------------------------------------------------------------------------- |
|
835 // |
|
836 EXPORT_C HBufC* MPXDbCommonUtil::CreateFullPathL( |
|
837 TInt aDriveId, |
|
838 const TDesC& aPath) |
|
839 { |
|
840 MPX_FUNC("MPXDbCommonUtil::CreateFullPathL"); |
|
841 |
|
842 HBufC* hbuf = HBufC::NewLC(aPath.Length() + KMaxDriveName); |
|
843 TPtr fullPath(hbuf->Des()); |
|
844 |
|
845 if (aDriveId != KErrNotFound) |
|
846 { |
|
847 TDriveUnit driveUnit(aDriveId); |
|
848 fullPath.Copy(driveUnit.Name()); |
|
849 } |
|
850 |
|
851 fullPath.Append(aPath); |
|
852 CleanupStack::Pop(hbuf); |
|
853 return hbuf; |
|
854 } |
|
855 |
|
856 // ---------------------------------------------------------------------------- |
|
857 // MPXDbCommonUtil::AppendValueL |
|
858 // ---------------------------------------------------------------------------- |
|
859 // |
|
860 EXPORT_C void MPXDbCommonUtil::AppendValueL( |
|
861 CDesCArray& aFields, |
|
862 CDesCArray& aValues, |
|
863 const TDesC& aField, |
|
864 const TDesC& aValue) |
|
865 { |
|
866 MPX_FUNC("MPXDbCommonUtil::AppendValueL"); |
|
867 |
|
868 aFields.AppendL(aField); |
|
869 |
|
870 HBufC* value = HBufC::NewLC(aValue.Length() * 2 + 2); |
|
871 TPtr valuePtr(value->Des()); |
|
872 |
|
873 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue, valuePtr); |
|
874 |
|
875 // use 'value' instead of value, 0 length strings should be '' |
|
876 // |
|
877 if( valuePtr.Length() ) |
|
878 { |
|
879 valuePtr.Insert(0, KMCSingleQuote); |
|
880 valuePtr.Append(KMCSingleQuote); |
|
881 } |
|
882 else |
|
883 { |
|
884 valuePtr.Append(KMCSingleQuote); |
|
885 valuePtr.Append(KMCSingleQuote); |
|
886 } |
|
887 aValues.AppendL(valuePtr); |
|
888 |
|
889 CleanupStack::PopAndDestroy(value); |
|
890 } |
|
891 |
|
892 // ---------------------------------------------------------------------------- |
|
893 // MPXDbCommonUtil::AppendValueL |
|
894 // ---------------------------------------------------------------------------- |
|
895 // |
|
896 EXPORT_C void MPXDbCommonUtil::AppendValueL( |
|
897 CDesCArray& aFields, |
|
898 CDesCArray& aValues, |
|
899 const TDesC& aField, |
|
900 TUint32 aValue) |
|
901 { |
|
902 MPX_FUNC("MPXDbCommonUtil::AppendValueL"); |
|
903 |
|
904 aFields.AppendL(aField); |
|
905 TBuf<KMCIntegerLen> value; |
|
906 value.AppendNum(static_cast<TInt64>(aValue)); |
|
907 aValues.AppendL(value); |
|
908 } |
|
909 |
|
910 // ---------------------------------------------------------------------------- |
|
911 // Gets the MIME type for a specified URI |
|
912 // ---------------------------------------------------------------------------- |
|
913 // |
|
914 EXPORT_C TDataType MPXDbCommonUtil::GetMimeTypeForUriL( |
|
915 const TDesC& aUri) |
|
916 { |
|
917 MPX_FUNC("MPXDbUtil::GetMimeTypeForUriL"); |
|
918 |
|
919 if ( const TDesC8 * type = FindMimeTypeFromMap (aUri) ) |
|
920 { |
|
921 return TDataType(*type); |
|
922 } |
|
923 |
|
924 RApaLsSession appArc; |
|
925 User::LeaveIfError(appArc.Connect()); |
|
926 CleanupClosePushL(appArc); |
|
927 TUid dummyUid(KNullUid); |
|
928 TDataType mimeType; |
|
929 appArc.AppForDocument(aUri, dummyUid, mimeType); |
|
930 CleanupStack::PopAndDestroy(&appArc); |
|
931 |
|
932 return mimeType; |
|
933 } |
|
934 |
|
935 // ---------------------------------------------------------------------------- |
|
936 // MPXDbCommonUtil::StringFromArrayLC |
|
937 // ---------------------------------------------------------------------------- |
|
938 // |
|
939 EXPORT_C HBufC* MPXDbCommonUtil::StringFromArrayLC( |
|
940 const CDesCArray& aArray, |
|
941 const TDesC& aSeparator) |
|
942 { |
|
943 MPX_FUNC("MPXDbCommonUtil::StringFromArrayLC"); |
|
944 |
|
945 HBufC* str(NULL); |
|
946 TInt count(aArray.Count()); |
|
947 if (count) |
|
948 { |
|
949 TInt len(0); |
|
950 TInt index(0); |
|
951 for (index = 0; index < count; ++index) |
|
952 { |
|
953 len += aArray[index].Length(); |
|
954 } |
|
955 |
|
956 str = HBufC::NewLC(len + (aSeparator.Length() * (count - 1))); |
|
957 TPtr ptr(str->Des()); |
|
958 TPtrC16 item; |
|
959 for (index = 0; index < count; ++index) |
|
960 { |
|
961 item.Set(aArray[index]); |
|
962 ptr.Append(item); |
|
963 MPX_DEBUG2("aArray[index] %S", &item); |
|
964 if (index < (count - 1)) |
|
965 { |
|
966 ptr.Append(aSeparator); |
|
967 } |
|
968 } |
|
969 } |
|
970 else |
|
971 { |
|
972 str = HBufC::NewLC(0); |
|
973 } |
|
974 |
|
975 return str; |
|
976 } |
|
977 |
|
978 // ---------------------------------------------------------------------------- |
|
979 // MPXDbCommonUtil::StringFromArraysLC |
|
980 // ---------------------------------------------------------------------------- |
|
981 // |
|
982 EXPORT_C HBufC* MPXDbCommonUtil::StringFromArraysLC( |
|
983 const CDesCArray& aNameArray, |
|
984 const CDesCArray& aValueArray, |
|
985 const TDesC& aValueSeparator, |
|
986 const TDesC& aEntitySeparator) |
|
987 { |
|
988 MPX_FUNC("MPXDbCommonUtil::StringFromArraysLC"); |
|
989 |
|
990 // calculate the length of the SET string |
|
991 TInt len(0); |
|
992 TInt index(0); |
|
993 TInt count(aNameArray.Count()); |
|
994 for (index = 0; index < count; ++index) |
|
995 { |
|
996 len += aNameArray[index].Length() + aValueArray[index].Length(); |
|
997 } |
|
998 |
|
999 // construct the result string |
|
1000 HBufC* result = HBufC::NewLC(len + |
|
1001 ((aValueSeparator.Length() + aEntitySeparator.Length()) * count)); |
|
1002 TPtr resultPtr(result->Des()); |
|
1003 for (index = 0; index < count; ++index) |
|
1004 { |
|
1005 resultPtr.Append(aNameArray[index]); |
|
1006 resultPtr.Append(aValueSeparator); |
|
1007 resultPtr.Append(aValueArray[index]); |
|
1008 |
|
1009 if (index < count - 1) |
|
1010 { |
|
1011 resultPtr.Append(aEntitySeparator); |
|
1012 } |
|
1013 } |
|
1014 |
|
1015 return result; |
|
1016 } |
|
1017 |
|
1018 // ---------------------------------------------------------------------------- |
|
1019 // MPXDbCommonUtil::TTimeToDesLC |
|
1020 // Converts a TTime to the internal SQLite format (YYYY-MM-DD HH:MM:SS). |
|
1021 // ---------------------------------------------------------------------------- |
|
1022 // |
|
1023 EXPORT_C HBufC* MPXDbCommonUtil::TTimeToDesLC( |
|
1024 const TTime& aTime) |
|
1025 { |
|
1026 MPX_FUNC("MPXDbCommonUtil::TTimeToDesLC"); |
|
1027 |
|
1028 HBufC* dateTime; |
|
1029 if (aTime == Time::NullTTime()) |
|
1030 { |
|
1031 dateTime = HBufC::NewLC(0); |
|
1032 } |
|
1033 else |
|
1034 { |
|
1035 _LIT(KDateTimeFormat, "%04d-%02d-%02d %02d:%02d:%02d"); |
|
1036 |
|
1037 TTime time(0); |
|
1038 |
|
1039 // negative time means BC, but format string will be invalid with our format, |
|
1040 // i.e. %04d in KDateTimeFormat when year is -1 will result in "00-1" and |
|
1041 // the whole string becomes "00-1-01-01 00:00:00" which will result in error, |
|
1042 // so set to 0 in such cases |
|
1043 TDateTime dt = aTime>time ? aTime.DateTime() : time.DateTime(); |
|
1044 TInt dateTimeLen = KDateTimeFormat().Length(); |
|
1045 dateTime = HBufC::NewLC(dateTimeLen); |
|
1046 TPtr dateTimePtr = dateTime->Des(); |
|
1047 dateTimePtr.Format(KDateTimeFormat, |
|
1048 dt.Year(), |
|
1049 dt.Month() + 1, // zero based |
|
1050 dt.Day() + 1, // zero based |
|
1051 dt.Hour(), |
|
1052 dt.Minute(), |
|
1053 dt.Second()); |
|
1054 } |
|
1055 return dateTime; |
|
1056 } |
|
1057 |
|
1058 // ---------------------------------------------------------------------------- |
|
1059 // MPXDbCommonUtil::DesToTTimeL |
|
1060 // Converts a date time string in the internal SQLite format (YYYY-MM-DD HH:MM:SS) |
|
1061 // to a TTime. TTime can only parse in the DD-MM-YYYY HH:MM:SS format. |
|
1062 // ---------------------------------------------------------------------------- |
|
1063 // |
|
1064 EXPORT_C TTime MPXDbCommonUtil::DesToTTimeL( |
|
1065 const TDesC& aDateTime) |
|
1066 { |
|
1067 MPX_FUNC("MPXDbCommonUtil::DesToTTimeL"); |
|
1068 |
|
1069 TTime time(0); |
|
1070 if (aDateTime.Length() != 0) |
|
1071 { |
|
1072 _LIT(KDash, "-"); |
|
1073 _LIT(KSpace, " "); |
|
1074 |
|
1075 TLocale locale; |
|
1076 TDateFormat iDateFormat = locale.DateFormat(); |
|
1077 |
|
1078 HBufC* dateTime = HBufC::NewLC(aDateTime.Length()); |
|
1079 TPtr dateTimePtr = dateTime->Des(); |
|
1080 |
|
1081 //as TTime::Parse is locale dependent, check it: |
|
1082 if(iDateFormat==EDateEuropean) |
|
1083 { |
|
1084 dateTimePtr.Append(aDateTime.Mid(8, 2));//day DD |
|
1085 dateTimePtr.Append(KDash); |
|
1086 dateTimePtr.Append(aDateTime.Mid(5, 2));//month MM |
|
1087 dateTimePtr.Append(KDash); |
|
1088 dateTimePtr.Append(aDateTime.Left(4));//year YYYY |
|
1089 dateTimePtr.Append(KSpace); |
|
1090 } |
|
1091 else if(iDateFormat==EDateJapanese) |
|
1092 { |
|
1093 dateTimePtr.Append(aDateTime.Left(4));//year YYYY |
|
1094 dateTimePtr.Append(KDash); |
|
1095 dateTimePtr.Append(aDateTime.Mid(5, 2));//month MM |
|
1096 dateTimePtr.Append(KDash); |
|
1097 dateTimePtr.Append(aDateTime.Mid(8, 2));//day DD |
|
1098 dateTimePtr.Append(KSpace); |
|
1099 } |
|
1100 else //iDateFormat==EDateAmerican |
|
1101 { |
|
1102 dateTimePtr.Append(aDateTime.Mid(5, 2));//month MM |
|
1103 dateTimePtr.Append(KDash); |
|
1104 dateTimePtr.Append(aDateTime.Mid(8, 2));//day DD |
|
1105 dateTimePtr.Append(KDash); |
|
1106 dateTimePtr.Append(aDateTime.Left(4));//year YYYY |
|
1107 dateTimePtr.Append(KSpace); |
|
1108 } |
|
1109 |
|
1110 // When colon (:) is set as Date separator in Date and Time setting, |
|
1111 // colon in Time descriptors is parsed as Date separator. |
|
1112 if ( locale.DateSeparator(1) == ':') |
|
1113 { |
|
1114 _LIT(KDot, "."); |
|
1115 |
|
1116 // time HH.MM.SS |
|
1117 dateTimePtr.Append( aDateTime.Mid(11, 2) ); |
|
1118 dateTimePtr.Append( KDot ); |
|
1119 dateTimePtr.Append( aDateTime.Mid(14, 2) ); |
|
1120 dateTimePtr.Append( KDot ); |
|
1121 dateTimePtr.Append( aDateTime.Mid(17, 2) ); |
|
1122 } |
|
1123 else |
|
1124 { |
|
1125 dateTimePtr.Append(aDateTime.Right(8));//time HH:MM:SS |
|
1126 } |
|
1127 |
|
1128 User::LeaveIfError(time.Parse(dateTimePtr)); |
|
1129 CleanupStack::PopAndDestroy(dateTime); |
|
1130 } |
|
1131 else |
|
1132 { |
|
1133 time = Time::NullTTime(); |
|
1134 } |
|
1135 return time; |
|
1136 } |
|
1137 |
|
1138 // ---------------------------------------------------------------------------- |
|
1139 // MPXDbCommonUtil::CurrentTimeDesLC |
|
1140 // ---------------------------------------------------------------------------- |
|
1141 // |
|
1142 EXPORT_C HBufC* MPXDbCommonUtil::CurrentTimeDesLC() |
|
1143 { |
|
1144 MPX_FUNC("MPXDbCommonUtil::CurrentTimeDesLC"); |
|
1145 |
|
1146 TTime time; |
|
1147 time.HomeTime(); |
|
1148 |
|
1149 return TTimeToDesLC(time); |
|
1150 } |
|
1151 |
|
1152 // ---------------------------------------------------------------------------- |
|
1153 // MPXDbCommonUtil::CurrentDateDesLC |
|
1154 // ---------------------------------------------------------------------------- |
|
1155 // |
|
1156 EXPORT_C HBufC* MPXDbCommonUtil::CurrentDateDesLC() |
|
1157 { |
|
1158 MPX_FUNC("MPXDbCommonUtil::CurrentDateDesLC"); |
|
1159 |
|
1160 TTime time; |
|
1161 time.HomeTime(); |
|
1162 |
|
1163 // Round off to the nearest hour |
|
1164 TDateTime date(time.DateTime()); |
|
1165 date.SetMinute(0); |
|
1166 date.SetSecond(0); |
|
1167 date.SetMicroSecond(0); |
|
1168 |
|
1169 return TTimeToDesLC(TTime(date)); |
|
1170 } |
|
1171 |
|
1172 // ---------------------------------------------------------------------------- |
|
1173 // MPXDbCommonUtil::GetDriveL |
|
1174 // ---------------------------------------------------------------------------- |
|
1175 // |
|
1176 EXPORT_C TInt MPXDbCommonUtil::GetDriveL( |
|
1177 const TDesC& aUri, |
|
1178 TDriveUnit& aDrive) |
|
1179 { |
|
1180 MPX_FUNC("MPXDbCommonUtil::GetDriveL"); |
|
1181 |
|
1182 TInt err(KErrNotFound); |
|
1183 TParsePtrC parser(aUri); |
|
1184 if (parser.Drive().Length()) |
|
1185 { |
|
1186 aDrive = TDriveUnit(aUri); |
|
1187 err = KErrNone; |
|
1188 } |
|
1189 |
|
1190 return err; |
|
1191 } |
|
1192 |
|
1193 // ---------------------------------------------------------------------------- |
|
1194 // MPXDbCommonUtil::AttributeExistsL |
|
1195 // ---------------------------------------------------------------------------- |
|
1196 // |
|
1197 EXPORT_C TBool MPXDbCommonUtil::AttributeExists( |
|
1198 const TArray<TMPXAttribute>& aAttrs, |
|
1199 const TMPXAttribute& aAttribute) |
|
1200 { |
|
1201 MPX_FUNC("MPXDbCommonUtil::AttributeExists"); |
|
1202 |
|
1203 TBool ret(EFalse); |
|
1204 |
|
1205 TUint content(aAttribute.ContentId()); |
|
1206 TUint attribute(aAttribute.AttributeId()); |
|
1207 |
|
1208 TInt count(aAttrs.Count()); |
|
1209 for (TInt i = 0; i < count; ++i) |
|
1210 { |
|
1211 if ((aAttrs[i].ContentId() == content) && |
|
1212 (aAttrs[i].AttributeId() & attribute)) |
|
1213 { |
|
1214 ret = ETrue; |
|
1215 break; |
|
1216 } |
|
1217 } |
|
1218 |
|
1219 return ret; |
|
1220 } |
|
1221 |
|
1222 // ---------------------------------------------------------------------------- |
|
1223 // MPXDbCommonUtil::ConstructMediaLC |
|
1224 // ---------------------------------------------------------------------------- |
|
1225 // |
|
1226 CMPXMedia* MPXDbCommonUtil::ConstructMediaLC( |
|
1227 const TDesC& aTitle, |
|
1228 TMPXGeneralType aType, |
|
1229 TMPXGeneralCategory aCat, |
|
1230 TMPXItemId aId, |
|
1231 TInt aNonPermissibleActions, |
|
1232 TUint aDbflag) |
|
1233 { |
|
1234 MPX_FUNC("MPXDbCommonUtil::ConstructMediaLC"); |
|
1235 |
|
1236 RArray<TInt> supportedIds; |
|
1237 CleanupClosePushL(supportedIds); |
|
1238 supportedIds.AppendL(KMPXMediaIdGeneral); |
|
1239 CMPXMedia* entry = CMPXMedia::NewL(supportedIds.Array()); |
|
1240 CleanupStack::PopAndDestroy(&supportedIds); |
|
1241 CleanupStack::PushL(entry); |
|
1242 entry->SetTextValueL(KMPXMediaGeneralTitle, aTitle); |
|
1243 entry->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, aType); |
|
1244 entry->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, aCat); |
|
1245 entry->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, aId); |
|
1246 entry->SetTObjectValueL<TUint>(KMPXMediaGeneralFlags, aDbflag); |
|
1247 |
|
1248 if (aNonPermissibleActions) |
|
1249 { |
|
1250 // set non-permissible actions |
|
1251 entry->SetTObjectValueL<TMPXGeneralNonPermissibleActions>(KMPXMediaGeneralNonPermissibleActions, |
|
1252 static_cast<TMPXGeneralNonPermissibleActions>(aNonPermissibleActions)); |
|
1253 } |
|
1254 |
|
1255 return entry; |
|
1256 } |
|
1257 |
|
1258 // ---------------------------------------------------------------------------- |
|
1259 // MPXDbCommonUtil::GetColumnTextL |
|
1260 // ---------------------------------------------------------------------------- |
|
1261 // |
|
1262 EXPORT_C TPtrC MPXDbCommonUtil::GetColumnTextL( |
|
1263 RSqlStatement& aStatement, |
|
1264 TInt aField) |
|
1265 { |
|
1266 MPX_FUNC("MPXDbCommonUtil::GetColumnTextL"); |
|
1267 |
|
1268 TPtrC text; |
|
1269 if (aStatement.ColumnSize(aField)) |
|
1270 { |
|
1271 text.Set(aStatement.ColumnTextL(aField)); |
|
1272 } |
|
1273 else |
|
1274 { |
|
1275 text.Set(KNullDesC); |
|
1276 } |
|
1277 |
|
1278 return text; |
|
1279 } |
|
1280 |
|
1281 // ---------------------------------------------------------------------------- |
|
1282 // Add an album item changed message to the message array |
|
1283 // ---------------------------------------------------------------------------- |
|
1284 // |
|
1285 EXPORT_C void MPXDbCommonUtil::AddItemAlbumChangedMessageL( |
|
1286 CMPXMessageArray& aMessageArray, |
|
1287 TMPXItemId aId, |
|
1288 TMPXChangeEventType aChangeType, |
|
1289 TMPXGeneralCategory aCategory, |
|
1290 TUint aUid, |
|
1291 TBool aAlbumArt, |
|
1292 TMPXItemId aDeprecatedId) |
|
1293 { |
|
1294 MPX_FUNC("MPXDbCommonUtil::AddItemChangedMessageL"); |
|
1295 CMPXMessage* message = CMPXMedia::NewL(); |
|
1296 CleanupStack::PushL(message); |
|
1297 |
|
1298 FillItemChangedMessageL(*message, aId, aChangeType, aCategory, aUid, |
|
1299 aDeprecatedId ); |
|
1300 if ( aAlbumArt ) |
|
1301 { |
|
1302 message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aId); |
|
1303 } |
|
1304 if (FindItemChangedMessageL(aMessageArray, *message) == KErrNotFound) |
|
1305 { |
|
1306 aMessageArray.AppendL(*message); // ownership xfer |
|
1307 } |
|
1308 CleanupStack::PopAndDestroy(message); |
|
1309 } |
|
1310 // End of File |