mpxplugins/viewplugins/views/mainview/src/mpxmainviewimp.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     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:  Implementation of Main view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <aknViewAppUi.h>
       
    22 #include <eikmenub.h>
       
    23 #include <eikfrlb.h>
       
    24 #include <eikfrlbd.h>
       
    25 #include <featmgr.h>
       
    26 #include <StringLoader.h>
       
    27 #include <eikapp.h>
       
    28 #include <AknUtils.h>
       
    29 #include <akntitle.h>
       
    30 #include <textresolver.h>
       
    31 #include <aknnotewrappers.h>
       
    32 #include <aknnavi.h>
       
    33 #include <hlplch.h>
       
    34 #include <bautils.h>
       
    35 #include <eikspmod.h>
       
    36 #include <eikclb.h>
       
    37 #include <avkon.hrh>
       
    38 #include <avkon.rsg>
       
    39 #include <StringLoader.h>
       
    40 #include <data_caging_path_literals.hrh>
       
    41 #include <bldvariant.hrh>
       
    42 #include <layoutmetadata.cdl.h>
       
    43 #include <aknSDData.h>
       
    44 #include <AknMediatorFacade.h>
       
    45 #include <mplayersecondarydisplayapi.h>
       
    46 
       
    47 #include <mpxplaybackutility.h>
       
    48 #include <mpxviewutility.h>
       
    49 #include <mpxcollectionutility.h>
       
    50 #include <mpxplaybackmessage.h>
       
    51 #include <mpxcollectionmessage.h>
       
    52 #include <mpxcollectionmessagedefs.h>
       
    53 #include <mpxmediageneraldefs.h>
       
    54 #include <mpxmediacontainerdefs.h>
       
    55 #include <mpxmediamusicdefs.h>
       
    56 #include <mpxmediacollectiondetaildefs.h>
       
    57 #include <mpxmedia.h>
       
    58 #include <mpxmediaarray.h>
       
    59 #include <mpxcollectionframeworkdefs.h>
       
    60 #include <mpxviewpluginmanager.h>
       
    61 
       
    62 #include <mpxcollectionplaylist.h>
       
    63 #include <mpxmusicplayerviewplugin.hrh>
       
    64 #include <mpxmainview.rsg>
       
    65 #include <mpxlog.h>
       
    66 #include <mpxcollectionpath.h>
       
    67 #include <mpxviewplugin.h>
       
    68 #include <mpxcollectionplugin.hrh>
       
    69 #include <mpxmessagegeneraldefs.h>
       
    70 #include <mpxcommandgeneraldefs.h>
       
    71 #include <mpxcollectioncommanddefs.h>
       
    72 #include <mpxmessagecontainerdefs.h>
       
    73 #include <mpxuser.h>
       
    74 #include "mpxcommonuihelper.h"
       
    75 #include "mpxalbumartutil.h"
       
    76 #include "mpxmainview.hrh"
       
    77 #include "mpxmainviewimp.h"
       
    78 #include "mpxmainviewcontainer.h"
       
    79 #include <mpxappui.hrh>
       
    80 
       
    81 // CONSTANTS
       
    82 _LIT( KMPXMainRscPath, "mpxmainview.rsc" );
       
    83 _LIT( KMPXTab, "\t" );
       
    84 _LIT( KMPXSpace, " " );
       
    85 
       
    86 const TInt KWaitNoteImpUid = 0x101FFC6C;
       
    87 
       
    88 // extra size for buffers
       
    89 const TInt KMPXDefaultBufferLength = 255;
       
    90 const TInt KMPXExtraBufferLength = 50;
       
    91 const TInt KSecondInMilliseconds = 1000;
       
    92 const TInt KOneHourInSeconds = 3600;
       
    93 
       
    94 // ======== MEMBER FUNCTIONS ========
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Two-phased constructor.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CMPXMainViewImp* CMPXMainViewImp::NewL()
       
   101     {
       
   102     MPX_FUNC( "CMPXMainViewImp::NewL" );
       
   103     CMPXMainViewImp* self = CMPXMainViewImp::NewLC();
       
   104     CleanupStack::Pop( self );
       
   105     return self;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // Two-phased constructor.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CMPXMainViewImp* CMPXMainViewImp::NewLC()
       
   113     {
       
   114     CMPXMainViewImp* self = new ( ELeave ) CMPXMainViewImp();
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL();
       
   117     return self;
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Destructor
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CMPXMainViewImp::~CMPXMainViewImp()
       
   125     {
       
   126     MPX_DEBUG1( "CMPXMainViewImp::~CMPXMainViewImp entering" );
       
   127 
       
   128     if ( iCollectionUtility )
       
   129         {
       
   130         iCollectionUtility->Close();
       
   131         }
       
   132 
       
   133     if ( iPlaybackUtility )
       
   134         {
       
   135         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   136         iPlaybackUtility->Close();
       
   137         }
       
   138 
       
   139     if ( iViewUtility )
       
   140         {
       
   141         iViewUtility->Close();
       
   142         }
       
   143 
       
   144     if ( iResourceOffset )
       
   145         {
       
   146         iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   147         }
       
   148 
       
   149     if ( iContainer )
       
   150         {
       
   151         AppUi()->RemoveFromStack( iContainer );
       
   152         delete iContainer;
       
   153         }
       
   154 
       
   155     delete iMPXUtility;
       
   156     delete iTitle;
       
   157     delete iCommonUiHelper;
       
   158     delete iCurPath;
       
   159     delete iMediaArray;
       
   160     delete iIdle;
       
   161     MPX_DEBUG1( "CMPXMainViewImp::~CMPXMainViewImp exiting" );
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // C++ default constructor can NOT contain any code, that
       
   166 // might leave.
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 CMPXMainViewImp::CMPXMainViewImp()
       
   170     {
       
   171     MPX_FUNC( "CMPXMainViewImp::CMPXMainViewImp" );
       
   172     iInitDBNeeded = EFalse;
       
   173     iInitDBCorrupted = EFalse;
       
   174     iCurSystemEvent = KErrNotFound;
       
   175     iShowPlaybackIndicator = EFalse;
       
   176     iColInitialized = EFalse;
       
   177     iRefreshingCollection = EFalse;
       
   178     iCurPlugin = KErrNotFound;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Symbian 2nd phase constructor can leave.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CMPXMainViewImp::ConstructL()
       
   186     {
       
   187     MPX_FUNC( "CMPXMainViewImp::ConstructL" );
       
   188 
       
   189     CCoeEnv* coeEnv = iEikonEnv;
       
   190     TParse parse;
       
   191     parse.Set( KMPXMainRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
   192     TFileName resourceFile( parse.FullName() );
       
   193     User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) );
       
   194     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile );
       
   195     iResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
   196 
       
   197     BaseConstructL( R_MPX_MAIN_VIEW );
       
   198     iViewUtility = MMPXViewUtility::UtilityL();
       
   199     iPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
       
   200     iPlaybackUtility->AddObserverL( *this );
       
   201     iCommonUiHelper = CMPXCommonUiHelper::NewL();
       
   202     iMPXUtility = CMPXAlbumArtUtil::NewL();
       
   203     iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
   204     iAlbumArtIndex = KMPXMainViewDefaultIcon;
       
   205 
       
   206     TMPXPlaybackState state = iPlaybackUtility->StateL();
       
   207     if( state == EPbStatePlaying ||
       
   208         state == EPbStatePaused )
       
   209         {
       
   210         iShowPlaybackIndicator = ETrue;
       
   211         }
       
   212     iIdle = CIdle::NewL( CActive::EPriorityStandard );
       
   213     iTitle = HBufC::NewL( 0 );
       
   214 
       
   215 #ifdef _DEBUG
       
   216     iExitOptionHidden = EFalse;
       
   217 #else // _DEBUG
       
   218     iExitOptionHidden = iCommonUiHelper->ExitOptionHiddenL() &&
       
   219         !iEikonEnv->StartedAsServerApp();
       
   220 #endif // _DEBUG
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // Displays error notes.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CMPXMainViewImp::HandleErrorL( TInt aError )
       
   228     {
       
   229     if ( aError )
       
   230         {
       
   231         MPX_DEBUG2( "CMPXMainViewImp::HandleErrorL(%d)", aError );
       
   232 
       
   233         // TextResolver instance for error resolving.
       
   234         CTextResolver* textresolver = CTextResolver::NewLC();
       
   235         // Resolve the error text
       
   236         const TDesC& text =
       
   237             textresolver->ResolveErrorString( aError );
       
   238 
       
   239         CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue );
       
   240         dlg->ExecuteLD( text );
       
   241         CleanupStack::PopAndDestroy( textresolver );
       
   242         }
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // Function to display information notes
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CMPXMainViewImp::DisplayInfoNoteL( TInt aResourceId )
       
   250     {
       
   251     MPX_FUNC( "CMPXMainViewImp::DisplayInfoNoteL" );
       
   252     HBufC* text = StringLoader::LoadLC( aResourceId );
       
   253     CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
       
   254     dlg->ExecuteLD( *text );
       
   255     CleanupStack::PopAndDestroy( text );
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // Function to display confirmation notes
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CMPXMainViewImp::DisplayConfirmionNoteL( TInt aResourceId )
       
   263     {
       
   264     MPX_FUNC( "CMPXMainViewImp::DisplayConfirmionNoteL" );
       
   265     HBufC* text = StringLoader::LoadLC( aResourceId );
       
   266     CAknConfirmationNote* dlg = new ( ELeave ) CAknConfirmationNote( ETrue );
       
   267     dlg->ExecuteLD( *text );
       
   268     CleanupStack::PopAndDestroy( text );
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // From MMPXCollectionObserver
       
   273 // Handle collection message
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 void CMPXMainViewImp::HandleCollectionMessage(
       
   277     CMPXMessage* aMessage, TInt aError )
       
   278     {
       
   279     if ( aError == KErrNone && aMessage )
       
   280         {
       
   281         TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) );
       
   282         }
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // From MMPXCollectionObserver
       
   287 // Handles the collection entries being opened. Typically called
       
   288 // when client has Open()'d a folder
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CMPXMainViewImp::HandleOpenL(
       
   292     const CMPXMedia& aEntries,
       
   293     TInt aIndex,
       
   294     TBool /*aComplete*/,
       
   295     TInt aError )
       
   296     {
       
   297     MPX_FUNC( "CMPXMainViewImp::HandleOpenL 4" );
       
   298     if( aError == KErrNone )
       
   299         {
       
   300         UpdateListBoxL( aEntries, aIndex );
       
   301 
       
   302         UpdatePluginInfo();
       
   303         }
       
   304     else if ( aError == KErrCorrupt )
       
   305         {
       
   306         DoHandleCorruptMsgL();
       
   307         }
       
   308     else
       
   309         {
       
   310         HandleErrorL( aError );
       
   311         }
       
   312     MPX_PERF_CHECKPT("MPX Main view displayed");
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // From MMPXCollectionObserver
       
   317 // Handles the collection entries being opened. Typically called
       
   318 // when client has Open()'d an item. Client typically responds by
       
   319 // 'playing' the item
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CMPXMainViewImp::HandleOpenL(
       
   323     const CMPXCollectionPlaylist& /*aPlaylist*/,
       
   324     TInt /*aError*/ )
       
   325     {
       
   326     // Do Nothing: playback/fetch client should handle this stage
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // From MMPXCollectionObserver
       
   331 // Handle media properties
       
   332 // Notes: The client is responsible for delete the object of aMedia
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 void CMPXMainViewImp::HandleCollectionMediaL(
       
   336     const CMPXMedia& aMedia,
       
   337     TInt aError)
       
   338     {
       
   339     MPX_FUNC( "CMPXMainViewImp::HandleCollectionMediaL" );
       
   340 
       
   341     if (aError == KErrNoMemory)
       
   342         {
       
   343         TRAP_IGNORE(
       
   344                 HandleErrorL( aError );
       
   345                 AppUi()->HandleCommandL( EEikCmdExit );
       
   346         );
       
   347         User::Exit(KErrNoMemory);
       
   348         return;
       
   349         }
       
   350 
       
   351     if (aError == KErrDiskFull)
       
   352         {
       
   353              iOutOfDisk = ETrue;
       
   354              CloseWaitNoteL();
       
   355              iCurPlugin = KErrNotFound;
       
   356              DoRetrieveDetailsL(ETrue);
       
   357         }
       
   358 
       
   359     if ( aError != KErrCorrupt )
       
   360         {
       
   361 
       
   362         if(!iOutOfDisk)
       
   363             {
       
   364             // Check to see if database has been created for this item
       
   365             //
       
   366             TBool dbCreated = ETrue;
       
   367             if( aMedia.IsSupported(KMPXMediaColDetailDBCreated))
       
   368                 {
       
   369                 dbCreated = aMedia.ValueTObjectL<TBool>(KMPXMediaColDetailDBCreated);
       
   370                 MPX_DEBUG2("CMPXMainViewImp::HandleCollectionMediaL dbcreated %i", dbCreated);
       
   371                 }
       
   372             iInitDBNeeded |= !dbCreated;  //lint !e514
       
   373 
       
   374             // Check to see if database was corrupted for this item
       
   375             //
       
   376             TBool dbCorrupted = EFalse;
       
   377             if( aMedia.IsSupported(KMPXMediaColDetailDBCorrupted))
       
   378                 {
       
   379                 dbCorrupted = aMedia.ValueTObjectL<TBool>(KMPXMediaColDetailDBCorrupted);
       
   380                 }
       
   381             iInitDBCorrupted |= dbCorrupted;
       
   382             }
       
   383 
       
   384         // Update the list box item, iCurPlugin++ because first item is pb state
       
   385         //
       
   386         iCurPlugin++;
       
   387         UpdateItemCountTotalL( aMedia );
       
   388 
       
   389 
       
   390         // Check to see if we need to do initial scan or refresh due to db corruption
       
   391         //
       
   392         if( iCurPlugin == iCurPath->Count() )
       
   393             {
       
   394             MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMediaL plugins MediaL loaded");
       
   395             if ( !iColInitialized )
       
   396                 {
       
   397                 CloseWaitNoteL();
       
   398                 iColInitialized = ETrue;
       
   399                 }
       
   400 
       
   401             if( (iInitDBNeeded || iInitDBCorrupted) && !iOutOfDisk )
       
   402                 {
       
   403                 MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMediaL starting scan");
       
   404                 TWaitNoteType noteType = iInitDBCorrupted ? EMPXCorruptScanningNote :
       
   405                                                             EMPXScanningNote;
       
   406 
       
   407                 StartWaitNoteL( noteType );
       
   408                 iInitDBNeeded = EFalse;
       
   409                 iInitDBCorrupted = EFalse;
       
   410                 iRefreshingCollection = ETrue;
       
   411                 iDelayedUsbRefresh = EFalse;
       
   412                 }
       
   413             else if( iDelayedUsbRefresh )
       
   414                 {
       
   415                 DoHandleBroadcastMsgL( EMcMsgUSBMassStorageEnd );
       
   416                 }
       
   417             iCurPlugin = KErrNotFound;
       
   418             }
       
   419         else if( iCurPlugin < iCurPath->Count() )  // Fetch next
       
   420             {
       
   421             // Set which plugin
       
   422             iCurPath->Set(iCurPlugin);
       
   423 
       
   424             // Fetch the extra data
       
   425             RArray<TMPXAttribute> atts;
       
   426             CleanupClosePushL( atts );
       
   427             if(!iOutOfDisk)
       
   428                 {
       
   429                 atts.Append(KMPXMediaColDetailDBCreated);
       
   430                 atts.Append(KMPXMediaColDetailDBCorrupted);
       
   431                 }
       
   432 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
   433             atts.Append(KMPXMediaGeneralTitle);
       
   434             atts.Append(KMPXMediaGeneralSubTitle);
       
   435             if(!iOutOfDisk)
       
   436                 {
       
   437                 atts.Append(KMPXMediaGeneralCount);
       
   438                 }
       
   439             atts.Append(KMPXMediaGeneralIcon);
       
   440 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
   441 
       
   442             MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMediaL fetch next");
       
   443             // Only fetch next if we haven't been interrupted by another event
       
   444             //
       
   445             if( iCurSystemEvent == KErrNotFound )
       
   446                 {
       
   447                 iCollectionUtility->Collection().MediaL(*iCurPath, atts.Array() );
       
   448                 }
       
   449             else
       
   450                 {
       
   451                 // Reset state machine
       
   452                 iCurPlugin = KErrNotFound;
       
   453                 }
       
   454             CleanupStack::PopAndDestroy( &atts );
       
   455             }
       
   456 
       
   457         if ( aError != KErrNone ) //lint !e961
       
   458             {
       
   459             HandleErrorL( aError );
       
   460             }
       
   461         }
       
   462     else
       
   463         {
       
   464         DoHandleCorruptMsgL();
       
   465         }
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 // From MMPXPlaybackObserver
       
   470 // Handle playback message.
       
   471 // ---------------------------------------------------------------------------
       
   472 //
       
   473 void CMPXMainViewImp::HandlePlaybackMessage(
       
   474     CMPXMessage* aMessage, TInt aError )
       
   475     {
       
   476     if ( aError == KErrNone && aMessage )
       
   477         {
       
   478         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
   479         }
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // From MMPXPlaybackCallback
       
   484 // Handle playback property.
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CMPXMainViewImp::HandlePropertyL(
       
   488     TMPXPlaybackProperty aProperty,
       
   489     TInt aValue,
       
   490     TInt aError )
       
   491     {
       
   492     MPX_DEBUG1( "CMPXMainViewImp::HandlePropertyL" );
       
   493     TRAP_IGNORE( DoHandlePropertyL( aProperty, aValue, aError ) );
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // From MMPXPlaybackCallback
       
   498 // Method is called continously until aComplete=ETrue, signifying that
       
   499 // it is done and there will be no more callbacks
       
   500 // Only new items are passed each time
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 void CMPXMainViewImp::HandleSubPlayerNamesL(
       
   504     TUid /* aPlayer */,
       
   505     const MDesCArray* /* aSubPlayers */,
       
   506     TBool /* aComplete */,
       
   507     TInt /* aError */ )
       
   508     {
       
   509     // do nothing
       
   510     }
       
   511 
       
   512 // ---------------------------------------------------------------------------
       
   513 // From MMPXPlaybackCallback
       
   514 // Handle extended media properties.
       
   515 // Notes: The client is responsible for delete the object of aProperties.
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void CMPXMainViewImp::HandleMediaL(
       
   519     const CMPXMedia& aMedia,
       
   520     TInt aError )
       
   521     {
       
   522     MPX_DEBUG2( "CMPXMainViewImp::HandleMediaL %i", aError );
       
   523     TRAP_IGNORE( DoHandleMediaL( aMedia, aError ) );
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------------------------
       
   527 // From CAknView
       
   528 // Returns views id.
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 TUid CMPXMainViewImp::Id() const
       
   532     {
       
   533     return TUid::Uid( KMPXMainViewId );
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // From CAknView
       
   538 // Command handling function.
       
   539 // ---------------------------------------------------------------------------
       
   540 //
       
   541 void CMPXMainViewImp::HandleCommandL( TInt aCommand )
       
   542     {
       
   543     MPX_DEBUG2( "CMPXMainViewImp::HandleCommandL(%d) entering", aCommand );
       
   544 
       
   545     switch (aCommand)
       
   546         {
       
   547         case EMPXCmdGoToNowPlaying:
       
   548             {
       
   549             // update view history first
       
   550             iViewUtility->PushDefaultHistoryL();
       
   551             //then open the view first
       
   552             AppUi()->HandleCommandL( aCommand );
       
   553             break;
       
   554             }
       
   555         case EMPXMainViewRefresh:
       
   556             {
       
   557             MPX_PERF_CHECKPT("Refresh collection library");
       
   558             // Package the argument from 8bit to 16bit then activate view
       
   559             //
       
   560             StartWaitNoteL( EMPXRefreshingNote );
       
   561             iPlaybackUtility->CommandL( EPbCmdStop );
       
   562             break;
       
   563             }
       
   564         case EAknCmdHelp:
       
   565             {
       
   566             HlpLauncher::LaunchHelpApplicationL(
       
   567                 iEikonEnv->WsSession(),
       
   568                 AppUi()->AppHelpContextL() );
       
   569             break;
       
   570             }
       
   571         case EAknCmdExit:
       
   572         case EAknSoftkeyExit:
       
   573             {
       
   574             AppUi()->HandleCommandL( aCommand );
       
   575             break;
       
   576             }
       
   577         default:
       
   578             {
       
   579             AppUi()->HandleCommandL( aCommand );
       
   580             break;
       
   581             }
       
   582         }
       
   583     MPX_DEBUG1( "CMPXMainViewImp::HandleCommandL() exiting" );
       
   584     }
       
   585 
       
   586 // ---------------------------------------------------------------------------
       
   587 // From CAknView
       
   588 // Handles a view activation.
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 void CMPXMainViewImp::DoActivateL(
       
   592     const TVwsViewId& /* aPrevViewId */,
       
   593     TUid /* aCustomMessageId */,
       
   594     const TDesC8& /* aCustomMessage */ )
       
   595     {
       
   596     MPX_FUNC( "CMPXMainViewImp::DoActivateL()" );
       
   597     StatusPane()->MakeVisible( ETrue );
       
   598     if ( StatusPane()->CurrentLayoutResId() !=
       
   599          R_AVKON_STATUS_PANE_LAYOUT_USUAL)
       
   600         {
       
   601         StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
       
   602         }
       
   603 
       
   604     if ( !iContainer )
       
   605         {
       
   606         iContainer = new ( ELeave ) CMPXMainViewContainer( this );
       
   607         iContainer->SetMopParent( this );
       
   608         iContainer->ConstructL( ClientRect() );
       
   609         AppUi()->AddToStackL( *this, iContainer );
       
   610         }
       
   611 
       
   612     // Set title
       
   613     CAknTitlePane* title( NULL );
       
   614 
       
   615     TRAP_IGNORE(
       
   616         {
       
   617         title = static_cast<CAknTitlePane*>
       
   618             ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   619         } );
       
   620     if ( title )
       
   621         {
       
   622         HBufC* titleText = StringLoader::LoadLC(
       
   623             R_MPX_MAIN_VIEW_TITLE );
       
   624         title->SetTextL( *titleText );
       
   625         CleanupStack::PopAndDestroy( titleText );
       
   626         }
       
   627 
       
   628     CEikButtonGroupContainer* cbgc = CEikButtonGroupContainer::Current();
       
   629     if ( cbgc )
       
   630         {
       
   631         if ( iViewUtility->ViewHistoryDepth() == 1 )
       
   632             {
       
   633             cbgc->SetCommandSetL( R_MPX_CUI_SOFTKEYS_OPTIONS_PHONE );
       
   634             }
       
   635         else
       
   636             {
       
   637             cbgc->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
   638             }
       
   639 
       
   640 #ifdef __ENABLE_MSK
       
   641         iCommonUiHelper->SetMiddleSoftKeyLabelL(
       
   642             *cbgc,
       
   643             R_QTN_MSK_OPEN,
       
   644             EAknSoftkeyForwardKeyEvent );
       
   645 #endif // __ENABLE_MSK
       
   646 
       
   647         cbgc->DrawDeferred();
       
   648         }
       
   649 
       
   650     iAlbumArtIndex = KMPXMainViewTransparent;
       
   651     iPlaybackState = iPlaybackUtility->StateL();
       
   652     MMPXSource* s = iPlaybackUtility->Source();
       
   653     if ( s )
       
   654         {
       
   655         RArray<TMPXAttribute> attrs;
       
   656         CleanupClosePushL(attrs);
       
   657         attrs.Append(
       
   658             TMPXAttribute( KMPXMediaIdGeneral,
       
   659             EMPXMediaGeneralTitle | EMPXMediaGeneralUri ) );
       
   660         attrs.Append(KMPXMediaMusicAlbumArtFileName);
       
   661         s->MediaL( attrs.Array(), *this );
       
   662         CleanupStack::PopAndDestroy( &attrs );
       
   663 
       
   664         CMPXCollectionPlaylist* pl = s->PlaylistL();
       
   665         if( pl )
       
   666             {
       
   667             CleanupStack::PushL( pl );
       
   668             iCurPlPlayPosition = pl->Index() + 1; // offset for 0th index
       
   669             iCurPlTotalCount   = pl->Count();
       
   670             CleanupStack::PopAndDestroy( pl );
       
   671             }
       
   672         }
       
   673     UpdatePlaybackViewStatusL();
       
   674 
       
   675     if ( iCollectionUtility )
       
   676         {
       
   677         if( iCurSystemEvent == EMcMsgUSBMassStorageStart ||
       
   678             iCurSystemEvent == EMcMsgUSBMTPStart )
       
   679             {
       
   680             // Fix grey out problem by re-starting the note
       
   681             //
       
   682             CMPXViewPlugin* pi =
       
   683                     iViewUtility->ViewPluginManager().PluginL( TUid::Uid(KWaitNoteImpUid) );
       
   684             pi->DeactivateView();
       
   685             DoHandleBroadcastMsgL( iCurSystemEvent );
       
   686             iColInitialized = ETrue;
       
   687             }
       
   688         else if ( !iColInitialized )
       
   689 
       
   690             {
       
   691             StartWaitNoteL( EMPXOpeningNote );
       
   692             }
       
   693 
       
   694         // Path Depth can be 2 if rapidly pressing back.
       
   695         // In this case, we wait until the collection container opened message
       
   696         // is sent
       
   697         //
       
   698         CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
   699         CleanupStack::PushL( cPath );
       
   700         MPX_DEBUG2("CMPXMainViewImp::DoActivateL path depth %i", cPath->Levels());
       
   701         if( cPath->Levels() == 1 )
       
   702             {
       
   703             iCollectionUtility->Collection().OpenL();
       
   704             iPathCorrupted = EFalse;
       
   705             }
       
   706         else
       
   707             {
       
   708             iPathCorrupted = ETrue;
       
   709             }
       
   710         CleanupStack::PopAndDestroy( cPath );
       
   711         }
       
   712     }
       
   713 
       
   714 // ---------------------------------------------------------------------------
       
   715 // From CAknView
       
   716 // View deactivation function.
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 void CMPXMainViewImp::DoDeactivate()
       
   720     {
       
   721     MPX_FUNC( "CMPXMainViewImp::DoDeactivate" );
       
   722     if ( iContainer )
       
   723         {
       
   724         AppUi()->RemoveFromStack( iContainer );
       
   725         delete iContainer;
       
   726         iContainer = NULL;
       
   727         }
       
   728     }
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // From CAknView
       
   732 // Foreground event handling function.
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 void CMPXMainViewImp::HandleForegroundEventL( TBool aForeground )
       
   736     {
       
   737     MPX_FUNC( "CMPXMainViewImp::HandleForegroundEventL" );
       
   738     CAknView::HandleForegroundEventL( aForeground );
       
   739     }
       
   740 
       
   741 // ---------------------------------------------------------------------------
       
   742 // From MEikMenuObserver
       
   743 // Dynamically initialises a menu pane.
       
   744 // ---------------------------------------------------------------------------
       
   745 //
       
   746 void CMPXMainViewImp::DynInitMenuPaneL(
       
   747     TInt aResourceId,
       
   748     CEikMenuPane* aMenuPane )
       
   749     {
       
   750     MPX_FUNC( "CMPXMainViewImp::DynInitMenuPaneL" );
       
   751     switch ( aResourceId )
       
   752         {
       
   753         case R_MPX_MAIN_VIEW_MENU:
       
   754             {
       
   755             aMenuPane->SetItemDimmed( EAknCmdExit, iExitOptionHidden );
       
   756             break;
       
   757             }
       
   758         default:
       
   759             {
       
   760             // Do nothing
       
   761             break;
       
   762             }
       
   763         }
       
   764     AknSelectionService::HandleMarkableListDynInitMenuPane(
       
   765         aResourceId,
       
   766         aMenuPane,
       
   767         iContainer->ListBox() );
       
   768     }
       
   769 
       
   770 // ---------------------------------------------------------------------------
       
   771 // From MEikListBoxObserver
       
   772 // Handles listbox events.
       
   773 // ---------------------------------------------------------------------------
       
   774 //
       
   775 void CMPXMainViewImp::HandleListBoxEventL(
       
   776     CEikListBox* /*aListBox*/,
       
   777     TListBoxEvent aEventType)
       
   778     {
       
   779     MPX_FUNC( "CMPXMainViewImp::HandleListBoxEventL" );
       
   780 
       
   781     if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked
       
   782 #ifdef SINGLE_CLICK_INCLUDED
       
   783         || aEventType == EEventItemSingleClicked    
       
   784 #endif
       
   785         )
       
   786         {
       
   787         TInt currentIndex = iContainer->ListBox()->CurrentItemIndex();
       
   788         if ( currentIndex == 0 && iShowPlaybackIndicator ) //lint !e961
       
   789             {
       
   790             MMPXPlayer* player =
       
   791                 iPlaybackUtility->PlayerManager().CurrentPlayer();
       
   792             TUid pluginUid( KNullUid );
       
   793             RArray<TUid> array;
       
   794             CleanupClosePushL( array );
       
   795 
       
   796             if ( player )
       
   797                 {
       
   798                 pluginUid = player->UidL();
       
   799                 MPX_DEBUG2( "CMPXMainViewImp::HandleListBoxEventL player UID = 0x%x", pluginUid.iUid );
       
   800                 array.AppendL( pluginUid );
       
   801                 }
       
   802             else
       
   803                 {
       
   804                 array.AppendL( TUid::Uid( KMPXPluginTypePlaybackUid ) );
       
   805                 }
       
   806 
       
   807             MMPXSource* source = iPlaybackUtility->Source();
       
   808             if ( source )
       
   809                 {
       
   810                 CMPXCollectionPlaylist* playlist = source->PlaylistL();
       
   811                 if ( playlist )
       
   812                     {
       
   813                     CleanupStack::PushL( playlist );
       
   814                     CMPXCollectionPath* pbPath =
       
   815                         CMPXCollectionPath::NewL( playlist->Path() );
       
   816                     CleanupStack::PushL( pbPath );
       
   817                     if ( pbPath->Levels() > 0 )
       
   818                         {
       
   819                         TMPXItemId cPathUid = pbPath->Id( 0 );
       
   820                         MPX_DEBUG2( "CMPXMainViewImp::HandleListBoxEventL collection uid = 0x%x", cPathUid.iId1 );
       
   821                         array.AppendL( TUid::Uid( cPathUid ) );
       
   822                         }
       
   823                     CleanupStack::PopAndDestroy( pbPath );
       
   824                     CleanupStack::PopAndDestroy( playlist );
       
   825                     }
       
   826                 }
       
   827             // Forced jump, clear main view from view history
       
   828             //
       
   829             iViewUtility->PushDefaultHistoryL();
       
   830             iViewUtility->ActivateViewL( array );
       
   831 
       
   832             CleanupStack::PopAndDestroy( &array );
       
   833             }
       
   834         else if ( currentIndex > -1 ) //lint !e961
       
   835             {
       
   836             // offset by 1 for playback view
       
   837             TInt offset = iShowPlaybackIndicator ? 1 : 0;
       
   838             iCollectionUtility->Collection().OpenL( currentIndex - offset );
       
   839             }
       
   840         }  //lint !e961
       
   841     }
       
   842 
       
   843 // ---------------------------------------------------------------------------
       
   844 // From MMPXAlbumArtUtilObserver
       
   845 // Notify that extraction of album art started.
       
   846 // ---------------------------------------------------------------------------
       
   847 //
       
   848 void CMPXMainViewImp::ExtractAlbumArtStarted()
       
   849     {
       
   850     MPX_DEBUG1("CMPXMainViewImp::ExtractAlbumArtStarted()");
       
   851     iAlbumArtIndex = KMPXMainViewTransparent;
       
   852     }
       
   853 
       
   854 // ---------------------------------------------------------------------------
       
   855 // From MMPXAlbumArtUtilObserver
       
   856 // Album art is extracted from file and ready to use.
       
   857 // ---------------------------------------------------------------------------
       
   858 //
       
   859 void CMPXMainViewImp::ExtractAlbumArtCompleted(
       
   860     CFbsBitmap* aBitmap, TInt aErr )
       
   861     {
       
   862     TRAP_IGNORE( DoExtractAlbumArtCompletedL( aBitmap, aErr ) );
       
   863     }
       
   864 
       
   865 // ---------------------------------------------------------------------------
       
   866 // Handle playback message.
       
   867 // ---------------------------------------------------------------------------
       
   868 //
       
   869 void CMPXMainViewImp::DoHandlePlaybackMessageL(
       
   870     const CMPXMessage& aMessage )
       
   871     {
       
   872     MPX_FUNC( "CMPXMainViewImp::DoHandlePlaybackMessageL" );
       
   873     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   874     if ( KMPXMessageGeneral == id )
       
   875         {
       
   876         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
   877         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
   878         switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) )
       
   879             {
       
   880             case TMPXPlaybackMessage::EPropertyChanged:
       
   881                 {
       
   882                 TMPXPlaybackProperty property(
       
   883                     static_cast<TMPXPlaybackProperty>( type ) );
       
   884                 TInt error( KErrNone );
       
   885 
       
   886                 DoHandlePropertyL( property, data, error );
       
   887                 break;
       
   888                 }
       
   889             case TMPXPlaybackMessage::EStateChanged:
       
   890                 {
       
   891                 MPX_DEBUG2( "CMPXMainViewImp::HandlePlaybackMessageL - EStateChanged(%d)", type );
       
   892 
       
   893                 TMPXPlaybackState state =
       
   894                     static_cast<TMPXPlaybackState>( type );
       
   895 
       
   896                 DoHandleStateChangedL( state );
       
   897                 break;
       
   898                 }
       
   899             case TMPXPlaybackMessage::EMediaChanged:
       
   900                 {
       
   901                 if ( iContainer )
       
   902                     {
       
   903                     MMPXSource* s = iPlaybackUtility->Source();
       
   904                     if ( s )
       
   905                         {
       
   906                         RArray<TMPXAttribute> attrs;
       
   907                         CleanupClosePushL(attrs);
       
   908                         attrs.Append(
       
   909                             TMPXAttribute( KMPXMediaIdGeneral,
       
   910                             EMPXMediaGeneralTitle | EMPXMediaGeneralUri ) );
       
   911                         attrs.Append(KMPXMediaMusicAlbumArtFileName);
       
   912                         s->MediaL( attrs.Array(), *this );
       
   913                         CleanupStack::PopAndDestroy( &attrs );
       
   914 
       
   915                         CMPXCollectionPlaylist* pl = s->PlaylistL();
       
   916                         if( pl )
       
   917                             {
       
   918                             CleanupStack::PushL( pl );
       
   919                             iCurPlPlayPosition = pl->Index() + 1; // offset for 0th index
       
   920                             iCurPlTotalCount   = pl->Count();
       
   921                             CleanupStack::PopAndDestroy( pl );
       
   922                             }
       
   923                         }
       
   924                     }
       
   925                 break;
       
   926                 }
       
   927             case TMPXPlaybackMessage::ECommandReceived:
       
   928                 {
       
   929                 MPX_DEBUG2( "CMPXMainViewImp - ECommandReceived(%d)", type );
       
   930                 break;
       
   931                 }
       
   932             case TMPXPlaybackMessage::EActivePlayerChanged:
       
   933                 {
       
   934                 MPX_DEBUG3( "CMPXMainViewImp - EActivePlayerChanged(%d, %d)", type, data );
       
   935                 if ( type && data )
       
   936                     {
       
   937                     // binded to active player, change state to active
       
   938                     DoHandleStateChangedL( EPbStatePlaying );
       
   939                     // refresh media property
       
   940                     MMPXSource* s = iPlaybackUtility->Source();
       
   941                     if ( s )
       
   942                         {
       
   943                         RArray<TMPXAttribute> attrs;
       
   944                         CleanupClosePushL(attrs);
       
   945                         attrs.Append(
       
   946                             TMPXAttribute( KMPXMediaIdGeneral,
       
   947                             EMPXMediaGeneralTitle | EMPXMediaGeneralUri ) );
       
   948                         attrs.Append(KMPXMediaMusicAlbumArtFileName);
       
   949                         s->MediaL( attrs.Array(), *this );
       
   950                         CleanupStack::PopAndDestroy( &attrs );
       
   951 
       
   952                         CMPXCollectionPlaylist* pl = s->PlaylistL();
       
   953                         if( pl )
       
   954                             {
       
   955                             CleanupStack::PushL( pl );
       
   956                             iCurPlPlayPosition = pl->Index() + 1; // offset for 0th index
       
   957                             iCurPlTotalCount   = pl->Count();
       
   958                             CleanupStack::PopAndDestroy( pl );
       
   959                             }
       
   960                         }
       
   961                     }
       
   962                 break;
       
   963                 }
       
   964             default:
       
   965                 {
       
   966                 break;
       
   967                 }
       
   968             }
       
   969         }
       
   970     }
       
   971 
       
   972 // ---------------------------------------------------------------------------
       
   973 // Handle playback property.
       
   974 // ---------------------------------------------------------------------------
       
   975 //
       
   976 void CMPXMainViewImp::DoHandlePropertyL(
       
   977     TMPXPlaybackProperty aProperty,
       
   978     TInt aValue,
       
   979     TInt aError )
       
   980     {
       
   981     MPX_FUNC( "CMPXMainViewImp::DoHandlePropertyL" );
       
   982     MPX_DEBUG4( "CMPXMainViewImp::DoHandlePropertyL - Property(%d); Value(%d); Error(%d)", aProperty, aValue, aError );
       
   983 
       
   984     if ( KErrNone == aError )
       
   985         {
       
   986         switch ( aProperty  )
       
   987             {
       
   988             case EPbPropertyPosition:
       
   989                 {
       
   990                 iPosition = aValue;
       
   991                 break;
       
   992                 }
       
   993             case EPbPropertyDuration:
       
   994                 {
       
   995                 iDuration = aValue;
       
   996                 break;
       
   997                 }
       
   998             default:
       
   999                 {
       
  1000                 break;
       
  1001                 }
       
  1002             }
       
  1003         UpdatePlaybackViewStatusL();
       
  1004         }
       
  1005     }
       
  1006 
       
  1007 // ---------------------------------------------------------------------------
       
  1008 // Handle collection messages.
       
  1009 // ---------------------------------------------------------------------------
       
  1010 //
       
  1011 void CMPXMainViewImp::DoHandleCollectionMessageL(
       
  1012     const CMPXMessage& aMessage )
       
  1013     {
       
  1014     MPX_FUNC( "CMPXCommandHandler::DoHandleCollectionMessageL" );
       
  1015     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  1016     if ( KMPXMessageGeneral == id )
       
  1017         {
       
  1018         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
  1019         TInt op( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  1020         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  1021         // End of refresh message, update the list box text
       
  1022         //
       
  1023         if( event == TMPXCollectionMessage::EBroadcastEvent &&
       
  1024             op == EMcMsgRefreshEnd )
       
  1025             {
       
  1026             MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMessageL - refresh end");
       
  1027             iRefreshingCollection = EFalse;
       
  1028             iOutOfDisk = data == KErrDiskFull ? ETrue : EFalse;
       
  1029 
       
  1030             if (!iOutOfDisk)
       
  1031                 {
       
  1032                 ResynchronizeCollectionL();
       
  1033                 }
       
  1034             else
       
  1035                 {
       
  1036                 iCurPlugin = KErrNotFound;
       
  1037                 iInitDBNeeded = EFalse;
       
  1038                 iInitDBCorrupted = EFalse;
       
  1039                 }
       
  1040 
       
  1041             DoRetrieveDetailsL(iOutOfDisk);
       
  1042             DoSetDefaultFocusL();
       
  1043             }
       
  1044         else if(event == TMPXCollectionMessage::EBroadcastEvent &&
       
  1045                 op == EMcMsgRefreshStart)
       
  1046             {
       
  1047             iRefreshingCollection = ETrue;
       
  1048             }
       
  1049         // Handle other broadcast messages
       
  1050         //
       
  1051         else if( event == TMPXCollectionMessage::EBroadcastEvent )
       
  1052             {
       
  1053             MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMessageL - broadcast");
       
  1054             DoHandleBroadcastMsgL( op );
       
  1055             }
       
  1056         // if not currently refreshing, the main view should make sure
       
  1057         // the collection item counters are always up to date
       
  1058         else if( event == TMPXCollectionMessage::EItemChanged &&
       
  1059                  !iRefreshingCollection )
       
  1060             {
       
  1061             MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMessageL - item changed");
       
  1062 
       
  1063             if((op == EMPXItemInserted || op == EMPXItemDeleted) &&
       
  1064                (data >> 28 == EMPXCollection)) //lint !e702 only update if collection has changed
       
  1065                 {
       
  1066                 // refresh since the podcasting collection has been updated
       
  1067                 DoRetrieveDetailsL();
       
  1068                 }
       
  1069             // else ignore
       
  1070             }
       
  1071         // If user rapidly presses back, main view gets activated with a Path of level 2
       
  1072         // but the path change to level 1 msg comes later
       
  1073         //
       
  1074         else if( event == TMPXCollectionMessage::EPathChanged &&
       
  1075                  op == EMcPathChangedByOpen &&
       
  1076                  data == EMcContainerOpened )
       
  1077             {
       
  1078             CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  1079             CleanupStack::PushL( cPath );
       
  1080             MPX_DEBUG2("CMPXMainViewImp::HandleCollectionMessageL - Path Changed By Open %i", cPath->Levels() );
       
  1081 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1082             if( cPath->Levels() == 1 && iContainer )
       
  1083                 {
       
  1084                 iCurPlugin = KErrNotFound;
       
  1085                 iCollectionUtility->Collection().CancelRequest();
       
  1086                 iCollectionUtility->Collection().OpenL();
       
  1087                 }
       
  1088 #else // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1089             if( cPath->Levels() == 2 ) // Music menu
       
  1090                 {
       
  1091                 DoRetrieveDetailsL();
       
  1092                 }
       
  1093 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1094 
       
  1095             CleanupStack::PopAndDestroy( cPath );
       
  1096             }
       
  1097         else if( event == TMPXCollectionMessage::EFocusChanged &&
       
  1098                  iContainer )
       
  1099             {
       
  1100             TInt offset = iShowPlaybackIndicator ? 1 : 0;
       
  1101             iContainer->ListBox()->SetCurrentItemIndex( data + offset );
       
  1102             }
       
  1103         else if ( event == TMPXCollectionMessage::ECollectionChanged &&
       
  1104                   iContainer && iPathCorrupted)
       
  1105             {
       
  1106             MPX_DEBUG1("CMPXMainViewImp::HandleCollectionMessageL -- Collection changed and Levels 1");
       
  1107             CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  1108             CleanupStack::PushL( cPath );
       
  1109             if( cPath->Levels() == 1 )
       
  1110                 {
       
  1111                 iCurPlugin = KErrNotFound;
       
  1112                 iCollectionUtility->Collection().CancelRequest();
       
  1113                 iCollectionUtility->Collection().OpenL();
       
  1114                 iPathCorrupted = EFalse;
       
  1115                 }
       
  1116             CleanupStack::PopAndDestroy( cPath );
       
  1117             }
       
  1118         }
       
  1119     else if( KMPXMessageIdItemChanged == id )
       
  1120         {
       
  1121         // Loop through messages for arrays.
       
  1122         //
       
  1123         if (aMessage.IsSupported(KMPXMessageArrayContents))
       
  1124             {
       
  1125             const CMPXMessageArray* messageArray =
       
  1126                         aMessage.Value<CMPXMessageArray>(KMPXMessageArrayContents);
       
  1127             User::LeaveIfNull(const_cast<CMPXMessageArray*>(messageArray));
       
  1128             
       
  1129             for( TInt i=0; i<messageArray->Count(); ++i )
       
  1130                   {
       
  1131                   HandleCollectionMessage( (*messageArray)[i], KErrNone );
       
  1132                   }
       
  1133             }
       
  1134         // Single item
       
  1135         else
       
  1136             {
       
  1137             MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL KMPXMessageIdItemChanged");
       
  1138             TMPXChangeEventType op( aMessage.ValueTObjectL<TMPXChangeEventType>( KMPXMessageChangeEventType ) );
       
  1139             TMPXItemId data( aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId) );
       
  1140             if( (op == EMPXItemInserted || op == EMPXItemDeleted) &&
       
  1141                 (data.iId2 >> 28 == EMPXCollection) &&
       
  1142                 !iRefreshingCollection ) //lint !e702 only update if collection has changed
       
  1143                 {
       
  1144                 // refresh since the podcasting collection has been updated
       
  1145                 DoRetrieveDetailsL();
       
  1146                 }
       
  1147             }
       
  1148         }//lint !e961
       
  1149     }
       
  1150 
       
  1151 // ---------------------------------------------------------------------------
       
  1152 // Handle media properties.
       
  1153 // ---------------------------------------------------------------------------
       
  1154 //
       
  1155 void CMPXMainViewImp::DoHandleMediaL(
       
  1156     const CMPXMedia& aMedia,
       
  1157     TInt aError )
       
  1158     {
       
  1159     MPX_FUNC( "CMPXMainViewImp::DoHandleMediaL" );
       
  1160     delete iTitle;
       
  1161     iTitle = NULL;
       
  1162     iTitle = aMedia.ValueText(KMPXMediaGeneralTitle).AllocL();
       
  1163 
       
  1164     if ( KErrNone == aError )
       
  1165         {
       
  1166         if ( iContainer )
       
  1167             {
       
  1168             TInt err( KErrNone );
       
  1169             MPX_TRAP( err,
       
  1170                 iMPXUtility->ExtractAlbumArtL(
       
  1171                     aMedia,
       
  1172                     *this,
       
  1173                     TSize( 50, 50 ) ) );
       
  1174             MPX_DEBUG2( "CMPXMainViewImp::DoHandleMediaPropertiesL err = %d", err );
       
  1175             if ( err != KErrNone )
       
  1176                 {
       
  1177                 iAlbumArtIndex = KMPXMainViewDefaultIcon;
       
  1178                 }
       
  1179             }
       
  1180          else
       
  1181             {
       
  1182             if ( aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName))
       
  1183                 {
       
  1184                 iAlbumArtIndex = KMPXMainViewTransparent;
       
  1185                 }
       
  1186             else
       
  1187                 {
       
  1188                 iAlbumArtIndex = KMPXMainViewDefaultIcon;
       
  1189                 }
       
  1190             }
       
  1191         }
       
  1192     else
       
  1193         {
       
  1194         iAlbumArtIndex = KMPXMainViewDefaultIcon;
       
  1195         }
       
  1196 
       
  1197     // check to see if default podcast album art should be displayed instead
       
  1198     // of default music album art icon
       
  1199     if(iAlbumArtIndex == KMPXMainViewDefaultIcon &&
       
  1200        aMedia.IsSupported(KMPXMediaGeneralCategory) &&
       
  1201        EMPXPodcast == aMedia.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralCategory))  //lint !e650 !e58
       
  1202         {
       
  1203         iAlbumArtIndex = KMPXMainViewDefaultPodcastIcon;
       
  1204         }
       
  1205 
       
  1206     UpdatePlaybackViewStatusL();
       
  1207     }
       
  1208 
       
  1209 // ---------------------------------------------------------------------------
       
  1210 // Handle playback state changed.
       
  1211 // ---------------------------------------------------------------------------
       
  1212 //
       
  1213 void CMPXMainViewImp::DoHandleStateChangedL(
       
  1214     TMPXPlaybackState aState )
       
  1215     {
       
  1216     MPX_FUNC( "CMPXMainViewImp::DoHandleStateChangedL" );
       
  1217 
       
  1218     // Store a state only if we are not seeking
       
  1219     //
       
  1220     if( aState != EPbStateSeekingForward &&
       
  1221         aState != EPbStateSeekingBackward )
       
  1222         {
       
  1223         iPlaybackState = aState;
       
  1224         }
       
  1225     UpdatePlaybackViewStatusL();
       
  1226     }
       
  1227 
       
  1228 // ---------------------------------------------------------------------------
       
  1229 // Updates list box
       
  1230 // ---------------------------------------------------------------------------
       
  1231 //
       
  1232 void CMPXMainViewImp::UpdateListBoxL(
       
  1233     const CMPXMedia& aEntries,
       
  1234     TInt aIndex )
       
  1235     {
       
  1236     MPX_FUNC( "CMPXMainViewImp::UpdateListBox" );
       
  1237 
       
  1238     if ( iContainer )
       
  1239         {
       
  1240         CDesCArray* array =
       
  1241             static_cast<CDesCArray*>(
       
  1242             iContainer->ListBox()->Model()->ItemTextArray() );
       
  1243 
       
  1244         // preserve playback status
       
  1245         if ( (array->MdcaCount() > 0) && iShowPlaybackIndicator )
       
  1246             {
       
  1247             HBufC* dataItem = array->MdcaPoint( 0 ).AllocLC();
       
  1248             array->Reset();
       
  1249             array->AppendL( *dataItem );
       
  1250             CleanupStack::PopAndDestroy( dataItem );
       
  1251             dataItem = NULL;
       
  1252             }
       
  1253         else
       
  1254             {
       
  1255             array->Reset();
       
  1256             }
       
  1257 
       
  1258         delete iMediaArray;
       
  1259         iMediaArray = NULL;
       
  1260         CMPXMediaArray* mediaAry( aEntries.Value<CMPXMediaArray>(KMPXMediaArrayContents) );
       
  1261         User::LeaveIfNull( mediaAry );
       
  1262         iMediaArray = CMPXMediaArray::NewL( *mediaAry );
       
  1263         TInt entriesCount = iMediaArray->Count();
       
  1264         CMPXMedia* entry = NULL;
       
  1265         for( TInt i=0; i < entriesCount; i++ )
       
  1266             {
       
  1267             entry = iMediaArray->AtL( i );
       
  1268             const TDesC& title = entry->ValueText(KMPXMediaGeneralTitle);
       
  1269             MPX_DEBUG2( "CMPXMainViewImp::UpdateListBox Name: %S", &title );
       
  1270             MPX_DEBUG3( "CMPXMainViewImp::UpdateListBox Type: %d, Category: %d",
       
  1271                         entry->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),
       
  1272                         entry->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory));
       
  1273             HBufC* dataItem = HBufC::NewLC( title.Length() + KMPXExtraBufferLength );
       
  1274             dataItem->Des().Format( _L("0\t%S\t\t\t"), &title );
       
  1275             array->AppendL( *dataItem );
       
  1276             CleanupStack::PopAndDestroy( dataItem );
       
  1277             }
       
  1278         iContainer->ListBox()->HandleItemAdditionL();
       
  1279         if ( iViewUtility->PreviousViewType().iUid == KMPXPluginTypeCollectionUid )
       
  1280             {
       
  1281             if ( aIndex < iContainer->ListBox()->Model()->NumberOfItems() )
       
  1282                 {
       
  1283                 TInt offset = iShowPlaybackIndicator ? 1 : 0;
       
  1284                 iContainer->ListBox()->SetCurrentItemIndexAndDraw( aIndex + offset );
       
  1285                 }
       
  1286             }
       
  1287         }
       
  1288     }
       
  1289 
       
  1290 
       
  1291 // ---------------------------------------------------------------------------
       
  1292 // Function to update the item count at the current item
       
  1293 // ---------------------------------------------------------------------------
       
  1294 //
       
  1295 void CMPXMainViewImp::UpdateItemCountTotalL( const CMPXMedia& aMedia )
       
  1296     {
       
  1297     MPX_FUNC( "CMPXMainViewImp::UpdateItemCountTotalL" );
       
  1298 
       
  1299     if( iContainer )
       
  1300         {
       
  1301         // Offset for icons and array position
       
  1302         TInt offset = iShowPlaybackIndicator ? 0 : 1;
       
  1303 
       
  1304         // Listbox descriptor array
       
  1305         CDesCArray* array = static_cast<CDesCArray*>(
       
  1306                             iContainer->ListBox()->Model()->ItemTextArray() );
       
  1307 
       
  1308         // Number of items
       
  1309         if(!aMedia.IsSupported(KMPXMediaGeneralSubTitle) ||
       
  1310            !aMedia.IsSupported(KMPXMediaGeneralCount))
       
  1311             {
       
  1312             User::Leave(KErrArgument);
       
  1313             }
       
  1314 
       
  1315         const TDesC& subTitle = aMedia.ValueText(KMPXMediaGeneralSubTitle);
       
  1316         const TInt numItems = aMedia.ValueTObjectL<TInt>(KMPXMediaGeneralCount);
       
  1317 
       
  1318         HBufC* formattedSubTitle(NULL);
       
  1319 
       
  1320         if(numItems != 1)
       
  1321             {
       
  1322             formattedSubTitle = HBufC::NewLC( subTitle.Length() + 7 ); // magic, >>10,000 episodes
       
  1323             TPtr ptr = formattedSubTitle->Des();
       
  1324             StringLoader::Format(ptr, subTitle, -1, numItems);
       
  1325             }
       
  1326         else
       
  1327             {
       
  1328             formattedSubTitle = subTitle.Alloc();
       
  1329             CleanupStack::PushL(formattedSubTitle);
       
  1330             }
       
  1331 
       
  1332         // Plugin Title
       
  1333         const TDesC& title = aMedia.ValueText(KMPXMediaGeneralTitle);
       
  1334 
       
  1335         // Plugin Icon and Mask
       
  1336         TIconInfo icon;
       
  1337         icon.bmpfile = KNullDesC;
       
  1338         CGulIcon* gulicon(NULL);
       
  1339         TInt iconIndex(0);
       
  1340         if(aMedia.IsSupported(KMPXMediaGeneralIcon))
       
  1341             {
       
  1342             MPX_DEBUG1("CMPXMainViewImp::UpdateItemCountTotalL - Got an Icon");
       
  1343             icon = aMedia.ValueTObjectL<TIconInfo>(KMPXMediaGeneralIcon);
       
  1344             // Create the icon
       
  1345             MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
       
  1346             CFbsBitmap* bmp(NULL);
       
  1347             CFbsBitmap* mask(NULL);
       
  1348             TParse parse;
       
  1349             parse.Set( icon.bmpfile , &KDC_APP_RESOURCE_DIR, NULL);
       
  1350             TFileName iconFile( parse.FullName() );
       
  1351             User::LeaveIfError( MPXUser::CompleteWithDllPath( iconFile ) );
       
  1352 
       
  1353             AknsUtils::CreateIconLC(
       
  1354                 skin,
       
  1355                 KAknsIIDNone,
       
  1356                 bmp,
       
  1357                 mask,
       
  1358                 iconFile,
       
  1359                 icon.bitmapId,
       
  1360                 icon.maskId );
       
  1361 
       
  1362             gulicon = CGulIcon::NewL( bmp, mask );
       
  1363             CleanupStack::Pop( 2 ); // bmp, mask
       
  1364 
       
  1365             // Add it to the list
       
  1366             CArrayPtr<CGulIcon>* icons = static_cast<CEikFormattedCellListBox*>(
       
  1367                     iContainer->ListBox() )->ItemDrawer()->
       
  1368                     FormattedCellData()->IconArray();
       
  1369             icons->AppendL( gulicon );
       
  1370             iconIndex = icons->Count()-1;
       
  1371             }
       
  1372 
       
  1373         // Reformat item and insert
       
  1374         //
       
  1375         MPX_DEBUG1("CMPXMainViewImp::UpdateItemCountTotalL - Updating item");
       
  1376         HBufC* dataItem = HBufC::NewLC( title.Length() + formattedSubTitle->Length()
       
  1377                                         + KMPXExtraBufferLength );
       
  1378         dataItem->Des().Format( _L("%d\t%S\t%S\t\t"), iconIndex, &title, formattedSubTitle );
       
  1379         if( array->Count() > (iCurPlugin-offset) )
       
  1380             {
       
  1381             array->Delete(iCurPlugin-offset);
       
  1382             array->InsertL(iCurPlugin-offset, *dataItem);
       
  1383             }
       
  1384         CleanupStack::PopAndDestroy( dataItem );
       
  1385         CleanupStack::PopAndDestroy(formattedSubTitle);
       
  1386 
       
  1387         // Redraw listbox
       
  1388         iContainer->ListBox()->DrawDeferred();
       
  1389         }
       
  1390     }
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // Updates playback view status
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 void CMPXMainViewImp::UpdatePlaybackViewStatusL()
       
  1397     {
       
  1398     MPX_FUNC( "CMPXMainViewImp::UpdatePlaybackViewStatusL" );
       
  1399 
       
  1400     TBool oldState( iShowPlaybackIndicator );
       
  1401     MPX_DEBUG2( "CMPXMainViewImp::UpdatePlaybackViewStatusL iPlaybackState = %d", iPlaybackState );
       
  1402 
       
  1403     if ( iPlaybackState != EPbStateInitialising )
       
  1404         {
       
  1405         // do not change state if it's in EPbStateInitialising state
       
  1406         if( iPlaybackState == EPbStatePlaying ||
       
  1407             iPlaybackState == EPbStatePaused ||
       
  1408             iPlaybackState == EPbStateSeekingForward ||
       
  1409             iPlaybackState == EPbStateSeekingBackward )
       
  1410             {
       
  1411             iShowPlaybackIndicator = ETrue;
       
  1412             }
       
  1413         else
       
  1414             {
       
  1415             // Remove indicator if it was being shown
       
  1416             //
       
  1417             if( iContainer && iShowPlaybackIndicator )
       
  1418                 {
       
  1419                 TInt currentIndex( iContainer->ListBox()->CurrentItemIndex() );
       
  1420                 MPX_DEBUG2( "CMPXMainViewImp::UpdatePlaybackViewStatusL currentIndex = %d", currentIndex );
       
  1421                 CDesCArray* array =
       
  1422                     static_cast<CDesCArray*>(
       
  1423                     iContainer->ListBox()->Model()->ItemTextArray() );
       
  1424 
       
  1425                 if ( array->Count() > 0 )
       
  1426                     {
       
  1427                     array->Delete( 0 );
       
  1428                     }
       
  1429                 iContainer->ListBox()->HandleItemAdditionL();
       
  1430                 if ( currentIndex > 0 )
       
  1431                     {
       
  1432                     // to preseve current selection index
       
  1433                     currentIndex--;
       
  1434                     MPX_DEBUG2( "CMPXMainViewImp::UpdatePlaybackViewStatusL setting index = %d", currentIndex );
       
  1435                     iContainer->ListBox()->SetCurrentItemIndexAndDraw( currentIndex );
       
  1436                     }
       
  1437                 }
       
  1438             MPX_DEBUG1( "CMPXMainViewImp::UpdatePlaybackViewStatusL dismissing playback indicator" );
       
  1439             iShowPlaybackIndicator = EFalse;
       
  1440             }
       
  1441         }
       
  1442     else
       
  1443         {
       
  1444         MPX_DEBUG1( "CMPXMainViewImp::UpdatePlaybackViewStatusL initializing, state unchanged" );
       
  1445         }
       
  1446 
       
  1447     // Show the item only if we want to show indicator
       
  1448     //
       
  1449     if ( iContainer && iShowPlaybackIndicator )
       
  1450         {
       
  1451         CDesCArray* array =
       
  1452             static_cast<CDesCArray*>(
       
  1453             iContainer->ListBox()->Model()->ItemTextArray() );
       
  1454 
       
  1455         TInt playStatusIcon = -1;
       
  1456 
       
  1457         if ( iPlaybackState == EPbStatePlaying )
       
  1458             {
       
  1459             playStatusIcon = KMPXMainViewPlayIcon;
       
  1460             }
       
  1461         else if ( iPlaybackState == EPbStatePaused )
       
  1462             {
       
  1463             playStatusIcon = KMPXMainViewPauseIcon;
       
  1464             }
       
  1465 
       
  1466         TInt duration = iPosition; //lint !e961
       
  1467         if ( duration > 0 ) //lint !e961
       
  1468             {
       
  1469             // convert milliseconds to seconds
       
  1470             duration = duration / KSecondInMilliseconds;
       
  1471             }
       
  1472         CMPXCommonUiHelper::TMPXDuratDisplayMode durationMode =
       
  1473             CMPXCommonUiHelper::EMPXDuratAuto;
       
  1474         if ( duration > KOneHourInSeconds )
       
  1475             {
       
  1476             durationMode = CMPXCommonUiHelper::EMPXDuratHMS;
       
  1477             }
       
  1478         HBufC* stringBuf = iCommonUiHelper->DisplayableDurationL(
       
  1479             (TInt64)duration, durationMode );
       
  1480         CleanupStack::PushL( stringBuf );
       
  1481 
       
  1482         // Only remove the old one if we were previously showing the
       
  1483         // playback indicator
       
  1484         if ( array->Count() > 0 && oldState)
       
  1485             {
       
  1486             array->Delete( 0 );
       
  1487             }
       
  1488         HBufC* dataItem;
       
  1489         if ( iTitle )
       
  1490             {
       
  1491             dataItem = HBufC::NewLC( iTitle->Length() + KMPXExtraBufferLength );
       
  1492             }
       
  1493         else
       
  1494             {
       
  1495             dataItem = HBufC::NewLC( KMPXDefaultBufferLength +
       
  1496                 KMPXExtraBufferLength );
       
  1497             }
       
  1498         if ( playStatusIcon > -1 )
       
  1499             {
       
  1500             dataItem->Des().AppendNum( (TInt64)iAlbumArtIndex );
       
  1501             dataItem->Des().Append( KMPXTab );
       
  1502             dataItem->Des().Append( *iTitle );
       
  1503             dataItem->Des().Append( KMPXTab );
       
  1504             dataItem->Des().Append( *stringBuf );
       
  1505             dataItem->Des().Append( KMPXSpace );
       
  1506             dataItem->Des().Append( KMPXSpace );
       
  1507 
       
  1508             CArrayFix< TInt >* intArray =
       
  1509                 new ( ELeave ) CArrayFixFlat<TInt>( 2 );  // magic number
       
  1510             CleanupStack::PushL( intArray );
       
  1511             intArray->AppendL( iCurPlPlayPosition );
       
  1512             intArray->AppendL( iCurPlTotalCount );
       
  1513             HBufC* posString = StringLoader::LoadLC(
       
  1514                 R_MPX_TRACK_POSITION, *intArray );
       
  1515             dataItem->Des().Append( *posString );
       
  1516             CleanupStack::PopAndDestroy( posString );
       
  1517             CleanupStack::PopAndDestroy( intArray );
       
  1518             dataItem->Des().Append( KMPXTab );
       
  1519 
       
  1520             dataItem->Des().Append( KMPXTab );
       
  1521             dataItem->Des().AppendNum( (TInt64)playStatusIcon );
       
  1522             }
       
  1523         else
       
  1524             {
       
  1525             dataItem->Des().AppendNum( (TInt64)iAlbumArtIndex );
       
  1526             dataItem->Des().Append( KMPXTab );
       
  1527             dataItem->Des().Append( *iTitle );
       
  1528             dataItem->Des().Append( KMPXTab );
       
  1529             dataItem->Des().Append( KMPXTab );
       
  1530             dataItem->Des().Append( KMPXTab );
       
  1531             }
       
  1532         array->InsertL( 0, dataItem->Des() );
       
  1533         iContainer->ListBox()->HandleItemAdditionL();
       
  1534 
       
  1535         CleanupStack::PopAndDestroy( dataItem );
       
  1536         CleanupStack::PopAndDestroy( stringBuf );
       
  1537         }
       
  1538     }
       
  1539 
       
  1540 // ---------------------------------------------------------------------------
       
  1541 // Start a refreshing note
       
  1542 // ---------------------------------------------------------------------------
       
  1543 //
       
  1544 void CMPXMainViewImp::StartWaitNoteL( TWaitNoteType aNoteType )
       
  1545     {
       
  1546     CloseWaitNoteL();
       
  1547     TUid waitnoteId = TUid::Uid( KMPXPluginTypeWaitNoteDialogUid );
       
  1548     TPckg<TWaitNoteType> note = aNoteType;
       
  1549     HBufC* arg = MPXUser::AllocL( note );
       
  1550     CleanupStack::PushL( arg );
       
  1551     iViewUtility->ActivateViewL( waitnoteId, arg );
       
  1552     CleanupStack::PopAndDestroy( arg );
       
  1553     }
       
  1554 
       
  1555 // ---------------------------------------------------------------------------
       
  1556 // Close waitnote dialog
       
  1557 // ---------------------------------------------------------------------------
       
  1558 //
       
  1559 void CMPXMainViewImp::CloseWaitNoteL(TBool aSkipCheckIfActive)
       
  1560     {
       
  1561     TUid waitnoteId = TUid::Uid( KMPXPluginTypeWaitNoteDialogUid );
       
  1562     TUid activeView = iViewUtility->ActiveViewType();
       
  1563     if(( activeView == waitnoteId ) || (aSkipCheckIfActive))
       
  1564         {
       
  1565         CMPXViewPlugin* pi =
       
  1566             iViewUtility->ViewPluginManager().PluginL( TUid::Uid(KWaitNoteImpUid) );
       
  1567         pi->DeactivateView();
       
  1568         }
       
  1569     }
       
  1570 
       
  1571 // ---------------------------------------------------------------------------
       
  1572 // Any processing to handle broadcast events
       
  1573 // ---------------------------------------------------------------------------
       
  1574 //
       
  1575 void CMPXMainViewImp::DoHandleBroadcastMsgL( TInt aEvent )
       
  1576     {
       
  1577     MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg<--");
       
  1578     switch( aEvent )
       
  1579         {
       
  1580         case EMcMsgFormatStart:
       
  1581             {
       
  1582             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgFormatStart");
       
  1583 
       
  1584             // If we were in MTP sync, we stay in mtp sync mode
       
  1585             if( iCurSystemEvent == KErrNotFound )
       
  1586                 {
       
  1587                 // Show a formatting wait note
       
  1588                 iCurSystemEvent = EMcMsgFormatStart;
       
  1589                 iDiskDismountDuringFormat = EFalse;
       
  1590                 iPlaybackUtility->CommandL( EPbCmdStop );
       
  1591 
       
  1592                 StartWaitNoteL( EMPXFormatScanningNote );
       
  1593                 }
       
  1594             break;
       
  1595             }
       
  1596         case EMcMsgFormatEnd:
       
  1597             {
       
  1598             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgFormatEnd");
       
  1599             if( iCurSystemEvent == EMcMsgFormatStart )
       
  1600                 {
       
  1601                 iCurSystemEvent = KErrNotFound;
       
  1602 
       
  1603                 if( !iDiskDismountDuringFormat )
       
  1604                     {
       
  1605                     MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - Sync db after format");
       
  1606                     ResynchronizeCollectionL();
       
  1607 
       
  1608                     if( !iRefreshingCollection )
       
  1609                         {
       
  1610                         StartWaitNoteL( EMPXScanningNote );
       
  1611                         iRefreshingCollection = ETrue;
       
  1612                         }
       
  1613                     }
       
  1614                 }
       
  1615             break;
       
  1616             }
       
  1617         case EMcMsgDiskRemoved:
       
  1618             {
       
  1619             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgDiskRemoved");
       
  1620             iPlaybackUtility->CommandL( EPbCmdStop );
       
  1621 
       
  1622             // Main view hasn't been activated
       
  1623             // Updating the view now causes a blank screen if usb is started
       
  1624             //
       
  1625             if( iColInitialized )
       
  1626                 {
       
  1627                 UpdatePluginInfo();
       
  1628                 }
       
  1629 
       
  1630             if( iCurSystemEvent == EMcMsgFormatStart )
       
  1631                 {
       
  1632                 iDiskDismountDuringFormat = ETrue;
       
  1633                 }
       
  1634             break;
       
  1635             }
       
  1636         case EMcMsgDiskInserted:
       
  1637             {
       
  1638             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgDiskInserted");
       
  1639             // Only show the query if we are not processing a usb event
       
  1640             // USB dismounts and re-mounts the drive several times
       
  1641             //
       
  1642             // Ignore the disk insert during format, after format a fake event will be sent.
       
  1643             //
       
  1644             if( iCurSystemEvent != EMcMsgUSBMassStorageStart &&
       
  1645                 iCurSystemEvent != EMcMsgUSBMTPStart &&
       
  1646                 iCurSystemEvent != EMcMsgFormatStart &&
       
  1647                 iColInitialized )
       
  1648                 {
       
  1649                 if( iQueryDialog )
       
  1650                     {
       
  1651                     MPX_DEBUG1("Main View -- Dismissing Query");
       
  1652                     iQueryDialog->DismissQueryL();
       
  1653                     }
       
  1654 
       
  1655                 // Always start a refresh
       
  1656                 //
       
  1657                 ResynchronizeCollectionL();
       
  1658                 if( !iRefreshingCollection )
       
  1659                     {
       
  1660                     StartWaitNoteL( EMPXScanningNote );
       
  1661                     iRefreshingCollection = ETrue;
       
  1662                     }
       
  1663                 }
       
  1664             break;
       
  1665             }
       
  1666         case EMcMsgUSBMassStorageEnd:
       
  1667             {
       
  1668             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgUSBMassStorageEnd");
       
  1669             // Show query dialog to ask if they want to refresh
       
  1670             //
       
  1671             MPX_DEBUG2( "CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgUSBMassStorageEnd iColInitialized = %d", iColInitialized );
       
  1672 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1673             if( iColInitialized || iDelayPluginInfoUpdate )
       
  1674                 {
       
  1675 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1676                 CloseWaitNoteL(ETrue);
       
  1677                 iDelayPluginInfoUpdate = EFalse;
       
  1678                 if( iIdle->IsActive() )
       
  1679                     {
       
  1680                     iIdle->Cancel();
       
  1681                     }
       
  1682                 TCallBack cb( &IdleCallback, this );
       
  1683                 iIdle->Start( cb );
       
  1684 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1685                 }
       
  1686             else
       
  1687                 {
       
  1688                 iDelayedUsbRefresh = ETrue;
       
  1689                 iCurSystemEvent = KErrNotFound;
       
  1690                 }
       
  1691 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1692             break;
       
  1693             }
       
  1694         case EMcMsgUSBMassStorageStart:
       
  1695             {
       
  1696             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgUSBMassStorageStart");
       
  1697             // Close playback framework and start wait note
       
  1698             if( iQueryDialog )
       
  1699                 {
       
  1700                 MPX_DEBUG1("Main View -- Dismissing Query");
       
  1701                 iQueryDialog->DismissQueryL();
       
  1702                 }
       
  1703             iCurSystemEvent = EMcMsgUSBMassStorageStart;
       
  1704             iPlaybackUtility->CommandL( EPbCmdStop );
       
  1705             StartWaitNoteL( EMPXUsbEventNote );
       
  1706             break;
       
  1707             }
       
  1708         case EMcMsgUSBMTPStart:
       
  1709             {
       
  1710             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgUSBMTPStart");
       
  1711             // Close playback framework and start wait note
       
  1712             if( iQueryDialog )
       
  1713                 {
       
  1714                 MPX_DEBUG1("Main View -- Dismissing Query");
       
  1715                 iQueryDialog->DismissQueryL();
       
  1716                 }
       
  1717             iCurSystemEvent = EMcMsgUSBMTPStart;
       
  1718             if( !iColInitialized )
       
  1719                 {
       
  1720                 iColInitialized = ETrue;
       
  1721                 }
       
  1722             iPlaybackUtility->CommandL( EPbCmdStop );
       
  1723             StartWaitNoteL( EMPXMTPEventNote );
       
  1724             break;
       
  1725             }
       
  1726         case EMcMsgUSBMTPEnd:
       
  1727             {
       
  1728             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg EMcMsgUSBMTPEnd");
       
  1729             iCurSystemEvent = KErrNotFound;
       
  1730             CloseWaitNoteL(ETrue);
       
  1731             if( iColInitialized )
       
  1732                 {
       
  1733                 ResynchronizeCollectionL();
       
  1734                 UpdatePluginInfo();
       
  1735                 }
       
  1736             break;
       
  1737             }
       
  1738         case EMcMsgRefreshEnd: // fall through
       
  1739             {
       
  1740             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgFormatEnd, EMcMsgUSBMTPEnd,EMcMsgRefreshEnd");
       
  1741             iCurSystemEvent = KErrNotFound;
       
  1742 
       
  1743             if( iColInitialized )
       
  1744                 {
       
  1745                 ResynchronizeCollectionL();
       
  1746                 UpdatePluginInfo();
       
  1747                 }
       
  1748             break;
       
  1749             }
       
  1750         case EMcMsgSystemEventMax:
       
  1751         case EMcMsgRefreshStart:    // fall through
       
  1752             {
       
  1753             MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg - EMcMsgSystemEventMax, EMcMsgRefreshStart");
       
  1754             break;
       
  1755             }
       
  1756         default:
       
  1757             {
       
  1758             break;
       
  1759             }
       
  1760         }
       
  1761      MPX_DEBUG1("CMPXMainViewImp::DoHandleBroadcastMsg -->");
       
  1762     }
       
  1763 
       
  1764 // ---------------------------------------------------------------------------
       
  1765 // Handle a corrupt message
       
  1766 // ---------------------------------------------------------------------------
       
  1767 //
       
  1768 void CMPXMainViewImp::DoHandleCorruptMsgL()
       
  1769     {
       
  1770     // Start the corrupt note. The corrupt note will delete
       
  1771     // the old databases and restart everything from SCRATCH
       
  1772     //
       
  1773     MPX_DEBUG1("CMPXMainViewImp::DoHandleCorruptMsgL <-- starting scan");
       
  1774 
       
  1775     StartWaitNoteL( EMPXCorruptScanningNote );
       
  1776     iInitDBNeeded = EFalse;
       
  1777     iInitDBCorrupted = EFalse;
       
  1778     }
       
  1779 
       
  1780 // ---------------------------------------------------------------------------
       
  1781 // Handle a corrupt message
       
  1782 // ---------------------------------------------------------------------------
       
  1783 //
       
  1784 void CMPXMainViewImp::UpdatePluginInfo()
       
  1785     {
       
  1786     MPX_DEBUG1("CMPXMainViewImp::UpdatePluginInfo");
       
  1787 
       
  1788     // MediaL on the first selection and only if we are
       
  1789     // not currently handling a system event
       
  1790     //
       
  1791     if( iCurSystemEvent == KErrNotFound )
       
  1792         {
       
  1793         TRAP_IGNORE( DoRetrieveDetailsL() );
       
  1794         }
       
  1795     else if ( !iColInitialized )
       
  1796         {
       
  1797         MPX_DEBUG1( "CMPXMainViewImp::UpdatePluginInfo setting iDelayPluginInfoUpdate" );
       
  1798         iDelayPluginInfoUpdate = ETrue;
       
  1799         }
       
  1800     }
       
  1801 
       
  1802 // ---------------------------------------------------------------------------
       
  1803 // Resynchronize collection(s)
       
  1804 // ---------------------------------------------------------------------------
       
  1805 //
       
  1806 void CMPXMainViewImp::ResynchronizeCollectionL()
       
  1807     {
       
  1808     MPX_FUNC( "CMPXMainViewImp::ResynchronizeCollectionL" );
       
  1809 
       
  1810     RArray<TUid> ary;
       
  1811     CleanupClosePushL( ary );
       
  1812 
       
  1813     // Resynchronize podcast databases
       
  1814     ary.AppendL( TUid::Uid(EMPXCollectionPluginPodCast) );
       
  1815     TUid collection = iCollectionUtility->CollectionIDL( ary.Array() );
       
  1816     TRAP_IGNORE(
       
  1817         iCollectionUtility->
       
  1818             Collection().CommandL( EMcCmdCollectionInit,
       
  1819                                    collection.iUid ) );
       
  1820 
       
  1821     // Resynchronize music collection databases
       
  1822     ary.Reset();
       
  1823     ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) );
       
  1824     collection = iCollectionUtility->CollectionIDL( ary.Array() );
       
  1825     iCollectionUtility->Collection().CommandL( EMcCmdCollectionInit,
       
  1826                                                collection.iUid );
       
  1827 
       
  1828     CleanupStack::PopAndDestroy( &ary );
       
  1829     }
       
  1830 
       
  1831 // ---------------------------------------------------------------------------
       
  1832 // Handle an idle callback event
       
  1833 // ---------------------------------------------------------------------------
       
  1834 //
       
  1835 TInt CMPXMainViewImp::IdleCallback( TAny* ptr )
       
  1836     {
       
  1837     TRAP_IGNORE( ( (CMPXMainViewImp*) ptr )->HandleIdleEventL() );
       
  1838     return 0;
       
  1839     }
       
  1840 
       
  1841 // ---------------------------------------------------------------------------
       
  1842 // Handle an idle callback event
       
  1843 // ---------------------------------------------------------------------------
       
  1844 //
       
  1845 void CMPXMainViewImp::HandleIdleEventL()
       
  1846     {
       
  1847     MPX_FUNC( "CMPXMainViewImp::HandleIdleEventL" );
       
  1848     TInt event = iDelayedUsbRefresh ? EMcMsgUSBMassStorageStart : iCurSystemEvent;
       
  1849     switch( event )
       
  1850         {
       
  1851         case EMcMsgUSBMassStorageStart:
       
  1852             {
       
  1853             MPX_DEBUG1("CMPXMainViewImp::HandleIdleEventL -- Mass Storage dialog");
       
  1854             iCurSystemEvent = KErrNotFound;
       
  1855             iDelayedUsbRefresh = EFalse;
       
  1856 
       
  1857             // Send resyn command
       
  1858             ResynchronizeCollectionL();
       
  1859 
       
  1860             HBufC* title = StringLoader::LoadLC( R_MPX_REFRESH_AFTER_SYNC );
       
  1861             CAknQueryDialog* query = new( ELeave ) CAknQueryDialog();
       
  1862             iQueryDialog = query;
       
  1863 
       
  1864             query->PublishDialogL(
       
  1865                 EMPlayerNoteUSBSyncRefresh,
       
  1866                 KMPlayerNoteCategory );
       
  1867 
       
  1868             TInt rtn = query->ExecuteLD( R_MPX_QUERY_YES_NO ,
       
  1869                                          *title );
       
  1870             CleanupStack::PopAndDestroy( title );
       
  1871             iQueryDialog = NULL;  // Dialog destroyed
       
  1872 
       
  1873             if ( rtn == EAknSoftkeyYes )
       
  1874                 {
       
  1875                 StartWaitNoteL( EMPXRefreshingNote );
       
  1876                 }
       
  1877             else
       
  1878                 {
       
  1879                 MPX_DEBUG1("CMPXMainViewImp::HandleIdleEventL -- refreshing view");
       
  1880                 UpdatePluginInfo();
       
  1881 
       
  1882                 // Refresh the UI view in this case
       
  1883                 // @todo, refactor all this handling to its own class
       
  1884                 //
       
  1885                 MPX_DEBUG1("CMPXMainViewImp::HandleIdleEventL() no refresh selected");
       
  1886                 if ( !CEikonEnv::Static()->StartedAsServerApp() )
       
  1887                     {
       
  1888                     CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();
       
  1889                     CleanupStack::PushL( cPath );
       
  1890                     if( cPath->Levels() > 1 &&
       
  1891                         iViewUtility->ActiveViewType() == TUid::Uid(KMPXPluginTypeCollectionUid) )
       
  1892                         {
       
  1893                         MPX_DEBUG1("CMPXMainViewImp::HandleIdleEventL() Refreshing UI");
       
  1894                         cPath->Back();
       
  1895                         iCollectionUtility->Collection().OpenL( *cPath );
       
  1896                         }
       
  1897                     CleanupStack::PopAndDestroy( cPath );
       
  1898                     }
       
  1899                 }
       
  1900             break;
       
  1901             }
       
  1902         default:
       
  1903             {
       
  1904             break;
       
  1905             }
       
  1906 
       
  1907         }
       
  1908     }
       
  1909 
       
  1910 // ---------------------------------------------------------------------------
       
  1911 // Calls MediaL to retrieve item details
       
  1912 // ---------------------------------------------------------------------------
       
  1913 //
       
  1914 void CMPXMainViewImp::DoRetrieveDetailsL(TBool aSkipAttribute)
       
  1915     {
       
  1916     MPX_DEBUG2("CMPXMainViewImp::DoRetrieveDetailsL %i", iCurPlugin);
       
  1917     iDelayPluginInfoUpdate = EFalse;
       
  1918     // Make sure we don't overlap 2 sets of MediaL()
       
  1919     //
       
  1920     if( iCurPlugin == KErrNotFound && iCurSystemEvent == KErrNotFound )
       
  1921         {
       
  1922         delete iCurPath;
       
  1923         iCurPath = NULL;
       
  1924 
       
  1925 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1926         iCurPath = iCollectionUtility->Collection().PathL();
       
  1927 #else
       
  1928         // TEMPORARY FIX, hardcode root level collections
       
  1929         // This needs to be re-written as a seperate class!
       
  1930         //
       
  1931         RArray<TMPXItemId> ids;
       
  1932         CleanupClosePushL( ids );
       
  1933 
       
  1934         // Root level path
       
  1935         iCurPath = CMPXCollectionPath::NewL();
       
  1936         ids.AppendL( TMPXItemId(0x101FFC3A) );
       
  1937         ids.AppendL( TMPXItemId(0x101FFC3C) );
       
  1938         iCurPath->AppendL( ids.Array() );
       
  1939 
       
  1940         CleanupStack::PopAndDestroy( &ids );
       
  1941 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1942 
       
  1943         if( iCurPath->Levels() == 1 && iCurPath->Count() )
       
  1944             {
       
  1945             iCurPath->SetToFirst();
       
  1946             iCurPlugin = 0;
       
  1947 
       
  1948             // Do a MediaL to re-retrieve details
       
  1949             //
       
  1950             RArray<TMPXAttribute> atts;
       
  1951             CleanupClosePushL( atts );
       
  1952             if(!aSkipAttribute)
       
  1953                 {
       
  1954                 atts.Append(KMPXMediaColDetailDBCreated);
       
  1955                 atts.Append(KMPXMediaColDetailDBCorrupted);
       
  1956                 }
       
  1957 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1958             atts.Append(KMPXMediaGeneralSubTitle);
       
  1959             if(!aSkipAttribute)
       
  1960                 {
       
  1961                 atts.Append(KMPXMediaGeneralCount);
       
  1962                 }
       
  1963             atts.Append(KMPXMediaGeneralTitle);
       
  1964             atts.Append(KMPXMediaGeneralIcon );
       
  1965 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1966             iCollectionUtility->Collection().MediaL(*iCurPath, atts.Array() );
       
  1967             CleanupStack::PopAndDestroy( &atts );
       
  1968             }
       
  1969         }
       
  1970     }
       
  1971 
       
  1972 // ---------------------------------------------------------------------------
       
  1973 // From MMPXAlbumArtUtilObserver
       
  1974 // Album art is extracted from file and ready to use.
       
  1975 // ---------------------------------------------------------------------------
       
  1976 //
       
  1977 void CMPXMainViewImp::DoExtractAlbumArtCompletedL(
       
  1978     CFbsBitmap* aBitmap, TInt aErr )
       
  1979     {
       
  1980     MPX_DEBUG3( "CMPXMainViewImp::DoExtractAlbumArtCompleted(bitmap:0x%x, err:%d)",
       
  1981         aBitmap, aErr );
       
  1982 
       
  1983     if ( !aErr )
       
  1984         {
       
  1985         if ( iContainer )
       
  1986             {
       
  1987             CGulIcon* icon = CGulIcon::NewL( aBitmap );
       
  1988             CArrayPtr<CGulIcon>* icons = static_cast<CEikFormattedCellListBox*>(
       
  1989                 iContainer->ListBox() )->ItemDrawer()->
       
  1990                 FormattedCellData()->IconArray();
       
  1991             icons->AppendL( icon );
       
  1992             iAlbumArtIndex = icons->Count() - 1;
       
  1993 
       
  1994             MPX_DEBUG2( "CMPXMainViewImp::ExtractAlbumArtCompleted Array icon index = %d", iAlbumArtIndex );
       
  1995             TRAP_IGNORE(UpdatePlaybackViewStatusL());
       
  1996             }
       
  1997         else
       
  1998             {
       
  1999             delete aBitmap;
       
  2000             }
       
  2001         }
       
  2002     else
       
  2003         {
       
  2004         iAlbumArtIndex = KMPXMainViewDefaultIcon;
       
  2005         }
       
  2006     }
       
  2007 
       
  2008 // ---------------------------------------------------------------------------
       
  2009 // Sets the default focus
       
  2010 // ---------------------------------------------------------------------------
       
  2011 //
       
  2012 void CMPXMainViewImp::DoSetDefaultFocusL()
       
  2013     {
       
  2014     if( iContainer )
       
  2015         {
       
  2016         CMPXCommand* cmd = CMPXCommand::NewL();
       
  2017         CleanupStack::PushL( cmd );
       
  2018 
       
  2019         // Select item 0
       
  2020         //
       
  2021         cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId,
       
  2022                                      KMPXCommandIdCollectionSelect);
       
  2023         cmd->SetTObjectValueL<TInt>( KMPXCommandCollectionSelectIndex, 0 );
       
  2024         cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  2025 
       
  2026         iCollectionUtility->Collection().CommandL( *cmd );
       
  2027         CleanupStack::PopAndDestroy( cmd );
       
  2028         }
       
  2029     }
       
  2030 
       
  2031 //  End of File