mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbartist.cpp
changeset 25 3ec52facab4d
parent 22 ecf06a08d4d9
child 51 560ce2306a17
equal deleted inserted replaced
22:ecf06a08d4d9 25:3ec52facab4d
    84 //
    84 //
    85 CMPXDbArtist::CMPXDbArtist(
    85 CMPXDbArtist::CMPXDbArtist(
    86     CMPXDbManager& aDbManager,
    86     CMPXDbManager& aDbManager,
    87     TMPXGeneralCategory aCategory,
    87     TMPXGeneralCategory aCategory,
    88     MMPXDbArtistObserver& aObserver) :
    88     MMPXDbArtistObserver& aObserver) :
    89     CMPXDbCategory(aDbManager, aCategory), 
    89     CMPXDbCategory(aDbManager, aCategory),
    90     iObserver(aObserver)
    90     iObserver(aObserver)
    91     {
    91     {
    92     MPX_FUNC("CMPXDbArtist::CMPXDbArtist");
    92     MPX_FUNC("CMPXDbArtist::CMPXDbArtist");
    93     }
    93     }
    94 
    94 
   120     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory,
   120     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory,
   121         aName, aCaseSensitive));
   121         aName, aCaseSensitive));
   122     aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
   122     aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
   123 
   123 
   124     if (aNewRecord)
   124     if (aNewRecord)
   125         {      
   125         {
   126         // insert new
   126         // insert new
   127         HBufC* query = PreProcessStringLC(KQueryArtistInsert);
   127         HBufC* query = PreProcessStringLC(KQueryArtistInsert);
   128         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
   128         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
   129         HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt);
   129         HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt);
   130 
   130 
   139         // retrieve the existing record
   139         // retrieve the existing record
   140         HBufC* query = NULL;
   140         HBufC* query = NULL;
   141         query = PreProcessStringLC(KQueryCategoryItem);
   141         query = PreProcessStringLC(KQueryCategoryItem);
   142         RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId));
   142         RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId));
   143         CleanupStack::PopAndDestroy(query);
   143         CleanupStack::PopAndDestroy(query);
   144         
   144 
   145         CleanupClosePushL(recordset);
   145         CleanupClosePushL(recordset);
   146         
   146 
   147         if (recordset.Next() != KSqlAtRow)
   147         if (recordset.Next() != KSqlAtRow)
   148             {
   148             {
   149             User::Leave(KErrNotFound);
   149             User::Leave(KErrNotFound);
   150         }
   150         }
   151             
   151 
   152         // Album Art
   152         // Album Art
   153         TPtrC art(KNullDesC);
   153         TPtrC art(KNullDesC);
   154         art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt));
   154         art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt));
   155     
   155 
   156         // the current one is Unknown and the new one is Not Unknown
   156         // the current one is Unknown and the new one is Not Unknown
   157         if ( art == KNullDesC && aArt != KNullDesC )
   157         if ( art == KNullDesC && aArt != KNullDesC )
   158             {
   158             {
   159             HBufC* artReplaceSingleQuote = 
   159             HBufC* artReplaceSingleQuote = 
   160                 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt );
   160                 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt );
   164 
   164 
   165             iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId);
   165             iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId);
   166             CleanupStack::PopAndDestroy(setStr);
   166             CleanupStack::PopAndDestroy(setStr);
   167             CleanupStack::PopAndDestroy(artReplaceSingleQuote);
   167             CleanupStack::PopAndDestroy(artReplaceSingleQuote);
   168             }
   168             }
   169         
   169 
   170         CleanupStack::PopAndDestroy(&recordset);
   170         CleanupStack::PopAndDestroy(&recordset);
   171         
   171 
   172         // increment the number of songs for the category
   172         // increment the number of songs for the category
   173         query = PreProcessStringLC(KQueryCategoryIncrementSongCount);
   173         query = PreProcessStringLC(KQueryCategoryIncrementSongCount);
   174         iDbManager.ExecuteQueryL(aDriveId, *query, rowId);
   174         iDbManager.ExecuteQueryL(aDriveId, *query, rowId);
   175         CleanupStack::PopAndDestroy(query);
   175         CleanupStack::PopAndDestroy(query);
   176         }
   176         }
   183 // ----------------------------------------------------------------------------
   183 // ----------------------------------------------------------------------------
   184 //
   184 //
   185 TBool CMPXDbArtist::IsUnknownArtistL(TUint32 aId)
   185 TBool CMPXDbArtist::IsUnknownArtistL(TUint32 aId)
   186     {
   186     {
   187 	MPX_FUNC("CMPXDbArtist::IsUnknownArtistL");
   187 	MPX_FUNC("CMPXDbArtist::IsUnknownArtistL");
   188 	
   188 
   189     HBufC* name = GetNameL(aId);
   189     HBufC* name = GetNameL(aId);
   190 	
   190 
   191 	TInt ret = EFalse;
   191 	TInt ret = EFalse;
   192 	if (*name == KNullDesC)
   192 	if (*name == KNullDesC)
   193 		{
   193 		{
   194 		ret = ETrue;
   194 		ret = ETrue;
   195 		}
   195 		}
   196 	delete name;
   196 	delete name;
   197 	
   197 
   198 	return ret;
   198 	return ret;
   199     }
   199     }
   200 
   200 
   201 // ----------------------------------------------------------------------------
   201 // ----------------------------------------------------------------------------
   202 // CMPXDbArtist::UpdateMediaL
   202 // CMPXDbArtist::UpdateMediaL
   218         if (contentId == KMPXMediaIdGeneral)
   218         if (contentId == KMPXMediaIdGeneral)
   219             {
   219             {
   220             if (attributeId & EMPXMediaGeneralId)
   220             if (attributeId & EMPXMediaGeneralId)
   221                 {
   221                 {
   222                 MPX_DEBUG1("	EMPXMediaGeneralId");
   222                 MPX_DEBUG1("	EMPXMediaGeneralId");
   223 				
   223 
   224                 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,
   224                 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,
   225                     aRecord.ColumnInt64(EArtistUniqueId));
   225                     aRecord.ColumnInt64(EArtistUniqueId));
   226 				MPX_DEBUG2("	Id[%d]", aRecord.ColumnInt64(EArtistUniqueId));
   226 				MPX_DEBUG2("	Id[%d]", aRecord.ColumnInt64(EArtistUniqueId));
   227                 }
   227                 }
   228             if (attributeId & EMPXMediaGeneralTitle)
   228             if (attributeId & EMPXMediaGeneralTitle)
   229                 {
   229                 {
   230                 MPX_DEBUG1("	EMPXMediaGeneralTitle");
   230                 MPX_DEBUG1("	EMPXMediaGeneralTitle");
   231 				
   231 
   232                 TPtrC artist( MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistName) );
   232                 TPtrC artist( MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistName) );
   233                 aMedia.SetTextValueL(KMPXMediaGeneralTitle,
   233                 aMedia.SetTextValueL(KMPXMediaGeneralTitle,
   234                     MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistName));
   234                     MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistName));
   235 
   235 
   236 				MPX_DEBUG2("	Artist[%S]", &artist);
   236 				MPX_DEBUG2("	Artist[%S]", &artist);
   243 //				MPX_DEBUG2("	AlbumCount[%d]", albumCount);
   243 //				MPX_DEBUG2("	AlbumCount[%d]", albumCount);
   244                 // get songs count from all drives
   244                 // get songs count from all drives
   245                 TInt songCount = GetSongsCountL( KDbManagerAllDrives,
   245                 TInt songCount = GetSongsCountL( KDbManagerAllDrives,
   246                                     aRecord.ColumnInt64( EArtistUniqueId ) );
   246                                     aRecord.ColumnInt64( EArtistUniqueId ) );
   247 				aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); // mod by anjokela
   247 				aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); // mod by anjokela
   248 				
   248 
   249                 MPX_DEBUG1("	EMPXMediaGeneralCount");
   249                 MPX_DEBUG1("	EMPXMediaGeneralCount");
   250 				MPX_DEBUG2("	SongCount[%d]", songCount);
   250 				MPX_DEBUG2("	SongCount[%d]", songCount);
   251                 }
   251                 }
   252             } // end if contentId == KMPXMediaIdGeneral
   252             } // end if contentId == KMPXMediaIdGeneral
   253         else if ( contentId == KMPXMediaIdMusic )
   253         else if ( contentId == KMPXMediaIdMusic )
   254             {
   254             {
   255             if (attributeId & EMPXMediaMusicAlbumArtFileName)
   255             if (attributeId & EMPXMediaMusicAlbumArtFileName)
   256                 {
   256                 {
   257                 MPX_DEBUG1("    EMPXMediaMusicAlbumArtFileName");
   257                 MPX_DEBUG1("    EMPXMediaMusicAlbumArtFileName");
   258                 TPtrC art(KNullDesC);                
   258                 TPtrC art(KNullDesC);
   259                 art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistArt));
   259                 art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistArt));
   260                 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art);
   260                 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art);
   261                 MPX_DEBUG2("    Art[%S]", &art);
   261                 MPX_DEBUG2("    Art[%S]", &art);
   262                 }
   262                 }
   263             }
   263             }
   277         {
   277         {
   278         const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen);
   278         const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen);
   279         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename);
   279         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename);
   280         }
   280         }
   281     }
   281     }
   282 	
   282 
   283 // ----------------------------------------------------------------------------
   283 // ----------------------------------------------------------------------------
   284 // CMPXDbArtist::GetAlbumsCountL
   284 // CMPXDbArtist::GetAlbumsCountL
   285 // ----------------------------------------------------------------------------
   285 // ----------------------------------------------------------------------------
   286 //
   286 //
   287 TInt CMPXDbArtist::GetAlbumsCountL(TUint32 aId)
   287 TInt CMPXDbArtist::GetAlbumsCountL(TUint32 aId)
   288     {
   288     {
   289     MPX_FUNC("CMPXDbArtist::GetAlbumsCountL");
   289     MPX_FUNC("CMPXDbArtist::GetAlbumsCountL");
   290 	
   290 
   291 	return iObserver.HandleGetAlbumsCountForArtistL(aId);
   291 	return iObserver.HandleGetAlbumsCountForArtistL(aId);
   292     }
   292     }
   293 	
   293 
   294 // ----------------------------------------------------------------------------
   294 // ----------------------------------------------------------------------------
   295 // CMPXDbArtist::GetAllCategoryItemsL
   295 // CMPXDbArtist::GetAllCategoryItemsL
   296 // ----------------------------------------------------------------------------
   296 // ----------------------------------------------------------------------------
   297 //	
   297 //
   298 void CMPXDbArtist::GetAllCategoryItemsL(
   298 void CMPXDbArtist::GetAllCategoryItemsL(
   299     const TArray<TMPXAttribute>& aAttrs,
   299     const TArray<TMPXAttribute>& aAttrs,
   300     CMPXMediaArray& aMediaArray)
   300     CMPXMediaArray& aMediaArray)
   301     {
   301     {
   302     MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL");
   302     MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL");
   311 // ----------------------------------------------------------------------------
   311 // ----------------------------------------------------------------------------
   312 // CMPXDbArtist::UpdateItemL
   312 // CMPXDbArtist::UpdateItemL
   313 // ----------------------------------------------------------------------------
   313 // ----------------------------------------------------------------------------
   314 //
   314 //
   315 void CMPXDbArtist::UpdateItemL(
   315 void CMPXDbArtist::UpdateItemL(
   316     TUint32 aId, 
   316     TUint32 aId,
   317     const CMPXMedia& aMedia, 
   317     const CMPXMedia& aMedia,
   318     TInt aDriveId, 
   318     TInt aDriveId,
   319     CMPXMessageArray* aItemChangedMessages)
   319     CMPXMessageArray* aItemChangedMessages)
   320     {
   320     {
   321     MPX_FUNC("CMPXDbAlbum::UpdateItemL");
   321     MPX_FUNC("CMPXDbAlbum::UpdateItemL");
   322 
   322 
   323     CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EArtistFieldCount);
   323     CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EArtistFieldCount);