680 void CMPXDbMusic::GetAllSongsLimitedL(const TArray<TMPXAttribute>& aAttrs, |
683 void CMPXDbMusic::GetAllSongsLimitedL(const TArray<TMPXAttribute>& aAttrs, |
681 CMPXMediaArray& aMediaArray, TInt aLimit) |
684 CMPXMediaArray& aMediaArray, TInt aLimit) |
682 { |
685 { |
683 MPX_FUNC("CMPXDbMusic::GetAllSongsLimitedL"); |
686 MPX_FUNC("CMPXDbMusic::GetAllSongsLimitedL"); |
684 |
687 |
685 // Gets a subset of the data from all songs ordered by title |
688 // Reset and create a cache for the query results. |
686 HBufC* query = HBufC::NewLC( KQueryMusicGetSongsLimited().Length() + KMCIntegerLen ); |
689 if (iAllSongsQueryResult.Count()) |
687 query->Des().Format( KQueryMusicGetSongsLimited, aLimit ); |
690 { |
688 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
691 iAllSongsQueryResult.ResetAndDestroy(); |
689 CleanupStack::PopAndDestroy( query ); |
692 } |
690 } |
693 |
|
694 ExecuteQueryAllSongsL(aAttrs); |
|
695 |
|
696 TInt limit = aLimit > iAllSongsQueryResult.Count() ? |
|
697 iAllSongsQueryResult.Count() : aLimit; |
|
698 |
|
699 for ( TInt i=0; i < limit; i++ ) |
|
700 { |
|
701 CMPXMedia* m = iAllSongsQueryResult[i]; |
|
702 aMediaArray.AppendL(*m); |
|
703 } |
|
704 } |
|
705 |
|
706 // ---------------------------------------------------------------------------- |
|
707 // CMPXDbMusic::ExecuteQueryAllSongsL |
|
708 // ---------------------------------------------------------------------------- |
|
709 // |
|
710 void CMPXDbMusic::ExecuteQueryAllSongsL(const TArray<TMPXAttribute>& aAttrs) |
|
711 { |
|
712 // Run query and add result media objects to the cache array. |
|
713 MPX_FUNC("CMPXDbMusic::ExecuteQueryAllSongsL"); |
|
714 |
|
715 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryMusicGetAllSongs)); |
|
716 CleanupClosePushL(recordset); |
|
717 |
|
718 TInt err(KErrNone); |
|
719 while ((err = recordset.Next()) == KSqlAtRow) |
|
720 { |
|
721 CMPXMedia* media = CMPXMedia::NewL(); |
|
722 CleanupStack::PushL(media); |
|
723 UpdateMediaL(recordset, aAttrs, *media); |
|
724 iAllSongsQueryResult.AppendL(media); |
|
725 CleanupStack::Pop(media); |
|
726 } |
|
727 |
|
728 CleanupStack::PopAndDestroy(&recordset); |
|
729 if (err!= KSqlAtEnd) |
|
730 { |
|
731 User::Leave(KErrCorrupt); |
|
732 } |
|
733 } |
|
734 |
691 |
735 |
692 // ---------------------------------------------------------------------------- |
736 // ---------------------------------------------------------------------------- |
693 // CMPXDbMusic::GetSongsInBlockL |
737 // CMPXDbMusic::GetSongsInBlockL |
694 // ---------------------------------------------------------------------------- |
738 // ---------------------------------------------------------------------------- |
695 // |
739 // |
721 void CMPXDbMusic::GetSongsAtOffsetL( CMPXMediaArray& aMediaArray, |
765 void CMPXDbMusic::GetSongsAtOffsetL( CMPXMediaArray& aMediaArray, |
722 const TArray<TMPXAttribute>& aAttrs, |
766 const TArray<TMPXAttribute>& aAttrs, |
723 TInt aOffset, |
767 TInt aOffset, |
724 TInt aCount ) |
768 TInt aCount ) |
725 { |
769 { |
726 MPX_DEBUG1("CMPXDbMusic::GetSongsAtOffsetL <--"); |
770 MPX_DEBUG3("CMPXDbMusic::GetSongsAtOffsetL offset[%d], count[%d]", aOffset, aCount); |
727 |
771 |
728 ExecuteMediaQueryL(aAttrs, aMediaArray, KQueryMusicGetSongsAtOffset, |
772 if ( !iAllSongsQueryResult.Count() ) |
729 aCount, aOffset, EOffSetQuery ); |
773 { |
730 |
774 // If there's no cache, create a cache for the query results. |
731 MPX_DEBUG1("CMPXDbMusic::GetSongsAtOffsetL() -->"); |
775 ExecuteQueryAllSongsL(aAttrs); |
|
776 } |
|
777 |
|
778 TInt limit = aOffset + aCount > iAllSongsQueryResult.Count() ? |
|
779 iAllSongsQueryResult.Count() : aOffset + aCount; |
|
780 for ( TInt i = aOffset; i < limit; i++ ) |
|
781 { |
|
782 CMPXMedia* m = iAllSongsQueryResult[i]; |
|
783 aMediaArray.AppendL(*m); |
|
784 } |
|
785 |
|
786 MPX_DEBUG1("CMPXDbMusic::GetSongsAtOffsetL() -->"); |
732 } |
787 } |
733 |
788 |
734 // ---------------------------------------------------------------------------- |
789 // ---------------------------------------------------------------------------- |
735 // CMPXDbMusic::GetSongsForArtistL |
790 // CMPXDbMusic::GetSongsForArtistL |
736 // ---------------------------------------------------------------------------- |
791 // ---------------------------------------------------------------------------- |
2076 |
2131 |
2077 // update the artist field |
2132 // update the artist field |
2078 TUint32 id(0); |
2133 TUint32 id(0); |
2079 TUint32 artistIdForAlbum(artistId); |
2134 TUint32 artistIdForAlbum(artistId); |
2080 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2135 if (UpdateCategoryFieldL(EMPXArtist, aMedia, KMPXMediaMusicArtist, artistId, |
2081 aDrive, aItemChangedMessages, id, 0)) |
2136 aDrive, aItemChangedMessages, id)) |
2082 { |
2137 { |
2083 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2138 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, id); |
2084 metaDataModified = (aMusicTable != NULL); |
2139 metaDataModified = (aMusicTable != NULL); |
2085 visibleChange = CMPXDbActiveTask::EAllVisible; |
2140 visibleChange = CMPXDbActiveTask::EAllVisible; |
2086 artistIdForAlbum = id; |
2141 artistIdForAlbum = id; |
2087 } |
2142 } |
2088 |
2143 |
2089 // update the album field |
2144 // update the album field |
2090 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2145 if (UpdateCategoryFieldL(EMPXAlbum, aMedia, KMPXMediaMusicAlbum, albumId, |
2091 aDrive, aItemChangedMessages, id, artistIdForAlbum)) |
2146 aDrive, aItemChangedMessages, id)) |
2092 { |
2147 { |
2093 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
2148 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbum, id); |
2094 metaDataModified = (aMusicTable != NULL); |
2149 metaDataModified = (aMusicTable != NULL); |
2095 visibleChange = CMPXDbActiveTask::EAllVisible; |
2150 visibleChange = CMPXDbActiveTask::EAllVisible; |
2096 |
2151 |
2476 aItemChangedMessages, itemAdded, name, albumartist); |
2531 aItemChangedMessages, itemAdded, name, albumartist); |
2477 } |
2532 } |
2478 } |
2533 } |
2479 else |
2534 else |
2480 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2535 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
2536 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
|
2537 { |
|
2538 TPtrC art(KNullDesC); |
|
2539 TPtrC artistname(KNullDesC); |
|
2540 |
|
2541 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2542 { |
|
2543 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2544 } |
|
2545 if (aCategory == EMPXAlbum) |
|
2546 { |
|
2547 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
2548 { |
|
2549 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
2550 } |
|
2551 } |
|
2552 iObserver.AddCategoryItemL(aCategory, name, artistname, art, aDriveId, aItemChangedMessages, itemAdded); |
|
2553 } |
|
2554 else |
2481 { |
2555 { |
2482 // ignore the return value |
2556 // ignore the return value |
2483 iObserver.AddCategoryItemL(aCategory, name, aDriveId, |
2557 iObserver.AddCategoryItemL(aCategory, name, aDriveId, |
2484 aItemChangedMessages, itemAdded); |
2558 aItemChangedMessages, itemAdded); |
2485 } |
2559 } |
2511 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2585 iObserver.AddCategoryItemL(aCategory, abstractAlbumName, aDriveId, |
2512 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2586 aItemChangedMessages, itemAdded, KNullDesC, albumartist); |
2513 } |
2587 } |
2514 else |
2588 else |
2515 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2589 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
2516 { |
2590 if (aCategory == EMPXArtist || aCategory == EMPXAlbum) |
2517 // ignore the return value |
2591 { |
|
2592 TPtrC art(KNullDesC); |
|
2593 TPtrC artistname(KNullDesC); |
|
2594 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2595 { |
|
2596 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2597 } |
|
2598 if (aCategory == EMPXAlbum) |
|
2599 { |
|
2600 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
2601 { |
|
2602 artistname.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
2603 } |
|
2604 } |
|
2605 iObserver.AddCategoryItemL(aCategory, KNullDesC, artistname, art, aDriveId, |
|
2606 aItemChangedMessages, itemAdded); |
|
2607 } |
|
2608 else |
|
2609 { |
|
2610 // ignore the return value |
2518 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2611 iObserver.AddCategoryItemL(aCategory, KNullDesC, aDriveId, |
2519 aItemChangedMessages, itemAdded); |
2612 aItemChangedMessages, itemAdded); |
2520 } |
2613 } |
2521 updated = ETrue; |
2614 updated = ETrue; |
2522 } |
2615 } |
2583 } |
2676 } |
2584 |
2677 |
2585 return updated; |
2678 return updated; |
2586 } |
2679 } |
2587 |
2680 |
2588 TBool CMPXDbMusic::UpdateCategoryFieldL( |
2681 |
2589 TMPXGeneralCategory aCategory, |
|
2590 const CMPXMedia& aMedia, |
|
2591 const TMPXAttribute& aAttribute, |
|
2592 TUint32 aOldId, |
|
2593 TInt aDriveId, |
|
2594 CMPXMessageArray* aItemChangedMessages, |
|
2595 TUint32& aItemId, |
|
2596 TUint32 aArtistId) |
|
2597 { |
|
2598 TBool updated(EFalse); |
|
2599 TBool itemNotRemoved( EFalse ); |
|
2600 TBool itemAdded( EFalse ); |
|
2601 |
|
2602 // update category table and add category Id to the music table |
|
2603 if (!aOldId || aMedia.IsSupported(aAttribute)) |
|
2604 { |
|
2605 TInt changeMsgCount( 0 ); |
|
2606 if( aItemChangedMessages ) |
|
2607 { |
|
2608 changeMsgCount = aItemChangedMessages->Count(); |
|
2609 } |
|
2610 |
|
2611 if (aMedia.IsSupported(aAttribute)) |
|
2612 { |
|
2613 TPtrC name(aMedia.ValueText(aAttribute).Left(KMCMaxTextLen)); |
|
2614 |
|
2615 // construct the new ID for the category record |
|
2616 // only genre is not case sensitive |
|
2617 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, |
|
2618 name, (aCategory != EMPXGenre)); |
|
2619 if (!aOldId || (aOldId != aItemId)) |
|
2620 { |
|
2621 // only add if the ID changed, |
|
2622 // otherwise the song was updated but the artist name was not |
|
2623 TPtrC art(KNullDesC); |
|
2624 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2625 { |
|
2626 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2627 } |
|
2628 |
|
2629 iObserver.AddCategoryItemL(aCategory, name, aArtistId, art, aDriveId, aItemChangedMessages, itemAdded); |
|
2630 updated = ETrue; |
|
2631 } |
|
2632 } |
|
2633 else |
|
2634 { |
|
2635 // only genre is not case sensitive |
|
2636 aItemId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), aCategory, KNullDesC, |
|
2637 (aCategory != EMPXGenre)); |
|
2638 if (!aOldId || (aOldId != aItemId)) |
|
2639 { |
|
2640 TPtrC art(KNullDesC); |
|
2641 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
2642 { |
|
2643 art.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
2644 } |
|
2645 |
|
2646 iObserver.AddCategoryItemL(aCategory, KNullDesC, aArtistId, art, aDriveId, |
|
2647 aItemChangedMessages, itemAdded); |
|
2648 updated = ETrue; |
|
2649 } |
|
2650 } |
|
2651 |
|
2652 if (aOldId && (aOldId != aItemId)) |
|
2653 { |
|
2654 iObserver.DeleteSongForCategoryL(aCategory, aOldId, aDriveId, |
|
2655 aItemChangedMessages, itemNotRemoved); |
|
2656 updated = ETrue; |
|
2657 } |
|
2658 |
|
2659 // Special case where the item(s) has been renamed. |
|
2660 // In this case, a new category is created +1 change msg |
|
2661 // a old category is removed +1 change msg |
|
2662 // We merge these 2 change messages into one using the deprecated ID |
|
2663 // |
|
2664 if( aItemChangedMessages ) |
|
2665 { |
|
2666 TInt newChangeMsgCount( aItemChangedMessages->Count() ); |
|
2667 if( newChangeMsgCount - changeMsgCount > 0 ) |
|
2668 { |
|
2669 TInt oldId = KErrNotFound; |
|
2670 TInt newId = KErrNotFound; |
|
2671 for( TInt i=0; i<newChangeMsgCount; ++i ) |
|
2672 { |
|
2673 CMPXMessage& msg = *(*aItemChangedMessages)[i]; |
|
2674 |
|
2675 TMPXItemId id = msg.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId); |
|
2676 TMPXChangeEventType changeType = msg.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType); |
|
2677 |
|
2678 // Look for the added and deleted category IDs |
|
2679 // |
|
2680 if( id == aOldId && changeType == EMPXItemDeleted ) |
|
2681 { |
|
2682 oldId = i; |
|
2683 } |
|
2684 else if( id == aItemId && changeType == EMPXItemInserted ) |
|
2685 { |
|
2686 newId = i; |
|
2687 } |
|
2688 } |
|
2689 |
|
2690 if( oldId != KErrNotFound && |
|
2691 newId != KErrNotFound ) |
|
2692 { |
|
2693 aItemChangedMessages->Remove(oldId); // category removed |
|
2694 aItemChangedMessages->Remove(newId); // category added |
|
2695 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2696 aCategory, KDBPluginUid, aOldId ); |
|
2697 } |
|
2698 else if ( oldId !=KErrNotFound && itemAdded ) // old item removed, new item already exist |
|
2699 { |
|
2700 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aItemId, EMPXItemModified, |
|
2701 aCategory, KDBPluginUid, aOldId ); |
|
2702 } |
|
2703 else if ( newId !=KErrNotFound && itemNotRemoved ) // new item added, old item still exist |
|
2704 { |
|
2705 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aOldId, EMPXItemModified, |
|
2706 aCategory, KDBPluginUid, aItemId ); |
|
2707 } |
|
2708 } |
|
2709 } |
|
2710 } |
|
2711 |
|
2712 return updated; |
|
2713 } |
|
2714 // ---------------------------------------------------------------------------- |
2682 // ---------------------------------------------------------------------------- |
2715 // CMPXDbMusic::ExtraFieldsRequired |
2683 // CMPXDbMusic::ExtraFieldsRequired |
2716 // ---------------------------------------------------------------------------- |
2684 // ---------------------------------------------------------------------------- |
2717 // |
2685 // |
2718 TBool CMPXDbMusic::ExtraFieldsRequired( |
2686 TBool CMPXDbMusic::ExtraFieldsRequired( |