contentstorage/cahandler/app/src/caapphandler.cpp
changeset 96 5d243a69bdda
parent 94 dbb8300717f7
child 98 d2f833ab7940
equal deleted inserted replaced
95:c739008478cc 96:5d243a69bdda
    13  *
    13  *
    14  * Description:  ?Description
    14  * Description:  ?Description
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <QString>
       
    19 #include <e32base.h>
    18 #include <w32std.h>
    20 #include <w32std.h>
    19 #include <apgtask.h>
    21 #include <apgtask.h>
    20 #include <apgcli.h>
    22 #include <apgcli.h>
    21 #include <eikenv.h>
    23 #include <eikenv.h>
    22 #include <eikappui.h>
    24 #include <eikappui.h>
    25 #include <AknTaskList.h>
    27 #include <AknTaskList.h>
    26 
    28 
    27 #include <usif/usifcommon.h>
    29 #include <usif/usifcommon.h>
    28 #include <usif/scr/scr.h>
    30 #include <usif/scr/scr.h>
    29 
    31 
       
    32 #include <cadefs.h>
       
    33 #include <caentry.h>
       
    34 
    30 #include "caapphandler.h"
    35 #include "caapphandler.h"
    31 #include "cainnerentry.h"
    36 #include "cainnerentry.h"
    32 #include "causifuninstalloperation.h"
    37 #include "causifuninstalloperation.h"
    33 #include "catasklist.h"
    38 #include "catasklist.h"
    34 
       
    35 #include "cautils.h"
    39 #include "cautils.h"
       
    40 #include "caclient_defines.h"
    36 #include "cadef.h"
    41 #include "cadef.h"
    37 
    42 
    38 // ======== MEMBER FUNCTIONS ========
       
    39 using namespace Usif;
    43 using namespace Usif;
    40 
    44 
    41 // ---------------------------------------------------------------------------
    45 static const char caTypeApp[] = "application";
    42 //
    46 static const char caTypePackage[] = "package";
    43 // ---------------------------------------------------------------------------
    47 static const char caTypeWidget[] = "widget";
    44 //
    48 static const char caAttrView[] = "view";
    45 CCaAppHandler::~CCaAppHandler()
    49 static const char caCmdClose[] = "close";
       
    50 static const char caAttrWindowGroupId[] = "window_group_id";
       
    51 static const char caAttrComponentId[] = "component_id";
       
    52 static const char caCmdRemove[] = "remove";
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 CaAppHandler::CaAppHandler(QObject *parent):
       
    59     iEikEnv(CEikonEnv::Static()),
       
    60     iUsifUninstallOperation(NULL)
       
    61 {
       
    62     Q_UNUSED(parent);
       
    63 }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CaAppHandler::~CaAppHandler()
    46 {
    70 {
    47     delete iUsifUninstallOperation;
    71     delete iUsifUninstallOperation;
    48 }
    72 }
    49 
    73 
    50 // ---------------------------------------------------------------------------
    74 int CaAppHandler::execute(const CaEntry &entry, const QString &command)
    51 //
    75 {
    52 // ---------------------------------------------------------------------------
    76     int result(KErrGeneral);
    53 //
    77     if (command == caCmdOpen && entry.entryTypeName() == caTypeApp) {
    54 CCaAppHandler *CCaAppHandler::NewL()
    78         QString viewIdValue = entry.attribute(caAttrView);
    55 {
    79         bool viewIdIsCorrect(true);
    56     CCaAppHandler *handler = new(ELeave) CCaAppHandler();
    80         int viewId(-1);
    57     CleanupStack::PushL( handler );
    81         if (!viewIdValue.isNull()) {
    58     handler->ConstructL();
    82             viewId = viewIdValue.toInt(&viewIdIsCorrect, 0);
    59     CleanupStack::Pop( handler );
    83         }
    60     return handler;
    84         if (viewIdIsCorrect) {
    61 }
    85             QString uidValue =
    62 
    86                 entry.attribute(APPLICATION_UID_ATTRIBUTE_NAME);
    63 // ---------------------------------------------------------
    87             int uid = uidValue.toInt();
    64 // CCaAppHandler::CCaAppHandler
    88             TRAP(result, launchApplicationL(TUid::Uid(uid), viewId));
    65 // ---------------------------------------------------------
    89         }
    66 //
    90     } else if (command == caCmdClose && entry.entryTypeName() == caTypeApp ) {
    67 CCaAppHandler::CCaAppHandler()
    91         QString windowGroupId = entry.attribute(caAttrWindowGroupId);
    68 {
    92         if (!windowGroupId.isNull()) {
    69     iEikEnv = CEikonEnv::Static();
    93             result = closeApplication(entry.flags(), windowGroupId.toInt());
    70     iUsifUninstallOperation = NULL;
    94         }
    71 }
    95     } else if (command == caCmdRemove) {
    72 
    96         QString componentId(entry.attribute(caAttrComponentId));
    73 // ---------------------------------------------------------------------------
    97         result = handleRemove(entry.flags(),
    74 //
    98             entry.entryTypeName(),
    75 // ---------------------------------------------------------------------------
    99             componentId);
    76 //
   100     } else {
    77 void CCaAppHandler::ConstructL()
   101         result = KErrNotSupported;
    78 {
   102     }
    79 }
   103 
    80 
   104     return result;
    81 // ---------------------------------------------------------------------------
   105 }
    82 //
   106 
    83 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
    84 //
   108 //
    85 void CCaAppHandler::HandleCommandL(
   109 // ---------------------------------------------------------------------------
    86         CCaInnerEntry &aEntry, const TDesC8 &aCommand )
   110 //
    87 {
   111 void CaAppHandler::launchApplicationL(const TUid aUid, TInt aViewId)
    88 
       
    89     if( aCommand == KCaCmdOpen()
       
    90             && aEntry.GetEntryTypeName() == KCaTypeApp() )
       
    91         {
       
    92         TInt viewId(-1);
       
    93         TPtrC viewIdValue;
       
    94         if( aEntry.FindAttribute( KCaAttrView(), viewIdValue ) )
       
    95             {
       
    96             if( MenuUtils::GetTUint( viewIdValue, (TUint &) viewId )
       
    97                     != KErrNone )
       
    98                 {
       
    99                 User::Leave( KErrCorrupt );
       
   100                 }
       
   101             }
       
   102         LaunchApplicationL(
       
   103                 TUid::Uid( aEntry.GetUid() ), KNullDesC8(), viewId );
       
   104         }
       
   105     else if ( aCommand == KCaCmdClose()
       
   106             && aEntry.GetEntryTypeName() == KCaTypeApp() )
       
   107         {
       
   108         CloseApplicationL( aEntry );
       
   109         }
       
   110     else if ( aCommand == KCaCmdRemove() )
       
   111         {
       
   112         HandleRemoveL(aEntry);
       
   113         }
       
   114     else
       
   115         {
       
   116         User::Leave( KErrNotSupported );
       
   117         }
       
   118 }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CCaAppHandler::LaunchApplicationL(
       
   125         const TUid aUid, const TDesC8 &aParam, TInt aViewId )
       
   126 {
   112 {
   127     if( aViewId > 0 && iEikEnv )
   113     if( aViewId > 0 && iEikEnv )
   128         {
   114         {
   129         TUid viewId = TUid::Uid( aViewId );
   115         TUid viewId = TUid::Uid( aViewId );
   130         TVwsViewId view( aUid, viewId );
   116         TVwsViewId view( aUid, viewId );
   170             else
   156             else
   171                 {
   157                 {
   172                 cmdLine->SetCommandL( EApaCommandRun );
   158                 cmdLine->SetCommandL( EApaCommandRun );
   173                 }
   159                 }
   174 
   160 
   175             cmdLine->SetTailEndL( aParam );
   161             cmdLine->SetTailEndL( KNullDesC8 );
   176 
   162 
   177             User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
   163             User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
   178 
   164 
   179             CleanupStack::PopAndDestroy( cmdLine );
   165             CleanupStack::PopAndDestroy( cmdLine );
   180             CleanupStack::PopAndDestroy( &appArcSession );
   166             CleanupStack::PopAndDestroy( &appArcSession );
   186 
   172 
   187 // ---------------------------------------------------------------------------
   173 // ---------------------------------------------------------------------------
   188 //
   174 //
   189 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   190 //
   176 //
   191 void CCaAppHandler::CloseApplicationL( CCaInnerEntry &aEntry )
   177 int CaAppHandler::closeApplication(const EntryFlags &flags, int windowGroupId)
   192 {
   178 {
   193     RWsSession wsSession;
   179     int result(KErrNone);
   194     User::LeaveIfError( wsSession.Connect() );
   180     if (flags.testFlag(RunningEntryFlag)
   195     CleanupClosePushL<RWsSession>( wsSession );
   181         && !( flags.testFlag(SystemEntryFlag))
   196 
   182         && windowGroupId > 0) {
   197     if( ( aEntry.GetFlags() & ERunning )
   183         RWsSession wsSession;
   198             && !( aEntry.GetFlags() & ESystem ) )
   184         result = wsSession.Connect();
   199         {
   185         if (result==KErrNone) {
   200         RBuf value;
   186             TWsEvent event;
   201         CleanupClosePushL( value );
   187             event.SetTimeNow();
   202         value.CreateL( KCaMaxAttrValueLen );
   188             event.SetType( KAknShutOrHideApp );
   203         if( aEntry.FindAttribute( KCaAttrWindowGroupId, value ) )
   189             wsSession.SendEventToWindowGroup( windowGroupId, event );
   204             {
   190         }
   205             TInt wgId( KErrNotFound );
   191         wsSession.Close();
   206             TLex16 parser( value );
   192     }
   207             if( KErrNone == parser.Val( wgId ) && wgId > 0 )
   193     return result;
   208                 {
   194 }
   209                 TWsEvent event;
   195 
   210                 event.SetTimeNow();
   196 // ---------------------------------------------------------------------------
   211                 event.SetType( KAknShutOrHideApp );
   197 //
   212                 wsSession.SendEventToWindowGroup( wgId, event );
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 int CaAppHandler::handleRemove(const EntryFlags &flags,
       
   201     const QString &typeName,
       
   202     const QString &componentId)
       
   203 {
       
   204     int result(KErrNone);
       
   205     if (flags.testFlag(RemovableEntryFlag)) {
       
   206         if (typeName == caTypeApp
       
   207             || typeName == caTypePackage
       
   208             || typeName == caTypeWidget) {
       
   209             if(componentId.isNull()) {
       
   210                 result = KErrNotFound;
       
   211             } else {
       
   212                 bool convertStatus(false);
       
   213                 int id = componentId.toInt(&convertStatus);
       
   214                 if (convertStatus) {
       
   215                     TRAP(result, startUsifUninstallL(id));
       
   216                 } else {
       
   217                     result = KErrGeneral;
   213                 }
   218                 }
   214             }
   219             }
   215         CleanupStack::PopAndDestroy( &value );
   220         }
   216     }
   221         else {
   217 
   222             result = KErrNotSupported;
   218     CleanupStack::PopAndDestroy( &wsSession );
   223         }
   219 }
   224     } else {
   220 
   225         result = KErrAccessDenied;
   221 // ---------------------------------------------------------------------------
   226     }
   222 //
   227     return result;
   223 // ---------------------------------------------------------------------------
   228 }
   224 //
   229 
   225 void CCaAppHandler::HandleRemoveL( CCaInnerEntry &aEntry )
   230 // ---------------------------------------------------------------------------
   226     {
   231 //
   227     if( !( aEntry.GetFlags() & ERemovable ) )
   232 // ---------------------------------------------------------------------------
   228         {
   233 //
   229         User::Leave( KErrAccessDenied );
   234 void CaAppHandler::startUsifUninstallL(TInt aComponentId)
   230         }
   235 {
   231     
   236     if (iUsifUninstallOperation && iUsifUninstallOperation->IsActive()) {
   232     const TPtrC entryTypeName(aEntry.GetEntryTypeName());
       
   233     
       
   234     if( entryTypeName == KCaTypeApp()  ||
       
   235         entryTypeName == KCaTypePackage() ||
       
   236         entryTypeName == KCaTypeWidget() )
       
   237         {
       
   238         TPtrC componentId;
       
   239         TBool result = aEntry.FindAttribute( KCaAttrComponentId, componentId );
       
   240         if( result )
       
   241             {
       
   242             TInt32 id ;
       
   243             TLex idDesc;
       
   244             idDesc.Assign( componentId );
       
   245             User::LeaveIfError( idDesc.Val( id ) );
       
   246             StartUsifUninstallL( id );
       
   247             }
       
   248          else
       
   249             {
       
   250             User::Leave( KErrNotFound );
       
   251             }
       
   252         }
       
   253     else
       
   254         {
       
   255         User::Leave( KErrNotSupported );
       
   256         }
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 TInt CCaAppHandler::GetComponentIdL( const CCaInnerEntry &aEntry,
       
   264         const TDesC& aSoftwareType )
       
   265 {
       
   266     TInt id(KErrNotFound);
       
   267     RSoftwareComponentRegistry scr;
       
   268     CleanupClosePushL(scr);
       
   269     User::LeaveIfError(scr.Connect());
       
   270     CComponentFilter* compFilter = CComponentFilter::NewLC();
       
   271     compFilter->AddPropertyL(_L("Uid"), aEntry.GetUid());
       
   272     compFilter->SetSoftwareTypeL(aSoftwareType);
       
   273     RArray<TComponentId> componentIdList;
       
   274     CleanupClosePushL(componentIdList);
       
   275     scr.GetComponentIdsL(componentIdList, compFilter);
       
   276     if (componentIdList.Count() > 0)
       
   277         {
       
   278         id = componentIdList[0];
       
   279         }
       
   280     CleanupStack::PopAndDestroy(&componentIdList);
       
   281     CleanupStack::PopAndDestroy(compFilter);
       
   282     CleanupStack::PopAndDestroy(&scr);
       
   283     return id;
       
   284 }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CCaAppHandler::StartUsifUninstallL( TInt aComponentId )
       
   291 {
       
   292     if ( iUsifUninstallOperation && iUsifUninstallOperation->IsActive() )
       
   293         {
       
   294         User::Leave( KErrInUse );
   237         User::Leave( KErrInUse );
   295         }
   238     }
   296     delete iUsifUninstallOperation;
   239     delete iUsifUninstallOperation;
   297     iUsifUninstallOperation = NULL;
   240     iUsifUninstallOperation = NULL;
   298     iUsifUninstallOperation = CCaUsifUninstallOperation::NewL( aComponentId );
   241     iUsifUninstallOperation = CCaUsifUninstallOperation::NewL(aComponentId);
   299 }
   242 }
   300 
   243