|
1 /* |
|
2 * Copyright (c) 2007 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: Responsible for interation with the music table. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <mpxlog.h> |
|
21 #include <mpxmedia.h> |
|
22 #include <mpxmediaarray.h> |
|
23 #include <mpxcollectionpath.h> |
|
24 #include <mpxmediageneraldefs.h> |
|
25 #include <mpxmediamusicdefs.h> |
|
26 #include <mpxmediaaudiodefs.h> |
|
27 #include <mpxmediadrmdefs.h> |
|
28 #include <mpxmediamtpdefs.h> |
|
29 #include <mpxcollectiondbres.rsg> |
|
30 |
|
31 #include "mpxdbcommondef.h" |
|
32 #include "mpxdbcommonstd.h" |
|
33 #include "mpxdbcommonutil.h" |
|
34 #include "mpxresource.h" |
|
35 |
|
36 #include "mpxcollectiondbdef.h" |
|
37 #include "mpxcollectiondbstd.h" |
|
38 #include "mpxdbpluginqueries.h" |
|
39 #include "mpxdbutil.h" |
|
40 #include "mpxdbmanager.h" |
|
41 #include "mpxdbmusic.h" |
|
42 |
|
43 // CONSTANTS |
|
44 |
|
45 // This is what KNullDesC album computes to for the hash |
|
46 // to-do: generate this Id through |
|
47 // MPXDbUtil::GenerateUniqueIdL(EMPXAlbum, KNullDesC, EFalse) |
|
48 // instead of hard-coding the number so if GenerateUniqueIdL |
|
49 // is modified, this constant doesn't need to be redefined |
|
50 const TInt KUnknownAlbumID = 1770790356; |
|
51 // UniqueID column in Uris requests |
|
52 const TInt KColUniqueID = 0; |
|
53 // URI column in Uris requests |
|
54 const TInt KColUri = 1; |
|
55 |
|
56 // ============================ MEMBER FUNCTIONS ============================== |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // Two-phased constructor. |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 CMPXDbMusic* CMPXDbMusic::NewL( |
|
63 CMPXDbManager& aDbManager, |
|
64 CMPXResource& aResource, |
|
65 MMPXDbMusicObserver& aObserver) |
|
66 { |
|
67 MPX_FUNC("CMPXDbMusic::NewL"); |
|
68 CMPXDbMusic* self = CMPXDbMusic::NewLC(aDbManager, aResource, aObserver); |
|
69 CleanupStack::Pop(self); |
|
70 return self; |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // Two-phased constructor. |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 CMPXDbMusic* CMPXDbMusic::NewLC( |
|
78 CMPXDbManager& aDbManager, |
|
79 CMPXResource& aResource, |
|
80 MMPXDbMusicObserver& aObserver) |
|
81 { |
|
82 MPX_FUNC("CMPXDbMusic::NewLC"); |
|
83 |
|
84 CMPXDbMusic* self = new (ELeave) CMPXDbMusic(aDbManager, aObserver); |
|
85 CleanupStack::PushL(self); |
|
86 self->ConstructL(aResource); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // Destructor |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 CMPXDbMusic::~CMPXDbMusic() |
|
95 { |
|
96 MPX_FUNC("CMPXDbMusic::~CMPXDbMusic"); |
|
97 delete iExtensionsDrm; |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // Constructor |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 CMPXDbMusic::CMPXDbMusic( |
|
105 CMPXDbManager& aDbManager, |
|
106 MMPXDbMusicObserver& aObserver) : |
|
107 CMPXDbTable(aDbManager), |
|
108 iObserver(aObserver) |
|
109 { |
|
110 MPX_FUNC("CMPXDbMusic::CMPXDbMusic"); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // Second phase constructor. |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 void CMPXDbMusic::ConstructL( |
|
118 CMPXResource& aResource) |
|
119 { |
|
120 MPX_FUNC("CMPXDbMusic::ConstructL"); |
|
121 |
|
122 BaseConstructL(); |
|
123 iExtensionsDrm = aResource.ReadDesCArrayL(R_MC_FILE_EXTENSIONS_DRM); |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // CMPXDbMusic::AddSongL |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 TUint32 CMPXDbMusic::AddSongL( |
|
131 const CMPXMedia& aMedia, |
|
132 TInt aDrive, |
|
133 CMPXMessageArray* aMessageArray) |
|
134 { |
|
135 MPX_FUNC("CMPXDbMusic::AddSongL"); |
|
136 |
|
137 TUint32 songId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXCollection, |
|
138 aMedia.ValueText(KMPXMediaGeneralUri), EFalse)); |
|
139 |
|
140 if (SongExistsL(songId)) |
|
141 { |
|
142 // Delete the existing record first and start from scratch |
|
143 DeleteSongL(songId, aDrive, ETrue); |
|
144 } |
|
145 // add the song |
|
146 DoAddSongL(songId, aMedia, aDrive, aMessageArray); |
|
147 |
|
148 return songId; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CMPXDbMusic::DoAddSongL |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 TBool CMPXDbMusic::DoAddSongL( |
|
156 TUint32 aSongId, |
|
157 const CMPXMedia& aMedia, |
|
158 TInt aDrive, |
|
159 CMPXMessageArray* aItemChangedMessages) |
|
160 { |
|
161 MPX_FUNC("CMPXDbMusic::DoAddSongL"); |
|
162 |
|
163 CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EMusicFieldCount); |
|
164 CleanupStack::PushL(fields); |
|
165 CDesCArrayFlat* values = new (ELeave) CDesCArrayFlat(EMusicFieldCount); |
|
166 CleanupStack::PushL(values); |
|
167 |
|
168 // add known fields |
|
169 MPXDbCommonUtil::AppendValueL(*fields, *values, KMCMusicUniqueId, aSongId); |
|
170 MPXDbCommonUtil::AppendValueL(*fields, *values, KMCMusicDel, 0); |
|
171 |
|
172 TTime time; |
|
173 time.HomeTime(); |
|
174 HBufC* timeAdded = MPXDbCommonUtil::TTimeToDesLC(time); |
|
175 MPXDbCommonUtil::AppendValueL(*fields, *values, KMCMusicTimeAdded, *timeAdded); |
|
176 CleanupStack::PopAndDestroy(timeAdded); |
|
177 |
|
178 // process the media parameter and construct the fields and values array |
|
179 TBool visible(GenerateMusicFieldsValuesL(aSongId, aMedia, aItemChangedMessages, |
|
180 NULL, *fields, *values, aDrive)); |
|
181 |
|
182 // create the fields and values strings |
|
183 HBufC* fieldStr = MPXDbCommonUtil::StringFromArrayLC(*fields, KMCCommaSign); |
|
184 HBufC* valueStr = MPXDbCommonUtil::StringFromArrayLC(*values, KMCCommaSign); |
|
185 |
|
186 // execute the query |
|
187 iDbManager.ExecuteQueryL(aDrive, KQueryMusicInsert, fieldStr, valueStr); |
|
188 |
|
189 CleanupStack::PopAndDestroy(valueStr); |
|
190 CleanupStack::PopAndDestroy(fieldStr); |
|
191 CleanupStack::PopAndDestroy(values); |
|
192 CleanupStack::PopAndDestroy(fields); |
|
193 |
|
194 return visible; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CMPXDbMusic::UpdateSongL |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 CMPXDbActiveTask::TChangeVisibility CMPXDbMusic::UpdateSongL( |
|
202 TUint32 aSongId, |
|
203 const CMPXMedia& aMedia, |
|
204 CMPXMessageArray& aItemChangedMessages) |
|
205 { |
|
206 MPX_FUNC("CMPXDbMusic::UpdateSongL"); |
|
207 return DoUpdateSongL(aSongId, aMedia, &aItemChangedMessages); |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // CMPXDbMusic::DoUpdateSongL |
|
212 // ---------------------------------------------------------------------------- |
|
213 // |
|
214 CMPXDbActiveTask::TChangeVisibility CMPXDbMusic::DoUpdateSongL( |
|
215 TUint32 aSongId, |
|
216 const CMPXMedia& aMedia, |
|
217 CMPXMessageArray* aItemChangedMessages) |
|
218 { |
|
219 MPX_FUNC("CMPXDbMusic::DoUpdateSongL"); |
|
220 |
|
221 CMPXDbActiveTask::TChangeVisibility visible(CMPXDbActiveTask::ENotVisibile); |
|
222 if (IsSupported(aMedia)) |
|
223 { |
|
224 // retrieve the existing record |
|
225 TInt oldSongId(0); |
|
226 oldSongId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2; |
|
227 if ( oldSongId <= 0 ) |
|
228 { |
|
229 oldSongId = aSongId; |
|
230 } |
|
231 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetSong, oldSongId)); |
|
232 CleanupClosePushL(recordset); |
|
233 |
|
234 if (recordset.Next() != KSqlAtRow) |
|
235 { |
|
236 User::Leave(KErrNotFound); |
|
237 } |
|
238 |
|
239 TDriveUnit driveUnit(MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
|
240 recordset.ColumnInt64(EMusicVolumeId))); |
|
241 visible = DoUpdateSongL(aSongId, aMedia, driveUnit, aItemChangedMessages, |
|
242 recordset); |
|
243 |
|
244 // Update Album table |
|
245 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) || aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
246 { |
|
247 TUint32 albumId = recordset.ColumnInt64(EMusicAlbum); |
|
248 iObserver.UpdateCategoryItemL(EMPXAlbum, albumId, aMedia, driveUnit, aItemChangedMessages); |
|
249 } |
|
250 |
|
251 // Update Artist table |
|
252 if ( aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) ) |
|
253 { |
|
254 TUint32 artistId = recordset.ColumnInt64(EMusicArtist); |
|
255 iObserver.UpdateCategoryItemL(EMPXArtist, artistId, aMedia, driveUnit, aItemChangedMessages); |
|
256 } |
|
257 |
|
258 CleanupStack::PopAndDestroy(&recordset); |
|
259 } |
|
260 |
|
261 return visible; |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------------------------------- |
|
265 // CMPXDbMusic::DoUpdateSongL |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 CMPXDbActiveTask::TChangeVisibility CMPXDbMusic::DoUpdateSongL( |
|
269 TUint32 aSongId, |
|
270 const CMPXMedia& aMedia, |
|
271 TInt aDrive, |
|
272 CMPXMessageArray* aItemChangedMessages, |
|
273 RSqlStatement& aRecordset) |
|
274 { |
|
275 MPX_FUNC("CMPXDbMusic::DoUpdateSongL"); |
|
276 |
|
277 CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EMusicFieldCount); |
|
278 CleanupStack::PushL(fields); |
|
279 CDesCArrayFlat* values = new (ELeave) CDesCArrayFlat(EMusicFieldCount); |
|
280 CleanupStack::PushL(values); |
|
281 |
|
282 TInt oldSongId(0); |
|
283 oldSongId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2; |
|
284 if ( oldSongId <= 0 ) |
|
285 { |
|
286 oldSongId = aSongId; |
|
287 } |
|
288 // process the media parameter and construct the fields and values array |
|
289 CMPXDbActiveTask::TChangeVisibility visible(GenerateMusicFieldsValuesL(oldSongId, aMedia, aItemChangedMessages, |
|
290 &aRecordset, *fields, *values, aDrive)); |
|
291 |
|
292 // construct the SET string |
|
293 HBufC* setStr = MPXDbCommonUtil::StringFromArraysLC(*fields, *values, KMCEqualSign, KMCCommaSign); |
|
294 if (setStr->Length()) |
|
295 { |
|
296 // execute the query |
|
297 iDbManager.ExecuteQueryL(aDrive, KQueryMusicUpdate, setStr, oldSongId); |
|
298 } |
|
299 |
|
300 CleanupStack::PopAndDestroy(setStr); |
|
301 CleanupStack::PopAndDestroy(values); |
|
302 CleanupStack::PopAndDestroy(fields); |
|
303 |
|
304 return visible; |
|
305 } |
|
306 |
|
307 // ---------------------------------------------------------------------------- |
|
308 // CMPXDbMusic::DeleteSongL |
|
309 // ---------------------------------------------------------------------------- |
|
310 // |
|
311 void CMPXDbMusic::DeleteSongL( |
|
312 TUint32 aSongId, |
|
313 TInt aDrive, |
|
314 TBool aDeleteRecord /* = EFalse */) |
|
315 { |
|
316 MPX_FUNC("CMPXDbMusic::DeleteSongL"); |
|
317 |
|
318 TPtrC query(aDeleteRecord ? KQueryMusicDelete() : KQueryMusicDeleteUpdate()); |
|
319 iDbManager.ExecuteQueryL(aDrive, query, aSongId); |
|
320 } |
|
321 |
|
322 // ---------------------------------------------------------------------------- |
|
323 // CMPXDbMusic::DeleteCategoryL |
|
324 // ---------------------------------------------------------------------------- |
|
325 // |
|
326 void CMPXDbMusic::DeleteCategoryL( |
|
327 TMPXGeneralCategory aCategory, |
|
328 TUint32 aCategoryId, |
|
329 CDesCArray& /* aUriArray */, |
|
330 CMPXMessageArray& /* aItemChangedMessages */, |
|
331 TInt aDrive) |
|
332 { |
|
333 MPX_FUNC("CMPXDbMusic::DeleteCategoryL"); |
|
334 TPtrC ptr(MPXDbUtil::MusicFieldNameForCategoryL(aCategory)); |
|
335 iDbManager.ExecuteQueryL(aDrive, KQueryMusicDeleteForCategory, &ptr, aCategoryId); |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CMPXDbMusic::CleanupL |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 void CMPXDbMusic::CleanupL() |
|
343 { |
|
344 MPX_FUNC("CMPXDbMusic::CleanupL"); |
|
345 iDbManager.ExecuteQueryL(KDbManagerAllDrives, KQueryMusicCleanup); |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------------------------------- |
|
349 // CMPXDbMusic::GetNameL |
|
350 // ---------------------------------------------------------------------------- |
|
351 // |
|
352 HBufC* CMPXDbMusic::GetNameL( |
|
353 TUint32 aSongId) |
|
354 { |
|
355 MPX_FUNC("CMPXDbMusic::GetNameL"); |
|
356 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetTitle, aSongId)); |
|
357 CleanupClosePushL(recordset); |
|
358 |
|
359 if (recordset.Next() != KSqlAtRow) |
|
360 { |
|
361 User::LeaveIfError(KErrNotFound); |
|
362 } |
|
363 |
|
364 HBufC* title = MPXDbCommonUtil::GetColumnTextL(recordset, KMPXTableDefaultIndex).AllocL(); |
|
365 CleanupStack::PopAndDestroy(&recordset); |
|
366 |
|
367 return title; |
|
368 } |
|
369 |
|
370 // ---------------------------------------------------------------------------- |
|
371 // CMPXDbMusic::GetUriL |
|
372 // ---------------------------------------------------------------------------- |
|
373 // |
|
374 HBufC* CMPXDbMusic::GetUriL( |
|
375 TUint32 aSongId) |
|
376 { |
|
377 MPX_FUNC("CMPXDbMusic::GetUriL"); |
|
378 |
|
379 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetUri, aSongId)); |
|
380 CleanupClosePushL(recordset); |
|
381 |
|
382 if (recordset.Next() != KSqlAtRow) |
|
383 { |
|
384 User::LeaveIfError(KErrNotFound); |
|
385 } |
|
386 |
|
387 // query fields |
|
388 enum |
|
389 { |
|
390 EMusicUriLocation = 0, |
|
391 EMusicUriVolId |
|
392 }; |
|
393 |
|
394 TUint volId(recordset.ColumnInt64(EMusicUriVolId)); |
|
395 HBufC* fullUri = MPXDbCommonUtil::CreateFullPathL( |
|
396 MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId), |
|
397 MPXDbCommonUtil::GetColumnTextL(recordset, EMusicUriLocation)); |
|
398 |
|
399 CleanupStack::PopAndDestroy(&recordset); |
|
400 |
|
401 return fullUri; |
|
402 } |
|
403 |
|
404 // ---------------------------------------------------------------------------- |
|
405 // CMPXDbMusic::GetDriveL |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 TInt CMPXDbMusic::GetDriveL( |
|
409 TUint32 aSongId) |
|
410 { |
|
411 MPX_FUNC("CMPXDbMusic::GetDriveL"); |
|
412 return MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
|
413 ExecuteIntQueryL(KQueryMusicVolume, aSongId)); |
|
414 } |
|
415 |
|
416 // ---------------------------------------------------------------------------- |
|
417 // CMPXDbMusic::GetSongInfoL |
|
418 // ---------------------------------------------------------------------------- |
|
419 // |
|
420 HBufC* CMPXDbMusic::GetSongInfoL( |
|
421 TUint32 aSongId, |
|
422 TUint32& aArtistId, |
|
423 TUint32& aAlbumId, |
|
424 TUint32& aGenreId, |
|
425 TUint32& aComposerId, |
|
426 TInt& aDriveId) |
|
427 { |
|
428 MPX_FUNC("CMPXDbMusic::GetSongInfoL"); |
|
429 |
|
430 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicInfo, aSongId)); |
|
431 CleanupClosePushL(recordset); |
|
432 |
|
433 if (recordset.Next() != KSqlAtRow) |
|
434 { |
|
435 User::Leave(KErrNotFound); |
|
436 } |
|
437 |
|
438 aDriveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
|
439 recordset.ColumnInt64(EMusicVolumeId)); |
|
440 aArtistId = recordset.ColumnInt64(EMusicArtist); |
|
441 aAlbumId = recordset.ColumnInt64(EMusicAlbum); |
|
442 aGenreId = recordset.ColumnInt64(EMusicGenre); |
|
443 aComposerId = recordset.ColumnInt64(EMusicComposer); |
|
444 HBufC* uri = ConstructUriL(recordset); |
|
445 |
|
446 CleanupStack::PopAndDestroy(&recordset); |
|
447 |
|
448 return uri; |
|
449 } |
|
450 |
|
451 // ---------------------------------------------------------------------------- |
|
452 // CMPXDbMusic::GetSongL |
|
453 // ---------------------------------------------------------------------------- |
|
454 // |
|
455 TInt CMPXDbMusic::GetSongL( |
|
456 const CMPXMedia& aCriteria, |
|
457 CMPXMedia*& aMedia) |
|
458 { |
|
459 MPX_FUNC("CMPXDbMusic::GetSongL"); |
|
460 |
|
461 TUint32 songId(0); |
|
462 |
|
463 // find song Id, title, URI, and general flags from its Id and/or URI. Do not use "aCriteria" |
|
464 // because it may contain attributes other than Id and URI. We don't want to search the |
|
465 // song by fields other than the ID and URI because other attributes for the song may have |
|
466 // been changed in the collection since the song was added |
|
467 CMPXMedia* criteria = CMPXMedia::NewL(); |
|
468 CleanupStack::PushL(criteria); |
|
469 if (aCriteria.IsSupported(KMPXMediaGeneralId)) |
|
470 { |
|
471 songId = (aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2; |
|
472 criteria->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, songId); |
|
473 } |
|
474 else if (aCriteria.IsSupported(KMPXMediaGeneralUri)) |
|
475 { |
|
476 criteria->SetTextValueL(KMPXMediaGeneralUri, |
|
477 aCriteria.ValueText(KMPXMediaGeneralUri)); |
|
478 } |
|
479 |
|
480 // get the criteria string |
|
481 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(songId, 0, EMPXItem, *criteria); |
|
482 |
|
483 // execute the query |
|
484 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicSong, criteriaStr)); |
|
485 CleanupClosePushL(recordset); |
|
486 |
|
487 TInt err(KErrNone); |
|
488 if ((err = recordset.Next()) == KSqlAtRow) |
|
489 { |
|
490 RArray<TMPXAttribute> attributes; |
|
491 CleanupClosePushL(attributes); |
|
492 attributes.AppendL(TMPXAttribute(KMPXMediaIdGeneral, |
|
493 EMPXMediaGeneralId | EMPXMediaGeneralTitle | EMPXMediaGeneralUri | EMPXMediaGeneralFlags)); |
|
494 |
|
495 aMedia = CMPXMedia::NewL(); |
|
496 CleanupStack::PushL(aMedia); |
|
497 |
|
498 UpdateMediaL(recordset, attributes.Array(), *aMedia); |
|
499 |
|
500 CleanupStack::Pop(aMedia); |
|
501 CleanupStack::PopAndDestroy(&attributes); |
|
502 |
|
503 err = KErrNone; |
|
504 } |
|
505 else |
|
506 { |
|
507 err = KErrNotFound; |
|
508 } |
|
509 |
|
510 CleanupStack::PopAndDestroy(&recordset); |
|
511 CleanupStack::PopAndDestroy(criteriaStr); |
|
512 CleanupStack::PopAndDestroy(criteria); |
|
513 |
|
514 return err; |
|
515 } |
|
516 |
|
517 // ---------------------------------------------------------------------------- |
|
518 // CMPXDbMusic::GetRecentlyPlayedSongsL |
|
519 // ---------------------------------------------------------------------------- |
|
520 // |
|
521 void CMPXDbMusic::GetRecentlyPlayedSongsL( |
|
522 const TArray<TMPXAttribute>& aAttrs, |
|
523 CMPXMediaArray& aMediaArray) |
|
524 { |
|
525 MPX_FUNC("CMPXDbMusic::GetRecentlyPlayedSongsL"); |
|
526 ExecuteMediaQueryL(aAttrs, aMediaArray, KQueryMusicGetRecentlyPlayed, |
|
527 KMPXMaxRecentlyPlayedSongs); |
|
528 } |
|
529 |
|
530 // ---------------------------------------------------------------------------- |
|
531 // CMPXDbMusic::GetMostPlayedSongsL |
|
532 // ---------------------------------------------------------------------------- |
|
533 // |
|
534 void CMPXDbMusic::GetMostPlayedSongsL( |
|
535 const TArray<TMPXAttribute>& aAttrs, |
|
536 CMPXMediaArray& aMediaArray) |
|
537 { |
|
538 MPX_FUNC("CMPXDbMusic::GetMostPlayedSongsL"); |
|
539 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
540 KQueryMusicGetMostPlayed() : KQueryMusicGetMostPlayedNoCategories(), |
|
541 KMPXMaxMostPlayedSongs); |
|
542 } |
|
543 |
|
544 // ---------------------------------------------------------------------------- |
|
545 // CMPXDbMusic::GetRecentlyAddedSongsL |
|
546 // ---------------------------------------------------------------------------- |
|
547 // |
|
548 void CMPXDbMusic::GetRecentlyAddedSongsL( |
|
549 const TArray<TMPXAttribute>& aAttrs, |
|
550 CMPXMediaArray& aMediaArray) |
|
551 { |
|
552 MPX_FUNC("CMPXDbMusic::GetRecentlyAddedSongsL"); |
|
553 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
554 KQueryMusicGetRecentlyAdded() : KQueryMusicGetRecentlyAddedNoCategories()); |
|
555 } |
|
556 |
|
557 // ---------------------------------------------------------------------------- |
|
558 // CMPXDbMusic::CountL |
|
559 // ---------------------------------------------------------------------------- |
|
560 // |
|
561 TInt CMPXDbMusic::CountL() |
|
562 { |
|
563 MPX_FUNC("CMPXDbMusic::CountL"); |
|
564 return ExecuteSumQueryL(KQueryMusicCount); |
|
565 } |
|
566 |
|
567 // ---------------------------------------------------------------------------- |
|
568 // CMPXDbMusic::GetAlbumsForArtistL |
|
569 // ---------------------------------------------------------------------------- |
|
570 // |
|
571 void CMPXDbMusic::GetAlbumsForArtistL( |
|
572 TUint32 aArtistId, |
|
573 CMPXMediaArray& aMediaArray) |
|
574 { |
|
575 MPX_FUNC("CMPXDbMusic::GetAlbumsForArtistL"); |
|
576 |
|
577 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicAlbum, aArtistId)); |
|
578 CleanupClosePushL(recordset); |
|
579 |
|
580 TInt err(KErrNone); |
|
581 while ((err = recordset.Next()) == KSqlAtRow) |
|
582 { |
|
583 TUint32 albumId(recordset.ColumnInt64(KMPXTableDefaultIndex)); |
|
584 |
|
585 CMPXMedia* media = CMPXMedia::NewL(); |
|
586 CleanupStack::PushL(media); |
|
587 |
|
588 media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, albumId); |
|
589 media->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
590 media->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
|
591 |
|
592 aMediaArray.AppendL(*media); |
|
593 CleanupStack::PopAndDestroy(media); |
|
594 } |
|
595 |
|
596 CleanupStack::PopAndDestroy(&recordset); |
|
597 if (err != KSqlAtEnd) |
|
598 { |
|
599 User::LeaveIfError(KErrCorrupt); |
|
600 } |
|
601 } |
|
602 |
|
603 // ---------------------------------------------------------------------------- |
|
604 // CMPXDbMusic::GetSongL |
|
605 // ---------------------------------------------------------------------------- |
|
606 // |
|
607 void CMPXDbMusic::GetSongL( |
|
608 TInt aSongId, |
|
609 const TArray<TMPXAttribute>& aAttrs, |
|
610 CMPXMedia& aMedia) |
|
611 { |
|
612 MPX_FUNC("CMPXDbMusic::GetSongL"); |
|
613 ExecuteMediaQueryL(aAttrs, aMedia, ExtraFieldsRequired(aAttrs) ? |
|
614 KQueryMusicGetSong() : KQueryMusicGetSongNoCategories(), aSongId); |
|
615 } |
|
616 |
|
617 // ---------------------------------------------------------------------------- |
|
618 // CMPXDbMusic::GetAllSongsL |
|
619 // ---------------------------------------------------------------------------- |
|
620 // |
|
621 void CMPXDbMusic::GetAllSongsL( |
|
622 TInt aDrive, |
|
623 TInt aPlaylistId, |
|
624 const TArray<TMPXAttribute>& aAttrs, |
|
625 CMPXMediaArray& aMediaArray) |
|
626 { |
|
627 MPX_FUNC("CMPXDbMusic::GetAllSongsL"); |
|
628 ExecuteMediaQueryL(aDrive, aAttrs, aMediaArray, KQueryMusicGetAllSongsInfobyPl(), aPlaylistId); |
|
629 } |
|
630 |
|
631 // ---------------------------------------------------------------------------- |
|
632 // CMPXDbMusic::GetAllSongsL |
|
633 // ---------------------------------------------------------------------------- |
|
634 // |
|
635 void CMPXDbMusic::GetAllSongsL( |
|
636 const TArray<TMPXAttribute>& aAttrs, |
|
637 CMPXMediaArray& aMediaArray) |
|
638 { |
|
639 MPX_FUNC("CMPXDbMusic::GetAllSongsL"); |
|
640 |
|
641 // do not execute the joins if no category name is required |
|
642 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
643 KQueryMusicGetAllSongs() : KQueryMusicGetAllSongsNoCategories()); |
|
644 } |
|
645 |
|
646 // ---------------------------------------------------------------------------- |
|
647 // CMPXDbMusic::GetAllSongsLimitedL |
|
648 // ---------------------------------------------------------------------------- |
|
649 // |
|
650 void CMPXDbMusic::GetAllSongsLimitedL(const TArray<TMPXAttribute>& aAttrs, |
|
651 CMPXMediaArray& aMediaArray, TInt aLimit) |
|
652 { |
|
653 MPX_FUNC("CMPXDbMusic::GetAllSongsLimitedL"); |
|
654 |
|
655 // Gets a subset of the data from all songs ordered by title |
|
656 HBufC* query = HBufC::NewLC( KQueryMusicGetSongsLimited().Length() + KMCIntegerLen ); |
|
657 query->Des().Format( KQueryMusicGetSongsLimited, aLimit ); |
|
658 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
659 CleanupStack::PopAndDestroy( query ); |
|
660 } |
|
661 |
|
662 // ---------------------------------------------------------------------------- |
|
663 // CMPXDbMusic::GetSongsInBlockL |
|
664 // ---------------------------------------------------------------------------- |
|
665 // |
|
666 void CMPXDbMusic::GetSongsInBlockL( |
|
667 const TArray<TMPXAttribute>& aAttrs, |
|
668 CMPXMediaArray& aMediaArray, |
|
669 TPtrC aTitle, |
|
670 TUint aNumOfSongs, |
|
671 TBool aAsc) |
|
672 { |
|
673 MPX_FUNC("CMPXDbMusic::GetSongsInBlockL"); |
|
674 |
|
675 if (aAsc) |
|
676 { |
|
677 ExecuteMediaQueryL(aAttrs, aMediaArray, KQueryMusicGetSongsInBlockAsc, |
|
678 aTitle, aNumOfSongs, ETrue, EAscQuery ); |
|
679 } |
|
680 else |
|
681 { |
|
682 ExecuteMediaQueryL(aAttrs, aMediaArray, KQueryMusicGetSongsInBlockDsc, |
|
683 aTitle, aNumOfSongs, EFalse, EDscQuery ); |
|
684 } |
|
685 } |
|
686 |
|
687 // ---------------------------------------------------------------------------- |
|
688 // CMPXDbMusic::GetSongsAtOffsetL |
|
689 // ---------------------------------------------------------------------------- |
|
690 // |
|
691 void CMPXDbMusic::GetSongsAtOffsetL( CMPXMediaArray& aMediaArray, |
|
692 const TArray<TMPXAttribute>& aAttrs, |
|
693 TInt aOffset, |
|
694 TInt aCount ) |
|
695 { |
|
696 MPX_DEBUG1("CMPXDbMusic::GetSongsAtOffsetL <--"); |
|
697 |
|
698 ExecuteMediaQueryL(aAttrs, aMediaArray, KQueryMusicGetSongsAtOffset, |
|
699 aCount, aOffset, EOffSetQuery ); |
|
700 |
|
701 MPX_DEBUG1("CMPXDbMusic::GetSongsAtOffsetL() -->"); |
|
702 } |
|
703 |
|
704 // ---------------------------------------------------------------------------- |
|
705 // CMPXDbMusic::GetSongsForArtistL |
|
706 // ---------------------------------------------------------------------------- |
|
707 // |
|
708 void CMPXDbMusic::GetSongsForArtistL( |
|
709 TUint aArtistId, |
|
710 const TArray<TMPXAttribute>& aAttrs, |
|
711 CMPXMediaArray& aMediaArray) |
|
712 { |
|
713 MPX_FUNC("CMPXDbMusic::GetSongsForArtistL"); |
|
714 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
715 KQueryMusicGetSongsForArtist() : KQueryMusicGetSongsForArtistNoCategories(), |
|
716 aArtistId); |
|
717 } |
|
718 |
|
719 // ---------------------------------------------------------------------------- |
|
720 // CMPXDbMusic::GetSongsForAlbumL |
|
721 // ---------------------------------------------------------------------------- |
|
722 // |
|
723 void CMPXDbMusic::GetSongsForAlbumL( |
|
724 TUint aAlbumId, |
|
725 const TArray<TMPXAttribute>& aAttrs, |
|
726 CMPXMediaArray& aMediaArray) |
|
727 { |
|
728 MPX_FUNC("CMPXDbMusic::GetSongsForAlbumL"); |
|
729 |
|
730 TPtrC query; |
|
731 if (aAlbumId == KUnknownAlbumID) |
|
732 { |
|
733 query.Set(ExtraFieldsRequired(aAttrs) ? KQueryMusicGetSongsForUnknownAlbum() : |
|
734 KQueryMusicGetSongsForUnknownAlbumNoCategories()); |
|
735 } |
|
736 else |
|
737 { |
|
738 query.Set(ExtraFieldsRequired(aAttrs) ? KQueryMusicGetSongsForAlbum() : |
|
739 KQueryMusicGetSongsForAlbumNoCategories()); |
|
740 } |
|
741 |
|
742 ExecuteMediaQueryL(aAttrs, aMediaArray, query, aAlbumId); |
|
743 } |
|
744 |
|
745 // ---------------------------------------------------------------------------- |
|
746 // CMPXDbMusic::GetSongsForArtistAndAlbumL |
|
747 // ---------------------------------------------------------------------------- |
|
748 // |
|
749 void CMPXDbMusic::GetSongsForArtistAndAlbumL( |
|
750 TUint aArtistId, |
|
751 TUint aAlbumId, |
|
752 const TArray<TMPXAttribute>& aAttrs, |
|
753 CMPXMediaArray& aMediaArray) |
|
754 { |
|
755 MPX_FUNC("CMPXDbMusic::GetSongsForArtistAndAlbumL"); |
|
756 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
757 KQueryMusicGetSongsForArtistAlbum() : KQueryMusicGetSongsForArtistAlbumNoCategories(), |
|
758 aArtistId, aAlbumId); |
|
759 } |
|
760 |
|
761 // ---------------------------------------------------------------------------- |
|
762 // CMPXDbMusic::GetSongsForGenreL |
|
763 // ---------------------------------------------------------------------------- |
|
764 // |
|
765 void CMPXDbMusic::GetSongsForGenreL( |
|
766 TUint aGenreId, |
|
767 const TArray<TMPXAttribute>& aAttrs, |
|
768 CMPXMediaArray& aMediaArray) |
|
769 { |
|
770 MPX_FUNC("CMPXDbMusic::GetSongsForGenreL"); |
|
771 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
772 KQueryMusicGetSongsForGenre() : KQueryMusicGetSongsForGenreNoCategories(), |
|
773 aGenreId); |
|
774 } |
|
775 |
|
776 // ---------------------------------------------------------------------------- |
|
777 // CMPXDbMusic::GetSongsForComposerL |
|
778 // ---------------------------------------------------------------------------- |
|
779 // |
|
780 void CMPXDbMusic::GetSongsForComposerL( |
|
781 TUint aComposerId, |
|
782 const TArray<TMPXAttribute>& aAttrs, |
|
783 CMPXMediaArray& aMediaArray) |
|
784 { |
|
785 MPX_FUNC("CMPXDbMusic::GetSongsForComposerL"); |
|
786 ExecuteMediaQueryL(aAttrs, aMediaArray, ExtraFieldsRequired(aAttrs) ? |
|
787 KQueryMusicGetSongsForComposer() : KQueryMusicGetSongsForComposerNoCategories(), |
|
788 aComposerId); |
|
789 } |
|
790 |
|
791 // ---------------------------------------------------------------------------- |
|
792 // CMPXDbMusic::AllSongsDurationL |
|
793 // ---------------------------------------------------------------------------- |
|
794 // |
|
795 TInt CMPXDbMusic::AllSongsDurationL() |
|
796 { |
|
797 MPX_FUNC("CMPXDbMusic::AllSongsDurationL"); |
|
798 return ExecuteSumQueryL(KQueryMusicDurationAll); |
|
799 } |
|
800 |
|
801 // ---------------------------------------------------------------------------- |
|
802 // CMPXDbMusic::ArtistDurationL |
|
803 // ---------------------------------------------------------------------------- |
|
804 // |
|
805 TInt CMPXDbMusic::ArtistDurationL( |
|
806 TUint aArtistId) |
|
807 { |
|
808 MPX_FUNC("CMPXDbMusic::ArtistDurationL"); |
|
809 return ExecuteSumQueryL(KQueryMusicDurationArtist, aArtistId); |
|
810 } |
|
811 |
|
812 // ---------------------------------------------------------------------------- |
|
813 // CMPXDbMusic::AlbumDurationL |
|
814 // ---------------------------------------------------------------------------- |
|
815 // |
|
816 TInt CMPXDbMusic::AlbumDurationL( |
|
817 TUint aAlbumId) |
|
818 { |
|
819 MPX_FUNC("CMPXDbMusic::AlbumDurationL"); |
|
820 return ExecuteSumQueryL(KQueryMusicDurationAlbum, aAlbumId); |
|
821 } |
|
822 |
|
823 // ---------------------------------------------------------------------------- |
|
824 // CMPXDbMusic::ArtistAlbumDurationL |
|
825 // ---------------------------------------------------------------------------- |
|
826 // |
|
827 TInt CMPXDbMusic::ArtistAlbumDurationL( |
|
828 TUint aArtistId, |
|
829 TUint aAlbumId) |
|
830 { |
|
831 MPX_FUNC("CMPXDbMusic::ArtistAlbumDurationL"); |
|
832 return ExecuteSumQueryL(KQueryMusicDurationArtistAlbum, aArtistId, aAlbumId); |
|
833 } |
|
834 |
|
835 // ---------------------------------------------------------------------------- |
|
836 // CMPXDbMusic::GenreDurationL |
|
837 // ---------------------------------------------------------------------------- |
|
838 // |
|
839 TInt CMPXDbMusic::GenreDurationL( |
|
840 TUint aGenreId) |
|
841 { |
|
842 MPX_FUNC("CMPXDbMusic::GenreDurationL"); |
|
843 return ExecuteSumQueryL(KQueryMusicDurationGenre, aGenreId); |
|
844 } |
|
845 |
|
846 // ---------------------------------------------------------------------------- |
|
847 // CMPXDbMusic::ComposerDurationL |
|
848 // ---------------------------------------------------------------------------- |
|
849 // |
|
850 TInt CMPXDbMusic::ComposerDurationL( |
|
851 TUint aComposerId) |
|
852 { |
|
853 MPX_FUNC("CMPXDbMusic::ComposerDurationL"); |
|
854 return ExecuteSumQueryL(KQueryMusicDurationComposer, aComposerId); |
|
855 } |
|
856 |
|
857 // ---------------------------------------------------------------------------- |
|
858 // CMPXDbMusic::RecentlyPlayedDurationL |
|
859 // ---------------------------------------------------------------------------- |
|
860 // |
|
861 TInt CMPXDbMusic::RecentlyPlayedDurationL() |
|
862 { |
|
863 MPX_FUNC("CMPXDbMusic::RecentlyPlayedDurationL"); |
|
864 return ExecuteSumQueryL(KQueryMusicDurationRecentlyPlayed, KMPXMaxRecentlyPlayedSongs); |
|
865 } |
|
866 |
|
867 // ---------------------------------------------------------------------------- |
|
868 // CMPXDbMusic::MostPlayedDurationL |
|
869 // ---------------------------------------------------------------------------- |
|
870 // |
|
871 TInt CMPXDbMusic::MostPlayedDurationL() |
|
872 { |
|
873 MPX_FUNC("CMPXDbMusic::MostPlayedDurationL"); |
|
874 return ExecuteSumQueryL(KQueryMusicDurationMostPlayed, KMPXMaxMostPlayedSongs); |
|
875 } |
|
876 |
|
877 // ---------------------------------------------------------------------------- |
|
878 // CMPXDbMusic::RecentlyAddedDurationL |
|
879 // ---------------------------------------------------------------------------- |
|
880 // |
|
881 TInt CMPXDbMusic::RecentlyAddedDurationL() |
|
882 { |
|
883 MPX_FUNC("CMPXDbMusic::RecentlyAddedDurationL"); |
|
884 return ExecuteSumQueryL(KQueryMusicDurationRecentlyAdded); |
|
885 } |
|
886 |
|
887 // ---------------------------------------------------------------------------- |
|
888 // CMPXDbMusic::FindSongsL |
|
889 // ---------------------------------------------------------------------------- |
|
890 // |
|
891 void CMPXDbMusic::FindSongsL( |
|
892 TUint32 aGeneralId, |
|
893 TUint32 aContainerId, |
|
894 TMPXGeneralType aType, |
|
895 const CMPXMedia& aCriteria, |
|
896 const TArray<TMPXAttribute>& aAttrs, |
|
897 CMPXMediaArray& aMediaArray) |
|
898 { |
|
899 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
|
900 |
|
901 // get the selection criteria string |
|
902 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
|
903 aCriteria); |
|
904 |
|
905 // construct the sort order depending on category. Albums are always sorted by track, |
|
906 // then name, except for unknown album. Songs are sorted by name for unknown album. |
|
907 // NULL track number is stored as KMaxTInt so that they will be sorted to the end |
|
908 TPtrC sortOrder; |
|
909 if ((aType == EMPXGroup) && (MPX_ITEM_CATEGORY(aGeneralId) == EMPXAlbum) && |
|
910 (aGeneralId != MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAlbum, KNullDesC, EFalse))) |
|
911 { |
|
912 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
|
913 } |
|
914 else |
|
915 { |
|
916 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
|
917 } |
|
918 |
|
919 // construct the query |
|
920 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
|
921 sortOrder.Length()); |
|
922 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
|
923 |
|
924 // iterate the results and append media objects to the destination array |
|
925 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
926 |
|
927 CleanupStack::PopAndDestroy(query); |
|
928 CleanupStack::PopAndDestroy(criteriaStr); |
|
929 } |
|
930 |
|
931 // ---------------------------------------------------------------------------- |
|
932 // CMPXDbMusic::GetDriveTrackCount |
|
933 // ---------------------------------------------------------------------------- |
|
934 // |
|
935 TUint CMPXDbMusic::GetDriveTrackCountL(TInt aDrive) |
|
936 { |
|
937 TUint count(0); |
|
938 |
|
939 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDrive,KQueryMusicCount)); |
|
940 CleanupClosePushL(recordset); |
|
941 |
|
942 if (recordset.Next() != KSqlAtRow) |
|
943 { |
|
944 User::Leave(KErrCorrupt); |
|
945 } |
|
946 |
|
947 count = TUint(recordset.ColumnInt64(KMPXTableDefaultIndex)); |
|
948 CleanupStack::PopAndDestroy(&recordset); |
|
949 |
|
950 return count; |
|
951 } |
|
952 |
|
953 // ---------------------------------------------------------------------------- |
|
954 // CMPXDbMusic::GetMusicUriArrayL |
|
955 // ---------------------------------------------------------------------------- |
|
956 // |
|
957 void CMPXDbMusic::GetMusicUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords, |
|
958 CDesCArray& aUriArr, TInt& aLastID) |
|
959 { |
|
960 MPX_FUNC("CMPXDbMusic::GetMusicUriArrayL"); |
|
961 |
|
962 HBufC* query = NULL; |
|
963 if(aFromID == 0) |
|
964 { |
|
965 query = HBufC::NewLC(KQueryMusicGetMusicUris().Length() + KMCIntegerLen); |
|
966 query->Des().Format(KQueryMusicGetMusicUris, aRecords); |
|
967 } |
|
968 else |
|
969 { |
|
970 query = HBufC::NewLC(KQueryMusicGetMusicUrisFrom().Length() + 2*KMCIntegerLen); |
|
971 query->Des().Format(KQueryMusicGetMusicUrisFrom, aFromID, aRecords); |
|
972 } |
|
973 |
|
974 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDrive,*query)); |
|
975 |
|
976 CleanupStack::PopAndDestroy(query); |
|
977 |
|
978 CleanupClosePushL(recordset); |
|
979 |
|
980 TInt lastID = 0; |
|
981 TInt err(KErrNone); |
|
982 while((err = recordset.Next()) == KSqlAtRow) |
|
983 { |
|
984 HBufC* fullPath = MPXDbCommonUtil::CreateFullPathL(aDrive, |
|
985 MPXDbCommonUtil::GetColumnTextL(recordset, KColUri)); |
|
986 CleanupStack::PushL(fullPath); |
|
987 aUriArr.AppendL(*fullPath); |
|
988 CleanupStack::PopAndDestroy(fullPath); |
|
989 |
|
990 lastID = recordset.ColumnInt(KColUniqueID); |
|
991 } |
|
992 CleanupStack::PopAndDestroy(&recordset); |
|
993 |
|
994 aLastID = lastID; |
|
995 |
|
996 if (err!= KSqlAtEnd) |
|
997 { |
|
998 User::Leave(KErrCorrupt); |
|
999 } |
|
1000 } |
|
1001 |
|
1002 // ---------------------------------------------------------------------------- |
|
1003 // CMPXDbMusic::ArtistForAlbumL |
|
1004 // ---------------------------------------------------------------------------- |
|
1005 // |
|
1006 TUint32 CMPXDbMusic::ArtistForAlbumL(const TUint32 aId) |
|
1007 { |
|
1008 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetArtistForAlbum, aId)); |
|
1009 |
|
1010 CleanupClosePushL(recordset); |
|
1011 if (recordset.Next() != KSqlAtRow) |
|
1012 { |
|
1013 User::Leave(KErrNotFound); |
|
1014 } |
|
1015 |
|
1016 TUint32 artistId = recordset.ColumnInt64(KMPXTableDefaultIndex); |
|
1017 CleanupStack::PopAndDestroy(&recordset); |
|
1018 |
|
1019 return artistId; |
|
1020 } |
|
1021 |
|
1022 // ---------------------------------------------------------------------------- |
|
1023 // CMPXDbMusic::RefreshStartL |
|
1024 // ---------------------------------------------------------------------------- |
|
1025 // |
|
1026 void CMPXDbMusic::RefreshStartL() |
|
1027 { |
|
1028 iRefresh = ETrue; |
|
1029 MPX_FUNC("CMPXDbMusic::RefreshStartL"); |
|
1030 } |
|
1031 |
|
1032 // ---------------------------------------------------------------------------- |
|
1033 // CMPXDbMusic::RefreshEndL |
|
1034 // ---------------------------------------------------------------------------- |
|
1035 // |
|
1036 void CMPXDbMusic::RefreshEndL() |
|
1037 { |
|
1038 MPX_FUNC("CMPXDbMusic::RefreshEndL"); |
|
1039 iRefresh = EFalse; |
|
1040 } |
|
1041 |
|
1042 // ---------------------------------------------------------------------------- |
|
1043 // CMPXDbMusic::SongExistsL |
|
1044 // ---------------------------------------------------------------------------- |
|
1045 // |
|
1046 TBool CMPXDbMusic::SongExistsL( |
|
1047 TUint32 aSongId) |
|
1048 { |
|
1049 MPX_FUNC("CMPXDbMusic::SongExistsL"); |
|
1050 |
|
1051 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicVolumeAll, aSongId)); |
|
1052 TBool found = (recordset.Next() == KSqlAtRow); |
|
1053 recordset.Close(); |
|
1054 |
|
1055 return found; |
|
1056 } |
|
1057 |
|
1058 // ---------------------------------------------------------------------------- |
|
1059 // CMPXDbMusic::UpdateMediaL |
|
1060 // ---------------------------------------------------------------------------- |
|
1061 // |
|
1062 void CMPXDbMusic::UpdateMediaL( |
|
1063 RSqlStatement& aMusicTable, |
|
1064 const TArray<TMPXAttribute>& aAttrs, |
|
1065 CMPXMedia& aMedia) |
|
1066 { |
|
1067 MPX_FUNC("CMPXDbMusic::UpdateMediaL"); |
|
1068 |
|
1069 TInt count(aAttrs.Count()); |
|
1070 for (TInt i = 0; i < count; ++i) |
|
1071 { |
|
1072 switch (aAttrs[i].ContentId()) |
|
1073 { |
|
1074 case KMPXMediaIdGeneral: |
|
1075 { |
|
1076 UpdateMediaGeneralL(aMusicTable, aAttrs[i].AttributeId(), aMedia); |
|
1077 break; |
|
1078 } |
|
1079 case KMPXMediaIdMusic: |
|
1080 { |
|
1081 UpdateMediaMusicL(aMusicTable, aAttrs[i].AttributeId(), aMedia); |
|
1082 break; |
|
1083 } |
|
1084 case KMPXMediaIdDrm: |
|
1085 { |
|
1086 // DRM is set by drm helper |
|
1087 break; |
|
1088 } |
|
1089 case KMPXMediaIdMTP: |
|
1090 { |
|
1091 // Only attribute stored in db is MTP drm status |
|
1092 UpdateMediaMTPL(aMusicTable, aAttrs[i].AttributeId(), aMedia); |
|
1093 break; |
|
1094 } |
|
1095 case KMPXMediaIdAudio: |
|
1096 { |
|
1097 UpdateMediaAudioL(aMusicTable, aAttrs[i].AttributeId(), aMedia); |
|
1098 break; |
|
1099 } |
|
1100 default: |
|
1101 // Do not leave. If this plugin doesn't support |
|
1102 // the content id they want, just return what we have |
|
1103 break; |
|
1104 } // end switch |
|
1105 } // end for |
|
1106 } |
|
1107 |
|
1108 // ---------------------------------------------------------------------------- |
|
1109 // CMPXDbMusic::UpdateMediaGeneralL |
|
1110 // ---------------------------------------------------------------------------- |
|
1111 // |
|
1112 void CMPXDbMusic::UpdateMediaGeneralL( |
|
1113 RSqlStatement& aMusicTable, |
|
1114 const TUint aAttrId, |
|
1115 CMPXMedia& aMedia) |
|
1116 { |
|
1117 MPX_DEBUG1("-->CMPXDbMusic::UpdateMediaGeneralL"); |
|
1118 MPX_DEBUG2(" aAttrId=%b", aAttrId); |
|
1119 |
|
1120 aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem ); |
|
1121 aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong ); |
|
1122 |
|
1123 // FIX ME, temporary always fetch item ID |
|
1124 //if (aAttrId & EMPXMediaGeneralId) |
|
1125 if (!aMedia.IsSupported(KMPXMediaGeneralId)) |
|
1126 { |
|
1127 MPX_DEBUG1(" !aMedia.IsSupported(KMPXMediaGeneralId)"); |
|
1128 TUint32 songId(aMusicTable.ColumnInt64(EMusicUniqueId)); |
|
1129 TInt columnCount(aMusicTable.ColumnCount()); |
|
1130 if(columnCount == 37 && aMusicTable.ColumnIndex(_L("PlUId"))==35) |
|
1131 { |
|
1132 TUint32 pListUId(aMusicTable.ColumnInt64(35)); |
|
1133 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(pListUId, songId)); |
|
1134 } |
|
1135 else |
|
1136 { |
|
1137 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, songId); |
|
1138 } |
|
1139 MPX_DEBUG2(" SongId[%d]", songId); |
|
1140 } |
|
1141 // FIX ME temporary always fetch URI |
|
1142 if (aAttrId & EMPXMediaGeneralUri) |
|
1143 { |
|
1144 MPX_DEBUG1(" !aMedia.IsSupported(KMPXMediaGeneralUri)"); |
|
1145 HBufC* uri = ConstructUriL(aMusicTable); |
|
1146 CleanupStack::PushL(uri); |
|
1147 aMedia.SetTextValueL(KMPXMediaGeneralUri, *uri); |
|
1148 MPX_DEBUG2(" FullPath[%S]", uri); |
|
1149 CleanupStack::PopAndDestroy(uri); |
|
1150 } |
|
1151 if (aAttrId & EMPXMediaGeneralDrive) |
|
1152 { |
|
1153 MPX_DEBUG1(" EMPXMediaGeneralDrive"); |
|
1154 TDriveUnit driveUnit; |
|
1155 if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
1156 { |
|
1157 MPX_DEBUG1(" aMedia.IsSupported(KMPXMediaGeneralUri)"); |
|
1158 driveUnit = aMedia.ValueText(KMPXMediaGeneralUri); |
|
1159 MPX_DEBUG2(" driveUnit=%d", (TInt)driveUnit); |
|
1160 } |
|
1161 else |
|
1162 { |
|
1163 MPX_DEBUG1(" !aMedia.IsSupported(KMPXMediaGeneralUri)"); |
|
1164 driveUnit = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
|
1165 aMusicTable.ColumnInt64(EMusicVolumeId)); |
|
1166 MPX_DEBUG2(" driveUnit=%d", (TInt)driveUnit); |
|
1167 } |
|
1168 |
|
1169 TPtrC driveName(driveUnit.Name()); |
|
1170 aMedia.SetTextValueL(KMPXMediaGeneralDrive, driveName); |
|
1171 MPX_DEBUG2(" Drive[%S]", &driveName); |
|
1172 } |
|
1173 if (aAttrId & EMPXMediaGeneralSize) |
|
1174 { |
|
1175 MPX_DEBUG1(" EMPXMediaGeneralSize"); |
|
1176 // to-do: store this in the DB |
|
1177 } |
|
1178 if (aAttrId & EMPXMediaGeneralDuration) |
|
1179 { |
|
1180 MPX_DEBUG1(" EMPXMediaGeneralDuration"); |
|
1181 TInt32 duration(aMusicTable.ColumnInt(EMusicDuration)); |
|
1182 aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, duration); |
|
1183 MPX_DEBUG2(" Duration[%d]", duration); |
|
1184 } |
|
1185 if ((aAttrId & EMPXMediaGeneralTitle) && !aMedia.IsSupported(KMPXMediaGeneralTitle)) |
|
1186 { |
|
1187 MPX_DEBUG1(" EMPXMediaGeneralTitle"); |
|
1188 TPtrC title(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicTitle)); |
|
1189 aMedia.SetTextValueL(KMPXMediaGeneralTitle, title); |
|
1190 MPX_DEBUG2(" Title[%S]", &title); |
|
1191 } |
|
1192 if ( aAttrId & EMPXMediaGeneralDate) |
|
1193 { |
|
1194 MPX_DEBUG1(" EMPXMediaGeneralDate"); |
|
1195 const TDesC& dateStr(MPXDbCommonUtil::GetColumnTextL (aMusicTable, |
|
1196 EMusicTimeAdded)); |
|
1197 if ( dateStr.Compare (KNullDesC)!= 0) |
|
1198 { |
|
1199 TTime dateTime(MPXDbCommonUtil::DesToTTimeL (dateStr)); |
|
1200 aMedia.SetTObjectValueL<TInt64> (KMPXMediaGeneralDate, |
|
1201 dateTime.Int64 ()); |
|
1202 } |
|
1203 MPX_DEBUG2(" Date[%S]", &dateStr); |
|
1204 } |
|
1205 if (aAttrId & EMPXMediaGeneralComment) |
|
1206 { |
|
1207 MPX_DEBUG1(" EMPXMediaGeneralComment"); |
|
1208 TPtrC comment(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicComment)); |
|
1209 aMedia.SetTextValueL(KMPXMediaGeneralComment, comment); |
|
1210 MPX_DEBUG2(" Comment[%S]", &comment); |
|
1211 } |
|
1212 if (aAttrId & EMPXMediaGeneralMimeType) |
|
1213 { |
|
1214 MPX_DEBUG1(" EMPXMediaGeneralMimeType"); |
|
1215 TPtrC mimeType(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicMimeType)); |
|
1216 aMedia.SetTextValueL(KMPXMediaGeneralMimeType, mimeType); |
|
1217 MPX_DEBUG2(" MimeType[%S]", &mimeType); |
|
1218 } |
|
1219 if (aAttrId & EMPXMediaGeneralSynchronized) |
|
1220 { |
|
1221 MPX_DEBUG1(" EMPXMediaGeneralSynchronized"); |
|
1222 TInt sync(aMusicTable.ColumnInt(EMusicSync)); |
|
1223 aMedia.SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized, sync); |
|
1224 MPX_DEBUG2(" Synchronized[%d]", sync); |
|
1225 } |
|
1226 if (aAttrId & EMPXMediaGeneralDeleted) |
|
1227 { |
|
1228 MPX_DEBUG1(" EMPXMediaGeneralDeleted"); |
|
1229 TInt del(aMusicTable.ColumnInt(EMusicDeleted)); |
|
1230 aMedia.SetTObjectValueL<TBool>(KMPXMediaGeneralDeleted, del); |
|
1231 MPX_DEBUG2(" Deleted[%d]", del); |
|
1232 } |
|
1233 if (aAttrId & EMPXMediaGeneralModified) |
|
1234 { |
|
1235 MPX_DEBUG1(" EMPXMediaGeneralModified"); |
|
1236 TInt mod(aMusicTable.ColumnInt(EMusicModified)); |
|
1237 aMedia.SetTObjectValueL<TBool>(KMPXMediaGeneralModified, mod); |
|
1238 MPX_DEBUG2(" Modified[%d]", mod); |
|
1239 } |
|
1240 if (aAttrId & EMPXMediaGeneralCount) |
|
1241 { |
|
1242 MPX_DEBUG1(" EMPXMediaGeneralCount"); |
|
1243 aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, 1); |
|
1244 } |
|
1245 if (aAttrId & EMPXMediaGeneralCollectionId) |
|
1246 { |
|
1247 MPX_DEBUG1(" EMPXMediaGeneralCollectionId"); |
|
1248 aMedia.SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId, |
|
1249 TUid::Uid(KDBPluginUid)); |
|
1250 } |
|
1251 if(aAttrId & EMPXMediaGeneralCopyright) |
|
1252 { |
|
1253 MPX_DEBUG1(" EMPXMediaGeneralCopyright"); |
|
1254 TPtrC copyright(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicCopyright)); |
|
1255 aMedia.SetTextValueL(KMPXMediaGeneralCopyright, copyright); |
|
1256 MPX_DEBUG2(" Copyright[%S]", ©right); |
|
1257 } |
|
1258 if (aAttrId & EMPXMediaGeneralFlags) |
|
1259 { |
|
1260 MPX_DEBUG1(" EMPXMediaGeneralFlags"); |
|
1261 TUint32 dbFlags(aMusicTable.ColumnInt64(EMusicDbFlag)); |
|
1262 MPX_DEBUG2(" dbFlags=%b", dbFlags); |
|
1263 TDriveUnit driveUnit; |
|
1264 if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
1265 { |
|
1266 MPX_DEBUG1(" aMedia.IsSupported(KMPXMediaGeneralUri)"); |
|
1267 TParsePtrC parse( aMedia.ValueText(KMPXMediaGeneralUri) ); |
|
1268 if( parse.DrivePresent() ) |
|
1269 { |
|
1270 driveUnit = parse.Drive(); |
|
1271 } |
|
1272 else |
|
1273 { |
|
1274 driveUnit = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
|
1275 aMusicTable.ColumnInt64(EMusicVolumeId)); |
|
1276 } |
|
1277 MPX_DEBUG2(" driveUnit=%d", (TInt)driveUnit); |
|
1278 } |
|
1279 else |
|
1280 { |
|
1281 MPX_DEBUG1(" !aMedia.IsSupported(KMPXMediaGeneralUri)"); |
|
1282 driveUnit = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
|
1283 aMusicTable.ColumnInt64(EMusicVolumeId)); |
|
1284 MPX_DEBUG2(" driveUnit=%d", (TInt)driveUnit); |
|
1285 } |
|
1286 |
|
1287 TInt driveId = driveUnit & KMPXMediaGeneralFlagsDriveInfo; // 5 bits |
|
1288 aMedia.SetTObjectValueL<TUint>(KMPXMediaGeneralFlags, dbFlags | driveId); |
|
1289 |
|
1290 MPX_DEBUG2(" GeneralFlags[%b]", dbFlags | driveId); |
|
1291 MPX_DEBUG2(" DriveId[%u]", driveId); |
|
1292 } |
|
1293 if (aAttrId & EMPXMediaGeneralPlayCount) |
|
1294 { |
|
1295 MPX_DEBUG1(" EMPXMediaGeneralPlayCount"); |
|
1296 TUint32 playcount(aMusicTable.ColumnInt(EMusicPlayCount)); |
|
1297 aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralPlayCount, playcount); |
|
1298 MPX_DEBUG2(" PlayCount[%d]", playcount); |
|
1299 } |
|
1300 |
|
1301 MPX_DEBUG1("<--CMPXDbMusic::UpdateMediaGeneralL"); |
|
1302 } |
|
1303 |
|
1304 // ---------------------------------------------------------------------------- |
|
1305 // CMPXDbMusic::UpdateMediaMusicL |
|
1306 // ---------------------------------------------------------------------------- |
|
1307 // |
|
1308 void CMPXDbMusic::UpdateMediaMusicL( |
|
1309 RSqlStatement& aMusicTable, |
|
1310 const TUint aAttrId, |
|
1311 CMPXMedia& aMedia) |
|
1312 { |
|
1313 MPX_FUNC("CMPXDbMusic::UpdateMediaMusicL"); |
|
1314 |
|
1315 if (aAttrId & EMPXMediaMusicAlbumArtFileName) |
|
1316 { |
|
1317 TPtrC art(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicArt)); |
|
1318 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art); |
|
1319 MPX_DEBUG2(" Album Art File Name[%S]", &art); |
|
1320 } |
|
1321 if (aAttrId & EMPXMediaMusicArtist) |
|
1322 { |
|
1323 TPtrC artist(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicArtistName)); |
|
1324 aMedia.SetTextValueL(KMPXMediaMusicArtist, artist); |
|
1325 MPX_DEBUG2(" Artist[%S]", &artist); |
|
1326 } |
|
1327 if (aAttrId & EMPXMediaMusicAlbum) |
|
1328 { |
|
1329 TPtrC album(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicAlbumName)); |
|
1330 aMedia.SetTextValueL(KMPXMediaMusicAlbum, album); |
|
1331 MPX_DEBUG2(" Album[%S]", &album); |
|
1332 } |
|
1333 if ( aAttrId & EMPXMediaMusicYear) |
|
1334 { |
|
1335 const TDesC& dateStr(MPXDbCommonUtil::GetColumnTextL (aMusicTable, |
|
1336 EMusicReleaseDate)); |
|
1337 if ( dateStr.Compare (KNullDesC)!= 0) |
|
1338 { |
|
1339 TTime dateTime(MPXDbCommonUtil::DesToTTimeL (dateStr)); |
|
1340 aMedia.SetTObjectValueL<TInt64> (KMPXMediaMusicYear, |
|
1341 dateTime.Int64 ()); |
|
1342 MPX_DEBUG2(" Year[%d]", dateTime.Int64()); |
|
1343 } |
|
1344 MPX_DEBUG2(" ReleaseDate[%S]", &dateStr); |
|
1345 } |
|
1346 if (aAttrId & EMPXMediaMusicAlbumTrack) |
|
1347 { |
|
1348 TInt32 track(aMusicTable.ColumnInt(EMusicAlbumTrack)); |
|
1349 HBufC* hbuf = HBufC::NewLC(KMCIntegerLen); |
|
1350 if (track != KMaxTInt) |
|
1351 { |
|
1352 hbuf->Des().AppendFormat(_L("%d"), track); |
|
1353 } |
|
1354 aMedia.SetTextValueL(KMPXMediaMusicAlbumTrack, *hbuf); |
|
1355 MPX_DEBUG3(" Album Track[%S][%d]", hbuf, track); |
|
1356 CleanupStack::PopAndDestroy(hbuf); |
|
1357 } |
|
1358 if (aAttrId & EMPXMediaMusicGenre) |
|
1359 { |
|
1360 TPtrC genre(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicGenreName)); |
|
1361 aMedia.SetTextValueL(KMPXMediaMusicGenre, genre); |
|
1362 MPX_DEBUG2(" Music Genre[%S]", &genre); |
|
1363 } |
|
1364 if (aAttrId & EMPXMediaMusicComposer) |
|
1365 { |
|
1366 TPtrC composer(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicComposerName)); |
|
1367 aMedia.SetTextValueL(KMPXMediaMusicComposer, composer); |
|
1368 MPX_DEBUG2(" Music Composer[%S]", &composer); |
|
1369 } |
|
1370 if (aAttrId & EMPXMediaMusicRating) |
|
1371 { |
|
1372 TUint32 rating(aMusicTable.ColumnInt(EMusicRating)); |
|
1373 aMedia.SetTObjectValueL<TUint32>(KMPXMediaMusicRating, rating); |
|
1374 MPX_DEBUG2(" Music Rating[%d]", rating); |
|
1375 } |
|
1376 if (aAttrId & EMPXMediaMusicURL) |
|
1377 { |
|
1378 TPtrC url(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicUrl)); |
|
1379 aMedia.SetTextValueL(KMPXMediaMusicURL, url); |
|
1380 MPX_DEBUG2(" Music URL[%S]", &url); |
|
1381 } |
|
1382 if (aAttrId & EMPXMediaMusicOriginalAlbumArtFileName) |
|
1383 { |
|
1384 // Always set original album art to be file path |
|
1385 // Maybe add a new column to db for future if services like rhapsody pushes jpgs to us |
|
1386 if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
1387 { |
|
1388 const TDesC& uri(aMedia.ValueText(KMPXMediaGeneralUri)); |
|
1389 aMedia.SetTextValueL(KMPXMediaMusicOriginalAlbumArtFileName, uri); |
|
1390 MPX_DEBUG2(" Music Original Album Art FullPath[%S]", &uri); |
|
1391 } |
|
1392 else |
|
1393 { |
|
1394 HBufC* fullPath = ConstructUriL(aMusicTable); |
|
1395 CleanupStack::PushL(fullPath); |
|
1396 aMedia.SetTextValueL(KMPXMediaMusicOriginalAlbumArtFileName, *fullPath); |
|
1397 MPX_DEBUG2(" Music Original Album Art FullPath[%S]", fullPath); |
|
1398 CleanupStack::PopAndDestroy(fullPath); |
|
1399 } |
|
1400 } |
|
1401 } |
|
1402 |
|
1403 // ---------------------------------------------------------------------------- |
|
1404 // CMPXDbMusic::UpdateMediaAudioL |
|
1405 // ---------------------------------------------------------------------------- |
|
1406 // |
|
1407 void CMPXDbMusic::UpdateMediaAudioL( |
|
1408 RSqlStatement& aMusicTable, |
|
1409 const TUint aAttrId, |
|
1410 CMPXMedia& aMedia) |
|
1411 { |
|
1412 MPX_FUNC("CMPXDbMusic::UpdateMediaAudioL"); |
|
1413 |
|
1414 if (aAttrId & EMPXMediaAudioBitrate) |
|
1415 { |
|
1416 TUint32 bitrate(aMusicTable.ColumnInt(EMusicBitRate)); |
|
1417 aMedia.SetTObjectValueL<TUint32>(KMPXMediaAudioBitrate, bitrate); |
|
1418 MPX_DEBUG2(" Bitrate[%d]", bitrate); |
|
1419 } |
|
1420 if (aAttrId & EMPXMediaAudioSamplerate) |
|
1421 { |
|
1422 TUint32 samplerate(aMusicTable.ColumnInt(EMusicSampleRate)); |
|
1423 aMedia.SetTObjectValueL<TUint32>(KMPXMediaAudioSamplerate, samplerate); |
|
1424 MPX_DEBUG2(" SampleRate[%d]", samplerate); |
|
1425 } |
|
1426 if (aAttrId & EMPXMediaAudioNumberOfChannels) |
|
1427 { |
|
1428 TUint32 numchannels(aMusicTable.ColumnInt(EMusicNumChannels)); |
|
1429 aMedia.SetTObjectValueL<TUint32>(KMPXMediaAudioNumberOfChannels, numchannels); |
|
1430 MPX_DEBUG2(" Num of Channels[%d]", numchannels); |
|
1431 } |
|
1432 if (aAttrId & EMPXMediaAudioCodec) |
|
1433 { |
|
1434 TUint32 codec(aMusicTable.ColumnInt(EMusicCodec)); |
|
1435 aMedia.SetTObjectValueL<TUint32>(KMPXMediaAudioAudioCodec, codec); |
|
1436 MPX_DEBUG2(" Audio Codec[%d]", codec); |
|
1437 } |
|
1438 } |
|
1439 |
|
1440 // ---------------------------------------------------------------------------- |
|
1441 // CMPXDbMusic::UpdateMediaMTPL |
|
1442 // ---------------------------------------------------------------------------- |
|
1443 // |
|
1444 void CMPXDbMusic::UpdateMediaMTPL( |
|
1445 RSqlStatement& aMusicTable, |
|
1446 const TUint aAttrId, |
|
1447 CMPXMedia& aMedia) |
|
1448 { |
|
1449 MPX_FUNC("CMPXDbMusic::UpdateMediaMTPL"); |
|
1450 |
|
1451 if (aAttrId & KMPXMediaMTPDrmStatus.iAttributeId) |
|
1452 { |
|
1453 TUint32 val(aMusicTable.ColumnInt(EMusicMTPDrmStatus)); |
|
1454 aMedia.SetTObjectValueL<TUint16>(KMPXMediaMTPDrmStatus, val); |
|
1455 } |
|
1456 } |
|
1457 |
|
1458 // ---------------------------------------------------------------------------- |
|
1459 // CMPXDbMusic::GenerateMusicFieldsValuesL |
|
1460 // ---------------------------------------------------------------------------- |
|
1461 // |
|
1462 CMPXDbActiveTask::TChangeVisibility CMPXDbMusic::GenerateMusicFieldsValuesL( |
|
1463 TUint32 aSongId, |
|
1464 const CMPXMedia& aMedia, |
|
1465 CMPXMessageArray* aItemChangedMessages, |
|
1466 RSqlStatement* aMusicTable, |
|
1467 CDesCArray& aFields, |
|
1468 CDesCArray& aValues, |
|
1469 TInt aDrive) |
|
1470 { |
|
1471 MPX_FUNC("CMPXDbMusic::GenerateMusicFieldsValuesL"); |
|
1472 |
|
1473 CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile); |
|
1474 TBool metaDataModified(EFalse); |
|
1475 const TArray<TMPXAttribute> attributes = aMedia.Attributes(); |
|
1476 |
|
1477 TBool addSongChangedMessage(ETrue); |
|
1478 CMPXMessage* songChangedMessage(NULL); |
|
1479 if (aItemChangedMessages) |
|
1480 { |
|
1481 songChangedMessage = CMPXMedia::NewL(); |
|
1482 CleanupStack::PushL(songChangedMessage); |
|
1483 MPXDbCommonUtil::FillItemChangedMessageL(*songChangedMessage, aSongId, |
|
1484 aMusicTable ? EMPXItemModified : EMPXItemInserted, EMPXSong, KDBPluginUid); |
|
1485 } |
|
1486 |
|
1487 // NOTE: Attributes being processed here should be listed in IsSupported() |
|
1488 TInt attrCount(attributes.Count()); |
|
1489 for (TInt i = 0; i < attrCount; ++i) |
|
1490 { |
|
1491 TUint attributeId(attributes[i].AttributeId()); |
|
1492 |
|
1493 switch (attributes[i].ContentId()) |
|
1494 { |
|
1495 case KMPXMediaIdGeneral: |
|
1496 { |
|
1497 if (attributeId & EMPXMediaGeneralDeleted) |
|
1498 { |
|
1499 TBool deleted(aMedia.ValueTObjectL<TBool>(KMPXMediaGeneralDeleted)); |
|
1500 if (!aMusicTable || (deleted != aMusicTable->ColumnInt(EMusicDeleted))) |
|
1501 { |
|
1502 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicDel, deleted); |
|
1503 } |
|
1504 MPX_DEBUG2(" Deleted[%d]", deleted); |
|
1505 } |
|
1506 |
|
1507 if (attributeId & EMPXMediaGeneralFlags) |
|
1508 { |
|
1509 TUint flag(aMedia.ValueTObjectL<TUint>(KMPXMediaGeneralFlags)); |
|
1510 TUint32 curFlag(0); |
|
1511 if (aMusicTable) |
|
1512 { |
|
1513 curFlag = aMusicTable->ColumnInt64(EMusicDbFlag); |
|
1514 } |
|
1515 TUint32 oldFlag(curFlag); |
|
1516 |
|
1517 if (flag & KMPXMediaGeneralFlagsSetOrUnsetBit) |
|
1518 { |
|
1519 // Set bits |
|
1520 curFlag |= flag; |
|
1521 } |
|
1522 else |
|
1523 { |
|
1524 // Clear bits |
|
1525 curFlag &= (~flag); |
|
1526 } |
|
1527 |
|
1528 // The field is written ONLY if the flag value is changing |
|
1529 if (((curFlag ^ oldFlag) & 0x7FFFFFFF) != 0) |
|
1530 { |
|
1531 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicDbFlag, curFlag); |
|
1532 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1533 } |
|
1534 MPX_DEBUG2(" GeneralFlags[%b]", curFlag); |
|
1535 } |
|
1536 |
|
1537 if (attributeId & EMPXMediaGeneralTitle) |
|
1538 { |
|
1539 TBool titleChanged(NULL == aMusicTable); |
|
1540 |
|
1541 const TDesC& title = aMedia.ValueText(KMPXMediaGeneralTitle); |
|
1542 TPtrC truncatedTitle(title.Left(KMCMaxTextLen)); |
|
1543 if (aMusicTable) |
|
1544 { |
|
1545 // Title of the song has been changed |
|
1546 if (truncatedTitle.Compare(MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicTitle)) != 0) |
|
1547 { |
|
1548 titleChanged = ETrue; |
|
1549 } |
|
1550 } |
|
1551 |
|
1552 if (titleChanged) |
|
1553 { |
|
1554 if ( title.Length() == 0 ) |
|
1555 { |
|
1556 const TDesC& path = aMedia.ValueText( KMPXMediaGeneralUri ); |
|
1557 TParsePtrC parse( path ); |
|
1558 TPtrC truncatedParse( parse.Name().Left( KMCMaxTextLen ) ); |
|
1559 |
|
1560 MPXDbCommonUtil::AppendValueL( aFields, aValues, KMCMusicName, truncatedParse ); |
|
1561 } |
|
1562 else |
|
1563 { |
|
1564 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicName, truncatedTitle); |
|
1565 } |
|
1566 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1567 metaDataModified = ETrue; |
|
1568 |
|
1569 MPX_DEBUG2(" Title[%S]", &truncatedTitle); |
|
1570 } |
|
1571 } |
|
1572 |
|
1573 if (attributeId & EMPXMediaGeneralUri) |
|
1574 { |
|
1575 const TDesC& uri = aMedia.ValueText(KMPXMediaGeneralUri); |
|
1576 const TDesC& uriTrunc(uri.Mid(KMCPathStartPos)); |
|
1577 |
|
1578 TDriveUnit driveUnit(uri); |
|
1579 TUint volId(MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), driveUnit)); |
|
1580 |
|
1581 if (!aMusicTable || ((uriTrunc != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicLocation)) || |
|
1582 (volId != aMusicTable->ColumnInt64(EMusicVolumeId)))) |
|
1583 { |
|
1584 // only do the update something changed |
|
1585 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicVolumeId, volId); |
|
1586 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicLocation, |
|
1587 uri.Mid(KMCPathStartPos)); |
|
1588 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicDRM, DRMTypeL(uri)); |
|
1589 |
|
1590 const TDesC& mimeTypeText(MPXDbCommonUtil::GetMimeTypeForUriL(uri).Des()); |
|
1591 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicMimeType, mimeTypeText); |
|
1592 |
|
1593 MPX_DEBUG3(" VolumeId[%u] Location[%S]", volId, &uri); |
|
1594 MPX_DEBUG2(" MimeType[%S]", &mimeTypeText); |
|
1595 |
|
1596 if (!aMusicTable && !aMedia.IsSupported(KMPXMediaGeneralTitle)) |
|
1597 { |
|
1598 TParsePtrC parser(uri); |
|
1599 TPtrC title = parser.Name(); |
|
1600 // use file name as song name |
|
1601 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicName, title); |
|
1602 |
|
1603 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1604 MPX_DEBUG2(" Title[%S]", &title); |
|
1605 } |
|
1606 |
|
1607 // URI of the song has been changed. This changes the Id of the song |
|
1608 if (aMusicTable) |
|
1609 { |
|
1610 TUint32 newSongId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXCollection, uri, EFalse); |
|
1611 if (aSongId != newSongId) |
|
1612 { |
|
1613 MPX_DEBUG3(" CurrentSongId[0x%x] changed to [0x%x]", aSongId, newSongId); |
|
1614 if (songChangedMessage) |
|
1615 { |
|
1616 songChangedMessage->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, newSongId); |
|
1617 songChangedMessage->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aSongId); |
|
1618 } |
|
1619 |
|
1620 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicUniqueId, newSongId); |
|
1621 } |
|
1622 } |
|
1623 } |
|
1624 } |
|
1625 |
|
1626 if (attributeId & EMPXMediaGeneralPlayCount) |
|
1627 { |
|
1628 TInt increment(aMedia.ValueTObjectL<TInt>(KMPXMediaGeneralPlayCount)); |
|
1629 TUint32 curCount(increment); |
|
1630 if (aMusicTable) |
|
1631 { |
|
1632 curCount += aMusicTable->ColumnInt(EMusicPlayCount); |
|
1633 } |
|
1634 |
|
1635 if (!aMusicTable || (curCount != aMusicTable->ColumnInt(EMusicPlayCount))) |
|
1636 { |
|
1637 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicPlayCount, curCount); |
|
1638 |
|
1639 // this needs to be visible in order for Recently Played and Most Played |
|
1640 // playlists will be updated |
|
1641 visibleChange = CMPXDbActiveTask::ESingleVisible; |
|
1642 |
|
1643 if (aItemChangedMessages) |
|
1644 { |
|
1645 iObserver.HandlePlayCountModifiedL(*aItemChangedMessages); |
|
1646 } |
|
1647 addSongChangedMessage = EFalse; |
|
1648 } |
|
1649 |
|
1650 MPX_DEBUG2(" PlayCount[%d]", curCount); |
|
1651 } |
|
1652 |
|
1653 if (attributeId & EMPXMediaGeneralLastPlaybackTime) |
|
1654 { |
|
1655 HBufC* time = MPXDbCommonUtil::TTimeToDesLC( |
|
1656 TTime(aMedia.ValueTObjectL<TInt64>(KMPXMediaGeneralLastPlaybackTime))); |
|
1657 if (!aMusicTable || (*time != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicTimePlayed))) |
|
1658 { |
|
1659 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicTimePlayed, *time); |
|
1660 // this needs to be visible in order for Recently Played playlist to be updated |
|
1661 visibleChange = CMPXDbActiveTask::ESingleVisible; |
|
1662 |
|
1663 if (aItemChangedMessages) |
|
1664 { |
|
1665 iObserver.HandlePlaybackTimeModifiedL(*aItemChangedMessages); |
|
1666 } |
|
1667 addSongChangedMessage = EFalse; |
|
1668 } |
|
1669 MPX_DEBUG2(" PlaybackTime[%S]", time); |
|
1670 CleanupStack::PopAndDestroy(time); |
|
1671 } |
|
1672 |
|
1673 if (attributeId & EMPXMediaGeneralDuration) |
|
1674 { |
|
1675 TInt duration(aMedia.ValueTObjectL<TInt>(KMPXMediaGeneralDuration)); |
|
1676 if (!aMusicTable || (duration != aMusicTable->ColumnInt(EMusicDuration))) |
|
1677 { |
|
1678 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicDuration, duration); |
|
1679 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1680 metaDataModified = ETrue; |
|
1681 } |
|
1682 MPX_DEBUG2(" Duration[%d]", duration); |
|
1683 } |
|
1684 |
|
1685 if (attributeId & EMPXMediaGeneralSynchronized) |
|
1686 { |
|
1687 TBool synced(aMedia.ValueTObjectL<TBool>(KMPXMediaGeneralSynchronized)); |
|
1688 if (!aMusicTable || (synced != aMusicTable->ColumnInt(EMusicSync))) |
|
1689 { |
|
1690 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicSync, synced); |
|
1691 } |
|
1692 MPX_DEBUG2(" Synchronized[%d]", synced); |
|
1693 } |
|
1694 |
|
1695 if (attributeId & EMPXMediaGeneralModified) |
|
1696 { |
|
1697 TBool modified(aMedia.ValueTObjectL<TBool>(KMPXMediaGeneralModified)); |
|
1698 if (!aMusicTable || (modified != aMusicTable->ColumnInt(EMusicModified))) |
|
1699 { |
|
1700 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicMod, modified); |
|
1701 } |
|
1702 MPX_DEBUG2(" Modified[%d]", modified); |
|
1703 } |
|
1704 |
|
1705 if (attributeId & EMPXMediaGeneralComment) |
|
1706 { |
|
1707 TPtrC comment = aMedia.ValueText(KMPXMediaGeneralComment).Left(KMCMaxTextLen); |
|
1708 if (!aMusicTable || (comment != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicComment))) |
|
1709 { |
|
1710 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicComment, comment); |
|
1711 metaDataModified = ETrue; |
|
1712 } |
|
1713 MPX_DEBUG2(" Comment[%S]", &comment); |
|
1714 } |
|
1715 |
|
1716 if (attributeId & EMPXMediaGeneralCopyright) |
|
1717 { |
|
1718 const TDesC& copyright = aMedia.ValueText(KMPXMediaGeneralCopyright). |
|
1719 Left(KMCMaxTextLen); |
|
1720 if (!aMusicTable || (copyright != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicCopyright))) |
|
1721 { |
|
1722 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicCopyright, copyright); |
|
1723 metaDataModified = ETrue; |
|
1724 } |
|
1725 MPX_DEBUG2(" Copyright[%S]", ©right); |
|
1726 } |
|
1727 } |
|
1728 break; |
|
1729 |
|
1730 case KMPXMediaIdMusic: |
|
1731 { |
|
1732 if (attributeId & EMPXMediaMusicAlbumTrack) |
|
1733 { |
|
1734 const TDesC& trackNumber = aMedia.ValueText(KMPXMediaMusicAlbumTrack); |
|
1735 |
|
1736 // KMaxTInt is used to represent null album track |
|
1737 TInt track(KMaxTInt); |
|
1738 if (trackNumber.Length()) |
|
1739 { |
|
1740 TLex stringParser(trackNumber); |
|
1741 |
|
1742 if ((stringParser.Val(track) != KErrNone) || |
|
1743 (track == 0) || (track > 999)) // Limit track number to 3 characters |
|
1744 { |
|
1745 track = KMaxTInt; |
|
1746 } |
|
1747 } |
|
1748 |
|
1749 if (!aMusicTable || (track != aMusicTable->ColumnInt(EMusicAlbumTrack))) |
|
1750 { |
|
1751 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicTrackNumber, track); |
|
1752 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1753 metaDataModified = ETrue; |
|
1754 } |
|
1755 MPX_DEBUG3(" Album Track[%S][%d]", &trackNumber, track); |
|
1756 } |
|
1757 |
|
1758 if (attributeId & EMPXMediaMusicYear) |
|
1759 { |
|
1760 TInt64 int64(aMedia.ValueTObjectL<TInt64>(KMPXMediaMusicYear)); |
|
1761 |
|
1762 TTime maxTime(0); |
|
1763 maxTime += TTimeIntervalYears(9999); // Limit years to 4 characters |
|
1764 TTime time(int64); |
|
1765 |
|
1766 if (time > maxTime) |
|
1767 { |
|
1768 time = Time::NullTTime(); |
|
1769 } |
|
1770 |
|
1771 HBufC* timeStr = MPXDbCommonUtil::TTimeToDesLC(time); |
|
1772 if (!aMusicTable || (*timeStr != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicReleaseDate))) |
|
1773 { |
|
1774 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicReleaseDate, *timeStr); |
|
1775 metaDataModified = ETrue; |
|
1776 } |
|
1777 MPX_DEBUG2(" Music Year[%S]", timeStr); |
|
1778 CleanupStack::PopAndDestroy(timeStr); |
|
1779 } |
|
1780 |
|
1781 if (attributeId & EMPXMediaMusicRating) |
|
1782 { |
|
1783 TInt rating(aMedia.ValueTObjectL<TInt>(KMPXMediaMusicRating)); |
|
1784 if (!aMusicTable || (rating != aMusicTable->ColumnInt(EMusicRating))) |
|
1785 { |
|
1786 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicRating, rating); |
|
1787 metaDataModified = ETrue; |
|
1788 } |
|
1789 MPX_DEBUG2(" Rating[%d]", rating); |
|
1790 } |
|
1791 |
|
1792 if (attributeId & EMPXMediaMusicAlbumArtFileName) |
|
1793 { |
|
1794 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
|
1795 if (!aMusicTable || (albumArtFilename != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicArt))) |
|
1796 { |
|
1797 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
|
1798 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1799 metaDataModified = ETrue; |
|
1800 } |
|
1801 |
|
1802 MPX_DEBUG2(" Album Art Filename[%S]", &albumArtFilename); |
|
1803 } |
|
1804 |
|
1805 if (attributeId & EMPXMediaMusicURL) |
|
1806 { |
|
1807 const TDesC& url = aMedia.ValueText(KMPXMediaMusicURL).Left(KMCMaxTextLen); |
|
1808 if (!aMusicTable || (url != MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicUrl))) |
|
1809 { |
|
1810 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicUrl, url); |
|
1811 metaDataModified = ETrue; |
|
1812 } |
|
1813 |
|
1814 MPX_DEBUG2(" Music URL[%S]", &url); |
|
1815 } |
|
1816 } |
|
1817 break; |
|
1818 |
|
1819 case KMPXMediaIdAudio: |
|
1820 { |
|
1821 if (attributeId & EMPXMediaAudioSamplerate) |
|
1822 { |
|
1823 TInt samplerate(aMedia.ValueTObjectL<TInt>(KMPXMediaAudioSamplerate)); |
|
1824 if (!aMusicTable || (samplerate != aMusicTable->ColumnInt(EMusicSampleRate))) |
|
1825 { |
|
1826 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicSampleRate, samplerate); |
|
1827 metaDataModified = ETrue; |
|
1828 } |
|
1829 |
|
1830 MPX_DEBUG2(" Sample Rate[%d]", samplerate); |
|
1831 } |
|
1832 |
|
1833 if (attributeId & EMPXMediaAudioBitrate) |
|
1834 { |
|
1835 TInt bitrate(aMedia.ValueTObjectL<TInt>(KMPXMediaAudioBitrate)); |
|
1836 if (!aMusicTable || (bitrate != aMusicTable->ColumnInt(EMusicBitRate))) |
|
1837 { |
|
1838 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicBitRate, bitrate); |
|
1839 metaDataModified = ETrue; |
|
1840 } |
|
1841 MPX_DEBUG2(" Bitrate[%d]", bitrate); |
|
1842 } |
|
1843 |
|
1844 if (attributeId & EMPXMediaAudioNumberOfChannels) |
|
1845 { |
|
1846 TUint32 val = aMedia.ValueTObjectL<TUint32>(KMPXMediaAudioNumberOfChannels); |
|
1847 if (!aMusicTable || (val != aMusicTable->ColumnInt(EMusicNumChannels))) |
|
1848 { |
|
1849 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicNumChannels, val); |
|
1850 } |
|
1851 MPX_DEBUG2(" Num of Channels[%d]", val); |
|
1852 } |
|
1853 } |
|
1854 break; |
|
1855 |
|
1856 case KMPXMediaIdDrm: |
|
1857 { |
|
1858 if (attributeId & EMPXMediaDrmType) |
|
1859 { |
|
1860 TInt drmType(aMedia.ValueTObjectL<TInt>(KMPXMediaDrmType)); |
|
1861 if (!aMusicTable || (drmType != aMusicTable->ColumnInt(EMusicDRM))) |
|
1862 { |
|
1863 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicDRM, drmType); |
|
1864 } |
|
1865 MPX_DEBUG2(" DRM type[%d]", drmType); |
|
1866 } |
|
1867 |
|
1868 if (attributeId & KMPXMediaDrmRightsStatus.iAttributeId) |
|
1869 { |
|
1870 if (aMusicTable) |
|
1871 { |
|
1872 TMPXMediaDrmRightsStatus status = |
|
1873 aMedia.ValueTObjectL<TMPXMediaDrmRightsStatus>(KMPXMediaDrmRightsStatus); |
|
1874 |
|
1875 //.Set the db flag |
|
1876 TUint32 curFlag(aMusicTable->ColumnInt64(EMusicDbFlag)); |
|
1877 TUint32 oldFlag(curFlag); |
|
1878 |
|
1879 if ((status != EMPXDrmRightsFull) && (status != EMPXDrmRightsRestricted)) |
|
1880 { |
|
1881 // No rights |
|
1882 curFlag |= KMPXMediaGeneralFlagsIsDrmLicenceInvalid; |
|
1883 } |
|
1884 else |
|
1885 { |
|
1886 // Rights valid |
|
1887 curFlag &= (KMPXMediaGeneralFlagsIsDrmLicenceInvalid ^ 0xFFFFFFFF); |
|
1888 } |
|
1889 |
|
1890 // The field is written ONLY if the flag value is changing |
|
1891 if (((curFlag ^ oldFlag) & 0x7FFFFFFF) != 0) |
|
1892 { |
|
1893 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicDbFlag, curFlag); |
|
1894 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1895 } |
|
1896 |
|
1897 MPX_DEBUG2(" Rights Status[%d]", curFlag); |
|
1898 } |
|
1899 } |
|
1900 |
|
1901 break; |
|
1902 } |
|
1903 |
|
1904 case KMPXMediaIdMTP: |
|
1905 { |
|
1906 if (attributeId & KMPXMediaMTPDrmStatus.iAttributeId) |
|
1907 { |
|
1908 TUint16 drmStatus(aMedia.ValueTObjectL<TUint16>(KMPXMediaMTPDrmStatus)); |
|
1909 if (!aMusicTable || (drmStatus != aMusicTable->ColumnInt(EMusicMTPDrmStatus))) |
|
1910 { |
|
1911 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicMTPDrmStatus, drmStatus); |
|
1912 } |
|
1913 MPX_DEBUG2(" MTP Drm Status[%d]", drmStatus); |
|
1914 } |
|
1915 } |
|
1916 break; |
|
1917 |
|
1918 default: |
|
1919 break; |
|
1920 } // end switch |
|
1921 } // end for |
|
1922 |
|
1923 // get the current artist/album/genre/composer |
|
1924 // this is required because the recordset may be reused by the code below |
|
1925 TUint32 artistId(0); |
|
1926 TUint32 albumId(0); |
|
1927 TUint32 genreId(0); |
|
1928 TUint32 composerId(0); |
|
1929 if (aMusicTable) |
|
1930 { |
|
1931 artistId = aMusicTable->ColumnInt64(EMusicArtist); |
|
1932 albumId = aMusicTable->ColumnInt64(EMusicAlbum); |
|
1933 genreId = aMusicTable->ColumnInt64(EMusicGenre); |
|
1934 composerId = aMusicTable->ColumnInt64(EMusicComposer); |
|
1935 } |
|
1936 |
|
1937 // update the artist field |
|
1938 TUint32 id(0); |
|
1939 TUint32 artistIdForAlbum(artistId); |
|
1940 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
|
1941 aDrive, aItemChangedMessages, id, 0)) |
|
1942 { |
|
1943 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
|
1944 metaDataModified = (aMusicTable != NULL); |
|
1945 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1946 artistIdForAlbum = id; |
|
1947 } |
|
1948 |
|
1949 // update the album field |
|
1950 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
|
1951 aDrive, aItemChangedMessages, id, artistIdForAlbum)) |
|
1952 { |
|
1953 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
|
1954 metaDataModified = (aMusicTable != NULL); |
|
1955 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1956 |
|
1957 // |
|
1958 // added to handle error EALU-73WDJN. If the album name of the last song |
|
1959 // in the album for the artist is changed to an existing album name from |
|
1960 // artist view, a change message needs to be sent in order for UI to |
|
1961 // correctly refresh. |
|
1962 // |
|
1963 // Fix for EDXU-7BBALS, remove check for HasOtherSongsInArtistAlbumL |
|
1964 // Always send a Album Inserted message when Album change to get Artist updated |
|
1965 if (aItemChangedMessages) |
|
1966 { |
|
1967 // send album added m essage instead of album deleted or modified |
|
1968 // to avoid collection paths of other clients being modified |
|
1969 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
|
1970 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
|
1971 } |
|
1972 } |
|
1973 |
|
1974 // update the genre field |
|
1975 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
|
1976 aDrive, aItemChangedMessages, id)) |
|
1977 { |
|
1978 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicGenre, id); |
|
1979 metaDataModified = (aMusicTable != NULL); |
|
1980 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1981 } |
|
1982 |
|
1983 // update the composer field |
|
1984 if (UpdateCategoryFieldL(EMPXComposer, aMedia, KMPXMediaMusicComposer, composerId, |
|
1985 aDrive, aItemChangedMessages, id)) |
|
1986 { |
|
1987 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicComposer, id); |
|
1988 metaDataModified = (aMusicTable != NULL); |
|
1989 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
1990 } |
|
1991 |
|
1992 #if defined (__MTP_PROTOCOL_SUPPORT) |
|
1993 // Set Mod bit to ETrue if metadata has been updated and caller hasn't explicitly |
|
1994 // set/reset it |
|
1995 if (aMusicTable && |
|
1996 !aMedia.IsSupported(KMPXMediaGeneralModified) && |
|
1997 metaDataModified) |
|
1998 { |
|
1999 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicMod, 1); |
|
2000 MPX_DEBUG1(" Modified[1]"); |
|
2001 } |
|
2002 #endif |
|
2003 |
|
2004 if (aItemChangedMessages) |
|
2005 { |
|
2006 if (aFields.Count() && addSongChangedMessage) |
|
2007 { |
|
2008 aItemChangedMessages->AppendL(*songChangedMessage); |
|
2009 } |
|
2010 CleanupStack::PopAndDestroy(songChangedMessage); |
|
2011 } |
|
2012 |
|
2013 return visibleChange; |
|
2014 } |
|
2015 |
|
2016 // ---------------------------------------------------------------------------- |
|
2017 // CMPXDbMusic::DRMTypeL |
|
2018 // ---------------------------------------------------------------------------- |
|
2019 // |
|
2020 TMCDrmType CMPXDbMusic::DRMTypeL( |
|
2021 const TDesC& aFile) |
|
2022 { |
|
2023 MPX_FUNC("CMPXDbMusic::DRMTypeL"); |
|
2024 |
|
2025 TMCDrmType drm(EMCDrmNone); |
|
2026 TInt pos(0); |
|
2027 TParsePtrC fullEntry(aFile); |
|
2028 TPtrC theExt = fullEntry.Ext(); |
|
2029 |
|
2030 if (iExtensionsDrm->Find(theExt, pos) == 0) |
|
2031 { |
|
2032 drm = MPXDbCommonUtil::GetDRMTypeL(aFile); |
|
2033 } |
|
2034 |
|
2035 return drm; |
|
2036 } |
|
2037 |
|
2038 // ---------------------------------------------------------------------------- |
|
2039 // CMPXDbMusic::GenerateMusicMatchingCriteriaLC |
|
2040 // ---------------------------------------------------------------------------- |
|
2041 // |
|
2042 HBufC* CMPXDbMusic::GenerateMusicMatchingCriteriaLC( |
|
2043 TUint32 aGeneralId, |
|
2044 TUint32 aContainerId, |
|
2045 TMPXGeneralType aType, |
|
2046 const CMPXMedia& aCriteria) |
|
2047 { |
|
2048 MPX_FUNC("CMPXDbMusic::GenerateMusicMatchingCriteriaLC"); |
|
2049 |
|
2050 const TArray<TMPXAttribute> criteria = aCriteria.Attributes(); |
|
2051 TInt criteriaCount(criteria.Count()); |
|
2052 |
|
2053 // construct an array of criteria strings |
|
2054 CDesCArrayFlat* sqlCriteria = new (ELeave) CDesCArrayFlat(criteriaCount); |
|
2055 CleanupStack::PushL(sqlCriteria); |
|
2056 |
|
2057 // If EMPXMediaGeneralDeleted is not defined, always unset the deleted bit for matching |
|
2058 if (!aCriteria.IsSupported(KMPXMediaGeneralDeleted)) |
|
2059 { |
|
2060 sqlCriteria->AppendL(KCriterionMusicNotDeleted); |
|
2061 } |
|
2062 |
|
2063 TBool volumeAdded(EFalse); |
|
2064 for (TInt i = 0; i < criteriaCount; ++i) |
|
2065 { |
|
2066 const TMPXAttribute& criterion = criteria[i]; |
|
2067 |
|
2068 if (criterion == KMPXMediaGeneralId) |
|
2069 { |
|
2070 // Set the type if no type is specified |
|
2071 TInt category(MPX_ITEM_CATEGORY(aGeneralId)); |
|
2072 |
|
2073 if( aType == EMPXNoType ) |
|
2074 { |
|
2075 aType = (category == EMPXCollection) ? EMPXItem : EMPXGroup; |
|
2076 } |
|
2077 |
|
2078 TPtrC ptr; |
|
2079 if (aType == EMPXItem && (category == EMPXCollection)) |
|
2080 { |
|
2081 ptr.Set(KCriterionMusicUniqueId); |
|
2082 } |
|
2083 else if (aType == EMPXGroup && (category == EMPXArtist)) |
|
2084 { |
|
2085 ptr.Set(KCriterionMusicArtist); |
|
2086 } |
|
2087 else if (aType == EMPXGroup && (category == EMPXAlbum)) |
|
2088 { |
|
2089 ptr.Set(KCriterionMusicAlbum); |
|
2090 } |
|
2091 else if (aType == EMPXGroup && (category == EMPXGenre)) |
|
2092 { |
|
2093 ptr.Set(KCriterionMusicGenre); |
|
2094 } |
|
2095 else if (aType == EMPXGroup && (category == EMPXComposer)) |
|
2096 { |
|
2097 ptr.Set(KCriterionMusicComposer); |
|
2098 } |
|
2099 else |
|
2100 { |
|
2101 User::Leave(KErrNotSupported); |
|
2102 } |
|
2103 |
|
2104 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, ptr, aGeneralId); |
|
2105 } |
|
2106 else if (criterion == KMPXMediaGeneralContainerId) |
|
2107 { |
|
2108 TInt containerCategory(MPX_ITEM_CATEGORY(aContainerId)); |
|
2109 |
|
2110 if (aType == EMPXGroup && (containerCategory == EMPXArtist)) |
|
2111 { |
|
2112 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, |
|
2113 KCriterionMusicArtist, aContainerId); |
|
2114 } |
|
2115 else if (aType == EMPXGroup && (containerCategory == EMPXAlbum)) |
|
2116 { |
|
2117 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, |
|
2118 KCriterionMusicAlbum, aContainerId); |
|
2119 } |
|
2120 else |
|
2121 { |
|
2122 //User::Leave(KErrNotSupported); |
|
2123 } |
|
2124 } |
|
2125 else if (criterion == KMPXMediaGeneralTitle) |
|
2126 { |
|
2127 HBufC* title = MPXDbCommonUtil::ProcessPatternCharsLC( |
|
2128 aCriteria.ValueText(KMPXMediaGeneralTitle)); |
|
2129 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, KCriterionMusicTitle, *title); |
|
2130 CleanupStack::PopAndDestroy(title); |
|
2131 } |
|
2132 else if (criterion == KMPXMediaGeneralUri) |
|
2133 { |
|
2134 // full URI from criteria |
|
2135 const TDesC& uri = aCriteria.ValueText(KMPXMediaGeneralUri); |
|
2136 TUint32 itemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXCollection, |
|
2137 uri, EFalse); |
|
2138 |
|
2139 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, KCriterionMusicUniqueId, itemId); |
|
2140 } |
|
2141 else if (criterion == KMPXMediaGeneralDrive) |
|
2142 { |
|
2143 if (!volumeAdded) |
|
2144 { |
|
2145 // validate the drive letter, TDriveUnit panics if given drive isn't between |
|
2146 // 'A' to 'Z' |
|
2147 TDriveUnit driveUnit(aCriteria.ValueText(KMPXMediaGeneralDrive)); |
|
2148 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, KCriterionMusicVolume, |
|
2149 MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), driveUnit)); |
|
2150 volumeAdded = ETrue; |
|
2151 } |
|
2152 } |
|
2153 else if (criterion == KMPXMediaGeneralSynchronized) |
|
2154 { |
|
2155 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, KCriterionMusicSync, |
|
2156 aCriteria.ValueTObjectL<TBool>(KMPXMediaGeneralSynchronized)); |
|
2157 } |
|
2158 else if (criterion == KMPXMediaGeneralDeleted) |
|
2159 { |
|
2160 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, KCriterionMusicDeleted, |
|
2161 aCriteria.ValueTObjectL<TBool>(KMPXMediaGeneralDeleted)); |
|
2162 } |
|
2163 else if (criterion == KMPXMediaGeneralModified) |
|
2164 { |
|
2165 MPXDbCommonUtil::AddSqlCriterionL(*sqlCriteria, KCriterionMusicModified, |
|
2166 aCriteria.ValueTObjectL<TBool>(KMPXMediaGeneralModified)); |
|
2167 } |
|
2168 else |
|
2169 { |
|
2170 // to-do: provide searching ability on the rest of the fields |
|
2171 } |
|
2172 } |
|
2173 |
|
2174 // construct the final criteria string |
|
2175 HBufC* criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*sqlCriteria, KMCAndKeyword); |
|
2176 |
|
2177 CleanupStack::Pop(criteriaStr); |
|
2178 CleanupStack::PopAndDestroy(sqlCriteria); |
|
2179 CleanupStack::PushL(criteriaStr); |
|
2180 |
|
2181 return criteriaStr; |
|
2182 } |
|
2183 |
|
2184 // ---------------------------------------------------------------------------- |
|
2185 // CMPXDbMusic::ConstructUriL |
|
2186 // ---------------------------------------------------------------------------- |
|
2187 // |
|
2188 HBufC* CMPXDbMusic::ConstructUriL( |
|
2189 RSqlStatement& aMusicTable) |
|
2190 { |
|
2191 MPX_FUNC("CMPXDbMusic::ConstructUriL"); |
|
2192 |
|
2193 TUint volId(aMusicTable.ColumnInt64(EMusicVolumeId)); |
|
2194 TPtrC location(MPXDbCommonUtil::GetColumnTextL(aMusicTable, EMusicLocation)); |
|
2195 return MPXDbCommonUtil::CreateFullPathL( |
|
2196 MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId), location); |
|
2197 } |
|
2198 |
|
2199 // ---------------------------------------------------------------------------- |
|
2200 // CMPXDbMusic::CreateTableL |
|
2201 // ---------------------------------------------------------------------------- |
|
2202 // |
|
2203 void CMPXDbMusic::CreateTableL( |
|
2204 RSqlDatabase& aDatabase, |
|
2205 TBool /* aCorruptTable */) |
|
2206 { |
|
2207 MPX_FUNC("CMPXDbMusic::CreateTableL"); |
|
2208 |
|
2209 // Create the table |
|
2210 User::LeaveIfError(aDatabase.Exec(KMusicCreateTable)); |
|
2211 |
|
2212 // Do not create any other indexes than the one on UniqueId |
|
2213 // as they only slow down the database overall |
|
2214 } |
|
2215 |
|
2216 // ---------------------------------------------------------------------------- |
|
2217 // CMPXDbMusic::DropTableL |
|
2218 // ---------------------------------------------------------------------------- |
|
2219 // |
|
2220 void CMPXDbMusic::DropTableL( |
|
2221 RSqlDatabase& aDatabase) |
|
2222 { |
|
2223 MPX_FUNC("CMPXDbMusic::DropTableL"); |
|
2224 User::LeaveIfError(aDatabase.Exec(KMusicDropTable)); |
|
2225 } |
|
2226 |
|
2227 // ---------------------------------------------------------------------------- |
|
2228 // CMPXDbMusic::CheckTableL |
|
2229 // ---------------------------------------------------------------------------- |
|
2230 // |
|
2231 TBool CMPXDbMusic::CheckTableL( |
|
2232 RSqlDatabase& aDatabase) |
|
2233 { |
|
2234 MPX_FUNC("CMPXDbMusic::CheckTableL"); |
|
2235 return DoCheckTable(aDatabase, KMusicCheckTable); |
|
2236 } |
|
2237 |
|
2238 // ---------------------------------------------------------------------------- |
|
2239 // CMPXDbMusic::UpdateCategoryFieldL |
|
2240 // ---------------------------------------------------------------------------- |
|
2241 // |
|
2242 TBool CMPXDbMusic::UpdateCategoryFieldL( |
|
2243 TMPXGeneralCategory aCategory, |
|
2244 const CMPXMedia& aMedia, |
|
2245 const TMPXAttribute& aAttribute, |
|
2246 TUint32 aOldId, |
|
2247 TInt aDriveId, |
|
2248 CMPXMessageArray* aItemChangedMessages, |
|
2249 TUint32& aItemId) |
|
2250 { |
|
2251 TBool updated(EFalse); |
|
2252 TBool itemNotRemoved( EFalse ); |
|
2253 TBool itemAdded( EFalse ); |
|
2254 |
|
2255 // update category table and add category Id to the music table |
|
2256 if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2257 { |
|
2258 TInt changeMsgCount( 0 ); |
|
2259 if( aItemChangedMessages ) |
|
2260 { |
|
2261 changeMsgCount = aItemChangedMessages->Count(); |
|
2262 } |
|
2263 |
|
2264 if (aMedia.IsSupported(aAttribute)) |
|
2265 { |
|
2266 TPtrC name(aMedia.ValueText(aAttribute).Left(KMCMaxTextLen)); |
|
2267 |
|
2268 // construct the new ID for the category record |
|
2269 // only genre is not case sensitive |
|
2270 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
|
2271 name, (aCategory != EMPXGenre)); |
|
2272 if (!aOldId || (aOldId != aItemId)) |
|
2273 { |
|
2274 // only add if the ID changed, |
|
2275 // otherwise the song was updated but the artist name was not |
|
2276 |
|
2277 // ignore the return value |
|
2278 iObserver.AddCategoryItemL(aCategory, name, aDriveId, |
|
2279 aItemChangedMessages, itemAdded); |
|
2280 updated = ETrue; |
|
2281 } |
|
2282 } |
|
2283 else |
|
2284 { |
|
2285 // only genre is not case sensitive |
|
2286 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, KNullDesC, |
|
2287 (aCategory != EMPXGenre)); |
|
2288 if (!aOldId || (aOldId != aItemId)) |
|
2289 { |
|
2290 // ignore the return value |
|
2291 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
|
2292 aItemChangedMessages, itemAdded); |
|
2293 updated = ETrue; |
|
2294 } |
|
2295 } |
|
2296 |
|
2297 if (aOldId && (aOldId != aItemId)) |
|
2298 { |
|
2299 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
|
2300 aItemChangedMessages, itemNotRemoved); |
|
2301 updated = ETrue; |
|
2302 } |
|
2303 |
|
2304 // Special case where the item(s) has been renamed. |
|
2305 // In this case, a new category is created +1 change msg |
|
2306 // a old category is removed +1 change msg |
|
2307 // We merge these 2 change messages into one using the deprecated ID |
|
2308 // |
|
2309 if( aItemChangedMessages ) |
|
2310 { |
|
2311 TInt newChangeMsgCount( aItemChangedMessages->Count() ); |
|
2312 if( newChangeMsgCount - changeMsgCount > 0 ) |
|
2313 { |
|
2314 TInt oldId = KErrNotFound; |
|
2315 TInt newId = KErrNotFound; |
|
2316 for( TInt i=0; i<newChangeMsgCount; ++i ) |
|
2317 { |
|
2318 CMPXMessage& msg = *(*aItemChangedMessages)[i]; |
|
2319 |
|
2320 TMPXItemId id = msg.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId); |
|
2321 TMPXChangeEventType changeType = msg.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType); |
|
2322 |
|
2323 // Look for the added and deleted category IDs |
|
2324 // |
|
2325 if( id == aOldId && changeType == EMPXItemDeleted ) |
|
2326 { |
|
2327 oldId = i; |
|
2328 } |
|
2329 else if( id == aItemId && changeType == EMPXItemInserted ) |
|
2330 { |
|
2331 newId = i; |
|
2332 } |
|
2333 } |
|
2334 |
|
2335 if( oldId != KErrNotFound && |
|
2336 newId != KErrNotFound ) |
|
2337 { |
|
2338 aItemChangedMessages->Remove(oldId); // category removed |
|
2339 aItemChangedMessages->Remove(newId); // category added |
|
2340 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2341 aCategory, KDBPluginUid, aOldId ); |
|
2342 } |
|
2343 else if ( oldId !=KErrNotFound && itemAdded ) // old item removed, new item already exist |
|
2344 { |
|
2345 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2346 aCategory, KDBPluginUid, aOldId ); |
|
2347 } |
|
2348 else if ( newId !=KErrNotFound && itemNotRemoved ) // new item added, old item still exist |
|
2349 { |
|
2350 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aOldId, EMPXItemModified, |
|
2351 aCategory, KDBPluginUid, aItemId ); |
|
2352 } |
|
2353 } |
|
2354 } |
|
2355 } |
|
2356 |
|
2357 return updated; |
|
2358 } |
|
2359 |
|
2360 TBool CMPXDbMusic::UpdateCategoryFieldL( |
|
2361 TMPXGeneralCategory aCategory, |
|
2362 const CMPXMedia& aMedia, |
|
2363 const TMPXAttribute& aAttribute, |
|
2364 TUint32 aOldId, |
|
2365 TInt aDriveId, |
|
2366 CMPXMessageArray* aItemChangedMessages, |
|
2367 TUint32& aItemId, |
|
2368 TUint32 aArtistId) |
|
2369 { |
|
2370 TBool updated(EFalse); |
|
2371 TBool itemNotRemoved( EFalse ); |
|
2372 TBool itemAdded( EFalse ); |
|
2373 |
|
2374 // update category table and add category Id to the music table |
|
2375 if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2376 { |
|
2377 TInt changeMsgCount( 0 ); |
|
2378 if( aItemChangedMessages ) |
|
2379 { |
|
2380 changeMsgCount = aItemChangedMessages->Count(); |
|
2381 } |
|
2382 |
|
2383 if (aMedia.IsSupported(aAttribute)) |
|
2384 { |
|
2385 TPtrC name(aMedia.ValueText(aAttribute).Left(KMCMaxTextLen)); |
|
2386 |
|
2387 // construct the new ID for the category record |
|
2388 // only genre is not case sensitive |
|
2389 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
|
2390 name, (aCategory != EMPXGenre)); |
|
2391 if (!aOldId || (aOldId != aItemId)) |
|
2392 { |
|
2393 // only add if the ID changed, |
|
2394 // otherwise the song was updated but the artist name was not |
|
2395 TPtrC art(KNullDesC); |
|
2396 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2397 { |
|
2398 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2399 } |
|
2400 |
|
2401 iObserver.AddCategoryItemL(aCategory, name, aArtistId, art, aDriveId, aItemChangedMessages, itemAdded); |
|
2402 updated = ETrue; |
|
2403 } |
|
2404 } |
|
2405 else |
|
2406 { |
|
2407 // only genre is not case sensitive |
|
2408 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, KNullDesC, |
|
2409 (aCategory != EMPXGenre)); |
|
2410 if (!aOldId || (aOldId != aItemId)) |
|
2411 { |
|
2412 TPtrC art(KNullDesC); |
|
2413 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2414 { |
|
2415 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2416 } |
|
2417 |
|
2418 iObserver.AddCategoryItemL(aCategory, KNullDesC, aArtistId, art, aDriveId, |
|
2419 aItemChangedMessages, itemAdded); |
|
2420 updated = ETrue; |
|
2421 } |
|
2422 } |
|
2423 |
|
2424 if (aOldId && (aOldId != aItemId)) |
|
2425 { |
|
2426 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
|
2427 aItemChangedMessages, itemNotRemoved); |
|
2428 updated = ETrue; |
|
2429 } |
|
2430 |
|
2431 // Special case where the item(s) has been renamed. |
|
2432 // In this case, a new category is created +1 change msg |
|
2433 // a old category is removed +1 change msg |
|
2434 // We merge these 2 change messages into one using the deprecated ID |
|
2435 // |
|
2436 if( aItemChangedMessages ) |
|
2437 { |
|
2438 TInt newChangeMsgCount( aItemChangedMessages->Count() ); |
|
2439 if( newChangeMsgCount - changeMsgCount > 0 ) |
|
2440 { |
|
2441 TInt oldId = KErrNotFound; |
|
2442 TInt newId = KErrNotFound; |
|
2443 for( TInt i=0; i<newChangeMsgCount; ++i ) |
|
2444 { |
|
2445 CMPXMessage& msg = *(*aItemChangedMessages)[i]; |
|
2446 |
|
2447 TMPXItemId id = msg.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId); |
|
2448 TMPXChangeEventType changeType = msg.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType); |
|
2449 |
|
2450 // Look for the added and deleted category IDs |
|
2451 // |
|
2452 if( id == aOldId && changeType == EMPXItemDeleted ) |
|
2453 { |
|
2454 oldId = i; |
|
2455 } |
|
2456 else if( id == aItemId && changeType == EMPXItemInserted ) |
|
2457 { |
|
2458 newId = i; |
|
2459 } |
|
2460 } |
|
2461 |
|
2462 if( oldId != KErrNotFound && |
|
2463 newId != KErrNotFound ) |
|
2464 { |
|
2465 aItemChangedMessages->Remove(oldId); // category removed |
|
2466 aItemChangedMessages->Remove(newId); // category added |
|
2467 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2468 aCategory, KDBPluginUid, aOldId ); |
|
2469 } |
|
2470 else if ( oldId !=KErrNotFound && itemAdded ) // old item removed, new item already exist |
|
2471 { |
|
2472 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2473 aCategory, KDBPluginUid, aOldId ); |
|
2474 } |
|
2475 else if ( newId !=KErrNotFound && itemNotRemoved ) // new item added, old item still exist |
|
2476 { |
|
2477 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aOldId, EMPXItemModified, |
|
2478 aCategory, KDBPluginUid, aItemId ); |
|
2479 } |
|
2480 } |
|
2481 } |
|
2482 } |
|
2483 |
|
2484 return updated; |
|
2485 } |
|
2486 // ---------------------------------------------------------------------------- |
|
2487 // CMPXDbMusic::ExtraFieldsRequired |
|
2488 // ---------------------------------------------------------------------------- |
|
2489 // |
|
2490 TBool CMPXDbMusic::ExtraFieldsRequired( |
|
2491 const TArray<TMPXAttribute>& aAttrs) |
|
2492 { |
|
2493 MPX_DEBUG1("-->CMPXDbMusic::ExtraFieldsRequired"); |
|
2494 |
|
2495 // check if any extra fields are required |
|
2496 TUint defaultFields(EMPXMediaGeneralId | |
|
2497 EMPXMediaGeneralType | |
|
2498 EMPXMediaGeneralCategory | |
|
2499 EMPXMediaGeneralTitle | |
|
2500 EMPXMediaGeneralUri | |
|
2501 EMPXMediaGeneralFlags); |
|
2502 |
|
2503 TBool extraRequired(EFalse); |
|
2504 TInt count(aAttrs.Count()); |
|
2505 for (TInt i = 0; i < count; ++i) |
|
2506 { |
|
2507 TUint attributeId(aAttrs[i].AttributeId()|defaultFields); |
|
2508 MPX_DEBUG2(" attribute content id 0x%x", aAttrs[i].ContentId()); |
|
2509 MPX_DEBUG3(" attribute id %b, original attribute id %b", attributeId, aAttrs[i].AttributeId()); |
|
2510 |
|
2511 if (KMPXMediaIdGeneral != aAttrs[i].ContentId() || |
|
2512 attributeId != defaultFields) |
|
2513 { |
|
2514 MPX_DEBUG1(" extraRequired YES"); |
|
2515 extraRequired = ETrue; |
|
2516 break; |
|
2517 } |
|
2518 } |
|
2519 |
|
2520 MPX_DEBUG2("<--CMPXDbMusic::ExtraFieldsRequired returns %d", extraRequired); |
|
2521 return extraRequired; |
|
2522 } |
|
2523 |
|
2524 // ---------------------------------------------------------------------------------------------------------- |
|
2525 // Test if the given media contains supported attributes |
|
2526 // ---------------------------------------------------------------------------------------------------------- |
|
2527 // |
|
2528 TBool CMPXDbMusic::IsSupported( |
|
2529 const CMPXMedia& aMedia) |
|
2530 { |
|
2531 MPX_FUNC("CMPXDbMusic::IsSupported"); |
|
2532 |
|
2533 // this checklist should match the attributes processed in DoFillInDatabaseInfoL |
|
2534 return aMedia.IsSupported(KMPXMediaGeneralTitle) || |
|
2535 aMedia.IsSupported(KMPXMediaGeneralUri) || |
|
2536 aMedia.IsSupported(KMPXMediaGeneralComment) || |
|
2537 aMedia.IsSupported(KMPXMediaGeneralSynchronized) || |
|
2538 aMedia.IsSupported(KMPXMediaGeneralDeleted) || |
|
2539 aMedia.IsSupported(KMPXMediaGeneralModified) || |
|
2540 aMedia.IsSupported(KMPXMediaGeneralCopyright) || |
|
2541 aMedia.IsSupported(KMPXMediaGeneralDuration) || |
|
2542 aMedia.IsSupported(KMPXMediaGeneralFlags) || |
|
2543 aMedia.IsSupported(KMPXMediaGeneralPlayCount) || |
|
2544 aMedia.IsSupported(KMPXMediaGeneralLastPlaybackTime) || |
|
2545 aMedia.IsSupported(KMPXMediaMusicAlbumTrack) || |
|
2546 aMedia.IsSupported(KMPXMediaMusicYear) || |
|
2547 aMedia.IsSupported(KMPXMediaMusicRating) || |
|
2548 aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) || |
|
2549 aMedia.IsSupported(KMPXMediaMusicURL) || |
|
2550 aMedia.IsSupported(KMPXMediaMusicArtist) || |
|
2551 aMedia.IsSupported(KMPXMediaMusicAlbum) || |
|
2552 aMedia.IsSupported(KMPXMediaMusicGenre) || |
|
2553 aMedia.IsSupported(KMPXMediaMusicComposer) || |
|
2554 aMedia.IsSupported(KMPXMediaAudioSamplerate) || |
|
2555 aMedia.IsSupported(KMPXMediaAudioBitrate) || |
|
2556 aMedia.IsSupported(KMPXMediaAudioNumberOfChannels) || |
|
2557 aMedia.IsSupported(KMPXMediaDrmType) || |
|
2558 aMedia.IsSupported(KMPXMediaDrmRightsStatus) || |
|
2559 aMedia.IsSupported(KMPXMediaMTPDrmStatus); |
|
2560 } |
|
2561 |
|
2562 // End of File |