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; |
45 // UniqueID column in Uris requests |
51 // UniqueID column in Uris requests |
46 const TInt KColUniqueID = 0; |
52 const TInt KColUniqueID = 0; |
47 // URI column in Uris requests |
53 // URI column in Uris requests |
48 const TInt KColUri = 1; |
54 const TInt KColUri = 1; |
49 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
55 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
246 if (recordset.Next() != KSqlAtRow) |
252 if (recordset.Next() != KSqlAtRow) |
247 { |
253 { |
248 User::Leave(KErrNotFound); |
254 User::Leave(KErrNotFound); |
249 } |
255 } |
250 |
256 |
251 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
252 iArtNeedUpdated = ETrue; // reset flag |
|
253 #endif |
|
254 TDriveUnit driveUnit(MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
257 TDriveUnit driveUnit(MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), |
255 recordset.ColumnInt64(EMusicVolumeId))); |
258 recordset.ColumnInt64(EMusicVolumeId))); |
256 visible = DoUpdateSongL(aSongId, aMedia, driveUnit, aItemChangedMessages, |
259 visible = DoUpdateSongL(aSongId, aMedia, driveUnit, aItemChangedMessages, |
257 recordset); |
260 recordset); |
258 |
261 |
259 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
262 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
260 if(iArtNeedUpdated) |
263 if(iArtNeedUpdated) |
261 { |
264 { |
262 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
265 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
263 // Update Album table |
266 // Update Album table |
264 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
267 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) || aMedia.IsSupported(KMPXMediaMusicArtist)) |
265 { |
268 { |
266 TUint32 albumId = recordset.ColumnInt64(EMusicAlbum); |
269 TUint32 albumId = recordset.ColumnInt64(EMusicAlbum); |
267 iObserver.UpdateCategoryItemL(EMPXAlbum, albumId, aMedia, driveUnit, aItemChangedMessages); |
270 iObserver.UpdateCategoryItemL(EMPXAlbum, albumId, aMedia, driveUnit, aItemChangedMessages); |
268 } |
271 } |
269 |
272 |
270 // Update Artist table |
273 // Update Artist table |
271 if ( aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) ) |
274 if ( aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName) ) |
272 { |
275 { |
273 TUint32 artistId = recordset.ColumnInt64(EMusicArtist); |
276 TUint32 artistId = recordset.ColumnInt64(EMusicArtist); |
274 iObserver.UpdateCategoryItemL(EMPXArtist, artistId, aMedia, driveUnit, aItemChangedMessages); |
277 iObserver.UpdateCategoryItemL(EMPXArtist, artistId, aMedia, driveUnit, aItemChangedMessages); |
275 } |
278 } |
276 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
279 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
277 } |
280 } |
|
281 iArtNeedUpdated = ETrue; //reset flag |
278 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
282 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
279 CleanupStack::PopAndDestroy(&recordset); |
283 CleanupStack::PopAndDestroy(&recordset); |
280 } |
284 } |
281 |
285 |
282 return visible; |
286 return visible; |
988 TUint32 aGeneralId, |
992 TUint32 aGeneralId, |
989 TUint32 aContainerId, |
993 TUint32 aContainerId, |
990 TMPXGeneralType aType, |
994 TMPXGeneralType aType, |
991 const CMPXMedia& aCriteria, |
995 const CMPXMedia& aCriteria, |
992 const TArray<TMPXAttribute>& aAttrs, |
996 const TArray<TMPXAttribute>& aAttrs, |
993 CMPXMediaArray& aMediaArray, |
997 CMPXMediaArray& aMediaArray) |
994 TBool aSortByTrackOrder |
|
995 ) |
|
996 { |
998 { |
997 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
999 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
998 |
1000 |
999 // get the selection criteria string |
1001 // get the selection criteria string |
1000 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
1002 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
1001 aCriteria); |
1003 aCriteria); |
1002 |
1004 |
1003 TPtrC sortOrder; |
1005 // construct the sort order depending on category. Albums are always sorted by track, |
1004 if (aSortByTrackOrder) |
1006 // then name, except for unknown album. Songs are sorted by name for unknown album. |
|
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))) |
1005 { |
1011 { |
1006 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
1012 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
1007 } |
1013 } |
1008 else |
1014 else |
1009 { |
1015 { |
1010 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
1016 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
1011 } |
1017 } |
1012 |
1018 |
1013 // construct the query |
1019 // construct the query |
1014 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
1020 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
1015 sortOrder.Length()); |
1021 sortOrder.Length()); |
1016 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
1022 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
1017 |
1023 |
1092 User::Leave(KErrCorrupt); |
1098 User::Leave(KErrCorrupt); |
1093 } |
1099 } |
1094 } |
1100 } |
1095 |
1101 |
1096 // ---------------------------------------------------------------------------- |
1102 // ---------------------------------------------------------------------------- |
|
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 // ---------------------------------------------------------------------------- |
1097 // CMPXDbMusic::AlbumartForAlbumL |
1123 // CMPXDbMusic::AlbumartForAlbumL |
1098 // ---------------------------------------------------------------------------- |
1124 // ---------------------------------------------------------------------------- |
1099 // |
1125 // |
1100 HBufC* CMPXDbMusic::AlbumartForAlbumL(const TUint32 aAlbumId, TPtrC aArt) |
1126 HBufC* CMPXDbMusic::AlbumartForAlbumL(const TUint32 aAlbumId, TPtrC aArt) |
1101 { |
1127 { |
1102 MPX_FUNC("CMPXDbMusic::AlbumartForAlbumL"); |
1128 MPX_FUNC("CMPXDbMusic::AlbumartForAlbumL"); |
1103 |
|
1104 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAlbumartForAlbum, aAlbumId)); |
1129 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAlbumartForAlbum, aAlbumId)); |
1105 HBufC* albumart(NULL); |
1130 HBufC* albumart(NULL); |
1106 |
1131 |
1107 CleanupClosePushL(recordset); |
1132 CleanupClosePushL(recordset); |
1108 TInt err(KErrNone); |
1133 TInt err(KErrNone); |
2091 TUint32 genreId(0); |
2116 TUint32 genreId(0); |
2092 TUint32 composerId(0); |
2117 TUint32 composerId(0); |
2093 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2118 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2094 TUint32 abstractAlbumId(0); |
2119 TUint32 abstractAlbumId(0); |
2095 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2120 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2096 //need to get song art for updating art field in Album and Artist tables |
|
2097 TPtrC art(KNullDesC); |
|
2098 if (aMusicTable) |
2121 if (aMusicTable) |
2099 { |
2122 { |
2100 artistId = aMusicTable->ColumnInt64(EMusicArtist); |
2123 artistId = aMusicTable->ColumnInt64(EMusicArtist); |
2101 albumId = aMusicTable->ColumnInt64(EMusicAlbum); |
2124 albumId = aMusicTable->ColumnInt64(EMusicAlbum); |
2102 genreId = aMusicTable->ColumnInt64(EMusicGenre); |
2125 genreId = aMusicTable->ColumnInt64(EMusicGenre); |
2103 composerId = aMusicTable->ColumnInt64(EMusicComposer); |
2126 composerId = aMusicTable->ColumnInt64(EMusicComposer); |
2104 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2127 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2105 abstractAlbumId = aMusicTable->ColumnInt64(EMusicAbstractAlbum); |
2128 abstractAlbumId = aMusicTable->ColumnInt64(EMusicAbstractAlbum); |
2106 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2129 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2107 art.Set(MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicArt)); |
|
2108 } |
2130 } |
2109 |
2131 |
2110 // update the artist field |
2132 // update the artist field |
2111 TUint32 id(0); |
2133 TUint32 id(0); |
|
2134 TUint32 artistIdForAlbum(artistId); |
2112 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2135 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2113 aDrive, aItemChangedMessages, id, art)) |
2136 aDrive, aItemChangedMessages, id)) |
2114 { |
2137 { |
2115 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2138 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2116 metaDataModified = (aMusicTable != NULL); |
2139 metaDataModified = (aMusicTable != NULL); |
2117 visibleChange = CMPXDbActiveTask::EAllVisible; |
2140 visibleChange = CMPXDbActiveTask::EAllVisible; |
2118 iArtNeedUpdated = EFalse; |
2141 artistIdForAlbum = id; |
2119 } |
2142 } |
2120 |
2143 |
2121 // update the album field |
2144 // update the album field |
2122 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2145 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2123 aDrive, aItemChangedMessages, id, art)) |
2146 aDrive, aItemChangedMessages, id)) |
2124 { |
2147 { |
2125 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
2148 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
2126 metaDataModified = (aMusicTable != NULL); |
2149 metaDataModified = (aMusicTable != NULL); |
2127 visibleChange = CMPXDbActiveTask::EAllVisible; |
2150 visibleChange = CMPXDbActiveTask::EAllVisible; |
2128 |
2151 |
2139 // send album added m essage instead of album deleted or modified |
2162 // send album added m essage instead of album deleted or modified |
2140 // to avoid collection paths of other clients being modified |
2163 // to avoid collection paths of other clients being modified |
2141 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
2164 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
2142 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
2165 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
2143 } |
2166 } |
2144 iArtNeedUpdated = EFalse; |
|
2145 } |
2167 } |
2146 |
2168 |
2147 // update the genre field |
2169 // update the genre field |
2148 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
2170 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
2149 aDrive, aItemChangedMessages, id)) |
2171 aDrive, aItemChangedMessages, id)) |
2441 const CMPXMedia& aMedia, |
2463 const CMPXMedia& aMedia, |
2442 const TMPXAttribute& aAttribute, |
2464 const TMPXAttribute& aAttribute, |
2443 TUint32 aOldId, |
2465 TUint32 aOldId, |
2444 TInt aDriveId, |
2466 TInt aDriveId, |
2445 CMPXMessageArray* aItemChangedMessages, |
2467 CMPXMessageArray* aItemChangedMessages, |
2446 TUint32& aItemId, |
2468 TUint32& aItemId) |
2447 const TDesC& aArt) |
2469 { |
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 |
|
2457 TBool updated(EFalse); |
2470 TBool updated(EFalse); |
2458 TBool itemNotRemoved( EFalse ); |
2471 TBool itemNotRemoved( EFalse ); |
2459 TBool itemAdded( EFalse ); |
2472 TBool itemAdded( EFalse ); |
2460 |
2473 |
2461 // update category table and add category Id to the music table |
2474 // update category table and add category Id to the music table |
2478 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
2491 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
2479 caseSensitive = EFalse; |
2492 caseSensitive = EFalse; |
2480 |
2493 |
2481 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2494 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2482 name, caseSensitive); |
2495 name, caseSensitive); |
|
2496 |
2483 #else |
2497 #else |
2484 // only genre is not case sensitive |
2498 // only genre is not case sensitive |
2485 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2499 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2486 name, (aCategory != EMPXGenre)); |
2500 name, (aCategory != EMPXGenre)); |
2487 #endif |
2501 #endif |
2492 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2506 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2493 if(aCategory == EMPXAbstractAlbum) |
2507 if(aCategory == EMPXAbstractAlbum) |
2494 { |
2508 { |
2495 if (aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXSong ) |
2509 if (aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXSong ) |
2496 { |
2510 { |
2497 iObserver.AddAbstractAlbumItemL(KNullDesC, aDriveId, |
2511 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2498 aItemChangedMessages, itemAdded, name, KNullDesC); |
2512 aItemChangedMessages, itemAdded, name, KNullDesC); |
2499 } |
2513 } |
2500 else |
2514 else |
2501 { |
2515 { |
2502 TPtrC albumartist(KNullDesC); |
2516 TPtrC albumartist(KNullDesC); |
2503 TPtrC abstractAlbumName(KNullDesC); |
2517 TPtrC abstractAlbumName(KNullDesC); |
2504 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist) ) |
2518 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist) ) |
2505 { |
2519 { |
2506 albumartist.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2520 albumartist.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2507 //get AlbumArt AbstractAlbum |
2521 //get AlbumArt AbstractAlbum |
2508 MPX_DEBUG2(" albumartist[%S]", &albumartist); |
2522 MPX_DEBUG2(" albumartist[%S]", &albumartist); |
2509 } |
2523 } |
2510 if (aMedia.IsSupported(KMPXMediaGeneralTitle) ) |
2524 if (aMedia.IsSupported(KMPXMediaGeneralTitle) ) |
2511 { |
2525 { |
2512 abstractAlbumName.Set(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2526 abstractAlbumName.Set(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2513 MPX_DEBUG2(" abstractAlbumName[%S]", &abstractAlbumName); |
2527 MPX_DEBUG2(" abstractAlbumName[%S]", &abstractAlbumName); |
2514 } |
2528 } |
2515 |
2529 // ignore the return value |
2516 // ignore the return value |
2530 |
2517 iObserver.AddAbstractAlbumItemL(abstractAlbumName, aDriveId, |
2531 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2518 aItemChangedMessages, itemAdded, name, albumartist); |
2532 aItemChangedMessages, itemAdded, name, albumartist); |
2519 } |
2533 } |
2520 } |
2534 } |
2521 else |
2535 else |
2522 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2536 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2523 if (aCategory == EMPXArtist) |
2537 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
2524 { |
2538 { |
2525 //for the update case, need to maintain art field for Artist/Album table. |
2539 TPtrC art(KNullDesC); |
2526 if (aOldId && (aOldId != aItemId)) |
2540 TPtrC artistname(KNullDesC); |
2527 { |
2541 |
2528 CMPXMedia* media = CMPXMedia::NewL(aMedia); |
2542 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
2529 CleanupStack::PushL(media); |
2543 { |
2530 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, aArt); |
2544 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
2531 iObserver.AddCategoryItemL(aCategory, *media, aDriveId, aItemChangedMessages, itemAdded); |
2545 } |
2532 CleanupStack::PopAndDestroy(media); |
2546 if (aCategory == EMPXAlbum) |
2533 } |
2547 { |
2534 else |
2548 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
2535 { |
2549 { |
2536 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, aItemChangedMessages, itemAdded); |
2550 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
2537 } |
2551 } |
|
2552 } |
|
2553 iObserver.AddCategoryItemL(aCategory, name, artistname, art, aDriveId, aItemChangedMessages, itemAdded); |
2538 } |
2554 } |
2539 else |
2555 else |
2540 { |
2556 { |
2541 // ignore the return value |
2557 // ignore the return value |
2542 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, |
2558 iObserver.AddCategoryItemL(aCategory, name, aDriveId, |
2543 aItemChangedMessages, itemAdded); |
2559 aItemChangedMessages, itemAdded); |
2544 } |
2560 } |
2545 updated = ETrue; |
2561 updated = ETrue; |
2546 } |
2562 } |
2547 } |
2563 } |
2565 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2581 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2566 MPX_DEBUG2(" Music albumartist[%S]", &albumartist); |
2582 MPX_DEBUG2(" Music albumartist[%S]", &albumartist); |
2567 TPtrC abstractAlbumName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2583 TPtrC abstractAlbumName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2568 MPX_DEBUG2(" Music abstractAlbumName[%S]", &abstractAlbumName); |
2584 MPX_DEBUG2(" Music abstractAlbumName[%S]", &abstractAlbumName); |
2569 // ignore the return value |
2585 // ignore the return value |
2570 iObserver.AddAbstractAlbumItemL(abstractAlbumName, aDriveId, |
2586 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2571 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2587 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2572 } |
2588 } |
2573 else |
2589 else |
2574 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2590 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
2591 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
|
2592 { |
|
2593 TPtrC art(KNullDesC); |
|
2594 TPtrC artistname(KNullDesC); |
|
2595 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2596 { |
|
2597 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2598 } |
|
2599 if (aCategory == EMPXAlbum) |
|
2600 { |
|
2601 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
2602 { |
|
2603 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
2604 } |
|
2605 } |
|
2606 iObserver.AddCategoryItemL(aCategory, KNullDesC, artistname, art, aDriveId, |
|
2607 aItemChangedMessages, itemAdded); |
|
2608 } |
|
2609 else |
2575 { |
2610 { |
2576 // ignore the return value |
2611 // ignore the return value |
2577 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, |
2612 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2578 aItemChangedMessages, itemAdded); |
2613 aItemChangedMessages, itemAdded); |
2579 } |
2614 } |
2580 updated = ETrue; |
2615 updated = ETrue; |
2581 } |
2616 } |
2582 } |
2617 } |
2583 |
2618 |
2584 if (aOldId && (aOldId != aItemId)) |
2619 if (aOldId && (aOldId != aItemId)) |
2585 { |
2620 { |
2586 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
2621 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
2722 ||aMedia.IsSupported(KMPXMediaMusicAlbumArtist) |
2758 ||aMedia.IsSupported(KMPXMediaMusicAlbumArtist) |
2723 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2759 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2724 ; |
2760 ; |
2725 } |
2761 } |
2726 |
2762 |
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 |
|
2843 // End of File |
2763 // End of File |