|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Responsible for interation with the category tables: |
|
15 * Artist, Album, Genre and Composer |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <sqldb.h> |
|
22 |
|
23 #include <mpxlog.h> |
|
24 |
|
25 #include "mpxdbcommonutil.h" |
|
26 #include "mpxdbcommondef.h" |
|
27 #include "mpxdbmanager.h" |
|
28 |
|
29 #include "mpxcollectiondbdef.h" |
|
30 #include "mpxmediamusicdefs.h" |
|
31 #include "mpxdbpluginqueries.h" |
|
32 #include "mpxdbutil.h" |
|
33 #include "mpxdbalbum.h" |
|
34 |
|
35 // CONSTANTS |
|
36 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
37 _LIT( KAbstractAlbumExt, ".alb" ); |
|
38 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS ============================== |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // Two-phased constructor. |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 CMPXDbAlbum* CMPXDbAlbum::NewL( |
|
47 CMPXDbManager& aDbManager, |
|
48 TMPXGeneralCategory aCategory, |
|
49 MMPXDbAlbumObserver& aObserver) |
|
50 { |
|
51 MPX_FUNC("CMPXDbAlbum::NewL"); |
|
52 |
|
53 CMPXDbAlbum* self = CMPXDbAlbum::NewLC(aDbManager, aCategory, aObserver); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // Two-phased constructor. |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 CMPXDbAlbum* CMPXDbAlbum::NewLC( |
|
63 CMPXDbManager& aDbManager, |
|
64 TMPXGeneralCategory aCategory, |
|
65 MMPXDbAlbumObserver& aObserver) |
|
66 { |
|
67 MPX_FUNC("CMPXDbAlbum::NewLC"); |
|
68 |
|
69 CMPXDbAlbum* self = new (ELeave) CMPXDbAlbum(aDbManager, aCategory, aObserver); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // Destructor |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 CMPXDbAlbum::~CMPXDbAlbum() |
|
80 { |
|
81 MPX_FUNC("CMPXDbAlbum::~CMPXDbAlbum"); |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // Constructor |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 CMPXDbAlbum::CMPXDbAlbum( |
|
89 CMPXDbManager& aDbManager, |
|
90 TMPXGeneralCategory aCategory, |
|
91 MMPXDbAlbumObserver& aObserver) : |
|
92 CMPXDbCategory(aDbManager, aCategory), |
|
93 iObserver(aObserver) |
|
94 { |
|
95 MPX_FUNC("CMPXDbAlbum::CMPXDbAlbum"); |
|
96 } |
|
97 |
|
98 // ---------------------------------------------------------------------------- |
|
99 // Second phase constructor. |
|
100 // ---------------------------------------------------------------------------- |
|
101 // |
|
102 void CMPXDbAlbum::ConstructL() |
|
103 { |
|
104 MPX_FUNC("CMPXDbAlbum::ConstructL"); |
|
105 |
|
106 BaseConstructL(); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CMPXDbAlbum::AddItemL |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 TUint32 CMPXDbAlbum::AddItemL( |
|
114 const TDesC& aName, |
|
115 const TDesC& aArtistName, |
|
116 const TDesC& aArt, |
|
117 TInt aDriveId, |
|
118 TBool& aNewRecord, |
|
119 TBool aCaseSensitive) |
|
120 { |
|
121 MPX_FUNC("CMPXDbAlbum::AddItemL"); |
|
122 |
|
123 // try to find the item first |
|
124 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
|
125 aName, aCaseSensitive)); |
|
126 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
|
127 |
|
128 if (aNewRecord) |
|
129 { |
|
130 // insert new |
|
131 HBufC* query = PreProcessStringLC(KQueryAlbumInsert); |
|
132 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
|
133 HBufC* artistname = MPXDbCommonUtil::ProcessSingleQuotesLC(aArtistName); |
|
134 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
|
135 |
|
136 iDbManager.ExecuteQueryL(aDriveId, *query, rowId, artistname, name, 1, art); |
|
137 |
|
138 CleanupStack::PopAndDestroy(art); |
|
139 CleanupStack::PopAndDestroy(artistname); |
|
140 CleanupStack::PopAndDestroy(name); |
|
141 CleanupStack::PopAndDestroy(query); |
|
142 } |
|
143 else |
|
144 { |
|
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); |
|
180 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArt)); |
|
181 |
|
182 // the current one is Unknown and the new one is Not Unknown |
|
183 if ( art == KNullDesC && aArt != KNullDesC ) |
|
184 { |
|
185 HBufC* artReplaceSingleQuote = |
|
186 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
|
187 |
|
188 TPtrC criteria(KCriterionArt); |
|
189 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
|
190 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
|
191 |
|
192 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId); |
|
193 CleanupStack::PopAndDestroy(setStr); |
|
194 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
|
195 } |
|
196 |
|
197 CleanupStack::PopAndDestroy(&recordset); |
|
198 |
|
199 // increment the number of songs for the category |
|
200 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
|
201 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
|
202 CleanupStack::PopAndDestroy(query); |
|
203 } |
|
204 |
|
205 return rowId; |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------------------------- |
|
209 // CMPXDbAlbum::DecrementSongsForCategoryL |
|
210 // ---------------------------------------------------------------------------- |
|
211 // |
|
212 void CMPXDbAlbum::DecrementSongsForCategoryL( |
|
213 const TUint32 aId, |
|
214 TInt aDriveId, |
|
215 CMPXMessageArray* aItemChangedMessages, |
|
216 TBool& aItemExist, |
|
217 const TUint32 aArtist, |
|
218 const TDesC& aArt) |
|
219 { |
|
220 MPX_FUNC("CMPXDbAlbum::DecrementSongsForCategoryL"); |
|
221 |
|
222 // if just one song uses this category. Use <= just in case |
|
223 if (GetSongsCountL(aDriveId, aId) <= 1) |
|
224 { |
|
225 aItemExist = EFalse; |
|
226 // delete the category |
|
227 DeleteCategoryL(aId, aDriveId); |
|
228 |
|
229 if (aItemChangedMessages) |
|
230 { |
|
231 // add the item changed message |
|
232 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted, |
|
233 iCategory, KDBPluginUid); |
|
234 } |
|
235 } |
|
236 else |
|
237 { |
|
238 aItemExist = ETrue; |
|
239 |
|
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; |
|
253 TPtrC artistname(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName)); |
|
254 TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist, |
|
255 artistname, ETrue); |
|
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 { |
|
298 MPX_DEBUG2("AlbumArt of the Song to be deleted is [%S]", &aArt); |
|
299 |
|
300 //need to get alternative art in the same album to display |
|
301 HBufC* newArt = AlbumartForAlbumL(aId, aArt); |
|
302 CleanupStack::PushL(newArt); |
|
303 |
|
304 //update Album table only if alternative albumart found |
|
305 if (newArt) |
|
306 { |
|
307 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt"); |
|
308 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt ); |
|
309 TPtrC criteria(KCriterionArt); |
|
310 HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); |
|
311 setStr->Des().Format( KCriterionArt, artReplaceSingleQuote ); |
|
312 |
|
313 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
|
314 CleanupStack::PopAndDestroy(setStr); |
|
315 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
|
316 itemModified = ETrue; |
|
317 } |
|
318 CleanupStack::PopAndDestroy(newArt); |
|
319 } |
|
320 #ifdef ABSTRACTAUDIOALBUM_INCLUDED |
|
321 } |
|
322 #endif // ABSTRACTAUDIOALBUM_INCLUDED |
|
323 if (aItemChangedMessages && itemModified) |
|
324 { |
|
325 // add the item changed message |
|
326 MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
|
327 EMPXAlbum, KDBPluginUid, ETrue, 0 ); |
|
328 } |
|
329 CleanupStack::PopAndDestroy(&recordset); |
|
330 |
|
331 // decrement the number of songs for the category |
|
332 query = PreProcessStringLC(KQueryCategoryDecrementSongCount); |
|
333 iDbManager.ExecuteQueryL(aDriveId, *query, aId); |
|
334 CleanupStack::PopAndDestroy(query); |
|
335 } |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CMPXDbAlbum::GetAllCategoryItemsL |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 void CMPXDbAlbum::GetAllCategoryItemsL( |
|
343 const TArray<TMPXAttribute>& aAttrs, |
|
344 CMPXMediaArray& aMediaArray) |
|
345 { |
|
346 MPX_FUNC("CMPXDbAlbum::GetAllCategoryItemsL"); |
|
347 |
|
348 HBufC* query = PreProcessStringLC(KQueryAlbumAll); |
|
349 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); |
|
350 CleanupStack::PopAndDestroy(query); |
|
351 |
|
352 CleanupClosePushL(recordset); |
|
353 ProcessAlbumRecordSetL(aAttrs, recordset, aMediaArray); |
|
354 CleanupStack::PopAndDestroy(&recordset); |
|
355 } |
|
356 |
|
357 // ---------------------------------------------------------------------------- |
|
358 // CMPXDbAlbum::UpdateItemL |
|
359 // ---------------------------------------------------------------------------- |
|
360 // |
|
361 void CMPXDbAlbum::UpdateItemL( |
|
362 TUint32 aId, |
|
363 const CMPXMedia& aMedia, |
|
364 TInt aDriveId, |
|
365 CMPXMessageArray* aItemChangedMessages) |
|
366 { |
|
367 MPX_FUNC("CMPXDbAlbum::UpdateItemL"); |
|
368 |
|
369 CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EAlbumFieldCount); |
|
370 CleanupStack::PushL(fields); |
|
371 CDesCArrayFlat* values = new (ELeave) CDesCArrayFlat(EAlbumFieldCount); |
|
372 CleanupStack::PushL(values); |
|
373 |
|
374 // process the media parameter and construct the fields and values array |
|
375 GenerateAlbumFieldsValuesL(aMedia, *fields, *values); |
|
376 |
|
377 // construct the SET string |
|
378 HBufC* setStr = MPXDbCommonUtil::StringFromArraysLC(*fields, *values, KMCEqualSign, KMCCommaSign); |
|
379 |
|
380 if (setStr->Length()) |
|
381 { |
|
382 // execute the query |
|
383 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId); |
|
384 MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
|
385 EMPXAlbum, KDBPluginUid, ETrue, 0 ); |
|
386 } |
|
387 |
|
388 CleanupStack::PopAndDestroy(setStr); |
|
389 CleanupStack::PopAndDestroy(values); |
|
390 CleanupStack::PopAndDestroy(fields); |
|
391 } |
|
392 |
|
393 // ---------------------------------------------------------------------------- |
|
394 // CMPXDbAlbum::GetAlbumsCountForArtistL |
|
395 // ---------------------------------------------------------------------------- |
|
396 // |
|
397 TInt CMPXDbAlbum::GetAlbumsCountForArtistL(TUint32 aArtistId) |
|
398 { |
|
399 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryCategorySubcategoryItems, aArtistId)); |
|
400 |
|
401 TInt prevId(0); |
|
402 TInt count(0); |
|
403 TInt err(KErrNone); |
|
404 |
|
405 while ((err = recordset.Next()) == KSqlAtRow) |
|
406 { |
|
407 TUint32 rowId(recordset.ColumnInt64(EAlbumUniqueId)); |
|
408 if (prevId == rowId) |
|
409 { |
|
410 continue; |
|
411 } |
|
412 |
|
413 count++; |
|
414 prevId = rowId; |
|
415 } |
|
416 |
|
417 if (err != KSqlAtEnd) |
|
418 { |
|
419 User::Leave(err); |
|
420 } |
|
421 |
|
422 return count; |
|
423 |
|
424 } |
|
425 |
|
426 // ---------------------------------------------------------------------------- |
|
427 // CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL |
|
428 // ---------------------------------------------------------------------------- |
|
429 // |
|
430 TInt CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL(TUint32 aArtistId, TUint32 aAlbumId) |
|
431 { |
|
432 MPX_FUNC("CMPXDbAlbum::GetSongsCountInAlbumMatchingArtistL"); |
|
433 |
|
434 return ExecuteSumQueryL(KQuerySongsInArtistAlbum, aArtistId, aAlbumId); |
|
435 } |
|
436 |
|
437 // ---------------------------------------------------------------------------- |
|
438 // CMPXDbAlbum::UpdateMediaL |
|
439 // ---------------------------------------------------------------------------- |
|
440 // |
|
441 void CMPXDbAlbum::UpdateMediaL( |
|
442 RSqlStatement& aRecord, |
|
443 const TArray<TMPXAttribute>& aAttrs, |
|
444 CMPXMedia& aMedia) |
|
445 { |
|
446 MPX_FUNC("CMPXDbAlbum::UpdateMediaL"); |
|
447 |
|
448 TInt count(aAttrs.Count()); |
|
449 for (TInt i = 0; i < count; ++i) |
|
450 { |
|
451 TInt contentId(aAttrs[i].ContentId()); |
|
452 TUint attributeId(aAttrs[i].AttributeId()); |
|
453 |
|
454 if (contentId == KMPXMediaIdGeneral) |
|
455 { |
|
456 if (attributeId & EMPXMediaGeneralId) |
|
457 { |
|
458 MPX_DEBUG1(" EMPXMediaGeneralId"); |
|
459 |
|
460 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, |
|
461 aRecord.ColumnInt64(EAlbumUniqueId)); |
|
462 } |
|
463 if (attributeId & EMPXMediaGeneralTitle) |
|
464 { |
|
465 MPX_DEBUG1(" EMPXMediaGeneralTitle"); |
|
466 |
|
467 TPtrC album( MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) ); |
|
468 aMedia.SetTextValueL(KMPXMediaGeneralTitle, |
|
469 MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName)); |
|
470 MPX_DEBUG2(" Album[%S]", &album ); |
|
471 } |
|
472 if (attributeId & EMPXMediaGeneralCount) |
|
473 { |
|
474 MPX_DEBUG1(" EMPXMediaGeneralCount"); |
|
475 |
|
476 TInt songCount = GetSongsCountL(KDbManagerAllDrives, |
|
477 aRecord.ColumnInt64(EAlbumUniqueId)); |
|
478 aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount ); |
|
479 MPX_DEBUG2(" SongCount[%d]", songCount ); |
|
480 } |
|
481 } // end if contentId == KMPXMediaIdGeneral |
|
482 else if ( contentId == KMPXMediaIdMusic ) |
|
483 { |
|
484 if (attributeId & EMPXMediaMusicArtist) |
|
485 { |
|
486 MPX_DEBUG1(" EMPXMediaMusicArtist"); |
|
487 |
|
488 TPtrC artistName(KNullDesC); |
|
489 |
|
490 // if album is unknown, ignore arist name |
|
491 if (MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) != KNullDesC) |
|
492 { |
|
493 artistName.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumArtistName)); |
|
494 } |
|
495 |
|
496 aMedia.SetTextValueL(KMPXMediaMusicArtist, artistName); |
|
497 MPX_DEBUG2(" Artist[%S]", &artistName); |
|
498 } |
|
499 |
|
500 if (attributeId & EMPXMediaMusicAlbum) |
|
501 { |
|
502 MPX_DEBUG1(" EMPXMediaMusicAlbum"); |
|
503 |
|
504 TPtrC albumName(KNullDesC); |
|
505 TPtrC album( MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) ); |
|
506 |
|
507 |
|
508 // if album is unknown |
|
509 if ( album != KNullDesC) |
|
510 { |
|
511 albumName.Set(album); |
|
512 } |
|
513 |
|
514 aMedia.SetTextValueL(KMPXMediaMusicAlbum, albumName); |
|
515 MPX_DEBUG2(" Album[%S]", &albumName); |
|
516 } |
|
517 if (attributeId & EMPXMediaMusicAlbumArtFileName) |
|
518 { |
|
519 MPX_DEBUG1(" EMPXMediaMusicAlbumArtFileName"); |
|
520 |
|
521 TPtrC art(KNullDesC); |
|
522 |
|
523 // if album is unknown, ignore album art name |
|
524 if (MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumName) != KNullDesC) |
|
525 { |
|
526 art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EAlbumArt)); |
|
527 } |
|
528 |
|
529 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art); |
|
530 MPX_DEBUG2(" Art[%S]", &art); |
|
531 } |
|
532 } |
|
533 } // end for |
|
534 |
|
535 aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
536 aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, iCategory); |
|
537 } |
|
538 |
|
539 // ---------------------------------------------------------------------------- |
|
540 // CMPXDbAlbum::GenerateAlbumFieldsValuesL |
|
541 // ---------------------------------------------------------------------------- |
|
542 // |
|
543 void CMPXDbAlbum::GenerateAlbumFieldsValuesL(const CMPXMedia& aMedia, CDesCArray& aFields, CDesCArray& aValues) |
|
544 { |
|
545 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
546 { |
|
547 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
|
548 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
|
549 } |
|
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 } |
|
557 |
|
558 // ---------------------------------------------------------------------------- |
|
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 |
|
578 // ---------------------------------------------------------------------------- |
|
579 // |
|
580 HBufC* CMPXDbAlbum::AlbumartForAlbumL(const TUint32 aId, TPtrC aArt) |
|
581 { |
|
582 return iObserver.HandleAlbumartForAlbumL(aId, aArt); |
|
583 } |
|
584 |
|
585 // ---------------------------------------------------------------------------- |
|
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 |
|
622 // Unknown album is stored in the database as NULL (name field). |
|
623 // The first 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. |
|
625 // |
|
626 // 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 |
|
628 // requested. |
|
629 // ---------------------------------------------------------------------------- |
|
630 // |
|
631 void CMPXDbAlbum::ProcessAlbumRecordSetL( |
|
632 const TArray<TMPXAttribute>& aAttrs, |
|
633 RSqlStatement& aRecordset, |
|
634 CMPXMediaArray& aMediaArray) |
|
635 { |
|
636 // populate the array |
|
637 TBool unknownRecord(EFalse); |
|
638 TBool firstUnknownRecord(EFalse); |
|
639 CMPXMedia* unknownMedia(NULL); |
|
640 TInt prevId(0); |
|
641 TInt err(KErrNone); |
|
642 |
|
643 TInt pPath(0); |
|
644 if (aMediaArray.Count()) |
|
645 { |
|
646 CMPXMedia* pMedia = aMediaArray[0]; |
|
647 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
|
648 { // Query excuted by OpenL |
|
649 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
|
650 MPX_ASSERT(pPath); |
|
651 } |
|
652 } |
|
653 RArray<TMPXItemId> ids; |
|
654 CleanupClosePushL(ids); |
|
655 |
|
656 while ((err = aRecordset.Next()) == KSqlAtRow) |
|
657 { |
|
658 TUint32 rowId(aRecordset.ColumnInt64(EAlbumUniqueId)); |
|
659 if (prevId == rowId) |
|
660 { |
|
661 continue; |
|
662 } |
|
663 |
|
664 prevId = rowId; |
|
665 CMPXMedia* media = CMPXMedia::NewL(); |
|
666 CleanupStack::PushL(media); |
|
667 |
|
668 UpdateMediaL(aRecordset, aAttrs, *media); |
|
669 |
|
670 if (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumName).Length() == 0) |
|
671 { |
|
672 if (!unknownMedia) |
|
673 { |
|
674 unknownMedia = media; |
|
675 firstUnknownRecord = ETrue; |
|
676 } |
|
677 unknownRecord = ETrue; |
|
678 } |
|
679 |
|
680 if (!unknownRecord) |
|
681 { |
|
682 if (media->IsSupported(KMPXMediaGeneralId) && pPath) |
|
683 { |
|
684 ids.AppendL(media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
685 } |
|
686 aMediaArray.AppendL(*media); |
|
687 } |
|
688 |
|
689 if (!firstUnknownRecord) |
|
690 { |
|
691 CleanupStack::PopAndDestroy(media); |
|
692 } |
|
693 else |
|
694 { |
|
695 firstUnknownRecord = EFalse; |
|
696 } |
|
697 |
|
698 unknownRecord = EFalse; |
|
699 } // end while |
|
700 |
|
701 if (err != KSqlAtEnd) |
|
702 { |
|
703 User::LeaveIfError(err); |
|
704 } |
|
705 |
|
706 if (unknownMedia) |
|
707 { |
|
708 if (unknownMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
|
709 { |
|
710 ids.AppendL(unknownMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
711 } |
|
712 aMediaArray.AppendL(*unknownMedia); |
|
713 CleanupStack::PopAndDestroy(unknownMedia); |
|
714 } |
|
715 |
|
716 // Append ids to the returned path |
|
717 if (pPath) |
|
718 { |
|
719 ((CMPXCollectionPath*)pPath)->AppendL(ids.Array()); |
|
720 } |
|
721 CleanupStack::PopAndDestroy(&ids); |
|
722 } |
|
723 |
|
724 // End of File |