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)); |
158 |
161 |
159 // the current one is Unknown and the new one is Not Unknown. |
162 // the current one is Unknown and the new one is Not Unknown. |
160 if ( IsUnknownArtistL( artistId ) && !IsUnknownArtistL( aArtist ) ) |
163 if ( artistname == KNullDesC && aArtistName!= KNullDesC ) |
161 { |
164 { |
162 _LIT( KFormatArtistId, "Artist=%d" ); |
165 HBufC* artistnameReplaceSingleQuote = |
163 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen); |
166 MPXDbCommonUtil::ProcessSingleQuotesLC( aArtistName ); |
164 setStr->Des().Format( KFormatArtistId, aArtist ); |
167 TPtrC criteria(KCriterionArtistName); |
165 |
168 HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); |
|
169 setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote ); |
|
170 |
166 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
171 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
167 CleanupStack::PopAndDestroy(setStr); |
172 CleanupStack::PopAndDestroy(setStr); |
|
173 CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote); |
168 } |
174 } |
169 |
175 |
170 // Album Art |
176 // Album Art |
171 TPtrC art(KNullDesC); |
177 TPtrC art(KNullDesC); |
172 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
178 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
174 // the current one is Unknown and the new one is Not Unknown |
180 // the current one is Unknown and the new one is Not Unknown |
175 if ( art == KNullDesC && aArt != KNullDesC ) |
181 if ( art == KNullDesC && aArt != KNullDesC ) |
176 { |
182 { |
177 HBufC* artReplaceSingleQuote = |
183 HBufC* artReplaceSingleQuote = |
178 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
184 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
179 _LIT( KFormatArt, "Art=\'%S\'" ); |
185 |
180 HBufC* setStr = HBufC::NewLC(256); |
186 TPtrC criteria(KCriterionArt); |
181 setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); |
187 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
|
188 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
182 |
189 |
183 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
190 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
184 CleanupStack::PopAndDestroy(setStr); |
191 CleanupStack::PopAndDestroy(setStr); |
185 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
192 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
186 } |
193 } |
238 if (recordset.Next() != KSqlAtRow) |
245 if (recordset.Next() != KSqlAtRow) |
239 { |
246 { |
240 User::Leave(KErrNotFound); |
247 User::Leave(KErrNotFound); |
241 } |
248 } |
242 |
249 |
243 TUint32 artistId = recordset.ColumnInt64(EAlbumArtist); |
|
244 TBool itemModified = EFalse; |
250 TBool itemModified = EFalse; |
|
251 TPtrC artistname(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName)); |
|
252 TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist, |
|
253 artistname, ETrue); |
245 |
254 |
246 // the current artist is equal to deleted song's artist |
255 // the current artist is equal to deleted song's artist |
247 if ( artistId == aArtist ) |
256 if ( artistId == aArtist ) |
248 { |
257 { |
249 TUint32 newArtistId = ArtistForAlbumL(aId); |
258 HBufC* newArtistname = ArtistForAlbumL(aId); |
250 if ( artistId != newArtistId ) |
259 |
251 { |
260 CleanupStack::PushL(newArtistname); |
252 _LIT( KFormatArtistId, "Artist=%d" ); |
261 if (newArtistname && newArtistname->CompareF(artistname)!=0) |
253 HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen); |
262 { |
254 setStr->Des().Format(KFormatArtistId, newArtistId); |
263 HBufC* artistnameReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArtistname ); |
|
264 TPtrC criteria(KCriterionArtistName); |
|
265 HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); |
|
266 setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote ); |
255 |
267 |
256 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
268 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
257 CleanupStack::PopAndDestroy(setStr); |
269 CleanupStack::PopAndDestroy(setStr); |
|
270 CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote); |
258 itemModified = ETrue; |
271 itemModified = ETrue; |
259 } |
272 } |
260 } |
273 CleanupStack::PopAndDestroy(newArtistname); |
|
274 } |
261 |
275 |
262 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
276 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
263 TBool nonEmbeddedArt = EFalse; |
277 TBool nonEmbeddedArt = EFalse; |
264 if (aArt.Length()>0) |
278 if (aArt.Length()>0) |
265 { |
279 { |
288 //update Album table only if alternative albumart found |
302 //update Album table only if alternative albumart found |
289 if (newArt) |
303 if (newArt) |
290 { |
304 { |
291 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt"); |
305 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt"); |
292 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt ); |
306 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt ); |
293 _LIT( KFormatArt, "Art=\'%S\'" ); |
307 TPtrC criteria(KCriterionArt); |
294 HBufC* setStr = HBufC::NewLC(256); |
308 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
295 setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); |
309 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
296 |
310 |
297 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
311 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
298 CleanupStack::PopAndDestroy(setStr); |
312 CleanupStack::PopAndDestroy(setStr); |
299 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
313 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
300 itemModified = ETrue; |
314 itemModified = ETrue; |
551 } |
565 } |
552 |
566 |
553 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
567 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
554 { |
568 { |
555 const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen); |
569 const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen); |
556 TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist, |
570 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCAlbumArtistName, artistName); |
557 artistName, ETrue); |
|
558 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, artistId); |
|
559 } |
571 } |
560 } |
572 } |
561 |
573 |
562 // ---------------------------------------------------------------------------- |
574 // ---------------------------------------------------------------------------- |
563 // CMPXDbAlbum::IsUnknownArtistL |
575 // CMPXDbAlbum::IsUnknownArtistL |
570 |
582 |
571 // ---------------------------------------------------------------------------- |
583 // ---------------------------------------------------------------------------- |
572 // CMPXDbAlbum::ArtistForAlbumL |
584 // CMPXDbAlbum::ArtistForAlbumL |
573 // ---------------------------------------------------------------------------- |
585 // ---------------------------------------------------------------------------- |
574 // |
586 // |
575 TUint32 CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId) |
587 HBufC* CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId) |
576 { |
588 { |
577 return iObserver.HandleArtistForAlbumL(aId); |
589 return iObserver.HandleArtistForAlbumL(aId); |
578 } |
590 } |
579 |
591 |
580 // ---------------------------------------------------------------------------- |
592 // ---------------------------------------------------------------------------- |