|
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: Wrapper for mpx framework utilities - private implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStringList> |
|
19 |
|
20 #include <s32strm.h> |
|
21 #include <s32mem.h> |
|
22 #include <apgcli.h> |
|
23 #include <apacmdln.h> |
|
24 |
|
25 #include <mpxplaybackutility.h> |
|
26 #include <mpxcollectionutility.h> |
|
27 #include <mpxharvesterutility.h> |
|
28 #include <mpxcollectionpath.h> |
|
29 #include <mpxcollectionmessage.h> |
|
30 #include <mpxcollectionplaylist.h> |
|
31 #include <mpxmessagecontainerdefs.h> |
|
32 #include <mpxmediacollectiondetaildefs.h> |
|
33 #include <mpxmediamusicdefs.h> |
|
34 #include <mpxmediageneraldefs.h> |
|
35 #include <mpxcollectionplugin.hrh> |
|
36 #include <mpxmessagegeneraldefs.h> |
|
37 #include <mpxmediacontainerdefs.h> |
|
38 #include <mpxcollectionmessagedefs.h> |
|
39 #include <mpxparameter.h> |
|
40 #include <mpxcollectionhelperfactory.h> |
|
41 #include <mpxcollectionuihelper.h> |
|
42 #include <mpxcollectionopenutility.h> |
|
43 #include <mpxmediaarray.h> |
|
44 #include <mpxmedia.h> |
|
45 #include <mpxlog.h> |
|
46 |
|
47 #include "mpmpxframeworkwrapper_p.h" |
|
48 #include "mpmpxframeworkwrapper.h" |
|
49 #include "mpmpxcollectiondata.h" |
|
50 #include "mpcommondefs.h" |
|
51 #include "mptrace.h" |
|
52 #include "mpsettingsmanager.h" |
|
53 |
|
54 const TInt KIncrementalDelayNone = 0; |
|
55 const TInt KIncrementalDelayHalfSecond = 1000000; |
|
56 const TInt KIncrementalFetchBlockSize = 40; |
|
57 |
|
58 const TInt KMPXChunkSize = 100; // number of songs added in each chunk, IncAddL |
|
59 _LIT( KPlaylistPath, "C:\\Data\\Playlists\\" ); // Todo |
|
60 |
|
61 /*! |
|
62 \class MpMpxFrameworkWrapperPrivate |
|
63 \brief Wrapper for mpx framework utilities - private implementation. |
|
64 |
|
65 This is a private implementation of the mpx framework wrapper utilties interface. |
|
66 */ |
|
67 |
|
68 /*! |
|
69 \internal |
|
70 */ |
|
71 MpMpxFrameworkWrapperPrivate::MpMpxFrameworkWrapperPrivate( MpMpxFrameworkWrapper *wrapper ) |
|
72 : q_ptr(wrapper), |
|
73 iCollectionUtility(0), |
|
74 iCollectionUiHelper(0), |
|
75 iIncrementalOpenUtil(0), |
|
76 iPlaybackUtility(0), |
|
77 iHarvesterUtility(0), |
|
78 iCollectionData(0), |
|
79 iFirstIncrementalOpen(EFalse), |
|
80 iUserPlaylists(0) |
|
81 { |
|
82 TX_LOG |
|
83 } |
|
84 |
|
85 /*! |
|
86 \internal |
|
87 */ |
|
88 MpMpxFrameworkWrapperPrivate::~MpMpxFrameworkWrapperPrivate() |
|
89 { |
|
90 TX_ENTRY |
|
91 delete iCollectionData; |
|
92 |
|
93 if ( iCollectionUtility ) { |
|
94 iCollectionUtility->Collection().CancelRequest(); |
|
95 iCollectionUtility->Close(); |
|
96 } |
|
97 |
|
98 if ( iCollectionUiHelper ) { |
|
99 iCollectionUiHelper->Close(); |
|
100 } |
|
101 |
|
102 if ( iPlaybackUtility ) { |
|
103 iPlaybackUtility->Close(); |
|
104 } |
|
105 |
|
106 if ( iHarvesterUtility ) { |
|
107 iHarvesterUtility->Close(); |
|
108 } |
|
109 |
|
110 delete iIncrementalOpenUtil; |
|
111 delete iUserPlaylists; |
|
112 |
|
113 TX_EXIT |
|
114 } |
|
115 |
|
116 /*! |
|
117 \internal |
|
118 */ |
|
119 void MpMpxFrameworkWrapperPrivate::init( MpCommon::MpViewMode viewMode ) |
|
120 { |
|
121 |
|
122 iViewMode = viewMode; |
|
123 TRAPD(err, DoInitL()); |
|
124 if ( err != KErrNone ) { |
|
125 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
126 } |
|
127 } |
|
128 |
|
129 /*! |
|
130 \internal |
|
131 */ |
|
132 void MpMpxFrameworkWrapperPrivate::openCollection( TCollectionContext context ) |
|
133 { |
|
134 TRAPD(err, DoOpenCollectionL(context)); |
|
135 if ( err != KErrNone ) { |
|
136 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
137 } |
|
138 } |
|
139 |
|
140 /*! |
|
141 \internal |
|
142 */ |
|
143 void MpMpxFrameworkWrapperPrivate::openCollectionItem( int index ) |
|
144 { |
|
145 TRAPD(err, DoOpenCollectionItemL(index)); |
|
146 if ( err != KErrNone ) { |
|
147 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
148 } |
|
149 } |
|
150 |
|
151 /*! |
|
152 \internal |
|
153 */ |
|
154 void MpMpxFrameworkWrapperPrivate::reopenCollection() |
|
155 { |
|
156 TRAPD(err, DoReopenCollectionL()); |
|
157 if ( err != KErrNone ) { |
|
158 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
159 } |
|
160 } |
|
161 |
|
162 /*! |
|
163 \internal |
|
164 */ |
|
165 void MpMpxFrameworkWrapperPrivate::back() |
|
166 { |
|
167 TRAPD(err, DoBackL()); |
|
168 if ( err != KErrNone ) { |
|
169 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
170 } |
|
171 } |
|
172 /*! |
|
173 \internal |
|
174 */ |
|
175 void MpMpxFrameworkWrapperPrivate::findPlaylists( QStringList &playlists ) |
|
176 { |
|
177 TRAPD(err, DoFindPlaylistsL(playlists)); |
|
178 if ( err != KErrNone ) { |
|
179 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
180 } |
|
181 } |
|
182 |
|
183 /*! |
|
184 \internal |
|
185 */ |
|
186 void MpMpxFrameworkWrapperPrivate::createPlaylist( QString playlistName, QList<int> selection ) |
|
187 { |
|
188 TRAPD(err, DoCreatePlaylistL(playlistName, selection)); |
|
189 if ( err != KErrNone ) { |
|
190 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
191 } |
|
192 } |
|
193 |
|
194 /*! |
|
195 \internal |
|
196 */ |
|
197 void MpMpxFrameworkWrapperPrivate::saveToPlaylist( int playlistIndex, QList<int> selection ) |
|
198 { |
|
199 TRAPD(err, DoSaveToPlaylistL(playlistIndex, selection)); |
|
200 if ( err != KErrNone ) { |
|
201 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
202 } |
|
203 } |
|
204 |
|
205 /*! |
|
206 \internal |
|
207 */ |
|
208 void MpMpxFrameworkWrapperPrivate::deleteSongs( QList<int> selection ) |
|
209 { |
|
210 TRAPD(err, DoDeleteSongsL(selection)); |
|
211 if ( err != KErrNone ) { |
|
212 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
213 } |
|
214 } |
|
215 |
|
216 /*! |
|
217 \internal |
|
218 */ |
|
219 void MpMpxFrameworkWrapperPrivate::renamePlaylist( QString newName, int index ) |
|
220 { |
|
221 TRAPD(err, DoRenamePlaylistL(newName, index)); |
|
222 if ( err != KErrNone ) { |
|
223 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
224 } |
|
225 } |
|
226 |
|
227 /*! |
|
228 \internal |
|
229 */ |
|
230 void MpMpxFrameworkWrapperPrivate::renamePlaylist( QString newName ) |
|
231 { |
|
232 TRAPD(err, DoRenamePlaylistL(newName)); |
|
233 if ( err != KErrNone ) { |
|
234 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
235 } |
|
236 } |
|
237 /*! |
|
238 \internal |
|
239 */ |
|
240 void MpMpxFrameworkWrapperPrivate::setShuffle( bool active ) |
|
241 { |
|
242 TRAPD(err, DoSetShuffleL(active)); |
|
243 if ( err != KErrNone ) { |
|
244 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
245 } |
|
246 } |
|
247 |
|
248 /*! |
|
249 \internal |
|
250 */ |
|
251 void MpMpxFrameworkWrapperPrivate::scan() |
|
252 { |
|
253 TRAPD(err, DoScanL()); |
|
254 if ( err != KErrNone ) { |
|
255 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
256 } |
|
257 } |
|
258 |
|
259 /*! |
|
260 \internal |
|
261 */ |
|
262 void MpMpxFrameworkWrapperPrivate::cancelScan() |
|
263 { |
|
264 TRAPD(err, DoCancelScanL()); |
|
265 if ( err != KErrNone ) { |
|
266 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
267 } |
|
268 } |
|
269 |
|
270 /*! |
|
271 \internal |
|
272 */ |
|
273 void MpMpxFrameworkWrapperPrivate::previewItem( int index ) |
|
274 { |
|
275 TRAPD(err, DoPreviewItemL(index)); |
|
276 if ( err != KErrNone ) { |
|
277 TX_LOG_ARGS("Error: " << err << "; should never get here."); |
|
278 } |
|
279 } |
|
280 |
|
281 /*! |
|
282 \internal |
|
283 */ |
|
284 MpMpxCollectionData *MpMpxFrameworkWrapperPrivate::collectionData() |
|
285 { |
|
286 return iCollectionData; |
|
287 } |
|
288 |
|
289 /*! |
|
290 \internal |
|
291 */ |
|
292 void MpMpxFrameworkWrapperPrivate::HandleOpenL( |
|
293 const CMPXMedia& aEntries, |
|
294 TInt aIndex, |
|
295 TBool aComplete, |
|
296 TInt aError ) |
|
297 { |
|
298 Q_UNUSED(aIndex); |
|
299 TX_UNUSED(aComplete); |
|
300 TX_ENTRY_ARGS("aError=" << aError << "aComplete=" << aComplete); |
|
301 if ( aError == KErrNone ) { |
|
302 if ( iFirstIncrementalOpen ) { |
|
303 iCollectionData->setMpxMedia(aEntries); |
|
304 iFirstIncrementalOpen = EFalse; |
|
305 } |
|
306 } |
|
307 else { |
|
308 TX_LOG_ARGS("Error: " << aError << "; should never get here."); |
|
309 } |
|
310 TX_EXIT |
|
311 } |
|
312 |
|
313 /*! |
|
314 \internal |
|
315 */ |
|
316 void MpMpxFrameworkWrapperPrivate::HandleOpenL( |
|
317 const CMPXCollectionPlaylist& aPlaylist, |
|
318 TInt aError ) |
|
319 { |
|
320 TX_ENTRY_ARGS("aError=" << aError); |
|
321 |
|
322 if ( aError == KErrNone ) { |
|
323 if ( !iPlaybackUtility ) { |
|
324 iPlaybackUtility = MMPXPlaybackUtility::UtilityL( TUid::Uid(MpCommon::KMusicPlayerUid) ); |
|
325 if ( iViewMode == MpCommon::DefaultView ) { |
|
326 iPlaybackUtility->SetL( EPbPropertyRandomMode, MpSettingsManager::shuffle() ? ETrue : EFalse ); |
|
327 iPlaybackUtility->SetL( EPbPropertyRepeatMode, MpSettingsManager::repeat() ? EPbRepeatAll : EPbRepeatOff); |
|
328 } |
|
329 } |
|
330 iPlaybackUtility->InitL( aPlaylist, ETrue ); |
|
331 emit q_ptr->collectionPlaylistOpened(); |
|
332 } |
|
333 else { |
|
334 TX_LOG_ARGS("Error: " << aError << "; should never get here."); |
|
335 } |
|
336 TX_EXIT |
|
337 } |
|
338 |
|
339 /*! |
|
340 \internal |
|
341 */ |
|
342 void MpMpxFrameworkWrapperPrivate::HandleCollectionMessage( |
|
343 CMPXMessage* aMsg, |
|
344 TInt aErr ) |
|
345 { |
|
346 TX_ENTRY_ARGS("aErr=" << aErr); |
|
347 if ( aErr == KErrNone && aMsg ) |
|
348 { |
|
349 TRAP_IGNORE( DoHandleCollectionMessageL( *aMsg ) ); |
|
350 } |
|
351 TX_EXIT |
|
352 } |
|
353 |
|
354 /*! |
|
355 \internal |
|
356 */ |
|
357 void MpMpxFrameworkWrapperPrivate::HandleCollectionMediaL( |
|
358 const CMPXMedia& aMedia, |
|
359 TInt aError ) |
|
360 { |
|
361 Q_UNUSED(aMedia); |
|
362 Q_UNUSED(aError); |
|
363 } |
|
364 |
|
365 /*! |
|
366 \internal |
|
367 Handles the completion of any collection helper event. |
|
368 */ |
|
369 void MpMpxFrameworkWrapperPrivate::HandleOperationCompleteL( |
|
370 TCHelperOperation aOperation, |
|
371 TInt aErr, |
|
372 void* aArgument ) |
|
373 { |
|
374 TX_ENTRY_ARGS("aErr=" << aErr); |
|
375 switch( aOperation ) { |
|
376 case EDeleteOp: |
|
377 if ( KErrNone == aErr ) { |
|
378 emit q_ptr->songsDeleted(true); |
|
379 } |
|
380 else { |
|
381 emit q_ptr->songsDeleted(false); |
|
382 } |
|
383 break; |
|
384 case EAddOp: |
|
385 if ( KErrNone == aErr ) { |
|
386 emit q_ptr->playlistSaved(true); |
|
387 } |
|
388 else { |
|
389 emit q_ptr->playlistSaved(false); |
|
390 } |
|
391 break; |
|
392 case ERenameOp: |
|
393 if ( KErrNone == aErr ) { |
|
394 emit q_ptr->playlistsRenamed(true); |
|
395 } |
|
396 else { |
|
397 emit q_ptr->playlistsRenamed(false); |
|
398 } |
|
399 break; |
|
400 default: |
|
401 break; |
|
402 } |
|
403 |
|
404 if ( aArgument ) { |
|
405 delete ( CBase* )aArgument; |
|
406 } |
|
407 } |
|
408 |
|
409 /*! |
|
410 \internal |
|
411 */ |
|
412 void MpMpxFrameworkWrapperPrivate::DoInitL() |
|
413 { |
|
414 TX_ENTRY |
|
415 iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault ); |
|
416 iCollectionUiHelper = CMPXCollectionHelperFactory:: NewCollectionUiHelperL(); |
|
417 iIncrementalOpenUtil = CMPXCollectionOpenUtility::NewL( this ); |
|
418 |
|
419 iHarvesterUtility = CMPXHarvesterFactory::NewL(); |
|
420 iHarvesterUtility->CheckForSystemEventsL(); |
|
421 |
|
422 iCollectionData = new MpMpxCollectionData(); |
|
423 TX_EXIT |
|
424 } |
|
425 |
|
426 /*! |
|
427 \internal |
|
428 */ |
|
429 void MpMpxFrameworkWrapperPrivate::DoOpenCollectionL( |
|
430 TCollectionContext aContext ) |
|
431 { |
|
432 TX_ENTRY_ARGS("aContext=" << aContext); |
|
433 |
|
434 switch ( aContext ) { |
|
435 case ECollectionContextAllSongs: |
|
436 { |
|
437 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicAllSongsPathL(); |
|
438 CleanupStack::PushL( cpath ); |
|
439 iCollectionUtility->Collection().OpenL( *cpath ); |
|
440 CleanupStack::PopAndDestroy( cpath ); |
|
441 break; |
|
442 } |
|
443 case ECollectionContextArtistAlbums: |
|
444 { |
|
445 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL(); |
|
446 CleanupStack::PushL( cpath ); |
|
447 cpath->AppendL( 3 ); |
|
448 iCollectionUtility->Collection().OpenL( *cpath ); |
|
449 CleanupStack::PopAndDestroy( cpath ); |
|
450 break; |
|
451 } |
|
452 case ECollectionContextPlaylists: |
|
453 { |
|
454 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicPlaylistPathL(); |
|
455 CleanupStack::PushL( cpath ); |
|
456 iCollectionUtility->Collection().OpenL( *cpath ); |
|
457 CleanupStack::PopAndDestroy( cpath ); |
|
458 break; |
|
459 } |
|
460 case ECollectionContextGenres: |
|
461 { |
|
462 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicMenuPathL(); |
|
463 CleanupStack::PushL( cpath ); |
|
464 // Temp |
|
465 cpath->AppendL( 5 ); |
|
466 iCollectionUtility->Collection().OpenL( *cpath ); |
|
467 CleanupStack::PopAndDestroy( cpath ); |
|
468 break; |
|
469 } |
|
470 default: |
|
471 TX_LOG_ARGS("Error: Unexpected context; should never get here."); |
|
472 break; |
|
473 } |
|
474 TX_EXIT |
|
475 } |
|
476 |
|
477 /*! |
|
478 \internal |
|
479 */ |
|
480 void MpMpxFrameworkWrapperPrivate::DoOpenCollectionItemL( TInt aIndex ) |
|
481 { |
|
482 TX_ENTRY_ARGS("aIndex=" << aIndex); |
|
483 iCollectionUtility->Collection().OpenL( aIndex ); |
|
484 TX_EXIT |
|
485 } |
|
486 |
|
487 /*! |
|
488 \internal |
|
489 */ |
|
490 void MpMpxFrameworkWrapperPrivate::DoIncrementalOpenL() |
|
491 { |
|
492 TX_ENTRY |
|
493 // Cancel any reads |
|
494 iIncrementalOpenUtil->Stop(); |
|
495 |
|
496 // Start the read |
|
497 iFirstIncrementalOpen = ETrue; |
|
498 RArray<TMPXAttribute> attrs; |
|
499 CleanupClosePushL( attrs ); |
|
500 TArray<TMPXAttribute> ary = attrs.Array(); |
|
501 iIncrementalOpenUtil->SetDelay( KIncrementalDelayNone ); |
|
502 iIncrementalOpenUtil->StartL( ary, KIncrementalFetchBlockSize, |
|
503 KErrNotFound, CMPXCollectionOpenUtility::EFetchNormal ); |
|
504 iIncrementalOpenUtil->SetDelay( KIncrementalDelayHalfSecond ); |
|
505 CleanupStack::PopAndDestroy( &attrs ); |
|
506 TX_EXIT |
|
507 } |
|
508 |
|
509 /*! |
|
510 \internal |
|
511 */ |
|
512 void MpMpxFrameworkWrapperPrivate::DoReopenCollectionL() |
|
513 { |
|
514 TX_ENTRY |
|
515 CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL(); |
|
516 CleanupStack::PushL( cpath ); |
|
517 cpath->Back(); |
|
518 iCollectionUtility->Collection().OpenL(*cpath); |
|
519 CleanupStack::PopAndDestroy( cpath ); |
|
520 TX_EXIT |
|
521 } |
|
522 |
|
523 /*! |
|
524 \internal |
|
525 */ |
|
526 void MpMpxFrameworkWrapperPrivate::DoBackL() |
|
527 { |
|
528 TX_ENTRY |
|
529 iCollectionUtility->Collection().BackL(); |
|
530 TX_EXIT |
|
531 } |
|
532 |
|
533 /*! |
|
534 \internal |
|
535 */ |
|
536 void MpMpxFrameworkWrapperPrivate::DoFindPlaylistsL( QStringList &playlists ) |
|
537 { |
|
538 TX_ENTRY |
|
539 delete iUserPlaylists; |
|
540 iUserPlaylists = NULL; |
|
541 |
|
542 RArray<TMPXAttribute> attrs; |
|
543 CleanupClosePushL( attrs ); |
|
544 attrs.Append( KMPXMediaGeneralId ); |
|
545 attrs.Append( KMPXMediaGeneralTitle ); |
|
546 |
|
547 CMPXMedia* criteria = CMPXMedia::NewL(); |
|
548 CleanupStack::PushL( criteria ); |
|
549 criteria->SetTObjectValueL<TMPXGeneralType>( |
|
550 KMPXMediaGeneralType, EMPXGroup ); |
|
551 criteria->SetTObjectValueL<TMPXGeneralCategory>( |
|
552 KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
553 |
|
554 // Look up collection UID and set to criteria |
|
555 RArray<TUid> ary; |
|
556 CleanupClosePushL( ary ); |
|
557 ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) ); |
|
558 TUid musicCollection = iCollectionUtility->CollectionIDL( ary.Array() ); |
|
559 CleanupStack::PopAndDestroy( &ary ); |
|
560 |
|
561 criteria->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, musicCollection ); |
|
562 |
|
563 iUserPlaylists = iCollectionUtility->Collection().FindAllL( *criteria, attrs.Array() ); |
|
564 CleanupStack::PopAndDestroy( criteria ); |
|
565 CleanupStack::PopAndDestroy( &attrs ); |
|
566 |
|
567 if ( iUserPlaylists ) { |
|
568 const CMPXMediaArray* mediaArray = |
|
569 iUserPlaylists->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
570 User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray)); |
|
571 TInt count = mediaArray->Count(); |
|
572 for ( TInt i = 0; i < count; i++ ) { |
|
573 CMPXMedia* media( mediaArray->AtL(i) ); |
|
574 const TDesC& titleText = media->ValueText( KMPXMediaGeneralTitle ); |
|
575 if ( titleText.Compare( KNullDesC ) != 0 ) { |
|
576 playlists += QString::fromUtf16( titleText.Ptr(), titleText.Length() ); |
|
577 } |
|
578 } |
|
579 } |
|
580 TX_EXIT |
|
581 } |
|
582 |
|
583 /*! |
|
584 \internal |
|
585 */ |
|
586 void MpMpxFrameworkWrapperPrivate::DoCreatePlaylistL( QString playlistName, QList<int> selection ) |
|
587 { |
|
588 TX_ENTRY_ARGS("playlistName=" << playlistName); |
|
589 CMPXMedia* tracks = CMPXMedia::NewL(); |
|
590 CleanupStack::PushL( tracks ); |
|
591 |
|
592 TPtrC ptr(reinterpret_cast<const TText*>(playlistName.constData())); |
|
593 tracks->SetTextValueL( KMPXMediaGeneralTitle, ptr ); |
|
594 tracks->SetTextValueL( KMPXMediaGeneralUri, KPlaylistPath ); |
|
595 PreparePlaylistMediaL(*tracks, selection); |
|
596 |
|
597 iCollectionUiHelper->IncAddL( *tracks, this, KMPXChunkSize ); |
|
598 CleanupStack::PopAndDestroy( tracks ); |
|
599 } |
|
600 |
|
601 /*! |
|
602 \internal |
|
603 */ |
|
604 void MpMpxFrameworkWrapperPrivate::DoSaveToPlaylistL( int playlistIndex, QList<int> selection ) |
|
605 { |
|
606 TX_ENTRY_ARGS("playlistIndex=" << playlistIndex); |
|
607 CMPXMedia* tracks = CMPXMedia::NewL(); |
|
608 CleanupStack::PushL( tracks ); |
|
609 |
|
610 const CMPXMediaArray* mediaArray = |
|
611 iUserPlaylists->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
612 User::LeaveIfNull( const_cast<CMPXMediaArray*>( mediaArray )); |
|
613 CMPXMedia* media( mediaArray->AtL(playlistIndex) ); |
|
614 TMPXItemId playlistId = media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ); |
|
615 |
|
616 RArray<TUid> ary; |
|
617 CleanupClosePushL( ary ); |
|
618 ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) ); |
|
619 TUid musicCollection = iCollectionUtility->CollectionIDL( ary.Array() ); |
|
620 CleanupStack::PopAndDestroy( &ary ); |
|
621 |
|
622 tracks->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, playlistId ); |
|
623 tracks->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, musicCollection ); |
|
624 PreparePlaylistMediaL(*tracks, selection); |
|
625 |
|
626 iCollectionUiHelper->IncAddL( *tracks, this, KMPXChunkSize ); |
|
627 CleanupStack::PopAndDestroy( tracks ); |
|
628 } |
|
629 |
|
630 /*! |
|
631 \internal |
|
632 */ |
|
633 void MpMpxFrameworkWrapperPrivate::DoDeleteSongsL( QList<int> selection ) |
|
634 { |
|
635 int count = selection.count(); |
|
636 TX_ENTRY_ARGS("selection count=" << count); |
|
637 |
|
638 CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() ); |
|
639 CleanupStack::PushL( path ); |
|
640 |
|
641 for ( TInt i = 0; i < count; i++ ) { |
|
642 path->SelectL( selection.at(i) ); |
|
643 } |
|
644 iCollectionUiHelper->DeleteL( *path, this ); |
|
645 CleanupStack::PopAndDestroy( path ); |
|
646 } |
|
647 |
|
648 /*! |
|
649 \internal |
|
650 */ |
|
651 void MpMpxFrameworkWrapperPrivate::DoRenamePlaylistL( QString newName, int index) |
|
652 { |
|
653 CMPXMediaArray *mediaArray; |
|
654 const CMPXMedia& container = iCollectionData->containerMedia(); |
|
655 mediaArray = const_cast<CMPXMediaArray*>(container.Value<CMPXMediaArray>( KMPXMediaArrayContents ) ); |
|
656 CMPXMedia* currentPlaylistMedia( mediaArray->AtL( index ) ); |
|
657 TMPXItemId id( currentPlaylistMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
658 DoRenamePlaylistL( id, newName ); |
|
659 } |
|
660 |
|
661 /*! |
|
662 \internal |
|
663 */ |
|
664 void MpMpxFrameworkWrapperPrivate::DoRenamePlaylistL( QString newName ) |
|
665 { |
|
666 const CMPXMedia& container = iCollectionData->containerMedia(); |
|
667 TMPXItemId id( container.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
668 DoRenamePlaylistL( id, newName ); |
|
669 } |
|
670 |
|
671 /*! |
|
672 \internal |
|
673 */ |
|
674 void MpMpxFrameworkWrapperPrivate::DoRenamePlaylistL( TMPXItemId id, QString newName ) |
|
675 { |
|
676 CMPXMedia* media = CMPXMedia::NewL(); |
|
677 CleanupStack::PushL( media ); |
|
678 media->SetTObjectValueL<TMPXGeneralType>( |
|
679 KMPXMediaGeneralType, EMPXItem ); |
|
680 media->SetTObjectValueL<TMPXGeneralCategory>( |
|
681 KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
682 media->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id ); |
|
683 TPtrC ptr(reinterpret_cast<const TText*>(newName.constData())); |
|
684 media->SetTextValueL( KMPXMediaGeneralTitle, ptr ); |
|
685 iCollectionUiHelper->RenameL( *media, this ); |
|
686 CleanupStack::PopAndDestroy( media ); |
|
687 } |
|
688 |
|
689 /*! |
|
690 \internal |
|
691 */ |
|
692 void MpMpxFrameworkWrapperPrivate::DoSetShuffleL( bool active ) |
|
693 { |
|
694 TX_ENTRY |
|
695 |
|
696 if ( iPlaybackUtility ) { |
|
697 iPlaybackUtility->SetL( EPbPropertyRandomMode, active ); |
|
698 } |
|
699 TX_EXIT |
|
700 } |
|
701 |
|
702 /*! |
|
703 \internal |
|
704 */ |
|
705 void MpMpxFrameworkWrapperPrivate::DoScanL() |
|
706 { |
|
707 TX_ENTRY |
|
708 iNumItemsAdded = 0; |
|
709 iHarvesterUtility->ScanL(); |
|
710 TX_EXIT |
|
711 } |
|
712 |
|
713 /*! |
|
714 \internal |
|
715 */ |
|
716 void MpMpxFrameworkWrapperPrivate::DoCancelScanL() |
|
717 { |
|
718 TX_ENTRY |
|
719 // If harvester crashes, restart it. |
|
720 TRAPD( err, iHarvesterUtility->CancelScanL() ); |
|
721 if ( err != KErrNone ) { |
|
722 iHarvesterUtility->Close(); |
|
723 iHarvesterUtility = NULL; |
|
724 iHarvesterUtility = CMPXHarvesterFactory::NewL(); |
|
725 iHarvesterUtility->CheckForSystemEventsL(); |
|
726 } |
|
727 TX_EXIT |
|
728 } |
|
729 |
|
730 /*! |
|
731 \internal |
|
732 */ |
|
733 void MpMpxFrameworkWrapperPrivate::DoPreviewItemL( int index ) |
|
734 { |
|
735 TX_ENTRY |
|
736 if ( !iPlaybackUtility ) { |
|
737 iPlaybackUtility = MMPXPlaybackUtility::UtilityL( TUid::Uid(MpCommon::KMusicPlayerUid) ); |
|
738 } |
|
739 |
|
740 // Get the current path |
|
741 CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL(); |
|
742 CleanupStack::PushL( cpath ); |
|
743 MPX_DEBUG_PATH(*cpath); |
|
744 cpath->Back(); |
|
745 |
|
746 CMPXMediaArray *mediaArray; |
|
747 const CMPXMedia& container = iCollectionData->containerMedia(); |
|
748 mediaArray = const_cast<CMPXMediaArray*>(container.Value<CMPXMediaArray>( KMPXMediaArrayContents ) ); |
|
749 CMPXMedia* currentMedia( mediaArray->AtL( index ) ); |
|
750 TMPXItemId id( currentMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
751 |
|
752 cpath->AppendL(id); // Top level items of songs |
|
753 cpath->Set(0); // Select 1st song |
|
754 |
|
755 CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath ); |
|
756 CleanupStack::PushL( playList ); |
|
757 playList->SetToFirst(); |
|
758 |
|
759 iPlaybackUtility->InitL( *playList, ETrue ); |
|
760 emit q_ptr->collectionPlaylistOpened(); |
|
761 |
|
762 CleanupStack::PopAndDestroy( playList ); |
|
763 CleanupStack::PopAndDestroy( cpath ); |
|
764 TX_EXIT |
|
765 } |
|
766 |
|
767 /*! |
|
768 \internal |
|
769 */ |
|
770 void MpMpxFrameworkWrapperPrivate::DoHandleCollectionMessageL( |
|
771 const CMPXMessage& aMsg ) |
|
772 { |
|
773 TX_ENTRY |
|
774 TMPXMessageId id( aMsg.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
775 if ( KMPXMessageGeneral == id ) { |
|
776 TInt event( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
777 TInt type( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ); |
|
778 TInt data( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralData ) ); |
|
779 TX_LOG_ARGS("event=" << event << ", type=" << type << ", data=" << data); |
|
780 |
|
781 if ( event == TMPXCollectionMessage::EPathChanged && |
|
782 type == EMcPathChangedByOpen && |
|
783 data == EMcContainerOpened ) { |
|
784 // Incremental Open when browsing to the next level |
|
785 DoIncrementalOpenL(); |
|
786 } |
|
787 else if ( event == TMPXCollectionMessage::EPathChanged && |
|
788 type == EMcPathChangedByOpen && |
|
789 data == EMcItemOpened ) { |
|
790 // Opened a song |
|
791 // This will result in HandleOpenL with CMPXCollectionPlaylist |
|
792 iCollectionUtility->Collection().OpenL(); |
|
793 } |
|
794 |
|
795 if ( event == TMPXCollectionMessage::EBroadcastEvent ) { |
|
796 switch (type) { |
|
797 case EMcMsgRefreshStart: |
|
798 emit q_ptr->scanStarted(); |
|
799 break; |
|
800 case EMcMsgRefreshEnd: |
|
801 case EMcMsgDiskInserted: |
|
802 emit q_ptr->scanEnded(); |
|
803 break; |
|
804 default: |
|
805 break; |
|
806 } |
|
807 } |
|
808 } |
|
809 else if( KMPXMessageIdItemChanged == id ) { |
|
810 if ( aMsg.IsSupported(KMPXMessageArrayContents) ) { |
|
811 // Loop through messages for arrays |
|
812 const CMPXMessageArray* messageArray = |
|
813 aMsg.Value<CMPXMessageArray>(KMPXMessageArrayContents); |
|
814 User::LeaveIfNull(const_cast<CMPXMessageArray*>(messageArray)); |
|
815 |
|
816 for ( TInt i=0; i<messageArray->Count(); ++i ) { |
|
817 HandleCollectionMessage( messageArray->AtL( i ), KErrNone ); |
|
818 } |
|
819 emit q_ptr->scanCountChanged(iNumItemsAdded); |
|
820 } |
|
821 else { |
|
822 // Single item |
|
823 TMPXChangeEventType changeType( aMsg.ValueTObjectL<TMPXChangeEventType>( KMPXMessageChangeEventType ) ); |
|
824 TMPXGeneralCategory cat(aMsg.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory)); |
|
825 if( changeType == EMPXItemInserted && |
|
826 (cat == EMPXSong || cat == EMPXPlaylist || cat == EMPXPodcast) ) { |
|
827 iNumItemsAdded++; |
|
828 } |
|
829 } |
|
830 } |
|
831 TX_EXIT |
|
832 } |
|
833 |
|
834 void MpMpxFrameworkWrapperPrivate::PreparePlaylistMediaL( |
|
835 CMPXMedia& aMedia, |
|
836 QList<int> selection ) |
|
837 { |
|
838 int count = selection.count(); |
|
839 TX_ENTRY_ARGS("selection count=" << count); |
|
840 |
|
841 const CMPXMedia& container = iCollectionData->containerMedia(); |
|
842 const CMPXMediaArray* containerArray = container.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
843 User::LeaveIfNull( const_cast<CMPXMediaArray*>( containerArray )); |
|
844 CMPXMediaArray* tracksArray( CMPXMediaArray::NewL() ); |
|
845 CleanupStack::PushL( tracksArray ); |
|
846 |
|
847 CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() ); |
|
848 CleanupStack::PushL( path ); |
|
849 TMPXItemId collectionId( path->Id( 0 ) ); |
|
850 CleanupStack::PopAndDestroy( path ); |
|
851 |
|
852 if ( iCollectionData->context() == ECollectionContextArtistAlbums ) { |
|
853 for ( TInt i = 0; i < count; i++ ) { |
|
854 CMPXMedia* results; |
|
855 CMPXMedia* album( containerArray->AtL( selection[i] ) ); |
|
856 // Fetch the songs for the selected album |
|
857 TMPXItemId albumId = album->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
858 CMPXMedia* findCriteria = CMPXMedia::NewL(); |
|
859 CleanupStack::PushL( findCriteria ); |
|
860 findCriteria->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXGroup ); |
|
861 findCriteria->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXSong ); |
|
862 findCriteria->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, albumId ); |
|
863 RArray<TMPXAttribute> attrs; |
|
864 CleanupClosePushL( attrs ); |
|
865 attrs.Append( TMPXAttribute( KMPXMediaIdGeneral, |
|
866 EMPXMediaGeneralTitle | |
|
867 EMPXMediaGeneralId ) ); |
|
868 attrs.Append( KMPXMediaMusicAlbumTrack ); |
|
869 results = iCollectionUtility->Collection().FindAllL( *findCriteria, attrs.Array()); |
|
870 CleanupStack::PopAndDestroy( &attrs ); |
|
871 CleanupStack::PopAndDestroy( findCriteria ); |
|
872 CleanupStack::PushL( results ); |
|
873 |
|
874 const CMPXMediaArray* resultsArray = results->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
875 User::LeaveIfNull( resultsArray ); |
|
876 for (int j = 0 ; j < resultsArray->Count();j++) { |
|
877 CMPXMedia* media( resultsArray->AtL(j) ); |
|
878 CMPXMedia* entry = CMPXMedia::NewL(); |
|
879 CleanupStack::PushL( entry ); |
|
880 entry->SetTextValueL( KMPXMediaGeneralTitle, |
|
881 media->ValueText( KMPXMediaGeneralTitle ) ); |
|
882 entry->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem); |
|
883 entry->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
884 entry->SetTObjectValueL( KMPXMediaGeneralId, |
|
885 media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
886 entry->SetTObjectValueL( KMPXMediaGeneralCollectionId, collectionId ); |
|
887 tracksArray->AppendL( entry ); |
|
888 CleanupStack::Pop( entry ); |
|
889 } |
|
890 CleanupStack::PopAndDestroy( results ); |
|
891 } |
|
892 |
|
893 } |
|
894 else { |
|
895 for ( TInt i = 0; i < count; i++ ) { |
|
896 CMPXMedia* media( containerArray->AtL(selection.at(i)) ); |
|
897 CMPXMedia* entry = CMPXMedia::NewL(); |
|
898 CleanupStack::PushL( entry ); |
|
899 entry->SetTextValueL( KMPXMediaGeneralTitle, |
|
900 media->ValueText( KMPXMediaGeneralTitle ) ); |
|
901 entry->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem); |
|
902 entry->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong ); |
|
903 entry->SetTObjectValueL( KMPXMediaGeneralId, |
|
904 media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ); |
|
905 entry->SetTObjectValueL( KMPXMediaGeneralCollectionId, collectionId ); |
|
906 tracksArray->AppendL( entry ); |
|
907 CleanupStack::Pop( entry ); |
|
908 } |
|
909 } |
|
910 aMedia.SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem ); |
|
911 aMedia.SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXPlaylist ); |
|
912 aMedia.SetCObjectValueL( KMPXMediaArrayContents, tracksArray ); |
|
913 aMedia.SetTObjectValueL( KMPXMediaArrayCount, tracksArray->Count() ); |
|
914 |
|
915 CleanupStack::PopAndDestroy( tracksArray ); |
|
916 TX_EXIT |
|
917 } |