|
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 /*! |
|
31 \class MpMpxCollectionDataPrivate |
|
32 \brief Music Player collection data - private implementation. |
|
33 |
|
34 This is a private implementation of the collection data interface. |
|
35 */ |
|
36 |
|
37 /*! |
|
38 \internal |
|
39 */ |
|
40 MpMpxCollectionDataPrivate::MpMpxCollectionDataPrivate( MpMpxCollectionData *wrapper ) |
|
41 : q_ptr(wrapper), |
|
42 iContext(ECollectionContextUnknown), |
|
43 iContainerMedia(0), |
|
44 iMediaArray(0), |
|
45 iCachedRemovedItem(0), |
|
46 iCurrentAlbumIndex(-1), |
|
47 iAlbumSongCount(0), |
|
48 iReloadAlbumContent(false), |
|
49 iNeedReload(false) |
|
50 { |
|
51 TX_LOG |
|
52 } |
|
53 |
|
54 /*! |
|
55 \internal |
|
56 */ |
|
57 MpMpxCollectionDataPrivate::~MpMpxCollectionDataPrivate() |
|
58 { |
|
59 TX_ENTRY |
|
60 delete iContainerMedia; |
|
61 delete iCachedRemovedItem; |
|
62 TX_EXIT |
|
63 } |
|
64 |
|
65 /*! |
|
66 \internal |
|
67 */ |
|
68 TCollectionContext MpMpxCollectionDataPrivate::context() const |
|
69 { |
|
70 return iContext; |
|
71 } |
|
72 |
|
73 /*! |
|
74 \internal |
|
75 */ |
|
76 int MpMpxCollectionDataPrivate::count() const |
|
77 { |
|
78 if ( iMediaArray ) { |
|
79 return iMediaArray->Count(); |
|
80 } |
|
81 return 0; |
|
82 } |
|
83 |
|
84 /*! |
|
85 \internal |
|
86 */ |
|
87 QString MpMpxCollectionDataPrivate::collectionTitle() const |
|
88 { |
|
89 TX_ENTRY |
|
90 QString title; |
|
91 if ( iContainerMedia && iContainerMedia->IsSupported( KMPXMediaGeneralTitle ) ) { |
|
92 const TDesC& titleText = iContainerMedia->ValueText( KMPXMediaGeneralTitle ); |
|
93 if ( titleText.Compare( KNullDesC ) != 0 ) { |
|
94 title = QString::fromUtf16( titleText.Ptr(), titleText.Length() ); |
|
95 } |
|
96 } |
|
97 TX_EXIT_ARGS("title =" << title); |
|
98 return title; |
|
99 } |
|
100 |
|
101 /*! |
|
102 \internal |
|
103 */ |
|
104 QString MpMpxCollectionDataPrivate::itemData( int index, MpMpxCollectionData::DataType type ) |
|
105 { |
|
106 TX_ENTRY_ARGS("index=" << index << ", type=" << type); |
|
107 QString data; |
|
108 TRAPD(err, DoGetDataL(index, type, data)); |
|
109 if ( err != KErrNone ) { |
|
110 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
111 } |
|
112 TX_EXIT |
|
113 return data; |
|
114 } |
|
115 |
|
116 /*! |
|
117 \internal |
|
118 */ |
|
119 bool MpMpxCollectionDataPrivate::isAutoPlaylist() |
|
120 { |
|
121 TX_ENTRY |
|
122 if ( iContext != ECollectionContextPlaylistSongs ) { |
|
123 TX_EXIT |
|
124 return false; |
|
125 } |
|
126 |
|
127 bool isAuto = false; |
|
128 TRAPD(err, isAuto = DoIsAutoPlaylistL()); |
|
129 if ( err == KErrNone ) { |
|
130 TX_LOG_ARGS("isAuto=" << isAuto); |
|
131 } |
|
132 else { |
|
133 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
134 } |
|
135 TX_EXIT |
|
136 return isAuto; |
|
137 } |
|
138 |
|
139 /*! |
|
140 \internal |
|
141 */ |
|
142 bool MpMpxCollectionDataPrivate::isAutoPlaylist( int index ) |
|
143 { |
|
144 TX_ENTRY_ARGS("index=" << index); |
|
145 if ( iContext != ECollectionContextPlaylists ) { |
|
146 TX_EXIT |
|
147 return false; |
|
148 } |
|
149 |
|
150 bool isAuto = false; |
|
151 TRAPD(err, isAuto = DoIsAutoPlaylistL(index)); |
|
152 if ( err == KErrNone ) { |
|
153 TX_LOG_ARGS("isAuto=" << isAuto); |
|
154 } |
|
155 else { |
|
156 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
157 } |
|
158 TX_EXIT |
|
159 return isAuto; |
|
160 } |
|
161 |
|
162 /*! |
|
163 \internal |
|
164 */ |
|
165 int MpMpxCollectionDataPrivate::itemCount( int index ) |
|
166 { |
|
167 TX_ENTRY_ARGS("index=" << index); |
|
168 int count = 0; |
|
169 TRAPD(err, count = DoGetItemCountL(index)); |
|
170 if ( err == KErrNone ) { |
|
171 TX_LOG_ARGS("count=" << count); |
|
172 } |
|
173 else { |
|
174 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
175 } |
|
176 TX_EXIT |
|
177 return count; |
|
178 } |
|
179 |
|
180 /*! |
|
181 \internal |
|
182 */ |
|
183 int MpMpxCollectionDataPrivate::containerId() |
|
184 { |
|
185 int id = -1; |
|
186 TRAPD( err, id = DoGetContainerIdL() ); |
|
187 if ( err == KErrNone ) { |
|
188 TX_LOG_ARGS("id=" << id); |
|
189 } |
|
190 else { |
|
191 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
192 } |
|
193 TX_EXIT |
|
194 return id; |
|
195 } |
|
196 |
|
197 /*! |
|
198 \internal |
|
199 */ |
|
200 int MpMpxCollectionDataPrivate::itemId( int index ) |
|
201 { |
|
202 TX_ENTRY_ARGS( "index=" << index ); |
|
203 int id = -1; |
|
204 TRAPD( err, id = DoGetItemIdL( index ) ); |
|
205 if ( err == KErrNone ) { |
|
206 TX_LOG_ARGS( "id=" << id ); |
|
207 } |
|
208 else { |
|
209 TX_LOG_ARGS( "Error: " << err << "; should never get here." ); |
|
210 } |
|
211 TX_EXIT |
|
212 return id; |
|
213 } |
|
214 |
|
215 /*! |
|
216 \internal |
|
217 */ |
|
218 int MpMpxCollectionDataPrivate::albumSongId( int index ) |
|
219 { |
|
220 TX_ENTRY_ARGS( "index=" << index ); |
|
221 int id = -1; |
|
222 TRAPD( err, id = DoGetAlbumSongIdL( index ) ); |
|
223 if ( err == KErrNone ) { |
|
224 TX_LOG_ARGS( "id=" << id ); |
|
225 } |
|
226 else { |
|
227 TX_LOG_ARGS( "Error: " << err << "; should never get here." ); |
|
228 } |
|
229 TX_EXIT |
|
230 return id; |
|
231 } |
|
232 |
|
233 /*! |
|
234 \internal |
|
235 */ |
|
236 void MpMpxCollectionDataPrivate::removeItem(int index) |
|
237 { |
|
238 TX_ENTRY_ARGS("index=" << index); |
|
239 TRAPD(err, DoRemoveItemL(index)); |
|
240 if ( err != KErrNone ) { |
|
241 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
242 } |
|
243 TX_EXIT |
|
244 } |
|
245 |
|
246 /*! |
|
247 \internal |
|
248 */ |
|
249 bool MpMpxCollectionDataPrivate::testCachedItem( int itemId ) |
|
250 { |
|
251 TX_ENTRY_ARGS( "itemId=" << itemId); |
|
252 bool match = false; |
|
253 TRAPD( err, match = DoTestCachedItemL( itemId ) ); |
|
254 if ( err == KErrNone ) { |
|
255 TX_LOG_ARGS("match=" << match); |
|
256 } |
|
257 else { |
|
258 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
259 } |
|
260 TX_EXIT |
|
261 return match; |
|
262 } |
|
263 |
|
264 /*! |
|
265 \internal |
|
266 */ |
|
267 void MpMpxCollectionDataPrivate::insertCachedItem(int index) |
|
268 { |
|
269 TX_ENTRY_ARGS("index=" << index); |
|
270 iMediaArray->Insert( iCachedRemovedItem, index ); |
|
271 iCachedRemovedItem = 0; //ownership tranferred above. |
|
272 TX_EXIT |
|
273 } |
|
274 |
|
275 /*! |
|
276 \internal |
|
277 */ |
|
278 bool MpMpxCollectionDataPrivate::setCurrentAlbum( int index ) |
|
279 { |
|
280 TX_ENTRY_ARGS( "index=" << index); |
|
281 bool available = false; |
|
282 TRAPD( err, available = DoSetCurrentAlbumL( index ) ); |
|
283 if ( err != KErrNone ) { |
|
284 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
285 } |
|
286 TX_EXIT |
|
287 return available; |
|
288 } |
|
289 |
|
290 /*! |
|
291 \internal |
|
292 */ |
|
293 int MpMpxCollectionDataPrivate::currentAlbumIndex() const |
|
294 { |
|
295 return iCurrentAlbumIndex; |
|
296 } |
|
297 |
|
298 /*! |
|
299 \internal |
|
300 */ |
|
301 int MpMpxCollectionDataPrivate::albumSongsCount() const |
|
302 { |
|
303 return iAlbumSongCount; |
|
304 } |
|
305 |
|
306 /*! |
|
307 \internal |
|
308 */ |
|
309 QString MpMpxCollectionDataPrivate::albumSongData( int index, MpMpxCollectionData::DataType type ) const |
|
310 { |
|
311 TX_ENTRY_ARGS("index=" << index << ", type=" << type); |
|
312 QString data; |
|
313 TRAPD(err, DoGetAlbumSongDataL(index, type, data)); |
|
314 if ( err != KErrNone ) { |
|
315 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
316 } |
|
317 TX_EXIT |
|
318 return data; |
|
319 } |
|
320 |
|
321 /*! |
|
322 \internal |
|
323 */ |
|
324 bool MpMpxCollectionDataPrivate::hasItemProperty( int index, MpMpxCollectionData:: DataProperty type ) const |
|
325 { |
|
326 TX_ENTRY_ARGS("index=" << index << ", type=" << type); |
|
327 bool available = false; |
|
328 TRAPD(err, available = DoHasItemPropertyL(index, type)); |
|
329 if ( err != KErrNone ) { |
|
330 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
331 } |
|
332 TX_EXIT |
|
333 return available; |
|
334 } |
|
335 |
|
336 /*! |
|
337 \internal |
|
338 */ |
|
339 bool MpMpxCollectionDataPrivate::hasAlbumSongProperty( int index, MpMpxCollectionData:: DataProperty type ) const |
|
340 { |
|
341 TX_ENTRY_ARGS("index=" << index << ", type=" << type); |
|
342 bool available = false; |
|
343 TRAPD(err, available = DoHasAlbumSongPropertyL(index, type)); |
|
344 if ( err != KErrNone ) { |
|
345 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
346 } |
|
347 TX_EXIT |
|
348 return available; |
|
349 } |
|
350 |
|
351 /*! |
|
352 \internal |
|
353 New data from MPX collection. This could be due to Open operation, in which case |
|
354 context would have changed. This could also be due to Re-open after operations |
|
355 such as delete, playlist renaming, playlist rearraging, etc., in which case the |
|
356 context would remain the same, but the internal data may have changed. |
|
357 */ |
|
358 void MpMpxCollectionDataPrivate::setMpxMedia( const CMPXMedia& entries, bool reopen ) |
|
359 { |
|
360 TX_ENTRY |
|
361 TCollectionContext prevContext = iContext; |
|
362 int prevCount = count(); |
|
363 |
|
364 TRAPD(err, DoSetMpxMediaL(entries)); |
|
365 if ( err == KErrNone ) { |
|
366 int newCount = count(); |
|
367 if ( (newCount == 0) || (prevCount == 0) ) { |
|
368 TX_LOG_ARGS("Empty container"); |
|
369 // Two cases: |
|
370 // 1) newCount is zero: Last item in the model was deleted. |
|
371 // 2) prevCount is zero: Refresh operation found new data. |
|
372 // In these cases, independent of context change, we must emit the |
|
373 // contextChanged() signal so that the container can properly reload |
|
374 // the layout. |
|
375 emit q_ptr->contextChanged(iContext); |
|
376 } |
|
377 else if ( iContext != prevContext ) { |
|
378 TX_LOG_ARGS("Context changed: iContext=" << iContext); |
|
379 if ( prevContext == ECollectionContextArtistAlbumsTBone |
|
380 && iContext == ECollectionContextArtistAlbums |
|
381 && reopen ) { |
|
382 // Special case 1: This occurs when a song was deleted from TBone list |
|
383 // within artist container. And the fact that the new context is ArtistAlbums |
|
384 // indicates that the artist has more than 1 album. |
|
385 // Restore context to ArtistAlbumsTBone. |
|
386 iContext = ECollectionContextArtistAlbumsTBone; |
|
387 if ( newCount != prevCount ) { |
|
388 // Change in count indicates that the deleted song was the last song |
|
389 // in the TBone list. As a result, the album was deleted also, therefore |
|
390 // we must emit dataChanged() indicating changes to the album section |
|
391 // of the TBone. |
|
392 emit q_ptr->dataChanged(); |
|
393 } |
|
394 else { |
|
395 // Same count indicates that one of the songs in the TBone's list |
|
396 // section was deleted. We only want to reload the list section of the |
|
397 // TBone in this case. |
|
398 emit q_ptr->albumDataChanged(); |
|
399 } |
|
400 } |
|
401 else if ( prevContext == ECollectionContextAlbumsTBone && reopen ) { |
|
402 // Special case 2: This occurs when a song was deleted from TBone list |
|
403 // within album container. Restore context to AlbumsTBone. |
|
404 iContext = ECollectionContextAlbumsTBone; |
|
405 if ( newCount != prevCount ) { |
|
406 // Change in count indicates that the deleted song was the last song |
|
407 // in the TBone list. As a result, the album was deleted also, therefore |
|
408 // we must emit dataChanged() indicating changes to the album section |
|
409 // of the TBone. |
|
410 emit q_ptr->dataChanged(); |
|
411 } |
|
412 else { |
|
413 // Same count indicates that one of the songs in the TBone's list |
|
414 // section was deleted. We only want to reload the list section of the |
|
415 // TBone in this case. |
|
416 emit q_ptr->albumDataChanged(); |
|
417 } |
|
418 } |
|
419 else { |
|
420 // Simple case where the context has really changed and it didn't |
|
421 // involve TBone. |
|
422 emit q_ptr->contextChanged(iContext); |
|
423 } |
|
424 } |
|
425 else if ( prevContext == ECollectionContextArtistAlbumsTBone |
|
426 && iContext == ECollectionContextArtistAlbumsTBone |
|
427 && reopen ) { |
|
428 // Special case 3: This occurs when a song was deleted from TBone list |
|
429 // within artist container. This is similar to special case 1, however, the |
|
430 // fact that the new context is also ArtistAlbumsTBone indicates that the |
|
431 // artist has only 1 album. We only want to reload the list section of the |
|
432 // TBone in this case. |
|
433 emit q_ptr->albumDataChanged(); |
|
434 } |
|
435 else { |
|
436 // Same context, but the data has changed. |
|
437 emit q_ptr->dataChanged(); |
|
438 } |
|
439 } |
|
440 else { |
|
441 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
442 } |
|
443 TX_EXIT |
|
444 } |
|
445 |
|
446 /*! |
|
447 \internal |
|
448 This indicates data update during incremental open operation. This indicates |
|
449 that media received in setMpxMedia() has updates. |
|
450 */ |
|
451 void MpMpxCollectionDataPrivate::incrementalOpenUpdate() |
|
452 { |
|
453 TX_ENTRY_ARGS( "iNeedReload=" << iNeedReload); |
|
454 if ( iNeedReload ) { |
|
455 if ( itemId(iReloadRange.second) != -1 ) { |
|
456 iNeedReload = false; |
|
457 emit q_ptr->dataChanged(iReloadRange.first, iReloadRange.second); |
|
458 } |
|
459 } |
|
460 TX_EXIT |
|
461 } |
|
462 |
|
463 /*! |
|
464 \internal |
|
465 */ |
|
466 const CMPXMedia& MpMpxCollectionDataPrivate::containerMedia() |
|
467 { |
|
468 return *iContainerMedia; |
|
469 } |
|
470 |
|
471 /*! |
|
472 \internal |
|
473 */ |
|
474 void MpMpxCollectionDataPrivate::setContext( TCollectionContext context ) |
|
475 { |
|
476 iContext = context; |
|
477 TX_LOG_ARGS("Context changed: iContext=" << iContext); |
|
478 loadAlbumsLookup(); |
|
479 emit q_ptr->contextChanged(iContext); |
|
480 } |
|
481 |
|
482 /*! |
|
483 \internal |
|
484 */ |
|
485 void MpMpxCollectionDataPrivate::setAlbumContent( const CMPXMedia& albumContent ) |
|
486 { |
|
487 TX_ENTRY |
|
488 TRAPD(err, DoSetAlbumContentL(albumContent)); |
|
489 if ( err == KErrNone ) { |
|
490 TX_LOG_ARGS("Album content is available."); |
|
491 loadAlbumSongsLookup(); |
|
492 emit q_ptr->refreshAlbumSongs(); |
|
493 } |
|
494 else { |
|
495 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
496 } |
|
497 TX_EXIT |
|
498 } |
|
499 |
|
500 /*! |
|
501 \internal |
|
502 Currently only used to lookup playing song album id to index of albums on |
|
503 media wall. |
|
504 */ |
|
505 int MpMpxCollectionDataPrivate::itemIndex( int itemUniqueId ) |
|
506 { |
|
507 return iAlbumIdIndexMapping.value( itemUniqueId, -1 ); |
|
508 } |
|
509 |
|
510 /*! |
|
511 \internal |
|
512 Currently only used to lookup playing song id to index of song in the |
|
513 current album on media wall. |
|
514 */ |
|
515 int MpMpxCollectionDataPrivate::albumSongIndex( int songUniqueId ) |
|
516 { |
|
517 return iAlbumSongIdIndexMapping.value( songUniqueId, -1 ); |
|
518 } |
|
519 |
|
520 /*! |
|
521 \internal |
|
522 Use to lookup playing song id to index of song in collection and playlist |
|
523 view |
|
524 */ |
|
525 QList<int> MpMpxCollectionDataPrivate::songIndex( int songUniqueId ) |
|
526 { |
|
527 TX_ENTRY |
|
528 if(iSongIdIndexMapping.empty()){ |
|
529 for ( int i = count() - 1 ; i >= 0 ; i-- ) { |
|
530 iSongIdIndexMapping.insertMulti( itemId2( i ) , i ); |
|
531 } |
|
532 } |
|
533 TX_EXIT |
|
534 return iSongIdIndexMapping.values( songUniqueId ); |
|
535 } |
|
536 |
|
537 /*! |
|
538 \internal |
|
539 Set item at index to corrupted depends on if viewing TBone |
|
540 */ |
|
541 void MpMpxCollectionDataPrivate::setCorruptValue( QModelIndex index, bool tBone) |
|
542 { |
|
543 TX_ENTRY |
|
544 TRAPD(err, DoSetCorruptValueL(index, tBone)); |
|
545 if ( err != KErrNone ) { |
|
546 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
547 } |
|
548 TX_EXIT |
|
549 } |
|
550 |
|
551 /*! |
|
552 \internal |
|
553 */ |
|
554 void MpMpxCollectionDataPrivate::setReloadAlbumContent( bool reloadAlbum ) |
|
555 { |
|
556 iReloadAlbumContent = reloadAlbum; |
|
557 } |
|
558 |
|
559 /*! |
|
560 \internal |
|
561 */ |
|
562 void MpMpxCollectionDataPrivate::loadAlbumsLookup() |
|
563 { |
|
564 //Clearing all the album ids. |
|
565 iAlbumIdIndexMapping.clear(); |
|
566 if ( iContext == ECollectionContextAlbumsMediaWall) { |
|
567 //Adding album ids and indixes to the hash, for itemIndex lookup. |
|
568 //This is disabled for other containers to save resources. |
|
569 for ( int i = count() - 1 ; i >= 0 ; i-- ) { |
|
570 iAlbumIdIndexMapping.insert( itemId( i ) , i ); |
|
571 } |
|
572 } |
|
573 } |
|
574 |
|
575 /*! |
|
576 \internal |
|
577 */ |
|
578 void MpMpxCollectionDataPrivate::loadAlbumSongsLookup() |
|
579 { |
|
580 //Clearing all the song ids. |
|
581 iAlbumSongIdIndexMapping.clear(); |
|
582 //Adding album song ids and indixes to the hash, for albumSongIndex lookup. |
|
583 //This is disabled for other containers to save resources. |
|
584 for ( int i = albumSongsCount() - 1 ; i >= 0 ; i-- ) { |
|
585 iAlbumSongIdIndexMapping.insert( albumSongId( i ) , i ); |
|
586 } |
|
587 } |
|
588 |
|
589 /*! |
|
590 \internal |
|
591 */ |
|
592 void MpMpxCollectionDataPrivate::setReloadRange( int index ) |
|
593 { |
|
594 TX_ENTRY_ARGS( "index=" << index); |
|
595 if ( !iNeedReload ) { |
|
596 iNeedReload = true; |
|
597 iReloadRange.first = index; |
|
598 iReloadRange.second = index; |
|
599 } |
|
600 else if ( index < iReloadRange.first ) { |
|
601 iReloadRange.first = index; |
|
602 } |
|
603 else if ( index > iReloadRange.second ) { |
|
604 iReloadRange.second = index; |
|
605 } |
|
606 TX_EXIT |
|
607 } |
|
608 |
|
609 /*! |
|
610 \internal |
|
611 */ |
|
612 int MpMpxCollectionDataPrivate::itemId2( int index ) |
|
613 { |
|
614 TX_ENTRY_ARGS( "index=" << index ); |
|
615 int id = -1; |
|
616 TRAPD( err, id = DoGetItemId2L( index ) ); |
|
617 if ( err == KErrNone ) { |
|
618 TX_LOG_ARGS( "id=" << id ); |
|
619 } |
|
620 else { |
|
621 TX_LOG_ARGS( "Error: " << err << "; should never get here." ); |
|
622 } |
|
623 TX_EXIT |
|
624 return id; |
|
625 } |
|
626 |
|
627 /*! |
|
628 \internal |
|
629 */ |
|
630 void MpMpxCollectionDataPrivate::DoGetDataL( int index, MpMpxCollectionData::DataType type, QString& data ) |
|
631 { |
|
632 TX_ENTRY |
|
633 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
634 |
|
635 if ( currentMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId) == KMPXInvalidItemId ) { |
|
636 // Accessing a data that hasn't been fully fetched from the collection. |
|
637 // This can happen during incremental open. Set the index as reload candidate. |
|
638 setReloadRange(index); |
|
639 } |
|
640 |
|
641 TBuf<10> countBuf; |
|
642 TInt count = 0; |
|
643 switch ( type ) { |
|
644 case MpMpxCollectionData::Title: |
|
645 if ( currentMedia->IsSupported( KMPXMediaGeneralTitle ) ) { |
|
646 const TDesC& title = currentMedia->ValueText( KMPXMediaGeneralTitle ); |
|
647 if ( title.Compare( KNullDesC ) != 0 ) { |
|
648 data = QString::fromUtf16( title.Ptr(), title.Length() ); |
|
649 } |
|
650 } |
|
651 break; |
|
652 case MpMpxCollectionData::Artist: |
|
653 if ( currentMedia->IsSupported( KMPXMediaMusicArtist ) ) { |
|
654 const TDesC& artist = currentMedia->ValueText( KMPXMediaMusicArtist ); |
|
655 if ( artist.Compare( KNullDesC ) != 0 ) { |
|
656 data = QString::fromUtf16( artist.Ptr(), artist.Length() ); |
|
657 } |
|
658 } |
|
659 break; |
|
660 case MpMpxCollectionData::Album: |
|
661 if ( currentMedia->IsSupported( KMPXMediaMusicAlbum ) ) { |
|
662 const TDesC& album = currentMedia->ValueText( KMPXMediaMusicAlbum ); |
|
663 if ( album.Compare( KNullDesC ) != 0 ) { |
|
664 data = QString::fromUtf16( album.Ptr(), album.Length() ); |
|
665 } |
|
666 } |
|
667 break; |
|
668 case MpMpxCollectionData::Count: |
|
669 if ( currentMedia->IsSupported( KMPXMediaGeneralCount ) ) { |
|
670 count = currentMedia->ValueTObjectL<TInt>( KMPXMediaGeneralCount ); |
|
671 } |
|
672 countBuf.AppendNum( count ); |
|
673 data = QString::fromUtf16( countBuf.Ptr(), countBuf.Length() ); |
|
674 break; |
|
675 case MpMpxCollectionData::AlbumArtUri: |
|
676 if ( currentMedia->IsSupported( KMPXMediaMusicAlbumArtFileName ) ) { |
|
677 const TDesC& album = currentMedia->ValueText( KMPXMediaMusicAlbumArtFileName ); |
|
678 if ( album.Compare( KNullDesC ) != 0 ) { |
|
679 data = QString::fromUtf16( album.Ptr(), album.Length() ); |
|
680 } |
|
681 } |
|
682 break; |
|
683 case MpMpxCollectionData::Uri: |
|
684 if ( currentMedia->IsSupported( KMPXMediaGeneralUri ) ) { |
|
685 const TDesC& uri = currentMedia->ValueText( KMPXMediaGeneralUri ); |
|
686 if ( uri.Compare( KNullDesC ) != 0 ) { |
|
687 data = QString::fromUtf16( uri.Ptr(), uri.Length() ); |
|
688 } |
|
689 } |
|
690 break; |
|
691 default: |
|
692 break; |
|
693 } |
|
694 TX_EXIT |
|
695 } |
|
696 |
|
697 /*! |
|
698 \internal |
|
699 */ |
|
700 bool MpMpxCollectionDataPrivate::DoIsAutoPlaylistL() |
|
701 { |
|
702 if ( iContainerMedia->IsSupported(KMPXMediaGeneralNonPermissibleActions) ) { |
|
703 TMPXGeneralNonPermissibleActions attr( |
|
704 iContainerMedia->ValueTObjectL<TMPXGeneralNonPermissibleActions>( |
|
705 KMPXMediaGeneralNonPermissibleActions ) ); |
|
706 if ( attr & EMPXWrite ) { |
|
707 return true; |
|
708 } |
|
709 } |
|
710 return false; |
|
711 } |
|
712 |
|
713 /*! |
|
714 \internal |
|
715 */ |
|
716 bool MpMpxCollectionDataPrivate::DoIsAutoPlaylistL( int index ) |
|
717 { |
|
718 const CMPXMediaArray* containerArray = iContainerMedia->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
719 User::LeaveIfNull( const_cast<CMPXMediaArray*>( containerArray )); |
|
720 CMPXMedia* media( containerArray->AtL(index) ); |
|
721 |
|
722 if ( media->IsSupported(KMPXMediaGeneralNonPermissibleActions) ) { |
|
723 TMPXGeneralNonPermissibleActions attr( |
|
724 media->ValueTObjectL<TMPXGeneralNonPermissibleActions>( |
|
725 KMPXMediaGeneralNonPermissibleActions ) ); |
|
726 if ( attr & EMPXWrite ) { |
|
727 return true; |
|
728 } |
|
729 } |
|
730 return false; |
|
731 } |
|
732 |
|
733 /*! |
|
734 \internal |
|
735 */ |
|
736 int MpMpxCollectionDataPrivate::DoGetItemCountL( int index ) |
|
737 { |
|
738 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
739 int count = 0; |
|
740 if ( currentMedia->IsSupported( KMPXMediaGeneralCount ) ) { |
|
741 count = currentMedia->ValueTObjectL<TInt>( KMPXMediaGeneralCount ); |
|
742 } |
|
743 return count; |
|
744 } |
|
745 |
|
746 /*! |
|
747 \internal |
|
748 */ |
|
749 int MpMpxCollectionDataPrivate::DoGetContainerIdL() |
|
750 { |
|
751 if ( !iContainerMedia->IsSupported( KMPXMediaGeneralId ) ) { |
|
752 User::Leave(KErrNotFound); |
|
753 } |
|
754 return iContainerMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ); |
|
755 } |
|
756 |
|
757 /*! |
|
758 \internal |
|
759 */ |
|
760 int MpMpxCollectionDataPrivate::DoGetItemIdL( int index ) |
|
761 { |
|
762 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
763 if ( currentMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId) == KMPXInvalidItemId ) { |
|
764 return -1; |
|
765 } |
|
766 else { |
|
767 int id1 = (currentMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )).iId1; |
|
768 int id2 = (currentMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )).iId2; |
|
769 TX_LOG_ARGS( "id1=" << id1 << ", id2=" << id2 ); |
|
770 return (currentMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )).iId1; |
|
771 } |
|
772 } |
|
773 |
|
774 /*! |
|
775 \internal |
|
776 */ |
|
777 int MpMpxCollectionDataPrivate::DoGetItemId2L( int index ) |
|
778 { |
|
779 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
780 if ( currentMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId) == KMPXInvalidItemId ) { |
|
781 return -1; |
|
782 } |
|
783 else { |
|
784 return (currentMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )).iId2; |
|
785 } |
|
786 } |
|
787 |
|
788 /*! |
|
789 \internal |
|
790 */ |
|
791 int MpMpxCollectionDataPrivate::DoGetAlbumSongIdL( int index ) |
|
792 { |
|
793 CMPXMedia* album( iMediaArray->AtL( iCurrentAlbumIndex ) ); |
|
794 const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
795 User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs)); |
|
796 CMPXMedia* song = songs->AtL(index); |
|
797 if ( song->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId) == KMPXInvalidItemId ) { |
|
798 return -1; |
|
799 } |
|
800 else { |
|
801 return song->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ); |
|
802 } |
|
803 } |
|
804 |
|
805 /*! |
|
806 \internal |
|
807 */ |
|
808 void MpMpxCollectionDataPrivate::DoRemoveItemL( int index ) |
|
809 { |
|
810 delete iCachedRemovedItem; |
|
811 iCachedRemovedItem = 0; |
|
812 iCachedRemovedItem = CMPXMedia::NewL( *iMediaArray->AtL( index ) ); |
|
813 iMediaArray->Remove( index ); |
|
814 } |
|
815 |
|
816 /*! |
|
817 \internal |
|
818 */ |
|
819 bool MpMpxCollectionDataPrivate::DoTestCachedItemL( int itemId ) |
|
820 { |
|
821 if ( !iCachedRemovedItem || !iCachedRemovedItem->IsSupported( KMPXMediaGeneralId ) ) { |
|
822 User::Leave(KErrNotFound); |
|
823 } |
|
824 return ( itemId == TInt( iCachedRemovedItem->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ) ); |
|
825 } |
|
826 |
|
827 /*! |
|
828 \internal |
|
829 */ |
|
830 bool MpMpxCollectionDataPrivate::DoSetCurrentAlbumL( int index ) |
|
831 { |
|
832 TX_ENTRY_ARGS( "index=" << index); |
|
833 iCurrentAlbumIndex = index; |
|
834 |
|
835 bool songsAvailable = false; |
|
836 if (!iReloadAlbumContent){ |
|
837 CMPXMedia* album( iMediaArray->AtL( index ) ); |
|
838 if ( album->IsSupported(KMPXMediaArrayContents) ) { |
|
839 // We've previously fetched the songs for this album so |
|
840 // all we do now is populate the list with the song titles. |
|
841 const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
842 iAlbumSongCount = songs->Count(); |
|
843 songsAvailable = true; |
|
844 TX_LOG_ARGS("Songs available."); |
|
845 loadAlbumSongsLookup(); |
|
846 emit q_ptr->refreshAlbumSongs(); |
|
847 } |
|
848 } |
|
849 TX_EXIT |
|
850 return songsAvailable; |
|
851 } |
|
852 |
|
853 /*! |
|
854 \internal |
|
855 */ |
|
856 void MpMpxCollectionDataPrivate::DoGetAlbumSongDataL( int index, MpMpxCollectionData::DataType type, QString& data ) const |
|
857 { |
|
858 TX_ENTRY |
|
859 CMPXMedia* album( iMediaArray->AtL( iCurrentAlbumIndex ) ); |
|
860 if ( album->IsSupported(KMPXMediaArrayContents) ) { |
|
861 const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
862 User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs)); |
|
863 CMPXMedia* song = songs->AtL(index); |
|
864 |
|
865 switch ( type ) { |
|
866 case MpMpxCollectionData::Title: |
|
867 if ( song->IsSupported( KMPXMediaGeneralTitle ) ) { |
|
868 const TDesC& title = song->ValueText( KMPXMediaGeneralTitle ); |
|
869 if ( title.Compare( KNullDesC ) != 0 ) { |
|
870 data = QString::fromUtf16( title.Ptr(), title.Length() ); |
|
871 } |
|
872 } |
|
873 break; |
|
874 case MpMpxCollectionData::Uri: |
|
875 if ( song->IsSupported( KMPXMediaGeneralUri ) ) { |
|
876 const TDesC& uri = song->ValueText( KMPXMediaGeneralUri ); |
|
877 if ( uri.Compare( KNullDesC ) != 0 ) { |
|
878 data = QString::fromUtf16( uri.Ptr(), uri.Length() ); |
|
879 } |
|
880 } |
|
881 break; |
|
882 default: |
|
883 break; |
|
884 } |
|
885 } |
|
886 TX_EXIT |
|
887 } |
|
888 |
|
889 /*! |
|
890 \internal |
|
891 */ |
|
892 bool MpMpxCollectionDataPrivate::DoHasItemPropertyL( int index, MpMpxCollectionData:: DataProperty type ) const |
|
893 { |
|
894 TX_ENTRY |
|
895 CMPXMedia* currentMedia( iMediaArray->AtL( index ) ); |
|
896 |
|
897 TInt flags(0); |
|
898 if ( currentMedia->IsSupported( KMPXMediaGeneralFlags ) ) { |
|
899 flags = currentMedia->ValueTObjectL<TUint>( KMPXMediaGeneralFlags ); |
|
900 } |
|
901 switch ( type ) { |
|
902 case MpMpxCollectionData::Corrupted: |
|
903 if ( ( flags ) & ( KMPXMediaGeneralFlagsIsCorrupted ) ){ |
|
904 return true; |
|
905 } |
|
906 break; |
|
907 case MpMpxCollectionData::DrmExpired: |
|
908 if ( ( flags ) & ( KMPXMediaGeneralFlagsIsDrmLicenceInvalid ) ){ |
|
909 return true; |
|
910 } |
|
911 break; |
|
912 default: |
|
913 break; |
|
914 } |
|
915 TX_EXIT |
|
916 return false; |
|
917 } |
|
918 |
|
919 /*! |
|
920 \internal |
|
921 */ |
|
922 bool MpMpxCollectionDataPrivate::DoHasAlbumSongPropertyL( int index, MpMpxCollectionData:: DataProperty type ) const |
|
923 { |
|
924 TX_ENTRY |
|
925 CMPXMedia* album( iMediaArray->AtL( iCurrentAlbumIndex ) ); |
|
926 if ( album->IsSupported(KMPXMediaArrayContents) ) { |
|
927 const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
928 User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs)); |
|
929 CMPXMedia* song = songs->AtL(index); |
|
930 TInt flags(0); |
|
931 if ( song->IsSupported( KMPXMediaGeneralFlags ) ) { |
|
932 flags = song->ValueTObjectL<TUint>( KMPXMediaGeneralFlags ); |
|
933 } |
|
934 switch ( type ) { |
|
935 case MpMpxCollectionData::Corrupted: |
|
936 if ( ( flags ) & ( KMPXMediaGeneralFlagsIsCorrupted ) ){ |
|
937 return true; |
|
938 } |
|
939 break; |
|
940 case MpMpxCollectionData::DrmExpired: |
|
941 if ( ( flags ) & ( KMPXMediaGeneralFlagsIsDrmLicenceInvalid ) ){ |
|
942 return true; |
|
943 } |
|
944 break; |
|
945 default: |
|
946 break; |
|
947 } |
|
948 |
|
949 } |
|
950 TX_EXIT |
|
951 return false; |
|
952 } |
|
953 /*! |
|
954 \internal |
|
955 */ |
|
956 void MpMpxCollectionDataPrivate::SetCollectionContextL() |
|
957 { |
|
958 TX_ENTRY |
|
959 // Clear Song Index Hash when context switched |
|
960 iSongIdIndexMapping.clear(); |
|
961 TMPXGeneralType containerType( EMPXNoType ); |
|
962 if ( iContainerMedia->IsSupported( KMPXMediaGeneralType ) ) { |
|
963 containerType = iContainerMedia->ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ); |
|
964 } |
|
965 |
|
966 TMPXGeneralCategory containerCategory( EMPXNoCategory ); |
|
967 if( iContainerMedia->IsSupported( KMPXMediaGeneralCategory ) ) { |
|
968 containerCategory = iContainerMedia->ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ); |
|
969 } |
|
970 TX_LOG_ARGS("type=" << containerType << ", category=" << containerCategory ); |
|
971 |
|
972 iContext = ECollectionContextUnknown; |
|
973 if ( containerType == EMPXGroup ) { |
|
974 switch (containerCategory) { |
|
975 case EMPXSong: |
|
976 iContext = ECollectionContextAllSongs; |
|
977 break; |
|
978 case EMPXArtist: |
|
979 iContext = ECollectionContextArtists; |
|
980 break; |
|
981 case EMPXAlbum: |
|
982 iContext = ECollectionContextAlbums; |
|
983 break; |
|
984 case EMPXPlaylist: |
|
985 iContext = ECollectionContextPlaylists; |
|
986 break; |
|
987 } |
|
988 } |
|
989 else if ( containerType == EMPXItem ) { |
|
990 switch (containerCategory) { |
|
991 case EMPXArtist: |
|
992 if ( iMediaArray->Count() > 1 ) { |
|
993 iContext = ECollectionContextArtistAlbums; |
|
994 } |
|
995 else { |
|
996 // Single album. Go directly to TBone. |
|
997 iContext = ECollectionContextArtistAlbumsTBone; |
|
998 } |
|
999 break; |
|
1000 case EMPXSong: |
|
1001 // All songs for an artist |
|
1002 iContext = ECollectionContextArtistAllSongs; |
|
1003 break; |
|
1004 case EMPXPlaylist: |
|
1005 iContext = ECollectionContextPlaylistSongs; |
|
1006 break; |
|
1007 } |
|
1008 } |
|
1009 TX_EXIT |
|
1010 } |
|
1011 |
|
1012 /*! |
|
1013 \internal |
|
1014 */ |
|
1015 void MpMpxCollectionDataPrivate::DoSetMpxMediaL( const CMPXMedia& entries ) |
|
1016 { |
|
1017 TX_ENTRY |
|
1018 delete iContainerMedia; |
|
1019 iContainerMedia = 0; |
|
1020 iContainerMedia = CMPXMedia::NewL(entries); |
|
1021 iMediaArray = const_cast<CMPXMediaArray*>(iContainerMedia->Value<CMPXMediaArray>( KMPXMediaArrayContents ) ); |
|
1022 TX_LOG_ARGS("media count=" << iMediaArray->Count() ); |
|
1023 iReloadAlbumContent = false; |
|
1024 SetCollectionContextL(); |
|
1025 TX_EXIT |
|
1026 } |
|
1027 |
|
1028 /*! |
|
1029 \internal |
|
1030 */ |
|
1031 void MpMpxCollectionDataPrivate::DoSetAlbumContentL( const CMPXMedia& albumContent ) |
|
1032 { |
|
1033 TX_ENTRY |
|
1034 CMPXMediaArray* songArray(const_cast<CMPXMediaArray*>( albumContent.Value<CMPXMediaArray>( |
|
1035 KMPXMediaArrayContents ) ) ); |
|
1036 User::LeaveIfNull( songArray ); |
|
1037 |
|
1038 // Save the songs to the album so that we don't need to find them again |
|
1039 // if the same album is selected again. |
|
1040 iAlbumSongCount = songArray->Count(); |
|
1041 |
|
1042 if ( iAlbumSongCount ) { |
|
1043 CMPXMedia* albumMedia( iMediaArray->AtL( iCurrentAlbumIndex ) ); |
|
1044 albumMedia->SetCObjectValueL(KMPXMediaArrayContents, songArray); |
|
1045 albumMedia->SetTObjectValueL<TInt>(KMPXMediaArrayCount, iAlbumSongCount); |
|
1046 } |
|
1047 TX_EXIT |
|
1048 } |
|
1049 |
|
1050 /*! |
|
1051 \internal |
|
1052 */ |
|
1053 void MpMpxCollectionDataPrivate::DoSetCorruptValueL(QModelIndex index, bool tBone) |
|
1054 { |
|
1055 TX_ENTRY |
|
1056 if (tBone){ |
|
1057 CMPXMedia* album( iMediaArray->AtL( iCurrentAlbumIndex ) ); |
|
1058 if ( album->IsSupported(KMPXMediaArrayContents) ) { |
|
1059 const CMPXMediaArray* songs = album->Value<CMPXMediaArray>(KMPXMediaArrayContents); |
|
1060 User::LeaveIfNull(const_cast<CMPXMediaArray*>(songs)); |
|
1061 CMPXMedia* song = songs->AtL( index.row() ); |
|
1062 song->SetTObjectValueL<TUint>( KMPXMediaGeneralFlags,KMPXMediaGeneralFlagsIsCorrupted ); |
|
1063 } |
|
1064 } |
|
1065 else { |
|
1066 CMPXMedia* song( iMediaArray->AtL( index.row() ) ); |
|
1067 song->SetTObjectValueL<TUint>( KMPXMediaGeneralFlags,KMPXMediaGeneralFlagsIsCorrupted ); |
|
1068 } |
|
1069 TX_EXIT |
|
1070 } |
|
1071 |