mpxplugins/viewplugins/views/podcastplaybackview/src/mpxpodcastplaybackviewimp.cpp
changeset 0 ff3acec5bc43
child 5 2a40e88564c8
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of Podcast playback view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <aknViewAppUi.h>
       
    23 #include <eikmenub.h>
       
    24 #include <eikapp.h>
       
    25 #include <AknUtils.h>
       
    26 #include <bautils.h>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <mpxpodcastplaybackview.rsg>
       
    29 #include <mpxcommonplaybackview.rsg>
       
    30 #include <featmgr.h>
       
    31 
       
    32 #include <mpxcollectionframeworkdefs.h>
       
    33 #include <mpxcollectionmessage.h>
       
    34 #include <mpxcollectionutility.h>
       
    35 #include <mpxcollectionhelperfactory.h>
       
    36 #include <mpxcollectionuihelper.h>
       
    37 #include <mpxcollectionpath.h>
       
    38 #include <mpxcollectionplaylist.h>
       
    39 #include <mpxmedia.h>
       
    40 #include <mpxviewutility.h>
       
    41 #include <mpxviewpluginmanager.h>
       
    42 #include <mpxmediamusicdefs.h>
       
    43 #include <mpxpodcastdefs.h>
       
    44 #include <mpxmediadrmdefs.h>
       
    45 #include <mpxplaybackutility.h>
       
    46 #include <mpxmessagegeneraldefs.h>
       
    47 #include <mpxplaybackmessage.h>
       
    48 #include <mpxuser.h>
       
    49 #include <mpxappui.hrh>
       
    50 #include "mpxcommonplaybackview.hrh"
       
    51 #include "mpxpodcastplaybackviewimp.h"
       
    52 #include "mpxpodcastplaybackviewcontainer.h"
       
    53 #include "mpxpodcastplaybackviewlayout.h"
       
    54 #include "mpxpodcastplaybackview.hrh"
       
    55 #include "mpxlog.h"
       
    56 
       
    57 #include "mpxcommonplaybackview.hrh"
       
    58 
       
    59 #include <akntoolbar.h>
       
    60 #include <aknbutton.h>
       
    61 // CONSTANTS
       
    62 _LIT( KMPXPodcastPlaybackRscPath, "mpxpodcastplaybackview.rsc" );
       
    63 const TInt KPodcastingCollectionID = 0x101FFC3C;
       
    64 
       
    65 // ======== MEMBER FUNCTIONS ========
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // C++ default constructor can NOT contain any code, that
       
    69 // might leave.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CMPXPodcastPlaybackViewImp::CMPXPodcastPlaybackViewImp()
       
    73     {
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Symbian 2nd phase constructor can leave.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CMPXPodcastPlaybackViewImp::ConstructL()
       
    81     {
       
    82     MPX_FUNC( "CMPXPodcastPlaybackViewImp::ConstructL" );
       
    83 
       
    84     CCoeEnv* coeEnv = iEikonEnv;
       
    85     TParse parse;
       
    86     parse.Set( KMPXPodcastPlaybackRscPath, &KDC_APP_RESOURCE_DIR, NULL );
       
    87     TFileName resourceFile( parse.FullName() );
       
    88     User::LeaveIfError( MPXUser::CompleteWithDllPath( resourceFile ) );
       
    89     BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile );
       
    90     iPodcastResourceOffset = coeEnv->AddResourceFileL( resourceFile );
       
    91 
       
    92     CMPXCommonPlaybackViewImp::ConstructL();
       
    93 
       
    94     BaseConstructL( R_MPX_PODCAST_PLAYBACK_VIEW );
       
    95     if(AknLayoutUtils::PenEnabled())
       
    96     {
       
    97     if ( Toolbar() )
       
    98         {
       
    99         iToolbar = Toolbar();
       
   100         iToolbar->SetToolbarObserver( this );
       
   101         }
       
   102     }
       
   103 
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Two-phased constructor.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 CMPXPodcastPlaybackViewImp* CMPXPodcastPlaybackViewImp::NewL()
       
   111     {
       
   112     CMPXPodcastPlaybackViewImp* self = CMPXPodcastPlaybackViewImp::NewLC();
       
   113     CleanupStack::Pop( self );
       
   114     return self;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Two-phased constructor.
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 CMPXPodcastPlaybackViewImp* CMPXPodcastPlaybackViewImp::NewLC()
       
   122     {
       
   123     CMPXPodcastPlaybackViewImp* self = new ( ELeave ) CMPXPodcastPlaybackViewImp();
       
   124     CleanupStack::PushL( self );
       
   125     self->ConstructL();
       
   126     return self;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // Destructor
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 CMPXPodcastPlaybackViewImp::~CMPXPodcastPlaybackViewImp()
       
   134     {
       
   135     MPX_DEBUG1( "CMPXPodcastPlaybackViewImp::~CMPXPodcastPlaybackViewImp entering" );
       
   136 
       
   137     delete iPlaybackViewLayout;
       
   138 
       
   139     if ( iPodcastResourceOffset )
       
   140         {
       
   141         iEikonEnv->DeleteResourceFile( iPodcastResourceOffset );
       
   142         }
       
   143 
       
   144     MPX_DEBUG1( "CMPXPodcastPlaybackViewImp::~CMPXPodcastPlaybackViewImp exiting" );
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // From base class CMPXCommonPlaybackViewImp
       
   149 //
       
   150 // Handle playback property.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CMPXPodcastPlaybackViewImp::DoHandlePropertyL(
       
   154     TMPXPlaybackProperty aProperty,
       
   155     TInt aValue,
       
   156     TInt aError )
       
   157     {
       
   158     MPX_FUNC( "CMPXPodcastPlaybackViewImp::DoHandlePropertyL" );
       
   159     MPX_DEBUG4( "HandlePropertyL - Property(%d); Value(%d); Error(%d)", aProperty, aValue, aError );
       
   160 
       
   161     if ( KErrNone == aError )
       
   162         {
       
   163         switch ( aProperty  )
       
   164             {
       
   165             case EPbPropertyPosition:
       
   166                 {
       
   167                 if (iPosition == 0 && aValue != 0)
       
   168                     {
       
   169                     MMPXSource* s = iPlaybackUtility->Source();
       
   170                     if (s)
       
   171                         {
       
   172                         // Trick to make the song played
       
   173                         CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
   174                         CleanupStack::PushL(playlist);
       
   175                         if ( playlist )
       
   176                             {
       
   177                             CMPXMedia* media = CMPXMedia::NewL();
       
   178                             CleanupStack::PushL(media);
       
   179                             media->SetTObjectValueL( KMPXMediaGeneralType,
       
   180                                                      EMPXItem );
       
   181                             media->SetTObjectValueL( KMPXMediaGeneralCategory,
       
   182                                                      EMPXSong );
       
   183                             media->SetTObjectValueL( KMPXMediaGeneralCollectionId,
       
   184                                                      playlist->Path().Id( CMPXCollectionPath::ECollectionUid ).iId1);
       
   185 
       
   186                             media->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId , playlist->Path().Id() );
       
   187                             media->SetTObjectValueL( KMPXMediaGeneralLastPlaybackPosition, aValue );
       
   188                             playlist->SetL( *media );
       
   189                             CleanupStack::PopAndDestroy(media);
       
   190                             }
       
   191                         CleanupStack::PopAndDestroy(playlist);
       
   192                         }
       
   193                     }
       
   194                 iPosition = aValue;
       
   195                 CMPXCommonPlaybackViewImp::DoHandlePropertyL(aProperty, aValue, aError);
       
   196                 break;
       
   197                 }
       
   198             default:
       
   199                 {
       
   200                 CMPXCommonPlaybackViewImp::DoHandlePropertyL(aProperty,
       
   201                     aValue,
       
   202                     aError);
       
   203                 break;
       
   204                 }
       
   205             }
       
   206         }
       
   207     else
       
   208         {
       
   209         HandleErrorL( aError );
       
   210         }
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Updates track info field.
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CMPXPodcastPlaybackViewImp::UpdateTrackInfoL(
       
   218     const CMPXMedia* aMedia )
       
   219     {
       
   220     MPX_FUNC( "CMPXPodcastPlaybackViewImp::UpdateTrackInfo" );
       
   221 
       
   222     CMPXCommonPlaybackViewImp::UpdateTrackInfoL( aMedia );
       
   223 
       
   224     if( iContainer && !iSwitchingView )
       
   225         {
       
   226         if ( aMedia )
       
   227             {
       
   228             // Set ETextArtist field as Podcast Title
       
   229             if ( aMedia->IsSupported(KMPXMediaMusicAlbum))
       
   230                 {
       
   231                 HBufC* titleText = aMedia->ValueText(KMPXMediaMusicAlbum).AllocL();
       
   232                 CleanupStack::PushL(titleText);
       
   233                 if ( titleText->Length() > 0)
       
   234                     {
       
   235                     iContainer->UpdateLabelL( ETextArtist, *titleText );
       
   236                     }
       
   237                 else
       
   238                     {
       
   239                     HBufC* unknownText =
       
   240                         StringLoader::LoadLC( R_MPX_QTN_NMP_UNKNOWN_TITLE );
       
   241                     iContainer->UpdateLabelL(
       
   242                         ETextArtist, *unknownText );
       
   243                     CleanupStack::PopAndDestroy( unknownText );
       
   244                     }
       
   245                 CleanupStack::PopAndDestroy( titleText );
       
   246                 }
       
   247             else
       
   248                 {
       
   249                 HBufC* unknownText =
       
   250                         StringLoader::LoadLC( R_MPX_QTN_NMP_UNKNOWN_TITLE );
       
   251                 iContainer->UpdateLabelL(
       
   252                     ETextArtist, *unknownText );
       
   253                 CleanupStack::PopAndDestroy( unknownText );
       
   254                 }
       
   255             }
       
   256         }
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // From MEikMenuObserver
       
   261 // Dynamically initialises a menu pane.
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CMPXPodcastPlaybackViewImp::DynInitMenuPaneL(
       
   265     TInt aResourceId,
       
   266     CEikMenuPane* aMenuPane )
       
   267     {
       
   268     switch( aResourceId )
       
   269         {
       
   270         case R_MPX_PODCAST_PLAYBACK_VIEW_MENU1:
       
   271             {
       
   272             break;
       
   273             }
       
   274         case R_MPX_PLAYBACK_VIEW_MENU:
       
   275             {
       
   276             CMPXCommonPlaybackViewImp::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   277 
       
   278             // dim the options that aren't applicable
       
   279             // to podcast collection
       
   280             aMenuPane->SetItemDimmed(
       
   281                     EMPXPbvCmdGotoMusicMenu,
       
   282                     ETrue );
       
   283             aMenuPane->SetItemDimmed(
       
   284                     EMPXPbvCmdAddToPlaylist,
       
   285                     ETrue );
       
   286             aMenuPane->SetItemDimmed(
       
   287                 EMPXPbvCmdUseAsCascade,
       
   288                 ETrue );
       
   289             aMenuPane->SetItemDimmed(
       
   290                     EMPXPbvCmdRepeat,
       
   291                     ETrue );
       
   292             aMenuPane->SetItemDimmed(
       
   293                     EMPXPbvCmdRandom,
       
   294                     ETrue );
       
   295 
       
   296 			// Check if FM Transmitter is supported
       
   297 			if ( !FeatureManager::FeatureSupported( KFeatureIdFmtx ) )
       
   298 				{
       
   299 				aMenuPane->SetItemDimmed(
       
   300 					EMPXPbvCmdFMTransmitter,
       
   301 					ETrue );
       
   302 				}
       
   303             break;
       
   304             }
       
   305         default:
       
   306             {
       
   307             // Call base clase to handle most cases
       
   308             CMPXCommonPlaybackViewImp::DynInitMenuPaneL(
       
   309                 aResourceId,
       
   310                 aMenuPane );
       
   311             break;
       
   312             }
       
   313         }
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // From CAknView
       
   318 // Returns views id.
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 TUid CMPXPodcastPlaybackViewImp::Id() const
       
   322     {
       
   323     return TUid::Uid( KMPXPodcastPlaybackViewId );
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // From CAknView
       
   328 // Command handling function.
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 EXPORT_C void CMPXPodcastPlaybackViewImp::HandleCommandL( TInt aCommand )
       
   332     {
       
   333     switch( aCommand )
       
   334         {
       
   335         case EMPXPbvCmdGoToPodcastMenu:
       
   336             {
       
   337             // Handle Goto main podcast menu
       
   338             CMPXCollectionPath* cpath = iCollectionUiHelper->PodCastMenuPathL();
       
   339             CleanupStack::PushL( cpath );
       
   340             MPX_DEBUG_PATH (*cpath);
       
   341             iCollectionUtility->Collection().OpenL( *cpath );
       
   342             CleanupStack::PopAndDestroy( cpath );
       
   343 
       
   344             // Restore status pane
       
   345             if ( StatusPane()->CurrentLayoutResId() !=
       
   346                  R_AVKON_STATUS_PANE_LAYOUT_USUAL)
       
   347                 {
       
   348                 StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
       
   349                 }
       
   350             break;
       
   351             }
       
   352         case EAknSoftkeyBack:
       
   353             {
       
   354             MMPXSource* s = iPlaybackUtility->Source();
       
   355             TBool handled = EFalse;
       
   356             if(s == NULL)
       
   357                 {
       
   358                 CMPXCollectionPath* path = iCollectionUtility->Collection().PathL();
       
   359                 CleanupStack::PushL(path);
       
   360                 TInt levels = path->Levels();
       
   361                 if(levels == 3)
       
   362                     {
       
   363                     const TMPXItemId& iid0 = path->Id(0);
       
   364                     const TMPXItemId& iid1 = path->Id(1);
       
   365                     if(iid0 == KPodcastingCollectionID && iid1 == 4) //EBrowseNotPlayed
       
   366                         {
       
   367                         path->Back();
       
   368                         iViewUtility->PushDefaultHistoryL();
       
   369                         iCollectionUtility->Collection().OpenL(*path);
       
   370                         handled = ETrue;
       
   371                         }
       
   372                     }
       
   373                 CleanupStack::PopAndDestroy(path);
       
   374                 }
       
   375             if(!handled)
       
   376                 {
       
   377                 CMPXCommonPlaybackViewImp::HandleCommandL( aCommand );
       
   378                 }
       
   379             break;
       
   380             }
       
   381         default:
       
   382             {
       
   383             CMPXCommonPlaybackViewImp::HandleCommandL( aCommand );
       
   384             break;
       
   385             }
       
   386         }
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // From CAknView
       
   391 // Handles a view activation.
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 void CMPXPodcastPlaybackViewImp::DoActivateL(
       
   395     const TVwsViewId& aPrevViewId,
       
   396     TUid aCustomMessageId,
       
   397     const TDesC8& aCustomMessage )
       
   398     {
       
   399     MPX_FUNC( "CMPXPodcastPlaybackViewImp::DoActivateL()" );
       
   400 
       
   401     if ( !iContainer )
       
   402         {
       
   403         if ( !iPlaybackViewLayout )
       
   404             {
       
   405             iPlaybackViewLayout = CMPXPodcastPlaybackViewLayout::NewL();
       
   406             }
       
   407         iContainer = new ( ELeave ) CMPXPodcastPlaybackViewContainer(
       
   408             this,
       
   409             this,
       
   410             iPlaybackViewLayout );
       
   411         iContainer->SetMopParent( this );
       
   412         iContainer->ConstructL( ClientRect() );
       
   413         AppUi()->AddToStackL( *this, iContainer );
       
   414         }
       
   415 
       
   416     CMPXCommonPlaybackViewImp::DoActivateL( aPrevViewId , aCustomMessageId, aCustomMessage );
       
   417     UpdateMiddleSoftKeyDisplayL();
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CMPXPodcastPlaybackViewImp::PrepareStatusPaneForExitingViewL
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CMPXPodcastPlaybackViewImp::PrepareStatusPaneForExitingViewL()
       
   425     {
       
   426     if ( StatusPane()->CurrentLayoutResId() !=
       
   427          R_AVKON_STATUS_PANE_LAYOUT_USUAL)
       
   428         {
       
   429         StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
       
   430         }
       
   431     }
       
   432 // -----------------------------------------------------------------------------
       
   433 // From MAknToolbarObserver
       
   434 // Used to change toolbar settings before toolbar becomes visible
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 void CMPXPodcastPlaybackViewImp::DynInitToolbarL(TInt aResourceId, CAknToolbar* aToolbar)
       
   438     {
       
   439     if (aResourceId == R_MPX_PBV_TOUCH_TOOLBAR)
       
   440         {
       
   441         // Put initializations here to take effect before toolbar is shown
       
   442         UpdateToolbar();
       
   443         aToolbar->UpdateBackground();
       
   444        }
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // From MAknToolbarObserver
       
   449 // Handles toolbar events
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CMPXPodcastPlaybackViewImp::OfferToolbarEventL( TInt aCommandId )
       
   453     {
       
   454     TInt commandId = aCommandId;
       
   455     TInt eventModifiers = iToolbar->EventModifiers();
       
   456     if ( eventModifiers == CAknToolbar::ELongPress )
       
   457         {
       
   458         if ( aCommandId == EMPXPbvCmdNextListItem )
       
   459             {
       
   460             commandId = EMPXPbvCmdSeekForward;
       
   461             }
       
   462         else if ( aCommandId == EMPXPbvCmdPreviousListItem )
       
   463             {
       
   464             commandId = EMPXPbvCmdSeekBackward;
       
   465             }
       
   466         }
       
   467     else if ( eventModifiers == CAknToolbar::ELongPressEnded )
       
   468         {
       
   469         if ( aCommandId == EMPXPbvCmdNextListItem || aCommandId == EMPXPbvCmdPreviousListItem )
       
   470             {
       
   471             commandId = EMPXPbvCmdEndSeek;
       
   472             }
       
   473         }
       
   474 
       
   475     CAknView::ProcessCommandL( commandId );
       
   476     }
       
   477 
       
   478 // ---------------------------------------------------------------------------
       
   479 // Handle playback message.
       
   480 // ---------------------------------------------------------------------------
       
   481 //
       
   482 void CMPXPodcastPlaybackViewImp::DoHandlePlaybackMessageL(
       
   483     const CMPXMessage& aMessage )
       
   484     {
       
   485     MPX_DEBUG1( "CMPXPodcastPlaybackViewImp::DoHandlePlaybackMessageL");
       
   486 
       
   487     TMPXMessageId id( *aMessage.Value<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   488     if ( KMPXMessageGeneral == id )
       
   489         {
       
   490         TInt type( *aMessage.Value<TInt>( KMPXMessageGeneralType ) );
       
   491         TInt data( *aMessage.Value<TInt>( KMPXMessageGeneralData ) );
       
   492         switch ( *aMessage.Value<TInt>( KMPXMessageGeneralEvent ) )
       
   493             {
       
   494             case TMPXPlaybackMessage::EStateChanged:
       
   495                 UpdateMiddleSoftKeyDisplayL();
       
   496                 UpdateToolbar();
       
   497                 break;
       
   498 
       
   499             default:
       
   500                 break;
       
   501             }
       
   502         }
       
   503     CMPXCommonPlaybackViewImp::DoHandlePlaybackMessageL (aMessage);
       
   504     }
       
   505 
       
   506 // ---------------------------------------------------------------------------
       
   507 // Updates the middle toolbar button
       
   508 // ---------------------------------------------------------------------------
       
   509 //
       
   510 void CMPXPodcastPlaybackViewImp::UpdateToolbar()
       
   511     {
       
   512     MPX_FUNC("CMPXPodcastPlaybackViewImp::UpdateToolbar");
       
   513 
       
   514     if ( AknLayoutUtils::PenEnabled() )
       
   515         {
       
   516         if ( iToolbar )
       
   517             {
       
   518             CAknButton* pausePlayControl;
       
   519             pausePlayControl = (CAknButton*)(iToolbar->ComponentControl( 1 ));
       
   520             MMPXSource* s = iPlaybackUtility->Source();
       
   521             if ( s )
       
   522                 {
       
   523                 CMPXCollectionPlaylist* playlist = s->PlaylistL();
       
   524                 if ( playlist )
       
   525                     {
       
   526                     if ( playlist->Count() > 0 && pausePlayControl )
       
   527                         {
       
   528                         TMPXPlaybackState state = iPlaybackUtility->StateL();
       
   529                         if ((state == EPbStateInitialising) || (state == EPbStatePlaying))
       
   530                            {
       
   531                            pausePlayControl->SetCurrentState(0, ETrue);
       
   532                            }
       
   533                         else
       
   534                            {
       
   535                            pausePlayControl->SetCurrentState(1, ETrue);
       
   536                            }
       
   537                         }
       
   538                     }
       
   539                 delete playlist;
       
   540                 }
       
   541             }
       
   542         }
       
   543     }
       
   544 
       
   545 //  End of File