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