mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbhandler.cpp
changeset 25 3ec52facab4d
parent 22 ecf06a08d4d9
child 29 8192e5b5c935
equal deleted inserted replaced
22:ecf06a08d4d9 25:3ec52facab4d
   152 
   152 
   153     iMimeTypes = iResource.ReadDesCArrayL(R_MC_MIME_TYPES);
   153     iMimeTypes = iResource.ReadDesCArrayL(R_MC_MIME_TYPES);
   154     iExtensions = iResource.ReadDesCArrayL(R_MC_MUSIC_FILE_EXTENSIONS);
   154     iExtensions = iResource.ReadDesCArrayL(R_MC_MUSIC_FILE_EXTENSIONS);
   155     iExtensionsMime = iResource.ReadDesCArrayL(R_MC_FILE_EXTENSIONS_MIME);
   155     iExtensionsMime = iResource.ReadDesCArrayL(R_MC_FILE_EXTENSIONS_MIME);
   156     iExtensionsDrm = iResource.ReadDesCArrayL(R_MC_FILE_EXTENSIONS_DRM);
   156     iExtensionsDrm = iResource.ReadDesCArrayL(R_MC_FILE_EXTENSIONS_DRM);
   157     
   157 
   158     // make sure all databases are created and valid
   158     // make sure all databases are created and valid
   159     iDbManager = CMPXCollectionDbManager::NewL(iFs);
   159     iDbManager = CMPXCollectionDbManager::NewL(iFs);
   160     
   160 
   161     CDesCArrayFlat* musicFolders =
   161     CDesCArrayFlat* musicFolders =
   162 #ifdef RD_MULTIPLE_DRIVE
   162 #ifdef RD_MULTIPLE_DRIVE
   163         GetMusicFoldersL();
   163         GetMusicFoldersL();
   164 #else
   164 #else
   165         iResource.ReadDesCArrayL(R_MC_DEFAULT_MUSIC_FOLDERS);
   165         iResource.ReadDesCArrayL(R_MC_DEFAULT_MUSIC_FOLDERS);
   168     // create the music folders and initialize iDbDrives
   168     // create the music folders and initialize iDbDrives
   169     CleanupStack::PushL(musicFolders);
   169     CleanupStack::PushL(musicFolders);
   170     ProcessMusicFoldersL(*musicFolders);
   170     ProcessMusicFoldersL(*musicFolders);
   171     CleanupStack::PopAndDestroy(musicFolders);
   171     CleanupStack::PopAndDestroy(musicFolders);
   172 
   172 
   173     // Create the db infrastructure, 
   173     // Create the db infrastructure,
   174     //
   174     //
   175     iDbMusic = CMPXDbMusic::NewL(*iDbManager, iResource, *this);
   175     iDbMusic = CMPXDbMusic::NewL(*iDbManager, iResource, *this);
   176     iDbPlaylist = CMPXDbPlaylist::NewL(*iDbManager, *this);
   176     iDbPlaylist = CMPXDbPlaylist::NewL(*iDbManager, *this);
   177     iDbArtist = CMPXDbArtist::NewL(*iDbManager, EMPXArtist, *this);
   177     iDbArtist = CMPXDbArtist::NewL(*iDbManager, EMPXArtist, *this);
   178 	iDbAlbum = CMPXDbAlbum::NewL(*iDbManager, EMPXAlbum, *this);
   178     iDbAlbum = CMPXDbAlbum::NewL(*iDbManager, EMPXAlbum, *this);
   179     iDbGenre = CMPXDbGenre::NewL(*iDbManager, EMPXGenre);
   179     iDbGenre = CMPXDbGenre::NewL(*iDbManager, EMPXGenre);
   180     iDbComposer = CMPXDbComposer::NewL(*iDbManager, EMPXComposer);
   180     iDbComposer = CMPXDbComposer::NewL(*iDbManager, EMPXComposer);
   181 #ifdef ABSTRACTAUDIOALBUM_INCLUDED  
   181 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
   182     iDbAbstractAlbum = CMPXDbAbstractAlbum::NewL(*iDbManager, EMPXAbstractAlbum);
   182     iDbAbstractAlbum = CMPXDbAbstractAlbum::NewL(*iDbManager, EMPXAbstractAlbum, iFs);
   183 #endif // ABSTRACTAUDIOALBUM_INCLUDED 
   183 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   184     iAutoPlaylist = CMPXDbAutoPlaylist::NewL(*iDbManager, iFs, iResource);
   184     iAutoPlaylist = CMPXDbAutoPlaylist::NewL(*iDbManager, iFs, iResource);
   185     iDbAuxiliary = CMPXDbAuxiliary::NewL(*iDbManager);
   185     iDbAuxiliary = CMPXDbAuxiliary::NewL(*iDbManager);
   186 
   186 
   187     MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives));
   187     MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives));
   188     iCollectionOpen = ETrue;
       
   189 
   188 
   190     // If KErrCorrupt is returned, a database file was found to be corrupted
   189     // If KErrCorrupt is returned, a database file was found to be corrupted
   191     // and was replaced with a new one.  The db plugin can ignore this error and continue
   190     // and was replaced with a new one.  The db plugin can ignore this error and continue
   192     // because a new db file was successfully created in a subsequent retry.
   191     // because a new db file was successfully created in a subsequent retry.
   193     if ((err != KErrNone) && (err != KErrCorrupt) && (err != KErrDiskFull))
   192     if ((err != KErrNone) && (err != KErrCorrupt) && (err != KErrDiskFull))
   314     CMPXMessageArray* aMessageArray)
   313     CMPXMessageArray* aMessageArray)
   315     {
   314     {
   316     MPX_FUNC("CMPXDbHandler::AddAbstractAlbumL");
   315     MPX_FUNC("CMPXDbHandler::AddAbstractAlbumL");
   317 
   316 
   318     BeginTransactionL();
   317     BeginTransactionL();
   319    // TUint32 abstractAlbumId(0);
       
   320     TBool newRecord(EFalse);
   318     TBool newRecord(EFalse);
   321     TInt err(KErrNone);
   319     TInt err(KErrNone);
   322 
   320 
   323     TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri));
   321     TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri));
   324     TPtrC name(aMedia.ValueText(KMPXMediaGeneralUri).Left(KMCMaxTextLen));
   322     TPtrC uri(aMedia.ValueText(KMPXMediaGeneralUri).Left(KMCMaxTextLen));
       
   323     TPtrC name(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen));
   325     TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen));
   324     TPtrC albumartist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen));
   326     TPtrC genre(aMedia.ValueText(KMPXMediaMusicGenre).Left(KMCMaxTextLen));
   325 
   327     
   326     //only insert to AbstractAlbum table when it is new item
   328     //only insert to AbstractAlbum table when it is new item  
   327     TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse));
   329      TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, name, (EMPXAbstractAlbum!=EMPXGenre)));      
   328 
   330    
       
   331     newRecord = !iDbAbstractAlbum->CategoryItemExistsL(drive, abstractAlbumId);
   329     newRecord = !iDbAbstractAlbum->CategoryItemExistsL(drive, abstractAlbumId);
   332    
   330 
   333     
   331     if (newRecord)
   334     if (newRecord)   
   332         {
   335         {
   333         MPX_TRAP(err, abstractAlbumId = iDbAbstractAlbum->AddItemL(uri, name, albumartist, drive, newRecord, EFalse));
   336         MPX_TRAP(err, abstractAlbumId = iDbAbstractAlbum->AddItemL( name, albumartist, genre, drive, newRecord, (EMPXAbstractAlbum != EMPXGenre)));      
       
   337         if (iOutOfDisk && (err == KErrNotFound))
   334         if (iOutOfDisk && (err == KErrNotFound))
   338             {
   335             {
   339             err = KErrDiskFull;
   336             err = KErrDiskFull;
   340             }
   337             }
   341         if (aMessageArray)
   338         if (aMessageArray)
   344             EMPXAbstractAlbum, KDBPluginUid);
   341             EMPXAbstractAlbum, KDBPluginUid);
   345             }
   342             }
   346         }
   343         }
   347     EndTransactionL(err);
   344     EndTransactionL(err);
   348 
   345 
   349     return abstractAlbumId;  
   346     return abstractAlbumId;
   350     }
   347     }
   351 
   348 
   352 // ----------------------------------------------------------------------------
   349 // ----------------------------------------------------------------------------
   353 // Update all songs which associate with AbstractAlbum in the collection
   350 // Update abstractalbum info to AbstractAlbum table and all songs which associate 
   354 // ----------------------------------------------------------------------------
   351 // with AbstractAlbum in the collection
   355 //
   352 // ----------------------------------------------------------------------------
   356 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateAbstractAlbumSongsL(
   353 //
       
   354 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateAbstractAlbumL(
   357     const CMPXMedia& aMedia,
   355     const CMPXMedia& aMedia,
   358     CMPXMessageArray& aItemChangedMessages)
   356     CMPXMessageArray& aItemChangedMessages)
   359     {
   357     {
   360     MPX_FUNC("CMPXDbHandler::UpdateAbstractAlbumSongsL");
   358     MPX_FUNC("CMPXDbHandler::UpdateAbstractAlbumL");
   361 
   359 
   362     CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile);
   360     CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile);
   363 
   361     TUint32 itemId(0);
   364     if (aMedia.IsSupported(KMPXMediaGeneralUri))
   362     if (aMedia.IsSupported(KMPXMediaGeneralUri))
   365         {
   363         {
   366         const TDesC& art(aMedia.ValueText (KMPXMediaGeneralUri));
   364         const TDesC& uri(aMedia.ValueText (KMPXMediaGeneralUri));
   367     
       
   368         TBool existRecord(EFalse); 
       
   369         TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri));
   365         TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri));
   370         TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, art, (EMPXAbstractAlbum != EMPXGenre)));    
   366 
   371         //check if abstractAlbum in ABSTRACTALBUM table before update songs
   367         //get Id based on new uri
   372         existRecord = iDbAbstractAlbum->CategoryItemExistsL(drive, rowId);
   368         itemId = MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse);
   373          
   369         if (!itemId)
   374         //update songs associated with abstractalbum only when abstractalbum associated already
   370             {
   375         //in the AbstractAlbum table     
   371             User::Leave(KErrNotSupported);
   376         if (existRecord)
   372             }
   377             {         
   373 
   378             if (aMedia.IsSupported(KMPXMediaArrayContents))
   374         //if updating to new item, need do renaming for AbstractAlbum: delete old one and insert a new entry to AbstractAlbum table
       
   375         //if a new item, need update songs associated and renaming albstractalbum table
       
   376         if (aMedia.IsSupported(KMPXMediaGeneralId))
       
   377             {
       
   378             MPX_DEBUG1("CMPXDbHandler::UpdateAbstractAlbumL, rename case");
       
   379             
       
   380             BeginTransactionL();
       
   381             //get old id, for renaming
       
   382             TInt err(KErrNone);
       
   383             TUint32 oldId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2;
       
   384             if (oldId && (oldId != itemId) )  //pass the old UID for renaming, do not care if new itemId exist or not
   379                 {
   385                 {
   380 
   386                 //get old Uri based on old Id
   381                 CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
   387                 HBufC* oldUri = iDbAbstractAlbum->GetUriL(oldId);
   382                 User::LeaveIfNull(mediaArray);
   388                 CleanupStack::PushL(oldUri);
       
   389 
       
   390                 //add and update new item to AbstractAlbum table
       
   391                 //old existing item field values need to be saved and added when adding new item                        
       
   392                 MPX_TRAP(err, itemId = iDbAbstractAlbum->AddUpdatedItemL(oldId, uri ));
       
   393 
       
   394                 if (iOutOfDisk && (err == KErrNotFound))
       
   395                     {
       
   396                     err = KErrDiskFull;
       
   397                     }
       
   398 
       
   399                 MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, itemId, EMPXItemInserted,
       
   400                 EMPXAbstractAlbum, KDBPluginUid);
       
   401 
       
   402                 //find and update all songs associated with oldId
       
   403                 RArray<TMPXAttribute> songAttributes;
       
   404                 CleanupClosePushL(songAttributes);
       
   405                 songAttributes.AppendL(KMPXMediaGeneralId);
       
   406 
       
   407                 CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
   408                 CleanupStack::PushL(mediaArray);
       
   409 
       
   410                 //get all songs associated
       
   411                 MPX_TRAP(err, iDbMusic->GetAllSongsForAbstractAlbumL(oldId, songAttributes.Array(), *mediaArray));
       
   412                 if (err == KErrNotFound)
       
   413                     {
       
   414                     // Leave with KErrNotFound
       
   415                     MPX_DEBUG1("CMPXDbHandler::UpdateAbstractAlbumL, leave with not found");
       
   416                     User::Leave(KErrNotFound);
       
   417                     }
       
   418 
   383                 TInt count(mediaArray->Count());
   419                 TInt count(mediaArray->Count());
       
   420                 MPX_DEBUG2("CMPXDbHandler::UpdateAbstractAlbumL, [%d] songs associated", count);
       
   421                 //go through all songs for updating
   384                 for (TInt i = 0; i < count; i++)
   422                 for (TInt i = 0; i < count; i++)
   385                     {
   423                     {
   386                     CMPXMedia* element = mediaArray->AtL(i);
   424                     CMPXMedia* song = mediaArray->AtL(i);
   387                     element->SetTextValueL(KMPXMediaMusicAlbumArtFileName, art );
   425                     song->SetTextValueL(KMPXMediaMusicAlbumArtFileName, uri );
   388                     visibleChange = UpdateSongL(*element, aItemChangedMessages);
   426                     visibleChange = UpdateSongL(*song, aItemChangedMessages);
   389                     }
   427                     }
   390                }
   428                 CleanupStack::PopAndDestroy(mediaArray);
   391             else
   429                 CleanupStack::PopAndDestroy(&songAttributes);
   392                 {
   430 
   393                 iDbAbstractAlbum->UpdateItemL(rowId, aMedia, drive, &aItemChangedMessages);
   431                 //rename TN
       
   432                 iDbAbstractAlbum->HandleTNL(*oldUri, uri, 0);
       
   433                 CleanupStack::PopAndDestroy(oldUri);
   394                 }
   434                 }
   395           }
   435             EndTransactionL(err);
       
   436             }//renaming
       
   437 
       
   438         //check if abstractAlbum exist in ABSTRACTALBUM table before update it
       
   439         else if (iDbAbstractAlbum->CategoryItemExistsL(drive, itemId))
       
   440             {
       
   441             //support updating Name, AlbumArtist fields for AbstractAlbum table
       
   442             iDbAbstractAlbum->UpdateItemL(itemId, aMedia, drive, &aItemChangedMessages);
       
   443             }
   396         }
   444         }
   397     return visibleChange;
   445     return visibleChange;
   398 }
   446     }
       
   447 
       
   448 // ----------------------------------------------------------------------------
       
   449 // Update all songs which associate with AbstractAlbum to new AbstractAlbum info 
       
   450 // in the collection
       
   451 // ----------------------------------------------------------------------------
       
   452 //
       
   453 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateSongsAbstractAlbumInfoL(
       
   454     const CMPXMedia& aMedia,
       
   455     CMPXMessageArray& aItemChangedMessages)
       
   456     {
       
   457     MPX_FUNC("CMPXDbHandler::UpdateSongsAbstractAlbumInfoL");
       
   458     const TDesC& uri(aMedia.ValueText (KMPXMediaGeneralUri));
       
   459     //need to update songs information to music table
       
   460     CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   461     User::LeaveIfNull(mediaArray);
       
   462     TInt count(mediaArray->Count());
       
   463     CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile);
       
   464     for (TInt i = 0; i < count; i++)
       
   465         {
       
   466         CMPXMedia* mediaSong = mediaArray->AtL(i);
       
   467         mediaSong->SetTextValueL(KMPXMediaMusicAlbumArtFileName, uri );
       
   468         visibleChange = UpdateSongL(*mediaSong, aItemChangedMessages);
       
   469         }
       
   470     return visibleChange;
       
   471     }
   399 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   472 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   473 
   400 // ----------------------------------------------------------------------------
   474 // ----------------------------------------------------------------------------
   401 // Update a song in the collection
   475 // Update a song in the collection
   402 // ----------------------------------------------------------------------------
   476 // ----------------------------------------------------------------------------
   403 //
   477 //
   404 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateSongL(
   478 CMPXDbActiveTask::TChangeVisibility CMPXDbHandler::UpdateSongL(
   588 // Remove specified abstractalbum
   662 // Remove specified abstractalbum
   589 // ----------------------------------------------------------------------------
   663 // ----------------------------------------------------------------------------
   590 //
   664 //
   591 void CMPXDbHandler::RemoveAbstractAlbumL(
   665 void CMPXDbHandler::RemoveAbstractAlbumL(
   592     TUint32 aAbstractAlbumId,
   666     TUint32 aAbstractAlbumId,
   593     CDesCArray& aUriArray,
   667     CMPXMessageArray& aItemChangedMessages, TBool aFileDeleted)
   594     CMPXMessageArray& aItemChangedMessages)
       
   595     {
   668     {
   596     MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumL");
   669     MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumL");
   597 
   670     iDbAbstractAlbum->RemoveAbstractAlbumL(aAbstractAlbumId, aItemChangedMessages, aFileDeleted);
   598     BeginTransactionL();
       
   599     MPX_TRAPD(err, DoRemoveAbstractAlbumL(aAbstractAlbumId, aUriArray, aItemChangedMessages));
       
   600     EndTransactionL(err);
       
   601     }
       
   602 
       
   603 // ----------------------------------------------------------------------------
       
   604 // Remove specified abstractalbum
       
   605 // ----------------------------------------------------------------------------
       
   606 //
       
   607 void CMPXDbHandler::DoRemoveAbstractAlbumL(
       
   608     TUint32 aAbstractAlbumId,
       
   609     CDesCArray& aUriArray,
       
   610     CMPXMessageArray& aItemChangedMessages)
       
   611     {
       
   612     MPX_FUNC("CMPXDbHandler::DoRemoveAbstractAlbumL");
       
   613 
       
   614 
       
   615     HBufC* uri(iDbAbstractAlbum->DeleteAbstractAlbumL(aAbstractAlbumId));
       
   616     if (uri)
       
   617         {
       
   618         CleanupStack::PushL(uri);
       
   619         aUriArray.AppendL(*uri);
       
   620         CleanupStack::PopAndDestroy(uri);
       
   621         }
       
   622 
       
   623     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aAbstractAlbumId, EMPXItemDeleted,
       
   624         EMPXAbstractAlbum, KDBPluginUid);
       
   625 
       
   626    
       
   627     }
   671     }
   628 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   672 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   629 
   673 
   630 // ----------------------------------------------------------------------------
   674 // ----------------------------------------------------------------------------
   631 // Cleanup records marked as deleted. This is designated for MTP to clean up records marked as deleted
   675 // Cleanup records marked as deleted. This is designated for MTP to clean up records marked as deleted
   888 //
   932 //
   889 TUint32 CMPXDbHandler::GetAbstractAlbumIdMatchingUriL(
   933 TUint32 CMPXDbHandler::GetAbstractAlbumIdMatchingUriL(
   890     const TDesC& aUri)
   934     const TDesC& aUri)
   891     {
   935     {
   892     MPX_FUNC("CMPXDbHandler::GetAbstractAlbumIdMatchingUriL");
   936     MPX_FUNC("CMPXDbHandler::GetAbstractAlbumIdMatchingUriL");
   893     return MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, aUri, ETrue);
   937     return MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, aUri, EFalse);
   894     }
   938     }
   895 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   939 #endif // ABSTRACTAUDIOALBUM_INCLUDED
   896 
   940 
   897 // ----------------------------------------------------------------------------
   941 // ----------------------------------------------------------------------------
   898 // Get all artists
   942 // Get all artists
   928     CMPXMediaArray& aMediaArray)
   972     CMPXMediaArray& aMediaArray)
   929     {
   973     {
   930     MPX_FUNC("CMPXDbHandler::GetAlbumsMatchingArtistL");
   974     MPX_FUNC("CMPXDbHandler::GetAlbumsMatchingArtistL");
   931     RArray<TMPXAttribute> attributes;
   975     RArray<TMPXAttribute> attributes;
   932     CleanupClosePushL( attributes );
   976     CleanupClosePushL( attributes );
   933         
   977 
   934     TBool tryGetSongCount = EFalse;
   978     TBool tryGetSongCount = EFalse;
   935     TInt attrCount(aAttrs.Count());
   979     TInt attrCount(aAttrs.Count());
   936     TInt i = 0;
   980     TInt i = 0;
   937     for (i = 0; i < attrCount; i++)
   981     for (i = 0; i < attrCount; i++)
   938         {
   982         {
   946             attributes.Append(TMPXAttribute(KMPXMediaIdGeneral, attributeId & ~EMPXMediaGeneralCount));
   990             attributes.Append(TMPXAttribute(KMPXMediaIdGeneral, attributeId & ~EMPXMediaGeneralCount));
   947 
   991 
   948             tryGetSongCount = ETrue;
   992             tryGetSongCount = ETrue;
   949             break;
   993             break;
   950             }
   994             }
   951         
   995 
   952         attributes.Append(aAttrs[i]);
   996         attributes.Append(aAttrs[i]);
   953         }
   997         }
   954     
   998 
   955     for (TInt j = i+1; j < attrCount; j++)
   999     for (TInt j = i+1; j < attrCount; j++)
   956         {
  1000         {
   957         attributes.Append(aAttrs[j]);
  1001         attributes.Append(aAttrs[j]);
   958         }
  1002         }
   959     iDbAlbum->GetSubCategoryItemsL(EMPXArtist, aArtistId, attributes.Array(), aMediaArray);
  1003     iDbAlbum->GetSubCategoryItemsL(EMPXArtist, aArtistId, attributes.Array(), aMediaArray);
   960     CleanupStack::PopAndDestroy(&attributes);
  1004     CleanupStack::PopAndDestroy(&attributes);
   961     
  1005 
   962     TInt pPath(0);
  1006     TInt pPath(0);
   963     if (aMediaArray.Count())
  1007     if (aMediaArray.Count())
   964         {
  1008         {
   965         CMPXMedia* pMedia = aMediaArray[0];
  1009         CMPXMedia* pMedia = aMediaArray[0];
   966         if (pMedia->IsSupported(KMPXMediaGeneralValue))
  1010         if (pMedia->IsSupported(KMPXMediaGeneralValue))
   967             {
  1011             {
   968             pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue);
  1012             pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue);
   969             MPX_ASSERT(pPath);
  1013             MPX_ASSERT(pPath);
   970             }
  1014             }
   971         }
  1015         }
   972     
  1016 
   973     TInt albumCount(aMediaArray.Count());
  1017     TInt albumCount(aMediaArray.Count());
   974     if (albumCount)
  1018     if (albumCount)
   975         {
  1019         {
   976         if ( tryGetSongCount )
  1020         if ( tryGetSongCount )
   977             {
  1021             {
   978             TInt startIndex = pPath ? 1 : 0;
  1022             TInt startIndex = pPath ? 1 : 0;
   979             
  1023 
   980             for (TInt i = startIndex; i < albumCount; i++)
  1024             for (TInt i = startIndex; i < albumCount; i++)
   981                 {
  1025                 {
   982                 CMPXMedia* media = aMediaArray[i];
  1026                 CMPXMedia* media = aMediaArray[i];
   983                 TUint32 albumId((media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)));
  1027                 TUint32 albumId((media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)));
   984 
  1028 
   985 				TInt songCount = iDbAlbum->GetSongsCountInAlbumMatchingArtistL(aArtistId, albumId);
  1029                 TInt songCount = iDbAlbum->GetSongsCountInAlbumMatchingArtistL(aArtistId, albumId);
   986 
  1030 
   987                 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount );
  1031                 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount );
   988                 MPX_DEBUG2("    SongCount[%d]", songCount );
  1032                 MPX_DEBUG2("    SongCount[%d]", songCount );
   989                 }
  1033                 }
   990             }
  1034             }
  1485     iOutOfDisk = EFalse;
  1529     iOutOfDisk = EFalse;
  1486     // Re-open databases
  1530     // Re-open databases
  1487     // This is needed for the case where we were OOD before, but user
  1531     // This is needed for the case where we were OOD before, but user
  1488     // has cleared some space but now try to refresh
  1532     // has cleared some space but now try to refresh
  1489     MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives));
  1533     MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives));
  1490     iCollectionOpen = ETrue;
       
  1491     // Update (synchronize) music basic table if it's not
       
  1492     // in sync with music table
       
  1493     if(iSynchronizeBasicTable)
       
  1494         {
       
  1495         iDbMusic->RefreshEndL();
       
  1496         }
       
  1497     iSynchronizeBasicTable = ETrue;
       
  1498 
  1534 
  1499     if(err == KErrDiskFull)
  1535     if(err == KErrDiskFull)
  1500         {
  1536         {
  1501             iOutOfDisk = ETrue;
  1537             iOutOfDisk = ETrue;
  1502         }
  1538         }
  1508         if(err == KErrDiskFull)
  1544         if(err == KErrDiskFull)
  1509             {
  1545             {
  1510             iOutOfDisk = ETrue;
  1546             iOutOfDisk = ETrue;
  1511             }
  1547             }
  1512     }
  1548     }
  1513     
       
  1514 #ifdef __RAMDISK_PERF_ENABLE
  1549 #ifdef __RAMDISK_PERF_ENABLE
  1515     iDbManager->CopyDBsToRamL();
  1550 	iDbManager->CopyDBsToRamL();
  1516 #endif //__RAMDISK_PERF_ENABLE
  1551 #endif //__RAMDISK_PERF_ENABLE
  1517     iDbMusic->RefreshStartL();
       
  1518 
  1552 
  1519     BeginTransactionL();
  1553     BeginTransactionL();
  1520     iRefresh = ETrue;
  1554     iRefresh = ETrue;
  1521     }
  1555     }
  1522 
  1556 
  1535         // This also sets corrupt = 0
  1569         // This also sets corrupt = 0
  1536         TTime curTime;
  1570         TTime curTime;
  1537         curTime.HomeTime();
  1571         curTime.HomeTime();
  1538         SetLastRefreshedTimeL(curTime);
  1572         SetLastRefreshedTimeL(curTime);
  1539         }
  1573         }
  1540     iDbMusic->RefreshEndL();
  1574 
  1541     //Update of music basic table fails when the collection is not open
  1575 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1542     //Next time the collection is opened the music basic table must be updated
  1576     //for AbstractAlbum garbage collection
  1543     if (iCollectionOpen )
  1577     //can not leave
  1544         {
  1578     TRAP_IGNORE( AbstractAlbumCleanUpL() );
  1545         iSynchronizeBasicTable = EFalse;
  1579 #endif
  1546         }
  1580    
  1547 
       
  1548 #ifdef __RAMDISK_PERF_ENABLE
  1581 #ifdef __RAMDISK_PERF_ENABLE
  1549     iDbManager->CopyDBsFromRamL();
  1582     iDbManager->CopyDBsFromRamL();
  1550 #endif //__RAMDISK_PERF_ENABLE
  1583 #endif //__RAMDISK_PERF_ENABLE
  1551     }
  1584     }
  1552 
  1585 
  1583     {
  1616     {
  1584     MPX_DEBUG1("-->CMPXDbHandler::MtpEndL");
  1617     MPX_DEBUG1("-->CMPXDbHandler::MtpEndL");
  1585     iMtpInUse = EFalse;
  1618     iMtpInUse = EFalse;
  1586     iOpOnDbCount = 0;
  1619     iOpOnDbCount = 0;
  1587     iDbManager->CommitL();
  1620     iDbManager->CommitL();
       
  1621     TInt err = KErrNone;
       
  1622 
  1588 
  1623 
  1589 #ifdef __RAMDISK_PERF_ENABLE
  1624 #ifdef __RAMDISK_PERF_ENABLE
  1590     TRAPD(err, iDbManager->CopyDBsFromRamL());
  1625     TRAP(err, iDbManager->CopyDBsFromRamL());
  1591     if ( err != KErrNone )
  1626     if ( err != KErrNone )
  1592         {
  1627         {
  1593         MPX_DEBUG2("CMPXDbHandler::MtpEndL error=%d", err);
  1628         MPX_DEBUG2("CMPXDbHandler::MtpEndL error=%d", err);
  1594         }
  1629         }
  1595 #endif //__RAMDISK_PERF_ENABLE
  1630 #endif //__RAMDISK_PERF_ENABLE
  1596     
  1631 
       
  1632 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
  1633     TRAP(err, RemoveAbstractAlbumsWithNoSongL());
       
  1634     if ( err != KErrNone )
       
  1635         {
       
  1636         MPX_DEBUG2("CMPXDbHandler::MtpEndL error happened when cleanup albstractalbum with no songs association[%d]", err);
       
  1637         }
       
  1638 #endif
  1597     MPX_DEBUG1("<--CMPXDbHandler::MtpEndL");
  1639     MPX_DEBUG1("<--CMPXDbHandler::MtpEndL");
  1598     }
  1640     }
  1599 
  1641 
  1600 // ----------------------------------------------------------------------------
  1642 // ----------------------------------------------------------------------------
  1601 // Get all records count for music
  1643 // Get all records count for music
  1707             {
  1749             {
  1708             iOpOnDbCount = 0;
  1750             iOpOnDbCount = 0;
  1709             iDbManager->RollbackL();
  1751             iDbManager->RollbackL();
  1710             User::Leave(aError);
  1752             User::Leave(aError);
  1711             }
  1753             }
  1712         
  1754 
  1713         if(iOpOnDbCount >= KMaxOpInTransaction)
  1755         if(iOpOnDbCount >= KMaxOpInTransaction)
  1714             {
  1756             {
  1715             MPX_DEBUG2("CMPXDbHandler::EndTransactionL - %d>KMaxOpInTransaction Commiting",iOpOnDbCount);
  1757             MPX_DEBUG2("CMPXDbHandler::EndTransactionL - %d>KMaxOpInTransaction Commiting",iOpOnDbCount);
  1716             iOpOnDbCount = 0;
  1758             iOpOnDbCount = 0;
  1717             iDbManager->CommitL();
  1759             iDbManager->CommitL();
  1718             iDbManager->BeginL();
  1760             iDbManager->BeginL();
  1719             }        
  1761             }
  1720         }
  1762         }
  1721     else
  1763     else
  1722         {
  1764         {
  1723         if (aError)
  1765         if (aError)
  1724             {
  1766             {
  1725             MPX_DEBUG2("CMPXDbHandler::EndTransactionL - Rollback [%d]", aError);
  1767             MPX_DEBUG2("CMPXDbHandler::EndTransactionL - Rollback [%d]", aError);
  1726 
  1768 
  1727             iDbManager->RollbackL();
  1769             iDbManager->RollbackL();
  1728             
  1770 
  1729             // KSqlDbCorrupted indicates DB corrupted, need to recreate.
  1771             // KSqlDbCorrupted indicates DB corrupted, need to recreate.
  1730             if ( aError != KSqlDbCorrupted )
  1772             if ( aError != KSqlDbCorrupted )
  1731                 {
  1773                 {
  1732                 User::Leave(aError);
  1774                 User::Leave(aError);
  1733                 }
  1775                 }
  1773             }
  1815             }
  1774         }
  1816         }
  1775     }
  1817     }
  1776 
  1818 
  1777 // ----------------------------------------------------------------------------
  1819 // ----------------------------------------------------------------------------
  1778 // Notifies the handler that the collection was closed.
       
  1779 // ----------------------------------------------------------------------------
       
  1780 //
       
  1781 void CMPXDbHandler::CollectionClosed()
       
  1782     {
       
  1783     MPX_FUNC("CMPXDbHandler::CollectionClosed");
       
  1784 
       
  1785     iCollectionOpen = EFalse;
       
  1786     }
       
  1787 
       
  1788 // ----------------------------------------------------------------------------
       
  1789 //Notifies the handler that the collection was opened.
       
  1790 // ----------------------------------------------------------------------------
       
  1791 //
       
  1792 void CMPXDbHandler::CollectionOpenedL()
       
  1793     {
       
  1794     MPX_FUNC("CMPXDbHandler::CollectionOpened");
       
  1795 
       
  1796     iCollectionOpen = ETrue;
       
  1797     // Update (synchronize) music basic table if it's not
       
  1798     // in sync with music table
       
  1799     if(iSynchronizeBasicTable)
       
  1800         {
       
  1801         iDbMusic->RefreshEndL();
       
  1802         iSynchronizeBasicTable = EFalse;
       
  1803         }
       
  1804     }
       
  1805 
       
  1806 // ----------------------------------------------------------------------------
       
  1807 // Add song to collection
  1820 // Add song to collection
  1808 // ----------------------------------------------------------------------------
  1821 // ----------------------------------------------------------------------------
  1809 //
  1822 //
  1810 TUint32 CMPXDbHandler::DoAddSongL(
  1823 TUint32 CMPXDbHandler::DoAddSongL(
  1811     const CMPXMedia& aMedia,
  1824     const CMPXMedia& aMedia,
  1824                                       iRefresh?NULL:aMessageArray));
  1837                                       iRefresh?NULL:aMessageArray));
  1825 
  1838 
  1826     // update the playlist tables
  1839     // update the playlist tables
  1827     // make sure the song db flags are reset and not just updated
  1840     // make sure the song db flags are reset and not just updated
  1828     iDbPlaylist->UpdateSongL(aMedia, ETrue);
  1841     iDbPlaylist->UpdateSongL(aMedia, ETrue);
  1829     
  1842 
  1830     if(iMtpInUse)
  1843     if(iMtpInUse)
  1831         {
  1844         {
  1832         ++iOpOnDbCount;
  1845         ++iOpOnDbCount;
  1833         }
  1846         }
  1834 
  1847 
  2164     iDbMusic->DeleteSongL(aSongId, drive, deleteRecord);
  2177     iDbMusic->DeleteSongL(aSongId, drive, deleteRecord);
  2165 
  2178 
  2166     // add the item changed message
  2179     // add the item changed message
  2167     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2180     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2168         EMPXSong, KDBPluginUid);
  2181         EMPXSong, KDBPluginUid);
  2169         
  2182 
  2170 
  2183 
  2171     if(iMtpInUse)
  2184     if(iMtpInUse)
  2172         {
  2185         {
  2173         ++iOpOnDbCount;
  2186         ++iOpOnDbCount;
  2174         }
  2187         }
  2347 
  2360 
  2348     // Send a message on the song in the playlist that is deleted
  2361     // Send a message on the song in the playlist that is deleted
  2349     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2362     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2350         EMPXSong, KDBPluginUid);
  2363         EMPXSong, KDBPluginUid);
  2351     }
  2364     }
       
  2365     
       
  2366 #ifdef ABSTRACTAUDIOALBUM_INCLUDED  
       
  2367 // ----------------------------------------------------------------------------
       
  2368 // Remove abstractalbums which have no songs associated.
       
  2369 // ----------------------------------------------------------------------------
       
  2370 //
       
  2371 void CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL()
       
  2372     {
       
  2373     MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL");
       
  2374     
       
  2375     BeginTransactionL();
       
  2376     RArray<TUint32> iItemsIds;
       
  2377     CleanupClosePushL(iItemsIds);
       
  2378       //get all abstractalbum with no songs associated.
       
  2379     iDbAbstractAlbum->GetAllItemsWithNoSongL(iItemsIds);
       
  2380     TInt count = iItemsIds.Count();
       
  2381     TInt err = KErrNone;
       
  2382     if (count)
       
  2383         {
       
  2384         MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, abstractalbum count[%d] ", iItemsIds.Count());
       
  2385         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2386         CleanupStack::PushL(itemChangedMessages);
       
  2387 
       
  2388         //go through each one to delete
       
  2389         for (TInt i=0; i< count; i++)
       
  2390             {
       
  2391             TRAP(err, RemoveAbstractAlbumL(iItemsIds[i], *itemChangedMessages, EFalse));
       
  2392             if (err != KErrNone)
       
  2393                 {
       
  2394                 MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, error happens when delete abstractalbum, err ", err);
       
  2395                 }
       
  2396             }
       
  2397        CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2398        }
       
  2399     CleanupStack::PopAndDestroy(&iItemsIds);
       
  2400     EndTransactionL(err); 
       
  2401   }
       
  2402   
       
  2403 // ----------------------------------------------------------------------------
       
  2404 // Remove .alb entry from AbstractAlnum table, TN table if .alb files deleted 
       
  2405 // from file manager when refresh library
       
  2406 // ----------------------------------------------------------------------------
       
  2407 //
       
  2408 void CMPXDbHandler::AbstractAlbumCleanUpL()
       
  2409     {
       
  2410     MPX_FUNC("CMPXDbHandler::AbstractAlbumCleanUpL");
       
  2411     RArray<TMPXAttribute> attributes;
       
  2412     CleanupClosePushL(attributes);
       
  2413     attributes.AppendL(KMPXMediaGeneralUri);
       
  2414     CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
  2415     CleanupStack::PushL(mediaArray);
       
  2416     
       
  2417     iDbAbstractAlbum->GetAllCategoryItemsL(attributes.Array(), *mediaArray);
       
  2418 
       
  2419     TInt count(mediaArray->Count());
       
  2420     if (count)
       
  2421         {
       
  2422         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2423         CleanupStack::PushL(itemChangedMessages);
       
  2424         for (TInt i = 0; i < count; i++)
       
  2425             {
       
  2426             CMPXMedia* element = mediaArray->AtL(i);
       
  2427             const TDesC& uri = element->ValueText(KMPXMediaGeneralUri);                                 
       
  2428 
       
  2429             //check if the file exists in file system
       
  2430             if (!(BaflUtils::FileExists(iFs, uri)))
       
  2431                 {
       
  2432                 //generate abstractalbum UID with the Uri
       
  2433                 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse));
       
  2434                 RemoveAbstractAlbumL(abstractAlbumId, *itemChangedMessages, ETrue);             
       
  2435                 }
       
  2436             }
       
  2437             CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2438         }
       
  2439         CleanupStack::PopAndDestroy(mediaArray);       
       
  2440         CleanupStack::PopAndDestroy(&attributes);     
       
  2441     }
       
  2442 #endif //ABSTRACTAUDIOALBUM_INCLUDED
  2352 
  2443 
  2353 // ----------------------------------------------------------------------------
  2444 // ----------------------------------------------------------------------------
  2354 // CMPXDbHandler::DoCleanupDeletedRecordsL
  2445 // CMPXDbHandler::DoCleanupDeletedRecordsL
  2355 // ----------------------------------------------------------------------------
  2446 // ----------------------------------------------------------------------------
  2356 //
  2447 //
  2470         TUint32 abstractAlbumId = (cat == EMPXAbstractAlbum) ?
  2561         TUint32 abstractAlbumId = (cat == EMPXAbstractAlbum) ?
  2471             id : (containerId & KMCCategoryMask);
  2562             id : (containerId & KMCCategoryMask);
  2472         TInt attrCount(aAttrs.Count());
  2563         TInt attrCount(aAttrs.Count());
  2473         if ( attrCount > 1 || (attrCount == 1 && !(aAttrs[0] == KMPXMediaGeneralId)) )
  2564         if ( attrCount > 1 || (attrCount == 1 && !(aAttrs[0] == KMPXMediaGeneralId)) )
  2474             {
  2565             {
  2475             TInt abstractAlbumDrive(iDbAbstractAlbum->GetDriveIdL(abstractAlbumId));
  2566             MPX_TRAPD(err, iDbMusic->GetAllSongsForAbstractAlbumL( abstractAlbumId, aAttrs, aMediaArray));
  2476             MPX_TRAPD(err, iDbMusic->GetAllSongsForAbstractAlbumL(abstractAlbumDrive, abstractAlbumId, aAttrs, aMediaArray));
       
  2477         if (err == KErrNotFound)
  2567         if (err == KErrNotFound)
  2478             {
  2568             {
  2479             //
  2569             //
  2480             // Leave with KErrNotFound
  2570             // Leave with KErrNotFound
  2481             User::Leave(KErrNotFound);
  2571             User::Leave(KErrNotFound);
  3032     TMPXGeneralCategory aCategory,
  3122     TMPXGeneralCategory aCategory,
  3033     const TDesC& aName,
  3123     const TDesC& aName,
  3034     TInt aDriveId,
  3124     TInt aDriveId,
  3035     CMPXMessageArray* aItemChangedMessages,
  3125     CMPXMessageArray* aItemChangedMessages,
  3036     TBool& aItemExist
  3126     TBool& aItemExist
  3037 #ifdef ABSTRACTAUDIOALBUM_INCLUDED    
  3127 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  3038       ,const TDesC& aAlbumArtist,
  3128     ,const TDesC& aUri
  3039     const TDesC& aGenre
  3129     ,const TDesC& aAlbumArtist
  3040 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3130 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3041     )
  3131     )
  3042     {
  3132     {
  3043     MPX_FUNC("CMPXDbHandler::AddCategoryItemL()");
  3133     MPX_FUNC("CMPXDbHandler::AddCategoryItemL()");
  3044 
  3134 
  3045     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
  3135     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
  3046 
  3136 
  3047     TBool newRecord(EFalse);
  3137     TBool newRecord(EFalse);
  3048 #ifdef ABSTRACTAUDIOALBUM_INCLUDED    
  3138 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  3049     TUint32 id(0);   
  3139     TUint32 id(0);
  3050     //for AbstractAlbum, SetAbstractAlbum, associate songs with abstractalbum.
  3140     //for AbstractAlbum, SetAbstractAlbum, associate songs with abstractalbum.
  3051     //only called with newRecord as EFalse
  3141     //only called with newRecord as EFalse
  3052     //increment songCount if id exist in AbstractAlbum table, otherwise do nothing.
  3142     //increment songCount if id exist in AbstractAlbum table, otherwise do nothing.
       
  3143 
       
  3144     //only Genre, AbstractAlbum are not case sensitive
       
  3145     TBool caseSensitive = ETrue;
       
  3146     if ((aCategory == EMPXGenre) || (aCategory == EMPXAbstractAlbum))
       
  3147         caseSensitive = EFalse;
       
  3148 
  3053     if (aCategory == EMPXAbstractAlbum)
  3149     if (aCategory == EMPXAbstractAlbum)
  3054         {     
  3150         {
  3055         id = iDbAbstractAlbum->AddItemL( aName, aAlbumArtist, aGenre, aDriveId, newRecord, (aCategory != EMPXGenre));     
  3151         id =  iDbAbstractAlbum->AddItemL(aUri, aName, aAlbumArtist, aDriveId, newRecord, caseSensitive);
  3056         }    
  3152         }
  3057     else
  3153     else
  3058         {
  3154         {
  3059         id = DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre));
  3155         id = DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, caseSensitive);
  3060 #else 
  3156 #else
  3061     TUint32 id(DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre)));
  3157     TUint32 id(DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, (aCategory != EMPXGenre)));
  3062 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3158 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
  3159 
  3063     if (newRecord && aItemChangedMessages)
  3160     if (newRecord && aItemChangedMessages)
  3064         {
  3161         {
  3065         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted,
  3162         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted,
  3066             aCategory, KDBPluginUid);
  3163             aCategory, KDBPluginUid);
  3067         }
  3164         }
  3068     // when the added item's category is Genre or Composer,
  3165     // when the added item's category is Genre or Composer,
  3069     // and it is NOT a new record,
  3166     // and it is NOT a new record,
  3070     // we should send the item number changed message
  3167     // we should send the item number changed message
  3071     else if ( ( aCategory == EMPXGenre || aCategory == EMPXComposer ) &&
  3168     else if ( ( aCategory == EMPXGenre || aCategory == EMPXComposer ) &&
  3072     		!newRecord && aItemChangedMessages )
  3169             !newRecord && aItemChangedMessages )
  3073         {
  3170         {
  3074         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemModified,
  3171         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemModified,
  3075             aCategory, KDBPluginUid);
  3172             aCategory, KDBPluginUid);
  3076         }
  3173         }
  3077     aItemExist = !newRecord;
  3174     aItemExist = !newRecord;
  3078 #ifdef ABSTRACTAUDIOALBUM_INCLUDED      
  3175 #ifdef ABSTRACTAUDIOALBUM_INCLUDED      
  3079        }
  3176        }
  3080 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3177 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3081     MPX_PERF_END(CMPXDbHandler_AddCategoryItemL);
  3178     MPX_PERF_END(CMPXDbHandler_AddCategoryItemL);
  3082 
       
  3083     return id;
  3179     return id;
  3084     }
  3180     }
  3085 
  3181 
  3086 TUint32 CMPXDbHandler::AddCategoryItemL(
  3182 TUint32 CMPXDbHandler::AddCategoryItemL(
  3087         TMPXGeneralCategory aCategory,
  3183         TMPXGeneralCategory aCategory,
  3105         }
  3201         }
  3106     else
  3202     else
  3107         {
  3203         {
  3108         id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3204         id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3109         }
  3205         }
  3110         
  3206 
  3111     if (newRecord && aItemChangedMessages)
  3207     if (newRecord && aItemChangedMessages)
  3112         {
  3208         {
  3113         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted,
  3209         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, EMPXItemInserted,
  3114             aCategory, KDBPluginUid);
  3210             aCategory, KDBPluginUid);
  3115         }
  3211         }
  3123         }
  3219         }
  3124     aItemExist = !newRecord;
  3220     aItemExist = !newRecord;
  3125     MPX_PERF_END(CMPXDbHandler_AddCategoryItemL);
  3221     MPX_PERF_END(CMPXDbHandler_AddCategoryItemL);
  3126 
  3222 
  3127     return id;
  3223     return id;
  3128 	}
  3224     }
  3129 
  3225 
  3130 void CMPXDbHandler::UpdateCategoryItemL(
  3226 void CMPXDbHandler::UpdateCategoryItemL(
  3131 		TMPXGeneralCategory aCategory,
  3227         TMPXGeneralCategory aCategory,
  3132 		TUint32 aCategoryId,
  3228         TUint32 aCategoryId,
  3133 		const CMPXMedia& aMedia,
  3229         const CMPXMedia& aMedia,
  3134 		TInt aDrive, 
  3230         TInt aDrive,
  3135 		CMPXMessageArray* aItemChangedMessages)
  3231         CMPXMessageArray* aItemChangedMessages)
  3136 	{
  3232     {
  3137 	switch(aCategory)
  3233     switch(aCategory)
  3138 	    {
  3234         {
  3139 	    case EMPXAlbum:
  3235         case EMPXAlbum:
  3140             iDbAlbum->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
  3236             iDbAlbum->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
  3141 	        break;
  3237             break;
  3142 	        
  3238 
  3143 	    case EMPXArtist:
  3239         case EMPXArtist:
  3144 	        iDbArtist->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
  3240             iDbArtist->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
  3145 	        break;
  3241             break;
  3146 
  3242 
  3147 	    default:
  3243         default:
  3148             DbCategoryL(aCategory)->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
  3244             DbCategoryL(aCategory)->UpdateItemL(aCategoryId, aMedia, aDrive, aItemChangedMessages);
  3149 	        break;
  3245             break;
  3150 	    }
  3246         }
  3151 	}
  3247     }
  3152 // ----------------------------------------------------------------------------
  3248 // ----------------------------------------------------------------------------
  3153 // CMPXDbHandler::DeleteSongForCategoryL
  3249 // CMPXDbHandler::DeleteSongForCategoryL
  3154 // ----------------------------------------------------------------------------
  3250 // ----------------------------------------------------------------------------
  3155 //
  3251 //
  3156 void CMPXDbHandler::DeleteSongForCategoryL(
  3252 void CMPXDbHandler::DeleteSongForCategoryL(
  3248     CleanupStack::PopAndDestroy(mediaArray);
  3344     CleanupStack::PopAndDestroy(mediaArray);
  3249     CleanupStack::PopAndDestroy(&attributes);        
  3345     CleanupStack::PopAndDestroy(&attributes);        
  3250     }
  3346     }
  3251 
  3347 
  3252 TInt CMPXDbHandler::HandleGetAlbumsCountForArtistL(TUint32 aArtistId)
  3348 TInt CMPXDbHandler::HandleGetAlbumsCountForArtistL(TUint32 aArtistId)
  3253 	{
  3349     {
  3254 	return iDbAlbum->GetAlbumsCountForArtistL(aArtistId);
  3350     return iDbAlbum->GetAlbumsCountForArtistL(aArtistId);
  3255 	}
  3351     }
  3256 
  3352 
  3257 TBool CMPXDbHandler::HandleIsUnknownArtistL(TUint32 aArtistId)
  3353 TBool CMPXDbHandler::HandleIsUnknownArtistL(TUint32 aArtistId)
  3258     {
  3354     {
  3259     return iDbArtist->IsUnknownArtistL(aArtistId);
  3355     return iDbArtist->IsUnknownArtistL(aArtistId);
  3260     }
  3356     }
  3265     }
  3361     }
  3266 #ifdef ABSTRACTAUDIOALBUM_INCLUDED   
  3362 #ifdef ABSTRACTAUDIOALBUM_INCLUDED   
  3267 // ----------------------------------------------------------------------------------------------------------
  3363 // ----------------------------------------------------------------------------------------------------------
  3268 // CMPXDbHandler::HandleGetAlbumNameForSongL
  3364 // CMPXDbHandler::HandleGetAlbumNameForSongL
  3269 // ----------------------------------------------------------------------------------------------------------
  3365 // ----------------------------------------------------------------------------------------------------------
  3270 // 
  3366 //
  3271 HBufC* CMPXDbHandler::HandleGetAlbumNameFromIdL(TUint32 aId)
  3367 HBufC* CMPXDbHandler::HandleGetAlbumNameFromIdL(TUint32 aId)
  3272     {
  3368     {
  3273     return iDbAbstractAlbum->GetNameL(aId);
  3369     return iDbAbstractAlbum->GetUriL(aId);
  3274     }
  3370     }
  3275 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3371 #endif // ABSTRACTAUDIOALBUM_INCLUDED
  3276 // End of file
  3372 // End of file