109 // ---------------------------------------------------------------------------- |
119 // ---------------------------------------------------------------------------- |
110 // CMPXDbAlbum::AddItemL |
120 // CMPXDbAlbum::AddItemL |
111 // ---------------------------------------------------------------------------- |
121 // ---------------------------------------------------------------------------- |
112 // |
122 // |
113 TUint32 CMPXDbAlbum::AddItemL( |
123 TUint32 CMPXDbAlbum::AddItemL( |
114 const TDesC& aName, |
124 TMPXGeneralCategory /*aCategory*/, |
115 const TDesC& aArtistName, |
125 const CMPXMedia& aMedia, |
116 const TDesC& aArt, |
|
117 TInt aDriveId, |
126 TInt aDriveId, |
118 TBool& aNewRecord, |
127 TBool& aNewRecord, |
119 TBool aCaseSensitive) |
128 TBool aCaseSensitive) |
120 { |
129 { |
121 MPX_FUNC("CMPXDbAlbum::AddItemL"); |
130 MPX_FUNC("CMPXDbAlbum::AddItemL"); |
122 |
131 |
|
132 TPtrC album(KNullDesC); |
|
133 TPtrC albumArtist(KNullDesC); |
|
134 TPtrC artist(KNullDesC); |
|
135 TPtrC albumArt(KNullDesC); |
|
136 |
123 // try to find the item first |
137 // try to find the item first |
124 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
138 TUint32 rowId(GenerateUniqueIdL(aMedia)); |
125 aName, aCaseSensitive)); |
139 |
126 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
140 // retrieve the existing record |
127 |
141 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
128 if (aNewRecord) |
142 RSqlStatement recordset( |
129 { |
143 iDbManager.ExecuteSelectQueryL(aDriveId, *query, rowId)); |
|
144 CleanupStack::PopAndDestroy(query); |
|
145 CleanupClosePushL(recordset); |
|
146 |
|
147 TInt result = recordset.Next(); |
|
148 if (result == KSqlAtEnd) |
|
149 { |
|
150 aNewRecord = result; |
|
151 |
|
152 // check Album attribute |
|
153 if (aMedia.IsSupported(KMPXMediaMusicAlbum)) |
|
154 { |
|
155 album.Set(aMedia.ValueText(KMPXMediaMusicAlbum).Left(KMCMaxTextLen)); |
|
156 } |
|
157 |
|
158 // check AlbumArt attirbute |
|
159 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
160 { |
|
161 albumArt.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
162 } |
|
163 |
130 // insert new |
164 // insert new |
131 HBufC* query = PreProcessStringLC(KQueryAlbumInsert); |
165 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(album); |
132 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
166 TUint32 artistId(0); |
133 HBufC* artistname = MPXDbCommonUtil::ProcessSingleQuotesLC(aArtistName); |
167 HBufC* artistName = NULL; |
134 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
168 if (RetrieveAlbumArtistL(aMedia, albumArtist)) |
135 |
169 { |
136 iDbManager.ExecuteQueryL(aDriveId, *query, rowId, artistname, name, 1, art); |
170 artistId = iObserver.AddAlbumArtistL(albumArtist, albumArt, aDriveId); |
137 |
171 artistName = MPXDbCommonUtil::ProcessSingleQuotesLC(albumArtist); |
138 CleanupStack::PopAndDestroy(art); |
172 } |
139 CleanupStack::PopAndDestroy(artistname); |
173 else |
|
174 { |
|
175 RetrieveArtist(aMedia, artist); |
|
176 artistId = iObserver.AddAlbumArtistL(artist, albumArt, aDriveId); |
|
177 artistName = MPXDbCommonUtil::ProcessSingleQuotesLC(artist); |
|
178 } |
|
179 |
|
180 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(albumArt); |
|
181 |
|
182 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumInsert, rowId, name, 1, artistId, artistName,art); |
|
183 |
|
184 CleanupStack::PopAndDestroy(art); |
|
185 CleanupStack::PopAndDestroy(artistName); |
140 CleanupStack::PopAndDestroy(name); |
186 CleanupStack::PopAndDestroy(name); |
141 CleanupStack::PopAndDestroy(query); |
187 } |
142 } |
188 else if (result == KSqlAtRow) |
143 else |
189 { |
144 { |
190 // retrieve Art from Album table |
145 // retrieve the existing record |
|
146 HBufC* query = NULL; |
|
147 query = PreProcessStringLC(KQueryCategoryItem); |
|
148 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId)); |
|
149 CleanupStack::PopAndDestroy(query); |
|
150 |
|
151 CleanupClosePushL(recordset); |
|
152 |
|
153 if (recordset.Next() != KSqlAtRow) |
|
154 { |
|
155 User::Leave(KErrNotFound); |
|
156 } |
|
157 |
|
158 // Artist |
|
159 TPtrC artistname(KNullDesC); |
|
160 artistname.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName)); |
|
161 |
|
162 |
|
163 // the current one is Unknown and the new one is Not Unknown. |
|
164 if ( artistname == KNullDesC && aArtistName!= KNullDesC ) |
|
165 { |
|
166 HBufC* artistnameReplaceSingleQuote = |
|
167 MPXDbCommonUtil::ProcessSingleQuotesLC( aArtistName ); |
|
168 TPtrC criteria(KCriterionArtistName); |
|
169 HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); |
|
170 setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote ); |
|
171 |
|
172 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
|
173 CleanupStack::PopAndDestroy(setStr); |
|
174 CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote); |
|
175 |
|
176 } |
|
177 |
|
178 // Album Art |
|
179 TPtrC art(KNullDesC); |
191 TPtrC art(KNullDesC); |
180 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
192 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
181 |
193 |
182 // the current one is Unknown and the new one is Not Unknown |
194 // the current one is Unknown and the new one is Not Unknown |
183 if ( art == KNullDesC && aArt != KNullDesC ) |
195 if ( art == KNullDesC && albumArt != KNullDesC ) |
184 { |
196 { |
185 HBufC* artReplaceSingleQuote = |
197 HBufC* artReplaceSingleQuote = |
186 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
198 MPXDbCommonUtil::ProcessSingleQuotesLC( albumArt ); |
187 |
199 |
188 TPtrC criteria(KCriterionArt); |
200 TPtrC criteria(KCriterionArt); |
189 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
201 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
190 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
202 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
191 |
203 |
192 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
204 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
193 CleanupStack::PopAndDestroy(setStr); |
205 CleanupStack::PopAndDestroy(setStr); |
194 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
206 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
195 } |
207 } |
196 |
|
197 CleanupStack::PopAndDestroy(&recordset); |
|
198 |
208 |
199 // increment the number of songs for the category |
209 // increment the number of songs for the category |
200 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
210 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
201 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
211 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
202 CleanupStack::PopAndDestroy(query); |
212 CleanupStack::PopAndDestroy(query); |
203 } |
213 } // existing record |
204 |
214 else |
|
215 { |
|
216 MPX_DEBUG2("SQL error %d", result); |
|
217 User::Leave(result); |
|
218 } |
|
219 |
|
220 CleanupStack::PopAndDestroy(&recordset); |
|
221 |
205 return rowId; |
222 return rowId; |
206 } |
223 } |
207 |
224 |
208 // ---------------------------------------------------------------------------- |
225 // ---------------------------------------------------------------------------- |
209 // CMPXDbAlbum::DecrementSongsForCategoryL |
226 // CMPXDbAlbum::DecrementSongsForAlbumL |
210 // ---------------------------------------------------------------------------- |
227 // ---------------------------------------------------------------------------- |
211 // |
228 // |
212 void CMPXDbAlbum::DecrementSongsForCategoryL( |
229 void CMPXDbAlbum::DecrementSongsForAlbumL( |
213 const TUint32 aId, |
230 const TUint32 aId, |
214 TInt aDriveId, |
231 TInt aDriveId, |
215 CMPXMessageArray* aItemChangedMessages, |
232 CMPXMessageArray* aItemChangedMessages, |
216 TBool& aItemExist, |
233 TBool& aItemExist, |
217 const TUint32 aArtist, |
234 const TDesC& aArt) |
218 const TDesC& aArt) |
235 { |
219 { |
236 MPX_FUNC("CMPXDbAlbum::DecrementSongsForAlbumL"); |
220 MPX_FUNC("CMPXDbAlbum::DecrementSongsForCategoryL"); |
237 |
|
238 // retrieve the existing record |
|
239 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
|
240 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aId)); |
|
241 CleanupStack::PopAndDestroy(query); |
|
242 |
|
243 CleanupClosePushL(recordset); |
|
244 |
|
245 if (recordset.Next() != KSqlAtRow) |
|
246 { |
|
247 User::Leave(KErrNotFound); |
|
248 } |
221 |
249 |
222 // if just one song uses this category. Use <= just in case |
250 // if just one song uses this category. Use <= just in case |
223 if (GetSongsCountL(aDriveId, aId) <= 1) |
251 if (recordset.ColumnInt64(EAlbumSongCount) <= 1) |
224 { |
252 { |
225 aItemExist = EFalse; |
253 aItemExist = EFalse; |
|
254 |
|
255 // Decrement albums count on artist |
|
256 TUint32 albumArtistId = recordset.ColumnInt64(EAlbumArtist); |
|
257 iObserver.DeleteAlbumForArtistL(albumArtistId, aDriveId, aItemChangedMessages); |
|
258 CleanupStack::PopAndDestroy(&recordset); |
|
259 |
226 // delete the category |
260 // delete the category |
227 DeleteCategoryL(aId, aDriveId); |
261 DeleteCategoryL(aId, aDriveId); |
228 |
262 |
229 if (aItemChangedMessages) |
263 if (aItemChangedMessages) |
230 { |
264 { |
235 } |
269 } |
236 else |
270 else |
237 { |
271 { |
238 aItemExist = ETrue; |
272 aItemExist = ETrue; |
239 |
273 |
240 // retrieve the existing record |
|
241 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
|
242 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aId)); |
|
243 CleanupStack::PopAndDestroy(query); |
|
244 |
|
245 CleanupClosePushL(recordset); |
|
246 |
|
247 if (recordset.Next() != KSqlAtRow) |
|
248 { |
|
249 User::Leave(KErrNotFound); |
|
250 } |
|
251 |
|
252 TBool itemModified = EFalse; |
274 TBool itemModified = EFalse; |
253 TPtrC artistname(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName)); |
275 |
254 TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist, |
276 TPtrC art(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
255 artistname, ETrue); |
277 if (NeedToUpdateArt(aArt, art)) |
256 |
|
257 // the current artist is equal to deleted song's artist |
|
258 if ( artistId == aArtist ) |
|
259 { |
|
260 HBufC* newArtistname = ArtistForAlbumL(aId); |
|
261 |
|
262 CleanupStack::PushL(newArtistname); |
|
263 if (newArtistname && newArtistname->CompareF(artistname)!=0) |
|
264 { |
|
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 ); |
|
269 |
|
270 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
|
271 CleanupStack::PopAndDestroy(setStr); |
|
272 CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote); |
|
273 itemModified = ETrue; |
|
274 } |
|
275 CleanupStack::PopAndDestroy(newArtistname); |
|
276 } |
|
277 |
|
278 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
279 TBool nonEmbeddedArt = EFalse; |
|
280 if (aArt.Length()>0) |
|
281 { |
|
282 TParsePtrC parse(aArt); |
|
283 TPtrC ext(parse.Ext()); |
|
284 //set flag to false, so .alb will not overwrite art field in album, artist table |
|
285 // when song with embedded art |
|
286 if (ext.CompareF(KAbstractAlbumExt)== 0) |
|
287 { |
|
288 nonEmbeddedArt = ETrue; |
|
289 } |
|
290 } |
|
291 if (!nonEmbeddedArt) |
|
292 { |
|
293 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
294 TPtrC art(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
|
295 // the current art is equal to deleted song's art |
|
296 if(aArt.Length()>0 && art.Length()>0 && aArt.CompareF(art) ==0 ) |
|
297 { |
278 { |
298 MPX_DEBUG2("AlbumArt of the Song to be deleted is [%S]", &aArt); |
279 MPX_DEBUG2("AlbumArt of the Song to be deleted is [%S]", &aArt); |
299 |
280 |
300 //need to get alternative art in the same album to display |
281 //need to get alternative art in the same album to display |
301 HBufC* newArt = AlbumartForAlbumL(aId, aArt); |
282 HBufC* newArt = AlbumartForAlbumL(aId, aArt); |
302 CleanupStack::PushL(newArt); |
283 CleanupStack::PushL(newArt); |
303 |
284 |
304 //update Album table only if alternative albumart found |
285 //update Album table only if alternative albumart found |
305 if (newArt) |
286 if (newArt) |
306 { |
287 { |
307 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt"); |
288 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForAlbumL, get newArt"); |
308 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt ); |
289 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt ); |
309 TPtrC criteria(KCriterionArt); |
290 TPtrC criteria(KCriterionArt); |
310 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
291 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
311 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
292 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
312 |
293 |
313 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
294 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
314 CleanupStack::PopAndDestroy(setStr); |
295 CleanupStack::PopAndDestroy(setStr); |
315 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
296 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
316 itemModified = ETrue; |
297 itemModified = ETrue; |
317 } |
298 } |
318 CleanupStack::PopAndDestroy(newArt); |
299 CleanupStack::PopAndDestroy(newArt); |
319 } |
300 } |
320 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
301 |
321 } |
|
322 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
323 if (aItemChangedMessages && itemModified) |
302 if (aItemChangedMessages && itemModified) |
324 { |
303 { |
325 // add the item changed message |
304 // add the item changed message |
326 MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
305 MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
327 EMPXAlbum, KDBPluginUid, ETrue, 0 ); |
306 EMPXAlbum, KDBPluginUid, ETrue, 0 ); |
328 } |
307 } |
329 CleanupStack::PopAndDestroy(&recordset); |
308 CleanupStack::PopAndDestroy(&recordset); |
330 |
309 |
331 // decrement the number of songs for the category |
310 // decrement the number of songs for the category |
332 query = PreProcessStringLC(KQueryCategoryDecrementSongCount); |
311 query = PreProcessStringLC(KQueryCategoryDecrementSongCount); |
333 iDbManager.ExecuteQueryL(aDriveId, *query, aId); |
312 iDbManager.ExecuteQueryL(aDriveId, *query, aId); |
544 { |
480 { |
545 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
481 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
546 { |
482 { |
547 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
483 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
548 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
484 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
549 } |
485 } |
550 |
|
551 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
552 { |
|
553 const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen); |
|
554 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCAlbumArtistName, artistName); |
|
555 } |
|
556 } |
486 } |
557 |
487 |
558 // ---------------------------------------------------------------------------- |
488 // ---------------------------------------------------------------------------- |
559 // CMPXDbAlbum::IsUnknownArtistL |
|
560 // ---------------------------------------------------------------------------- |
|
561 // |
|
562 TBool CMPXDbAlbum::IsUnknownArtistL(TUint32 aId) |
|
563 { |
|
564 return iObserver.HandleIsUnknownArtistL(aId); |
|
565 } |
|
566 |
|
567 // ---------------------------------------------------------------------------- |
|
568 // CMPXDbAlbum::ArtistForAlbumL |
|
569 // ---------------------------------------------------------------------------- |
|
570 // |
|
571 HBufC* CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId) |
|
572 { |
|
573 return iObserver.HandleArtistForAlbumL(aId); |
|
574 } |
|
575 |
|
576 // ---------------------------------------------------------------------------- |
|
577 // CMPXDbAlbum::AlbumartForAlbumL |
489 // CMPXDbAlbum::AlbumartForAlbumL |
578 // ---------------------------------------------------------------------------- |
490 // ---------------------------------------------------------------------------- |
579 // |
491 // |
580 HBufC* CMPXDbAlbum::AlbumartForAlbumL(const TUint32 aId, TPtrC aArt) |
492 HBufC* CMPXDbAlbum::AlbumartForAlbumL(const TUint32 aId, TPtrC aArt) |
581 { |
493 { |
582 return iObserver.HandleAlbumartForAlbumL(aId, aArt); |
494 return iObserver.HandleAlbumartForAlbumL(aId, aArt); |
583 } |
495 } |
584 |
496 |
585 // ---------------------------------------------------------------------------- |
497 // ---------------------------------------------------------------------------- |
586 // CMPXDbAlbum::CreateTableL |
|
587 // ---------------------------------------------------------------------------- |
|
588 // |
|
589 void CMPXDbAlbum::CreateTableL( |
|
590 RSqlDatabase& aDatabase, |
|
591 TBool /* aCorruptTable */) |
|
592 { |
|
593 MPX_FUNC("CMPXDbCategory::CreateTableL"); |
|
594 |
|
595 // create the table |
|
596 HBufC* query = PreProcessStringLC(KAlbumCreateTable); |
|
597 User::LeaveIfError(aDatabase.Exec(*query)); |
|
598 CleanupStack::PopAndDestroy(query); |
|
599 |
|
600 // do not create an index on the Name field |
|
601 // as it only slows down the insert/update queries overall |
|
602 } |
|
603 |
|
604 // ---------------------------------------------------------------------------- |
|
605 // CMPXDbAlbum::CheckTableL |
|
606 // ---------------------------------------------------------------------------- |
|
607 // |
|
608 TBool CMPXDbAlbum::CheckTableL( |
|
609 RSqlDatabase& aDatabase) |
|
610 { |
|
611 MPX_FUNC("CMPXDbCategory::CheckTableL"); |
|
612 |
|
613 HBufC* query = PreProcessStringLC(KAlbumCheckTable); |
|
614 TBool check(DoCheckTable(aDatabase, *query)); |
|
615 CleanupStack::PopAndDestroy(query); |
|
616 |
|
617 return check; |
|
618 } |
|
619 |
|
620 // ---------------------------------------------------------------------------- |
|
621 // CMPXDbAlbum::ProcessAlbumRecordSetL |
498 // CMPXDbAlbum::ProcessAlbumRecordSetL |
622 // Unknown album is stored in the database as NULL (name field). |
499 // Unknown album or Unknown artist are stored in the database as NULL (Name field and ArtistName field). |
623 // The first available unknown album is saved for later and will be appended to the array |
500 // The available unknown album is saved for later and will be appended to the array |
624 // as the last item and rest available unknown album will be ignored. |
501 // as the last item among items which have the same artist. |
|
502 // The available unknown artists are saved for later and will be appended to the array |
|
503 // as the last items after all known artists are appended. |
|
504 // The unknown album and unknown artist is saved for later and will be appended to the array |
|
505 // as the last item. |
625 // |
506 // |
626 // NOTE: putting unknown album to the end of the array only takes place when title |
507 // NOTE: putting unknown album to the end of the array only takes place when title |
627 // field is requested. normal sorting algorithm occurs if title isn't |
508 // field is requested. normal sorting algorithm occurs if title isn't |
628 // requested. |
509 // requested. |
|
510 // |
|
511 // Example: |
|
512 // Album X of artist A |
|
513 // Album Y of artist A |
|
514 // Unknown album of artist A |
|
515 // Album X of artist B |
|
516 // Album Z of artist B |
|
517 // Unknown album of artist B |
|
518 // Album X of unknown artist |
|
519 // Album Y of unknown artist |
|
520 // Unknown album of unknown artist |
629 // ---------------------------------------------------------------------------- |
521 // ---------------------------------------------------------------------------- |
630 // |
522 // |
631 void CMPXDbAlbum::ProcessAlbumRecordSetL( |
523 void CMPXDbAlbum::ProcessAlbumRecordSetL( |
632 const TArray<TMPXAttribute>& aAttrs, |
524 const TArray<TMPXAttribute>& aAttrs, |
633 RSqlStatement& aRecordset, |
525 RSqlStatement& aRecordset, |
634 CMPXMediaArray& aMediaArray) |
526 CMPXMediaArray& aMediaArray) |
635 { |
527 { |
636 // populate the array |
528 // populate the array |
637 TBool unknownRecord(EFalse); |
529 TBool firstRecord(ETrue); |
638 TBool firstUnknownRecord(EFalse); |
530 CMPXMedia* unknownAlbumUnknownArtistMedia(NULL); |
639 CMPXMedia* unknownMedia(NULL); |
531 CMPXMedia* unknownMedia(NULL); |
640 TInt prevId(0); |
532 TUint32 prevId(0); |
|
533 TUint32 artistId(0); |
|
534 TUint32 prevArtistId(0); |
|
535 TInt count(0); |
641 TInt err(KErrNone); |
536 TInt err(KErrNone); |
642 |
537 |
|
538 // Reset array for unknown artists |
|
539 if (iUnknownArtists.Count() > 0) |
|
540 { |
|
541 iUnknownArtists.ResetAndDestroy(); |
|
542 } |
|
543 |
|
544 // Reset array for unknown albums |
|
545 if (iUnknownAlbums.Count() > 0) |
|
546 { |
|
547 iUnknownAlbums.ResetAndDestroy(); |
|
548 } |
|
549 |
643 TInt pPath(0); |
550 TInt pPath(0); |
644 if (aMediaArray.Count()) |
551 if (aMediaArray.Count()) |
645 { |
552 { |
646 CMPXMedia* pMedia = aMediaArray[0]; |
553 CMPXMedia* pMedia = aMediaArray[0]; |
647 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
554 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
648 { // Query excuted by OpenL |
555 { // Query excuted by OpenL |
649 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
556 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
650 MPX_ASSERT(pPath); |
557 MPX_ASSERT(pPath); |
651 } |
558 } |
652 } |
559 } |
|
560 |
653 RArray<TMPXItemId> ids; |
561 RArray<TMPXItemId> ids; |
654 CleanupClosePushL(ids); |
562 CleanupClosePushL(ids); |
655 |
563 |
656 while ((err = aRecordset.Next()) == KSqlAtRow) |
564 while ((err = aRecordset.Next()) == KSqlAtRow) |
657 { |
565 { |
664 prevId = rowId; |
572 prevId = rowId; |
665 CMPXMedia* media = CMPXMedia::NewL(); |
573 CMPXMedia* media = CMPXMedia::NewL(); |
666 CleanupStack::PushL(media); |
574 CleanupStack::PushL(media); |
667 |
575 |
668 UpdateMediaL(aRecordset, aAttrs, *media); |
576 UpdateMediaL(aRecordset, aAttrs, *media); |
669 |
577 |
670 if (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumName).Length() == 0) |
578 artistId = aRecordset.ColumnInt64(EAlbumArtist); |
671 { |
579 |
672 if (!unknownMedia) |
580 // Append Known artist and Unknown albums |
|
581 count = iUnknownAlbums.Count(); |
|
582 if (prevArtistId != artistId && count > 0) |
|
583 { |
|
584 unknownMedia = NULL; |
|
585 |
|
586 for (TInt i = 0; i < count; i++) |
673 { |
587 { |
674 unknownMedia = media; |
588 unknownMedia = iUnknownAlbums[i]; |
675 firstUnknownRecord = ETrue; |
589 if (unknownMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
|
590 { |
|
591 ids.Append(unknownMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
592 } |
|
593 aMediaArray.AppendL(*unknownMedia); |
676 } |
594 } |
677 unknownRecord = ETrue; |
595 |
678 } |
596 iUnknownAlbums.ResetAndDestroy(); |
679 |
597 } |
680 if (!unknownRecord) |
598 |
|
599 // for Unknown artist and Unknown album |
|
600 if (firstRecord && (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumName).Length() == 0) && |
|
601 (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumArtistName).Length() == 0)) |
|
602 { |
|
603 unknownAlbumUnknownArtistMedia = media; |
|
604 } |
|
605 // for Unknown artists and Known albums |
|
606 else if (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumArtistName).Length() == 0) |
|
607 { |
|
608 iUnknownArtists.Append(media); |
|
609 CleanupStack::Pop(media); |
|
610 } |
|
611 // for Known artist and Unknown album |
|
612 else if (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumName).Length() == 0) |
|
613 { |
|
614 iUnknownAlbums.Append(media); |
|
615 CleanupStack::Pop(media); |
|
616 prevArtistId = artistId; |
|
617 } |
|
618 else |
681 { |
619 { |
682 if (media->IsSupported(KMPXMediaGeneralId) && pPath) |
620 if (media->IsSupported(KMPXMediaGeneralId) && pPath) |
683 { |
621 { |
684 ids.AppendL(media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
622 ids.AppendL(media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
685 } |
623 } |
686 aMediaArray.AppendL(*media); |
624 aMediaArray.AppendL(*media); |
687 } |
625 CleanupStack::PopAndDestroy(media); |
688 |
626 } |
689 if (!firstUnknownRecord) |
627 |
690 { |
628 firstRecord = EFalse; |
691 CleanupStack::PopAndDestroy(media); |
|
692 } |
|
693 else |
|
694 { |
|
695 firstUnknownRecord = EFalse; |
|
696 } |
|
697 |
|
698 unknownRecord = EFalse; |
|
699 } // end while |
629 } // end while |
700 |
630 |
701 if (err != KSqlAtEnd) |
631 if (err != KSqlAtEnd) |
702 { |
632 { |
703 User::LeaveIfError(err); |
633 User::LeaveIfError(err); |
704 } |
634 } |
705 |
635 |
706 if (unknownMedia) |
636 // Append Known artist and Unknown albums |
707 { |
637 count = iUnknownAlbums.Count(); |
708 if (unknownMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
638 if ( count > 0) |
709 { |
639 { |
710 ids.AppendL(unknownMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
640 unknownMedia = NULL; |
711 } |
641 |
712 aMediaArray.AppendL(*unknownMedia); |
642 for (TInt i = 0; i < count; i++) |
713 CleanupStack::PopAndDestroy(unknownMedia); |
643 { |
714 } |
644 unknownMedia = iUnknownAlbums[i]; |
715 |
645 if (unknownMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
|
646 { |
|
647 ids.Append(unknownMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
648 } |
|
649 aMediaArray.AppendL(*unknownMedia); |
|
650 } |
|
651 |
|
652 iUnknownAlbums.ResetAndDestroy(); |
|
653 } |
|
654 |
|
655 // Append Unknown artists to MediaArray |
|
656 count = iUnknownArtists.Count(); |
|
657 if ( count > 0) |
|
658 { |
|
659 CMPXMedia* unknownMedia = NULL; |
|
660 |
|
661 for (TInt i = 0; i < count; i++) |
|
662 { |
|
663 unknownMedia = iUnknownArtists[i]; |
|
664 if (unknownMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
|
665 { |
|
666 ids.Append(unknownMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
667 } |
|
668 aMediaArray.AppendL(*unknownMedia); |
|
669 } |
|
670 |
|
671 iUnknownArtists.ResetAndDestroy(); |
|
672 } |
|
673 |
|
674 // the last item in the list |
|
675 if (unknownAlbumUnknownArtistMedia) |
|
676 { |
|
677 if (unknownAlbumUnknownArtistMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
|
678 { |
|
679 ids.AppendL(unknownAlbumUnknownArtistMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
680 } |
|
681 aMediaArray.AppendL(*unknownAlbumUnknownArtistMedia); |
|
682 CleanupStack::PopAndDestroy(unknownAlbumUnknownArtistMedia); |
|
683 } |
|
684 |
716 // Append ids to the returned path |
685 // Append ids to the returned path |
717 if (pPath) |
686 if (pPath) |
718 { |
687 { |
719 ((CMPXCollectionPath*)pPath)->AppendL(ids.Array()); |
688 ((CMPXCollectionPath*)pPath)->AppendL(ids.Array()); |
720 } |
689 } |
721 CleanupStack::PopAndDestroy(&ids); |
690 CleanupStack::PopAndDestroy(&ids); |
722 } |
691 } |
723 |
692 |
|
693 // ---------------------------------------------------------------------------- |
|
694 // CMPXDbAlbum::GenerateUniqueIdL |
|
695 // ---------------------------------------------------------------------------- |
|
696 // |
|
697 TUint32 CMPXDbAlbum::GenerateUniqueIdL(const CMPXMedia& aMedia) |
|
698 { |
|
699 TPtrC album(KNullDesC); |
|
700 TPtrC albumArtist(KNullDesC); |
|
701 TPtrC artist(KNullDesC); |
|
702 |
|
703 // check Album attirbute |
|
704 if (aMedia.IsSupported(KMPXMediaMusicAlbum)) |
|
705 { |
|
706 album.Set(aMedia.ValueText(KMPXMediaMusicAlbum).Left(KMCMaxTextLen)); |
|
707 } |
|
708 |
|
709 HBufC* buf(NULL); |
|
710 if (RetrieveAlbumArtistL(aMedia, albumArtist)) |
|
711 { |
|
712 buf = HBufC::NewLC(album.Length() + albumArtist.Length() + KAlbumAlbumArtistSeperator().Length()); |
|
713 |
|
714 buf->Des().Append(album); |
|
715 buf->Des().Append(KAlbumAlbumArtistSeperator); |
|
716 buf->Des().Append(albumArtist); |
|
717 } |
|
718 else |
|
719 { |
|
720 RetrieveArtist(aMedia, artist); |
|
721 |
|
722 buf = HBufC::NewLC(album.Length() + artist.Length() + KAlbumArtistSeperator().Length()); |
|
723 |
|
724 buf->Des().Append(album); |
|
725 buf->Des().Append(KAlbumArtistSeperator); |
|
726 buf->Des().Append(artist); |
|
727 } |
|
728 |
|
729 // try to find the item first |
|
730 TUint32 id(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAlbum, |
|
731 *buf, ETrue)); |
|
732 CleanupStack::PopAndDestroy(buf); |
|
733 |
|
734 return id; |
|
735 } |
|
736 |
|
737 // ---------------------------------------------------------------------------- |
|
738 // CMPXDbAlbum::IsUnknownAlbumL |
|
739 // ---------------------------------------------------------------------------- |
|
740 // |
|
741 TBool CMPXDbAlbum::IsUnknownAlbumL(const TUint32 aId) |
|
742 { |
|
743 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
|
744 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aId)); |
|
745 CleanupStack::PopAndDestroy(query); |
|
746 CleanupClosePushL(recordset); |
|
747 |
|
748 if (recordset.Next() != KSqlAtRow) |
|
749 { |
|
750 User::Leave(KErrNotFound); |
|
751 } |
|
752 |
|
753 TPtrC album(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumName)); |
|
754 TPtrC artistName(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName)); |
|
755 |
|
756 TBool ret = EFalse; |
|
757 if (album.Length() == 0 || artistName.Length() == 0) |
|
758 { |
|
759 ret = ETrue; |
|
760 } |
|
761 else |
|
762 { |
|
763 ret = EFalse; |
|
764 } |
|
765 |
|
766 CleanupStack::PopAndDestroy(&recordset); |
|
767 |
|
768 return ret; |
|
769 } |
|
770 |
|
771 // ---------------------------------------------------------------------------- |
|
772 // CMPXDbAlbum::RetrieveAlbumArtistL |
|
773 // ---------------------------------------------------------------------------- |
|
774 // |
|
775 TBool CMPXDbAlbum::RetrieveAlbumArtistL(const CMPXMedia& aMedia, TPtrC& aName) |
|
776 { |
|
777 // check AlbumArtist attribute |
|
778 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist)) |
|
779 { |
|
780 aName.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen)); |
|
781 } |
|
782 else |
|
783 { |
|
784 aName.Set(KNullDesC); |
|
785 } |
|
786 |
|
787 if (aName.Length() > 0 ) |
|
788 { |
|
789 return ETrue; |
|
790 } |
|
791 else |
|
792 { |
|
793 return EFalse; |
|
794 } |
|
795 } |
|
796 |
|
797 // ---------------------------------------------------------------------------- |
|
798 // CMPXDbAlbum::RetrieveArtist |
|
799 // ---------------------------------------------------------------------------- |
|
800 // |
|
801 void CMPXDbAlbum::RetrieveArtist(const CMPXMedia& aMedia, TPtrC& aName) |
|
802 { |
|
803 // check Artist attribute |
|
804 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
805 { |
|
806 aName.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
807 } |
|
808 else |
|
809 { |
|
810 aName.Set(KNullDesC); |
|
811 } |
|
812 } |
|
813 |
|
814 // ---------------------------------------------------------------------------- |
|
815 // CMPXDbAlbum::NeedToUpdateArt |
|
816 // ---------------------------------------------------------------------------- |
|
817 // |
|
818 TBool CMPXDbAlbum::NeedToUpdateArt(const TDesC& aDeletedSongArt, const TDesC& aCurrentAlbumArt) |
|
819 { |
|
820 if (aDeletedSongArt.Length() == 0) |
|
821 { |
|
822 // Deleted song's art has default album art |
|
823 return EFalse; |
|
824 } |
|
825 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
826 else |
|
827 if (aDeletedSongArt.Length() > 0) |
|
828 { |
|
829 TParsePtrC parse(aDeletedSongArt); |
|
830 TPtrC ext(parse.Ext()); |
|
831 //set flag to false, so .alb will not overwrite art field in album, artist table |
|
832 // when song with embedded art |
|
833 if (ext.CompareF(KAbstractAlbumExt) == 0) |
|
834 { |
|
835 // Deleted song's art is Non-embedded album art |
|
836 return EFalse; |
|
837 } |
|
838 } |
|
839 else |
|
840 #endif |
|
841 if (aDeletedSongArt.Length() > 0 && aCurrentAlbumArt.Length() > 0 && aDeletedSongArt.CompareF(aCurrentAlbumArt) == 0) |
|
842 { |
|
843 // Deleted song's art is Embedded album art and it is the same as Album's current art |
|
844 return ETrue; |
|
845 } |
|
846 else |
|
847 { |
|
848 return EFalse; |
|
849 } |
|
850 } |
|
851 |
|
852 // ---------------------------------------------------------------------------- |
|
853 // CMPXDbAlbum::CreateTableL |
|
854 // ---------------------------------------------------------------------------- |
|
855 // |
|
856 void CMPXDbAlbum::CreateTableL( |
|
857 RSqlDatabase& aDatabase, |
|
858 TBool /* aCorruptTable */) |
|
859 { |
|
860 MPX_FUNC("CMPXDbCategory::CreateTableL"); |
|
861 |
|
862 // create the table |
|
863 User::LeaveIfError(aDatabase.Exec(KAlbumCreateTable)); |
|
864 |
|
865 // do not create an index on the Name field |
|
866 // as it only slows down the insert/update queries overall |
|
867 } |
|
868 |
|
869 // ---------------------------------------------------------------------------- |
|
870 // CMPXDbAlbum::CheckTableL |
|
871 // ---------------------------------------------------------------------------- |
|
872 // |
|
873 TBool CMPXDbAlbum::CheckTableL( |
|
874 RSqlDatabase& aDatabase) |
|
875 { |
|
876 MPX_FUNC("CMPXDbCategory::CheckTableL"); |
|
877 |
|
878 TBool check(DoCheckTable(aDatabase, KAlbumCheckTable)); |
|
879 |
|
880 return check; |
|
881 } |
|
882 |
724 // End of File |
883 // End of File |