114 TInt aDriveId, |
114 TInt aDriveId, |
115 TBool& aNewRecord, |
115 TBool& aNewRecord, |
116 TBool aCaseSensitive) |
116 TBool aCaseSensitive) |
117 { |
117 { |
118 MPX_FUNC("CMPXDbAlbum::AddItemL"); |
118 MPX_FUNC("CMPXDbAlbum::AddItemL"); |
119 |
119 |
120 // try to find the item first |
120 // try to find the item first |
121 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
121 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
122 aName, aCaseSensitive)); |
122 aName, aCaseSensitive)); |
123 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
123 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
124 |
124 |
125 if (aNewRecord) |
125 if (aNewRecord) |
126 { |
126 { |
127 // insert new |
127 // insert new |
128 HBufC* query = PreProcessStringLC(KQueryAlbumInsert); |
128 HBufC* query = PreProcessStringLC(KQueryAlbumInsert); |
129 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
129 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
130 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
130 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
131 |
131 |
140 // retrieve the existing record |
140 // retrieve the existing record |
141 HBufC* query = NULL; |
141 HBufC* query = NULL; |
142 query = PreProcessStringLC(KQueryCategoryItem); |
142 query = PreProcessStringLC(KQueryCategoryItem); |
143 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId)); |
143 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId)); |
144 CleanupStack::PopAndDestroy(query); |
144 CleanupStack::PopAndDestroy(query); |
145 |
145 |
146 CleanupClosePushL(recordset); |
146 CleanupClosePushL(recordset); |
147 |
147 |
148 if (recordset.Next() != KSqlAtRow) |
148 if (recordset.Next() != KSqlAtRow) |
149 { |
149 { |
150 User::Leave(KErrNotFound); |
150 User::Leave(KErrNotFound); |
151 } |
151 } |
152 |
152 |
153 // Artist |
153 // Artist |
154 TUint32 artistId = recordset.ColumnInt64(EAlbumArtist); |
154 TUint32 artistId = recordset.ColumnInt64(EAlbumArtist); |
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 ( IsUnknownArtistL( artistId ) && !IsUnknownArtistL( aArtist ) ) |
157 if ( IsUnknownArtistL( artistId ) && !IsUnknownArtistL( aArtist ) ) |
158 { |
158 { |
159 _LIT( KFormatArtistId, "Artist=%d" ); |
159 _LIT( KFormatArtistId, "Artist=%d" ); |
160 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen); |
160 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen); |
161 setStr->Des().Format( KFormatArtistId, aArtist ); |
161 setStr->Des().Format( KFormatArtistId, aArtist ); |
162 |
162 |
163 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
163 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
164 CleanupStack::PopAndDestroy(setStr); |
164 CleanupStack::PopAndDestroy(setStr); |
165 } |
165 } |
166 |
166 |
167 // Album Art |
167 // Album Art |
168 TPtrC art(KNullDesC); |
168 TPtrC art(KNullDesC); |
169 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
169 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
170 |
170 |
171 // the current one is Unknown and the new one is Not Unknown |
171 // the current one is Unknown and the new one is Not Unknown |
172 if ( art == KNullDesC && aArt != KNullDesC ) |
172 if ( art == KNullDesC && aArt != KNullDesC ) |
173 { |
173 { |
174 HBufC* artReplaceSingleQuote = |
174 HBufC* artReplaceSingleQuote = |
175 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
175 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
179 |
179 |
180 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
180 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
181 CleanupStack::PopAndDestroy(setStr); |
181 CleanupStack::PopAndDestroy(setStr); |
182 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
182 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
183 } |
183 } |
184 |
184 |
185 CleanupStack::PopAndDestroy(&recordset); |
185 CleanupStack::PopAndDestroy(&recordset); |
186 |
186 |
187 // increment the number of songs for the category |
187 // increment the number of songs for the category |
188 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
188 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
189 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
189 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
190 CleanupStack::PopAndDestroy(query); |
190 CleanupStack::PopAndDestroy(query); |
191 } |
191 } |
221 } |
221 } |
222 } |
222 } |
223 else |
223 else |
224 { |
224 { |
225 aItemExist = ETrue; |
225 aItemExist = ETrue; |
226 |
226 |
227 // retrieve the existing record |
227 // retrieve the existing record |
228 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
228 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
229 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aId)); |
229 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aId)); |
230 CleanupStack::PopAndDestroy(query); |
230 CleanupStack::PopAndDestroy(query); |
231 |
231 |
232 CleanupClosePushL(recordset); |
232 CleanupClosePushL(recordset); |
233 |
233 |
234 if (recordset.Next() != KSqlAtRow) |
234 if (recordset.Next() != KSqlAtRow) |
235 { |
235 { |
236 User::Leave(KErrNotFound); |
236 User::Leave(KErrNotFound); |
237 } |
237 } |
238 |
238 |
239 TUint32 artistId = recordset.ColumnInt64(EAlbumArtist); |
239 TUint32 artistId = recordset.ColumnInt64(EAlbumArtist); |
240 |
240 |
241 CleanupStack::PopAndDestroy(&recordset); |
241 CleanupStack::PopAndDestroy(&recordset); |
242 |
242 |
243 // the current artist is equal to deleted song's artist |
243 // the current artist is equal to deleted song's artist |
244 if ( artistId == aArtist ) |
244 if ( artistId == aArtist ) |
245 { |
245 { |
246 TUint32 newArtistId = ArtistForAlbumL(aId); |
246 TUint32 newArtistId = ArtistForAlbumL(aId); |
247 |
247 if ( artistId != newArtistId ) |
248 _LIT( KFormatArtistId, "Artist=%d" ); |
|
249 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen); |
|
250 setStr->Des().Format(KFormatArtistId, newArtistId); |
|
251 |
|
252 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
|
253 CleanupStack::PopAndDestroy(setStr); |
|
254 |
|
255 if (aItemChangedMessages) |
|
256 { |
248 { |
257 // add the item changed message |
249 _LIT( KFormatArtistId, "Artist=%d" ); |
258 MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
250 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen); |
259 EMPXAlbum, KDBPluginUid, ETrue, 0 ); |
251 setStr->Des().Format(KFormatArtistId, newArtistId); |
|
252 |
|
253 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
|
254 CleanupStack::PopAndDestroy(setStr); |
|
255 |
|
256 if (aItemChangedMessages) |
|
257 { |
|
258 // add the item changed message |
|
259 MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
|
260 EMPXAlbum, KDBPluginUid, ETrue, 0 ); |
|
261 } |
260 } |
262 } |
261 } |
263 } |
262 |
264 |
263 // decrement the number of songs for the category |
265 // decrement the number of songs for the category |
264 query = PreProcessStringLC(KQueryCategoryDecrementSongCount); |
266 query = PreProcessStringLC(KQueryCategoryDecrementSongCount); |
265 iDbManager.ExecuteQueryL(aDriveId, *query, aId); |
267 iDbManager.ExecuteQueryL(aDriveId, *query, aId); |
266 CleanupStack::PopAndDestroy(query); |
268 CleanupStack::PopAndDestroy(query); |
267 } |
269 } |
289 // ---------------------------------------------------------------------------- |
291 // ---------------------------------------------------------------------------- |
290 // CMPXDbAlbum::UpdateItemL |
292 // CMPXDbAlbum::UpdateItemL |
291 // ---------------------------------------------------------------------------- |
293 // ---------------------------------------------------------------------------- |
292 // |
294 // |
293 void CMPXDbAlbum::UpdateItemL( |
295 void CMPXDbAlbum::UpdateItemL( |
294 TUint32 aId, |
296 TUint32 aId, |
295 const CMPXMedia& aMedia, |
297 const CMPXMedia& aMedia, |
296 TInt aDriveId, |
298 TInt aDriveId, |
297 CMPXMessageArray* aItemChangedMessages) |
299 CMPXMessageArray* aItemChangedMessages) |
298 { |
300 { |
299 MPX_FUNC("CMPXDbAlbum::UpdateItemL"); |
301 MPX_FUNC("CMPXDbAlbum::UpdateItemL"); |
300 |
302 |
301 CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EAlbumFieldCount); |
303 CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EAlbumFieldCount); |
360 // ---------------------------------------------------------------------------- |
362 // ---------------------------------------------------------------------------- |
361 // |
363 // |
362 TInt CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL(TUint32 aArtistId, TUint32 aAlbumId) |
364 TInt CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL(TUint32 aArtistId, TUint32 aAlbumId) |
363 { |
365 { |
364 MPX_FUNC("CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL"); |
366 MPX_FUNC("CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL"); |
365 |
367 |
366 return ExecuteSumQueryL(KQuerySongsInArtistAlbum, aArtistId, aAlbumId); |
368 return ExecuteSumQueryL(KQuerySongsInArtistAlbum, aArtistId, aAlbumId); |
367 } |
369 } |
368 |
370 |
369 // ---------------------------------------------------------------------------- |
371 // ---------------------------------------------------------------------------- |
370 // CMPXDbAlbum::UpdateMediaL |
372 // CMPXDbAlbum::UpdateMediaL |
386 if (contentId == KMPXMediaIdGeneral) |
388 if (contentId == KMPXMediaIdGeneral) |
387 { |
389 { |
388 if (attributeId & EMPXMediaGeneralId) |
390 if (attributeId & EMPXMediaGeneralId) |
389 { |
391 { |
390 MPX_DEBUG1(" EMPXMediaGeneralId"); |
392 MPX_DEBUG1(" EMPXMediaGeneralId"); |
391 |
393 |
392 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, |
394 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, |
393 aRecord.ColumnInt64(EAlbumUniqueId)); |
395 aRecord.ColumnInt64(EAlbumUniqueId)); |
394 } |
396 } |
395 if (attributeId & EMPXMediaGeneralTitle) |
397 if (attributeId & EMPXMediaGeneralTitle) |
396 { |
398 { |
397 MPX_DEBUG1(" EMPXMediaGeneralTitle"); |
399 MPX_DEBUG1(" EMPXMediaGeneralTitle"); |
398 |
400 |
399 TPtrC album( MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) ); |
401 TPtrC album( MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) ); |
400 aMedia.SetTextValueL(KMPXMediaGeneralTitle, |
402 aMedia.SetTextValueL(KMPXMediaGeneralTitle, |
401 MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName)); |
403 MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName)); |
402 MPX_DEBUG2(" Album[%S]", &album ); |
404 MPX_DEBUG2(" Album[%S]", &album ); |
403 } |
405 } |
412 } |
414 } |
413 } // end if contentId == KMPXMediaIdGeneral |
415 } // end if contentId == KMPXMediaIdGeneral |
414 else if ( contentId == KMPXMediaIdMusic ) |
416 else if ( contentId == KMPXMediaIdMusic ) |
415 { |
417 { |
416 if (attributeId & EMPXMediaMusicArtist) |
418 if (attributeId & EMPXMediaMusicArtist) |
417 { |
419 { |
418 MPX_DEBUG1(" EMPXMediaMusicArtist"); |
420 MPX_DEBUG1(" EMPXMediaMusicArtist"); |
419 |
421 |
420 TPtrC artistName(KNullDesC); |
422 TPtrC artistName(KNullDesC); |
421 |
423 |
422 // if album is unknown, ignore arist name |
424 // if album is unknown, ignore arist name |
423 if (MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) != KNullDesC) |
425 if (MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) != KNullDesC) |
424 { |
426 { |
425 artistName.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumArtistName)); |
427 artistName.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumArtistName)); |
426 } |
428 } |
427 |
429 |
428 aMedia.SetTextValueL(KMPXMediaMusicArtist, artistName); |
430 aMedia.SetTextValueL(KMPXMediaMusicArtist, artistName); |
429 MPX_DEBUG2(" Artist[%S]", &artistName); |
431 MPX_DEBUG2(" Artist[%S]", &artistName); |
430 } |
432 } |
431 |
433 |
432 if (attributeId & EMPXMediaMusicAlbum) |
434 if (attributeId & EMPXMediaMusicAlbum) |
449 if (attributeId & EMPXMediaMusicAlbumArtFileName) |
451 if (attributeId & EMPXMediaMusicAlbumArtFileName) |
450 { |
452 { |
451 MPX_DEBUG1(" EMPXMediaMusicAlbumArtFileName"); |
453 MPX_DEBUG1(" EMPXMediaMusicAlbumArtFileName"); |
452 |
454 |
453 TPtrC art(KNullDesC); |
455 TPtrC art(KNullDesC); |
454 |
456 |
455 // if album is unknown, ignore album art name |
457 // if album is unknown, ignore album art name |
456 if (MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) != KNullDesC) |
458 if (MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) != KNullDesC) |
457 { |
459 { |
458 art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumArt)); |
460 art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumArt)); |
459 } |
461 } |
460 |
462 |
461 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art); |
463 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art); |
462 MPX_DEBUG2(" Art[%S]", &art); |
464 MPX_DEBUG2(" Art[%S]", &art); |
463 } |
465 } |
464 } |
466 } |
465 } // end for |
467 } // end for |
477 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
479 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
478 { |
480 { |
479 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
481 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
480 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
482 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
481 } |
483 } |
482 |
484 |
483 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
485 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
484 { |
486 { |
485 const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen); |
487 const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen); |
486 TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist, |
488 TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist, |
487 artistName, ETrue); |
489 artistName, ETrue); |
488 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, artistId); |
490 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, artistId); |
489 } |
491 } |
490 } |
492 } |
491 |
493 |
492 // ---------------------------------------------------------------------------- |
494 // ---------------------------------------------------------------------------- |
493 // CMPXDbAlbum::IsUnknownArtistL |
495 // CMPXDbAlbum::IsUnknownArtistL |