diff -r 397d00875918 -r 156f692b1687 contentstorage/cahandler/app/src/caapphandler.cpp --- a/contentstorage/cahandler/app/src/caapphandler.cpp Thu May 27 13:11:12 2010 +0300 +++ b/contentstorage/cahandler/app/src/caapphandler.cpp Fri Jun 11 13:58:37 2010 +0300 @@ -15,6 +15,8 @@ * */ +#include +#include #include #include #include @@ -27,102 +29,86 @@ #include #include +#include +#include + #include "caapphandler.h" #include "cainnerentry.h" #include "causifuninstalloperation.h" #include "catasklist.h" - #include "cautils.h" +#include "caclient_defines.h" #include "cadef.h" -// ======== MEMBER FUNCTIONS ======== using namespace Usif; -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CCaAppHandler::~CCaAppHandler() -{ - delete iUsifUninstallOperation; -} - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CCaAppHandler *CCaAppHandler::NewL() -{ - CCaAppHandler *handler = new(ELeave) CCaAppHandler(); - CleanupStack::PushL( handler ); - handler->ConstructL(); - CleanupStack::Pop( handler ); - return handler; -} +static const char caTypeApp[] = "application"; +static const char caTypePackage[] = "package"; +static const char caTypeWidget[] = "widget"; +static const char caAttrView[] = "view"; +static const char caCmdClose[] = "close"; +static const char caAttrWindowGroupId[] = "window_group_id"; +static const char caAttrComponentId[] = "component_id"; +static const char caCmdRemove[] = "remove"; // --------------------------------------------------------- -// CCaAppHandler::CCaAppHandler +// // --------------------------------------------------------- // -CCaAppHandler::CCaAppHandler() +CaAppHandler::CaAppHandler(QObject *parent): + iEikEnv(CEikonEnv::Static()), + iUsifUninstallOperation(NULL) { - iEikEnv = CEikonEnv::Static(); - iUsifUninstallOperation = NULL; + Q_UNUSED(parent); } // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // -void CCaAppHandler::ConstructL() +CaAppHandler::~CaAppHandler() +{ + delete iUsifUninstallOperation; +} + +int CaAppHandler::execute(const CaEntry &entry, const QString &command) { + int result(KErrGeneral); + if (command == caCmdOpen && entry.entryTypeName() == caTypeApp) { + QString viewIdValue = entry.attribute(caAttrView); + bool viewIdIsCorrect(true); + int viewId(-1); + if (!viewIdValue.isNull()) { + viewId = viewIdValue.toInt(&viewIdIsCorrect, 0); + } + if (viewIdIsCorrect) { + QString uidValue = + entry.attribute(APPLICATION_UID_ATTRIBUTE_NAME); + int uid = uidValue.toInt(); + TRAP(result, launchApplicationL(TUid::Uid(uid), viewId)); + } + } else if (command == caCmdClose && entry.entryTypeName() == caTypeApp ) { + QString windowGroupId = entry.attribute(caAttrWindowGroupId); + if (!windowGroupId.isNull()) { + result = closeApplication(entry.flags(), windowGroupId.toInt()); + } + } else if (command == caCmdRemove) { + QString componentId(entry.attribute(caAttrComponentId)); + result = handleRemove(entry.flags(), + entry.entryTypeName(), + componentId); + } else { + result = KErrNotSupported; + } + + return result; } // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // -void CCaAppHandler::HandleCommandL( - CCaInnerEntry &aEntry, const TDesC8 &aCommand ) -{ - - if( aCommand == KCaCmdOpen() - && aEntry.GetEntryTypeName() == KCaTypeApp() ) - { - TInt viewId(-1); - TPtrC viewIdValue; - if( aEntry.FindAttribute( KCaAttrView(), viewIdValue ) ) - { - if( MenuUtils::GetTUint( viewIdValue, (TUint &) viewId ) - != KErrNone ) - { - User::Leave( KErrCorrupt ); - } - } - LaunchApplicationL( - TUid::Uid( aEntry.GetUid() ), KNullDesC8(), viewId ); - } - else if ( aCommand == KCaCmdClose() - && aEntry.GetEntryTypeName() == KCaTypeApp() ) - { - CloseApplicationL( aEntry ); - } - else if ( aCommand == KCaCmdRemove() ) - { - HandleRemoveL(aEntry); - } - else - { - User::Leave( KErrNotSupported ); - } -} - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CCaAppHandler::LaunchApplicationL( - const TUid aUid, const TDesC8 &aParam, TInt aViewId ) +void CaAppHandler::launchApplicationL(const TUid aUid, TInt aViewId) { if( aViewId > 0 && iEikEnv ) { @@ -172,7 +158,7 @@ cmdLine->SetCommandL( EApaCommandRun ); } - cmdLine->SetTailEndL( aParam ); + cmdLine->SetTailEndL( KNullDesC8 ); User::LeaveIfError( appArcSession.StartApp( *cmdLine ) ); @@ -188,113 +174,70 @@ // // --------------------------------------------------------------------------- // -void CCaAppHandler::CloseApplicationL( CCaInnerEntry &aEntry ) +int CaAppHandler::closeApplication(const EntryFlags &flags, int windowGroupId) { - RWsSession wsSession; - User::LeaveIfError( wsSession.Connect() ); - CleanupClosePushL( wsSession ); - - if( ( aEntry.GetFlags() & ERunning ) - && !( aEntry.GetFlags() & ESystem ) ) - { - RBuf value; - CleanupClosePushL( value ); - value.CreateL( KCaMaxAttrValueLen ); - if( aEntry.FindAttribute( KCaAttrWindowGroupId, value ) ) - { - TInt wgId( KErrNotFound ); - TLex16 parser( value ); - if( KErrNone == parser.Val( wgId ) && wgId > 0 ) - { - TWsEvent event; - event.SetTimeNow(); - event.SetType( KAknShutOrHideApp ); - wsSession.SendEventToWindowGroup( wgId, event ); - } - } - CleanupStack::PopAndDestroy( &value ); + int result(KErrNone); + if (flags.testFlag(RunningEntryFlag) + && !( flags.testFlag(SystemEntryFlag)) + && windowGroupId > 0) { + RWsSession wsSession; + result = wsSession.Connect(); + if (result==KErrNone) { + TWsEvent event; + event.SetTimeNow(); + event.SetType( KAknShutOrHideApp ); + wsSession.SendEventToWindowGroup( windowGroupId, event ); + } + wsSession.Close(); } - - CleanupStack::PopAndDestroy( &wsSession ); + return result; } // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // -void CCaAppHandler::HandleRemoveL( CCaInnerEntry &aEntry ) - { - if( !( aEntry.GetFlags() & ERemovable ) ) - { - User::Leave( KErrAccessDenied ); - } - - const TPtrC entryTypeName(aEntry.GetEntryTypeName()); - - if( entryTypeName == KCaTypeApp() || - entryTypeName == KCaTypePackage() || - entryTypeName == KCaTypeWidget() ) - { - TPtrC componentId; - TBool result = aEntry.FindAttribute( KCaAttrComponentId, componentId ); - if( result ) - { - TInt32 id ; - TLex idDesc; - idDesc.Assign( componentId ); - User::LeaveIfError( idDesc.Val( id ) ); - StartUsifUninstallL( id ); - } - else - { - User::Leave( KErrNotFound ); +int CaAppHandler::handleRemove(const EntryFlags &flags, + const QString &typeName, + const QString &componentId) +{ + int result(KErrNone); + if (flags.testFlag(RemovableEntryFlag)) { + if (typeName == caTypeApp + || typeName == caTypePackage + || typeName == caTypeWidget) { + if(componentId.isNull()) { + result = KErrNotFound; + } else { + bool convertStatus(false); + int id = componentId.toInt(&convertStatus); + if (convertStatus) { + TRAP(result, startUsifUninstallL(id)); + } else { + result = KErrGeneral; + } } } - else - { - User::Leave( KErrNotSupported ); + else { + result = KErrNotSupported; } + } else { + result = KErrAccessDenied; } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -TInt CCaAppHandler::GetComponentIdL( const CCaInnerEntry &aEntry, - const TDesC& aSoftwareType ) -{ - TInt id(KErrNotFound); - RSoftwareComponentRegistry scr; - CleanupClosePushL(scr); - User::LeaveIfError(scr.Connect()); - CComponentFilter* compFilter = CComponentFilter::NewLC(); - compFilter->AddPropertyL(_L("Uid"), aEntry.GetUid()); - compFilter->SetSoftwareTypeL(aSoftwareType); - RArray componentIdList; - CleanupClosePushL(componentIdList); - scr.GetComponentIdsL(componentIdList, compFilter); - if (componentIdList.Count() > 0) - { - id = componentIdList[0]; - } - CleanupStack::PopAndDestroy(&componentIdList); - CleanupStack::PopAndDestroy(compFilter); - CleanupStack::PopAndDestroy(&scr); - return id; + return result; } // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // -void CCaAppHandler::StartUsifUninstallL( TInt aComponentId ) +void CaAppHandler::startUsifUninstallL(TInt aComponentId) { - if ( iUsifUninstallOperation && iUsifUninstallOperation->IsActive() ) - { + if (iUsifUninstallOperation && iUsifUninstallOperation->IsActive()) { User::Leave( KErrInUse ); - } + } delete iUsifUninstallOperation; iUsifUninstallOperation = NULL; - iUsifUninstallOperation = CCaUsifUninstallOperation::NewL( aComponentId ); + iUsifUninstallOperation = CCaUsifUninstallOperation::NewL(aComponentId); }