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