168 // create the music folders and initialize iDbDrives |
168 // create the music folders and initialize iDbDrives |
169 CleanupStack::PushL(musicFolders); |
169 CleanupStack::PushL(musicFolders); |
170 ProcessMusicFoldersL(*musicFolders); |
170 ProcessMusicFoldersL(*musicFolders); |
171 CleanupStack::PopAndDestroy(musicFolders); |
171 CleanupStack::PopAndDestroy(musicFolders); |
172 |
172 |
173 // Create the db infrastructure, |
173 // Create the db infrastructure, |
174 // |
174 // |
175 iDbMusic = CMPXDbMusic::NewL(*iDbManager, iResource, *this); |
175 iDbMusic = CMPXDbMusic::NewL(*iDbManager, iResource, *this); |
176 iDbPlaylist = CMPXDbPlaylist::NewL(*iDbManager, *this); |
176 iDbPlaylist = CMPXDbPlaylist::NewL(*iDbManager, *this); |
177 iDbArtist = CMPXDbArtist::NewL(*iDbManager, EMPXArtist, *this); |
177 iDbArtist = CMPXDbArtist::NewL(*iDbManager, EMPXArtist, *this); |
178 iDbAlbum = CMPXDbAlbum::NewL(*iDbManager, EMPXAlbum, *this); |
178 iDbAlbum = CMPXDbAlbum::NewL(*iDbManager, EMPXAlbum, *this); |
179 iDbGenre = CMPXDbGenre::NewL(*iDbManager, EMPXGenre); |
179 iDbGenre = CMPXDbGenre::NewL(*iDbManager, EMPXGenre); |
180 iDbComposer = CMPXDbComposer::NewL(*iDbManager, EMPXComposer); |
180 iDbComposer = CMPXDbComposer::NewL(*iDbManager, EMPXComposer); |
181 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
181 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
182 iDbAbstractAlbum = CMPXDbAbstractAlbum::NewL(*iDbManager, EMPXAbstractAlbum); |
182 iDbAbstractAlbum = CMPXDbAbstractAlbum::NewL(*iDbManager, EMPXAbstractAlbum, iFs); |
183 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
183 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
184 iAutoPlaylist = CMPXDbAutoPlaylist::NewL(*iDbManager, iFs, iResource); |
184 iAutoPlaylist = CMPXDbAutoPlaylist::NewL(*iDbManager, iFs, iResource); |
185 iDbAuxiliary = CMPXDbAuxiliary::NewL(*iDbManager); |
185 iDbAuxiliary = CMPXDbAuxiliary::NewL(*iDbManager); |
186 |
186 |
187 MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives)); |
187 MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives)); |
188 iCollectionOpen = ETrue; |
|
189 |
188 |
190 // If KErrCorrupt is returned, a database file was found to be corrupted |
189 // If KErrCorrupt is returned, a database file was found to be corrupted |
191 // and was replaced with a new one. The db plugin can ignore this error and continue |
190 // and was replaced with a new one. The db plugin can ignore this error and continue |
192 // because a new db file was successfully created in a subsequent retry. |
191 // because a new db file was successfully created in a subsequent retry. |
193 if ((err != KErrNone) && (err != KErrCorrupt) && (err != KErrDiskFull)) |
192 if ((err != KErrNone) && (err != KErrCorrupt) && (err != KErrDiskFull)) |
314 CMPXMessageArray* aMessageArray) |
313 CMPXMessageArray* aMessageArray) |
315 { |
314 { |
316 MPX_FUNC("CMPXDbHandler::AddAbstractAlbumL"); |
315 MPX_FUNC("CMPXDbHandler::AddAbstractAlbumL"); |
317 |
316 |
318 BeginTransactionL(); |
317 BeginTransactionL(); |
319 // TUint32 abstractAlbumId(0); |
|
320 TBool newRecord(EFalse); |
318 TBool newRecord(EFalse); |
321 TInt err(KErrNone); |
319 TInt err(KErrNone); |
322 |
320 |
323 TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri)); |
321 TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri)); |
324 TPtrC name(aMedia.ValueText(KMPXMediaGeneralUri).Left(KMCMaxTextLen)); |
322 TPtrC uri(aMedia.ValueText(KMPXMediaGeneralUri).Left(KMCMaxTextLen)); |
|
323 TPtrC name(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
325 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
324 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
326 TPtrC genre(aMedia.ValueText(KMPXMediaMusicGenre).Left(KMCMaxTextLen)); |
325 |
327 |
326 //only insert to AbstractAlbum table when it is new item |
328 //only insert to AbstractAlbum table when it is new item |
327 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse)); |
329 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, name, (EMPXAbstractAlbum!=EMPXGenre))); |
328 |
330 |
|
331 newRecord = !iDbAbstractAlbum->CategoryItemExistsL(drive, abstractAlbumId); |
329 newRecord = !iDbAbstractAlbum->CategoryItemExistsL(drive, abstractAlbumId); |
332 |
330 |
333 |
331 if (newRecord) |
334 if (newRecord) |
332 { |
335 { |
333 MPX_TRAP(err, abstractAlbumId = iDbAbstractAlbum->AddItemL(uri, name, albumartist, drive, newRecord, EFalse)); |
336 MPX_TRAP(err, abstractAlbumId = iDbAbstractAlbum->AddItemL( name, albumartist, genre, drive, newRecord, (EMPXAbstractAlbum != EMPXGenre))); |
|
337 if (iOutOfDisk && (err == KErrNotFound)) |
334 if (iOutOfDisk && (err == KErrNotFound)) |
338 { |
335 { |
339 err = KErrDiskFull; |
336 err = KErrDiskFull; |
340 } |
337 } |
341 if (aMessageArray) |
338 if (aMessageArray) |
344 EMPXAbstractAlbum, KDBPluginUid); |
341 EMPXAbstractAlbum, KDBPluginUid); |
345 } |
342 } |
346 } |
343 } |
347 EndTransactionL(err); |
344 EndTransactionL(err); |
348 |
345 |
349 return abstractAlbumId; |
346 return abstractAlbumId; |
350 } |
347 } |
351 |
348 |
352 // ---------------------------------------------------------------------------- |
349 // ---------------------------------------------------------------------------- |
353 // Update all songs which associate with AbstractAlbum in the collection |
350 // Update abstractalbum info to AbstractAlbum table and all songs which associate |
354 // ---------------------------------------------------------------------------- |
351 // with AbstractAlbum in the collection |
355 // |
352 // ---------------------------------------------------------------------------- |
356 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateAbstractAlbumSongsL( |
353 // |
|
354 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateAbstractAlbumL( |
357 const CMPXMedia& aMedia, |
355 const CMPXMedia& aMedia, |
358 CMPXMessageArray& aItemChangedMessages) |
356 CMPXMessageArray& aItemChangedMessages) |
359 { |
357 { |
360 MPX_FUNC("CMPXDbHandler::UpdateAbstractAlbumSongsL"); |
358 MPX_FUNC("CMPXDbHandler::UpdateAbstractAlbumL"); |
361 |
359 |
362 CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile); |
360 CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile); |
363 |
361 TUint32 itemId(0); |
364 if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
362 if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
365 { |
363 { |
366 const TDesC& art(aMedia.ValueText (KMPXMediaGeneralUri)); |
364 const TDesC& uri(aMedia.ValueText (KMPXMediaGeneralUri)); |
367 |
|
368 TBool existRecord(EFalse); |
|
369 TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri)); |
365 TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri)); |
370 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, art, (EMPXAbstractAlbum != EMPXGenre))); |
366 |
371 //check if abstractAlbum in ABSTRACTALBUM table before update songs |
367 //get Id based on new uri |
372 existRecord = iDbAbstractAlbum->CategoryItemExistsL(drive, rowId); |
368 itemId = MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse); |
373 |
369 if (!itemId) |
374 //update songs associated with abstractalbum only when abstractalbum associated already |
370 { |
375 //in the AbstractAlbum table |
371 User::Leave(KErrNotSupported); |
376 if (existRecord) |
372 } |
377 { |
373 |
378 if (aMedia.IsSupported(KMPXMediaArrayContents)) |
374 //if updating to new item, need do renaming for AbstractAlbum: delete old one and insert a new entry to AbstractAlbum table |
|
375 //if a new item, need update songs associated and renaming albstractalbum table |
|
376 if (aMedia.IsSupported(KMPXMediaGeneralId)) |
|
377 { |
|
378 MPX_DEBUG1("CMPXDbHandler::UpdateAbstractAlbumL, rename case"); |
|
379 |
|
380 BeginTransactionL(); |
|
381 //get old id, for renaming |
|
382 TInt err(KErrNone); |
|
383 TUint32 oldId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2; |
|
384 if (oldId && (oldId != itemId) ) //pass the old UID for renaming, do not care if new itemId exist or not |
379 { |
385 { |
380 |
386 //get old Uri based on old Id |
381 CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents); |
387 HBufC* oldUri = iDbAbstractAlbum->GetUriL(oldId); |
382 User::LeaveIfNull(mediaArray); |
388 CleanupStack::PushL(oldUri); |
|
389 |
|
390 //add and update new item to AbstractAlbum table |
|
391 //old existing item field values need to be saved and added when adding new item |
|
392 MPX_TRAP(err, itemId = iDbAbstractAlbum->AddUpdatedItemL(oldId, uri )); |
|
393 |
|
394 if (iOutOfDisk && (err == KErrNotFound)) |
|
395 { |
|
396 err = KErrDiskFull; |
|
397 } |
|
398 |
|
399 MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, itemId, EMPXItemInserted, |
|
400 EMPXAbstractAlbum, KDBPluginUid); |
|
401 |
|
402 //find and update all songs associated with oldId |
|
403 RArray<TMPXAttribute> songAttributes; |
|
404 CleanupClosePushL(songAttributes); |
|
405 songAttributes.AppendL(KMPXMediaGeneralId); |
|
406 |
|
407 CMPXMediaArray* mediaArray = CMPXMediaArray::NewL(); |
|
408 CleanupStack::PushL(mediaArray); |
|
409 |
|
410 //get all songs associated |
|
411 MPX_TRAP(err, iDbMusic->GetAllSongsForAbstractAlbumL(oldId, songAttributes.Array(), *mediaArray)); |
|
412 if (err == KErrNotFound) |
|
413 { |
|
414 // Leave with KErrNotFound |
|
415 MPX_DEBUG1("CMPXDbHandler::UpdateAbstractAlbumL, leave with not found"); |
|
416 User::Leave(KErrNotFound); |
|
417 } |
|
418 |
383 TInt count(mediaArray->Count()); |
419 TInt count(mediaArray->Count()); |
|
420 MPX_DEBUG2("CMPXDbHandler::UpdateAbstractAlbumL, [%d] songs associated", count); |
|
421 //go through all songs for updating |
384 for (TInt i = 0; i < count; i++) |
422 for (TInt i = 0; i < count; i++) |
385 { |
423 { |
386 CMPXMedia* element = mediaArray->AtL(i); |
424 CMPXMedia* song = mediaArray->AtL(i); |
387 element->SetTextValueL(KMPXMediaMusicAlbumArtFileName, art ); |
425 song->SetTextValueL(KMPXMediaMusicAlbumArtFileName, uri ); |
388 visibleChange = UpdateSongL(*element, aItemChangedMessages); |
426 visibleChange = UpdateSongL(*song, aItemChangedMessages); |
389 } |
427 } |
390 } |
428 CleanupStack::PopAndDestroy(mediaArray); |
391 else |
429 CleanupStack::PopAndDestroy(&songAttributes); |
392 { |
430 |
393 iDbAbstractAlbum->UpdateItemL(rowId, aMedia, drive, &aItemChangedMessages); |
431 //rename TN |
|
432 iDbAbstractAlbum->HandleTNL(*oldUri, uri, 0); |
|
433 CleanupStack::PopAndDestroy(oldUri); |
394 } |
434 } |
395 } |
435 EndTransactionL(err); |
|
436 }//renaming |
|
437 |
|
438 //check if abstractAlbum exist in ABSTRACTALBUM table before update it |
|
439 else if (iDbAbstractAlbum->CategoryItemExistsL(drive, itemId)) |
|
440 { |
|
441 //support updating Name, AlbumArtist fields for AbstractAlbum table |
|
442 iDbAbstractAlbum->UpdateItemL(itemId, aMedia, drive, &aItemChangedMessages); |
|
443 } |
396 } |
444 } |
397 return visibleChange; |
445 return visibleChange; |
398 } |
446 } |
|
447 |
|
448 // ---------------------------------------------------------------------------- |
|
449 // Update all songs which associate with AbstractAlbum to new AbstractAlbum info |
|
450 // in the collection |
|
451 // ---------------------------------------------------------------------------- |
|
452 // |
|
453 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateSongsAbstractAlbumInfoL( |
|
454 const CMPXMedia& aMedia, |
|
455 CMPXMessageArray& aItemChangedMessages) |
|
456 { |
|
457 MPX_FUNC("CMPXDbHandler::UpdateSongsAbstractAlbumInfoL"); |
|
458 const TDesC& uri(aMedia.ValueText (KMPXMediaGeneralUri)); |
|
459 //need to update songs information to music table |
|
460 CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
461 User::LeaveIfNull(mediaArray); |
|
462 TInt count(mediaArray->Count()); |
|
463 CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile); |
|
464 for (TInt i = 0; i < count; i++) |
|
465 { |
|
466 CMPXMedia* mediaSong = mediaArray->AtL(i); |
|
467 mediaSong->SetTextValueL(KMPXMediaMusicAlbumArtFileName, uri ); |
|
468 visibleChange = UpdateSongL(*mediaSong, aItemChangedMessages); |
|
469 } |
|
470 return visibleChange; |
|
471 } |
399 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
472 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
473 |
400 // ---------------------------------------------------------------------------- |
474 // ---------------------------------------------------------------------------- |
401 // Update a song in the collection |
475 // Update a song in the collection |
402 // ---------------------------------------------------------------------------- |
476 // ---------------------------------------------------------------------------- |
403 // |
477 // |
404 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateSongL( |
478 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateSongL( |
588 // Remove specified abstractalbum |
662 // Remove specified abstractalbum |
589 // ---------------------------------------------------------------------------- |
663 // ---------------------------------------------------------------------------- |
590 // |
664 // |
591 void CMPXDbHandler::RemoveAbstractAlbumL( |
665 void CMPXDbHandler::RemoveAbstractAlbumL( |
592 TUint32 aAbstractAlbumId, |
666 TUint32 aAbstractAlbumId, |
593 CDesCArray& aUriArray, |
667 CMPXMessageArray& aItemChangedMessages, TBool aFileDeleted) |
594 CMPXMessageArray& aItemChangedMessages) |
|
595 { |
668 { |
596 MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumL"); |
669 MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumL"); |
597 |
670 iDbAbstractAlbum->RemoveAbstractAlbumL(aAbstractAlbumId, aItemChangedMessages, aFileDeleted); |
598 BeginTransactionL(); |
|
599 MPX_TRAPD(err, DoRemoveAbstractAlbumL(aAbstractAlbumId, aUriArray, aItemChangedMessages)); |
|
600 EndTransactionL(err); |
|
601 } |
|
602 |
|
603 // ---------------------------------------------------------------------------- |
|
604 // Remove specified abstractalbum |
|
605 // ---------------------------------------------------------------------------- |
|
606 // |
|
607 void CMPXDbHandler::DoRemoveAbstractAlbumL( |
|
608 TUint32 aAbstractAlbumId, |
|
609 CDesCArray& aUriArray, |
|
610 CMPXMessageArray& aItemChangedMessages) |
|
611 { |
|
612 MPX_FUNC("CMPXDbHandler::DoRemoveAbstractAlbumL"); |
|
613 |
|
614 |
|
615 HBufC* uri(iDbAbstractAlbum->DeleteAbstractAlbumL(aAbstractAlbumId)); |
|
616 if (uri) |
|
617 { |
|
618 CleanupStack::PushL(uri); |
|
619 aUriArray.AppendL(*uri); |
|
620 CleanupStack::PopAndDestroy(uri); |
|
621 } |
|
622 |
|
623 MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aAbstractAlbumId, EMPXItemDeleted, |
|
624 EMPXAbstractAlbum, KDBPluginUid); |
|
625 |
|
626 |
|
627 } |
671 } |
628 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
672 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
629 |
673 |
630 // ---------------------------------------------------------------------------- |
674 // ---------------------------------------------------------------------------- |
631 // Cleanup records marked as deleted. This is designated for MTP to clean up records marked as deleted |
675 // Cleanup records marked as deleted. This is designated for MTP to clean up records marked as deleted |
946 attributes.Append(TMPXAttribute(KMPXMediaIdGeneral, attributeId & ~EMPXMediaGeneralCount)); |
990 attributes.Append(TMPXAttribute(KMPXMediaIdGeneral, attributeId & ~EMPXMediaGeneralCount)); |
947 |
991 |
948 tryGetSongCount = ETrue; |
992 tryGetSongCount = ETrue; |
949 break; |
993 break; |
950 } |
994 } |
951 |
995 |
952 attributes.Append(aAttrs[i]); |
996 attributes.Append(aAttrs[i]); |
953 } |
997 } |
954 |
998 |
955 for (TInt j = i+1; j < attrCount; j++) |
999 for (TInt j = i+1; j < attrCount; j++) |
956 { |
1000 { |
957 attributes.Append(aAttrs[j]); |
1001 attributes.Append(aAttrs[j]); |
958 } |
1002 } |
959 iDbAlbum->GetSubCategoryItemsL(EMPXArtist, aArtistId, attributes.Array(), aMediaArray); |
1003 iDbAlbum->GetSubCategoryItemsL(EMPXArtist, aArtistId, attributes.Array(), aMediaArray); |
960 CleanupStack::PopAndDestroy(&attributes); |
1004 CleanupStack::PopAndDestroy(&attributes); |
961 |
1005 |
962 TInt pPath(0); |
1006 TInt pPath(0); |
963 if (aMediaArray.Count()) |
1007 if (aMediaArray.Count()) |
964 { |
1008 { |
965 CMPXMedia* pMedia = aMediaArray[0]; |
1009 CMPXMedia* pMedia = aMediaArray[0]; |
966 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
1010 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
967 { |
1011 { |
968 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
1012 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
969 MPX_ASSERT(pPath); |
1013 MPX_ASSERT(pPath); |
970 } |
1014 } |
971 } |
1015 } |
972 |
1016 |
973 TInt albumCount(aMediaArray.Count()); |
1017 TInt albumCount(aMediaArray.Count()); |
974 if (albumCount) |
1018 if (albumCount) |
975 { |
1019 { |
976 if ( tryGetSongCount ) |
1020 if ( tryGetSongCount ) |
977 { |
1021 { |
978 TInt startIndex = pPath ? 1 : 0; |
1022 TInt startIndex = pPath ? 1 : 0; |
979 |
1023 |
980 for (TInt i = startIndex; i < albumCount; i++) |
1024 for (TInt i = startIndex; i < albumCount; i++) |
981 { |
1025 { |
982 CMPXMedia* media = aMediaArray[i]; |
1026 CMPXMedia* media = aMediaArray[i]; |
983 TUint32 albumId((media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId))); |
1027 TUint32 albumId((media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId))); |
984 |
1028 |
985 TInt songCount = iDbAlbum->GetSongsCountInAlbumMatchingArtistL(aArtistId, albumId); |
1029 TInt songCount = iDbAlbum->GetSongsCountInAlbumMatchingArtistL(aArtistId, albumId); |
986 |
1030 |
987 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount ); |
1031 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount ); |
988 MPX_DEBUG2(" SongCount[%d]", songCount ); |
1032 MPX_DEBUG2(" SongCount[%d]", songCount ); |
989 } |
1033 } |
990 } |
1034 } |
2347 |
2360 |
2348 // Send a message on the song in the playlist that is deleted |
2361 // Send a message on the song in the playlist that is deleted |
2349 MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted, |
2362 MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted, |
2350 EMPXSong, KDBPluginUid); |
2363 EMPXSong, KDBPluginUid); |
2351 } |
2364 } |
|
2365 |
|
2366 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
2367 // ---------------------------------------------------------------------------- |
|
2368 // Remove abstractalbums which have no songs associated. |
|
2369 // ---------------------------------------------------------------------------- |
|
2370 // |
|
2371 void CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL() |
|
2372 { |
|
2373 MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL"); |
|
2374 |
|
2375 BeginTransactionL(); |
|
2376 RArray<TUint32> iItemsIds; |
|
2377 CleanupClosePushL(iItemsIds); |
|
2378 //get all abstractalbum with no songs associated. |
|
2379 iDbAbstractAlbum->GetAllItemsWithNoSongL(iItemsIds); |
|
2380 TInt count = iItemsIds.Count(); |
|
2381 TInt err = KErrNone; |
|
2382 if (count) |
|
2383 { |
|
2384 MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, abstractalbum count[%d] ", iItemsIds.Count()); |
|
2385 CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL(); |
|
2386 CleanupStack::PushL(itemChangedMessages); |
|
2387 |
|
2388 //go through each one to delete |
|
2389 for (TInt i=0; i< count; i++) |
|
2390 { |
|
2391 TRAP(err, RemoveAbstractAlbumL(iItemsIds[i], *itemChangedMessages, EFalse)); |
|
2392 if (err != KErrNone) |
|
2393 { |
|
2394 MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, error happens when delete abstractalbum, err ", err); |
|
2395 } |
|
2396 } |
|
2397 CleanupStack::PopAndDestroy(itemChangedMessages); |
|
2398 } |
|
2399 CleanupStack::PopAndDestroy(&iItemsIds); |
|
2400 EndTransactionL(err); |
|
2401 } |
|
2402 |
|
2403 // ---------------------------------------------------------------------------- |
|
2404 // Remove .alb entry from AbstractAlnum table, TN table if .alb files deleted |
|
2405 // from file manager when refresh library |
|
2406 // ---------------------------------------------------------------------------- |
|
2407 // |
|
2408 void CMPXDbHandler::AbstractAlbumCleanUpL() |
|
2409 { |
|
2410 MPX_FUNC("CMPXDbHandler::AbstractAlbumCleanUpL"); |
|
2411 RArray<TMPXAttribute> attributes; |
|
2412 CleanupClosePushL(attributes); |
|
2413 attributes.AppendL(KMPXMediaGeneralUri); |
|
2414 CMPXMediaArray* mediaArray = CMPXMediaArray::NewL(); |
|
2415 CleanupStack::PushL(mediaArray); |
|
2416 |
|
2417 iDbAbstractAlbum->GetAllCategoryItemsL(attributes.Array(), *mediaArray); |
|
2418 |
|
2419 TInt count(mediaArray->Count()); |
|
2420 if (count) |
|
2421 { |
|
2422 CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL(); |
|
2423 CleanupStack::PushL(itemChangedMessages); |
|
2424 for (TInt i = 0; i < count; i++) |
|
2425 { |
|
2426 CMPXMedia* element = mediaArray->AtL(i); |
|
2427 const TDesC& uri = element->ValueText(KMPXMediaGeneralUri); |
|
2428 |
|
2429 //check if the file exists in file system |
|
2430 if (!(BaflUtils::FileExists(iFs, uri))) |
|
2431 { |
|
2432 //generate abstractalbum UID with the Uri |
|
2433 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse)); |
|
2434 RemoveAbstractAlbumL(abstractAlbumId, *itemChangedMessages, ETrue); |
|
2435 } |
|
2436 } |
|
2437 CleanupStack::PopAndDestroy(itemChangedMessages); |
|
2438 } |
|
2439 CleanupStack::PopAndDestroy(mediaArray); |
|
2440 CleanupStack::PopAndDestroy(&attributes); |
|
2441 } |
|
2442 #endif //ABSTRACTAUDIOALBUM_INCLUDED |
2352 |
2443 |
2353 // ---------------------------------------------------------------------------- |
2444 // ---------------------------------------------------------------------------- |
2354 // CMPXDbHandler::DoCleanupDeletedRecordsL |
2445 // CMPXDbHandler::DoCleanupDeletedRecordsL |
2355 // ---------------------------------------------------------------------------- |
2446 // ---------------------------------------------------------------------------- |
2356 // |
2447 // |
3032 TMPXGeneralCategory aCategory, |
3122 TMPXGeneralCategory aCategory, |
3033 const TDesC& aName, |
3123 const TDesC& aName, |
3034 TInt aDriveId, |
3124 TInt aDriveId, |
3035 CMPXMessageArray* aItemChangedMessages, |
3125 CMPXMessageArray* aItemChangedMessages, |
3036 TBool& aItemExist |
3126 TBool& aItemExist |
3037 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
3127 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
3038 ,const TDesC& aAlbumArtist, |
3128 ,const TDesC& aUri |
3039 const TDesC& aGenre |
3129 ,const TDesC& aAlbumArtist |
3040 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
3130 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
3041 ) |
3131 ) |
3042 { |
3132 { |
3043 MPX_FUNC("CMPXDbHandler::AddCategoryItemL()"); |
3133 MPX_FUNC("CMPXDbHandler::AddCategoryItemL()"); |
3044 |
3134 |
3045 MPX_PERF_START(CMPXDbHandler_AddCategoryItemL); |
3135 MPX_PERF_START(CMPXDbHandler_AddCategoryItemL); |
3046 |
3136 |
3047 TBool newRecord(EFalse); |
3137 TBool newRecord(EFalse); |
3048 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
3138 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
3049 TUint32 id(0); |
3139 TUint32 id(0); |
3050 //for AbstractAlbum, SetAbstractAlbum, associate songs with abstractalbum. |
3140 //for AbstractAlbum, SetAbstractAlbum, associate songs with abstractalbum. |
3051 //only called with newRecord as EFalse |
3141 //only called with newRecord as EFalse |
3052 //increment songCount if id exist in AbstractAlbum table, otherwise do nothing. |
3142 //increment songCount if id exist in AbstractAlbum table, otherwise do nothing. |
|
3143 |
|
3144 //only Genre, AbstractAlbum are not case sensitive |
|
3145 TBool caseSensitive = ETrue; |
|
3146 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
|
3147 caseSensitive = EFalse; |
|
3148 |
3053 if (aCategory == EMPXAbstractAlbum) |
3149 if (aCategory == EMPXAbstractAlbum) |
3054 { |
3150 { |
3055 id = iDbAbstractAlbum->AddItemL( aName, aAlbumArtist, aGenre, aDriveId, newRecord, (aCategory != EMPXGenre)); |
3151 id = iDbAbstractAlbum->AddItemL(aUri, aName, aAlbumArtist, aDriveId, newRecord, caseSensitive); |
3056 } |
3152 } |
3057 else |
3153 else |
3058 { |
3154 { |
3059 id = DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre)); |
3155 id = DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, caseSensitive); |
3060 #else |
3156 #else |
3061 TUint32 id(DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre))); |
3157 TUint32 id(DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre))); |
3062 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
3158 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
3159 |
3063 if (newRecord && aItemChangedMessages) |
3160 if (newRecord && aItemChangedMessages) |
3064 { |
3161 { |
3065 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted, |
3162 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted, |
3066 aCategory, KDBPluginUid); |
3163 aCategory, KDBPluginUid); |
3067 } |
3164 } |
3068 // when the added item's category is Genre or Composer, |
3165 // when the added item's category is Genre or Composer, |
3069 // and it is NOT a new record, |
3166 // and it is NOT a new record, |
3070 // we should send the item number changed message |
3167 // we should send the item number changed message |
3071 else if ( ( aCategory == EMPXGenre || aCategory == EMPXComposer ) && |
3168 else if ( ( aCategory == EMPXGenre || aCategory == EMPXComposer ) && |
3072 !newRecord && aItemChangedMessages ) |
3169 !newRecord && aItemChangedMessages ) |
3073 { |
3170 { |
3074 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemModified, |
3171 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemModified, |
3075 aCategory, KDBPluginUid); |
3172 aCategory, KDBPluginUid); |
3076 } |
3173 } |
3077 aItemExist = !newRecord; |
3174 aItemExist = !newRecord; |
3078 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
3175 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
3079 } |
3176 } |
3080 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
3177 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
3081 MPX_PERF_END(CMPXDbHandler_AddCategoryItemL); |
3178 MPX_PERF_END(CMPXDbHandler_AddCategoryItemL); |
3082 |
|
3083 return id; |
3179 return id; |
3084 } |
3180 } |
3085 |
3181 |
3086 TUint32 CMPXDbHandler::AddCategoryItemL( |
3182 TUint32 CMPXDbHandler::AddCategoryItemL( |
3087 TMPXGeneralCategory aCategory, |
3183 TMPXGeneralCategory aCategory, |
3123 } |
3219 } |
3124 aItemExist = !newRecord; |
3220 aItemExist = !newRecord; |
3125 MPX_PERF_END(CMPXDbHandler_AddCategoryItemL); |
3221 MPX_PERF_END(CMPXDbHandler_AddCategoryItemL); |
3126 |
3222 |
3127 return id; |
3223 return id; |
3128 } |
3224 } |
3129 |
3225 |
3130 void CMPXDbHandler::UpdateCategoryItemL( |
3226 void CMPXDbHandler::UpdateCategoryItemL( |
3131 TMPXGeneralCategory aCategory, |
3227 TMPXGeneralCategory aCategory, |
3132 TUint32 aCategoryId, |
3228 TUint32 aCategoryId, |
3133 const CMPXMedia& aMedia, |
3229 const CMPXMedia& aMedia, |
3134 TInt aDrive, |
3230 TInt aDrive, |
3135 CMPXMessageArray* aItemChangedMessages) |
3231 CMPXMessageArray* aItemChangedMessages) |
3136 { |
3232 { |
3137 switch(aCategory) |
3233 switch(aCategory) |
3138 { |
3234 { |
3139 case EMPXAlbum: |
3235 case EMPXAlbum: |
3140 iDbAlbum->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages); |
3236 iDbAlbum->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages); |
3141 break; |
3237 break; |
3142 |
3238 |
3143 case EMPXArtist: |
3239 case EMPXArtist: |
3144 iDbArtist->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages); |
3240 iDbArtist->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages); |
3145 break; |
3241 break; |
3146 |
3242 |
3147 default: |
3243 default: |
3148 DbCategoryL(aCategory)->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages); |
3244 DbCategoryL(aCategory)->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages); |
3149 break; |
3245 break; |
3150 } |
3246 } |
3151 } |
3247 } |
3152 // ---------------------------------------------------------------------------- |
3248 // ---------------------------------------------------------------------------- |
3153 // CMPXDbHandler::DeleteSongForCategoryL |
3249 // CMPXDbHandler::DeleteSongForCategoryL |
3154 // ---------------------------------------------------------------------------- |
3250 // ---------------------------------------------------------------------------- |
3155 // |
3251 // |
3156 void CMPXDbHandler::DeleteSongForCategoryL( |
3252 void CMPXDbHandler::DeleteSongForCategoryL( |