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