homescreensrv_plat/sapi_actionhandler/actionhandlerplugins/src/ahpapplauncher.cpp
changeset 93 82b66994846c
parent 92 782e3408c2ab
child 94 dbb8300717f7
equal deleted inserted replaced
92:782e3408c2ab 93:82b66994846c
     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:  App for Action handler
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <apgcli.h>
       
    20 #include <apacmdln.h>
       
    21 #include <apgtask.h>
       
    22 #include <vwsdef.h>
       
    23 #include <eikenv.h>
       
    24 #include <eikappui.h>
       
    25 #include <liwvariant.h>
       
    26 
       
    27 #include "ahproperties.hrh"
       
    28 #include "ahpapplauncher.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // Symbian 2nd phase constructor can leave.
       
    34 // ----------------------------------------------------------------------------
       
    35 //
       
    36 void CAHAppLauncher::ConstructL()
       
    37     {
       
    38     iEnv = CEikonEnv::Static( );
       
    39     }
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // Two-phased constructor.
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CAHAppLauncher* CAHAppLauncher::NewL()
       
    46     {
       
    47     CAHAppLauncher* self = CAHAppLauncher::NewLC( );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // Two-phased constructor.
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CAHAppLauncher* CAHAppLauncher::NewLC()
       
    57     {
       
    58     CAHAppLauncher* self = new( ELeave ) CAHAppLauncher;
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL( );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // destructor
       
    66 // ---------------------------------------------------------------------------
       
    67 CAHAppLauncher::~CAHAppLauncher()
       
    68     {
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Executes provided action
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 TInt CAHAppLauncher::ExecuteTypeLaunchL( const CLiwMap* aMap )
       
    76     {
       
    77     TInt errCode(KErrArgument);
       
    78     RBuf launchMethod;
       
    79     CleanupClosePushL( launchMethod );
       
    80 
       
    81     if ( !ExtractDesL( aMap, launchMethod, KLaunchMethod ) )
       
    82         {
       
    83         if ( !launchMethod.CompareF( KLaunchMethodValueCmdLine ) )
       
    84             {
       
    85             errCode = ExecuteCommmandLineL( aMap );
       
    86             }
       
    87         else if ( !launchMethod.CompareF( KLaunchMethodValueMessageWithDoc )
       
    88                 || !launchMethod.CompareF( KLaunchMethodValueMessageWithTail ) )
       
    89             {
       
    90             errCode = ExecuteApaMessageL( aMap );
       
    91             }
       
    92         }
       
    93 
       
    94     CleanupStack::PopAndDestroy( &launchMethod );
       
    95     return errCode;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Executes provided command line action
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TInt CAHAppLauncher::ExecuteCommmandLineL( const CLiwMap* aMap )
       
   103     {
       
   104     TInt errCode(KErrArgument);
       
   105     TUid appUid= TUid::Null( );
       
   106 
       
   107     if ( !ExtractUidL( aMap, appUid, KApplicationUid ) )
       
   108         {
       
   109         RApaLsSession appSession;
       
   110         CleanupClosePushL( appSession );
       
   111         User::LeaveIfError( appSession.Connect( ) );
       
   112 
       
   113         CApaCommandLine* cmd = CApaCommandLine::NewLC( );
       
   114         cmd->SetCommandL( GetCommandL( aMap ) );
       
   115         RBuf documentNameValue;
       
   116         CleanupClosePushL( documentNameValue );
       
   117         if( !ExtractDesL( aMap, documentNameValue, KDocumentName ) )
       
   118             {
       
   119             cmd->SetDocumentNameL( documentNameValue );
       
   120             }
       
   121         TApaAppInfo appInfo;
       
   122         appSession.GetAppInfo( appInfo, appUid );
       
   123         cmd->SetExecutableNameL( appInfo.iFullName );
       
   124         errCode = appSession.StartApp( *cmd );
       
   125 
       
   126         CleanupStack::PopAndDestroy( &documentNameValue );
       
   127         CleanupStack::PopAndDestroy( cmd );
       
   128         CleanupStack::PopAndDestroy( &appSession );
       
   129         }
       
   130     return errCode;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // Executes provided apa message action
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TInt CAHAppLauncher::ExecuteApaMessageL( const CLiwMap* aMap )
       
   138     {
       
   139     TInt errCode(KErrArgument);
       
   140     TUid appUid= TUid::Null( );
       
   141     if ( !ExtractUidL( aMap, appUid, KApplicationUid ) )
       
   142         {
       
   143         TApaTaskList taskList( iEnv->WsSession() );
       
   144         TApaTask task = taskList.FindApp( appUid );
       
   145         if ( task.Exists( ) )
       
   146             {
       
   147             TUid messageUid= TUid::Null( );
       
   148 
       
   149             RBuf8 additionalData;
       
   150             CleanupClosePushL( additionalData );
       
   151             if ( !ExtractUidL( aMap, messageUid, KMessageUid )
       
   152                     && !ExtractDes8L( aMap, additionalData, KAdditionalData ) )
       
   153                 {
       
   154                 errCode = task.SendMessage( messageUid, additionalData );
       
   155                 }
       
   156             CleanupStack::PopAndDestroy( &additionalData );
       
   157             }
       
   158         else
       
   159             { // app not yet running
       
   160             RBuf launchMethod;
       
   161             CleanupClosePushL( launchMethod );
       
   162             if ( !ExtractDesL( aMap, launchMethod, KLaunchMethod ) )
       
   163                 {
       
   164                 if ( !launchMethod.CompareF( KLaunchMethodValueMessageWithDoc ) )
       
   165                     {
       
   166                     errCode = StartDocumentL( aMap ) ;
       
   167                     }
       
   168                 else if ( !launchMethod.CompareF( KLaunchMethodValueMessageWithTail ) )
       
   169                     {
       
   170                     errCode = StartAppL( aMap );
       
   171                     }
       
   172                 }
       
   173             CleanupStack::PopAndDestroy( &launchMethod );
       
   174             }
       
   175         }
       
   176     return errCode;
       
   177 
       
   178     }
       
   179 // ---------------------------------------------------------------------------
       
   180 // Start document
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 TInt CAHAppLauncher::StartDocumentL( const CLiwMap* aMap )
       
   184     {
       
   185     TInt errCode(KErrArgument);
       
   186     TUid appUid= TUid::Null( );
       
   187     RBuf documentNameValue;
       
   188     CleanupClosePushL( documentNameValue );
       
   189     if ( !ExtractUidL( aMap, appUid, KApplicationUid )
       
   190         && !ExtractDesL( aMap, documentNameValue, KDocumentName ) )
       
   191         {
       
   192         RApaLsSession appArcSession;
       
   193         CleanupClosePushL( appArcSession );
       
   194         User::LeaveIfError( appArcSession.Connect( ) );
       
   195         TThreadId id;
       
   196         errCode = appArcSession.StartDocument( documentNameValue, appUid, id );
       
   197         CleanupStack::PopAndDestroy( &appArcSession );
       
   198         }
       
   199     CleanupStack::PopAndDestroy( &documentNameValue );
       
   200     return errCode;
       
   201     }
       
   202 // ---------------------------------------------------------------------------
       
   203 // Starts application
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 TInt CAHAppLauncher::StartAppL( const CLiwMap* aMap )
       
   207     {
       
   208     TInt errCode(KErrArgument);
       
   209     TUid appUid= TUid::Null( );
       
   210     RBuf8 additionalData;
       
   211     CleanupClosePushL( additionalData );
       
   212     if ( !ExtractUidL( aMap, appUid, KApplicationUid )
       
   213         && !ExtractDes8L( aMap, additionalData, KAdditionalData ) )
       
   214         {
       
   215         RApaLsSession appArcSession;
       
   216         CleanupClosePushL( appArcSession );
       
   217         User::LeaveIfError( appArcSession.Connect( ) );
       
   218         TApaAppInfo appInfo;
       
   219         errCode = appArcSession.GetAppInfo( appInfo, appUid );
       
   220         if ( errCode == KErrNone )
       
   221             {
       
   222             CApaCommandLine* cmdLine = CApaCommandLine::NewLC( );
       
   223             cmdLine->SetExecutableNameL( appInfo.iFullName );
       
   224             cmdLine->SetCommandL( EApaCommandRun );
       
   225             cmdLine->SetTailEndL( additionalData );
       
   226 
       
   227             errCode = appArcSession.StartApp( *cmdLine );
       
   228             CleanupStack::PopAndDestroy( cmdLine );
       
   229             }
       
   230         CleanupStack::PopAndDestroy( &appArcSession );
       
   231         }
       
   232     CleanupStack::PopAndDestroy( &additionalData );
       
   233     return errCode;
       
   234     }
       
   235 // ----------------------------------------------------------------------------
       
   236 // Executes provided action - activate view
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 TInt CAHAppLauncher::ExecuteActivateViewL( const CLiwMap* aMap )
       
   240     {
       
   241     TInt errCode(KErrGeneral);
       
   242     if ( iEnv )
       
   243         {
       
   244         CCoeAppUi* appui = iEnv-> EikAppUi( );
       
   245         if ( appui )
       
   246             {
       
   247             TUid messageUid= TUid::Null( );
       
   248             TVwsViewId viewId;
       
   249             if ( !ExtractViewIdL( aMap, viewId ) )
       
   250                 {
       
   251                 RBuf8 additionalData;
       
   252                 CleanupClosePushL( additionalData );
       
   253                 if ( !ExtractUidL( aMap, messageUid, KMessageUid )
       
   254                     && !ExtractDes8L( aMap, additionalData, KAdditionalData ) )
       
   255                     {
       
   256                     appui->ActivateViewL( viewId, messageUid, additionalData );
       
   257                     }
       
   258                 else
       
   259                     {
       
   260                     appui->ActivateViewL( viewId );
       
   261                     }
       
   262                 errCode = KErrNone;
       
   263                 CleanupStack::PopAndDestroy( &additionalData );
       
   264                 }
       
   265             }
       
   266         }
       
   267     return errCode;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // Executes provided action
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 TInt CAHAppLauncher::ExecuteActionL( const CLiwMap* aMap )
       
   275     {
       
   276     TInt errCode(KErrNotFound);
       
   277     RBuf type;
       
   278     CleanupClosePushL( type );
       
   279     errCode = ExtractDesL( aMap, type, KType );
       
   280 
       
   281     if ( errCode == KErrNone )
       
   282         {
       
   283         if ( !type.CompareF( KActionValueLaunchApplication ) )
       
   284             {
       
   285             errCode = ExecuteTypeLaunchL( aMap );
       
   286             }
       
   287         else if ( !type.CompareF( KActionValueViewActivation ) )
       
   288             {
       
   289             errCode = ExecuteActivateViewL( aMap );
       
   290             }
       
   291         }
       
   292     CleanupStack::PopAndDestroy( &type );
       
   293     return errCode;
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 TInt CAHAppLauncher::ExtractDesL( const CLiwMap* aMap,
       
   301     RBuf& aString, const TDesC8& aMapName )
       
   302     {
       
   303     TInt errCode(KErrNotFound);
       
   304     TLiwVariant variant;
       
   305     variant.PushL( );
       
   306     TPtrC tempString( KNullDesC );
       
   307     if ( aMap->FindL( aMapName, variant ) )
       
   308         {
       
   309         if ( variant.Get( tempString ) )
       
   310             {
       
   311             aString.ReAllocL( tempString.Length( ) );
       
   312             aString.Append( tempString );
       
   313             errCode = KErrNone;
       
   314             }
       
   315         else
       
   316             {
       
   317             errCode = KErrCorrupt;
       
   318             }
       
   319         }
       
   320     CleanupStack::PopAndDestroy( &variant );
       
   321     return errCode;
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 TInt CAHAppLauncher::ExtractDes8L( const CLiwMap* aMap,
       
   329     RBuf8& aString, const TDesC8& aMapName )
       
   330     {
       
   331     TInt errCode(KErrNotFound);
       
   332     TLiwVariant variant;
       
   333     variant.PushL( );
       
   334     TPtrC8 tempString( KNullDesC8 );
       
   335     if ( aMap->FindL( aMapName, variant ) )
       
   336         {
       
   337         if ( variant.Get( tempString ) )
       
   338             {
       
   339             aString.ReAllocL( tempString.Length( ) );
       
   340             aString.Append( tempString );
       
   341             errCode = KErrNone;
       
   342             }
       
   343         else
       
   344             {
       
   345             errCode = KErrCorrupt;
       
   346             }
       
   347         }
       
   348     CleanupStack::PopAndDestroy( &variant );
       
   349     return errCode;
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 TInt CAHAppLauncher::ExtractUidL( const CLiwMap* aMap, TUid& aUid,
       
   357     const TDesC8& aMapName )
       
   358 
       
   359     {
       
   360     TInt errCode(KErrNotFound);
       
   361     TInt32 temp;
       
   362     TLiwVariant variant;
       
   363     variant.PushL( );
       
   364     if ( aMap->FindL( aMapName, variant ) )
       
   365         {
       
   366         if ( variant.Get( temp ) )
       
   367             {
       
   368             aUid = TUid::Uid( temp );
       
   369             errCode = KErrNone;
       
   370             }
       
   371         else
       
   372             {
       
   373             errCode = KErrCorrupt;
       
   374             }
       
   375         }
       
   376     CleanupStack::PopAndDestroy( &variant );
       
   377     return errCode;
       
   378     }
       
   379 
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 TInt CAHAppLauncher::ExtractViewIdL( const CLiwMap* aMap, TVwsViewId& aViewId )
       
   385 
       
   386     {
       
   387     TInt errCode(KErrNotFound);
       
   388     TLiwVariant variant;
       
   389     if ( aMap->FindL( KViewId, variant ) )
       
   390         {
       
   391         if ( variant.Get( aViewId.iViewUid.iUid ) )
       
   392             {
       
   393             variant.Reset( );
       
   394             if ( aMap->FindL( KViewAppUid, variant ) )
       
   395                 {
       
   396                 if ( variant.Get( aViewId.iAppUid.iUid ) )
       
   397                     {
       
   398                     variant.Reset( );
       
   399                     errCode = KErrNone;
       
   400                     }
       
   401                 else
       
   402                     {
       
   403                     errCode = KErrCorrupt;
       
   404                     }
       
   405                 }
       
   406             }
       
   407         else
       
   408             {
       
   409             errCode = KErrCorrupt;
       
   410             }
       
   411         }
       
   412 
       
   413     return errCode;
       
   414     }
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 // ---------------------------------------------------------------------------
       
   419 //
       
   420 TApaCommand CAHAppLauncher::GetCommandL( const CLiwMap* aMap )
       
   421     {
       
   422     TApaCommand command(EApaCommandOpen);
       
   423     RBuf appCommand;
       
   424     CleanupClosePushL( appCommand );
       
   425     if ( ExtractDesL( aMap, appCommand, KApaCommand ) == KErrNone )
       
   426         {
       
   427         if( appCommand.Compare( KApaCommandBackground ) == KErrNone )
       
   428             {
       
   429             command = EApaCommandBackground;
       
   430             }
       
   431         }
       
   432     CleanupStack::PopAndDestroy( &appCommand );
       
   433     return command;
       
   434     }
       
   435 
       
   436 // End of file