|
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 Artist table |
|
15 * |
|
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 "mpxmediamusicdefs.h" |
|
28 #include "mpxdbmanager.h" |
|
29 |
|
30 #include "mpxcollectiondbdef.h" |
|
31 #include "mpxdbpluginqueries.h" |
|
32 #include "mpxdbutil.h" |
|
33 #include "mpxdbartist.h" |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS ============================== |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // Two-phased constructor. |
|
41 // ---------------------------------------------------------------------------- |
|
42 // |
|
43 CMPXDbArtist* CMPXDbArtist::NewL( |
|
44 CMPXDbManager& aDbManager, |
|
45 TMPXGeneralCategory aCategory, |
|
46 MMPXDbArtistObserver& aObserver) |
|
47 { |
|
48 MPX_FUNC("CMPXDbArtist::NewL"); |
|
49 |
|
50 CMPXDbArtist* self = CMPXDbArtist::NewLC(aDbManager, aCategory, aObserver); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // Two-phased constructor. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CMPXDbArtist* CMPXDbArtist::NewLC( |
|
60 CMPXDbManager& aDbManager, |
|
61 TMPXGeneralCategory aCategory, |
|
62 MMPXDbArtistObserver& aObserver) |
|
63 { |
|
64 MPX_FUNC("CMPXDbArtist::NewLC"); |
|
65 |
|
66 CMPXDbArtist* self = new (ELeave) CMPXDbArtist(aDbManager, aCategory, aObserver); |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // Destructor |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CMPXDbArtist::~CMPXDbArtist() |
|
77 { |
|
78 MPX_FUNC("CMPXDbArtist::~CMPXDbArtist"); |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // Constructor |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 CMPXDbArtist::CMPXDbArtist( |
|
86 CMPXDbManager& aDbManager, |
|
87 TMPXGeneralCategory aCategory, |
|
88 MMPXDbArtistObserver& aObserver) : |
|
89 CMPXDbCategory(aDbManager, aCategory), |
|
90 iObserver(aObserver) |
|
91 { |
|
92 MPX_FUNC("CMPXDbArtist::CMPXDbArtist"); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // Second phase constructor. |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 void CMPXDbArtist::ConstructL() |
|
100 { |
|
101 MPX_FUNC("CMPXDbArtist::ConstructL"); |
|
102 |
|
103 BaseConstructL(); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CMPXDbArtist::AddItemL |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 TUint32 CMPXDbArtist::AddItemL( |
|
111 const TDesC& aName, |
|
112 const TDesC& aArt, |
|
113 TInt aDriveId, |
|
114 TBool& aNewRecord, |
|
115 TBool aCaseSensitive) |
|
116 { |
|
117 MPX_FUNC("CMPXDbArtist::AddItemL"); |
|
118 |
|
119 // try to find the item first |
|
120 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
|
121 aName, aCaseSensitive)); |
|
122 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
|
123 |
|
124 if (aNewRecord) |
|
125 { |
|
126 // insert new |
|
127 HBufC* query = PreProcessStringLC(KQueryArtistInsert); |
|
128 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
|
129 HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); |
|
130 |
|
131 iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1, art); |
|
132 |
|
133 CleanupStack::PopAndDestroy(art); |
|
134 CleanupStack::PopAndDestroy(name); |
|
135 CleanupStack::PopAndDestroy(query); |
|
136 } |
|
137 else |
|
138 { |
|
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 art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt)); |
|
155 |
|
156 // the current one is Unknown and the new one is Not Unknown |
|
157 if ( art == KNullDesC && aArt != KNullDesC ) |
|
158 { |
|
159 HBufC* artReplaceSingleQuote = |
|
160 MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); |
|
161 _LIT( KFormatArt, "Art=\'%S\'" ); |
|
162 HBufC* setStr = HBufC::NewLC(256); |
|
163 setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); |
|
164 |
|
165 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId); |
|
166 CleanupStack::PopAndDestroy(setStr); |
|
167 CleanupStack::PopAndDestroy(artReplaceSingleQuote); |
|
168 } |
|
169 |
|
170 CleanupStack::PopAndDestroy(&recordset); |
|
171 |
|
172 // increment the number of songs for the category |
|
173 query = PreProcessStringLC(KQueryCategoryIncrementSongCount); |
|
174 iDbManager.ExecuteQueryL(aDriveId, *query, rowId); |
|
175 CleanupStack::PopAndDestroy(query); |
|
176 } |
|
177 |
|
178 return rowId; |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // CMPXDbArtist::IsUnknownArtistL |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 TBool CMPXDbArtist::IsUnknownArtistL(TUint32 aId) |
|
186 { |
|
187 MPX_FUNC("CMPXDbArtist::IsUnknownArtistL"); |
|
188 |
|
189 HBufC* name = GetNameL(aId); |
|
190 |
|
191 TInt ret = EFalse; |
|
192 if (*name == KNullDesC) |
|
193 { |
|
194 ret = ETrue; |
|
195 } |
|
196 delete name; |
|
197 |
|
198 return ret; |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CMPXDbArtist::UpdateMediaL |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 void CMPXDbArtist::UpdateMediaL( |
|
206 RSqlStatement& aRecord, |
|
207 const TArray<TMPXAttribute>& aAttrs, |
|
208 CMPXMedia& aMedia) |
|
209 { |
|
210 MPX_FUNC("CMPXDbArtist::UpdateMediaL"); |
|
211 |
|
212 TInt count(aAttrs.Count()); |
|
213 for (TInt i = 0; i < count; ++i) |
|
214 { |
|
215 TInt contentId(aAttrs[i].ContentId()); |
|
216 TUint attributeId(aAttrs[i].AttributeId()); |
|
217 |
|
218 if (contentId == KMPXMediaIdGeneral) |
|
219 { |
|
220 if (attributeId & EMPXMediaGeneralId) |
|
221 { |
|
222 MPX_DEBUG1(" EMPXMediaGeneralId"); |
|
223 |
|
224 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, |
|
225 aRecord.ColumnInt64(EArtistUniqueId)); |
|
226 MPX_DEBUG2(" Id[%d]", aRecord.ColumnInt64(EArtistUniqueId)); |
|
227 } |
|
228 if (attributeId & EMPXMediaGeneralTitle) |
|
229 { |
|
230 MPX_DEBUG1(" EMPXMediaGeneralTitle"); |
|
231 |
|
232 TPtrC artist( MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistName) ); |
|
233 aMedia.SetTextValueL(KMPXMediaGeneralTitle, |
|
234 MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistName)); |
|
235 |
|
236 MPX_DEBUG2(" Artist[%S]", &artist); |
|
237 } |
|
238 if (attributeId & EMPXMediaGeneralCount) |
|
239 { |
|
240 // TInt albumCount = GetAlbumsCountL(aRecord.ColumnInt64(EArtistUniqueId)); |
|
241 // aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount,albumCount); |
|
242 // MPX_DEBUG1(" EMPXMediaGeneralCount"); |
|
243 // MPX_DEBUG2(" AlbumCount[%d]", albumCount); |
|
244 TInt songCount = aRecord.ColumnInt64(EArtistSongCount); |
|
245 aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); // mod by anjokela |
|
246 |
|
247 MPX_DEBUG1(" EMPXMediaGeneralCount"); |
|
248 MPX_DEBUG2(" SongCount[%d]", songCount); |
|
249 } |
|
250 } // end if contentId == KMPXMediaIdGeneral |
|
251 else if ( contentId == KMPXMediaIdMusic ) |
|
252 { |
|
253 if (attributeId & EMPXMediaMusicAlbumArtFileName) |
|
254 { |
|
255 MPX_DEBUG1(" EMPXMediaMusicAlbumArtFileName"); |
|
256 TPtrC art(KNullDesC); |
|
257 art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistArt)); |
|
258 aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art); |
|
259 MPX_DEBUG2(" Art[%S]", &art); |
|
260 } |
|
261 } |
|
262 } // end for |
|
263 |
|
264 aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
265 aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, iCategory); |
|
266 } |
|
267 |
|
268 // ---------------------------------------------------------------------------- |
|
269 // CMPXDbArtist::GenerateArtistFieldsValuesL |
|
270 // ---------------------------------------------------------------------------- |
|
271 // |
|
272 void CMPXDbArtist::GenerateArtistFieldsValuesL(const CMPXMedia& aMedia, CDesCArray& aFields, CDesCArray& aValues) |
|
273 { |
|
274 if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) |
|
275 { |
|
276 const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen); |
|
277 MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename); |
|
278 } |
|
279 } |
|
280 |
|
281 // ---------------------------------------------------------------------------- |
|
282 // CMPXDbArtist::GetAlbumsCountL |
|
283 // ---------------------------------------------------------------------------- |
|
284 // |
|
285 TInt CMPXDbArtist::GetAlbumsCountL(TUint32 aId) |
|
286 { |
|
287 MPX_FUNC("CMPXDbArtist::GetAlbumsCountL"); |
|
288 |
|
289 return iObserver.HandleGetAlbumsCountForArtistL(aId); |
|
290 } |
|
291 |
|
292 // ---------------------------------------------------------------------------- |
|
293 // CMPXDbArtist::GetAllCategoryItemsL |
|
294 // ---------------------------------------------------------------------------- |
|
295 // |
|
296 void CMPXDbArtist::GetAllCategoryItemsL( |
|
297 const TArray<TMPXAttribute>& aAttrs, |
|
298 CMPXMediaArray& aMediaArray) |
|
299 { |
|
300 MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL"); |
|
301 HBufC* query = PreProcessStringLC(KQueryArtistAll); |
|
302 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); |
|
303 CleanupStack::PopAndDestroy(query); |
|
304 CleanupClosePushL(recordset); |
|
305 ProcessRecordsetL(aAttrs, recordset, aMediaArray); |
|
306 CleanupStack::PopAndDestroy(&recordset); |
|
307 } |
|
308 |
|
309 // ---------------------------------------------------------------------------- |
|
310 // CMPXDbArtist::UpdateItemL |
|
311 // ---------------------------------------------------------------------------- |
|
312 // |
|
313 void CMPXDbArtist::UpdateItemL( |
|
314 TUint32 aId, |
|
315 const CMPXMedia& aMedia, |
|
316 TInt aDriveId, |
|
317 CMPXMessageArray* aItemChangedMessages) |
|
318 { |
|
319 MPX_FUNC("CMPXDbAlbum::UpdateItemL"); |
|
320 |
|
321 CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EArtistFieldCount); |
|
322 CleanupStack::PushL(fields); |
|
323 CDesCArrayFlat* values = new (ELeave) CDesCArrayFlat(EArtistFieldCount); |
|
324 CleanupStack::PushL(values); |
|
325 |
|
326 // process the media parameter and construct the fields and values array |
|
327 GenerateArtistFieldsValuesL(aMedia, *fields, *values); |
|
328 |
|
329 // construct the SET string |
|
330 HBufC* setStr = MPXDbCommonUtil::StringFromArraysLC(*fields, *values, KMCEqualSign, KMCCommaSign); |
|
331 |
|
332 if (setStr->Length()) |
|
333 { |
|
334 // execute the query |
|
335 iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, aId); |
|
336 TInt oldSongId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2; |
|
337 MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified, |
|
338 EMPXArtist, KDBPluginUid, oldSongId ); |
|
339 } |
|
340 |
|
341 CleanupStack::PopAndDestroy(setStr); |
|
342 CleanupStack::PopAndDestroy(values); |
|
343 CleanupStack::PopAndDestroy(fields); |
|
344 } |
|
345 // ---------------------------------------------------------------------------- |
|
346 // CMPXDbAlbum::CreateTableL |
|
347 // ---------------------------------------------------------------------------- |
|
348 // |
|
349 void CMPXDbArtist::CreateTableL( |
|
350 RSqlDatabase& aDatabase, |
|
351 TBool /* aCorruptTable */) |
|
352 { |
|
353 MPX_FUNC("CMPXDbCategory::CreateTableL"); |
|
354 |
|
355 // create the table |
|
356 HBufC* query = PreProcessStringLC(KArtistCreateTable); |
|
357 User::LeaveIfError(aDatabase.Exec(*query)); |
|
358 CleanupStack::PopAndDestroy(query); |
|
359 |
|
360 // do not create an index on the Name field |
|
361 // as it only slows down the insert/update queries overall |
|
362 } |
|
363 |
|
364 // ---------------------------------------------------------------------------- |
|
365 // CMPXDbAlbum::CheckTableL |
|
366 // ---------------------------------------------------------------------------- |
|
367 // |
|
368 TBool CMPXDbArtist::CheckTableL( |
|
369 RSqlDatabase& aDatabase) |
|
370 { |
|
371 MPX_FUNC("CMPXDbCategory::CheckTableL"); |
|
372 |
|
373 HBufC* query = PreProcessStringLC(KArtistCheckTable); |
|
374 TBool check(DoCheckTable(aDatabase, *query)); |
|
375 CleanupStack::PopAndDestroy(query); |
|
376 |
|
377 return check; |
|
378 } |
|
379 |
|
380 // End of File |