mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbhandler.cpp
branchRCL_3
changeset 56 2cbbefa9af78
parent 53 3de6c4cf6b67
child 66 1f1dad4af8f8
--- a/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbhandler.cpp	Wed Sep 01 12:32:02 2010 +0100
+++ b/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbhandler.cpp	Tue Sep 14 21:14:08 2010 +0300
@@ -174,7 +174,7 @@
     //
     iDbMusic = CMPXDbMusic::NewL(*iDbManager, iResource, *this);
     iDbPlaylist = CMPXDbPlaylist::NewL(*iDbManager, *this);
-    iDbArtist = CMPXDbArtist::NewL(*iDbManager, EMPXArtist, *this);
+    iDbArtist = CMPXDbArtist::NewL(*iDbManager, EMPXArtist);
     iDbAlbum = CMPXDbAlbum::NewL(*iDbManager, EMPXAlbum, *this);
     iDbGenre = CMPXDbGenre::NewL(*iDbManager, EMPXGenre);
     iDbComposer = CMPXDbComposer::NewL(*iDbManager, EMPXComposer);
@@ -987,18 +987,18 @@
             {
             MPX_DEBUG1("    EMPXMediaGeneralCount");
 
-            attributes.Append(TMPXAttribute(KMPXMediaIdGeneral, attributeId & ~EMPXMediaGeneralCount));
+            attributes.AppendL(TMPXAttribute(KMPXMediaIdGeneral, attributeId & ~EMPXMediaGeneralCount));
 
             tryGetSongCount = ETrue;
             break;
             }
 
-        attributes.Append(aAttrs[i]);
+        attributes.AppendL(aAttrs[i]);
         }
 
     for (TInt j = i+1; j < attrCount; j++)
         {
-        attributes.Append(aAttrs[j]);
+        attributes.AppendL(aAttrs[j]);
         }
     iDbAlbum->GetSubCategoryItemsL(EMPXArtist, aArtistId, attributes.Array(), aMediaArray);
     CleanupStack::PopAndDestroy(&attributes);
@@ -2148,7 +2148,7 @@
     // Update the category records
     TBool categoryExist( EFalse );
     iDbArtist->DecrementSongsForCategoryL(artistID, drive, &aItemChangedMessages, categoryExist);
-    iDbAlbum->DecrementSongsForCategoryL(albumID, drive, &aItemChangedMessages, categoryExist, artistID, *art);
+    iDbAlbum->DecrementSongsForAlbumL(albumID, drive, &aItemChangedMessages, categoryExist, *art);
     iDbGenre->DecrementSongsForCategoryL(genreID, drive, &aItemChangedMessages, categoryExist);
     iDbComposer->DecrementSongsForCategoryL(composerID, drive, &aItemChangedMessages, categoryExist);
     CleanupStack::PopAndDestroy(art);
@@ -2551,7 +2551,16 @@
     //////////////////////////////////////////////////////////////////////
     else
         {
-        iDbMusic->FindSongsL(id, containerId, type, aCriteria, aAttrs, aMediaArray);
+        TBool sortByTrackOrder = EFalse;
+		
+        // construct the sort order depending on category. Albums are always sorted by track,
+        // then name, except for unknown album. Songs are sorted by name for unknown album.
+        // NULL track number is stored as KMaxTInt so that they will be sorted to the end
+        if ((type == EMPXGroup) && (MPX_ITEM_CATEGORY(id) == EMPXAlbum) && !iDbAlbum->IsUnknownAlbumL(id))
+            {
+            sortByTrackOrder = ETrue;
+            }
+        iDbMusic->FindSongsL(id, containerId, type, aCriteria, aAttrs, aMediaArray, sortByTrackOrder);
         }
     }
 
@@ -3037,103 +3046,63 @@
 #endif // RD_MULTIPLE_DRIVE
 
 // ----------------------------------------------------------------------------
+// CMPXDbHandler::AddAbstractAlbumItemL
+// ----------------------------------------------------------------------------
+//
+#ifdef ABSTRACTAUDIOALBUM_INCLUDED
+TUint32 CMPXDbHandler::AddAbstractAlbumItemL(
+    const TDesC& aName,
+    TInt aDriveId,
+    CMPXMessageArray* aItemChangedMessages,
+    TBool& aItemExist,
+    const TDesC& aUri,
+    const TDesC& aAlbumArtist
+    )
+    {
+    MPX_FUNC("CMPXDbHandler::AddAbstractAlbumItemL()");
+
+    MPX_PERF_START(CMPXDbHandler_AddAbstractAlbumItemL);
+    
+    TBool newRecord(EFalse);
+    TUint32 id(0);
+
+    //AbstractAlbum is not case sensitive
+    id =  iDbAbstractAlbum->AddItemL(aUri, aName, aAlbumArtist, aDriveId, newRecord, EFalse);
+    MPX_PERF_END(CMPXDbHandler_AddAbstractAlbumItemL);
+    
+    return id;
+    }
+#endif
+
+// ----------------------------------------------------------------------------
 // CMPXDbHandler::AddCategoryItemL
 // ----------------------------------------------------------------------------
 //
 TUint32 CMPXDbHandler::AddCategoryItemL(
     TMPXGeneralCategory aCategory,
-    const TDesC& aName,
+    const CMPXMedia& aMedia,
     TInt aDriveId,
     CMPXMessageArray* aItemChangedMessages,
-    TBool& aItemExist
-#ifdef ABSTRACTAUDIOALBUM_INCLUDED
-    ,const TDesC& aUri
-    ,const TDesC& aAlbumArtist
-#endif // ABSTRACTAUDIOALBUM_INCLUDED
-    )
+    TBool& aItemExist)
     {
     MPX_FUNC("CMPXDbHandler::AddCategoryItemL()");
-
+    
     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
 
+    ASSERT(aCategory != EMPXAbstractAlbum);
+	
     TBool newRecord(EFalse);
-#ifdef ABSTRACTAUDIOALBUM_INCLUDED
-    TUint32 id(0);
-    //for AbstractAlbum, SetAbstractAlbum, associate songs with abstractalbum.
-    //only called with newRecord as EFalse
-    //increment songCount if id exist in AbstractAlbum table, otherwise do nothing.
-
-    //only Genre, AbstractAlbum are not case sensitive
-    TBool caseSensitive = ETrue;
-    if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum))
-        caseSensitive = EFalse;
-
-    if (aCategory == EMPXAbstractAlbum)
-        {
-        id =  iDbAbstractAlbum->AddItemL(aUri, aName, aAlbumArtist, aDriveId, newRecord, caseSensitive);
-        }
-    else
-        {
-        id = DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, caseSensitive);
-#else
-    TUint32 id(DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre)));
-#endif // ABSTRACTAUDIOALBUM_INCLUDED
+
+    TUint32 id = DbCategoryL(aCategory)->AddItemL(aCategory, aMedia, aDriveId, newRecord, aCategory != EMPXGenre);
 
     if (newRecord && aItemChangedMessages)
         {
         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted,
             aCategory, KDBPluginUid);
         }
-    // when the added item's category is Genre or Composer,
-    // and it is NOT a new record,
+    // when the added item's category is Genre, Composer or Artist, and it is NOT a new record,
     // we should send the item number changed message
-    else if ( ( aCategory == EMPXGenre || aCategory == EMPXComposer ) &&
-            !newRecord && aItemChangedMessages )
-        {
-        MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemModified,
-            aCategory, KDBPluginUid);
-        }
-    aItemExist = !newRecord;
-#ifdef ABSTRACTAUDIOALBUM_INCLUDED      
-       }
-#endif // ABSTRACTAUDIOALBUM_INCLUDED
-    MPX_PERF_END(CMPXDbHandler_AddCategoryItemL);
-    return id;
-    }
-
-TUint32 CMPXDbHandler::AddCategoryItemL(
-        TMPXGeneralCategory aCategory,
-        const TDesC& aName,
-        const TDesC& aArtistName,
-        const TDesC& aArt,
-        TInt aDriveId,
-        CMPXMessageArray* aItemChangedMessages,
-        TBool& aItemExist)
-	{
-    MPX_FUNC("CMPXDbHandler::AddCategoryItemL()");
-
-    MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
-
-    TBool newRecord(EFalse);
-
-    TUint32 id = 0;
-    if(aCategory == EMPXAlbum)
-        {
-        id = iDbAlbum->AddItemL(aName, aArtistName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
-        }
-    else
-        {
-        id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
-        }
-
-    if (newRecord && aItemChangedMessages)
-        {
-        MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted,
-            aCategory, KDBPluginUid);
-        }
-    // when the added item's category is Artist, and it is NOT a new record,
-    // we should send the item number changed message
-    else if (  aCategory == EMPXArtist &&
+    else if ( ( aCategory == EMPXGenre || aCategory == EMPXComposer || aCategory == EMPXArtist) &&
             !newRecord && aItemChangedMessages )
         {
         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemModified,
@@ -3142,31 +3111,23 @@
     aItemExist = !newRecord;
     MPX_PERF_END(CMPXDbHandler_AddCategoryItemL);
 
-    return id;
+    return id;    
     }
 
+// ----------------------------------------------------------------------------
+// CMPXDbHandler::UpdateCategoryItemL
+// ----------------------------------------------------------------------------
+//
 void CMPXDbHandler::UpdateCategoryItemL(
-        TMPXGeneralCategory aCategory,
-        TUint32 aCategoryId,
-        const CMPXMedia& aMedia,
-        TInt aDrive,
-        CMPXMessageArray* aItemChangedMessages)
+    TMPXGeneralCategory aCategory,
+    TUint32 aCategoryId,
+    const CMPXMedia& aMedia,
+    TInt aDrive,
+    CMPXMessageArray* aItemChangedMessages)
     {
-    switch(aCategory)
-        {
-        case EMPXAlbum:
-            iDbAlbum->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
-            break;
-
-        case EMPXArtist:
-            iDbArtist->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
-            break;
-
-        default:
-            DbCategoryL(aCategory)->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
-            break;
-        }
+    DbCategoryL(aCategory)->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
     }
+
 // ----------------------------------------------------------------------------
 // CMPXDbHandler::DeleteSongForCategoryL
 // ----------------------------------------------------------------------------
@@ -3176,11 +3137,21 @@
     TUint32 aCategoryId,
     TInt aDriveId,
     CMPXMessageArray* aItemChangedMessages,
-    TBool& aItemExist)
+    TBool& aItemExist,
+    const TDesC& aArt   
+    )
     {
     MPX_FUNC("CMPXDbHandler::DeleteSongForCategoryL");
-    DbCategoryL(aCategory)->DecrementSongsForCategoryL(aCategoryId, aDriveId,
-        aItemChangedMessages, aItemExist);
+    switch(aCategory)
+        {
+        case EMPXAlbum:
+            iDbAlbum->DecrementSongsForAlbumL(aCategoryId, aDriveId, aItemChangedMessages, aItemExist, aArt);
+            break;
+        default:
+            DbCategoryL(aCategory)->DecrementSongsForCategoryL(aCategoryId, aDriveId,
+                    aItemChangedMessages, aItemExist);
+            break;
+        }
     }
 
 // ----------------------------------------------------------------------------
@@ -3221,7 +3192,6 @@
         SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, plId);
     }
 
-
 // ---------------------------------------------------------------------------
 // CMPXDbHandler::IsRemoteDrive
 // ---------------------------------------------------------------------------
@@ -3267,28 +3237,6 @@
     CleanupStack::PopAndDestroy(&attributes);        
     }
 
-TInt CMPXDbHandler::HandleGetAlbumsCountForArtistL(TUint32 aArtistId)
-    {
-    return iDbAlbum->GetAlbumsCountForArtistL(aArtistId);
-    }
-
-TBool CMPXDbHandler::HandleIsUnknownArtistL(TUint32 aArtistId)
-    {
-    return iDbArtist->IsUnknownArtistL(aArtistId);
-    }
-
-// ---------------------------------------------------------------------------
-// CMPXDbHandler::HandleArtistForAlbumL
-// ---------------------------------------------------------------------------
-//
-HBufC* CMPXDbHandler::HandleArtistForAlbumL(const TUint32 aAlbumId)
-    {
-
-    TUint32 artistId = iDbMusic->ArtistForAlbumL(aAlbumId);
-    HBufC* artistname = GetNameMatchingIdL(artistId);
-    return artistname;
-    }
-
 // ---------------------------------------------------------------------------
 // CMPXDbHandler::HandleAlbumartForAlbumL
 // ---------------------------------------------------------------------------
@@ -3297,6 +3245,7 @@
     {
     return iDbMusic->AlbumartForAlbumL(aAlbumId, aArt);
     }
+
 #ifdef ABSTRACTAUDIOALBUM_INCLUDED   
 // ----------------------------------------------------------------------------------------------------------
 // CMPXDbHandler::HandleGetAlbumNameForSongL
@@ -3307,4 +3256,43 @@
     return iDbAbstractAlbum->GetUriL(aId);
     }
 #endif // ABSTRACTAUDIOALBUM_INCLUDED
+
+// ----------------------------------------------------------------------------
+// CMPXDbHandler::DeleteAlbumForArtistL
+// ----------------------------------------------------------------------------
+//
+void CMPXDbHandler::DeleteAlbumForArtistL(TUint32 aCategoryId,
+    TInt aDrive, CMPXMessageArray* aItemChangedMessages)
+    {
+    MPX_FUNC("CMPXDbHandler::DeleteAlbumForArtistL");
+    iDbArtist->DecrementAlbumsForArtistL(aCategoryId, aDrive, aItemChangedMessages);
+    }
+
+// ----------------------------------------------------------------------------
+// CMPXDbHandler::AddAlbumArtistL
+// ----------------------------------------------------------------------------
+//
+TUint32 CMPXDbHandler::AddAlbumArtistL(const TDesC& aName, const TDesC& aArt, TInt aDriveId)
+    {
+    MPX_FUNC("CMPXDbHandler::AddAlbumArtistL");
+    return iDbArtist->AddAlbumArtistL(aName, aArt, aDriveId);
+    }
+
+// ----------------------------------------------------------------------------
+// CMPXDbHandler::GenerateUniqueIdForAlbumL
+// ----------------------------------------------------------------------------
+//
+TUint32 CMPXDbHandler::GenerateUniqueIdForAlbumL(const CMPXMedia& aMedia)
+    {
+    return iDbAlbum->GenerateUniqueIdL(aMedia);
+    }
+
+// ----------------------------------------------------------------------------
+// CMPXDbHandler::IsUnknownAlbumL
+// ----------------------------------------------------------------------------
+//
+TBool CMPXDbHandler::IsUnknownAlbumL(const TUint32 aId)
+    {
+    return iDbAlbum->IsUnknownAlbumL(aId);
+    }
 // End of file