|
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 the auto playlist functionality. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <mpxlog.h> |
|
21 #include <mpxcollectiondbhgres.rsg> |
|
22 #include <sqldb.h> |
|
23 |
|
24 #include "mpxresource.h" |
|
25 #include "mpxdbcommonutil.h" |
|
26 #include "mpxdbmanager.h" |
|
27 #include "mpxdbutil.h" |
|
28 #include "mpxcollectiondbdef.h" |
|
29 #include "mpxdbautoplaylist.h" |
|
30 #include "mpxdbpluginqueries.h" |
|
31 |
|
32 const TInt KMPXTableDefaultIndex = 0; |
|
33 const TInt32 KMPXRecentlyPlayedPlaylistId = 0x20000000; |
|
34 const TInt32 KMPXMostPlayedPlaylistId = 0x20000001; |
|
35 const TInt32 KMPXRecentlyAddedPlaylistId = 0x20000002; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS ============================== |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // Two-phased constructor. |
|
41 // ---------------------------------------------------------------------------- |
|
42 // |
|
43 CMPXDbAutoPlaylist* CMPXDbAutoPlaylist::NewL( |
|
44 CMPXDbManager& aDbManager, |
|
45 RFs& aFs, |
|
46 CMPXResource& aResource) |
|
47 { |
|
48 MPX_FUNC("CMPXDbAutoPlaylist::NewL"); |
|
49 |
|
50 CMPXDbAutoPlaylist* self = CMPXDbAutoPlaylist::NewLC(aDbManager, aFs, aResource); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // Two-phased constructor. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CMPXDbAutoPlaylist* CMPXDbAutoPlaylist::NewLC( |
|
60 CMPXDbManager& aDbManager, |
|
61 RFs& aFs, |
|
62 CMPXResource& aResource) |
|
63 { |
|
64 MPX_FUNC("CMPXDbAutoPlaylist::NewLC"); |
|
65 |
|
66 CMPXDbAutoPlaylist* self = new (ELeave) CMPXDbAutoPlaylist(aDbManager); |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(aFs, aResource); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // Destructor |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CMPXDbAutoPlaylist::~CMPXDbAutoPlaylist() |
|
77 { |
|
78 MPX_FUNC("CMPXDbAutoPlaylist::~CMPXDbAutoPlaylist"); |
|
79 |
|
80 delete iRecentlyPlayedPlaylist; |
|
81 delete iMostPlayedPlaylist; |
|
82 delete iRecentlyAddedPlaylist; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // Constructor |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 CMPXDbAutoPlaylist::CMPXDbAutoPlaylist(CMPXDbManager& aDbManager) |
|
90 : iDbManager(aDbManager) |
|
91 { |
|
92 MPX_FUNC("CMPXDbAutoPlaylist::CMPXDbAutoPlaylist"); |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // Second phase constructor. |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 void CMPXDbAutoPlaylist::ConstructL( |
|
100 RFs& /*aFs*/, |
|
101 CMPXResource& aResource) |
|
102 { |
|
103 MPX_FUNC("CMPXDbAutoPlaylist::ConstructL"); |
|
104 |
|
105 iRecentlyPlayedPlaylist = aResource.ReadHBufCL(R_MC_RECENTLY_PLAYED_PLAYLIST); |
|
106 iMostPlayedPlaylist = aResource.ReadHBufCL(R_MC_MOST_PLAYED_PLAYLIST); |
|
107 iRecentlyAddedPlaylist = aResource.ReadHBufCL(R_MC_RECENTLY_ADDED_PLAYLIST); |
|
108 |
|
109 iRecentlyPlayedPlaylistId = KMPXRecentlyPlayedPlaylistId; |
|
110 iMostPlayedPlaylistId = KMPXMostPlayedPlaylistId; |
|
111 iRecentlyAddedPlaylistId = KMPXRecentlyAddedPlaylistId; |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CMPXDbAutoPlaylist::AutoPlaylistIdL |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 TUint32 CMPXDbAutoPlaylist::AutoPlaylistIdL( |
|
119 TMPXAutoPlaylistType aPlaylistType) |
|
120 { |
|
121 MPX_FUNC("CMPXDbAutoPlaylist::AutoPlaylistIdL"); |
|
122 |
|
123 TUint32 id(0); |
|
124 switch (aPlaylistType) |
|
125 { |
|
126 case EMPXRecentlyPlayedPlaylist: |
|
127 { |
|
128 id = iRecentlyPlayedPlaylistId; |
|
129 } |
|
130 break; |
|
131 |
|
132 case EMPXMostPlayedPlaylist: |
|
133 { |
|
134 id = iMostPlayedPlaylistId; |
|
135 } |
|
136 break; |
|
137 |
|
138 case EMPXRecentlyAddedPlaylist: |
|
139 { |
|
140 id = iRecentlyAddedPlaylistId; |
|
141 } |
|
142 break; |
|
143 |
|
144 default: |
|
145 User::Leave(KErrNotSupported); |
|
146 } |
|
147 |
|
148 return id; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CMPXDbAutoPlaylist::AutoPlaylistNameL |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 TPtrC CMPXDbAutoPlaylist::AutoPlaylistNameL( |
|
156 TUint32 aPlaylistId) |
|
157 { |
|
158 MPX_FUNC("CMPXDbAutoPlaylist::AutoPlaylistNameL"); |
|
159 |
|
160 TPtrC ptr; |
|
161 if (aPlaylistId == iRecentlyPlayedPlaylistId) |
|
162 { |
|
163 ptr.Set(*iRecentlyPlayedPlaylist); |
|
164 } |
|
165 else if (aPlaylistId == iMostPlayedPlaylistId) |
|
166 { |
|
167 ptr.Set(*iMostPlayedPlaylist); |
|
168 } |
|
169 else if (aPlaylistId == iRecentlyAddedPlaylistId) |
|
170 { |
|
171 ptr.Set(*iRecentlyAddedPlaylist); |
|
172 } |
|
173 else |
|
174 { |
|
175 User::Leave(KErrNotSupported); |
|
176 } |
|
177 |
|
178 return ptr; |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // CMPXDbAutoPlaylist::AutoPlaylistTypeL |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 TMPXAutoPlaylistType CMPXDbAutoPlaylist::AutoPlaylistTypeL( |
|
186 TUint32 aPlaylistId) |
|
187 { |
|
188 MPX_FUNC("CMPXDbAutoPlaylist::AutoPlaylistTypeL"); |
|
189 |
|
190 TMPXAutoPlaylistType type(EMPXNoAutoPlaylist); |
|
191 if (aPlaylistId == iRecentlyPlayedPlaylistId) |
|
192 { |
|
193 type = EMPXRecentlyPlayedPlaylist; |
|
194 } |
|
195 else if (aPlaylistId == iMostPlayedPlaylistId) |
|
196 { |
|
197 type = EMPXMostPlayedPlaylist; |
|
198 } |
|
199 else if (aPlaylistId == iRecentlyAddedPlaylistId) |
|
200 { |
|
201 type = EMPXRecentlyAddedPlaylist; |
|
202 } |
|
203 else |
|
204 { |
|
205 // do nothing |
|
206 } |
|
207 |
|
208 return type; |
|
209 } |
|
210 |
|
211 // ---------------------------------------------------------------------------- |
|
212 // CMPXDbAutoPlaylist::GetPlaylistL |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 void CMPXDbAutoPlaylist::GetPlaylistL( |
|
216 TUint32 aPlaylistId, |
|
217 const TArray<TMPXAttribute>& aAttrs, |
|
218 CMPXMedia& aMedia) |
|
219 { |
|
220 MPX_FUNC("CMPXDbAutoPlaylist::GetPlaylistL"); |
|
221 |
|
222 if (EMPXNoAutoPlaylist == AutoPlaylistTypeL(aPlaylistId)) |
|
223 { |
|
224 User::Leave(KErrNotSupported); |
|
225 } |
|
226 |
|
227 UpdateMediaL(aPlaylistId, aAttrs, aMedia); |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // CMPXDbAutoPlaylist::GetAllPlaylistsL |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 void CMPXDbAutoPlaylist::GetAllPlaylistsL( |
|
235 CMPXMediaArray& aMediaArray) |
|
236 { |
|
237 MPX_FUNC("CMPXDbAutoPlaylist::GetAllPlaylistsL"); |
|
238 |
|
239 MPX_ASSERT(aMediaArray.Count()); |
|
240 MPX_ASSERT(aMediaArray[0]->IsSupported(KMPXMediaGeneralValue)); |
|
241 TInt pPath = aMediaArray[0]->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
|
242 MPX_ASSERT(pPath); |
|
243 MPXDbCommonUtil::AppendMediaL(aMediaArray, *iMostPlayedPlaylist, EMPXItem, |
|
244 EMPXPlaylist, iMostPlayedPlaylistId, EMPXWrite); |
|
245 TInt count = aMediaArray.Count(); |
|
246 TMPXItemId id = aMediaArray[count-1]->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
247 if (count==2) |
|
248 { // the first playlist |
|
249 if (((CMPXCollectionPath*)pPath)->Id()==KMPXInvalidItemId) |
|
250 { // Remove top level with invalid id |
|
251 ((CMPXCollectionPath*)pPath)->Back(); |
|
252 } |
|
253 ((CMPXCollectionPath*)pPath)->AppendL(id); |
|
254 } |
|
255 else |
|
256 { // append the end |
|
257 ((CMPXCollectionPath*)pPath)->InsertL(id, |
|
258 ((CMPXCollectionPath*)pPath)->Count()); |
|
259 } |
|
260 TInt songCount = 0; |
|
261 TInt duration = 0; |
|
262 GetPlaylistDetailsL(EMPXMostPlayedPlaylist, songCount, duration); |
|
263 aMediaArray[count-1]->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); |
|
264 aMediaArray[count-1]->SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, duration); |
|
265 |
|
266 MPXDbCommonUtil::AppendMediaL(aMediaArray, *iRecentlyPlayedPlaylist, EMPXItem, |
|
267 EMPXPlaylist, iRecentlyPlayedPlaylistId, EMPXWrite); |
|
268 id = aMediaArray[count]->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
269 ((CMPXCollectionPath*)pPath)->InsertL(id, ((CMPXCollectionPath*)pPath)->Count()); |
|
270 songCount = 0; |
|
271 duration = 0; |
|
272 GetPlaylistDetailsL(EMPXRecentlyPlayedPlaylist, songCount, duration); |
|
273 aMediaArray[count]->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); |
|
274 aMediaArray[count]->SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, duration); |
|
275 |
|
276 MPXDbCommonUtil::AppendMediaL(aMediaArray, *iRecentlyAddedPlaylist, EMPXItem, |
|
277 EMPXPlaylist, iRecentlyAddedPlaylistId, EMPXWrite); |
|
278 id = aMediaArray[count+1]->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
279 ((CMPXCollectionPath*)pPath)->InsertL(id, ((CMPXCollectionPath*)pPath)->Count()); |
|
280 songCount = 0; |
|
281 duration = 0; |
|
282 GetPlaylistDetailsL(EMPXRecentlyAddedPlaylist, songCount, duration); |
|
283 aMediaArray[count+1]->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount); |
|
284 aMediaArray[count+1]->SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, duration); |
|
285 } |
|
286 |
|
287 // ---------------------------------------------------------------------------- |
|
288 // CMPXDbAutoPlaylist::GetPlaylistDetails |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 void CMPXDbAutoPlaylist::GetPlaylistDetailsL(TMPXAutoPlaylistType aType, TInt& aCount, TInt& aDuration) |
|
292 { |
|
293 MPX_FUNC("CMPXDbAutoPlaylist::GetPlaylistDetails"); |
|
294 |
|
295 HBufC* query = NULL; |
|
296 |
|
297 switch ( aType ) |
|
298 { |
|
299 case EMPXMostPlayedPlaylist: |
|
300 query = HBufC::NewLC(KQueryMusicGetDurationMostPlayed().Length() + KMCIntegerLen); |
|
301 query->Des().Format(KQueryMusicGetDurationMostPlayed(), KMPXMaxMostPlayedSongs); |
|
302 break; |
|
303 case EMPXRecentlyPlayedPlaylist: |
|
304 query = HBufC::NewLC(KQueryMusicGetDurationRecentlyPlayed().Length() + KMCIntegerLen); |
|
305 query->Des().Format(KQueryMusicGetDurationRecentlyPlayed(), KMPXMaxRecentlyPlayedSongs); |
|
306 break; |
|
307 case EMPXRecentlyAddedPlaylist: |
|
308 query = HBufC::NewLC(KQueryMusicGetDurationRecentlyAdded().Length()); |
|
309 query->Des().Append(KQueryMusicGetDurationRecentlyAdded()); |
|
310 break; |
|
311 default: |
|
312 User::Leave(KErrArgument); |
|
313 break; |
|
314 } |
|
315 |
|
316 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); |
|
317 CleanupClosePushL(recordset); |
|
318 |
|
319 TInt sum(0); |
|
320 TInt err(KErrNone); |
|
321 while ((err = recordset.Next()) == KSqlAtRow) |
|
322 { |
|
323 aCount++; |
|
324 sum += recordset.ColumnInt64(KMPXTableDefaultIndex); |
|
325 } |
|
326 |
|
327 CleanupStack::PopAndDestroy(&recordset); |
|
328 CleanupStack::PopAndDestroy(query); |
|
329 |
|
330 if (err != KSqlAtEnd) |
|
331 { |
|
332 User::Leave(KErrCorrupt); |
|
333 } |
|
334 |
|
335 aDuration = sum; |
|
336 MPX_DEBUG3(" Count[%d], Duration[%d]", aCount, aDuration); |
|
337 } |
|
338 |
|
339 // ---------------------------------------------------------------------------- |
|
340 // CMPXDbAutoPlaylist::UpdateMediaL |
|
341 // ---------------------------------------------------------------------------- |
|
342 // |
|
343 void CMPXDbAutoPlaylist::UpdateMediaL( |
|
344 TUint32 aPlaylistId, |
|
345 const TArray<TMPXAttribute>& aAttrs, |
|
346 CMPXMedia& aMedia) |
|
347 { |
|
348 MPX_FUNC("CMPXDbAutoPlaylist::UpdateMediaL"); |
|
349 |
|
350 TInt count(aAttrs.Count()); |
|
351 for (TInt i = 0; i < count; ++i) |
|
352 { |
|
353 TInt contentId(aAttrs[i].ContentId()); |
|
354 |
|
355 if (contentId == KMPXMediaIdGeneral) |
|
356 { |
|
357 TUint attributeId(aAttrs[i].AttributeId()); |
|
358 |
|
359 if (attributeId & EMPXMediaGeneralId) |
|
360 { |
|
361 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, aPlaylistId); |
|
362 } |
|
363 if (attributeId & EMPXMediaGeneralCollectionId ) |
|
364 { |
|
365 aMedia.SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId, |
|
366 TUid::Uid(KDBPluginUid)); |
|
367 } |
|
368 if (attributeId & EMPXMediaGeneralTitle) |
|
369 { |
|
370 if (aPlaylistId == iRecentlyPlayedPlaylistId) |
|
371 { |
|
372 aMedia.SetTextValueL(KMPXMediaGeneralTitle, *iRecentlyPlayedPlaylist); |
|
373 } |
|
374 else if (aPlaylistId == iMostPlayedPlaylistId) |
|
375 { |
|
376 aMedia.SetTextValueL(KMPXMediaGeneralTitle,*iMostPlayedPlaylist); |
|
377 } |
|
378 else if (aPlaylistId == iRecentlyAddedPlaylistId) |
|
379 { |
|
380 aMedia.SetTextValueL(KMPXMediaGeneralTitle, *iRecentlyAddedPlaylist); |
|
381 } |
|
382 else |
|
383 { |
|
384 User::Leave(KErrArgument); |
|
385 } |
|
386 } |
|
387 if (attributeId & EMPXMediaGeneralSynchronized) |
|
388 { |
|
389 aMedia.SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized, EFalse); |
|
390 } |
|
391 if (attributeId & EMPXMediaGeneralNonPermissibleActions) |
|
392 { |
|
393 aMedia.SetTObjectValueL<TMPXGeneralNonPermissibleActions>( |
|
394 KMPXMediaGeneralNonPermissibleActions, EMPXWrite); |
|
395 } |
|
396 // EMPXMediaGeneralCount, EMPXMediaGeneralDate, EMPXMediaGeneralDuration, |
|
397 // EMPXMediaGeneralUri, EMPXMediaGeneralDrive, and EMPXMediaGeneralFlags |
|
398 // attributes are not applicable for auto-playlists |
|
399 } // end if contentId == KMPXMediaIdGeneral |
|
400 } // end for |
|
401 |
|
402 aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
403 aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
|
404 } |
|
405 |
|
406 // End of File |