40 // Two-phased constructor. |
40 // Two-phased constructor. |
41 // ---------------------------------------------------------------------------- |
41 // ---------------------------------------------------------------------------- |
42 // |
42 // |
43 CMPXDbArtist* CMPXDbArtist::NewL( |
43 CMPXDbArtist* CMPXDbArtist::NewL( |
44 CMPXDbManager& aDbManager, |
44 CMPXDbManager& aDbManager, |
45 TMPXGeneralCategory aCategory, |
45 TMPXGeneralCategory aCategory) |
46 MMPXDbArtistObserver& aObserver) |
|
47 { |
46 { |
48 MPX_FUNC("CMPXDbArtist::NewL"); |
47 MPX_FUNC("CMPXDbArtist::NewL"); |
49 |
48 |
50 CMPXDbArtist* self = CMPXDbArtist::NewLC(aDbManager, aCategory, aObserver); |
49 CMPXDbArtist* self = CMPXDbArtist::NewLC(aDbManager, aCategory); |
51 CleanupStack::Pop(self); |
50 CleanupStack::Pop(self); |
52 return self; |
51 return self; |
53 } |
52 } |
54 |
53 |
55 // ---------------------------------------------------------------------------- |
54 // ---------------------------------------------------------------------------- |
56 // Two-phased constructor. |
55 // Two-phased constructor. |
57 // ---------------------------------------------------------------------------- |
56 // ---------------------------------------------------------------------------- |
58 // |
57 // |
59 CMPXDbArtist* CMPXDbArtist::NewLC( |
58 CMPXDbArtist* CMPXDbArtist::NewLC( |
60 CMPXDbManager& aDbManager, |
59 CMPXDbManager& aDbManager, |
61 TMPXGeneralCategory aCategory, |
60 TMPXGeneralCategory aCategory) |
62 MMPXDbArtistObserver& aObserver) |
|
63 { |
61 { |
64 MPX_FUNC("CMPXDbArtist::NewLC"); |
62 MPX_FUNC("CMPXDbArtist::NewLC"); |
65 |
63 |
66 CMPXDbArtist* self = new (ELeave) CMPXDbArtist(aDbManager, aCategory, aObserver); |
64 CMPXDbArtist* self = new (ELeave) CMPXDbArtist(aDbManager, aCategory); |
67 CleanupStack::PushL(self); |
65 CleanupStack::PushL(self); |
68 self->ConstructL(); |
66 self->ConstructL(); |
69 return self; |
67 return self; |
70 } |
68 } |
71 |
69 |
106 // ---------------------------------------------------------------------------- |
102 // ---------------------------------------------------------------------------- |
107 // CMPXDbArtist::AddItemL |
103 // CMPXDbArtist::AddItemL |
108 // ---------------------------------------------------------------------------- |
104 // ---------------------------------------------------------------------------- |
109 // |
105 // |
110 TUint32 CMPXDbArtist::AddItemL( |
106 TUint32 CMPXDbArtist::AddItemL( |
111 const TDesC& aName, |
107 TMPXGeneralCategory /*aCategory*/, |
112 const TDesC& aArt, |
108 const CMPXMedia& aMedia, |
113 TInt aDriveId, |
109 TInt aDriveId, |
114 TBool& aNewRecord, |
110 TBool& aNewRecord, |
115 TBool aCaseSensitive) |
111 TBool aCaseSensitive) |
116 { |
112 { |
117 MPX_FUNC("CMPXDbArtist::AddItemL"); |
113 MPX_FUNC("CMPXDbArtist::AddItemL"); |
118 |
114 |
|
115 TPtrC artist(KNullDesC); |
|
116 TPtrC albumArt(KNullDesC); |
|
117 |
|
118 if (aMedia.IsSupported(KMPXMediaMusicArtist)) |
|
119 { |
|
120 artist.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); |
|
121 } |
|
122 |
|
123 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
124 { |
|
125 albumArt.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); |
|
126 } |
|
127 |
119 // try to find the item first |
128 // try to find the item first |
120 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
129 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
121 aName, aCaseSensitive)); |
130 artist, aCaseSensitive)); |
122 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
131 |
123 |
132 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
124 if (aNewRecord) |
133 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDriveId, *query, rowId)); |
125 { |
134 CleanupStack::PopAndDestroy(query); |
|
135 CleanupClosePushL(recordset); |
|
136 |
|
137 TInt result(recordset.Next()); |
|
138 if (result == KSqlAtEnd) |
|
139 { |
|
140 aNewRecord = result; |
|
141 |
126 // insert new |
142 // insert new |
127 HBufC* query = PreProcessStringLC(KQueryArtistInsert); |
143 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(artist); |
128 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
144 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(albumArt); |
129 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
145 |
130 |
146 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistInsert, rowId, name, 1, 0, art); |
131 iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1, art); |
|
132 |
147 |
133 CleanupStack::PopAndDestroy(art); |
148 CleanupStack::PopAndDestroy(art); |
134 CleanupStack::PopAndDestroy(name); |
149 CleanupStack::PopAndDestroy(name); |
135 CleanupStack::PopAndDestroy(query); |
150 } |
136 } |
151 else if (result == KSqlAtRow) |
137 else |
152 { |
138 { |
153 // retrieve Art from Artist table |
139 // retrieve the existing record |
|
140 HBufC* query = NULL; |
|
141 query = PreProcessStringLC(KQueryCategoryItem); |
|
142 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId)); |
|
143 CleanupStack::PopAndDestroy(query); |
|
144 |
|
145 CleanupClosePushL(recordset); |
|
146 |
|
147 if (recordset.Next() != KSqlAtRow) |
|
148 { |
|
149 User::Leave(KErrNotFound); |
|
150 } |
|
151 |
|
152 // Album Art |
|
153 TPtrC art(KNullDesC); |
154 TPtrC art(KNullDesC); |
154 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt)); |
155 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt)); |
155 |
156 |
156 // the current one is Unknown and the new one is Not Unknown |
157 // the current one is Unknown and the new one is Not Unknown |
157 if ( art == KNullDesC && aArt != KNullDesC ) |
158 if ( art == KNullDesC && albumArt != KNullDesC ) |
158 { |
159 { |
159 HBufC* artReplaceSingleQuote = |
160 HBufC* artReplaceSingleQuote = |
160 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
161 MPXDbCommonUtil::ProcessSingleQuotesLC( albumArt ); |
161 _LIT( KFormatArt, "Art=\'%S\'" ); |
162 _LIT( KFormatArt, "Art=\'%S\'" ); |
162 HBufC* setStr = HBufC::NewLC(256); |
163 HBufC* setStr = HBufC::NewLC(KMaxFileName); |
163 setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); |
164 setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); |
164 |
165 |
165 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId); |
166 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId); |
166 CleanupStack::PopAndDestroy(setStr); |
167 CleanupStack::PopAndDestroy(setStr); |
167 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
168 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
168 } |
169 } |
169 |
170 |
170 CleanupStack::PopAndDestroy(&recordset); |
|
171 |
|
172 // increment the number of songs for the category |
171 // increment the number of songs for the category |
173 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
172 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
174 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
173 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
175 CleanupStack::PopAndDestroy(query); |
174 CleanupStack::PopAndDestroy(query); |
176 } |
175 } |
177 |
176 else |
|
177 { |
|
178 MPX_DEBUG2("SQL error %d", result); |
|
179 User::Leave(result); |
|
180 } |
|
181 |
|
182 CleanupStack::PopAndDestroy(&recordset); |
|
183 |
178 return rowId; |
184 return rowId; |
179 } |
185 } |
180 |
186 |
181 // ---------------------------------------------------------------------------- |
187 // ---------------------------------------------------------------------------- |
182 // CMPXDbArtist::IsUnknownArtistL |
188 // CMPXDbArtist::DecrementSongsForCategoryL |
183 // ---------------------------------------------------------------------------- |
189 // ---------------------------------------------------------------------------- |
184 // |
190 // |
185 TBool CMPXDbArtist::IsUnknownArtistL(TUint32 aId) |
191 void CMPXDbArtist::DecrementSongsForCategoryL( |
186 { |
192 const TUint32 aId, |
187 MPX_FUNC("CMPXDbArtist::IsUnknownArtistL"); |
193 TInt aDriveId, |
188 |
194 CMPXMessageArray* aItemChangedMessages, |
189 HBufC* name = GetNameL(aId); |
195 TBool& aItemExist |
190 |
196 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
191 TInt ret = EFalse; |
197 , |
192 if (*name == KNullDesC) |
198 TBool /*aMTPInUse*/ |
193 { |
199 #endif //ABSTRACTAUDIOALBUM_INCLUDED |
194 ret = ETrue; |
200 ) |
195 } |
201 { |
196 delete name; |
202 MPX_FUNC("CMPXDbArtist::DecrementSongsForCategoryL"); |
197 |
203 |
198 return ret; |
204 TInt songsCount(0); |
|
205 TInt albumsCount(0); |
|
206 |
|
207 GetSongsAndAlbumsCountL(aDriveId, aId, songsCount, albumsCount); |
|
208 |
|
209 MPX_DEBUG4("id %d, songsCount %d, albumsCount %d", aId, songsCount, albumsCount); |
|
210 |
|
211 // if just one song uses this category. Use <= just in case |
|
212 if (songsCount <= 1 && albumsCount == 0) |
|
213 { |
|
214 aItemExist = EFalse; |
|
215 // delete the category |
|
216 DeleteCategoryL(aId, aDriveId); |
|
217 |
|
218 if (aItemChangedMessages) |
|
219 { |
|
220 // add the item changed message |
|
221 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted, |
|
222 iCategory, KDBPluginUid); |
|
223 } |
|
224 } |
|
225 else if (songsCount > 0) |
|
226 { |
|
227 aItemExist = ETrue; |
|
228 // decrement the number of songs for the category |
|
229 HBufC* query = PreProcessStringLC(KQueryCategoryDecrementSongCount); |
|
230 iDbManager.ExecuteQueryL(aDriveId, *query, aId); |
|
231 CleanupStack::PopAndDestroy(query); |
|
232 } |
199 } |
233 } |
200 |
234 |
201 // ---------------------------------------------------------------------------- |
235 // ---------------------------------------------------------------------------- |
202 // CMPXDbArtist::UpdateMediaL |
236 // CMPXDbArtist::UpdateMediaL |
203 // ---------------------------------------------------------------------------- |
237 // ---------------------------------------------------------------------------- |
279 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
309 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
280 } |
310 } |
281 } |
311 } |
282 |
312 |
283 // ---------------------------------------------------------------------------- |
313 // ---------------------------------------------------------------------------- |
284 // CMPXDbArtist::GetAlbumsCountL |
|
285 // ---------------------------------------------------------------------------- |
|
286 // |
|
287 TInt CMPXDbArtist::GetAlbumsCountL(TUint32 aId) |
|
288 { |
|
289 MPX_FUNC("CMPXDbArtist::GetAlbumsCountL"); |
|
290 |
|
291 return iObserver.HandleGetAlbumsCountForArtistL(aId); |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // CMPXDbArtist::GetAllCategoryItemsL |
314 // CMPXDbArtist::GetAllCategoryItemsL |
296 // ---------------------------------------------------------------------------- |
315 // ---------------------------------------------------------------------------- |
297 // |
316 // |
298 void CMPXDbArtist::GetAllCategoryItemsL( |
317 void CMPXDbArtist::GetAllCategoryItemsL( |
299 const TArray<TMPXAttribute>& aAttrs, |
318 const TArray<TMPXAttribute>& aAttrs, |
300 CMPXMediaArray& aMediaArray) |
319 CMPXMediaArray& aMediaArray) |
301 { |
320 { |
302 MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL"); |
321 MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL"); |
303 HBufC* query = PreProcessStringLC(KQueryArtistAll); |
322 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryArtistAll())); |
304 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); |
|
305 CleanupStack::PopAndDestroy(query); |
|
306 CleanupClosePushL(recordset); |
323 CleanupClosePushL(recordset); |
307 ProcessRecordsetL(aAttrs, recordset, aMediaArray); |
324 ProcessRecordsetL(aAttrs, recordset, aMediaArray); |
308 CleanupStack::PopAndDestroy(&recordset); |
325 CleanupStack::PopAndDestroy(&recordset); |
309 } |
326 } |
310 |
327 |
341 |
358 |
342 CleanupStack::PopAndDestroy(setStr); |
359 CleanupStack::PopAndDestroy(setStr); |
343 CleanupStack::PopAndDestroy(values); |
360 CleanupStack::PopAndDestroy(values); |
344 CleanupStack::PopAndDestroy(fields); |
361 CleanupStack::PopAndDestroy(fields); |
345 } |
362 } |
346 // ---------------------------------------------------------------------------- |
363 |
347 // CMPXDbAlbum::CreateTableL |
364 // ---------------------------------------------------------------------------- |
|
365 // CMPXDbArtist::AddAlbumArtistL |
|
366 // ---------------------------------------------------------------------------- |
|
367 // |
|
368 TUint32 CMPXDbArtist::AddAlbumArtistL( |
|
369 const TDesC& aName, |
|
370 const TDesC& aArt, |
|
371 TInt aDriveId) |
|
372 { |
|
373 MPX_FUNC("CMPXDbArtist::AddAlbumArtistL"); |
|
374 |
|
375 // try to find the item first |
|
376 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
|
377 aName, ETrue)); |
|
378 HBufC* query = PreProcessStringLC(KQueryCategoryItem); |
|
379 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDriveId, *query, rowId)); |
|
380 CleanupStack::PopAndDestroy(query); |
|
381 CleanupClosePushL(recordset); |
|
382 |
|
383 TInt result(recordset.Next()); |
|
384 if (result == KSqlAtEnd) |
|
385 { |
|
386 // insert new |
|
387 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
|
388 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
|
389 |
|
390 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistInsert, rowId, name, 0, 1, art); |
|
391 |
|
392 CleanupStack::PopAndDestroy(art); |
|
393 CleanupStack::PopAndDestroy(name); |
|
394 } |
|
395 else if (result == KSqlAtRow) |
|
396 { |
|
397 // retrieve Art from Artist table |
|
398 TPtrC art(KNullDesC); |
|
399 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt)); |
|
400 |
|
401 // the current one is Unknown and the new one is Not Unknown |
|
402 if ( art == KNullDesC && aArt != KNullDesC ) |
|
403 { |
|
404 HBufC* artReplaceSingleQuote = |
|
405 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
|
406 _LIT( KFormatArt, "Art=\'%S\'" ); |
|
407 HBufC* setStr = HBufC::NewLC(KMaxFileName); |
|
408 setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); |
|
409 |
|
410 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId); |
|
411 CleanupStack::PopAndDestroy(setStr); |
|
412 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
|
413 } |
|
414 |
|
415 // increment the number of songs for the category |
|
416 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistIncrementAlbumCount, rowId); |
|
417 } |
|
418 else |
|
419 { |
|
420 MPX_DEBUG2("SQL error %d", result); |
|
421 User::Leave(result); |
|
422 } |
|
423 |
|
424 CleanupStack::PopAndDestroy(&recordset); |
|
425 |
|
426 return rowId; |
|
427 } |
|
428 |
|
429 // ---------------------------------------------------------------------------- |
|
430 // CMPXDbArtist::DecrementAlbumsForArtistL |
|
431 // ---------------------------------------------------------------------------- |
|
432 // |
|
433 void CMPXDbArtist::DecrementAlbumsForArtistL( |
|
434 const TUint32 aId, |
|
435 TInt aDriveId, |
|
436 CMPXMessageArray* aItemChangedMessages |
|
437 ) |
|
438 { |
|
439 MPX_FUNC("CMPXDbArtist::DecrementAlbumsForCategoryL"); |
|
440 |
|
441 TInt songsCount(0); |
|
442 TInt albumsCount(0); |
|
443 |
|
444 GetSongsAndAlbumsCountL(aDriveId, aId, songsCount, albumsCount); |
|
445 |
|
446 MPX_DEBUG4("id %d, songsCount %d, albumsCount %d", aId, songsCount, albumsCount); |
|
447 |
|
448 // if just one album uses this category. Use <= just in case |
|
449 if (songsCount == 0 && albumsCount <= 1) |
|
450 { |
|
451 // delete the category |
|
452 DeleteCategoryL(aId, aDriveId); |
|
453 |
|
454 if (aItemChangedMessages) |
|
455 { |
|
456 // add the item changed message |
|
457 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted, |
|
458 iCategory, KDBPluginUid); |
|
459 } |
|
460 } |
|
461 else if (albumsCount > 0) |
|
462 { |
|
463 // decrement the number of albums for the category |
|
464 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistDecrementAlbumCount, aId); |
|
465 } |
|
466 } |
|
467 |
|
468 // ---------------------------------------------------------------------------- |
|
469 // CMPXDbArtist::GetSongsAndAlbumsCountL |
|
470 // ---------------------------------------------------------------------------- |
|
471 // |
|
472 void CMPXDbArtist::GetSongsAndAlbumsCountL( |
|
473 TInt aDriveId, |
|
474 TUint32 aId, |
|
475 TInt& aSongCount, |
|
476 TInt& aAlbumCount) |
|
477 { |
|
478 MPX_FUNC("CMPXDbArtist::GetSongsAndAlbumsCountL"); |
|
479 |
|
480 RSqlStatement recordset( |
|
481 iDbManager.ExecuteSelectQueryL(aDriveId, KQueryArtistGetSongCountAndAlbumCount, aId)); |
|
482 CleanupClosePushL(recordset); |
|
483 |
|
484 TInt err(KErrNone); |
|
485 while ((err = recordset.Next()) == KSqlAtRow) |
|
486 { |
|
487 aSongCount += recordset.ColumnInt(KMPXTableDefaultIndex); |
|
488 aAlbumCount += recordset.ColumnInt(KMPXTableDefaultIndex+1); |
|
489 } |
|
490 |
|
491 if (err != KSqlAtEnd) |
|
492 { |
|
493 User::Leave(err); |
|
494 } |
|
495 |
|
496 CleanupStack::PopAndDestroy(&recordset); |
|
497 } |
|
498 |
|
499 // ---------------------------------------------------------------------------- |
|
500 // CMPXDbArtist::CreateTableL |
348 // ---------------------------------------------------------------------------- |
501 // ---------------------------------------------------------------------------- |
349 // |
502 // |
350 void CMPXDbArtist::CreateTableL( |
503 void CMPXDbArtist::CreateTableL( |
351 RSqlDatabase& aDatabase, |
504 RSqlDatabase& aDatabase, |
352 TBool /* aCorruptTable */) |
505 TBool /* aCorruptTable */) |
353 { |
506 { |
354 MPX_FUNC("CMPXDbCategory::CreateTableL"); |
507 MPX_FUNC("CMPXDbArtist::CreateTableL"); |
355 |
508 |
356 // create the table |
509 // create the table |
357 HBufC* query = PreProcessStringLC(KArtistCreateTable); |
510 User::LeaveIfError(aDatabase.Exec(KArtistCreateTable)); |
358 User::LeaveIfError(aDatabase.Exec(*query)); |
|
359 CleanupStack::PopAndDestroy(query); |
|
360 |
511 |
361 // do not create an index on the Name field |
512 // do not create an index on the Name field |
362 // as it only slows down the insert/update queries overall |
513 // as it only slows down the insert/update queries overall |
363 } |
514 } |
364 |
515 |
365 // ---------------------------------------------------------------------------- |
516 // ---------------------------------------------------------------------------- |
366 // CMPXDbAlbum::CheckTableL |
517 // CMPXDbArtist::CheckTableL |
367 // ---------------------------------------------------------------------------- |
518 // ---------------------------------------------------------------------------- |
368 // |
519 // |
369 TBool CMPXDbArtist::CheckTableL( |
520 TBool CMPXDbArtist::CheckTableL( |
370 RSqlDatabase& aDatabase) |
521 RSqlDatabase& aDatabase) |
371 { |
522 { |
372 MPX_FUNC("CMPXDbCategory::CheckTableL"); |
523 MPX_FUNC("CMPXDbArtist::CheckTableL"); |
373 |
524 |
374 HBufC* query = PreProcessStringLC(KArtistCheckTable); |
525 TBool check(DoCheckTable(aDatabase, KArtistCheckTable)); |
375 TBool check(DoCheckTable(aDatabase, *query)); |
|
376 CleanupStack::PopAndDestroy(query); |
|
377 |
526 |
378 return check; |
527 return check; |
379 } |
528 } |
380 |
529 |
381 // End of File |
530 // End of File |