53
|
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 |
// get songs count from all drives
|
|
248 |
TInt songCount = GetSongsCountL( KDbManagerAllDrives,
|
|
249 |
aRecord.ColumnInt64( EArtistUniqueId ) );
|
|
250 |
aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); // mod by anjokela
|
|
251 |
|
|
252 |
MPX_DEBUG1(" EMPXMediaGeneralCount");
|
|
253 |
MPX_DEBUG2(" SongCount[%d]", songCount);
|
|
254 |
}
|
|
255 |
} // end if contentId == KMPXMediaIdGeneral
|
|
256 |
else if ( contentId == KMPXMediaIdMusic )
|
|
257 |
{
|
|
258 |
if (attributeId & EMPXMediaMusicAlbumArtFileName)
|
|
259 |
{
|
|
260 |
MPX_DEBUG1(" EMPXMediaMusicAlbumArtFileName");
|
|
261 |
TPtrC art(KNullDesC);
|
|
262 |
art.Set(MPXDbCommonUtil::GetColumnTextL(aRecord, EArtistArt));
|
|
263 |
aMedia.SetTextValueL(KMPXMediaMusicAlbumArtFileName, art);
|
|
264 |
MPX_DEBUG2(" Art[%S]", &art);
|
|
265 |
}
|
|
266 |
}
|
|
267 |
} // end for
|
|
268 |
|
|
269 |
aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
|
|
270 |
aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, iCategory);
|
|
271 |
}
|
|
272 |
|
|
273 |
// ----------------------------------------------------------------------------
|
|
274 |
// CMPXDbArtist::GenerateArtistFieldsValuesL
|
|
275 |
// ----------------------------------------------------------------------------
|
|
276 |
//
|
|
277 |
void CMPXDbArtist::GenerateArtistFieldsValuesL(const CMPXMedia& aMedia, CDesCArray& aFields, CDesCArray& aValues)
|
|
278 |
{
|
|
279 |
if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName))
|
|
280 |
{
|
|
281 |
const TDesC& albumArtFilename = aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen);
|
|
282 |
MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArt, albumArtFilename);
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
// ----------------------------------------------------------------------------
|
|
287 |
// CMPXDbArtist::GetAlbumsCountL
|
|
288 |
// ----------------------------------------------------------------------------
|
|
289 |
//
|
|
290 |
TInt CMPXDbArtist::GetAlbumsCountL(TUint32 aId)
|
|
291 |
{
|
|
292 |
MPX_FUNC("CMPXDbArtist::GetAlbumsCountL");
|
|
293 |
|
|
294 |
return iObserver.HandleGetAlbumsCountForArtistL(aId);
|
|
295 |
}
|
|
296 |
|
|
297 |
// ----------------------------------------------------------------------------
|
|
298 |
// CMPXDbArtist::GetAllCategoryItemsL
|
|
299 |
// ----------------------------------------------------------------------------
|
|
300 |
//
|
|
301 |
void CMPXDbArtist::GetAllCategoryItemsL(
|
|
302 |
const TArray<TMPXAttribute>& aAttrs,
|
|
303 |
CMPXMediaArray& aMediaArray)
|
|
304 |
{
|
|
305 |
MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL");
|
|
306 |
HBufC* query = PreProcessStringLC(KQueryArtistAll);
|
|
307 |
RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query));
|
|
308 |
CleanupStack::PopAndDestroy(query);
|
|
309 |
CleanupClosePushL(recordset);
|
|
310 |
ProcessRecordsetL(aAttrs, recordset, aMediaArray);
|
|
311 |
CleanupStack::PopAndDestroy(&recordset);
|
|
312 |
}
|
|
313 |
|
|
314 |
// ----------------------------------------------------------------------------
|
|
315 |
// CMPXDbArtist::UpdateItemL
|
|
316 |
// ----------------------------------------------------------------------------
|
|
317 |
//
|
|
318 |
void CMPXDbArtist::UpdateItemL(
|
|
319 |
TUint32 aId,
|
|
320 |
const CMPXMedia& aMedia,
|
|
321 |
TInt aDriveId,
|
|
322 |
CMPXMessageArray* aItemChangedMessages)
|
|
323 |
{
|
|
324 |
MPX_FUNC("CMPXDbAlbum::UpdateItemL");
|
|
325 |
|
|
326 |
CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EArtistFieldCount);
|
|
327 |
CleanupStack::PushL(fields);
|
|
328 |
CDesCArrayFlat* values = new (ELeave) CDesCArrayFlat(EArtistFieldCount);
|
|
329 |
CleanupStack::PushL(values);
|
|
330 |
|
|
331 |
// process the media parameter and construct the fields and values array
|
|
332 |
GenerateArtistFieldsValuesL(aMedia, *fields, *values);
|
|
333 |
|
|
334 |
// construct the SET string
|
|
335 |
HBufC* setStr = MPXDbCommonUtil::StringFromArraysLC(*fields, *values, KMCEqualSign, KMCCommaSign);
|
|
336 |
|
|
337 |
if (setStr->Length())
|
|
338 |
{
|
|
339 |
// execute the query
|
|
340 |
iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, aId);
|
|
341 |
MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified,
|
|
342 |
EMPXArtist, KDBPluginUid, ETrue, 0 );
|
|
343 |
}
|
|
344 |
|
|
345 |
CleanupStack::PopAndDestroy(setStr);
|
|
346 |
CleanupStack::PopAndDestroy(values);
|
|
347 |
CleanupStack::PopAndDestroy(fields);
|
|
348 |
}
|
|
349 |
// ----------------------------------------------------------------------------
|
|
350 |
// CMPXDbAlbum::CreateTableL
|
|
351 |
// ----------------------------------------------------------------------------
|
|
352 |
//
|
|
353 |
void CMPXDbArtist::CreateTableL(
|
|
354 |
RSqlDatabase& aDatabase,
|
|
355 |
TBool /* aCorruptTable */)
|
|
356 |
{
|
|
357 |
MPX_FUNC("CMPXDbCategory::CreateTableL");
|
|
358 |
|
|
359 |
// create the table
|
|
360 |
HBufC* query = PreProcessStringLC(KArtistCreateTable);
|
|
361 |
User::LeaveIfError(aDatabase.Exec(*query));
|
|
362 |
CleanupStack::PopAndDestroy(query);
|
|
363 |
|
|
364 |
// do not create an index on the Name field
|
|
365 |
// as it only slows down the insert/update queries overall
|
|
366 |
}
|
|
367 |
|
|
368 |
// ----------------------------------------------------------------------------
|
|
369 |
// CMPXDbAlbum::CheckTableL
|
|
370 |
// ----------------------------------------------------------------------------
|
|
371 |
//
|
|
372 |
TBool CMPXDbArtist::CheckTableL(
|
|
373 |
RSqlDatabase& aDatabase)
|
|
374 |
{
|
|
375 |
MPX_FUNC("CMPXDbCategory::CheckTableL");
|
|
376 |
|
|
377 |
HBufC* query = PreProcessStringLC(KArtistCheckTable);
|
|
378 |
TBool check(DoCheckTable(aDatabase, *query));
|
|
379 |
CleanupStack::PopAndDestroy(query);
|
|
380 |
|
|
381 |
return check;
|
|
382 |
}
|
|
383 |
|
|
384 |
// End of File
|