40 #include "mpxdbmanager.h" |
40 #include "mpxdbmanager.h" |
41 #include "mpxdbmusic.h" |
41 #include "mpxdbmusic.h" |
42 |
42 |
43 // CONSTANTS |
43 // CONSTANTS |
44 |
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 |
45 // UniqueID column in Uris requests |
52 const TInt KColUniqueID = 0; |
46 const TInt KColUniqueID = 0; |
53 // URI column in Uris requests |
47 // URI column in Uris requests |
54 const TInt KColUri = 1; |
48 const TInt KColUri = 1; |
55 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
49 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
252 if (recordset.Next() != KSqlAtRow) |
246 if (recordset.Next() != KSqlAtRow) |
253 { |
247 { |
254 User::Leave(KErrNotFound); |
248 User::Leave(KErrNotFound); |
255 } |
249 } |
256 |
250 |
|
251 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
252 iArtNeedUpdated = ETrue; // reset flag |
|
253 #endif |
257 TDriveUnit driveUnit(MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
254 TDriveUnit driveUnit(MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
258 recordset.ColumnInt64(EMusicVolumeId))); |
255 recordset.ColumnInt64(EMusicVolumeId))); |
259 visible = DoUpdateSongL(aSongId, aMedia, driveUnit, aItemChangedMessages, |
256 visible = DoUpdateSongL(aSongId, aMedia, driveUnit, aItemChangedMessages, |
260 recordset); |
257 recordset); |
261 |
258 |
262 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
259 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
263 if(iArtNeedUpdated) |
260 if(iArtNeedUpdated) |
264 { |
261 { |
265 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
262 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
266 // Update Album table |
263 // Update Album table |
267 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) || aMedia.IsSupported(KMPXMediaMusicArtist)) |
264 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
268 { |
265 { |
269 TUint32 albumId = recordset.ColumnInt64(EMusicAlbum); |
266 TUint32 albumId = recordset.ColumnInt64(EMusicAlbum); |
270 iObserver.UpdateCategoryItemL(EMPXAlbum, albumId, aMedia, driveUnit, aItemChangedMessages); |
267 iObserver.UpdateCategoryItemL(EMPXAlbum, albumId, aMedia, driveUnit, aItemChangedMessages); |
271 } |
268 } |
272 |
269 |
273 // Update Artist table |
270 // Update Artist table |
274 if ( aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) ) |
271 if ( aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) ) |
275 { |
272 { |
276 TUint32 artistId = recordset.ColumnInt64(EMusicArtist); |
273 TUint32 artistId = recordset.ColumnInt64(EMusicArtist); |
277 iObserver.UpdateCategoryItemL(EMPXArtist, artistId, aMedia, driveUnit, aItemChangedMessages); |
274 iObserver.UpdateCategoryItemL(EMPXArtist, artistId, aMedia, driveUnit, aItemChangedMessages); |
278 } |
275 } |
279 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
276 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
280 } |
277 } |
281 iArtNeedUpdated = ETrue; //reset flag |
|
282 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
278 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
283 CleanupStack::PopAndDestroy(&recordset); |
279 CleanupStack::PopAndDestroy(&recordset); |
284 } |
280 } |
285 |
281 |
286 return visible; |
282 return visible; |
992 TUint32 aGeneralId, |
988 TUint32 aGeneralId, |
993 TUint32 aContainerId, |
989 TUint32 aContainerId, |
994 TMPXGeneralType aType, |
990 TMPXGeneralType aType, |
995 const CMPXMedia& aCriteria, |
991 const CMPXMedia& aCriteria, |
996 const TArray<TMPXAttribute>& aAttrs, |
992 const TArray<TMPXAttribute>& aAttrs, |
997 CMPXMediaArray& aMediaArray) |
993 CMPXMediaArray& aMediaArray, |
|
994 TBool aSortByTrackOrder |
|
995 ) |
998 { |
996 { |
999 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
997 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
1000 |
998 |
1001 // get the selection criteria string |
999 // get the selection criteria string |
1002 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
1000 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
1003 aCriteria); |
1001 aCriteria); |
1004 |
1002 |
1005 // construct the sort order depending on category. Albums are always sorted by track, |
1003 TPtrC sortOrder; |
1006 // then name, except for unknown album. Songs are sorted by name for unknown album. |
1004 if (aSortByTrackOrder) |
1007 // NULL track number is stored as KMaxTInt so that they will be sorted to the end |
|
1008 TPtrC sortOrder; |
|
1009 if ((aType == EMPXGroup) && (MPX_ITEM_CATEGORY(aGeneralId) == EMPXAlbum) && |
|
1010 (aGeneralId != MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAlbum, KNullDesC, EFalse))) |
|
1011 { |
1005 { |
1012 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
1006 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
1013 } |
1007 } |
1014 else |
1008 else |
1015 { |
1009 { |
1016 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
1010 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
1017 } |
1011 } |
1018 |
1012 |
1019 // construct the query |
1013 // construct the query |
1020 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
1014 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
1021 sortOrder.Length()); |
1015 sortOrder.Length()); |
1022 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
1016 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
1023 |
1017 |
1098 User::Leave(KErrCorrupt); |
1092 User::Leave(KErrCorrupt); |
1099 } |
1093 } |
1100 } |
1094 } |
1101 |
1095 |
1102 // ---------------------------------------------------------------------------- |
1096 // ---------------------------------------------------------------------------- |
1103 // CMPXDbMusic::ArtistForAlbumL |
|
1104 // ---------------------------------------------------------------------------- |
|
1105 // |
|
1106 TUint32 CMPXDbMusic::ArtistForAlbumL(const TUint32 aId) |
|
1107 { |
|
1108 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetArtistForAlbum, aId)); |
|
1109 |
|
1110 CleanupClosePushL(recordset); |
|
1111 if (recordset.Next() != KSqlAtRow) |
|
1112 { |
|
1113 User::Leave(KErrNotFound); |
|
1114 } |
|
1115 |
|
1116 TUint32 artistId = recordset.ColumnInt64(KMPXTableDefaultIndex); |
|
1117 CleanupStack::PopAndDestroy(&recordset); |
|
1118 |
|
1119 return artistId; |
|
1120 } |
|
1121 |
|
1122 // ---------------------------------------------------------------------------- |
|
1123 // CMPXDbMusic::AlbumartForAlbumL |
1097 // CMPXDbMusic::AlbumartForAlbumL |
1124 // ---------------------------------------------------------------------------- |
1098 // ---------------------------------------------------------------------------- |
1125 // |
1099 // |
1126 HBufC* CMPXDbMusic::AlbumartForAlbumL(const TUint32 aAlbumId, TPtrC aArt) |
1100 HBufC* CMPXDbMusic::AlbumartForAlbumL(const TUint32 aAlbumId, TPtrC aArt) |
1127 { |
1101 { |
1128 MPX_FUNC("CMPXDbMusic::AlbumartForAlbumL"); |
1102 MPX_FUNC("CMPXDbMusic::AlbumartForAlbumL"); |
|
1103 |
1129 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAlbumartForAlbum, aAlbumId)); |
1104 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAlbumartForAlbum, aAlbumId)); |
1130 HBufC* albumart(NULL); |
1105 HBufC* albumart(NULL); |
1131 |
1106 |
1132 CleanupClosePushL(recordset); |
1107 CleanupClosePushL(recordset); |
1133 TInt err(KErrNone); |
1108 TInt err(KErrNone); |
2132 art.Set(MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicArt)); |
2107 art.Set(MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicArt)); |
2133 } |
2108 } |
2134 |
2109 |
2135 // update the artist field |
2110 // update the artist field |
2136 TUint32 id(0); |
2111 TUint32 id(0); |
2137 TUint32 artistIdForAlbum(artistId); |
|
2138 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2112 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2139 aDrive, aItemChangedMessages, id, art)) |
2113 aDrive, aItemChangedMessages, id, art)) |
2140 { |
2114 { |
2141 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2115 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2142 metaDataModified = (aMusicTable != NULL); |
2116 metaDataModified = (aMusicTable != NULL); |
2143 visibleChange = CMPXDbActiveTask::EAllVisible; |
2117 visibleChange = CMPXDbActiveTask::EAllVisible; |
2144 artistIdForAlbum = id; |
2118 iArtNeedUpdated = EFalse; |
2145 } |
2119 } |
2146 |
2120 |
2147 // update the album field |
2121 // update the album field |
2148 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2122 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2149 aDrive, aItemChangedMessages, id, art)) |
2123 aDrive, aItemChangedMessages, id, art)) |
2165 // send album added m essage instead of album deleted or modified |
2139 // send album added m essage instead of album deleted or modified |
2166 // to avoid collection paths of other clients being modified |
2140 // to avoid collection paths of other clients being modified |
2167 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
2141 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
2168 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
2142 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
2169 } |
2143 } |
|
2144 iArtNeedUpdated = EFalse; |
2170 } |
2145 } |
2171 |
2146 |
2172 // update the genre field |
2147 // update the genre field |
2173 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
2148 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
2174 aDrive, aItemChangedMessages, id)) |
2149 aDrive, aItemChangedMessages, id)) |
2466 const CMPXMedia& aMedia, |
2441 const CMPXMedia& aMedia, |
2467 const TMPXAttribute& aAttribute, |
2442 const TMPXAttribute& aAttribute, |
2468 TUint32 aOldId, |
2443 TUint32 aOldId, |
2469 TInt aDriveId, |
2444 TInt aDriveId, |
2470 CMPXMessageArray* aItemChangedMessages, |
2445 CMPXMessageArray* aItemChangedMessages, |
2471 TUint32& aItemId, const TDesC& aArt) |
2446 TUint32& aItemId, |
2472 { |
2447 const TDesC& aArt) |
|
2448 { |
|
2449 MPX_FUNC("CMPXDbMusic::UpdateCategoryFieldL"); |
|
2450 |
|
2451 if (aCategory == EMPXAlbum) |
|
2452 { |
|
2453 return UpdateCategoryFieldForAlbumL(aMedia, aAttribute, aOldId, |
|
2454 aDriveId, aItemChangedMessages, aItemId, aArt); |
|
2455 } |
|
2456 |
2473 TBool updated(EFalse); |
2457 TBool updated(EFalse); |
2474 TBool itemNotRemoved( EFalse ); |
2458 TBool itemNotRemoved( EFalse ); |
2475 TBool itemAdded( EFalse ); |
2459 TBool itemAdded( EFalse ); |
2476 |
2460 |
2477 // update category table and add category Id to the music table |
2461 // update category table and add category Id to the music table |
2494 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
2478 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
2495 caseSensitive = EFalse; |
2479 caseSensitive = EFalse; |
2496 |
2480 |
2497 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2481 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2498 name, caseSensitive); |
2482 name, caseSensitive); |
2499 |
|
2500 #else |
2483 #else |
2501 // only genre is not case sensitive |
2484 // only genre is not case sensitive |
2502 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2485 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2503 name, (aCategory != EMPXGenre)); |
2486 name, (aCategory != EMPXGenre)); |
2504 #endif |
2487 #endif |
2509 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2492 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2510 if(aCategory == EMPXAbstractAlbum) |
2493 if(aCategory == EMPXAbstractAlbum) |
2511 { |
2494 { |
2512 if (aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXSong ) |
2495 if (aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXSong ) |
2513 { |
2496 { |
2514 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2497 iObserver.AddAbstractAlbumItemL(KNullDesC, aDriveId, |
2515 aItemChangedMessages, itemAdded, name, KNullDesC); |
2498 aItemChangedMessages, itemAdded, name, KNullDesC); |
2516 } |
2499 } |
2517 else |
2500 else |
2518 { |
2501 { |
2519 TPtrC albumartist(KNullDesC); |
2502 TPtrC albumartist(KNullDesC); |
2520 TPtrC abstractAlbumName(KNullDesC); |
2503 TPtrC abstractAlbumName(KNullDesC); |
2521 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist) ) |
2504 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist) ) |
2522 { |
2505 { |
2523 albumartist.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2506 albumartist.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2524 //get AlbumArt AbstractAlbum |
2507 //get AlbumArt AbstractAlbum |
2525 MPX_DEBUG2(" albumartist[%S]", &albumartist); |
2508 MPX_DEBUG2(" albumartist[%S]", &albumartist); |
2526 } |
2509 } |
2527 if (aMedia.IsSupported(KMPXMediaGeneralTitle) ) |
2510 if (aMedia.IsSupported(KMPXMediaGeneralTitle) ) |
2528 { |
2511 { |
2529 abstractAlbumName.Set(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2512 abstractAlbumName.Set(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2530 MPX_DEBUG2(" abstractAlbumName[%S]", &abstractAlbumName); |
2513 MPX_DEBUG2(" abstractAlbumName[%S]", &abstractAlbumName); |
2531 } |
2514 } |
2532 // ignore the return value |
2515 |
2533 |
2516 // ignore the return value |
2534 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2517 iObserver.AddAbstractAlbumItemL(abstractAlbumName, aDriveId, |
2535 aItemChangedMessages, itemAdded, name, albumartist); |
2518 aItemChangedMessages, itemAdded, name, albumartist); |
2536 } |
2519 } |
2537 } |
2520 } |
2538 else |
2521 else |
2539 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2522 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2540 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
2523 if (aCategory == EMPXArtist) |
2541 { |
2524 { |
2542 TPtrC art(KNullDesC); |
2525 //for the update case, need to maintain art field for Artist/Album table. |
2543 TPtrC artistname(KNullDesC); |
|
2544 |
|
2545 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2546 { |
|
2547 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2548 } |
|
2549 if (aCategory == EMPXAlbum) |
|
2550 { |
|
2551 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
2552 { |
|
2553 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
2554 } |
|
2555 } |
|
2556 //for the update case, need to maitain art field for Artist/Album table. |
|
2557 if (aOldId && (aOldId != aItemId)) |
2526 if (aOldId && (aOldId != aItemId)) |
2558 { |
2527 { |
2559 iObserver.AddCategoryItemL(aCategory, name, artistname, aArt, aDriveId, aItemChangedMessages, itemAdded); |
2528 CMPXMedia* media = CMPXMedia::NewL(aMedia); |
2560 } |
2529 CleanupStack::PushL(media); |
|
2530 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, aArt); |
|
2531 iObserver.AddCategoryItemL(aCategory, *media, aDriveId, aItemChangedMessages, itemAdded); |
|
2532 CleanupStack::PopAndDestroy(media); |
|
2533 } |
2561 else |
2534 else |
2562 { |
2535 { |
2563 iObserver.AddCategoryItemL(aCategory, name, artistname, art, aDriveId, aItemChangedMessages, itemAdded); |
2536 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, aItemChangedMessages, itemAdded); |
2564 } |
2537 } |
2565 } |
2538 } |
2566 else |
2539 else |
2567 { |
2540 { |
2568 // ignore the return value |
2541 // ignore the return value |
2569 iObserver.AddCategoryItemL(aCategory, name, aDriveId, |
2542 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, |
2570 aItemChangedMessages, itemAdded); |
2543 aItemChangedMessages, itemAdded); |
2571 } |
2544 } |
2572 updated = ETrue; |
2545 updated = ETrue; |
2573 } |
2546 } |
2574 } |
2547 } |
2592 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2565 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2593 MPX_DEBUG2(" Music albumartist[%S]", &albumartist); |
2566 MPX_DEBUG2(" Music albumartist[%S]", &albumartist); |
2594 TPtrC abstractAlbumName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2567 TPtrC abstractAlbumName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2595 MPX_DEBUG2(" Music abstractAlbumName[%S]", &abstractAlbumName); |
2568 MPX_DEBUG2(" Music abstractAlbumName[%S]", &abstractAlbumName); |
2596 // ignore the return value |
2569 // ignore the return value |
2597 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2570 iObserver.AddAbstractAlbumItemL(abstractAlbumName, aDriveId, |
2598 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2571 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2599 } |
2572 } |
2600 else |
2573 else |
2601 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2574 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2602 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
|
2603 { |
|
2604 TPtrC art(KNullDesC); |
|
2605 TPtrC artistname(KNullDesC); |
|
2606 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2607 { |
|
2608 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2609 } |
|
2610 if (aCategory == EMPXAlbum) |
|
2611 { |
|
2612 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
2613 { |
|
2614 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
2615 } |
|
2616 } |
|
2617 iObserver.AddCategoryItemL(aCategory, KNullDesC, artistname, art, aDriveId, |
|
2618 aItemChangedMessages, itemAdded); |
|
2619 } |
|
2620 else |
|
2621 { |
2575 { |
2622 // ignore the return value |
2576 // ignore the return value |
2623 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2577 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, |
2624 aItemChangedMessages, itemAdded); |
2578 aItemChangedMessages, itemAdded); |
2625 } |
2579 } |
2626 updated = ETrue; |
2580 updated = ETrue; |
2627 } |
2581 } |
2628 } |
2582 } |
2629 |
2583 |
2630 if (aOldId && (aOldId != aItemId)) |
2584 if (aOldId && (aOldId != aItemId)) |
2631 { |
2585 { |
2632 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
2586 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
2769 ||aMedia.IsSupported(KMPXMediaMusicAlbumArtist) |
2722 ||aMedia.IsSupported(KMPXMediaMusicAlbumArtist) |
2770 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2723 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2771 ; |
2724 ; |
2772 } |
2725 } |
2773 |
2726 |
|
2727 // ---------------------------------------------------------------------------- |
|
2728 // CMPXDbMusic::UpdateCategoryFieldForAlbumL |
|
2729 // ---------------------------------------------------------------------------- |
|
2730 // |
|
2731 TBool CMPXDbMusic::UpdateCategoryFieldForAlbumL( |
|
2732 const CMPXMedia& aMedia, |
|
2733 const TMPXAttribute& aAttribute, |
|
2734 TUint32 aOldId, |
|
2735 TInt aDriveId, |
|
2736 CMPXMessageArray* aItemChangedMessages, |
|
2737 TUint32& aItemId, |
|
2738 const TDesC& aArt) |
|
2739 { |
|
2740 MPX_FUNC("CMPXDbMusic::UpdateCategoryFieldForAlbumL"); |
|
2741 |
|
2742 TBool updated(EFalse); |
|
2743 TBool itemNotRemoved( EFalse ); |
|
2744 TBool itemAdded( EFalse ); |
|
2745 |
|
2746 // update category table and add category Id to the music table |
|
2747 if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2748 { |
|
2749 TInt changeMsgCount( 0 ); |
|
2750 if( aItemChangedMessages ) |
|
2751 { |
|
2752 changeMsgCount = aItemChangedMessages->Count(); |
|
2753 } |
|
2754 |
|
2755 // construct the new ID for the category record |
|
2756 aItemId = iObserver.GenerateUniqueIdForAlbumL(aMedia); |
|
2757 |
|
2758 if (!aOldId || (aOldId != aItemId)) |
|
2759 { |
|
2760 // only add if the ID changed, |
|
2761 // otherwise the song was updated but the artist name was not |
|
2762 |
|
2763 //for the update case, need to maitain art field for Artist/Album table. |
|
2764 if (aOldId && (aOldId != aItemId)) |
|
2765 { |
|
2766 CMPXMedia* media = CMPXMedia::NewL(aMedia); |
|
2767 CleanupStack::PushL(media); |
|
2768 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, aArt); |
|
2769 |
|
2770 iObserver.AddCategoryItemL(EMPXAlbum, *media, aDriveId, aItemChangedMessages, itemAdded); |
|
2771 CleanupStack::PopAndDestroy(media); |
|
2772 } |
|
2773 else // !aOldId |
|
2774 { |
|
2775 iObserver.AddCategoryItemL(EMPXAlbum, aMedia, aDriveId, aItemChangedMessages, itemAdded); |
|
2776 } |
|
2777 updated = ETrue; |
|
2778 } |
|
2779 |
|
2780 if (aOldId && (aOldId != aItemId)) |
|
2781 { |
|
2782 iObserver.DeleteSongForCategoryL(EMPXAlbum, aOldId, aDriveId, |
|
2783 aItemChangedMessages, itemNotRemoved, aArt); |
|
2784 updated = ETrue; |
|
2785 } |
|
2786 |
|
2787 // Special case where the item(s) has been renamed. |
|
2788 // In this case, a new category is created +1 change msg |
|
2789 // a old category is removed +1 change msg |
|
2790 // We merge these 2 change messages into one using the deprecated ID |
|
2791 // |
|
2792 if( aItemChangedMessages ) |
|
2793 { |
|
2794 TInt newChangeMsgCount( aItemChangedMessages->Count() ); |
|
2795 if( newChangeMsgCount - changeMsgCount > 0 ) |
|
2796 { |
|
2797 TInt oldId = KErrNotFound; |
|
2798 TInt newId = KErrNotFound; |
|
2799 for( TInt i=0; i<newChangeMsgCount; ++i ) |
|
2800 { |
|
2801 CMPXMessage& msg = *(*aItemChangedMessages)[i]; |
|
2802 |
|
2803 TMPXItemId id = msg.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId); |
|
2804 TMPXChangeEventType changeType = msg.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType); |
|
2805 |
|
2806 // Look for the added and deleted category IDs |
|
2807 // |
|
2808 if( id == aOldId && changeType == EMPXItemDeleted ) |
|
2809 { |
|
2810 oldId = i; |
|
2811 } |
|
2812 else if( id == aItemId && changeType == EMPXItemInserted ) |
|
2813 { |
|
2814 newId = i; |
|
2815 } |
|
2816 }// for |
|
2817 |
|
2818 if( oldId != KErrNotFound && |
|
2819 newId != KErrNotFound ) |
|
2820 { |
|
2821 aItemChangedMessages->Remove(oldId); // category removed |
|
2822 aItemChangedMessages->Remove(newId); // category added |
|
2823 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2824 EMPXAlbum, KDBPluginUid, aOldId ); |
|
2825 } |
|
2826 else if ( oldId !=KErrNotFound && itemAdded ) // old item removed, new item already exist |
|
2827 { |
|
2828 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2829 EMPXAlbum, KDBPluginUid, aOldId ); |
|
2830 } |
|
2831 else if ( newId !=KErrNotFound && itemNotRemoved ) // new item added, old item still exist |
|
2832 { |
|
2833 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aOldId, EMPXItemModified, |
|
2834 EMPXAlbum, KDBPluginUid, aItemId ); |
|
2835 } |
|
2836 } |
|
2837 }// aItemChangedMessages |
|
2838 }// if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2839 |
|
2840 return updated; |
|
2841 } |
|
2842 |
2774 // End of File |
2843 // End of File |