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