mpxplugins/viewplugins/views/collectionviewhg/src/mpxcollectionviewhgimp.cpp
branchRCL_3
changeset 53 3de6c4cf6b67
child 56 2cbbefa9af78
equal deleted inserted replaced
52:14979e23cb5e 53:3de6c4cf6b67
       
     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 Collection view
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <bldvariant.hrh>
       
    20 #include <f32file.h>
       
    21 #include <eikmenub.h>
       
    22 #include <coeutils.h>
       
    23 #include <aknlists.h>
       
    24 #include <aknViewAppUi.h>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <StringLoader.h>
       
    27 #include <aknnavilabel.h>
       
    28 #include <aknnavide.h>
       
    29 #include <akntitle.h>
       
    30 #include <textresolver.h>
       
    31 #include <aknnotewrappers.h>
       
    32 #include <aknnavi.h>
       
    33 #include <hlplch.h>
       
    34 #include <avkon.hrh>
       
    35 #include <avkon.rsg>
       
    36 #include <avkon.mbg>
       
    37 #include <sendui.h>
       
    38 #include <CMessageData.h>
       
    39 #include <centralrepository.h>
       
    40 #include <MProfileEngine.h>
       
    41 #include <AknDlgShut.h>
       
    42 #ifdef RD_MULTIPLE_DRIVE
       
    43 #include <driveinfo.h>
       
    44 #endif //RD_MULTIPLE_DRIVE
       
    45 #include <aknmessagequerydialog.h>
       
    46 #include <gfxtranseffect/gfxtranseffect.h>    
       
    47 #include <akntranseffect.h>
       
    48 
       
    49 #include <upnpcopycommand.h>
       
    50 #include <AiwServiceHandler.h>  //Copy to remote feature
       
    51 
       
    52 #include <mediarecognizer.h>
       
    53 #include <featmgr.h>
       
    54 #include <AknMediatorFacade.h>
       
    55 #include <MediatorCommandInitiator.h>
       
    56 #include <MediatorDomainUIDs.h>
       
    57 
       
    58 #include <mplayersecondarydisplayapi.h>
       
    59 #include <data_caging_path_literals.hrh>
       
    60 #include <layoutmetadata.cdl.h>
       
    61 #include <mpxplaybackframeworkdefs.h>
       
    62 #include <mpxcollectionmessage.h>
       
    63 #include <mpxviewutility.h>
       
    64 #include <mpxmusicplayerviewplugin.hrh>
       
    65 #include <mpxcollectionviewhg.rsg>
       
    66 #include <mpxcollectionviewhg.mbg>
       
    67 #include <mpxcommonui.rsg>
       
    68 #include <mpxcollectionutility.h>
       
    69 #include <mpxplaybackutility.h>
       
    70 #include <mpxplaybackmessage.h>
       
    71 #include <mpxmedia.h>
       
    72 #include <mpxcollectionhelperfactory.h>
       
    73 #include <mpxcollectionplaylist.h>
       
    74 #include <mpxmediacontainerdefs.h>
       
    75 #include <mpxmediamusicdefs.h>
       
    76 #include <mpxmediacollectiondetaildefs.h>
       
    77 #include <mpxmediadrmdefs.h>
       
    78 #include <mpxmediaarray.h>
       
    79 #include <mpxcollectioncommanddefs.h>
       
    80 #include <mpxcommandgeneraldefs.h>
       
    81 #include <mpxmessagegeneraldefs.h>
       
    82 #include <mpxcommandgeneraldefs.h>
       
    83 #include <mpxcollectioncommanddefs.h>
       
    84 #include <mpxviewpluginmanager.h>
       
    85 #include <mpxviewplugin.h>
       
    86 #ifdef BACKSTEPPING_INCLUDED
       
    87 #include <mpxbacksteppingutility.h>
       
    88 #endif // BACKSTEPPING_INCLUDED
       
    89 #include <mpxcollectionopenutility.h>
       
    90 
       
    91 #include <mpxfindinmusicshop.h>
       
    92 #include <mpxfindinmusicshopcommon.h>  // KFindInMShopKeyInValid
       
    93 
       
    94 // cenrep key need to be checked whether Mass Storage or MTP is connected
       
    95 #include <UsbWatcherInternalPSKeys.h>
       
    96 #include <usbpersonalityids.h>
       
    97 #include <mtpprivatepskeys.h>
       
    98 #include <mpxappui.hrh>
       
    99 #include <mpxinternalcrkeys.h>
       
   100 #include <mpxtlshelper.h>
       
   101 #include <mpxuser.h>
       
   102 #include "mpxcollectionviewhglistboxarray.h"
       
   103 #include "mpxcommoncontainer.hrh"
       
   104 #include "mpxcommonuihelper.h"
       
   105 #include "mpxcollectionviewhgcontainer.h"
       
   106 #include "mpxcollectionviewhg.hrh"
       
   107 #include "mpxcollectionviewhg.hlp.hrh"
       
   108 #include "mpxcollectionviewhgimp.h"
       
   109 #include "mpxviewprivatepskeys.h"
       
   110 #include "mpxlog.h"
       
   111 
       
   112 
       
   113 // CONSTANTS
       
   114 _LIT( KMPXCollectionRscPath, "mpxcollectionviewhg.rsc" );
       
   115 
       
   116 const TInt KMilliSecondsToSeconds( 1000 );
       
   117 const TInt KMPXReorderNaviPaneGranularity( 2 );
       
   118 const TInt KMPXMaxBufferLength( 160 );
       
   119 const TInt KMPXMaxTimeLength( 36 );
       
   120 const TInt KMPXDurationDisplayResvLen( 10 );
       
   121 const TInt KMPXPlaylistExportRetry( 10 );
       
   122 const TInt KMPXDirectionUp( -1 );
       
   123 const TInt KMPXDirectionDown( 1 );
       
   124 const TInt KMPXErrDataNotReady( -8000 );
       
   125 const TInt KMPXErrDataNotReadyCacheCommand( -8001 );
       
   126 const TInt KMPXArrayGranularity( 100 );
       
   127 const TInt KMusicCollectionMenuLevel( 2 );
       
   128 
       
   129 _LIT( KMPXCollDetailsItemsFormat, "%S\t%S" );
       
   130 
       
   131 _LIT( KCategoryEmpty, "" );
       
   132 
       
   133 const TInt KIncrementalDelayNone = 0;
       
   134 const TInt KIncrementalDelayHalfSecond = 500000;
       
   135 const TInt KIncrementalFetchBlockSize = 400;
       
   136 const TInt KIncrementalDirectionCount = 8;
       
   137 const TInt KWaitNoteImpUid = 0x101FFC6C; // refresh wait note UID
       
   138 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
   139 const TInt KMusicMenuPodcastMenuItemIndex = 4; // podcast menu item index
       
   140 #define KPodcastCollectionUid 0x101FFC3C
       
   141 #endif
       
   142 
       
   143 const TInt KMaxIntLen( 10 );
       
   144 _LIT8( KMVPrefix, "MVviewID:" );
       
   145 const TInt KMVPrefixLen( 9 );
       
   146 
       
   147 // Music setting
       
   148 const TUid KCRUidMPXMPSettings = {0x101FFCDC};
       
   149 const TUint32 KMPXMusicStoreUID = 0x00000003;
       
   150 const TUint32 KOperatorMusicStore = 0x00000004;
       
   151 const TUint32 KOperatorMusicStoreType = 0x00000005;
       
   152 const TUint32 KOperatorMusicStoreDisplayName = 0x00000006;
       
   153 const TUint32 KOperatorMusicStoreNativeUid = 0x00000007;
       
   154 const TUint32 KOperatorMusicStoreJavaName = 0x00000008;
       
   155 const TUint32 KOperatorMusicStoreWebPage = 0x00000009;
       
   156 const TUint32 KOperatorMusicStoreURI = 0x0000000A;
       
   157 const TUint32 KEducatingUserURI = 0x0000000D;
       
   158 const TUint32 KEducatingPopupState = 0x0000000E;
       
   159 
       
   160 const TInt KJavaMusicShopType( 1 );
       
   161 const TInt KUIDMaxLength = 8;
       
   162 const TInt KMPXMaxHistoryLength( 255 );
       
   163 
       
   164 #define KProgressDownloadUid  0x10207BCD
       
   165 
       
   166 // Music collection browse type
       
   167 const TInt KMPXCollectionArtistAlbum( 3 );
       
   168 const TInt KMPXCollectionGenre( 5 );
       
   169 
       
   170 _LIT(KEmptyTitle, " ");
       
   171 
       
   172 // ======== MEMBER FUNCTIONS ========
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // Two-phased constructor.
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 CMPXCollectionViewHgImp* CMPXCollectionViewHgImp::NewL()
       
   179     {
       
   180     MPX_FUNC( "CMPXCollectionViewHgImp::NewL" );
       
   181     CMPXCollectionViewHgImp* self = CMPXCollectionViewHgImp::NewLC();
       
   182     CleanupStack::Pop( self );
       
   183     return self;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Two-phased constructor.
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CMPXCollectionViewHgImp* CMPXCollectionViewHgImp::NewLC()
       
   191     {
       
   192     CMPXCollectionViewHgImp* self = new ( ELeave ) CMPXCollectionViewHgImp();
       
   193     CleanupStack::PushL( self );
       
   194     self->ConstructL();
       
   195     return self;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Destructor
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 CMPXCollectionViewHgImp::~CMPXCollectionViewHgImp()
       
   203     {
       
   204     MPX_FUNC( "CMPXCollectionViewHgImp::~CMPXCollectionViewHgImp" );
       
   205 
       
   206     if ( iCoverDisplay )
       
   207         {
       
   208         delete iCommandInitiator;
       
   209         }
       
   210 
       
   211     // Cleanup observer, does not panic if not found
       
   212     //
       
   213     AppUi()->RemoveViewDeactivationObserver( this );
       
   214 
       
   215     if ( iCollectionUtility )
       
   216         {
       
   217         iCollectionUtility->Close();
       
   218         }
       
   219 
       
   220     if ( iPlaybackUtility )
       
   221         {
       
   222         TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) );
       
   223         iPlaybackUtility->Close();
       
   224         }
       
   225 
       
   226     if ( iViewUtility )
       
   227         {
       
   228         iViewUtility->RemoveObserver( this );
       
   229         iViewUtility->Close();
       
   230         }
       
   231 
       
   232     if ( iCollectionUiHelper )
       
   233         {
       
   234         iCollectionUiHelper->Close();
       
   235         }
       
   236 
       
   237     if ( iCollectionHelper )
       
   238         {
       
   239         iCollectionHelper->Close();
       
   240         }
       
   241 
       
   242     if ( iProfileEngine )
       
   243         {
       
   244         iProfileEngine->Release();
       
   245         }
       
   246 
       
   247     if ( iUpnpFrameworkSupport )
       
   248         {
       
   249         MPX_DEBUG1(_L("CMPXCollectionViewHgImp::~CMPXCollectionViewHgImp Detaching 'Copy to external' menu service..."));
       
   250         if ( iServiceHandler )
       
   251             {
       
   252             iServiceHandler->DetachMenu( R_MPX_COLLECTION_VIEW_MENU_1,
       
   253                                      R_MPX_UPNP_COPY_TO_EXTERNAL_MENU_INTEREST );
       
   254         iServiceHandler->DetachMenu( R_MPX_USE_AS_CASCADE,
       
   255                                  R_MPX_AIW_ASSIGN_INTEREST );
       
   256             delete iServiceHandler;
       
   257             iServiceHandler = NULL;
       
   258             }
       
   259         iPlayersList.Close();
       
   260         delete iSubPlayerName;
       
   261         }
       
   262     if ( iUpnpCopyCommand )
       
   263         {
       
   264         delete iUpnpCopyCommand;
       
   265         }
       
   266 
       
   267     if ( iServiceHandler )
       
   268         {
       
   269         iServiceHandler->DetachMenu( R_MPX_USE_AS_CASCADE,
       
   270                                  R_MPX_AIW_ASSIGN_INTEREST );
       
   271         delete iServiceHandler;
       
   272         }
       
   273     if ( iMediaRecognizer )
       
   274         {
       
   275         delete iMediaRecognizer;
       
   276         }
       
   277 
       
   278 #ifdef BACKSTEPPING_INCLUDED
       
   279     if( iBackSteppingUtility )
       
   280         {
       
   281         iBackSteppingUtility->Close();
       
   282         }
       
   283 #endif // BACKSTEPPING_INCLUDED
       
   284 
       
   285     if ( iResourceOffset )
       
   286         {
       
   287         iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   288         }
       
   289 
       
   290     if ( iContainer )
       
   291         {
       
   292         AppUi()->RemoveFromStack( iContainer );
       
   293         delete iContainer;
       
   294         }
       
   295     if( iTitleWait )
       
   296 	    {
       
   297 	    delete iTitleWait;
       
   298 		}
       
   299     delete iUserPlaylists;
       
   300     delete iCommonUiHelper;
       
   301     delete iSendUi;
       
   302     delete iTitle;
       
   303     delete iDuration;
       
   304     delete iOriginalTitle;
       
   305     delete iOriginalDuration;
       
   306     delete iNewName;
       
   307     delete iBottomIndex;
       
   308     delete iCurrentCba;
       
   309     delete iIncrementalOpenUtil;
       
   310     delete iCachedSelectionIndex;
       
   311     FeatureManager::UnInitializeLib();
       
   312     delete iOperatorMusicStoreName ;
       
   313     if ( iOperatorMusicStoreURI )
       
   314         {
       
   315         delete iOperatorMusicStoreURI;
       
   316         }
       
   317     if ( iEducateUserURI )
       
   318         {
       
   319         delete iEducateUserURI;
       
   320         }
       
   321     if (iRepository)
       
   322         {
       
   323         delete iRepository;
       
   324         }
       
   325     if (iStoredAlbum)
       
   326         delete iStoredAlbum;
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // C++ default constructor can NOT contain any code, that
       
   331 // might leave.
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 CMPXCollectionViewHgImp::CMPXCollectionViewHgImp() :
       
   335     iLastDepth( 1 ),
       
   336     iPlayIndex( KErrNotFound ),
       
   337     iSetMediaLCount( KErrNotFound ),
       
   338     iCurrentHighlightedIndex( KErrNotFound ),
       
   339     iCachedCommand( KErrNotFound ),
       
   340     iNoteType( EMPXNoteNotDefined ),
       
   341 	iFirstIncrementalBatch( ETrue ),
       
   342 	iDialogDismissed( EFalse ),
       
   343 	iTitleWait( NULL )
       
   344 	{
       
   345     MPX_FUNC( "CMPXCollectionViewHgImp::CMPXCollectionViewHgImp" );
       
   346     iUsingNokiaService = EFalse;
       
   347 #ifdef __ENABLE_MSK
       
   348     iCurrentMskId = KErrNotFound;
       
   349     iShowContextMenu = EFalse;
       
   350     iCollectionCacheReady = ETrue;
       
   351 #endif // __ENABLE_MSK
       
   352 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
   353     iPodcast = EFalse;
       
   354 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
   355     iInAlbumArtDialog = EFalse;
       
   356 
       
   357     iMarkedAll = EFalse;
       
   358     // grab the current process priority
       
   359     RProcess proc;
       
   360     iPriority = proc.Priority();
       
   361     iGoToNowPlaying = EFalse; 
       
   362     }
       
   363 
       
   364 void CMPXCollectionViewHgImp::HandleStatusPaneSizeChange()
       
   365     {
       
   366 	MPX_FUNC( "CMPXCollectionViewHgImp::HandleStatusPaneSizeChange" );
       
   367 	CMPXCollectionViewHg::HandleStatusPaneSizeChange();
       
   368 	if ( iContainer )
       
   369         {
       
   370 		iContainer->SetRect( ClientRect() );
       
   371 		UpdateTitlePaneL();
       
   372         }
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // Symbian 2nd phase constructor can leave.
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CMPXCollectionViewHgImp::ConstructL()
       
   380     {
       
   381     MPX_FUNC( "CMPXCollectionViewHgImp::ConstructL" );
       
   382 
       
   383 // initialize FeatureManager
       
   384     FeatureManager::InitializeLibL();
       
   385 
       
   386     if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
       
   387         {
       
   388         iCoverDisplay = ETrue;
       
   389         iCommandInitiator = CMediatorCommandInitiator::NewL( NULL );
       
   390         }
       
   391     else
       
   392         {
       
   393         iCoverDisplay = EFalse;
       
   394         }
       
   395 
       
   396 
       
   397     CCoeEnv* coeEnv( iEikonEnv );
       
   398     TParse parse;
       
   399     parse.Set( KMPXCollectionRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
   400     TFileName resourceFile( parse.FullName() );
       
   401     User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) );
       
   402     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile );
       
   403     iResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
   404 
       
   405     BaseConstructL( R_MPX_COLLECTION_VIEW );
       
   406 
       
   407     iIsEmbedded = iEikonEnv->StartedAsServerApp();
       
   408 
       
   409     // create a new collection utility bound to the default context.
       
   410     iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
   411     iPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault );
       
   412     iPlaybackUtility->AddObserverL( *this );
       
   413     iViewUtility = MMPXViewUtility::UtilityL();
       
   414     iViewUtility->AddObserverL( this );
       
   415     iBottomIndex = new (ELeave) CArrayFixFlat<TInt>( 1 );
       
   416 
       
   417     iCommonUiHelper = CMPXCommonUiHelper::NewL( iCollectionUtility );
       
   418     iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL();
       
   419 
       
   420     // Monitor for view activation
       
   421     AppUi()->AddViewActivationObserverL( this );
       
   422 
       
   423     if (!iUpnpCopyCommand )
       
   424         {
       
   425         MPX_TRAPD ( error, iUpnpCopyCommand = CUpnpCopyCommand::NewL() );
       
   426 		    if ( error == KErrNone )
       
   427             {
       
   428             iUpnpFrameworkSupport = ETrue;
       
   429             iServiceHandler = CAiwServiceHandler::NewL();
       
   430             MPX_DEBUG1("CMPXCollectionViewHgImp::ConstructL() Attaching 'Copy to external' menu service...");
       
   431             MPX_TRAP( iErrorAttachCopyMenu, iServiceHandler->AttachMenuL( R_MPX_COLLECTION_VIEW_MENU_1,
       
   432                                                    R_MPX_UPNP_COPY_TO_EXTERNAL_MENU_INTEREST ) );
       
   433             if ( iErrorAttachCopyMenu == KErrNotSupported )
       
   434                 {
       
   435                 // when CCoeEnv is not available
       
   436                 User::Leave( iErrorAttachCopyMenu );
       
   437                 }
       
   438             MPX_DEBUG2( "CMPXCollectionViewHgImp::ConstructL(): attach Copy menu error: %d", iErrorAttachCopyMenu );
       
   439             }
       
   440         else
       
   441             {
       
   442             iUpnpFrameworkSupport = EFalse;
       
   443             iUpnpCopyCommand = NULL;
       
   444             }
       
   445         }
       
   446     iMediaRecognizer = CMediaRecognizer::NewL();
       
   447     if ( iServiceHandler == NULL)
       
   448         {
       
   449         iServiceHandler = CAiwServiceHandler::NewL();
       
   450         }
       
   451     MPX_DEBUG1("CMPXCollectionViewHgImp::ConstructL() Attaching 'use tone as' menu service...");
       
   452     MPX_TRAP( iErrorAttachAssignMenu, iServiceHandler->AttachMenuL( R_MPX_USE_AS_CASCADE,
       
   453                                                R_MPX_AIW_ASSIGN_INTEREST ) );
       
   454 
       
   455 
       
   456     TInt flags( 0 );
       
   457     CRepository* repository = CRepository::NewL( KCRUidMPXMPFeatures );
       
   458     repository->Get( KMPXMPLocalVariation, flags );
       
   459     delete repository;
       
   460     iGoToMusicShopOptionHidden =
       
   461         !static_cast<TBool>( flags & KMPXEnableGoToMusicShopOption );
       
   462     iUsingNokiaService =
       
   463         static_cast<TBool>( flags & KMPXEnableFindInMusicShopOption );
       
   464     MPX_DEBUG2( "CMPXCollectionViewHgImp::ConstructL(): iUsingNokiaService: %d", iUsingNokiaService );
       
   465     iDisablePodcasting = flags&KMPXDisablePodcastingOption ? ETrue : EFalse;
       
   466 
       
   467 #ifdef _DEBUG
       
   468     iExitOptionHidden = EFalse;
       
   469 #else // _DEBUG
       
   470     iExitOptionHidden = iCommonUiHelper->ExitOptionHiddenL() && !iIsEmbedded;
       
   471 #endif // _DEBUG
       
   472 
       
   473     iBottomIndex->AppendL( 0 );
       
   474     iProfileEngine = CreateProfileEngineL();
       
   475 
       
   476     _LIT_SECURITY_POLICY_C1(KMPlayerRemoteReadPolicy, ECapabilityReadUserData);
       
   477     _LIT_SECURITY_POLICY_C1(KMPlayerRemoteWritePolicy, ECapabilityWriteUserData);
       
   478 
       
   479     if (iGoToMusicShopOptionHidden)
       
   480         {
       
   481         iMusicStoreUID = 0;
       
   482         }
       
   483     else
       
   484         {
       
   485         // Get music store uid from cenrep
       
   486         //
       
   487         TBuf8< KUIDMaxLength > musicStoreUID;
       
   488         TRAP_IGNORE(
       
   489             {
       
   490             CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings );
       
   491             repository->Get( KMPXMusicStoreUID, musicStoreUID );
       
   492             delete repository;
       
   493             repository = NULL;
       
   494             } );
       
   495 
       
   496         GetUint32Presentation( iMusicStoreUID, musicStoreUID, 0 );
       
   497         if (iMusicStoreUID == 0)
       
   498             {
       
   499             iGoToMusicShopOptionHidden = ETrue;
       
   500             }
       
   501         }
       
   502     MPX_DEBUG2("CMPXCollectionViewHgImp::ConstructL musicStoreUID = %x", iMusicStoreUID);
       
   503 
       
   504     TInt retval(KErrNone);
       
   505     // P/S key for music shop
       
   506     retval = RProperty::Define( TUid::Uid(iMusicStoreUID),
       
   507                                 KMShopCategoryId,
       
   508                                 RProperty::EInt,
       
   509                                 KMPlayerRemoteReadPolicy,
       
   510                                 KMPlayerRemoteWritePolicy );
       
   511 
       
   512     if( retval != KErrAlreadyExists)
       
   513         {
       
   514         RProperty::Set( TUid::Uid(iMusicStoreUID),
       
   515                         KMShopCategoryId,
       
   516                         KFindInMShopKeyInValid );  // initialize Find In Musicshop was not called
       
   517 
       
   518 
       
   519         RProperty::Define(  TUid::Uid(iMusicStoreUID),
       
   520                             KMShopCategoryName,
       
   521                             RProperty::ELargeText,
       
   522                             KMPlayerRemoteReadPolicy,
       
   523                             KMPlayerRemoteWritePolicy );
       
   524         }
       
   525 
       
   526     iCachedSelectionIndex = new ( ELeave )CArrayFixFlat<TInt>( KMPXArrayGranularity );
       
   527     iIncrementalOpenUtil = CMPXCollectionOpenUtility::NewL( this );
       
   528 
       
   529 #ifdef BACKSTEPPING_INCLUDED
       
   530     // Initialize the Back Stepping Service Utility with the MPX Music Player
       
   531     iBackSteppingUtility = MMPXBackSteppingUtility::UtilityL();
       
   532     iBackSteppingUtility->InitializeL(
       
   533         TUid::Uid( KMusicPlayerAppUidConstant ) );
       
   534     iActivateBackStepping = EFalse;
       
   535 #endif //BACKSTEPPING_INCLUDED
       
   536 
       
   537     iIsAddingToPlaylist = EFalse;
       
   538    
       
   539     //Get educating user URI and popup state from cenrep
       
   540     iEducateUserURI = HBufC16::NewL( KMPXMaxHistoryLength );
       
   541     TPtr16 educatingURI = iEducateUserURI->Des();
       
   542     iRepository = CRepository::NewL( KCRUidMPXMPSettings );
       
   543     iRepository->Get( KEducatingUserURI, educatingURI );
       
   544     iRepository->Get( KEducatingPopupState, iEducatingPopupState);
       
   545         
       
   546        // Get music store information from cenrep
       
   547    //
       
   548    TBuf8< KUIDMaxLength > operatorMusicStoreUID;
       
   549 
       
   550    iOperatorMusicStoreName = HBufC16::NewL( KMPXMaxHistoryLength );
       
   551    TPtr operatorMusicStoreMenuOption = iOperatorMusicStoreName->Des();
       
   552 
       
   553    HBufC16* musicStoreJavaName = HBufC16::NewLC( KMPXMaxHistoryLength );
       
   554    TPtr operatorMusicStoreJavaName = musicStoreJavaName->Des();
       
   555 
       
   556    TRAP_IGNORE(
       
   557     {
       
   558     CRepository* musicshoprepository = CRepository::NewL( KCRUidMPXMPSettings );
       
   559     musicshoprepository->Get( KOperatorMusicStore, iOperatorMusicStore );
       
   560     if(iOperatorMusicStore)
       
   561         {
       
   562         musicshoprepository->Get( KOperatorMusicStoreType, iOperatorMusicStoreType );
       
   563         musicshoprepository->Get( KOperatorMusicStoreDisplayName, operatorMusicStoreMenuOption );
       
   564         if (iOperatorMusicStoreType == KJavaMusicShopType)
       
   565             {
       
   566             musicshoprepository->Get( KOperatorMusicStoreJavaName, operatorMusicStoreJavaName );
       
   567             }
       
   568         else
       
   569             {
       
   570             musicshoprepository->Get( KOperatorMusicStoreNativeUid, operatorMusicStoreUID );
       
   571             GetUint32Presentation( iOperatorNativeMusicStoreUID, operatorMusicStoreUID, 0 );
       
   572 
       
   573             musicshoprepository->Get(KOperatorMusicStoreWebPage, iMusicStoreWebPage);
       
   574             iOperatorMusicStoreURI = HBufC16::NewL( KMPXMaxHistoryLength );
       
   575             TPtr16 operatorMusicStoreuri = iOperatorMusicStoreURI->Des();
       
   576             musicshoprepository->Get(KOperatorMusicStoreURI, operatorMusicStoreuri);
       
   577 
       
   578             }
       
   579         }
       
   580     delete musicshoprepository;
       
   581     musicshoprepository = NULL;
       
   582     } );
       
   583 
       
   584     if(iOperatorMusicStoreType == KJavaMusicShopType)
       
   585         {
       
   586             TApaAppInfo appInfo;
       
   587             RApaLsSession apaSession;
       
   588             User::LeaveIfError( apaSession.Connect() );
       
   589             CleanupClosePushL( apaSession );
       
   590             User::LeaveIfError( apaSession.GetAllApps() );
       
   591 
       
   592             while ( apaSession.GetNextApp( appInfo ) == KErrNone )
       
   593                 {
       
   594                 if(appInfo.iFullName.Right(8).Compare(_L(".fakeapp")) == 0)
       
   595                     {
       
   596                     TApaAppCaption appname;
       
   597                     appname = appInfo.iCaption ;
       
   598                     if (!appInfo.iCaption.Compare(operatorMusicStoreJavaName))
       
   599                         {
       
   600                         iOperatorMusicStoreUID = appInfo.iUid;
       
   601                         }
       
   602                     }
       
   603                 }
       
   604             CleanupStack::PopAndDestroy(&apaSession); // close apaSession
       
   605         }
       
   606     //else
       
   607     //    {
       
   608     //    GetUint32Presentation( iMusicStoreUID, operatorMusicStoreUID, 0 );
       
   609     //    }
       
   610     CleanupStack::PopAndDestroy(musicStoreJavaName);
       
   611 
       
   612     // P/S key for usb unblocking
       
   613     RProperty::Define( KMPXViewPSUid,
       
   614             KMPXUSBUnblockingPSStatus,
       
   615             RProperty::EInt,
       
   616             KMPlayerRemoteReadPolicy,
       
   617             KMPlayerRemoteWritePolicy );
       
   618 
       
   619     TInt usbStatus;
       
   620     RProperty::Get(KPSUidUsbWatcher, KUsbWatcherSelectedPersonality, usbStatus);
       
   621 
       
   622     TInt mtpStatus = EMtpPSStatusUninitialized;
       
   623     RProperty::Get( KMtpPSUid, KMtpPSStatus, mtpStatus);
       
   624     
       
   625     MPX_DEBUG2("CMPXCollectionViewHgImp::ConstructL, mtpstatus = %d", mtpStatus);
       
   626 
       
   627     // Whenever usb/mtp is connected
       
   628     if ( usbStatus == KUsbPersonalityIdMS
       
   629                 || usbStatus == KUsbPersonalityIdPTP
       
   630                 || usbStatus == KUsbPersonalityIdPCSuite 
       
   631                 || mtpStatus != EMtpPSStatusUninitialized )
       
   632         {
       
   633         RProperty::Set( KMPXViewPSUid,
       
   634         		        KMPXUSBUnblockingPSStatus,
       
   635                         EMPXUSBUnblockingPSStatusActive);
       
   636         }
       
   637     else
       
   638         {
       
   639         RProperty::Set( KMPXViewPSUid, 
       
   640         		        KMPXUSBUnblockingPSStatus,
       
   641                         EMPXUSBUnblockingPSStatusUninitialized );
       
   642         }
       
   643     } 
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // Delete the selected items in TBone View
       
   647 // ---------------------------------------------------------------------------
       
   648 //
       
   649 void CMPXCollectionViewHgImp::DeleteSelectedTBoneItemsL(TInt aCommand)
       
   650     {
       
   651     MPX_FUNC( "CMPXCollectionViewHgImp::DeleteSelectedTBoneItemsL" );
       
   652      // if reorder mode is on, or something is currently deleting, disable delete
       
   653     TBool isIgnore( iContainer->IsInReorderMode() || iIsDeleting );
       
   654 
       
   655     if ( !isIgnore  && iCollectionReady )
       
   656         {
       
   657         CMPXCommonListBoxArrayBase* listboxArray( iContainer->ListBoxArray() );
       
   658 
       
   659         HBufC* promptTxt( NULL );
       
   660         HBufC* waitNoteText( NULL );
       
   661         TInt waitNoteCBA( R_AVKON_SOFTKEYS_EMPTY );
       
   662         
       
   663         // Create a copy of collection path
       
   664         CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
       
   665         CleanupStack::PushL( path );
       
   666 
       
   667         if ( iContainer->IsTBoneView() )
       
   668             {
       
   669              //get the media object of the selected track in TBone View
       
   670             CMPXMedia* albumTrack = iContainer->SelectedItemMediaL();
       
   671             
       
   672             TMPXGeneralType mediaType(
       
   673                     albumTrack->ValueTObjectL<TMPXGeneralType>(
       
   674                             KMPXMediaGeneralType ) );
       
   675             TMPXGeneralCategory mediaCategory(
       
   676                     albumTrack->ValueTObjectL<TMPXGeneralCategory>(
       
   677                     KMPXMediaGeneralCategory ) );
       
   678 
       
   679             if ( mediaType == EMPXItem && mediaCategory == EMPXSong )
       
   680                 {
       
   681                 // tracks level in Tbone View
       
   682                 TMPXItemId trackId = albumTrack->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
   683                 const TDesC& trackTitle( albumTrack->ValueText( KMPXMediaGeneralTitle ) );
       
   684                 // create the item path to delete
       
   685 
       
   686                 if ( 2 == path->Levels() )
       
   687                     {
       
   688                     path->Back();
       
   689                     path->AppendL(3);
       
   690                     }
       
   691                  else if ( path->Levels() == 3 )
       
   692 					{
       
   693 					path->Back();
       
   694 					}
       
   695 				 else if (path->Levels() == 4)
       
   696 					{
       
   697 					path->Back();
       
   698 					path->Back();
       
   699 					}
       
   700 
       
   701                 TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
   702                 const CMPXMediaArray& albums = listboxArray->MediaArray();
       
   703                 CMPXMedia* album( albums.AtL( currentIndex ) );
       
   704                 const TMPXItemId albumId = album->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
   705 
       
   706                 path->AppendL(albumId);
       
   707                 path->AppendL(trackId);
       
   708                  
       
   709                 MPX_DEBUG_PATH(*path);
       
   710 
       
   711                 waitNoteText = StringLoader::LoadLC(
       
   712                     R_MPX_QTN_ALBUM_WAITING_DELETING, trackTitle );
       
   713                 promptTxt = StringLoader::LoadLC(
       
   714                     R_MPX_QTN_QUERY_COMMON_CONF_DELETE,
       
   715                     trackTitle );
       
   716 
       
   717                 iConfirmationDlg = CAknQueryDialog::NewL(
       
   718                 CAknQueryDialog::EConfirmationTone );
       
   719 
       
   720                 waitNoteCBA = R_MPX_COLLECTION_WAITNOTE_SOFTKEYS_EMPTY_STOP;
       
   721                 
       
   722                 iConfirmationDlg->SetPromptL( *promptTxt );
       
   723                 CleanupStack::PopAndDestroy( promptTxt );
       
   724                 TBool performDelete(EFalse);
       
   725                 if(iCachedCommand == aCommand)
       
   726                    {
       
   727                    performDelete = ETrue;
       
   728                    }
       
   729                 if (!performDelete)
       
   730                     {
       
   731                     if ( iConfirmationDlg->ExecuteLD( R_MPX_CUI_DELETE_CONFIRMATION_QUERY ) )
       
   732                         {
       
   733                         performDelete = ETrue;
       
   734                         }
       
   735                     }
       
   736                 if (performDelete)
       
   737                     {
       
   738                     HandleCommandL( EMPXCmdIgnoreExternalCommand );
       
   739                     MPX_PERF_START_EX( MPX_PERF_SHOW_WAITNOTE );
       
   740                     if(iCachedCommand != aCommand)
       
   741                         {
       
   742                         iIsWaitNoteCanceled = EFalse;
       
   743                         StartDeleteWaitNoteL();
       
   744                         TPtr buf = waitNoteText->Des();
       
   745                         UpdateProcessL( buf );
       
   746                         }
       
   747                     if ( !iIsWaitNoteCanceled )
       
   748                         {
       
   749                         iIsDeleting = ETrue;
       
   750                         iCollectionUiHelper->DeleteL( *path, this );
       
   751                         }
       
   752                     else if( iContainer )
       
   753                         {
       
   754                         // delete was canceled before it even began, clear marked items
       
   755                         iContainer->ClearLbxSelection();
       
   756                         }
       
   757                     iIsWaitNoteCanceled = EFalse;
       
   758         
       
   759                     if(iContainer->FindBoxVisibility())
       
   760                         {
       
   761                         iContainer->EnableFindBox(EFalse);
       
   762                         }
       
   763 
       
   764                     // delete songs list to update T-bone view after deleting a song
       
   765                     album->Delete( KMPXMediaArrayContents );
       
   766                     }
       
   767                 iConfirmationDlg = NULL;
       
   768                 CleanupStack::PopAndDestroy( waitNoteText );                
       
   769                 }
       
   770             }
       
   771         CleanupStack::PopAndDestroy( path );
       
   772         }
       
   773     }
       
   774 
       
   775 
       
   776 // ---------------------------------------------------------------------------
       
   777 // Delete the selected items
       
   778 // ---------------------------------------------------------------------------
       
   779 //
       
   780 void CMPXCollectionViewHgImp::DeleteSelectedItemsL(TInt aCommand)
       
   781     {
       
   782     MPX_FUNC( "CMPXCollectionViewHgImp::DeleteSelectedItemsL" );
       
   783 
       
   784     // if reorder mode is on, or something is currently deleting, disable delete
       
   785     TBool isIgnore( iContainer->IsInReorderMode() || iIsDeleting );
       
   786 
       
   787     CMPXCommonListBoxArrayBase* listboxArray(
       
   788         iContainer->ListBoxArray() );
       
   789     const CMPXMedia& containerMedia( listboxArray->ContainerMedia() );
       
   790     TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
   791 
       
   792     // Marked indicies
       
   793     // cannot use the caches indexes since this can be reached by pressing the cancel key
       
   794     const CArrayFix<TInt>* array (
       
   795         iContainer->CurrentSelectionIndicesL() ); // not owned
       
   796     TInt arrayCount( array->Count() );
       
   797 
       
   798     if ( !isIgnore )
       
   799         {
       
   800         if ( iContainer->CurrentListItemCount() == 0 )
       
   801             {
       
   802             // list is empty
       
   803             isIgnore = ETrue;
       
   804             }
       
   805         if ( !isIgnore &&
       
   806             containerMedia.IsSupported( KMPXMediaGeneralNonPermissibleActions ) )
       
   807             {
       
   808             TMPXGeneralNonPermissibleActions attr(
       
   809                 containerMedia.ValueTObjectL<TMPXGeneralNonPermissibleActions>(
       
   810                 KMPXMediaGeneralNonPermissibleActions ) );
       
   811             if ( attr & EMPXWrite )
       
   812                 {
       
   813                 isIgnore = ETrue;
       
   814                 }
       
   815             }
       
   816         if ( !isIgnore )
       
   817             {
       
   818             const CMPXMedia& media( listboxArray->MediaL( currentIndex ) );
       
   819             if ( ( arrayCount == 0 || arrayCount == 1 ) &&
       
   820                 ( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId ) )
       
   821                 {
       
   822                 // not marked, or only 1 item is marked
       
   823                 // and the highlighted item is not yet available
       
   824                 isIgnore = ETrue;
       
   825                 }
       
   826             else if ( media.IsSupported( KMPXMediaGeneralNonPermissibleActions ) )
       
   827                 {
       
   828                 TMPXGeneralNonPermissibleActions attr(
       
   829                     media.ValueTObjectL<TMPXGeneralNonPermissibleActions>(
       
   830                         KMPXMediaGeneralNonPermissibleActions ) );
       
   831                 if ( attr & EMPXWrite )
       
   832                     {
       
   833                     isIgnore = ETrue;
       
   834                     }
       
   835                 }
       
   836             }
       
   837         }
       
   838 
       
   839     if ( !isIgnore )
       
   840         {
       
   841         // Create a copy of collection path
       
   842         CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
       
   843         CleanupStack::PushL( path );
       
   844         
       
   845         if ( 2 == path->Levels() )
       
   846              {
       
   847              path->Back();
       
   848              path->AppendL(3);
       
   849              
       
   850              const CMPXMediaArray& albums = listboxArray->MediaArray();
       
   851              
       
   852              RArray<TMPXItemId> ids;
       
   853              CleanupClosePushL(ids);
       
   854 
       
   855              TInt albumCount = albums.Count();
       
   856               for (TInt i=0; i<albumCount; ++i)
       
   857                   {
       
   858                   CMPXMedia* album = albums.AtL(i);
       
   859                   const TMPXItemId id = album->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
   860                   ids.AppendL(id);
       
   861                   }
       
   862               path->AppendL(ids.Array()); // top level items
       
   863               ids.Reset();
       
   864               path->Set(currentIndex);
       
   865               CleanupStack::PopAndDestroy(&ids);             
       
   866              }
       
   867         MPX_DEBUG_PATH(*path);
       
   868         
       
   869         HBufC* promptTxt( NULL );
       
   870         HBufC* waitNoteText( NULL );
       
   871         TInt waitNoteCBA( R_AVKON_SOFTKEYS_EMPTY );
       
   872         MPX_DEBUG2( "CMPXCollectionViewHgImp::DeleteSelectedItemsL delete array count = %d", arrayCount );
       
   873 
       
   874         TMPXGeneralType containerType(
       
   875             containerMedia.ValueTObjectL<TMPXGeneralType>(
       
   876                 KMPXMediaGeneralType ) );
       
   877         TMPXGeneralCategory containerCategory(
       
   878             containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
   879                 KMPXMediaGeneralCategory ) );
       
   880 
       
   881         if ( arrayCount > 1 )
       
   882             {
       
   883             if ( containerType == EMPXItem && containerCategory == EMPXPlaylist )
       
   884                 {
       
   885                 // playlist view
       
   886                 waitNoteText = StringLoader::LoadLC(
       
   887                     R_MPX_QTN_NMP_NOTE_REMOVING_MANY );
       
   888                 promptTxt = StringLoader::LoadLC(
       
   889                     R_MPX_QTN_MUS_QUERY_CONF_REMOVE_MANY,
       
   890                     arrayCount );
       
   891                 }
       
   892             else
       
   893                 {
       
   894                 waitNoteText = StringLoader::LoadLC(
       
   895                     R_MPX_QTN_NMP_DEL_SONGS_WAIT_NOTE );
       
   896                 promptTxt = StringLoader::LoadLC(
       
   897                     R_MPX_QTN_NMP_DEL_SONGS_QUERY,
       
   898                     arrayCount );
       
   899                 }
       
   900             waitNoteCBA = R_MPX_COLLECTION_WAITNOTE_SOFTKEYS_EMPTY_STOP;
       
   901             iConfirmationDlg = CAknQueryDialog::NewL(
       
   902                 CAknQueryDialog::EConfirmationTone );
       
   903             if ( iCoverDisplay )
       
   904                 {
       
   905                 if ( containerType == EMPXItem && containerCategory == EMPXPlaylist )
       
   906                     {
       
   907                     iConfirmationDlg->PublishDialogL(
       
   908                         EMPlayerQueryRemoveTracks,
       
   909                         KMPlayerNoteCategory);
       
   910                     iWaitNoteId = EMPlayerNoteRemovingMany;
       
   911                     }
       
   912                 else
       
   913                     {
       
   914                     iConfirmationDlg->PublishDialogL(
       
   915                         EMPlayerQueryDeleteTracks,
       
   916                         KMPlayerNoteCategory);
       
   917                     iWaitNoteId = EMPlayerNoteDeletingMany;
       
   918                     }
       
   919                 CAknMediatorFacade* covercl(
       
   920                     AknMediatorFacade( iConfirmationDlg ) );
       
   921                 if ( covercl )
       
   922                     {
       
   923                     covercl->BufStream().WriteInt32L( arrayCount );
       
   924                     }
       
   925                 }
       
   926             if(iCollectionReady || aCommand == EMPXCmdCommonDelete )
       
   927                 {
       
   928             for ( TInt i = 0; i < arrayCount; i++ )
       
   929                 {
       
   930                 MPX_DEBUG2( "CMPXCollectionViewHgImp::DeleteSelectedItemsL delete array index = %d", array->At( i ) );
       
   931                 path->SelectL( array->At(i) );
       
   932                     }
       
   933                 }
       
   934             }
       
   935         else
       
   936             {
       
   937             // not marked, process the highlighted item
       
   938             const CMPXMedia& media( listboxArray->MediaL(
       
   939                 ( arrayCount > 0 ) ? array->At( 0 ) : currentIndex ) );
       
   940             const TDesC& title( media.ValueText( KMPXMediaGeneralTitle ) );
       
   941 
       
   942             TMPXGeneralType type(
       
   943                 media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
   944             TMPXGeneralCategory category(
       
   945                 media.ValueTObjectL<TMPXGeneralCategory>(
       
   946                     KMPXMediaGeneralCategory ) );
       
   947 
       
   948             if ( containerType == EMPXItem && containerCategory == EMPXPlaylist )
       
   949                 {
       
   950                 // playlist view
       
   951                 waitNoteText = StringLoader::LoadLC(
       
   952                     R_MPX_QTN_MUS_NOTE_REMOVING_TRACK, title );
       
   953                 promptTxt = StringLoader::LoadLC(
       
   954                     R_MPX_QTN_MUS_QUERY_CONF_REMOVE_TRACK,
       
   955                     title );
       
   956                 }
       
   957             else if ( containerType == EMPXItem && containerCategory == EMPXArtist
       
   958                 && type == EMPXItem && category == EMPXAlbum && currentIndex == 0 )
       
   959                 {
       
   960                 // deleting first entry in artist/album view
       
   961                 const TDesC& containerTitle(
       
   962                     containerMedia.ValueText( KMPXMediaGeneralTitle ) );
       
   963                 waitNoteText = StringLoader::LoadLC(
       
   964                     R_MPX_QTN_MUS_QUERY_CONF_DELETE_ALL, containerTitle );
       
   965                 waitNoteCBA = R_MPX_COLLECTION_WAITNOTE_SOFTKEYS_EMPTY_STOP;
       
   966                 promptTxt = StringLoader::LoadLC(
       
   967                     R_MPX_QTN_NMP_QUERY_CONF_DELETE_GROUP,
       
   968                     containerTitle );
       
   969                 }
       
   970             else
       
   971                 {
       
   972                 if ( ( type == EMPXItem && category == EMPXSong ) ||
       
   973                     ( type == EMPXItem && category == EMPXPlaylist ) )
       
   974                     {
       
   975                     // tracks level, or deleting a playlist
       
   976                     waitNoteText = StringLoader::LoadLC(
       
   977                         R_MPX_QTN_ALBUM_WAITING_DELETING, title );
       
   978                     promptTxt = StringLoader::LoadLC(
       
   979                         R_MPX_QTN_QUERY_COMMON_CONF_DELETE,
       
   980                         title );
       
   981                     }
       
   982                 else
       
   983                     {
       
   984                     // deleting a group
       
   985                     if ( ( currentIndex == ( iContainer->CurrentListItemCount() - 1 ) ) &&
       
   986                         title.Compare( KNullDesC ) == 0 )
       
   987                         {
       
   988                         // check for unknown entry
       
   989                         // if it's the last entry, and it's null text
       
   990                         // load "unknown" text to display in prompt
       
   991                         waitNoteText = StringLoader::LoadLC(
       
   992                             R_MPX_QTN_MUS_QUERY_CONF_DELETE_ALL_UNKNOWN);
       
   993                         promptTxt = StringLoader::LoadLC(
       
   994                             R_MPX_QTN_NMP_QUERY_CONF_DELETE_GROUP_UNKNOWN);
       
   995                         }
       
   996                     else
       
   997                         {
       
   998                         waitNoteText = StringLoader::LoadLC(
       
   999                             R_MPX_QTN_MUS_QUERY_CONF_DELETE_ALL, title );
       
  1000                         promptTxt = StringLoader::LoadLC(
       
  1001                             R_MPX_QTN_NMP_QUERY_CONF_DELETE_GROUP, title );
       
  1002                         }
       
  1003                     waitNoteCBA = R_MPX_COLLECTION_WAITNOTE_SOFTKEYS_EMPTY_STOP;
       
  1004                     }
       
  1005                 }
       
  1006             iConfirmationDlg = CAknQueryDialog::NewL(
       
  1007                 CAknQueryDialog::EConfirmationTone );
       
  1008             if ( iCoverDisplay )
       
  1009                 {
       
  1010                 if ( containerType == EMPXItem && containerCategory == EMPXPlaylist )
       
  1011                     {
       
  1012                     iConfirmationDlg->PublishDialogL(
       
  1013                         EMPlayerQueryRemoveTrack,
       
  1014                         KMPlayerNoteCategory);
       
  1015                     iWaitNoteId = EMPlayerNoteRemovingTrack;
       
  1016                     }
       
  1017                 else if ( containerType == EMPXItem && containerCategory == EMPXArtist
       
  1018                     && type == EMPXItem && category == EMPXAlbum && currentIndex == 0 )
       
  1019                     {
       
  1020                     iConfirmationDlg->PublishDialogL(
       
  1021                         EMPlayerQueryDeleteCategory,
       
  1022                         KMPlayerNoteCategory);
       
  1023                     iWaitNoteId = EMPlayerNoteDeletingSingle;
       
  1024                     }
       
  1025                 else
       
  1026                     {
       
  1027                     if ( ( type == EMPXItem && category == EMPXSong ) ||
       
  1028                         ( type == EMPXItem && category == EMPXPlaylist ) )
       
  1029                         {
       
  1030                         // tracks level
       
  1031                         iConfirmationDlg->PublishDialogL(
       
  1032                             EMPlayerQueryDeleteCategory,
       
  1033                             KMPlayerNoteCategory);
       
  1034                         iWaitNoteId = EMPlayerNoteDeletingSingle;
       
  1035                         }
       
  1036                     else
       
  1037                         {
       
  1038                         iConfirmationDlg->PublishDialogL(
       
  1039                             EMPlayerQueryDeleteTrack,
       
  1040                             KMPlayerNoteCategory);
       
  1041                         iWaitNoteId = EMPlayerNoteDeletingSingle;
       
  1042                         }
       
  1043                     }
       
  1044                 CAknMediatorFacade* covercl(
       
  1045                     AknMediatorFacade( iConfirmationDlg ) );
       
  1046                 if ( covercl )
       
  1047                     {
       
  1048                     covercl->BufStream() << title;
       
  1049                     }
       
  1050                 iItemTitle.Set( title );
       
  1051                 }
       
  1052 //#endif //__COVER_DISPLAY
       
  1053 // Cover UI end
       
  1054             if(iCollectionReady || aCommand == EMPXCmdCommonDelete )
       
  1055                 {
       
  1056             path->SelectL( arrayCount > 0 ? array->At( 0 ) : currentIndex );
       
  1057                 }
       
  1058             }
       
  1059         iConfirmationDlg->SetPromptL( *promptTxt );
       
  1060         CleanupStack::PopAndDestroy( promptTxt );
       
  1061         TBool performDelete(EFalse);
       
  1062         if(iCachedCommand == aCommand)
       
  1063             {
       
  1064             performDelete = ETrue;
       
  1065             }
       
  1066         if (!performDelete)
       
  1067             {
       
  1068         if ( iConfirmationDlg->ExecuteLD( R_MPX_CUI_DELETE_CONFIRMATION_QUERY ) )
       
  1069                 {
       
  1070                 performDelete = ETrue;
       
  1071                 }
       
  1072             }
       
  1073         if (performDelete)
       
  1074             {
       
  1075             HandleCommandL( EMPXCmdIgnoreExternalCommand );
       
  1076 // Cover UI start
       
  1077 //#ifdef __COVER_DISPLAY
       
  1078         if ( iCoverDisplay )
       
  1079             {
       
  1080             InitiateWaitDialogL();
       
  1081             }
       
  1082 //#endif // __COVER_DISPLAY
       
  1083 // Cover UI end
       
  1084             MPX_PERF_START_EX( MPX_PERF_SHOW_WAITNOTE );
       
  1085             if(iCachedCommand != aCommand)
       
  1086                 {
       
  1087                 iIsWaitNoteCanceled = EFalse;
       
  1088                 StartDeleteWaitNoteL();
       
  1089 				TPtr buf = waitNoteText->Des();
       
  1090 				UpdateProcessL( buf );
       
  1091                 }
       
  1092 
       
  1093                 if ( !iIsWaitNoteCanceled )
       
  1094                     {
       
  1095                     iIsDeleting = ETrue;
       
  1096                     iCollectionUiHelper->DeleteL( *path, this );
       
  1097                     iFirstIndexOnScreen = iContainer->FirstIndexOnScreen();               
       
  1098                     }
       
  1099                 else if( iContainer )
       
  1100                     {
       
  1101                     // delete was canceled before it even began, clear marked items
       
  1102                     iContainer->ClearLbxSelection();
       
  1103                     }
       
  1104                 iIsWaitNoteCanceled = EFalse;
       
  1105 
       
  1106 
       
  1107             if(iContainer->FindBoxVisibility())
       
  1108                 {
       
  1109                 iContainer->EnableFindBox(EFalse);
       
  1110                 }
       
  1111             }
       
  1112         iConfirmationDlg = NULL;
       
  1113         CleanupStack::PopAndDestroy( waitNoteText );
       
  1114         CleanupStack::PopAndDestroy( path );
       
  1115         }
       
  1116     }
       
  1117 
       
  1118 // ---------------------------------------------------------------------------
       
  1119 // Initiates wait dialog
       
  1120 // ---------------------------------------------------------------------------
       
  1121 //
       
  1122 void CMPXCollectionViewHgImp::InitiateWaitDialogL()
       
  1123     {
       
  1124     if ( iCommandInitiator )
       
  1125         {
       
  1126         HBufC8* filename8 = HBufC8::NewLC( KMaxFileName );
       
  1127         filename8->Des().Copy( iItemTitle );
       
  1128         HBufC8* data = HBufC8::NewLC(KMaxFileName);
       
  1129 
       
  1130         TPtr8 dataPtr = data->Des();
       
  1131         RDesWriteStream str(dataPtr);
       
  1132 
       
  1133         TPtrC8 b(KNullDesC8);
       
  1134         b.Set(*filename8);
       
  1135 
       
  1136         str << b;
       
  1137         str.CommitL();
       
  1138 
       
  1139         iCommandInitiator->IssueCommand( KMediatorSecondaryDisplayDomain,
       
  1140                                     KMPlayerNoteCategory,
       
  1141                                     iWaitNoteId,
       
  1142                                     TVersion ( 0,0,0 ),
       
  1143                                     *data );
       
  1144 
       
  1145         CleanupStack::PopAndDestroy( data );
       
  1146         CleanupStack::PopAndDestroy( filename8 );
       
  1147         }
       
  1148     }
       
  1149 
       
  1150 // ---------------------------------------------------------------------------
       
  1151 // Updates list box
       
  1152 // ---------------------------------------------------------------------------
       
  1153 //
       
  1154 void CMPXCollectionViewHgImp::UpdateListBoxL(
       
  1155     const CMPXMedia& aEntries,
       
  1156     TInt aIndex,
       
  1157     TBool aComplete)
       
  1158     {
       
  1159     MPX_FUNC( "CMPXCollectionViewHgImp::UpdateListBox" );
       
  1160     MPX_DEBUG2( "CMPXCollectionViewHgImp::UpdateListBox aIndex = %d", aIndex );
       
  1161     if ( iContainer )
       
  1162         {
       
  1163         CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  1164         MPX_DEBUG_PATH(*cpath);
       
  1165 
       
  1166         CleanupStack::PushL( cpath );
       
  1167 
       
  1168         TInt topIndex = 0;
       
  1169         if (iContainer->IsInReorderMode())
       
  1170             {
       
  1171             TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  1172             TInt currentBottomIndex( iContainer->BottomLbxItemIndex() );
       
  1173             topIndex = iContainer->CalculateTopIndex( currentBottomIndex ) ;
       
  1174             }
       
  1175 
       
  1176         CMPXCommonListBoxArrayBase* array( iContainer->ListBoxArray() );
       
  1177         array->ResetMediaArrayL();
       
  1178         array->AppendMediaL( aEntries );
       
  1179         iCollectionCacheReady = ETrue;
       
  1180         //keep the marked item indicies
       
  1181         const CArrayFix<TInt>* markedList = iContainer->CurrentSelectionIndicesL();
       
  1182 		if ( iFirstIncrementalBatch )
       
  1183             {
       
  1184             iContainer->HandleLbxItemAdditionL();
       
  1185             iFirstIncrementalBatch = EFalse;
       
  1186             }
       
  1187 		else
       
  1188 			{
       
  1189 			iContainer->HandleListBoxArrayEventL(
       
  1190 			MMPXCommonListBoxArrayObserver::EMPXCommonListBoxArrayEventMediaArrayChange );
       
  1191 			}
       
  1192 
       
  1193         if (aComplete)
       
  1194             {
       
  1195             iFirstIncrementalBatch = ETrue;
       
  1196             }
       
  1197         //mark all again after list box item addition
       
  1198         if (iMarkedAll)
       
  1199             {
       
  1200             iContainer->HandleMarkableListProcessCommandL(EAknMarkAll);
       
  1201             if (aComplete)
       
  1202                 {
       
  1203                 iMarkedAll = EFalse;
       
  1204                 }
       
  1205             }
       
  1206 		   //mark again individual items after list box item addition
       
  1207         else if ( markedList )
       
  1208             {
       
  1209 		       TInt markedItemCount( markedList->Count() );
       
  1210 		       if ( markedItemCount >0 )
       
  1211                 {
       
  1212                 iContainer->SetCurrentSelectionIndicesL( const_cast<CArrayFix<TInt>*>(markedList) );
       
  1213                 }
       
  1214             }
       
  1215         UpdatePlaybackStatusL();
       
  1216 
       
  1217         if ( iBackOneLevel || iPossibleJump )
       
  1218             {
       
  1219             if ( cpath->Levels() == iLastDepth )
       
  1220                 {
       
  1221                 iLastDepth--;
       
  1222                 iContainer->SetLbxTopItemIndex(
       
  1223                     iContainer->CalculateTopIndex(
       
  1224                     iBottomIndex->At( iLastDepth ) ) );
       
  1225                 iContainer->SetLbxCurrentItemIndexAndDraw( aIndex );
       
  1226                 iBottomIndex->Delete( iLastDepth );
       
  1227                 }
       
  1228             else
       
  1229                 {
       
  1230                 MPX_DEBUG1( "CMPXCollectionViewHgImp::UpdateListBox Invalid history, rebuilding" );
       
  1231                 // invalid path, rebuild with all 0. possibily caused by a jump in views
       
  1232                 iBottomIndex->Reset();
       
  1233                 iLastDepth = cpath->Levels();
       
  1234                 for ( TInt i = 0; i < iLastDepth; i++ )
       
  1235                     {
       
  1236                     iBottomIndex->AppendL( 0 );
       
  1237                     }
       
  1238                 iContainer->SetLbxCurrentItemIndexAndDraw( aIndex );
       
  1239                 }
       
  1240             iPossibleJump = EFalse;
       
  1241             iBackOneLevel = EFalse;
       
  1242             }
       
  1243         else
       
  1244             {
       
  1245             if ( iAddingSong )
       
  1246                 {
       
  1247                 // always highlight the last item when a track
       
  1248                 // is added in add tracks view
       
  1249                 TInt currentItemCount =
       
  1250                     iContainer->CurrentListItemCount();
       
  1251                 if ( currentItemCount > 0 )
       
  1252                     {
       
  1253                     iContainer->
       
  1254                         SetLbxCurrentItemIndexAndDraw( currentItemCount - 1 );
       
  1255                     }
       
  1256                 }
       
  1257             else if ( iCurrentHighlightedIndex > KErrNotFound &&
       
  1258                 ( iCurrentHighlightedIndex <
       
  1259                 iContainer->CurrentListItemCount() ) )
       
  1260                 {
       
  1261                 if (iContainer->IsInReorderMode())
       
  1262                     {
       
  1263                     iContainer->SetLbxTopItemIndex( topIndex );
       
  1264                     }
       
  1265                 iContainer->
       
  1266                     SetLbxCurrentItemIndexAndDraw( iCurrentHighlightedIndex );
       
  1267                 iCollectionUtility->Collection().CommandL(
       
  1268                     EMcCmdSelect, iCurrentHighlightedIndex );
       
  1269                 iCurrentHighlightedIndex = KErrNotFound;
       
  1270                 }
       
  1271             else if ( ( aIndex > 0 )
       
  1272                 && ( aIndex < iContainer->CurrentListItemCount() ) )
       
  1273                 {
       
  1274 				iContainer->SetLbxCurrentItemIndexAndDraw( aIndex );
       
  1275                 }
       
  1276             else
       
  1277                 {
       
  1278                 iContainer->SetLbxCurrentItemIndexAndDraw( 0 );
       
  1279                 }
       
  1280             }
       
  1281         if (!aComplete || cpath->Levels() == KMusicCollectionMenuLevel || iContainer->IsInReorderMode())
       
  1282             {
       
  1283             iContainer->EnableFindBox(EFalse);
       
  1284             }
       
  1285         else
       
  1286             {
       
  1287             iContainer->EnableFindBox(ETrue);
       
  1288             }
       
  1289 
       
  1290         CleanupStack::PopAndDestroy( cpath );
       
  1291         }
       
  1292     }
       
  1293 
       
  1294 // ---------------------------------------------------------------------------
       
  1295 // Displays error notes.
       
  1296 // ---------------------------------------------------------------------------
       
  1297 //
       
  1298 void CMPXCollectionViewHgImp::HandleError( TInt aError )
       
  1299     {
       
  1300     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleError(%d)", aError );
       
  1301     ASSERT( aError );
       
  1302 
       
  1303     // only display error message if collection view is in the foreground
       
  1304     if ( iContainer )
       
  1305         {
       
  1306         TRAP_IGNORE( iCommonUiHelper->HandleErrorL( aError ) );
       
  1307         }
       
  1308     }
       
  1309 
       
  1310 // ---------------------------------------------------------------------------
       
  1311 // Updates the title pane
       
  1312 // ---------------------------------------------------------------------------
       
  1313 //
       
  1314 void CMPXCollectionViewHgImp::UpdateTitlePaneL()
       
  1315     {
       
  1316     MPX_FUNC( "CMPXCollectionViewHgImp::UpdateTitlePaneL" );
       
  1317     // Set title
       
  1318 
       
  1319     if ( iViewUtility->ActiveViewType() ==
       
  1320         TUid::Uid( KMPXPluginTypeCollectionUid ) ||
       
  1321         ( iViewUtility->ActiveViewType() ==
       
  1322          TUid::Uid( KMPXPluginTypeWaitNoteDialogUid ) && iContainer ) )
       
  1323         {
       
  1324         CAknTitlePane* title( NULL );
       
  1325 
       
  1326         TRAP_IGNORE(
       
  1327             {
       
  1328             title = static_cast<CAknTitlePane*>
       
  1329                 ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
  1330             } );
       
  1331 
       
  1332         if ( title )
       
  1333             {
       
  1334             if ( iTitle )
       
  1335                 {
       
  1336                 title->SetTextL( *iTitle );
       
  1337                 }
       
  1338             }
       
  1339         }
       
  1340     }
       
  1341 
       
  1342 // ---------------------------------------------------------------------------
       
  1343 // Updates playback status indicator
       
  1344 // ---------------------------------------------------------------------------
       
  1345 //
       
  1346 TInt CMPXCollectionViewHgImp::UpdatePlaybackStatusL()
       
  1347     {
       
  1348     MPX_FUNC( "CMPXCollectionViewHgImp::UpdatePlaybackStatusL" );
       
  1349     TInt ret( KErrNotFound );  // default selection
       
  1350     if ( iContainer )
       
  1351         {
       
  1352         TMPXPlaybackState pbState( EPbStateNotInitialised );
       
  1353         TInt selectedIndex( KErrNotFound );
       
  1354         TMPXItemId selectedItemId( KMPXInvalidItemId );
       
  1355         CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  1356         CleanupStack::PushL( cpath );
       
  1357 
       
  1358         MMPXSource* source( iPlaybackUtility->Source() );
       
  1359         if ( source )
       
  1360             {
       
  1361             CMPXCollectionPlaylist* playlist( source->PlaylistL() );
       
  1362             if ( playlist )
       
  1363                 {
       
  1364                 CleanupStack::PushL( playlist );
       
  1365                 CMPXCollectionPath* pbPath(
       
  1366                     CMPXCollectionPath::NewL( playlist->Path() ) );
       
  1367                 CleanupStack::PushL( pbPath );
       
  1368                 TInt playbackPathCount( pbPath->Levels() );
       
  1369                 if ( cpath->Levels() == playbackPathCount )
       
  1370                     {
       
  1371                     // not comparing the index
       
  1372                     TBool isEqual( ETrue );
       
  1373                     for ( TInt i = 0; i < playbackPathCount - 1; i++ )
       
  1374                         {
       
  1375                         if ( cpath->Id( i ) != pbPath->Id( i ) )
       
  1376                             {
       
  1377                             isEqual = EFalse;
       
  1378                             break;
       
  1379                             }
       
  1380                         }
       
  1381                     if ( isEqual )
       
  1382                         {
       
  1383                         selectedIndex = pbPath->Index();
       
  1384                         selectedItemId = pbPath->Id();
       
  1385                         ret = selectedIndex;
       
  1386                         pbState = iPlaybackUtility->StateL();
       
  1387                         }
       
  1388                     }
       
  1389                 CleanupStack::PopAndDestroy( pbPath );
       
  1390                 CleanupStack::PopAndDestroy( playlist );
       
  1391                 }
       
  1392             }
       
  1393         CleanupStack::PopAndDestroy( cpath );
       
  1394         if ( selectedIndex != KErrNotFound )
       
  1395             {
       
  1396             if ( iContainer->IsInReorderMode() )
       
  1397                 {
       
  1398                 // in reorder mode, need to pass unique ID to list box
       
  1399                 // to search for now playing song
       
  1400                 iContainer->SetPlaybackStatusByIdL( selectedItemId, pbState );
       
  1401                 }
       
  1402             else
       
  1403                 {
       
  1404                 // Fixed for EBLI-7AG8ZN, the Playlist in the Engine is updated
       
  1405                 // later than UI (because of Inc Open), so index does not work
       
  1406                 iContainer->SetPlaybackStatusByIdL( selectedItemId, pbState, selectedIndex );
       
  1407                 }
       
  1408             }
       
  1409         }
       
  1410     return ret;
       
  1411     }
       
  1412 
       
  1413 // ---------------------------------------------------------------------------
       
  1414 // Start a refreshing note
       
  1415 // ---------------------------------------------------------------------------
       
  1416 //
       
  1417 void CMPXCollectionViewHgImp::StartWaitNoteL( TWaitNoteType aNoteType )
       
  1418     {
       
  1419     MPX_FUNC( "CMPXCollectionViewHgImp::StartWaitNoteL" );
       
  1420     TUid waitnoteId = TUid::Uid( KMPXPluginTypeWaitNoteDialogUid );
       
  1421     TUid activeView = iViewUtility->ActiveViewType();
       
  1422     if( !iIsEmbedded && activeView != waitnoteId )
       
  1423         {
       
  1424         TPckg<TWaitNoteType> note = aNoteType;
       
  1425         HBufC* arg = MPXUser::AllocL( note );
       
  1426         CleanupStack::PushL( arg );
       
  1427         RProcess proc;
       
  1428         iPriority = proc.Priority();
       
  1429         proc.SetPriority( EPriorityHigh );
       
  1430         iNoteType = aNoteType;
       
  1431         iViewUtility->ActivateViewL( waitnoteId, arg );
       
  1432         CleanupStack::PopAndDestroy( arg );
       
  1433         }
       
  1434     }
       
  1435 
       
  1436 // ---------------------------------------------------------------------------
       
  1437 // Start a Wait note
       
  1438 // ---------------------------------------------------------------------------
       
  1439 //
       
  1440 void CMPXCollectionViewHgImp::StartDeleteWaitNoteL()
       
  1441     {
       
  1442     iWaitDialog = new (ELeave) CAknWaitDialog(
       
  1443         (REINTERPRET_CAST(CEikDialog**, &iWaitDialog)),
       
  1444         ETrue);
       
  1445     iWaitDialog->PrepareLC(R_MPX_WAIT_NOTE);
       
  1446 
       
  1447     iWaitDialog->SetCallback(this);
       
  1448     iWaitDialog->RunLD();
       
  1449     }
       
  1450 
       
  1451 // ---------------------------------------------------------------------------
       
  1452 // Update the Progress note
       
  1453 // ---------------------------------------------------------------------------
       
  1454 //
       
  1455 void CMPXCollectionViewHgImp::UpdateProcessL( const TDesC& aProgressText )
       
  1456     {
       
  1457     if ( iWaitDialog )
       
  1458         {
       
  1459         iWaitDialog->SetTextL(aProgressText);
       
  1460         }
       
  1461     }
       
  1462 
       
  1463 // ---------------------------------------------------------------------------
       
  1464 // Close waitnote dialog
       
  1465 // ---------------------------------------------------------------------------
       
  1466 //
       
  1467 void CMPXCollectionViewHgImp::CloseWaitNoteL()
       
  1468     {
       
  1469     MPX_FUNC( "CMPXCollectionViewHgImp::CloseWaitNoteL" );
       
  1470     if( !iUSBOnGoing && !iIsEmbedded)
       
  1471         {
       
  1472         RProcess proc;
       
  1473         proc.SetPriority( iPriority );
       
  1474         // Fix for ESLU-7CFEPF, try to close the WaitNote even if it's not the current view
       
  1475         TRAP_IGNORE(
       
  1476             CMPXViewPlugin* pi =
       
  1477                 iViewUtility->ViewPluginManager().PluginL( TUid::Uid(KWaitNoteImpUid) );
       
  1478             pi->DeactivateView();
       
  1479             );
       
  1480         }
       
  1481     }
       
  1482 
       
  1483 
       
  1484 // -----------------------------------------------------------------------------
       
  1485 // Change the navi pane
       
  1486 // -----------------------------------------------------------------------------
       
  1487 //
       
  1488 void CMPXCollectionViewHgImp::UpdateReorderNaviPaneL()
       
  1489     {
       
  1490     MPX_FUNC( "CMPXCollectionViewHgImp::UpdateReorderNaviPaneL" );
       
  1491     delete iDuration;
       
  1492     iDuration = NULL;
       
  1493 
       
  1494     // Set playlist counter text to pos/size by default
       
  1495     CArrayFixFlat<TInt>* params =
       
  1496         new ( ELeave ) CArrayFixFlat<TInt>( KMPXReorderNaviPaneGranularity );
       
  1497     CleanupStack::PushL( params );
       
  1498     // Position of selection in index
       
  1499     params->AppendL( iContainer->CurrentLbxItemIndex() + 1 );
       
  1500     // Total Number of items in lbx
       
  1501     params->AppendL( iContainer->TotalListItemCount() );
       
  1502     iDuration = StringLoader::LoadL(
       
  1503         R_MPX_CUI_POSITION_COUNTER_TXT, *params );
       
  1504     CleanupStack::PopAndDestroy( params );
       
  1505     }
       
  1506 
       
  1507 // ---------------------------------------------------------------------------
       
  1508 // Activates reorder mode
       
  1509 // ---------------------------------------------------------------------------
       
  1510 //
       
  1511 void CMPXCollectionViewHgImp::ActivateReorderGrabbedModeL()
       
  1512     {
       
  1513     MPX_FUNC( "CMPXCollectionViewHgImp::ActivateReorderGrabbedModeL" );
       
  1514     iIsGrabbed = ETrue;
       
  1515     TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  1516     iContainer->EnableFindBox( EFalse );
       
  1517     iContainer->SetReorderGrabbedMode( ETrue, currentItem );
       
  1518 	// mark the grabbed item
       
  1519     iContainer->MarkGrabedItemL( currentItem );
       
  1520     if ( !iContainer->IsInReorderMode() )
       
  1521         {
       
  1522         iContainer->UpdateReorderTitleIconL();
       
  1523 
       
  1524         if ( iTitle )
       
  1525             {
       
  1526             delete iOriginalTitle;
       
  1527             iOriginalTitle = NULL;
       
  1528             iOriginalTitle = iTitle->AllocL();
       
  1529             delete iTitle;
       
  1530             iTitle = NULL;
       
  1531             }
       
  1532         iTitle = StringLoader::LoadL( R_QTN_NMP_TITLE_REORDER_LIST );
       
  1533         UpdateTitlePaneL();
       
  1534 
       
  1535         if ( iDuration )
       
  1536             {
       
  1537             delete iOriginalDuration;
       
  1538             iOriginalDuration = NULL;
       
  1539             iOriginalDuration = iDuration->AllocL();
       
  1540             delete iDuration;
       
  1541             iDuration = NULL;
       
  1542             }
       
  1543         iContainer->ActivateReorderMode( ETrue );
       
  1544         SetNewCbaL( R_MPX_CUI_REORDER_CANCEL_CBA );
       
  1545         }
       
  1546     iContainer->SetLbxCurrentItemIndexAndDraw( currentItem );
       
  1547     UpdateReorderNaviPaneL();
       
  1548     }
       
  1549 
       
  1550 // ---------------------------------------------------------------------------
       
  1551 // Deactivates reorder mode
       
  1552 // ---------------------------------------------------------------------------
       
  1553 //
       
  1554 void CMPXCollectionViewHgImp::DeactivateReorderGrabbedModeL( TBool aExit )
       
  1555     {
       
  1556     MPX_FUNC( "CMPXCollectionViewHgImp::DeactivateReorderGrabbedModeL" );
       
  1557     iIsGrabbed = EFalse;
       
  1558     delete iCurrentCba;
       
  1559     iCurrentCba = NULL;
       
  1560 
       
  1561     iContainer->SetReorderGrabbedMode( EFalse );
       
  1562     if ( aExit )
       
  1563         {
       
  1564         CEikButtonGroupContainer* cba = Cba();
       
  1565         if ( cba )
       
  1566             {
       
  1567             cba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  1568             cba->DrawDeferred();
       
  1569 
       
  1570 #ifdef __ENABLE_MSK
       
  1571             // set middle softkey label display
       
  1572             UpdateMiddleSoftKeyDisplayL( R_QTN_MSK_PLAY );
       
  1573 #endif // __ENABLE_MSK
       
  1574 
       
  1575             }
       
  1576 
       
  1577         iContainer->RestoreOriginalTitleIconL();
       
  1578         delete iTitle;
       
  1579         iTitle = NULL;
       
  1580         if ( iOriginalTitle )
       
  1581             {
       
  1582             iTitle = iOriginalTitle->AllocL();
       
  1583             delete iOriginalTitle;
       
  1584             iOriginalTitle = NULL;
       
  1585             }
       
  1586         UpdateTitlePaneL();
       
  1587 
       
  1588         delete iDuration;
       
  1589         iDuration = NULL;
       
  1590         if ( iOriginalDuration )
       
  1591             {
       
  1592             iDuration = iOriginalDuration->AllocL();
       
  1593             delete iOriginalDuration;
       
  1594             iOriginalDuration = NULL;
       
  1595             }
       
  1596         iContainer->ActivateReorderMode( EFalse );
       
  1597         iContainer->EnableFindBox( ETrue );
       
  1598         }
       
  1599     iHandlingKeyEvent = ETrue;
       
  1600     iContainer->HandleLbxItemAdditionPreserveIndexL();
       
  1601     }
       
  1602 
       
  1603 // -----------------------------------------------------------------------------
       
  1604 // Change the button group
       
  1605 // -----------------------------------------------------------------------------
       
  1606 //
       
  1607 void CMPXCollectionViewHgImp::SetNewCbaL( TInt aResId )
       
  1608     {
       
  1609     MPX_FUNC( "CMPXCollectionViewHgImp::SetNewCbaL" );
       
  1610     if ( !iCurrentCba )
       
  1611         {
       
  1612         iCurrentCba = CEikButtonGroupContainer::NewL(
       
  1613             CEikButtonGroupContainer::ECba,
       
  1614             CEikButtonGroupContainer::EHorizontal,
       
  1615             this,
       
  1616             aResId, *iContainer );
       
  1617         }
       
  1618     else
       
  1619         {
       
  1620         iCurrentCba->SetCommandSetL( aResId );
       
  1621         iCurrentCba->DrawDeferred();
       
  1622         }
       
  1623     }
       
  1624 
       
  1625 // -----------------------------------------------------------------------------
       
  1626 // Display the details dialog
       
  1627 // -----------------------------------------------------------------------------
       
  1628 //
       
  1629 void CMPXCollectionViewHgImp::DisplayDetailsDialogL( MDesC16Array& aDataArray,
       
  1630     TInt aDialogResourceId, TInt aTitleResourceId )
       
  1631     {
       
  1632     MPX_FUNC( "CMPXCollectionViewHgImp::DisplayDetailsDialogL" );
       
  1633     CAknSingleHeadingPopupMenuStyleListBox* list =
       
  1634         new ( ELeave ) CAknSingleHeadingPopupMenuStyleListBox;
       
  1635     CleanupStack::PushL( list );
       
  1636     CAknPopupList* popupList = CAknPopupList::NewL(
       
  1637         list, R_AVKON_SOFTKEYS_OK_EMPTY,
       
  1638         AknPopupLayouts::EMenuGraphicHeadingWindow);
       
  1639     CleanupStack::PushL( popupList );
       
  1640     list->ConstructL( popupList, EAknListBoxViewerFlags );
       
  1641     list->CreateScrollBarFrameL( ETrue );
       
  1642     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
  1643         CEikScrollBarFrame::EOff,
       
  1644         CEikScrollBarFrame::EAuto);
       
  1645 
       
  1646     // Enable Marquee
       
  1647     static_cast<CEikFormattedCellListBox*>( list )->ItemDrawer()->ColumnData()->
       
  1648         EnableMarqueeL( ETrue );
       
  1649 
       
  1650     // Retrieve heading array
       
  1651     CDesCArrayFlat* headingsArray(
       
  1652         iCoeEnv->ReadDesCArrayResourceL( aDialogResourceId ) );
       
  1653     CleanupStack::PushL( headingsArray );
       
  1654 
       
  1655     // Item array combines heading array and data array
       
  1656     CDesCArrayFlat* itemArray =
       
  1657         new ( ELeave ) CDesCArrayFlat( headingsArray->Count() );
       
  1658     CleanupStack::PushL( itemArray );
       
  1659 
       
  1660     TInt count = headingsArray->Count();
       
  1661     for ( TInt i = 0; i < count; i++ )
       
  1662         {
       
  1663         HBufC* item = HBufC::NewLC(
       
  1664             headingsArray->MdcaPoint( i ).Length() +
       
  1665             aDataArray.MdcaPoint( i ).Length() +
       
  1666             KMPXDurationDisplayResvLen );
       
  1667 
       
  1668         TPtrC tempPtr1 = headingsArray->MdcaPoint( i );
       
  1669         TPtrC tempPtr2 = aDataArray.MdcaPoint( i );
       
  1670 
       
  1671         item->Des().Format( KMPXCollDetailsItemsFormat,
       
  1672                             &tempPtr1,
       
  1673                             &tempPtr2 );
       
  1674 
       
  1675         itemArray->AppendL( *item );
       
  1676         CleanupStack::PopAndDestroy( item );
       
  1677         }
       
  1678 
       
  1679     CleanupStack::Pop( itemArray );
       
  1680     CleanupStack::PopAndDestroy( headingsArray );
       
  1681 
       
  1682     // Set list items
       
  1683     CTextListBoxModel* model = list->Model();
       
  1684     model->SetOwnershipType( ELbmOwnsItemArray );
       
  1685     model->SetItemTextArray( itemArray );
       
  1686 
       
  1687     // Set title
       
  1688     HBufC* title = StringLoader::LoadLC( aTitleResourceId );
       
  1689     popupList->SetTitleL( *title );
       
  1690     CleanupStack::PopAndDestroy( title );
       
  1691 
       
  1692     // Show popup list
       
  1693     CleanupStack::Pop( popupList );
       
  1694     popupList->ExecuteLD();
       
  1695     CleanupStack::PopAndDestroy( list );
       
  1696     }
       
  1697 
       
  1698 // -----------------------------------------------------------------------------
       
  1699 // Display collection details
       
  1700 // -----------------------------------------------------------------------------
       
  1701 //
       
  1702 void CMPXCollectionViewHgImp::DoShowCollectionDetailsL( const CMPXMedia& aMedia )
       
  1703     {
       
  1704     MPX_FUNC( "CMPXCollectionViewHgImp::ShowCollectionDetailsL" );
       
  1705     CDesCArrayFlat* dataArray =
       
  1706         new ( ELeave ) CDesCArrayFlat( EMPXCollectionDetailsCount );
       
  1707     CleanupStack::PushL( dataArray );
       
  1708 
       
  1709     // number of items
       
  1710     HBufC* dataToAppend = HBufC::NewLC( KMPXMaxBufferLength );
       
  1711     TInt songsCount( 0 );
       
  1712     if ( aMedia.IsSupported( KMPXMediaColDetailNumberOfItems ) )
       
  1713         {
       
  1714         songsCount = aMedia.ValueTObjectL<TInt>( KMPXMediaColDetailNumberOfItems );
       
  1715         }
       
  1716     TPtr ptr( dataToAppend->Des() );
       
  1717     ptr.AppendNum( songsCount );
       
  1718     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
  1719     dataArray->AppendL( ptr );
       
  1720     CleanupStack::PopAndDestroy( dataToAppend );
       
  1721 
       
  1722     // total duration
       
  1723     TInt duration( 0 );
       
  1724     if ( aMedia.IsSupported( KMPXMediaColDetailDuration ) )
       
  1725         {
       
  1726         duration = aMedia.ValueTObjectL<TInt>( KMPXMediaColDetailDuration );
       
  1727         }
       
  1728     if ( duration > 0 )
       
  1729         {
       
  1730         dataToAppend = iCommonUiHelper->DisplayableDurationInTextL( duration/KMilliSecondsToSeconds );
       
  1731         CleanupStack::PushL( dataToAppend );
       
  1732         ptr.Set( dataToAppend->Des() );
       
  1733         AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
  1734         dataArray->AppendL( ptr );
       
  1735         CleanupStack::PopAndDestroy( dataToAppend );
       
  1736         }
       
  1737     else
       
  1738         {
       
  1739         dataArray->AppendL( KNullDesC );
       
  1740         }
       
  1741 
       
  1742 #ifdef RD_MULTIPLE_DRIVE
       
  1743     RFs& fileSession( iCoeEnv->FsSession() );
       
  1744     TDriveList driveList;
       
  1745     TInt driveCount(0);
       
  1746     TInt64 freePhoneMemory(KErrNotFound);
       
  1747     TInt64 freeInternalMemory(KErrNotFound);
       
  1748     TInt64 freeExternalMemory(KErrNotFound);
       
  1749     TVolumeInfo volInfo;
       
  1750 
       
  1751     // Get all visible drives
       
  1752     User::LeaveIfError( DriveInfo::GetUserVisibleDrives(
       
  1753            fileSession, driveList, driveCount ) );
       
  1754     MPX_DEBUG2 ("CMPXCollectionViewHgImp::ShowCollectionDetailsL - driveCount = %d", driveCount);
       
  1755 
       
  1756     for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
  1757         {
       
  1758         if (driveList[driveNum])
       
  1759             {
       
  1760             // Get the volume information
       
  1761             if ( fileSession.Volume( volInfo, driveNum ) == KErrNone )
       
  1762                 {
       
  1763                 // Get the drive status
       
  1764                 TUint driveStatus(0);
       
  1765                 DriveInfo::GetDriveStatus( fileSession, driveNum, driveStatus );
       
  1766 
       
  1767                 // Add up free memory depending on memory location
       
  1768                 if ( driveNum == EDriveC )
       
  1769                     {
       
  1770                     if ( freePhoneMemory == KErrNotFound )
       
  1771                         {
       
  1772                         freePhoneMemory = 0;
       
  1773                         }
       
  1774                     freePhoneMemory += volInfo.iFree;
       
  1775                     }
       
  1776                 else if ( driveStatus & DriveInfo::EDriveInternal )
       
  1777                     {
       
  1778                     if ( freeInternalMemory == KErrNotFound )
       
  1779                         {
       
  1780                         freeInternalMemory = 0;
       
  1781                         }
       
  1782                     freeInternalMemory += volInfo.iFree;
       
  1783                     }
       
  1784                 else if ( driveStatus &
       
  1785                     (DriveInfo::EDriveRemovable | DriveInfo::EDriveRemote) )
       
  1786                     {
       
  1787                     if ( freeExternalMemory == KErrNotFound )
       
  1788                         {
       
  1789                         freeExternalMemory = 0;
       
  1790                         }
       
  1791                     freeExternalMemory += volInfo.iFree;
       
  1792                     }
       
  1793                 }
       
  1794             }
       
  1795         }
       
  1796 
       
  1797     // phone memory free
       
  1798     if ( freePhoneMemory != KErrNotFound )
       
  1799         {
       
  1800         dataToAppend = iCommonUiHelper->UnitConversionL(
       
  1801             freePhoneMemory, ETrue );
       
  1802         ptr.Set(dataToAppend->Des());
       
  1803         AknTextUtils::LanguageSpecificNumberConversion( ptr);
       
  1804         }
       
  1805     else
       
  1806         {
       
  1807         dataToAppend = StringLoader::LoadL(
       
  1808             R_MPX_CUI_COLLECTION_DETAILS_MEMORY_UNAVAILABLE );
       
  1809         ptr.Set(dataToAppend->Des());
       
  1810         }
       
  1811 
       
  1812     CleanupStack::PushL( dataToAppend );
       
  1813     dataArray->AppendL( ptr );
       
  1814     CleanupStack::PopAndDestroy( dataToAppend );
       
  1815 
       
  1816     // internal memory (mass storage) free
       
  1817     if ( freeInternalMemory != KErrNotFound )
       
  1818         {
       
  1819         dataToAppend = iCommonUiHelper->UnitConversionL(
       
  1820             freeInternalMemory, ETrue );
       
  1821         ptr.Set(dataToAppend->Des());
       
  1822         AknTextUtils::LanguageSpecificNumberConversion( ptr);
       
  1823         }
       
  1824     else
       
  1825         {
       
  1826         dataToAppend = StringLoader::LoadL(
       
  1827             R_MPX_CUI_COLLECTION_DETAILS_MEMORY_UNAVAILABLE );
       
  1828         ptr.Set(dataToAppend->Des());
       
  1829         }
       
  1830 
       
  1831     CleanupStack::PushL( dataToAppend );
       
  1832     dataArray->AppendL( ptr );
       
  1833     CleanupStack::PopAndDestroy( dataToAppend );
       
  1834 
       
  1835     // removable/remote (memory card) memory free
       
  1836     if ( freeExternalMemory != KErrNotFound )
       
  1837         {
       
  1838         dataToAppend = iCommonUiHelper->UnitConversionL(
       
  1839             freeExternalMemory, ETrue );
       
  1840         ptr.Set(dataToAppend->Des());
       
  1841         AknTextUtils::LanguageSpecificNumberConversion( ptr);
       
  1842         }
       
  1843     else
       
  1844         {
       
  1845         dataToAppend = StringLoader::LoadL(
       
  1846             R_MPX_CUI_COLLECTION_DETAILS_CARD_UNAVAILABLE_ITEM );
       
  1847         ptr.Set(dataToAppend->Des());
       
  1848         }
       
  1849     CleanupStack::PushL( dataToAppend );
       
  1850     dataArray->AppendL( ptr );
       
  1851     CleanupStack::PopAndDestroy( dataToAppend );
       
  1852 #else
       
  1853     // phone memory free
       
  1854     HBufC* driveLetter = StringLoader::LoadLC( R_MPX_COLLECTION_PHONE_MEMORY_ROOT_PATH );
       
  1855     RFs& fileSession( iCoeEnv->FsSession() );
       
  1856     TVolumeInfo volInfo;
       
  1857     TDriveUnit driveUnit( *driveLetter ); // Get the drive
       
  1858     CleanupStack::PopAndDestroy( driveLetter );
       
  1859     if ( KErrNone == fileSession.Volume( volInfo, ( TInt )driveUnit ) )
       
  1860         {
       
  1861         dataToAppend = iCommonUiHelper->UnitConversionL( volInfo.iFree, ETrue );
       
  1862         ptr.Set(dataToAppend->Des());
       
  1863         AknTextUtils::LanguageSpecificNumberConversion( ptr);
       
  1864         }
       
  1865     else
       
  1866         {
       
  1867         dataToAppend = StringLoader::LoadL(
       
  1868             R_MPX_CUI_COLLECTION_DETAILS_CARD_UNAVAILABLE_ITEM );
       
  1869         ptr.Set(dataToAppend->Des());
       
  1870         }
       
  1871     CleanupStack::PushL( dataToAppend );
       
  1872     dataArray->AppendL( ptr );
       
  1873     CleanupStack::PopAndDestroy( dataToAppend );
       
  1874 
       
  1875     // memory card
       
  1876     driveLetter = StringLoader::LoadLC( R_MPX_COLLECTION_MEMORY_CARD_ROOT_PATH );
       
  1877     driveUnit = *driveLetter; // Get the drive
       
  1878     CleanupStack::PopAndDestroy( driveLetter );
       
  1879     if ( fileSession.Volume( volInfo, ( TInt )driveUnit ) == KErrNone )
       
  1880         {
       
  1881         dataToAppend = iCommonUiHelper->UnitConversionL( volInfo.iFree, ETrue );
       
  1882         ptr.Set(dataToAppend->Des());
       
  1883         AknTextUtils::LanguageSpecificNumberConversion( ptr);
       
  1884         }
       
  1885     else
       
  1886         {
       
  1887         dataToAppend = StringLoader::LoadL(
       
  1888             R_MPX_CUI_COLLECTION_DETAILS_CARD_UNAVAILABLE_ITEM );
       
  1889         ptr.Set(dataToAppend->Des());
       
  1890         }
       
  1891     CleanupStack::PushL( dataToAppend );
       
  1892     dataArray->AppendL( ptr );
       
  1893     CleanupStack::PopAndDestroy( dataToAppend );
       
  1894 #endif // RD_MULTIPLE_DRIVE
       
  1895 
       
  1896     // last refreshed
       
  1897     TInt64 lastRefreshed( 0 );
       
  1898     if ( aMedia.IsSupported( KMPXMediaColDetailLastRefreshed ) )
       
  1899         {
       
  1900         lastRefreshed = aMedia.ValueTObjectL<TInt64>( KMPXMediaColDetailLastRefreshed );
       
  1901         }
       
  1902     TTime time( lastRefreshed );
       
  1903     dataToAppend = HBufC::NewLC(
       
  1904         KMPXMaxTimeLength + KMPXDurationDisplayResvLen );
       
  1905     HBufC* format( StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ) );
       
  1906     TPtr modDatePtr( dataToAppend->Des() );
       
  1907     time.FormatL( modDatePtr, *format );
       
  1908     CleanupStack::PopAndDestroy( format );
       
  1909     AknTextUtils::LanguageSpecificNumberConversion( modDatePtr );
       
  1910     dataArray->AppendL( modDatePtr );
       
  1911     CleanupStack::PopAndDestroy( dataToAppend );
       
  1912 
       
  1913     DisplayDetailsDialogL( *dataArray,
       
  1914         R_MPX_CUI_COLLECTION_DETAILS_HEADINGS,
       
  1915         R_MPX_QTN_NMP_TITLE_COLLECTION_DETAILS );
       
  1916     CleanupStack::PopAndDestroy( dataArray );
       
  1917     }
       
  1918 
       
  1919 // -----------------------------------------------------------------------------
       
  1920 // Display playlist details
       
  1921 // -----------------------------------------------------------------------------
       
  1922 //
       
  1923 void CMPXCollectionViewHgImp::DoShowPlaylistDetailsL( const CMPXMedia& aMedia )
       
  1924     {
       
  1925     MPX_FUNC( "CMPXCollectionViewHgImp::ShowPlaylistDetailsL" );
       
  1926     CDesCArrayFlat* dataArray =
       
  1927         new ( ELeave ) CDesCArrayFlat( EMPXPlaylistDetailsCount );
       
  1928     CleanupStack::PushL( dataArray );
       
  1929 
       
  1930     // playlist name
       
  1931     if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) )
       
  1932         {
       
  1933         dataArray->AppendL( aMedia.ValueText( KMPXMediaGeneralTitle ) );
       
  1934         }
       
  1935     else if ( aMedia.IsSupported( KMPXMediaGeneralUri ) )
       
  1936         {
       
  1937         TParsePtrC fileDetail( aMedia.ValueText( KMPXMediaGeneralUri ) );
       
  1938         dataArray->AppendL( fileDetail.Name() );
       
  1939         }
       
  1940     else
       
  1941         {
       
  1942         dataArray->AppendL( KNullDesC );
       
  1943         }
       
  1944 
       
  1945     // number of songs
       
  1946     TInt songsCount( 0 );
       
  1947     if ( aMedia.IsSupported( KMPXMediaGeneralCount ) )
       
  1948         {
       
  1949         songsCount = aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralCount );
       
  1950         }
       
  1951     HBufC* dataToAppend = HBufC::NewLC( KMPXMaxBufferLength );
       
  1952     TPtr ptr( dataToAppend->Des() );
       
  1953     ptr.AppendNum( songsCount );
       
  1954     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
  1955     dataArray->AppendL( ptr );
       
  1956     CleanupStack::PopAndDestroy( dataToAppend );
       
  1957 
       
  1958     // Duration
       
  1959     TInt duration( 0 );
       
  1960     if ( aMedia.IsSupported( KMPXMediaGeneralDuration ) )
       
  1961         {
       
  1962         duration = aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralDuration );
       
  1963         }
       
  1964     if ( duration > 0 )
       
  1965         {
       
  1966         dataToAppend = iCommonUiHelper->DisplayableDurationInTextL( duration/KMilliSecondsToSeconds );
       
  1967         CleanupStack::PushL( dataToAppend );
       
  1968         ptr.Set( dataToAppend->Des() );
       
  1969         AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
  1970         dataArray->AppendL( ptr );
       
  1971         CleanupStack::PopAndDestroy( dataToAppend );
       
  1972         }
       
  1973     else
       
  1974         {
       
  1975         dataArray->AppendL( KNullDesC );
       
  1976         }
       
  1977 
       
  1978     // Location
       
  1979     TUint flags( aMedia.ValueTObjectL<TUint>( KMPXMediaGeneralFlags ) );
       
  1980     TUint isVirtual( ( flags ) & ( KMPXMediaGeneralFlagsIsVirtual ) );
       
  1981     if ( !isVirtual )
       
  1982         {
       
  1983         if ( aMedia.IsSupported( KMPXMediaGeneralUri ) )
       
  1984             {
       
  1985             dataArray->AppendL( aMedia.ValueText( KMPXMediaGeneralUri ) );
       
  1986             }
       
  1987         else
       
  1988             {
       
  1989             dataArray->AppendL( KNullDesC );
       
  1990             }
       
  1991         }
       
  1992 
       
  1993     // last refreshed
       
  1994     TInt64 lastMod( 0 );
       
  1995     if ( aMedia.IsSupported( KMPXMediaGeneralDate ) )
       
  1996         {
       
  1997         lastMod = aMedia.ValueTObjectL<TInt64>( KMPXMediaGeneralDate );
       
  1998         }
       
  1999     TTime time( lastMod );
       
  2000     dataToAppend = HBufC::NewLC(
       
  2001         KMPXMaxTimeLength + KMPXDurationDisplayResvLen );
       
  2002     HBufC* format = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
  2003     ptr.Set( dataToAppend->Des() );
       
  2004     time.FormatL( ptr, *format );
       
  2005     CleanupStack::PopAndDestroy( format );
       
  2006     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
  2007     dataArray->AppendL( ptr );
       
  2008     CleanupStack::PopAndDestroy( dataToAppend );
       
  2009 
       
  2010     dataToAppend = HBufC::NewLC(
       
  2011         KMPXMaxTimeLength + KMPXDurationDisplayResvLen );
       
  2012     format = StringLoader::LoadLC( R_QTN_TIME_USUAL );
       
  2013     ptr.Set( dataToAppend->Des() );
       
  2014     time.FormatL( ptr, *format );
       
  2015     CleanupStack::PopAndDestroy( format );
       
  2016     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
  2017     dataArray->AppendL( ptr );
       
  2018     CleanupStack::PopAndDestroy( dataToAppend );
       
  2019 
       
  2020     TInt headingResource( isVirtual ?
       
  2021         R_MPX_CUI_PLAYLIST_DETAILS_HEADINGS_WITHOUT_URI :
       
  2022         R_MPX_CUI_PLAYLIST_DETAILS_HEADINGS_WITH_URI );
       
  2023     DisplayDetailsDialogL( *dataArray, headingResource,
       
  2024         R_MPX_QTN_NMP_TITLE_PLAYLIST_DETAILS );
       
  2025     CleanupStack::PopAndDestroy( dataArray );
       
  2026     }
       
  2027 
       
  2028 
       
  2029 // ---------------------------------------------------------------------------
       
  2030 // Handles Upnp menus from DynInitMenuPaneL()
       
  2031 // ---------------------------------------------------------------------------
       
  2032 //
       
  2033 void CMPXCollectionViewHgImp::HandleDynInitUpnpL(
       
  2034     TInt aResourceId,
       
  2035     CEikMenuPane& aMenuPane )
       
  2036     {
       
  2037     MPX_FUNC( "CMPXCollectionViewHgImp::HandleDynInitUpnpL()" );
       
  2038 
       
  2039     if ( !IsUpnpVisibleL() )
       
  2040         {
       
  2041         GetCurrentPlayerDetails();
       
  2042 
       
  2043         if ( iCurrentPlayerType == EPbLocal )
       
  2044             {
       
  2045             aMenuPane.SetItemDimmed(
       
  2046                 EMPXCmdUpnpPlayVia,
       
  2047                 ETrue);
       
  2048             }
       
  2049         aMenuPane.SetItemDimmed(
       
  2050             EMPXCmdUPnPAiwCmdCopyToExternalCriteria,
       
  2051             ETrue);
       
  2052         }
       
  2053     else
       
  2054         {
       
  2055         MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleDynInitUpnpL(): UPnP visible and media" );
       
  2056         TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  2057 
       
  2058         const CMPXMedia& media =
       
  2059             (iContainer->ListBoxArray())->MediaL( currentItem );
       
  2060         TMPXGeneralType type( EMPXNoType );
       
  2061         if (media.IsSupported(KMPXMediaGeneralType))
       
  2062             {
       
  2063             type =
       
  2064                 media.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType);
       
  2065             }
       
  2066 
       
  2067         if ( ( type == EMPXItem ) ||
       
  2068              ( type == EMPXGroup ) )
       
  2069             {
       
  2070             MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleDynInitUpnpL(): folder or song" );
       
  2071             if ( iErrorAttachCopyMenu != KErrNone )
       
  2072                 {
       
  2073                 MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleDynInitUpnpL(): error, Dim Copy" );
       
  2074                 aMenuPane.SetItemDimmed(
       
  2075                     EMPXCmdUPnPAiwCmdCopyToExternalCriteria,
       
  2076                     ETrue);
       
  2077                 }
       
  2078             else
       
  2079                 {
       
  2080                 if (iServiceHandler->HandleSubmenuL(aMenuPane))
       
  2081                     {
       
  2082                     return;
       
  2083                     }
       
  2084 
       
  2085                 if ( iServiceHandler->IsAiwMenu(aResourceId))
       
  2086                     {
       
  2087                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleDynInitUpnpL(): Aiw menu" );
       
  2088                     CAiwGenericParamList& in = iServiceHandler->InParamListL();
       
  2089 
       
  2090                     iServiceHandler->InitializeMenuPaneL(aMenuPane, aResourceId, EMPXCmdUPnPAiwCmdCopyToExternalCriteria, in);
       
  2091                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleDynInitUpnpL(): after InitializeMenuPaneL" );
       
  2092                     }
       
  2093                 }
       
  2094             }
       
  2095          else
       
  2096             {
       
  2097             aMenuPane.SetItemDimmed(
       
  2098                 EMPXCmdUpnpPlayVia,
       
  2099                 ETrue);
       
  2100             aMenuPane.SetItemDimmed(
       
  2101                 EMPXCmdUPnPAiwCmdCopyToExternalCriteria,
       
  2102                 ETrue);
       
  2103             }
       
  2104         }
       
  2105     }
       
  2106 
       
  2107 // -----------------------------------------------------------------------------
       
  2108 // CMPXCollectionViewHgImp::IsUpnpVisible
       
  2109 // Checks if UPnP access point is defined
       
  2110 // -----------------------------------------------------------------------------
       
  2111 //
       
  2112 TBool CMPXCollectionViewHgImp::IsUpnpVisibleL()
       
  2113     {
       
  2114     MPX_FUNC( "CMPXCollectionViewHgImp::IsUpnpVisibleL" );
       
  2115  	  TBool returnValue = EFalse;
       
  2116 
       
  2117    	if ( iUpnpCopyCommand  && iUpnpFrameworkSupport)
       
  2118         {
       
  2119         returnValue = iUpnpCopyCommand->IsAvailableL();
       
  2120         }
       
  2121     return returnValue;
       
  2122     }
       
  2123 
       
  2124 // -----------------------------------------------------------------------------
       
  2125 // CMPXCollectionViewHgImp::AddPlayersNamesToMenuL
       
  2126 // Taken from Gallery upnp support implementation
       
  2127 // -----------------------------------------------------------------------------
       
  2128 //
       
  2129 void CMPXCollectionViewHgImp::AddPlayersNamesToMenuL( CEikMenuPane& aMenuPane )
       
  2130     {
       
  2131     RArray<TMPXPlaybackPlayerType> playerTypes;
       
  2132     CleanupClosePushL(playerTypes);
       
  2133 
       
  2134     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  2135     manager.GetPlayerTypesL(playerTypes);
       
  2136 
       
  2137     GetCurrentPlayerDetails();
       
  2138 
       
  2139     TInt countPlayersTypes( playerTypes.Count() );
       
  2140     TInt countLocalType(0);
       
  2141     TInt countRemoteType(0);
       
  2142 
       
  2143     if ( countPlayersTypes >= 1 )
       
  2144         {
       
  2145         iPlayersList.Close();
       
  2146 
       
  2147         for ( TInt i = 0; i < countPlayersTypes; i++ )
       
  2148             {
       
  2149             MPX_DEBUG3( "playerTypes[%d]: %d", i, playerTypes[i] );
       
  2150             switch (playerTypes[i])
       
  2151                 {
       
  2152                 case EPbLocal:
       
  2153                     {
       
  2154                     // we only show 1 specific type once in the menu
       
  2155                     if ( countLocalType == 0 )
       
  2156                         {
       
  2157                         AddPlayerNameToMenuL( aMenuPane,
       
  2158                                             EMPXCmdUpnpPlayViaLocal,
       
  2159                                             manager,
       
  2160                                             playerTypes[i] );
       
  2161 
       
  2162                         countLocalType++;
       
  2163                         }
       
  2164                     break;
       
  2165                     }
       
  2166                 case EPbRemote:
       
  2167                     {
       
  2168                     // we only show 1 specific type once in the menu
       
  2169                     if ( countRemoteType == 0 )
       
  2170                         {
       
  2171                         AddPlayerNameToMenuL( aMenuPane,
       
  2172                                             EMPXCmdUpnpPlayViaRemotePlayer,
       
  2173                                             manager,
       
  2174                                             playerTypes[i] );
       
  2175                         countRemoteType++;
       
  2176                         }
       
  2177                     break;
       
  2178                     }
       
  2179                 default:
       
  2180                     {
       
  2181                     // default case is handled in the next loop, we want
       
  2182                     // to add any "other" player at the end of the list
       
  2183                     break;
       
  2184                     }
       
  2185                 }
       
  2186             } // for loop
       
  2187 
       
  2188         for ( TInt i = 0; i < countPlayersTypes; i++ )
       
  2189             {
       
  2190             MPX_DEBUG3( "playerTypes[%d]: %d", i, playerTypes[i] );
       
  2191             // EPbLocal and EPbRemote were already added to the
       
  2192             // submenu in the previous loop
       
  2193             if ( playerTypes[i] != EPbLocal &&
       
  2194                  playerTypes[i] != EPbRemote )
       
  2195                 {
       
  2196                 // EPbUnknown or else
       
  2197                 TBool alreadyInTheList( EFalse );
       
  2198 
       
  2199                 for ( TInt j = 0; j < i; j++)
       
  2200                     {
       
  2201                     // if the new playertype is already in the list
       
  2202                     if ( playerTypes[i] == playerTypes[j] )
       
  2203                         {
       
  2204                         alreadyInTheList = ETrue;
       
  2205                         break;
       
  2206                         }
       
  2207                     }
       
  2208 
       
  2209                 if ( !alreadyInTheList )
       
  2210                     {
       
  2211                     HBufC* buf = manager.PlayerTypeDisplayNameL(playerTypes[i]);
       
  2212 
       
  2213                     if ( buf )
       
  2214                         {
       
  2215                         CleanupStack::PushL(buf);
       
  2216                         AddPlayerNameToMenuL( aMenuPane,
       
  2217                                             EMPXCmdUpnpPlayViaRemotePlayer,
       
  2218                                             manager,
       
  2219                                             playerTypes[i],
       
  2220                                             *buf );
       
  2221                         CleanupStack::PopAndDestroy(buf);
       
  2222                         }
       
  2223                     // else we don't do anything. other player type is not
       
  2224                     // currently supported. Implementation will be finalized
       
  2225                     // when the requirement is defined.
       
  2226                     }
       
  2227                 }
       
  2228             }
       
  2229         }
       
  2230 
       
  2231     CleanupStack::PopAndDestroy(&playerTypes);
       
  2232 
       
  2233     if ( iPlayersList.Count() <= 1 )
       
  2234         {
       
  2235         aMenuPane.SetItemDimmed( EMPXCmdUpnpPlayViaRemotePlayer,
       
  2236                                   ETrue );
       
  2237         }
       
  2238     }
       
  2239 
       
  2240 // -----------------------------------------------------------------------------
       
  2241 // CMPXCollectionViewHgImp::AddPlayerNameToMenuL
       
  2242 // Taken from Gallery upnp support implementation
       
  2243 // -----------------------------------------------------------------------------
       
  2244 //
       
  2245 void CMPXCollectionViewHgImp::AddPlayerNameToMenuL( CEikMenuPane& aMenuPane,
       
  2246                                                 TInt aCommandId,
       
  2247                                                 MMPXPlayerManager& aPlayerManager,
       
  2248                                                 TMPXPlaybackPlayerType& aPlayerType,
       
  2249                                                 const TDesC& aMenuText )
       
  2250     {
       
  2251     RArray<TUid> players;
       
  2252     CleanupClosePushL(players);
       
  2253     aPlayerManager.GetPlayerListL(players, aPlayerType);
       
  2254 
       
  2255     // For now we only keep the first player we find
       
  2256     // Local player is always the first one in the list
       
  2257     // Ui spec limitation
       
  2258     MPX_DEBUG2( "players[0]: %d", players[0].iUid );
       
  2259     if ( aCommandId == EMPXCmdUpnpPlayViaLocal )
       
  2260         {
       
  2261         iPlayersList.Insert(players[0], 0);
       
  2262         }
       
  2263     else if ( ( aCommandId == EMPXCmdUpnpPlayViaRemotePlayer ) &&
       
  2264               (iPlayersList.Count() > 1) )
       
  2265         {
       
  2266         iPlayersList.Insert(players[0], 1);
       
  2267         }
       
  2268     else
       
  2269         {
       
  2270         iPlayersList.AppendL(players[0]);
       
  2271         }
       
  2272     CleanupStack::PopAndDestroy(&players);
       
  2273 
       
  2274     // if the player is of unknown type
       
  2275     if ( ( aCommandId != EMPXCmdUpnpPlayViaRemotePlayer ) &&
       
  2276          ( aCommandId != EMPXCmdUpnpPlayViaLocal ) )
       
  2277         {
       
  2278         CEikMenuPaneItem::SData menuItem;
       
  2279         menuItem.iText.Copy( aMenuText );
       
  2280         menuItem.iCascadeId = 0;
       
  2281         menuItem.iFlags = EEikMenuItemRadioEnd;
       
  2282 
       
  2283         menuItem.iCommandId = aCommandId + (iPlayersList.Count() - 1);
       
  2284         aCommandId = menuItem.iCommandId;
       
  2285 
       
  2286         aMenuPane.AddMenuItemL( menuItem );
       
  2287         }
       
  2288 
       
  2289     if ( iCurrentPlayerType == aPlayerType )
       
  2290         {
       
  2291         aMenuPane.SetItemButtonState( aCommandId, EEikMenuItemSymbolOn );
       
  2292         }
       
  2293     }
       
  2294 
       
  2295 // -----------------------------------------------------------------------------
       
  2296 // CMPXCollectionViewHgImp::GetCurrentPlayerDetails
       
  2297 // Retrieves the current player name and type
       
  2298 // -----------------------------------------------------------------------------
       
  2299 //
       
  2300 void CMPXCollectionViewHgImp::GetCurrentPlayerDetails()
       
  2301     {
       
  2302     MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  2303     TUid currentlyUsedPlayer;
       
  2304     TInt currentlyUsedSubPlayer;
       
  2305     iCurrentPlayerType = EPbLocal;
       
  2306     delete iSubPlayerName;
       
  2307     iSubPlayerName = NULL;
       
  2308     TRAP_IGNORE( manager.GetSelectionL( iCurrentPlayerType,
       
  2309                                         currentlyUsedPlayer,
       
  2310                                         currentlyUsedSubPlayer,
       
  2311                                         iSubPlayerName));
       
  2312     }
       
  2313 
       
  2314 // -----------------------------------------------------------------------------
       
  2315 // CMPXCollectionViewHgImp::SelectNewPlayerL
       
  2316 // Selects a new player for audio playback
       
  2317 // -----------------------------------------------------------------------------
       
  2318 //
       
  2319 void CMPXCollectionViewHgImp::SelectNewPlayerL( TInt aCommand )
       
  2320     {
       
  2321     MPX_FUNC( "CMPXCollectionViewHgImp::SelectNewPlayerL()" );
       
  2322     MPX_DEBUG2( "CMPXCollectionViewHgImp::SelectNewPlayerL(%d)", aCommand );
       
  2323 
       
  2324     TInt errorSelectPlayer( KErrCancel );
       
  2325 
       
  2326     switch (aCommand)
       
  2327         {
       
  2328         case EMPXCmdUpnpPlayViaLocal:
       
  2329             {
       
  2330             // if Local is not already the current player, select it
       
  2331             if ( iCurrentPlayerType != EPbLocal )
       
  2332                 {
       
  2333                 MMPXPlayerManager& manager = iPlaybackUtility->PlayerManager();
       
  2334                 MPX_TRAP( errorSelectPlayer, manager.ClearSelectPlayersL() );
       
  2335                 }
       
  2336             else // no need to reselect it but always start playback
       
  2337                 {
       
  2338                 errorSelectPlayer = KErrNone;
       
  2339                 }
       
  2340             break;
       
  2341             }
       
  2342         default:
       
  2343             {
       
  2344             if ( aCommand >= EMPXCmdUpnpPlayViaRemotePlayer )
       
  2345                 {
       
  2346                 HBufC* buf = HBufC::NewLC( KMaxUidName );
       
  2347                 buf->Des().AppendNum(
       
  2348                      (iPlayersList[aCommand -
       
  2349                                    EMPXCmdUpnpPlayViaLocal]).iUid );
       
  2350 
       
  2351                 // ActivateViewL leaves with KErrCancel if the dialog is
       
  2352                 // cancelled
       
  2353                 // ActivateViewL leaves with KErrInUse if the selected player
       
  2354                 // is already the active player
       
  2355                 MPX_TRAP(errorSelectPlayer, iViewUtility->ActivateViewL(
       
  2356                                 TUid::Uid( KMPXPluginTypeUPnPBrowseDialogUid ),
       
  2357                                 buf ));
       
  2358                 CleanupStack::PopAndDestroy( buf );
       
  2359                 }
       
  2360             break;
       
  2361             }
       
  2362         }
       
  2363 
       
  2364     GetCurrentPlayerDetails();
       
  2365 
       
  2366     // If InUse, the player selected is already the current one, we start playback anyway
       
  2367     // contrary to Playback view
       
  2368     if ( ( errorSelectPlayer == KErrNone ) ||
       
  2369          ( errorSelectPlayer == KErrInUse ) )
       
  2370         {
       
  2371         // Starts playback by calling OpenL() for the selected track
       
  2372         CMPXCommonListBoxArrayBase* array = iContainer->ListBoxArray();
       
  2373         if ( array && ( iContainer->TotalListItemCount() > 0 ) )
       
  2374             {
       
  2375             MPX_DEBUG1( "CMPXCollectionViewHgImp::SelectNewPlayerL() before MediaL()" );
       
  2376 
       
  2377             TInt currentListBoxItemIndex(
       
  2378                 iContainer->CurrentLbxItemIndex() );
       
  2379 
       
  2380             if ( currentListBoxItemIndex >= 0 )
       
  2381                 {
       
  2382                 const CMPXMedia& media = array->MediaL( currentListBoxItemIndex );
       
  2383 
       
  2384                 TMPXGeneralType type( EMPXNoType );
       
  2385                 TMPXGeneralCategory category( EMPXNoCategory );
       
  2386 
       
  2387                 if ( media.IsSupported( KMPXMediaGeneralType ) )
       
  2388                     {
       
  2389                     type = media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType );
       
  2390                     }
       
  2391 
       
  2392                 if ( media.IsSupported( KMPXMediaGeneralCategory ) )
       
  2393                     {
       
  2394                     category = media.ValueTObjectL<TMPXGeneralCategory>(
       
  2395                                     KMPXMediaGeneralCategory );
       
  2396                     }
       
  2397 
       
  2398                 MPX_DEBUG2( "CMPXCollectionViewHgImp::SelectNewPlayerL() currentIndex %d", currentListBoxItemIndex );
       
  2399 
       
  2400                 // Needed to reset the status of iPreservedState
       
  2401                 iPlaybackUtility->CommandL(EPbCmdResetPreserveState);
       
  2402 
       
  2403                 if ( ( type == EMPXItem ) && ( category == EMPXSong ) )
       
  2404                     {
       
  2405                     MPX_DEBUG1( "CMPXCollectionViewHgImp::SelectNewPlayerL() type is EMPXItem" );
       
  2406                     if(iCollectionCacheReady)
       
  2407                         {
       
  2408                         iCollectionUtility->Collection().OpenL( currentListBoxItemIndex );
       
  2409 						iFirstIncrementalBatch = ETrue;
       
  2410                         }
       
  2411                     }
       
  2412                 else if ( ( type == EMPXItem ) && ( category == EMPXPlaylist ) )
       
  2413                     {
       
  2414                     MPX_DEBUG1( "CMPXCollectionViewHgImp::SelectNewPlayerL() category is EMPXPlaylist" );
       
  2415                     // if we want to play a playlist, we need to find out
       
  2416                     // if it's empty first
       
  2417                     ASSERT( iCurrentFindAllLOp == EMPXOpFindAllLIdle );
       
  2418 
       
  2419                     TMPXItemId id(
       
  2420                         media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  2421                     CMPXMedia* entry = CMPXMedia::NewL();
       
  2422                     CleanupStack::PushL( entry );
       
  2423                     entry->SetTObjectValueL<TMPXGeneralType>(
       
  2424                         KMPXMediaGeneralType, EMPXGroup );
       
  2425                     entry->SetTObjectValueL<TMPXGeneralCategory>(
       
  2426                         KMPXMediaGeneralCategory, EMPXSong );
       
  2427                     entry->SetTObjectValueL<TMPXItemId>(
       
  2428                         KMPXMediaGeneralId, id );
       
  2429                     RArray<TMPXAttribute> attrs;
       
  2430                     CleanupClosePushL( attrs );
       
  2431                     attrs.Append( KMPXMediaGeneralId );
       
  2432                     iCollectionUtility->Collection().FindAllL(
       
  2433                                             *entry, attrs.Array(), *this );
       
  2434                     iCurrentFindAllLOp = EMPXOpFindAllLUpnpPlayback;
       
  2435 
       
  2436                     CleanupStack::PopAndDestroy( &attrs );
       
  2437                     CleanupStack::PopAndDestroy( entry );
       
  2438                     }
       
  2439                 else // if a folder is selected
       
  2440                     {
       
  2441                     MPX_DEBUG1( "CMPXCollectionViewHgImp::SelectNewPlayerL() type is EMPXGroup" );
       
  2442                     if(iCollectionCacheReady)
       
  2443                         {
       
  2444                         iCollectionUtility->Collection().OpenL( currentListBoxItemIndex,
       
  2445                                                             EMPXOpenPlaylistOnly);
       
  2446 						iFirstIncrementalBatch = ETrue;
       
  2447                         }
       
  2448                     }
       
  2449                 }
       
  2450             }
       
  2451         }
       
  2452     else if ( errorSelectPlayer != KErrCancel )
       
  2453         {
       
  2454         User::LeaveIfError(errorSelectPlayer);
       
  2455         }
       
  2456     }
       
  2457 
       
  2458 // -----------------------------------------------------------------------------
       
  2459 // CMPXCollectionViewHgImp::CopySelectedItemsToRemoteL
       
  2460 // Copies selected file(s) to remote player
       
  2461 // -----------------------------------------------------------------------------
       
  2462 //
       
  2463 void CMPXCollectionViewHgImp::CopySelectedItemsToRemoteL()
       
  2464     {
       
  2465     MPX_FUNC( "CMPXCollectionViewHgImp::CopySelectedItemsToRemoteL()" );
       
  2466 
       
  2467     TInt index( iContainer->CurrentLbxItemIndex() );
       
  2468     if ( index >= 0 )
       
  2469         {
       
  2470         CMPXCommonListBoxArrayBase* array = iContainer->ListBoxArray();
       
  2471         const CMPXMedia& media = array->MediaL( index );
       
  2472 
       
  2473         TMPXGeneralType type( EMPXNoType );
       
  2474         TMPXGeneralCategory category( EMPXNoCategory );
       
  2475 
       
  2476        if ( media.IsSupported( KMPXMediaGeneralType ) )
       
  2477             {
       
  2478             type =
       
  2479                 media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType );
       
  2480             }
       
  2481         if ( media.IsSupported( KMPXMediaGeneralCategory ) )
       
  2482             {
       
  2483             category =
       
  2484                 media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
  2485             }
       
  2486 
       
  2487         CMPXCollectionPath* cpath =
       
  2488                               iCollectionUtility->Collection().PathL();
       
  2489         CleanupStack::PushL( cpath );
       
  2490 
       
  2491         if ( ( type == EMPXItem ) && ( category == EMPXSong ) )
       
  2492             {
       
  2493             const CArrayFix<TInt>* arrayIndex =
       
  2494                 iContainer->CurrentSelectionIndicesL();
       
  2495             TInt arrayCount( arrayIndex->Count() );
       
  2496 
       
  2497             cpath->ClearSelection();
       
  2498             if ( arrayCount > 0 )
       
  2499                 {
       
  2500                 for (TInt index=0; index < arrayCount; index++)
       
  2501                     {
       
  2502                     cpath->SelectL(arrayIndex->At(index));
       
  2503                     }
       
  2504                 }
       
  2505             else
       
  2506                 {
       
  2507                 cpath->Set( index );
       
  2508                 }
       
  2509 
       
  2510             // Ask for the list of selected song paths: will return in HandleMedia()
       
  2511             ASSERT( iCurrentMediaLOp == EMPXOpMediaLIdle );
       
  2512             RArray<TMPXAttribute> attrs;
       
  2513             CleanupClosePushL(attrs);
       
  2514             attrs.Append( KMPXMediaGeneralUri );
       
  2515             iCollectionUtility->Collection().MediaL( *cpath, attrs.Array() );
       
  2516             iCurrentMediaLOp = EMPXOpMediaLCopyToRemote;
       
  2517             CleanupStack::PopAndDestroy( &attrs );
       
  2518             }
       
  2519         else // if a folder is selected
       
  2520             {
       
  2521             TMPXItemId id(0);
       
  2522             if ( media.IsSupported( KMPXMediaGeneralId ) )
       
  2523                 {
       
  2524                 id = media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
  2525                 }
       
  2526 
       
  2527             RArray<TInt> supportedIds;
       
  2528             CleanupClosePushL(supportedIds);
       
  2529             supportedIds.AppendL(KMPXMediaIdGeneral);
       
  2530 
       
  2531             CMPXMedia* entry = CMPXMedia::NewL(supportedIds.Array());
       
  2532             CleanupStack::PushL(entry);
       
  2533             entry->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup );
       
  2534 
       
  2535             entry->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong );
       
  2536 
       
  2537             entry->SetTObjectValueL( KMPXMediaGeneralId, id );
       
  2538 
       
  2539             if ( category == EMPXAlbum )
       
  2540                 {
       
  2541                 const CMPXMedia& containerMedia = array->ContainerMedia();
       
  2542                 TMPXGeneralCategory containerCategory( EMPXNoCategory );
       
  2543                 if ( containerMedia.IsSupported( KMPXMediaGeneralCategory ) )
       
  2544                     {
       
  2545                     containerCategory = containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
  2546                                                 KMPXMediaGeneralCategory );
       
  2547                     }
       
  2548 
       
  2549                 if ( containerCategory == EMPXArtist )
       
  2550                     {
       
  2551                     // artist/album level, need to specify artist ID in container ID
       
  2552                     TMPXItemId containerId =
       
  2553                         containerMedia.ValueTObjectL<TMPXItemId>(
       
  2554                             KMPXMediaGeneralId );
       
  2555                     entry->SetTObjectValueL<TMPXItemId>(
       
  2556                         KMPXMediaGeneralContainerId, containerId );
       
  2557                     }
       
  2558                 }
       
  2559 
       
  2560             RArray<TMPXAttribute> attrs;
       
  2561             CleanupClosePushL(attrs);
       
  2562             attrs.Append( KMPXMediaGeneralUri );
       
  2563 
       
  2564             ASSERT( iCurrentFindAllLOp == EMPXOpFindAllLIdle );
       
  2565             iCollectionUtility->Collection().FindAllL( *entry,
       
  2566                                                        attrs.Array(),
       
  2567                                                        *this );
       
  2568             iCurrentFindAllLOp = EMPXOpFindAllLUpnp;
       
  2569 
       
  2570             CleanupStack::PopAndDestroy( &attrs );
       
  2571             CleanupStack::PopAndDestroy( entry );
       
  2572             CleanupStack::PopAndDestroy( &supportedIds );
       
  2573             }
       
  2574         CleanupStack::PopAndDestroy( cpath );
       
  2575         }
       
  2576     }
       
  2577 
       
  2578 // -----------------------------------------------------------------------------
       
  2579 // CMPXCollectionViewHgImp::DoHandleCopyToRemoteL
       
  2580 // Handle call back from collectionframework for Copy to Remote command
       
  2581 // -----------------------------------------------------------------------------
       
  2582 //
       
  2583 void CMPXCollectionViewHgImp::DoHandleCopyToRemoteL(
       
  2584     const CMPXMedia& aMedia, TBool aComplete )
       
  2585     {
       
  2586     MPX_FUNC( "CMPXCollectionViewHgImp::DoHandleCopyToRemoteL()");
       
  2587 
       
  2588     CMPXMediaArray* mediaArray( NULL );
       
  2589     TInt fileCount( 0 );
       
  2590 
       
  2591     if ( aMedia.IsSupported( KMPXMediaArrayContents ) )
       
  2592         {
       
  2593         mediaArray =
       
  2594             aMedia.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  2595         if ( mediaArray )
       
  2596             {
       
  2597             fileCount = mediaArray->Count();
       
  2598             }
       
  2599         }
       
  2600     MPX_DEBUG2("CMPXCollectionViewHgImp::DoHandleCopyToRemoteL Entry count = %d", fileCount);
       
  2601 
       
  2602     // Change this to Global will be needed if FindAll() is called
       
  2603     // repeatedly until aComplete is ETrue (Inc9?)
       
  2604     CAiwGenericParamList* aiwCopyInParamList = CAiwGenericParamList::NewLC();
       
  2605 
       
  2606     // multiple files or folder
       
  2607     if ( fileCount > 0 )
       
  2608         {
       
  2609         if ( mediaArray )
       
  2610             {
       
  2611             for ( TInt i = 0; i < fileCount; i++ )
       
  2612                 {
       
  2613                 CMPXMedia* media( mediaArray->AtL( i ) );
       
  2614 
       
  2615                 const TDesC& location =
       
  2616                     media->ValueText( KMPXMediaGeneralUri );
       
  2617                 MPX_DEBUG3( "CMPXCollectionViewHgImp::DoHandleCopyToRemote %d filePath = %S", i, &location );
       
  2618 
       
  2619                 TAiwVariant path( location );
       
  2620                 TAiwGenericParam fileParameter( EGenericParamFile,
       
  2621                                                 path );
       
  2622                 aiwCopyInParamList->AppendL( fileParameter );
       
  2623                 }
       
  2624             }
       
  2625         }
       
  2626     else // single file
       
  2627         {
       
  2628         TMPXGeneralType type( EMPXNoType );
       
  2629 
       
  2630         if ( aMedia.IsSupported( KMPXMediaGeneralType ) )
       
  2631             {
       
  2632             type = aMedia.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType );
       
  2633             }
       
  2634 
       
  2635         if ( type == EMPXItem )
       
  2636             {
       
  2637             const TDesC& location =
       
  2638                 aMedia.ValueText( KMPXMediaGeneralUri );
       
  2639             TAiwVariant path( location );
       
  2640             MPX_DEBUG2( "CMPXCollectionViewHgImp::DoHandleCopyToRemote filePath = %S", &location );
       
  2641 
       
  2642             TAiwGenericParam fileParameter( EGenericParamFile, path );
       
  2643             aiwCopyInParamList->AppendL( fileParameter );
       
  2644             }
       
  2645         }
       
  2646 
       
  2647     if ( ( aiwCopyInParamList->Count() > 0 ) &&
       
  2648          aComplete )
       
  2649         {
       
  2650         CAiwGenericParamList* outParamList = CAiwGenericParamList::NewLC();
       
  2651         // do not allow the copy dialog to be dismissed by external command
       
  2652         HandleCommandL( EMPXCmdIgnoreExternalCommand );
       
  2653         iServiceHandler->ExecuteMenuCmdL(
       
  2654                   EMPXCmdUPnPAiwCmdCopyToExternalCriteria, /* command id */
       
  2655                   *aiwCopyInParamList,   /* in parameters */
       
  2656                   *outParamList,          /* out parameters */
       
  2657                   0,                      /* options */
       
  2658                   NULL );                 /* call back */
       
  2659         HandleCommandL( EMPXCmdHandleExternalCommand );
       
  2660 
       
  2661         CleanupStack::PopAndDestroy( outParamList );
       
  2662         }
       
  2663 
       
  2664     // Clear selection
       
  2665     if( iContainer )
       
  2666         {
       
  2667         iContainer->ClearLbxSelection();
       
  2668         }
       
  2669 
       
  2670     CleanupStack::PopAndDestroy( aiwCopyInParamList );
       
  2671     }
       
  2672 
       
  2673 // -----------------------------------------------------------------------------
       
  2674 // Find playlists
       
  2675 // -----------------------------------------------------------------------------
       
  2676 //
       
  2677 TInt CMPXCollectionViewHgImp::FindPlaylistsL()
       
  2678     {
       
  2679     MPX_FUNC( "CMPXCollectionViewHgImp::FindPlaylistsL" );
       
  2680     TInt entriesCount( 0 );
       
  2681     delete iUserPlaylists;
       
  2682     iUserPlaylists = NULL;
       
  2683     iUserPlaylists = iCommonUiHelper->FindPlaylistsL();
       
  2684 
       
  2685     if ( iUserPlaylists )
       
  2686         {
       
  2687         const CMPXMediaArray* mediaArray =
       
  2688             iUserPlaylists->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  2689         User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  2690 
       
  2691         entriesCount = mediaArray->Count();
       
  2692         MPX_DEBUG2( "CMPXCollectionViewHgImp::FindPlaylistsL Entry count = %d", entriesCount );
       
  2693         }
       
  2694     else
       
  2695         {
       
  2696         MPX_DEBUG1( "CMPXCollectionViewHgImp::FindPlaylistsL Error getting playlist" );
       
  2697         User::Leave( KErrNotFound );
       
  2698         }
       
  2699     return entriesCount;
       
  2700     }
       
  2701 
       
  2702 // -----------------------------------------------------------------------------
       
  2703 // Save the playlist after reorder
       
  2704 // -----------------------------------------------------------------------------
       
  2705 //
       
  2706 void CMPXCollectionViewHgImp::SaveCurrentPlaylistL()
       
  2707     {
       
  2708     MPX_FUNC( "CMPXCollectionViewHgImp::SaveCurrentPlaylistL" );
       
  2709     CMPXCommonListBoxArrayBase* listboxArray =
       
  2710         iContainer->ListBoxArray();
       
  2711     TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  2712     TInt origIndex( iContainer->GetOriginalIndex() );
       
  2713     const CMPXMedia& media( listboxArray->MediaL( origIndex ) );
       
  2714     TMPXItemId id( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  2715     const CMPXMedia& containerMedia = listboxArray->ContainerMedia();
       
  2716     TMPXItemId playlistId( containerMedia.ValueTObjectL<TMPXItemId>(
       
  2717         KMPXMediaGeneralId ) );
       
  2718     MPX_DEBUG4( "CMPXCollectionViewHgImp::SaveCurrentPlaylistL song 0x%x is moved from %d to %d",
       
  2719          id.iId1, origIndex, currentIndex );
       
  2720     MPX_DEBUG2( "CMPXCollectionViewHgImp::SaveCurrentPlaylistL playlist ID 0x%x", playlistId.iId1 );
       
  2721     iIsSavingReorderPlaylist = ETrue;
       
  2722     iCollectionUiHelper->ReorderPlaylistL(
       
  2723         playlistId, id, origIndex, currentIndex, this );
       
  2724     iCurrentHighlightedIndex = currentIndex;
       
  2725     }
       
  2726 
       
  2727 // -----------------------------------------------------------------------------
       
  2728 // Handles rename operation complete
       
  2729 // -----------------------------------------------------------------------------
       
  2730 //
       
  2731 void CMPXCollectionViewHgImp::HandleRenameOpCompleteL()
       
  2732     {
       
  2733     MPX_FUNC( "CMPXCollectionViewHgImp::HandleRenameOpCompleteL" );
       
  2734     iSetMediaLCount = KErrNotFound;
       
  2735     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleRenameOpCompleteL dismiss wait note" );
       
  2736     iCommonUiHelper->DismissWaitNoteL();
       
  2737     HandleCommandL( EMPXCmdHandleExternalCommand );
       
  2738     if ( iInvalidFileExist )
       
  2739         {
       
  2740         // there are invalid files, diplay info note
       
  2741         HBufC* string = StringLoader::LoadLC(
       
  2742             R_MPX_COLLECTION_NOTE_RENAME_WITH_INVALID, *iNewName );
       
  2743         iCommonUiHelper->DisplayInfoNoteL( *string );
       
  2744         CleanupStack::PopAndDestroy( string );
       
  2745         }
       
  2746     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleRenameOpCompleteL calling OpenL" );
       
  2747     // path changed messages were ignored during rename, need to
       
  2748     // manually refresh the screen
       
  2749     DoIncrementalOpenL();
       
  2750     }
       
  2751 
       
  2752 // -----------------------------------------------------------------------------
       
  2753 // checks if send option should be shown
       
  2754 // -----------------------------------------------------------------------------
       
  2755 //
       
  2756 TBool CMPXCollectionViewHgImp::SendOptionVisibilityL()
       
  2757     {
       
  2758     MPX_FUNC( "CMPXCollectionViewHgImp::SendOptionVisibilityL" );
       
  2759     TBool isHidden( iContainer->TotalListItemCount() < 1 );
       
  2760 
       
  2761     if ( !isHidden )
       
  2762         {
       
  2763         CMPXCommonListBoxArrayBase* baseArray =
       
  2764             iContainer->ListBoxArray();
       
  2765         CMPXCollectionViewListBoxArray* array =
       
  2766             static_cast<CMPXCollectionViewListBoxArray*>( baseArray );
       
  2767         TInt selectionCount( 0 );
       
  2768         iSelectionIndexCache = iContainer->CurrentSelectionIndicesL();
       
  2769         if ( iSelectionIndexCache )
       
  2770             {
       
  2771             selectionCount = iSelectionIndexCache->Count();
       
  2772             }
       
  2773 
       
  2774         if ( selectionCount > 0 )
       
  2775             {
       
  2776             TBool isValid( EFalse );
       
  2777             for ( TInt i = 0; i < selectionCount && !isValid; i++ )
       
  2778                 {
       
  2779                 // multiple selection
       
  2780                 isValid = !array->IsItemBrokenLinkL(
       
  2781                     iSelectionIndexCache->At( i ) );
       
  2782                 isValid = isValid &&
       
  2783                     !array->IsItemCorruptedL(
       
  2784                     iSelectionIndexCache->At( i ));
       
  2785                 }
       
  2786             // if anything is valid, display the item
       
  2787             isHidden = !isValid;
       
  2788             }
       
  2789         else
       
  2790             {
       
  2791             //single selection
       
  2792             TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  2793             if( currentIndex > KErrNotFound )
       
  2794                 {   
       
  2795                 isHidden = array->IsItemBrokenLinkL( currentIndex );
       
  2796                 isHidden = isHidden || array->IsItemCorruptedL( currentIndex );
       
  2797                 }
       
  2798 			else
       
  2799                 {
       
  2800                 isHidden = ETrue;
       
  2801                 }	
       
  2802             }
       
  2803         }
       
  2804 
       
  2805     return isHidden;
       
  2806     }
       
  2807 
       
  2808 // -----------------------------------------------------------------------------
       
  2809 // Checks if Set as ringtone option should be shown
       
  2810 // -----------------------------------------------------------------------------
       
  2811 //
       
  2812 TBool CMPXCollectionViewHgImp::SetAsRingToneOptionVisibilityL()
       
  2813     {
       
  2814     MPX_FUNC( "CMPXCollectionViewHgImp::SetAsRingToneOptionVisibilityL" );
       
  2815     TBool isHidden( iContainer->TotalListItemCount() < 1 );
       
  2816 
       
  2817     if ( !isHidden )
       
  2818         {
       
  2819         CMPXCollectionViewListBoxArray* array =
       
  2820             static_cast<CMPXCollectionViewListBoxArray*>(
       
  2821             iContainer->ListBoxArray() );
       
  2822         const CMPXMedia& media =
       
  2823             array->MediaL( iContainer->CurrentLbxItemIndex() );
       
  2824 
       
  2825         // if item is not yet fetched from database, assume that it's valid
       
  2826         if ( !( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) ==
       
  2827             KMPXInvalidItemId ) )
       
  2828             {
       
  2829             CMPXMedia* criteria = CMPXMedia::NewL();
       
  2830             CleanupStack::PushL( criteria );
       
  2831             RArray<TMPXAttribute> attrs;
       
  2832             CleanupClosePushL( attrs );
       
  2833             attrs.Append( KMPXMediaGeneralUri );
       
  2834             attrs.Append( KMPXMediaDrmProtected );
       
  2835             attrs.Append( KMPXMediaDrmCanSetAutomated );
       
  2836             criteria->SetTObjectValueL<TMPXGeneralType>(
       
  2837                 KMPXMediaGeneralType,
       
  2838                 media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  2839             criteria->SetTObjectValueL<TMPXGeneralCategory>(
       
  2840                 KMPXMediaGeneralCategory,
       
  2841                 media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  2842             if ( media.IsSupported( KMPXMediaGeneralCollectionId ) )
       
  2843                 {
       
  2844                 criteria->SetTObjectValueL<TUid>(
       
  2845                     KMPXMediaGeneralCollectionId,
       
  2846                     media.ValueTObjectL<TUid>( KMPXMediaGeneralCollectionId ) );
       
  2847                 }
       
  2848             else
       
  2849                 {
       
  2850                 CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
       
  2851                 CleanupStack::PushL( path );
       
  2852                 criteria->SetTObjectValueL<TUid>(
       
  2853                     KMPXMediaGeneralCollectionId,
       
  2854                     TUid::Uid( path->Id( 0 ) ) );
       
  2855                 CleanupStack::PopAndDestroy( path );
       
  2856                 }
       
  2857             criteria->SetTObjectValueL<TMPXItemId>(
       
  2858                 KMPXMediaGeneralId,
       
  2859                 media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  2860 
       
  2861             CMPXMedia* songInfo = iCollectionUtility->Collection().FindAllL( *criteria,
       
  2862                                                              attrs.Array() );
       
  2863             CleanupStack::PopAndDestroy( &attrs );
       
  2864             CleanupStack::PushL( songInfo );
       
  2865 
       
  2866             const CMPXMediaArray* mediaArray(
       
  2867                 songInfo->Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
       
  2868             User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  2869 
       
  2870             if ( mediaArray->Count() > 0 )
       
  2871                 {
       
  2872                 CMPXMedia* si( mediaArray->AtL( 0 ) );
       
  2873                 if ( si->IsSupported( KMPXMediaDrmProtected ) )
       
  2874                     {
       
  2875                     if ( si->ValueTObjectL<TBool>( KMPXMediaDrmProtected ) &&
       
  2876                         si->IsSupported( KMPXMediaDrmCanSetAutomated ) )
       
  2877                         {
       
  2878                         // if it's drm protected, check if
       
  2879                         // KMPXMediaDrmCanSetAutomated
       
  2880                         isHidden = !( si->ValueTObjectL<TBool>( KMPXMediaDrmCanSetAutomated ) );
       
  2881                         }
       
  2882                     }
       
  2883                 }
       
  2884             CleanupStack::PopAndDestroy( songInfo );
       
  2885             CleanupStack::PopAndDestroy( criteria );
       
  2886             }
       
  2887         }
       
  2888     return isHidden;
       
  2889     }
       
  2890 
       
  2891 // -----------------------------------------------------------------------------
       
  2892 // Checks if file details option should be shown
       
  2893 // -----------------------------------------------------------------------------
       
  2894 //
       
  2895 TBool CMPXCollectionViewHgImp::FileDetailsOptionVisibilityL()
       
  2896     {
       
  2897     MPX_FUNC( "CMPXCollectionViewHgImp::FileDetailsOptionVisibilityL" );
       
  2898     TInt selectionCount( 0 );
       
  2899     if ( iSelectionIndexCache)
       
  2900         {
       
  2901         selectionCount = iSelectionIndexCache->Count();
       
  2902         }
       
  2903     TBool isHidden( iContainer->TotalListItemCount() < 1 ||
       
  2904             selectionCount );
       
  2905     if ( !isHidden )
       
  2906         {
       
  2907         CMPXCollectionViewListBoxArray* array =
       
  2908             static_cast<CMPXCollectionViewListBoxArray*>(
       
  2909             iContainer->ListBoxArray() );
       
  2910 
       
  2911         TInt currentItem = iContainer->CurrentLbxItemIndex();
       
  2912         if ( currentItem > KErrNotFound )
       
  2913             {
       
  2914             const CMPXMedia& media = array->MediaL( currentItem );
       
  2915 
       
  2916             if ( media.IsSupported( KMPXMediaGeneralFlags ) )
       
  2917                 {
       
  2918                 TUint flags( media.ValueTObjectL<TUint>( KMPXMediaGeneralFlags ) );
       
  2919                 if ( ( flags ) & ( KMPXMediaGeneralFlagsIsMissingDetails ) )
       
  2920                     {
       
  2921                     isHidden = ETrue;
       
  2922                     }
       
  2923                 }
       
  2924             }
       
  2925         else
       
  2926             {
       
  2927             isHidden = ETrue;
       
  2928             }
       
  2929 
       
  2930         }
       
  2931     return isHidden;
       
  2932     }
       
  2933 
       
  2934 
       
  2935 
       
  2936 // -----------------------------------------------------------------------------
       
  2937 // Handle send command in TBone view.
       
  2938 // -----------------------------------------------------------------------------
       
  2939 //
       
  2940 void CMPXCollectionViewHgImp::DoSendTBoneListItemL(TMPXItemId aContainerId)
       
  2941     {
       
  2942 
       
  2943     MPX_FUNC( "CMPXCollectionViewHgImp::DoSendTBoneListItemL" );
       
  2944     
       
  2945     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
       
  2946     CleanupStack::PushL( path );
       
  2947     
       
  2948     CMPXMedia* albumTrack = iContainer->SelectedItemMediaL();
       
  2949     TMPXItemId trackId = albumTrack->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  2950     // create the item path to send
       
  2951 
       
  2952     if ( path->Levels() == 3 ) //TBone album level
       
  2953         {
       
  2954         path->Back();  
       
  2955         }
       
  2956     else if (path->Levels() == 4) //TBone Song Node level
       
  2957         {
       
  2958         path->Back();
       
  2959         path->Back();
       
  2960         }
       
  2961     path->AppendL(aContainerId);
       
  2962     path->AppendL(trackId); 
       
  2963 
       
  2964     RArray<TMPXAttribute> attrs;
       
  2965     CleanupClosePushL(attrs);
       
  2966     attrs.Append(
       
  2967         TMPXAttribute( KMPXMediaIdGeneral,
       
  2968             EMPXMediaGeneralUri | EMPXMediaGeneralSize |
       
  2969             EMPXMediaGeneralCollectionId |
       
  2970             EMPXMediaGeneralFlags | EMPXMediaGeneralId |
       
  2971             EMPXMediaGeneralType | EMPXMediaGeneralCategory ) );
       
  2972     iCurrentMediaLOp = EMPXOpMediaLSend;
       
  2973     iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  2974     CleanupStack::PopAndDestroy( &attrs );
       
  2975     CleanupStack::PopAndDestroy( path );
       
  2976 }
       
  2977 
       
  2978 
       
  2979 
       
  2980 
       
  2981 // -----------------------------------------------------------------------------
       
  2982 // Handle send command.
       
  2983 // -----------------------------------------------------------------------------
       
  2984 //
       
  2985 void CMPXCollectionViewHgImp::DoSendL()
       
  2986     {
       
  2987     MPX_FUNC( "CMPXCollectionViewHgImp::DoSendL" );
       
  2988 
       
  2989 
       
  2990     CMPXCommonListBoxArrayBase* listboxArray(
       
  2991         iContainer->ListBoxArray() );
       
  2992     TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  2993     const CMPXMedia& media( listboxArray->MediaL(
       
  2994         iContainer->CurrentLbxItemIndex() ) );
       
  2995 
       
  2996     // Marked indicies
       
  2997     TInt arrayCount( iSelectionIndexCache->Count() );
       
  2998 
       
  2999     if ( ( arrayCount == 0 || arrayCount == 1 ) &&
       
  3000         ( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId ) )
       
  3001         {
       
  3002         // not marked, or only 1 item is marked
       
  3003         // and the highlighted item is not yet available
       
  3004         MPX_DEBUG1( "CMPXCollectionViewHgImp::DoSendL item not yet fetched" );
       
  3005         }
       
  3006     else
       
  3007         {
       
  3008         CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  3009         CleanupStack::PushL( path );
       
  3010 
       
  3011         MPX_DEBUG2( "CMPXCollectionViewHgImp::DoSendL array count = %d", arrayCount );
       
  3012         if ( arrayCount > 1 )
       
  3013             {
       
  3014             // if more than 1 selected
       
  3015             for ( TInt i = 0; i < arrayCount; i++ )
       
  3016                 {
       
  3017                 MPX_DEBUG2( "CMPXCollectionViewHgImp::DoSendL array index = %d", iSelectionIndexCache->At( i ) );
       
  3018                 path->SelectL( iSelectionIndexCache->At(i) );
       
  3019                 }
       
  3020             }
       
  3021         else
       
  3022             {
       
  3023             // if only 1 item is marked, treat it as single selection
       
  3024             path->Set( ( arrayCount == 1 ) ?
       
  3025                 iSelectionIndexCache->At( 0 ) : iContainer->CurrentLbxItemIndex() );
       
  3026             }
       
  3027 
       
  3028         RArray<TMPXAttribute> attrs;
       
  3029         CleanupClosePushL(attrs);
       
  3030         attrs.Append(
       
  3031             TMPXAttribute( KMPXMediaIdGeneral,
       
  3032                 EMPXMediaGeneralUri | EMPXMediaGeneralSize |
       
  3033                 EMPXMediaGeneralCollectionId |
       
  3034                 EMPXMediaGeneralFlags | EMPXMediaGeneralId |
       
  3035                 EMPXMediaGeneralType | EMPXMediaGeneralCategory ) );
       
  3036         iCurrentMediaLOp = EMPXOpMediaLSend;
       
  3037         iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  3038         CleanupStack::PopAndDestroy( &attrs );
       
  3039         CleanupStack::PopAndDestroy( path );
       
  3040         }
       
  3041     }
       
  3042 
       
  3043 // -----------------------------------------------------------------------------
       
  3044 // Handle send playlist command
       
  3045 // -----------------------------------------------------------------------------
       
  3046 //
       
  3047 void CMPXCollectionViewHgImp::DoSendPlaylistL( TMPXItemId aItemId )
       
  3048     {
       
  3049     MPX_FUNC( "CMPXCollectionViewHgImp::DoSendPlaylistL" );
       
  3050     // export the playlist to file system, and send the playlist
       
  3051     // when the operation is completed
       
  3052     HBufC* defaultDrive = iCommonUiHelper->DefaultDriveLC();
       
  3053     TFileName defaultPath;
       
  3054     defaultPath.Append( *defaultDrive );
       
  3055     RFs& fileSession = iCoeEnv->FsSession();
       
  3056     TBool folderExist = BaflUtils::FolderExists( fileSession, defaultPath );
       
  3057     TInt count( 0 );
       
  3058     // use time stamp as the directory name for export, so that
       
  3059     // it won't overwrite any existing files.  It will search for the first
       
  3060     // available folder that is not currently in the file system
       
  3061     while ( folderExist )
       
  3062         {
       
  3063         if ( count++ > KMPXPlaylistExportRetry )
       
  3064             {
       
  3065             MPX_DEBUG1( "CMPXCollectionViewHgImp::DoSendPlaylistL maximum retry count reached, leaving" );
       
  3066             User::Leave( KErrNotReady );
       
  3067             }
       
  3068         defaultPath.Copy( *defaultDrive );
       
  3069         TTime timeStamp;
       
  3070         timeStamp.UniversalTime();
       
  3071         defaultPath.AppendNum( timeStamp.Int64() );
       
  3072         defaultPath.Append( KPathDelimiter );
       
  3073         folderExist = BaflUtils::FolderExists( fileSession, defaultPath );
       
  3074         }
       
  3075     CleanupStack::PopAndDestroy( defaultDrive );
       
  3076     MPX_DEBUG2( "CMPXCollectionViewHgImp::DoSendPlaylistL creating path = %S", &defaultPath );
       
  3077     BaflUtils::EnsurePathExistsL( fileSession, defaultPath );
       
  3078     // playlist is sent in the call back of this function
       
  3079     iCollectionUiHelper->ExportPlaylistL( aItemId, defaultPath, this );
       
  3080     }
       
  3081 
       
  3082 // -----------------------------------------------------------------------------
       
  3083 // Handle call back from collectionframework for send command
       
  3084 // -----------------------------------------------------------------------------
       
  3085 //
       
  3086 void CMPXCollectionViewHgImp::DoHandleSendL( const CMPXMedia& aMedia )
       
  3087     {
       
  3088     MPX_FUNC( "CMPXCollectionViewHgImp::DoHandleSendL" );
       
  3089     TInt invalidFileCount( 0 );
       
  3090     TInt maxSize( 0 );
       
  3091     CMessageData* messageData = CMessageData::NewLC();
       
  3092 
       
  3093     TInt fileCount( 0 );
       
  3094     if( aMedia.IsSupported( KMPXMediaArrayContents ) )
       
  3095         {
       
  3096         const CMPXMediaArray* mediaArray =
       
  3097             aMedia.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  3098         User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  3099         fileCount = mediaArray->Count();
       
  3100 
       
  3101         }
       
  3102     MPX_DEBUG2( "CMPXCollectionViewHgImp::DoHandleSendL Entry count = %d", fileCount );
       
  3103 
       
  3104     if ( fileCount > 0 )
       
  3105         {
       
  3106         const CMPXMediaArray* mediaArray =
       
  3107             aMedia.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  3108         User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  3109 
       
  3110         CMPXMedia* media( NULL );
       
  3111         for ( TInt i = 0; i < fileCount; i++ )
       
  3112             {
       
  3113             media = mediaArray->AtL( i );
       
  3114             TUint flags( media->ValueTObjectL<TUint>( KMPXMediaGeneralFlags ) );
       
  3115             const TDesC& location = media->ValueText( KMPXMediaGeneralUri );
       
  3116 
       
  3117             if ( !( flags & KMPXMediaGeneralFlagsIsInvalid ) &&
       
  3118                 ConeUtils::FileExists( location ) )
       
  3119                 {
       
  3120                 TInt fileSize( 0 );
       
  3121                 if ( media->IsSupported( KMPXMediaGeneralSize ) )
       
  3122                     {
       
  3123                     fileSize = media->ValueTObjectL<TInt>( KMPXMediaGeneralSize );
       
  3124                     }
       
  3125                 else
       
  3126                     {
       
  3127                     RFs& fileSession = iCoeEnv->FsSession();
       
  3128                     TEntry pl;
       
  3129                     fileSession.Entry( location, pl );
       
  3130                     fileSize = pl.iSize;
       
  3131                     }
       
  3132                 if ( fileSize > maxSize )
       
  3133                     {
       
  3134                     maxSize = fileSize;
       
  3135                     }
       
  3136                 messageData->AppendAttachmentL( location );
       
  3137                 }
       
  3138             else
       
  3139                 {
       
  3140                 UpdateDatabaseFlagL( KErrNotFound, *media,
       
  3141                     KMPXMediaGeneralFlagsIsInvalid, ETrue, EFalse );
       
  3142                 invalidFileCount++;
       
  3143                 }
       
  3144             }
       
  3145         }
       
  3146     else
       
  3147         {
       
  3148         // single file
       
  3149         fileCount = 1;
       
  3150         TUint flags = aMedia.ValueTObjectL<TUint>( KMPXMediaGeneralFlags );
       
  3151         const TDesC& location = aMedia.ValueText( KMPXMediaGeneralUri );
       
  3152 
       
  3153         if ( !( flags & KMPXMediaGeneralFlagsIsInvalid ) &&
       
  3154             ConeUtils::FileExists( location ) )
       
  3155             {
       
  3156             TInt fileSize( 0 );
       
  3157             if ( aMedia.IsSupported( KMPXMediaGeneralSize ) )
       
  3158                 {
       
  3159                 fileSize = aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralSize );
       
  3160                 }
       
  3161             else
       
  3162                 {
       
  3163                 RFs& fileSession = iCoeEnv->FsSession();
       
  3164                 TEntry pl;
       
  3165                 fileSession.Entry( location, pl );
       
  3166                 fileSize = pl.iSize;
       
  3167                 }
       
  3168             if ( fileSize > maxSize )
       
  3169                 {
       
  3170                 maxSize = fileSize;
       
  3171                 }
       
  3172             messageData->AppendAttachmentL( location );
       
  3173             }
       
  3174         else
       
  3175             {
       
  3176             UpdateDatabaseFlagL( KErrNotFound, aMedia,
       
  3177                 KMPXMediaGeneralFlagsIsInvalid, ETrue, EFalse );
       
  3178             invalidFileCount++;
       
  3179             }
       
  3180         }
       
  3181     TBool confirmOk( EFalse );
       
  3182     MPX_DEBUG3( "CMPXCollectionViewHgImp::DoHandleSendL Invalid Count = %d, Total Count = %d", invalidFileCount, fileCount );
       
  3183     if ( invalidFileCount )
       
  3184         {
       
  3185         if ( invalidFileCount == fileCount )
       
  3186             {
       
  3187             // all files are invalid
       
  3188             iCommonUiHelper->DisplayInfoNoteL( ( invalidFileCount == 1 ) ?
       
  3189                 R_MPX_COLLECTION_INFO_FILE_NOT_FOUND :
       
  3190                 R_MPX_COLLECTION_SEND_ALL_INVALID_SONGS_NOTE_TXT );
       
  3191             }
       
  3192         else
       
  3193             {
       
  3194             // Show confirmation query if invalid file found
       
  3195             HBufC* queryTxt = StringLoader::LoadLC(
       
  3196                 R_MPX_COLLECTION_QUERY_SEND_INVALID_SONGS_TXT );
       
  3197             CAknQueryDialog* query = CAknQueryDialog::NewL(
       
  3198                 CAknQueryDialog::EConfirmationTone );
       
  3199             CleanupStack::PushL( query );
       
  3200             query->PublishDialogL( EMPlayerNoteSendInvalidSongs,
       
  3201                                 KMPlayerNoteCategory);
       
  3202             CleanupStack::Pop( query );
       
  3203             confirmOk = query->ExecuteLD(
       
  3204                 R_MPX_COLLECTION_GENERIC_CONFIRMATION_QUERY,
       
  3205                 *queryTxt );
       
  3206             CleanupStack::PopAndDestroy( queryTxt );
       
  3207             }
       
  3208         }
       
  3209 
       
  3210     if ( !invalidFileCount || confirmOk )
       
  3211         {
       
  3212         if ( !iSendUi )
       
  3213             {
       
  3214             iSendUi = CSendUi::NewL();
       
  3215             }
       
  3216         TSendingCapabilities capabilities(
       
  3217             0,
       
  3218             maxSize,
       
  3219             TSendingCapabilities::ESupportsAttachments );
       
  3220         // ignore commands from external clients so that the
       
  3221         // sending is not interrupted
       
  3222         HandleCommandL( EMPXCmdIgnoreExternalCommand );
       
  3223         // send ui leaves with error 0 if canceled, have to be trapped
       
  3224         MPX_TRAPD( err, iSendUi->ShowQueryAndSendL( messageData, capabilities ) );
       
  3225         if ( err != KErrNone )
       
  3226             {
       
  3227             HandleError( err );
       
  3228             }
       
  3229         HandleCommandL( EMPXCmdHandleExternalCommand );
       
  3230         }
       
  3231 
       
  3232     // Clear selection
       
  3233     iContainer->ClearLbxSelection();
       
  3234     CleanupStack::PopAndDestroy( messageData );
       
  3235     }
       
  3236 
       
  3237 // -----------------------------------------------------------------------------
       
  3238 // Handle rename command
       
  3239 // -----------------------------------------------------------------------------
       
  3240 //
       
  3241 void CMPXCollectionViewHgImp::DoHandleRenameL()
       
  3242     {
       
  3243     MPX_FUNC( "CMPXCollectionViewHgImp::DoHandleRenameL" );
       
  3244     CMPXCommonListBoxArrayBase* listboxArray(
       
  3245         iContainer->ListBoxArray() );
       
  3246     TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  3247     const CMPXMedia& currentMedia( listboxArray->MediaL( currentIndex ) );
       
  3248     TMPXGeneralCategory category(
       
  3249         currentMedia.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  3250     switch ( category )
       
  3251         {
       
  3252         case EMPXPlaylist:
       
  3253             {
       
  3254             // rename playlist
       
  3255             iCurrentMediaLOp = EMPXOpMediaLRenamePlaylist;
       
  3256             CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  3257             CleanupStack::PushL( path );
       
  3258             path->Set( iContainer->CurrentLbxItemIndex() );
       
  3259             RArray<TMPXAttribute> attrs;
       
  3260             CleanupClosePushL(attrs);
       
  3261             attrs.Append(
       
  3262                 TMPXAttribute( KMPXMediaIdGeneral,
       
  3263                     EMPXMediaGeneralUri | EMPXMediaGeneralId |
       
  3264                     EMPXMediaGeneralTitle ) );
       
  3265             iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  3266             CleanupStack::PopAndDestroy( &attrs );
       
  3267             CleanupStack::PopAndDestroy( path );
       
  3268             break;
       
  3269             }
       
  3270         case EMPXAlbum:
       
  3271         case EMPXArtist:
       
  3272         case EMPXGenre:
       
  3273         case EMPXComposer:
       
  3274             {
       
  3275             delete iNewName;
       
  3276             iNewName = NULL;
       
  3277             iNewName = HBufC::NewL( KMaxFileName );
       
  3278             TPtr ptr( iNewName->Des() );
       
  3279 
       
  3280             // Set default text as current selected item text
       
  3281             const CMPXMediaArray& mediaAry = listboxArray->MediaArray();
       
  3282             CMPXMedia* origMedia( mediaAry.AtL( currentIndex ) );
       
  3283             const TDesC& title = origMedia->ValueText( KMPXMediaGeneralTitle );
       
  3284             ptr.Append( title.Left(KMaxFileName) );
       
  3285 
       
  3286             CAknTextQueryDialog* query = CAknTextQueryDialog::NewL( ptr );
       
  3287             CleanupStack::PushL( query );
       
  3288             query->SetMaxLength( KMaxFileName );
       
  3289             HBufC* promptTxt = StringLoader::LoadLC( R_MPX_QTN_NMP_PRMPT_NEW_NAME );
       
  3290             query->SetPromptL( *promptTxt );
       
  3291             query->SetPredictiveTextInputPermitted( ETrue );
       
  3292             CleanupStack::PopAndDestroy( promptTxt );
       
  3293             query->PublishDialogL(
       
  3294                     EMPlayerQueryPrmptNewName,
       
  3295                     KMPlayerNoteCategory);
       
  3296             CleanupStack::Pop( query );
       
  3297             if ( query->ExecuteLD( R_MPX_CUI_RENAME_QUERY ) )
       
  3298                 {
       
  3299                 TMPXItemId id(
       
  3300                     currentMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  3301 
       
  3302                 CMPXMedia* media = CMPXMedia::NewL();
       
  3303                 CleanupStack::PushL( media );
       
  3304                 media->SetTObjectValueL<TMPXGeneralType>(
       
  3305                     KMPXMediaGeneralType, EMPXGroup );
       
  3306                 media->SetTObjectValueL<TMPXGeneralCategory>(
       
  3307                     KMPXMediaGeneralCategory, EMPXSong );
       
  3308                 media->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id );
       
  3309 
       
  3310                 switch ( category )
       
  3311                     {
       
  3312                     case EMPXAlbum:
       
  3313                         {
       
  3314                         iCurrentFindAllLOp = EMPXOpFindAllLRenameAlbum;
       
  3315                         // check if it's album or artist/album
       
  3316                         const CMPXMedia& containerMedia = listboxArray->ContainerMedia();
       
  3317                         TMPXGeneralCategory containerCategory(
       
  3318                             containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
  3319                              KMPXMediaGeneralCategory ) );
       
  3320                         if ( containerCategory == EMPXArtist )
       
  3321                             {
       
  3322                             // artist/album level, need to specify artist ID in container ID
       
  3323                             TMPXItemId containerId(
       
  3324                                 containerMedia.ValueTObjectL<TMPXItemId>(
       
  3325                                     KMPXMediaGeneralId ) );
       
  3326                             media->SetTObjectValueL<TMPXItemId>(
       
  3327                                 KMPXMediaGeneralContainerId, containerId );
       
  3328                             }
       
  3329                         break;
       
  3330                         }
       
  3331                     case EMPXArtist:
       
  3332                         {
       
  3333                         iCurrentFindAllLOp = EMPXOpFindAllLRenameArtist;
       
  3334                         break;
       
  3335                         }
       
  3336                     case EMPXGenre:
       
  3337                         {
       
  3338                         iCurrentFindAllLOp = EMPXOpFindAllLRenameGenre;
       
  3339                         break;
       
  3340                         }
       
  3341                     case EMPXComposer:
       
  3342                         {
       
  3343                         iCurrentFindAllLOp = EMPXOpFindAllLRenameComposer;
       
  3344                         break;
       
  3345                         }
       
  3346                     default:
       
  3347                         {
       
  3348                         ASSERT( 0 );
       
  3349                         break;
       
  3350                         }
       
  3351                     }
       
  3352                 RArray<TMPXAttribute> attrs;
       
  3353                 CleanupClosePushL( attrs );
       
  3354                 attrs.Append(
       
  3355                     TMPXAttribute( KMPXMediaIdGeneral,
       
  3356                         EMPXMediaGeneralId | EMPXMediaGeneralUri |
       
  3357                         EMPXMediaGeneralCollectionId |
       
  3358                         EMPXMediaGeneralType | EMPXMediaGeneralCategory | EMPXMediaGeneralFlags ) );
       
  3359                 if ( category == EMPXAlbum || category == EMPXArtist )
       
  3360                     {
       
  3361                     attrs.Append( TMPXAttribute( KMPXMediaIdMusic,
       
  3362                         EMPXMediaMusicAlbumArtFileName ) );
       
  3363                     }
       
  3364                 iCollectionUtility->Collection().FindAllL( *media, attrs.Array(), *this );
       
  3365                 CleanupStack::PopAndDestroy( &attrs );
       
  3366                 CleanupStack::PopAndDestroy( media );
       
  3367                 }
       
  3368             break;
       
  3369             }
       
  3370         default:
       
  3371             {
       
  3372             // shouldn't reach here
       
  3373             ASSERT( 0 );
       
  3374             break;
       
  3375             }
       
  3376         }
       
  3377     }
       
  3378 
       
  3379 // -----------------------------------------------------------------------------
       
  3380 // Prepares media object for selected items
       
  3381 // -----------------------------------------------------------------------------
       
  3382 //
       
  3383 void CMPXCollectionViewHgImp::PrepareMediaForSelectedItemsL( CMPXMedia& aMedia, TMPXGeneralCategory aContainerCategory, TMPXGeneralType aContainerType  )
       
  3384     {
       
  3385     MPX_FUNC( "CMPXCollectionViewHgImp::PrepareMediaForSelectedItemsL" );
       
  3386     CMPXMediaArray* mediaArray( CMPXMediaArray::NewL() );
       
  3387     CleanupStack::PushL( mediaArray );
       
  3388 
       
  3389     CMPXCollectionPath* path( iCollectionUtility->Collection().PathL() );
       
  3390     CleanupStack::PushL( path );
       
  3391     TMPXItemId id( path->Id( 0 ) );
       
  3392     MPX_DEBUG2( "CMPXCollectionViewHgImp::PrepareMediaForSelectedItemsL collection ID = 0x%x", id.iId1 );
       
  3393     CleanupStack::PopAndDestroy( path );
       
  3394     
       
  3395     //support for TBone view add to playlist
       
  3396     if ( iContainer->IsTBoneView() )
       
  3397         {
       
  3398         CMPXMedia* media = iContainer->SelectedItemMediaL();
       
  3399         if ( media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId )
       
  3400            {
       
  3401            // leave with special error code, this error
       
  3402            // should not trigger any error message, the operation should
       
  3403            // be terminated silently
       
  3404            User::Leave( KMPXErrDataNotReady );
       
  3405            }
       
  3406         else
       
  3407            {
       
  3408            CMPXMedia* entry( PopulateMediaLC( *media, id ) );
       
  3409            mediaArray->AppendL( entry );
       
  3410            CleanupStack::Pop( entry );
       
  3411            }      	
       
  3412        }
       
  3413 
       
  3414     else
       
  3415         {
       
  3416         TInt count( iSelectionIndexCache->Count() );   
       
  3417         CMPXCommonListBoxArrayBase* listBoxArray =   
       
  3418             iContainer->ListBoxArray(); 
       
  3419         if ( count > 0 )
       
  3420             {
       
  3421                             
       
  3422             if ( count == 1 )
       
  3423                 {
       
  3424                 // marked one item, if it's not valid, ignore the command
       
  3425                 const CMPXMedia& listBoxMedia = listBoxArray->MediaL( iSelectionIndexCache->At(0) );
       
  3426                 if ( listBoxMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId )
       
  3427                     {
       
  3428                     // leave with special error code, this error
       
  3429                     // should not trigger any error message, the operation should
       
  3430                     // be terminated silently
       
  3431                     User::Leave( KMPXErrDataNotReady );
       
  3432                     }
       
  3433                 
       
  3434                 }
       
  3435                 for ( TInt i = 0; i < count; i++ )
       
  3436                     {
       
  3437                     const CMPXMedia& listBoxMedia = listBoxArray->MediaL( iSelectionIndexCache->At(i) );
       
  3438                     if ( listBoxMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId )
       
  3439                         {
       
  3440                         // item not ready, cache this command and execute
       
  3441                         // it when the data becomes valid
       
  3442                         User::Leave( KMPXErrDataNotReadyCacheCommand );
       
  3443                         }
       
  3444                     CMPXMedia* entry( PopulateMediaLC( listBoxMedia, id ) );
       
  3445                     mediaArray->AppendL( entry );
       
  3446                     CleanupStack::Pop( entry );
       
  3447                     }
       
  3448             }
       
  3449        
       
  3450         else
       
  3451             {
       
  3452             const CMPXMedia& listBoxMedia = listBoxArray->MediaL(
       
  3453                 iContainer->CurrentLbxItemIndex() );
       
  3454             if ( listBoxMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId )
       
  3455                 {
       
  3456                 // leave with special error code, this error
       
  3457                 // should not trigger any error message, the operation should
       
  3458                 // be terminated silently
       
  3459                 User::Leave( KMPXErrDataNotReady );
       
  3460                 }
       
  3461             else
       
  3462                 {
       
  3463                 CMPXMedia* entry( PopulateMediaLC( listBoxMedia, id ) );
       
  3464                 mediaArray->AppendL( entry );
       
  3465                 CleanupStack::Pop( entry );
       
  3466                 }
       
  3467             }
       
  3468        }
       
  3469  
       
  3470        aMedia.SetTObjectValueL( KMPXMediaGeneralCollectionId, id );
       
  3471        aMedia.SetCObjectValueL( KMPXMediaArrayContents, mediaArray );
       
  3472        aMedia.SetTObjectValueL( KMPXMediaArrayCount, mediaArray->Count() );
       
  3473        iNumSongAddedToPlaylist = mediaArray->Count();
       
  3474        CleanupStack::PopAndDestroy( mediaArray );
       
  3475     }
       
  3476 
       
  3477 // -----------------------------------------------------------------------------
       
  3478 // Populates media object with information needed for save to
       
  3479 // existing playlist
       
  3480 // -----------------------------------------------------------------------------
       
  3481 //
       
  3482 CMPXMedia* CMPXCollectionViewHgImp::PopulateMediaLC(
       
  3483     const CMPXMedia& aMedia, TMPXItemId aCollectionId )
       
  3484     {
       
  3485     MPX_FUNC( "CMPXCollectionViewHgImp::PopulateMediaLC" );
       
  3486     CMPXMedia* entry = CMPXMedia::NewL();
       
  3487     CleanupStack::PushL( entry );
       
  3488     entry->SetTextValueL(
       
  3489         KMPXMediaGeneralTitle,
       
  3490         aMedia.ValueText( KMPXMediaGeneralTitle ) );
       
  3491     entry->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem);
       
  3492     entry->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong );
       
  3493     entry->SetTObjectValueL( KMPXMediaGeneralId,
       
  3494         aMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  3495     entry->SetTObjectValueL( KMPXMediaGeneralCollectionId, aCollectionId );
       
  3496     return entry;
       
  3497     }
       
  3498 
       
  3499 // -----------------------------------------------------------------------------
       
  3500 // Handle rename playlist command
       
  3501 // -----------------------------------------------------------------------------
       
  3502 //
       
  3503 void CMPXCollectionViewHgImp::DoHandleRenamePlaylistL( const CMPXMedia& aMedia )
       
  3504     {
       
  3505     MPX_FUNC( "CMPXCollectionViewHgImp::DoHandleRenamePlaylistL" );
       
  3506     const TDesC& uri = aMedia.ValueText( KMPXMediaGeneralUri );
       
  3507     TParsePtrC fn( uri );
       
  3508 #ifdef _DEBUG
       
  3509     TPtrC ptr( fn.NameAndExt() );
       
  3510     MPX_DEBUG2( "CMPXCollectionViewHgImp::DoHandleRenamePlaylistL Original Uri = %S", &ptr );
       
  3511 #endif
       
  3512     HBufC* playlistName = HBufC::NewLC( KMaxFileName );
       
  3513     TPtr playlistNamePtr = playlistName->Des();
       
  3514     const TDesC& title = aMedia.ValueText( KMPXMediaGeneralTitle );
       
  3515     TInt ret = iCommonUiHelper->LaunchRenameDialogL(
       
  3516         title, playlistNamePtr, fn.DriveAndPath() );
       
  3517     if ( ret )
       
  3518         {
       
  3519         CMPXMedia* media = CMPXMedia::NewL();
       
  3520         CleanupStack::PushL( media );
       
  3521         media->SetTObjectValueL<TMPXGeneralType>(
       
  3522             KMPXMediaGeneralType, EMPXItem );
       
  3523         media->SetTObjectValueL<TMPXGeneralCategory>(
       
  3524             KMPXMediaGeneralCategory, EMPXPlaylist );
       
  3525         TMPXItemId id( aMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  3526         media->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id );
       
  3527         TParsePtrC newFn( *playlistName );
       
  3528         media->SetTextValueL( KMPXMediaGeneralTitle, newFn.NameAndExt() );
       
  3529         iCollectionUiHelper->RenameL( *media, this );
       
  3530         CleanupStack::PopAndDestroy( media );
       
  3531         }
       
  3532     CleanupStack::PopAndDestroy( playlistName );
       
  3533     }
       
  3534 
       
  3535 // ---------------------------------------------------------------------------
       
  3536 // Set/clears the flags for item in database
       
  3537 // ---------------------------------------------------------------------------
       
  3538 //
       
  3539 void CMPXCollectionViewHgImp::UpdateDatabaseFlagL(
       
  3540     TInt aIndex, const CMPXMedia& aMedia, TUint aFlag,
       
  3541     TBool aSet, TBool aEnableInfoDialog )
       
  3542     {
       
  3543     MPX_FUNC( "CMPXCollectionViewHgImp::UpdateDatabaseFlagL" );
       
  3544     MPX_DEBUG3( "CMPXCollectionViewHgImp::UpdateDatabaseFlagL aFlag = 0x%x, aSet = %d", aFlag, aSet );
       
  3545     CMPXCommonListBoxArrayBase* array(0);
       
  3546     if (iContainer)
       
  3547     	array = iContainer->ListBoxArray();
       
  3548     	
       
  3549     ASSERT( array );
       
  3550 
       
  3551     // set the item as invalid
       
  3552     TUint flags( 0 );
       
  3553     if ( aSet )
       
  3554         {
       
  3555         flags = KMPXMediaGeneralFlagsSetOrUnsetBit;
       
  3556         }
       
  3557     flags |= aFlag;
       
  3558 
       
  3559     MPX_DEBUG2( "CMPXCollectionViewHgImp::UpdateDatabaseFlagL flag after 0x%x", flags );
       
  3560     CMPXMedia* entry = CMPXMedia::NewL();
       
  3561     CleanupStack::PushL( entry );
       
  3562     if ( aIndex > KErrNotFound )
       
  3563         {
       
  3564         MPX_DEBUG2( "CMPXCollectionViewHgImp::UpdateDatabaseFlagL using aIndex = %d", aIndex );
       
  3565         const CMPXMedia& media = array->MediaL( aIndex );
       
  3566         TMPXItemId id( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  3567         TMPXGeneralType type(
       
  3568             media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  3569         TMPXGeneralCategory category(
       
  3570             media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  3571         entry->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id );
       
  3572         entry->SetTObjectValueL<TMPXGeneralType>(
       
  3573             KMPXMediaGeneralType, type );
       
  3574         entry->SetTObjectValueL<TMPXGeneralCategory>(
       
  3575             KMPXMediaGeneralCategory, category );
       
  3576         }
       
  3577     else
       
  3578         {
       
  3579         // try to look for the info inside aMedia
       
  3580         if ( aMedia.IsSupported( KMPXMediaGeneralId ) )
       
  3581             {
       
  3582             TMPXItemId id( aMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  3583             entry->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id );
       
  3584             }
       
  3585         if ( aMedia.IsSupported( KMPXMediaGeneralType ) )
       
  3586             {
       
  3587             TMPXGeneralType type(
       
  3588                 aMedia.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  3589             entry->SetTObjectValueL<TMPXGeneralType>(
       
  3590                 KMPXMediaGeneralType, type );
       
  3591             }
       
  3592         if ( aMedia.IsSupported( KMPXMediaGeneralCategory ) )
       
  3593             {
       
  3594             TMPXGeneralCategory category(
       
  3595                 aMedia.ValueTObjectL<TMPXGeneralCategory>(
       
  3596                     KMPXMediaGeneralCategory ) );
       
  3597             entry->SetTObjectValueL<TMPXGeneralCategory>(
       
  3598                 KMPXMediaGeneralCategory, category );
       
  3599             }
       
  3600         }
       
  3601     TUid collectionId( aMedia.ValueTObjectL<TUid>( KMPXMediaGeneralCollectionId ) );
       
  3602     entry->SetTObjectValueL<TUid>(
       
  3603         KMPXMediaGeneralCollectionId, collectionId );
       
  3604     entry->SetTObjectValueL<TUint>( KMPXMediaGeneralFlags, flags );
       
  3605 
       
  3606     // Update the collection via CommandL
       
  3607     CMPXCommand* cmd( CMPXCommand::NewL() );
       
  3608     CleanupStack::PushL( cmd );
       
  3609     cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionSet );
       
  3610     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
  3611     TUid colId( entry->ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId) );
       
  3612     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
  3613     cmd->SetCObjectValueL<CMPXMedia>( KMPXCommandColSetMedia, entry );
       
  3614     iCollectionUtility->Collection().CommandL( *cmd );
       
  3615     CleanupStack::PopAndDestroy( cmd );
       
  3616 
       
  3617     CleanupStack::PopAndDestroy( entry );
       
  3618     if ( aEnableInfoDialog && KMPXMediaGeneralFlagsIsInvalid == aFlag )
       
  3619         {
       
  3620         iCommonUiHelper->DisplayInfoNoteL( R_MPX_COLLECTION_INFO_FILE_NOT_FOUND );
       
  3621         }
       
  3622     }
       
  3623 
       
  3624 // ---------------------------------------------------------------------------
       
  3625 // Get duration of current view
       
  3626 // ---------------------------------------------------------------------------
       
  3627 //
       
  3628 void CMPXCollectionViewHgImp::GetDurationL()
       
  3629     {
       
  3630     MPX_FUNC( "CMPXCollectionViewHgImp::GetDurationL" );
       
  3631     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  3632     CleanupStack::PushL( cpath );
       
  3633     cpath->Back();  // Container
       
  3634     RArray<TMPXAttribute> attrs;
       
  3635     CleanupClosePushL(attrs);
       
  3636     iCurrentMediaLOp = EMPXOpMediaLGetContainerInfo;
       
  3637     attrs.Append( KMPXMediaGeneralDuration );
       
  3638     iCollectionUtility->Collection().MediaL( *cpath, attrs.Array() );
       
  3639     CleanupStack::PopAndDestroy( &attrs );
       
  3640     CleanupStack::PopAndDestroy( cpath );
       
  3641     }
       
  3642 
       
  3643 // ---------------------------------------------------------------------------
       
  3644 // Handles file check result
       
  3645 // ---------------------------------------------------------------------------
       
  3646 //
       
  3647 void CMPXCollectionViewHgImp::DoHandleFileCheckResultL(
       
  3648     TUid aViewToActivate, const CMPXMedia& aMedia )
       
  3649     {
       
  3650     MPX_FUNC( "CMPXCollectionViewHgImp::HandleFileCheckResultL" );
       
  3651     const TDesC& location = aMedia.ValueText( KMPXMediaGeneralUri );
       
  3652     if ( location.Length() == 0 || ConeUtils::FileExists( location ) )
       
  3653         {
       
  3654         HandleListBoxEventL( NULL, EEventItemClicked );   
       
  3655         HBufC* buf = HBufC::NewLC( 5 ); // magic number, array granularity
       
  3656         buf->Des().AppendNum( iContainer->CurrentLbxItemIndex() );
       
  3657         // Activate view via View Framework
       
  3658         iViewUtility->ActivateViewL( aViewToActivate, buf );
       
  3659         CleanupStack::PopAndDestroy( buf );
       
  3660         }
       
  3661     else
       
  3662         {
       
  3663         // mark database entry for this item as invalid
       
  3664         UpdateDatabaseFlagL( iContainer->CurrentLbxItemIndex(),
       
  3665             aMedia, KMPXMediaGeneralFlagsIsInvalid, ETrue );
       
  3666         }
       
  3667     }
       
  3668 
       
  3669 #ifdef __ENABLE_MSK
       
  3670 // ---------------------------------------------------------------------------
       
  3671 // Updates the middle softkey display
       
  3672 // ---------------------------------------------------------------------------
       
  3673 //
       
  3674 void CMPXCollectionViewHgImp::UpdateMiddleSoftKeyDisplayL( TInt aMskId )
       
  3675     {
       
  3676     MPX_FUNC( "CMPXCollectionViewHgImp::UpdateMiddleSoftKeyDisplayL" );
       
  3677     CEikButtonGroupContainer* cba = Cba();
       
  3678 	// We only update middle softkey for non-touch UI
       
  3679     if ( cba && !AknLayoutUtils::PenEnabled() )
       
  3680         {
       
  3681         if ( !iContainer->CurrentListItemCount() ) // list is empty
       
  3682             {
       
  3683             // remove middle softkey label
       
  3684             iCommonUiHelper->RemoveMiddleSoftKeyLabel( *cba );
       
  3685             MPX_DEBUG1( "CMPXCollectionViewHgImp::UpdateMiddleSoftKeyDisplayL - remove label, list is empty" );
       
  3686             }
       
  3687         else if ( iContainer->CurrentSelectionIndicesL()->Count() ) // marked items
       
  3688             {
       
  3689             CFbsBitmap* bitmap = NULL;
       
  3690             CFbsBitmap* mask = NULL;
       
  3691             AknsUtils::CreateColorIconL(
       
  3692                 AknsUtils::SkinInstance(),
       
  3693                 KAknsIIDQgnPropMskMenu,
       
  3694                 KAknsIIDQsnComponentColors,
       
  3695                 EAknsCIQsnComponentColorsCG13,
       
  3696                 bitmap,
       
  3697                 mask,
       
  3698                 AknIconUtils::AvkonIconFileName(),
       
  3699                 EMbmAvkonQgn_prop_msk_menu,
       
  3700                 EMbmAvkonQgn_prop_msk_menu_mask,
       
  3701                 KRgbBlack);
       
  3702 
       
  3703             CleanupStack::PushL(bitmap);
       
  3704             CleanupStack::PushL(mask);
       
  3705 
       
  3706             // set middle softkey icon
       
  3707             iCommonUiHelper->SetMiddleSoftKeyIconL(*cba, bitmap, mask);
       
  3708 
       
  3709             CleanupStack::PopAndDestroy(2, bitmap);
       
  3710             MPX_DEBUG1("CMPXCollectionViewHgImp::UpdateMiddleSoftKeyDisplayL - items marked, show icon");
       
  3711             }
       
  3712         else
       
  3713             {
       
  3714             // set middle softkey label
       
  3715             iCommonUiHelper->SetMiddleSoftKeyLabelL(
       
  3716                 *cba,
       
  3717                 aMskId,
       
  3718                 EAknSoftkeyForwardKeyEvent );
       
  3719             iCurrentMskId = aMskId;
       
  3720             MPX_DEBUG1( "CMPXCollectionViewHgImp::UpdateMiddleSoftKeyDisplayL - label displayed" );
       
  3721             }
       
  3722         cba->DrawDeferred();
       
  3723         }
       
  3724     }
       
  3725 #endif // __ENABLE_MSK
       
  3726 
       
  3727 
       
  3728 // ---------------------------------------------------------------------------
       
  3729 // Handles the completion of adding a playlist event
       
  3730 // ---------------------------------------------------------------------------
       
  3731 //
       
  3732 void CMPXCollectionViewHgImp::HandleAddCompletedL(
       
  3733     CMPXMedia* aPlaylist, TInt aError )
       
  3734     {
       
  3735     MPX_FUNC( "CMPXCollectionViewHgImp::HandleAddCompletedL" );
       
  3736     iAddingToNewPlaylist = EFalse;
       
  3737     iDialogDismissed = EFalse;
       
  3738     iCommonUiHelper->DismissWaitNoteL();
       
  3739     HandleCommandL( EMPXCmdHandleExternalCommand );
       
  3740     if ( aError == KErrNone )
       
  3741         {
       
  3742         // Show confirmation note
       
  3743         if( aPlaylist->IsSupported( KMPXMediaGeneralId ) )
       
  3744             {
       
  3745             iPlaylistId = aPlaylist->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
  3746             }
       
  3747         MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleAddCompletedL iPlaylistId = 0x%x", iPlaylistId.iId1 );
       
  3748         if ( iCurrentPlaylistOp != EMPXOpPLCreating )
       
  3749             {
       
  3750             if( !iTitleWait )
       
  3751                 {
       
  3752                 delete iTitleWait;
       
  3753                 iTitleWait = NULL;
       
  3754                 }
       
  3755             iTitleWait = aPlaylist->ValueText( KMPXMediaGeneralTitle ).AllocL();
       
  3756             if( iDialogDismissed )
       
  3757                 {
       
  3758                 ShowAddedItemsDialogL();
       
  3759                 }
       
  3760             }
       
  3761         else // iCurrentPlaylistOp == EMPXOpPLCreating
       
  3762             {
       
  3763             // Re-open the collection, because we cannot
       
  3764             // depend on the change events that could be a race condition
       
  3765             // against this HandleAddCompleteL() callback!
       
  3766             //
       
  3767             DoIncrementalOpenL();
       
  3768             }
       
  3769         }
       
  3770     else
       
  3771         {
       
  3772         HandleError( aError );
       
  3773         }
       
  3774 
       
  3775     delete aPlaylist;
       
  3776     if ( iContainer )
       
  3777         {
       
  3778         iContainer->ClearLbxSelection();
       
  3779         }
       
  3780     }
       
  3781 
       
  3782 // ---------------------------------------------------------------------------
       
  3783 // Shows the added items dialog
       
  3784 // ---------------------------------------------------------------------------
       
  3785 //
       
  3786 void CMPXCollectionViewHgImp::ShowAddedItemsDialogL()
       
  3787     {
       
  3788     HBufC* confirmTxt( NULL );
       
  3789     
       
  3790     TMPlayerSecondaryDisplayNote noteId( EMPlayerNoteNone );
       
  3791     if ( iNumSongAddedToPlaylist > 1 )
       
  3792         {
       
  3793         
       
  3794         confirmTxt = StringLoader::LoadLC(
       
  3795             R_MPX_QTN_MUS_MULTIPLE_TRACKS_ADDED_TO_PL,
       
  3796             iTitleWait->Des(), iNumSongAddedToPlaylist );
       
  3797         noteId = EMPlayerNoteAddManySongToPlaylist;
       
  3798         }
       
  3799     else
       
  3800         {
       
  3801         confirmTxt = StringLoader::LoadLC(
       
  3802             R_MPX_QTN_MUS_NOTE_TRACK_ADDED_TO_PL, iTitleWait->Des() );
       
  3803         noteId = EMPlayerNoteAddSongToPlaylist;
       
  3804         }
       
  3805     
       
  3806     CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote();
       
  3807 
       
  3808     note->PublishDialogL(
       
  3809         noteId,
       
  3810         KMPlayerNoteCategory );
       
  3811 
       
  3812     if ( iCoverDisplay )
       
  3813         {
       
  3814         CAknMediatorFacade* covercl = AknMediatorFacade( note );
       
  3815         if ( covercl )
       
  3816             {
       
  3817             covercl->BufStream() << iTitleWait;
       
  3818             if ( iNumSongAddedToPlaylist > 1 )
       
  3819                 {
       
  3820                 covercl->BufStream().WriteInt32L( iNumSongAddedToPlaylist );
       
  3821                 }
       
  3822             }
       
  3823         }
       
  3824     note->ExecuteLD( *confirmTxt );
       
  3825     CleanupStack::PopAndDestroy( confirmTxt );
       
  3826 	if( iTitleWait )
       
  3827 	    {
       
  3828 	    delete iTitleWait;
       
  3829 	    iTitleWait = NULL;
       
  3830 		}
       
  3831     }
       
  3832 
       
  3833 // -----------------------------------------------------------------------------
       
  3834 // Handles the completion of setting a media event.
       
  3835 // -----------------------------------------------------------------------------
       
  3836 //
       
  3837 void CMPXCollectionViewHgImp::HandleSetCompletedL( CMPXMedia* aMedia, TInt aError )
       
  3838     {
       
  3839     MPX_FUNC( "CMPXCollectionViewHgImp::HandleSetCompletedL" );
       
  3840     delete aMedia;
       
  3841     if ( aError == KErrNone )
       
  3842         {
       
  3843         // save successful, set flag so that it can't be saved again
       
  3844         MPXTlsHelper::SetNeedSave( EFalse );
       
  3845         }
       
  3846     else
       
  3847         {
       
  3848         if (iContainer->IsInReorderMode())
       
  3849             {
       
  3850             DeactivateReorderGrabbedModeL(ETrue);
       
  3851             }
       
  3852         HandleError( aError );
       
  3853         }
       
  3854     if ( iIsSavingReorderPlaylist )
       
  3855         {
       
  3856         // change messages are ignored during save command,
       
  3857         // when save is complete, it should open the collection again to refresh
       
  3858         // display data
       
  3859         DoIncrementalOpenL();
       
  3860         iIsSavingReorderPlaylist = EFalse;
       
  3861         }
       
  3862     }
       
  3863 
       
  3864 // -----------------------------------------------------------------------------
       
  3865 // Handle playback message
       
  3866 // -----------------------------------------------------------------------------
       
  3867 //
       
  3868 void CMPXCollectionViewHgImp::DoHandlePlaybackMessageL( const CMPXMessage& aMessage )
       
  3869     {
       
  3870     MPX_FUNC( "CMPXCollectionViewHgImp::DoHandlePlaybackMessageL" );
       
  3871     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  3872     if ( KMPXMessageGeneral == id )
       
  3873         {
       
  3874         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  3875         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  3876         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
  3877         switch ( event )
       
  3878             {
       
  3879             case TMPXPlaybackMessage::EActivePlayerChanged:
       
  3880             case TMPXPlaybackMessage::EStateChanged:
       
  3881                 {
       
  3882                 MPX_DEBUG2( "CMPXCollectionViewHgImp::HandlePlaybackMessageL - EStateChanged(%d)", type );
       
  3883                 UpdatePlaybackStatusL();
       
  3884                 break;
       
  3885                 }
       
  3886             case TMPXPlaybackMessage::EError:
       
  3887                 {
       
  3888                 if ( iCommonUiHelper )
       
  3889                     {
       
  3890                     iCommonUiHelper->DismissWaitNoteL();
       
  3891                     HandleCommandL( EMPXCmdHandleExternalCommand );
       
  3892                     }
       
  3893                 if ( iIsDeleting )
       
  3894                     {
       
  3895                     iCollectionUiHelper->Cancel();
       
  3896                     iIsDeleting = EFalse;
       
  3897                     // if delete is interrupted, reopen
       
  3898                     DoIncrementalOpenL();
       
  3899                     }
       
  3900                 MPX_DEBUG2( "CMPXCollectionViewHgImp::HandlePlaybackMessageL Error = %d", data );
       
  3901                 break;
       
  3902                 }
       
  3903             case TMPXPlaybackMessage::EPlayerUnavailable:
       
  3904                 {
       
  3905                 if ( iUpnpFrameworkSupport )
       
  3906                     {
       
  3907                     if ( data == KErrNotFound )
       
  3908                         {
       
  3909                         if ( iViewUtility->ActiveViewType() ==
       
  3910                             TUid::Uid( KMPXPluginTypeCollectionUid ) )
       
  3911                             {
       
  3912                             if ( iSubPlayerName )
       
  3913                                 {
       
  3914                                 HBufC* dialogText = StringLoader::LoadLC( R_MPX_COLLECTION_NOTE_REMOTE_CONNECTION_FAILED,
       
  3915                                                                           *iSubPlayerName );
       
  3916                                 CAknErrorNote* errNote = new(ELeave) CAknErrorNote(ETrue);
       
  3917                                 errNote->SetTimeout(CAknNoteDialog::ELongTimeout);
       
  3918                                 errNote->ExecuteLD( *dialogText );
       
  3919                                 CleanupStack::PopAndDestroy( dialogText );
       
  3920                                 }
       
  3921                             }
       
  3922                         }
       
  3923                     }
       
  3924                 // else we don't show any error note
       
  3925                 break;
       
  3926                 }
       
  3927             default:
       
  3928                 {
       
  3929                 // ignore other messages
       
  3930                 break;
       
  3931                 }
       
  3932             }
       
  3933         // Fix EBLI-7CFE4D press select key very quick cause System Error KErrArgument
       
  3934         if (event != TMPXPlaybackMessage::ECommandReceived)
       
  3935             {
       
  3936             iHandlingKeyEvent = EFalse;
       
  3937             }
       
  3938         }
       
  3939     else
       
  3940         {
       
  3941         iHandlingKeyEvent = EFalse;
       
  3942         }
       
  3943     }
       
  3944 
       
  3945 // -----------------------------------------------------------------------------
       
  3946 // Handle collection message
       
  3947 // -----------------------------------------------------------------------------
       
  3948 //
       
  3949 void CMPXCollectionViewHgImp::DoHandleCollectionMessageL( const CMPXMessage& aMessage )
       
  3950     {
       
  3951     MPX_FUNC( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL" );
       
  3952     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  3953     if ( KMPXMessageGeneral == id )
       
  3954         {
       
  3955         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
  3956         TInt type( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
  3957         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
  3958         MPX_DEBUG4( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL Event = %d, Type() = %d, data = %d",
       
  3959             event, type, data );
       
  3960 
       
  3961         // Only handle collection messages while collection view is in focus
       
  3962         // and not transitioning views
       
  3963         if( iContainer )
       
  3964             {
       
  3965 
       
  3966             if ( event == TMPXCollectionMessage::EPathChanged &&
       
  3967                  type == EMcPathChangedByOpen &&
       
  3968                  data == EMcContainerOpened
       
  3969                  )
       
  3970                 { // Open new entries
       
  3971                 MPX_DEBUG1( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL calling OpenL EMcPathChangedByOpen" );
       
  3972                 if ( iContainer->IsInReorderMode() )
       
  3973                     {
       
  3974                     MPX_DEBUG1( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL canceling reorder mode" );
       
  3975                     // cancel reorder mode if path has changed
       
  3976                     ProcessCommandL( EMPXCmdReorderDone );
       
  3977                     }
       
  3978                 if( iContainer->CurrentSelectionIndicesL()->Count() )
       
  3979                     {
       
  3980                     HandleCommandL( EAknUnmarkAll );
       
  3981                     }
       
  3982 
       
  3983                 // Incremental Open when browsing to the next level
       
  3984                 DoIncrementalOpenL();
       
  3985                 }
       
  3986             else if ( event == TMPXCollectionMessage::EPathChanged &&
       
  3987                       type == EMcPathChangedByCollectionChange )
       
  3988                 {
       
  3989                 // Re-Fetch entries only if we are in playlist
       
  3990                 // creation idle stage. Ignore change messages during playlist op
       
  3991                 // because there are race conditions and we don't know
       
  3992                 // which handle open is actually opening the playlist!
       
  3993                 //
       
  3994                 // don't call openL if it's currently deleting
       
  3995                 // don't call openL if saving after reorder
       
  3996                 // don't call openL if renaming
       
  3997                 if( iCurrentPlaylistOp == EMPXOpPLIdle  && !iIsDeleting
       
  3998                     && !iIsSavingReorderPlaylist && iSetMediaLCount == KErrNotFound )
       
  3999                     {
       
  4000                     MPX_DEBUG1( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL calling OpenL EMcPathChangedByCollectionChange" );
       
  4001                     if( iContainer->CurrentSelectionIndicesL()->Count() )
       
  4002                         {
       
  4003                         HandleCommandL( EAknUnmarkAll );
       
  4004                         }
       
  4005                     // dismiss find pane if it's visible
       
  4006                     if( iContainer->FindBoxVisibility() )
       
  4007                         {
       
  4008                         iContainer->EnableFindBox( EFalse );
       
  4009                         }
       
  4010                     DoIncrementalOpenL();
       
  4011                     }
       
  4012                 else
       
  4013                     {
       
  4014                     MPX_DEBUG4( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL PathChange Message Ignored iIsDeleting = %d, iCurrentPlaylistOp = %d, iIsSavingReorderPlaylist = %d", iIsDeleting, iCurrentPlaylistOp, iIsSavingReorderPlaylist );
       
  4015                     MPX_DEBUG2( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL PathChange Message Ignored iSetMediaLCount = %d", iSetMediaLCount );
       
  4016                     }
       
  4017                 }
       
  4018             else if ( event == TMPXCollectionMessage::EPathChanged &&
       
  4019                  type == EMcPathChangedByOpen &&
       
  4020                  data == EMcItemOpened)
       
  4021                 {
       
  4022                 // opened a song, revert back one level when collection view
       
  4023                 // is activated again
       
  4024                 iIncrementalOpenUtil->Stop();
       
  4025                 iBackOneLevel = ETrue;
       
  4026                 }
       
  4027             else if( event == TMPXCollectionMessage::EBroadcastEvent )
       
  4028                 {
       
  4029                 MPX_DEBUG2( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL - broadcast type = %d", type );
       
  4030                 if ( type == EMcMsgDiskRemoved &&
       
  4031                      iViewUtility->ActiveViewType() != TUid::Uid(KMPXPluginTypeWaitNoteDialogUid) )
       
  4032                     {
       
  4033                     AknDialogShutter::ShutDialogsL( *CEikonEnv::Static() );
       
  4034                     }
       
  4035                 if ( iConfirmationDlg && ( type == EMcMsgUSBMTPStart || type == EMcMsgUSBMassStorageStart ) )
       
  4036                     {
       
  4037                     TKeyEvent kEvent;
       
  4038                     kEvent.iCode = EKeyEscape;
       
  4039                     kEvent.iScanCode = EStdKeyEscape;
       
  4040                     iConfirmationDlg->OfferKeyEventL( kEvent, EEventKey );
       
  4041                     }
       
  4042 
       
  4043                 }
       
  4044         else if ( event == TMPXCollectionMessage::EFocusChanged && iContainer && iCoverDisplay )
       
  4045             {
       
  4046             if ( data != KErrNotFound &&
       
  4047                  data < iContainer->CurrentListItemCount() &&
       
  4048                  !iIgnoreNextFocusChangedMessage )
       
  4049                 {
       
  4050                 MPX_DEBUG2( "CMPXCollectionViewHgImp::DoHandleCollectionMessageL - EFocusChanged to %d", data );
       
  4051                 iContainer->SetLbxCurrentItemIndexAndDraw( data );
       
  4052                 }
       
  4053             iIgnoreNextFocusChangedMessage = EFalse;
       
  4054             }
       
  4055             } // if iContainer
       
  4056 
       
  4057         // System events need to be checked regardless of iContainer
       
  4058         //
       
  4059         if( event == TMPXCollectionMessage::EBroadcastEvent )
       
  4060             {
       
  4061             if((type == EMcMsgUSBMassStorageStart ) || (type == EMcMsgUSBMTPEnd) || (type == EMcMsgRefreshEnd))
       
  4062                 {
       
  4063                 iCollectionCacheReady = EFalse;
       
  4064                 }
       
  4065             if(type == EMcMsgRefreshEnd)
       
  4066                 {
       
  4067                 TInt songAdded = aMessage.ValueTObjectL<TInt>(KMPXMessageGeneralData);
       
  4068                 MPX_DEBUG2("EMcMsgRefreshEnd, songAdded = %d", songAdded);
       
  4069                 if (iPopuponRefresh)
       
  4070                     {   
       
  4071                     iPopuponRefresh =(songAdded > KErrNone)? ETrue:EFalse;
       
  4072                     }
       
  4073      
       
  4074 	            if( NeedToShowEducatingDialog())
       
  4075                     {  
       
  4076                     EducatingUserDialog();
       
  4077                     iPopuponRefresh = EFalse;
       
  4078                     } 
       
  4079                 } 
       
  4080             // USB flags
       
  4081             //
       
  4082 	        CEikMenuBar* menuBar( MenuBar() );
       
  4083 	        TBool IsUSBEvent( EFalse );
       
  4084             if( type == EMcMsgUSBMassStorageStart || type == EMcMsgUSBMTPStart )
       
  4085                 {
       
  4086                 iUSBOnGoing = ETrue;
       
  4087 		        IsUSBEvent = ETrue;
       
  4088                 }
       
  4089             else if( type == EMcMsgUSBMassStorageEnd || type == EMcMsgUSBMTPEnd )
       
  4090                 {
       
  4091                 iUSBOnGoing = EFalse;
       
  4092 		        IsUSBEvent = ETrue;
       
  4093                 RProperty::Set( KMPXViewPSUid,
       
  4094                                 KMPXUSBUnblockingPSStatus,
       
  4095                                 EMPXUSBUnblockingPSStatusUninitialized );
       
  4096                 }
       
  4097             else if( type == EMcMsgUSBMTPNotActive )
       
  4098                 {
       
  4099 		        IsUSBEvent = ETrue;
       
  4100                 RProperty::Set( KMPXViewPSUid,
       
  4101                                 KMPXUSBUnblockingPSStatus,
       
  4102                                 EMPXUSBUnblockingPSStatusActive );
       
  4103 		        }
       
  4104             if( IsUSBEvent && menuBar && menuBar->IsDisplayed() )
       
  4105             	{
       
  4106             	menuBar->StopDisplayingMenuBar();
       
  4107             	}
       
  4108 
       
  4109             if ( iContainer && iIsEmbedded && type == EMcMsgUSBMassStorageEnd )
       
  4110             	{
       
  4111             	DoIncrementalOpenL();
       
  4112             	}
       
  4113             } // if event == EBroadcastEvent
       
  4114         } // if ( KMPXMessageGeneral == id )
       
  4115     }
       
  4116 
       
  4117 // ---------------------------------------------------------------------------
       
  4118 // CMPXCollectionViewHgImp::DoIncrementalOpenL
       
  4119 // Start the incremental fetching algorithm
       
  4120 // ---------------------------------------------------------------------------
       
  4121 //
       
  4122 void CMPXCollectionViewHgImp::DoIncrementalOpenL( TBool aShowWaitDlg )
       
  4123     {
       
  4124      MPX_FUNC( "CMPXCollectionViewHgImp::DoIncrementalOpenL" );
       
  4125     // Show the opening note if > 1.5 seconds
       
  4126     if( aShowWaitDlg )
       
  4127         {
       
  4128         //StartWaitNoteL( EMPXOpeningNote );
       
  4129         }
       
  4130 
       
  4131     // Cancel any reads
       
  4132     iIncrementalOpenUtil->Stop();
       
  4133 
       
  4134     // Start the read
       
  4135     RArray<TMPXAttribute> attrs;
       
  4136     CleanupClosePushL( attrs );
       
  4137     TArray<TMPXAttribute> ary = attrs.Array();
       
  4138     iIncrementalOpenUtil->SetDelay( KIncrementalDelayNone );
       
  4139     iIncrementalOpenUtil->StartL( ary, KIncrementalFetchBlockSize,
       
  4140                                   KErrNotFound, CMPXCollectionOpenUtility::EFetchDown );
       
  4141     iIncrementalOpenUtil->SetDelay( KIncrementalDelayHalfSecond );
       
  4142     CleanupStack::PopAndDestroy( &attrs );
       
  4143 
       
  4144     if (iContainer)
       
  4145      {	 
       
  4146      // Default empty text
       
  4147      iContainer->SetLbxEmptyTextL( KNullDesC );
       
  4148      iContainer->DrawDeferred();
       
  4149      }
       
  4150     iFirstIncrementalBatch = ETrue;
       
  4151     }
       
  4152 
       
  4153 // -----------------------------------------------------------------------------
       
  4154 // Start wait note for delayed action due to the items not ready
       
  4155 // -----------------------------------------------------------------------------
       
  4156 //
       
  4157 void CMPXCollectionViewHgImp::StartDelayedActionL(
       
  4158     TInt aCommand, TDesC& aNote,TBool aSkipDisplay  )
       
  4159     {
       
  4160     MPX_FUNC( "CMPXCollectionViewHgImp::StartDelayedActionL" );
       
  4161     HandleCommandL( EMPXCmdIgnoreExternalCommand );
       
  4162     if(!aSkipDisplay)
       
  4163         {
       
  4164     	iCommonUiHelper->ShowWaitNoteL( aNote, R_AVKON_SOFTKEYS_EMPTY, ETrue, this );
       
  4165         }
       
  4166 
       
  4167     iCachedCommand = aCommand;
       
  4168     const CArrayFix<TInt>* array (
       
  4169         iContainer->CurrentSelectionIndicesL() ); // not owned
       
  4170     TInt arrayCount( array->Count() );
       
  4171     iCachedSelectionIndex->Reset();
       
  4172     for ( TInt i = 0; i < arrayCount; i++ )
       
  4173         {
       
  4174         iCachedSelectionIndex->AppendL( array->At( i ) );
       
  4175         }
       
  4176     }
       
  4177 
       
  4178 // ---------------------------------------------------------------------------
       
  4179 // From MProgressDialogCallback
       
  4180 // Callback method. Get's called when a dialog is dismissed
       
  4181 // ---------------------------------------------------------------------------
       
  4182 //
       
  4183 void CMPXCollectionViewHgImp::DialogDismissedL( TInt aButtonId )
       
  4184     {
       
  4185     iDialogDismissed = ETrue;
       
  4186     MPX_FUNC( "CMPXCollectionViewHgImp::DialogDismissedL" );
       
  4187     if ( iCommandInitiator )
       
  4188         {
       
  4189         iCommandInitiator->CancelCommand( KMediatorSecondaryDisplayDomain,
       
  4190                                       KMPlayerNoteCategory,
       
  4191                                       iWaitNoteId );
       
  4192         }
       
  4193 
       
  4194     switch ( aButtonId )
       
  4195         {
       
  4196         case EAknSoftkeyCancel:
       
  4197             {
       
  4198             iIsWaitNoteCanceled = ETrue;
       
  4199             if( iIsDeleting )
       
  4200                 {
       
  4201                 iCollectionUiHelper->Cancel();
       
  4202                 iIsDeleting = EFalse;
       
  4203                 // if delete is interrupted, reopen
       
  4204                 }
       
  4205             else if ( iSetMediaLCount > 0 )
       
  4206                 {
       
  4207                 // cancel the async request
       
  4208                 iCollectionUtility->Collection().CancelRequest();
       
  4209                 iSetMediaLCount = KErrNotFound;
       
  4210 
       
  4211                 DoIncrementalOpenL();
       
  4212                 }
       
  4213             else if ( iIsAddingToPlaylist )
       
  4214                 {
       
  4215                 // cancel incremental adding of songs
       
  4216                 iCommonUiHelper->CancelCollectionOperation();
       
  4217                 iIsAddingToPlaylist = EFalse;
       
  4218                 }
       
  4219             break;
       
  4220             }
       
  4221         case EAknSoftkeyDone:
       
  4222             {
       
  4223             // Double check that we should be showing the dialog
       
  4224             if( iTitleWait )
       
  4225                 {
       
  4226                 ShowAddedItemsDialogL();
       
  4227                 }
       
  4228             break;
       
  4229             }
       
  4230         default:
       
  4231             {
       
  4232             // no special handling for other cases
       
  4233             break;
       
  4234             }
       
  4235         }
       
  4236     }
       
  4237 
       
  4238 // ---------------------------------------------------------------------------
       
  4239 // From MMPXCollectionObserver
       
  4240 // Handle collection message
       
  4241 // ---------------------------------------------------------------------------
       
  4242 //
       
  4243 void CMPXCollectionViewHgImp::HandleCollectionMessage(
       
  4244     CMPXMessage* aMessage, TInt aError )
       
  4245     {
       
  4246     if ( aError == KErrNone && aMessage )
       
  4247         {
       
  4248         TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) );
       
  4249         }
       
  4250     }
       
  4251 
       
  4252 // ---------------------------------------------------------------------------
       
  4253 // From MMPXCollectionObserver
       
  4254 // Handles the collection entries being opened. Typically called
       
  4255 // when client has Open()'d a folder
       
  4256 // ---------------------------------------------------------------------------
       
  4257 //
       
  4258 void CMPXCollectionViewHgImp::HandleOpenL(
       
  4259     const CMPXMedia& aEntries,
       
  4260     TInt aIndex,
       
  4261     TBool aComplete,
       
  4262     TInt aError )
       
  4263     {
       
  4264     MPX_FUNC( "CMPXCollectionViewHgImp::HandleOpenL 4" );
       
  4265     iHandlingKeyEvent = EFalse;
       
  4266     if( aError == KErrNone )
       
  4267         {
       
  4268         if ( !iContainer )
       
  4269             {
       
  4270             // View is not active. Ignore.
       
  4271             return;
       
  4272             }
       
  4273     #ifdef BACKSTEPPING_INCLUDED
       
  4274         // handle deferred notification when view is in focus but not for view transitions
       
  4275         if ( iActivateBackStepping )
       
  4276             {
       
  4277 	        HandleBacksteppingActivation();
       
  4278 		    }
       
  4279 	#endif // BACKSTEPPING_INCLUDED
       
  4280 
       
  4281         iCollectionReady = aComplete;
       
  4282 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  4283         if( iPodcast && !iDisablePodcasting )
       
  4284             {
       
  4285             iPodcast = EFalse;
       
  4286             UpdateListBoxL( aEntries, KMusicMenuPodcastMenuItemIndex, aComplete );
       
  4287             ( void ) aIndex;
       
  4288             }
       
  4289         else
       
  4290             {
       
  4291             TInt topIndex = aIndex;
       
  4292             if ( iFirstIndexOnScreen > 0 )
       
  4293                 {
       
  4294                 topIndex = iFirstIndexOnScreen;
       
  4295                 if ( aComplete )
       
  4296                     {
       
  4297                     iFirstIndexOnScreen = 0;
       
  4298                     }
       
  4299                 }
       
  4300             UpdateListBoxL( aEntries, topIndex, aComplete );            
       
  4301             }
       
  4302 #else
       
  4303         UpdateListBoxL( aEntries, aIndex, aComplete );
       
  4304 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  4305         if ( iContainer )
       
  4306             {
       
  4307             iContainer->ContentIsReady( ETrue );
       
  4308             // this has to be done after the list box media is properly
       
  4309             // updated
       
  4310             if ( !iContainer->FindBoxVisibility() )
       
  4311                 {
       
  4312                 MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleOpenL find box not visible" );
       
  4313 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  4314                 CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  4315                 CleanupStack::PushL( cpath );
       
  4316 
       
  4317                 CMPXCommonListBoxArrayBase* listboxArray(
       
  4318                     iContainer->ListBoxArray() );
       
  4319                 const CMPXMedia& media( listboxArray->ContainerMedia() );
       
  4320 
       
  4321                 TMPXGeneralType containerType( EMPXNoType );
       
  4322                 if ( media.IsSupported( KMPXMediaGeneralType ) )
       
  4323                     {
       
  4324                     containerType = media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType );
       
  4325                     }
       
  4326 
       
  4327                 TMPXGeneralCategory containerCategory( EMPXNoCategory );
       
  4328                 if ( media.IsSupported( KMPXMediaGeneralCategory ) )
       
  4329                     {
       
  4330                     containerCategory = media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
  4331                     }
       
  4332                 TBool landscapeOrientation = Layout_Meta_Data::IsLandscapeOrientation();
       
  4333                 CEikButtonGroupContainer* cba = Cba();
       
  4334                 if ( cba && containerType == EMPXGroup && containerCategory == EMPXAlbum && landscapeOrientation )
       
  4335                     {
       
  4336                     cba->SetCommandSetL( R_MPX_COLLECTION_TRANSPARENT_CBA );
       
  4337                     cba->MakeVisible( EFalse );
       
  4338 					cba->DrawDeferred();
       
  4339                     }
       
  4340                 else if ( cba )
       
  4341                     {
       
  4342                     if ( iContainer->IsTBoneView() )
       
  4343                         {
       
  4344                         cba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  4345                         }
       
  4346                     else
       
  4347                         {
       
  4348                         cba->SetCommandSetL(
       
  4349                             ( cpath->Levels() == 3 && !iIsEmbedded ) ?
       
  4350                             R_MPX_OPTIONS_HIDE_CBA : R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  4351                         }
       
  4352                     cba->MakeVisible( ETrue );
       
  4353                     cba->DrawDeferred();
       
  4354                     }
       
  4355 
       
  4356                 CleanupStack::PopAndDestroy(cpath);
       
  4357 #else
       
  4358                 CEikButtonGroupContainer* cba = Cba();
       
  4359                 if ( cba )
       
  4360                     {
       
  4361                     cba->SetCommandSetL(
       
  4362                         ( iViewUtility->ViewHistoryDepth() == 1 && !iIsEmbedded ) ?
       
  4363                         R_AVKON_SOFTKEYS_OPTIONS_EXIT : R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  4364                     cba->DrawDeferred();
       
  4365                     }
       
  4366 #endif
       
  4367                 }
       
  4368             else
       
  4369                 {
       
  4370                 MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleOpenL find box visible" );
       
  4371                 }
       
  4372 
       
  4373             CMPXCommonListBoxArrayBase* array(
       
  4374                 iContainer->ListBoxArray() );
       
  4375             const CMPXMedia& containerMedia = array->ContainerMedia();
       
  4376             if ( containerMedia.IsSupported( KMPXMediaGeneralTitle ) )
       
  4377                 {
       
  4378                 delete iTitle;
       
  4379                 iTitle = NULL;
       
  4380                 iTitle = containerMedia.ValueText( KMPXMediaGeneralTitle ).AllocL();
       
  4381                 }
       
  4382             if ( !iContainer->IsInReorderMode() &&
       
  4383                 !iAddingSong &&
       
  4384                 !iInAlbumArtDialog &&
       
  4385                 !iInSongDetails && !iContainer->IsTBoneView())
       
  4386                 {
       
  4387                 UpdateTitlePaneL();
       
  4388                 }
       
  4389 
       
  4390             TMPXGeneralType containerType( EMPXNoType );
       
  4391             if( containerMedia.IsSupported( KMPXMediaGeneralType ) )
       
  4392                 {
       
  4393                 containerType = containerMedia.ValueTObjectL<TMPXGeneralType>(
       
  4394                                 KMPXMediaGeneralType );
       
  4395                 }
       
  4396 
       
  4397             TMPXGeneralCategory containerCategory( EMPXNoCategory );
       
  4398             if( containerMedia.IsSupported( KMPXMediaGeneralCategory ) )
       
  4399                 {
       
  4400                 containerCategory = containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
  4401                                     KMPXMediaGeneralCategory );
       
  4402                 }
       
  4403             MPX_DEBUG3( "CMPXCollectionViewHgImp::HandleOpenL container type = %d, category = %d", containerType, containerCategory );
       
  4404 
       
  4405             CEikMenuBar* menuBar( MenuBar() );
       
  4406             TInt resId( KErrNotFound );
       
  4407 #ifdef __ENABLE_MSK
       
  4408             TInt mskId( R_QTN_MSK_OPEN );
       
  4409 #endif // __ENABLE_MSK
       
  4410             if ( iIsEmbedded )
       
  4411                 {
       
  4412                 // embedded playlist view
       
  4413                 iContainer->EnableMarking( ETrue );
       
  4414                 menuBar->SetMenuTitleResourceId( R_MPX_COLLECTION_VIEW_MENUBAR_EMBEDDED_PLAYLIST_VIEW );
       
  4415                 resId = R_MPX_VMP_NO_SONGS;
       
  4416 #ifdef __ENABLE_MSK
       
  4417                 mskId = R_QTN_MSK_PLAY;
       
  4418 #endif // __ENABLE_MSK
       
  4419                 }
       
  4420             else
       
  4421                 {
       
  4422                 if ( containerType == EMPXGroup && containerCategory == EMPXCollection )
       
  4423                     {
       
  4424                     // music menu view
       
  4425                     iContainer->EnableMarking( EFalse );
       
  4426                     menuBar->SetMenuTitleResourceId( R_MPX_COLLECTION_VIEW_MENUBAR_MUSIC_MENU );
       
  4427                     }
       
  4428                 else if ( ( containerType == EMPXGroup && containerCategory == EMPXPlaylist ) || // playlist view
       
  4429                     ( containerType == EMPXGroup && containerCategory == EMPXArtist ) || // artist view
       
  4430                     ( containerType == EMPXItem && containerCategory == EMPXArtist ) || // artist/album view
       
  4431                     ( containerType == EMPXGroup && containerCategory == EMPXAlbum ) || // album view
       
  4432                     ( containerType == EMPXGroup && containerCategory == EMPXGenre ) || // genre view
       
  4433                     ( containerType == EMPXGroup && containerCategory == EMPXComposer ) ) // composer view
       
  4434                     {
       
  4435                     iContainer->EnableMarking( EFalse );
       
  4436                     menuBar->SetMenuTitleResourceId( R_MPX_COLLECTION_VIEW_MENUBAR_NO_MARKING );
       
  4437                     switch ( containerCategory )
       
  4438                         {
       
  4439                         case EMPXArtist:
       
  4440                             {
       
  4441                             if ( containerType == EMPXGroup )
       
  4442                                 {
       
  4443                                 // artist view
       
  4444                                 resId = R_MPX_COLLECTION_ARTIST_LBX_EMPTYTEXT;
       
  4445                                 }
       
  4446                             else if ( containerType == EMPXItem )
       
  4447                                 {
       
  4448                                 // artist/album view
       
  4449                                 resId = R_MPX_COLLECTION_ALBUM_LBX_EMPTYTEXT;
       
  4450                                 }
       
  4451                             else
       
  4452                                 {
       
  4453                                 // should not reach here
       
  4454                                 ASSERT( 0 );
       
  4455                                 }
       
  4456                             break;
       
  4457                             }
       
  4458                         case EMPXAlbum:
       
  4459                             {
       
  4460                             // album view
       
  4461                             resId = R_MPX_VMP_NO_ALBUMS;
       
  4462                             break;
       
  4463                             }
       
  4464                         case EMPXGenre:
       
  4465                             {
       
  4466                             // genre view
       
  4467                             resId = R_MPX_VMP_NO_GENRES;
       
  4468                             break;
       
  4469                             }
       
  4470                         case EMPXPlaylist:
       
  4471                             {
       
  4472                             // no special handling for playlist
       
  4473                             break;
       
  4474                             }
       
  4475                         default:
       
  4476                             {
       
  4477                             // should not reach here
       
  4478                             ASSERT( 0 );
       
  4479                             break;
       
  4480                             }
       
  4481                         }
       
  4482                     }
       
  4483                 else
       
  4484                     {
       
  4485                     // tracks view
       
  4486                     iContainer->EnableMarking( EFalse );
       
  4487                     menuBar->SetMenuTitleResourceId( R_MPX_COLLECTION_VIEW_MENUBAR_NO_MARKING );
       
  4488                     resId = R_MPX_VMP_NO_SONGS;
       
  4489 #ifdef __ENABLE_MSK
       
  4490                     mskId = R_QTN_MSK_PLAY;
       
  4491 #endif // __ENABLE_MSK
       
  4492                     }
       
  4493                 }
       
  4494 
       
  4495             if ( resId != KErrNotFound )
       
  4496                 {
       
  4497                 HBufC* emptyText = StringLoader::LoadLC( resId );
       
  4498                 iContainer->SetLbxEmptyTextL( *emptyText );
       
  4499                 CleanupStack::PopAndDestroy( emptyText );
       
  4500                 iContainer->DrawDeferred();
       
  4501                 }
       
  4502 
       
  4503 #ifdef __ENABLE_MSK
       
  4504             // set middle softkey label display
       
  4505             UpdateMiddleSoftKeyDisplayL( mskId );
       
  4506 #endif // __ENABLE_MSK
       
  4507 
       
  4508             switch ( iCurrentPlaylistOp )
       
  4509                 {
       
  4510                 case EMPXOpPLCreating:
       
  4511                     {
       
  4512                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleOpenL searching for playlist" );
       
  4513                     // after creating a new playlist
       
  4514                     // playlist created callback will always come before this
       
  4515                     // iPlaylistId should have already been set, check to see if
       
  4516                     // we're in playlist view
       
  4517                     if ( iPlaylistId != 0 &&
       
  4518                         containerType == EMPXGroup && containerCategory == EMPXPlaylist )
       
  4519                         {
       
  4520                         const CMPXMediaArray& mediaArray = array->MediaArray();
       
  4521                         TInt arrayCount( mediaArray.Count() );
       
  4522                         for ( TInt i = 0; i < arrayCount; i++ )
       
  4523                             {
       
  4524                             CMPXMedia* origMedia( mediaArray.AtL( i ) );
       
  4525                             TMPXItemId plId = origMedia->ValueTObjectL<TMPXItemId>(
       
  4526                                 KMPXMediaGeneralId );
       
  4527                             if ( plId == iPlaylistId )
       
  4528                                 {
       
  4529                                 MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleOpenL Playlist match found 0x%x", iPlaylistId.iId1 );
       
  4530                                 iCurrentPlaylistOp = EMPXOpPlOpening;
       
  4531                                 iContainer->SetLbxCurrentItemIndex( i );
       
  4532                                 HandleListBoxEventL( NULL, // not used
       
  4533                                     EEventEnterKeyPressed );
       
  4534                                 break;
       
  4535                                 }
       
  4536 
       
  4537                             // Stay in Creating state as every OpenL()
       
  4538                             // will be called back with a HandleOpenL()
       
  4539                             // During playlist creation, there is a race condition
       
  4540                             // between HandleCollectionMessage() -> Collection change -> OpenL()
       
  4541                             // and playlist added's  OpenL()
       
  4542                             }
       
  4543                         }
       
  4544                     break;
       
  4545                     }
       
  4546                 case EMPXOpPlOpening:
       
  4547                     {
       
  4548                     // check how many songs are stored in collection
       
  4549                     iCurrentMediaLOp = EMPXOpMediaLNewPlaylistCollectionSongCount;
       
  4550                     CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  4551                     CleanupStack::PushL( path );
       
  4552                     path->Back();
       
  4553                     RArray<TMPXAttribute> attrs;
       
  4554                     CleanupClosePushL( attrs );
       
  4555                     attrs.Append( KMPXMediaColDetailNumberOfItems );
       
  4556                     iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  4557                     CleanupStack::PopAndDestroy( &attrs );
       
  4558                     CleanupStack::PopAndDestroy( path );
       
  4559                     iCurrentPlaylistOp = EMPXOpPLIdle;
       
  4560                     break;
       
  4561                     }
       
  4562                 case EMPXOpPLIdle: // fall through
       
  4563                 default:
       
  4564                     {
       
  4565                     // Update Duration
       
  4566                     //
       
  4567                     if ( !iContainer->IsInReorderMode() && !iAddingSong )
       
  4568                         {
       
  4569                         GetDurationL();
       
  4570                         }
       
  4571                     break;
       
  4572                     }
       
  4573                 }
       
  4574             iPlaylistId = 0;
       
  4575             }
       
  4576         }
       
  4577     else
       
  4578         {
       
  4579         if ( iContainer )
       
  4580             {
       
  4581 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  4582             CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  4583             CleanupStack::PushL( cpath );
       
  4584 
       
  4585             // media is not valid until the first HandleOpenL call
       
  4586             CEikButtonGroupContainer* cba = Cba();
       
  4587             if ( cba )
       
  4588                 {
       
  4589                 cba->SetCommandSetL(
       
  4590                     ( cpath->Levels() == 2 && !iIsEmbedded ) ?
       
  4591                     R_AVKON_SOFTKEYS_OPTIONS_BACK : R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  4592                 cba->DrawDeferred();
       
  4593                 }
       
  4594 
       
  4595             CleanupStack::PopAndDestroy(cpath);
       
  4596 #else
       
  4597             CEikButtonGroupContainer* cba = Cba();
       
  4598             if ( cba )
       
  4599                 {
       
  4600                 cba->SetCommandSetL(
       
  4601                     ( iViewUtility->ViewHistoryDepth() == 1 && !iIsEmbedded ) ?
       
  4602                     R_AVKON_SOFTKEYS_OPTIONS_EXIT : R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  4603                 cba->DrawDeferred();
       
  4604                 }
       
  4605 
       
  4606 #endif
       
  4607             }
       
  4608         if (aError == KErrNotFound)
       
  4609             {
       
  4610             HandleCommandL(EAknSoftkeyBack);
       
  4611             }
       
  4612         else
       
  4613             {
       
  4614             HandleError( aError );
       
  4615             }
       
  4616         }
       
  4617     if ( iIsDeleting )
       
  4618         {
       
  4619         // nothing else to delete
       
  4620         iIsDeleting = EFalse;
       
  4621         if ( iWaitDialog )
       
  4622             {
       
  4623             iWaitDialog->ProcessFinishedL();
       
  4624             }
       
  4625         HandleCommandL( EMPXCmdHandleExternalCommand );
       
  4626         }
       
  4627     if ( iPlayIndex > KErrNotFound )
       
  4628         {
       
  4629         CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  4630         CleanupStack::PushL( cpath );
       
  4631         cpath->Set( iPlayIndex );
       
  4632         iPlayIndex = KErrNotFound;
       
  4633         iCollectionUtility->Collection().OpenL( *cpath, EMPXOpenPlaylistOnly );
       
  4634         iFirstIncrementalBatch = ETrue;
       
  4635         CleanupStack::PopAndDestroy( cpath );
       
  4636         }
       
  4637     if ( ( iCachedCommand != KErrNotFound ) && iCollectionReady )
       
  4638         {
       
  4639         if((iCachedCommand != EMPXCmdRemove) && (iCachedCommand != EMPXCmdCommonDelete) && (iCachedCommand != EMPXCmdDelete) )
       
  4640             {
       
  4641         iCommonUiHelper->DismissWaitNoteL();
       
  4642         HandleCommandL( EMPXCmdHandleExternalCommand );
       
  4643             }
       
  4644         else
       
  4645             {
       
  4646             iCachedCommand = EMPXCmdRemove;
       
  4647             }
       
  4648         if( iContainer )
       
  4649             {
       
  4650             iContainer->SetCurrentSelectionIndicesL( iCachedSelectionIndex );
       
  4651             }
       
  4652         HandleCommandL( iCachedCommand );
       
  4653         iCachedSelectionIndex->Reset();
       
  4654         iCachedCommand = KErrNotFound;
       
  4655         }
       
  4656 
       
  4657     // Close the opening wait note, if the current item is valid or all open completes
       
  4658     if ( iContainer && !aComplete )
       
  4659         {
       
  4660         // if the list is empty, it shouldn't go in this path as aComplete should be ETrue
       
  4661         CMPXCommonListBoxArrayBase* listboxArray(
       
  4662             iContainer->ListBoxArray() );
       
  4663         const CMPXMedia& currentMedia( listboxArray->MediaL( aIndex ) );
       
  4664         }
       
  4665     else
       
  4666         {
       
  4667         if ( EMPXOpeningNote == iNoteType || EMPXImmediatelyOpeningNote == iNoteType )
       
  4668             {
       
  4669             CloseWaitNoteL();
       
  4670             }
       
  4671         }
       
  4672 
       
  4673     MPX_PERF_CHECKPT("Collection View opened");
       
  4674     }
       
  4675 
       
  4676 // ---------------------------------------------------------------------------
       
  4677 // From MMPXCollectionObserver
       
  4678 // Handles the collection entries being opened.
       
  4679 // ---------------------------------------------------------------------------
       
  4680 //
       
  4681 void CMPXCollectionViewHgImp::HandleOpenL(
       
  4682     const CMPXCollectionPlaylist& /*aPlaylist*/,
       
  4683     TInt /*aError*/ )
       
  4684     {
       
  4685     MPX_FUNC( "CMPXCollectionViewHgImp::HandleOpenL 2" );
       
  4686     iHandlingKeyEvent = EFalse;
       
  4687     // Do Nothing: playback/fetch client should handle this stage
       
  4688     }
       
  4689 
       
  4690 // ---------------------------------------------------------------------------
       
  4691 // From MMPXCollectionObserver
       
  4692 // Handle media properties
       
  4693 // ---------------------------------------------------------------------------
       
  4694 //
       
  4695 void CMPXCollectionViewHgImp::HandleCollectionMediaL(
       
  4696     const CMPXMedia& aMedia,
       
  4697     TInt aError)
       
  4698     {
       
  4699     MPX_FUNC( "CMPXCollectionViewHgImp::HandleCollectionMediaL" );
       
  4700 
       
  4701     TInt nextMediaLOp( EMPXOpMediaLIdle );
       
  4702     if ( aError == KErrNone )
       
  4703         {
       
  4704         switch ( iCurrentMediaLOp )
       
  4705             {
       
  4706             case EMPXOpMediaLGetContainerInfo:
       
  4707                 {
       
  4708                 delete iDuration;
       
  4709                 iDuration = NULL;
       
  4710                 if ( aMedia.IsSupported( KMPXMediaGeneralDuration ) )
       
  4711                     {
       
  4712                     TInt duration(
       
  4713                         aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) );
       
  4714                     if ( duration > 0 )
       
  4715                         {
       
  4716                         // only display duration when the list contains something
       
  4717                         iDuration = iCommonUiHelper->DisplayableDurationInTextL( duration/KMilliSecondsToSeconds );
       
  4718                         }
       
  4719                     }
       
  4720                 break;
       
  4721                 }
       
  4722             case EMPXOpMediaLSend:
       
  4723                 {
       
  4724                 DoHandleSendL( aMedia );
       
  4725                 if ( !iContainer->FindBoxVisibility() )
       
  4726                     {
       
  4727                     iContainer->RestoreFindBoxPopupCBA();
       
  4728                     }
       
  4729                 break;
       
  4730                 }
       
  4731             case EMPXOpMediaLSongDetailsFileCheck:
       
  4732                 {
       
  4733                 if ( iContainer )
       
  4734                     {
       
  4735                     DoHandleFileCheckResultL(
       
  4736                         TUid::Uid( KMPXPluginTypeMetadataEditorUid ), aMedia );
       
  4737                     if ( !iContainer->FindBoxVisibility() )
       
  4738                         {
       
  4739                         iContainer->RestoreFindBoxPopupCBA();
       
  4740                         }
       
  4741                     }
       
  4742                 break;
       
  4743                 }
       
  4744             case EMPXOpMediaLAlbumArtFileCheck:
       
  4745                 {
       
  4746                 if ( iContainer )
       
  4747                     {
       
  4748                     DoHandleFileCheckResultL(
       
  4749                         TUid::Uid( KMPXPluginTypeAlbumArtEditorUid ), aMedia );
       
  4750 
       
  4751                     if ( !iContainer->FindBoxVisibility() )
       
  4752                         {
       
  4753                         iContainer->RestoreFindBoxPopupCBA();
       
  4754                         }
       
  4755                     }
       
  4756                 break;
       
  4757                 }
       
  4758             case EMPXOpMediaLCollectionDetails:
       
  4759                 {
       
  4760                 DoShowCollectionDetailsL( aMedia );
       
  4761                 break;
       
  4762                 }
       
  4763             case EMPXOpMediaLPlaylistDetails:
       
  4764                 {
       
  4765                 DoShowPlaylistDetailsL( aMedia );
       
  4766                 break;
       
  4767                 }
       
  4768             case EMPXOpMediaLRenamePlaylist:
       
  4769                 {
       
  4770                 DoHandleRenamePlaylistL( aMedia );
       
  4771                 break;
       
  4772                 }
       
  4773             case EMPXOpMediaLNewPlaylistCollectionSongCount:
       
  4774                 {
       
  4775                 TInt songsCount( 0 );
       
  4776                 if ( aMedia.IsSupported( KMPXMediaColDetailNumberOfItems ) )
       
  4777                     {
       
  4778                     songsCount =
       
  4779                         aMedia.ValueTObjectL<TInt>( KMPXMediaColDetailNumberOfItems );
       
  4780                     }
       
  4781                 if ( songsCount > 0 )
       
  4782                     {
       
  4783                     // show add songs prompt only if collection contains
       
  4784                     // at least one song
       
  4785                     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleCollectionMediaL openning add songs view, collection contains %d songs", songsCount );
       
  4786                     CAknQueryDialog* confirmationDlg = CAknQueryDialog::NewL(
       
  4787                         CAknQueryDialog::EConfirmationTone );
       
  4788                     CleanupStack::PushL( confirmationDlg );
       
  4789                     HBufC* promptTxt = StringLoader::LoadLC(
       
  4790                         R_MPX_QTN_NMP_QUERY_ADD_SONGS );
       
  4791                     confirmationDlg->SetPromptL( *promptTxt );
       
  4792                     CleanupStack::PopAndDestroy( promptTxt );
       
  4793                     confirmationDlg->PublishDialogL(
       
  4794                         EMPlayerQueryAddSongsToPlaylist,
       
  4795                         KMPlayerNoteCategory);
       
  4796                     CleanupStack::Pop( confirmationDlg );
       
  4797                     AppUi()->StopDisplayingMenuBar();
       
  4798                     if ( confirmationDlg->ExecuteLD( R_MPX_CUI_ADD_SONGS_CONFIRMATION_QUERY ) )
       
  4799                         {
       
  4800                         HandleCommandL( EMPXCmdAddSongs );
       
  4801                         iCurrentMediaLOp = EMPXOpMediaLNewPlaylistCollectionSongCount;
       
  4802                         }
       
  4803                     }
       
  4804 #ifdef _DEBUG
       
  4805                 else
       
  4806                     {
       
  4807                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleCollectionMediaL collection empty, not opening add songs view" );
       
  4808                     }
       
  4809 #endif // _DEBUG
       
  4810                 break;
       
  4811                 }
       
  4812             case EMPXOpMediaLCopyToRemote:
       
  4813                 {
       
  4814                 if ( iUpnpFrameworkSupport )
       
  4815                     {
       
  4816                     DoHandleCopyToRemoteL( aMedia );
       
  4817                     }
       
  4818                 break;
       
  4819                 }
       
  4820 
       
  4821             case EMPXOpMediaLFindInMusicShopSongDetails:
       
  4822                 {
       
  4823                 const TDesC& location = aMedia.ValueText( KMPXMediaGeneralUri );
       
  4824                 if ( location != KNullDesC && ConeUtils::FileExists( location ) )
       
  4825                     {
       
  4826                     HBufC* buf = HBufC::NewLC( 5 ); // magic number to hold index value
       
  4827                     buf->Des().AppendNum(
       
  4828                         iContainer->CurrentLbxItemIndex() );
       
  4829                     // set current list box index
       
  4830                     SetParamL( buf );
       
  4831                     CleanupStack::PopAndDestroy( buf );
       
  4832 
       
  4833                     DoGetSongMediaPropertyL();
       
  4834                     // Set the next operation to handle MediaL completed.
       
  4835                     nextMediaLOp = EMPXOpMediaLFindInMusicShopMediaLCompleted;
       
  4836                     }
       
  4837                 else
       
  4838                     {
       
  4839                     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  4840                     CleanupStack::PushL( cpath );
       
  4841                     TInt currentDepth( cpath->Levels() );
       
  4842                     CleanupStack::PopAndDestroy( cpath );
       
  4843                     CMPXCommonListBoxArrayBase* listboxArray =
       
  4844                         iContainer->ListBoxArray();
       
  4845                     TInt currentIndex =
       
  4846                         iContainer->CurrentLbxItemIndex();
       
  4847                     const CMPXMedia& currentMedia = listboxArray->MediaL( currentIndex );
       
  4848                     TMPXGeneralCategory category(
       
  4849                         currentMedia.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  4850                     const CMPXMediaArray& mediaAry( listboxArray->MediaArray() );
       
  4851                     CMPXMedia* origMedia( mediaAry.AtL( currentIndex ) );
       
  4852                     const TDesC& title( origMedia->ValueText( KMPXMediaGeneralTitle ) );
       
  4853                     if ( ( title.Length() > 0 ) && ( title.Length() < KMaxFileName ) )
       
  4854                         {
       
  4855                         switch ( category )
       
  4856                             {
       
  4857                             case EMPXAlbum:
       
  4858                                 {
       
  4859                                 const CMPXMedia& containerMedia = listboxArray->ContainerMedia();
       
  4860                                 // The Artist/Album View Title shows the Artist name
       
  4861                                 const TDesC& titleArtist =
       
  4862                                         containerMedia.ValueText( KMPXMediaGeneralTitle );
       
  4863                                 HBufC* unknownArtistText =
       
  4864                                         StringLoader::LoadLC( R_MPX_QTN_NMP_UNKNOWN_ARTIST );
       
  4865                                 // 4 is the level of Artist and Album View
       
  4866                                 if ( currentDepth == 4 && titleArtist != unknownArtistText->Des() )
       
  4867                                     {
       
  4868                                     DoFindInMusicShopL(KCategoryEmpty, titleArtist, title); // Artist and Album View
       
  4869                                     }
       
  4870                                 else
       
  4871                                     {
       
  4872                                     DoFindInMusicShopL(KCategoryEmpty, KCategoryEmpty, title); // Album View
       
  4873                                     }
       
  4874                                 CleanupStack::PopAndDestroy( unknownArtistText );
       
  4875                                 break;
       
  4876                                 }
       
  4877                             case EMPXArtist:
       
  4878                                 {
       
  4879                                 DoFindInMusicShopL(KCategoryEmpty, title, KCategoryEmpty);  // Artist only
       
  4880                                 break;
       
  4881                                 }
       
  4882                             case EMPXSong:
       
  4883                                 {
       
  4884                                 DoFindInMusicShopL(title, KCategoryEmpty, KCategoryEmpty);  // Song only
       
  4885                                 break;
       
  4886                                 }
       
  4887                             default:
       
  4888                                 {
       
  4889                                 break;
       
  4890                                 }
       
  4891                             } // switch
       
  4892                         } // if
       
  4893                     }  // else
       
  4894                 break;
       
  4895                 }
       
  4896             case EMPXOpMediaLFindInMusicShopMediaLCompleted:
       
  4897                 {
       
  4898                 // call DoFindInMusicShop when SongName, AlbumName, and ArtistName are
       
  4899                 // available at this point
       
  4900                 DoFindInMusicShopL(
       
  4901                     aMedia.ValueText( KMPXMediaGeneralTitle ),
       
  4902                     aMedia.ValueText( KMPXMediaMusicArtist ),
       
  4903                     aMedia.ValueText( KMPXMediaMusicAlbum ) );
       
  4904                 break;
       
  4905                 }
       
  4906 
       
  4907             default:
       
  4908                 {
       
  4909                 break;
       
  4910                 }
       
  4911             }
       
  4912         }
       
  4913     else
       
  4914         {
       
  4915         /* If a Composer,Artist or Album consists single song.
       
  4916          * On changing the song details(composer+genre or album name+genre)
       
  4917          * No more record exist corresponding to previous data.
       
  4918          * In this case no need to show Error Message. */
       
  4919         if( aError != KErrNotFound)
       
  4920             {
       
  4921             HandleError( aError );
       
  4922             }
       
  4923         else
       
  4924             {
       
  4925             MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleCollectionMediaL ERROR: %d",aError);
       
  4926             }
       
  4927         }
       
  4928     if ( iCurrentMediaLOp == EMPXOpMediaLNewPlaylistCollectionSongCount )
       
  4929         {
       
  4930         iCurrentMediaLOp = EMPXOpMediaLGetContainerInfo;
       
  4931         }
       
  4932     else
       
  4933         {
       
  4934         iCurrentMediaLOp = nextMediaLOp;
       
  4935         }
       
  4936     }
       
  4937 
       
  4938 // ---------------------------------------------------------------------------
       
  4939 // From MMPXCollectionHelperObserver
       
  4940 // Callback function after executing a command
       
  4941 // ---------------------------------------------------------------------------
       
  4942 //
       
  4943 void CMPXCollectionViewHgImp::HandleCommandComplete(CMPXCommand* /*aCommandResult*/,
       
  4944                                                   TInt /*aError*/)
       
  4945     {
       
  4946     // Make sure we are doing the right operation
       
  4947     if( iSetMediaLCount )
       
  4948         {
       
  4949         iSetMediaLCount--;
       
  4950         if ( iSetMediaLCount < 1 )
       
  4951             {
       
  4952             TRAP_IGNORE( HandleRenameOpCompleteL() );
       
  4953             }
       
  4954         }
       
  4955     }
       
  4956 // ---------------------------------------------------------------------------
       
  4957 // From MMPXCollectionHelperObserver
       
  4958 // Callback function to signal that adding a file is complete
       
  4959 // ---------------------------------------------------------------------------
       
  4960 //
       
  4961 void CMPXCollectionViewHgImp::HandleAddFileCompleteL( TInt aErr )
       
  4962     {
       
  4963     MPX_FUNC( "CMPXCollectionViewHgImp::HandleAddFileCompleteL" );
       
  4964     if ( aErr != KErrNone )
       
  4965         {
       
  4966         HandleError( aErr );
       
  4967         }
       
  4968     }
       
  4969 
       
  4970 // ---------------------------------------------------------------------------
       
  4971 // From MMPXCHelperObserver
       
  4972 // Handles the completion of helper events
       
  4973 // ---------------------------------------------------------------------------
       
  4974 //
       
  4975 
       
  4976 void CMPXCollectionViewHgImp::HandleOperationCompleteL( TCHelperOperation aOperation,
       
  4977                                            TInt aErr,
       
  4978                                            void* aArgument )
       
  4979     {
       
  4980     MPX_FUNC( "CMPXCollectionViewHgImp::HandleOperationCompleteL" );
       
  4981     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleOperationCompleteL aErr = %d", aErr );
       
  4982     switch( aOperation )
       
  4983         {
       
  4984         case EDeleteOp:
       
  4985             {
       
  4986             MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleOperationCompleteL Delete operation" );
       
  4987             // do not dismiss the wait note until HandleOpenL is called,
       
  4988             // unless it's error case
       
  4989             delete iCurrentCba;
       
  4990             iCurrentCba = NULL;
       
  4991             if( aErr == KErrInUse )
       
  4992                 {
       
  4993                 if ( !iIsWaitNoteCanceled )
       
  4994                     {
       
  4995                     // only dismiss wait note if the wait note is not
       
  4996                     // canceled
       
  4997                     if ( iWaitDialog )
       
  4998                         {
       
  4999                         iWaitDialog->ProcessFinishedL();
       
  5000                         }
       
  5001                     HandleCommandL( EMPXCmdHandleExternalCommand );
       
  5002                     iIsWaitNoteCanceled = EFalse;
       
  5003                     }
       
  5004                 if ( iIsDeleting )
       
  5005                     {
       
  5006                     HBufC* text = StringLoader::LoadLC(
       
  5007                         ( iContainer->CurrentSelectionIndicesL()->Count() == 0 ) ?
       
  5008                         R_MPX_COLLECTION_NOTE_DELETE_FAIL : // Single selection
       
  5009                         R_MPX_COLLECTION_NOTE_DELETE_FAIL_MULTI_SELECTION ); // Multi selection
       
  5010 
       
  5011                     CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue );
       
  5012                     dlg->ExecuteLD( *text );
       
  5013                     CleanupStack::PopAndDestroy( text );
       
  5014                     }
       
  5015                 iIsDeleting = EFalse;
       
  5016                 }
       
  5017             else if ( aErr != KErrNone )
       
  5018                 {
       
  5019                 iIsDeleting = EFalse;
       
  5020                 if ( !iIsWaitNoteCanceled )
       
  5021                     {
       
  5022                     if ( iWaitDialog )
       
  5023                     	{
       
  5024 						iWaitDialog->ProcessFinishedL();
       
  5025 						}
       
  5026                     HandleCommandL( EMPXCmdHandleExternalCommand );
       
  5027                     iIsWaitNoteCanceled = EFalse;
       
  5028                     }
       
  5029                 HandleError( aErr );
       
  5030                 }
       
  5031             if ( iContainer )
       
  5032                 {
       
  5033                 iContainer->ClearLbxSelection();
       
  5034                 }
       
  5035             MPX_PERF_END_EX( MPX_PERF_SHOW_WAITNOTE );
       
  5036             // reopen collection
       
  5037             DoIncrementalOpenL( !iIsDeleting );
       
  5038             break;
       
  5039             }
       
  5040         case EExportPlaylistOp:
       
  5041             {
       
  5042             MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleOperationCompleteL Export playlist operation" );
       
  5043             if ( aErr == KErrNone )
       
  5044                 {
       
  5045                 HBufC* uri = static_cast<HBufC*>( aArgument );
       
  5046                 CleanupStack::PushL(uri);
       
  5047                 MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleOperationCompleteL playlist exported as %S", uri );
       
  5048 
       
  5049                 CMessageData* messageData = CMessageData::NewLC();
       
  5050                 messageData->AppendAttachmentL( *uri );
       
  5051                 RFs& fileSession = iCoeEnv->FsSession();
       
  5052                 TEntry pl;
       
  5053                 TInt err( fileSession.Entry( *uri, pl ) );
       
  5054                 if ( err == KErrNone )
       
  5055                     {
       
  5056                     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleOperationCompleteL playlist size = %d", pl.iSize );
       
  5057                     if ( !iSendUi )
       
  5058                         {
       
  5059                         iSendUi = CSendUi::NewL();
       
  5060                         }
       
  5061                     TSendingCapabilities capabilities(
       
  5062                         0,
       
  5063                         pl.iSize,
       
  5064                         TSendingCapabilities::ESupportsAttachments );
       
  5065 
       
  5066                     // sendui leaves with error code 0 when canceling sending
       
  5067                     // via bluetooth, this should be trapped
       
  5068                     MPX_TRAP( err, iSendUi->ShowQueryAndSendL( messageData, capabilities ) );
       
  5069                     if ( err != KErrNone )
       
  5070                         {
       
  5071                         HandleError( err );
       
  5072                         }
       
  5073                     // remove the file then remove the directory
       
  5074                     err = fileSession.Delete( *uri );
       
  5075                     if ( err != KErrNone )
       
  5076                         {
       
  5077                         HandleError( err );
       
  5078                         }
       
  5079                     err = fileSession.RmDir( *uri );
       
  5080                     if ( err != KErrNone )
       
  5081                         {
       
  5082                         HandleError( err );
       
  5083                         }
       
  5084                     }
       
  5085                 else
       
  5086                     {
       
  5087                     HandleError( err );
       
  5088                     }
       
  5089                 CleanupStack::PopAndDestroy( 2, uri ); // messageData & uri
       
  5090                 aArgument = NULL;
       
  5091                 }
       
  5092             else
       
  5093                 {
       
  5094                 HandleError( aErr );
       
  5095                 }
       
  5096             break;
       
  5097             }
       
  5098         case EAddOp:
       
  5099             {
       
  5100             HandleAddCompletedL( (CMPXMedia*)aArgument, aErr );
       
  5101             aArgument = NULL; // ownership transferred
       
  5102             iIsAddingToPlaylist = EFalse;  // reset flag once incremental adding is finished
       
  5103             break;
       
  5104             }
       
  5105         case ESetOp:
       
  5106             {
       
  5107             if ( iAddingToNewPlaylist )
       
  5108                 {
       
  5109                 // if user selects overwrite existing playlist,
       
  5110                 // the OP will be set, and is handled here
       
  5111                 HandleAddCompletedL( (CMPXMedia*)aArgument, aErr );
       
  5112                 }
       
  5113             else
       
  5114                 {
       
  5115                 HandleSetCompletedL( (CMPXMedia*)aArgument, aErr );
       
  5116                 }
       
  5117             aArgument = NULL; // ownership transferred
       
  5118             break;
       
  5119             }
       
  5120         case EReorderPlaylistOp:
       
  5121             {
       
  5122             HandleSetCompletedL( (CMPXMedia*)aArgument, aErr );
       
  5123             aArgument = NULL; // ownership transferred
       
  5124             break;
       
  5125             }
       
  5126         case ERenameOp:
       
  5127             {
       
  5128             if ( aErr != KErrNone )
       
  5129                 {
       
  5130                 iCommonUiHelper->HandleErrorL( aErr );
       
  5131                 }
       
  5132             break;
       
  5133             }
       
  5134         default:
       
  5135             {
       
  5136             break;
       
  5137             }
       
  5138         }
       
  5139 
       
  5140     if( aArgument )
       
  5141         {
       
  5142         delete ( CBase* )aArgument;
       
  5143         }
       
  5144     }
       
  5145 
       
  5146 // ---------------------------------------------------------------------------
       
  5147 // From MMPXPlaybackObserver
       
  5148 // Handle playback message.
       
  5149 // ---------------------------------------------------------------------------
       
  5150 //
       
  5151 void CMPXCollectionViewHgImp::HandlePlaybackMessage(
       
  5152     CMPXMessage* aMessage, TInt aError )
       
  5153     {
       
  5154     MPX_FUNC( "CMPXCollectionViewHgImp::HandlePlaybackMessage" );
       
  5155     if ( aError == KErrNone && aMessage )
       
  5156         {
       
  5157         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
  5158         }
       
  5159     // Fix EBLI-7CFE4D press select key very quick cause System Error KErrArgument
       
  5160     else
       
  5161         {
       
  5162         // Fix for EJDI-77WCRF Low memory cause MP not resp.
       
  5163         iHandlingKeyEvent = EFalse;
       
  5164         }
       
  5165     }
       
  5166 
       
  5167 // ---------------------------------------------------------------------------
       
  5168 // From MMPXPlaybackCallback
       
  5169 // Handle playback property.
       
  5170 // ---------------------------------------------------------------------------
       
  5171 //
       
  5172 void CMPXCollectionViewHgImp::HandlePropertyL(
       
  5173     TMPXPlaybackProperty /*aProperty*/,
       
  5174     TInt /*aValue*/,
       
  5175     TInt /*aError*/ )
       
  5176     {
       
  5177     // do nothing
       
  5178     }
       
  5179 
       
  5180 // ---------------------------------------------------------------------------
       
  5181 // From MMPXPlaybackCallback
       
  5182 // Method is called continously until aComplete=ETrue, signifying that
       
  5183 // it is done and there will be no more callbacks
       
  5184 // Only new items are passed each time
       
  5185 // ---------------------------------------------------------------------------
       
  5186 //
       
  5187 void CMPXCollectionViewHgImp::HandleSubPlayerNamesL(
       
  5188     TUid /* aPlayer */,
       
  5189     const MDesCArray* /* aSubPlayers */,
       
  5190     TBool /* aComplete */,
       
  5191     TInt /* aError */ )
       
  5192     {
       
  5193     // do nothing
       
  5194     }
       
  5195 
       
  5196 // ---------------------------------------------------------------------------
       
  5197 // From MMPXPlaybackCallback
       
  5198 // Handle media event.
       
  5199 // ---------------------------------------------------------------------------
       
  5200 //
       
  5201 void CMPXCollectionViewHgImp::HandleMediaL(
       
  5202     const CMPXMedia& /*aMedia*/,
       
  5203     TInt /*aError*/ )
       
  5204     {
       
  5205     // do nothing
       
  5206     }
       
  5207 
       
  5208 // ---------------------------------------------------------------------------
       
  5209 // From CAknView
       
  5210 // Returns views id.
       
  5211 // ---------------------------------------------------------------------------
       
  5212 //
       
  5213 TUid CMPXCollectionViewHgImp::Id() const
       
  5214     {
       
  5215     return TUid::Uid( KMPXCollectionViewHgId );
       
  5216     }
       
  5217 
       
  5218 // ---------------------------------------------------------------------------
       
  5219 // From CAknView
       
  5220 // Command handling function.
       
  5221 // ---------------------------------------------------------------------------
       
  5222 //
       
  5223 void CMPXCollectionViewHgImp::HandleCommandL( TInt aCommand )
       
  5224     {
       
  5225     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleCommandL(0x%x) entering", aCommand );
       
  5226 
       
  5227     switch (aCommand)
       
  5228         {
       
  5229         case EAknCmdMark:
       
  5230         case EAknCmdUnmark:
       
  5231         case EAknMarkAll:
       
  5232         case EAknUnmarkAll:
       
  5233             {
       
  5234             // Custom handling of markable lists
       
  5235             iContainer->HandleMarkableListProcessCommandL(
       
  5236                 aCommand );
       
  5237 #ifdef __ENABLE_MSK
       
  5238             // Determine middle soft key labeling
       
  5239             UpdateMiddleSoftKeyDisplayL( iCurrentMskId );
       
  5240 #endif // __ENABLE_MSK
       
  5241             if (aCommand == EAknMarkAll && !iCollectionReady)
       
  5242                 {
       
  5243                 iMarkedAll = ETrue;
       
  5244                 }
       
  5245             if (aCommand == EAknUnmarkAll || aCommand == EAknCmdUnmark)
       
  5246                 {
       
  5247                 iMarkedAll = EFalse;
       
  5248                 }
       
  5249             break;
       
  5250             }
       
  5251         case EMPXCmdGoToNowPlaying:
       
  5252             {
       
  5253             iGoToNowPlaying = ETrue;
       
  5254             AppUi()->HandleCommandL( aCommand );
       
  5255             break;
       
  5256             }
       
  5257         case EMPXCmdGoToAllSongs:
       
  5258             {
       
  5259             OpenAllSongsL();
       
  5260             break;
       
  5261             }
       
  5262         case EMPXCmdGoToArtistAlbums:
       
  5263             {
       
  5264             OpenArtistAlbumsL();
       
  5265             break;
       
  5266             }
       
  5267         case EMPXCmdGoToPlaylists:
       
  5268             {
       
  5269             OpenPlaylistsL();
       
  5270             break;
       
  5271             }
       
  5272         case EMPXCmdGoToGenre:
       
  5273             {
       
  5274             OpenGenreL();
       
  5275             break;
       
  5276             }
       
  5277         case EMPXCmdGoToPodcasts:
       
  5278             {
       
  5279             OpenPodcastsL();
       
  5280             break;
       
  5281             }
       
  5282         case EMPXCmdPlayItem:
       
  5283             {
       
  5284             iContainer->HandleItemCommandL(EMPXCmdPlay);
       
  5285             break;
       
  5286             }
       
  5287         case EMPXCmdCreatePlaylist:
       
  5288             {
       
  5289             iCurrentPlaylistOp = EMPXOpPLCreating;
       
  5290             CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
  5291             CleanupStack::PushL( mediaArray );
       
  5292             CMPXMedia* media = CMPXMedia::NewL();
       
  5293             CleanupStack::PushL( media );
       
  5294             media->SetCObjectValueL( KMPXMediaArrayContents, mediaArray );
       
  5295             media->SetTObjectValueL( KMPXMediaArrayCount, 0 );
       
  5296             TInt ret( iCommonUiHelper->CreatePlaylistL( *media, this, this ) );
       
  5297             if ( !ret )
       
  5298                 {
       
  5299                 // create playlist failed,
       
  5300                 iCurrentPlaylistOp = EMPXOpPLIdle;
       
  5301                 }
       
  5302             CleanupStack::PopAndDestroy( media );
       
  5303             CleanupStack::PopAndDestroy( mediaArray );
       
  5304             break;
       
  5305             }
       
  5306         case EMPXCmdAddToNewPlaylist:
       
  5307         case EMPXCmdAddToSavedPlaylist:
       
  5308             {
       
  5309             // flag used only in the case when songs are added incrementally
       
  5310             iIsAddingToPlaylist = ETrue;
       
  5311             iNumSongAddedToPlaylist = -1;
       
  5312       
       
  5313             CMPXCommonListBoxArrayBase* listboxArray(
       
  5314                    iContainer->ListBoxArray() );
       
  5315                 
       
  5316             const CMPXMedia& currentMedia = listboxArray->MediaL(
       
  5317                 iContainer->CurrentLbxItemIndex() );
       
  5318             
       
  5319             TMPXGeneralCategory mediaCategory( currentMedia.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ));
       
  5320                  
       
  5321             const CMPXMedia& containerMedia = listboxArray->ContainerMedia();
       
  5322        
       
  5323             TMPXGeneralType containerType( EMPXNoType );
       
  5324             if ( containerMedia.IsSupported( KMPXMediaGeneralType ) )
       
  5325                  {
       
  5326                  containerType = containerMedia.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType );
       
  5327                  }
       
  5328 
       
  5329             TMPXGeneralCategory containerCategory( EMPXNoCategory );
       
  5330             if ( containerMedia.IsSupported( KMPXMediaGeneralCategory ) )
       
  5331                  {
       
  5332                  containerCategory = containerMedia.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
  5333                  }
       
  5334 
       
  5335             if ( mediaCategory == EMPXSong || iContainer->IsTBoneView() )
       
  5336                 {
       
  5337                 CMPXMedia* tracks = CMPXMedia::NewL();
       
  5338                 CleanupStack::PushL( tracks );
       
  5339 
       
  5340                 MPX_TRAPD( err, PrepareMediaForSelectedItemsL( *tracks, containerCategory, containerType ) );
       
  5341                 if ( err == KErrNone )
       
  5342                     {
       
  5343                     TBool ret = EFalse;
       
  5344                     if ( aCommand == EMPXCmdAddToNewPlaylist )
       
  5345                         {
       
  5346                         iAddingToNewPlaylist = ETrue;
       
  5347                         MPX_TRAP( err,ret = iCommonUiHelper->CreatePlaylistL(
       
  5348                                 *tracks, this, this ) );
       
  5349                         if ( err != KErrNone )
       
  5350                             {
       
  5351                             HandleError( err );
       
  5352                             }
       
  5353                         if ( !ret )
       
  5354                             {
       
  5355                             iAddingToNewPlaylist = EFalse;
       
  5356                             }
       
  5357                         }
       
  5358                     else
       
  5359                         {
       
  5360                         MPX_TRAP( err, ret = iCommonUiHelper->AddToSavedPlaylistL(
       
  5361                             *iUserPlaylists, *tracks, this, this ) );
       
  5362                         if ( err != KErrNone )
       
  5363                             {
       
  5364                             HandleError( err );
       
  5365                             }
       
  5366                         }
       
  5367 #ifdef __ENABLE_MSK
       
  5368                      // If Save play list or create play list return True (OK)
       
  5369                      //  1 - Unselect marks
       
  5370                      //  2 - Force to refresh the MSK with title "Play"
       
  5371                      // If Save play list or create play list return False (Cancel)
       
  5372                      //  1 - let the marks
       
  5373                      //  2 - let the MSK with the "context menu"
       
  5374                      if (ret)
       
  5375                        {
       
  5376                        iContainer->ClearLbxSelection();
       
  5377                        UpdateMiddleSoftKeyDisplayL( iCurrentMskId );
       
  5378                        }
       
  5379 #endif // __ENABLE_MSK
       
  5380                     }
       
  5381                 else if ( err == KMPXErrDataNotReadyCacheCommand )
       
  5382                     {
       
  5383                     // cache this command
       
  5384                     HBufC* text = StringLoader::LoadLC(
       
  5385                         R_MPX_QTN_MUS_NOTE_ADDING_TRACKS );
       
  5386                     StartDelayedActionL( aCommand, *text );
       
  5387                     CleanupStack::PopAndDestroy( text );
       
  5388                     }
       
  5389                 else if ( err != KMPXErrDataNotReady )
       
  5390                     {
       
  5391                     HandleError( err );
       
  5392                     }
       
  5393                 else
       
  5394                     {
       
  5395                     // KMPXErrDataNotReady, ignore
       
  5396                     }
       
  5397                 CleanupStack::PopAndDestroy( tracks );
       
  5398                 }
       
  5399             else
       
  5400                 {
       
  5401                 // on artist/album level
       
  5402                 if ( aCommand == EMPXCmdAddToNewPlaylist )
       
  5403                     {
       
  5404                     iAddingToNewPlaylist = ETrue;
       
  5405                     iCurrentFindAllLOp = EMPXOpFindAllLAlbumArtistAddToNewPlaylist;
       
  5406                     }
       
  5407                 else
       
  5408                     {
       
  5409                     iCurrentFindAllLOp = EMPXOpFindAllLAlbumArtistAddToSavedPlaylist;
       
  5410                     }
       
  5411                 RArray<TMPXAttribute> attrs;
       
  5412                 CleanupClosePushL( attrs );
       
  5413                 attrs.Append(
       
  5414                     TMPXAttribute( KMPXMediaIdGeneral,
       
  5415                     EMPXMediaGeneralTitle | EMPXMediaGeneralId |
       
  5416                     EMPXMediaGeneralType | EMPXMediaGeneralCategory ) );
       
  5417                 CMPXMedia* criteria = CMPXMedia::NewL();
       
  5418                 CleanupStack::PushL( criteria );
       
  5419                 if ( containerCategory == EMPXArtist )
       
  5420                     {
       
  5421                     // artist/album level, need to specify artist ID in container ID
       
  5422                     TMPXItemId containerId(
       
  5423                         containerMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  5424                     criteria->SetTObjectValueL<TMPXItemId>(
       
  5425                         KMPXMediaGeneralContainerId, containerId );
       
  5426                     }
       
  5427             
       
  5428                 TMPXItemId id(
       
  5429                     currentMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  5430                 criteria->SetTObjectValueL<TMPXGeneralType>(
       
  5431                     KMPXMediaGeneralType, EMPXGroup );
       
  5432                 criteria->SetTObjectValueL<TMPXGeneralCategory>(
       
  5433                     KMPXMediaGeneralCategory, EMPXSong );
       
  5434                 criteria->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id );
       
  5435                 iCollectionUtility->Collection().FindAllL(
       
  5436                     *criteria, attrs.Array(), *this );
       
  5437                 CleanupStack::PopAndDestroy( criteria );
       
  5438                 CleanupStack::PopAndDestroy( &attrs );
       
  5439                 }
       
  5440             break;
       
  5441             }
       
  5442         case EMPXCmdAddSongs:
       
  5443             {
       
  5444             iAddingSong = ETrue;
       
  5445             iViewUtility->ActivateViewL(
       
  5446                 TUid::Uid( KMPXPluginTypeAddSongsEditorUid ) );
       
  5447             break;
       
  5448             }
       
  5449         case EMPXCmdReorder:
       
  5450             {
       
  5451             ActivateReorderGrabbedModeL();
       
  5452             break;
       
  5453             }
       
  5454         case EMPXCmdDelete: // fall through
       
  5455         case EMPXCmdRemove:
       
  5456             {
       
  5457             StoreListboxItemIndexL();
       
  5458             if ( iContainer->IsTBoneView() )
       
  5459                 {
       
  5460                 DeleteSelectedTBoneItemsL(aCommand);
       
  5461                 }
       
  5462             else
       
  5463                 {
       
  5464                 DeleteSelectedItemsL(aCommand);    
       
  5465                 }
       
  5466             break;
       
  5467             }
       
  5468         case EMPXCmdSend:
       
  5469             {
       
  5470             const CMPXMedia& media =
       
  5471                 iContainer->ListBoxArray()->MediaL(
       
  5472                     iContainer->CurrentLbxItemIndex() );
       
  5473 
       
  5474             TMPXGeneralType type(
       
  5475                 media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  5476             TMPXGeneralCategory category(
       
  5477                 media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  5478 
       
  5479             if( type == EMPXItem && category == EMPXAlbum && 
       
  5480                     iContainer->IsTBoneView() )
       
  5481                 {
       
  5482                 const TMPXItemId containerId = media.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  5483                 DoSendTBoneListItemL(containerId);
       
  5484                 }
       
  5485             else if ( iContainer->CurrentSelectionIndicesL()->Count() == 0 &&
       
  5486                 type == EMPXItem &&
       
  5487                 category == EMPXPlaylist )
       
  5488                 {
       
  5489                 // sending a playlist
       
  5490                 DoSendPlaylistL( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  5491                 }
       
  5492             else
       
  5493                 {
       
  5494                 DoSendL();
       
  5495                 }
       
  5496             break;
       
  5497             }
       
  5498         case EMPXCmdSongDetails: // fall through
       
  5499         case EMPXCmdAlbumArt: // fall through
       
  5500         case EMPXCmdFindInMusicShop:
       
  5501             {
       
  5502             StoreListboxItemIndexL();
       
  5503 
       
  5504             CMPXCommonListBoxArrayBase* listboxArray(
       
  5505                 iContainer->ListBoxArray() );
       
  5506             const CMPXMedia& media( listboxArray->MediaL(
       
  5507                 iContainer->CurrentLbxItemIndex() ) );
       
  5508             if ( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId )
       
  5509                 {
       
  5510                 // highlighted item is not yet available
       
  5511                 MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleCommandL item not yet fetched" );
       
  5512                 }
       
  5513             else
       
  5514                 {
       
  5515                 // need to check if the file exists.  if the file doesn't exist
       
  5516                 // and mediaL is called with drm status, it'll leave
       
  5517                 if ( aCommand == EMPXCmdSongDetails )
       
  5518                     {
       
  5519                     iCurrentMediaLOp = EMPXOpMediaLSongDetailsFileCheck;
       
  5520                     iInSongDetails = ETrue;
       
  5521                     }
       
  5522                 else if ( aCommand == EMPXCmdAlbumArt )
       
  5523                     {
       
  5524                     iInAlbumArtDialog = ETrue;
       
  5525                     iCurrentMediaLOp = EMPXOpMediaLAlbumArtFileCheck;
       
  5526                     }
       
  5527                 else if ( aCommand == EMPXCmdFindInMusicShop )
       
  5528                     {
       
  5529                     iCurrentMediaLOp = EMPXOpMediaLFindInMusicShopSongDetails;
       
  5530                     }
       
  5531                 CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  5532                 CleanupStack::PushL( path );
       
  5533                 
       
  5534                 if ( 2 == path->Levels() )
       
  5535                      {
       
  5536                      path->Back();
       
  5537                      path->AppendL(3);
       
  5538                      
       
  5539                      const CMPXMediaArray& albums = listboxArray->MediaArray();
       
  5540                      
       
  5541                      RArray<TMPXItemId> ids;
       
  5542                      CleanupClosePushL(ids);
       
  5543 
       
  5544                      TInt albumCount = albums.Count();
       
  5545                       for (TInt i=0; i<albumCount; ++i)
       
  5546                           {
       
  5547                           CMPXMedia* album = albums.AtL(i);
       
  5548                           const TMPXItemId id = album->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  5549                           ids.AppendL(id);
       
  5550                           }
       
  5551                       path->AppendL(ids.Array()); // top level items
       
  5552                       ids.Reset();
       
  5553                       CleanupStack::PopAndDestroy(&ids);             
       
  5554                      }
       
  5555                 path->Set( iContainer->CurrentLbxItemIndex() );
       
  5556                 RArray<TMPXAttribute> attrs;
       
  5557                 CleanupClosePushL( attrs );
       
  5558                 attrs.Append(
       
  5559                     TMPXAttribute( KMPXMediaIdGeneral,
       
  5560                         EMPXMediaGeneralUri | EMPXMediaGeneralCollectionId ) );
       
  5561                 iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  5562                 CleanupStack::PopAndDestroy( &attrs );
       
  5563                 CleanupStack::PopAndDestroy( path );
       
  5564                 }
       
  5565             break;
       
  5566             }
       
  5567         case EMPXCmdGoToMusicShop:
       
  5568             {
       
  5569             LaunchMusicShopL();
       
  5570             break;
       
  5571             }
       
  5572         case EMPXCmdGoToNokiaMusicShop:
       
  5573             {
       
  5574             LaunchMusicShopL();
       
  5575             break;
       
  5576             }
       
  5577         case EMPXCmdGoToOperatorMusicShop:
       
  5578             {
       
  5579             if(iMusicStoreWebPage)
       
  5580                 {
       
  5581                 LaunchOperatorURLMusicShopL();
       
  5582                 }
       
  5583             else
       
  5584                 {
       
  5585                 if(iOperatorMusicStoreType)
       
  5586                 {
       
  5587                 LaunchOperatorJavaMusicShopL(iOperatorMusicStoreUID);
       
  5588                 }
       
  5589             else
       
  5590                 {
       
  5591                 LaunchOperatorNativeMusicShopL();
       
  5592                 }
       
  5593                 }
       
  5594             break;
       
  5595             }
       
  5596         case EMPXCmdMusicLibraryDetails:
       
  5597             {
       
  5598             iCurrentMediaLOp = EMPXOpMediaLCollectionDetails;
       
  5599             CMPXCollectionPath* path = iCollectionUiHelper->MusicMenuPathL();
       
  5600             CleanupStack::PushL( path );
       
  5601             RArray<TMPXAttribute> attrs;
       
  5602             CleanupClosePushL( attrs );
       
  5603             attrs.Append( KMPXMediaColDetailAll );
       
  5604             iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  5605             CleanupStack::PopAndDestroy( &attrs );
       
  5606             CleanupStack::PopAndDestroy( path );
       
  5607             break;
       
  5608             }
       
  5609         case EMPXCmdRename:
       
  5610             {
       
  5611             DoHandleRenameL();
       
  5612             break;
       
  5613             }
       
  5614         case EMPXCmdPlaylistDetails:
       
  5615             {
       
  5616             iCurrentMediaLOp = EMPXOpMediaLPlaylistDetails;
       
  5617             CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
  5618             CleanupStack::PushL( path );
       
  5619             path->Set( iContainer->CurrentLbxItemIndex() );
       
  5620             RArray<TMPXAttribute> attrs;
       
  5621             CleanupClosePushL( attrs );
       
  5622             attrs.Append( TMPXAttribute( KMPXMediaIdGeneral,
       
  5623                 EMPXMediaGeneralCount | EMPXMediaGeneralTitle |
       
  5624                 EMPXMediaGeneralUri | EMPXMediaGeneralDate |
       
  5625                 EMPXMediaGeneralDuration | EMPXMediaGeneralFlags ) );
       
  5626             iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  5627             CleanupStack::PopAndDestroy( &attrs );
       
  5628             CleanupStack::PopAndDestroy( path );
       
  5629             break;
       
  5630             }
       
  5631         case EAknSoftkeyBack:
       
  5632             {
       
  5633 			if (iContainer->OfferCommandL(EAknSoftkeyBack))
       
  5634 				{
       
  5635 				CEikButtonGroupContainer* cba = Cba();
       
  5636 				if (cba)
       
  5637 					{
       
  5638 					cba->SetCommandSetL( R_MPX_OPTIONS_HIDE_CBA );
       
  5639 					cba->MakeVisible( ETrue );
       
  5640 					cba->DrawDeferred();
       
  5641 					}
       
  5642 				break;
       
  5643 				}
       
  5644 
       
  5645             iMarkedAll = EFalse;
       
  5646             if( iIsDeleting )
       
  5647             	{
       
  5648             	break;
       
  5649             	}
       
  5650 
       
  5651             if ( iIsEmbedded )
       
  5652                 {
       
  5653                 AppUi()->HandleCommandL(
       
  5654                     ( MPXTlsHelper::NeedSave() && iCommonUiHelper->IsHostMessagingBrowserL() )
       
  5655                     ? EMPXCmdSaveAndExit : EEikCmdExit );
       
  5656                 }
       
  5657             else
       
  5658                 {
       
  5659                 if ( !iHandlingKeyEvent )
       
  5660                     {
       
  5661                     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  5662                     CleanupStack::PushL( cpath );
       
  5663                     TInt currentDepth( cpath->Levels() );
       
  5664                     if ( currentDepth == 2 ) // 2 is the level of music main view
       
  5665                         {
       
  5666 #ifdef BACKSTEPPING_INCLUDED
       
  5667                         // let Back Stepping Service handle the event
       
  5668                         TInt statusInfo( KMPXBackSteppingNotConsumed );
       
  5669                         if( iViewUtility &&
       
  5670                             ( iViewUtility->ActiveViewImplementationUid() != KNullUid ) )
       
  5671                             {
       
  5672                             TInt viewId( iViewUtility->ActiveViewType().iUid );
       
  5673                             TBuf8<KMVPrefixLen + KMaxIntLen> buf;
       
  5674                             buf.Copy( KMVPrefix );
       
  5675                             buf.AppendNum( viewId );
       
  5676                             statusInfo = iBackSteppingUtility->HandleBackCommandL( buf );
       
  5677                             MPX_DEBUG3("CMPXCollectionViewHgImp::HandleCommandL - viewid=0x%x, statusInfo=%d",
       
  5678                                  viewId, statusInfo );
       
  5679                             }
       
  5680                         if ( statusInfo == KMPXBackSteppingNotConsumed )
       
  5681                             // event not consumed by Back Stepping utility, handle here
       
  5682                             //
       
  5683 #endif // BACKSTEPPING_INCLUDED
       
  5684                             {
       
  5685                             AppUi()->HandleCommandL( aCommand );
       
  5686                             }
       
  5687                         }
       
  5688                     else
       
  5689                         {
       
  5690                         if ( currentDepth > 2 && !iBackOneLevel )
       
  5691                             {
       
  5692                             iContainer->ClearLbxSelection();
       
  5693                             iCollectionUtility->Collection().BackL();
       
  5694                             iFirstIncrementalBatch = ETrue;
       
  5695                             MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleCommandL Getting container media, currentDepth = %d", currentDepth );
       
  5696                             cpath->Back();
       
  5697                             cpath->Back();
       
  5698                             RArray<TMPXAttribute> attrs;
       
  5699                             CleanupClosePushL(attrs);
       
  5700                             iCurrentMediaLOp = EMPXOpMediaLGetContainerInfo;
       
  5701                             attrs.Append( KMPXMediaGeneralDuration );
       
  5702                             iCollectionUtility->Collection().MediaL( *cpath, attrs.Array() );
       
  5703                             CleanupStack::PopAndDestroy( &attrs );
       
  5704                             iBackOneLevel = ETrue;
       
  5705                             }
       
  5706                         else
       
  5707                             {
       
  5708                             MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleCommandL Not getting container media" );
       
  5709                             }
       
  5710 
       
  5711                         iHandlingKeyEvent = ETrue;
       
  5712                         }
       
  5713                     CleanupStack::PopAndDestroy( cpath );
       
  5714                     }
       
  5715                 else
       
  5716                     {
       
  5717                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleCommandL Busy, ignoring command" );
       
  5718                     }
       
  5719                 }
       
  5720             break;
       
  5721             }
       
  5722         case EMPXCmdSavePlaylist:
       
  5723             {
       
  5724             AppUi()->HandleCommandL( EMPXCmdSaveAndReopen );
       
  5725             break;
       
  5726             }
       
  5727         case EMPXCmdAbout:
       
  5728             {
       
  5729             DisplayAboutDlgL();
       
  5730             break;
       
  5731             }    
       
  5732         case EAknCmdExit:
       
  5733         case EAknSoftkeyExit:
       
  5734             {
       
  5735             AppUi()->HandleCommandL( aCommand );
       
  5736             break;
       
  5737             }
       
  5738         case EMPXCmdCancelReorder:
       
  5739             {
       
  5740             if ( iContainer && iContainer->IsInReorderMode() )
       
  5741                 {
       
  5742                 TRAP_IGNORE( ProcessCommandL( EMPXCmdReorderCancel ) );
       
  5743                 iCurrentHighlightedIndex = KErrNotFound;
       
  5744                 }
       
  5745             break;
       
  5746             }
       
  5747         case EMPXCmdUpnpPlayViaLocal:
       
  5748             {
       
  5749             if ( iUpnpFrameworkSupport )
       
  5750                 {
       
  5751                 SelectNewPlayerL( aCommand );
       
  5752                 }
       
  5753             break;
       
  5754             }
       
  5755         case EMPXCmdUPnPAiwCmdCopyToExternalCriteria:
       
  5756             {
       
  5757             if ( iUpnpFrameworkSupport )
       
  5758                 {
       
  5759                 CopySelectedItemsToRemoteL();
       
  5760                 }
       
  5761             break;
       
  5762             }
       
  5763 
       
  5764         case EMPXCmdPlay:
       
  5765         case EMPXCmdForcePlay:
       
  5766         case EMPXCmdPlayPause:
       
  5767             {
       
  5768             TBool isReady( ETrue );
       
  5769             TMPXPlaybackState state( iPlaybackUtility->StateL() );
       
  5770 
       
  5771             // if it's in paused state, resume playback, no need
       
  5772             // to check if current highlight is a playlist
       
  5773             if ( iContainer &&
       
  5774                 aCommand != EMPXCmdForcePlay &&
       
  5775                 state != EPbStatePaused && state != EPbStatePlaying )
       
  5776                 {
       
  5777                 CMPXCommonListBoxArrayBase* listboxArray =
       
  5778                     iContainer->ListBoxArray();
       
  5779                 if ( iContainer->CurrentListItemCount() > 0 )
       
  5780                     {
       
  5781                     TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  5782                     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleCommandL currentItem %d", currentItem );
       
  5783                     if (currentItem == KErrNotFound)
       
  5784                         {
       
  5785                         // no item selected
       
  5786                         // start playing previous playlist
       
  5787                         if ( iPlaybackUtility->Source() )
       
  5788                             {
       
  5789                             iPlaybackUtility->CommandL( EPbCmdPlay );
       
  5790                             HandleCommandL( EMPXCmdGoToNowPlaying );
       
  5791                             }
       
  5792                         isReady = EFalse;
       
  5793                         } 
       
  5794                     else 
       
  5795                         {
       
  5796                         const CMPXMedia& media = listboxArray->MediaL( currentItem );
       
  5797                         TMPXGeneralType type(
       
  5798                             media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  5799                         TMPXGeneralCategory category(
       
  5800                             media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  5801                         if ( category == EMPXPlaylist && type == EMPXItem )
       
  5802                             {
       
  5803                             MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleCommandL checking item count in playlist" );
       
  5804                             isReady = EFalse;
       
  5805                             TMPXItemId id(
       
  5806                                 media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  5807                             CMPXMedia* entry = CMPXMedia::NewL();
       
  5808                             CleanupStack::PushL( entry );
       
  5809                             entry->SetTObjectValueL<TMPXGeneralType>(
       
  5810                                 KMPXMediaGeneralType, EMPXGroup );
       
  5811                             entry->SetTObjectValueL<TMPXGeneralCategory>(
       
  5812                                 KMPXMediaGeneralCategory, EMPXSong );
       
  5813                             entry->SetTObjectValueL<TMPXItemId>(
       
  5814                                 KMPXMediaGeneralId, id );
       
  5815                             iCurrentFindAllLOp = EMPXOpFindAllLPlaylistTracksCount;
       
  5816                             RArray<TMPXAttribute> attrs;
       
  5817                             CleanupClosePushL( attrs );
       
  5818                             attrs.Append( KMPXMediaGeneralId );
       
  5819                             iCollectionUtility->Collection().FindAllL(
       
  5820                                 *entry, attrs.Array(), *this );
       
  5821                             CleanupStack::PopAndDestroy( &attrs );
       
  5822                             CleanupStack::PopAndDestroy( entry );
       
  5823                             }
       
  5824                         }
       
  5825                     }
       
  5826                 else
       
  5827                     {
       
  5828                     // current list view is empty, and no song currently playing
       
  5829                     // ignore the command
       
  5830                     isReady = EFalse;
       
  5831                     }
       
  5832                 }
       
  5833             if ( isReady )
       
  5834                 {
       
  5835                 if ( aCommand == EMPXCmdForcePlay )
       
  5836                     {
       
  5837                     aCommand = EMPXCmdPlay;
       
  5838                     }
       
  5839                 if (iContainer && (EPbStateNotInitialised == state ||
       
  5840                      EPbStateStopped == state ))
       
  5841                     {
       
  5842                     // Needed to reset the status of iPreservedState
       
  5843                     if ( EPbStateStopped == state )
       
  5844                         {
       
  5845                         iPlaybackUtility->CommandL(EPbCmdResetPreserveState);
       
  5846                         }
       
  5847                     TInt currentItem(
       
  5848                         iContainer->CurrentLbxItemIndex() );
       
  5849                     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleCommandL playing index %d", currentItem );
       
  5850                     if ( iContainer->IsInReorderMode() )
       
  5851                         {
       
  5852                         // if in reorder mode, and in not playing state
       
  5853                         // drop the reorder target and start playing
       
  5854                         if ( iIsGrabbed )
       
  5855                             {
       
  5856                             ProcessCommandL( EMPXCmdReorderDrop );
       
  5857                             }
       
  5858                         ProcessCommandL( EMPXCmdReorderDone );
       
  5859                         iPlayIndex = currentItem;
       
  5860                         }
       
  5861                     else if ( currentItem != KErrNotFound )
       
  5862                         {
       
  5863                         if ( iContainer && !AppUi()->IsDisplayingDialog() )
       
  5864                             {
       
  5865                             StopDisplayingMenuBar();
       
  5866                             }
       
  5867                         iPlayIndex = KErrNotFound;
       
  5868 
       
  5869                         if (iContainer->IsSelectedItemASong())
       
  5870 							{
       
  5871 							if(iCollectionCacheReady)
       
  5872 								{
       
  5873 								iCollectionUtility->Collection().OpenL( currentItem, EMPXOpenPlaylistOnly );
       
  5874 								iFirstIncrementalBatch = ETrue;
       
  5875 								}
       
  5876 							}
       
  5877 						else
       
  5878 							{
       
  5879 							iContainer->HandleItemCommandL(EMPXCmdPlay);
       
  5880 							}
       
  5881 
       
  5882                         }
       
  5883                     }
       
  5884                 else
       
  5885                     {
       
  5886                     AppUi()->HandleCommandL( aCommand );
       
  5887                     }
       
  5888                 }
       
  5889             break;
       
  5890             }
       
  5891         case EMPXCmdSaveComplete:
       
  5892             {
       
  5893             MPXTlsHelper::SetNeedSave( EFalse );
       
  5894             break;
       
  5895             }
       
  5896 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  5897         case EMPXCmdRefreshLibrary:
       
  5898             {
       
  5899             MPX_PERF_CHECKPT("Refresh collection library");
       
  5900             // Package the argument from 8bit to 16bit then activate view
       
  5901             //
       
  5902             StartWaitNoteL( EMPXRefreshingNote );
       
  5903             iPlaybackUtility->CommandL( EPbCmdStop );
       
  5904             iPopuponRefresh = ETrue;
       
  5905             break;
       
  5906             }
       
  5907 #endif
       
  5908         default:
       
  5909             {
       
  5910             MPX_PERF_CHECKPT("Handle Collection view unknown command");
       
  5911             if ( iUpnpFrameworkSupport )
       
  5912                 {
       
  5913                 if ( aCommand >= EMPXCmdUpnpPlayViaRemotePlayer  &&
       
  5914                      aCommand < EMPXCmdUpnpLastCommandId )
       
  5915                     {
       
  5916                     SelectNewPlayerL( aCommand );
       
  5917                     }
       
  5918                 else
       
  5919                     {
       
  5920                     if ( iServiceHandler->ServiceCmdByMenuCmd(aCommand) != KAiwCmdNone )
       
  5921                         {
       
  5922                         CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  5923                         FillAiwParametersL(paramList);
       
  5924                         iServiceHandler->ExecuteMenuCmdL(aCommand, paramList,
       
  5925                             iServiceHandler->OutParamListL());
       
  5926                         }
       
  5927                     AppUi()->HandleCommandL( aCommand );
       
  5928                     }
       
  5929                 }
       
  5930             else
       
  5931                 {
       
  5932                 if ( iServiceHandler->ServiceCmdByMenuCmd(aCommand) != KAiwCmdNone )
       
  5933                     {
       
  5934                     CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  5935                     FillAiwParametersL(paramList);
       
  5936                     iServiceHandler->ExecuteMenuCmdL(aCommand, paramList,
       
  5937                         iServiceHandler->OutParamListL());
       
  5938                     }
       
  5939                 AppUi()->HandleCommandL( aCommand );
       
  5940                 }
       
  5941             break;
       
  5942             }
       
  5943         }
       
  5944     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleCommandL() exiting" );
       
  5945     }
       
  5946 
       
  5947 // ---------------------------------------------------------------------------
       
  5948 // From CAknView
       
  5949 // Handles a view activation.
       
  5950 // ---------------------------------------------------------------------------
       
  5951 //
       
  5952 void CMPXCollectionViewHgImp::DoActivateL(
       
  5953     const TVwsViewId& /* aPrevViewId */,
       
  5954     TUid /* aCustomMessageId */,
       
  5955     const TDesC8& /* aCustomMessage */ )
       
  5956     {
       
  5957     MPX_FUNC( "CMPXCollectionViewHgImp::DoActivateL()" );
       
  5958 
       
  5959     // Add view deactivation observer
       
  5960     AppUi()->AddViewDeactivationObserverL( this );
       
  5961 
       
  5962     CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  5963     CleanupStack::PushL( cpath );
       
  5964     // media is not valid until the first HandleOpenL call
       
  5965     CEikButtonGroupContainer* cba = Cba();
       
  5966     if ( cba )
       
  5967         {
       
  5968         cba->SetCommandSetL(( cpath->Levels() == 3 && !iIsEmbedded ) ?
       
  5969             R_MPX_OPTIONS_HIDE_CBA: R_MPX_OPTIONS_BACK_CBA_NO_ACTION );
       
  5970         cba->DrawDeferred(); 
       
  5971         }
       
  5972 
       
  5973     // Set status pane layout if switched here directly from another view,
       
  5974     // such as when using the AnyKey
       
  5975     StatusPane()->MakeVisible( ETrue );
       
  5976     StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT);
       
  5977 
       
  5978     if ( !iContainer )
       
  5979         {
       
  5980         iContainer = CMPXCollectionViewHgContainer::NewL( this, this, this, iIsEmbedded );
       
  5981         iContainer->SetCbaHandler( this );
       
  5982         }
       
  5983     iContainer->SetMopParent( this );
       
  5984     AppUi()->AddToStackL( *this, iContainer );
       
  5985     iContainer->SetRect( ClientRect() );
       
  5986 
       
  5987 
       
  5988 	UpdateTitlePaneL();
       
  5989 
       
  5990 
       
  5991     if ( iViewUtility->PreviousViewType().iUid == KMPXPluginTypePlaybackUid )
       
  5992         {
       
  5993 		// Set the previous view for animatin purposes.
       
  5994 		iContainer->SetPreviousViewId(TUid::Uid(KMPXPluginTypePlaybackUid));
       
  5995 
       
  5996 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  5997         // If previous view is Playback view, it can only be normal playback view
       
  5998         // Podcast shouldn't be highlighted in any case.
       
  5999         iPodcast = EFalse;
       
  6000 #endif
       
  6001 
       
  6002         // return back from playback view and in songs level,
       
  6003         // highlight the new playing song
       
  6004         MMPXSource* source( iPlaybackUtility->Source() );
       
  6005 
       
  6006         if ( source )
       
  6007             {
       
  6008             CMPXCollectionPlaylist* playlist( source->PlaylistL() );
       
  6009             if ( playlist )
       
  6010                 {
       
  6011                 // Going from Now Playing View -> Collection, same collection level
       
  6012                 iPossibleJump = ( playlist->Path().Levels() == cpath->Levels() );
       
  6013                 delete playlist;
       
  6014                 }
       
  6015             }
       
  6016 
       
  6017         if ( cpath->Levels() > 1 )
       
  6018             {
       
  6019             // valid path in collection
       
  6020             MPX_DEBUG_PATH(*cpath);
       
  6021 
       
  6022             DoIncrementalOpenL();
       
  6023             }
       
  6024         else
       
  6025             {
       
  6026             TUid defaultView( iViewUtility->DefaultViewUid() );
       
  6027             iViewUtility->ActivateViewL( ( defaultView != KNullUid ) ?
       
  6028                 defaultView : TUid::Uid( KMPXPluginTypeMainUid ) );
       
  6029             }
       
  6030         }
       
  6031     else
       
  6032         {
       
  6033 #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  6034         // If previous view is Collection view, it can only be podcast view
       
  6035         if ( iViewUtility->PreviousViewType().iUid == KMPXPluginTypeCollectionUid )
       
  6036             {
       
  6037             iPodcast = ETrue;
       
  6038             }
       
  6039 #endif
       
  6040 
       
  6041         MPX_DEBUG_PATH(*cpath);
       
  6042 
       
  6043         DoIncrementalOpenL( cpath->Levels()>KMusicCollectionMenuLevel ? ETrue:EFalse );
       
  6044 
       
  6045         iUpCount = 0;
       
  6046         iDownCount = 0;
       
  6047         }
       
  6048     CleanupStack::PopAndDestroy( cpath );
       
  6049     }
       
  6050 
       
  6051 // ---------------------------------------------------------------------------
       
  6052 // From CAknView
       
  6053 // View deactivation function.
       
  6054 // ---------------------------------------------------------------------------
       
  6055 //
       
  6056 void CMPXCollectionViewHgImp::DoDeactivate()
       
  6057     {
       
  6058     MPX_FUNC( "CMPXCollectionViewHgImp::DoDeactivate" );
       
  6059     if ( iContainer && iContainer->IsInReorderMode() )
       
  6060         {
       
  6061         TRAP_IGNORE( ProcessCommandL( EMPXCmdReorderDone ) );
       
  6062         iCurrentHighlightedIndex = KErrNotFound;
       
  6063         }
       
  6064 
       
  6065     if ( iContainer )
       
  6066         {
       
  6067         iContainer->ContentIsReady( EFalse );
       
  6068         AppUi()->RemoveFromStack( iContainer );
       
  6069         delete iContainer;
       
  6070         iContainer = NULL;
       
  6071         }
       
  6072 
       
  6073     if (iDuration)
       
  6074         {
       
  6075         delete iDuration;
       
  6076         iDuration = NULL;
       
  6077         }
       
  6078     if (iTitle)
       
  6079        {
       
  6080 	   delete iTitle;
       
  6081        iTitle = NULL;
       
  6082        }
       
  6083     // for Avkon calling Deactivate, not manually hiding window contorls, reset iGoToNowPlaying
       
  6084     iGoToNowPlaying = EFalse;
       
  6085     // Cleanup view deactivation observer
       
  6086     AppUi()->RemoveViewDeactivationObserver( this );
       
  6087     }
       
  6088 
       
  6089 // ---------------------------------------------------------------------------
       
  6090 // From CAknView
       
  6091 // Foreground event handling function.
       
  6092 // ---------------------------------------------------------------------------
       
  6093 //
       
  6094 void CMPXCollectionViewHgImp::HandleForegroundEventL( TBool aForeground )
       
  6095     {
       
  6096     MPX_FUNC( "CMPXCollectionViewHgImp::HandleForegroundEventL" );
       
  6097     if ( aForeground && iOpeningNote )
       
  6098     	{
       
  6099         CloseWaitNoteL();
       
  6100         iOpeningNote = EFalse;
       
  6101     	}
       
  6102 
       
  6103 /* This code is added to avoid CBA flicker which happens after pressing "Now playing" 
       
  6104    from artist&album view and pressing BACK from Playback view.
       
  6105    While going to playback view, reset CBA to "Back". */
       
  6106     if( !aForeground && iViewUtility->ActiveViewType().iUid == KMPXPluginTypePlaybackUid )
       
  6107         {
       
  6108         TRAP_IGNORE( CEikButtonGroupContainer* cba = Cba();
       
  6109         if ( cba )
       
  6110             {
       
  6111             cba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  6112             cba->DrawDeferred();
       
  6113             } );
       
  6114         }
       
  6115 		
       
  6116 #ifdef BACKSTEPPING_INCLUDED
       
  6117     iActivateBackStepping = EFalse;
       
  6118     MPX_DEBUG3("CMPXCollectionViewHgImp::HandleForegroundEventL - is in foreground=%d, this view=0x%x",
       
  6119         aForeground, Id().iUid );
       
  6120     if( aForeground &&
       
  6121         iViewUtility &&
       
  6122         ( iViewUtility->ActiveViewImplementationUid() != KNullUid ) )
       
  6123         {
       
  6124         iActivateBackStepping = ETrue;
       
  6125         }
       
  6126 #endif // BACKSTEPPING_INCLUDED
       
  6127         {
       
  6128         CAknView::HandleForegroundEventL( aForeground );
       
  6129         }
       
  6130     }
       
  6131 
       
  6132 // -----------------------------------------------------------------------------
       
  6133 // CMPXCollectionViewHgImp::HandleBacksteppingActivation
       
  6134 // Handle backstepping activation
       
  6135 // -----------------------------------------------------------------------------
       
  6136 //
       
  6137 void CMPXCollectionViewHgImp::HandleBacksteppingActivation()
       
  6138     {
       
  6139 #ifdef BACKSTEPPING_INCLUDED
       
  6140     TInt viewId( iViewUtility->ActiveViewType().iUid );
       
  6141     TBuf8<KMVPrefixLen + KMaxIntLen> buf;
       
  6142     buf.Copy( KMVPrefix );
       
  6143     buf.AppendNum( viewId );
       
  6144     TInt statusInfo( KMPXBackSteppingNotConsumed );
       
  6145     TRAP_IGNORE(
       
  6146        statusInfo =
       
  6147         iBackSteppingUtility->ForwardActivationEventL( buf, ETrue );
       
  6148          );
       
  6149     MPX_DEBUG3("CMPXCollectionViewHgImp::HandleBacksteppingActivation - viewId=0x%x, statusInfo=%d", viewId, statusInfo );
       
  6150     iActivateBackStepping = EFalse;
       
  6151 #endif // BACKSTEPPING_INCLUDED
       
  6152    }
       
  6153 
       
  6154 
       
  6155 
       
  6156 // -----------------------------------------------------------------------------
       
  6157 // checks if Now Playing option should be shown
       
  6158 // -----------------------------------------------------------------------------
       
  6159 //
       
  6160 TBool CMPXCollectionViewHgImp::NowPlayingOptionVisibilityL()
       
  6161     {
       
  6162     MPX_FUNC( "CMPXCollectionViewHgImp::SendOptionVisibilityL" );
       
  6163     TBool isHidden( iContainer->TotalListItemCount() < 1 );
       
  6164 
       
  6165 	// First check if there's a local playback source
       
  6166 	MMPXSource* source( iPlaybackUtility->Source() );
       
  6167 	if ( source == 0 )
       
  6168 		{
       
  6169 		// If no local playback, check if there's a progressive download playback source.
       
  6170 		MMPXPlaybackUtility* pdPlaybackUtility;
       
  6171 		pdPlaybackUtility = MMPXPlaybackUtility::UtilityL( TUid::Uid( KProgressDownloadUid ) );
       
  6172 		isHidden = pdPlaybackUtility->Source() ? EFalse : ETrue;
       
  6173 		pdPlaybackUtility->Close();
       
  6174 		}
       
  6175 	else
       
  6176 	    {
       
  6177         isHidden = EFalse;
       
  6178 	    }
       
  6179 
       
  6180     return isHidden;
       
  6181     }
       
  6182 
       
  6183 
       
  6184 // ---------------------------------------------------------------------------
       
  6185 // Handle initialing a music menu pane.
       
  6186 // ---------------------------------------------------------------------------
       
  6187 //
       
  6188 void CMPXCollectionViewHgImp::HandleInitMusicMenuPaneL(
       
  6189     CEikMenuPane* aMenuPane )
       
  6190     {
       
  6191     CMPXCollectionViewListBoxArray* array =
       
  6192         static_cast<CMPXCollectionViewListBoxArray*>(
       
  6193         iContainer->ListBoxArray() );
       
  6194 	const CMPXMedia& containerMedia = array->ContainerMedia();
       
  6195 
       
  6196 	TMPXGeneralCategory containerCategory(
       
  6197 		containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
  6198 			KMPXMediaGeneralCategory ) );
       
  6199 			
       
  6200 	TMPXGeneralType containerType(
       
  6201     	containerMedia.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );			
       
  6202     
       
  6203 	TInt usbUnblockingStatus;
       
  6204     RProperty::Get( KMPXViewPSUid,
       
  6205                     KMPXUSBUnblockingPSStatus,
       
  6206                     usbUnblockingStatus);
       
  6207    
       
  6208    if(usbUnblockingStatus)
       
  6209        {
       
  6210        aMenuPane->SetItemDimmed( EMPXCmdRefreshLibrary, ETrue );
       
  6211        }
       
  6212    
       
  6213 	switch ( containerCategory )
       
  6214 		{
       
  6215 		case EMPXPlaylist:
       
  6216 			{
       
  6217 			// playlist view
       
  6218 			aMenuPane->SetItemDimmed( EMPXCmdGoToPlaylists, ETrue );
       
  6219 			if(usbUnblockingStatus)
       
  6220 			 {
       
  6221 			 aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  6222 			 }
       
  6223 			else          
       
  6224 			 {
       
  6225              aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, iGoToMusicShopOptionHidden );
       
  6226              }
       
  6227 	        if (containerType != EMPXGroup ) // EMPXItem -> playlist tracks level
       
  6228 			 {
       
  6229 			  aMenuPane->SetItemDimmed( EMPXCmdGoToArtistAlbums, ETrue );
       
  6230 			  aMenuPane->SetItemDimmed( EMPXCmdGoToAllSongs, ETrue );
       
  6231 			  aMenuPane->SetItemDimmed( EMPXCmdGoToPodcasts, ETrue );
       
  6232 			  aMenuPane->SetItemDimmed( EMPXCmdGoToGenre, ETrue );
       
  6233 			  aMenuPane->SetItemDimmed( EMPXCmdRefreshLibrary, ETrue );
       
  6234               aMenuPane->SetItemDimmed( EMPXCmdMusicLibraryDetails, ETrue);
       
  6235 			  aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  6236 	          aMenuPane->SetItemDimmed( EMPXCmdGoToMultipleMusicShop, ETrue); 
       
  6237 	          aMenuPane->SetItemDimmed( EMPXCmdAbout, ETrue); 
       
  6238 	          }  
       
  6239 			break;
       
  6240 			}
       
  6241 		case EMPXAlbum:
       
  6242 		case EMPXArtist:
       
  6243 			{
       
  6244 			// Artists & Albums view
       
  6245 			aMenuPane->SetItemDimmed( EMPXCmdGoToArtistAlbums, ETrue );
       
  6246 			if(usbUnblockingStatus)
       
  6247 			 {
       
  6248              aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  6249 			 }
       
  6250 			else          
       
  6251 			 {
       
  6252              aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, iGoToMusicShopOptionHidden );
       
  6253              }
       
  6254 			if ( iContainer->IsTBoneView() ) //TBone View
       
  6255 			    {
       
  6256 			    aMenuPane->SetItemDimmed( EMPXCmdGoToAllSongs, ETrue );
       
  6257 			    aMenuPane->SetItemDimmed( EMPXCmdGoToPlaylists, ETrue );
       
  6258 			    aMenuPane->SetItemDimmed( EMPXCmdGoToPodcasts, ETrue );
       
  6259 			    aMenuPane->SetItemDimmed( EMPXCmdGoToGenre, ETrue );
       
  6260 			    aMenuPane->SetItemDimmed( EMPXCmdRefreshLibrary, ETrue );
       
  6261                 aMenuPane->SetItemDimmed( EMPXCmdMusicLibraryDetails, ETrue); 
       
  6262                 aMenuPane->SetItemDimmed( EMPXCmdAbout, ETrue);
       
  6263 			    }    
       
  6264 			break;
       
  6265 			}
       
  6266 		case EMPXGenre:
       
  6267 			{
       
  6268 			// Genre view
       
  6269         	aMenuPane->SetItemDimmed( EMPXCmdGoToGenre, ETrue );
       
  6270 			if(usbUnblockingStatus)
       
  6271 			 {
       
  6272 			 aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  6273 			 }
       
  6274 			else          
       
  6275 			 {
       
  6276 			 aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, iGoToMusicShopOptionHidden );
       
  6277              }
       
  6278 			if ( containerType != EMPXGroup ) // EMPXItem -> tracks level
       
  6279 				{
       
  6280                 aMenuPane->SetItemDimmed( EMPXCmdGoToAllSongs, ETrue );
       
  6281                 aMenuPane->SetItemDimmed( EMPXCmdGoToArtistAlbums, ETrue );
       
  6282                 aMenuPane->SetItemDimmed( EMPXCmdGoToPlaylists, ETrue );
       
  6283                 aMenuPane->SetItemDimmed( EMPXCmdGoToPodcasts, ETrue );
       
  6284                 aMenuPane->SetItemDimmed( EMPXCmdRefreshLibrary, ETrue );
       
  6285                 aMenuPane->SetItemDimmed( EMPXCmdMusicLibraryDetails, ETrue);
       
  6286 				aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  6287                 aMenuPane->SetItemDimmed( EMPXCmdGoToMultipleMusicShop, ETrue); 
       
  6288                 aMenuPane->SetItemDimmed( EMPXCmdAbout, ETrue);
       
  6289 				}
       
  6290 			
       
  6291 			break;
       
  6292 			}
       
  6293 		case EMPXSong:
       
  6294 			{
       
  6295 			// Song view and Genre Track view
       
  6296 			aMenuPane->SetItemDimmed( EMPXCmdGoToAllSongs, ETrue );
       
  6297 			if(usbUnblockingStatus)
       
  6298 			 {
       
  6299 			 aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  6300 			 }
       
  6301 			else          
       
  6302 			 {
       
  6303              aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, iGoToMusicShopOptionHidden );
       
  6304 			 }
       
  6305 			break;
       
  6306 			}
       
  6307 		default:
       
  6308 			{
       
  6309 			break;
       
  6310 			}
       
  6311 		}
       
  6312    	}
       
  6313 // ---------------------------------------------------------------------------
       
  6314 // Dynamically initialises a menu pane for the Album context
       
  6315 // ---------------------------------------------------------------------------
       
  6316 //
       
  6317 void CMPXCollectionViewHgImp::DynInitMenuPaneAlbumL(
       
  6318     TInt aResourceId,
       
  6319     CEikMenuPane* aMenuPane )
       
  6320     {
       
  6321     MPX_FUNC( "CMPXCollectionViewHgImp::DynInitMenuPaneAlbumL" );
       
  6322     ASSERT( iContainer && aMenuPane != NULL);
       
  6323     switch ( aResourceId )
       
  6324         {
       
  6325         case R_MPX_COLLECTION_VIEW_MENU_1:
       
  6326             {
       
  6327             HandleInitMusicMenuPaneL(aMenuPane);
       
  6328             aMenuPane->SetItemDimmed( EMPXCmdGoToNowPlaying, NowPlayingOptionVisibilityL() );
       
  6329             aMenuPane->SetItemDimmed( EMPXCmdFind, ETrue );
       
  6330             aMenuPane->SetItemDimmed( EMPXCmdUpnpPlayVia, ETrue );
       
  6331             aMenuPane->SetItemDimmed( EMPXCmdUPnPAiwCmdCopyToExternalCriteria, ETrue );
       
  6332             aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, ETrue );
       
  6333             aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6334             aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6335             aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6336             aMenuPane->SetItemDimmed( EMPXCmdSend, ETrue );
       
  6337             aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6338             aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6339             aMenuPane->SetItemDimmed( EMPXCmdPlayItem, ETrue );
       
  6340             TBool landscapeOrientation = Layout_Meta_Data::IsLandscapeOrientation();
       
  6341 			if ( !landscapeOrientation )
       
  6342 				{
       
  6343 				TInt usbUnblockingStatus;
       
  6344 				RProperty::Get( KMPXViewPSUid,
       
  6345 								KMPXUSBUnblockingPSStatus,
       
  6346 								usbUnblockingStatus);
       
  6347 
       
  6348 				if ( iContainer->CurrentLbxItemIndex() > KErrNotFound && !iContainer->IsTBoneView())
       
  6349 				    {
       
  6350 				    aMenuPane->SetItemDimmed( EMPXCmdPlayItem, EFalse );			    	       
       
  6351                     if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6352                         {
       
  6353                         aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6354                         aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6355                         }
       
  6356                     else
       
  6357                         {
       
  6358                          aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, EFalse );
       
  6359                          aMenuPane->SetItemDimmed( EMPXCmdDelete, EFalse );
       
  6360                         }
       
  6361 					}
       
  6362 				if ( iContainer->IsSelectedItemASong() && iContainer->IsTBoneView() )
       
  6363 					{
       
  6364 					if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6365 						{
       
  6366 						aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6367 						aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6368 						}
       
  6369 					else
       
  6370 						{
       
  6371 						aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, EFalse );
       
  6372 						aMenuPane->SetItemDimmed( EMPXCmdDelete, EFalse );
       
  6373 						aMenuPane->SetItemDimmed( EMPXCmdSend, EFalse );
       
  6374 						}
       
  6375 					}
       
  6376 				}
       
  6377 					
       
  6378 				//If Operator Music store exist, show the cascade menu with Nokia and Operator music store.
       
  6379 				if ( iOperatorMusicStore )
       
  6380 				    {
       
  6381 				    aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, ETrue);
       
  6382 				    }
       
  6383 				else
       
  6384 				    {
       
  6385 				    aMenuPane->SetItemDimmed(EMPXCmdGoToMultipleMusicShop, ETrue);
       
  6386 				    }
       
  6387 
       
  6388 			break;
       
  6389 			}
       
  6390 
       
  6391 		case R_MPX_COLLECTION_VIEW_MENU_2:
       
  6392             {
       
  6393 			aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6394 			aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6395 			aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6396  			aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6397 			aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6398 			aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6399 			if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  6400  				{
       
  6401  				TInt usbUnblockingStatus;
       
  6402 				RProperty::Get( KMPXViewPSUid,
       
  6403 							KMPXUSBUnblockingPSStatus,
       
  6404 							usbUnblockingStatus);
       
  6405 
       
  6406 				if (usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive)
       
  6407 					{
       
  6408 					aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue); 
       
  6409 					}
       
  6410 				else if( !iContainer->IsTBoneView()&& (iContainer->CurrentLbxItemIndex() > KErrNotFound))								
       
  6411 			        {  
       
  6412                     CMPXCollectionViewListBoxArray* array =
       
  6413                     static_cast<CMPXCollectionViewListBoxArray*>(
       
  6414                         iContainer->ListBoxArray() );
       
  6415 			        const CMPXMedia& media = array->MediaL( iContainer->CurrentLbxItemIndex() );
       
  6416 			        const TDesC& title( media.ValueText( KMPXMediaGeneralTitle ) );
       
  6417 			        if( title.Length() > 0)
       
  6418 			            {   
       
  6419 			            aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, !iUsingNokiaService );
       
  6420 			            }
       
  6421 			        } 
       
  6422 			    }
       
  6423 		    break;
       
  6424 			}
       
  6425         case R_MPX_ADD_TO_PL_SUB_MENU:
       
  6426             {
       
  6427             aMenuPane->SetItemDimmed( EMPXCmdAddToSavedPlaylist, !FindPlaylistsL() );
       
  6428             break;
       
  6429             }
       
  6430         default:
       
  6431             {
       
  6432             // Do nothing
       
  6433             break;
       
  6434             }
       
  6435 		}
       
  6436 	}
       
  6437 
       
  6438 // ---------------------------------------------------------------------------
       
  6439 // Dynamically initialises a menu pane for the Playlist context
       
  6440 // ---------------------------------------------------------------------------
       
  6441 //
       
  6442 void CMPXCollectionViewHgImp::DynInitMenuPanePlaylistL(
       
  6443     TInt aResourceId,
       
  6444     CEikMenuPane* aMenuPane )
       
  6445     {
       
  6446     MPX_FUNC( "CMPXCollectionViewHgImp::DynInitMenuPanePlaylistL" );
       
  6447  
       
  6448     switch ( aResourceId )
       
  6449         {
       
  6450         case R_MPX_COLLECTION_VIEW_MENU_1:
       
  6451             {
       
  6452             HandleInitMusicMenuPaneL(aMenuPane);
       
  6453 
       
  6454 			aMenuPane->SetItemDimmed( EMPXCmdGoToNowPlaying, NowPlayingOptionVisibilityL() );
       
  6455 			aMenuPane->SetItemDimmed( EMPXCmdFind, ETrue );
       
  6456 			aMenuPane->SetItemDimmed( EMPXCmdUpnpPlayVia, ETrue );
       
  6457 			aMenuPane->SetItemDimmed( EMPXCmdUPnPAiwCmdCopyToExternalCriteria, ETrue );
       
  6458 			aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6459 			aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6460 			aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6461 			aMenuPane->SetItemDimmed( EMPXCmdSend, ETrue );
       
  6462 			aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6463 			aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6464 
       
  6465 			TInt usbUnblockingStatus;
       
  6466 			RProperty::Get( KMPXViewPSUid,
       
  6467 							KMPXUSBUnblockingPSStatus,
       
  6468 							usbUnblockingStatus);
       
  6469 			if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6470 				{
       
  6471 				aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, ETrue );
       
  6472 				aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6473 				}
       
  6474 			else
       
  6475 				{
       
  6476 				aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, EFalse );
       
  6477 				aMenuPane->SetItemDimmed( EMPXCmdDelete, EFalse );
       
  6478 				}
       
  6479 
       
  6480 			TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  6481 			if(currentItem > KErrNotFound )
       
  6482 			    {  
       
  6483 			    CMPXCollectionViewListBoxArray* array =
       
  6484 			    static_cast<CMPXCollectionViewListBoxArray*>(
       
  6485 			            iContainer->ListBoxArray() );
       
  6486 			    const CMPXMedia& media = array->MediaL( currentItem );
       
  6487 
       
  6488 			    if ( media.IsSupported( KMPXMediaGeneralNonPermissibleActions ) )
       
  6489 			        {
       
  6490 			        // check for auto playlist, disable delete
       
  6491 			        TMPXGeneralNonPermissibleActions attr(
       
  6492 			                media.ValueTObjectL<TMPXGeneralNonPermissibleActions>(
       
  6493 			                        KMPXMediaGeneralNonPermissibleActions ) );
       
  6494 			        if ( attr & EMPXWrite )
       
  6495 			            {
       
  6496 			            aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6497 			            }
       
  6498 			        }
       
  6499 
       
  6500 			    TInt trackCount (0);
       
  6501 			    if( media.IsSupported(KMPXMediaGeneralCount) )
       
  6502 			        {
       
  6503 			        trackCount = media.ValueTObjectL<TInt>( KMPXMediaGeneralCount );
       
  6504 			        }
       
  6505 			    if( trackCount < 1 )
       
  6506 			        {
       
  6507 			        aMenuPane->SetItemDimmed( EMPXCmdPlayItem, ETrue );
       
  6508 			        }
       
  6509 			    } 
       
  6510 			if ( iOperatorMusicStore )
       
  6511 			    {
       
  6512 			    aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, ETrue);
       
  6513 			    }
       
  6514 			else
       
  6515 			    {
       
  6516 			    aMenuPane->SetItemDimmed(EMPXCmdGoToMultipleMusicShop, ETrue);
       
  6517 			    }
       
  6518 
       
  6519 			break;
       
  6520 			}
       
  6521 
       
  6522 		case R_MPX_COLLECTION_VIEW_MENU_2:
       
  6523             {
       
  6524 			aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6525 			aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6526 			aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6527 			aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6528 			aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6529 
       
  6530 			TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  6531             
       
  6532 			if(currentItem > KErrNotFound )
       
  6533 			    {  
       
  6534 			    CMPXCollectionViewListBoxArray* array =
       
  6535 			    static_cast<CMPXCollectionViewListBoxArray*>(
       
  6536 			            iContainer->ListBoxArray() );
       
  6537 			    const CMPXMedia& media = array->MediaL( currentItem );
       
  6538 
       
  6539 			    TInt usbUnblockingStatus;
       
  6540 			    RProperty::Get( KMPXViewPSUid,
       
  6541 			            KMPXUSBUnblockingPSStatus,
       
  6542 			            usbUnblockingStatus);
       
  6543 			    if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6544 			        {
       
  6545 			        aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6546 			        }
       
  6547 			    else
       
  6548 			        {
       
  6549 			        aMenuPane->SetItemDimmed( EMPXCmdRename, EFalse );
       
  6550 			        }
       
  6551 
       
  6552 			    if ( media.IsSupported(
       
  6553 			            KMPXMediaGeneralNonPermissibleActions ) )
       
  6554 			        {
       
  6555 			        // check for auto playlist, disable delete
       
  6556 			        TMPXGeneralNonPermissibleActions attr(
       
  6557 			                media.ValueTObjectL<TMPXGeneralNonPermissibleActions>(
       
  6558 			                        KMPXMediaGeneralNonPermissibleActions ) );
       
  6559 			        if ( attr & EMPXWrite )
       
  6560 			            {
       
  6561 			            aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6562 			            // TODO: this should be an item specific command.
       
  6563 			            aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6564 			            }
       
  6565 			        }
       
  6566 			    if ( array->IsItemBrokenLinkL( currentItem ) ||
       
  6567 			            array->IsItemCorruptedL( currentItem ) )
       
  6568 			        {
       
  6569 			        aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6570 			        // TODO: this should be an item specific command.
       
  6571 			        aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6572 			        }
       
  6573 			    } 
       
  6574 			break;
       
  6575 			}
       
  6576         default:
       
  6577             {
       
  6578             // Do nothing
       
  6579             break;
       
  6580             }
       
  6581 		}
       
  6582 	}
       
  6583 
       
  6584 
       
  6585 
       
  6586 // ---------------------------------------------------------------------------
       
  6587 // Dynamically initialises a menu pane for the Genre context
       
  6588 // ---------------------------------------------------------------------------
       
  6589 //
       
  6590 void CMPXCollectionViewHgImp::DynInitMenuPaneGenreL(
       
  6591     TInt aResourceId,
       
  6592     CEikMenuPane* aMenuPane )
       
  6593     {
       
  6594     MPX_FUNC( "CMPXCollectionViewHgImp::DynInitMenuPanePlaylistL" );
       
  6595 
       
  6596     switch ( aResourceId )
       
  6597         {
       
  6598         case R_MPX_COLLECTION_VIEW_MENU_1:
       
  6599             {
       
  6600             HandleInitMusicMenuPaneL(aMenuPane);
       
  6601 
       
  6602             aMenuPane->SetItemDimmed( EMPXCmdGoToNowPlaying, NowPlayingOptionVisibilityL() );
       
  6603             aMenuPane->SetItemDimmed( EMPXCmdFind, ETrue );
       
  6604             aMenuPane->SetItemDimmed( EMPXCmdUpnpPlayVia, ETrue );
       
  6605             aMenuPane->SetItemDimmed( EMPXCmdUPnPAiwCmdCopyToExternalCriteria, ETrue );
       
  6606             aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6607             aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, ETrue );
       
  6608             aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6609             aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6610             aMenuPane->SetItemDimmed( EMPXCmdSend, ETrue );
       
  6611             aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6612             aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6613             aMenuPane->SetItemDimmed( EMPXCmdPlayItem, ETrue );
       
  6614 
       
  6615             if ( iContainer->CurrentLbxItemIndex() > KErrNotFound )
       
  6616                 {
       
  6617                 aMenuPane->SetItemDimmed( EMPXCmdPlayItem, EFalse ); 
       
  6618                 TInt usbUnblockingStatus;
       
  6619                 RProperty::Get( KMPXViewPSUid,
       
  6620                                 KMPXUSBUnblockingPSStatus,
       
  6621                                 usbUnblockingStatus);
       
  6622                 if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6623                     {
       
  6624                     aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6625                    }
       
  6626                 else
       
  6627                     {
       
  6628                     aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, EFalse );
       
  6629                     }
       
  6630                 }
       
  6631             
       
  6632             if ( iOperatorMusicStore )
       
  6633                 {
       
  6634                 aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, ETrue);
       
  6635                 }
       
  6636             else
       
  6637                 {
       
  6638                 aMenuPane->SetItemDimmed(EMPXCmdGoToMultipleMusicShop, ETrue);
       
  6639                 }
       
  6640 			break;
       
  6641 			}
       
  6642 
       
  6643 		case R_MPX_COLLECTION_VIEW_MENU_2:
       
  6644             {
       
  6645 			aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6646 			aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6647 			aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6648 			aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6649 			aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6650             aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6651 			break;
       
  6652 			}
       
  6653         case R_MPX_ADD_TO_PL_SUB_MENU:
       
  6654             {
       
  6655             aMenuPane->SetItemDimmed( EMPXCmdAddToSavedPlaylist, !FindPlaylistsL() );
       
  6656             break;
       
  6657             }
       
  6658         default:
       
  6659             {
       
  6660             // Do nothing
       
  6661             break;
       
  6662             }
       
  6663 		}
       
  6664 	}
       
  6665 
       
  6666 
       
  6667 // ---------------------------------------------------------------------------
       
  6668 // Dynamically initialises a menu pane for the Songs context
       
  6669 // Handling for any tracks view except playlist tracks.
       
  6670 // ---------------------------------------------------------------------------
       
  6671 //
       
  6672 void CMPXCollectionViewHgImp::DynInitMenuPaneSongsL(
       
  6673     TInt aResourceId,
       
  6674     CEikMenuPane* aMenuPane )
       
  6675     {
       
  6676     MPX_FUNC( "CMPXCollectionViewHgImp::DynInitMenuPaneAllSongsL" );
       
  6677     TInt selectionCount( 0 );
       
  6678     iSelectionIndexCache = iContainer->CurrentSelectionIndicesL(); // not owned
       
  6679     switch ( aResourceId )
       
  6680         {
       
  6681         case R_MPX_COLLECTION_VIEW_MENU_1:
       
  6682             {
       
  6683             HandleInitMusicMenuPaneL(aMenuPane);
       
  6684             aMenuPane->SetItemDimmed( EMPXCmdGoToNowPlaying, NowPlayingOptionVisibilityL() );
       
  6685             aMenuPane->SetItemDimmed( EMPXCmdFind, ETrue );
       
  6686             aMenuPane->SetItemDimmed( EMPXCmdUpnpPlayVia, ETrue );
       
  6687             aMenuPane->SetItemDimmed( EMPXCmdUPnPAiwCmdCopyToExternalCriteria, ETrue );
       
  6688             aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6689             aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, ETrue );
       
  6690             aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6691             aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6692             aMenuPane->SetItemDimmed( EMPXCmdSend, ETrue );
       
  6693             aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6694             aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6695             aMenuPane->SetItemDimmed( EMPXCmdPlayItem, ETrue );
       
  6696 			TInt usbUnblockingStatus;
       
  6697 			RProperty::Get( KMPXViewPSUid,
       
  6698 								KMPXUSBUnblockingPSStatus,
       
  6699 								usbUnblockingStatus);
       
  6700 
       
  6701 			if ( iContainer->IsSelectedItemASong() )
       
  6702 				{
       
  6703 				if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6704 					{
       
  6705 					aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6706 					aMenuPane->SetItemDimmed( EMPXCmdSend, SendOptionVisibilityL() );
       
  6707 					aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6708 					}
       
  6709 				else
       
  6710 					{
       
  6711 					aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, EFalse );
       
  6712 					aMenuPane->SetItemDimmed( EMPXCmdSend, SendOptionVisibilityL() );
       
  6713 					aMenuPane->SetItemDimmed( EMPXCmdDelete, EFalse );
       
  6714 					}
       
  6715 				}
       
  6716 			if ( iOperatorMusicStore )
       
  6717 			    {
       
  6718 			    aMenuPane->SetItemDimmed(EMPXCmdGoToMusicShop, ETrue);
       
  6719 			    }
       
  6720 			else
       
  6721 			    {
       
  6722 			    aMenuPane->SetItemDimmed(EMPXCmdGoToMultipleMusicShop, ETrue);
       
  6723 			    }
       
  6724 			break;
       
  6725 			}
       
  6726 
       
  6727 		case R_MPX_COLLECTION_VIEW_MENU_2:
       
  6728             {
       
  6729 
       
  6730 		
       
  6731 			if ( iSelectionIndexCache)
       
  6732 				{
       
  6733 				selectionCount = iSelectionIndexCache->Count();
       
  6734 				}
       
  6735 			if ( selectionCount > 0 )
       
  6736 				{
       
  6737 				// multiple selection
       
  6738 				aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6739 				aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6740 				aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6741 				aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6742 				}
       
  6743 			else
       
  6744 				{
       
  6745 				aMenuPane->SetItemDimmed( EMPXCmdSongDetails,
       
  6746 				        FileDetailsOptionVisibilityL() );
       
  6747 				aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6748 				aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6749                 aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6750 
       
  6751 				TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  6752 				if ( currentItem > KErrNotFound )
       
  6753 					{
       
  6754 					CMPXCollectionViewListBoxArray* array =
       
  6755 						static_cast<CMPXCollectionViewListBoxArray*>(
       
  6756 						iContainer->ListBoxArray() );
       
  6757 
       
  6758 					if ( array->IsItemBrokenLinkL( currentItem ) ||
       
  6759 						array->IsItemCorruptedL( currentItem ) )
       
  6760 						{
       
  6761 						aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6762 						aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6763 						aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6764 						aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6765 						}
       
  6766 
       
  6767 					TInt usbUnblockingStatus;
       
  6768 					RProperty::Get( KMPXViewPSUid,
       
  6769 						KMPXUSBUnblockingPSStatus,
       
  6770 						usbUnblockingStatus);
       
  6771 
       
  6772 					if (usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive)
       
  6773 						{
       
  6774 						aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue); 
       
  6775 						}
       
  6776 					else
       
  6777 						{	
       
  6778 					    aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, !iUsingNokiaService );
       
  6779 						}
       
  6780 					}
       
  6781 				}
       
  6782 			aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6783 			aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6784 			if (iServiceHandler->HandleSubmenuL(*aMenuPane))
       
  6785 				{
       
  6786 				return;
       
  6787 				}
       
  6788 
       
  6789 			break;
       
  6790 			}
       
  6791         case R_MPX_ADD_TO_PL_SUB_MENU:
       
  6792             {
       
  6793             aMenuPane->SetItemDimmed( EMPXCmdAddToSavedPlaylist, !FindPlaylistsL() );
       
  6794             break;
       
  6795             }
       
  6796         default:
       
  6797             {
       
  6798             // Do nothing
       
  6799             break;
       
  6800             }
       
  6801 		}
       
  6802 	}
       
  6803 
       
  6804 
       
  6805 
       
  6806 // ---------------------------------------------------------------------------
       
  6807 // Dynamically initialises a menu pane for the playlist Songs context
       
  6808 // ---------------------------------------------------------------------------
       
  6809 //
       
  6810 void CMPXCollectionViewHgImp::DynInitMenuPanePlaylistSongsL(
       
  6811     TInt aResourceId,
       
  6812     CEikMenuPane* aMenuPane )
       
  6813     {
       
  6814     MPX_FUNC( "CMPXCollectionViewHgImp::DynInitMenuPanePlaylistSongsL" );
       
  6815 
       
  6816     TBool isListEmpty( iContainer->TotalListItemCount() == 0 );
       
  6817 
       
  6818     switch ( aResourceId )
       
  6819         {
       
  6820         case R_MPX_COLLECTION_VIEW_MENU_1:
       
  6821             {
       
  6822             TInt usbUnblockingStatus;
       
  6823             RProperty::Get( KMPXViewPSUid,
       
  6824                     KMPXUSBUnblockingPSStatus,
       
  6825                     usbUnblockingStatus);
       
  6826 								
       
  6827             HandleInitMusicMenuPaneL(aMenuPane);
       
  6828             aMenuPane->SetItemDimmed( EMPXCmdGoToNowPlaying, NowPlayingOptionVisibilityL() );
       
  6829             aMenuPane->SetItemDimmed( EMPXCmdFind, ETrue );
       
  6830             aMenuPane->SetItemDimmed( EMPXCmdUpnpPlayVia, ETrue );
       
  6831             aMenuPane->SetItemDimmed( EMPXCmdUPnPAiwCmdCopyToExternalCriteria, ETrue );
       
  6832             aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, ETrue );
       
  6833             aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  6834             aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6835             aMenuPane->SetItemDimmed( EMPXCmdSend, ETrue );
       
  6836             aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  6837             aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6838             aMenuPane->SetItemDimmed( EMPXCmdPlayItem, ETrue );
       
  6839             
       
  6840             if( iContainer->IsInReorderMode() )
       
  6841                 break;
       
  6842             
       
  6843 			if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6844 				{
       
  6845 				aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6846 				aMenuPane->SetItemDimmed( EMPXCmdSend, SendOptionVisibilityL() );
       
  6847 				aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6848 				aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6849 				}
       
  6850 			else
       
  6851 				{
       
  6852 				TInt selectionCount( 0 );
       
  6853 				iSelectionIndexCache = iContainer->CurrentSelectionIndicesL(); // not owned
       
  6854 				if ( iSelectionIndexCache)
       
  6855 					{
       
  6856 					selectionCount = iSelectionIndexCache->Count();
       
  6857 					}
       
  6858 				// do not display add songs option when marking is on or USB is connected
       
  6859 				if ( usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive )
       
  6860 					{
       
  6861 					aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6862 					}
       
  6863 				else
       
  6864 					{
       
  6865 					aMenuPane->SetItemDimmed( EMPXCmdAddSongs, selectionCount > 0 );
       
  6866 					}
       
  6867 
       
  6868 				if ( iContainer->CurrentLbxItemIndex() > KErrNotFound )
       
  6869 					{
       
  6870 					aMenuPane->SetItemDimmed( EMPXCmdSend, SendOptionVisibilityL() );
       
  6871 					aMenuPane->SetItemDimmed( EMPXCmdRemove, EFalse );
       
  6872 					if ( iContainer->CurrentListItemCount() > 1 )
       
  6873 					    {
       
  6874 					    aMenuPane->SetItemDimmed( EMPXCmdReorder, EFalse );
       
  6875 					    }
       
  6876 					}
       
  6877 				}
       
  6878 				
       
  6879 			CMPXCollectionViewListBoxArray* array =
       
  6880             static_cast<CMPXCollectionViewListBoxArray*>(
       
  6881                     iContainer->ListBoxArray() );
       
  6882             const CMPXMedia& containerMedia = array->ContainerMedia();
       
  6883 
       
  6884             if ( containerMedia.IsSupported( KMPXMediaGeneralNonPermissibleActions ) )
       
  6885                 {
       
  6886                 // check for auto playlist, disable add, remove and reorder
       
  6887                 TMPXGeneralNonPermissibleActions attr(
       
  6888                         containerMedia.ValueTObjectL<TMPXGeneralNonPermissibleActions>(
       
  6889                                 KMPXMediaGeneralNonPermissibleActions ) );
       
  6890                 if ( attr & EMPXWrite )
       
  6891                     {
       
  6892                     aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  6893                     aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  6894                     aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  6895                     }
       
  6896                 }
       
  6897 			break;
       
  6898 			}
       
  6899 
       
  6900 		case R_MPX_COLLECTION_VIEW_MENU_2:
       
  6901             {
       
  6902             aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  6903             aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  6904             aMenuPane->SetItemDimmed( EMPXCmdUseAsCascade, ETrue );
       
  6905             aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  6906             aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6907             aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6908             
       
  6909             if( iContainer->IsInReorderMode() )
       
  6910                 break;
       
  6911             
       
  6912 			TInt selectionCount( 0 );
       
  6913 			iSelectionIndexCache = iContainer->CurrentSelectionIndicesL(); // not owned
       
  6914 			if ( iSelectionIndexCache)
       
  6915 				{
       
  6916 				selectionCount = iSelectionIndexCache->Count();
       
  6917 				}
       
  6918 			if ( selectionCount > 0 )
       
  6919 				{
       
  6920 				// multiple selection
       
  6921 				aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6922 				aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  6923 				}
       
  6924 			else
       
  6925 				{
       
  6926 				aMenuPane->SetItemDimmed( EMPXCmdSongDetails,
       
  6927 					FileDetailsOptionVisibilityL() );
       
  6928 
       
  6929 				TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  6930 
       
  6931 				if ( currentItem > KErrNotFound )
       
  6932 					{
       
  6933 					CMPXCollectionViewListBoxArray* array =
       
  6934 						static_cast<CMPXCollectionViewListBoxArray*>(
       
  6935 						iContainer->ListBoxArray() );
       
  6936 					if ( array->IsItemBrokenLinkL( currentItem ) ||
       
  6937 						array->IsItemCorruptedL( currentItem ) )
       
  6938 						{
       
  6939 						aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  6940 						}
       
  6941 						
       
  6942 					TInt usbUnblockingStatus;
       
  6943 					RProperty::Get( KMPXViewPSUid,
       
  6944 							KMPXUSBUnblockingPSStatus,
       
  6945 							usbUnblockingStatus);
       
  6946 
       
  6947 					if (usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive)
       
  6948 						{
       
  6949 						aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue);
       
  6950 						}
       
  6951 					else
       
  6952 						{		
       
  6953 					    aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, !iUsingNokiaService );
       
  6954 						}
       
  6955 					}
       
  6956 				}
       
  6957 			if (iServiceHandler->HandleSubmenuL(*aMenuPane))
       
  6958 				{
       
  6959 				return;
       
  6960 				}
       
  6961 
       
  6962 			break;
       
  6963 			}
       
  6964         default:
       
  6965             {
       
  6966             // Do nothing
       
  6967             break;
       
  6968             }
       
  6969 		}
       
  6970 	}
       
  6971 
       
  6972 // ---------------------------------------------------------------------------
       
  6973 // From MEikMenuObserver
       
  6974 // Dynamically initialises a menu pane.
       
  6975 // ---------------------------------------------------------------------------
       
  6976 //
       
  6977 void CMPXCollectionViewHgImp::DynInitMenuPaneL(
       
  6978     TInt aResourceId,
       
  6979     CEikMenuPane* aMenuPane )
       
  6980     {
       
  6981     MPX_FUNC( "CMPXCollectionViewHgImp::DynInitMenuPaneL" );
       
  6982 
       
  6983     CMPXCollectionViewListBoxArray* array =
       
  6984         static_cast<CMPXCollectionViewListBoxArray*>(
       
  6985         iContainer->ListBoxArray() );
       
  6986 	const CMPXMedia& containerMedia = array->ContainerMedia();
       
  6987 
       
  6988     if ( &containerMedia == NULL )
       
  6989         {
       
  6990         // If containerMedia is NULL, Dim all options 
       
  6991         DimAllOptions(aResourceId, aMenuPane);
       
  6992         return; 
       
  6993         } 
       
  6994 		
       
  6995 	TMPXGeneralType containerType(
       
  6996 		containerMedia.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  6997 	TMPXGeneralCategory containerCategory(
       
  6998 		containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
  6999 			KMPXMediaGeneralCategory ) );
       
  7000 
       
  7001     TInt usbUnblockingStatus;
       
  7002     RProperty::Get( KMPXViewPSUid,
       
  7003                     KMPXUSBUnblockingPSStatus,
       
  7004                     usbUnblockingStatus);
       
  7005 
       
  7006 	// We first construct options menu based on collection browsing context.
       
  7007 	// For resource R_MPX_COLLECTION_VIEW_MENU_1, R_MPX_COLLECTION_VIEW_MENU_2.
       
  7008 	if ( containerType == EMPXGroup )
       
  7009 		{
       
  7010 		switch (containerCategory)
       
  7011 			{
       
  7012 			case EMPXCollection:
       
  7013 				break;
       
  7014 			case EMPXArtist:
       
  7015 				break;
       
  7016 			case EMPXAlbum:
       
  7017 			    // Artist & Album view
       
  7018 				DynInitMenuPaneAlbumL(aResourceId, aMenuPane);
       
  7019 				break;
       
  7020 			case EMPXPlaylist:
       
  7021 			    // Playlist view
       
  7022 				DynInitMenuPanePlaylistL(aResourceId, aMenuPane);
       
  7023 				break;
       
  7024 			case EMPXSong:
       
  7025 			    // Songs (All Songs) View
       
  7026 				DynInitMenuPaneSongsL(aResourceId, aMenuPane);
       
  7027 				break;
       
  7028 			case EMPXGenre:
       
  7029 			    // Genre View
       
  7030 				DynInitMenuPaneGenreL(aResourceId, aMenuPane);
       
  7031 				break;
       
  7032 			case EMPXComposer:
       
  7033 				break;
       
  7034 			default:
       
  7035 				User::Leave(KErrNotSupported);
       
  7036 				break;
       
  7037 			}
       
  7038 		}
       
  7039 	else if ( containerType == EMPXItem )
       
  7040 		{
       
  7041 		switch (containerCategory)
       
  7042 			{
       
  7043 			case EMPXSong:
       
  7044 				break;
       
  7045 			case EMPXArtist:
       
  7046 				break;
       
  7047 			case EMPXPlaylist:
       
  7048 			    // Playlist tracks view
       
  7049 				DynInitMenuPanePlaylistSongsL(aResourceId, aMenuPane);
       
  7050 				break;
       
  7051 			case EMPXAlbum:
       
  7052 			case EMPXGenre:
       
  7053 			case EMPXComposer:
       
  7054 			    // Other tracks view
       
  7055 				DynInitMenuPaneSongsL(aResourceId, aMenuPane);
       
  7056 				break;
       
  7057 			default:
       
  7058 				User::Leave(KErrNotSupported);
       
  7059 				break;
       
  7060 			}
       
  7061 		}
       
  7062 
       
  7063 	// Handle other menu resources.
       
  7064     switch ( aResourceId )
       
  7065         {
       
  7066         case R_MPX_ADD_TO_PL_SUB_MENU:
       
  7067             {
       
  7068             aMenuPane->SetItemDimmed( EMPXCmdAddToSavedPlaylist, !FindPlaylistsL() );
       
  7069             break;
       
  7070             }
       
  7071         case R_MPX_COLLECTION_PLAY_VIA_SUB_MENU:
       
  7072             {
       
  7073             if ( iUpnpFrameworkSupport )
       
  7074                 {
       
  7075                 AddPlayersNamesToMenuL( *aMenuPane );
       
  7076                 }
       
  7077             break;
       
  7078             }
       
  7079         case R_MPX_COLLECTION_VIEW_EMBEDDED_PLAYLIST_VIEW:
       
  7080             {
       
  7081             // if it's from browser/messaging, display save option if
       
  7082             // it has not been saved
       
  7083             aMenuPane->SetItemDimmed( EMPXCmdSavePlaylist,
       
  7084                 ( !iCommonUiHelper->IsHostMessagingBrowserL() || !MPXTlsHelper::NeedSave() ) );
       
  7085             aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  7086             break;
       
  7087             }
       
  7088         case R_MPX_PLAYBACK_COLLECTION_MUSICSHOP_SUB_MENU:
       
  7089         	{
       
  7090         	aMenuPane->SetItemTextL(EMPXCmdGoToOperatorMusicShop,  iOperatorMusicStoreName->Des() );
       
  7091         	break;
       
  7092         	}
       
  7093         case R_AVKON_MENUPANE_MARKABLE_LIST:
       
  7094             {
       
  7095             // Mark/Unmark submenu is displayed only if USB is on going
       
  7096             if (usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive)
       
  7097                 {
       
  7098                 MPX_DEBUG1("CMPXCollectionViewHgImp::DynInitMenuPaneL() dimmed Mark/Unmark submenu");
       
  7099                 aMenuPane->SetItemDimmed(EAknCmdEditListMenu, ETrue);
       
  7100                 }
       
  7101             break;
       
  7102             }
       
  7103         default:
       
  7104             {
       
  7105             // Do nothing
       
  7106             break;
       
  7107             }
       
  7108         }
       
  7109 
       
  7110     if (!(aResourceId == R_AVKON_MENUPANE_MARKABLE_LIST && usbUnblockingStatus == EMPXUSBUnblockingPSStatusActive))
       
  7111         {
       
  7112         // Custom handling of menu pane for markable lists
       
  7113         iContainer->HandleMarkableListDynInitMenuPane(
       
  7114             aResourceId,
       
  7115             aMenuPane );
       
  7116         }
       
  7117     }
       
  7118 
       
  7119 // ---------------------------------------------------------------------------
       
  7120 // From MEikListBoxObserver
       
  7121 // Handles listbox events.
       
  7122 // ---------------------------------------------------------------------------
       
  7123 //
       
  7124 void CMPXCollectionViewHgImp::HandleListBoxEventL(
       
  7125     CEikListBox* /*aListBox*/,
       
  7126     TListBoxEvent aEventType)
       
  7127     {
       
  7128     MPX_FUNC( "CMPXCollectionViewHgImp::HandleListBoxEventL" );
       
  7129     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleListBoxEventL iLastDepth = %d", iLastDepth );
       
  7130     MPX_PERF_CHECKPT( "Select collection item to open" );
       
  7131     if ( iContainer )
       
  7132         {
       
  7133         //to keep/change focus on right song in rename/remove
       
  7134         if ( aEventType == EEventItemSingleClicked )         
       
  7135             {
       
  7136             if ( !iHandlingKeyEvent && iCollectionCacheReady )
       
  7137                 {
       
  7138                 CMPXCommonListBoxArrayBase* listboxArray( iContainer->ListBoxArray() );
       
  7139                 TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  7140 
       
  7141                 CMPXCommand* command = CMPXCommand::NewL();
       
  7142                 CleanupStack::PushL( command );
       
  7143                 command->SetTObjectValueL<TMPXCommandId>( KMPXCommandGeneralId,
       
  7144                                                           KMPXCommandIdCollectionSelect );
       
  7145                 command->SetTObjectValueL( KMPXCommandCollectionSelectIndex, currentIndex );
       
  7146                 command->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  7147                 iCollectionUtility->Collection().CommandL( *command );
       
  7148                 CleanupStack::PopAndDestroy( command );
       
  7149                 }
       
  7150             }
       
  7151 
       
  7152         if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked
       
  7153             || aEventType == EEventItemSingleClicked
       
  7154            )
       
  7155             {
       
  7156             if ( iContainer->IsInReorderMode() )
       
  7157                 {
       
  7158                 ProcessCommandL( iContainer->IsInReorderMode() ?
       
  7159                     EMPXCmdReorderDrop : EMPXCmdReorderGrab );
       
  7160                 }
       
  7161 		    else if ( !iHandlingKeyEvent )
       
  7162                 {
       
  7163                 TMPXPlaybackState pbState( iPlaybackUtility->StateL() );
       
  7164                 TBool isEqual( EFalse );
       
  7165                 if ( pbState == EPbStatePlaying || pbState == EPbStatePaused )
       
  7166                     {
       
  7167                     // in currently playing view, check if current item is playing
       
  7168                     if ( iContainer->CurrentLbxItemIndex() ==
       
  7169                         iContainer->PlaybackIndex() )
       
  7170                         {
       
  7171                         isEqual = ETrue;
       
  7172                         }
       
  7173                     }
       
  7174 
       
  7175                 if ( isEqual )
       
  7176                     {
       
  7177                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleListBoxEventL going to now playing view" );
       
  7178                     if ( pbState == EPbStatePaused )
       
  7179                         {
       
  7180                         MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleListBoxEventL resuming playback" );
       
  7181                         iPlaybackUtility->CommandL( EPbCmdPlay );
       
  7182                         }
       
  7183                     HandleCommandL( EMPXCmdGoToNowPlaying );
       
  7184                     }
       
  7185                 else
       
  7186                     {
       
  7187                     CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  7188                     CleanupStack::PushL( cpath );
       
  7189                     if ( cpath->Levels() == ( iLastDepth + 1 ) )
       
  7190                         {
       
  7191                         // navigated in one level
       
  7192                         iLastDepth++;
       
  7193                         iBottomIndex->AppendL(
       
  7194                             iContainer->BottomLbxItemIndex() );
       
  7195                         }
       
  7196                     else
       
  7197                         {
       
  7198                         // invalid path, rebuild with all 0
       
  7199                         iBottomIndex->Reset();
       
  7200                         iLastDepth = cpath->Levels();
       
  7201                         for ( TInt i = 0; i < iLastDepth; i++ )
       
  7202                             {
       
  7203                             iBottomIndex->AppendL( 0 );
       
  7204                             }
       
  7205                         }
       
  7206                     CleanupStack::PopAndDestroy( cpath );
       
  7207                     TInt currentItem( iContainer->CurrentLbxItemIndex() );
       
  7208                     MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleListBoxEventL Opening Item: %d", currentItem );
       
  7209 
       
  7210                     iHandlingKeyEvent = ETrue;
       
  7211 
       
  7212                     // Needed to reset the status of iPreservedState
       
  7213                     if ( EPbStateStopped == pbState )
       
  7214                         {
       
  7215                         iPlaybackUtility->CommandL(EPbCmdResetPreserveState);
       
  7216                         }
       
  7217 
       
  7218     #ifdef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  7219                     // check to see if user has selected podcast item
       
  7220                     if ( (iLastDepth == KMusicCollectionMenuLevel) &&
       
  7221                          (currentItem == KMusicMenuPodcastMenuItemIndex) &&
       
  7222                          !iDisablePodcasting )
       
  7223                         {
       
  7224                         // open the podcast collection db plugin
       
  7225                         iPodcast = ETrue;
       
  7226                         CMPXCollectionPath* mainPodcastMenu = CMPXCollectionPath::NewL();
       
  7227                         CleanupStack::PushL( mainPodcastMenu );
       
  7228                         mainPodcastMenu->AppendL(KPodcastCollectionUid);
       
  7229                         iCollectionUtility->Collection().OpenL( *mainPodcastMenu );
       
  7230 						iFirstIncrementalBatch = ETrue;
       
  7231                         CleanupStack::PopAndDestroy( mainPodcastMenu );
       
  7232 
       
  7233                         // activate the podcast collection view
       
  7234                         RArray<TUid> uids;
       
  7235                         CleanupClosePushL( uids );
       
  7236                         uids.AppendL( TUid::Uid( KMPXPluginTypeCollectionUid ) );
       
  7237                         uids.AppendL( TUid::Uid( KPodcastCollectionUid ));
       
  7238                         iViewUtility->ActivateViewL(uids);
       
  7239 
       
  7240                         CleanupStack::PopAndDestroy( &uids );
       
  7241                         }
       
  7242                     else
       
  7243     #endif
       
  7244                         {
       
  7245                         if(iCollectionCacheReady)
       
  7246                             {
       
  7247                             CMPXCommonListBoxArrayBase* listboxArray( iContainer->ListBoxArray() );
       
  7248                             TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  7249                             const CMPXMedia& media( listboxArray->MediaL( currentIndex ) );
       
  7250                             TMPXGeneralType type(
       
  7251                                 media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType ) );
       
  7252                             TMPXGeneralCategory category(
       
  7253                                 media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory ) );
       
  7254                             if ( type != EMPXItem || category != EMPXSong )
       
  7255                                 {
       
  7256                                 if ( type == EMPXGroup && category== EMPXSong )
       
  7257                                     {
       
  7258                                     // dismiss for HGList
       
  7259                                     //StartWaitNoteL( EMPXImmediatelyOpeningNote );
       
  7260                                     }
       
  7261                                 else
       
  7262                                     {
       
  7263                                     //do not show wait note if opening a song
       
  7264                                     // dismiss for HGList
       
  7265                                     //StartWaitNoteL( EMPXOpeningNote );
       
  7266                                     }
       
  7267                                 }
       
  7268                             iCollectionUtility->Collection().OpenL( currentItem );
       
  7269 							iFirstIncrementalBatch = ETrue;
       
  7270                             }
       
  7271                         }
       
  7272 
       
  7273                     }
       
  7274                 }
       
  7275             else
       
  7276                 {
       
  7277                 MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleListBoxEventL Busy, ignoring command" );
       
  7278                 }
       
  7279             }
       
  7280         }
       
  7281     }
       
  7282 
       
  7283 // ---------------------------------------------------------------------------
       
  7284 // From MEikCommandObserver
       
  7285 // Processes user commands.
       
  7286 // ---------------------------------------------------------------------------
       
  7287 //
       
  7288 void CMPXCollectionViewHgImp::ProcessCommandL(TInt aCommandId)
       
  7289     {
       
  7290     MPX_FUNC( "CMPXCollectionViewHgImp::ProcessCommandL" );
       
  7291 
       
  7292     switch( aCommandId )
       
  7293         {
       
  7294         case EMPXCmdReorderDrop:
       
  7295             {
       
  7296             SaveCurrentPlaylistL();
       
  7297             iContainer->ConfirmReorderL();
       
  7298             DeactivateReorderGrabbedModeL( ETrue );
       
  7299             break;
       
  7300             }
       
  7301         case EMPXCmdReorderGrab:
       
  7302             {
       
  7303             SetNewCbaL( R_MPX_CUI_REORDER_DROP_CANCEL_CBA );
       
  7304             ActivateReorderGrabbedModeL();
       
  7305             break;
       
  7306             }
       
  7307         case EMPXCmdReorderCancel:
       
  7308             {
       
  7309             iCurrentHighlightedIndex = iContainer->GetOriginalIndex();
       
  7310             MPX_DEBUG2( "CMPXCollectionViewHgImp::ProcessCommandL Setting iCurrentHighlightedIndex = %d", iCurrentHighlightedIndex );
       
  7311             iContainer->CancelReorder();
       
  7312             } // Fall through on purpose
       
  7313         case EMPXCmdReorderDone:
       
  7314             {
       
  7315             DeactivateReorderGrabbedModeL( ETrue );
       
  7316             iHandlingKeyEvent = EFalse;            
       
  7317             break;
       
  7318             }
       
  7319         case EMPXCmdUpArrow:
       
  7320             {
       
  7321             iIgnoreNextFocusChangedMessage = ETrue;
       
  7322             if ( iContainer->IsInReorderMode() )
       
  7323                 {
       
  7324                 iContainer->MoveReorderIndex( KMPXDirectionUp );
       
  7325                 }
       
  7326             else
       
  7327                 {
       
  7328                 iDownCount = 0;
       
  7329 
       
  7330                 if( iUpCount != KErrNotFound )
       
  7331                     {
       
  7332                     if( iUpCount++ > KIncrementalDirectionCount )
       
  7333                         {
       
  7334                         iIncrementalOpenUtil->SetDirection( CMPXCollectionOpenUtility::EFetchUp );
       
  7335                         iUpCount = KErrNotFound;
       
  7336                         }
       
  7337                     }
       
  7338                 }
       
  7339             break;
       
  7340             }
       
  7341         case EMPXCmdDownArrow:
       
  7342             {
       
  7343             iIgnoreNextFocusChangedMessage = ETrue;
       
  7344             if ( iContainer->IsInReorderMode() )
       
  7345                 {
       
  7346                 iContainer->MoveReorderIndex( KMPXDirectionDown );
       
  7347                 }
       
  7348             else
       
  7349                 {
       
  7350                 iUpCount = 0;
       
  7351 
       
  7352                 if( iDownCount != KErrNotFound )
       
  7353                     {
       
  7354                     if( iDownCount++ > KIncrementalDirectionCount  )
       
  7355                         {
       
  7356                         iIncrementalOpenUtil->SetDirection( CMPXCollectionOpenUtility::EFetchDown );
       
  7357                         iDownCount = KErrNotFound;
       
  7358                         }
       
  7359 
       
  7360                     }
       
  7361                 }
       
  7362             break;
       
  7363             }
       
  7364         case EMPXCmdCommonEnterKey:
       
  7365             {
       
  7366             // Handle list box event for enter key pressed
       
  7367             TInt index( iContainer->CurrentLbxItemIndex() );
       
  7368             if( index >= 0 )
       
  7369             	{
       
  7370                 HandleListBoxEventL(
       
  7371             	    NULL, // ignore
       
  7372             	    EEventEnterKeyPressed );
       
  7373             	}
       
  7374             break;
       
  7375             }
       
  7376 
       
  7377 		case EMPXCmdGoToNowPlaying:
       
  7378 			{
       
  7379 			HandleCommandL( aCommandId );
       
  7380 			break;
       
  7381 			}
       
  7382         case EMPXCmdUpArrowAfterListboxHandled:
       
  7383             {
       
  7384             if ( iContainer->IsInReorderMode() )
       
  7385                 {
       
  7386                 TInt index( iContainer->CurrentLbxItemIndex() );
       
  7387                 if ( index == iContainer->CurrentListItemCount() - 1 )
       
  7388                     {
       
  7389                     // if after up arrow is pressed, and end up at the
       
  7390                     // lowest index.  list box looped, sync with listboxarray needed
       
  7391                     iContainer->SetReorderIndex( index );
       
  7392                     iContainer->HandleLbxItemAdditionL();
       
  7393                     // need to set index and redraw
       
  7394                     iContainer->SetLbxCurrentItemIndexAndDraw( index );
       
  7395                     }
       
  7396                 UpdateReorderNaviPaneL();
       
  7397                 }
       
  7398             break;
       
  7399             }
       
  7400         case EMPXCmdDownArrowAfterListboxHandled:
       
  7401             {
       
  7402             if ( iContainer->IsInReorderMode() )
       
  7403                 {
       
  7404                 TInt index( iContainer->CurrentLbxItemIndex() );
       
  7405                 if ( index == 0 )
       
  7406                     {
       
  7407                     // if after down arrow is pressed, and end up at the
       
  7408                     // top index.  list box looped, sync with listboxarray needed
       
  7409                     iContainer->SetReorderIndex( index );
       
  7410                     iContainer->HandleLbxItemAdditionL();
       
  7411                     }
       
  7412                 UpdateReorderNaviPaneL();
       
  7413                 }
       
  7414             break;
       
  7415             }
       
  7416         case EMPXCmdCommonDelete:
       
  7417             {
       
  7418             if ( !iIsEmbedded )
       
  7419                 {
       
  7420                 StoreListboxItemIndexL();
       
  7421                 // embedded mode doesn't support delete key
       
  7422                 DeleteSelectedItemsL(aCommandId);
       
  7423                 }
       
  7424             break;
       
  7425             }
       
  7426         case EMPXCmdCommonResourceChange:
       
  7427             {
       
  7428             iContainer->SetRect( ClientRect() );
       
  7429             break;
       
  7430             }
       
  7431         case EAknSoftkeyEmpty:
       
  7432             {
       
  7433             // do nothing.  handled to avoid "unsupported" message
       
  7434             break;
       
  7435             }
       
  7436 #ifdef __ENABLE_MSK
       
  7437         case EMPXCmdCommonUpdateMiddleSoftKey:
       
  7438             {
       
  7439             // Determine middle soft key labeling
       
  7440             UpdateMiddleSoftKeyDisplayL( iCurrentMskId );
       
  7441             break;
       
  7442             }
       
  7443         case EAknSoftkeyContextOptions :
       
  7444             {
       
  7445             // set context menu flag
       
  7446             iShowContextMenu = ETrue;
       
  7447             // open context menu (by processing "Options" command)
       
  7448             if ( iContainer )
       
  7449                 {
       
  7450                 iSelectionIndexCache = iContainer->CurrentSelectionIndicesL(); // not owned
       
  7451                 MPX_DEBUG2( "CMPXCollectionViewHgImp::ProcessCommandL count = %d", iSelectionIndexCache->Count() );
       
  7452                 }
       
  7453             CAknView::ProcessCommandL( EAknSoftkeyOptions );
       
  7454             break;
       
  7455             }
       
  7456 #endif // __ENABLE_MSK
       
  7457         case EAknCmdExit:
       
  7458 			{
       
  7459             HandleCommandL( aCommandId );
       
  7460 			CAknView::ProcessCommandL( aCommandId );
       
  7461 			break;
       
  7462 			}
       
  7463 		case EAknSoftkeyOptions:
       
  7464             {
       
  7465             if ( iContainer )
       
  7466                 {
       
  7467                 iSelectionIndexCache = iContainer->CurrentSelectionIndicesL(); // not owned
       
  7468                 MPX_DEBUG2( "CMPXCollectionViewHgImp::ProcessCommandL count = %d", iSelectionIndexCache->Count() );
       
  7469                 }
       
  7470             }
       
  7471         default:
       
  7472             {
       
  7473             CAknView::ProcessCommandL( aCommandId );
       
  7474             break;
       
  7475             }
       
  7476         }
       
  7477     }
       
  7478 
       
  7479 // -----------------------------------------------------------------------------
       
  7480 // CMPXCollectionViewHgImp::LaunchMusicShopL
       
  7481 // Launch music shop application
       
  7482 // -----------------------------------------------------------------------------
       
  7483 //
       
  7484 void CMPXCollectionViewHgImp::LaunchMusicShopL()
       
  7485     {
       
  7486     MPX_FUNC( "CMPXCollectionViewHgImp::LaunchMusicShopL" );
       
  7487 
       
  7488     if ( iMusicStoreUID != 0)
       
  7489         {
       
  7490     TApaTaskList taskList( iCoeEnv->WsSession() );
       
  7491         TApaTask task = taskList.FindApp( TUid::Uid(iMusicStoreUID) );
       
  7492 
       
  7493     if ( task.Exists() )
       
  7494         {
       
  7495         GfxTransEffect::BeginFullScreen( 
       
  7496         AknTransEffect::EApplicationStart,
       
  7497             TRect(), 
       
  7498             AknTransEffect::EParameterType, 
       
  7499             AknTransEffect::GfxTransParam( TUid::Uid(iMusicStoreUID),        
       
  7500             AknTransEffect::TParameter::EActivateExplicitContinue ));            
       
  7501         task.BringToForeground();
       
  7502         }
       
  7503     else
       
  7504         {
       
  7505         RApaLsSession session;
       
  7506         if ( KErrNone == session.Connect() )
       
  7507             {
       
  7508             CleanupClosePushL( session );
       
  7509             TThreadId threadId;
       
  7510                 session.CreateDocument( KNullDesC, TUid::Uid(iMusicStoreUID), threadId );
       
  7511             CleanupStack::PopAndDestroy(&session);
       
  7512                 }
       
  7513             }
       
  7514         }
       
  7515     }
       
  7516 
       
  7517 
       
  7518 // -----------------------------------------------------------------------------
       
  7519 // CMPlayerCategoryView::DoFindInMusicShopL
       
  7520 // Handle find in music shop event
       
  7521 // -----------------------------------------------------------------------------
       
  7522 //
       
  7523 void CMPXCollectionViewHgImp::DoFindInMusicShopL( const TDesC& aSongName,
       
  7524                                                 const TDesC& aArtistName,
       
  7525                                                 const TDesC& aAlbumName )
       
  7526     {
       
  7527     MPX_FUNC( "CMPXCollectionViewHgImp::DoFindInMusicShopL" );
       
  7528     CMPXFindInMShop* finder = CMPXFindInMShop::NewL();
       
  7529     CleanupStack::PushL( finder );
       
  7530     HBufC* url = NULL;
       
  7531     url = finder->CreateSearchURLL( aSongName,
       
  7532                                      aArtistName,
       
  7533                                      aAlbumName,
       
  7534                                      KNullDesC,     // Composer - Not used
       
  7535                                      KNullDesC );   // Genre - Not used
       
  7536     CleanupStack::PushL(url);   // the pointer will be poped
       
  7537     RProperty::Set( TUid::Uid(iMusicStoreUID),
       
  7538                     KMShopCategoryId,
       
  7539                     KFindInMShopKeyValid );  // Set Key to Valid
       
  7540 
       
  7541     RProperty::Set( TUid::Uid(iMusicStoreUID),
       
  7542                     KMShopCategoryName,
       
  7543                     *url );
       
  7544 
       
  7545     LaunchMusicShopL();
       
  7546 
       
  7547 
       
  7548     if(url)
       
  7549         {
       
  7550         CleanupStack::PopAndDestroy(url);
       
  7551         }
       
  7552 
       
  7553     CleanupStack::PopAndDestroy( finder ); // finder
       
  7554     REComSession::FinalClose();
       
  7555     }
       
  7556 
       
  7557 
       
  7558 // ----------------------------------------------------------------------------
       
  7559 // CMPXCollectionViewHgImp::SetParamL
       
  7560 // Set the parameter passed in from viewframework to the current select index
       
  7561 // ----------------------------------------------------------------------------
       
  7562 //
       
  7563 void CMPXCollectionViewHgImp::SetParamL( const TDesC* aParam )
       
  7564     {
       
  7565     MPX_FUNC( "CMPXCollectionViewHgImp::SetParamL" );
       
  7566     delete iCurrentSelectedIndex;
       
  7567     iCurrentSelectedIndex = NULL;
       
  7568     iCurrentSelectedIndex = aParam->AllocL();    //  aParam = L"0" for 1st item
       
  7569     }
       
  7570 
       
  7571 
       
  7572 // -----------------------------------------------------------------------------
       
  7573 // CMPlayerCategoryView::DoGetSongMediaPropertyL
       
  7574 // Handle find in music shop event
       
  7575 // -----------------------------------------------------------------------------
       
  7576 //
       
  7577 void CMPXCollectionViewHgImp::DoGetSongMediaPropertyL()
       
  7578     {
       
  7579     MPX_FUNC( "CMPXCollectionViewHgImp::DoGetSongMediaPropertyL" );
       
  7580 
       
  7581     if ( iCurrentSelectedIndex )
       
  7582         {
       
  7583         TLex currentSelectedIndexLex( iCurrentSelectedIndex->Des() );
       
  7584         TInt lexToInt = NULL;
       
  7585         if ( currentSelectedIndexLex.Val( lexToInt ) == KErrNone )
       
  7586             {
       
  7587             // Get media property for the current song
       
  7588             CMPXCollectionPath* cpath = iCollectionUtility->Collection().PathL();
       
  7589             CleanupStack::PushL( cpath );
       
  7590 
       
  7591             cpath->Set( lexToInt );
       
  7592             RArray<TMPXAttribute> attrs;
       
  7593             CleanupClosePushL(attrs);
       
  7594             // to get EMPXMediaGeneralTitle
       
  7595             attrs.Append( KMPXMediaGeneralTitle );
       
  7596             // to get EMPXMediaMusicArtist and EMPXMediaMusicAlbum
       
  7597             attrs.Append( KMPXMediaMusicArtist );
       
  7598             attrs.Append( KMPXMediaMusicAlbum );
       
  7599 
       
  7600             // Call MediaL and handle callback at HandleCollectionMediaL
       
  7601             iCollectionUtility->Collection().MediaL( *cpath, attrs.Array() );
       
  7602             CleanupStack::PopAndDestroy( &attrs );
       
  7603             CleanupStack::PopAndDestroy( cpath );
       
  7604             }
       
  7605         }
       
  7606 
       
  7607     }
       
  7608 
       
  7609 // -----------------------------------------------------------------------------
       
  7610 // CMPXCollectionViewHgImp::HandleFindAllL
       
  7611 // Handle callback for "find" operation
       
  7612 // -----------------------------------------------------------------------------
       
  7613 //
       
  7614 void CMPXCollectionViewHgImp::HandleFindAllL(
       
  7615     const CMPXMedia& aResults,
       
  7616     TBool aComplete,
       
  7617     TInt aError )
       
  7618     {
       
  7619     MPX_FUNC( "CMPXCollectionViewHgImp::HandleFindAllL" );
       
  7620     if ( aError == KErrNone )
       
  7621         {
       
  7622         switch ( iCurrentFindAllLOp )
       
  7623             {
       
  7624             case EMPXOpFindAllLAlbumArtistAddToNewPlaylist:
       
  7625                 {
       
  7626                 iNumSongAddedToPlaylist = aResults.ValueTObjectL<TInt>(
       
  7627                     KMPXMediaArrayCount );
       
  7628                 TBool ret = iCommonUiHelper->CreatePlaylistL(
       
  7629                     aResults, this, this );
       
  7630                 if ( !ret )
       
  7631                     {
       
  7632                     iAddingToNewPlaylist = EFalse;
       
  7633                     }
       
  7634                 break;
       
  7635                 }
       
  7636             case EMPXOpFindAllLAlbumArtistAddToSavedPlaylist:
       
  7637                 {
       
  7638                 if ( !iUserPlaylists )
       
  7639                     {
       
  7640                     MPX_DEBUG1( "CMPXCollectionViewHgImp::HandleFindAllL Null iUserPlaylists" );
       
  7641                     User::Leave( KErrArgument );
       
  7642                     }
       
  7643                 iNumSongAddedToPlaylist = aResults.ValueTObjectL<TInt>(
       
  7644                     KMPXMediaArrayCount );
       
  7645                 MPX_TRAPD( err, iCommonUiHelper->AddToSavedPlaylistL(
       
  7646                     *iUserPlaylists, aResults, this, this ) );
       
  7647                 if ( err != KErrNone )
       
  7648                     {
       
  7649                     HandleError( err );
       
  7650                     }
       
  7651                 break;
       
  7652                 }
       
  7653             case EMPXOpFindAllLRenameAlbum:
       
  7654             case EMPXOpFindAllLRenameArtist:
       
  7655             case EMPXOpFindAllLRenameGenre:
       
  7656             case EMPXOpFindAllLRenameComposer:
       
  7657                 {
       
  7658                 const CMPXMediaArray* mediaArray =
       
  7659                     aResults.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  7660                 User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  7661 
       
  7662                 iSetMediaLCount = mediaArray->Count();
       
  7663                 iInvalidFileExist = EFalse;
       
  7664                 TInt invalidItemCount( 0 );
       
  7665                 MPX_DEBUG2( "CMPXCollectionViewHgImp::HandleFindAllL Rename song count = %d", iSetMediaLCount );
       
  7666                 iIsWaitNoteCanceled = EFalse;
       
  7667                 HBufC* waitNoteString( NULL );
       
  7668                 if ( iSetMediaLCount > 1 )
       
  7669                     {
       
  7670                     // multiple item
       
  7671                     waitNoteString = StringLoader::LoadLC(
       
  7672                         R_MPX_COLLECTION_NOTE_UPDATING_MULTIPLE_ITEMS,
       
  7673                         iSetMediaLCount );
       
  7674                     }
       
  7675                 else
       
  7676                     {
       
  7677                     // single item
       
  7678                     waitNoteString = StringLoader::LoadLC(
       
  7679                         R_MPX_COLLECTION_NOTE_UPDATING_ITEM );
       
  7680                     }
       
  7681                 HandleCommandL( EMPXCmdIgnoreExternalCommand );
       
  7682                 iCommonUiHelper->ShowWaitNoteL( *waitNoteString,
       
  7683                     R_MPX_COLLECTION_WAITNOTE_SOFTKEYS_EMPTY_STOP, EFalse, this );
       
  7684                 CleanupStack::PopAndDestroy( waitNoteString );
       
  7685 
       
  7686                 TPtrC art( KNullDesC );
       
  7687                 if ( (iCurrentFindAllLOp == EMPXOpFindAllLRenameAlbum || iCurrentFindAllLOp == EMPXOpFindAllLRenameArtist )&&
       
  7688                         iContainer )
       
  7689                     {
       
  7690                     CMPXCommonListBoxArrayBase* listboxArray(
       
  7691                         iContainer->ListBoxArray() );
       
  7692                     TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  7693                     const CMPXMedia& currentMedia( listboxArray->MediaL( currentIndex ) );
       
  7694                     if ( currentMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ) )
       
  7695                         {
       
  7696                         art.Set( currentMedia.ValueText( KMPXMediaMusicAlbumArtFileName ) );
       
  7697                         }
       
  7698                     }
       
  7699 
       
  7700                 CMPXMediaArray* entryArray = CMPXMediaArray::NewL();
       
  7701                 CleanupStack::PushL( entryArray );
       
  7702                 TUid collectionId( KNullUid );
       
  7703                 for ( TInt i = 0; i < iSetMediaLCount && !iIsWaitNoteCanceled; i++ )
       
  7704                     {
       
  7705                     CMPXMedia* media( mediaArray->AtL( i ) );
       
  7706                     TUint flags( 0 );
       
  7707                     if( media->IsSupported( KMPXMediaGeneralFlags ) )
       
  7708                         {
       
  7709                         flags = media->ValueTObjectL<TUint>( KMPXMediaGeneralFlags );
       
  7710                         }
       
  7711                     const TDesC& songUri =
       
  7712                         media->ValueText( KMPXMediaGeneralUri );
       
  7713                     TBool fileExist( ConeUtils::FileExists( songUri ) );
       
  7714                     if (!(flags & KMPXMediaGeneralFlagsIsInvalid)
       
  7715                      && !(flags & KMPXMediaGeneralFlagsIsCorrupted)
       
  7716                      && fileExist )
       
  7717                         {
       
  7718                         CMPXMedia* entry = CMPXMedia::NewL();
       
  7719                         CleanupStack::PushL( entry );
       
  7720                         entry->SetTextValueL( KMPXMediaGeneralUri, songUri );
       
  7721                         TMPXItemId id( media->ValueTObjectL<TMPXItemId>(
       
  7722                                         KMPXMediaGeneralId ) );
       
  7723                         collectionId = media->ValueTObjectL<TUid>(
       
  7724                                              KMPXMediaGeneralCollectionId );
       
  7725                         entry->SetTObjectValueL<TMPXItemId>(
       
  7726                             KMPXMediaGeneralId, id );
       
  7727                         entry->SetTObjectValueL<TUid>(
       
  7728                             KMPXMediaGeneralCollectionId, collectionId );
       
  7729                         entry->SetTObjectValueL<TMPXGeneralType>(
       
  7730                             KMPXMediaGeneralType, EMPXItem );
       
  7731                         entry->SetTObjectValueL<TMPXGeneralCategory>(
       
  7732                             KMPXMediaGeneralCategory, EMPXSong );
       
  7733 
       
  7734                         TPtrC ptr( songUri );
       
  7735                         MPX_DEBUG3( "CMPXCollectionViewHgImp::HandleFindAllL setting item id 0x%x, uri %S", id.iId1, &ptr );
       
  7736                         switch ( iCurrentFindAllLOp )
       
  7737                             {
       
  7738                             case EMPXOpFindAllLRenameAlbum:
       
  7739                                 {
       
  7740                                 if ( art.Compare( KNullDesC ) != 0 &&
       
  7741                                         art.Compare(
       
  7742                                             media->ValueText( KMPXMediaMusicAlbumArtFileName ) ) == 0 )
       
  7743                                     {
       
  7744                                     entry->SetTextValueL(
       
  7745                                         KMPXMediaMusicAlbumArtFileName,
       
  7746                                         art );
       
  7747                                     }
       
  7748                                 entry->SetTextValueL(
       
  7749                                     KMPXMediaMusicAlbum, *iNewName );
       
  7750                                 break;
       
  7751                                 }
       
  7752                             case EMPXOpFindAllLRenameArtist:
       
  7753                                 {
       
  7754                                 if ( art.Compare( KNullDesC ) != 0 &&
       
  7755                                         art.Compare(
       
  7756                                             media->ValueText( KMPXMediaMusicAlbumArtFileName ) ) == 0 )
       
  7757                                     {
       
  7758                                     entry->SetTextValueL(
       
  7759                                         KMPXMediaMusicAlbumArtFileName,
       
  7760                                         art );
       
  7761                                     }
       
  7762                                 entry->SetTextValueL(
       
  7763                                     KMPXMediaMusicArtist, *iNewName );
       
  7764                                 break;
       
  7765                                 }
       
  7766                             case EMPXOpFindAllLRenameGenre:
       
  7767                                 {
       
  7768                                 entry->SetTextValueL(
       
  7769                                     KMPXMediaMusicGenre, *iNewName );
       
  7770                                 break;
       
  7771                                 }
       
  7772                             case EMPXOpFindAllLRenameComposer:
       
  7773                                 {
       
  7774                                 entry->SetTextValueL(
       
  7775                                     KMPXMediaMusicComposer, *iNewName );
       
  7776                                 break;
       
  7777                                 }
       
  7778                             default:
       
  7779                                 {
       
  7780                                 // should not reach here
       
  7781                                 ASSERT( 0 );
       
  7782                                 break;
       
  7783                                 }
       
  7784                             }
       
  7785                         if ( (iCurrentFindAllLOp == EMPXOpFindAllLRenameAlbum || iCurrentFindAllLOp == EMPXOpFindAllLRenameArtist) &&
       
  7786                                 art.Compare( KNullDesC ) != 0 &&
       
  7787                                 art.Compare(
       
  7788                                     media->ValueText( KMPXMediaMusicAlbumArtFileName ) ) == 0 )
       
  7789                             {
       
  7790                             entryArray->InsertL( entry, 0 );  // ownership xfer
       
  7791                             }
       
  7792                         else
       
  7793                             {
       
  7794                             entryArray->AppendL( entry );  // ownership xfer
       
  7795                             }
       
  7796                         CleanupStack::Pop( entry );
       
  7797                         }
       
  7798                     else
       
  7799                         {
       
  7800                         iInvalidFileExist = ETrue;
       
  7801                         invalidItemCount++;
       
  7802                         if ( !fileExist )
       
  7803                             {
       
  7804                             UpdateDatabaseFlagL( KErrNotFound, *media,
       
  7805                                 KMPXMediaGeneralFlagsIsInvalid, ETrue, EFalse );
       
  7806                             }
       
  7807                         }
       
  7808                     }
       
  7809                 // Package array of items to set
       
  7810                 //
       
  7811                 CMPXMedia* setData = CMPXMedia::NewL();
       
  7812                 CleanupStack::PushL( setData );
       
  7813                 setData->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup );
       
  7814                 setData->SetCObjectValueL( KMPXMediaArrayContents, entryArray );
       
  7815 
       
  7816                 // Generate the command
       
  7817                 //
       
  7818                 CMPXCommand* command = CMPXCommand::NewL();
       
  7819                 CleanupStack::PushL( command );
       
  7820                 command->SetTObjectValueL<TMPXCommandId>( KMPXCommandGeneralId,
       
  7821                                                           KMPXCommandIdCollectionSet );
       
  7822                 command->SetTObjectValueL<TInt>( KMPXCommandGeneralCollectionId,
       
  7823                                                  collectionId.iUid);
       
  7824                 command->SetCObjectValueL( KMPXCommandColSetMedia, setData );
       
  7825 
       
  7826                 iCollectionUtility->Collection().CommandL( *command );
       
  7827 
       
  7828                 // Cleanup
       
  7829                 CleanupStack::PopAndDestroy( command );
       
  7830                 CleanupStack::PopAndDestroy( setData );
       
  7831                 CleanupStack::PopAndDestroy( entryArray );
       
  7832 
       
  7833                 iSetMediaLCount = 1;  // 1 async set
       
  7834                 MPX_DEBUG3( "CMPXCollectionViewHgImp::HandleFindAllL valid items = %d, invalid items = %d", iSetMediaLCount, invalidItemCount );
       
  7835                 if ( iSetMediaLCount == 0 )
       
  7836                     {
       
  7837                     // if all items are invalid, display note
       
  7838                     // now instead of waiting for callback
       
  7839                     HandleRenameOpCompleteL();
       
  7840                     }
       
  7841                 break;
       
  7842                 }
       
  7843             case EMPXOpFindAllLPlaylistTracksCount:
       
  7844                 {
       
  7845                 TInt trackCount = aResults.ValueTObjectL<TInt>( KMPXMediaArrayCount );
       
  7846                 MPX_DEBUG2( "CMPXCollectionViewHgImp:: playlist tracks count = %d", trackCount );
       
  7847                 if ( trackCount == 0 )
       
  7848                     {
       
  7849                     // empty playlist, display info note
       
  7850                     HBufC* string = StringLoader::LoadLC(
       
  7851                         R_MPX_COLLECTION_NOTE_EMPTY_PLAYLIST );
       
  7852                     iCommonUiHelper->DisplayInfoNoteL( *string );
       
  7853                     CleanupStack::PopAndDestroy( string );
       
  7854                     }
       
  7855                 else
       
  7856                     {
       
  7857                     HandleCommandL( EMPXCmdForcePlay );
       
  7858                     }
       
  7859                 break;
       
  7860                 }
       
  7861             case EMPXOpFindAllLUpnp:
       
  7862                 {
       
  7863                 if ( iUpnpFrameworkSupport )
       
  7864                     {
       
  7865                     DoHandleCopyToRemoteL( aResults, aComplete );
       
  7866                     }
       
  7867                 break;
       
  7868                 }
       
  7869             case EMPXOpFindAllLUpnpPlayback:
       
  7870                 {
       
  7871                 if ( iUpnpFrameworkSupport )
       
  7872                     {
       
  7873                     TInt trackCount = aResults.ValueTObjectL<TInt>( KMPXMediaArrayCount );
       
  7874                     MPX_DEBUG2( "CMPXCollectionViewHgImp:: playlist tracks count = %d", trackCount );
       
  7875                     if ( trackCount > 0 )
       
  7876                         {
       
  7877                         TInt currentListBoxItemIndex(
       
  7878                             iContainer->CurrentLbxItemIndex() );
       
  7879                         if ( currentListBoxItemIndex >= 0 )
       
  7880                             {
       
  7881                             GetCurrentPlayerDetails();
       
  7882 
       
  7883                             // Needed to reset the status of iPreservedState
       
  7884                             if ( EPbStateStopped == iPlaybackUtility->StateL() )
       
  7885                                 {
       
  7886                                 iPlaybackUtility->CommandL(EPbCmdResetPreserveState);
       
  7887                                 }
       
  7888                             if(iCollectionCacheReady)
       
  7889                                 {
       
  7890                                 iCollectionUtility->Collection().OpenL(
       
  7891                                                 currentListBoxItemIndex,
       
  7892                                                 EMPXOpenPlaylistOnly);
       
  7893 								iFirstIncrementalBatch = ETrue;
       
  7894                                 }
       
  7895                             }
       
  7896                         }
       
  7897                     else
       
  7898                         {
       
  7899                         // empty playlist, display info note
       
  7900                         HBufC* string = StringLoader::LoadLC(
       
  7901                             R_MPX_COLLECTION_NOTE_EMPTY_PLAYLIST );
       
  7902                         iCommonUiHelper->DisplayInfoNoteL( *string );
       
  7903                         CleanupStack::PopAndDestroy( string );
       
  7904                         }
       
  7905                     }
       
  7906                 break;
       
  7907                 }
       
  7908             default:
       
  7909                 {
       
  7910                 // should not reach here
       
  7911                 break;
       
  7912                 }
       
  7913             }
       
  7914         }
       
  7915     else
       
  7916         {
       
  7917         HandleError( aError );
       
  7918         }
       
  7919     iCurrentFindAllLOp = EMPXOpFindAllLIdle;
       
  7920 
       
  7921     if ( !iUpnpFrameworkSupport )
       
  7922         {
       
  7923         // Remove compilation warnings
       
  7924         (void)aComplete;
       
  7925         }
       
  7926     }
       
  7927 
       
  7928 // -----------------------------------------------------------------------------
       
  7929 // CMPXCollectionViewHgImp::HandleViewActivation
       
  7930 // Handle view activation
       
  7931 // -----------------------------------------------------------------------------
       
  7932 //
       
  7933 void CMPXCollectionViewHgImp::HandleViewActivation(
       
  7934     const TUid& aCurrentViewType,
       
  7935     const TUid& /*aPreviousViewType*/ )
       
  7936     {
       
  7937     MPX_FUNC( "CMPXCollectionViewHgImp::HandleViewActivation" );
       
  7938 
       
  7939     if ( aCurrentViewType.iUid == KMPXPluginTypeCollectionUid )
       
  7940         {
       
  7941         if( iAddingSong )
       
  7942             {
       
  7943             iAddingSong = EFalse;
       
  7944             TRAP_IGNORE( GetDurationL() );
       
  7945             }
       
  7946         if( iInAlbumArtDialog )
       
  7947             {
       
  7948             iInAlbumArtDialog = EFalse;
       
  7949             TRAP_IGNORE( UpdateTitlePaneL() );
       
  7950             }
       
  7951         if( iInSongDetails )
       
  7952             {
       
  7953             iInSongDetails = EFalse;
       
  7954             }
       
  7955         }
       
  7956      else if ( ( aCurrentViewType.iUid == KMPXPluginTypePlaybackUid ) && ( iGoToNowPlaying == EFalse ) )        
       
  7957         {
       
  7958 		// It is view switching when launched from other applications
       
  7959 		// hide this view to avoid flickering 
       
  7960 		// since this view is the current active view, it receives this event
       
  7961 
       
  7962 		if ( iContainer )
       
  7963         	{
       
  7964             iContainer->HideContainerWindow();
       
  7965    	  
       
  7966             // set title to blank to avoid title flickering
       
  7967             CAknTitlePane* title( static_cast<CAknTitlePane*>
       
  7968                 ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ))));
       
  7969             if ( title )
       
  7970                 {
       
  7971                 title->SetTextL(KEmptyTitle); 
       
  7972                 title->DrawNow();
       
  7973 	            }
       
  7974 		    }
       
  7975         }
       
  7976     }
       
  7977 
       
  7978 // -----------------------------------------------------------------------------
       
  7979 // CMPXCollectionViewHgImp::HandleViewUpdate
       
  7980 // -----------------------------------------------------------------------------
       
  7981 //
       
  7982 void CMPXCollectionViewHgImp::HandleViewUpdate(
       
  7983     TUid /* aViewUid */,
       
  7984     MMPXViewActivationObserver::TViewUpdateEvent /* aUpdateEvent */,
       
  7985     TBool /* aLoaded */,
       
  7986     TInt /* aData */)
       
  7987     {
       
  7988     // Do nothing, this should be handled by the AppUI
       
  7989     }
       
  7990 
       
  7991 // -----------------------------------------------------------------------------
       
  7992 // CMPXCollectionViewHgImp::HandleViewActivation
       
  7993 // -----------------------------------------------------------------------------
       
  7994 //
       
  7995 void CMPXCollectionViewHgImp::HandleViewActivation(const TVwsViewId& aNewlyActivatedViewId,
       
  7996                                                  const TVwsViewId& /*aViewIdToBeDeactivated */)
       
  7997     {
       
  7998     }
       
  7999 
       
  8000 // -----------------------------------------------------------------------------
       
  8001 // CMPXCollectionViewHgImp::HandleViewDeactivation
       
  8002 // -----------------------------------------------------------------------------
       
  8003 //
       
  8004 void CMPXCollectionViewHgImp::HandleViewDeactivation(const TVwsViewId& aViewIdToBeDeactivated,
       
  8005                                                    const TVwsViewId& /*aNewlyActivatedViewId*/)
       
  8006     {
       
  8007     }
       
  8008 
       
  8009 // -----------------------------------------------------------------------------
       
  8010 // CMPXCollectionViewHgImp::FillAiwParameters
       
  8011 // -----------------------------------------------------------------------------
       
  8012 //
       
  8013 void CMPXCollectionViewHgImp::FillAiwParametersL(
       
  8014     CAiwGenericParamList& aParamList )
       
  8015     {
       
  8016     CMPXCommonListBoxArrayBase* array( iContainer->ListBoxArray() );
       
  8017     const CMPXMedia& media = array->MediaL(
       
  8018         iContainer->CurrentLbxItemIndex() );
       
  8019     TPtrC location( media.ValueText(KMPXMediaGeneralUri) );
       
  8020     TPtrC mimeType( media.ValueText(KMPXMediaGeneralMimeType) );
       
  8021 
       
  8022     if ( !location.Length() )
       
  8023         {
       
  8024         if ( media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) == KMPXInvalidItemId )
       
  8025             {
       
  8026             // highlighted item is not yet available
       
  8027             MPX_DEBUG1( "CMPXCollectionViewHgImp::FillAiwParametersL item not yet fetched" );
       
  8028             User::Leave( KMPXErrDataNotReady );
       
  8029             }
       
  8030         else
       
  8031             {
       
  8032             TMPXItemId id(
       
  8033                     media.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
  8034             CMPXMedia* criteria = CMPXMedia::NewL();
       
  8035             CleanupStack::PushL( criteria );
       
  8036             criteria->SetTObjectValueL<TMPXGeneralType>(
       
  8037                 KMPXMediaGeneralType, EMPXItem );
       
  8038             criteria->SetTObjectValueL<TMPXGeneralCategory>(
       
  8039                 KMPXMediaGeneralCategory, EMPXSong );
       
  8040             criteria->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, id );
       
  8041 
       
  8042             RArray<TMPXAttribute> attrs;
       
  8043             CleanupClosePushL( attrs );
       
  8044             attrs.Append( KMPXMediaGeneralUri );
       
  8045             attrs.Append( KMPXMediaGeneralMimeType );
       
  8046 
       
  8047             CMPXMedia* songInfo = iCollectionUtility->Collection().FindAllL( *criteria,
       
  8048                                                              attrs.Array() );
       
  8049             CleanupStack::PopAndDestroy( &attrs );
       
  8050             CleanupStack::PushL( songInfo );
       
  8051 
       
  8052             const CMPXMediaArray* mediaArray(
       
  8053                 songInfo->Value<CMPXMediaArray>( KMPXMediaArrayContents ) );
       
  8054             User::LeaveIfNull(const_cast<CMPXMediaArray*>(mediaArray));
       
  8055 
       
  8056             if ( mediaArray->Count() > 0 )
       
  8057                 {
       
  8058                 CMPXMedia* si( mediaArray->AtL( 0 ) );
       
  8059                 location.Set( si->ValueText(KMPXMediaGeneralUri) );
       
  8060                 mimeType.Set( si->ValueText(KMPXMediaGeneralMimeType) );
       
  8061                 }
       
  8062             CleanupStack::PopAndDestroy( songInfo );
       
  8063             CleanupStack::PopAndDestroy( criteria );
       
  8064             }
       
  8065         }
       
  8066 
       
  8067     TAiwVariant varMime(mimeType);
       
  8068     if ( !mimeType.Length() && ( iMediaRecognizer ) )
       
  8069         {
       
  8070         varMime.Set(iMediaRecognizer->MimeTypeL(location));
       
  8071         }
       
  8072     TAiwGenericParam paramMime(EGenericParamMIMEType, varMime);
       
  8073     aParamList.Reset();
       
  8074     aParamList.AppendL(paramMime);
       
  8075     TAiwVariant varFile(location);
       
  8076     TAiwGenericParam paramFile(EGenericParamFile, varFile);
       
  8077     aParamList.AppendL(paramFile);
       
  8078     }
       
  8079 
       
  8080 // -----------------------------------------------------------------------------
       
  8081 // CMPXCollectionViewHgImp::GetUint32Presentation
       
  8082 //
       
  8083 // (other items were commented in a header).
       
  8084 // -----------------------------------------------------------------------------
       
  8085 //
       
  8086 void CMPXCollectionViewHgImp::GetUint32Presentation( TUint32& aResult,
       
  8087                                                    const TDesC8& aBuf,
       
  8088                                                    TInt aOffset )
       
  8089     {
       
  8090     aResult = 0;
       
  8091     const TInt KProEngByteLength( 8 );
       
  8092     const TInt length( aBuf.Length() );
       
  8093     const TInt maxBitShift( KProEngByteLength * ( length - 1 ) );
       
  8094 
       
  8095     for( TInt i( 0 ); i<length; ++i )
       
  8096         {
       
  8097         aResult |= ( aBuf[aOffset + i] <<
       
  8098                    ( maxBitShift - ( KProEngByteLength * i ) ) );
       
  8099         }
       
  8100     }
       
  8101 
       
  8102 // -----------------------------------------------------------------------------
       
  8103 // CMPXCollectionViewHgImp::LaunchMusicShopL
       
  8104 // Launch music shop application
       
  8105 // -----------------------------------------------------------------------------
       
  8106 //
       
  8107 void CMPXCollectionViewHgImp::LaunchOperatorJavaMusicShopL(TUid aUid)
       
  8108     {
       
  8109     MPX_FUNC( "CMPXCollectionViewHgImp::LaunchOperatorMusicShopL" );
       
  8110     TThreadId threadId;
       
  8111     RApaLsSession apaSession;
       
  8112     User::LeaveIfError( apaSession.Connect() );
       
  8113     CleanupClosePushL( apaSession );
       
  8114     apaSession.StartDocument(_L(""), aUid, threadId);
       
  8115     CleanupStack::PopAndDestroy( &apaSession ); // close apaSession
       
  8116     }
       
  8117 
       
  8118 // -----------------------------------------------------------------------------
       
  8119 // CMPXCollectionViewHgImp::LaunchMusicShopL
       
  8120 // Launch music shop application
       
  8121 // -----------------------------------------------------------------------------
       
  8122 //
       
  8123 void CMPXCollectionViewHgImp::LaunchOperatorNativeMusicShopL()
       
  8124     {
       
  8125     MPX_FUNC( "CMPXCollectionViewHgImp::LaunchMusicShopL" );
       
  8126 
       
  8127     TApaTaskList taskList( iCoeEnv->WsSession() );
       
  8128     TApaTask task = taskList.FindApp( TUid::Uid(iOperatorNativeMusicStoreUID) );
       
  8129 
       
  8130     if ( task.Exists() )
       
  8131         {
       
  8132         GfxTransEffect::BeginFullScreen( 
       
  8133         AknTransEffect::EApplicationStart,
       
  8134             TRect(), 
       
  8135             AknTransEffect::EParameterType, 
       
  8136             AknTransEffect::GfxTransParam( TUid::Uid(iOperatorNativeMusicStoreUID),        
       
  8137             AknTransEffect::TParameter::EActivateExplicitContinue ));                           
       
  8138         task.BringToForeground();
       
  8139         }
       
  8140     else
       
  8141         {
       
  8142         RApaLsSession session;
       
  8143         if ( KErrNone == session.Connect() )
       
  8144             {
       
  8145             CleanupClosePushL( session );
       
  8146             TThreadId threadId;
       
  8147             session.CreateDocument( KNullDesC, TUid::Uid(iOperatorNativeMusicStoreUID), threadId );
       
  8148             CleanupStack::PopAndDestroy(&session);
       
  8149             }
       
  8150         }
       
  8151     }
       
  8152 // -----------------------------------------------------------------------------
       
  8153 // CMPXCollectionViewHgImp::LaunchOperatorURLMusicShopL
       
  8154 // Launch music shop URL application
       
  8155 // -----------------------------------------------------------------------------
       
  8156 //
       
  8157 void CMPXCollectionViewHgImp::LaunchOperatorURLMusicShopL()
       
  8158     {
       
  8159     MPX_FUNC( "CMPXCollectionViewHgImp::LaunchOperatorURLMusicShopL" );
       
  8160     const TUid KOSSBrowserUidValue = {0x10008D39}; // 0x1020724D for S60 3rd Ed
       
  8161     TUid id(KOSSBrowserUidValue);
       
  8162     TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
  8163     TApaTask task = taskList.FindApp(id);
       
  8164 
       
  8165     if ( task.Exists() )
       
  8166         {
       
  8167         GfxTransEffect::BeginFullScreen( 
       
  8168         AknTransEffect::EApplicationStart,
       
  8169             TRect(), 
       
  8170             AknTransEffect::EParameterType, 
       
  8171             AknTransEffect::GfxTransParam( id,        
       
  8172             AknTransEffect::TParameter::EActivateExplicitContinue ));                            
       
  8173         task.BringToForeground();
       
  8174         if ( iOperatorMusicStoreURI->Length() != NULL )
       
  8175             {
       
  8176             TBuf8<KMPXMaxHistoryLength> tempUrl;
       
  8177             tempUrl.Copy(iOperatorMusicStoreURI->Des());
       
  8178             task.SendMessage(TUid::Uid(0), tempUrl);
       
  8179             }
       
  8180         }
       
  8181     else
       
  8182         {
       
  8183         RApaLsSession apaLsSession;
       
  8184         if ( KErrNone == apaLsSession.Connect() )
       
  8185             {
       
  8186             CleanupClosePushL( apaLsSession );
       
  8187             TThreadId threadId;
       
  8188 
       
  8189  			apaLsSession.StartDocument(*iOperatorMusicStoreURI, KOSSBrowserUidValue, threadId);
       
  8190          	CleanupStack::PopAndDestroy(&apaLsSession);
       
  8191             }
       
  8192 		}
       
  8193 	}
       
  8194 
       
  8195 // -----------------------------------------------------------------------------
       
  8196 // CMPXCollectionViewHgImp::StoreListboxItemIndexL
       
  8197 // Stores the current list box item index.
       
  8198 // -----------------------------------------------------------------------------
       
  8199 //
       
  8200 void CMPXCollectionViewHgImp::StoreListboxItemIndexL()
       
  8201 	{
       
  8202     TInt currentIndex( iContainer->CurrentLbxItemIndex() );
       
  8203 
       
  8204 	CMPXCommand* command = CMPXCommand::NewL();
       
  8205 	CleanupStack::PushL( command );
       
  8206 	command->SetTObjectValueL<TMPXCommandId>( KMPXCommandGeneralId,
       
  8207 											  KMPXCommandIdCollectionSelect );
       
  8208 	command->SetTObjectValueL( KMPXCommandCollectionSelectIndex, currentIndex );
       
  8209 	command->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
  8210 	iCollectionUtility->Collection().CommandL( *command );
       
  8211 	CleanupStack::PopAndDestroy( command );
       
  8212 	}
       
  8213 
       
  8214 
       
  8215 // -----------------------------------------------------------------------------
       
  8216 // CMPXCollectionViewHgImp::ChangeCbaVisibility
       
  8217 // -----------------------------------------------------------------------------
       
  8218 //
       
  8219 void CMPXCollectionViewHgImp::ChangeCbaVisibility( TBool aVisible )
       
  8220     {
       
  8221     CEikButtonGroupContainer* cba = Cba();
       
  8222     if( cba )
       
  8223 		{
       
  8224         cba->MakeVisible( aVisible );
       
  8225 		cba->DrawDeferred();
       
  8226 		}
       
  8227     }
       
  8228 
       
  8229 void CMPXCollectionViewHgImp::UpdateCba()
       
  8230     {
       
  8231     TRAP_IGNORE( 
       
  8232         {
       
  8233         CMPXCollectionPath* cpath( iCollectionUtility->Collection().PathL() );
       
  8234         CleanupStack::PushL( cpath );
       
  8235     
       
  8236         CMPXCommonListBoxArrayBase* listboxArray(
       
  8237             iContainer->ListBoxArray() );
       
  8238         const CMPXMedia& media( listboxArray->ContainerMedia() );
       
  8239     
       
  8240         TMPXGeneralType containerType( EMPXNoType );
       
  8241         if ( media.IsSupported( KMPXMediaGeneralType ) )
       
  8242             {
       
  8243             containerType = media.ValueTObjectL<TMPXGeneralType>( KMPXMediaGeneralType );
       
  8244             }
       
  8245     
       
  8246         TMPXGeneralCategory containerCategory( EMPXNoCategory );
       
  8247         if ( media.IsSupported( KMPXMediaGeneralCategory ) )
       
  8248             {
       
  8249             containerCategory = media.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
  8250             }
       
  8251         TBool landscapeOrientation = Layout_Meta_Data::IsLandscapeOrientation();
       
  8252         CEikButtonGroupContainer* cba = Cba();
       
  8253         if ( cba && containerType == EMPXGroup && containerCategory == EMPXAlbum && landscapeOrientation )
       
  8254             {
       
  8255             cba->SetCommandSetL( R_MPX_COLLECTION_TRANSPARENT_CBA );
       
  8256             cba->MakeVisible( EFalse );
       
  8257             cba->DrawDeferred();
       
  8258             }
       
  8259         else if ( cba )
       
  8260             {
       
  8261 			if ( iContainer->IsTBoneView() )
       
  8262 				{
       
  8263             	cba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  8264 				}
       
  8265 			else
       
  8266 				{
       
  8267 				cba->SetCommandSetL(
       
  8268 					( cpath->Levels() == 3 && !iIsEmbedded ) ?
       
  8269 					R_MPX_OPTIONS_HIDE_CBA : R_AVKON_SOFTKEYS_OPTIONS_BACK );
       
  8270 				}
       
  8271             cba->MakeVisible( ETrue );
       
  8272             cba->DrawDeferred();
       
  8273             }
       
  8274         CleanupStack::PopAndDestroy(cpath);
       
  8275         });
       
  8276     }
       
  8277 
       
  8278 // -----------------------------------------------------------------------------
       
  8279 // CMPXCollectionViewHgImp::OpenAllSongsL
       
  8280 // Open the collection at all songs level.
       
  8281 // -----------------------------------------------------------------------------
       
  8282 //
       
  8283 void CMPXCollectionViewHgImp::OpenAllSongsL()
       
  8284 	{
       
  8285 	CMPXCollectionPath* path = iCollectionUiHelper->MusicAllSongsPathL();
       
  8286 	CleanupStack::PushL( path );
       
  8287 	iCollectionUtility->Collection().OpenL( *path );
       
  8288 	CleanupStack::PopAndDestroy( path );
       
  8289 	}
       
  8290 
       
  8291 
       
  8292 // -----------------------------------------------------------------------------
       
  8293 // CMPXCollectionViewHgImp::OpenArtistAlbumsL
       
  8294 // Open the collection at artist & albums level.
       
  8295 // -----------------------------------------------------------------------------
       
  8296 //
       
  8297 void CMPXCollectionViewHgImp::OpenArtistAlbumsL()
       
  8298 	{
       
  8299 	CMPXCollectionPath* path = iCollectionUiHelper->MusicMenuPathL();
       
  8300 	CleanupStack::PushL( path );
       
  8301 	path->AppendL(KMPXCollectionArtistAlbum);
       
  8302 	iCollectionUtility->Collection().OpenL( *path );
       
  8303 	CleanupStack::PopAndDestroy( path );
       
  8304 	}
       
  8305 
       
  8306 // -----------------------------------------------------------------------------
       
  8307 // CMPXCollectionViewHgImp::OpenPlaylistsL
       
  8308 // Open the collection at playlists level.
       
  8309 // -----------------------------------------------------------------------------
       
  8310 //
       
  8311 void CMPXCollectionViewHgImp::OpenPlaylistsL()
       
  8312 	{
       
  8313 	CMPXCollectionPath* path = iCollectionUiHelper->MusicPlaylistPathL();
       
  8314 	CleanupStack::PushL( path );
       
  8315 	iCollectionUtility->Collection().OpenL( *path );
       
  8316 	CleanupStack::PopAndDestroy( path );
       
  8317 	}
       
  8318 
       
  8319 // -----------------------------------------------------------------------------
       
  8320 // CMPXCollectionViewHgImp::OpenGenreL
       
  8321 // Open the collection at genre level.
       
  8322 // -----------------------------------------------------------------------------
       
  8323 //
       
  8324 void CMPXCollectionViewHgImp::OpenGenreL()
       
  8325 	{
       
  8326 	CMPXCollectionPath* path = iCollectionUiHelper->MusicMenuPathL();
       
  8327 	CleanupStack::PushL( path );
       
  8328 	path->AppendL(KMPXCollectionGenre); // Genre
       
  8329 	iCollectionUtility->Collection().OpenL( *path );
       
  8330 	CleanupStack::PopAndDestroy( path );
       
  8331 	}
       
  8332 
       
  8333 // -----------------------------------------------------------------------------
       
  8334 // CMPXCollectionViewHgImp::OpenPodcastsL
       
  8335 // Open the collection at podcasts level.
       
  8336 // -----------------------------------------------------------------------------
       
  8337 //
       
  8338 void CMPXCollectionViewHgImp::OpenPodcastsL()
       
  8339 	{
       
  8340 	CMPXCollectionPath* path = iCollectionUiHelper->PodCastMenuPathL();
       
  8341 	CleanupStack::PushL( path );
       
  8342 	iCollectionUtility->Collection().OpenL( *path );
       
  8343 	CleanupStack::PopAndDestroy( path );
       
  8344 	}
       
  8345 
       
  8346 
       
  8347 
       
  8348 // -----------------------------------------------------------------------------
       
  8349 // CMPXCollectionViewHgImp::SaveSelectedAlbumL
       
  8350 // -----------------------------------------------------------------------------
       
  8351 //
       
  8352 void CMPXCollectionViewHgImp::SaveSelectedAlbumL(CMPXMedia &aMedia)
       
  8353     {
       
  8354     MPX_FUNC( "CMPXCollectionViewHgImp::SaveSelectedAlbumL" );
       
  8355     if (iStoredAlbum)
       
  8356 		{
       
  8357 		delete iStoredAlbum;
       
  8358 		}
       
  8359     iStoredAlbum = CMPXMedia::NewL(aMedia);
       
  8360     }
       
  8361 
       
  8362 
       
  8363 // -----------------------------------------------------------------------------
       
  8364 // CMPXCollectionViewHgImp::RestoreSelectedAlbum
       
  8365 // -----------------------------------------------------------------------------
       
  8366 //
       
  8367 const CMPXMedia* CMPXCollectionViewHgImp::RestoreSelectedAlbum ()
       
  8368     {
       
  8369     MPX_FUNC( "CMPXCollectionViewHgImp::RestoreSelectedAlbum" );
       
  8370 
       
  8371 	return iStoredAlbum;
       
  8372     }
       
  8373 
       
  8374 // -----------------------------------------------------------------------------
       
  8375 // CMPXCollectionViewHgImp::DisplayAboutDlgL()
       
  8376 // -----------------------------------------------------------------------------
       
  8377 //
       
  8378 void CMPXCollectionViewHgImp::DisplayAboutDlgL() const
       
  8379      {
       
  8380       TBuf<32> version;
       
  8381       version.Format(_L("%d.%d.%d"), MUSIC_PLAYER_VERSION_MAJOR, MUSIC_PLAYER_VERSION_MINOR, MUSIC_PLAYER_VERSION_WEEK);
       
  8382       HBufC* aboutContent  = StringLoader::LoadL(R_QTN_MUS_ABOUT_VERSION ,version);
       
  8383       HBufC* aboutTitle  = StringLoader::LoadLC(R_QTN_MUS_ABOUT_NOTE);
       
  8384       CleanupStack::PushL(aboutContent );
       
  8385       CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(*aboutContent );
       
  8386       CleanupStack::PushL(dlg);
       
  8387       dlg->SetHeaderTextL(*aboutTitle );
       
  8388       dlg->ExecuteLD(R_MPX_ABOUT_DIALOG);
       
  8389       CleanupStack::Pop(dlg);
       
  8390       CleanupStack::PopAndDestroy(2,aboutTitle ); 
       
  8391      }
       
  8392 	 
       
  8393 // -----------------------------------------------------------------------------
       
  8394 // CMPXCollectionViewHgImp::EducatingUserDialog
       
  8395 // Display Educating User Dialog
       
  8396 // -----------------------------------------------------------------------------
       
  8397 //
       
  8398 void CMPXCollectionViewHgImp::EducatingUserDialog ()
       
  8399     {
       
  8400     MPX_FUNC( "CMPXCollectionViewHgImp::EducatingUserDialog " );
       
  8401     CAknMessageQueryDialog* query = new (ELeave) CAknMessageQueryDialog(
       
  8402             CAknMessageQueryDialog::ENoTone);
       
  8403     CleanupStack::PushL(query);
       
  8404 
       
  8405     HBufC* message= HBufC::NewLC(500); 
       
  8406 
       
  8407     message->Des().Append(_L("<AknMessageQuery Link>")); 
       
  8408     message->Des().Append(iEducateUserURI->Des());
       
  8409     message->Des().Append(_L("</AknMessageQuery Link>"));
       
  8410     HBufC* promptTxt = StringLoader::LoadLC(
       
  8411             R_QTN_NMP_NOTE_EDUCATING_THE_USER,message->Des() );
       
  8412     query->SetMessageTextL( promptTxt->Des());
       
  8413     TCallBack cb( CMPXCollectionViewHgImp::LinkCallback, this );
       
  8414     query->SetLink( cb );
       
  8415 
       
  8416     CleanupStack::PopAndDestroy( promptTxt );
       
  8417     CleanupStack::PopAndDestroy( message );
       
  8418     CleanupStack::Pop( query );
       
  8419             
       
  8420     if(query->ExecuteLD( R_MPX_CUI_EDUCATING_THE_USER_QUERY ))
       
  8421         {
       
  8422         iRepository->Set( KEducatingPopupState, EMPXShowEducatingPopup );
       
  8423         iEducatingPopupState = EMPXShowEducatingPopup;
       
  8424         }
       
  8425     else
       
  8426         {
       
  8427         iRepository->Set( KEducatingPopupState, EMPXDonotShowEducatingPopup );
       
  8428         iEducatingPopupState = EMPXDonotShowEducatingPopup; 
       
  8429         } 
       
  8430     }
       
  8431 
       
  8432 // -----------------------------------------------------------------------------
       
  8433 // CMPXCollectionViewHgImp::LaunchEducatingURL
       
  8434 // Launch Educating URL
       
  8435 // -----------------------------------------------------------------------------
       
  8436 //
       
  8437 void CMPXCollectionViewHgImp::LaunchEducatingURL()
       
  8438     {
       
  8439     MPX_FUNC( "CMPXCollectionViewHgImp::LaunchEducatingURL" );
       
  8440     const TUid KOSSBrowserUidValue = {0x10008D39}; // 0x1020724D for S60 3rd Ed
       
  8441     TUid id(KOSSBrowserUidValue);
       
  8442     TApaTaskList taskList(CEikonEnv::Static()->WsSession());
       
  8443     TApaTask task = taskList.FindApp(id);
       
  8444   
       
  8445     if ( task.Exists() )
       
  8446         {
       
  8447         task.BringToForeground();
       
  8448         if ( iEducateUserURI->Length() != NULL )
       
  8449             {
       
  8450             TBuf8<KMPXMaxHistoryLength> tempUrl;
       
  8451             tempUrl.Copy(iEducateUserURI->Des());
       
  8452             task.SendMessage(TUid::Uid(0), tempUrl);
       
  8453             }
       
  8454         }
       
  8455     else
       
  8456         {
       
  8457         RApaLsSession apaLsSession;
       
  8458         if ( KErrNone == apaLsSession.Connect() )
       
  8459             {
       
  8460             CleanupClosePushL( apaLsSession );
       
  8461             TThreadId threadId;
       
  8462 
       
  8463             apaLsSession.StartDocument(*iEducateUserURI, KOSSBrowserUidValue, threadId);
       
  8464             CleanupStack::PopAndDestroy(&apaLsSession);
       
  8465             }
       
  8466         }
       
  8467      }
       
  8468 
       
  8469 // -----------------------------------------------------------------------------
       
  8470 // CMPXCollectionViewHgImp::LinkCallback
       
  8471 // Call back for Educating User URL 
       
  8472 // -----------------------------------------------------------------------------
       
  8473 // 
       
  8474 TInt CMPXCollectionViewHgImp::LinkCallback(TAny* aPtr)
       
  8475     {
       
  8476     CMPXCollectionViewHgImp* ptr = static_cast<CMPXCollectionViewHgImp*>( aPtr );
       
  8477     TRAPD( err, ptr->LaunchEducatingURL() );
       
  8478     MPX_DEBUG2( "CMPXCollectionViewHgImp::LinkCallback()-err:%d", err );
       
  8479     return err;
       
  8480     }
       
  8481 
       
  8482 // -----------------------------------------------------------------------------
       
  8483 // CMPXCollectionViewHgImp::NeedToShowEducatingDialog
       
  8484 // -----------------------------------------------------------------------------
       
  8485 //
       
  8486 TBool CMPXCollectionViewHgImp::NeedToShowEducatingDialog()
       
  8487     {
       
  8488     if(iEducateUserURI->Length() > 0 && iCollectionReady && //If educating user URI is in cenrep and Collection is Ready
       
  8489       //(iEducatingPopupState == EMPXInitialEducatingPopup || //If Music Player is launched first time after phone flash 
       
  8490       (iEducatingPopupState == EMPXShowEducatingPopup && iPopuponRefresh)) //If user pressed yes on "Remind me later" and its manual refresh with some song added
       
  8491         {
       
  8492         return ETrue;
       
  8493         }
       
  8494     else
       
  8495         return EFalse;
       
  8496     }
       
  8497 
       
  8498 void CMPXCollectionViewHgImp::DimAllOptions(TInt aResourceId, CEikMenuPane* aMenuPane)
       
  8499     {
       
  8500     switch ( aResourceId )
       
  8501         {
       
  8502         case R_MPX_COLLECTION_VIEW_MENU_1:
       
  8503             {
       
  8504             aMenuPane->SetItemDimmed( EMPXCmdGoToNowPlaying, ETrue );
       
  8505             aMenuPane->SetItemDimmed( EMPXCmdGoToArtistAlbums, ETrue );
       
  8506             aMenuPane->SetItemDimmed( EMPXCmdGoToAllSongs, ETrue );
       
  8507             aMenuPane->SetItemDimmed( EMPXCmdGoToPlaylists, ETrue );
       
  8508             aMenuPane->SetItemDimmed( EMPXCmdGoToGenre, ETrue );
       
  8509             aMenuPane->SetItemDimmed( EMPXCmdGoToPodcasts, ETrue );
       
  8510             aMenuPane->SetItemDimmed( EMPXCmdGoToMusicShop, ETrue );
       
  8511             aMenuPane->SetItemDimmed( EMPXCmdGoToMultipleMusicShop, ETrue );
       
  8512             aMenuPane->SetItemDimmed( EMPXCmdMusicLibraryDetails, ETrue );
       
  8513             aMenuPane->SetItemDimmed( EMPXCmdRefreshLibrary, ETrue );
       
  8514             aMenuPane->SetItemDimmed( EMPXCmdAbout, ETrue );
       
  8515             aMenuPane->SetItemDimmed( EMPXCmdFind, ETrue );
       
  8516             aMenuPane->SetItemDimmed( EMPXCmdUpnpPlayVia, ETrue );
       
  8517             aMenuPane->SetItemDimmed( EMPXCmdUPnPAiwCmdCopyToExternalCriteria, ETrue );
       
  8518             aMenuPane->SetItemDimmed( EMPXCmdCreatePlaylist, ETrue );
       
  8519             aMenuPane->SetItemDimmed( EMPXCmdAddToPlaylist, ETrue );
       
  8520             aMenuPane->SetItemDimmed( EMPXCmdAddSongs, ETrue );
       
  8521             aMenuPane->SetItemDimmed( EMPXCmdReorder, ETrue );
       
  8522             aMenuPane->SetItemDimmed( EMPXCmdSend, ETrue );
       
  8523             aMenuPane->SetItemDimmed( EMPXCmdDelete, ETrue );
       
  8524             aMenuPane->SetItemDimmed( EMPXCmdRemove, ETrue );
       
  8525             aMenuPane->SetItemDimmed( EMPXCmdPlayItem, ETrue );
       
  8526             break;
       
  8527             }
       
  8528         case R_MPX_COLLECTION_VIEW_MENU_2:
       
  8529             {
       
  8530             aMenuPane->SetItemDimmed( EMPXCmdRename, ETrue );
       
  8531             aMenuPane->SetItemDimmed( EMPXCmdAlbumArt, ETrue );
       
  8532             aMenuPane->SetItemDimmed( EMPXCmdFindInMusicShop, ETrue );
       
  8533             aMenuPane->SetItemDimmed( EMPXCmdSongDetails, ETrue );
       
  8534             aMenuPane->SetItemDimmed( EMPXCmdPlaylistDetails, ETrue );
       
  8535             break;
       
  8536             }
       
  8537         case R_AVKON_MENUPANE_MARKABLE_LIST:
       
  8538             {
       
  8539             aMenuPane->SetItemDimmed(EAknCmdEditListMenu, ETrue);
       
  8540             break;
       
  8541             }
       
  8542         }    
       
  8543     }
       
  8544 //  End of File