1 /* |
|
2 * Copyright (c) 2009 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: Music Player collection data - private implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <thumbnaildata.h> |
|
19 #include <thumbnailobjectsource.h> |
|
20 |
|
21 #include <mpxmedia.h> |
|
22 #include <mpxmediacontainerdefs.h> |
|
23 #include <mpxmediaarray.h> |
|
24 #include <mpxmediageneraldefs.h> |
|
25 #include <mpxmediamusicdefs.h> |
|
26 |
|
27 #include "mpmpxcollectiondata_p.h" |
|
28 #include "mptrace.h" |
|
29 |
|
30 _LIT( KSong, " song" ); |
|
31 _LIT( KSongs, " songs" ); |
|
32 |
|
33 /*! |
|
34 \class MpMpxCollectionDataPrivate |
|
35 \brief Music Player collection data - private implementation. |
|
36 |
|
37 This is a private implementation of the collection data interface. |
|
38 */ |
|
39 |
|
40 /*! |
|
41 \internal |
|
42 */ |
|
43 MpMpxCollectionDataPrivate::MpMpxCollectionDataPrivate( MpMpxCollectionData *wrapper ) |
|
44 : q_ptr( wrapper ), |
|
45 iContainerMedia(0), |
|
46 iMediaArray(0), |
|
47 iContext( ECollectionContextUnknown ), |
|
48 iCachedRemovedItem ( 0 ) |
|
49 { |
|
50 TX_LOG |
|
51 } |
|
52 |
|
53 /*! |
|
54 \internal |
|
55 */ |
|
56 MpMpxCollectionDataPrivate::~MpMpxCollectionDataPrivate() |
|
57 { |
|
58 TX_ENTRY |
|
59 delete iContainerMedia; |
|
60 delete iCachedRemovedItem; |
|
61 TX_EXIT |
|
62 } |
|
63 |
|
64 /*! |
|
65 \internal |
|
66 */ |
|
67 TCollectionContext MpMpxCollectionDataPrivate::context() const |
|
68 { |
|
69 return iContext; |
|
70 } |
|
71 |
|
72 /*! |
|
73 \internal |
|
74 */ |
|
75 int MpMpxCollectionDataPrivate::count() const |
|
76 { |
|
77 if ( iMediaArray ) { |
|
78 return iMediaArray->Count(); |
|
79 } |
|
80 return 0; |
|
81 } |
|
82 |
|
83 /*! |
|
84 \internal |
|
85 */ |
|
86 QString MpMpxCollectionDataPrivate::collectionTitle() const |
|
87 { |
|
88 TX_ENTRY |
|
89 QString title; |
|
90 if ( iContainerMedia && iContainerMedia->IsSupported( KMPXMediaGeneralTitle ) ) { |
|
91 const TDesC& titleText = iContainerMedia->ValueText( KMPXMediaGeneralTitle ); |
|
92 if ( titleText.Compare( KNullDesC ) != 0 ) { |
|
93 title = QString::fromUtf16( titleText.Ptr(), titleText.Length() ); |
|
94 } |
|
95 } |
|
96 TX_EXIT_ARGS("title =" << title); |
|
97 return title; |
|
98 } |
|
99 |
|
100 /*! |
|
101 \internal |
|
102 */ |
|
103 QString MpMpxCollectionDataPrivate::itemData( int index, MpMpxCollectionData::DataType type ) const |
|
104 { |
|
105 TX_ENTRY_ARGS("index=" << index << ", type=" << type); |
|
106 QString data; |
|
107 TRAPD(err, DoGetDataL(index, type, data)); |
|
108 if ( err != KErrNone ) { |
|
109 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
110 } |
|
111 TX_EXIT |
|
112 return data; |
|
113 } |
|
114 |
|
115 /*! |
|
116 \internal |
|
117 */ |
|
118 bool MpMpxCollectionDataPrivate::isAutoPlaylist() |
|
119 { |
|
120 TX_ENTRY |
|
121 if ( iContext != ECollectionContextPlaylistSongs ) { |
|
122 TX_EXIT |
|
123 return false; |
|
124 } |
|
125 |
|
126 bool isAuto = false; |
|
127 TRAPD(err, isAuto = DoIsAutoPlaylistL()); |
|
128 if ( err == KErrNone ) { |
|
129 TX_LOG_ARGS("isAuto=" << isAuto); |
|
130 } |
|
131 else { |
|
132 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
133 } |
|
134 TX_EXIT |
|
135 return isAuto; |
|
136 } |
|
137 |
|
138 /*! |
|
139 \internal |
|
140 */ |
|
141 bool MpMpxCollectionDataPrivate::isAutoPlaylist( int index ) |
|
142 { |
|
143 TX_ENTRY_ARGS("index=" << index); |
|
144 if ( iContext != ECollectionContextPlaylists ) { |
|
145 TX_EXIT |
|
146 return false; |
|
147 } |
|
148 |
|
149 bool isAuto = false; |
|
150 TRAPD(err, isAuto = DoIsAutoPlaylistL(index)); |
|
151 if ( err == KErrNone ) { |
|
152 TX_LOG_ARGS("isAuto=" << isAuto); |
|
153 } |
|
154 else { |
|
155 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
156 } |
|
157 TX_EXIT |
|
158 return isAuto; |
|
159 } |
|
160 |
|
161 /*! |
|
162 \internal |
|
163 */ |
|
164 int MpMpxCollectionDataPrivate::itemCount( int index ) |
|
165 { |
|
166 TX_ENTRY_ARGS("index=" << index); |
|
167 int count = 0; |
|
168 TRAPD(err, count = DoGetItemCountL(index)); |
|
169 if ( err == KErrNone ) { |
|
170 TX_LOG_ARGS("count=" << count); |
|
171 } |
|
172 else { |
|
173 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
174 } |
|
175 TX_EXIT |
|
176 return count; |
|
177 } |
|
178 |
|
179 /*! |
|
180 \internal |
|
181 */ |
|
182 int MpMpxCollectionDataPrivate::containerId() |
|
183 { |
|
184 int id = -1; |
|
185 TRAPD( err, id = DoGetContainerIdL() ); |
|
186 if ( err == KErrNone ) { |
|
187 TX_LOG_ARGS("id=" << id); |
|
188 } |
|
189 else { |
|
190 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
191 } |
|
192 TX_EXIT |
|
193 return id; |
|
194 } |
|
195 |
|
196 /*! |
|
197 \internal |
|
198 */ |
|
199 int MpMpxCollectionDataPrivate::itemId(int index) |
|
200 { |
|
201 TX_ENTRY_ARGS("index=" << index); |
|
202 int id = -1; |
|
203 TRAPD(err, id = DoGetItemIdL(index)); |
|
204 if ( err == KErrNone ) { |
|
205 TX_LOG_ARGS("id=" << id); |
|
206 } |
|
207 else { |
|
208 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
209 } |
|
210 TX_EXIT |
|
211 return id; |
|
212 } |
|
213 |
|
214 /*! |
|
215 \internal |
|
216 */ |
|
217 void MpMpxCollectionDataPrivate::removeItem(int index) |
|
218 { |
|
219 TX_ENTRY_ARGS("index=" << index); |
|
220 TRAPD(err, DoRemoveItemL(index)); |
|
221 if ( err != KErrNone ) { |
|
222 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
223 } |
|
224 TX_EXIT |
|
225 } |
|
226 |
|
227 /*! |
|
228 \internal |
|
229 */ |
|
230 bool MpMpxCollectionDataPrivate::testCachedItem( int itemId ) |
|
231 { |
|
232 TX_ENTRY_ARGS( "itemId=" << itemId); |
|
233 bool match = false; |
|
234 TRAPD( err, match = DoTestCachedItemL( itemId ) ); |
|
235 if ( err == KErrNone ) { |
|
236 TX_LOG_ARGS("match=" << match); |
|
237 } |
|
238 else { |
|
239 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
240 } |
|
241 TX_EXIT |
|
242 return match; |
|
243 } |
|
244 |
|
245 /*! |
|
246 \internal |
|
247 */ |
|
248 void MpMpxCollectionDataPrivate::insertCachedItem(int index) |
|
249 { |
|
250 TX_ENTRY_ARGS("index=" << index); |
|
251 iMediaArray->Insert( iCachedRemovedItem, index ); |
|
252 iCachedRemovedItem = 0; //ownership tranferred above. |
|
253 TX_EXIT |
|
254 } |
|
255 |
|
256 /*! |
|
257 \internal |
|
258 */ |
|
259 void MpMpxCollectionDataPrivate::setMpxMedia( const CMPXMedia& entries ) |
|
260 { |
|
261 TX_ENTRY |
|
262 TRAPD(err, DoSetMpxMediaL(entries)); |
|
263 if ( err == KErrNone ) { |
|
264 TX_LOG_ARGS("Context changed: iContext=" << iContext); |
|
265 emit q_ptr->contextChanged(iContext); |
|
266 } |
|
267 else { |
|
268 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
269 } |
|
270 TX_EXIT |
|
271 } |
|
272 |
|
273 /*! |
|
274 \internal |
|
275 */ |
|
276 void MpMpxCollectionDataPrivate::DoGetDataL( int index, MpMpxCollectionData::DataType type, QString& data ) const |
|
277 { |
|
278 TX_ENTRY |
|
279 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
280 |
|
281 TBuf<256> countBuf; |
|
282 TBuf<20> temp; |
|
283 TInt count = 0; |
|
284 switch ( type ) { |
|
285 case MpMpxCollectionData::Title: |
|
286 if ( currentMedia->IsSupported( KMPXMediaGeneralTitle ) ) { |
|
287 const TDesC& title = currentMedia->ValueText( KMPXMediaGeneralTitle ); |
|
288 if ( title.Compare( KNullDesC ) != 0 ) { |
|
289 data = QString::fromUtf16( title.Ptr(), title.Length() ); |
|
290 } |
|
291 } |
|
292 break; |
|
293 case MpMpxCollectionData::Artist: |
|
294 if ( currentMedia->IsSupported( KMPXMediaMusicArtist ) ) { |
|
295 const TDesC& artist = currentMedia->ValueText( KMPXMediaMusicArtist ); |
|
296 if ( artist.Compare( KNullDesC ) != 0 ) { |
|
297 data = QString::fromUtf16( artist.Ptr(), artist.Length() ); |
|
298 } |
|
299 } |
|
300 break; |
|
301 case MpMpxCollectionData::Count: |
|
302 if ( currentMedia->IsSupported( KMPXMediaGeneralCount ) ) { |
|
303 count = currentMedia->ValueTObjectL<TInt>( KMPXMediaGeneralCount ); |
|
304 } |
|
305 temp.AppendNum( count ); |
|
306 //AknTextUtils::LanguageSpecificNumberConversion( temp ); |
|
307 countBuf.Append( temp ); |
|
308 countBuf.Append( (count > 1 ) ? KSongs() : KSong() ); |
|
309 data = QString::fromUtf16( countBuf.Ptr(), countBuf.Length() ); |
|
310 break; |
|
311 case MpMpxCollectionData::AlbumArtUri: |
|
312 if ( currentMedia->IsSupported( KMPXMediaMusicAlbumArtFileName ) ) { |
|
313 const TDesC& album = currentMedia->ValueText( KMPXMediaMusicAlbumArtFileName ); |
|
314 if ( album.Compare( KNullDesC ) != 0 ) { |
|
315 data = QString::fromUtf16( album.Ptr(), album.Length() ); |
|
316 } |
|
317 } |
|
318 break; |
|
319 case MpMpxCollectionData::Uri: |
|
320 if ( currentMedia->IsSupported( KMPXMediaGeneralUri ) ) { |
|
321 const TDesC& uri = currentMedia->ValueText( KMPXMediaGeneralUri ); |
|
322 if ( uri.Compare( KNullDesC ) != 0 ) { |
|
323 data = QString::fromUtf16( uri.Ptr(), uri.Length() ); |
|
324 } |
|
325 } |
|
326 break; |
|
327 default: |
|
328 break; |
|
329 } |
|
330 TX_EXIT |
|
331 } |
|
332 |
|
333 /*! |
|
334 \internal |
|
335 */ |
|
336 bool MpMpxCollectionDataPrivate::DoIsAutoPlaylistL() |
|
337 { |
|
338 if ( iContainerMedia->IsSupported(KMPXMediaGeneralNonPermissibleActions) ) { |
|
339 TMPXGeneralNonPermissibleActions attr( |
|
340 iContainerMedia->ValueTObjectL<TMPXGeneralNonPermissibleActions>( |
|
341 KMPXMediaGeneralNonPermissibleActions ) ); |
|
342 if ( attr & EMPXWrite ) { |
|
343 return true; |
|
344 } |
|
345 } |
|
346 return false; |
|
347 } |
|
348 |
|
349 /*! |
|
350 \internal |
|
351 */ |
|
352 bool MpMpxCollectionDataPrivate::DoIsAutoPlaylistL( int index ) |
|
353 { |
|
354 const CMPXMediaArray* containerArray = iContainerMedia->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
355 User::LeaveIfNull( const_cast<CMPXMediaArray*>( containerArray )); |
|
356 CMPXMedia* media( containerArray->AtL(index) ); |
|
357 |
|
358 if ( media->IsSupported(KMPXMediaGeneralNonPermissibleActions) ) { |
|
359 TMPXGeneralNonPermissibleActions attr( |
|
360 media->ValueTObjectL<TMPXGeneralNonPermissibleActions>( |
|
361 KMPXMediaGeneralNonPermissibleActions ) ); |
|
362 if ( attr & EMPXWrite ) { |
|
363 return true; |
|
364 } |
|
365 } |
|
366 return false; |
|
367 } |
|
368 |
|
369 /*! |
|
370 \internal |
|
371 */ |
|
372 int MpMpxCollectionDataPrivate::DoGetItemCountL( int index ) |
|
373 { |
|
374 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
375 int count = 0; |
|
376 if ( currentMedia->IsSupported( KMPXMediaGeneralCount ) ) { |
|
377 count = currentMedia->ValueTObjectL<TInt>( KMPXMediaGeneralCount ); |
|
378 } |
|
379 return count; |
|
380 } |
|
381 |
|
382 /*! |
|
383 \internal |
|
384 */ |
|
385 int MpMpxCollectionDataPrivate::DoGetContainerIdL() |
|
386 { |
|
387 if ( !iContainerMedia->IsSupported( KMPXMediaGeneralId ) ) { |
|
388 User::Leave(KErrNotFound); |
|
389 } |
|
390 return iContainerMedia->ValueTObjectL<TInt>( KMPXMediaGeneralId ); |
|
391 } |
|
392 |
|
393 /*! |
|
394 \internal |
|
395 */ |
|
396 int MpMpxCollectionDataPrivate::DoGetItemIdL( int index ) |
|
397 { |
|
398 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
399 if ( !currentMedia->IsSupported( KMPXMediaGeneralId ) ) { |
|
400 User::Leave(KErrNotFound); |
|
401 } |
|
402 return currentMedia->ValueTObjectL<TInt>( KMPXMediaGeneralId ); |
|
403 } |
|
404 |
|
405 /*! |
|
406 \internal |
|
407 */ |
|
408 void MpMpxCollectionDataPrivate::DoRemoveItemL( int index ) |
|
409 { |
|
410 delete iCachedRemovedItem; |
|
411 iCachedRemovedItem = 0; |
|
412 iCachedRemovedItem = CMPXMedia::NewL( *iMediaArray->AtL( index ) ); |
|
413 iMediaArray->Remove( index ); |
|
414 } |
|
415 |
|
416 /*! |
|
417 \internal |
|
418 */ |
|
419 bool MpMpxCollectionDataPrivate::DoTestCachedItemL( int itemId ) |
|
420 { |
|
421 if ( !iCachedRemovedItem && !iCachedRemovedItem->IsSupported( KMPXMediaGeneralId ) ) { |
|
422 User::Leave(KErrNotFound); |
|
423 } |
|
424 return ( itemId == iCachedRemovedItem->ValueTObjectL<TInt>( KMPXMediaGeneralId ) ); |
|
425 } |
|
426 |
|
427 |
|
428 /*! |
|
429 \internal |
|
430 */ |
|
431 void MpMpxCollectionDataPrivate::SetCollectionContextL() |
|
432 { |
|
433 TX_ENTRY |
|
434 TMPXGeneralType containerType( EMPXNoType ); |
|
435 if ( iContainerMedia->IsSupported( KMPXMediaGeneralType ) ) { |
|
436 containerType = iContainerMedia->ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ); |
|
437 } |
|
438 |
|
439 TMPXGeneralCategory containerCategory( EMPXNoCategory ); |
|
440 if( iContainerMedia->IsSupported( KMPXMediaGeneralCategory ) ) { |
|
441 containerCategory = iContainerMedia->ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ); |
|
442 } |
|
443 TX_LOG_ARGS("type=" << containerType << ", category=" << containerCategory ); |
|
444 |
|
445 iContext = ECollectionContextUnknown; |
|
446 if ( containerType == EMPXGroup ) { |
|
447 switch (containerCategory) { |
|
448 case EMPXSong: |
|
449 iContext = ECollectionContextAllSongs; |
|
450 break; |
|
451 case EMPXAlbum: |
|
452 iContext = ECollectionContextAlbums; |
|
453 break; |
|
454 case EMPXPlaylist: |
|
455 iContext = ECollectionContextPlaylists; |
|
456 break; |
|
457 case EMPXGenre: |
|
458 iContext = ECollectionContextGenres; |
|
459 break; |
|
460 } |
|
461 } |
|
462 else if ( containerType == EMPXItem ) { |
|
463 switch (containerCategory) { |
|
464 case EMPXAlbum: |
|
465 iContext = ECollectionContextAlbumSongs; |
|
466 break; |
|
467 case EMPXPlaylist: |
|
468 iContext = ECollectionContextPlaylistSongs; |
|
469 break; |
|
470 case EMPXGenre: |
|
471 iContext = ECollectionContextGenreSongs; |
|
472 break; |
|
473 } |
|
474 } |
|
475 TX_EXIT |
|
476 } |
|
477 |
|
478 /*! |
|
479 \internal |
|
480 */ |
|
481 void MpMpxCollectionDataPrivate::DoSetMpxMediaL( const CMPXMedia& entries ) |
|
482 { |
|
483 TX_ENTRY |
|
484 delete iContainerMedia; |
|
485 iContainerMedia = 0; |
|
486 iContainerMedia = CMPXMedia::NewL(entries); |
|
487 iMediaArray = const_cast<CMPXMediaArray*>(iContainerMedia->Value<CMPXMediaArray>( KMPXMediaArrayContents ) ); |
|
488 TX_LOG_ARGS("media count=" << iMediaArray->Count() ); |
|
489 |
|
490 SetCollectionContextL(); |
|
491 TX_EXIT |
|
492 } |
|
493 |
|
494 /*! |
|
495 \internal |
|
496 */ |
|
497 const CMPXMedia& MpMpxCollectionDataPrivate::containerMedia() |
|
498 { |
|
499 return *iContainerMedia; |
|
500 } |
|
501 |
|