mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbalbum.cpp
branchRCL_3
changeset 40 cb96c29156b2
parent 26 70a8526f03f2
child 50 26a1709b9fec
equal deleted inserted replaced
31:a12246c97fcc 40:cb96c29156b2
   110 // CMPXDbAlbum::AddItemL
   110 // CMPXDbAlbum::AddItemL
   111 // ----------------------------------------------------------------------------
   111 // ----------------------------------------------------------------------------
   112 //
   112 //
   113 TUint32 CMPXDbAlbum::AddItemL(
   113 TUint32 CMPXDbAlbum::AddItemL(
   114     const TDesC& aName,
   114     const TDesC& aName,
   115     TUint32 aArtist,
   115     const TDesC& aArtistName,
   116     const TDesC& aArt,
   116     const TDesC& aArt,
   117     TInt aDriveId,
   117     TInt aDriveId,
   118     TBool& aNewRecord,
   118     TBool& aNewRecord,
   119     TBool aCaseSensitive)
   119     TBool aCaseSensitive)
   120     {
   120     {
   128     if (aNewRecord)
   128     if (aNewRecord)
   129         {
   129         {
   130         // insert new
   130         // insert new
   131         HBufC* query = PreProcessStringLC(KQueryAlbumInsert);
   131         HBufC* query = PreProcessStringLC(KQueryAlbumInsert);
   132         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
   132         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
       
   133         HBufC* artistname = MPXDbCommonUtil::ProcessSingleQuotesLC(aArtistName);
   133 		HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt);
   134 		HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt);
   134 
   135 
   135         iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1, aArtist, art);
   136         iDbManager.ExecuteQueryL(aDriveId, *query, rowId, artistname, name, 1, art); 
   136 
   137 
   137 		CleanupStack::PopAndDestroy(art);
   138 		CleanupStack::PopAndDestroy(art);
       
   139         CleanupStack::PopAndDestroy(artistname);
   138         CleanupStack::PopAndDestroy(name);
   140         CleanupStack::PopAndDestroy(name);
   139         CleanupStack::PopAndDestroy(query);
   141         CleanupStack::PopAndDestroy(query);
   140         }
   142         }
   141     else
   143     else
   142         {
   144         {
   152             {
   154             {
   153             User::Leave(KErrNotFound);
   155             User::Leave(KErrNotFound);
   154 	    }
   156 	    }
   155 
   157 
   156         // Artist
   158         // Artist
   157         TUint32 artistId = recordset.ColumnInt64(EAlbumArtist);
   159         TPtrC artistname(KNullDesC);
       
   160         artistname.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName));
       
   161 
   158 
   162 
   159         // the current one is Unknown and the new one is Not Unknown.
   163         // the current one is Unknown and the new one is Not Unknown.
   160         if ( IsUnknownArtistL( artistId ) && !IsUnknownArtistL( aArtist ) )
   164          if ( artistname == KNullDesC  && aArtistName!= KNullDesC )
   161             {
   165             {
   162             _LIT( KFormatArtistId, "Artist=%d" );
   166             HBufC* artistnameReplaceSingleQuote = 
   163             HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen);
   167                             MPXDbCommonUtil::ProcessSingleQuotesLC( aArtistName );
   164             setStr->Des().Format( KFormatArtistId, aArtist );
   168             TPtrC criteria(KCriterionArtistName);
   165 
   169             HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); 
       
   170             setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote );
       
   171            
   166             iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId);
   172             iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId);
   167             CleanupStack::PopAndDestroy(setStr);
   173             CleanupStack::PopAndDestroy(setStr);
       
   174             CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote);
       
   175 
   168             }
   176             }
   169 
   177 
   170         // Album Art
   178         // Album Art
   171         TPtrC art(KNullDesC);
   179         TPtrC art(KNullDesC);
   172         art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt));
   180         art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt));
   174         // the current one is Unknown and the new one is Not Unknown
   182         // the current one is Unknown and the new one is Not Unknown
   175         if ( art == KNullDesC && aArt != KNullDesC )
   183         if ( art == KNullDesC && aArt != KNullDesC )
   176             {
   184             {
   177             HBufC* artReplaceSingleQuote = 
   185             HBufC* artReplaceSingleQuote = 
   178                             MPXDbCommonUtil::ProcessSingleQuotesLC( aArt );
   186                             MPXDbCommonUtil::ProcessSingleQuotesLC( aArt );
   179             _LIT( KFormatArt, "Art=\'%S\'" );
   187 
   180             HBufC* setStr = HBufC::NewLC(256);
   188             TPtrC criteria(KCriterionArt);
   181             setStr->Des().Format( KFormatArt, artReplaceSingleQuote );
   189             HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); 
       
   190             setStr->Des().Format( KCriterionArt, artReplaceSingleQuote );
   182 
   191 
   183             iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId);
   192             iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId);
   184             CleanupStack::PopAndDestroy(setStr);
   193             CleanupStack::PopAndDestroy(setStr);
   185             CleanupStack::PopAndDestroy(artReplaceSingleQuote);
   194             CleanupStack::PopAndDestroy(artReplaceSingleQuote);
   186             }
   195             }
   238         if (recordset.Next() != KSqlAtRow)
   247         if (recordset.Next() != KSqlAtRow)
   239             {
   248             {
   240             User::Leave(KErrNotFound);
   249             User::Leave(KErrNotFound);
   241         }
   250         }
   242 
   251 
   243         TUint32 artistId = recordset.ColumnInt64(EAlbumArtist);
       
   244         TBool itemModified = EFalse;
   252         TBool itemModified = EFalse;
       
   253         TPtrC artistname(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName));
       
   254         TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist,
       
   255 	            artistname, ETrue);
   245 
   256 
   246         // the current artist is equal to deleted song's artist
   257         // the current artist is equal to deleted song's artist
   247         if ( artistId == aArtist )
   258         if ( artistId == aArtist )
   248             {
   259             {
   249             TUint32 newArtistId = ArtistForAlbumL(aId);
   260             HBufC* newArtistname = ArtistForAlbumL(aId);
   250             if ( artistId != newArtistId )
   261             
   251                 {
   262             CleanupStack::PushL(newArtistname);
   252                 _LIT( KFormatArtistId, "Artist=%d" );
   263             if (newArtistname && newArtistname->CompareF(artistname)!=0)
   253                 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen);
   264                 { 
   254                 setStr->Des().Format(KFormatArtistId, newArtistId);
   265                 HBufC* artistnameReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArtistname );
       
   266                 TPtrC criteria(KCriterionArtistName);
       
   267                 HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); 
       
   268                 setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote );                    	
   255 
   269 
   256                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
   270                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
   257                 CleanupStack::PopAndDestroy(setStr);
   271                 CleanupStack::PopAndDestroy(setStr);
       
   272                 CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote);
   258                 itemModified = ETrue;
   273                 itemModified = ETrue;
   259                 }
   274                 }
   260             }
   275             CleanupStack::PopAndDestroy(newArtistname);             
       
   276             }         
   261         
   277         
   262 #ifdef ABSTRACTAUDIOALBUM_INCLUDED      
   278 #ifdef ABSTRACTAUDIOALBUM_INCLUDED      
   263     TBool nonEmbeddedArt = EFalse;
   279     TBool nonEmbeddedArt = EFalse;
   264     if (aArt.Length()>0)
   280     if (aArt.Length()>0)
   265         {
   281         {
   288             //update Album table only if alternative albumart found
   304             //update Album table only if alternative albumart found
   289             if (newArt)
   305             if (newArt)
   290                 {
   306                 {
   291                 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt");
   307                 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt");
   292                 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt );
   308                 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt );
   293                 _LIT( KFormatArt, "Art=\'%S\'" );
   309                 TPtrC criteria(KCriterionArt);   
   294                 HBufC* setStr = HBufC::NewLC(256);                 
   310                 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); 
   295                 setStr->Des().Format( KFormatArt, artReplaceSingleQuote );
   311                 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote );
   296 
   312 
   297                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
   313                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
   298                 CleanupStack::PopAndDestroy(setStr);
   314                 CleanupStack::PopAndDestroy(setStr);
   299                 CleanupStack::PopAndDestroy(artReplaceSingleQuote);
   315                 CleanupStack::PopAndDestroy(artReplaceSingleQuote);
   300                 itemModified = ETrue;                     
   316                 itemModified = ETrue;                     
   533 		}
   549 		}
   534 
   550 
   535 	if (aMedia.IsSupported(KMPXMediaMusicArtist))
   551 	if (aMedia.IsSupported(KMPXMediaMusicArtist))
   536 	    {
   552 	    {
   537 	    const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen);
   553 	    const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen);
   538 	    TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist,
   554 	    MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCAlbumArtistName, artistName);
   539 	            artistName, ETrue);
       
   540 	    MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, artistId);
       
   541 	    }
   555 	    }
   542 	}
   556 	}
   543 
   557 
   544 // ----------------------------------------------------------------------------
   558 // ----------------------------------------------------------------------------
   545 // CMPXDbAlbum::IsUnknownArtistL
   559 // CMPXDbAlbum::IsUnknownArtistL
   552 
   566 
   553 // ----------------------------------------------------------------------------
   567 // ----------------------------------------------------------------------------
   554 // CMPXDbAlbum::ArtistForAlbumL
   568 // CMPXDbAlbum::ArtistForAlbumL
   555 // ----------------------------------------------------------------------------
   569 // ----------------------------------------------------------------------------
   556 //
   570 //
   557 TUint32 CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId)
   571 HBufC* CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId)
   558     {
   572     {
   559     return iObserver.HandleArtistForAlbumL(aId);
   573     return iObserver.HandleArtistForAlbumL(aId);
   560     }
   574     }
   561 
   575 
   562 // ----------------------------------------------------------------------------
   576 // ----------------------------------------------------------------------------