menucontentsrv/handlersrc/menuapphandler.cpp
changeset 0 79c6a41cd166
child 18 bd874ee5e5e2
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     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:
       
    15 *
       
    16 */
       
    17 #include "menuapphandler.h"
       
    18 #include "mcsmenuitem.h"
       
    19 #include "menucompletedoperation.h"
       
    20 #include "menuuninstalloperation.h"
       
    21 
       
    22 #include <mcsmenuutils.h>
       
    23 #include <w32std.h>
       
    24 #include <apgtask.h>
       
    25 #include <apgcli.h>
       
    26 #include <eikenv.h>
       
    27 #include <eikappui.h>
       
    28 #include <vwsdef.h>
       
    29 #include <AknTaskList.h>
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CMenuAppHandler::~CMenuAppHandler
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CMenuAppHandler::~CMenuAppHandler()
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CMenuAppHandler::NewL
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 CMenuAppHandler* CMenuAppHandler::NewL( RMenu &aMenu )
       
    46     {
       
    47     CMenuAppHandler* handler = new (ELeave) CMenuAppHandler( aMenu );
       
    48     CleanupStack::PushL( handler );
       
    49     handler->ConstructL();
       
    50     CleanupStack::Pop( handler );
       
    51     return handler;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 // CMenuAppHandler::CMenuAppHandler
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 CMenuAppHandler::CMenuAppHandler( RMenu &aMenu )
       
    59 : CMenuHandlerPlugin( aMenu )
       
    60     {
       
    61     iEikEnv = CEikonEnv::Static();
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // CMenuAppHandler::ConstructL
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 void CMenuAppHandler::ConstructL()
       
    69     {
       
    70     BaseConstructL();
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // CMenuAppHandler::SupportsType
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 TBool CMenuAppHandler::SupportsType( const TDesC& aType )
       
    78     {
       
    79     if ( !aType.Compare( KMenuTypeApp() ) )
       
    80         {
       
    81         return ETrue;
       
    82         }
       
    83     return EFalse;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CMenuAppHandler::HandleCommandL
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 CMenuOperation* CMenuAppHandler::HandleCommandL(
       
    91         CMenuItem& aItem,
       
    92         const TDesC8& aCommand,
       
    93         const TDesC8& aParams,
       
    94         TRequestStatus& aStatus )
       
    95     {
       
    96     if ( aCommand == KMenuCmdOpen() && aItem.Type() == KMenuTypeApp() )
       
    97         {
       
    98         TBool attrExists = ETrue;
       
    99         TPtrC url = aItem.GetAttributeL( KMenuAttrUid(), attrExists );
       
   100 
       
   101         if ( !attrExists )
       
   102             {
       
   103             User::Leave( KErrCorrupt );
       
   104             }
       
   105             
       
   106         TUint appUidNo;
       
   107         TInt err = MenuUtils::GetTUint( url, appUidNo );
       
   108         if ( err != KErrNone )
       
   109             {
       
   110             User::Leave( KErrCorrupt );
       
   111             }
       
   112             
       
   113         TInt viewId;
       
   114         TPtrC view = aItem.GetAttributeL( KMenuAttrView(), attrExists );
       
   115 
       
   116         if ( attrExists )
       
   117             {
       
   118             err = MenuUtils::GetTUint( view, (TUint &)viewId );
       
   119             if( err != KErrNone )
       
   120                 {
       
   121                 User::Leave( KErrCorrupt );
       
   122                 }
       
   123             }
       
   124            else
       
   125             {
       
   126             viewId = -1;
       
   127             }
       
   128         
       
   129         LaunchApplicationL( TUid::Uid( appUidNo ), aParams, viewId );
       
   130 
       
   131         return CMenuCompletedOperation::NewL
       
   132             ( iMenu, CActive::EPriorityStandard, aStatus, KErrNone );
       
   133         }
       
   134     else if ( aCommand == KMenuCmdRemove() && aItem.Type() == KMenuTypeApp() )
       
   135         {
       
   136         return CMenuUninstallOperation::NewL
       
   137             ( iMenu, CActive::EPriorityStandard, aStatus, aItem );
       
   138         }
       
   139     User::Leave ( KErrNotSupported );
       
   140     return NULL;
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------
       
   144 // CMenuAppHandler::LaunchApplicationL
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 void CMenuAppHandler::LaunchApplicationL( const TUid aUid, const TDesC8 &aParam, TInt aViewId )
       
   148     {
       
   149     if ( aViewId > 0 && iEikEnv )
       
   150         {
       
   151         TUid viewId = TUid::Uid( aViewId );
       
   152         TVwsViewId view( aUid, viewId );
       
   153         iEikEnv->EikAppUi()->ActivateViewL( view );
       
   154         }
       
   155     else
       
   156         {
       
   157         RWsSession wsSession;
       
   158     	User::LeaveIfError( wsSession.Connect() );
       
   159     	CleanupClosePushL<RWsSession>( wsSession );
       
   160     	
       
   161     	TApaTaskList* taskList = new (ELeave) TApaTaskList( wsSession ); 
       
   162         TApaTask task = taskList->FindApp( aUid );
       
   163         
       
   164         delete taskList;
       
   165 
       
   166         if ( task.Exists() )
       
   167             {
       
   168             task.BringToForeground();
       
   169             }
       
   170         else
       
   171             {
       
   172             TApaAppInfo appInfo;
       
   173             TApaAppCapabilityBuf capabilityBuf;
       
   174     	    RApaLsSession appArcSession;
       
   175     	    User::LeaveIfError( appArcSession.Connect() );
       
   176     	    CleanupClosePushL<RApaLsSession>( appArcSession );
       
   177 
       
   178             User::LeaveIfError( appArcSession.GetAppInfo( appInfo, aUid ) );
       
   179             User::LeaveIfError( appArcSession.GetAppCapability( capabilityBuf, aUid ) );
       
   180 
       
   181             TApaAppCapability& caps = capabilityBuf();
       
   182             TFileName appName = appInfo.iFullName;
       
   183             CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   184 	        cmdLine->SetExecutableNameL( appName );
       
   185 
       
   186             if ( caps.iLaunchInBackground )
       
   187                 {
       
   188                 cmdLine->SetCommandL( EApaCommandBackground );
       
   189                 }
       
   190             else
       
   191                 {
       
   192                 cmdLine->SetCommandL( EApaCommandRun );
       
   193                 }
       
   194 
       
   195             cmdLine->SetTailEndL( aParam );
       
   196             
       
   197             User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
       
   198 
       
   199     	    CleanupStack::PopAndDestroy( cmdLine );
       
   200     	    CleanupStack::PopAndDestroy( &appArcSession );
       
   201             }
       
   202         CleanupStack::PopAndDestroy( &wsSession );
       
   203         }
       
   204     }