mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbalbum.cpp
changeset 29 8192e5b5c935
parent 25 3ec52facab4d
child 38 b93f525c9244
equal deleted inserted replaced
25:3ec52facab4d 29:8192e5b5c935
    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);
   286     CleanupClosePushL(recordset);
   336     CleanupClosePushL(recordset);
   287     ProcessRecordsetL(aAttrs, recordset, aMediaArray);
   337     ProcessRecordsetL(aAttrs, recordset, aMediaArray);
   288     CleanupStack::PopAndDestroy(&recordset);
   338     CleanupStack::PopAndDestroy(&recordset);
   289     }
   339     }
   290 
   340 
       
   341 // ----------------------------------------------------------------------------
       
   342 // CMPXDbAlbum::GetAllCategoryItemsMediaWallL
       
   343 // ----------------------------------------------------------------------------
       
   344 //
       
   345 void CMPXDbAlbum::GetAllCategoryItemsMediaWallL(
       
   346     const TArray<TMPXAttribute>& aAttrs,
       
   347     CMPXMediaArray& aMediaArray)
       
   348     {
       
   349     MPX_FUNC("CMPXDbAlbum::GetAllCategoryItemsL");
       
   350 
       
   351     HBufC* query = PreProcessStringLC(KQueryAlbumAllMediaWall);
       
   352     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query));
       
   353     CleanupStack::PopAndDestroy(query);
       
   354 
       
   355     CleanupClosePushL(recordset);
       
   356     ProcessRecordsetL(aAttrs, recordset, aMediaArray);
       
   357     CleanupStack::PopAndDestroy(&recordset);
       
   358     }
   291 // ----------------------------------------------------------------------------
   359 // ----------------------------------------------------------------------------
   292 // CMPXDbAlbum::UpdateItemL
   360 // CMPXDbAlbum::UpdateItemL
   293 // ----------------------------------------------------------------------------
   361 // ----------------------------------------------------------------------------
   294 //
   362 //
   295 void CMPXDbAlbum::UpdateItemL(
   363 void CMPXDbAlbum::UpdateItemL(
   508     {
   576     {
   509     return iObserver.HandleArtistForAlbumL(aId);
   577     return iObserver.HandleArtistForAlbumL(aId);
   510     }
   578     }
   511 
   579 
   512 // ----------------------------------------------------------------------------
   580 // ----------------------------------------------------------------------------
       
   581 // CMPXDbAlbum::AlbumartForAlbumL
       
   582 // ----------------------------------------------------------------------------
       
   583 //
       
   584 HBufC* CMPXDbAlbum::AlbumartForAlbumL(const TUint32 aId, TPtrC aArt)
       
   585     {
       
   586     return iObserver.HandleAlbumartForAlbumL(aId, aArt);
       
   587     }
       
   588 
       
   589 // ----------------------------------------------------------------------------
   513 // CMPXDbAlbum::CreateTableL
   590 // CMPXDbAlbum::CreateTableL
   514 // ----------------------------------------------------------------------------
   591 // ----------------------------------------------------------------------------
   515 //
   592 //
   516 void CMPXDbAlbum::CreateTableL(
   593 void CMPXDbAlbum::CreateTableL(
   517     RSqlDatabase& aDatabase,
   594     RSqlDatabase& aDatabase,