videoplayerapp/mpxvideoplayer/src/mpxvideoplayerappui.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 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:  AppUI implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: da1mmcf#33 %
       
    19 
       
    20 
       
    21 #include <hlplch.h>                     // Help launcher
       
    22 #include <sysutil.h>                    // disk space check
       
    23 #include <f32file.h>                    // TDriveNumber::EDriveC
       
    24 #include <s32mem.h>
       
    25 #include <StringLoader.h>
       
    26 #include <AknQueryDialog.h>
       
    27 #include <aknview.h>
       
    28 #include <aknconsts.h>
       
    29 #include <akndef.h>
       
    30 #include <AiwGenericParam.h>
       
    31 #include <coeutils.h>
       
    32 
       
    33 #include <mpxplaybackutility.h>
       
    34 #include <mpxplaybackmessage.h>
       
    35 #include <mpxviewutility.h>
       
    36 #include <vcxmyvideosdefs.h>
       
    37 #include <mpxvideoplayer.rsg>
       
    38 
       
    39 #include "mpxvideoplayerappui.h"
       
    40 #include "mpxvideoplayerconstants.h"
       
    41 #include "mpxvideoplayerlogger.h"
       
    42 #include "mpxvideoplayerappuiengine.h"
       
    43 #include "mpxvideoplayeraiwparamextractor.h"
       
    44 #include "mpxvideo_debug.h"
       
    45 #include "videoplayerpskeys.h"
       
    46 
       
    47 // Matrix uid, needed for activating the suite view.
       
    48 const TInt KVcxMatrixUid = 0x101F4CD2;
       
    49 
       
    50 // The action=exit flag tells menu that the suite app view is exiting via options->exit.
       
    51 _LIT8( KVcxVideoSuiteExitMessage, "mm://tvvideosuite?action=exit" );
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 // -----------------------------------------------------------------------------
       
    55 // CMpxVideoPlayerAppUi::CMpxVideoPlayerAppUi
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CMpxVideoPlayerAppUi::CMpxVideoPlayerAppUi()
       
    59     : iEndKeyExit( EFalse )
       
    60 {
       
    61     MPX_DEBUG(_L("CMpxVideoPlayerAppUi::CMpxVideoPlayerAppUi()"));
       
    62 }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMpxVideoPlayerAppUi::ConstructL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CMpxVideoPlayerAppUi::ConstructL()
       
    69 {
       
    70     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::ConstructL()"));
       
    71 
       
    72     BaseConstructL( EAknEnableSkin | EAknSingleClickCompatible );
       
    73 
       
    74     DoWgIdUpkeep();
       
    75 
       
    76     if ( IsEmbedded() )
       
    77     {
       
    78         //
       
    79         //  Set the orientation to landscape for Embedded instances
       
    80         //
       
    81         SetOrientationL( CAknAppUiBase::EAppUiOrientationLandscape );
       
    82     }
       
    83     else
       
    84     {
       
    85         //
       
    86         //  if we are stand alone mode store window group id to RProperty
       
    87         //  so we can identify it in ActionHandlerPlugin.
       
    88         //
       
    89         RProperty::Define( KVideoPlayerRPropertyCategory,
       
    90                            KVideoPlayerRPropertyWGIdKey,
       
    91                            RProperty::EInt );
       
    92 
       
    93         RProperty::Set( KVideoPlayerRPropertyCategory,
       
    94                         KVideoPlayerRPropertyWGIdKey,
       
    95                         iCoeEnv->RootWin().Identifier() );
       
    96     }
       
    97 
       
    98     iAppUiEngine = CMpxVideoPlayerAppUiEngine::NewL( this );
       
    99 }
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CMpxVideoPlayerAppUi::DoWgIdUpkeer
       
   104 // Checks if stored wgid is run by other application than us
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CMpxVideoPlayerAppUi::DoWgIdUpkeep()
       
   108 {
       
   109     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::DoWgIdUpkeep()"));
       
   110 
       
   111     // Do the upkeep for stand alone wg identifier
       
   112     // If we find that the WgId of this application is same
       
   113     // as the one stored in RProperty we know that the stand
       
   114     // alone has crashed and we have to clear it.
       
   115     TInt wgId( 0 );
       
   116     TInt err( RProperty::Get( KVideoPlayerRPropertyCategory, KVideoPlayerRPropertyWGIdKey, wgId ) );
       
   117 
       
   118     if ( wgId && !err )
       
   119     {
       
   120         if ( IsEmbedded() && wgId == iCoeEnv->RootWin().Identifier() )
       
   121         {
       
   122             // Stored wgId is ours and we are in embedded mode. Delete!
       
   123             RProperty::Delete( KVideoPlayerRPropertyCategory,
       
   124                                KVideoPlayerRPropertyWGIdKey );
       
   125         }
       
   126     }
       
   127 }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CMpxVideoPlayerAppUi::~CMpxVideoPlayerAppUi
       
   131 // Destructor. Frees reserved resources
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 CMpxVideoPlayerAppUi::~CMpxVideoPlayerAppUi()
       
   135 {
       
   136     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::~CMpxVideoPlayerAppUi()"));
       
   137 
       
   138     // If we are running in embedded we keep the RProperty alive when exiting.
       
   139     if ( ! IsEmbedded() )
       
   140     {
       
   141         RProperty::Delete( KVideoPlayerRPropertyCategory,
       
   142                            KVideoPlayerRPropertyWGIdKey );
       
   143     }
       
   144 
       
   145     delete iAppUiEngine;
       
   146 }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CMpxVideoPlayerAppUi::HandleExit
       
   150 // Handles exit command
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CMpxVideoPlayerAppUi::HandleExit()
       
   154 {
       
   155     Exit();
       
   156 }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CMpxVideoPlayerAppUi::ProcessCommandParametersL
       
   160 // From CEikAppUi, called from plugin when remind occurs and MpxVideoPlayer is not
       
   161 // exist
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 TBool CMpxVideoPlayerAppUi::ProcessCommandParametersL( TApaCommand aCommand,
       
   165                                                        TFileName& aDocumentName,
       
   166                                                        const TDesC8& aTail )
       
   167 {
       
   168     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::ProcessCommandParametersL()"),
       
   169                    _L("aCommand = %d"), aCommand );
       
   170 
       
   171 
       
   172     return iAppUiEngine->ProcessCommandParametersL( aCommand, aDocumentName, aTail );
       
   173 }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // From CEikAppUi.
       
   177 // Handle window server events.
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CMpxVideoPlayerAppUi::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* aDestination )
       
   181 {
       
   182     TInt eventType = aEvent.Type();
       
   183     if ( eventType == KAknUidValueEndKeyCloseEvent // End Call key
       
   184             || eventType == KAknShutOrHideApp ) // Exit cmd from Task Switcher
       
   185     {
       
   186         MPX_DEBUG(_L("CMpxVideoPlayerAppUi::HandleWsEventL() Closed by framework"));
       
   187 
       
   188         iEndKeyExit = ETrue;
       
   189         iAppUiEngine->PrepareCloseMpxL();
       
   190     }
       
   191 
       
   192     CAknAppUi::HandleWsEventL( aEvent, aDestination );
       
   193 }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMpxVideoPlayerAppUi::HandleCommandL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMpxVideoPlayerAppUi::HandleCommandL( TInt aCommand )
       
   200 {
       
   201     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::HandleCommandL()"),
       
   202                    _L("aCommand = %d"), aCommand );
       
   203 
       
   204     switch ( aCommand )
       
   205     {
       
   206         case EEikCmdExit: // fall through
       
   207         case EAknCmdExit:
       
   208         {
       
   209             MPX_DEBUG(_L("CMpxVideoPlayerAppUi::HandleCommandL() - Exit"));
       
   210 
       
   211             iAppUiEngine->PrepareCloseMpxL();
       
   212 
       
   213             //
       
   214             //  Send message to matrix menu on a stand alone instance if:
       
   215             //     1)  End Key is pressed
       
   216             //     2)  Exit command has been issued
       
   217             //
       
   218             if ( ! IsEmbedded() && ( ! iEndKeyExit && iAppUiEngine->ExitToMatrixMenu() ) )
       
   219             {
       
   220                 LaunchMmViewL( KVcxVideoSuiteExitMessage );
       
   221             }
       
   222 
       
   223             HandleExit();
       
   224             break;
       
   225         }
       
   226         case EAknSoftkeyBack:
       
   227         {
       
   228             iAppUiEngine->HandleSoftKeyBackL();
       
   229             break;
       
   230         }
       
   231         case EAknCmdHelp:
       
   232         {
       
   233             MPX_DEBUG(_L("CMpxVideoPlayerAppUi::HandleCommandL() - Help"));
       
   234             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), AppHelpContextL() );
       
   235             break;
       
   236         }
       
   237         case EAknCmdHideInBackground:
       
   238         {
       
   239             iAppUiEngine->ClearPdlInformation();
       
   240             break;
       
   241         }
       
   242         default:
       
   243         {
       
   244             // do nothing if the command is not reconized
       
   245             break;
       
   246         }
       
   247     }
       
   248 }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // Querying whether the application is launched in embedded mode or not.
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 TBool CMpxVideoPlayerAppUi::IsEmbedded() const
       
   255 {
       
   256     TBool embedded = iEikonEnv->StartedAsServerApp();
       
   257 
       
   258     MPX_DEBUG(_L("CMpxVideoPlayerAppUi::IsEmbedded(%d)"), embedded );
       
   259 
       
   260     return embedded;
       
   261 }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // Opens the specified file in response to a corresponding message.
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 void CMpxVideoPlayerAppUi::OpenFileL( RFile& aFile, const CAiwGenericParamList* aParams )
       
   268 {
       
   269     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::OpenFileL(RFile)"));
       
   270 
       
   271     MPX_TRAPD( err, iAppUiEngine->OpenFileL( aFile, aParams ) );
       
   272 
       
   273     //
       
   274     //  Cancel comes from a Cancel on the Select AP dialog
       
   275     //  Perform a softkey back
       
   276     //
       
   277     if ( err )
       
   278     {
       
   279         if ( err == KErrCancel )
       
   280         {
       
   281             // if the app is launched in embedded mode (view history depth would be zero)
       
   282             // we close the app using the softkey back, if it was launched by a active view
       
   283             // we stay in that view.
       
   284             if ( iAppUiEngine->ViewHistoryDepth() <= 0 )
       
   285             {
       
   286                 MPX_TRAPD( error, HandleCommandL( EAknSoftkeyBack ) );
       
   287             }
       
   288         }
       
   289         else
       
   290         {
       
   291             User::Leave( err );
       
   292         }
       
   293     }
       
   294 
       
   295     aFile.Close();
       
   296 }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // From CEikAppUi.
       
   300 // Opens the specified file
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CMpxVideoPlayerAppUi::OpenFileL( const TDesC& aFileName )
       
   304 {
       
   305     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::OpenFileL()"),
       
   306                    _L("aFileName = %S"), &aFileName );
       
   307 
       
   308     MPX_TRAPD( err, iAppUiEngine->OpenFileL( aFileName ) );
       
   309 
       
   310     //
       
   311     //  Cancel comes from a Cancel on the Select AP dialog
       
   312     //  Perform a softkey back
       
   313     //
       
   314     if ( err )
       
   315     {
       
   316         if ( err == KErrCancel )
       
   317         {
       
   318             // if the app is launched in embedded mode (view history depth would be zero)
       
   319             // we close the app using the softkey back, if it was launched by a active view
       
   320             // we stay in that view.
       
   321             if ( iAppUiEngine->ViewHistoryDepth() <= 0 )
       
   322             {
       
   323                 MPX_TRAPD( error, HandleCommandL( EAknSoftkeyBack ) );
       
   324             }
       
   325         }
       
   326         else
       
   327         {
       
   328             User::Leave( err );
       
   329         }
       
   330     }
       
   331 }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // From CEikAppUi
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 MCoeMessageObserver::TMessageResponse
       
   338 CMpxVideoPlayerAppUi::HandleMessageL( TUint32 aClientHandleOfTargetWindowGroup,
       
   339                                       TUid aMessageUid,
       
   340                                       const TDesC8& aMessageParameters )
       
   341 {
       
   342     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::HandleMessageL()"));
       
   343 
       
   344     MCoeMessageObserver::TMessageResponse ret( EMessageNotHandled );
       
   345 
       
   346     if ( iAppUiEngine->HandleMessageL( aMessageUid, aMessageParameters ) )
       
   347     {
       
   348         ret = EMessageHandled;
       
   349     }
       
   350     else
       
   351     {
       
   352         ret = CAknViewAppUi::HandleMessageL( aClientHandleOfTargetWindowGroup,
       
   353                                              aMessageUid,
       
   354                                              aMessageParameters );
       
   355     }
       
   356 
       
   357     return  ret;
       
   358 }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // From CCoeAppUi.
       
   362 // Handle foreground event.
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CMpxVideoPlayerAppUi::HandleForegroundEventL( TBool aForeground )
       
   366 {
       
   367     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::HandleForegroundEventL()"),
       
   368                    _L("aForeground = %d"), aForeground );
       
   369 
       
   370     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
   371 }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // Return active view.
       
   375 // ---------------------------------------------------------------------------
       
   376 CAknView* CMpxVideoPlayerAppUi::View()
       
   377 {
       
   378     return iView;
       
   379 }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // Sends a message to Matrix Menu
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 void CMpxVideoPlayerAppUi::LaunchMmViewL( const TDesC8& aMessage )
       
   386 {
       
   387     MPX_ENTER_EXIT(_L("CMpxVideoPlayerAppUi::LaunchMmViewL()"));
       
   388 
       
   389     TApaTaskList taskList( iCoeEnv->WsSession() );
       
   390     TApaTask task = taskList.FindApp( TUid::Uid( KVcxMatrixUid ) );
       
   391 
       
   392     if ( task.Exists() )
       
   393     {
       
   394         //
       
   395         //  Matrix is already running in background - send APA Message
       
   396         //
       
   397         task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ), aMessage );
       
   398     }
       
   399 }
       
   400