mpengine/src/mpmpxcollectionframeworkwrapper_p.cpp
changeset 38 b93f525c9244
parent 37 eb79a7c355bf
child 43 0f32e550d9d8
child 48 af3740e3753f
equal deleted inserted replaced
37:eb79a7c355bf 38:b93f525c9244
    80       iFirstIncrementalOpen( EFalse ),
    80       iFirstIncrementalOpen( EFalse ),
    81       iUserPlaylists( 0 ),
    81       iUserPlaylists( 0 ),
    82       iRepeatFeature( ETrue ),
    82       iRepeatFeature( ETrue ),
    83       iShuffleFeature( ETrue ),
    83       iShuffleFeature( ETrue ),
    84       iReopen( EFalse ),
    84       iReopen( EFalse ),
    85       iShuffleAll( EFalse )
    85       iShuffleAll( EFalse ),
       
    86       iRestoreDefaultPath( EFalse ),
       
    87       iRestorePathIndex(0)
    86 {
    88 {
    87     TX_LOG
    89     TX_LOG
    88 }
    90 }
    89 
    91 
    90 /*!
    92 /*!
   377     else {
   379     else {
   378         iShuffleAll = ETrue; 
   380         iShuffleAll = ETrue; 
   379     }
   381     }
   380     TX_EXIT
   382     TX_EXIT
   381 }
   383 }
       
   384 
       
   385 /*!
       
   386  \internal
       
   387  */
       
   388 void MpMpxCollectionFrameworkWrapperPrivate::savePath( QByteArray &data )
       
   389 {
       
   390     TX_ENTRY
       
   391     TRAPD( err, DoSavePathL( data ) );
       
   392     if ( err != KErrNone ) {
       
   393         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   394     }
       
   395     TX_EXIT
       
   396     
       
   397 }
       
   398 
       
   399 /*!
       
   400  \internal
       
   401  */
       
   402 void MpMpxCollectionFrameworkWrapperPrivate::restorePath( const QByteArray &data )
       
   403 {
       
   404     TX_ENTRY
       
   405     TRAPD( err, DoRestorePathL( data ) );
       
   406     if ( err != KErrNone ) {
       
   407         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   408     }
       
   409     TX_EXIT
       
   410 }
       
   411 
   382 
   412 
   383 /*!
   413 /*!
   384  \internal
   414  \internal
   385  Result of open or re-open operation to the Collection Framework.
   415  Result of open or re-open operation to the Collection Framework.
   386  */
   416  */
   502         iIsolatedCollectionData = new MpMpxCollectionData();
   532         iIsolatedCollectionData = new MpMpxCollectionData();
   503         iIsolatedCollectionData->setMpxMedia( aEntries );
   533         iIsolatedCollectionData->setMpxMedia( aEntries );
   504         emit q_ptr->isolatedCollectionOpened( iIsolatedCollectionData );
   534         emit q_ptr->isolatedCollectionOpened( iIsolatedCollectionData );
   505     }
   535     }
   506     else {
   536     else {
       
   537         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
       
   538     }
       
   539     TX_EXIT
       
   540 }
       
   541 
       
   542 /*!
       
   543  \internal
       
   544  */
       
   545 void MpMpxCollectionFrameworkWrapperPrivate::HandleIsolatedOpenRestorePathL( const CMPXCollectionPath& aPath, TInt aError )
       
   546 {
       
   547     TX_ENTRY_ARGS( "aError=" << aError );
       
   548     if ( aError == KErrNone ) {
       
   549         CMPXCollectionPath* cpath = CMPXCollectionPath::NewL( aPath );
       
   550         CleanupStack::PushL( cpath );
       
   551         if ( cpath->Count() <= 0 ) {
       
   552             //There are no entries on the path
       
   553             if ( !iRestoreDefaultPath ) {
       
   554                 //Try restoring default path if not already tried
       
   555                 //This is a special case where a playlist's songs where on the MMC and it was removed
       
   556                 iRestoreDefaultPath = ETrue;
       
   557                 iRestorePathIndex = 0;
       
   558                 CMPXCollectionPath* cpath = iCollectionUiHelper->MusicAllSongsPathL();
       
   559                 CleanupStack::PushL( cpath );
       
   560                 iIsolatedCollectionHelper->OpenCollectionL( *cpath, iRestorePathIndex, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   561                 CleanupStack::PopAndDestroy( cpath );
       
   562             }
       
   563             else {
       
   564                 //emit signal to go back to collection view because there is no music
       
   565                 emit q_ptr->restorePathFailed();
       
   566             }
       
   567         }
       
   568         else if ( iRestorePathIndex ) {
       
   569             //If RestorePathIndex equals zero there is no need to check with previous index
       
   570             //just go and create playlist below
       
   571             if ( iRestorePathIndex == cpath->IndexOfId( iRestorePathIndexId ) ) {
       
   572                 //Song is in path and maintains previous position
       
   573                 cpath->Set( iRestorePathIndex );
       
   574                 CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath );
       
   575                 CleanupStack::PushL( playList );
       
   576                 createPlaybackUtilityL();
       
   577                 iPlaybackUtility->InitL( *playList, EFalse );
       
   578                 CleanupStack::PopAndDestroy( playList );
       
   579             }
       
   580             else { 
       
   581                 //Re open path starting at the beginning of the collection
       
   582                 iRestorePathIndex = 0;
       
   583                 cpath->Back(); 
       
   584                 iIsolatedCollectionHelper->OpenCollectionL( *cpath, iRestorePathIndex, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   585             }
       
   586         }
       
   587         else {
       
   588             //We create a playlist right away since there is no need to check the index for the first element
       
   589             CMPXCollectionPlaylist* playList = CMPXCollectionPlaylist::NewL( *cpath );
       
   590             CleanupStack::PushL( playList );
       
   591             createPlaybackUtilityL();
       
   592             iPlaybackUtility->InitL( *playList, EFalse );
       
   593             CleanupStack::PopAndDestroy( playList );
       
   594         }
       
   595         CleanupStack::PopAndDestroy( cpath );
       
   596     }
       
   597     else if ( aError == KErrNotFound ) {
       
   598         //Path not found (e.g. MMC removed) try restoring default path
       
   599         iRestoreDefaultPath = ETrue;
       
   600         iRestorePathIndex = 0;
       
   601         CMPXCollectionPath* cpath = iCollectionUiHelper->MusicAllSongsPathL();
       
   602         CleanupStack::PushL( cpath );
       
   603         iIsolatedCollectionHelper->OpenCollectionL( *cpath, iRestorePathIndex, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   604         CleanupStack::PopAndDestroy( cpath );
       
   605     }
       
   606     else {
       
   607         //Open path failed
   507         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
   608         TX_LOG_ARGS( "Error: " << aError << "; should never get here." );
   508     }
   609     }
   509     TX_EXIT
   610     TX_EXIT
   510 }
   611 }
   511 
   612 
  1292     CleanupStack::PopAndDestroy( playList );
  1393     CleanupStack::PopAndDestroy( playList );
  1293     CleanupStack::PopAndDestroy( cpath );
  1394     CleanupStack::PopAndDestroy( cpath );
  1294     TX_EXIT
  1395     TX_EXIT
  1295 }
  1396 }
  1296 
  1397 
       
  1398 /*!
       
  1399  \internal
       
  1400  */
       
  1401 void MpMpxCollectionFrameworkWrapperPrivate::DoSavePathL( QByteArray &data )
       
  1402 {
       
  1403     TX_ENTRY
       
  1404     CBufFlat* buffer = CBufFlat::NewL( 256 );
       
  1405     CleanupStack::PushL( buffer );
       
  1406     TBufBuf bufBuf;
       
  1407     bufBuf.Set( *buffer, 0, TBufBuf::EWrite );
       
  1408     
       
  1409     RWriteStream writeStream( &bufBuf );
       
  1410     writeStream.PushL();
       
  1411     
       
  1412     if ( iPlaybackUtility ) {
       
  1413         MMPXSource* source = iPlaybackUtility->Source();
       
  1414         CMPXCollectionPlaylist* playList( NULL );
       
  1415         if( source ) {
       
  1416         playList = source->PlaylistL();
       
  1417             if ( playList ) {
       
  1418                 CleanupStack::PushL( playList );
       
  1419                 const CMPXCollectionPath& cpath = playList->Path();
       
  1420                 writeStream << cpath;
       
  1421                 writeStream.CommitL();
       
  1422                 CleanupStack::PopAndDestroy( playList );
       
  1423             }
       
  1424         }
       
  1425     }
       
  1426     data.append(reinterpret_cast<const char*>(buffer->Ptr(0).Ptr()) ,buffer->Ptr(0).Length());
       
  1427     CleanupStack::PopAndDestroy( 2, buffer ); //writeStream and buffer
       
  1428     TX_EXIT
       
  1429 }
       
  1430 
       
  1431 /*!
       
  1432  \internal
       
  1433  */
       
  1434 void MpMpxCollectionFrameworkWrapperPrivate::DoRestorePathL( const QByteArray &data )
       
  1435 {
       
  1436     TX_ENTRY
       
  1437     int dataSize = data.size();
       
  1438     if ( dataSize > 0 ) {
       
  1439         TPtrC8 activityDataDescriptor( reinterpret_cast<const unsigned char*> ( data.constData() ), data.size() );
       
  1440          
       
  1441         //Take a copy of the data
       
  1442         CBufFlat* buffer = CBufFlat::NewL( dataSize );
       
  1443         CleanupStack::PushL( buffer );
       
  1444         buffer->InsertL( 0, activityDataDescriptor, dataSize );
       
  1445         
       
  1446         TBufBuf bufBuf;
       
  1447         bufBuf.Set( *buffer, 0, TBufBuf::ERead );
       
  1448         RReadStream readStream( &bufBuf );
       
  1449         readStream.PushL();
       
  1450         
       
  1451         CMPXCollectionPath* cpath( NULL );
       
  1452         cpath = CMPXCollectionPath::NewL(readStream);
       
  1453         CleanupStack::PushL(cpath);
       
  1454         iRestorePathIndex = 0;
       
  1455         if( cpath->Levels() ) {
       
  1456             iRestorePathIndexId = cpath->Id();
       
  1457             iRestorePathIndex = cpath->Index();
       
  1458             cpath->Back();
       
  1459         }
       
  1460         if ( !iIsolatedCollectionHelper ) {
       
  1461             iIsolatedCollectionHelper = CMpMpxIsolatedCollectionHelper::NewL( this );
       
  1462         }   
       
  1463         iIsolatedCollectionHelper->OpenCollectionL( *cpath, iRestorePathIndex, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
  1464           
       
  1465         CleanupStack::PopAndDestroy( cpath );
       
  1466         CleanupStack::PopAndDestroy( 2, buffer ); //readStream and buffer
       
  1467     }
       
  1468     TX_EXIT
       
  1469 }
  1297 
  1470 
  1298 //EOF
  1471 //EOF