mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbalbum.cpp
branchRCL_3
changeset 26 70a8526f03f2
parent 18 c54d95799c80
child 40 cb96c29156b2
equal deleted inserted replaced
21:a1247965635c 26:70a8526f03f2
    31 #include "mpxdbpluginqueries.h"
    31 #include "mpxdbpluginqueries.h"
    32 #include "mpxdbutil.h"
    32 #include "mpxdbutil.h"
    33 #include "mpxdbalbum.h"
    33 #include "mpxdbalbum.h"
    34 
    34 
    35 // CONSTANTS
    35 // CONSTANTS
       
    36 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
    37 _LIT( KAbstractAlbumExt, ".alb" );
       
    38 #endif // ABSTRACTAUDIOALBUM_INCLUDED
    36 
    39 
    37 // ============================ MEMBER FUNCTIONS ==============================
    40 // ============================ MEMBER FUNCTIONS ==============================
    38 
    41 
    39 // ----------------------------------------------------------------------------
    42 // ----------------------------------------------------------------------------
    40 // Two-phased constructor.
    43 // Two-phased constructor.
   200 void CMPXDbAlbum::DecrementSongsForCategoryL(
   203 void CMPXDbAlbum::DecrementSongsForCategoryL(
   201     const TUint32 aId,
   204     const TUint32 aId,
   202     TInt aDriveId,
   205     TInt aDriveId,
   203     CMPXMessageArray* aItemChangedMessages,
   206     CMPXMessageArray* aItemChangedMessages,
   204     TBool& aItemExist,
   207     TBool& aItemExist,
   205     const TUint32 aArtist)
   208     const TUint32 aArtist,
       
   209     const TDesC& aArt)
   206     {
   210     {
   207     MPX_FUNC("CMPXDbAlbum::DecrementSongsForCategoryL");
   211     MPX_FUNC("CMPXDbAlbum::DecrementSongsForCategoryL");
   208 
   212 
   209     // if just one song uses this category. Use <= just in case
   213     // if just one song uses this category. Use <= just in case
   210     if (GetSongsCountL(aDriveId, aId) <= 1)
   214     if (GetSongsCountL(aDriveId, aId) <= 1)
   235             {
   239             {
   236             User::Leave(KErrNotFound);
   240             User::Leave(KErrNotFound);
   237         }
   241         }
   238 
   242 
   239         TUint32 artistId = recordset.ColumnInt64(EAlbumArtist);
   243         TUint32 artistId = recordset.ColumnInt64(EAlbumArtist);
   240 
   244         TBool itemModified = EFalse;
   241         CleanupStack::PopAndDestroy(&recordset);
       
   242 
   245 
   243         // the current artist is equal to deleted song's artist
   246         // the current artist is equal to deleted song's artist
   244         if ( artistId == aArtist )
   247         if ( artistId == aArtist )
   245             {
   248             {
   246             TUint32 newArtistId = ArtistForAlbumL(aId);
   249             TUint32 newArtistId = ArtistForAlbumL(aId);
   250                 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen);
   253                 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen);
   251                 setStr->Des().Format(KFormatArtistId, newArtistId);
   254                 setStr->Des().Format(KFormatArtistId, newArtistId);
   252 
   255 
   253                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
   256                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
   254                 CleanupStack::PopAndDestroy(setStr);
   257                 CleanupStack::PopAndDestroy(setStr);
   255                 
   258                 itemModified = ETrue;
   256                 if (aItemChangedMessages)
       
   257                     {
       
   258                     // add the item changed message
       
   259                     MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified,
       
   260                         EMPXAlbum, KDBPluginUid, ETrue, 0 );  
       
   261                     }
       
   262                 }
   259                 }
   263             }
   260             }
       
   261         
       
   262 #ifdef ABSTRACTAUDIOALBUM_INCLUDED      
       
   263     TBool nonEmbeddedArt = EFalse;
       
   264     if (aArt.Length()>0)
       
   265         {
       
   266         TParsePtrC parse(aArt);
       
   267         TPtrC ext(parse.Ext());
       
   268         //set flag to false, so .alb will not overwrite art field in album, artist table 
       
   269         // when song with embedded art
       
   270         if (ext.CompareF(KAbstractAlbumExt)== 0) 
       
   271             {     
       
   272             nonEmbeddedArt = ETrue;        
       
   273             }
       
   274         }
       
   275   if (!nonEmbeddedArt)       
       
   276        {
       
   277 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   278        TPtrC art(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt));
       
   279         // the current art is equal to deleted song's art      
       
   280         if(aArt.Length()>0 && art.Length()>0 && aArt.CompareF(art) ==0 )
       
   281             {
       
   282             MPX_DEBUG2("AlbumArt of the Song to be deleted is [%S]", &aArt);
       
   283             
       
   284             //need to get alternative art in the same album to display
       
   285             HBufC* newArt = AlbumartForAlbumL(aId, aArt);
       
   286             CleanupStack::PushL(newArt);
       
   287 
       
   288             //update Album table only if alternative albumart found
       
   289             if (newArt)
       
   290                 {
       
   291                 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt");
       
   292                 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt );
       
   293                 _LIT( KFormatArt, "Art=\'%S\'" );
       
   294                 HBufC* setStr = HBufC::NewLC(256);                 
       
   295                 setStr->Des().Format( KFormatArt, artReplaceSingleQuote );
       
   296 
       
   297                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
       
   298                 CleanupStack::PopAndDestroy(setStr);
       
   299                 CleanupStack::PopAndDestroy(artReplaceSingleQuote);
       
   300                 itemModified = ETrue;                     
       
   301                 }
       
   302            CleanupStack::PopAndDestroy(newArt);             
       
   303            }
       
   304 #ifdef ABSTRACTAUDIOALBUM_INCLUDED            
       
   305          }
       
   306 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   307         if (aItemChangedMessages && itemModified)
       
   308            {
       
   309            // add the item changed message
       
   310            MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified,
       
   311                       EMPXAlbum, KDBPluginUid, ETrue, 0 );
       
   312            }
       
   313         CleanupStack::PopAndDestroy(&recordset);
   264         
   314         
   265         // decrement the number of songs for the category
   315         // decrement the number of songs for the category
   266         query = PreProcessStringLC(KQueryCategoryDecrementSongCount);
   316         query = PreProcessStringLC(KQueryCategoryDecrementSongCount);
   267         iDbManager.ExecuteQueryL(aDriveId, *query, aId);
   317         iDbManager.ExecuteQueryL(aDriveId, *query, aId);
   268         CleanupStack::PopAndDestroy(query);
   318         CleanupStack::PopAndDestroy(query);
   508     {
   558     {
   509     return iObserver.HandleArtistForAlbumL(aId);
   559     return iObserver.HandleArtistForAlbumL(aId);
   510     }
   560     }
   511 
   561 
   512 // ----------------------------------------------------------------------------
   562 // ----------------------------------------------------------------------------
       
   563 // CMPXDbAlbum::AlbumartForAlbumL
       
   564 // ----------------------------------------------------------------------------
       
   565 //
       
   566 HBufC* CMPXDbAlbum::AlbumartForAlbumL(const TUint32 aId, TPtrC aArt)
       
   567     {
       
   568     return iObserver.HandleAlbumartForAlbumL(aId, aArt);
       
   569     }
       
   570 
       
   571 // ----------------------------------------------------------------------------
   513 // CMPXDbAlbum::CreateTableL
   572 // CMPXDbAlbum::CreateTableL
   514 // ----------------------------------------------------------------------------
   573 // ----------------------------------------------------------------------------
   515 //
   574 //
   516 void CMPXDbAlbum::CreateTableL(
   575 void CMPXDbAlbum::CreateTableL(
   517     RSqlDatabase& aDatabase,
   576     RSqlDatabase& aDatabase,