contentstorage/cahandler/app/src/caapphandler.cpp
changeset 61 8e5041d13c84
child 66 32469d7d46ff
equal deleted inserted replaced
60:f62f87b200ec 61:8e5041d13c84
       
     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:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 #include <w32std.h>
       
    19 #include <apgtask.h>
       
    20 #include <apgcli.h>
       
    21 #include <eikenv.h>
       
    22 #include <eikappui.h>
       
    23 #include <vwsdef.h>
       
    24 #include <AknDef.h>
       
    25 #include <AknTaskList.h>
       
    26 
       
    27 #include "caapphandler.h"
       
    28 #include "cainnerentry.h"
       
    29 #include "cauninstalloperation.h"
       
    30 #include"catasklist.h"
       
    31 
       
    32 #include "cautils.h"
       
    33 #include "cadef.h"
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CCaAppHandler::~CCaAppHandler()
       
    42 {
       
    43     delete iUninstallOperation;
       
    44 }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CCaAppHandler *CCaAppHandler::NewL()
       
    51 {
       
    52     CCaAppHandler *handler = new(ELeave) CCaAppHandler();
       
    53     CleanupStack::PushL( handler );
       
    54     handler->ConstructL();
       
    55     CleanupStack::Pop( handler );
       
    56     return handler;
       
    57 }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CCaAppHandler::CCaAppHandler
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 CCaAppHandler::CCaAppHandler()
       
    64 {
       
    65     iEikEnv = CEikonEnv::Static();
       
    66     iUninstallOperation = NULL;
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CCaAppHandler::ConstructL()
       
    74 {
       
    75 }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CCaAppHandler::HandleCommandL(
       
    82         CCaInnerEntry &aEntry, const TDesC8 &aCommand )
       
    83 {
       
    84     if( aCommand == KCaCmdOpen()
       
    85             && aEntry.GetEntryTypeName() == KCaTypeApp() )
       
    86         {
       
    87         TInt viewId(-1);
       
    88         TBuf<KCaMaxAttrValueLen> viewIdValue;
       
    89         if( aEntry.FindAttribute( KCaAttrView(), viewIdValue ) )
       
    90             {
       
    91             if( MenuUtils::GetTUint( viewIdValue, (TUint &) viewId )
       
    92                     != KErrNone )
       
    93                 {
       
    94                 User::Leave( KErrCorrupt );
       
    95                 }
       
    96             }
       
    97         LaunchApplicationL(
       
    98                 TUid::Uid( aEntry.GetUid() ), KNullDesC8(), viewId );
       
    99         }
       
   100     else if ( aCommand == KCaCmdClose()
       
   101             && aEntry.GetEntryTypeName() == KCaTypeApp() )
       
   102         {
       
   103         CloseApplicationL( aEntry );
       
   104         }
       
   105     else if ( aCommand == KCaCmdRemove()
       
   106                && ( aEntry.GetEntryTypeName() == KCaTypeApp()
       
   107                    || aEntry.GetEntryTypeName() == KCaTypeWidget() ) )
       
   108         {
       
   109         if ( iUninstallOperation && iUninstallOperation->IsActive() )
       
   110             {
       
   111             User::Leave( KErrInUse );
       
   112             }
       
   113         delete iUninstallOperation;
       
   114         iUninstallOperation = NULL;
       
   115         iUninstallOperation = CCaUninstallOperation::NewL( aEntry );
       
   116         }
       
   117     else
       
   118         {
       
   119         User::Leave( KErrNotSupported );
       
   120         }
       
   121 }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CCaAppHandler::LaunchApplicationL(
       
   128         const TUid aUid, const TDesC8 &aParam, TInt aViewId )
       
   129 {
       
   130     if( aViewId > 0 && iEikEnv )
       
   131         {
       
   132         TUid viewId = TUid::Uid( aViewId );
       
   133         TVwsViewId view( aUid, viewId );
       
   134         iEikEnv->EikAppUi()->ActivateViewL( view );
       
   135         }
       
   136     else
       
   137         {
       
   138         RWsSession wsSession;
       
   139         User::LeaveIfError( wsSession.Connect() );
       
   140         CleanupClosePushL<RWsSession>( wsSession );
       
   141 
       
   142         CCaTaskList* taskList = CCaTaskList::NewLC( wsSession );
       
   143         TApaTask task = taskList->FindRootApp( aUid );
       
   144         CleanupStack::PopAndDestroy( taskList );
       
   145 
       
   146         if( task.Exists() )
       
   147             {
       
   148             task.BringToForeground();
       
   149             }
       
   150         else
       
   151             {
       
   152             TApaAppInfo appInfo;
       
   153             TApaAppCapabilityBuf capabilityBuf;
       
   154             RApaLsSession appArcSession;
       
   155             User::LeaveIfError( appArcSession.Connect() );
       
   156             CleanupClosePushL<RApaLsSession>( appArcSession );
       
   157 
       
   158             User::LeaveIfError( appArcSession.GetAppInfo( appInfo, aUid ) );
       
   159             User::LeaveIfError( appArcSession.GetAppCapability(
       
   160                                    capabilityBuf, aUid ) );
       
   161 
       
   162             TApaAppCapability &caps = capabilityBuf();
       
   163             TFileName appName = appInfo.iFullName;
       
   164             CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
       
   165             cmdLine->SetExecutableNameL( appName );
       
   166 
       
   167             if( caps.iLaunchInBackground )
       
   168                 {
       
   169                 cmdLine->SetCommandL( EApaCommandBackground );
       
   170                 }
       
   171             else
       
   172                 {
       
   173                 cmdLine->SetCommandL( EApaCommandRun );
       
   174                 }
       
   175 
       
   176             cmdLine->SetTailEndL( aParam );
       
   177 
       
   178             User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
       
   179 
       
   180             CleanupStack::PopAndDestroy( cmdLine );
       
   181             CleanupStack::PopAndDestroy( &appArcSession );
       
   182         }
       
   183         CleanupStack::PopAndDestroy( &wsSession );
       
   184     }
       
   185 }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CCaAppHandler::CloseApplicationL( CCaInnerEntry &aEntry )
       
   192 {
       
   193     RWsSession wsSession;
       
   194     User::LeaveIfError( wsSession.Connect() );
       
   195     CleanupClosePushL<RWsSession>( wsSession );
       
   196 
       
   197     if( ( aEntry.GetFlags() & ERunning )
       
   198             && !( aEntry.GetFlags() & ESystem ) )
       
   199         {
       
   200         RBuf value;
       
   201         CleanupClosePushL( value );
       
   202         value.CreateL( KCaMaxAttrValueLen );
       
   203         if( aEntry.FindAttribute( KCaAttrWindowGroupId, value ) )
       
   204             {
       
   205             TInt wgId( KErrNotFound );
       
   206             TLex16 parser( value );
       
   207             if( KErrNone == parser.Val( wgId ) && wgId > 0 )
       
   208                 {
       
   209                 TWsEvent event;
       
   210                 event.SetTimeNow();
       
   211                 event.SetType( KAknShutOrHideApp );
       
   212                 wsSession.SendEventToWindowGroup( wgId, event );
       
   213                 }
       
   214             }
       
   215         CleanupStack::PopAndDestroy( &value );
       
   216     }
       
   217 
       
   218     CleanupStack::PopAndDestroy( &wsSession );
       
   219 }
       
   220