|
1 /* |
|
2 * Copyright (c) 2006 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: Saves/restores current playback path |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <bldvariant.hrh> |
|
21 #include <s32file.h> |
|
22 |
|
23 #include <eikenv.h> |
|
24 #include <mpxcollectionframeworkdefs.h> |
|
25 #include <mpxcollectionmessage.h> |
|
26 #include <mpxcollectionutility.h> |
|
27 #include <mpxcollectionplaylist.h> |
|
28 #include <mpxcollectionpath.h> |
|
29 #include <mpxcollectionuihelper.h> |
|
30 #include <mpxcollectionhelperfactory.h> |
|
31 #include <mpxplaybackutility.h> |
|
32 #include <mpxplaybackmessage.h> |
|
33 #include <mpxplaybackpluginobserver.h> |
|
34 #include <mpxmessagegeneraldefs.h> |
|
35 #include <mpxplaybackmessagedefs.h> |
|
36 #include <mpxcollectionopenutility.h> |
|
37 #include <mpxsubscription.h> |
|
38 #include <mpxviewutility.h> |
|
39 #include <mpxmusicplayerviewplugin.hrh> |
|
40 |
|
41 #include "mpxrestorepath.h" |
|
42 #include <mpxconstants.h> |
|
43 #include "mpxlog.h" |
|
44 |
|
45 // CONSTANTS |
|
46 _LIT( KMPXCollectionPathFileName, "c:\\system\\data\\mpxcollectionpath.dat" ); |
|
47 const TInt KIncrementalFetchCount = 400; |
|
48 const TInt KIncrementalNullOffset = 0; |
|
49 const TInt KIncrementalLoadDelay = 1000000; // 1 second in ms |
|
50 #define KMPXPdSbPlaybackViewImplementationId 0x10207BD0 |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS ============================== |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // Two-phased constructor. |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 CMPXRestorePath* CMPXRestorePath::NewL(MMPXPlaybackUtility* aPlaybackUtility, |
|
59 MMPXCollectionUiHelper* aCollectionUiHelper) |
|
60 { |
|
61 CMPXRestorePath* self = NewLC(aPlaybackUtility, aCollectionUiHelper); |
|
62 CleanupStack::Pop(self); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // Two-phased constructor. |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 CMPXRestorePath* CMPXRestorePath::NewLC(MMPXPlaybackUtility* aPlaybackUtility, |
|
71 MMPXCollectionUiHelper* aCollectionUiHelper ) |
|
72 { |
|
73 CMPXRestorePath* self = new (ELeave) CMPXRestorePath(aPlaybackUtility, |
|
74 aCollectionUiHelper); |
|
75 CleanupStack::PushL(self); |
|
76 self->ConstructL(); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // C++ constructor can NOT contain any code that might leave. |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 CMPXRestorePath::CMPXRestorePath(MMPXPlaybackUtility* aPlaybackUtility, |
|
85 MMPXCollectionUiHelper* aCollectionUiHelper ): |
|
86 iPlaybackUtility(aPlaybackUtility), |
|
87 iCollectionUiHelper( aCollectionUiHelper ), |
|
88 iPathInitialized(0), |
|
89 iIsInitializing(EFalse), |
|
90 iInitCanceled(EFalse), |
|
91 iLoadSavedPath(EFalse), |
|
92 iRootPathId( KNullUid ) |
|
93 { |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // Destructor. |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 CMPXRestorePath::~CMPXRestorePath() |
|
101 { |
|
102 if ( iCollectionUtility ) |
|
103 { |
|
104 iCollectionUtility->Close(); |
|
105 } |
|
106 |
|
107 delete iIncOpenUtil; |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // Symbian 2nd phase constructor can leave. |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 void CMPXRestorePath::ConstructL() |
|
115 { |
|
116 iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated ); |
|
117 |
|
118 #ifdef __USE_MESSAGE_SUBSCRIPTION |
|
119 // Subscribe to only a few messages from collection utility |
|
120 CMPXSubscription* subscription( CMPXSubscription::NewL() ); |
|
121 CleanupStack::PushL( subscription ); |
|
122 CMPXSubscriptionItem* subItem1( CMPXSubscriptionItem::NewL() ); |
|
123 CleanupStack::PushL( subItem1 ); |
|
124 subItem1->SetTObjectValueL( KMPXMessageGeneralId, KMPXMessageGeneral ); |
|
125 subItem1->SetTObjectValueL( KMPXMessageGeneralEvent, TMPXCollectionMessage::EBroadcastEvent ); |
|
126 subscription->AddItemL( *subItem1 ); |
|
127 CMPXSubscriptionItem* subItem2( CMPXSubscriptionItem::CopyL( *subItem1 )); |
|
128 CleanupStack::PushL( subItem2 ); |
|
129 subItem2->SetTObjectValueL( KMPXMessageGeneralEvent, TMPXCollectionMessage::EPathChanged ); |
|
130 subItem2->SetTObjectValueL( KMPXMessageGeneralType, EMcPathChangedByOpen ); |
|
131 subItem2->SetTObjectValueL( KMPXMessageGeneralData, EMcItemOpened ); |
|
132 subscription->AddItemL( *subItem2 ); |
|
133 iCollectionUtility->Collection().AddSubscriptionL( *subscription ); |
|
134 CleanupStack::PopAndDestroy( subItem2 ); |
|
135 CleanupStack::PopAndDestroy( subItem1 ); |
|
136 CleanupStack::PopAndDestroy( subscription ); |
|
137 #endif |
|
138 |
|
139 iIncOpenUtil = CMPXCollectionOpenUtility::NewL( this, KMcModeIsolated ); |
|
140 iMTPStarted = EFalse; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // Load from file |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CMPXRestorePath::LoadPathL() |
|
148 { |
|
149 MPX_FUNC("CMPXRestorePath::LoadPathL()"); |
|
150 if (iIsInitializing) // avoid reenter |
|
151 return; |
|
152 iDefaultPath = EFalse; |
|
153 |
|
154 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
155 fs.MkDirAll( KMPXCollectionPathFileName ); |
|
156 TParse parsedName; |
|
157 |
|
158 fs.Parse( KMPXCollectionPathFileName, parsedName ); |
|
159 CFileStore* store( NULL ); |
|
160 MPX_TRAPD( error, store = CDirectFileStore::OpenL(fs, |
|
161 parsedName.FullName(), |
|
162 EFileRead ); ); |
|
163 |
|
164 // If we can internalize a collection path from file, we use that to |
|
165 // create a collection playlist. Otherwise, we construct the default |
|
166 // path using the collection helper. |
|
167 // |
|
168 CMPXCollectionPath* cpath( NULL ); |
|
169 if ( error == KErrNone ) |
|
170 { |
|
171 CleanupStack::PushL( store ); |
|
172 |
|
173 RStoreReadStream stream; |
|
174 stream.OpenLC( *store, store->Root() ); |
|
175 |
|
176 // Recreate the collection path that we were browsing |
|
177 cpath = CMPXCollectionPath::NewL(stream); |
|
178 CleanupStack::PushL(cpath); |
|
179 if( cpath->Levels() ) |
|
180 { |
|
181 iRootPathId = TUid::Uid( cpath->Id( 0 ) ); |
|
182 } |
|
183 TInt selection = stream.ReadInt32L(); |
|
184 |
|
185 // bounds checking |
|
186 if( selection >=0 && selection < cpath->Count() ) |
|
187 { |
|
188 cpath->Set( selection ); |
|
189 |
|
190 // Find out what we were selecting |
|
191 iSelectionId = cpath->Id(); |
|
192 iSelectionIndex = cpath->Index(); |
|
193 |
|
194 MPX_DEBUG1("CMPXRestorePath::LoadPathL -- Opening Path in collection"); |
|
195 |
|
196 // Rebrowse collection path of the container |
|
197 // We re-select the item when the container is opened and |
|
198 // in turn open the song |
|
199 // |
|
200 if( cpath->Levels() ) |
|
201 { |
|
202 cpath->Back(); |
|
203 } |
|
204 DoIncrementalOpenL( *cpath, iSelectionIndex, KIncrementalLoadDelay ); |
|
205 } |
|
206 else |
|
207 { |
|
208 // Bad collection path, restore to default |
|
209 MPX_DEBUG1("CMPXRestorePath::LoadPathL -- bad collection path found"); |
|
210 LoadDefaultPathL( KIncrementalLoadDelay ); |
|
211 } |
|
212 |
|
213 CleanupStack::PopAndDestroy( cpath); |
|
214 CleanupStack::PopAndDestroy(&stream); |
|
215 |
|
216 CleanupStack::PopAndDestroy(store); |
|
217 } |
|
218 else |
|
219 { |
|
220 delete store; |
|
221 cpath = iCollectionUiHelper->CreateDefaultPlaylistPathLC(); |
|
222 |
|
223 iDefaultPath = ETrue; |
|
224 iSelectionId = KMPXInvalidItemId; |
|
225 iSelectionIndex = 0; |
|
226 |
|
227 DoIncrementalOpenL( *cpath, iSelectionIndex, KIncrementalLoadDelay ); |
|
228 CleanupStack::PopAndDestroy( cpath ); |
|
229 } |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // Create the default path and load it in collection |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 void CMPXRestorePath::LoadDefaultPathL( TInt aDelay ) |
|
237 { |
|
238 MPX_DEBUG1("CMPXRestorePath::LoadDefaultPathL"); |
|
239 CMPXCollectionPath* cpath = iCollectionUiHelper->CreateDefaultPlaylistPathLC(); |
|
240 |
|
241 if (!iIsInitializing) |
|
242 { |
|
243 // Get incremental utility to open the path |
|
244 // |
|
245 DoIncrementalOpenL( *cpath, KIncrementalNullOffset, aDelay ); |
|
246 |
|
247 iPathInitialized = EFalse; |
|
248 iIsInitializing = ETrue; |
|
249 iInitCanceled = EFalse; |
|
250 iDefaultPath = ETrue; |
|
251 iSelectionId = KMPXInvalidItemId; |
|
252 } |
|
253 CleanupStack::PopAndDestroy( cpath ); |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // Save the currently playing playlist path |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 void CMPXRestorePath::SavePathL() |
|
261 { |
|
262 RFs& fs = CEikonEnv::Static()->FsSession(); |
|
263 fs.MkDirAll( KMPXCollectionPathFileName ); |
|
264 TParse parsedName; |
|
265 |
|
266 fs.Parse( KMPXCollectionPathFileName, parsedName ); |
|
267 CFileStore* store( NULL ); |
|
268 MPX_TRAPD( error, store = CDirectFileStore::ReplaceL(fs, |
|
269 parsedName.FullName(), |
|
270 EFileWrite ); ); |
|
271 |
|
272 if( error == KErrNone ) |
|
273 { |
|
274 CleanupStack::PushL( store ); |
|
275 store->SetTypeL(store->Layout()); |
|
276 |
|
277 RStoreWriteStream wStream; |
|
278 TStreamId stream = wStream.CreateLC( *store ); |
|
279 store->SetRootL( stream ); |
|
280 |
|
281 MMPXSource* source = iPlaybackUtility->Source(); |
|
282 CMPXCollectionPlaylist* pl( NULL ); |
|
283 TInt levels(0); |
|
284 |
|
285 // Make sure we have a source, a playlist, and a valid path |
|
286 // Playback engine path could be invalid (0 levels) but have |
|
287 // a source and playlist if the currently playing playlist |
|
288 // is deleted. |
|
289 // |
|
290 if( source ) |
|
291 { |
|
292 pl = source->PlaylistL(); |
|
293 if (pl) |
|
294 { |
|
295 CleanupStack::PushL( pl ); |
|
296 const CMPXCollectionPath& path = pl->Path(); |
|
297 levels = path.Levels(); |
|
298 if( levels > 0 ) |
|
299 { |
|
300 wStream << path; |
|
301 wStream.WriteInt32L( path.Index( path.Levels() - 1 ) ); |
|
302 wStream.CommitL(); |
|
303 } |
|
304 CleanupStack::PopAndDestroy( pl ); |
|
305 } |
|
306 } |
|
307 |
|
308 CleanupStack::PopAndDestroy( &wStream ); |
|
309 CleanupStack::PopAndDestroy( store ); |
|
310 |
|
311 // Delete if source was invalid. Have to do it here |
|
312 // because store owned a file handle to the file |
|
313 // |
|
314 if( !source || !pl || !levels ) |
|
315 { |
|
316 fs.Delete( KMPXCollectionPathFileName ); |
|
317 } |
|
318 } |
|
319 else |
|
320 { |
|
321 // File cannot be opened, so try to delete it so that when |
|
322 // music player tries to load the path next time it'll use |
|
323 // the default path |
|
324 // |
|
325 fs.Delete( KMPXCollectionPathFileName ); |
|
326 } |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // Check the initialized flag |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 TBool CMPXRestorePath::Initialized() |
|
334 { |
|
335 return iPathInitialized; |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // Check the iIsInitializing flag |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 TBool CMPXRestorePath::IsInitializing() |
|
343 { |
|
344 return iIsInitializing; |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // Set the initialized flag |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 void CMPXRestorePath::SetInitialized( TBool aInit ) |
|
352 { |
|
353 iPathInitialized = aInit; |
|
354 iIsInitializing = EFalse; |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // Cancels the initialize operation |
|
359 // --------------------------------------------------------------------------- |
|
360 // |
|
361 void CMPXRestorePath::CancelInit() |
|
362 { |
|
363 iInitCanceled = ETrue; |
|
364 SetInitialized( ETrue ); |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------------------------- |
|
368 // From MMPXCollectionObserver. |
|
369 // Handle media properties. |
|
370 // --------------------------------------------------------------------------- |
|
371 // |
|
372 void CMPXRestorePath::HandleCollectionMediaL( |
|
373 const CMPXMedia& /*aMedia*/, |
|
374 TInt /*aError*/ ) |
|
375 { |
|
376 // Do nothing |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // From MMPXCollectionObserver. |
|
381 // Handle collection message. |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 void CMPXRestorePath::HandleCollectionMessage( |
|
385 CMPXMessage* aMessage, TInt aError ) |
|
386 { |
|
387 if ( aError == KErrNone && aMessage ) |
|
388 { |
|
389 TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) ); |
|
390 } |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------------------------- |
|
394 // From MMPXCollectionObserver. |
|
395 // Handles the collection entries being opened. |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 void CMPXRestorePath::HandleOpenL( |
|
399 const CMPXMedia& /* aEntries */, |
|
400 TInt /* aIndex */, |
|
401 TBool /* aComplete */, |
|
402 TInt aError ) |
|
403 { |
|
404 // OpenL() callback from trying to open the default Music Menu -> All Songs |
|
405 // or from opening a container |
|
406 // |
|
407 MPX_DEBUG1("CMPXRestorePath::HandleOpenL -- Passing path to playback engine"); |
|
408 |
|
409 // Stop the incremental open algorithm. We are only interested in fetcing |
|
410 // a single block containing the item we want to play. This will speed up the |
|
411 // initalization procedure. Once the playlist is created, the playlist |
|
412 // takes over the rest of the incremental open operation |
|
413 // |
|
414 iIncOpenUtil->Stop(); |
|
415 if ( aError == KErrNone ) |
|
416 { |
|
417 |
|
418 CMPXCollectionPath* cPath = iIncOpenUtil->PathL(); |
|
419 CleanupStack::PushL( cPath ); |
|
420 |
|
421 if( iSelectionId != KMPXInvalidItemId ) |
|
422 { |
|
423 // Find the Index first |
|
424 TInt index = cPath->IndexOfId( iSelectionId ); |
|
425 |
|
426 // If the item still exists in the path, we open it to init playback |
|
427 if( index != KErrNotFound ) |
|
428 { |
|
429 cPath->Set( index ); |
|
430 iCollectionUtility->Collection().OpenL( *cPath ); |
|
431 } |
|
432 else |
|
433 { |
|
434 LoadDefaultPathL(); |
|
435 } |
|
436 iSelectionId = KMPXInvalidItemId; |
|
437 } |
|
438 else // Opening the default path |
|
439 { |
|
440 InitPlaybackEngineL( *cPath ); |
|
441 } |
|
442 CleanupStack::PopAndDestroy( cPath ); |
|
443 } |
|
444 else |
|
445 { |
|
446 if( iDefaultPath ) |
|
447 { |
|
448 MPX_DEBUG1("CMPXRestorePath::HandleOpenL - Failed to open default path"); |
|
449 // Failed to open default path, set to initialized |
|
450 // "No songs view" |
|
451 // |
|
452 iDefaultPath = EFalse; |
|
453 iPathInitialized = ETrue; |
|
454 iIsInitializing = EFalse; |
|
455 } |
|
456 else |
|
457 { |
|
458 MPX_DEBUG1("CMPXRestorePath::HandleOpenL - Opening default Path"); |
|
459 iIsInitializing = EFalse; |
|
460 // Try opening default |
|
461 LoadDefaultPathL(); |
|
462 } |
|
463 } |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // Handle playback message. |
|
468 // --------------------------------------------------------------------------- |
|
469 // |
|
470 void CMPXRestorePath::HandlePlaybackMessage( |
|
471 CMPXMessage* aMessage, TInt aError ) |
|
472 { |
|
473 if ( aError == KErrNone && aMessage ) |
|
474 { |
|
475 TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
476 } |
|
477 } |
|
478 |
|
479 |
|
480 // --------------------------------------------------------------------------- |
|
481 // From MMPXCollectionObserver. |
|
482 // Handles the item being opened. |
|
483 // --------------------------------------------------------------------------- |
|
484 // |
|
485 void CMPXRestorePath::HandleOpenL( |
|
486 const CMPXCollectionPlaylist& aPlaylist, |
|
487 TInt aError ) |
|
488 { |
|
489 MPX_FUNC("CMPXRestorePath::HandleOpenL"); |
|
490 if( aError == KErrNone ) |
|
491 { |
|
492 if ( !iInitCanceled ) |
|
493 { |
|
494 MPX_DEBUG1( "CMPXRestorePath::HandleOpenL - Opening playlist" ); |
|
495 |
|
496 // toggle repeat and shuffle to off if podcast playlist |
|
497 if(KMPXUidPodcastDBPlugin == TUid::Uid((TInt)aPlaylist.Path().Id(0))) |
|
498 { |
|
499 CMPXCollectionPlaylist* tmp = |
|
500 CMPXCollectionPlaylist::NewL( aPlaylist ); |
|
501 CleanupStack::PushL( tmp ); |
|
502 tmp->SetRepeatEnabled( EFalse ); |
|
503 tmp->SetShuffleEnabledL( EFalse ); |
|
504 iPlaybackUtility->InitL( *tmp, EFalse ); |
|
505 CleanupStack::PopAndDestroy( tmp ); |
|
506 } |
|
507 else |
|
508 { |
|
509 iPlaybackUtility->InitL( aPlaylist, EFalse ); |
|
510 } |
|
511 } |
|
512 else |
|
513 { |
|
514 MPX_DEBUG1( "CMPXRestorePath::HandleOpenL - Init canceled, do nothing" ); |
|
515 } |
|
516 } |
|
517 else |
|
518 { |
|
519 if( iDefaultPath ) |
|
520 { |
|
521 // Failed to open default path, set to initialized |
|
522 // "No songs view" |
|
523 // |
|
524 iDefaultPath = EFalse; |
|
525 iPathInitialized = ETrue; |
|
526 iIsInitializing = EFalse; |
|
527 } |
|
528 else |
|
529 { |
|
530 // Try opening default |
|
531 LoadDefaultPathL(); |
|
532 } |
|
533 } |
|
534 } |
|
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // Initialize the playback engine with a collection path |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 void CMPXRestorePath::InitPlaybackEngineL( CMPXCollectionPath& aPath ) |
|
541 { |
|
542 MPX_FUNC( "CMPXRestorePath::InitPlaybackEngineL" ); |
|
543 // Do not load a playlist if USB started, this |
|
544 // could happen if the user switches mode from MTP to USB |
|
545 // which would lose the playback playlist |
|
546 // |
|
547 if( !iUSBOngoing && !iInitCanceled ) |
|
548 { |
|
549 CMPXCollectionPlaylist* playlist = CMPXCollectionPlaylist::NewL( aPath ); |
|
550 CleanupStack::PushL( playlist ); |
|
551 iPlaybackUtility->InitL( *playlist, EFalse ); |
|
552 CleanupStack::PopAndDestroy( playlist ); |
|
553 } |
|
554 else |
|
555 { |
|
556 iIsInitializing = EFalse; |
|
557 iPathInitialized = ETrue; |
|
558 iInitCanceled = EFalse; |
|
559 } |
|
560 } |
|
561 |
|
562 // ----------------------------------------------------------------------------- |
|
563 // Handle playback message |
|
564 // ----------------------------------------------------------------------------- |
|
565 // |
|
566 void CMPXRestorePath::DoHandlePlaybackMessageL( const CMPXMessage& aMessage ) |
|
567 { |
|
568 MPX_FUNC( "CMPXRestorePath::DoHandlePlaybackMessageL" ); |
|
569 TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
570 if ( KMPXMessageGeneral == id ) |
|
571 { |
|
572 TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
573 MPX_DEBUG2( "CMPXRestorePath::DoHandlePlaybackMessageL(%d)", event ); |
|
574 |
|
575 switch ( event ) |
|
576 { |
|
577 default: |
|
578 { |
|
579 // ignore other messages |
|
580 break; |
|
581 } |
|
582 } |
|
583 } |
|
584 } |
|
585 |
|
586 // ----------------------------------------------------------------------------- |
|
587 // Handle collection message |
|
588 // ----------------------------------------------------------------------------- |
|
589 // |
|
590 void CMPXRestorePath::DoHandleCollectionMessageL( const CMPXMessage& aMessage ) |
|
591 { |
|
592 MPX_FUNC( "CMPXRestorePath::DoHandleCollectionMessageL" ); |
|
593 TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
594 if ( KMPXMessageGeneral == id ) |
|
595 { |
|
596 TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
597 TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ); |
|
598 TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) ); |
|
599 MPX_DEBUG3( "CMPXRestorePath::DoHandleCollectionMessageL Event = %d, Type() = %d", |
|
600 event, type ); |
|
601 |
|
602 // When OpenL( *path ) is done we get a path changed msg |
|
603 // |
|
604 if ( event == TMPXCollectionMessage::EPathChanged && |
|
605 type == EMcPathChangedByOpen && |
|
606 data == EMcItemOpened ) |
|
607 { |
|
608 MPX_DEBUG1("CMPXRestorePath::DoHandleCollectionMessageL -- opening new path"); |
|
609 iCollectionUtility->Collection().OpenL(); |
|
610 } |
|
611 else if( event == TMPXCollectionMessage::EBroadcastEvent ) |
|
612 { |
|
613 // Restore default path after refresh or end of mtp |
|
614 // |
|
615 if( type == EMcMsgRefreshEnd ) |
|
616 { |
|
617 MPX_DEBUG1( "CMPXRestorePath::DoHandleCollectionMessageL -- Refresh End" ); |
|
618 if( iLoadSavedPath ) |
|
619 { |
|
620 MPX_DEBUG1(" ---> Loading a saved path"); |
|
621 LoadPathL(); |
|
622 } |
|
623 else |
|
624 { |
|
625 MPX_DEBUG1(" ---> Loading a default path"); |
|
626 LoadDefaultPathL(); |
|
627 } |
|
628 iLoadSavedPath = EFalse; |
|
629 } |
|
630 else if ( type == EMcMsgUSBMTPEnd ) |
|
631 { |
|
632 if ( iMTPStarted ) |
|
633 { |
|
634 MPX_DEBUG1( "CMPXRestorePath::DoHandleCollectionMessageL -- MTP End" ); |
|
635 if( iLoadSavedPath ) |
|
636 { |
|
637 MPX_DEBUG1(" ---> Loading a saved path"); |
|
638 LoadPathL(); |
|
639 } |
|
640 else |
|
641 { |
|
642 MPX_DEBUG1(" ---> Loading a default path"); |
|
643 LoadDefaultPathL(); |
|
644 } |
|
645 iLoadSavedPath = EFalse; |
|
646 iMTPStarted = EFalse; |
|
647 } |
|
648 } |
|
649 // Disk inserted, we try to keep playback playlist at the |
|
650 // currently selected song after the automatic refresh |
|
651 // |
|
652 // USB mass storage dismounts the disk, but in that case |
|
653 // we do want to revert back to first song of all songs |
|
654 // |
|
655 else if( type == EMcMsgDiskInserted && |
|
656 !iUSBOngoing ) |
|
657 { |
|
658 SavePathL(); |
|
659 iLoadSavedPath = ETrue; |
|
660 } |
|
661 else if( type == EMcMsgUSBMassStorageStart ) |
|
662 { |
|
663 iUSBOngoing = ETrue; |
|
664 } |
|
665 else if( type == EMcMsgUSBMassStorageEnd ) |
|
666 { |
|
667 iUSBOngoing = EFalse; |
|
668 } |
|
669 else if( type == EMcMsgDiskRemoved |
|
670 && !iUSBOngoing ) |
|
671 { |
|
672 MPX_DEBUG1(" ---> Save the current path and restore it"); |
|
673 SavePathL(); |
|
674 LoadPathL(); |
|
675 } |
|
676 else if( type == EMcMsgFormatEnd ) |
|
677 { |
|
678 MPX_DEBUG1(" --> Loading a default path after formatting "); |
|
679 LoadDefaultPathL(); |
|
680 } |
|
681 else if ( type == EMcMsgUSBMTPStart ) |
|
682 { |
|
683 iMTPStarted = ETrue; |
|
684 } |
|
685 } |
|
686 else if ( event == TMPXCollectionMessage::ECollectionChanged && !iInitCanceled ) |
|
687 { |
|
688 //To Handle the case when path is restored and we are in playback view. |
|
689 //This will switch to the right playback view to prevent podcast playback on music playback view. |
|
690 MMPXViewUtility* viewUtility = MMPXViewUtility::UtilityL(); |
|
691 if (viewUtility->ActiveViewType() == TUid::Uid( KMPXPluginTypePlaybackUid ) && |
|
692 viewUtility->ActiveViewImplementationUid() != TUid::Uid(KMPXPdSbPlaybackViewImplementationId)) |
|
693 { |
|
694 MMPXPlayer* player = iPlaybackUtility->PlayerManager().CurrentPlayer(); |
|
695 if ( player ) |
|
696 { |
|
697 RArray<TUid> array; |
|
698 CleanupClosePushL( array ); |
|
699 array.AppendL( player->UidL() ); |
|
700 array.AppendL(TUid::Uid(data)); |
|
701 viewUtility->ActivateViewL( array ); |
|
702 CleanupStack::PopAndDestroy( &array ); |
|
703 } |
|
704 } |
|
705 viewUtility->Close(); |
|
706 } |
|
707 else |
|
708 { |
|
709 // Ignore all other messages |
|
710 } |
|
711 } |
|
712 } |
|
713 |
|
714 // ----------------------------------------------------------------------------- |
|
715 // Start the incremental reading operation at an offset |
|
716 // ----------------------------------------------------------------------------- |
|
717 // |
|
718 void CMPXRestorePath::DoIncrementalOpenL( CMPXCollectionPath& aPath, |
|
719 TInt aIndex, |
|
720 TInt aDelay ) |
|
721 { |
|
722 RArray<TMPXAttribute> attrs; |
|
723 CleanupClosePushL( attrs ); |
|
724 TArray<TMPXAttribute> ary = attrs.Array(); |
|
725 iIncOpenUtil->Stop(); |
|
726 iIncOpenUtil->SetDelay( aDelay ); |
|
727 iIncOpenUtil->StartL( aPath, ary, KIncrementalFetchCount, |
|
728 aIndex, CMPXCollectionOpenUtility::EFetchNormal ); |
|
729 CleanupStack::PopAndDestroy( &attrs ); |
|
730 } |
|
731 |
|
732 // ----------------------------------------------------------------------------- |
|
733 // Get the Uid of the root path |
|
734 // ----------------------------------------------------------------------------- |
|
735 // |
|
736 TUid CMPXRestorePath::RooPathId() |
|
737 { |
|
738 return iRootPathId; |
|
739 } |
|
740 // End of File |