videoplayerapp/videoplayerlauncher/src/videoplayerlauncher.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2009 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:   Main application class
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: da1mmcf#3 %
       
    19 
       
    20 // Command Line and APA
       
    21 #include <apgtask.h>
       
    22 #include <apgcli.h>
       
    23 #include <apaid.h>
       
    24 #include <apacmdln.h>
       
    25 #include <centralrepository.h>
       
    26 
       
    27 #include "mpxvideo_debug.h"
       
    28 #include "videoplayerpskeys.h"
       
    29 
       
    30 const TInt KVcxMatrixUid = 0x101F4CD2;
       
    31 const TUint KVideoPlayerWgNameSize = 50;
       
    32 
       
    33 _LIT8( KVcxVideoSuiteActivationMessage, "mm://tvvideosuite?exit=hide" );
       
    34 _LIT( KVideoPlayerWgName, "*200159b2*");
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // LaunchMenuViewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 void LaunchMenuViewL( const TDesC8& aMessage )
       
    41     {
       
    42     MPX_ENTER_EXIT(_L("VideoPlayerLauncher LaunchMenuViewL()"));
       
    43     RWsSession wsSession;
       
    44     User::LeaveIfError( wsSession.Connect() );
       
    45     CleanupClosePushL( wsSession );
       
    46     
       
    47     TApaTaskList taskList( wsSession );
       
    48     TApaTask task = taskList.FindApp( TUid::Uid( KVcxMatrixUid ) );
       
    49 
       
    50     if ( task.Exists() )
       
    51         {
       
    52         // Matrix is already running in background - send APA Message
       
    53         task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ), aMessage );
       
    54         }
       
    55     else
       
    56         {
       
    57         // Matrix not running yet - use Command Line Tail
       
    58         RApaLsSession appArcSession;
       
    59         CleanupClosePushL( appArcSession );
       
    60         User::LeaveIfError( appArcSession.Connect() );      
       
    61         TApaAppInfo appInfo;
       
    62         TInt err = appArcSession.GetAppInfo( appInfo, TUid::Uid( KVcxMatrixUid ) );
       
    63         if ( err == KErrNone )
       
    64             {
       
    65             CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
    66             cmdLine->SetExecutableNameL( appInfo.iFullName );
       
    67             cmdLine->SetCommandL( EApaCommandRun );
       
    68             cmdLine->SetTailEndL( aMessage );
       
    69 
       
    70             appArcSession.StartApp( *cmdLine );
       
    71             CleanupStack::PopAndDestroy( cmdLine );
       
    72             }
       
    73         CleanupStack::PopAndDestroy( &appArcSession ); 
       
    74         }
       
    75 
       
    76     CleanupStack::PopAndDestroy( &wsSession ); 
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CVideoActionHandler::TryBringToForegroundL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 TInt TryBringToForegroundL()
       
    84     {
       
    85     TInt ret ( KErrNotFound );
       
    86     RWsSession session;
       
    87     User::LeaveIfError( session.Connect() );
       
    88 	CleanupClosePushL( session );
       
    89 
       
    90     TInt ourWgId( 0 );
       
    91     TInt error = RProperty::Get( KVideoPlayerRPropertyCategory, KVideoPlayerRPropertyWGIdKey, ourWgId );
       
    92         
       
    93     if( error == KErrNone && ourWgId != 0 )
       
    94         {
       
    95         TBuf<KVideoPlayerWgNameSize> wgName;
       
    96         session.GetWindowGroupNameFromIdentifier(ourWgId, wgName );
       
    97         
       
    98         if( wgName.MatchF( KVideoPlayerWgName ) != KErrNotFound )
       
    99             {
       
   100             ret = session.SetWindowGroupOrdinalPosition( ourWgId, 0 );
       
   101             }
       
   102         }
       
   103 
       
   104 	CleanupStack::PopAndDestroy( &session );
       
   105     return ret;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // E32Main
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 GLDEF_C TInt E32Main()
       
   113     {
       
   114     __UHEAP_MARK;
       
   115     // create cleanup stack
       
   116     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   117 
       
   118     TInt broughtToForegrondResp( KErrGeneral );
       
   119 	
       
   120     TRAP_IGNORE( broughtToForegrondResp = TryBringToForegroundL() );
       
   121 	
       
   122     if ( broughtToForegrondResp != KErrNone )
       
   123         {
       
   124         TRAP_IGNORE( LaunchMenuViewL( KVcxVideoSuiteActivationMessage ) );
       
   125         }
       
   126 
       
   127     // destroy cleanup stack
       
   128     delete cleanup;
       
   129     __UHEAP_MARKEND;
       
   130     return 0;
       
   131     }