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; |
683 void CMPXDbMusic::GetAllSongsLimitedL(const TArray<TMPXAttribute>& aAttrs, |
679 void CMPXDbMusic::GetAllSongsLimitedL(const TArray<TMPXAttribute>& aAttrs, |
684 CMPXMediaArray& aMediaArray, TInt aLimit) |
680 CMPXMediaArray& aMediaArray, TInt aLimit) |
685 { |
681 { |
686 MPX_FUNC("CMPXDbMusic::GetAllSongsLimitedL"); |
682 MPX_FUNC("CMPXDbMusic::GetAllSongsLimitedL"); |
687 |
683 |
688 // Reset and create a cache for the query results. |
684 // Reset the previous query results. This will cause creation of query result |
|
685 // cache during actual incremental open stage (i.e. GetSongsAtOffsetL). |
689 if (iAllSongsQueryResult.Count()) |
686 if (iAllSongsQueryResult.Count()) |
690 { |
687 { |
691 iAllSongsQueryResult.ResetAndDestroy(); |
688 iAllSongsQueryResult.ResetAndDestroy(); |
692 } |
689 } |
693 |
690 |
694 ExecuteQueryAllSongsL(aAttrs); |
691 // Gets a subset of the data from all songs ordered by title |
695 |
692 HBufC* query = HBufC::NewLC( KQueryMusicGetAllSongsMinimumLimited().Length() + KMCIntegerLen ); |
696 TInt limit = aLimit > iAllSongsQueryResult.Count() ? |
693 query->Des().Format( KQueryMusicGetAllSongsMinimumLimited, aLimit ); |
697 iAllSongsQueryResult.Count() : aLimit; |
694 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
698 |
695 CleanupStack::PopAndDestroy( query ); |
699 for ( TInt i=0; i < limit; i++ ) |
|
700 { |
|
701 CMPXMedia* m = iAllSongsQueryResult[i]; |
|
702 aMediaArray.AppendL(*m); |
|
703 } |
|
704 } |
696 } |
705 |
697 |
706 // ---------------------------------------------------------------------------- |
698 // ---------------------------------------------------------------------------- |
707 // CMPXDbMusic::ExecuteQueryAllSongsL |
699 // CMPXDbMusic::ExecuteQueryAllSongsL |
708 // ---------------------------------------------------------------------------- |
700 // ---------------------------------------------------------------------------- |
991 TUint32 aGeneralId, |
984 TUint32 aGeneralId, |
992 TUint32 aContainerId, |
985 TUint32 aContainerId, |
993 TMPXGeneralType aType, |
986 TMPXGeneralType aType, |
994 const CMPXMedia& aCriteria, |
987 const CMPXMedia& aCriteria, |
995 const TArray<TMPXAttribute>& aAttrs, |
988 const TArray<TMPXAttribute>& aAttrs, |
996 CMPXMediaArray& aMediaArray) |
989 CMPXMediaArray& aMediaArray, |
|
990 TBool aSortByTrackOrder |
|
991 ) |
997 { |
992 { |
998 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
993 MPX_FUNC("CMPXDbMusic::FindSongsL"); |
999 |
994 |
1000 // get the selection criteria string |
995 // get the selection criteria string |
1001 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
996 HBufC* criteriaStr = GenerateMusicMatchingCriteriaLC(aGeneralId, aContainerId, aType, |
1002 aCriteria); |
997 aCriteria); |
1003 |
998 |
1004 // construct the sort order depending on category. Albums are always sorted by track, |
999 TPtrC sortOrder; |
1005 // then name, except for unknown album. Songs are sorted by name for unknown album. |
1000 if (aSortByTrackOrder) |
1006 // NULL track number is stored as KMaxTInt so that they will be sorted to the end |
|
1007 TPtrC sortOrder; |
|
1008 if ((aType == EMPXGroup) && (MPX_ITEM_CATEGORY(aGeneralId) == EMPXAlbum) && |
|
1009 (aGeneralId != MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAlbum, KNullDesC, EFalse))) |
|
1010 { |
1001 { |
1011 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
1002 sortOrder.Set(KQueryMusicFindAllSortOrderTrack); |
1012 } |
1003 } |
1013 else |
1004 else |
1014 { |
1005 { |
1015 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
1006 sortOrder.Set(KQueryMusicFindAllSortOrderTitle); |
1016 } |
1007 } |
1017 |
1008 |
1018 // construct the query |
1009 // construct the query |
1019 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
1010 HBufC* query = HBufC::NewLC(KQueryMusicFindAll().Length() + criteriaStr->Length() + |
1020 sortOrder.Length()); |
1011 sortOrder.Length()); |
1021 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
1012 query->Des().Format(KQueryMusicFindAll, criteriaStr, &sortOrder); |
1022 |
1013 |
1097 User::Leave(KErrCorrupt); |
1088 User::Leave(KErrCorrupt); |
1098 } |
1089 } |
1099 } |
1090 } |
1100 |
1091 |
1101 // ---------------------------------------------------------------------------- |
1092 // ---------------------------------------------------------------------------- |
1102 // CMPXDbMusic::ArtistForAlbumL |
|
1103 // ---------------------------------------------------------------------------- |
|
1104 // |
|
1105 TUint32 CMPXDbMusic::ArtistForAlbumL(const TUint32 aId) |
|
1106 { |
|
1107 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetArtistForAlbum, aId)); |
|
1108 |
|
1109 CleanupClosePushL(recordset); |
|
1110 if (recordset.Next() != KSqlAtRow) |
|
1111 { |
|
1112 User::Leave(KErrNotFound); |
|
1113 } |
|
1114 |
|
1115 TUint32 artistId = recordset.ColumnInt64(KMPXTableDefaultIndex); |
|
1116 CleanupStack::PopAndDestroy(&recordset); |
|
1117 |
|
1118 return artistId; |
|
1119 } |
|
1120 |
|
1121 // ---------------------------------------------------------------------------- |
|
1122 // CMPXDbMusic::AlbumartForAlbumL |
1093 // CMPXDbMusic::AlbumartForAlbumL |
1123 // ---------------------------------------------------------------------------- |
1094 // ---------------------------------------------------------------------------- |
1124 // |
1095 // |
1125 HBufC* CMPXDbMusic::AlbumartForAlbumL(const TUint32 aAlbumId, TPtrC aArt) |
1096 HBufC* CMPXDbMusic::AlbumartForAlbumL(const TUint32 aAlbumId, TPtrC aArt) |
1126 { |
1097 { |
1127 MPX_FUNC("CMPXDbMusic::AlbumartForAlbumL"); |
1098 MPX_FUNC("CMPXDbMusic::AlbumartForAlbumL"); |
|
1099 |
1128 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAlbumartForAlbum, aAlbumId)); |
1100 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAlbumartForAlbum, aAlbumId)); |
1129 HBufC* albumart(NULL); |
1101 HBufC* albumart(NULL); |
1130 |
1102 |
1131 CleanupClosePushL(recordset); |
1103 CleanupClosePushL(recordset); |
1132 while ( recordset.Next() == KSqlAtRow ) |
1104 TInt err(KErrNone); |
|
1105 while ((err = recordset.Next()) == KSqlAtRow) |
1133 { |
1106 { |
1134 TPtrC art(MPXDbCommonUtil::GetColumnTextL(recordset, KMPXTableDefaultIndex)); |
1107 TPtrC art(MPXDbCommonUtil::GetColumnTextL(recordset, KMPXTableDefaultIndex)); |
1135 if (art.Length()>0 && art.Compare(KNullDesC)!=0 && art.CompareF(aArt)!=0 ) |
1108 if (art.Length()>0 && art.Compare(KNullDesC)!=0 && art.CompareF(aArt)!=0 ) |
1136 { |
1109 { |
1137 albumart = art.AllocL(); |
1110 albumart = art.AllocL(); |
2120 TUint32 genreId(0); |
2093 TUint32 genreId(0); |
2121 TUint32 composerId(0); |
2094 TUint32 composerId(0); |
2122 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2095 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2123 TUint32 abstractAlbumId(0); |
2096 TUint32 abstractAlbumId(0); |
2124 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2097 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
2098 //need to get song art for updating art field in Album and Artist tables |
|
2099 TPtrC art(KNullDesC); |
2125 if (aMusicTable) |
2100 if (aMusicTable) |
2126 { |
2101 { |
2127 artistId = aMusicTable->ColumnInt64(EMusicArtist); |
2102 artistId = aMusicTable->ColumnInt64(EMusicArtist); |
2128 albumId = aMusicTable->ColumnInt64(EMusicAlbum); |
2103 albumId = aMusicTable->ColumnInt64(EMusicAlbum); |
2129 genreId = aMusicTable->ColumnInt64(EMusicGenre); |
2104 genreId = aMusicTable->ColumnInt64(EMusicGenre); |
2130 composerId = aMusicTable->ColumnInt64(EMusicComposer); |
2105 composerId = aMusicTable->ColumnInt64(EMusicComposer); |
2131 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2106 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2132 abstractAlbumId = aMusicTable->ColumnInt64(EMusicAbstractAlbum); |
2107 abstractAlbumId = aMusicTable->ColumnInt64(EMusicAbstractAlbum); |
2133 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2108 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
2109 art.Set(MPXDbCommonUtil::GetColumnTextL(*aMusicTable, EMusicArt)); |
2134 } |
2110 } |
2135 |
2111 |
2136 // update the artist field |
2112 // update the artist field |
2137 TUint32 id(0); |
2113 TUint32 id(0); |
2138 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2114 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2139 aDrive, aItemChangedMessages, id)) |
2115 aDrive, aItemChangedMessages, id, art)) |
2140 { |
2116 { |
2141 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2117 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2142 metaDataModified = (aMusicTable != NULL); |
2118 metaDataModified = (aMusicTable != NULL); |
2143 visibleChange = CMPXDbActiveTask::EAllVisible; |
2119 visibleChange = CMPXDbActiveTask::EAllVisible; |
|
2120 iArtNeedUpdated = EFalse; |
2144 } |
2121 } |
2145 |
2122 |
2146 // update the album field |
2123 // update the album field |
2147 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2124 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2148 aDrive, aItemChangedMessages, id)) |
2125 aDrive, aItemChangedMessages, id, art)) |
2149 { |
2126 { |
2150 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
2127 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
2151 metaDataModified = (aMusicTable != NULL); |
2128 metaDataModified = (aMusicTable != NULL); |
2152 visibleChange = CMPXDbActiveTask::EAllVisible; |
2129 visibleChange = CMPXDbActiveTask::EAllVisible; |
2153 |
2130 |
2164 // send album added m essage instead of album deleted or modified |
2141 // send album added m essage instead of album deleted or modified |
2165 // to avoid collection paths of other clients being modified |
2142 // to avoid collection paths of other clients being modified |
2166 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
2143 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, albumId, |
2167 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
2144 EMPXItemInserted, EMPXAlbum, KDBPluginUid); |
2168 } |
2145 } |
|
2146 iArtNeedUpdated = EFalse; |
2169 } |
2147 } |
2170 |
2148 |
2171 // update the genre field |
2149 // update the genre field |
2172 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
2150 if (UpdateCategoryFieldL(EMPXGenre, aMedia, KMPXMediaMusicGenre, genreId, |
2173 aDrive, aItemChangedMessages, id)) |
2151 aDrive, aItemChangedMessages, id)) |
2470 const CMPXMedia& aMedia, |
2448 const CMPXMedia& aMedia, |
2471 const TMPXAttribute& aAttribute, |
2449 const TMPXAttribute& aAttribute, |
2472 TUint32 aOldId, |
2450 TUint32 aOldId, |
2473 TInt aDriveId, |
2451 TInt aDriveId, |
2474 CMPXMessageArray* aItemChangedMessages, |
2452 CMPXMessageArray* aItemChangedMessages, |
2475 TUint32& aItemId) |
2453 TUint32& aItemId, |
2476 { |
2454 const TDesC& aArt) |
|
2455 { |
|
2456 MPX_FUNC("CMPXDbMusic::UpdateCategoryFieldL"); |
|
2457 |
|
2458 if (aCategory == EMPXAlbum) |
|
2459 { |
|
2460 return UpdateCategoryFieldForAlbumL(aMedia, aAttribute, aOldId, |
|
2461 aDriveId, aItemChangedMessages, aItemId, aArt); |
|
2462 } |
|
2463 |
2477 TBool updated(EFalse); |
2464 TBool updated(EFalse); |
2478 TBool itemNotRemoved( EFalse ); |
2465 TBool itemNotRemoved( EFalse ); |
2479 TBool itemAdded( EFalse ); |
2466 TBool itemAdded( EFalse ); |
2480 |
2467 |
2481 // update category table and add category Id to the music table |
2468 // update category table and add category Id to the music table |
2498 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
2485 if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum)) |
2499 caseSensitive = EFalse; |
2486 caseSensitive = EFalse; |
2500 |
2487 |
2501 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2488 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2502 name, caseSensitive); |
2489 name, caseSensitive); |
2503 |
|
2504 #else |
2490 #else |
2505 // only genre is not case sensitive |
2491 // only genre is not case sensitive |
2506 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2492 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
2507 name, (aCategory != EMPXGenre)); |
2493 name, (aCategory != EMPXGenre)); |
2508 #endif |
2494 #endif |
2513 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2499 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
2514 if(aCategory == EMPXAbstractAlbum) |
2500 if(aCategory == EMPXAbstractAlbum) |
2515 { |
2501 { |
2516 if (aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXSong ) |
2502 if (aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXSong ) |
2517 { |
2503 { |
2518 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2504 iObserver.AddAbstractAlbumItemL(KNullDesC, aDriveId, |
2519 aItemChangedMessages, itemAdded, name, KNullDesC); |
2505 aItemChangedMessages, itemAdded, name, KNullDesC); |
2520 } |
2506 } |
2521 else |
2507 else |
2522 { |
2508 { |
2523 TPtrC albumartist(KNullDesC); |
2509 TPtrC albumartist(KNullDesC); |
2524 TPtrC abstractAlbumName(KNullDesC); |
2510 TPtrC abstractAlbumName(KNullDesC); |
2525 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist) ) |
2511 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist) ) |
2526 { |
2512 { |
2527 albumartist.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2513 albumartist.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2528 //get AlbumArt AbstractAlbum |
2514 //get AlbumArt AbstractAlbum |
2529 MPX_DEBUG2(" albumartist[%S]", &albumartist); |
2515 MPX_DEBUG2(" albumartist[%S]", &albumartist); |
2530 } |
2516 } |
2531 if (aMedia.IsSupported(KMPXMediaGeneralTitle) ) |
2517 if (aMedia.IsSupported(KMPXMediaGeneralTitle) ) |
2532 { |
2518 { |
2533 abstractAlbumName.Set(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2519 abstractAlbumName.Set(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2534 MPX_DEBUG2(" abstractAlbumName[%S]", &abstractAlbumName); |
2520 MPX_DEBUG2(" abstractAlbumName[%S]", &abstractAlbumName); |
2535 } |
2521 } |
2536 // ignore the return value |
2522 |
2537 |
2523 // ignore the return value |
2538 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2524 iObserver.AddAbstractAlbumItemL(abstractAlbumName, aDriveId, |
2539 aItemChangedMessages, itemAdded, name, albumartist); |
2525 aItemChangedMessages, itemAdded, name, albumartist); |
2540 } |
2526 } |
2541 } |
2527 } |
2542 else |
2528 else |
2543 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2529 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2544 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
2530 if (aCategory == EMPXArtist) |
2545 { |
2531 { |
2546 TPtrC art(KNullDesC); |
2532 //for the update case, need to maintain art field for Artist/Album table. |
2547 TPtrC artistname(KNullDesC); |
2533 if (aOldId && (aOldId != aItemId)) |
2548 |
2534 { |
2549 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
2535 CMPXMedia* media = CMPXMedia::NewL(aMedia); |
2550 { |
2536 CleanupStack::PushL(media); |
2551 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
2537 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, aArt); |
2552 } |
2538 iObserver.AddCategoryItemL(aCategory, *media, aDriveId, aItemChangedMessages, itemAdded); |
2553 if (aCategory == EMPXAlbum) |
2539 CleanupStack::PopAndDestroy(media); |
2554 { |
2540 } |
2555 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
2541 else |
2556 { |
2542 { |
2557 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
2543 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, aItemChangedMessages, itemAdded); |
2558 } |
2544 } |
2559 } |
|
2560 iObserver.AddCategoryItemL(aCategory, name, artistname, art, aDriveId, aItemChangedMessages, itemAdded); |
|
2561 } |
2545 } |
2562 else |
2546 else |
2563 { |
2547 { |
2564 // ignore the return value |
2548 // ignore the return value |
2565 iObserver.AddCategoryItemL(aCategory, name, aDriveId, |
2549 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, |
2566 aItemChangedMessages, itemAdded); |
2550 aItemChangedMessages, itemAdded); |
2567 } |
2551 } |
2568 updated = ETrue; |
2552 updated = ETrue; |
2569 } |
2553 } |
2570 } |
2554 } |
2588 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2572 TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
2589 MPX_DEBUG2(" Music albumartist[%S]", &albumartist); |
2573 MPX_DEBUG2(" Music albumartist[%S]", &albumartist); |
2590 TPtrC abstractAlbumName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2574 TPtrC abstractAlbumName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen)); |
2591 MPX_DEBUG2(" Music abstractAlbumName[%S]", &abstractAlbumName); |
2575 MPX_DEBUG2(" Music abstractAlbumName[%S]", &abstractAlbumName); |
2592 // ignore the return value |
2576 // ignore the return value |
2593 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2577 iObserver.AddAbstractAlbumItemL(abstractAlbumName, aDriveId, |
2594 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2578 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2595 } |
2579 } |
2596 else |
2580 else |
2597 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2581 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2598 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
|
2599 { |
|
2600 TPtrC art(KNullDesC); |
|
2601 TPtrC artistname(KNullDesC); |
|
2602 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2603 { |
|
2604 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2605 } |
|
2606 if (aCategory == EMPXAlbum) |
|
2607 { |
|
2608 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
2609 { |
|
2610 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
2611 } |
|
2612 } |
|
2613 iObserver.AddCategoryItemL(aCategory, KNullDesC, artistname, art, aDriveId, |
|
2614 aItemChangedMessages, itemAdded); |
|
2615 } |
|
2616 else |
|
2617 { |
2582 { |
2618 // ignore the return value |
2583 // ignore the return value |
2619 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2584 iObserver.AddCategoryItemL(aCategory, aMedia, aDriveId, |
2620 aItemChangedMessages, itemAdded); |
2585 aItemChangedMessages, itemAdded); |
2621 } |
2586 } |
2622 updated = ETrue; |
2587 updated = ETrue; |
2623 } |
2588 } |
2624 } |
2589 } |
2625 |
2590 |
2626 if (aOldId && (aOldId != aItemId)) |
2591 if (aOldId && (aOldId != aItemId)) |
2627 { |
2592 { |
2628 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
2593 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
2765 ||aMedia.IsSupported(KMPXMediaMusicAlbumArtist) |
2729 ||aMedia.IsSupported(KMPXMediaMusicAlbumArtist) |
2766 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2730 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2767 ; |
2731 ; |
2768 } |
2732 } |
2769 |
2733 |
|
2734 // ---------------------------------------------------------------------------- |
|
2735 // CMPXDbMusic::UpdateCategoryFieldForAlbumL |
|
2736 // ---------------------------------------------------------------------------- |
|
2737 // |
|
2738 TBool CMPXDbMusic::UpdateCategoryFieldForAlbumL( |
|
2739 const CMPXMedia& aMedia, |
|
2740 const TMPXAttribute& aAttribute, |
|
2741 TUint32 aOldId, |
|
2742 TInt aDriveId, |
|
2743 CMPXMessageArray* aItemChangedMessages, |
|
2744 TUint32& aItemId, |
|
2745 const TDesC& aArt) |
|
2746 { |
|
2747 MPX_FUNC("CMPXDbMusic::UpdateCategoryFieldForAlbumL"); |
|
2748 |
|
2749 TBool updated(EFalse); |
|
2750 TBool itemNotRemoved( EFalse ); |
|
2751 TBool itemAdded( EFalse ); |
|
2752 |
|
2753 // update category table and add category Id to the music table |
|
2754 if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2755 { |
|
2756 TInt changeMsgCount( 0 ); |
|
2757 if( aItemChangedMessages ) |
|
2758 { |
|
2759 changeMsgCount = aItemChangedMessages->Count(); |
|
2760 } |
|
2761 |
|
2762 // construct the new ID for the category record |
|
2763 aItemId = iObserver.GenerateUniqueIdForAlbumL(aMedia); |
|
2764 |
|
2765 if (!aOldId || (aOldId != aItemId)) |
|
2766 { |
|
2767 // only add if the ID changed, |
|
2768 // otherwise the song was updated but the artist name was not |
|
2769 |
|
2770 //for the update case, need to maitain art field for Artist/Album table. |
|
2771 if (aOldId && (aOldId != aItemId)) |
|
2772 { |
|
2773 CMPXMedia* media = CMPXMedia::NewL(aMedia); |
|
2774 CleanupStack::PushL(media); |
|
2775 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, aArt); |
|
2776 |
|
2777 iObserver.AddCategoryItemL(EMPXAlbum, *media, aDriveId, aItemChangedMessages, itemAdded); |
|
2778 CleanupStack::PopAndDestroy(media); |
|
2779 } |
|
2780 else // !aOldId |
|
2781 { |
|
2782 iObserver.AddCategoryItemL(EMPXAlbum, aMedia, aDriveId, aItemChangedMessages, itemAdded); |
|
2783 } |
|
2784 updated = ETrue; |
|
2785 } |
|
2786 |
|
2787 if (aOldId && (aOldId != aItemId)) |
|
2788 { |
|
2789 iObserver.DeleteSongForCategoryL(EMPXAlbum, aOldId, aDriveId, |
|
2790 aItemChangedMessages, itemNotRemoved, aArt); |
|
2791 updated = ETrue; |
|
2792 } |
|
2793 |
|
2794 // Special case where the item(s) has been renamed. |
|
2795 // In this case, a new category is created +1 change msg |
|
2796 // a old category is removed +1 change msg |
|
2797 // We merge these 2 change messages into one using the deprecated ID |
|
2798 // |
|
2799 if( aItemChangedMessages ) |
|
2800 { |
|
2801 TInt newChangeMsgCount( aItemChangedMessages->Count() ); |
|
2802 if( newChangeMsgCount - changeMsgCount > 0 ) |
|
2803 { |
|
2804 TInt oldId = KErrNotFound; |
|
2805 TInt newId = KErrNotFound; |
|
2806 for( TInt i=0; i<newChangeMsgCount; ++i ) |
|
2807 { |
|
2808 CMPXMessage& msg = *(*aItemChangedMessages)[i]; |
|
2809 |
|
2810 TMPXItemId id = msg.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId); |
|
2811 TMPXChangeEventType changeType = msg.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType); |
|
2812 |
|
2813 // Look for the added and deleted category IDs |
|
2814 // |
|
2815 if( id == aOldId && changeType == EMPXItemDeleted ) |
|
2816 { |
|
2817 oldId = i; |
|
2818 } |
|
2819 else if( id == aItemId && changeType == EMPXItemInserted ) |
|
2820 { |
|
2821 newId = i; |
|
2822 } |
|
2823 }// for |
|
2824 |
|
2825 if( oldId != KErrNotFound && |
|
2826 newId != KErrNotFound ) |
|
2827 { |
|
2828 aItemChangedMessages->Remove(oldId); // category removed |
|
2829 aItemChangedMessages->Remove(newId); // category added |
|
2830 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2831 EMPXAlbum, KDBPluginUid, aOldId ); |
|
2832 } |
|
2833 else if ( oldId !=KErrNotFound && itemAdded ) // old item removed, new item already exist |
|
2834 { |
|
2835 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2836 EMPXAlbum, KDBPluginUid, aOldId ); |
|
2837 } |
|
2838 else if ( newId !=KErrNotFound && itemNotRemoved ) // new item added, old item still exist |
|
2839 { |
|
2840 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aOldId, EMPXItemModified, |
|
2841 EMPXAlbum, KDBPluginUid, aItemId ); |
|
2842 } |
|
2843 } |
|
2844 }// aItemChangedMessages |
|
2845 }// if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2846 |
|
2847 return updated; |
|
2848 } |
|
2849 |
2770 // End of File |
2850 // End of File |